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.

67 lines
1.7 KiB

  1. /*
  2. * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. /*
  10. * BF low level APIs are deprecated for public use, but still ok for internal
  11. * use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <openssl/blowfish.h>
  15. #include "bf_local.h"
  16. /*
  17. * The input and output encrypted as though 64bit ofb mode is being used.
  18. * The extra state information to record how much of the 64bit block we have
  19. * used is contained in *num;
  20. */
  21. void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  22. long length, const BF_KEY *schedule,
  23. unsigned char *ivec, int *num)
  24. {
  25. register BF_LONG v0, v1, t;
  26. register int n = *num;
  27. register long l = length;
  28. unsigned char d[8];
  29. register char *dp;
  30. BF_LONG ti[2];
  31. unsigned char *iv;
  32. int save = 0;
  33. iv = (unsigned char *)ivec;
  34. n2l(iv, v0);
  35. n2l(iv, v1);
  36. ti[0] = v0;
  37. ti[1] = v1;
  38. dp = (char *)d;
  39. l2n(v0, dp);
  40. l2n(v1, dp);
  41. while (l--) {
  42. if (n == 0) {
  43. BF_encrypt((BF_LONG *)ti, schedule);
  44. dp = (char *)d;
  45. t = ti[0];
  46. l2n(t, dp);
  47. t = ti[1];
  48. l2n(t, dp);
  49. save++;
  50. }
  51. *(out++) = *(in++) ^ d[n];
  52. n = (n + 1) & 0x07;
  53. }
  54. if (save) {
  55. v0 = ti[0];
  56. v1 = ti[1];
  57. iv = (unsigned char *)ivec;
  58. l2n(v0, iv);
  59. l2n(v1, iv);
  60. }
  61. t = v0 = v1 = ti[0] = ti[1] = 0;
  62. *num = n;
  63. }