md5_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. * MD5 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 <string.h>
  16. #include <openssl/md5.h>
  17. #include <openssl/crypto.h>
  18. #ifdef CHARSET_EBCDIC
  19. # include <openssl/ebcdic.h>
  20. #endif
  21. unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
  22. {
  23. MD5_CTX c;
  24. static unsigned char m[MD5_DIGEST_LENGTH];
  25. if (md == NULL)
  26. md = m;
  27. if (!MD5_Init(&c))
  28. return NULL;
  29. #ifndef CHARSET_EBCDIC
  30. MD5_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. MD5_Update(&c, temp, chunk);
  39. n -= chunk;
  40. d += chunk;
  41. }
  42. }
  43. #endif
  44. MD5_Final(md, &c);
  45. OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */
  46. return md;
  47. }