summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/regress/lib/libcrypto/evp/evp_test.c133
1 files changed, 132 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/evp/evp_test.c b/src/regress/lib/libcrypto/evp/evp_test.c
index eff071fa51..88eb978ef3 100644
--- a/src/regress/lib/libcrypto/evp/evp_test.c
+++ b/src/regress/lib/libcrypto/evp/evp_test.c
@@ -1,6 +1,7 @@
1/* $OpenBSD: evp_test.c,v 1.7 2023/09/29 06:53:05 tb Exp $ */ 1/* $OpenBSD: evp_test.c,v 1.8 2023/11/27 22:29:51 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
4 * 5 *
5 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
@@ -17,6 +18,7 @@
17 18
18#include <assert.h> 19#include <assert.h>
19#include <stdio.h> 20#include <stdio.h>
21#include <string.h>
20 22
21#include <openssl/evp.h> 23#include <openssl/evp.h>
22#include <openssl/ossl_typ.h> 24#include <openssl/ossl_typ.h>
@@ -404,6 +406,133 @@ evp_pkey_iv_len_test(void)
404 return failure; 406 return failure;
405} 407}
406 408
409struct do_all_arg {
410 const char *previous;
411 int failure;
412};
413
414static void
415evp_do_all_cb_common(const char *descr, const void *ptr, const char *from,
416 const char *to, struct do_all_arg *arg)
417{
418 const char *previous = arg->previous;
419
420 assert(from != NULL);
421 arg->previous = from;
422
423 if (ptr == NULL && to == NULL) {
424 arg->failure |= 1;
425 fprintf(stderr, "FAIL: %s %s: method and alias both NULL\n",
426 descr, from);
427 }
428 if (ptr != NULL && to != NULL) {
429 arg->failure |= 1;
430 fprintf(stderr, "FAIL: %s %s has method and alias \"%s\"\n",
431 descr, from, to);
432 }
433
434 if (previous == NULL)
435 return;
436
437 if (strcmp(previous, from) >= 0) {
438 arg->failure |= 1;
439 fprintf(stderr, "FAIL: %ss %s and %s out of order\n", descr,
440 previous, from);
441 }
442 arg->previous = from;
443}
444
445static void
446evp_cipher_do_all_cb(const EVP_CIPHER *cipher, const char *from, const char *to,
447 void *arg)
448{
449 evp_do_all_cb_common("cipher", cipher, from, to, arg);
450}
451
452static void
453evp_md_do_all_cb(const EVP_MD *md, const char *from, const char *to, void *arg)
454{
455 evp_do_all_cb_common("digest", md, from, to, arg);
456}
457
458static int
459evp_do_all_test(void)
460{
461 struct do_all_arg arg;
462 int failure = 0;
463
464 memset(&arg, 0, sizeof(arg));
465 /* XXX - replace with EVP_CIPHER_do_all() after next bump. */
466 EVP_CIPHER_do_all_sorted(evp_cipher_do_all_cb, &arg);
467 failure |= arg.failure;
468
469 memset(&arg, 0, sizeof(arg));
470 /* XXX - replace with EVP_MD_do_all() after next bump. */
471 EVP_MD_do_all_sorted(evp_md_do_all_cb, &arg);
472 failure |= arg.failure;
473
474 return failure;
475}
476
477static void
478evp_cipher_aliases_cb(const EVP_CIPHER *cipher, const char *from, const char *to,
479 void *arg)
480{
481 struct do_all_arg *do_all = arg;
482 const EVP_CIPHER *from_cipher, *to_cipher;
483
484 if (to == NULL)
485 return;
486
487 from_cipher = EVP_get_cipherbyname(from);
488 to_cipher = EVP_get_cipherbyname(to);
489
490 if (from_cipher != NULL && from_cipher == to_cipher)
491 return;
492
493 fprintf(stderr, "FAIL: cipher mismatch from \"%s\" to \"%s\": "
494 "from: %p, to: %p\n", from, to, from_cipher, to_cipher);
495 do_all->failure |= 1;
496}
497
498static void
499evp_digest_aliases_cb(const EVP_MD *digest, const char *from, const char *to,
500 void *arg)
501{
502 struct do_all_arg *do_all = arg;
503 const EVP_MD *from_digest, *to_digest;
504
505 if (to == NULL)
506 return;
507
508 from_digest = EVP_get_digestbyname(from);
509 to_digest = EVP_get_digestbyname(to);
510
511 if (from_digest != NULL && from_digest == to_digest)
512 return;
513
514 fprintf(stderr, "FAIL: digest mismatch from \"%s\" to \"%s\": "
515 "from: %p, to: %p\n", from, to, from_digest, to_digest);
516 do_all->failure |= 1;
517}
518
519static int
520evp_aliases_test(void)
521{
522 struct do_all_arg arg;
523 int failure = 0;
524
525 memset(&arg, 0, sizeof(arg));
526 EVP_CIPHER_do_all(evp_cipher_aliases_cb, &arg);
527 failure |= arg.failure;
528
529 memset(&arg, 0, sizeof(arg));
530 EVP_MD_do_all(evp_digest_aliases_cb, &arg);
531 failure |= arg.failure;
532
533 return failure;
534}
535
407int 536int
408main(int argc, char **argv) 537main(int argc, char **argv)
409{ 538{
@@ -412,6 +541,8 @@ main(int argc, char **argv)
412 failed |= evp_asn1_method_test(); 541 failed |= evp_asn1_method_test();
413 failed |= evp_pkey_method_test(); 542 failed |= evp_pkey_method_test();
414 failed |= evp_pkey_iv_len_test(); 543 failed |= evp_pkey_iv_len_test();
544 failed |= evp_do_all_test();
545 failed |= evp_aliases_test();
415 546
416 OPENSSL_cleanup(); 547 OPENSSL_cleanup();
417 548