ofb64ede.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * DES low level APIs are deprecated for public use, but still ok for internal
  11. * use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include "des_local.h"
  15. /*
  16. * The input and output encrypted as though 64bit ofb mode is being used.
  17. * The extra state information to record how much of the 64bit block we have
  18. * used is contained in *num;
  19. */
  20. void DES_ede3_ofb64_encrypt(register const unsigned char *in,
  21. register unsigned char *out, long length,
  22. DES_key_schedule *k1, DES_key_schedule *k2,
  23. DES_key_schedule *k3, DES_cblock *ivec, int *num)
  24. {
  25. register DES_LONG v0, v1;
  26. register int n = *num;
  27. register long l = length;
  28. DES_cblock d;
  29. register char *dp;
  30. DES_LONG ti[2];
  31. unsigned char *iv;
  32. int save = 0;
  33. iv = &(*ivec)[0];
  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. /* ti[0]=v0; */
  44. /* ti[1]=v1; */
  45. DES_encrypt3(ti, k1, k2, k3);
  46. v0 = ti[0];
  47. v1 = ti[1];
  48. dp = (char *)d;
  49. l2c(v0, dp);
  50. l2c(v1, dp);
  51. save++;
  52. }
  53. *(out++) = *(in++) ^ d[n];
  54. n = (n + 1) & 0x07;
  55. }
  56. if (save) {
  57. iv = &(*ivec)[0];
  58. l2c(v0, iv);
  59. l2c(v1, iv);
  60. }
  61. v0 = v1 = ti[0] = ti[1] = 0;
  62. *num = n;
  63. }