1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6   @file der_asn1_maps.c
7   ASN.1 DER, a collection of maps to convert between different representations, Steffen Jaeckel
8 */
9 
10 #ifdef LTC_DER
11 
12 /**
13   A Map from ltc_asn1_type to the regularly used ASN.1 identifier
14 */
15 const int der_asn1_type_to_identifier_map[] =
16 {
17      /*  0 */
18  -1, /* LTC_ASN1_EOL, */
19   1, /* LTC_ASN1_BOOLEAN, */
20   2, /* LTC_ASN1_INTEGER, */
21   2, /* LTC_ASN1_SHORT_INTEGER, */
22   3, /* LTC_ASN1_BIT_STRING, */
23      /*  5 */
24   4, /* LTC_ASN1_OCTET_STRING, */
25   5, /* LTC_ASN1_NULL, */
26   6, /* LTC_ASN1_OBJECT_IDENTIFIER, */
27  22, /* LTC_ASN1_IA5_STRING, */
28  19, /* LTC_ASN1_PRINTABLE_STRING, */
29      /* 10 */
30  12, /* LTC_ASN1_UTF8_STRING, */
31  23, /* LTC_ASN1_UTCTIME, */
32  -1, /* LTC_ASN1_CHOICE, */
33  48, /* LTC_ASN1_SEQUENCE, */
34  49, /* LTC_ASN1_SET, */
35      /* 15 */
36  49, /* LTC_ASN1_SETOF, */
37   3, /* LTC_ASN1_RAW_BIT_STRING, */
38  20, /* LTC_ASN1_TELETEX_STRING, */
39  24, /* LTC_ASN1_GENERALIZEDTIME, */
40  -1, /* LTC_ASN1_CUSTOM_TYPE, */
41 };
42 const unsigned long der_asn1_type_to_identifier_map_sz = sizeof(der_asn1_type_to_identifier_map)/sizeof(der_asn1_type_to_identifier_map[0]);
43 
44 /**
45   A Map from the ASN.1 Class to its string
46 */
47 const char* der_asn1_class_to_string_map[] =
48 {
49   "UNIVERSAL",
50   "APPLICATION",
51   "CONTEXT-SPECIFIC",
52   "PRIVATE",
53 };
54 const unsigned long der_asn1_class_to_string_map_sz = sizeof(der_asn1_class_to_string_map)/sizeof(der_asn1_class_to_string_map[0]);
55 
56 /**
57   A Map from the ASN.1 P/C-bit to its string
58 */
59 const char* der_asn1_pc_to_string_map[] =
60 {
61   "PRIMITIVE",
62   "CONSTRUCTED",
63 };
64 const unsigned long der_asn1_pc_to_string_map_sz = sizeof(der_asn1_pc_to_string_map)/sizeof(der_asn1_pc_to_string_map[0]);
65 
66 /**
67   A Map from the ASN.1 tag to its string
68 */
69 const char* der_asn1_tag_to_string_map[] =
70 {
71   "Reserved for use by the encoding rules",
72   "Boolean type",
73   "Integer type",
74   "Bitstring type",
75   "Octetstring type",
76   "Null type",
77   "Object identifier type",
78   "Object descriptor type",
79   "External type and Instance-of type",
80   "Real type",
81   "Enumerated type",
82   "Embedded-pdv type",
83   "UTF8String type",
84   "Relative object identifier type",
85   "The time type",
86   "Reserved for future editions of this Recommendation | International Standard",
87   "Sequence and Sequence-of types",
88   "Set and Set-of types",
89   "NumericString type",
90   "PrintableString type",
91   "TeletexString (T61String) type",
92   "VideotexString type",
93   "IA5String type",
94   "UTCTime type",
95   "GeneralizedTime type",
96   "GraphicString type",
97   "VisibleString (ISO646String) type",
98   "GeneralString type",
99   "UniversalString type",
100   "UnrestrictedCharacterString type",
101   "BMPString type",
102   "Date type",
103   "TimeOfDay type",
104   "DateTime type",
105   "Duration type",
106   "OID internationalized resource identifier type",
107   "Relative OID internationalized resource identifier type",
108 };
109 const unsigned long der_asn1_tag_to_string_map_sz = sizeof(der_asn1_tag_to_string_map)/sizeof(der_asn1_tag_to_string_map[0]);
110 
111 /**
112   A Map from ASN.1 Tags to ltc_asn1_type
113 */
114 const ltc_asn1_type der_asn1_tag_to_type_map[] =
115 {
116   /*  0 */
117   LTC_ASN1_EOL,               /* Reserved for use by the encoding rules */
118   LTC_ASN1_BOOLEAN,           /* Boolean type */
119   LTC_ASN1_INTEGER,           /* Integer type */
120   LTC_ASN1_BIT_STRING,        /* Bitstring type */
121   LTC_ASN1_OCTET_STRING,      /* Octetstring type */
122   /*  5 */
123   LTC_ASN1_NULL,              /* Null type */
124   LTC_ASN1_OBJECT_IDENTIFIER, /* Object identifier type */
125   LTC_ASN1_CUSTOM_TYPE,      /* Object descriptor type */
126   LTC_ASN1_CUSTOM_TYPE,      /* External type and Instance-of type */
127   LTC_ASN1_CUSTOM_TYPE,      /* Real type */
128   /* 10 */
129   LTC_ASN1_CUSTOM_TYPE,      /* Enumerated type */
130   LTC_ASN1_CUSTOM_TYPE,      /* Embedded-pdv type */
131   LTC_ASN1_UTF8_STRING,       /* UTF8String type */
132   LTC_ASN1_CUSTOM_TYPE,      /* Relative object identifier type */
133   LTC_ASN1_CUSTOM_TYPE,      /* The time type */
134   /* 15 */
135   LTC_ASN1_EOL,               /* Reserved for future editions of this Recommendation | International Standard */
136   LTC_ASN1_SEQUENCE,          /* Sequence and Sequence-of types */
137   LTC_ASN1_SET,               /* Set and Set-of types */
138   LTC_ASN1_CUSTOM_TYPE,      /* NumericString types */
139   LTC_ASN1_PRINTABLE_STRING,  /* PrintableString types */
140   /* 20 */
141   LTC_ASN1_TELETEX_STRING,    /* TeletexString (T61String) types */
142   LTC_ASN1_CUSTOM_TYPE,      /* VideotexString types */
143   LTC_ASN1_IA5_STRING,        /* IA5String types */
144   LTC_ASN1_UTCTIME,           /* UTCTime types */
145   LTC_ASN1_GENERALIZEDTIME,   /* GeneralizedTime types */
146   /* 25 */
147   LTC_ASN1_CUSTOM_TYPE,      /* GraphicString types */
148   LTC_ASN1_CUSTOM_TYPE,      /* VisibleString (ISO646String) types */
149   LTC_ASN1_CUSTOM_TYPE,      /* GeneralString types */
150   LTC_ASN1_CUSTOM_TYPE,      /* UniversalString types */
151   LTC_ASN1_CUSTOM_TYPE,      /* UnrestrictedCharacterString types */
152   /* 30 */
153   LTC_ASN1_CUSTOM_TYPE,      /* BMPString types */
154 };
155 const unsigned long der_asn1_tag_to_type_map_sz = sizeof(der_asn1_tag_to_type_map)/sizeof(der_asn1_tag_to_type_map[0]);
156 
157 #endif
158