You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9 KiB

  1. /* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software Foundation,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
  12. /**
  13. @file
  14. @brief
  15. Wrapper functions for OpenSSL and YaSSL. Also provides a Compatibility layer
  16. to make available YaSSL's MD5 implementation.
  17. */
  18. #include <my_global.h>
  19. #include <my_md5.h>
  20. #if defined(HAVE_YASSL)
  21. #include "my_config.h"
  22. #include "md5.hpp"
  23. static void my_md5_hash(char *digest, const char *buf, int len)
  24. {
  25. TaoCrypt::MD5 hasher;
  26. hasher.Update((TaoCrypt::byte *) buf, len);
  27. hasher.Final((TaoCrypt::byte *) digest);
  28. }
  29. #elif defined(HAVE_OPENSSL)
  30. #include <openssl/md5.h>
  31. static void my_md5_hash(unsigned char* digest, unsigned const char *buf, int len)
  32. {
  33. MD5_CTX ctx;
  34. MD5_Init (&ctx);
  35. MD5_Update (&ctx, buf, len);
  36. MD5_Final (digest, &ctx);
  37. }
  38. #endif /* HAVE_YASSL */
  39. /**
  40. Wrapper function to compute MD5 message digest.
  41. @param digest [out] Computed MD5 digest
  42. @param buf [in] Message to be computed
  43. @param len [in] Length of the message
  44. @return void
  45. */
  46. void compute_md5_hash(char *digest, const char *buf, int len)
  47. {
  48. #if defined(HAVE_YASSL)
  49. my_md5_hash(digest, buf, len);
  50. #elif defined(HAVE_OPENSSL)
  51. my_md5_hash((unsigned char*)digest, (unsigned const char*)buf, len);
  52. #endif /* HAVE_YASSL */
  53. }