Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 1 | /* |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 2 | * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved. |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <getopt.h> |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 12 | /* Suppress OpenSSL engine deprecation warnings */ |
| 13 | #define OPENSSL_SUPPRESS_DEPRECATED |
| 14 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 15 | #include <openssl/conf.h> |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 16 | #include <openssl/engine.h> |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 17 | #include <openssl/evp.h> |
| 18 | #include <openssl/pem.h> |
| 19 | |
| 20 | #include "cert.h" |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 21 | #include "cmd_opt.h" |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 22 | #include "debug.h" |
| 23 | #include "key.h" |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 24 | #include "sha.h" |
| 25 | |
| 26 | #define MAX_FILENAME_LEN 1024 |
| 27 | |
Pankaj Gupta | dd906e6 | 2020-12-09 14:02:38 +0530 | [diff] [blame] | 28 | key_t *keys; |
| 29 | unsigned int num_keys; |
| 30 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 31 | #if !USING_OPENSSL3 |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 32 | /* |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 33 | * Create a new key container |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 34 | */ |
Masahiro Yamada | bccb109 | 2017-02-06 21:15:01 +0900 | [diff] [blame] | 35 | int key_new(key_t *key) |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 36 | { |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 37 | /* Create key pair container */ |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 38 | key->key = EVP_PKEY_new(); |
| 39 | if (key->key == NULL) { |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 43 | return 1; |
| 44 | } |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 45 | #endif |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 46 | |
Justin Chadwell | febe86c | 2019-07-29 17:13:45 +0100 | [diff] [blame] | 47 | static int key_create_rsa(key_t *key, int key_bits) |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 48 | { |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 49 | #if USING_OPENSSL3 |
Juan Pablo Conde | 7275a5a | 2022-03-02 18:10:08 -0500 | [diff] [blame] | 50 | EVP_PKEY *rsa = EVP_RSA_gen(key_bits); |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 51 | if (rsa == NULL) { |
Michalis Pappas | 3862894 | 2017-10-06 16:11:44 +0800 | [diff] [blame] | 52 | printf("Cannot generate RSA key\n"); |
Juan Pablo Conde | 7275a5a | 2022-03-02 18:10:08 -0500 | [diff] [blame] | 53 | return 0; |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 54 | } |
Juan Pablo Conde | 7275a5a | 2022-03-02 18:10:08 -0500 | [diff] [blame] | 55 | key->key = rsa; |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 56 | return 1; |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 57 | #else |
| 58 | BIGNUM *e; |
| 59 | RSA *rsa = NULL; |
| 60 | |
| 61 | e = BN_new(); |
| 62 | if (e == NULL) { |
| 63 | printf("Cannot create RSA exponent\n"); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | if (!BN_set_word(e, RSA_F4)) { |
| 68 | printf("Cannot assign RSA exponent\n"); |
| 69 | goto err2; |
| 70 | } |
| 71 | |
| 72 | rsa = RSA_new(); |
| 73 | if (rsa == NULL) { |
| 74 | printf("Cannot create RSA key\n"); |
| 75 | goto err2; |
| 76 | } |
| 77 | |
| 78 | if (!RSA_generate_key_ex(rsa, key_bits, e, NULL)) { |
| 79 | printf("Cannot generate RSA key\n"); |
| 80 | goto err; |
| 81 | } |
| 82 | |
| 83 | if (!EVP_PKEY_assign_RSA(key->key, rsa)) { |
| 84 | printf("Cannot assign RSA key\n"); |
| 85 | goto err; |
| 86 | } |
| 87 | |
| 88 | BN_free(e); |
| 89 | return 1; |
| 90 | |
| 91 | err: |
| 92 | RSA_free(rsa); |
| 93 | err2: |
| 94 | BN_free(e); |
| 95 | return 0; |
| 96 | #endif |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | #ifndef OPENSSL_NO_EC |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 100 | #if USING_OPENSSL3 |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 101 | static int key_create_ecdsa(key_t *key, int key_bits, const char *curve) |
| 102 | { |
| 103 | EVP_PKEY *ec = EVP_EC_gen(curve); |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 104 | if (ec == NULL) { |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 105 | printf("Cannot generate EC key\n"); |
Juan Pablo Conde | 7275a5a | 2022-03-02 18:10:08 -0500 | [diff] [blame] | 106 | return 0; |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 107 | } |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 108 | |
Juan Pablo Conde | 7275a5a | 2022-03-02 18:10:08 -0500 | [diff] [blame] | 109 | key->key = ec; |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 110 | return 1; |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static int key_create_ecdsa_nist(key_t *key, int key_bits) |
| 114 | { |
| 115 | return key_create_ecdsa(key, key_bits, "prime256v1"); |
| 116 | } |
| 117 | |
| 118 | static int key_create_ecdsa_brainpool_r(key_t *key, int key_bits) |
| 119 | { |
| 120 | return key_create_ecdsa(key, key_bits, "brainpoolP256r1"); |
| 121 | } |
| 122 | |
| 123 | static int key_create_ecdsa_brainpool_t(key_t *key, int key_bits) |
| 124 | { |
| 125 | return key_create_ecdsa(key, key_bits, "brainpoolP256t1"); |
| 126 | } |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 127 | #else |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 128 | static int key_create_ecdsa(key_t *key, int key_bits, const int curve_id) |
| 129 | { |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 130 | EC_KEY *ec; |
| 131 | |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 132 | ec = EC_KEY_new_by_curve_name(curve_id); |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 133 | if (ec == NULL) { |
| 134 | printf("Cannot create EC key\n"); |
| 135 | return 0; |
| 136 | } |
| 137 | if (!EC_KEY_generate_key(ec)) { |
| 138 | printf("Cannot generate EC key\n"); |
| 139 | goto err; |
| 140 | } |
| 141 | EC_KEY_set_flags(ec, EC_PKEY_NO_PARAMETERS); |
| 142 | EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE); |
| 143 | if (!EVP_PKEY_assign_EC_KEY(key->key, ec)) { |
| 144 | printf("Cannot assign EC key\n"); |
| 145 | goto err; |
| 146 | } |
| 147 | |
| 148 | return 1; |
| 149 | |
| 150 | err: |
| 151 | EC_KEY_free(ec); |
| 152 | return 0; |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static int key_create_ecdsa_nist(key_t *key, int key_bits) |
| 156 | { |
| 157 | return key_create_ecdsa(key, key_bits, NID_X9_62_prime256v1); |
| 158 | } |
| 159 | |
| 160 | static int key_create_ecdsa_brainpool_r(key_t *key, int key_bits) |
| 161 | { |
| 162 | return key_create_ecdsa(key, key_bits, NID_brainpoolP256r1); |
| 163 | } |
| 164 | |
| 165 | static int key_create_ecdsa_brainpool_t(key_t *key, int key_bits) |
| 166 | { |
| 167 | return key_create_ecdsa(key, key_bits, NID_brainpoolP256t1); |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 168 | } |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 169 | #endif /* USING_OPENSSL3 */ |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 170 | #endif /* OPENSSL_NO_EC */ |
| 171 | |
Justin Chadwell | febe86c | 2019-07-29 17:13:45 +0100 | [diff] [blame] | 172 | typedef int (*key_create_fn_t)(key_t *key, int key_bits); |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 173 | static const key_create_fn_t key_create_fn[KEY_ALG_MAX_NUM] = { |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 174 | [KEY_ALG_RSA] = key_create_rsa, |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 175 | #ifndef OPENSSL_NO_EC |
Lionel Debieve | fefeffb | 2022-11-14 11:03:42 +0100 | [diff] [blame] | 176 | [KEY_ALG_ECDSA_NIST] = key_create_ecdsa_nist, |
| 177 | [KEY_ALG_ECDSA_BRAINPOOL_R] = key_create_ecdsa_brainpool_r, |
| 178 | [KEY_ALG_ECDSA_BRAINPOOL_T] = key_create_ecdsa_brainpool_t, |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 179 | #endif /* OPENSSL_NO_EC */ |
| 180 | }; |
| 181 | |
Justin Chadwell | febe86c | 2019-07-29 17:13:45 +0100 | [diff] [blame] | 182 | int key_create(key_t *key, int type, int key_bits) |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 183 | { |
| 184 | if (type >= KEY_ALG_MAX_NUM) { |
| 185 | printf("Invalid key type\n"); |
| 186 | return 0; |
| 187 | } |
| 188 | |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 189 | if (key_create_fn[type]) { |
Justin Chadwell | febe86c | 2019-07-29 17:13:45 +0100 | [diff] [blame] | 190 | return key_create_fn[type](key, key_bits); |
Juan Castillo | a2224ab | 2015-06-30 13:36:57 +0100 | [diff] [blame] | 191 | } |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 192 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 196 | static EVP_PKEY *key_load_pkcs11(const char *uri) |
| 197 | { |
| 198 | char *key_pass; |
| 199 | EVP_PKEY *pkey; |
| 200 | ENGINE *e; |
| 201 | |
| 202 | ENGINE_load_builtin_engines(); |
| 203 | e = ENGINE_by_id("pkcs11"); |
| 204 | if (!e) { |
| 205 | fprintf(stderr, "Cannot Load PKCS#11 ENGINE\n"); |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | if (!ENGINE_init(e)) { |
| 210 | fprintf(stderr, "Cannot ENGINE_init\n"); |
| 211 | goto err; |
| 212 | } |
| 213 | |
| 214 | key_pass = getenv("PKCS11_PIN"); |
| 215 | if (key_pass) { |
| 216 | if (!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0)) { |
| 217 | fprintf(stderr, "Cannot Set PKCS#11 PIN\n"); |
| 218 | goto err; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | pkey = ENGINE_load_private_key(e, uri, NULL, NULL); |
| 223 | if (pkey) |
| 224 | return pkey; |
| 225 | err: |
| 226 | ENGINE_free(e); |
| 227 | return NULL; |
| 228 | |
| 229 | } |
| 230 | |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 231 | int key_load(key_t *key, unsigned int *err_code) |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 232 | { |
Masahiro Yamada | 48cb5e5 | 2017-02-06 19:47:44 +0900 | [diff] [blame] | 233 | FILE *fp; |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 234 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 235 | if (key->fn) { |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 236 | if (!strncmp(key->fn, "pkcs11:", 7)) { |
| 237 | /* Load key through pkcs11 */ |
| 238 | key->key = key_load_pkcs11(key->fn); |
| 239 | } else { |
| 240 | /* Load key from file */ |
| 241 | fp = fopen(key->fn, "r"); |
| 242 | if (fp) { |
| 243 | key->key = PEM_read_PrivateKey(fp, NULL, NULL, NULL); |
| 244 | fclose(fp); |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 245 | } else { |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 246 | WARN("Cannot open file %s\n", key->fn); |
| 247 | *err_code = KEY_ERR_OPEN; |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 248 | } |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 249 | } |
| 250 | if (key->key) { |
| 251 | *err_code = KEY_ERR_NONE; |
| 252 | return 1; |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 253 | } else { |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 254 | ERROR("Cannot load key from %s\n", key->fn); |
| 255 | *err_code = KEY_ERR_LOAD; |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 256 | } |
| 257 | } else { |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 258 | VERBOSE("Key not specified\n"); |
Juan Castillo | f9f39c3 | 2015-06-01 16:34:23 +0100 | [diff] [blame] | 259 | *err_code = KEY_ERR_FILENAME; |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | int key_store(key_t *key) |
| 266 | { |
Masahiro Yamada | 48cb5e5 | 2017-02-06 19:47:44 +0900 | [diff] [blame] | 267 | FILE *fp; |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 268 | |
| 269 | if (key->fn) { |
Robin van der Gracht | 06b5cdb | 2023-09-12 11:16:23 +0200 | [diff] [blame] | 270 | if (!strncmp(key->fn, "pkcs11:", 7)) { |
| 271 | ERROR("PKCS11 URI provided instead of a file"); |
| 272 | return 0; |
| 273 | } |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 274 | fp = fopen(key->fn, "w"); |
| 275 | if (fp) { |
| 276 | PEM_write_PrivateKey(fp, key->key, |
| 277 | NULL, NULL, 0, NULL, NULL); |
| 278 | fclose(fp); |
| 279 | return 1; |
| 280 | } else { |
| 281 | ERROR("Cannot create file %s\n", key->fn); |
| 282 | } |
| 283 | } else { |
| 284 | ERROR("Key filename not specified\n"); |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 289 | |
| 290 | int key_init(void) |
| 291 | { |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 292 | cmd_opt_t cmd_opt; |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 293 | key_t *key; |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 294 | unsigned int i; |
| 295 | |
Pankaj Gupta | dd906e6 | 2020-12-09 14:02:38 +0530 | [diff] [blame] | 296 | keys = malloc((num_def_keys * sizeof(def_keys[0])) |
| 297 | #ifdef PDEF_KEYS |
| 298 | + (num_pdef_keys * sizeof(pdef_keys[0])) |
| 299 | #endif |
| 300 | ); |
| 301 | |
| 302 | if (keys == NULL) { |
| 303 | ERROR("%s:%d Failed to allocate memory.\n", __func__, __LINE__); |
| 304 | return 1; |
| 305 | } |
| 306 | |
| 307 | memcpy(&keys[0], &def_keys[0], (num_def_keys * sizeof(def_keys[0]))); |
| 308 | #ifdef PDEF_KEYS |
| 309 | memcpy(&keys[num_def_keys], &pdef_keys[0], |
| 310 | (num_pdef_keys * sizeof(pdef_keys[0]))); |
| 311 | |
| 312 | num_keys = num_def_keys + num_pdef_keys; |
| 313 | #else |
| 314 | num_keys = num_def_keys; |
| 315 | #endif |
| 316 | ; |
| 317 | |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 318 | for (i = 0; i < num_keys; i++) { |
| 319 | key = &keys[i]; |
| 320 | if (key->opt != NULL) { |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 321 | cmd_opt.long_opt.name = key->opt; |
| 322 | cmd_opt.long_opt.has_arg = required_argument; |
| 323 | cmd_opt.long_opt.flag = NULL; |
| 324 | cmd_opt.long_opt.val = CMD_OPT_KEY; |
| 325 | cmd_opt.help_msg = key->help_msg; |
| 326 | cmd_opt_add(&cmd_opt); |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
Masahiro Yamada | 48cb5e5 | 2017-02-06 19:47:44 +0900 | [diff] [blame] | 330 | return 0; |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | key_t *key_get_by_opt(const char *opt) |
| 334 | { |
Masahiro Yamada | 48cb5e5 | 2017-02-06 19:47:44 +0900 | [diff] [blame] | 335 | key_t *key; |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 336 | unsigned int i; |
| 337 | |
| 338 | /* Sequential search. This is not a performance concern since the number |
| 339 | * of keys is bounded and the code runs on a host machine */ |
| 340 | for (i = 0; i < num_keys; i++) { |
| 341 | key = &keys[i]; |
| 342 | if (0 == strcmp(key->opt, opt)) { |
| 343 | return key; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | return NULL; |
| 348 | } |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 349 | |
| 350 | void key_cleanup(void) |
| 351 | { |
| 352 | unsigned int i; |
| 353 | |
| 354 | for (i = 0; i < num_keys; i++) { |
| 355 | EVP_PKEY_free(keys[i].key); |
| 356 | if (keys[i].fn != NULL) { |
| 357 | void *ptr = keys[i].fn; |
| 358 | |
| 359 | free(ptr); |
| 360 | keys[i].fn = NULL; |
| 361 | } |
| 362 | } |
| 363 | free(keys); |
| 364 | } |
| 365 | |