2
0

md5_one.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. #include <stdio.h>
  10. #include <string.h>
  11. #include <openssl/md5.h>
  12. #include <openssl/crypto.h>
  13. #ifdef CHARSET_EBCDIC
  14. # include <openssl/ebcdic.h>
  15. #endif
  16. unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
  17. {
  18. MD5_CTX c;
  19. static unsigned char m[MD5_DIGEST_LENGTH];
  20. if (md == NULL)
  21. md = m;
  22. if (!MD5_Init(&c))
  23. return NULL;
  24. #ifndef CHARSET_EBCDIC
  25. MD5_Update(&c, d, n);
  26. #else
  27. {
  28. char temp[1024];
  29. unsigned long chunk;
  30. while (n > 0) {
  31. chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
  32. ebcdic2ascii(temp, d, chunk);
  33. MD5_Update(&c, temp, chunk);
  34. n -= chunk;
  35. d += chunk;
  36. }
  37. }
  38. #endif
  39. MD5_Final(md, &c);
  40. OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */
  41. return md;
  42. }