der.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_INTERNAL_DER_H
  10. # define OSSL_INTERNAL_DER_H
  11. # pragma once
  12. # include <openssl/bn.h>
  13. # include "internal/packet.h"
  14. /*
  15. * NOTE: X.690 numbers the identifier octet bits 1 to 8.
  16. * We use the same numbering in comments here.
  17. */
  18. /* Well known primitive tags */
  19. /*
  20. * DER UNIVERSAL tags, occupying bits 1-5 in the DER identifier byte
  21. * These are only valid for the UNIVERSAL class. With the other classes,
  22. * these bits have a different meaning.
  23. */
  24. # define DER_P_EOC 0 /* BER End Of Contents tag */
  25. # define DER_P_BOOLEAN 1
  26. # define DER_P_INTEGER 2
  27. # define DER_P_BIT_STRING 3
  28. # define DER_P_OCTET_STRING 4
  29. # define DER_P_NULL 5
  30. # define DER_P_OBJECT 6
  31. # define DER_P_OBJECT_DESCRIPTOR 7
  32. # define DER_P_EXTERNAL 8
  33. # define DER_P_REAL 9
  34. # define DER_P_ENUMERATED 10
  35. # define DER_P_UTF8STRING 12
  36. # define DER_P_SEQUENCE 16
  37. # define DER_P_SET 17
  38. # define DER_P_NUMERICSTRING 18
  39. # define DER_P_PRINTABLESTRING 19
  40. # define DER_P_T61STRING 20
  41. # define DER_P_VIDEOTEXSTRING 21
  42. # define DER_P_IA5STRING 22
  43. # define DER_P_UTCTIME 23
  44. # define DER_P_GENERALIZEDTIME 24
  45. # define DER_P_GRAPHICSTRING 25
  46. # define DER_P_ISO64STRING 26
  47. # define DER_P_GENERALSTRING 27
  48. # define DER_P_UNIVERSALSTRING 28
  49. # define DER_P_BMPSTRING 30
  50. /* DER Flags, occupying bit 6 in the DER identifier byte */
  51. # define DER_F_PRIMITIVE 0x00
  52. # define DER_F_CONSTRUCTED 0x20
  53. /* DER classes tags, occupying bits 7-8 in the DER identifier byte */
  54. # define DER_C_UNIVERSAL 0x00
  55. # define DER_C_APPLICATION 0x40
  56. # define DER_C_CONTEXT 0x80
  57. # define DER_C_PRIVATE 0xC0
  58. /*
  59. * Run-time constructors.
  60. *
  61. * They all construct DER backwards, so care should be taken to use them
  62. * that way.
  63. */
  64. /* This can be used for all items that don't have a context */
  65. # define DER_NO_CONTEXT -1
  66. int ossl_DER_w_precompiled(WPACKET *pkt, int tag,
  67. const unsigned char *precompiled,
  68. size_t precompiled_n);
  69. int ossl_DER_w_boolean(WPACKET *pkt, int tag, int b);
  70. int ossl_DER_w_uint32(WPACKET *pkt, int tag, uint32_t v);
  71. int ossl_DER_w_bn(WPACKET *pkt, int tag, const BIGNUM *v);
  72. int ossl_DER_w_null(WPACKET *pkt, int tag);
  73. int ossl_DER_w_octet_string(WPACKET *pkt, int tag,
  74. const unsigned char *data, size_t data_n);
  75. int ossl_DER_w_octet_string_uint32(WPACKET *pkt, int tag, uint32_t value);
  76. /*
  77. * All constructors for constructed elements have a begin and a end function
  78. */
  79. int ossl_DER_w_begin_sequence(WPACKET *pkt, int tag);
  80. int ossl_DER_w_end_sequence(WPACKET *pkt, int tag);
  81. #endif