Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* ASN.1 BER/DER/CER parsing state machine internal definitions
0003  *
0004  * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
0005  * Written by David Howells (dhowells@redhat.com)
0006  */
0007 
0008 #ifndef _LINUX_ASN1_BER_BYTECODE_H
0009 #define _LINUX_ASN1_BER_BYTECODE_H
0010 
0011 #ifdef __KERNEL__
0012 #include <linux/types.h>
0013 #endif
0014 #include <linux/asn1.h>
0015 
0016 typedef int (*asn1_action_t)(void *context,
0017                  size_t hdrlen, /* In case of ANY type */
0018                  unsigned char tag, /* In case of ANY type */
0019                  const void *value, size_t vlen);
0020 
0021 struct asn1_decoder {
0022     const unsigned char *machine;
0023     size_t machlen;
0024     const asn1_action_t *actions;
0025 };
0026 
0027 enum asn1_opcode {
0028     /* The tag-matching ops come first and the odd-numbered slots
0029      * are for OR_SKIP ops.
0030      */
0031 #define ASN1_OP_MATCH__SKIP       0x01
0032 #define ASN1_OP_MATCH__ACT        0x02
0033 #define ASN1_OP_MATCH__JUMP       0x04
0034 #define ASN1_OP_MATCH__ANY        0x08
0035 #define ASN1_OP_MATCH__COND       0x10
0036 
0037     ASN1_OP_MATCH           = 0x00,
0038     ASN1_OP_MATCH_OR_SKIP       = 0x01,
0039     ASN1_OP_MATCH_ACT       = 0x02,
0040     ASN1_OP_MATCH_ACT_OR_SKIP   = 0x03,
0041     ASN1_OP_MATCH_JUMP      = 0x04,
0042     ASN1_OP_MATCH_JUMP_OR_SKIP  = 0x05,
0043     ASN1_OP_MATCH_ANY       = 0x08,
0044     ASN1_OP_MATCH_ANY_OR_SKIP   = 0x09,
0045     ASN1_OP_MATCH_ANY_ACT       = 0x0a,
0046     ASN1_OP_MATCH_ANY_ACT_OR_SKIP   = 0x0b,
0047     /* Everything before here matches unconditionally */
0048 
0049     ASN1_OP_COND_MATCH_OR_SKIP  = 0x11,
0050     ASN1_OP_COND_MATCH_ACT_OR_SKIP  = 0x13,
0051     ASN1_OP_COND_MATCH_JUMP_OR_SKIP = 0x15,
0052     ASN1_OP_COND_MATCH_ANY      = 0x18,
0053     ASN1_OP_COND_MATCH_ANY_OR_SKIP  = 0x19,
0054     ASN1_OP_COND_MATCH_ANY_ACT  = 0x1a,
0055     ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP = 0x1b,
0056 
0057     /* Everything before here will want a tag from the data */
0058 #define ASN1_OP__MATCHES_TAG ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP
0059 
0060     /* These are here to help fill up space */
0061     ASN1_OP_COND_FAIL       = 0x1c,
0062     ASN1_OP_COMPLETE        = 0x1d,
0063     ASN1_OP_ACT         = 0x1e,
0064     ASN1_OP_MAYBE_ACT       = 0x1f,
0065 
0066     /* The following eight have bit 0 -> SET, 1 -> OF, 2 -> ACT */
0067     ASN1_OP_END_SEQ         = 0x20,
0068     ASN1_OP_END_SET         = 0x21,
0069     ASN1_OP_END_SEQ_OF      = 0x22,
0070     ASN1_OP_END_SET_OF      = 0x23,
0071     ASN1_OP_END_SEQ_ACT     = 0x24,
0072     ASN1_OP_END_SET_ACT     = 0x25,
0073     ASN1_OP_END_SEQ_OF_ACT      = 0x26,
0074     ASN1_OP_END_SET_OF_ACT      = 0x27,
0075 #define ASN1_OP_END__SET          0x01
0076 #define ASN1_OP_END__OF           0x02
0077 #define ASN1_OP_END__ACT          0x04
0078 
0079     ASN1_OP_RETURN          = 0x28,
0080 
0081     ASN1_OP__NR
0082 };
0083 
0084 #define _tag(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | ASN1_##TAG)
0085 #define _tagn(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | TAG)
0086 #define _jump_target(N) (N)
0087 #define _action(N) (N)
0088 
0089 #endif /* _LINUX_ASN1_BER_BYTECODE_H */