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