blob: ab3a6c002f7b9d2e265b08061d78e7f260b13633 [file] [log] [blame]
David Howells4520c6a2012-09-21 23:31:13 +01001/* ASN.1 BER/DER/CER parsing state machine internal definitions
2 *
3 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
12#ifndef _LINUX_ASN1_BER_BYTECODE_H
13#define _LINUX_ASN1_BER_BYTECODE_H
14
15#ifdef __KERNEL__
16#include <linux/types.h>
17#endif
18#include <linux/asn1.h>
19
20typedef int (*asn1_action_t)(void *context,
21 size_t hdrlen, /* In case of ANY type */
22 unsigned char tag, /* In case of ANY type */
23 const void *value, size_t vlen);
24
25struct asn1_decoder {
26 const unsigned char *machine;
27 size_t machlen;
28 const asn1_action_t *actions;
29};
30
31enum asn1_opcode {
32 /* The tag-matching ops come first and the odd-numbered slots
33 * are for OR_SKIP ops.
34 */
35#define ASN1_OP_MATCH__SKIP 0x01
36#define ASN1_OP_MATCH__ACT 0x02
37#define ASN1_OP_MATCH__JUMP 0x04
38#define ASN1_OP_MATCH__ANY 0x08
39#define ASN1_OP_MATCH__COND 0x10
40
41 ASN1_OP_MATCH = 0x00,
42 ASN1_OP_MATCH_OR_SKIP = 0x01,
43 ASN1_OP_MATCH_ACT = 0x02,
44 ASN1_OP_MATCH_ACT_OR_SKIP = 0x03,
45 ASN1_OP_MATCH_JUMP = 0x04,
46 ASN1_OP_MATCH_JUMP_OR_SKIP = 0x05,
47 ASN1_OP_MATCH_ANY = 0x08,
David Howells233ce792015-08-05 12:54:46 +010048 ASN1_OP_MATCH_ANY_OR_SKIP = 0x09,
David Howells4520c6a2012-09-21 23:31:13 +010049 ASN1_OP_MATCH_ANY_ACT = 0x0a,
David Howells233ce792015-08-05 12:54:46 +010050 ASN1_OP_MATCH_ANY_ACT_OR_SKIP = 0x0b,
David Howells4520c6a2012-09-21 23:31:13 +010051 /* Everything before here matches unconditionally */
52
53 ASN1_OP_COND_MATCH_OR_SKIP = 0x11,
54 ASN1_OP_COND_MATCH_ACT_OR_SKIP = 0x13,
55 ASN1_OP_COND_MATCH_JUMP_OR_SKIP = 0x15,
56 ASN1_OP_COND_MATCH_ANY = 0x18,
David Howells233ce792015-08-05 12:54:46 +010057 ASN1_OP_COND_MATCH_ANY_OR_SKIP = 0x19,
David Howells4520c6a2012-09-21 23:31:13 +010058 ASN1_OP_COND_MATCH_ANY_ACT = 0x1a,
David Howells233ce792015-08-05 12:54:46 +010059 ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP = 0x1b,
David Howells4520c6a2012-09-21 23:31:13 +010060
61 /* Everything before here will want a tag from the data */
David Howells233ce792015-08-05 12:54:46 +010062#define ASN1_OP__MATCHES_TAG ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP
David Howells4520c6a2012-09-21 23:31:13 +010063
64 /* These are here to help fill up space */
David Howells233ce792015-08-05 12:54:46 +010065 ASN1_OP_COND_FAIL = 0x1c,
66 ASN1_OP_COMPLETE = 0x1d,
67 ASN1_OP_ACT = 0x1e,
68 ASN1_OP_MAYBE_ACT = 0x1f,
David Howells4520c6a2012-09-21 23:31:13 +010069
70 /* The following eight have bit 0 -> SET, 1 -> OF, 2 -> ACT */
71 ASN1_OP_END_SEQ = 0x20,
72 ASN1_OP_END_SET = 0x21,
73 ASN1_OP_END_SEQ_OF = 0x22,
74 ASN1_OP_END_SET_OF = 0x23,
75 ASN1_OP_END_SEQ_ACT = 0x24,
76 ASN1_OP_END_SET_ACT = 0x25,
77 ASN1_OP_END_SEQ_OF_ACT = 0x26,
78 ASN1_OP_END_SET_OF_ACT = 0x27,
79#define ASN1_OP_END__SET 0x01
80#define ASN1_OP_END__OF 0x02
81#define ASN1_OP_END__ACT 0x04
82
David Howells233ce792015-08-05 12:54:46 +010083 ASN1_OP_RETURN = 0x28,
84
David Howells4520c6a2012-09-21 23:31:13 +010085 ASN1_OP__NR
86};
87
88#define _tag(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | ASN1_##TAG)
89#define _tagn(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | TAG)
90#define _jump_target(N) (N)
91#define _action(N) (N)
92
93#endif /* _LINUX_ASN1_BER_BYTECODE_H */