2
0

md2_one.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. * MD2 low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <stdio.h>
  15. #include "internal/cryptlib.h"
  16. #include <openssl/md2.h>
  17. /*
  18. * This is a separate file so that #defines in cryptlib.h can map my MD
  19. * functions to different names
  20. */
  21. unsigned char *MD2(const unsigned char *d, size_t n, unsigned char *md)
  22. {
  23. MD2_CTX c;
  24. static unsigned char m[MD2_DIGEST_LENGTH];
  25. if (md == NULL)
  26. md = m;
  27. if (!MD2_Init(&c))
  28. return NULL;
  29. #ifndef CHARSET_EBCDIC
  30. MD2_Update(&c, d, n);
  31. #else
  32. {
  33. char temp[1024];
  34. unsigned long chunk;
  35. while (n > 0) {
  36. chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
  37. ebcdic2ascii(temp, d, chunk);
  38. MD2_Update(&c, temp, chunk);
  39. n -= chunk;
  40. d += chunk;
  41. }
  42. }
  43. #endif
  44. MD2_Final(md, &c);
  45. OPENSSL_cleanse(&c, sizeof(c)); /* Security consideration */
  46. return md;
  47. }