add packaging
[platform/upstream/nettle.git] / testsuite / md5-test.c
1 #include "testutils.h"
2 #include "md5.h"
3
4 void
5 test_main(void)
6 {
7   test_hash(&nettle_md5, SDATA(""),
8             SHEX("D41D8CD98F00B204 E9800998ECF8427E"));
9
10   test_hash(&nettle_md5, SDATA("a"),
11             SHEX("0CC175B9C0F1B6A8 31C399E269772661"));
12             
13   test_hash(&nettle_md5, SDATA("abc"),
14             SHEX("900150983cd24fb0 D6963F7D28E17F72"));
15
16   test_hash(&nettle_md5, SDATA("message digest"),
17             SHEX("F96B697D7CB7938D 525A2F31AAF161D0"));
18   
19   test_hash(&nettle_md5, SDATA("abcdefghijklmnopqrstuvwxyz"),
20             SHEX("C3FCD3D76192E400 7DFB496CCA67E13B"));
21   
22   test_hash(&nettle_md5,
23             SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
24                   "abcdefghijklmnopqrstuvwxyz"
25                   "0123456789"),
26             SHEX("D174AB98D277D9F5 A5611C2C9F419D9F"));
27
28   test_hash(&nettle_md5,
29             SDATA("1234567890123456789012345678901234567890"
30                   "1234567890123456789012345678901234567890"),
31             SHEX("57EDF4A22BE3C955 AC49DA2E2107B67A"));
32
33   /* Additional test vector, from Daniel Kahn Gillmor */
34   test_hash(&nettle_md5, SDATA("38"),
35             SHEX("a5771bce93e200c3 6f7cd9dfd0e5deaa"));
36
37   /* Collisions, reported by Xiaoyun Wang1, Dengguo Feng2, Xuejia
38      Lai3, Hongbo Yu1, http://eprint.iacr.org/2004/199. */
39
40 #define M0 \
41   /*                                          vv */                             \
42   "d131dd02 c5e6eec4 693d9a06 98aff95c 2fcab5 87 12467eab 4004583e b8fb7f89"    \
43   "55ad3406 09f4b302 83e48883 25 71 415a 085125e8 f7cdc99f d91dbd f2 80373c5b"  \
44   /*                             ^^                               ^^ */
45
46 #define M1 \
47   /*                                          vv */                             \
48   "d131dd02 c5e6eec4 693d9a06 98aff95c 2fcab5 07 12467eab 4004583e b8fb7f89"    \
49   "55ad3406 09f4b302 83e48883 25 f1 415a 085125e8 f7cdc99f d91dbd 72 80373c5b"  \
50   /*                             ^^                               ^^ */
51
52 #define N0                                                                      \
53   /*                                          vv */                             \
54   "960b1dd1 dc417b9c e4d897f4 5a6555d5 35739a c7 f0ebfd0c 3029f166 d109b18f"    \
55   "75277f79 30d55ceb 22e8adba 79 cc 155c ed74cbdd 5fc5d36d b19b0a d8 35cca7e3"  \
56   /*                             ^^                               ^^ */
57
58 #define N1                                                                      \
59   /*                                          vv */                             \
60   "960b1dd1 dc417b9c e4d897f4 5a6555d5 35739a 47 f0ebfd0c 3029f166 d109b18f"    \
61   "75277f79 30d55ceb 22e8adba 79 4c 155c ed74cbdd 5fc5d36d b19b0a 58 35cca7e3"  \
62   /*                             ^^                               ^^ */
63
64   /* Note: The checksum in the paper, 1f160396 efc71ff4 bcff659f
65      bf9d0fa3, is incorrect. */
66
67 #define H0 "a4c0d35c 95a63a80 5915367d cfe6b751"
68
69 #define N2                                                                      \
70   /*                                          vv */                             \
71   "d8823e31 56348f5b ae6dacd4 36c919c6 dd53e2 b4 87da03fd 02396306 d248cda0"    \
72   "e99f3342 0f577ee8 ce54b670 80 a8 0d1e c69821bc b6a88393 96f965 2b 6ff72a70"  \
73   /*                             ^^                               ^^ */
74
75 #define N3                                                                      \
76   /*                                          vv */                             \
77   "d8823e31 56348f5b ae6dacd4 36c919c6 dd53e2 34 87da03fd 02396306 d248cda0"    \
78   "e99f3342 0f577ee8 ce54b670 80 28 0d1e c69821bc b6a88393 96f965 ab 6ff72a70"  \
79   /*                             ^^                               ^^ */
80
81   /* Note: Also different from the checksum in the paper */
82   
83 #define H1 "79054025 255fb1a2 6e4bc422 aef54eb4"
84   
85   test_hash(&nettle_md5,
86             SHEX(M0 N0), SHEX(H0));
87
88   test_hash(&nettle_md5,
89             SHEX(M1 N1), SHEX(H0));
90
91   test_hash(&nettle_md5,
92             SHEX(M0 N2), SHEX(H1));
93
94   test_hash(&nettle_md5,
95             SHEX(M1 N3), SHEX(H1));
96 }
97
98 /* Intermediate values for the single _nettle_md5_compress call for
99    the first test case. Each row gives the values for a, b, c, d after
100    the i:th round. The row i = -1 gives the initial values, and i = 99
101    gives the output values.
102
103      i         a        b        c        d
104     -1: 67452301 efcdab89 98badcfe 10325476
105      0: a5202774 efcdab89 98badcfe 10325476
106      1: a5202774 efcdab89 98badcfe f59592dd
107     15: f56c7cf1 d6819c6a 5aa53f75 374943a7
108     16: 1c7d7513 d6819c6a 5aa53f75 374943a7
109     17: 1c7d7513 d6819c6a 5aa53f75 7bd57a3a
110     31: 13707036 a2205f1f 1c31c384 ae7813db
111     32: df63eaa1 a2205f1f 1c31c384 ae7813db
112     33: df63eaa1 a2205f1f 1c31c384 c3689f5b
113     47: 3f55edfd ca7d2dbd 68d84ea2 22a31f54
114     48: 93aa2577 ca7d2dbd 68d84ea2 22a31f54
115     49: 93aa2577 ca7d2dbd 68d84ea2 1688dc85
116     63: 7246fad3 14e45506 ff4ea3eb 6e10a476
117     99: d98c1dd4  4b2008f 980980e9 7e42f8ec
118 */