xref: /freebsd/contrib/bearssl/src/x509/x509_decoder.c (revision 2aaf9152a852aba9eb2036b95f4948ee77988826)
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
t0_parse7E_unsigned(const unsigned char ** p)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
t0_parse7E_signed(const unsigned char ** p)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 unsigned char 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 *)(void *)((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
br_x509_decoder_init(br_x509_decoder_context * ctx,void (* append_dn)(void * ctx,const void * buf,size_t len),void * append_dn_ctx)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
br_x509_decoder_push(br_x509_decoder_context * ctx,const void * data,size_t len)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 unsigned char 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 unsigned char 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, 0x83, 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 #define T0_NEXT(t0ipp)   (*(*(t0ipp)) ++)
376 
377 void
br_x509_decoder_run(void * t0ctx)378 br_x509_decoder_run(void *t0ctx)
379 {
380 	uint32_t *dp, *rp;
381 	const unsigned char *ip;
382 
383 #define T0_LOCAL(x)    (*(rp - 2 - (x)))
384 #define T0_POP()       (*-- dp)
385 #define T0_POPi()      (*(int32_t *)(-- dp))
386 #define T0_PEEK(x)     (*(dp - 1 - (x)))
387 #define T0_PEEKi(x)    (*(int32_t *)(dp - 1 - (x)))
388 #define T0_PUSH(v)     do { *dp = (v); dp ++; } while (0)
389 #define T0_PUSHi(v)    do { *(int32_t *)dp = (v); dp ++; } while (0)
390 #define T0_RPOP()      (*-- rp)
391 #define T0_RPOPi()     (*(int32_t *)(-- rp))
392 #define T0_RPUSH(v)    do { *rp = (v); rp ++; } while (0)
393 #define T0_RPUSHi(v)   do { *(int32_t *)rp = (v); rp ++; } while (0)
394 #define T0_ROLL(x)     do { \
395 	size_t t0len = (size_t)(x); \
396 	uint32_t t0tmp = *(dp - 1 - t0len); \
397 	memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \
398 	*(dp - 1) = t0tmp; \
399 } while (0)
400 #define T0_SWAP()      do { \
401 	uint32_t t0tmp = *(dp - 2); \
402 	*(dp - 2) = *(dp - 1); \
403 	*(dp - 1) = t0tmp; \
404 } while (0)
405 #define T0_ROT()       do { \
406 	uint32_t t0tmp = *(dp - 3); \
407 	*(dp - 3) = *(dp - 2); \
408 	*(dp - 2) = *(dp - 1); \
409 	*(dp - 1) = t0tmp; \
410 } while (0)
411 #define T0_NROT()       do { \
412 	uint32_t t0tmp = *(dp - 1); \
413 	*(dp - 1) = *(dp - 2); \
414 	*(dp - 2) = *(dp - 3); \
415 	*(dp - 3) = t0tmp; \
416 } while (0)
417 #define T0_PICK(x)      do { \
418 	uint32_t t0depth = (x); \
419 	T0_PUSH(T0_PEEK(t0depth)); \
420 } while (0)
421 #define T0_CO()         do { \
422 	goto t0_exit; \
423 } while (0)
424 #define T0_RET()        goto t0_next
425 
426 	dp = ((t0_context *)t0ctx)->dp;
427 	rp = ((t0_context *)t0ctx)->rp;
428 	ip = ((t0_context *)t0ctx)->ip;
429 	goto t0_next;
430 	for (;;) {
431 		uint32_t t0x;
432 
433 	t0_next:
434 		t0x = T0_NEXT(&ip);
435 		if (t0x < T0_INTERPRETED) {
436 			switch (t0x) {
437 				int32_t t0off;
438 
439 			case 0: /* ret */
440 				t0x = T0_RPOP();
441 				rp -= (t0x >> 16);
442 				t0x &= 0xFFFF;
443 				if (t0x == 0) {
444 					ip = NULL;
445 					goto t0_exit;
446 				}
447 				ip = &t0_codeblock[t0x];
448 				break;
449 			case 1: /* literal constant */
450 				T0_PUSHi(t0_parse7E_signed(&ip));
451 				break;
452 			case 2: /* read local */
453 				T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip)));
454 				break;
455 			case 3: /* write local */
456 				T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP();
457 				break;
458 			case 4: /* jump */
459 				t0off = t0_parse7E_signed(&ip);
460 				ip += t0off;
461 				break;
462 			case 5: /* jump if */
463 				t0off = t0_parse7E_signed(&ip);
464 				if (T0_POP()) {
465 					ip += t0off;
466 				}
467 				break;
468 			case 6: /* jump if not */
469 				t0off = t0_parse7E_signed(&ip);
470 				if (!T0_POP()) {
471 					ip += t0off;
472 				}
473 				break;
474 			case 7: {
475 				/* %25 */
476 
477 	int32_t b = T0_POPi();
478 	int32_t a = T0_POPi();
479 	T0_PUSHi(a % b);
480 
481 				}
482 				break;
483 			case 8: {
484 				/* * */
485 
486 	uint32_t b = T0_POP();
487 	uint32_t a = T0_POP();
488 	T0_PUSH(a * b);
489 
490 				}
491 				break;
492 			case 9: {
493 				/* + */
494 
495 	uint32_t b = T0_POP();
496 	uint32_t a = T0_POP();
497 	T0_PUSH(a + b);
498 
499 				}
500 				break;
501 			case 10: {
502 				/* - */
503 
504 	uint32_t b = T0_POP();
505 	uint32_t a = T0_POP();
506 	T0_PUSH(a - b);
507 
508 				}
509 				break;
510 			case 11: {
511 				/* -rot */
512  T0_NROT();
513 				}
514 				break;
515 			case 12: {
516 				/* / */
517 
518 	int32_t b = T0_POPi();
519 	int32_t a = T0_POPi();
520 	T0_PUSHi(a / b);
521 
522 				}
523 				break;
524 			case 13: {
525 				/* < */
526 
527 	int32_t b = T0_POPi();
528 	int32_t a = T0_POPi();
529 	T0_PUSH(-(uint32_t)(a < b));
530 
531 				}
532 				break;
533 			case 14: {
534 				/* << */
535 
536 	int c = (int)T0_POPi();
537 	uint32_t x = T0_POP();
538 	T0_PUSH(x << c);
539 
540 				}
541 				break;
542 			case 15: {
543 				/* <= */
544 
545 	int32_t b = T0_POPi();
546 	int32_t a = T0_POPi();
547 	T0_PUSH(-(uint32_t)(a <= b));
548 
549 				}
550 				break;
551 			case 16: {
552 				/* <> */
553 
554 	uint32_t b = T0_POP();
555 	uint32_t a = T0_POP();
556 	T0_PUSH(-(uint32_t)(a != b));
557 
558 				}
559 				break;
560 			case 17: {
561 				/* = */
562 
563 	uint32_t b = T0_POP();
564 	uint32_t a = T0_POP();
565 	T0_PUSH(-(uint32_t)(a == b));
566 
567 				}
568 				break;
569 			case 18: {
570 				/* > */
571 
572 	int32_t b = T0_POPi();
573 	int32_t a = T0_POPi();
574 	T0_PUSH(-(uint32_t)(a > b));
575 
576 				}
577 				break;
578 			case 19: {
579 				/* >= */
580 
581 	int32_t b = T0_POPi();
582 	int32_t a = T0_POPi();
583 	T0_PUSH(-(uint32_t)(a >= b));
584 
585 				}
586 				break;
587 			case 20: {
588 				/* >> */
589 
590 	int c = (int)T0_POPi();
591 	int32_t x = T0_POPi();
592 	T0_PUSHi(x >> c);
593 
594 				}
595 				break;
596 			case 21: {
597 				/* and */
598 
599 	uint32_t b = T0_POP();
600 	uint32_t a = T0_POP();
601 	T0_PUSH(a & b);
602 
603 				}
604 				break;
605 			case 22: {
606 				/* co */
607  T0_CO();
608 				}
609 				break;
610 			case 23: {
611 				/* copy-ec-pkey */
612 
613 	size_t qlen = T0_POP();
614 	uint32_t curve = T0_POP();
615 	CTX->pkey.key_type = BR_KEYTYPE_EC;
616 	CTX->pkey.key.ec.curve = curve;
617 	CTX->pkey.key.ec.q = CTX->pkey_data;
618 	CTX->pkey.key.ec.qlen = qlen;
619 
620 				}
621 				break;
622 			case 24: {
623 				/* copy-rsa-pkey */
624 
625 	size_t elen = T0_POP();
626 	size_t nlen = T0_POP();
627 	CTX->pkey.key_type = BR_KEYTYPE_RSA;
628 	CTX->pkey.key.rsa.n = CTX->pkey_data;
629 	CTX->pkey.key.rsa.nlen = nlen;
630 	CTX->pkey.key.rsa.e = CTX->pkey_data + nlen;
631 	CTX->pkey.key.rsa.elen = elen;
632 
633 				}
634 				break;
635 			case 25: {
636 				/* data-get8 */
637 
638 	size_t addr = T0_POP();
639 	T0_PUSH(t0_datablock[addr]);
640 
641 				}
642 				break;
643 			case 26: {
644 				/* drop */
645  (void)T0_POP();
646 				}
647 				break;
648 			case 27: {
649 				/* dup */
650  T0_PUSH(T0_PEEK(0));
651 				}
652 				break;
653 			case 28: {
654 				/* eqOID */
655 
656 	const unsigned char *a2 = &t0_datablock[T0_POP()];
657 	const unsigned char *a1 = &CTX->pad[0];
658 	size_t len = a1[0];
659 	int x;
660 	if (len == a2[0]) {
661 		x = -(memcmp(a1 + 1, a2 + 1, len) == 0);
662 	} else {
663 		x = 0;
664 	}
665 	T0_PUSH((uint32_t)x);
666 
667 				}
668 				break;
669 			case 29: {
670 				/* fail */
671 
672 	CTX->err = T0_POPi();
673 	T0_CO();
674 
675 				}
676 				break;
677 			case 30: {
678 				/* neg */
679 
680 	uint32_t a = T0_POP();
681 	T0_PUSH(-a);
682 
683 				}
684 				break;
685 			case 31: {
686 				/* or */
687 
688 	uint32_t b = T0_POP();
689 	uint32_t a = T0_POP();
690 	T0_PUSH(a | b);
691 
692 				}
693 				break;
694 			case 32: {
695 				/* over */
696  T0_PUSH(T0_PEEK(1));
697 				}
698 				break;
699 			case 33: {
700 				/* read-blob-inner */
701 
702 	uint32_t len = T0_POP();
703 	uint32_t addr = T0_POP();
704 	size_t clen = CTX->hlen;
705 	if (clen > len) {
706 		clen = (size_t)len;
707 	}
708 	if (addr != 0) {
709 		memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen);
710 	}
711 	if (CTX->copy_dn && CTX->append_dn) {
712 		CTX->append_dn(CTX->append_dn_ctx, CTX->hbuf, clen);
713 	}
714 	CTX->hbuf += clen;
715 	CTX->hlen -= clen;
716 	T0_PUSH(addr + clen);
717 	T0_PUSH(len - clen);
718 
719 				}
720 				break;
721 			case 34: {
722 				/* read8-low */
723 
724 	if (CTX->hlen == 0) {
725 		T0_PUSHi(-1);
726 	} else {
727 		unsigned char x = *CTX->hbuf ++;
728 		if (CTX->copy_dn && CTX->append_dn) {
729 			CTX->append_dn(CTX->append_dn_ctx, &x, 1);
730 		}
731 		CTX->hlen --;
732 		T0_PUSH(x);
733 	}
734 
735 				}
736 				break;
737 			case 35: {
738 				/* rot */
739  T0_ROT();
740 				}
741 				break;
742 			case 36: {
743 				/* set32 */
744 
745 	uint32_t addr = T0_POP();
746 	*(uint32_t *)(void *)((unsigned char *)CTX + addr) = T0_POP();
747 
748 				}
749 				break;
750 			case 37: {
751 				/* set8 */
752 
753 	uint32_t addr = T0_POP();
754 	*((unsigned char *)CTX + addr) = (unsigned char)T0_POP();
755 
756 				}
757 				break;
758 			case 38: {
759 				/* swap */
760  T0_SWAP();
761 				}
762 				break;
763 			}
764 
765 		} else {
766 			T0_ENTER(ip, rp, t0x);
767 		}
768 	}
769 t0_exit:
770 	((t0_context *)t0ctx)->dp = dp;
771 	((t0_context *)t0ctx)->rp = rp;
772 	((t0_context *)t0ctx)->ip = ip;
773 }
774