FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
rfc2202_hmac_md5.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /* Test vectors published in RFC2202 */
17 
18 #include <vppinfra/clib.h>
19 #include <vnet/crypto/crypto.h>
20 #include <unittest/crypto/crypto.h>
21 
22 static u8 md5_tc1_key[16] = {
23  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
24  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
25 };
26 
27 static char md5_tc1_data[8] = "Hi There";
28 
29 static u8 md5_tc1_digest[] = {
30  0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
31  0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d
32 };
33 
34 /* *INDENT-OFF* */
35 UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc1) = {
36  .name = "RFC2202 HMAC-MD5 TC1",
37  .alg = VNET_CRYPTO_ALG_HMAC_MD5,
38  .key = TEST_DATA (md5_tc1_key),
39  .plaintext = TEST_DATA (md5_tc1_data),
40  .digest = TEST_DATA (md5_tc1_digest),
41 };
42 /* *INDENT-ON* */
43 
44 static char md5_tc2_key[4] = "Jefe";
45 
46 static char md5_tc2_data[28] = "what do ya want for nothing?";
47 
48 static u8 md5_tc2_digest[] = {
49  0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
50  0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38,
51 };
52 
53 /* *INDENT-OFF* */
54 UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc2) = {
55  .name = "RFC2202 HMAC-MD5 TC2",
56  .alg = VNET_CRYPTO_ALG_HMAC_MD5,
57  .key = TEST_DATA (md5_tc2_key),
58  .plaintext = TEST_DATA (md5_tc2_data),
59  .digest = TEST_DATA (md5_tc2_digest),
60 };
61 /* *INDENT-ON* */
62 
63 static char md5_tc3_key[16] = {
64  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
65  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
66 };
67 
68 static char md5_tc3_data[50] = {
69  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
70  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
71  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
72  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
73  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
74  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
75  0xdd, 0xdd
76 };
77 
78 static u8 md5_tc3_digest[] = {
79  0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
80  0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6,
81 };
82 
83 /* *INDENT-OFF* */
84 UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc3) = {
85  .name = "RFC2202 HMAC-MD5 TC3",
86  .alg = VNET_CRYPTO_ALG_HMAC_MD5,
87  .key = TEST_DATA (md5_tc3_key),
88  .plaintext = TEST_DATA (md5_tc3_data),
89  .digest = TEST_DATA (md5_tc3_digest),
90 };
91 /* *INDENT-ON* */
92 
93 static u8 md5_tc4_key[25] = {
94  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
95  0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
96  0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
97  0x19,
98 };
99 
100 static u8 md5_tc4_data[50] = {
101  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
102  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
103  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
104  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
105  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
106  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
107  0xcd, 0xcd,
108 };
109 
110 static u8 md5_tc4_digest[] = {
111  0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea,
112  0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79,
113 };
114 
115 /* *INDENT-OFF* */
116 UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc4) = {
117  .name = "RFC2202 HMAC-MD5 TC4",
118  .alg = VNET_CRYPTO_ALG_HMAC_MD5,
119  .key = TEST_DATA (md5_tc4_key),
120  .plaintext = TEST_DATA (md5_tc4_data),
121  .digest = TEST_DATA (md5_tc4_digest),
122 };
123 /* *INDENT-ON* */
124 
125 static u8 md5_tc5_key[16] = {
126  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
127  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
128 };
129 
130 static char md5_tc5_data[20] = "Test With Truncation";
131 
132 static u8 md5_tc5_digest[] = {
133  0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00,
134  0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c,
135 };
136 
137 /* *INDENT-OFF* */
138 UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc5) = {
139  .name = "RFC2202 HMAC-MD5 TC5",
140  .alg = VNET_CRYPTO_ALG_HMAC_MD5,
141  .key = TEST_DATA (md5_tc5_key),
142  .plaintext = TEST_DATA (md5_tc5_data),
143  .digest = TEST_DATA (md5_tc5_digest),
144 };
145 /* *INDENT-ON* */
146 
147 static u8 md5_tc6_key[80] = {
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,
154  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
155  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
156  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
157  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
158 };
159 
160 static char md5_tc6_data[54] =
161  "Test Using Larger Than Block-Size Key - Hash Key First";
162 
163 static u8 md5_tc6_digest[] = {
164  0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f,
165  0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd,
166 };
167 
168 /* *INDENT-OFF* */
169 UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc6) = {
170  .name = "RFC2202 HMAC-MD5 TC6",
171  .alg = VNET_CRYPTO_ALG_HMAC_MD5,
172  .key = TEST_DATA (md5_tc6_key),
173  .plaintext = TEST_DATA (md5_tc6_data),
174  .digest = TEST_DATA (md5_tc6_digest),
175 };
176 /* *INDENT-ON* */
177 
178 static char md5_tc7_data[73] =
179  "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
180 
181 static u8 md5_tc7_digest[] = {
182  0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee,
183  0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e,
184 };
185 
186 /* *INDENT-OFF* */
187 UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc7) = {
188  .name = "RFC2202 HMAC-MD5 TC7",
189  .alg = VNET_CRYPTO_ALG_HMAC_MD5,
190  .key = TEST_DATA (md5_tc6_key),
191  .plaintext = TEST_DATA (md5_tc7_data),
192  .digest = TEST_DATA (md5_tc7_digest),
193 };
194 /* *INDENT-ON* */
195 
196 /*
197  * fd.io coding-style-patch-verification: ON
198  *
199  * Local Variables:
200  * eval: (c-set-style "gnu")
201  * End:
202  */
static char md5_tc7_data[73]
static u8 md5_tc4_digest[]
static u8 md5_tc1_digest[]
static char md5_tc3_key[16]
static char md5_tc2_data[28]
unsigned char u8
Definition: types.h:56
static u8 md5_tc5_digest[]
static u8 md5_tc4_data[50]
UNITTEST_REGISTER_CRYPTO_TEST(rfc_2202_md5_tc1)
static u8 md5_tc5_key[16]
static u8 md5_tc4_key[25]
static char md5_tc5_data[20]
static char md5_tc1_data[8]
static u8 md5_tc3_digest[]
static u8 md5_tc6_key[80]
#define TEST_DATA(n)
Definition: crypto.h:46
static u8 md5_tc2_digest[]
static u8 md5_tc6_digest[]
static u8 md5_tc1_key[16]
static char md5_tc6_data[54]
static char md5_tc3_data[50]
static u8 md5_tc7_digest[]
static char md5_tc2_key[4]