Lines Matching full:hdr

106 static int asn1_valid_der_boolean(struct asn1_hdr *hdr)  in asn1_valid_der_boolean()  argument
109 if (hdr->length != 1) { in asn1_valid_der_boolean()
111 hdr->length); in asn1_valid_der_boolean()
115 if (hdr->payload[0] != 0 && hdr->payload[0] != 0xff) { in asn1_valid_der_boolean()
118 hdr->payload[0]); in asn1_valid_der_boolean()
126 static int asn1_valid_der(struct asn1_hdr *hdr) in asn1_valid_der() argument
128 if (hdr->class != ASN1_CLASS_UNIVERSAL) in asn1_valid_der()
130 if (hdr->tag == ASN1_TAG_BOOLEAN && !asn1_valid_der_boolean(hdr)) in asn1_valid_der()
132 if (hdr->tag == ASN1_TAG_NULL && hdr->length != 0) in asn1_valid_der()
136 if (hdr->constructed && in asn1_valid_der()
137 (hdr->tag == ASN1_TAG_BOOLEAN || in asn1_valid_der()
138 hdr->tag == ASN1_TAG_INTEGER || in asn1_valid_der()
139 hdr->tag == ASN1_TAG_NULL || in asn1_valid_der()
140 hdr->tag == ASN1_TAG_OID || in asn1_valid_der()
141 hdr->tag == ANS1_TAG_RELATIVE_OID || in asn1_valid_der()
142 hdr->tag == ASN1_TAG_REAL || in asn1_valid_der()
143 hdr->tag == ASN1_TAG_ENUMERATED || in asn1_valid_der()
144 hdr->tag == ASN1_TAG_BITSTRING || in asn1_valid_der()
145 hdr->tag == ASN1_TAG_OCTETSTRING || in asn1_valid_der()
146 hdr->tag == ASN1_TAG_NUMERICSTRING || in asn1_valid_der()
147 hdr->tag == ASN1_TAG_PRINTABLESTRING || in asn1_valid_der()
148 hdr->tag == ASN1_TAG_T61STRING || in asn1_valid_der()
149 hdr->tag == ASN1_TAG_VIDEOTEXSTRING || in asn1_valid_der()
150 hdr->tag == ASN1_TAG_VISIBLESTRING || in asn1_valid_der()
151 hdr->tag == ASN1_TAG_IA5STRING || in asn1_valid_der()
152 hdr->tag == ASN1_TAG_GRAPHICSTRING || in asn1_valid_der()
153 hdr->tag == ASN1_TAG_GENERALSTRING || in asn1_valid_der()
154 hdr->tag == ASN1_TAG_UNIVERSALSTRING || in asn1_valid_der()
155 hdr->tag == ASN1_TAG_UTF8STRING || in asn1_valid_der()
156 hdr->tag == ASN1_TAG_BMPSTRING || in asn1_valid_der()
157 hdr->tag == ASN1_TAG_CHARACTERSTRING || in asn1_valid_der()
158 hdr->tag == ASN1_TAG_UTCTIME || in asn1_valid_der()
159 hdr->tag == ASN1_TAG_GENERALIZEDTIME || in asn1_valid_der()
160 hdr->tag == ASN1_TAG_TIME)) in asn1_valid_der()
162 if (!hdr->constructed && in asn1_valid_der()
163 (hdr->tag == ASN1_TAG_SEQUENCE || in asn1_valid_der()
164 hdr->tag == ASN1_TAG_SET)) in asn1_valid_der()
171 int asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr) in asn1_get_next() argument
176 os_memset(hdr, 0, sizeof(*hdr)); in asn1_get_next()
184 hdr->identifier = *pos++; in asn1_get_next()
185 hdr->class = hdr->identifier >> 6; in asn1_get_next()
186 hdr->constructed = !!(hdr->identifier & (1 << 5)); in asn1_get_next()
188 if ((hdr->identifier & 0x1f) == 0x1f) { in asn1_get_next()
191 hdr->tag = 0; in asn1_get_next()
207 hdr->tag = (hdr->tag << 7) | (tmp & 0x7f); in asn1_get_next()
210 hdr->tag, ext_len); in asn1_get_next()
211 if ((hdr->class != ASN1_CLASS_PRIVATE && hdr->tag < 31) || in asn1_get_next()
212 ext_len * 7 > sizeof(hdr->tag) * 8) { in asn1_get_next()
215 hdr->tag, ext_len); in asn1_get_next()
219 hdr->tag = hdr->identifier & 0x1f; in asn1_get_next()
233 hdr->length = 0; in asn1_get_next()
249 hdr->length = (hdr->length << 8) | *pos++; in asn1_get_next()
251 if (hdr->length < 128) { in asn1_get_next()
258 hdr->length = tmp; in asn1_get_next()
261 if (end < pos || hdr->length > (unsigned int) (end - pos)) { in asn1_get_next()
266 hdr->payload = pos; in asn1_get_next()
268 if (!asn1_valid_der(hdr)) { in asn1_get_next()
269 asn1_print_hdr(hdr, "ASN.1: Invalid DER encoding: "); in asn1_get_next()
276 void asn1_print_hdr(const struct asn1_hdr *hdr, const char *title) in asn1_print_hdr() argument
279 title, hdr->class, hdr->constructed, hdr->tag); in asn1_print_hdr()
283 void asn1_unexpected(const struct asn1_hdr *hdr, const char *title) in asn1_unexpected() argument
286 title, hdr->class, hdr->constructed, hdr->tag); in asn1_unexpected()
337 struct asn1_hdr hdr; in asn1_get_oid() local
339 if (asn1_get_next(buf, len, &hdr) < 0 || hdr.length == 0 || in asn1_get_oid()
340 !asn1_is_oid(&hdr)) { in asn1_get_oid()
341 asn1_unexpected(&hdr, "ASN.1: Expected OID"); in asn1_get_oid()
345 *next = hdr.payload + hdr.length; in asn1_get_oid()
347 return asn1_parse_oid(hdr.payload, hdr.length, oid); in asn1_get_oid()
435 struct asn1_hdr hdr; in asn1_get_integer() local
440 if (asn1_get_next(buf, len, &hdr) < 0 || hdr.length == 0 || in asn1_get_integer()
441 !asn1_is_integer(&hdr)) { in asn1_get_integer()
442 asn1_unexpected(&hdr, "ASN.1: Expected INTEGER"); in asn1_get_integer()
446 *next = hdr.payload + hdr.length; in asn1_get_integer()
447 pos = hdr.payload; in asn1_get_integer()
448 left = hdr.length; in asn1_get_integer()
451 hdr.length); in asn1_get_integer()
466 int asn1_get_sequence(const u8 *buf, size_t len, struct asn1_hdr *hdr, in asn1_get_sequence() argument
469 if (asn1_get_next(buf, len, hdr) < 0 || !asn1_is_sequence(hdr)) { in asn1_get_sequence()
470 asn1_unexpected(hdr, "ASN.1: Expected SEQUENCE"); in asn1_get_sequence()
475 *next = hdr->payload + hdr->length; in asn1_get_sequence()
484 struct asn1_hdr hdr; in asn1_get_alg_id() local
491 if (asn1_get_sequence(pos, end - pos, &hdr, next) < 0 || in asn1_get_alg_id()
492 asn1_get_oid(hdr.payload, hdr.length, oid, &pos) < 0) in asn1_get_alg_id()
497 *params_len = hdr.payload + hdr.length - pos; in asn1_get_alg_id()