ofb64enc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_ofb64_encrypt(register const unsigned char *in,
  21. register unsigned char *out, long length,
  22. DES_key_schedule *schedule, DES_cblock *ivec, int *num)
  23. {
  24. register DES_LONG v0, v1, t;
  25. register int n = *num;
  26. register long l = length;
  27. DES_cblock d;
  28. register unsigned char *dp;
  29. DES_LONG ti[2];
  30. unsigned char *iv;
  31. int save = 0;
  32. iv = &(*ivec)[0];
  33. c2l(iv, v0);
  34. c2l(iv, v1);
  35. ti[0] = v0;
  36. ti[1] = v1;
  37. dp = d;
  38. l2c(v0, dp);
  39. l2c(v1, dp);
  40. while (l--) {
  41. if (n == 0) {
  42. DES_encrypt1(ti, schedule, DES_ENCRYPT);
  43. dp = d;
  44. t = ti[0];
  45. l2c(t, dp);
  46. t = ti[1];
  47. l2c(t, dp);
  48. save++;
  49. }
  50. *(out++) = *(in++) ^ d[n];
  51. n = (n + 1) & 0x07;
  52. }
  53. if (save) {
  54. v0 = ti[0];
  55. v1 = ti[1];
  56. iv = &(*ivec)[0];
  57. l2c(v0, iv);
  58. l2c(v1, iv);
  59. }
  60. t = v0 = v1 = ti[0] = ti[1] = 0;
  61. *num = n;
  62. }