18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* ASN.1 BER/DER/CER parsing state machine internal definitions 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. 58c2ecf20Sopenharmony_ci * Written by David Howells (dhowells@redhat.com) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _LINUX_ASN1_BER_BYTECODE_H 98c2ecf20Sopenharmony_ci#define _LINUX_ASN1_BER_BYTECODE_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 128c2ecf20Sopenharmony_ci#include <linux/types.h> 138c2ecf20Sopenharmony_ci#endif 148c2ecf20Sopenharmony_ci#include <linux/asn1.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_citypedef int (*asn1_action_t)(void *context, 178c2ecf20Sopenharmony_ci size_t hdrlen, /* In case of ANY type */ 188c2ecf20Sopenharmony_ci unsigned char tag, /* In case of ANY type */ 198c2ecf20Sopenharmony_ci const void *value, size_t vlen); 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistruct asn1_decoder { 228c2ecf20Sopenharmony_ci const unsigned char *machine; 238c2ecf20Sopenharmony_ci size_t machlen; 248c2ecf20Sopenharmony_ci const asn1_action_t *actions; 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cienum asn1_opcode { 288c2ecf20Sopenharmony_ci /* The tag-matching ops come first and the odd-numbered slots 298c2ecf20Sopenharmony_ci * are for OR_SKIP ops. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci#define ASN1_OP_MATCH__SKIP 0x01 328c2ecf20Sopenharmony_ci#define ASN1_OP_MATCH__ACT 0x02 338c2ecf20Sopenharmony_ci#define ASN1_OP_MATCH__JUMP 0x04 348c2ecf20Sopenharmony_ci#define ASN1_OP_MATCH__ANY 0x08 358c2ecf20Sopenharmony_ci#define ASN1_OP_MATCH__COND 0x10 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci ASN1_OP_MATCH = 0x00, 388c2ecf20Sopenharmony_ci ASN1_OP_MATCH_OR_SKIP = 0x01, 398c2ecf20Sopenharmony_ci ASN1_OP_MATCH_ACT = 0x02, 408c2ecf20Sopenharmony_ci ASN1_OP_MATCH_ACT_OR_SKIP = 0x03, 418c2ecf20Sopenharmony_ci ASN1_OP_MATCH_JUMP = 0x04, 428c2ecf20Sopenharmony_ci ASN1_OP_MATCH_JUMP_OR_SKIP = 0x05, 438c2ecf20Sopenharmony_ci ASN1_OP_MATCH_ANY = 0x08, 448c2ecf20Sopenharmony_ci ASN1_OP_MATCH_ANY_OR_SKIP = 0x09, 458c2ecf20Sopenharmony_ci ASN1_OP_MATCH_ANY_ACT = 0x0a, 468c2ecf20Sopenharmony_ci ASN1_OP_MATCH_ANY_ACT_OR_SKIP = 0x0b, 478c2ecf20Sopenharmony_ci /* Everything before here matches unconditionally */ 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci ASN1_OP_COND_MATCH_OR_SKIP = 0x11, 508c2ecf20Sopenharmony_ci ASN1_OP_COND_MATCH_ACT_OR_SKIP = 0x13, 518c2ecf20Sopenharmony_ci ASN1_OP_COND_MATCH_JUMP_OR_SKIP = 0x15, 528c2ecf20Sopenharmony_ci ASN1_OP_COND_MATCH_ANY = 0x18, 538c2ecf20Sopenharmony_ci ASN1_OP_COND_MATCH_ANY_OR_SKIP = 0x19, 548c2ecf20Sopenharmony_ci ASN1_OP_COND_MATCH_ANY_ACT = 0x1a, 558c2ecf20Sopenharmony_ci ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP = 0x1b, 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci /* Everything before here will want a tag from the data */ 588c2ecf20Sopenharmony_ci#define ASN1_OP__MATCHES_TAG ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci /* These are here to help fill up space */ 618c2ecf20Sopenharmony_ci ASN1_OP_COND_FAIL = 0x1c, 628c2ecf20Sopenharmony_ci ASN1_OP_COMPLETE = 0x1d, 638c2ecf20Sopenharmony_ci ASN1_OP_ACT = 0x1e, 648c2ecf20Sopenharmony_ci ASN1_OP_MAYBE_ACT = 0x1f, 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci /* The following eight have bit 0 -> SET, 1 -> OF, 2 -> ACT */ 678c2ecf20Sopenharmony_ci ASN1_OP_END_SEQ = 0x20, 688c2ecf20Sopenharmony_ci ASN1_OP_END_SET = 0x21, 698c2ecf20Sopenharmony_ci ASN1_OP_END_SEQ_OF = 0x22, 708c2ecf20Sopenharmony_ci ASN1_OP_END_SET_OF = 0x23, 718c2ecf20Sopenharmony_ci ASN1_OP_END_SEQ_ACT = 0x24, 728c2ecf20Sopenharmony_ci ASN1_OP_END_SET_ACT = 0x25, 738c2ecf20Sopenharmony_ci ASN1_OP_END_SEQ_OF_ACT = 0x26, 748c2ecf20Sopenharmony_ci ASN1_OP_END_SET_OF_ACT = 0x27, 758c2ecf20Sopenharmony_ci#define ASN1_OP_END__SET 0x01 768c2ecf20Sopenharmony_ci#define ASN1_OP_END__OF 0x02 778c2ecf20Sopenharmony_ci#define ASN1_OP_END__ACT 0x04 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci ASN1_OP_RETURN = 0x28, 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci ASN1_OP__NR 828c2ecf20Sopenharmony_ci}; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define _tag(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | ASN1_##TAG) 858c2ecf20Sopenharmony_ci#define _tagn(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | TAG) 868c2ecf20Sopenharmony_ci#define _jump_target(N) (N) 878c2ecf20Sopenharmony_ci#define _action(N) (N) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#endif /* _LINUX_ASN1_BER_BYTECODE_H */ 90