A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "des_locl.h"
  10. /*
  11. * The input and output encrypted as though 64bit ofb mode is being used.
  12. * The extra state information to record how much of the 64bit block we have
  13. * used is contained in *num;
  14. */
  15. void DES_ofb64_encrypt(register const unsigned char *in,
  16. register unsigned char *out, long length,
  17. DES_key_schedule *schedule, DES_cblock *ivec, int *num)
  18. {
  19. register DES_LONG v0, v1, t;
  20. register int n = *num;
  21. register long l = length;
  22. DES_cblock d;
  23. register unsigned char *dp;
  24. DES_LONG ti[2];
  25. unsigned char *iv;
  26. int save = 0;
  27. iv = &(*ivec)[0];
  28. c2l(iv, v0);
  29. c2l(iv, v1);
  30. ti[0] = v0;
  31. ti[1] = v1;
  32. dp = d;
  33. l2c(v0, dp);
  34. l2c(v1, dp);
  35. while (l--) {
  36. if (n == 0) {
  37. DES_encrypt1(ti, schedule, DES_ENCRYPT);
  38. dp = d;
  39. t = ti[0];
  40. l2c(t, dp);
  41. t = ti[1];
  42. l2c(t, dp);
  43. save++;
  44. }
  45. *(out++) = *(in++) ^ d[n];
  46. n = (n + 1) & 0x07;
  47. }
  48. if (save) {
  49. v0 = ti[0];
  50. v1 = ti[1];
  51. iv = &(*ivec)[0];
  52. l2c(v0, iv);
  53. l2c(v1, iv);
  54. }
  55. t = v0 = v1 = ti[0] = ti[1] = 0;
  56. *num = n;
  57. }