added HMAC SHA1 test vectors
[strongswan.git] / src / libstrongswan / plugins / test_vectors / test_vectors / sha1_hmac.c
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the Licenseor (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be usefulbut
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <crypto/crypto_tester.h>
17
18 /**
19 * SHA1 hmac test vectors from RFC2202
20 */
21 signer_test_vector_t sha1_hmac_s1 = {
22 .alg = AUTH_HMAC_SHA1_96, .len = 8,
23 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
24 "\x0b\x0b\x0b\x0b",
25 .data = "Hi There",
26 .mac = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6"
27 };
28
29 signer_test_vector_t sha1_hmac_s2 = {
30 .alg = AUTH_HMAC_SHA1_128, .len = 8,
31 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
32 "\x0b\x0b\x0b\x0b",
33 .data = "Hi There",
34 .mac = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e"
35 };
36
37 signer_test_vector_t sha1_hmac_s3 = {
38 .alg = AUTH_HMAC_SHA1_160, .len = 8,
39 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
40 "\x0b\x0b\x0b\x0b",
41 .data = "Hi There",
42 .mac = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e"
43 "\xf1\x46\xbe\x00"
44 };
45
46 prf_test_vector_t sha1_hmac_p1 = {
47 .alg = PRF_HMAC_SHA1, .key_size = 20, .len = 8,
48 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
49 "\x0b\x0b\x0b\x0b",
50 .seed = "Hi There",
51 .out = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e"
52 "\xf1\x46\xbe\x00"
53 };
54
55 prf_test_vector_t sha1_hmac_p2 = {
56 .alg = PRF_HMAC_SHA1, .key_size = 4, .len = 28,
57 .key = "Jefe",
58 .seed = "what do ya want for nothing?",
59 .out = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c"
60 "\x25\x9a\x7c\x79"
61 };
62
63 signer_test_vector_t sha1_hmac_s4 = {
64 .alg = AUTH_HMAC_SHA1_96, .len = 50,
65 .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
66 "\xaa\xaa\xaa\xaa",
67 .data = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
68 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
69 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
70 "\xdd\xdd",
71 .mac = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4"
72 "\x63\xf1\x75\xd3"
73 };
74
75 signer_test_vector_t sha1_hmac_s5 = {
76 .alg = AUTH_HMAC_SHA1_128, .len = 50,
77 .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
78 "\xaa\xaa\xaa\xaa",
79 .data = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
80 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
81 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
82 "\xdd\xdd",
83 .mac = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f"
84 };
85
86 signer_test_vector_t sha1_hmac_s6 = {
87 .alg = AUTH_HMAC_SHA1_160, .len = 50,
88 .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
89 "\xaa\xaa\xaa\xaa",
90 .data = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
91 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
92 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
93 "\xdd\xdd",
94 .mac = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f"
95 "\x63\xf1\x75\xd3"
96 };
97
98 prf_test_vector_t sha1_hmac_p3 = {
99 .alg = PRF_HMAC_SHA1, .key_size = 20, .len = 50,
100 .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
101 "\xaa\xaa\xaa\xaa",
102 .seed = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
103 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
104 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
105 "\xdd\xdd",
106 .out = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f"
107 "\x63\xf1\x75\xd3"
108 };
109
110 prf_test_vector_t sha1_hmac_p4 = {
111 .alg = PRF_HMAC_SHA1, .key_size = 25, .len = 50,
112 .key = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
113 "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
114 .seed = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
115 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
116 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
117 "\xcd\xcd",
118 .out = "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c"
119 "\x2d\x72\x35\xda"
120 };
121
122 prf_test_vector_t sha1_hmac_p5 = {
123 .alg = PRF_HMAC_SHA1, .key_size = 80, .len = 54,
124 .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
125 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
126 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
127 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
128 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
129 .seed = "Test Using Larger Than Block-Size Key - Hash Key First",
130 .out = "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55"
131 "\xed\x40\x21\x12"
132 };
133
134 prf_test_vector_t sha1_hmac_p6 = {
135 .alg = PRF_HMAC_SHA1, .key_size = 80, .len = 73,
136 .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
137 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
138 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
139 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
140 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
141 .seed = "Test Using Larger Than Block-Size Key and Larger "
142 "Than One Block-Size Data",
143 .out = "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08"
144 "\xbb\xff\x1a\x91"
145 };
146