diff options
author | jsing <> | 2022-11-09 16:13:39 +0000 |
---|---|---|
committer | jsing <> | 2022-11-09 16:13:39 +0000 |
commit | 2bfaf5352df5074d889ade8fdce3f8563de2d5af (patch) | |
tree | 1377f6ee37d19f34e49ae7a3ffc8b8e2c238fed6 | |
parent | 2ea919ef988c51be365c13bd705c0fa9aee3f4b5 (diff) | |
download | openbsd-2bfaf5352df5074d889ade8fdce3f8563de2d5af.tar.gz openbsd-2bfaf5352df5074d889ade8fdce3f8563de2d5af.tar.bz2 openbsd-2bfaf5352df5074d889ade8fdce3f8563de2d5af.zip |
Add some regress coverage for EVP_PKEY_ASN1_METHOD
-rw-r--r-- | src/regress/lib/libcrypto/evp/Makefile | 8 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/evp/evp_test.c | 112 |
2 files changed, 118 insertions, 2 deletions
diff --git a/src/regress/lib/libcrypto/evp/Makefile b/src/regress/lib/libcrypto/evp/Makefile index f883584a17..8c6fa2305b 100644 --- a/src/regress/lib/libcrypto/evp/Makefile +++ b/src/regress/lib/libcrypto/evp/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | # $OpenBSD: Makefile,v 1.7 2022/03/30 08:57:26 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.8 2022/11/09 16:13:39 jsing Exp $ |
2 | 2 | ||
3 | PROGS= evptest evp_pkey_check evp_pkey_cleanup | 3 | PROGS= evptest evp_test evp_pkey_check evp_pkey_cleanup |
4 | LDADD= -lcrypto | 4 | LDADD= -lcrypto |
5 | DPADD= ${LIBCRYPTO} | 5 | DPADD= ${LIBCRYPTO} |
6 | WARNINGS= Yes | 6 | WARNINGS= Yes |
@@ -8,12 +8,16 @@ CFLAGS+= -DLIBRESSL_INTERNAL -DLIBRESSL_CRYPTO_INTERNAL -Werror | |||
8 | CFLAGS+= -I${.CURDIR}/../../../../lib/libcrypto/evp | 8 | CFLAGS+= -I${.CURDIR}/../../../../lib/libcrypto/evp |
9 | 9 | ||
10 | REGRESS_TARGETS+= regress-evptest | 10 | REGRESS_TARGETS+= regress-evptest |
11 | REGRESS_TARGETS+= regress-evp_test | ||
11 | REGRESS_TARGETS+= regress-evp_pkey_check | 12 | REGRESS_TARGETS+= regress-evp_pkey_check |
12 | REGRESS_TARGETS+= regress-evp_pkey_cleanup | 13 | REGRESS_TARGETS+= regress-evp_pkey_cleanup |
13 | 14 | ||
14 | regress-evptest: evptest | 15 | regress-evptest: evptest |
15 | ./evptest ${.CURDIR}/evptests.txt | 16 | ./evptest ${.CURDIR}/evptests.txt |
16 | 17 | ||
18 | regress-evp_test: evp_test | ||
19 | ./evp_test | ||
20 | |||
17 | regress-evp_pkey_check: evp_pkey_check | 21 | regress-evp_pkey_check: evp_pkey_check |
18 | ./evp_pkey_check | 22 | ./evp_pkey_check |
19 | 23 | ||
diff --git a/src/regress/lib/libcrypto/evp/evp_test.c b/src/regress/lib/libcrypto/evp/evp_test.c new file mode 100644 index 0000000000..bf43d7a5ab --- /dev/null +++ b/src/regress/lib/libcrypto/evp/evp_test.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /* $OpenBSD: evp_test.c,v 1.1 2022/11/09 16:13:39 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> | ||
4 | * | ||
5 | * 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 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <openssl/evp.h> | ||
19 | #include <openssl/ossl_typ.h> | ||
20 | |||
21 | #include "evp_locl.h" | ||
22 | |||
23 | static int | ||
24 | evp_meth_find_test(void) | ||
25 | { | ||
26 | const EVP_PKEY_ASN1_METHOD *method; | ||
27 | int count, pkey_id, i; | ||
28 | int failed = 1; | ||
29 | |||
30 | if ((count = EVP_PKEY_asn1_get_count()) < 1) { | ||
31 | fprintf(stderr, "FAIL: failed to get pkey asn1 method count\n"); | ||
32 | goto failure; | ||
33 | } | ||
34 | for (i = 0; i < count; i++) { | ||
35 | if ((method = EVP_PKEY_asn1_get0(i)) == NULL) { | ||
36 | fprintf(stderr, "FAIL: failed to get pkey %d\n", i); | ||
37 | goto failure; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | if ((method = EVP_PKEY_asn1_find(NULL, EVP_PKEY_RSA)) == NULL) { | ||
42 | fprintf(stderr, "FAIL: failed to find RSA method\n"); | ||
43 | goto failure; | ||
44 | } | ||
45 | if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { | ||
46 | fprintf(stderr, "FAIL: failed to get RSA method info\n"); | ||
47 | goto failure; | ||
48 | } | ||
49 | if (pkey_id != EVP_PKEY_RSA) { | ||
50 | fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", | ||
51 | pkey_id, EVP_PKEY_RSA); | ||
52 | goto failure; | ||
53 | } | ||
54 | |||
55 | if ((method = EVP_PKEY_asn1_find(NULL, EVP_PKEY_RSA_PSS)) == NULL) { | ||
56 | fprintf(stderr, "FAIL: failed to find RSA-PSS method\n"); | ||
57 | goto failure; | ||
58 | } | ||
59 | if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { | ||
60 | fprintf(stderr, "FAIL: failed to get RSA-PSS method info\n"); | ||
61 | goto failure; | ||
62 | } | ||
63 | if (pkey_id != EVP_PKEY_RSA_PSS) { | ||
64 | fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", | ||
65 | pkey_id, EVP_PKEY_RSA_PSS); | ||
66 | goto failure; | ||
67 | } | ||
68 | |||
69 | if ((method = EVP_PKEY_asn1_find_str(NULL, "RSA", -1)) == NULL) { | ||
70 | fprintf(stderr, "FAIL: failed to find RSA method by str\n"); | ||
71 | goto failure; | ||
72 | } | ||
73 | if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { | ||
74 | fprintf(stderr, "FAIL: failed to get RSA method info\n"); | ||
75 | goto failure; | ||
76 | } | ||
77 | if (pkey_id != EVP_PKEY_RSA) { | ||
78 | fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", | ||
79 | pkey_id, EVP_PKEY_RSA); | ||
80 | goto failure; | ||
81 | } | ||
82 | |||
83 | if ((method = EVP_PKEY_asn1_find_str(NULL, "RSA-PSS", -1)) == NULL) { | ||
84 | fprintf(stderr, "FAIL: failed to find RSA-PSS method\n"); | ||
85 | goto failure; | ||
86 | } | ||
87 | if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, method)) { | ||
88 | fprintf(stderr, "FAIL: failed to get RSA-PSS method info\n"); | ||
89 | goto failure; | ||
90 | } | ||
91 | if (pkey_id != EVP_PKEY_RSA_PSS) { | ||
92 | fprintf(stderr, "FAIL: method ID mismatch (%d != %d)\n", | ||
93 | pkey_id, EVP_PKEY_RSA_PSS); | ||
94 | goto failure; | ||
95 | } | ||
96 | |||
97 | failed = 0; | ||
98 | |||
99 | failure: | ||
100 | |||
101 | return failed; | ||
102 | } | ||
103 | |||
104 | int | ||
105 | main(int argc, char **argv) | ||
106 | { | ||
107 | int failed = 0; | ||
108 | |||
109 | failed |= evp_meth_find_test(); | ||
110 | |||
111 | return failed; | ||
112 | } | ||