rc5ofb64.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 1995-2016 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. * RC5 low level APIs are deprecated for public use, but still ok for internal
  11. * use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <openssl/rc5.h>
  15. #include "rc5_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 RC5_32_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  22. long length, RC5_32_KEY *schedule,
  23. unsigned char *ivec, int *num)
  24. {
  25. register unsigned long v0, v1, t;
  26. register int n = *num;
  27. register long l = length;
  28. unsigned char d[8];
  29. register char *dp;
  30. unsigned long ti[2];
  31. unsigned char *iv;
  32. int save = 0;
  33. iv = (unsigned char *)ivec;
  34. c2l(iv, v0);
  35. c2l(iv, v1);
  36. ti[0] = v0;
  37. ti[1] = v1;
  38. dp = (char *)d;
  39. l2c(v0, dp);
  40. l2c(v1, dp);
  41. while (l--) {
  42. if (n == 0) {
  43. RC5_32_encrypt((unsigned long *)ti, schedule);
  44. dp = (char *)d;
  45. t = ti[0];
  46. l2c(t, dp);
  47. t = ti[1];
  48. l2c(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. l2c(v0, iv);
  59. l2c(v1, iv);
  60. }
  61. t = v0 = v1 = ti[0] = ti[1] = 0;
  62. *num = n;
  63. }