4a36dcb9c128e4bb663ba2ae2cf6367012de71e2
4 * @brief Tests the hmac class
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #include "hmac_test.h"
27 #include "../transforms/hmac.h"
28 #include "../utils/allocator.h"
32 * described in Header-File
34 void test_hmac_sha1(tester_t
*tester
)
37 * Test cases from RFC2202
40 * key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
44 * digest = 0xb617318655057264e28bc0b6fb378c8ef146be00
49 * data = "what do ya want for nothing?"
51 * digest = 0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79
54 * key = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
56 * data = 0xdd repeated 50 times
58 * digest = 0x125d7342b9ac11cd91a39af48aa17b4f63f175d3
61 * key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819
63 * data = 0xcd repeated 50 times
65 * digest = 0x4c9007f4026250c6bc8414f9bf50c86c2d7235da
68 * key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
70 * data = "Test With Truncation"
72 * digest = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04
73 * digest-96 = 0x4c1a03424b55e07fe7f27be1
76 * key = 0xaa repeated 80 times
78 * data = "Test Using Larger Than Block-Size Key - Hash Key First"
80 * digest = 0xaa4ae5e15272d00e95705637ce8a3b55ed402112
83 * key = 0xaa repeated 80 times
85 * data = "Test Using Larger Than Block-Size Key and Larger
86 * Than One Block-Size Data"
88 * digest = 0xe8e99d0f45237d786d6bbaa7965c7808bbff1a91
90 * currently performing test 1, 2 and 7
110 keys
[0].len
= sizeof(key1
);
111 data
[0].ptr
= "Hi There";
113 u_int8_t reference1
[] = {
120 reference
[0].ptr
= reference1
;
121 reference
[0].len
= sizeof(reference1
);
126 u_int8_t reference2
[] = {
133 keys
[1].ptr
= "Jefe";
135 data
[1].ptr
= "what do ya want for nothing?";
137 reference
[1].ptr
= reference2
;
138 reference
[1].len
= sizeof(reference2
);
144 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
145 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
146 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
147 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
148 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
149 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
150 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
151 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
152 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
153 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
155 u_int8_t reference7
[] = {
163 keys
[2].len
= sizeof(key7
);
164 data
[2].ptr
= "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
166 reference
[2].ptr
= reference7
;
167 reference
[2].len
= sizeof(reference7
);
172 hmac_t
*hmac
= hmac_create(HASH_SHA1
, keys
[i
]);
173 hmac
->allocate_mac(hmac
, data
[i
], &digest
[i
]);
176 tester
->assert_true(tester
, digest
[i
].len
== 20, "chunk len");
177 tester
->assert_false(tester
, memcmp(digest
[i
].ptr
, reference
[i
].ptr
, 20), "hmac value");
178 allocator_free(digest
[i
].ptr
);