/src/hostap/src/tls/asn1.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * ASN.1 DER parsing |
3 | | * Copyright (c) 2006, Jouni Malinen <j@w1.fi> |
4 | | * |
5 | | * This software may be distributed under the terms of the BSD license. |
6 | | * See README for more details. |
7 | | */ |
8 | | |
9 | | #ifndef ASN1_H |
10 | | #define ASN1_H |
11 | | |
12 | | #define ASN1_TAG_EOC 0x00 /* not used with DER */ |
13 | 670k | #define ASN1_TAG_BOOLEAN 0x01 |
14 | 228k | #define ASN1_TAG_INTEGER 0x02 |
15 | 218k | #define ASN1_TAG_BITSTRING 0x03 |
16 | 230k | #define ASN1_TAG_OCTETSTRING 0x04 |
17 | 636k | #define ASN1_TAG_NULL 0x05 |
18 | 316k | #define ASN1_TAG_OID 0x06 |
19 | | #define ASN1_TAG_OBJECT_DESCRIPTOR 0x07 /* not yet parsed */ |
20 | | #define ASN1_TAG_EXTERNAL 0x08 /* not yet parsed */ |
21 | 208k | #define ASN1_TAG_REAL 0x09 /* not yet parsed */ |
22 | 208k | #define ASN1_TAG_ENUMERATED 0x0A /* not yet parsed */ |
23 | | #define ASN1_TAG_EMBEDDED_PDV 0x0B /* not yet parsed */ |
24 | 244k | #define ASN1_TAG_UTF8STRING 0x0C /* not yet parsed */ |
25 | 208k | #define ANS1_TAG_RELATIVE_OID 0x0D |
26 | 104k | #define ASN1_TAG_TIME 0x0E |
27 | 389k | #define ASN1_TAG_SEQUENCE 0x10 /* shall be constructed */ |
28 | 147k | #define ASN1_TAG_SET 0x11 |
29 | 243k | #define ASN1_TAG_NUMERICSTRING 0x12 /* not yet parsed */ |
30 | 242k | #define ASN1_TAG_PRINTABLESTRING 0x13 |
31 | 241k | #define ASN1_TAG_T61STRING 0x14 /* not yet parsed */ |
32 | 240k | #define ASN1_TAG_VIDEOTEXSTRING 0x15 /* not yet parsed */ |
33 | 239k | #define ASN1_TAG_IA5STRING 0x16 |
34 | 231k | #define ASN1_TAG_UTCTIME 0x17 |
35 | 209k | #define ASN1_TAG_GENERALIZEDTIME 0x18 /* not yet parsed */ |
36 | 238k | #define ASN1_TAG_GRAPHICSTRING 0x19 /* not yet parsed */ |
37 | 238k | #define ASN1_TAG_VISIBLESTRING 0x1A |
38 | 237k | #define ASN1_TAG_GENERALSTRING 0x1B /* not yet parsed */ |
39 | 236k | #define ASN1_TAG_UNIVERSALSTRING 0x1C /* not yet parsed */ |
40 | 236k | #define ASN1_TAG_CHARACTERSTRING 0x1D /* not yet parsed */ |
41 | 235k | #define ASN1_TAG_BMPSTRING 0x1E /* not yet parsed */ |
42 | | |
43 | 693k | #define ASN1_CLASS_UNIVERSAL 0 |
44 | | #define ASN1_CLASS_APPLICATION 1 |
45 | 27.8k | #define ASN1_CLASS_CONTEXT_SPECIFIC 2 |
46 | 9.10k | #define ASN1_CLASS_PRIVATE 3 |
47 | | |
48 | | |
49 | | struct asn1_hdr { |
50 | | const u8 *payload; |
51 | | u8 identifier, class, constructed; |
52 | | unsigned int tag, length; |
53 | | }; |
54 | | |
55 | 242k | #define ASN1_MAX_OID_LEN 20 |
56 | | struct asn1_oid { |
57 | | unsigned long oid[ASN1_MAX_OID_LEN]; |
58 | | size_t len; |
59 | | }; |
60 | | |
61 | | |
62 | | int asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr); |
63 | | void asn1_print_hdr(const struct asn1_hdr *hdr, const char *title); |
64 | | void asn1_unexpected(const struct asn1_hdr *hdr, const char *title); |
65 | | int asn1_parse_oid(const u8 *buf, size_t len, struct asn1_oid *oid); |
66 | | int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid, |
67 | | const u8 **next); |
68 | | void asn1_oid_to_str(const struct asn1_oid *oid, char *buf, size_t len); |
69 | | unsigned long asn1_bit_string_to_long(const u8 *buf, size_t len); |
70 | | int asn1_oid_equal(const struct asn1_oid *a, const struct asn1_oid *b); |
71 | | int asn1_get_integer(const u8 *buf, size_t len, int *integer, const u8 **next); |
72 | | int asn1_get_sequence(const u8 *buf, size_t len, struct asn1_hdr *hdr, |
73 | | const u8 **next); |
74 | | int asn1_get_alg_id(const u8 *buf, size_t len, struct asn1_oid *oid, |
75 | | const u8 **params, size_t *params_len, const u8 **next); |
76 | | void asn1_put_integer(struct wpabuf *buf, int val); |
77 | | void asn1_put_octet_string(struct wpabuf *buf, const struct wpabuf *val); |
78 | | void asn1_put_oid(struct wpabuf *buf, const struct asn1_oid *oid); |
79 | | void asn1_put_hdr(struct wpabuf *buf, u8 class, int constructed, u8 tag, |
80 | | size_t len); |
81 | | void asn1_put_sequence(struct wpabuf *buf, const struct wpabuf *payload); |
82 | | void asn1_put_set(struct wpabuf *buf, const struct wpabuf *payload); |
83 | | void asn1_put_utf8string(struct wpabuf *buf, const char *val); |
84 | | struct wpabuf * asn1_build_alg_id(const struct asn1_oid *oid, |
85 | | const struct wpabuf *params); |
86 | | struct wpabuf * asn1_encaps(struct wpabuf *buf, u8 class, u8 tag); |
87 | | |
88 | | static inline bool asn1_is_oid(const struct asn1_hdr *hdr) |
89 | 53.7k | { |
90 | 53.7k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
91 | 53.7k | hdr->tag == ASN1_TAG_OID; |
92 | 53.7k | } Unexecuted instantiation: x509.c:asn1_is_oid Unexecuted instantiation: x509v3.c:asn1_is_oid Line | Count | Source | 89 | 53.7k | { | 90 | 53.7k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 91 | 53.7k | hdr->tag == ASN1_TAG_OID; | 92 | 53.7k | } |
Unexecuted instantiation: pkcs1.c:asn1_is_oid Unexecuted instantiation: pkcs8.c:asn1_is_oid Unexecuted instantiation: rsa.c:asn1_is_oid Unexecuted instantiation: pkcs5.c:asn1_is_oid |
93 | | |
94 | | static inline bool asn1_is_boolean(const struct asn1_hdr *hdr) |
95 | 11.5k | { |
96 | 11.5k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
97 | 11.5k | hdr->tag == ASN1_TAG_BOOLEAN; |
98 | 11.5k | } Unexecuted instantiation: x509.c:asn1_is_boolean Line | Count | Source | 95 | 11.5k | { | 96 | 11.5k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 97 | 11.5k | hdr->tag == ASN1_TAG_BOOLEAN; | 98 | 11.5k | } |
Unexecuted instantiation: asn1.c:asn1_is_boolean Unexecuted instantiation: pkcs1.c:asn1_is_boolean Unexecuted instantiation: pkcs8.c:asn1_is_boolean Unexecuted instantiation: rsa.c:asn1_is_boolean Unexecuted instantiation: pkcs5.c:asn1_is_boolean |
99 | | |
100 | | static inline bool asn1_is_integer(const struct asn1_hdr *hdr) |
101 | 10.0k | { |
102 | 10.0k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
103 | 10.0k | hdr->tag == ASN1_TAG_INTEGER; |
104 | 10.0k | } Unexecuted instantiation: x509.c:asn1_is_integer Line | Count | Source | 101 | 10.0k | { | 102 | 10.0k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 103 | 10.0k | hdr->tag == ASN1_TAG_INTEGER; | 104 | 10.0k | } |
Unexecuted instantiation: asn1.c:asn1_is_integer Unexecuted instantiation: pkcs1.c:asn1_is_integer Unexecuted instantiation: pkcs8.c:asn1_is_integer Unexecuted instantiation: rsa.c:asn1_is_integer Unexecuted instantiation: pkcs5.c:asn1_is_integer |
105 | | |
106 | | static inline bool asn1_is_enumerated(const struct asn1_hdr *hdr) |
107 | 0 | { |
108 | 0 | return hdr->class == ASN1_CLASS_UNIVERSAL && |
109 | 0 | hdr->tag == ASN1_TAG_ENUMERATED; |
110 | 0 | } Unexecuted instantiation: x509.c:asn1_is_enumerated Unexecuted instantiation: x509v3.c:asn1_is_enumerated Unexecuted instantiation: asn1.c:asn1_is_enumerated Unexecuted instantiation: pkcs1.c:asn1_is_enumerated Unexecuted instantiation: pkcs8.c:asn1_is_enumerated Unexecuted instantiation: rsa.c:asn1_is_enumerated Unexecuted instantiation: pkcs5.c:asn1_is_enumerated |
111 | | |
112 | | static inline bool asn1_is_sequence(const struct asn1_hdr *hdr) |
113 | 85.1k | { |
114 | 85.1k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
115 | 85.1k | hdr->tag == ASN1_TAG_SEQUENCE; |
116 | 85.1k | } Unexecuted instantiation: x509.c:asn1_is_sequence x509v3.c:asn1_is_sequence Line | Count | Source | 113 | 85.1k | { | 114 | 85.1k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 115 | 85.1k | hdr->tag == ASN1_TAG_SEQUENCE; | 116 | 85.1k | } |
Unexecuted instantiation: asn1.c:asn1_is_sequence Unexecuted instantiation: pkcs1.c:asn1_is_sequence Unexecuted instantiation: pkcs8.c:asn1_is_sequence Unexecuted instantiation: rsa.c:asn1_is_sequence Unexecuted instantiation: pkcs5.c:asn1_is_sequence |
117 | | |
118 | | static inline bool asn1_is_set(const struct asn1_hdr *hdr) |
119 | 18.8k | { |
120 | 18.8k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
121 | 18.8k | hdr->tag == ASN1_TAG_SET; |
122 | 18.8k | } Unexecuted instantiation: x509.c:asn1_is_set Line | Count | Source | 119 | 18.8k | { | 120 | 18.8k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 121 | 18.8k | hdr->tag == ASN1_TAG_SET; | 122 | 18.8k | } |
Unexecuted instantiation: asn1.c:asn1_is_set Unexecuted instantiation: pkcs1.c:asn1_is_set Unexecuted instantiation: pkcs8.c:asn1_is_set Unexecuted instantiation: rsa.c:asn1_is_set Unexecuted instantiation: pkcs5.c:asn1_is_set |
123 | | |
124 | | static inline bool asn1_is_octetstring(const struct asn1_hdr *hdr) |
125 | 10.8k | { |
126 | 10.8k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
127 | 10.8k | hdr->tag == ASN1_TAG_OCTETSTRING; |
128 | 10.8k | } Unexecuted instantiation: x509.c:asn1_is_octetstring x509v3.c:asn1_is_octetstring Line | Count | Source | 125 | 10.8k | { | 126 | 10.8k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 127 | 10.8k | hdr->tag == ASN1_TAG_OCTETSTRING; | 128 | 10.8k | } |
Unexecuted instantiation: asn1.c:asn1_is_octetstring Unexecuted instantiation: pkcs1.c:asn1_is_octetstring Unexecuted instantiation: pkcs8.c:asn1_is_octetstring Unexecuted instantiation: rsa.c:asn1_is_octetstring Unexecuted instantiation: pkcs5.c:asn1_is_octetstring |
129 | | |
130 | | static inline bool asn1_is_bitstring(const struct asn1_hdr *hdr) |
131 | 5.12k | { |
132 | 5.12k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
133 | 5.12k | hdr->tag == ASN1_TAG_BITSTRING; |
134 | 5.12k | } Unexecuted instantiation: x509.c:asn1_is_bitstring x509v3.c:asn1_is_bitstring Line | Count | Source | 131 | 5.12k | { | 132 | 5.12k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 133 | 5.12k | hdr->tag == ASN1_TAG_BITSTRING; | 134 | 5.12k | } |
Unexecuted instantiation: asn1.c:asn1_is_bitstring Unexecuted instantiation: pkcs1.c:asn1_is_bitstring Unexecuted instantiation: pkcs8.c:asn1_is_bitstring Unexecuted instantiation: rsa.c:asn1_is_bitstring Unexecuted instantiation: pkcs5.c:asn1_is_bitstring |
135 | | |
136 | | static inline bool asn1_is_utctime(const struct asn1_hdr *hdr) |
137 | 7.52k | { |
138 | 7.52k | return hdr->class == ASN1_CLASS_UNIVERSAL && |
139 | 7.52k | hdr->tag == ASN1_TAG_UTCTIME; |
140 | 7.52k | } Unexecuted instantiation: x509.c:asn1_is_utctime Line | Count | Source | 137 | 7.52k | { | 138 | 7.52k | return hdr->class == ASN1_CLASS_UNIVERSAL && | 139 | 7.52k | hdr->tag == ASN1_TAG_UTCTIME; | 140 | 7.52k | } |
Unexecuted instantiation: asn1.c:asn1_is_utctime Unexecuted instantiation: pkcs1.c:asn1_is_utctime Unexecuted instantiation: pkcs8.c:asn1_is_utctime Unexecuted instantiation: rsa.c:asn1_is_utctime Unexecuted instantiation: pkcs5.c:asn1_is_utctime |
141 | | |
142 | | static inline bool asn1_is_generalizedtime(const struct asn1_hdr *hdr) |
143 | 180 | { |
144 | 180 | return hdr->class == ASN1_CLASS_UNIVERSAL && |
145 | 180 | hdr->tag == ASN1_TAG_GENERALIZEDTIME; |
146 | 180 | } Unexecuted instantiation: x509.c:asn1_is_generalizedtime x509v3.c:asn1_is_generalizedtime Line | Count | Source | 143 | 180 | { | 144 | 180 | return hdr->class == ASN1_CLASS_UNIVERSAL && | 145 | 180 | hdr->tag == ASN1_TAG_GENERALIZEDTIME; | 146 | 180 | } |
Unexecuted instantiation: asn1.c:asn1_is_generalizedtime Unexecuted instantiation: pkcs1.c:asn1_is_generalizedtime Unexecuted instantiation: pkcs8.c:asn1_is_generalizedtime Unexecuted instantiation: rsa.c:asn1_is_generalizedtime Unexecuted instantiation: pkcs5.c:asn1_is_generalizedtime |
147 | | |
148 | | static inline bool asn1_is_string_type(const struct asn1_hdr *hdr) |
149 | 18.6k | { |
150 | 18.6k | if (hdr->class != ASN1_CLASS_UNIVERSAL || hdr->constructed) |
151 | 729 | return false; |
152 | 17.9k | return hdr->tag == ASN1_TAG_UTF8STRING || |
153 | 17.9k | hdr->tag == ASN1_TAG_NUMERICSTRING || |
154 | 17.9k | hdr->tag == ASN1_TAG_PRINTABLESTRING || |
155 | 17.9k | hdr->tag == ASN1_TAG_T61STRING || |
156 | 17.9k | hdr->tag == ASN1_TAG_VIDEOTEXSTRING || |
157 | 17.9k | hdr->tag == ASN1_TAG_IA5STRING || |
158 | 17.9k | hdr->tag == ASN1_TAG_GRAPHICSTRING || |
159 | 17.9k | hdr->tag == ASN1_TAG_VISIBLESTRING || |
160 | 17.9k | hdr->tag == ASN1_TAG_GENERALSTRING || |
161 | 17.9k | hdr->tag == ASN1_TAG_UNIVERSALSTRING || |
162 | 17.9k | hdr->tag == ASN1_TAG_CHARACTERSTRING || |
163 | 17.9k | hdr->tag == ASN1_TAG_BMPSTRING; |
164 | 18.6k | } Unexecuted instantiation: x509.c:asn1_is_string_type x509v3.c:asn1_is_string_type Line | Count | Source | 149 | 18.6k | { | 150 | 18.6k | if (hdr->class != ASN1_CLASS_UNIVERSAL || hdr->constructed) | 151 | 729 | return false; | 152 | 17.9k | return hdr->tag == ASN1_TAG_UTF8STRING || | 153 | 17.9k | hdr->tag == ASN1_TAG_NUMERICSTRING || | 154 | 17.9k | hdr->tag == ASN1_TAG_PRINTABLESTRING || | 155 | 17.9k | hdr->tag == ASN1_TAG_T61STRING || | 156 | 17.9k | hdr->tag == ASN1_TAG_VIDEOTEXSTRING || | 157 | 17.9k | hdr->tag == ASN1_TAG_IA5STRING || | 158 | 17.9k | hdr->tag == ASN1_TAG_GRAPHICSTRING || | 159 | 17.9k | hdr->tag == ASN1_TAG_VISIBLESTRING || | 160 | 17.9k | hdr->tag == ASN1_TAG_GENERALSTRING || | 161 | 17.9k | hdr->tag == ASN1_TAG_UNIVERSALSTRING || | 162 | 17.9k | hdr->tag == ASN1_TAG_CHARACTERSTRING || | 163 | 17.9k | hdr->tag == ASN1_TAG_BMPSTRING; | 164 | 18.6k | } |
Unexecuted instantiation: asn1.c:asn1_is_string_type Unexecuted instantiation: pkcs1.c:asn1_is_string_type Unexecuted instantiation: pkcs8.c:asn1_is_string_type Unexecuted instantiation: rsa.c:asn1_is_string_type Unexecuted instantiation: pkcs5.c:asn1_is_string_type |
165 | | |
166 | | static inline bool asn1_is_bmpstring(const struct asn1_hdr *hdr) |
167 | 0 | { |
168 | 0 | return hdr->class == ASN1_CLASS_UNIVERSAL && |
169 | 0 | hdr->tag == ASN1_TAG_BMPSTRING; |
170 | 0 | } Unexecuted instantiation: x509.c:asn1_is_bmpstring Unexecuted instantiation: x509v3.c:asn1_is_bmpstring Unexecuted instantiation: asn1.c:asn1_is_bmpstring Unexecuted instantiation: pkcs1.c:asn1_is_bmpstring Unexecuted instantiation: pkcs8.c:asn1_is_bmpstring Unexecuted instantiation: rsa.c:asn1_is_bmpstring Unexecuted instantiation: pkcs5.c:asn1_is_bmpstring |
171 | | |
172 | | static inline bool asn1_is_utf8string(const struct asn1_hdr *hdr) |
173 | 0 | { |
174 | 0 | return hdr->class == ASN1_CLASS_UNIVERSAL && |
175 | 0 | hdr->tag == ASN1_TAG_UTF8STRING; |
176 | 0 | } Unexecuted instantiation: x509.c:asn1_is_utf8string Unexecuted instantiation: x509v3.c:asn1_is_utf8string Unexecuted instantiation: asn1.c:asn1_is_utf8string Unexecuted instantiation: pkcs1.c:asn1_is_utf8string Unexecuted instantiation: pkcs8.c:asn1_is_utf8string Unexecuted instantiation: rsa.c:asn1_is_utf8string Unexecuted instantiation: pkcs5.c:asn1_is_utf8string |
177 | | |
178 | | static inline bool asn1_is_null(const struct asn1_hdr *hdr) |
179 | 0 | { |
180 | 0 | return hdr->class == ASN1_CLASS_UNIVERSAL && |
181 | 0 | hdr->tag == ASN1_TAG_NULL; |
182 | 0 | } Unexecuted instantiation: x509.c:asn1_is_null Unexecuted instantiation: x509v3.c:asn1_is_null Unexecuted instantiation: asn1.c:asn1_is_null Unexecuted instantiation: pkcs1.c:asn1_is_null Unexecuted instantiation: pkcs8.c:asn1_is_null Unexecuted instantiation: rsa.c:asn1_is_null Unexecuted instantiation: pkcs5.c:asn1_is_null |
183 | | |
184 | | static inline bool asn1_is_cs_tag(const struct asn1_hdr *hdr, unsigned int tag) |
185 | 6.05k | { |
186 | 6.05k | return hdr->class == ASN1_CLASS_CONTEXT_SPECIFIC && |
187 | 6.05k | hdr->tag == tag; |
188 | 6.05k | } Unexecuted instantiation: x509.c:asn1_is_cs_tag Line | Count | Source | 185 | 6.05k | { | 186 | 6.05k | return hdr->class == ASN1_CLASS_CONTEXT_SPECIFIC && | 187 | 6.05k | hdr->tag == tag; | 188 | 6.05k | } |
Unexecuted instantiation: asn1.c:asn1_is_cs_tag Unexecuted instantiation: pkcs1.c:asn1_is_cs_tag Unexecuted instantiation: pkcs8.c:asn1_is_cs_tag Unexecuted instantiation: rsa.c:asn1_is_cs_tag Unexecuted instantiation: pkcs5.c:asn1_is_cs_tag |
189 | | |
190 | | extern const struct asn1_oid asn1_sha1_oid; |
191 | | extern const struct asn1_oid asn1_sha256_oid; |
192 | | extern const struct asn1_oid asn1_ec_public_key_oid; |
193 | | extern const struct asn1_oid asn1_prime256v1_oid; |
194 | | extern const struct asn1_oid asn1_secp384r1_oid; |
195 | | extern const struct asn1_oid asn1_secp521r1_oid; |
196 | | extern const struct asn1_oid asn1_brainpoolP256r1_oid; |
197 | | extern const struct asn1_oid asn1_brainpoolP384r1_oid; |
198 | | extern const struct asn1_oid asn1_brainpoolP512r1_oid; |
199 | | extern const struct asn1_oid asn1_aes_siv_cmac_aead_256_oid; |
200 | | extern const struct asn1_oid asn1_aes_siv_cmac_aead_384_oid; |
201 | | extern const struct asn1_oid asn1_aes_siv_cmac_aead_512_oid; |
202 | | extern const struct asn1_oid asn1_aes_siv_cmac_aead_256_oid; |
203 | | extern const struct asn1_oid asn1_aes_siv_cmac_aead_384_oid; |
204 | | extern const struct asn1_oid asn1_aes_siv_cmac_aead_512_oid; |
205 | | extern const struct asn1_oid asn1_pbkdf2_oid; |
206 | | extern const struct asn1_oid asn1_pbkdf2_hmac_sha256_oid; |
207 | | extern const struct asn1_oid asn1_pbkdf2_hmac_sha384_oid; |
208 | | extern const struct asn1_oid asn1_pbkdf2_hmac_sha512_oid; |
209 | | extern const struct asn1_oid asn1_dpp_config_params_oid; |
210 | | extern const struct asn1_oid asn1_dpp_asymmetric_key_package_oid; |
211 | | |
212 | | #endif /* ASN1_H */ |