diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/evp/evp_test.c | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/src/regress/lib/libcrypto/evp/evp_test.c b/src/regress/lib/libcrypto/evp/evp_test.c index 9b6e18eec6..b1f7d59c2a 100644 --- a/src/regress/lib/libcrypto/evp/evp_test.c +++ b/src/regress/lib/libcrypto/evp/evp_test.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: evp_test.c,v 1.9 2023/11/27 22:39:26 tb Exp $ */ | 1 | /* $OpenBSD: evp_test.c,v 1.10 2023/12/08 08:30:04 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 | * Copyright (c) 2023 Theo Buehler <tb@openbsd.org> |
| @@ -439,7 +439,6 @@ evp_do_all_cb_common(const char *descr, const void *ptr, const char *from, | |||
| 439 | fprintf(stderr, "FAIL: %ss %s and %s out of order\n", descr, | 439 | fprintf(stderr, "FAIL: %ss %s and %s out of order\n", descr, |
| 440 | previous, from); | 440 | previous, from); |
| 441 | } | 441 | } |
| 442 | arg->previous = from; | ||
| 443 | } | 442 | } |
| 444 | 443 | ||
| 445 | static void | 444 | static void |
| @@ -533,6 +532,103 @@ evp_aliases_test(void) | |||
| 533 | return failure; | 532 | return failure; |
| 534 | } | 533 | } |
| 535 | 534 | ||
| 535 | static void | ||
| 536 | obj_name_cb(const OBJ_NAME *obj_name, void *do_all_arg) | ||
| 537 | { | ||
| 538 | struct do_all_arg *arg = do_all_arg; | ||
| 539 | struct do_all_arg arg_copy = *arg; | ||
| 540 | const char *previous = arg->previous; | ||
| 541 | const char *descr = "OBJ_NAME unknown"; | ||
| 542 | |||
| 543 | assert(obj_name->name != NULL); | ||
| 544 | arg->previous = obj_name->name; | ||
| 545 | |||
| 546 | if (obj_name->type == OBJ_NAME_TYPE_CIPHER_METH) { | ||
| 547 | descr = "OBJ_NAME cipher"; | ||
| 548 | |||
| 549 | if (obj_name->alias == 0) { | ||
| 550 | const EVP_CIPHER *cipher; | ||
| 551 | |||
| 552 | if ((cipher = EVP_get_cipherbyname(obj_name->name)) != | ||
| 553 | (const EVP_CIPHER *)obj_name->data) { | ||
| 554 | arg->failure |= 1; | ||
| 555 | fprintf(stderr, "FAIL: %s by name %p != %p\n", | ||
| 556 | descr, cipher, obj_name->data); | ||
| 557 | } | ||
| 558 | |||
| 559 | evp_do_all_cb_common(descr, obj_name->data, | ||
| 560 | obj_name->name, NULL, &arg_copy); | ||
| 561 | } else if (obj_name->alias == OBJ_NAME_ALIAS) { | ||
| 562 | evp_cipher_aliases_cb(NULL, obj_name->name, | ||
| 563 | obj_name->data, &arg_copy); | ||
| 564 | } else { | ||
| 565 | fprintf(stderr, "FAIL %s %s: unexpected alias value %d\n", | ||
| 566 | descr, obj_name->name, obj_name->alias); | ||
| 567 | arg->failure |= 1; | ||
| 568 | } | ||
| 569 | } else if (obj_name->type == OBJ_NAME_TYPE_MD_METH) { | ||
| 570 | descr = "OBJ_NAME digest"; | ||
| 571 | |||
| 572 | if (obj_name->alias == 0) { | ||
| 573 | const EVP_MD *evp_md; | ||
| 574 | |||
| 575 | if ((evp_md = EVP_get_digestbyname(obj_name->name)) != | ||
| 576 | (const EVP_MD *)obj_name->data) { | ||
| 577 | arg->failure |= 1; | ||
| 578 | fprintf(stderr, "FAIL: %s by name %p != %p\n", | ||
| 579 | descr, evp_md, obj_name->data); | ||
| 580 | } | ||
| 581 | |||
| 582 | evp_do_all_cb_common(descr, obj_name->data, | ||
| 583 | obj_name->name, NULL, &arg_copy); | ||
| 584 | } else if (obj_name->alias == OBJ_NAME_ALIAS) { | ||
| 585 | evp_digest_aliases_cb(NULL, obj_name->name, | ||
| 586 | obj_name->data, &arg_copy); | ||
| 587 | } else { | ||
| 588 | fprintf(stderr, "FAIL: %s %s: unexpected alias value %d\n", | ||
| 589 | descr, obj_name->name, obj_name->alias); | ||
| 590 | arg->failure |= 1; | ||
| 591 | } | ||
| 592 | } else { | ||
| 593 | fprintf(stderr, "FAIL: unexpected OBJ_NAME type %d\n", | ||
| 594 | obj_name->type); | ||
| 595 | arg->failure |= 1; | ||
| 596 | } | ||
| 597 | |||
| 598 | if (previous != NULL && strcmp(previous, obj_name->name) >= 0) { | ||
| 599 | arg->failure |= 1; | ||
| 600 | fprintf(stderr, "FAIL: %ss %s and %s out of order\n", descr, | ||
| 601 | previous, obj_name->name); | ||
| 602 | } | ||
| 603 | |||
| 604 | |||
| 605 | arg->failure |= arg_copy.failure; | ||
| 606 | } | ||
| 607 | |||
| 608 | static int | ||
| 609 | obj_name_do_all_test(void) | ||
| 610 | { | ||
| 611 | struct do_all_arg arg; | ||
| 612 | int failure = 0; | ||
| 613 | |||
| 614 | memset(&arg, 0, sizeof(arg)); | ||
| 615 | /* XXX - replace with OBJ_NAME_do_all() after next bump. */ | ||
| 616 | OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, obj_name_cb, &arg); | ||
| 617 | failure |= arg.failure; | ||
| 618 | |||
| 619 | memset(&arg, 0, sizeof(arg)); | ||
| 620 | /* XXX - replace with OBJ_NAME_do_all() after next bump. */ | ||
| 621 | OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, obj_name_cb, &arg); | ||
| 622 | failure |= arg.failure; | ||
| 623 | |||
| 624 | memset(&arg, 0, sizeof(arg)); | ||
| 625 | /* XXX - replace with OBJ_NAME_do_all() after next bump. */ | ||
| 626 | OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_PKEY_METH, obj_name_cb, &arg); | ||
| 627 | failure |= arg.failure; | ||
| 628 | |||
| 629 | return failure; | ||
| 630 | } | ||
| 631 | |||
| 536 | int | 632 | int |
| 537 | main(int argc, char **argv) | 633 | main(int argc, char **argv) |
| 538 | { | 634 | { |
| @@ -543,6 +639,7 @@ main(int argc, char **argv) | |||
| 543 | failed |= evp_pkey_iv_len_test(); | 639 | failed |= evp_pkey_iv_len_test(); |
| 544 | failed |= evp_do_all_test(); | 640 | failed |= evp_do_all_test(); |
| 545 | failed |= evp_aliases_test(); | 641 | failed |= evp_aliases_test(); |
| 642 | failed |= obj_name_do_all_test(); | ||
| 546 | 643 | ||
| 547 | OPENSSL_cleanup(); | 644 | OPENSSL_cleanup(); |
| 548 | 645 | ||
