Add cert_create tool support for RSA key sizes
[project/bcm63xx/atf.git] / tools / cert_create / include / key.h
1 /*
2 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef KEY_H
8 #define KEY_H
9
10 #include <openssl/ossl_typ.h>
11
12 /* Error codes */
13 enum {
14 KEY_ERR_NONE,
15 KEY_ERR_MALLOC,
16 KEY_ERR_FILENAME,
17 KEY_ERR_OPEN,
18 KEY_ERR_LOAD
19 };
20
21 /* Supported key algorithms */
22 enum {
23 KEY_ALG_RSA, /* RSA PSS as defined by PKCS#1 v2.1 (default) */
24 KEY_ALG_RSA_1_5, /* RSA as defined by PKCS#1 v1.5 */
25 #ifndef OPENSSL_NO_EC
26 KEY_ALG_ECDSA,
27 #endif /* OPENSSL_NO_EC */
28 KEY_ALG_MAX_NUM
29 };
30
31 /* Maximum number of valid key sizes per algorithm */
32 #define KEY_SIZE_MAX_NUM 4
33
34 /* Supported hash algorithms */
35 enum{
36 HASH_ALG_SHA256,
37 HASH_ALG_SHA384,
38 HASH_ALG_SHA512,
39 };
40
41 /* Supported key sizes */
42 /* NOTE: the first item in each array is the default key size */
43 static const unsigned int KEY_SIZES[KEY_ALG_MAX_NUM][KEY_SIZE_MAX_NUM] = {
44 { 2048, 1024, 3072, 4096 }, /* KEY_ALG_RSA */
45 { 2048, 1024, 3072, 4096 }, /* KEY_ALG_RSA_1_5 */
46 #ifndef OPENSSL_NO_EC
47 {} /* KEY_ALG_ECDSA */
48 #endif /* OPENSSL_NO_EC */
49 };
50
51 /*
52 * This structure contains the relevant information to create the keys
53 * required to sign the certificates.
54 *
55 * One instance of this structure must be created for each key, usually in an
56 * array fashion. The filename is obtained at run time from the command line
57 * parameters
58 */
59 typedef struct key_s {
60 int id; /* Key id */
61 const char *opt; /* Command line option to specify a key */
62 const char *help_msg; /* Help message */
63 const char *desc; /* Key description (debug purposes) */
64 char *fn; /* Filename to load/store the key */
65 EVP_PKEY *key; /* Key container */
66 } key_t;
67
68 /* Exported API */
69 int key_init(void);
70 key_t *key_get_by_opt(const char *opt);
71 int key_new(key_t *key);
72 int key_create(key_t *key, int type, int key_bits);
73 int key_load(key_t *key, unsigned int *err_code);
74 int key_store(key_t *key);
75
76 /* Macro to register the keys used in the CoT */
77 #define REGISTER_KEYS(_keys) \
78 key_t *keys = &_keys[0]; \
79 const unsigned int num_keys = sizeof(_keys)/sizeof(_keys[0])
80
81 /* Exported variables */
82 extern key_t *keys;
83 extern const unsigned int num_keys;
84
85 #endif /* KEY_H */