md2_one.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 1995-2016 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. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/md2.h>
  12. /*
  13. * This is a separate file so that #defines in cryptlib.h can map my MD
  14. * functions to different names
  15. */
  16. unsigned char *MD2(const unsigned char *d, size_t n, unsigned char *md)
  17. {
  18. MD2_CTX c;
  19. static unsigned char m[MD2_DIGEST_LENGTH];
  20. if (md == NULL)
  21. md = m;
  22. if (!MD2_Init(&c))
  23. return NULL;
  24. #ifndef CHARSET_EBCDIC
  25. MD2_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. MD2_Update(&c, temp, chunk);
  34. n -= chunk;
  35. d += chunk;
  36. }
  37. }
  38. #endif
  39. MD2_Final(md, &c);
  40. OPENSSL_cleanse(&c, sizeof(c)); /* Security consideration */
  41. return md;
  42. }