test-md4.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Test program for MD4 (test vectors from RFC 1320)
  3. * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "crypto/crypto.h"
  11. int main(int argc, char *argv[])
  12. {
  13. struct {
  14. char *data;
  15. char *hash;
  16. } tests[] = {
  17. {
  18. "",
  19. "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31"
  20. "\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0"
  21. },
  22. {
  23. "a",
  24. "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46"
  25. "\x24\x5e\x05\xfb\xdb\xd6\xfb\x24"
  26. },
  27. {
  28. "abc",
  29. "\xa4\x48\x01\x7a\xaf\x21\xd8\x52"
  30. "\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"
  31. },
  32. {
  33. "message digest",
  34. "\xd9\x13\x0a\x81\x64\x54\x9f\xe8"
  35. "\x18\x87\x48\x06\xe1\xc7\x01\x4b"
  36. },
  37. {
  38. "abcdefghijklmnopqrstuvwxyz",
  39. "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd"
  40. "\xee\xa8\xed\x63\xdf\x41\x2d\xa9"
  41. },
  42. {
  43. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  44. "0123456789",
  45. "\x04\x3f\x85\x82\xf2\x41\xdb\x35"
  46. "\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4"
  47. },
  48. {
  49. "12345678901234567890123456789012345678901234567890"
  50. "123456789012345678901234567890",
  51. "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19"
  52. "\x9c\x3e\x7b\x16\x4f\xcc\x05\x36"
  53. }
  54. };
  55. unsigned int i;
  56. u8 hash[16];
  57. const u8 *addr[2];
  58. size_t len[2];
  59. int errors = 0;
  60. for (i = 0; i < ARRAY_SIZE(tests); i++) {
  61. printf("MD4 test case %d:", i);
  62. addr[0] = (u8 *) tests[i].data;
  63. len[0] = strlen(tests[i].data);
  64. md4_vector(1, addr, len, hash);
  65. if (memcmp(hash, tests[i].hash, 16) != 0) {
  66. printf(" FAIL");
  67. errors++;
  68. } else
  69. printf(" OK");
  70. if (len[0]) {
  71. addr[0] = (u8 *) tests[i].data;
  72. len[0] = strlen(tests[i].data);
  73. addr[1] = (u8 *) tests[i].data + 1;
  74. len[1] = strlen(tests[i].data) - 1;
  75. md4_vector(1, addr, len, hash);
  76. if (memcmp(hash, tests[i].hash, 16) != 0) {
  77. printf(" FAIL");
  78. errors++;
  79. } else
  80. printf(" OK");
  81. }
  82. printf("\n");
  83. }
  84. return errors;
  85. }