asn1_ber_bytecode.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* ASN.1 BER/DER/CER parsing state machine internal definitions
  3. *
  4. * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #ifndef _LINUX_ASN1_BER_BYTECODE_H
  8. #define _LINUX_ASN1_BER_BYTECODE_H
  9. #ifdef __KERNEL__
  10. #include <linux/types.h>
  11. #endif
  12. #include <linux/asn1.h>
  13. typedef int (*asn1_action_t)(void *context,
  14. size_t hdrlen, /* In case of ANY type */
  15. unsigned char tag, /* In case of ANY type */
  16. const void *value, size_t vlen);
  17. struct asn1_decoder {
  18. const unsigned char *machine;
  19. size_t machlen;
  20. const asn1_action_t *actions;
  21. };
  22. enum asn1_opcode {
  23. /* The tag-matching ops come first and the odd-numbered slots
  24. * are for OR_SKIP ops.
  25. */
  26. #define ASN1_OP_MATCH__SKIP 0x01
  27. #define ASN1_OP_MATCH__ACT 0x02
  28. #define ASN1_OP_MATCH__JUMP 0x04
  29. #define ASN1_OP_MATCH__ANY 0x08
  30. #define ASN1_OP_MATCH__COND 0x10
  31. ASN1_OP_MATCH = 0x00,
  32. ASN1_OP_MATCH_OR_SKIP = 0x01,
  33. ASN1_OP_MATCH_ACT = 0x02,
  34. ASN1_OP_MATCH_ACT_OR_SKIP = 0x03,
  35. ASN1_OP_MATCH_JUMP = 0x04,
  36. ASN1_OP_MATCH_JUMP_OR_SKIP = 0x05,
  37. ASN1_OP_MATCH_ANY = 0x08,
  38. ASN1_OP_MATCH_ANY_OR_SKIP = 0x09,
  39. ASN1_OP_MATCH_ANY_ACT = 0x0a,
  40. ASN1_OP_MATCH_ANY_ACT_OR_SKIP = 0x0b,
  41. /* Everything before here matches unconditionally */
  42. ASN1_OP_COND_MATCH_OR_SKIP = 0x11,
  43. ASN1_OP_COND_MATCH_ACT_OR_SKIP = 0x13,
  44. ASN1_OP_COND_MATCH_JUMP_OR_SKIP = 0x15,
  45. ASN1_OP_COND_MATCH_ANY = 0x18,
  46. ASN1_OP_COND_MATCH_ANY_OR_SKIP = 0x19,
  47. ASN1_OP_COND_MATCH_ANY_ACT = 0x1a,
  48. ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP = 0x1b,
  49. /* Everything before here will want a tag from the data */
  50. #define ASN1_OP__MATCHES_TAG ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP
  51. /* These are here to help fill up space */
  52. ASN1_OP_COND_FAIL = 0x1c,
  53. ASN1_OP_COMPLETE = 0x1d,
  54. ASN1_OP_ACT = 0x1e,
  55. ASN1_OP_MAYBE_ACT = 0x1f,
  56. /* The following eight have bit 0 -> SET, 1 -> OF, 2 -> ACT */
  57. ASN1_OP_END_SEQ = 0x20,
  58. ASN1_OP_END_SET = 0x21,
  59. ASN1_OP_END_SEQ_OF = 0x22,
  60. ASN1_OP_END_SET_OF = 0x23,
  61. ASN1_OP_END_SEQ_ACT = 0x24,
  62. ASN1_OP_END_SET_ACT = 0x25,
  63. ASN1_OP_END_SEQ_OF_ACT = 0x26,
  64. ASN1_OP_END_SET_OF_ACT = 0x27,
  65. #define ASN1_OP_END__SET 0x01
  66. #define ASN1_OP_END__OF 0x02
  67. #define ASN1_OP_END__ACT 0x04
  68. ASN1_OP_RETURN = 0x28,
  69. ASN1_OP__NR
  70. };
  71. #define _tag(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | ASN1_##TAG)
  72. #define _tagn(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | TAG)
  73. #define _jump_target(N) (N)
  74. #define _action(N) (N)
  75. #endif /* _LINUX_ASN1_BER_BYTECODE_H */