1189251Ssam/* 2189251Ssam * ASN.1 DER parsing 3189251Ssam * Copyright (c) 2006, Jouni Malinen <j@w1.fi> 4189251Ssam * 5189251Ssam * This program is free software; you can redistribute it and/or modify 6189251Ssam * it under the terms of the GNU General Public License version 2 as 7189251Ssam * published by the Free Software Foundation. 8189251Ssam * 9189251Ssam * Alternatively, this software may be distributed under the terms of BSD 10189251Ssam * license. 11189251Ssam * 12189251Ssam * See README and COPYING for more details. 13189251Ssam */ 14189251Ssam 15189251Ssam#ifndef ASN1_H 16189251Ssam#define ASN1_H 17189251Ssam 18189251Ssam#define ASN1_TAG_EOC 0x00 /* not used with DER */ 19189251Ssam#define ASN1_TAG_BOOLEAN 0x01 20189251Ssam#define ASN1_TAG_INTEGER 0x02 21189251Ssam#define ASN1_TAG_BITSTRING 0x03 22189251Ssam#define ASN1_TAG_OCTETSTRING 0x04 23189251Ssam#define ASN1_TAG_NULL 0x05 24189251Ssam#define ASN1_TAG_OID 0x06 25189251Ssam#define ASN1_TAG_OBJECT_DESCRIPTOR 0x07 /* not yet parsed */ 26189251Ssam#define ASN1_TAG_EXTERNAL 0x08 /* not yet parsed */ 27189251Ssam#define ASN1_TAG_REAL 0x09 /* not yet parsed */ 28189251Ssam#define ASN1_TAG_ENUMERATED 0x0A /* not yet parsed */ 29189251Ssam#define ASN1_TAG_UTF8STRING 0x0C /* not yet parsed */ 30189251Ssam#define ANS1_TAG_RELATIVE_OID 0x0D 31189251Ssam#define ASN1_TAG_SEQUENCE 0x10 /* shall be constructed */ 32189251Ssam#define ASN1_TAG_SET 0x11 33189251Ssam#define ASN1_TAG_NUMERICSTRING 0x12 /* not yet parsed */ 34189251Ssam#define ASN1_TAG_PRINTABLESTRING 0x13 35189251Ssam#define ASN1_TAG_TG1STRING 0x14 /* not yet parsed */ 36189251Ssam#define ASN1_TAG_VIDEOTEXSTRING 0x15 /* not yet parsed */ 37189251Ssam#define ASN1_TAG_IA5STRING 0x16 38189251Ssam#define ASN1_TAG_UTCTIME 0x17 39189251Ssam#define ASN1_TAG_GENERALIZEDTIME 0x18 /* not yet parsed */ 40189251Ssam#define ASN1_TAG_GRAPHICSTRING 0x19 /* not yet parsed */ 41189251Ssam#define ASN1_TAG_VISIBLESTRING 0x1A 42189251Ssam#define ASN1_TAG_GENERALSTRING 0x1B /* not yet parsed */ 43189251Ssam#define ASN1_TAG_UNIVERSALSTRING 0x1C /* not yet parsed */ 44189251Ssam#define ASN1_TAG_BMPSTRING 0x1D /* not yet parsed */ 45189251Ssam 46189251Ssam#define ASN1_CLASS_UNIVERSAL 0 47189251Ssam#define ASN1_CLASS_APPLICATION 1 48189251Ssam#define ASN1_CLASS_CONTEXT_SPECIFIC 2 49189251Ssam#define ASN1_CLASS_PRIVATE 3 50189251Ssam 51189251Ssam 52189251Ssamstruct asn1_hdr { 53189251Ssam const u8 *payload; 54189251Ssam u8 identifier, class, constructed; 55189251Ssam unsigned int tag, length; 56189251Ssam}; 57189251Ssam 58189251Ssam#define ASN1_MAX_OID_LEN 20 59189251Ssamstruct asn1_oid { 60189251Ssam unsigned long oid[ASN1_MAX_OID_LEN]; 61189251Ssam size_t len; 62189251Ssam}; 63189251Ssam 64189251Ssam 65189251Ssamint asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr); 66214734Srpauloint asn1_parse_oid(const u8 *buf, size_t len, struct asn1_oid *oid); 67189251Ssamint asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid, 68189251Ssam const u8 **next); 69189251Ssamvoid asn1_oid_to_str(struct asn1_oid *oid, char *buf, size_t len); 70189251Ssamunsigned long asn1_bit_string_to_long(const u8 *buf, size_t len); 71189251Ssam 72189251Ssam#endif /* ASN1_H */ 73