summaryrefslogtreecommitdiffstats
path: root/src/plugins/unittest/crypto/rfc2202_hmac_md5.c
blob: da6da7e47f4ae2283de1dc7d2b591be3d2fe4931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * Copyright (c) 2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* Test vectors published in RFC2202 */

#include <vppinfra/clib.h>
#include <vnet/crypto/crypto.h>
#include <unittest/crypto/crypto.h>

static u8 md5_tc1_key[16] = {
  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
};

static char md5_tc1_data[8] = "Hi There";

static u8 md5_tc1_digest[] = {
  0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
  0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d
};

/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc1) = {
  .name = "RFC2202 HMAC-MD5 TC1",
  .op = VNET_CRYPTO_OP_MD5_HMAC,
  .key = TEST_DATA (md5_tc1_key),
  .data = TEST_DATA (md5_tc1_data),
  .expected = TEST_DATA (md5_tc1_digest),
};
/* *INDENT-ON* */

static char md5_tc2_key[4] = "Jefe";

static char md5_tc2_data[28] = "what do ya want for nothing?";

static u8 md5_tc2_digest[] = {
  0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
  0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38,
};

/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc2) = {
  .name = "RFC2202 HMAC-MD5 TC2",
  .op = VNET_CRYPTO_OP_MD5_HMAC,
  .key = TEST_DATA (md5_tc2_key),
  .data = TEST_DATA (md5_tc2_data),
  .expected = TEST_DATA (md5_tc2_digest),
};
/* *INDENT-ON* */

static char md5_tc3_key[16] = {
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
};

static char md5_tc3_data[50] = {
  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
  0xdd, 0xdd
};

static u8 md5_tc3_digest[] = {
  0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
  0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6,
};

/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc3) = {
  .name = "RFC2202 HMAC-MD5 TC3",
  .op = VNET_CRYPTO_OP_MD5_HMAC,
  .key = TEST_DATA (md5_tc3_key),
  .data = TEST_DATA (md5_tc3_data),
  .expected = TEST_DATA (md5_tc3_digest),
};
/* *INDENT-ON* */

static u8 md5_tc4_key[25] = {
  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
  0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
  0x19,
};

static u8 md5_tc4_data[50] = {
  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
  0xcd, 0xcd,
};

static u8 md5_tc4_digest[] = {
  0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea,
  0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79,
};

/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc4) = {
  .name = "RFC2202 HMAC-MD5 TC4",
  .op = VNET_CRYPTO_OP_MD5_HMAC,
  .key = TEST_DATA (md5_tc4_key),
  .data = TEST_DATA (md5_tc4_data),
  .expected = TEST_DATA (md5_tc4_digest),
};
/* *INDENT-ON* */

static u8 md5_tc5_key[16] = {
  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
};

static char md5_tc5_data[20] = "Test With Truncation";

static u8 md5_tc5_digest[] = {
  0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00,
  0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c,
};

/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc5) = {
  .name = "RFC2202 HMAC-MD5 TC5",
  .op = VNET_CRYPTO_OP_MD5_HMAC,
  .key = TEST_DATA (md5_tc5_key),
  .data = TEST_DATA (md5_tc5_data),
  .expected = TEST_DATA (md5_tc5_digest),
};
/* *INDENT-ON* */

static u8 md5_tc6_key[80] = {
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
};

static char md5_tc6_data[54] =
  "Test Using Larger Than Block-Size Key - Hash Key First";

static u8 md5_tc6_digest[] = {
  0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f,
  0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd,
};

/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc6) = {
  .name = "RFC2202 HMAC-MD5 TC6",
  .op = VNET_CRYPTO_OP_MD5_HMAC,
  .key = TEST_DATA (md5_tc6_key),
  .data = TEST_DATA (md5_tc6_data),
  .expected = TEST_DATA (md5_tc6_digest),
};
/* *INDENT-ON* */

static char md5_tc7_data[73] =
  "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";

static u8 md5_tc7_digest[] = {
  0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee,
  0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e,
};

/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc7) = {
  .name = "RFC2202 HMAC-MD5 TC7",
  .op = VNET_CRYPTO_OP_MD5_HMAC,
  .key = TEST_DATA (md5_tc6_key),
  .data = TEST_DATA (md5_tc7_data),
  .expected = TEST_DATA (md5_tc7_digest),
};
/* *INDENT-ON* */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */