1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2018-2020 NXP
4  *
5  * Brief   Definition of the cryptographic algorthim's OID in the
6  *         ASN1 String format.
7  *         Definition of the ASN1 DER tags.
8  *
9  * Computer Security Objects Register
10  * http://csrc.nist.gov/groups/ST/crypto_apps_infra/csor/algorithms.html
11  */
12 #ifndef __ASN1_OID_H__
13 #define __ASN1_OID_H__
14 
15 #include <drvcrypt_hash.h>
16 #include <stdint.h>
17 
18 /*
19  * ASN1 Tags
20  */
21 #define DRVCRYPT_ASN1_CONSTRUCTED  0x20
22 #define DRVCRYPT_ASN1_SEQUENCE	   0x10
23 #define DRVCRYPT_ASN1_OID	   0x06
24 #define DRVCRYPT_ASN1_NULL	   0x05
25 #define DRVCRYPT_ASN1_OCTET_STRING 0x04
26 
27 /*
28  * OID Top Level = first two Node (Standard and Registration-authority)
29  *
30  * iso(1) member-body(2)
31  * iso(1) identified-organization(3)
32  * joint-iso-itu-t(2) country(16)
33  */
34 #define DRVCRYPT_OID_ISO_MEMBER_BODY "\x2a"
35 #define DRVCRYPT_OID_ISO_ID_ORG	     "\x2b"
36 #define DRVCRYPT_OID_ISO_ITU_COUNTRY "\x60"
37 
38 /*
39  * ISO Member body
40  *
41  * us(840)
42  * us(840) rsadsi(113549)
43  */
44 #define DRVCRYPT_OID_MB_US	  "\x86\x48"
45 #define DRVCRYPT_OID_MB_US_RSADSI DRVCRYPT_OID_MB_US "\x86\xF7\x0D"
46 
47 /*
48  * ISO Identified organization
49  *
50  * oiw(14)
51  * oiw(14) secsig(3)
52  */
53 #define DRVCRYPT_OID_IO_OIW	   "\x0e"
54 #define DRVCRYPT_OID_IO_OIW_SECSIG DRVCRYPT_OID_IO_OIW "\x03"
55 
56 /*
57  * ISO ITU OID
58  *
59  * organization(1)
60  * organization(1) gov(101)
61  */
62 #define DRVCRYPT_OID_ITU_ORG	 "\x01"
63 #define DRVCRYPT_OID_ITU_ORG_GOV DRVCRYPT_OID_ITU_ORG "\x65"
64 
65 /*
66  * Digest Algorithm
67  *
68  * digestAlgorithm(2)
69  * csor(3) nistalgotrithm(4)
70  */
71 #define DRVCRYPT_OID_DIGEST	      "\x02"
72 #define DRVCRYPT_OID_DIGEST_CSOR_NIST "\x03\x04"
73 
74 /*
75  * Definition of the Hash OID String
76  *
77  * id-md5 OBJECT IDENTIFIER ::= {
78  *   iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5
79  * }
80  * id-sha1 OBJECT IDENTIFIER ::= {
81  *   iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 26
82  * }
83  * id-sha224 OBJECT IDENTIFIER ::= {
84  *   joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)
85  *   csor(3) nistalgorithm(4) hashalgs(2) 4
86  * }
87  * id-sha256 OBJECT IDENTIFIER ::= {
88  *   joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)
89  *   csor(3) nistalgorithm(4) hashalgs(2) 1
90  * }
91  * id-sha384 OBJECT IDENTIFIER ::= {
92  *   joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)
93  *   csor(3) nistalgorithm(4) hashalgs(2) 2
94  * }
95  * id-sha512 OBJECT IDENTIFIER ::= {
96  *   joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)
97  *   csor(3) nistalgorithm(4) hashalgs(2) 3
98  * }
99  *
100  */
101 #define DRVCRYPT_OID_ID_MD5                                                    \
102 	DRVCRYPT_OID_ISO_MEMBER_BODY DRVCRYPT_OID_MB_US_RSADSI                 \
103 		DRVCRYPT_OID_DIGEST "\x05"
104 
105 #define DRVCRYPT_OID_ID_SHA1                                                   \
106 	DRVCRYPT_OID_ISO_ID_ORG DRVCRYPT_OID_IO_OIW_SECSIG DRVCRYPT_OID_DIGEST \
107 		"\x1a"
108 
109 #define DRVCRYPT_OID_ID_SHA224                                                 \
110 	DRVCRYPT_OID_ISO_ITU_COUNTRY DRVCRYPT_OID_MB_US                        \
111 		DRVCRYPT_OID_ITU_ORG_GOV DRVCRYPT_OID_DIGEST_CSOR_NIST         \
112 			DRVCRYPT_OID_DIGEST "\x04"
113 
114 #define DRVCRYPT_OID_ID_SHA256                                                 \
115 	DRVCRYPT_OID_ISO_ITU_COUNTRY DRVCRYPT_OID_MB_US                        \
116 		DRVCRYPT_OID_ITU_ORG_GOV DRVCRYPT_OID_DIGEST_CSOR_NIST         \
117 			DRVCRYPT_OID_DIGEST "\x01"
118 
119 #define DRVCRYPT_OID_ID_SHA384                                                 \
120 	DRVCRYPT_OID_ISO_ITU_COUNTRY DRVCRYPT_OID_MB_US                        \
121 		DRVCRYPT_OID_ITU_ORG_GOV DRVCRYPT_OID_DIGEST_CSOR_NIST         \
122 			DRVCRYPT_OID_DIGEST "\x02"
123 
124 #define DRVCRYPT_OID_ID_SHA512                                                 \
125 	DRVCRYPT_OID_ISO_ITU_COUNTRY DRVCRYPT_OID_MB_US                        \
126 		DRVCRYPT_OID_ITU_ORG_GOV DRVCRYPT_OID_DIGEST_CSOR_NIST         \
127 			DRVCRYPT_OID_DIGEST "\x03"
128 
129 #define DRVCRYPT_OID_LEN(_id) (sizeof(_id) - 1)
130 
131 /*
132  * Definition of the ASN1 OID structure
133  */
134 struct drvcrypt_oid {
135 	const char *asn1;	  /* OID ASN1 string */
136 	const size_t asn1_length; /* OID ASN1 string length */
137 };
138 
139 /*
140  * Hash OID constant array
141  */
142 extern const struct drvcrypt_oid drvcrypt_hash_oid[];
143 
144 /*
145  * Return the Hash OID value registered in the Hash OID table.
146  *
147  * @algo	Hash algorithm identifier
148  */
149 const struct drvcrypt_oid *drvcrypt_get_alg_hash_oid(uint32_t algo);
150 
151 #endif /* __ASN1_OID_H__ */
152