asn1.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef ASN1_H
  9. #define ASN1_H
  10. #define ASN1_TAG_EOC 0x00 /* not used with DER */
  11. #define ASN1_TAG_BOOLEAN 0x01
  12. #define ASN1_TAG_INTEGER 0x02
  13. #define ASN1_TAG_BITSTRING 0x03
  14. #define ASN1_TAG_OCTETSTRING 0x04
  15. #define ASN1_TAG_NULL 0x05
  16. #define ASN1_TAG_OID 0x06
  17. #define ASN1_TAG_OBJECT_DESCRIPTOR 0x07 /* not yet parsed */
  18. #define ASN1_TAG_EXTERNAL 0x08 /* not yet parsed */
  19. #define ASN1_TAG_REAL 0x09 /* not yet parsed */
  20. #define ASN1_TAG_ENUMERATED 0x0A /* not yet parsed */
  21. #define ASN1_TAG_EMBEDDED_PDV 0x0B /* not yet parsed */
  22. #define ASN1_TAG_UTF8STRING 0x0C /* not yet parsed */
  23. #define ANS1_TAG_RELATIVE_OID 0x0D
  24. #define ASN1_TAG_SEQUENCE 0x10 /* shall be constructed */
  25. #define ASN1_TAG_SET 0x11
  26. #define ASN1_TAG_NUMERICSTRING 0x12 /* not yet parsed */
  27. #define ASN1_TAG_PRINTABLESTRING 0x13
  28. #define ASN1_TAG_TG1STRING 0x14 /* not yet parsed */
  29. #define ASN1_TAG_VIDEOTEXSTRING 0x15 /* not yet parsed */
  30. #define ASN1_TAG_IA5STRING 0x16
  31. #define ASN1_TAG_UTCTIME 0x17
  32. #define ASN1_TAG_GENERALIZEDTIME 0x18 /* not yet parsed */
  33. #define ASN1_TAG_GRAPHICSTRING 0x19 /* not yet parsed */
  34. #define ASN1_TAG_VISIBLESTRING 0x1A
  35. #define ASN1_TAG_GENERALSTRING 0x1B /* not yet parsed */
  36. #define ASN1_TAG_UNIVERSALSTRING 0x1C /* not yet parsed */
  37. #define ASN1_TAG_CHARACTERSTRING 0x1D /* not yet parsed */
  38. #define ASN1_TAG_BMPSTRING 0x1E /* not yet parsed */
  39. #define ASN1_CLASS_UNIVERSAL 0
  40. #define ASN1_CLASS_APPLICATION 1
  41. #define ASN1_CLASS_CONTEXT_SPECIFIC 2
  42. #define ASN1_CLASS_PRIVATE 3
  43. struct asn1_hdr {
  44. const u8 *payload;
  45. u8 identifier, class, constructed;
  46. unsigned int tag, length;
  47. };
  48. #define ASN1_MAX_OID_LEN 20
  49. struct asn1_oid {
  50. unsigned long oid[ASN1_MAX_OID_LEN];
  51. size_t len;
  52. };
  53. int asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr);
  54. int asn1_parse_oid(const u8 *buf, size_t len, struct asn1_oid *oid);
  55. int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
  56. const u8 **next);
  57. void asn1_oid_to_str(const struct asn1_oid *oid, char *buf, size_t len);
  58. unsigned long asn1_bit_string_to_long(const u8 *buf, size_t len);
  59. int asn1_oid_equal(const struct asn1_oid *a, const struct asn1_oid *b);
  60. extern struct asn1_oid asn1_sha1_oid;
  61. extern struct asn1_oid asn1_sha256_oid;
  62. #endif /* ASN1_H */