16f971622SJuan Castillo /* 26f971622SJuan Castillo * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 36f971622SJuan Castillo * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 56f971622SJuan Castillo */ 66f971622SJuan Castillo 76f971622SJuan Castillo #ifndef KEY_H_ 86f971622SJuan Castillo #define KEY_H_ 96f971622SJuan Castillo 106f971622SJuan Castillo #include <openssl/ossl_typ.h> 116f971622SJuan Castillo 126f971622SJuan Castillo #define RSA_KEY_BITS 2048 136f971622SJuan Castillo 14ccbf890eSJuan Castillo /* Error codes */ 15ccbf890eSJuan Castillo enum { 16ccbf890eSJuan Castillo KEY_ERR_NONE, 17ccbf890eSJuan Castillo KEY_ERR_MALLOC, 18ccbf890eSJuan Castillo KEY_ERR_FILENAME, 19ccbf890eSJuan Castillo KEY_ERR_OPEN, 20ccbf890eSJuan Castillo KEY_ERR_LOAD 21ccbf890eSJuan Castillo }; 22ccbf890eSJuan Castillo 23ccbf890eSJuan Castillo /* Supported key algorithms */ 24ccbf890eSJuan Castillo enum { 25*a8eb286aSSoby Mathew KEY_ALG_RSA, /* RSA PSS as defined by PKCS#1 v2.1 (default) */ 26*a8eb286aSSoby Mathew KEY_ALG_RSA_1_5, /* RSA as defined by PKCS#1 v1.5 */ 27ed2a76eaSJuan Castillo #ifndef OPENSSL_NO_EC 28ed2a76eaSJuan Castillo KEY_ALG_ECDSA, 29ed2a76eaSJuan Castillo #endif /* OPENSSL_NO_EC */ 30ed2a76eaSJuan Castillo KEY_ALG_MAX_NUM 31ccbf890eSJuan Castillo }; 32ccbf890eSJuan Castillo 336f971622SJuan Castillo /* 346f971622SJuan Castillo * This structure contains the relevant information to create the keys 356f971622SJuan Castillo * required to sign the certificates. 366f971622SJuan Castillo * 376f971622SJuan Castillo * One instance of this structure must be created for each key, usually in an 386f971622SJuan Castillo * array fashion. The filename is obtained at run time from the command line 396f971622SJuan Castillo * parameters 406f971622SJuan Castillo */ 416f971622SJuan Castillo typedef struct key_s { 426f971622SJuan Castillo int id; /* Key id */ 43ad2c1a9aSJuan Castillo const char *opt; /* Command line option to specify a key */ 44159807e2SJuan Castillo const char *help_msg; /* Help message */ 456f971622SJuan Castillo const char *desc; /* Key description (debug purposes) */ 466f971622SJuan Castillo char *fn; /* Filename to load/store the key */ 476f971622SJuan Castillo EVP_PKEY *key; /* Key container */ 486f971622SJuan Castillo } key_t; 496f971622SJuan Castillo 5055e291a4SJuan Castillo /* Exported API */ 51ad2c1a9aSJuan Castillo int key_init(void); 52ad2c1a9aSJuan Castillo key_t *key_get_by_opt(const char *opt); 53762f1ebeSMasahiro Yamada int key_new(key_t *key); 54ccbf890eSJuan Castillo int key_create(key_t *key, int type); 55ccbf890eSJuan Castillo int key_load(key_t *key, unsigned int *err_code); 566f971622SJuan Castillo int key_store(key_t *key); 576f971622SJuan Castillo 5855e291a4SJuan Castillo /* Macro to register the keys used in the CoT */ 5955e291a4SJuan Castillo #define REGISTER_KEYS(_keys) \ 6055e291a4SJuan Castillo key_t *keys = &_keys[0]; \ 61aa856917SSandrine Bailleux const unsigned int num_keys = sizeof(_keys)/sizeof(_keys[0]) 6255e291a4SJuan Castillo 6355e291a4SJuan Castillo /* Exported variables */ 6455e291a4SJuan Castillo extern key_t *keys; 6555e291a4SJuan Castillo extern const unsigned int num_keys; 6655e291a4SJuan Castillo 676f971622SJuan Castillo #endif /* KEY_H_ */ 68