rc2ofb64.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/rc2.h>
  10. #include "rc2_local.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 RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  17. long length, RC2_KEY *schedule, unsigned char *ivec,
  18. int *num)
  19. {
  20. register unsigned long v0, v1, t;
  21. register int n = *num;
  22. register long l = length;
  23. unsigned char d[8];
  24. register char *dp;
  25. unsigned long ti[2];
  26. unsigned char *iv;
  27. int save = 0;
  28. iv = (unsigned char *)ivec;
  29. c2l(iv, v0);
  30. c2l(iv, v1);
  31. ti[0] = v0;
  32. ti[1] = v1;
  33. dp = (char *)d;
  34. l2c(v0, dp);
  35. l2c(v1, dp);
  36. while (l--) {
  37. if (n == 0) {
  38. RC2_encrypt((unsigned long *)ti, schedule);
  39. dp = (char *)d;
  40. t = ti[0];
  41. l2c(t, dp);
  42. t = ti[1];
  43. l2c(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. l2c(v0, iv);
  54. l2c(v1, iv);
  55. }
  56. t = v0 = v1 = ti[0] = ti[1] = 0;
  57. *num = n;
  58. }