xref: /rk3399_ARM-atf/tools/cert_create/include/ext.h (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
16f971622SJuan Castillo /*
26f971622SJuan Castillo  * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
36f971622SJuan Castillo  *
4*82cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
56f971622SJuan Castillo  */
66f971622SJuan Castillo 
76f971622SJuan Castillo #ifndef EXT_H_
86f971622SJuan Castillo #define EXT_H_
96f971622SJuan Castillo 
1055e291a4SJuan Castillo #include "key.h"
116f971622SJuan Castillo #include <openssl/x509v3.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);
756f971622SJuan Castillo 
7655e291a4SJuan Castillo /* Macro to register the extensions used in the CoT */
7755e291a4SJuan Castillo #define REGISTER_EXTENSIONS(_ext) \
7855e291a4SJuan Castillo 	ext_t *extensions = &_ext[0]; \
79aa856917SSandrine Bailleux 	const unsigned int num_extensions = sizeof(_ext)/sizeof(_ext[0])
8055e291a4SJuan Castillo 
8155e291a4SJuan Castillo /* Exported variables */
8255e291a4SJuan Castillo extern ext_t *extensions;
8355e291a4SJuan Castillo extern const unsigned int num_extensions;
8455e291a4SJuan Castillo 
856f971622SJuan Castillo #endif /* EXT_H_ */
86