1 /*
2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 /* Internal tests for EVP_PKEY method ordering */
11
12 /*
13 * Because of *asn1_*
14 */
15 #define OPENSSL_SUPPRESS_DEPRECATED
16
17 #include <stdio.h>
18 #include <string.h>
19
20 #include <openssl/evp.h>
21 #include "testutil.h"
22
23 #ifndef OPENSSL_NO_DEPRECATED_3_6
24 /* Test of EVP_PKEY_ASN1_METHOD ordering */
test_asn1_meths(void)25 static int test_asn1_meths(void)
26 {
27 int i;
28 int prev = -1;
29 int good = 1;
30 int pkey_id;
31 const EVP_PKEY_ASN1_METHOD *ameth;
32
33 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
34 ameth = EVP_PKEY_asn1_get0(i);
35 EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
36 if (pkey_id < prev)
37 good = 0;
38 prev = pkey_id;
39
40 }
41 if (!good) {
42 TEST_error("EVP_PKEY_ASN1_METHOD table out of order");
43 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
44 const char *info;
45
46 ameth = EVP_PKEY_asn1_get0(i);
47 EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth);
48 if (info == NULL)
49 info = "<NO NAME>";
50 TEST_note("%d : %s : %s", pkey_id, OBJ_nid2ln(pkey_id), info);
51 }
52 }
53 return good;
54 }
55 #endif
56
57 #ifndef OPENSSL_NO_DEPRECATED_3_0
58 /* Test of EVP_PKEY_METHOD ordering */
test_pkey_meths(void)59 static int test_pkey_meths(void)
60 {
61 size_t i;
62 int prev = -1;
63 int good = 1;
64 int pkey_id;
65 const EVP_PKEY_METHOD *pmeth;
66
67 for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
68 pmeth = EVP_PKEY_meth_get0(i);
69 EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
70 if (pkey_id < prev)
71 good = 0;
72 prev = pkey_id;
73
74 }
75 if (!good) {
76 TEST_error("EVP_PKEY_METHOD table out of order");
77 for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
78 pmeth = EVP_PKEY_meth_get0(i);
79 EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
80 TEST_note("%d : %s", pkey_id, OBJ_nid2ln(pkey_id));
81 }
82 }
83 return good;
84 }
85 #endif
86
setup_tests(void)87 int setup_tests(void)
88 {
89 #ifndef OPENSSL_NO_DEPRECATED_3_6
90 ADD_TEST(test_asn1_meths);
91 #endif
92 #ifndef OPENSSL_NO_DEPRECATED_3_0
93 ADD_TEST(test_pkey_meths);
94 #endif
95 return 1;
96 }
97