16f971622SJuan Castillo /* 2*cf2dd17dSJuan Pablo Conde * Copyright (c) 2015-2022, 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 EXT_H 8c3cf06f1SAntonio Nino Diaz #define EXT_H 96f971622SJuan Castillo 106f971622SJuan Castillo #include <openssl/x509v3.h> 112a4b4b71SIsla Mitchell #include "key.h" 126f971622SJuan Castillo 1355e291a4SJuan Castillo /* Extension types supported */ 1496103d5aSJuan Castillo enum ext_type_e { 1555e291a4SJuan Castillo EXT_TYPE_NVCOUNTER, 1655e291a4SJuan Castillo EXT_TYPE_PKEY, 1755e291a4SJuan Castillo EXT_TYPE_HASH 1855e291a4SJuan Castillo }; 1955e291a4SJuan Castillo 2096103d5aSJuan Castillo /* NV-Counter types */ 2196103d5aSJuan Castillo enum nvctr_type_e { 2296103d5aSJuan Castillo NVCTR_TYPE_TFW, 2396103d5aSJuan Castillo NVCTR_TYPE_NTFW 2496103d5aSJuan Castillo }; 2596103d5aSJuan Castillo 266f971622SJuan Castillo /* 276f971622SJuan Castillo * This structure contains the relevant information to create the extensions 286f971622SJuan Castillo * to be included in the certificates. This extensions will be used to 296f971622SJuan Castillo * establish the chain of trust. 306f971622SJuan Castillo */ 316f971622SJuan Castillo typedef struct ext_s { 326f971622SJuan Castillo const char *oid; /* OID of the extension */ 336f971622SJuan Castillo const char *sn; /* Short name */ 346f971622SJuan Castillo const char *ln; /* Long description */ 3596103d5aSJuan Castillo const char *opt; /* Command line option to specify data */ 36159807e2SJuan Castillo const char *help_msg; /* Help message */ 3796103d5aSJuan Castillo const char *arg; /* Argument passed from command line */ 3855e291a4SJuan Castillo int asn1_type; /* OpenSSL ASN1 type of the extension data. 396f971622SJuan Castillo * Supported types are: 406f971622SJuan Castillo * - V_ASN1_INTEGER 416f971622SJuan Castillo * - V_ASN1_OCTET_STRING 426f971622SJuan Castillo */ 4396103d5aSJuan Castillo int type; /* See ext_type_e */ 4496103d5aSJuan Castillo 4596103d5aSJuan Castillo /* Extension attributes (depends on extension type) */ 4655e291a4SJuan Castillo union { 4796103d5aSJuan Castillo int nvctr_type; /* See nvctr_type_e */ 4896103d5aSJuan Castillo int key; /* Index into array of registered public keys */ 4996103d5aSJuan Castillo } attr; 5055e291a4SJuan Castillo 516f971622SJuan Castillo int alias; /* In case OpenSSL provides an standard 526f971622SJuan Castillo * extension of the same type, add the new 536f971622SJuan Castillo * extension as an alias of this one 546f971622SJuan Castillo */ 556f971622SJuan Castillo 566f971622SJuan Castillo X509V3_EXT_METHOD method; /* This field may be used to define a custom 576f971622SJuan Castillo * function to print the contents of the 586f971622SJuan Castillo * extension */ 59cebe1f23SYatharth Kochar 60cebe1f23SYatharth Kochar int optional; /* This field may be used optionally to exclude an image */ 616f971622SJuan Castillo } ext_t; 626f971622SJuan Castillo 636f971622SJuan Castillo enum { 646f971622SJuan Castillo EXT_NON_CRIT = 0, 656f971622SJuan Castillo EXT_CRIT = !EXT_NON_CRIT, 666f971622SJuan Castillo }; 676f971622SJuan Castillo 6855e291a4SJuan Castillo /* Exported API */ 69ad2c1a9aSJuan Castillo int ext_init(void); 70ad2c1a9aSJuan Castillo ext_t *ext_get_by_opt(const char *opt); 71c3da66b1SJuan Castillo X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md, 72c3da66b1SJuan Castillo unsigned char *buf, size_t len); 736f971622SJuan Castillo X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value); 746f971622SJuan Castillo X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k); 75*cf2dd17dSJuan Pablo Conde void ext_cleanup(void); 766f971622SJuan Castillo 7755e291a4SJuan Castillo /* Macro to register the extensions used in the CoT */ 7855e291a4SJuan Castillo #define REGISTER_EXTENSIONS(_ext) \ 79b94bf967SPankaj Gupta ext_t *def_extensions = &_ext[0]; \ 80b94bf967SPankaj Gupta const unsigned int num_def_extensions = sizeof(_ext)/sizeof(_ext[0]) 81b94bf967SPankaj Gupta 82b94bf967SPankaj Gupta /* Macro to register the platform defined extensions used in the CoT */ 83b94bf967SPankaj Gupta #define PLAT_REGISTER_EXTENSIONS(_pdef_ext) \ 84b94bf967SPankaj Gupta ext_t *pdef_extensions = &_pdef_ext[0]; \ 85b94bf967SPankaj Gupta const unsigned int num_pdef_extensions = sizeof(_pdef_ext)/sizeof(_pdef_ext[0]) 8655e291a4SJuan Castillo 8755e291a4SJuan Castillo /* Exported variables */ 88b94bf967SPankaj Gupta extern ext_t *def_extensions; 89b94bf967SPankaj Gupta extern const unsigned int num_def_extensions; 90b94bf967SPankaj Gupta extern ext_t *pdef_extensions; 91b94bf967SPankaj Gupta extern const unsigned int num_pdef_extensions; 9255e291a4SJuan Castillo 93b94bf967SPankaj Gupta extern ext_t *extensions; 94b94bf967SPankaj Gupta extern unsigned int num_extensions; 95c3cf06f1SAntonio Nino Diaz #endif /* EXT_H */ 96