From 0342f06fd8522eaa67c4dc05193b011cb5aed39b Mon Sep 17 00:00:00 2001 From: jsing Date: Wed, 9 Nov 2022 16:13:39 +0000 Subject: [PATCH] Add some regress coverage for EVP_PKEY_ASN1_METHOD --- regress/lib/libcrypto/evp/Makefile | 8 +- regress/lib/libcrypto/evp/evp_test.c | 112 +++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 regress/lib/libcrypto/evp/evp_test.c diff --git a/regress/lib/libcrypto/evp/Makefile b/regress/lib/libcrypto/evp/Makefile index f883584a17c..8c6fa2305bd 100644 --- a/regress/lib/libcrypto/evp/Makefile +++ b/regress/lib/libcrypto/evp/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.7 2022/03/30 08:57:26 tb Exp $ +# $OpenBSD: Makefile,v 1.8 2022/11/09 16:13:39 jsing Exp $ -PROGS= evptest evp_pkey_check evp_pkey_cleanup +PROGS= evptest evp_test evp_pkey_check evp_pkey_cleanup LDADD= -lcrypto DPADD= ${LIBCRYPTO} WARNINGS= Yes @@ -8,12 +8,16 @@ CFLAGS+= -DLIBRESSL_INTERNAL -DLIBRESSL_CRYPTO_INTERNAL -Werror CFLAGS+= -I${.CURDIR}/../../../../lib/libcrypto/evp REGRESS_TARGETS+= regress-evptest +REGRESS_TARGETS+= regress-evp_test REGRESS_TARGETS+= regress-evp_pkey_check REGRESS_TARGETS+= regress-evp_pkey_cleanup regress-evptest: evptest ./evptest ${.CURDIR}/evptests.txt +regress-evp_test: evp_test + ./evp_test + regress-evp_pkey_check: evp_pkey_check ./evp_pkey_check diff --git a/regress/lib/libcrypto/evp/evp_test.c b/regress/lib/libcrypto/evp/evp_test.c new file mode 100644 index 00000000000..bf43d7a5ab4 --- /dev/null +++ b/regress/lib/libcrypto/evp/evp_test.c @@ -0,0 +1,112 @@ +/* $OpenBSD: evp_test.c,v 1.1 2022/11/09 16:13:39 jsing Exp $ */ +/* + * Copyright (c) 2022 Joel Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +#include "evp_locl.h" + +static int +evp_meth_find_test(void) +{ + const EVP_PKEY_ASN1_METHOD *method; + int count, pkey_id, i; + int failed = 1; + + if ((count = EVP_PKEY_asn1_get_count()) < 1) { + fprintf(stderr, "FAIL: failed to get pkey asn1 method count\n"); + goto failure; + } + for (i = 0; i < count; i++) { + if ((method = EVP_PKEY_asn1_get0(i)) == NULL) { + fprintf(stderr, "FAIL: failed to get pkey %d\n", i); + goto failure; + } + } + + if ((method = EVP_PKEY_asn1_find(NULL, EVP_PKEY_RSA)) == NULL) { + fprintf(stderr, "FAIL: failed to find RSA method\n"); + goto failure; + } + if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { + fprintf(stderr, "FAIL: failed to get RSA method info\n"); + goto failure; + } + if (pkey_id != EVP_PKEY_RSA) { + fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", + pkey_id, EVP_PKEY_RSA); + goto failure; + } + + if ((method = EVP_PKEY_asn1_find(NULL, EVP_PKEY_RSA_PSS)) == NULL) { + fprintf(stderr, "FAIL: failed to find RSA-PSS method\n"); + goto failure; + } + if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { + fprintf(stderr, "FAIL: failed to get RSA-PSS method info\n"); + goto failure; + } + if (pkey_id != EVP_PKEY_RSA_PSS) { + fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", + pkey_id, EVP_PKEY_RSA_PSS); + goto failure; + } + + if ((method = EVP_PKEY_asn1_find_str(NULL, "RSA", -1)) == NULL) { + fprintf(stderr, "FAIL: failed to find RSA method by str\n"); + goto failure; + } + if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { + fprintf(stderr, "FAIL: failed to get RSA method info\n"); + goto failure; + } + if (pkey_id != EVP_PKEY_RSA) { + fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", + pkey_id, EVP_PKEY_RSA); + goto failure; + } + + if ((method = EVP_PKEY_asn1_find_str(NULL, "RSA-PSS", -1)) == NULL) { + fprintf(stderr, "FAIL: failed to find RSA-PSS method\n"); + goto failure; + } + if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { + fprintf(stderr, "FAIL: failed to get RSA-PSS method info\n"); + goto failure; + } + if (pkey_id != EVP_PKEY_RSA_PSS) { + fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", + pkey_id, EVP_PKEY_RSA_PSS); + goto failure; + } + + failed = 0; + + failure: + + return failed; +} + +int +main(int argc, char **argv) +{ + int failed = 0; + + failed |= evp_meth_find_test(); + + return failed; +} -- 2.20.1