Added support for TLS_FALLBACK_SCSV.
[BearSSL] / src / x509 / x509_decoder.c
1 /* Automatically generated code; do not modify directly. */
2
3 #include <stddef.h>
4 #include <stdint.h>
5
6 typedef struct {
7 uint32_t *dp;
8 uint32_t *rp;
9 const unsigned char *ip;
10 } t0_context;
11
12 static uint32_t
13 t0_parse7E_unsigned(const unsigned char **p)
14 {
15 uint32_t x;
16
17 x = 0;
18 for (;;) {
19 unsigned y;
20
21 y = *(*p) ++;
22 x = (x << 7) | (uint32_t)(y & 0x7F);
23 if (y < 0x80) {
24 return x;
25 }
26 }
27 }
28
29 static int32_t
30 t0_parse7E_signed(const unsigned char **p)
31 {
32 int neg;
33 uint32_t x;
34
35 neg = ((**p) >> 6) & 1;
36 x = (uint32_t)-neg;
37 for (;;) {
38 unsigned y;
39
40 y = *(*p) ++;
41 x = (x << 7) | (uint32_t)(y & 0x7F);
42 if (y < 0x80) {
43 if (neg) {
44 return -(int32_t)~x - 1;
45 } else {
46 return (int32_t)x;
47 }
48 }
49 }
50 }
51
52 #define T0_VBYTE(x, n) (unsigned char)((((uint32_t)(x) >> (n)) & 0x7F) | 0x80)
53 #define T0_FBYTE(x, n) (unsigned char)(((uint32_t)(x) >> (n)) & 0x7F)
54 #define T0_SBYTE(x) (unsigned char)((((uint32_t)(x) >> 28) + 0xF8) ^ 0xF8)
55 #define T0_INT1(x) T0_FBYTE(x, 0)
56 #define T0_INT2(x) T0_VBYTE(x, 7), T0_FBYTE(x, 0)
57 #define T0_INT3(x) T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
58 #define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
59 #define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
60
61 static const uint8_t t0_datablock[];
62
63
64 void br_x509_decoder_init_main(void *t0ctx);
65
66 void br_x509_decoder_run(void *t0ctx);
67
68
69
70 #include "inner.h"
71
72
73
74
75
76 #include "inner.h"
77
78 #define CTX ((br_x509_decoder_context *)((unsigned char *)t0ctx - offsetof(br_x509_decoder_context, cpu)))
79 #define CONTEXT_NAME br_x509_decoder_context
80
81 /* see bearssl_x509.h */
82 void
83 br_x509_decoder_init(br_x509_decoder_context *ctx,
84 void (*append_dn)(void *ctx, const void *buf, size_t len),
85 void *append_dn_ctx)
86 {
87 memset(ctx, 0, sizeof *ctx);
88 /* obsolete
89 ctx->err = 0;
90 ctx->hbuf = NULL;
91 ctx->hlen = 0;
92 */
93 ctx->append_dn = append_dn;
94 ctx->append_dn_ctx = append_dn_ctx;
95 ctx->cpu.dp = &ctx->dp_stack[0];
96 ctx->cpu.rp = &ctx->rp_stack[0];
97 br_x509_decoder_init_main(&ctx->cpu);
98 br_x509_decoder_run(&ctx->cpu);
99 }
100
101 /* see bearssl_x509.h */
102 void
103 br_x509_decoder_push(br_x509_decoder_context *ctx,
104 const void *data, size_t len)
105 {
106 ctx->hbuf = data;
107 ctx->hlen = len;
108 br_x509_decoder_run(&ctx->cpu);
109 }
110
111
112
113 static const uint8_t t0_datablock[] = {
114 0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x09,
115 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x09, 0x2A, 0x86,
116 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0E, 0x09, 0x2A, 0x86, 0x48, 0x86,
117 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
118 0x01, 0x01, 0x0C, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01,
119 0x0D, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x08, 0x2A, 0x86,
120 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22,
121 0x05, 0x2B, 0x81, 0x04, 0x00, 0x23, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
122 0x04, 0x01, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x01, 0x08,
123 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x08, 0x2A, 0x86, 0x48,
124 0xCE, 0x3D, 0x04, 0x03, 0x03, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04,
125 0x03, 0x04, 0x00, 0x1F, 0x03, 0xFC, 0x07, 0x7F, 0x0B, 0x5E, 0x0F, 0x1F,
126 0x12, 0xFE, 0x16, 0xBF, 0x1A, 0x9F, 0x1E, 0x7E, 0x22, 0x3F, 0x26, 0x1E,
127 0x29, 0xDF, 0x00, 0x1F, 0x03, 0xFD, 0x07, 0x9F, 0x0B, 0x7E, 0x0F, 0x3F,
128 0x13, 0x1E, 0x16, 0xDF, 0x1A, 0xBF, 0x1E, 0x9E, 0x22, 0x5F, 0x26, 0x3E,
129 0x29, 0xFF, 0x03, 0x55, 0x1D, 0x13
130 };
131
132 static const uint8_t t0_codeblock[] = {
133 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x11, 0x00, 0x00, 0x01,
134 0x01, 0x09, 0x00, 0x00, 0x01, 0x01, 0x0A, 0x00, 0x00, 0x1A, 0x1A, 0x00,
135 0x00, 0x01, T0_INT1(BR_ERR_X509_BAD_BOOLEAN), 0x00, 0x00, 0x01,
136 T0_INT1(BR_ERR_X509_BAD_TAG_CLASS), 0x00, 0x00, 0x01,
137 T0_INT1(BR_ERR_X509_BAD_TAG_VALUE), 0x00, 0x00, 0x01,
138 T0_INT1(BR_ERR_X509_BAD_TIME), 0x00, 0x00, 0x01,
139 T0_INT1(BR_ERR_X509_EXTRA_ELEMENT), 0x00, 0x00, 0x01,
140 T0_INT1(BR_ERR_X509_INDEFINITE_LENGTH), 0x00, 0x00, 0x01,
141 T0_INT1(BR_ERR_X509_INNER_TRUNC), 0x00, 0x00, 0x01,
142 T0_INT1(BR_ERR_X509_LIMIT_EXCEEDED), 0x00, 0x00, 0x01,
143 T0_INT1(BR_ERR_X509_NOT_CONSTRUCTED), 0x00, 0x00, 0x01,
144 T0_INT1(BR_ERR_X509_NOT_PRIMITIVE), 0x00, 0x00, 0x01,
145 T0_INT1(BR_ERR_X509_OVERFLOW), 0x00, 0x00, 0x01,
146 T0_INT1(BR_ERR_X509_PARTIAL_BYTE), 0x00, 0x00, 0x01,
147 T0_INT1(BR_ERR_X509_UNEXPECTED), 0x00, 0x00, 0x01,
148 T0_INT1(BR_ERR_X509_UNSUPPORTED), 0x00, 0x00, 0x01,
149 T0_INT1(BR_KEYTYPE_EC), 0x00, 0x00, 0x01, T0_INT1(BR_KEYTYPE_RSA),
150 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME, copy_dn)), 0x00, 0x00,
151 0x01, T0_INT2(offsetof(CONTEXT_NAME, decoded)), 0x00, 0x00, 0x01,
152 T0_INT2(offsetof(CONTEXT_NAME, isCA)), 0x00, 0x00, 0x01,
153 T0_INT2(offsetof(br_x509_decoder_context, pkey_data)), 0x01,
154 T0_INT2(BR_X509_BUFSIZE_KEY), 0x00, 0x00, 0x01,
155 T0_INT2(offsetof(CONTEXT_NAME, notafter_days)), 0x00, 0x00, 0x01,
156 T0_INT2(offsetof(CONTEXT_NAME, notafter_seconds)), 0x00, 0x00, 0x01,
157 T0_INT2(offsetof(CONTEXT_NAME, notbefore_days)), 0x00, 0x00, 0x01,
158 T0_INT2(offsetof(CONTEXT_NAME, notbefore_seconds)), 0x00, 0x00, 0x01,
159 T0_INT2(offsetof(CONTEXT_NAME, pad)), 0x00, 0x00, 0x01,
160 T0_INT2(offsetof(CONTEXT_NAME, signer_hash_id)), 0x00, 0x00, 0x01,
161 T0_INT2(offsetof(CONTEXT_NAME, signer_key_type)), 0x00, 0x00, 0x01,
162 0x80, 0x45, 0x00, 0x00, 0x01, 0x80, 0x4E, 0x00, 0x00, 0x01, 0x80, 0x54,
163 0x00, 0x00, 0x01, 0x81, 0x36, 0x00, 0x02, 0x03, 0x00, 0x03, 0x01, 0x1B,
164 0x02, 0x01, 0x13, 0x26, 0x02, 0x00, 0x0F, 0x15, 0x00, 0x00, 0x05, 0x02,
165 0x34, 0x1D, 0x00, 0x00, 0x06, 0x02, 0x35, 0x1D, 0x00, 0x00, 0x01, 0x10,
166 0x4F, 0x00, 0x00, 0x11, 0x05, 0x02, 0x38, 0x1D, 0x4C, 0x00, 0x00, 0x11,
167 0x05, 0x02, 0x38, 0x1D, 0x4D, 0x00, 0x00, 0x06, 0x02, 0x30, 0x1D, 0x00,
168 0x00, 0x1B, 0x19, 0x01, 0x08, 0x0E, 0x26, 0x29, 0x19, 0x09, 0x00, 0x00,
169 0x01, 0x30, 0x0A, 0x1B, 0x01, 0x00, 0x01, 0x09, 0x4B, 0x05, 0x02, 0x2F,
170 0x1D, 0x00, 0x00, 0x20, 0x20, 0x00, 0x00, 0x01, 0x80, 0x5A, 0x00, 0x00,
171 0x01, 0x80, 0x62, 0x00, 0x00, 0x01, 0x80, 0x6B, 0x00, 0x00, 0x01, 0x80,
172 0x74, 0x00, 0x00, 0x01, 0x80, 0x7D, 0x00, 0x00, 0x01, 0x3D, 0x00, 0x00,
173 0x20, 0x11, 0x06, 0x04, 0x2B, 0x6B, 0x7A, 0x71, 0x00, 0x04, 0x01, 0x00,
174 0x3D, 0x25, 0x01, 0x00, 0x3C, 0x25, 0x01, 0x87, 0xFF, 0xFF, 0x7F, 0x6D,
175 0x6D, 0x70, 0x1B, 0x01, 0x20, 0x11, 0x06, 0x11, 0x1A, 0x4C, 0x6B, 0x70,
176 0x01, 0x02, 0x50, 0x6E, 0x01, 0x02, 0x12, 0x06, 0x02, 0x39, 0x1D, 0x51,
177 0x70, 0x01, 0x02, 0x50, 0x6C, 0x6D, 0x7A, 0x6D, 0x7A, 0x6D, 0x65, 0x43,
178 0x24, 0x42, 0x24, 0x65, 0x41, 0x24, 0x40, 0x24, 0x51, 0x01, 0x01, 0x3C,
179 0x25, 0x6D, 0x7A, 0x01, 0x00, 0x3C, 0x25, 0x6D, 0x6D, 0x60, 0x05, 0x02,
180 0x39, 0x1D, 0x74, 0x1C, 0x06, 0x1C, 0x7A, 0x61, 0x6D, 0x3F, 0x68, 0x03,
181 0x00, 0x3F, 0x26, 0x02, 0x00, 0x09, 0x26, 0x02, 0x00, 0x0A, 0x68, 0x03,
182 0x01, 0x51, 0x51, 0x02, 0x00, 0x02, 0x01, 0x18, 0x04, 0x1E, 0x5A, 0x1C,
183 0x06, 0x18, 0x64, 0x03, 0x02, 0x51, 0x61, 0x1B, 0x03, 0x03, 0x1B, 0x3F,
184 0x23, 0x0D, 0x06, 0x02, 0x33, 0x1D, 0x62, 0x02, 0x02, 0x02, 0x03, 0x17,
185 0x04, 0x02, 0x39, 0x1D, 0x51, 0x01, 0x00, 0x3E, 0x25, 0x71, 0x01, 0x21,
186 0x5B, 0x01, 0x22, 0x5B, 0x1B, 0x01, 0x23, 0x11, 0x06, 0x28, 0x1A, 0x4C,
187 0x6B, 0x6D, 0x1B, 0x06, 0x1D, 0x6D, 0x60, 0x1A, 0x70, 0x1B, 0x01, 0x01,
188 0x11, 0x06, 0x03, 0x63, 0x1A, 0x70, 0x01, 0x04, 0x50, 0x6B, 0x4A, 0x1C,
189 0x06, 0x03, 0x5F, 0x04, 0x01, 0x7B, 0x51, 0x51, 0x04, 0x60, 0x51, 0x51,
190 0x04, 0x08, 0x01, 0x7F, 0x11, 0x05, 0x02, 0x38, 0x1D, 0x1A, 0x51, 0x6D,
191 0x60, 0x06, 0x80, 0x63, 0x75, 0x1C, 0x06, 0x06, 0x01, 0x02, 0x3B, 0x04,
192 0x80, 0x57, 0x76, 0x1C, 0x06, 0x06, 0x01, 0x03, 0x3B, 0x04, 0x80, 0x4D,
193 0x77, 0x1C, 0x06, 0x06, 0x01, 0x04, 0x3B, 0x04, 0x80, 0x43, 0x78, 0x1C,
194 0x06, 0x05, 0x01, 0x05, 0x3B, 0x04, 0x3A, 0x79, 0x1C, 0x06, 0x05, 0x01,
195 0x06, 0x3B, 0x04, 0x31, 0x55, 0x1C, 0x06, 0x05, 0x01, 0x02, 0x3A, 0x04,
196 0x28, 0x56, 0x1C, 0x06, 0x05, 0x01, 0x03, 0x3A, 0x04, 0x1F, 0x57, 0x1C,
197 0x06, 0x05, 0x01, 0x04, 0x3A, 0x04, 0x16, 0x58, 0x1C, 0x06, 0x05, 0x01,
198 0x05, 0x3A, 0x04, 0x0D, 0x59, 0x1C, 0x06, 0x05, 0x01, 0x06, 0x3A, 0x04,
199 0x04, 0x01, 0x00, 0x01, 0x00, 0x04, 0x04, 0x01, 0x00, 0x01, 0x00, 0x46,
200 0x25, 0x45, 0x25, 0x7A, 0x61, 0x7A, 0x51, 0x1A, 0x01, 0x01, 0x3D, 0x25,
201 0x73, 0x30, 0x1D, 0x00, 0x00, 0x01, 0x81, 0x06, 0x00, 0x01, 0x54, 0x0D,
202 0x06, 0x02, 0x32, 0x1D, 0x1B, 0x03, 0x00, 0x0A, 0x02, 0x00, 0x00, 0x00,
203 0x6D, 0x71, 0x1B, 0x01, 0x01, 0x11, 0x06, 0x08, 0x63, 0x01, 0x01, 0x15,
204 0x3E, 0x25, 0x04, 0x01, 0x2B, 0x7A, 0x00, 0x00, 0x70, 0x01, 0x06, 0x50,
205 0x6F, 0x00, 0x00, 0x70, 0x01, 0x03, 0x50, 0x6B, 0x72, 0x06, 0x02, 0x37,
206 0x1D, 0x00, 0x00, 0x26, 0x1B, 0x06, 0x07, 0x21, 0x1B, 0x06, 0x01, 0x16,
207 0x04, 0x76, 0x2B, 0x00, 0x00, 0x01, 0x01, 0x50, 0x6A, 0x01, 0x01, 0x10,
208 0x06, 0x02, 0x2C, 0x1D, 0x72, 0x27, 0x00, 0x00, 0x60, 0x05, 0x02, 0x39,
209 0x1D, 0x47, 0x1C, 0x06, 0x04, 0x01, 0x17, 0x04, 0x12, 0x48, 0x1C, 0x06,
210 0x04, 0x01, 0x18, 0x04, 0x0A, 0x49, 0x1C, 0x06, 0x04, 0x01, 0x19, 0x04,
211 0x02, 0x39, 0x1D, 0x00, 0x04, 0x70, 0x1B, 0x01, 0x17, 0x01, 0x18, 0x4B,
212 0x05, 0x02, 0x2F, 0x1D, 0x01, 0x18, 0x11, 0x03, 0x00, 0x4D, 0x6B, 0x66,
213 0x02, 0x00, 0x06, 0x0C, 0x01, 0x80, 0x64, 0x08, 0x03, 0x01, 0x66, 0x02,
214 0x01, 0x09, 0x04, 0x0E, 0x1B, 0x01, 0x32, 0x0D, 0x06, 0x04, 0x01, 0x80,
215 0x64, 0x09, 0x01, 0x8E, 0x6C, 0x09, 0x03, 0x01, 0x02, 0x01, 0x01, 0x82,
216 0x6D, 0x08, 0x02, 0x01, 0x01, 0x03, 0x09, 0x01, 0x04, 0x0C, 0x09, 0x02,
217 0x01, 0x01, 0x80, 0x63, 0x09, 0x01, 0x80, 0x64, 0x0C, 0x0A, 0x02, 0x01,
218 0x01, 0x83, 0x0F, 0x09, 0x01, 0x83, 0x10, 0x0C, 0x09, 0x03, 0x03, 0x01,
219 0x01, 0x01, 0x0C, 0x67, 0x2A, 0x01, 0x01, 0x0E, 0x02, 0x01, 0x01, 0x04,
220 0x07, 0x28, 0x02, 0x01, 0x01, 0x80, 0x64, 0x07, 0x27, 0x02, 0x01, 0x01,
221 0x83, 0x10, 0x07, 0x28, 0x1F, 0x15, 0x06, 0x03, 0x01, 0x18, 0x09, 0x5D,
222 0x09, 0x52, 0x1B, 0x01, 0x05, 0x14, 0x02, 0x03, 0x09, 0x03, 0x03, 0x01,
223 0x1F, 0x15, 0x01, 0x01, 0x26, 0x67, 0x02, 0x03, 0x09, 0x2A, 0x03, 0x03,
224 0x01, 0x00, 0x01, 0x17, 0x67, 0x01, 0x9C, 0x10, 0x08, 0x03, 0x02, 0x01,
225 0x00, 0x01, 0x3B, 0x67, 0x01, 0x3C, 0x08, 0x02, 0x02, 0x09, 0x03, 0x02,
226 0x01, 0x00, 0x01, 0x3C, 0x67, 0x02, 0x02, 0x09, 0x03, 0x02, 0x72, 0x1B,
227 0x01, 0x2E, 0x11, 0x06, 0x0D, 0x1A, 0x72, 0x1B, 0x01, 0x30, 0x01, 0x39,
228 0x4B, 0x06, 0x03, 0x1A, 0x04, 0x74, 0x01, 0x80, 0x5A, 0x10, 0x06, 0x02,
229 0x2F, 0x1D, 0x51, 0x02, 0x03, 0x02, 0x02, 0x00, 0x01, 0x72, 0x53, 0x01,
230 0x0A, 0x08, 0x03, 0x00, 0x72, 0x53, 0x02, 0x00, 0x09, 0x00, 0x02, 0x03,
231 0x00, 0x03, 0x01, 0x66, 0x1B, 0x02, 0x01, 0x02, 0x00, 0x4B, 0x05, 0x02,
232 0x2F, 0x1D, 0x00, 0x00, 0x23, 0x70, 0x01, 0x02, 0x50, 0x0B, 0x69, 0x00,
233 0x03, 0x1B, 0x03, 0x00, 0x03, 0x01, 0x03, 0x02, 0x6B, 0x72, 0x1B, 0x01,
234 0x81, 0x00, 0x13, 0x06, 0x02, 0x36, 0x1D, 0x1B, 0x01, 0x00, 0x11, 0x06,
235 0x0B, 0x1A, 0x1B, 0x05, 0x04, 0x1A, 0x01, 0x00, 0x00, 0x72, 0x04, 0x6F,
236 0x02, 0x01, 0x1B, 0x05, 0x02, 0x33, 0x1D, 0x2A, 0x03, 0x01, 0x02, 0x02,
237 0x25, 0x02, 0x02, 0x29, 0x03, 0x02, 0x1B, 0x06, 0x03, 0x72, 0x04, 0x68,
238 0x1A, 0x02, 0x00, 0x02, 0x01, 0x0A, 0x00, 0x01, 0x72, 0x1B, 0x01, 0x81,
239 0x00, 0x0D, 0x06, 0x01, 0x00, 0x01, 0x81, 0x00, 0x0A, 0x1B, 0x05, 0x02,
240 0x31, 0x1D, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x12, 0x06,
241 0x19, 0x02, 0x00, 0x2A, 0x03, 0x00, 0x1B, 0x01, 0x87, 0xFF, 0xFF, 0x7F,
242 0x12, 0x06, 0x02, 0x32, 0x1D, 0x01, 0x08, 0x0E, 0x26, 0x72, 0x23, 0x09,
243 0x04, 0x60, 0x00, 0x00, 0x6A, 0x5E, 0x00, 0x00, 0x6B, 0x7A, 0x00, 0x00,
244 0x70, 0x4E, 0x6B, 0x00, 0x01, 0x6B, 0x1B, 0x05, 0x02, 0x36, 0x1D, 0x72,
245 0x1B, 0x01, 0x81, 0x00, 0x13, 0x06, 0x02, 0x36, 0x1D, 0x03, 0x00, 0x1B,
246 0x06, 0x16, 0x72, 0x02, 0x00, 0x1B, 0x01, 0x87, 0xFF, 0xFF, 0x7F, 0x13,
247 0x06, 0x02, 0x36, 0x1D, 0x01, 0x08, 0x0E, 0x09, 0x03, 0x00, 0x04, 0x67,
248 0x1A, 0x02, 0x00, 0x00, 0x00, 0x6B, 0x1B, 0x01, 0x81, 0x7F, 0x12, 0x06,
249 0x08, 0x7A, 0x01, 0x00, 0x44, 0x25, 0x01, 0x00, 0x00, 0x1B, 0x44, 0x25,
250 0x44, 0x29, 0x62, 0x01, 0x7F, 0x00, 0x01, 0x72, 0x03, 0x00, 0x02, 0x00,
251 0x01, 0x05, 0x14, 0x01, 0x01, 0x15, 0x1E, 0x02, 0x00, 0x01, 0x06, 0x14,
252 0x1B, 0x01, 0x01, 0x15, 0x06, 0x02, 0x2D, 0x1D, 0x01, 0x04, 0x0E, 0x02,
253 0x00, 0x01, 0x1F, 0x15, 0x1B, 0x01, 0x1F, 0x11, 0x06, 0x02, 0x2E, 0x1D,
254 0x09, 0x00, 0x00, 0x1B, 0x05, 0x05, 0x01, 0x00, 0x01, 0x7F, 0x00, 0x70,
255 0x00, 0x00, 0x1B, 0x05, 0x02, 0x32, 0x1D, 0x2A, 0x73, 0x00, 0x00, 0x22,
256 0x1B, 0x01, 0x00, 0x13, 0x06, 0x01, 0x00, 0x1A, 0x16, 0x04, 0x74, 0x00,
257 0x01, 0x01, 0x00, 0x00, 0x01, 0x0B, 0x00, 0x00, 0x01, 0x15, 0x00, 0x00,
258 0x01, 0x1F, 0x00, 0x00, 0x01, 0x29, 0x00, 0x00, 0x01, 0x33, 0x00, 0x00,
259 0x7B, 0x1A, 0x00, 0x00, 0x1B, 0x06, 0x07, 0x7C, 0x1B, 0x06, 0x01, 0x16,
260 0x04, 0x76, 0x00, 0x00, 0x01, 0x00, 0x20, 0x21, 0x0B, 0x2B, 0x00
261 };
262
263 static const uint16_t t0_caddr[] = {
264 0,
265 5,
266 10,
267 15,
268 20,
269 24,
270 28,
271 32,
272 36,
273 40,
274 44,
275 48,
276 52,
277 56,
278 60,
279 64,
280 68,
281 72,
282 76,
283 80,
284 84,
285 88,
286 93,
287 98,
288 103,
289 111,
290 116,
291 121,
292 126,
293 131,
294 136,
295 141,
296 146,
297 151,
298 156,
299 161,
300 166,
301 181,
302 187,
303 193,
304 198,
305 206,
306 214,
307 220,
308 231,
309 246,
310 250,
311 255,
312 260,
313 265,
314 270,
315 275,
316 279,
317 289,
318 620,
319 625,
320 639,
321 659,
322 666,
323 678,
324 692,
325 707,
326 740,
327 960,
328 974,
329 991,
330 1000,
331 1067,
332 1123,
333 1127,
334 1131,
335 1136,
336 1184,
337 1210,
338 1254,
339 1265,
340 1274,
341 1287,
342 1291,
343 1295,
344 1299,
345 1303,
346 1307,
347 1311,
348 1315,
349 1327
350 };
351
352 #define T0_INTERPRETED 39
353
354 #define T0_ENTER(ip, rp, slot) do { \
355 const unsigned char *t0_newip; \
356 uint32_t t0_lnum; \
357 t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \
358 t0_lnum = t0_parse7E_unsigned(&t0_newip); \
359 (rp) += t0_lnum; \
360 *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \
361 (ip) = t0_newip; \
362 } while (0)
363
364 #define T0_DEFENTRY(name, slot) \
365 void \
366 name(void *ctx) \
367 { \
368 t0_context *t0ctx = ctx; \
369 t0ctx->ip = &t0_codeblock[0]; \
370 T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \
371 }
372
373 T0_DEFENTRY(br_x509_decoder_init_main, 92)
374
375 void
376 br_x509_decoder_run(void *t0ctx)
377 {
378 uint32_t *dp, *rp;
379 const unsigned char *ip;
380
381 #define T0_LOCAL(x) (*(rp - 2 - (x)))
382 #define T0_POP() (*-- dp)
383 #define T0_POPi() (*(int32_t *)(-- dp))
384 #define T0_PEEK(x) (*(dp - 1 - (x)))
385 #define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x)))
386 #define T0_PUSH(v) do { *dp = (v); dp ++; } while (0)
387 #define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0)
388 #define T0_RPOP() (*-- rp)
389 #define T0_RPOPi() (*(int32_t *)(-- rp))
390 #define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0)
391 #define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0)
392 #define T0_ROLL(x) do { \
393 size_t t0len = (size_t)(x); \
394 uint32_t t0tmp = *(dp - 1 - t0len); \
395 memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \
396 *(dp - 1) = t0tmp; \
397 } while (0)
398 #define T0_SWAP() do { \
399 uint32_t t0tmp = *(dp - 2); \
400 *(dp - 2) = *(dp - 1); \
401 *(dp - 1) = t0tmp; \
402 } while (0)
403 #define T0_ROT() do { \
404 uint32_t t0tmp = *(dp - 3); \
405 *(dp - 3) = *(dp - 2); \
406 *(dp - 2) = *(dp - 1); \
407 *(dp - 1) = t0tmp; \
408 } while (0)
409 #define T0_NROT() do { \
410 uint32_t t0tmp = *(dp - 1); \
411 *(dp - 1) = *(dp - 2); \
412 *(dp - 2) = *(dp - 3); \
413 *(dp - 3) = t0tmp; \
414 } while (0)
415 #define T0_PICK(x) do { \
416 uint32_t t0depth = (x); \
417 T0_PUSH(T0_PEEK(t0depth)); \
418 } while (0)
419 #define T0_CO() do { \
420 goto t0_exit; \
421 } while (0)
422 #define T0_RET() break
423
424 dp = ((t0_context *)t0ctx)->dp;
425 rp = ((t0_context *)t0ctx)->rp;
426 ip = ((t0_context *)t0ctx)->ip;
427 for (;;) {
428 uint32_t t0x;
429
430 t0x = t0_parse7E_unsigned(&ip);
431 if (t0x < T0_INTERPRETED) {
432 switch (t0x) {
433 int32_t t0off;
434
435 case 0: /* ret */
436 t0x = T0_RPOP();
437 rp -= (t0x >> 16);
438 t0x &= 0xFFFF;
439 if (t0x == 0) {
440 ip = NULL;
441 goto t0_exit;
442 }
443 ip = &t0_codeblock[t0x];
444 break;
445 case 1: /* literal constant */
446 T0_PUSHi(t0_parse7E_signed(&ip));
447 break;
448 case 2: /* read local */
449 T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip)));
450 break;
451 case 3: /* write local */
452 T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP();
453 break;
454 case 4: /* jump */
455 t0off = t0_parse7E_signed(&ip);
456 ip += t0off;
457 break;
458 case 5: /* jump if */
459 t0off = t0_parse7E_signed(&ip);
460 if (T0_POP()) {
461 ip += t0off;
462 }
463 break;
464 case 6: /* jump if not */
465 t0off = t0_parse7E_signed(&ip);
466 if (!T0_POP()) {
467 ip += t0off;
468 }
469 break;
470 case 7: {
471 /* %25 */
472
473 int32_t b = T0_POPi();
474 int32_t a = T0_POPi();
475 T0_PUSHi(a % b);
476
477 }
478 break;
479 case 8: {
480 /* * */
481
482 uint32_t b = T0_POP();
483 uint32_t a = T0_POP();
484 T0_PUSH(a * b);
485
486 }
487 break;
488 case 9: {
489 /* + */
490
491 uint32_t b = T0_POP();
492 uint32_t a = T0_POP();
493 T0_PUSH(a + b);
494
495 }
496 break;
497 case 10: {
498 /* - */
499
500 uint32_t b = T0_POP();
501 uint32_t a = T0_POP();
502 T0_PUSH(a - b);
503
504 }
505 break;
506 case 11: {
507 /* -rot */
508 T0_NROT();
509 }
510 break;
511 case 12: {
512 /* / */
513
514 int32_t b = T0_POPi();
515 int32_t a = T0_POPi();
516 T0_PUSHi(a / b);
517
518 }
519 break;
520 case 13: {
521 /* < */
522
523 int32_t b = T0_POPi();
524 int32_t a = T0_POPi();
525 T0_PUSH(-(uint32_t)(a < b));
526
527 }
528 break;
529 case 14: {
530 /* << */
531
532 int c = (int)T0_POPi();
533 uint32_t x = T0_POP();
534 T0_PUSH(x << c);
535
536 }
537 break;
538 case 15: {
539 /* <= */
540
541 int32_t b = T0_POPi();
542 int32_t a = T0_POPi();
543 T0_PUSH(-(uint32_t)(a <= b));
544
545 }
546 break;
547 case 16: {
548 /* <> */
549
550 uint32_t b = T0_POP();
551 uint32_t a = T0_POP();
552 T0_PUSH(-(uint32_t)(a != b));
553
554 }
555 break;
556 case 17: {
557 /* = */
558
559 uint32_t b = T0_POP();
560 uint32_t a = T0_POP();
561 T0_PUSH(-(uint32_t)(a == b));
562
563 }
564 break;
565 case 18: {
566 /* > */
567
568 int32_t b = T0_POPi();
569 int32_t a = T0_POPi();
570 T0_PUSH(-(uint32_t)(a > b));
571
572 }
573 break;
574 case 19: {
575 /* >= */
576
577 int32_t b = T0_POPi();
578 int32_t a = T0_POPi();
579 T0_PUSH(-(uint32_t)(a >= b));
580
581 }
582 break;
583 case 20: {
584 /* >> */
585
586 int c = (int)T0_POPi();
587 int32_t x = T0_POPi();
588 T0_PUSHi(x >> c);
589
590 }
591 break;
592 case 21: {
593 /* and */
594
595 uint32_t b = T0_POP();
596 uint32_t a = T0_POP();
597 T0_PUSH(a & b);
598
599 }
600 break;
601 case 22: {
602 /* co */
603 T0_CO();
604 }
605 break;
606 case 23: {
607 /* copy-ec-pkey */
608
609 size_t qlen = T0_POP();
610 uint32_t curve = T0_POP();
611 CTX->pkey.key_type = BR_KEYTYPE_EC;
612 CTX->pkey.key.ec.curve = curve;
613 CTX->pkey.key.ec.q = CTX->pkey_data;
614 CTX->pkey.key.ec.qlen = qlen;
615
616 }
617 break;
618 case 24: {
619 /* copy-rsa-pkey */
620
621 size_t elen = T0_POP();
622 size_t nlen = T0_POP();
623 CTX->pkey.key_type = BR_KEYTYPE_RSA;
624 CTX->pkey.key.rsa.n = CTX->pkey_data;
625 CTX->pkey.key.rsa.nlen = nlen;
626 CTX->pkey.key.rsa.e = CTX->pkey_data + nlen;
627 CTX->pkey.key.rsa.elen = elen;
628
629 }
630 break;
631 case 25: {
632 /* data-get8 */
633
634 size_t addr = T0_POP();
635 T0_PUSH(t0_datablock[addr]);
636
637 }
638 break;
639 case 26: {
640 /* drop */
641 (void)T0_POP();
642 }
643 break;
644 case 27: {
645 /* dup */
646 T0_PUSH(T0_PEEK(0));
647 }
648 break;
649 case 28: {
650 /* eqOID */
651
652 const unsigned char *a2 = &t0_datablock[T0_POP()];
653 const unsigned char *a1 = &CTX->pad[0];
654 size_t len = a1[0];
655 int x;
656 if (len == a2[0]) {
657 x = -(memcmp(a1 + 1, a2 + 1, len) == 0);
658 } else {
659 x = 0;
660 }
661 T0_PUSH((uint32_t)x);
662
663 }
664 break;
665 case 29: {
666 /* fail */
667
668 CTX->err = T0_POPi();
669 T0_CO();
670
671 }
672 break;
673 case 30: {
674 /* neg */
675
676 uint32_t a = T0_POP();
677 T0_PUSH(-a);
678
679 }
680 break;
681 case 31: {
682 /* or */
683
684 uint32_t b = T0_POP();
685 uint32_t a = T0_POP();
686 T0_PUSH(a | b);
687
688 }
689 break;
690 case 32: {
691 /* over */
692 T0_PUSH(T0_PEEK(1));
693 }
694 break;
695 case 33: {
696 /* read-blob-inner */
697
698 uint32_t len = T0_POP();
699 uint32_t addr = T0_POP();
700 size_t clen = CTX->hlen;
701 if (clen > len) {
702 clen = (size_t)len;
703 }
704 if (addr != 0) {
705 memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen);
706 }
707 if (CTX->copy_dn && CTX->append_dn) {
708 CTX->append_dn(CTX->append_dn_ctx, CTX->hbuf, clen);
709 }
710 CTX->hbuf += clen;
711 CTX->hlen -= clen;
712 T0_PUSH(addr + clen);
713 T0_PUSH(len - clen);
714
715 }
716 break;
717 case 34: {
718 /* read8-low */
719
720 if (CTX->hlen == 0) {
721 T0_PUSHi(-1);
722 } else {
723 unsigned char x = *CTX->hbuf ++;
724 if (CTX->copy_dn && CTX->append_dn) {
725 CTX->append_dn(CTX->append_dn_ctx, &x, 1);
726 }
727 CTX->hlen --;
728 T0_PUSH(x);
729 }
730
731 }
732 break;
733 case 35: {
734 /* rot */
735 T0_ROT();
736 }
737 break;
738 case 36: {
739 /* set32 */
740
741 uint32_t addr = T0_POP();
742 *(uint32_t *)((unsigned char *)CTX + addr) = T0_POP();
743
744 }
745 break;
746 case 37: {
747 /* set8 */
748
749 uint32_t addr = T0_POP();
750 *((unsigned char *)CTX + addr) = (unsigned char)T0_POP();
751
752 }
753 break;
754 case 38: {
755 /* swap */
756 T0_SWAP();
757 }
758 break;
759 }
760
761 } else {
762 T0_ENTER(ip, rp, t0x);
763 }
764 }
765 t0_exit:
766 ((t0_context *)t0ctx)->dp = dp;
767 ((t0_context *)t0ctx)->rp = rp;
768 ((t0_context *)t0ctx)->ip = ip;
769 }