16f971622SJuan Castillo /* 2*60753a63Slaurenw-arm * Copyright (c) 2015-2023, 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, 23*60753a63Slaurenw-arm NVCTR_TYPE_NTFW, 24*60753a63Slaurenw-arm NVCTR_TYPE_CCAFW 2596103d5aSJuan Castillo }; 2696103d5aSJuan Castillo 276f971622SJuan Castillo /* 286f971622SJuan Castillo * This structure contains the relevant information to create the extensions 296f971622SJuan Castillo * to be included in the certificates. This extensions will be used to 306f971622SJuan Castillo * establish the chain of trust. 316f971622SJuan Castillo */ 326f971622SJuan Castillo typedef struct ext_s { 336f971622SJuan Castillo const char *oid; /* OID of the extension */ 346f971622SJuan Castillo const char *sn; /* Short name */ 356f971622SJuan Castillo const char *ln; /* Long description */ 3696103d5aSJuan Castillo const char *opt; /* Command line option to specify data */ 37159807e2SJuan Castillo const char *help_msg; /* Help message */ 3896103d5aSJuan Castillo const char *arg; /* Argument passed from command line */ 3955e291a4SJuan Castillo int asn1_type; /* OpenSSL ASN1 type of the extension data. 406f971622SJuan Castillo * Supported types are: 416f971622SJuan Castillo * - V_ASN1_INTEGER 426f971622SJuan Castillo * - V_ASN1_OCTET_STRING 436f971622SJuan Castillo */ 4496103d5aSJuan Castillo int type; /* See ext_type_e */ 4596103d5aSJuan Castillo 4696103d5aSJuan Castillo /* Extension attributes (depends on extension type) */ 4755e291a4SJuan Castillo union { 4896103d5aSJuan Castillo int nvctr_type; /* See nvctr_type_e */ 4996103d5aSJuan Castillo int key; /* Index into array of registered public keys */ 5096103d5aSJuan Castillo } attr; 5155e291a4SJuan Castillo 526f971622SJuan Castillo int alias; /* In case OpenSSL provides an standard 536f971622SJuan Castillo * extension of the same type, add the new 546f971622SJuan Castillo * extension as an alias of this one 556f971622SJuan Castillo */ 566f971622SJuan Castillo 576f971622SJuan Castillo X509V3_EXT_METHOD method; /* This field may be used to define a custom 586f971622SJuan Castillo * function to print the contents of the 596f971622SJuan Castillo * extension */ 60cebe1f23SYatharth Kochar 61cebe1f23SYatharth Kochar int optional; /* This field may be used optionally to exclude an image */ 626f971622SJuan Castillo } ext_t; 636f971622SJuan Castillo 646f971622SJuan Castillo enum { 656f971622SJuan Castillo EXT_NON_CRIT = 0, 666f971622SJuan Castillo EXT_CRIT = !EXT_NON_CRIT, 676f971622SJuan Castillo }; 686f971622SJuan Castillo 6955e291a4SJuan Castillo /* Exported API */ 70ad2c1a9aSJuan Castillo int ext_init(void); 71ad2c1a9aSJuan Castillo ext_t *ext_get_by_opt(const char *opt); 72c3da66b1SJuan Castillo X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md, 73c3da66b1SJuan Castillo unsigned char *buf, size_t len); 746f971622SJuan Castillo X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value); 756f971622SJuan Castillo X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k); 76cf2dd17dSJuan Pablo Conde void ext_cleanup(void); 776f971622SJuan Castillo 7855e291a4SJuan Castillo /* Macro to register the extensions used in the CoT */ 7955e291a4SJuan Castillo #define REGISTER_EXTENSIONS(_ext) \ 80b94bf967SPankaj Gupta ext_t *def_extensions = &_ext[0]; \ 81b94bf967SPankaj Gupta const unsigned int num_def_extensions = sizeof(_ext)/sizeof(_ext[0]) 82b94bf967SPankaj Gupta 83b94bf967SPankaj Gupta /* Macro to register the platform defined extensions used in the CoT */ 84b94bf967SPankaj Gupta #define PLAT_REGISTER_EXTENSIONS(_pdef_ext) \ 85b94bf967SPankaj Gupta ext_t *pdef_extensions = &_pdef_ext[0]; \ 86b94bf967SPankaj Gupta const unsigned int num_pdef_extensions = sizeof(_pdef_ext)/sizeof(_pdef_ext[0]) 8755e291a4SJuan Castillo 8855e291a4SJuan Castillo /* Exported variables */ 89b94bf967SPankaj Gupta extern ext_t *def_extensions; 90b94bf967SPankaj Gupta extern const unsigned int num_def_extensions; 91b94bf967SPankaj Gupta extern ext_t *pdef_extensions; 92b94bf967SPankaj Gupta extern const unsigned int num_pdef_extensions; 9355e291a4SJuan Castillo 94b94bf967SPankaj Gupta extern ext_t *extensions; 95b94bf967SPankaj Gupta extern unsigned int num_extensions; 96c3cf06f1SAntonio Nino Diaz #endif /* EXT_H */ 97