c_ofb64.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. * CAST low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <openssl/cast.h>
  15. #include "cast_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 CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  22. long length, const CAST_KEY *schedule,
  23. unsigned char *ivec, int *num)
  24. {
  25. register CAST_LONG v0, v1, t;
  26. register int n = *num;
  27. register long l = length;
  28. unsigned char d[8];
  29. register char *dp;
  30. CAST_LONG ti[2];
  31. unsigned char *iv;
  32. int save = 0;
  33. iv = 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. CAST_encrypt((CAST_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 = ivec;
  58. l2n(v0, iv);
  59. l2n(v1, iv);
  60. }
  61. t = v0 = v1 = ti[0] = ti[1] = 0;
  62. *num = n;
  63. }