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