File Coverage

src/codec/pemdec.c
Criterion Covered Total %
statement 190 194 97.9
branch 21 26 80.7
condition n/a
subroutine n/a
pod n/a
total 211 220 95.9


line stmt bran cond sub pod time code
1             /* Automatically generated code; do not modify directly. */
2              
3             #include
4             #include
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 1760419           t0_parse7E_unsigned(const unsigned char **p)
14             {
15             uint32_t x;
16              
17 1760419           x = 0;
18 0           for (;;) {
19             unsigned y;
20              
21 1760419           y = *(*p) ++;
22 1760419           x = (x << 7) | (uint32_t)(y & 0x7F);
23 1760419 50         if (y < 0x80) {
24 1760419           return x;
25             }
26             }
27             }
28              
29             static int32_t
30 3092307           t0_parse7E_signed(const unsigned char **p)
31             {
32             int neg;
33             uint32_t x;
34              
35 3092307           neg = ((**p) >> 6) & 1;
36 3092307           x = (uint32_t)-neg;
37 75125           for (;;) {
38             unsigned y;
39              
40 3167432           y = *(*p) ++;
41 3167432           x = (x << 7) | (uint32_t)(y & 0x7F);
42 3167432 100         if (y < 0x80) {
43 3092307 100         if (neg) {
44 84194           return -(int32_t)~x - 1;
45             } else {
46 3008113           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_pem_decoder_init_main(void *t0ctx);
65              
66             void br_pem_decoder_run(void *t0ctx);
67              
68              
69              
70             #include "inner.h"
71              
72             #define CTX ((br_pem_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu)))
73              
74             /* see bearssl_pem.h */
75             void
76 13           br_pem_decoder_init(br_pem_decoder_context *ctx)
77             {
78 13           memset(ctx, 0, sizeof *ctx);
79 13           ctx->cpu.dp = &ctx->dp_stack[0];
80 13           ctx->cpu.rp = &ctx->rp_stack[0];
81 13           br_pem_decoder_init_main(&ctx->cpu);
82 13           br_pem_decoder_run(&ctx->cpu);
83 13           }
84              
85             /* see bearssl_pem.h */
86             size_t
87 351           br_pem_decoder_push(br_pem_decoder_context *ctx,
88             const void *data, size_t len)
89             {
90 351 50         if (ctx->event) {
91 0           return 0;
92             }
93 351           ctx->hbuf = data;
94 351           ctx->hlen = len;
95 351           br_pem_decoder_run(&ctx->cpu);
96 351           return len - ctx->hlen;
97             }
98              
99             /* see bearssl_pem.h */
100             int
101 351           br_pem_decoder_event(br_pem_decoder_context *ctx)
102             {
103             int event;
104              
105 351           event = ctx->event;
106 351           ctx->event = 0;
107 351           return event;
108             }
109              
110              
111              
112             static const unsigned char t0_datablock[] = {
113             0x00, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20,
114             0x00, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x00
115             };
116              
117             static const unsigned char t0_codeblock[] = {
118             0x00, 0x01, 0x00, 0x09, 0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x01,
119             0x01, 0x08, 0x00, 0x00, 0x13, 0x13, 0x00, 0x00, 0x01,
120             T0_INT2(offsetof(br_pem_decoder_context, event)), 0x00, 0x00, 0x01,
121             T0_INT2(offsetof(br_pem_decoder_context, name)), 0x00, 0x00, 0x05,
122             0x14, 0x2C, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x03, 0x13, 0x04, 0x76, 0x01,
123             0x2D, 0x0C, 0x06, 0x05, 0x2E, 0x01, 0x03, 0x2D, 0x00, 0x01, 0x0D, 0x27,
124             0x05, 0x04, 0x01, 0x03, 0x2D, 0x00, 0x15, 0x2E, 0x01, 0x02, 0x2D, 0x00,
125             0x01, 0x01, 0x7F, 0x03, 0x00, 0x25, 0x01, 0x00, 0x18, 0x0D, 0x06, 0x03,
126             0x13, 0x04, 0x3C, 0x01, 0x7F, 0x18, 0x0D, 0x06, 0x13, 0x13, 0x02, 0x00,
127             0x05, 0x06, 0x2E, 0x01, 0x03, 0x2D, 0x04, 0x03, 0x01, 0x7F, 0x23, 0x01,
128             0x00, 0x00, 0x04, 0x23, 0x01, 0x01, 0x18, 0x0D, 0x06, 0x09, 0x13, 0x01,
129             0x00, 0x23, 0x01, 0x00, 0x00, 0x04, 0x14, 0x01, 0x02, 0x18, 0x0D, 0x06,
130             0x06, 0x13, 0x01, 0x7F, 0x00, 0x04, 0x08, 0x13, 0x01, 0x03, 0x2D, 0x01,
131             0x00, 0x00, 0x13, 0x01, 0x00, 0x03, 0x00, 0x04, 0xFF, 0x33, 0x01, 0x2C,
132             0x14, 0x01, 0x2D, 0x0D, 0x06, 0x04, 0x13, 0x01, 0x7F, 0x00, 0x14, 0x31,
133             0x06, 0x02, 0x13, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13, 0x01,
134             0x02, 0x00, 0x16, 0x14, 0x1D, 0x06, 0x05, 0x13, 0x2E, 0x01, 0x03, 0x00,
135             0x03, 0x00, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13, 0x01, 0x03,
136             0x00, 0x16, 0x14, 0x1D, 0x06, 0x05, 0x13, 0x2E, 0x01, 0x03, 0x00, 0x02,
137             0x00, 0x01, 0x06, 0x0A, 0x07, 0x03, 0x00, 0x29, 0x14, 0x01, 0x0A, 0x0D,
138             0x06, 0x04, 0x13, 0x01, 0x03, 0x00, 0x14, 0x01, 0x3D, 0x0D, 0x06, 0x2E,
139             0x13, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13, 0x01, 0x03, 0x00,
140             0x2F, 0x05, 0x04, 0x13, 0x01, 0x03, 0x00, 0x01, 0x3D, 0x0C, 0x06, 0x03,
141             0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x0F, 0x10, 0x06, 0x03, 0x01, 0x03,
142             0x00, 0x02, 0x00, 0x01, 0x04, 0x0F, 0x1C, 0x01, 0x01, 0x00, 0x16, 0x14,
143             0x1D, 0x06, 0x05, 0x13, 0x2E, 0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x06,
144             0x0A, 0x07, 0x03, 0x00, 0x29, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x04, 0x13,
145             0x01, 0x03, 0x00, 0x14, 0x01, 0x3D, 0x0D, 0x06, 0x20, 0x13, 0x2F, 0x05,
146             0x03, 0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x03, 0x10, 0x06, 0x03, 0x01,
147             0x03, 0x00, 0x02, 0x00, 0x01, 0x0A, 0x0F, 0x1C, 0x02, 0x00, 0x01, 0x02,
148             0x0F, 0x1C, 0x01, 0x01, 0x00, 0x16, 0x14, 0x1D, 0x06, 0x05, 0x13, 0x2E,
149             0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x06, 0x0A, 0x07, 0x03, 0x00, 0x02,
150             0x00, 0x01, 0x10, 0x0F, 0x1C, 0x02, 0x00, 0x01, 0x08, 0x0F, 0x1C, 0x02,
151             0x00, 0x1C, 0x01, 0x00, 0x00, 0x00, 0x28, 0x01, 0x01, 0x2D, 0x24, 0x06,
152             0x02, 0x04, 0x7B, 0x04, 0x75, 0x00, 0x14, 0x12, 0x2A, 0x14, 0x05, 0x04,
153             0x20, 0x01, 0x7F, 0x00, 0x2C, 0x2A, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x05,
154             0x13, 0x20, 0x01, 0x00, 0x00, 0x0D, 0x05, 0x05, 0x13, 0x2E, 0x01, 0x00,
155             0x00, 0x1E, 0x04, 0x5E, 0x00, 0x01, 0x01, 0x27, 0x06, 0x0B, 0x22, 0x01,
156             0x80, 0x7F, 0x2B, 0x14, 0x06, 0x02, 0x30, 0x00, 0x13, 0x04, 0x6E, 0x00,
157             0x2C, 0x14, 0x31, 0x05, 0x01, 0x00, 0x13, 0x04, 0x77, 0x00, 0x14, 0x14,
158             0x01, 0x80, 0x61, 0x0E, 0x1B, 0x01, 0x80, 0x7A, 0x0B, 0x10, 0x06, 0x03,
159             0x01, 0x20, 0x08, 0x00, 0x01, 0x14, 0x03, 0x00, 0x1B, 0x18, 0x05, 0x05,
160             0x20, 0x2E, 0x01, 0x00, 0x00, 0x2C, 0x14, 0x01, 0x0A, 0x0D, 0x06, 0x06,
161             0x20, 0x02, 0x00, 0x1B, 0x08, 0x00, 0x14, 0x01, 0x0D, 0x0D, 0x06, 0x03,
162             0x13, 0x04, 0x03, 0x2A, 0x18, 0x1A, 0x1E, 0x1B, 0x1F, 0x1B, 0x04, 0x59,
163             0x00, 0x19, 0x14, 0x1D, 0x05, 0x01, 0x00, 0x13, 0x11, 0x04, 0x76, 0x00,
164             0x21, 0x1A, 0x11, 0x00, 0x00, 0x2C, 0x01, 0x0A, 0x0C, 0x06, 0x02, 0x04,
165             0x78, 0x00, 0x01, 0x01, 0x7F, 0x03, 0x00, 0x2C, 0x14, 0x01, 0x0A, 0x0C,
166             0x06, 0x09, 0x31, 0x05, 0x04, 0x01, 0x00, 0x03, 0x00, 0x04, 0x70, 0x13,
167             0x02, 0x00, 0x00, 0x00, 0x14, 0x06, 0x14, 0x1F, 0x14, 0x22, 0x07, 0x17,
168             0x01, 0x2D, 0x0C, 0x06, 0x08, 0x22, 0x07, 0x1E, 0x01, 0x00, 0x1B, 0x1A,
169             0x00, 0x04, 0x69, 0x22, 0x1A, 0x00, 0x00, 0x14, 0x01, 0x0A, 0x0C, 0x1B,
170             0x01, 0x20, 0x0B, 0x10, 0x00
171             };
172              
173             static const uint16_t t0_caddr[] = {
174             0,
175             5,
176             10,
177             15,
178             19,
179             24,
180             29,
181             67,
182             149,
183             384,
184             396,
185             431,
186             450,
187             460,
188             479,
189             523,
190             534,
191             539,
192             549,
193             574,
194             601
195             };
196              
197             #define T0_INTERPRETED 29
198              
199             #define T0_ENTER(ip, rp, slot) do { \
200             const unsigned char *t0_newip; \
201             uint32_t t0_lnum; \
202             t0_newip = &t0_codeblock[t0_caddr[(slot) - T0_INTERPRETED]]; \
203             t0_lnum = t0_parse7E_unsigned(&t0_newip); \
204             (rp) += t0_lnum; \
205             *((rp) ++) = (uint32_t)((ip) - &t0_codeblock[0]) + (t0_lnum << 16); \
206             (ip) = t0_newip; \
207             } while (0)
208              
209             #define T0_DEFENTRY(name, slot) \
210             void \
211             name(void *ctx) \
212             { \
213             t0_context *t0ctx = ctx; \
214             t0ctx->ip = &t0_codeblock[0]; \
215             T0_ENTER(t0ctx->ip, t0ctx->rp, slot); \
216             }
217              
218 13           T0_DEFENTRY(br_pem_decoder_init_main, 38)
219              
220             #define T0_NEXT(t0ipp) (*(*(t0ipp)) ++)
221              
222             void
223 364           br_pem_decoder_run(void *t0ctx)
224             {
225             uint32_t *dp, *rp;
226             const unsigned char *ip;
227              
228             #define T0_LOCAL(x) (*(rp - 2 - (x)))
229             #define T0_POP() (*-- dp)
230             #define T0_POPi() (*(int32_t *)(-- dp))
231             #define T0_PEEK(x) (*(dp - 1 - (x)))
232             #define T0_PEEKi(x) (*(int32_t *)(dp - 1 - (x)))
233             #define T0_PUSH(v) do { *dp = (v); dp ++; } while (0)
234             #define T0_PUSHi(v) do { *(int32_t *)dp = (v); dp ++; } while (0)
235             #define T0_RPOP() (*-- rp)
236             #define T0_RPOPi() (*(int32_t *)(-- rp))
237             #define T0_RPUSH(v) do { *rp = (v); rp ++; } while (0)
238             #define T0_RPUSHi(v) do { *(int32_t *)rp = (v); rp ++; } while (0)
239             #define T0_ROLL(x) do { \
240             size_t t0len = (size_t)(x); \
241             uint32_t t0tmp = *(dp - 1 - t0len); \
242             memmove(dp - t0len - 1, dp - t0len, t0len * sizeof *dp); \
243             *(dp - 1) = t0tmp; \
244             } while (0)
245             #define T0_SWAP() do { \
246             uint32_t t0tmp = *(dp - 2); \
247             *(dp - 2) = *(dp - 1); \
248             *(dp - 1) = t0tmp; \
249             } while (0)
250             #define T0_ROT() do { \
251             uint32_t t0tmp = *(dp - 3); \
252             *(dp - 3) = *(dp - 2); \
253             *(dp - 2) = *(dp - 1); \
254             *(dp - 1) = t0tmp; \
255             } while (0)
256             #define T0_NROT() do { \
257             uint32_t t0tmp = *(dp - 1); \
258             *(dp - 1) = *(dp - 2); \
259             *(dp - 2) = *(dp - 3); \
260             *(dp - 3) = t0tmp; \
261             } while (0)
262             #define T0_PICK(x) do { \
263             uint32_t t0depth = (x); \
264             T0_PUSH(T0_PEEK(t0depth)); \
265             } while (0)
266             #define T0_CO() do { \
267             goto t0_exit; \
268             } while (0)
269             #define T0_RET() goto t0_next
270              
271 364           dp = ((t0_context *)t0ctx)->dp;
272 364           rp = ((t0_context *)t0ctx)->rp;
273 364           ip = ((t0_context *)t0ctx)->ip;
274 364           goto t0_next;
275 10391656           for (;;) {
276             uint32_t t0x;
277              
278 10392020           t0_next:
279 10392020           t0x = T0_NEXT(&ip);
280 10392020 100         if (t0x < T0_INTERPRETED) {
281 9232647           switch (t0x) {
282             int32_t t0off;
283              
284 1159334           case 0: /* ret */
285 1159334           t0x = T0_RPOP();
286 1159334           rp -= (t0x >> 16);
287 1159334           t0x &= 0xFFFF;
288 1159334 50         if (t0x == 0) {
289 0           ip = NULL;
290 0           goto t0_exit;
291             }
292 1159334           ip = &t0_codeblock[t0x];
293 1159334           break;
294 1790270           case 1: /* literal constant */
295 1790270           T0_PUSHi(t0_parse7E_signed(&ip));
296 1790270           break;
297 326231           case 2: /* read local */
298 326231           T0_PUSH(T0_LOCAL(t0_parse7E_unsigned(&ip)));
299 326231           break;
300 274802           case 3: /* write local */
301 274802           T0_LOCAL(t0_parse7E_unsigned(&ip)) = T0_POP();
302 274802           break;
303 128968           case 4: /* jump */
304 128968           t0off = t0_parse7E_signed(&ip);
305 128968           ip += t0off;
306 128968           break;
307 410874           case 5: /* jump if */
308 410874           t0off = t0_parse7E_signed(&ip);
309 410874 100         if (T0_POP()) {
310 9407           ip += t0off;
311             }
312 410874           break;
313 762195           case 6: /* jump if not */
314 762195           t0off = t0_parse7E_signed(&ip);
315 762195 100         if (!T0_POP()) {
316 686557           ip += t0off;
317             }
318 762195           break;
319 169582           case 7: {
320             /* + */
321              
322 169582           uint32_t b = T0_POP();
323 169582           uint32_t a = T0_POP();
324 169582           T0_PUSH(a + b);
325              
326             }
327 169582           break;
328 3575           case 8: {
329             /* - */
330              
331 3575           uint32_t b = T0_POP();
332 3575           uint32_t a = T0_POP();
333 3575           T0_PUSH(a - b);
334              
335             }
336 3575           break;
337 455041           case 9: {
338             /* < */
339              
340 455041           int32_t b = T0_POPi();
341 455041           int32_t a = T0_POPi();
342 455041           T0_PUSH(-(uint32_t)(a < b));
343              
344             }
345 455041           break;
346 162917           case 10: {
347             /* << */
348              
349 162917           int c = (int)T0_POPi();
350 162917           uint32_t x = T0_POP();
351 162917           T0_PUSH(x << c);
352              
353             }
354 162917           break;
355 229849           case 11: {
356             /* <= */
357              
358 229849           int32_t b = T0_POPi();
359 229849           int32_t a = T0_POPi();
360 229849           T0_PUSH(-(uint32_t)(a <= b));
361              
362             }
363 229849           break;
364 232592           case 12: {
365             /* <> */
366              
367 232592           uint32_t b = T0_POP();
368 232592           uint32_t a = T0_POP();
369 232592           T0_PUSH(-(uint32_t)(a != b));
370              
371             }
372 232592           break;
373 464251           case 13: {
374             /* = */
375              
376 464251           uint32_t b = T0_POP();
377 464251           uint32_t a = T0_POP();
378 464251           T0_PUSH(-(uint32_t)(a == b));
379              
380             }
381 464251           break;
382 9580           case 14: {
383             /* >= */
384              
385 9580           int32_t b = T0_POPi();
386 9580           int32_t a = T0_POPi();
387 9580           T0_PUSH(-(uint32_t)(a >= b));
388              
389             }
390 9580           break;
391 108657           case 15: {
392             /* >> */
393              
394 108657           int c = (int)T0_POPi();
395 108657           int32_t x = T0_POPi();
396 108657           T0_PUSHi(x >> c);
397              
398             }
399 108657           break;
400 229936           case 16: {
401             /* and */
402              
403 229936           uint32_t b = T0_POP();
404 229936           uint32_t a = T0_POP();
405 229936           T0_PUSH(a & b);
406              
407             }
408 229936           break;
409 364           case 17: {
410             /* co */
411 364           T0_CO();
412             }
413             break;
414 3705           case 18: {
415             /* data-get8 */
416              
417 3705           size_t addr = T0_POP();
418 3705           T0_PUSH(t0_datablock[addr]);
419              
420             }
421 3705           break;
422 62141           case 19: {
423             /* drop */
424 62141           (void)T0_POP();
425             }
426 62141           break;
427 1319225           case 20: {
428             /* dup */
429 1319225           T0_PUSH(T0_PEEK(0));
430             }
431 1319225           break;
432 155           case 21: {
433             /* flush-buf */
434              
435 155 100         if (CTX->ptr > 0) {
436 154 50         if (CTX->dest) {
437 154           CTX->dest(CTX->dest_ctx, CTX->buf, CTX->ptr);
438             }
439 154           CTX->ptr = 0;
440             }
441              
442             }
443 155           break;
444 217264           case 22: {
445             /* from-base64 */
446              
447 217264           uint32_t c = T0_POP();
448             uint32_t p, q, r, z;
449 217264           p = c - 0x41;
450 217264           q = c - 0x61;
451 217264           r = c - 0x30;
452              
453 217264           z = ((p + 2) & -LT(p, 26))
454 217264           | ((q + 28) & -LT(q, 26))
455 217264           | ((r + 54) & -LT(r, 10))
456 217264           | (64 & -EQ(c, 0x2B))
457 217264           | (65 & -EQ(c, 0x2F))
458 217264           | EQ(c, 0x3D);
459 217264           T0_PUSHi((int32_t)z - 2);
460              
461             }
462 217264           break;
463 930           case 23: {
464             /* get8 */
465              
466 930           size_t addr = T0_POP();
467 930           T0_PUSH(*((unsigned char *)CTX + addr));
468              
469             }
470 930           break;
471 71296           case 24: {
472             /* over */
473 71296           T0_PUSH(T0_PEEK(1));
474             }
475 71296           break;
476 237777           case 25: {
477             /* read8-native */
478              
479 237777 100         if (CTX->hlen > 0) {
480 237723           T0_PUSH(*CTX->hbuf ++);
481 237723           CTX->hlen --;
482             } else {
483 54           T0_PUSHi(-1);
484             }
485              
486             }
487 237777           break;
488 2945           case 26: {
489             /* set8 */
490              
491 2945           size_t addr = T0_POP();
492 2945           unsigned x = T0_POP();
493 2945           *((unsigned char *)CTX + addr) = x;
494              
495             }
496 2945           break;
497 235274           case 27: {
498             /* swap */
499 235274           T0_SWAP();
500             }
501 235274           break;
502 162917           case 28: {
503             /* write8 */
504              
505 162917           unsigned char x = (unsigned char)T0_POP();
506 162917           CTX->buf[CTX->ptr ++] = x;
507 162917 100         if (CTX->ptr == sizeof CTX->buf) {
508 564 50         if (CTX->dest) {
509 564           CTX->dest(CTX->dest_ctx, CTX->buf, sizeof CTX->buf);
510             }
511 564           CTX->ptr = 0;
512             }
513              
514             }
515 162917           break;
516             }
517              
518             } else {
519 1159373           T0_ENTER(ip, rp, t0x);
520             }
521             }
522 364           t0_exit:
523 364           ((t0_context *)t0ctx)->dp = dp;
524 364           ((t0_context *)t0ctx)->rp = rp;
525 364           ((t0_context *)t0ctx)->ip = ip;
526 364           }