ofb64ede.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "des_local.h"
  10. /*
  11. * The input and output encrypted as though 64bit ofb mode is being used.
  12. * The extra state information to record how much of the 64bit block we have
  13. * used is contained in *num;
  14. */
  15. void DES_ede3_ofb64_encrypt(register const unsigned char *in,
  16. register unsigned char *out, long length,
  17. DES_key_schedule *k1, DES_key_schedule *k2,
  18. DES_key_schedule *k3, DES_cblock *ivec, int *num)
  19. {
  20. register DES_LONG v0, v1;
  21. register int n = *num;
  22. register long l = length;
  23. DES_cblock d;
  24. register char *dp;
  25. DES_LONG ti[2];
  26. unsigned char *iv;
  27. int save = 0;
  28. iv = &(*ivec)[0];
  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. /* ti[0]=v0; */
  39. /* ti[1]=v1; */
  40. DES_encrypt3(ti, k1, k2, k3);
  41. v0 = ti[0];
  42. v1 = ti[1];
  43. dp = (char *)d;
  44. l2c(v0, dp);
  45. l2c(v1, dp);
  46. save++;
  47. }
  48. *(out++) = *(in++) ^ d[n];
  49. n = (n + 1) & 0x07;
  50. }
  51. if (save) {
  52. iv = &(*ivec)[0];
  53. l2c(v0, iv);
  54. l2c(v1, iv);
  55. }
  56. v0 = v1 = ti[0] = ti[1] = 0;
  57. *num = n;
  58. }