Removed needless variable shadowing (suggested by Doug Hogan).
[BearSSL] / src / x509 / skey_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_skey_decoder_init_main(void *t0ctx);
65
66 void br_skey_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_skey_decoder_context *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu)))
79 #define CONTEXT_NAME br_skey_decoder_context
80
81 /* see bearssl_x509.h */
82 void
83 br_skey_decoder_init(br_skey_decoder_context *ctx)
84 {
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);
90 }
91
92 /* see bearssl_x509.h */
93 void
94 br_skey_decoder_push(br_skey_decoder_context *ctx,
95 const void *data, size_t len)
96 {
97 ctx->hbuf = data;
98 ctx->hlen = len;
99 br_skey_decoder_run(&ctx->cpu);
100 }
101
102
103
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
109 };
110
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,
198 0x24, 0x00
199 };
200
201 static const uint16_t t0_caddr[] = {
202 0,
203 5,
204 10,
205 14,
206 18,
207 22,
208 26,
209 30,
210 34,
211 38,
212 42,
213 46,
214 50,
215 54,
216 58,
217 62,
218 66,
219 70,
220 75,
221 80,
222 84,
223 89,
224 93,
225 97,
226 101,
227 107,
228 113,
229 118,
230 126,
231 134,
232 140,
233 163,
234 244,
235 311,
236 329,
237 404,
238 408,
239 412,
240 429,
241 434,
242 505,
243 519,
244 526,
245 540,
246 573,
247 582,
248 587,
249 654,
250 665,
251 721,
252 725,
253 730,
254 778,
255 804,
256 848,
257 859,
258 868,
259 881,
260 885,
261 889,
262 901
263 };
264
265 #define T0_INTERPRETED 34
266
267 #define T0_ENTER(ip, rp, slot) do { \
268 const unsigned char *t0_newip; \
269 uint32_t t0_lnum; \
270 t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \
271 t0_lnum = t0_parse7E_unsigned(&t0_newip); \
272 (rp) += t0_lnum; \
273 *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \
274 (ip) = t0_newip; \
275 } while (0)
276
277 #define T0_DEFENTRY(name, slot) \
278 void \
279 name(void *ctx) \
280 { \
281 t0_context *t0ctx = ctx; \
282 t0ctx->ip = &t0_codeblock[0]; \
283 T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \
284 }
285
286 T0_DEFENTRY(br_skey_decoder_init_main, 73)
287
288 void
289 br_skey_decoder_run(void *t0ctx)
290 {
291 uint32_t *dp, *rp;
292 const unsigned char *ip;
293
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); \
309 *(dp - 1) = t0tmp; \
310 } while (0)
311 #define T0_SWAP() do { \
312 uint32_t t0tmp = *(dp - 2); \
313 *(dp - 2) = *(dp - 1); \
314 *(dp - 1) = t0tmp; \
315 } while (0)
316 #define T0_ROT() do { \
317 uint32_t t0tmp = *(dp - 3); \
318 *(dp - 3) = *(dp - 2); \
319 *(dp - 2) = *(dp - 1); \
320 *(dp - 1) = t0tmp; \
321 } while (0)
322 #define T0_NROT() do { \
323 uint32_t t0tmp = *(dp - 1); \
324 *(dp - 1) = *(dp - 2); \
325 *(dp - 2) = *(dp - 3); \
326 *(dp - 3) = t0tmp; \
327 } while (0)
328 #define T0_PICK(x) do { \
329 uint32_t t0depth = (x); \
330 T0_PUSH(T0_PEEK(t0depth)); \
331 } while (0)
332 #define T0_CO() do { \
333 goto t0_exit; \
334 } while (0)
335 #define T0_RET() break
336
337 dp = ((t0_context *)t0ctx)->dp;
338 rp = ((t0_context *)t0ctx)->rp;
339 ip = ((t0_context *)t0ctx)->ip;
340 for (;;) {
341 uint32_t t0x;
342
343 t0x = t0_parse7E_unsigned(&ip);
344 if (t0x < T0_INTERPRETED) {
345 switch (t0x) {
346 int32_t t0off;
347
348 case 0: /* ret */
349 t0x = T0_RPOP();
350 rp -= (t0x >> 16);
351 t0x &= 0xFFFF;
352 if (t0x == 0) {
353 ip = NULL;
354 goto t0_exit;
355 }
356 ip = &t0_codeblock[t0x];
357 break;
358 case 1: /* literal constant */
359 T0_PUSHi(t0_parse7E_signed(&ip));
360 break;
361 case 2: /* read local */
362 T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip)));
363 break;
364 case 3: /* write local */
365 T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP();
366 break;
367 case 4: /* jump */
368 t0off = t0_parse7E_signed(&ip);
369 ip += t0off;
370 break;
371 case 5: /* jump if */
372 t0off = t0_parse7E_signed(&ip);
373 if (T0_POP()) {
374 ip += t0off;
375 }
376 break;
377 case 6: /* jump if not */
378 t0off = t0_parse7E_signed(&ip);
379 if (!T0_POP()) {
380 ip += t0off;
381 }
382 break;
383 case 7: {
384 /* + */
385
386 uint32_t b = T0_POP();
387 uint32_t a = T0_POP();
388 T0_PUSH(a + b);
389
390 }
391 break;
392 case 8: {
393 /* - */
394
395 uint32_t b = T0_POP();
396 uint32_t a = T0_POP();
397 T0_PUSH(a - b);
398
399 }
400 break;
401 case 9: {
402 /* -rot */
403 T0_NROT();
404 }
405 break;
406 case 10: {
407 /* < */
408
409 int32_t b = T0_POPi();
410 int32_t a = T0_POPi();
411 T0_PUSH(-(uint32_t)(a < b));
412
413 }
414 break;
415 case 11: {
416 /* << */
417
418 int c = (int)T0_POPi();
419 uint32_t x = T0_POP();
420 T0_PUSH(x << c);
421
422 }
423 break;
424 case 12: {
425 /* <> */
426
427 uint32_t b = T0_POP();
428 uint32_t a = T0_POP();
429 T0_PUSH(-(uint32_t)(a != b));
430
431 }
432 break;
433 case 13: {
434 /* = */
435
436 uint32_t b = T0_POP();
437 uint32_t a = T0_POP();
438 T0_PUSH(-(uint32_t)(a == b));
439
440 }
441 break;
442 case 14: {
443 /* > */
444
445 int32_t b = T0_POPi();
446 int32_t a = T0_POPi();
447 T0_PUSH(-(uint32_t)(a > b));
448
449 }
450 break;
451 case 15: {
452 /* >= */
453
454 int32_t b = T0_POPi();
455 int32_t a = T0_POPi();
456 T0_PUSH(-(uint32_t)(a >= b));
457
458 }
459 break;
460 case 16: {
461 /* >> */
462
463 int c = (int)T0_POPi();
464 int32_t x = T0_POPi();
465 T0_PUSHi(x >> c);
466
467 }
468 break;
469 case 17: {
470 /* and */
471
472 uint32_t b = T0_POP();
473 uint32_t a = T0_POP();
474 T0_PUSH(a & b);
475
476 }
477 break;
478 case 18: {
479 /* co */
480 T0_CO();
481 }
482 break;
483 case 19: {
484 /* drop */
485 (void)T0_POP();
486 }
487 break;
488 case 20: {
489 /* dup */
490 T0_PUSH(T0_PEEK(0));
491 }
492 break;
493 case 21: {
494 /* eqOID */
495
496 const unsigned char *a2 = &t0_datablock[T0_POP()];
497 const unsigned char *a1 = &CTX->pad[0];
498 size_t len = a1[0];
499 int x;
500 if (len == a2[0]) {
501 x = -(memcmp(a1 + 1, a2 + 1, len) == 0);
502 } else {
503 x = 0;
504 }
505 T0_PUSH((uint32_t)x);
506
507 }
508 break;
509 case 22: {
510 /* fail */
511
512 CTX->err = T0_POPi();
513 T0_CO();
514
515 }
516 break;
517 case 23: {
518 /* get8 */
519
520 uint32_t addr = T0_POP();
521 T0_PUSH(*((unsigned char *)CTX + addr));
522
523 }
524 break;
525 case 24: {
526 /* neg */
527
528 uint32_t a = T0_POP();
529 T0_PUSH(-a);
530
531 }
532 break;
533 case 25: {
534 /* over */
535 T0_PUSH(T0_PEEK(1));
536 }
537 break;
538 case 26: {
539 /* read-blob-inner */
540
541 uint32_t len = T0_POP();
542 uint32_t addr = T0_POP();
543 size_t clen = CTX->hlen;
544 if (clen > len) {
545 clen = (size_t)len;
546 }
547 if (addr != 0) {
548 memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen);
549 }
550 CTX->hbuf += clen;
551 CTX->hlen -= clen;
552 T0_PUSH(addr + clen);
553 T0_PUSH(len - clen);
554
555 }
556 break;
557 case 27: {
558 /* read8-low */
559
560 if (CTX->hlen == 0) {
561 T0_PUSHi(-1);
562 } else {
563 CTX->hlen --;
564 T0_PUSH(*CTX->hbuf ++);
565 }
566
567 }
568 break;
569 case 28: {
570 /* rot */
571 T0_ROT();
572 }
573 break;
574 case 29: {
575 /* set-ec-key */
576
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;
582
583 }
584 break;
585 case 30: {
586 /* set-rsa-key */
587
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();
594 size_t off;
595
596 CTX->key.rsa.n_bitlen = n_bitlen;
597 CTX->key.rsa.p = CTX->key_data;
598 CTX->key.rsa.plen = plen;
599 off = plen;
600 CTX->key.rsa.q = CTX->key_data + off;
601 CTX->key.rsa.qlen = qlen;
602 off += qlen;
603 CTX->key.rsa.dp = CTX->key_data + off;
604 CTX->key.rsa.dplen = dplen;
605 off += dplen;
606 CTX->key.rsa.dq = CTX->key_data + off;
607 CTX->key.rsa.dqlen = dqlen;
608 off += dqlen;
609 CTX->key.rsa.iq = CTX->key_data + off;
610 CTX->key.rsa.iqlen = iqlen;
611
612 }
613 break;
614 case 31: {
615 /* set8 */
616
617 uint32_t addr = T0_POP();
618 *((unsigned char *)CTX + addr) = (unsigned char)T0_POP();
619
620 }
621 break;
622 case 32: {
623 /* swap */
624 T0_SWAP();
625 }
626 break;
627 case 33: {
628 /* u>> */
629
630 int c = (int)T0_POPi();
631 uint32_t x = T0_POP();
632 T0_PUSH(x >> c);
633
634 }
635 break;
636 }
637
638 } else {
639 T0_ENTER(ip, rp, t0x);
640 }
641 }
642 t0_exit:
643 ((t0_context *)t0ctx)->dp = dp;
644 ((t0_context *)t0ctx)->rp = rp;
645 ((t0_context *)t0ctx)->ip = ip;
646 }