md5utils.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* MDDRIVER.C - test driver for MD2, MD4 and MD5
  2. *
  3. */
  4. /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
  5. rights reserved.
  6. RSA Data Security, Inc. makes no representations concerning either
  7. the merchantability of this software or the suitability of this
  8. software for any particular purpose. It is provided "as is"
  9. without express or implied warranty of any kind.
  10. These notices must be retained in any copies of any part of this
  11. documentation and/or software.
  12. */
  13. /*
  14. jku: added support to deal with vectors
  15. */
  16. #define MD 5
  17. #include <stdio.h>
  18. #include <time.h>
  19. #include <string.h>
  20. #include "md5global.h"
  21. #include "md5.h"
  22. #include "md5utils.h"
  23. #include "dprint.h"
  24. #include "ut.h"
  25. /*static void MDString PROTO_LIST ((char *));*/
  26. #define MD_CTX MD5_CTX
  27. #define MDInit MD5Init
  28. #define MDUpdate MD5Update
  29. #define MDFinal MD5Final
  30. /* Digests a string array and store the result in dst; assumes
  31. 32 bytes in dst
  32. */
  33. void MDStringArray (char *dst, str src[], int size)
  34. {
  35. MD_CTX context;
  36. unsigned char digest[16];
  37. int i;
  38. int len;
  39. char *s;
  40. /*
  41. # ifdef EXTRA_DEBUG
  42. int j;
  43. int sum;
  44. #endif
  45. */
  46. MDInit (&context);
  47. for (i=0; i<size; i++) {
  48. trim_len( len, s, src[i] );
  49. /*
  50. # ifdef EXTRA_DEBUG
  51. fprintf(stderr, "EXTRA_DEBUG: %d. (%d) {", i+1, len);
  52. sum=0;
  53. for (j=0; j<len; j++) {
  54. fprintf( stderr, "%c ", *(s+j));
  55. sum+=*(s+j);
  56. }
  57. for (j=0; j<len; j++) {
  58. fprintf( stderr, "%d ", *(s+j));
  59. sum+=*(s+j);
  60. }
  61. fprintf(stderr, " [%d]\n", sum );
  62. # endif
  63. */
  64. MDUpdate (&context, s, len);
  65. }
  66. MDFinal (digest, &context);
  67. string2hex(digest, 16, dst );
  68. DBG("DEBUG: MD5 calculated: %.*s\n", MD5_LEN, dst );
  69. }