16f971622SJuan Castillo /* 2*dfe0f4c2SJustin Chadwell * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved. 36f971622SJuan Castillo * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 56f971622SJuan Castillo */ 66f971622SJuan Castillo 7c3cf06f1SAntonio Nino Diaz #ifndef KEY_H 8c3cf06f1SAntonio Nino Diaz #define KEY_H 96f971622SJuan Castillo 106f971622SJuan Castillo #include <openssl/ossl_typ.h> 116f971622SJuan Castillo 12ccbf890eSJuan Castillo /* Error codes */ 13ccbf890eSJuan Castillo enum { 14ccbf890eSJuan Castillo KEY_ERR_NONE, 15ccbf890eSJuan Castillo KEY_ERR_MALLOC, 16ccbf890eSJuan Castillo KEY_ERR_FILENAME, 17ccbf890eSJuan Castillo KEY_ERR_OPEN, 18ccbf890eSJuan Castillo KEY_ERR_LOAD 19ccbf890eSJuan Castillo }; 20ccbf890eSJuan Castillo 21ccbf890eSJuan Castillo /* Supported key algorithms */ 22ccbf890eSJuan Castillo enum { 23a8eb286aSSoby Mathew KEY_ALG_RSA, /* RSA PSS as defined by PKCS#1 v2.1 (default) */ 24a8eb286aSSoby Mathew KEY_ALG_RSA_1_5, /* RSA as defined by PKCS#1 v1.5 */ 25ed2a76eaSJuan Castillo #ifndef OPENSSL_NO_EC 26ed2a76eaSJuan Castillo KEY_ALG_ECDSA, 27ed2a76eaSJuan Castillo #endif /* OPENSSL_NO_EC */ 28ed2a76eaSJuan Castillo KEY_ALG_MAX_NUM 29ccbf890eSJuan Castillo }; 30ccbf890eSJuan Castillo 31*dfe0f4c2SJustin Chadwell /* Maximum number of valid key sizes per algorithm */ 32*dfe0f4c2SJustin Chadwell #define KEY_SIZE_MAX_NUM 4 33*dfe0f4c2SJustin Chadwell 342972247cSQixiang Xu /* Supported hash algorithms */ 352972247cSQixiang Xu enum{ 362972247cSQixiang Xu HASH_ALG_SHA256, 372972247cSQixiang Xu HASH_ALG_SHA384, 382972247cSQixiang Xu HASH_ALG_SHA512, 392972247cSQixiang Xu }; 402972247cSQixiang Xu 41*dfe0f4c2SJustin Chadwell /* Supported key sizes */ 42*dfe0f4c2SJustin Chadwell /* NOTE: the first item in each array is the default key size */ 43*dfe0f4c2SJustin Chadwell static const unsigned int KEY_SIZES[KEY_ALG_MAX_NUM][KEY_SIZE_MAX_NUM] = { 44*dfe0f4c2SJustin Chadwell { 2048, 1024, 3072, 4096 }, /* KEY_ALG_RSA */ 45*dfe0f4c2SJustin Chadwell { 2048, 1024, 3072, 4096 }, /* KEY_ALG_RSA_1_5 */ 46*dfe0f4c2SJustin Chadwell #ifndef OPENSSL_NO_EC 47*dfe0f4c2SJustin Chadwell {} /* KEY_ALG_ECDSA */ 48*dfe0f4c2SJustin Chadwell #endif /* OPENSSL_NO_EC */ 49*dfe0f4c2SJustin Chadwell }; 50*dfe0f4c2SJustin Chadwell 516f971622SJuan Castillo /* 526f971622SJuan Castillo * This structure contains the relevant information to create the keys 536f971622SJuan Castillo * required to sign the certificates. 546f971622SJuan Castillo * 556f971622SJuan Castillo * One instance of this structure must be created for each key, usually in an 566f971622SJuan Castillo * array fashion. The filename is obtained at run time from the command line 576f971622SJuan Castillo * parameters 586f971622SJuan Castillo */ 596f971622SJuan Castillo typedef struct key_s { 606f971622SJuan Castillo int id; /* Key id */ 61ad2c1a9aSJuan Castillo const char *opt; /* Command line option to specify a key */ 62159807e2SJuan Castillo const char *help_msg; /* Help message */ 636f971622SJuan Castillo const char *desc; /* Key description (debug purposes) */ 646f971622SJuan Castillo char *fn; /* Filename to load/store the key */ 656f971622SJuan Castillo EVP_PKEY *key; /* Key container */ 666f971622SJuan Castillo } key_t; 676f971622SJuan Castillo 6855e291a4SJuan Castillo /* Exported API */ 69ad2c1a9aSJuan Castillo int key_init(void); 70ad2c1a9aSJuan Castillo key_t *key_get_by_opt(const char *opt); 71762f1ebeSMasahiro Yamada int key_new(key_t *key); 72*dfe0f4c2SJustin Chadwell int key_create(key_t *key, int type, int key_bits); 73ccbf890eSJuan Castillo int key_load(key_t *key, unsigned int *err_code); 746f971622SJuan Castillo int key_store(key_t *key); 756f971622SJuan Castillo 7655e291a4SJuan Castillo /* Macro to register the keys used in the CoT */ 7755e291a4SJuan Castillo #define REGISTER_KEYS(_keys) \ 7855e291a4SJuan Castillo key_t *keys = &_keys[0]; \ 79aa856917SSandrine Bailleux const unsigned int num_keys = sizeof(_keys)/sizeof(_keys[0]) 8055e291a4SJuan Castillo 8155e291a4SJuan Castillo /* Exported variables */ 8255e291a4SJuan Castillo extern key_t *keys; 8355e291a4SJuan Castillo extern const unsigned int num_keys; 8455e291a4SJuan Castillo 85c3cf06f1SAntonio Nino Diaz #endif /* KEY_H */ 86