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.

61 lines
1.6 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 <openssl/blowfish.h>
  10. #include "bf_locl.h"
  11. /*
  12. * The input and output encrypted as though 64bit ofb mode is being used.
  13. * The extra state information to record how much of the 64bit block we have
  14. * used is contained in *num;
  15. */
  16. void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  17. long length, const BF_KEY *schedule,
  18. unsigned char *ivec, int *num)
  19. {
  20. register BF_LONG v0, v1, t;
  21. register int n = *num;
  22. register long l = length;
  23. unsigned char d[8];
  24. register char *dp;
  25. BF_LONG ti[2];
  26. unsigned char *iv;
  27. int save = 0;
  28. iv = (unsigned char *)ivec;
  29. n2l(iv, v0);
  30. n2l(iv, v1);
  31. ti[0] = v0;
  32. ti[1] = v1;
  33. dp = (char *)d;
  34. l2n(v0, dp);
  35. l2n(v1, dp);
  36. while (l--) {
  37. if (n == 0) {
  38. BF_encrypt((BF_LONG *)ti, schedule);
  39. dp = (char *)d;
  40. t = ti[0];
  41. l2n(t, dp);
  42. t = ti[1];
  43. l2n(t, dp);
  44. save++;
  45. }
  46. *(out++) = *(in++) ^ d[n];
  47. n = (n + 1) & 0x07;
  48. }
  49. if (save) {
  50. v0 = ti[0];
  51. v1 = ti[1];
  52. iv = (unsigned char *)ivec;
  53. l2n(v0, iv);
  54. l2n(v1, iv);
  55. }
  56. t = v0 = v1 = ti[0] = ti[1] = 0;
  57. *num = n;
  58. }