ecb_enc.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <openssl/opensslv.h>
  16. #include <openssl/bio.h>
  17. const char *DES_options(void)
  18. {
  19. static int init = 1;
  20. static char buf[12];
  21. if (init) {
  22. if (sizeof(DES_LONG) != sizeof(long))
  23. OPENSSL_strlcpy(buf, "des(int)", sizeof(buf));
  24. else
  25. OPENSSL_strlcpy(buf, "des(long)", sizeof(buf));
  26. init = 0;
  27. }
  28. return buf;
  29. }
  30. void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
  31. DES_key_schedule *ks, int enc)
  32. {
  33. register DES_LONG l;
  34. DES_LONG ll[2];
  35. const unsigned char *in = &(*input)[0];
  36. unsigned char *out = &(*output)[0];
  37. c2l(in, l);
  38. ll[0] = l;
  39. c2l(in, l);
  40. ll[1] = l;
  41. DES_encrypt1(ll, ks, enc);
  42. l = ll[0];
  43. l2c(l, out);
  44. l = ll[1];
  45. l2c(l, out);
  46. l = ll[0] = ll[1] = 0;
  47. }