diff options
author | tb <> | 2021-11-18 15:20:02 +0000 |
---|---|---|
committer | tb <> | 2021-11-18 15:20:02 +0000 |
commit | 240cc0c7fdc8ebbb2216dd6769cdf009860ffd22 (patch) | |
tree | 0f8f8b038ee601eb9764193460c33b81f46e48a1 /src/regress/lib | |
parent | 03991a14f44f129f6f8514cada1cb470a5d0f78c (diff) | |
download | openbsd-240cc0c7fdc8ebbb2216dd6769cdf009860ffd22.tar.gz openbsd-240cc0c7fdc8ebbb2216dd6769cdf009860ffd22.tar.bz2 openbsd-240cc0c7fdc8ebbb2216dd6769cdf009860ffd22.zip |
hmactest: convert to opaque HMAC_CTX.
Diffstat (limited to 'src/regress/lib')
-rw-r--r-- | src/regress/lib/libcrypto/hmac/hmactest.c | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/regress/lib/libcrypto/hmac/hmactest.c b/src/regress/lib/libcrypto/hmac/hmactest.c index 1f120da5d9..64ff52cc28 100644 --- a/src/regress/lib/libcrypto/hmac/hmactest.c +++ b/src/regress/lib/libcrypto/hmac/hmactest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: hmactest.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */ | 1 | /* $OpenBSD: hmactest.c,v 1.5 2021/11/18 15:20:02 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -142,7 +142,7 @@ main(int argc, char *argv[]) | |||
142 | char *p; | 142 | char *p; |
143 | #endif | 143 | #endif |
144 | int err = 0; | 144 | int err = 0; |
145 | HMAC_CTX ctx, ctx2; | 145 | HMAC_CTX *ctx = NULL, *ctx2 = NULL; |
146 | unsigned char buf[EVP_MAX_MD_SIZE]; | 146 | unsigned char buf[EVP_MAX_MD_SIZE]; |
147 | unsigned int len; | 147 | unsigned int len; |
148 | 148 | ||
@@ -166,57 +166,60 @@ main(int argc, char *argv[]) | |||
166 | #endif /* OPENSSL_NO_MD5 */ | 166 | #endif /* OPENSSL_NO_MD5 */ |
167 | 167 | ||
168 | /* test4 */ | 168 | /* test4 */ |
169 | HMAC_CTX_init(&ctx); | 169 | if ((ctx = HMAC_CTX_new()) == NULL) { |
170 | if (HMAC_Init_ex(&ctx, NULL, 0, NULL, NULL)) { | 170 | printf("HMAC_CTX_init failed (test 4)\n"); |
171 | exit(1); | ||
172 | } | ||
173 | if (HMAC_Init_ex(ctx, NULL, 0, NULL, NULL)) { | ||
171 | printf("Should fail to initialise HMAC with empty MD and key (test 4)\n"); | 174 | printf("Should fail to initialise HMAC with empty MD and key (test 4)\n"); |
172 | err++; | 175 | err++; |
173 | goto test5; | 176 | goto test5; |
174 | } | 177 | } |
175 | if (HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | 178 | if (HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
176 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); | 179 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); |
177 | err++; | 180 | err++; |
178 | goto test5; | 181 | goto test5; |
179 | } | 182 | } |
180 | if (HMAC_Init_ex(&ctx, NULL, 0, EVP_sha1(), NULL)) { | 183 | if (HMAC_Init_ex(ctx, NULL, 0, EVP_sha1(), NULL)) { |
181 | printf("Should fail to initialise HMAC with empty key (test 4)\n"); | 184 | printf("Should fail to initialise HMAC with empty key (test 4)\n"); |
182 | err++; | 185 | err++; |
183 | goto test5; | 186 | goto test5; |
184 | } | 187 | } |
185 | if (HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | 188 | if (HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
186 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); | 189 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); |
187 | err++; | 190 | err++; |
188 | goto test5; | 191 | goto test5; |
189 | } | 192 | } |
190 | printf("test 4 ok\n"); | 193 | printf("test 4 ok\n"); |
191 | test5: | 194 | test5: |
192 | HMAC_CTX_cleanup(&ctx); | 195 | HMAC_CTX_cleanup(ctx); |
193 | HMAC_CTX_init(&ctx); | 196 | HMAC_CTX_init(ctx); |
194 | if (HMAC_Init_ex(&ctx, test[4].key, test[4].key_len, NULL, NULL)) { | 197 | if (HMAC_Init_ex(ctx, test[4].key, test[4].key_len, NULL, NULL)) { |
195 | printf("Should fail to initialise HMAC with empty MD (test 5)\n"); | 198 | printf("Should fail to initialise HMAC with empty MD (test 5)\n"); |
196 | err++; | 199 | err++; |
197 | goto test6; | 200 | goto test6; |
198 | } | 201 | } |
199 | if (HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | 202 | if (HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
200 | printf("Should fail HMAC_Update with ctx not set up (test 5)\n"); | 203 | printf("Should fail HMAC_Update with ctx not set up (test 5)\n"); |
201 | err++; | 204 | err++; |
202 | goto test6; | 205 | goto test6; |
203 | } | 206 | } |
204 | if (HMAC_Init_ex(&ctx, test[4].key, -1, EVP_sha1(), NULL)) { | 207 | if (HMAC_Init_ex(ctx, test[4].key, -1, EVP_sha1(), NULL)) { |
205 | printf("Should fail to initialise HMAC with invalid key len(test 5)\n"); | 208 | printf("Should fail to initialise HMAC with invalid key len(test 5)\n"); |
206 | err++; | 209 | err++; |
207 | goto test6; | 210 | goto test6; |
208 | } | 211 | } |
209 | if (!HMAC_Init_ex(&ctx, test[4].key, test[4].key_len, EVP_sha1(), NULL)) { | 212 | if (!HMAC_Init_ex(ctx, test[4].key, test[4].key_len, EVP_sha1(), NULL)) { |
210 | printf("Failed to initialise HMAC (test 5)\n"); | 213 | printf("Failed to initialise HMAC (test 5)\n"); |
211 | err++; | 214 | err++; |
212 | goto test6; | 215 | goto test6; |
213 | } | 216 | } |
214 | if (!HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | 217 | if (!HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
215 | printf("Error updating HMAC with data (test 5)\n"); | 218 | printf("Error updating HMAC with data (test 5)\n"); |
216 | err++; | 219 | err++; |
217 | goto test6; | 220 | goto test6; |
218 | } | 221 | } |
219 | if (!HMAC_Final(&ctx, buf, &len)) { | 222 | if (!HMAC_Final(ctx, buf, &len)) { |
220 | printf("Error finalising data (test 5)\n"); | 223 | printf("Error finalising data (test 5)\n"); |
221 | err++; | 224 | err++; |
222 | goto test6; | 225 | goto test6; |
@@ -228,22 +231,22 @@ main(int argc, char *argv[]) | |||
228 | err++; | 231 | err++; |
229 | goto test6; | 232 | goto test6; |
230 | } | 233 | } |
231 | if (HMAC_Init_ex(&ctx, NULL, 0, EVP_sha256(), NULL)) { | 234 | if (HMAC_Init_ex(ctx, NULL, 0, EVP_sha256(), NULL)) { |
232 | printf("Should disallow changing MD without a new key (test 5)\n"); | 235 | printf("Should disallow changing MD without a new key (test 5)\n"); |
233 | err++; | 236 | err++; |
234 | goto test6; | 237 | goto test6; |
235 | } | 238 | } |
236 | if (!HMAC_Init_ex(&ctx, test[4].key, test[4].key_len, EVP_sha256(), NULL)) { | 239 | if (!HMAC_Init_ex(ctx, test[4].key, test[4].key_len, EVP_sha256(), NULL)) { |
237 | printf("Failed to reinitialise HMAC (test 5)\n"); | 240 | printf("Failed to reinitialise HMAC (test 5)\n"); |
238 | err++; | 241 | err++; |
239 | goto test6; | 242 | goto test6; |
240 | } | 243 | } |
241 | if (!HMAC_Update(&ctx, test[5].data, test[5].data_len)) { | 244 | if (!HMAC_Update(ctx, test[5].data, test[5].data_len)) { |
242 | printf("Error updating HMAC with data (sha256) (test 5)\n"); | 245 | printf("Error updating HMAC with data (sha256) (test 5)\n"); |
243 | err++; | 246 | err++; |
244 | goto test6; | 247 | goto test6; |
245 | } | 248 | } |
246 | if (!HMAC_Final(&ctx, buf, &len)) { | 249 | if (!HMAC_Final(ctx, buf, &len)) { |
247 | printf("Error finalising data (sha256) (test 5)\n"); | 250 | printf("Error finalising data (sha256) (test 5)\n"); |
248 | err++; | 251 | err++; |
249 | goto test6; | 252 | goto test6; |
@@ -255,17 +258,17 @@ main(int argc, char *argv[]) | |||
255 | err++; | 258 | err++; |
256 | goto test6; | 259 | goto test6; |
257 | } | 260 | } |
258 | if (!HMAC_Init_ex(&ctx, test[6].key, test[6].key_len, NULL, NULL)) { | 261 | if (!HMAC_Init_ex(ctx, test[6].key, test[6].key_len, NULL, NULL)) { |
259 | printf("Failed to reinitialise HMAC with key (test 5)\n"); | 262 | printf("Failed to reinitialise HMAC with key (test 5)\n"); |
260 | err++; | 263 | err++; |
261 | goto test6; | 264 | goto test6; |
262 | } | 265 | } |
263 | if (!HMAC_Update(&ctx, test[6].data, test[6].data_len)) { | 266 | if (!HMAC_Update(ctx, test[6].data, test[6].data_len)) { |
264 | printf("Error updating HMAC with data (new key) (test 5)\n"); | 267 | printf("Error updating HMAC with data (new key) (test 5)\n"); |
265 | err++; | 268 | err++; |
266 | goto test6; | 269 | goto test6; |
267 | } | 270 | } |
268 | if (!HMAC_Final(&ctx, buf, &len)) { | 271 | if (!HMAC_Final(ctx, buf, &len)) { |
269 | printf("Error finalising data (new key) (test 5)\n"); | 272 | printf("Error finalising data (new key) (test 5)\n"); |
270 | err++; | 273 | err++; |
271 | goto test6; | 274 | goto test6; |
@@ -279,24 +282,28 @@ main(int argc, char *argv[]) | |||
279 | printf("test 5 ok\n"); | 282 | printf("test 5 ok\n"); |
280 | } | 283 | } |
281 | test6: | 284 | test6: |
282 | HMAC_CTX_cleanup(&ctx); | 285 | HMAC_CTX_cleanup(ctx); |
283 | HMAC_CTX_init(&ctx); | 286 | HMAC_CTX_init(ctx); |
284 | if (!HMAC_Init_ex(&ctx, test[7].key, test[7].key_len, EVP_sha1(), NULL)) { | 287 | if (!HMAC_Init_ex(ctx, test[7].key, test[7].key_len, EVP_sha1(), NULL)) { |
285 | printf("Failed to initialise HMAC (test 6)\n"); | 288 | printf("Failed to initialise HMAC (test 6)\n"); |
286 | err++; | 289 | err++; |
287 | goto end; | 290 | goto end; |
288 | } | 291 | } |
289 | if (!HMAC_Update(&ctx, test[7].data, test[7].data_len)) { | 292 | if (!HMAC_Update(ctx, test[7].data, test[7].data_len)) { |
290 | printf("Error updating HMAC with data (test 6)\n"); | 293 | printf("Error updating HMAC with data (test 6)\n"); |
291 | err++; | 294 | err++; |
292 | goto end; | 295 | goto end; |
293 | } | 296 | } |
294 | if (!HMAC_CTX_copy(&ctx2, &ctx)) { | 297 | if ((ctx2 = HMAC_CTX_new()) == NULL) { |
298 | printf("HMAC_CTX_new failed (test 6)\n"); | ||
299 | exit(1); | ||
300 | } | ||
301 | if (!HMAC_CTX_copy(ctx2, ctx)) { | ||
295 | printf("Failed to copy HMAC_CTX (test 6)\n"); | 302 | printf("Failed to copy HMAC_CTX (test 6)\n"); |
296 | err++; | 303 | err++; |
297 | goto end; | 304 | goto end; |
298 | } | 305 | } |
299 | if (!HMAC_Final(&ctx2, buf, &len)) { | 306 | if (!HMAC_Final(ctx2, buf, &len)) { |
300 | printf("Error finalising data (test 6)\n"); | 307 | printf("Error finalising data (test 6)\n"); |
301 | err++; | 308 | err++; |
302 | goto end; | 309 | goto end; |
@@ -310,7 +317,8 @@ main(int argc, char *argv[]) | |||
310 | printf("test 6 ok\n"); | 317 | printf("test 6 ok\n"); |
311 | } | 318 | } |
312 | end: | 319 | end: |
313 | HMAC_CTX_cleanup(&ctx); | 320 | HMAC_CTX_free(ctx); |
321 | HMAC_CTX_free(ctx2); | ||
314 | exit(err); | 322 | exit(err); |
315 | return(0); | 323 | return(0); |
316 | } | 324 | } |