1 /* Automatically generated code; do not modify directly. */
9 const unsigned char *ip
;
13 t0_parse7E_unsigned(const unsigned char **p
)
22 x
= (x
<< 7) | (uint32_t)(y
& 0x7F);
30 t0_parse7E_signed(const unsigned char **p
)
35 neg
= ((**p
) >> 6) & 1;
41 x
= (x
<< 7) | (uint32_t)(y
& 0x7F);
44 return -(int32_t)~x
- 1;
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)
61 static const uint8_t t0_datablock
[];
64 void br_skey_decoder_init_main(void *t0ctx
);
66 void br_skey_decoder_run(void *t0ctx
);
78 #define CTX ((br_skey_decoder_context *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu)))
79 #define CONTEXT_NAME br_skey_decoder_context
81 /* see bearssl_x509.h */
83 br_skey_decoder_init(br_skey_decoder_context
*ctx
)
85 memset(ctx
, 0, sizeof *ctx
);
86 ctx
->cpu
.dp
= &ctx
->dp_stack
[0];
87 ctx
->cpu
.rp
= &ctx
->rp_stack
[0];
88 br_skey_decoder_init_main(&ctx
->cpu
);
89 br_skey_decoder_run(&ctx
->cpu
);
92 /* see bearssl_x509.h */
94 br_skey_decoder_push(br_skey_decoder_context
*ctx
,
95 const void *data
, size_t len
)
99 br_skey_decoder_run(&ctx
->cpu
);
104 static const uint8_t t0_datablock
[] = {
105 0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x07,
106 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x08, 0x2A, 0x86, 0x48, 0xCE,
107 0x3D, 0x03, 0x01, 0x07, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22, 0x05, 0x2B,
108 0x81, 0x04, 0x00, 0x23
111 static const uint8_t t0_codeblock
[] = {
112 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x01, 0x01, 0x08, 0x00, 0x00, 0x13,
113 0x13, 0x00, 0x00, 0x01, T0_INT1(BR_ERR_X509_BAD_TAG_CLASS
), 0x00, 0x00,
114 0x01, T0_INT1(BR_ERR_X509_BAD_TAG_VALUE
), 0x00, 0x00, 0x01,
115 T0_INT1(BR_ERR_X509_EXTRA_ELEMENT
), 0x00, 0x00, 0x01,
116 T0_INT1(BR_ERR_X509_INDEFINITE_LENGTH
), 0x00, 0x00, 0x01,
117 T0_INT1(BR_ERR_X509_INNER_TRUNC
), 0x00, 0x00, 0x01,
118 T0_INT1(BR_ERR_X509_INVALID_VALUE
), 0x00, 0x00, 0x01,
119 T0_INT1(BR_ERR_X509_LIMIT_EXCEEDED
), 0x00, 0x00, 0x01,
120 T0_INT1(BR_ERR_X509_NOT_CONSTRUCTED
), 0x00, 0x00, 0x01,
121 T0_INT1(BR_ERR_X509_NOT_PRIMITIVE
), 0x00, 0x00, 0x01,
122 T0_INT1(BR_ERR_X509_OVERFLOW
), 0x00, 0x00, 0x01,
123 T0_INT1(BR_ERR_X509_UNEXPECTED
), 0x00, 0x00, 0x01,
124 T0_INT1(BR_ERR_X509_UNSUPPORTED
), 0x00, 0x00, 0x01,
125 T0_INT1(BR_KEYTYPE_EC
), 0x00, 0x00, 0x01, T0_INT1(BR_KEYTYPE_RSA
),
126 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME
, key_data
)), 0x00,
127 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME
, key_type
)), 0x00, 0x00,
128 0x33, 0x48, 0x00, 0x00, 0x01, T0_INT2(offsetof(CONTEXT_NAME
, pad
)),
129 0x00, 0x00, 0x01, 0x13, 0x00, 0x00, 0x01, 0x1C, 0x00, 0x00, 0x01, 0x22,
130 0x00, 0x00, 0x05, 0x02, 0x2C, 0x16, 0x00, 0x00, 0x06, 0x02, 0x2D, 0x16,
131 0x00, 0x00, 0x01, 0x10, 0x3D, 0x00, 0x00, 0x0D, 0x05, 0x02, 0x2F, 0x16,
132 0x3A, 0x00, 0x00, 0x0D, 0x05, 0x02, 0x2F, 0x16, 0x3B, 0x00, 0x00, 0x06,
133 0x02, 0x27, 0x16, 0x00, 0x01, 0x03, 0x00, 0x54, 0x57, 0x01, 0x02, 0x3E,
134 0x55, 0x23, 0x06, 0x02, 0x30, 0x16, 0x57, 0x01, 0x04, 0x3E, 0x02, 0x00,
135 0x41, 0x3F, 0x00, 0x02, 0x03, 0x00, 0x53, 0x14, 0x14, 0x03, 0x01, 0x48,
136 0x0E, 0x06, 0x02, 0x30, 0x16, 0x33, 0x4C, 0x58, 0x01, 0x7F, 0x19, 0x0D,
137 0x06, 0x04, 0x13, 0x13, 0x04, 0x29, 0x01, 0x20, 0x19, 0x0D, 0x06, 0x16,
138 0x13, 0x3A, 0x53, 0x4D, 0x02, 0x00, 0x06, 0x09, 0x02, 0x00, 0x0C, 0x06,
139 0x02, 0x2A, 0x16, 0x04, 0x02, 0x03, 0x00, 0x3F, 0x04, 0x0D, 0x01, 0x21,
140 0x19, 0x0D, 0x06, 0x04, 0x13, 0x3A, 0x04, 0x03, 0x30, 0x16, 0x13, 0x5D,
141 0x02, 0x00, 0x05, 0x02, 0x30, 0x16, 0x02, 0x00, 0x02, 0x01, 0x1D, 0x00,
142 0x02, 0x53, 0x4B, 0x05, 0x02, 0x30, 0x16, 0x5B, 0x15, 0x06, 0x07, 0x5D,
143 0x01, 0x7F, 0x03, 0x01, 0x04, 0x16, 0x46, 0x15, 0x06, 0x10, 0x01, 0x00,
144 0x03, 0x01, 0x14, 0x06, 0x03, 0x4D, 0x04, 0x02, 0x01, 0x00, 0x03, 0x00,
145 0x04, 0x02, 0x30, 0x16, 0x3F, 0x57, 0x01, 0x04, 0x3E, 0x53, 0x02, 0x01,
146 0x06, 0x03, 0x43, 0x04, 0x03, 0x02, 0x00, 0x40, 0x3F, 0x5D, 0x02, 0x01,
147 0x06, 0x03, 0x32, 0x04, 0x01, 0x31, 0x00, 0x00, 0x54, 0x57, 0x01, 0x02,
148 0x3E, 0x55, 0x06, 0x02, 0x30, 0x16, 0x57, 0x01, 0x02, 0x3E, 0x44, 0x3F,
149 0x00, 0x07, 0x35, 0x50, 0x14, 0x05, 0x02, 0x2F, 0x16, 0x23, 0x01, 0x03,
150 0x0B, 0x33, 0x17, 0x47, 0x07, 0x03, 0x00, 0x4F, 0x4F, 0x35, 0x4E, 0x14,
151 0x14, 0x03, 0x01, 0x03, 0x02, 0x51, 0x14, 0x03, 0x03, 0x02, 0x02, 0x07,
152 0x14, 0x03, 0x02, 0x51, 0x14, 0x03, 0x04, 0x02, 0x02, 0x07, 0x14, 0x03,
153 0x02, 0x51, 0x14, 0x03, 0x05, 0x02, 0x02, 0x07, 0x14, 0x03, 0x02, 0x51,
154 0x03, 0x06, 0x02, 0x00, 0x02, 0x01, 0x02, 0x03, 0x02, 0x04, 0x02, 0x05,
155 0x02, 0x06, 0x1E, 0x00, 0x00, 0x19, 0x19, 0x00, 0x00, 0x01, 0x0B, 0x00,
156 0x00, 0x01, 0x00, 0x20, 0x14, 0x06, 0x08, 0x01, 0x01, 0x21, 0x20, 0x22,
157 0x20, 0x04, 0x75, 0x13, 0x00, 0x00, 0x01,
158 T0_INT2(3 * BR_X509_BUFSIZE_KEY
), 0x00, 0x01, 0x01, 0x87, 0xFF, 0xFF,
159 0x7F, 0x54, 0x57, 0x01, 0x02, 0x3E, 0x55, 0x01, 0x01, 0x0E, 0x06, 0x02,
160 0x30, 0x16, 0x57, 0x01, 0x02, 0x19, 0x0D, 0x06, 0x06, 0x13, 0x3B, 0x44,
161 0x32, 0x04, 0x1C, 0x01, 0x04, 0x19, 0x0D, 0x06, 0x08, 0x13, 0x3B, 0x01,
162 0x00, 0x41, 0x31, 0x04, 0x0E, 0x01, 0x10, 0x19, 0x0D, 0x06, 0x05, 0x13,
163 0x3A, 0x42, 0x04, 0x03, 0x30, 0x16, 0x13, 0x03, 0x00, 0x3F, 0x02, 0x00,
164 0x34, 0x1F, 0x5A, 0x27, 0x16, 0x00, 0x01, 0x45, 0x0A, 0x06, 0x02, 0x29,
165 0x16, 0x14, 0x03, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x57, 0x01, 0x06,
166 0x3E, 0x56, 0x00, 0x00, 0x20, 0x14, 0x06, 0x07, 0x1A, 0x14, 0x06, 0x01,
167 0x12, 0x04, 0x76, 0x24, 0x00, 0x00, 0x4B, 0x05, 0x02, 0x30, 0x16, 0x37,
168 0x15, 0x06, 0x04, 0x01, 0x17, 0x04, 0x12, 0x38, 0x15, 0x06, 0x04, 0x01,
169 0x18, 0x04, 0x0A, 0x39, 0x15, 0x06, 0x04, 0x01, 0x19, 0x04, 0x02, 0x30,
170 0x16, 0x00, 0x00, 0x1C, 0x57, 0x01, 0x02, 0x3E, 0x09, 0x50, 0x00, 0x00,
171 0x35, 0x4E, 0x13, 0x00, 0x03, 0x14, 0x03, 0x00, 0x03, 0x01, 0x03, 0x02,
172 0x53, 0x59, 0x14, 0x01, 0x81, 0x00, 0x0F, 0x06, 0x02, 0x2E, 0x16, 0x14,
173 0x01, 0x00, 0x0D, 0x06, 0x0B, 0x13, 0x14, 0x05, 0x04, 0x13, 0x01, 0x00,
174 0x00, 0x59, 0x04, 0x6F, 0x02, 0x01, 0x14, 0x05, 0x02, 0x2B, 0x16, 0x23,
175 0x03, 0x01, 0x02, 0x02, 0x1F, 0x02, 0x02, 0x22, 0x03, 0x02, 0x14, 0x06,
176 0x03, 0x59, 0x04, 0x68, 0x13, 0x02, 0x00, 0x02, 0x01, 0x08, 0x00, 0x00,
177 0x14, 0x35, 0x1C, 0x08, 0x20, 0x1C, 0x07, 0x20, 0x4E, 0x00, 0x01, 0x59,
178 0x14, 0x01, 0x81, 0x00, 0x0A, 0x06, 0x01, 0x00, 0x01, 0x81, 0x00, 0x08,
179 0x14, 0x05, 0x02, 0x28, 0x16, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01,
180 0x00, 0x0E, 0x06, 0x19, 0x02, 0x00, 0x23, 0x03, 0x00, 0x14, 0x01, 0x87,
181 0xFF, 0xFF, 0x7F, 0x0E, 0x06, 0x02, 0x29, 0x16, 0x01, 0x08, 0x0B, 0x20,
182 0x59, 0x1C, 0x07, 0x04, 0x60, 0x00, 0x00, 0x52, 0x4A, 0x00, 0x00, 0x57,
183 0x3C, 0x53, 0x00, 0x01, 0x53, 0x14, 0x05, 0x02, 0x2E, 0x16, 0x59, 0x14,
184 0x01, 0x81, 0x00, 0x0F, 0x06, 0x02, 0x2E, 0x16, 0x03, 0x00, 0x14, 0x06,
185 0x16, 0x59, 0x02, 0x00, 0x14, 0x01, 0x87, 0xFF, 0xFF, 0x7F, 0x0F, 0x06,
186 0x02, 0x2E, 0x16, 0x01, 0x08, 0x0B, 0x07, 0x03, 0x00, 0x04, 0x67, 0x13,
187 0x02, 0x00, 0x00, 0x00, 0x53, 0x14, 0x01, 0x81, 0x7F, 0x0E, 0x06, 0x08,
188 0x5C, 0x01, 0x00, 0x36, 0x1F, 0x01, 0x00, 0x00, 0x14, 0x36, 0x1F, 0x36,
189 0x22, 0x4C, 0x01, 0x7F, 0x00, 0x01, 0x59, 0x03, 0x00, 0x02, 0x00, 0x01,
190 0x05, 0x10, 0x01, 0x01, 0x11, 0x18, 0x02, 0x00, 0x01, 0x06, 0x10, 0x14,
191 0x01, 0x01, 0x11, 0x06, 0x02, 0x25, 0x16, 0x01, 0x04, 0x0B, 0x02, 0x00,
192 0x01, 0x1F, 0x11, 0x14, 0x01, 0x1F, 0x0D, 0x06, 0x02, 0x26, 0x16, 0x07,
193 0x00, 0x00, 0x14, 0x05, 0x05, 0x01, 0x00, 0x01, 0x7F, 0x00, 0x57, 0x00,
194 0x00, 0x14, 0x05, 0x02, 0x29, 0x16, 0x23, 0x5A, 0x00, 0x00, 0x1B, 0x14,
195 0x01, 0x00, 0x0F, 0x06, 0x01, 0x00, 0x13, 0x12, 0x04, 0x74, 0x00, 0x01,
196 0x01, 0x00, 0x00, 0x5D, 0x13, 0x00, 0x00, 0x14, 0x06, 0x07, 0x5E, 0x14,
197 0x06, 0x01, 0x12, 0x04, 0x76, 0x00, 0x00, 0x01, 0x00, 0x19, 0x1A, 0x09,
201 static const uint16_t t0_caddr
[] = {
265 #define T0_INTERPRETED 34
267 #define T0_ENTER(ip, rp, slot) do { \
268 const unsigned char *t0_newip; \
270 t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \
271 t0_lnum = t0_parse7E_unsigned(&t0_newip); \
273 *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \
277 #define T0_DEFENTRY(name, slot) \
281 t0_context *t0ctx = ctx; \
282 t0ctx->ip = &t0_codeblock[0]; \
283 T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \
286 T0_DEFENTRY(br_skey_decoder_init_main
, 73)
289 br_skey_decoder_run(void *t0ctx
)
292 const unsigned char *ip
;
294 #define T0_LOCAL(x) (*(rp - 2 - (x)))
295 #define T0_POP() (*-- dp)
296 #define T0_POPi() (*(int32_t *)(-- dp))
297 #define T0_PEEK(x) (*(dp - 1 - (x)))
298 #define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x)))
299 #define T0_PUSH(v) do { *dp = (v); dp ++; } while (0)
300 #define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0)
301 #define T0_RPOP() (*-- rp)
302 #define T0_RPOPi() (*(int32_t *)(-- rp))
303 #define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0)
304 #define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0)
305 #define T0_ROLL(x) do { \
306 size_t t0len = (size_t)(x); \
307 uint32_t t0tmp = *(dp - 1 - t0len); \
308 memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \
311 #define T0_SWAP() do { \
312 uint32_t t0tmp = *(dp - 2); \
313 *(dp - 2) = *(dp - 1); \
316 #define T0_ROT() do { \
317 uint32_t t0tmp = *(dp - 3); \
318 *(dp - 3) = *(dp - 2); \
319 *(dp - 2) = *(dp - 1); \
322 #define T0_NROT() do { \
323 uint32_t t0tmp = *(dp - 1); \
324 *(dp - 1) = *(dp - 2); \
325 *(dp - 2) = *(dp - 3); \
328 #define T0_PICK(x) do { \
329 uint32_t t0depth = (x); \
330 T0_PUSH(T0_PEEK(t0depth)); \
332 #define T0_CO() do { \
335 #define T0_RET() break
337 dp
= ((t0_context
*)t0ctx
)->dp
;
338 rp
= ((t0_context
*)t0ctx
)->rp
;
339 ip
= ((t0_context
*)t0ctx
)->ip
;
343 t0x
= t0_parse7E_unsigned(&ip
);
344 if (t0x
< T0_INTERPRETED
) {
356 ip
= &t0_codeblock
[t0x
];
358 case 1: /* literal constant */
359 T0_PUSHi(t0_parse7E_signed(&ip
));
361 case 2: /* read local */
362 T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip
)));
364 case 3: /* write local */
365 T0_LOCAL(t0_parse7E_unsigned(&ip
)) = T0_POP();
368 t0off
= t0_parse7E_signed(&ip
);
371 case 5: /* jump if */
372 t0off
= t0_parse7E_signed(&ip
);
377 case 6: /* jump if not */
378 t0off
= t0_parse7E_signed(&ip
);
386 uint32_t b
= T0_POP();
387 uint32_t a
= T0_POP();
395 uint32_t b
= T0_POP();
396 uint32_t a
= T0_POP();
409 int32_t b
= T0_POPi();
410 int32_t a
= T0_POPi();
411 T0_PUSH(-(uint32_t)(a
< b
));
418 int c
= (int)T0_POPi();
419 uint32_t x
= T0_POP();
427 uint32_t b
= T0_POP();
428 uint32_t a
= T0_POP();
429 T0_PUSH(-(uint32_t)(a
!= b
));
436 uint32_t b
= T0_POP();
437 uint32_t a
= T0_POP();
438 T0_PUSH(-(uint32_t)(a
== b
));
445 int32_t b
= T0_POPi();
446 int32_t a
= T0_POPi();
447 T0_PUSH(-(uint32_t)(a
> b
));
454 int32_t b
= T0_POPi();
455 int32_t a
= T0_POPi();
456 T0_PUSH(-(uint32_t)(a
>= b
));
463 int c
= (int)T0_POPi();
464 int32_t x
= T0_POPi();
472 uint32_t b
= T0_POP();
473 uint32_t a
= T0_POP();
496 const unsigned char *a2
= &t0_datablock
[T0_POP()];
497 const unsigned char *a1
= &CTX
->pad
[0];
501 x
= -(memcmp(a1
+ 1, a2
+ 1, len
) == 0);
505 T0_PUSH((uint32_t)x
);
512 CTX
->err
= T0_POPi();
520 uint32_t addr
= T0_POP();
521 T0_PUSH(*((unsigned char *)CTX
+ addr
));
528 uint32_t a
= T0_POP();
539 /* read-blob-inner */
541 uint32_t len
= T0_POP();
542 uint32_t addr
= T0_POP();
543 size_t clen
= CTX
->hlen
;
548 memcpy((unsigned char *)CTX
+ addr
, CTX
->hbuf
, clen
);
552 T0_PUSH(addr
+ clen
);
560 if (CTX
->hlen
== 0) {
564 T0_PUSH(*CTX
->hbuf
++);
577 size_t xlen
= T0_POP();
578 uint32_t curve
= T0_POP();
579 CTX
->key
.ec
.curve
= curve
;
580 CTX
->key
.ec
.x
= CTX
->key_data
;
581 CTX
->key
.ec
.xlen
= xlen
;
588 size_t iqlen
= T0_POP();
589 size_t dqlen
= T0_POP();
590 size_t dplen
= T0_POP();
591 size_t qlen
= T0_POP();
592 size_t plen
= T0_POP();
593 uint32_t n_bitlen
= T0_POP();
596 CTX
->key
.rsa
.n_bitlen
= n_bitlen
;
597 CTX
->key
.rsa
.p
= CTX
->key_data
;
598 CTX
->key
.rsa
.plen
= plen
;
600 CTX
->key
.rsa
.q
= CTX
->key_data
+ off
;
601 CTX
->key
.rsa
.qlen
= qlen
;
603 CTX
->key
.rsa
.dp
= CTX
->key_data
+ off
;
604 CTX
->key
.rsa
.dplen
= dplen
;
606 CTX
->key
.rsa
.dq
= CTX
->key_data
+ off
;
607 CTX
->key
.rsa
.dqlen
= dqlen
;
609 CTX
->key
.rsa
.iq
= CTX
->key_data
+ off
;
610 CTX
->key
.rsa
.iqlen
= iqlen
;
617 uint32_t addr
= T0_POP();
618 *((unsigned char *)CTX
+ addr
) = (unsigned char)T0_POP();
630 int c
= (int)T0_POPi();
631 uint32_t x
= T0_POP();
639 T0_ENTER(ip
, rp
, t0x
);
643 ((t0_context
*)t0ctx
)->dp
= dp
;
644 ((t0_context
*)t0ctx
)->rp
= rp
;
645 ((t0_context
*)t0ctx
)->ip
= ip
;