md5utils.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  3. * rights reserved.
  4. *
  5. * License to copy and use this software is granted provided that it
  6. * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  7. * Algorithm" in all material mentioning or referencing this software
  8. * or this function.
  9. *
  10. * License is also granted to make and use derivative works provided
  11. * that such works are identified as "derived from the RSA Data
  12. * Security, Inc. MD5 Message-Digest Algorithm" in all material
  13. * mentioning or referencing the derived work.
  14. *
  15. * RSA Data Security, Inc. makes no representations concerning either
  16. * the merchantability of this software or the suitability of this
  17. * software for any particular purpose. It is provided "as is"
  18. * without express or implied warranty of any kind.
  19. *
  20. * These notices must be retained in any copies of any part of this
  21. * documentation and/or software.
  22. */
  23. /*!
  24. * \file
  25. * \brief SIP-router core :: md5 hash support
  26. * \ingroup core
  27. * Module: \ref core
  28. */
  29. #include <stdio.h>
  30. #include <time.h>
  31. #include <string.h>
  32. #include "md5.h"
  33. #include "md5utils.h"
  34. #include "dprint.h"
  35. #include "ut.h"
  36. /*!
  37. * \brief Calculate a MD5 digests over a string array
  38. *
  39. * Calculate a MD5 digests over a string array and stores the result in the
  40. * destination char array. This function assumes 32 bytes in the destination
  41. * buffer.
  42. * \param dst destination
  43. * \param src string input array
  44. * \param size elements in the input array
  45. */
  46. void MD5StringArray (char *dst, str src[], int size)
  47. {
  48. MD5_CTX context;
  49. unsigned char digest[16];
  50. int i;
  51. int len;
  52. char *s;
  53. MD5Init (&context);
  54. for (i=0; i<size; i++) {
  55. trim_len( len, s, src[i] );
  56. if (len > 0)
  57. MD5Update (&context, s, len);
  58. }
  59. U_MD5Final (digest, &context);
  60. string2hex(digest, 16, dst );
  61. DBG("DEBUG: MD5 calculated: %.*s\n", MD5_LEN, dst );
  62. }