summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/asn1_local.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_local.h')
-rw-r--r--src/lib/libcrypto/asn1/asn1_local.h251
1 files changed, 251 insertions, 0 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_local.h b/src/lib/libcrypto/asn1/asn1_local.h
new file mode 100644
index 0000000000..ed40e18ec9
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_local.h
@@ -0,0 +1,251 @@
1/* $OpenBSD: asn1_local.h,v 1.1 2022/11/26 16:08:50 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006.
4 */
5/* ====================================================================
6 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include "bytestring.h"
60
61__BEGIN_HIDDEN_DECLS
62
63/* Internal ASN1 structures and functions: not for application use */
64
65ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t);
66void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t);
67
68/* These are used internally in the ASN1_OBJECT to keep track of
69 * whether the names and data need to be free()ed */
70#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
71#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
72#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
73#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
74struct asn1_object_st {
75 const char *sn, *ln;
76 int nid;
77 int length;
78 const unsigned char *data; /* data remains const after init */
79 int flags; /* Should we free this one */
80} /* ASN1_OBJECT */;
81
82/* ASN1 print context structure */
83
84struct asn1_pctx_st {
85 unsigned long flags;
86 unsigned long nm_flags;
87 unsigned long cert_flags;
88 unsigned long oid_flags;
89 unsigned long str_flags;
90} /* ASN1_PCTX */;
91
92/* ASN1 public key method structure */
93
94struct evp_pkey_asn1_method_st {
95 int pkey_id;
96 int pkey_base_id;
97 unsigned long pkey_flags;
98
99 char *pem_str;
100 char *info;
101
102 int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub);
103 int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk);
104 int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
105 int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
106 ASN1_PCTX *pctx);
107
108 int (*priv_decode)(EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf);
109 int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
110 int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
111 ASN1_PCTX *pctx);
112
113 int (*pkey_size)(const EVP_PKEY *pk);
114 int (*pkey_bits)(const EVP_PKEY *pk);
115 int (*pkey_security_bits)(const EVP_PKEY *pk);
116
117 int (*param_decode)(EVP_PKEY *pkey, const unsigned char **pder,
118 int derlen);
119 int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder);
120 int (*param_missing)(const EVP_PKEY *pk);
121 int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from);
122 int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
123 int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
124 ASN1_PCTX *pctx);
125 int (*sig_print)(BIO *out, const X509_ALGOR *sigalg,
126 const ASN1_STRING *sig, int indent, ASN1_PCTX *pctx);
127
128 void (*pkey_free)(EVP_PKEY *pkey);
129 int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2);
130
131 /* Legacy functions for old PEM */
132
133 int (*old_priv_decode)(EVP_PKEY *pkey, const unsigned char **pder,
134 int derlen);
135 int (*old_priv_encode)(const EVP_PKEY *pkey, unsigned char **pder);
136 /* Custom ASN1 signature verification */
137 int (*item_verify)(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
138 X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey);
139 int (*item_sign)(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
140 X509_ALGOR *alg1, X509_ALGOR *alg2, ASN1_BIT_STRING *sig);
141
142 int (*pkey_check)(const EVP_PKEY *pk);
143 int (*pkey_public_check)(const EVP_PKEY *pk);
144 int (*pkey_param_check)(const EVP_PKEY *pk);
145
146 int (*set_priv_key)(EVP_PKEY *pk, const unsigned char *private_key,
147 size_t len);
148 int (*set_pub_key)(EVP_PKEY *pk, const unsigned char *public_key,
149 size_t len);
150 int (*get_priv_key)(const EVP_PKEY *pk, unsigned char *out_private_key,
151 size_t *out_len);
152 int (*get_pub_key)(const EVP_PKEY *pk, unsigned char *out_public_key,
153 size_t *out_len);
154} /* EVP_PKEY_ASN1_METHOD */;
155
156/* Method to handle CRL access.
157 * In general a CRL could be very large (several Mb) and can consume large
158 * amounts of resources if stored in memory by multiple processes.
159 * This method allows general CRL operations to be redirected to more
160 * efficient callbacks: for example a CRL entry database.
161 */
162
163#define X509_CRL_METHOD_DYNAMIC 1
164
165struct x509_crl_method_st {
166 int flags;
167 int (*crl_init)(X509_CRL *crl);
168 int (*crl_free)(X509_CRL *crl);
169 int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
170 ASN1_INTEGER *ser, X509_NAME *issuer);
171 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk);
172};
173
174int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
175int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
176
177ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
178
179const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
180
181int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
182
183void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
184void asn1_enc_cleanup(ASN1_VALUE **pval, const ASN1_ITEM *it);
185int asn1_enc_save(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it);
186int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
187
188int i2d_ASN1_BOOLEAN(int a, unsigned char **pp);
189int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length);
190
191/*
192 * Unicode codepoint constants
193 */
194#define UNICODE_MAX 0x10FFFF
195#define UNICODE_SURROGATE_MIN 0x00D800
196#define UNICODE_SURROGATE_MAX 0x00DFFF
197
198#define UNICODE_IS_SURROGATE(x) \
199 ((x) >= UNICODE_SURROGATE_MIN && (x) <= UNICODE_SURROGATE_MAX)
200
201int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
202int UTF8_putc(unsigned char *str, int len, unsigned long value);
203
204int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
205
206int asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class,
207 int *out_constructed, uint32_t *out_tag_number);
208int asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite,
209 size_t *out_length);
210int asn1_get_object_cbs(CBS *cbs, int der_mode, uint8_t *out_class,
211 int *out_constructed, uint32_t *out_tag_number, int *out_indefinite,
212 size_t *out_length);
213int asn1_get_primitive(CBS *cbs, int der_mode, uint32_t *out_tag_number,
214 CBS *out_content);
215
216int asn1_must_be_constructed(int tag);
217int asn1_must_be_primitive(int tag);
218int asn1_tag2charwidth(int tag);
219
220int asn1_abs_set_unused_bits(ASN1_BIT_STRING *abs, uint8_t unused_bits);
221int c2i_ASN1_BIT_STRING_cbs(ASN1_BIT_STRING **out_abs, CBS *cbs);
222
223int c2i_ASN1_ENUMERATED_cbs(ASN1_ENUMERATED **out_aenum, CBS *cbs);
224
225int asn1_aint_get_uint64(CBS *cbs, uint64_t *out_val);
226int asn1_aint_set_uint64(uint64_t val, uint8_t **out_data, int *out_len);
227int asn1_aint_get_int64(CBS *cbs, int negative, int64_t *out_val);
228int c2i_ASN1_INTEGER_cbs(ASN1_INTEGER **out_aint, CBS *cbs);
229
230int c2i_ASN1_OBJECT_cbs(ASN1_OBJECT **out_aobj, CBS *content);
231int i2t_ASN1_OBJECT_internal(const ASN1_OBJECT *aobj, char *buf, int buf_len,
232 int no_name);
233ASN1_OBJECT *t2i_ASN1_OBJECT_internal(const char *oid);
234
235int asn1_time_parse_cbs(const CBS *cbs, int is_gentime, struct tm *out_tm);
236
237ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
238 long length);
239int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp);
240ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
241 const unsigned char **pp, long length);
242int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp);
243ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
244 long length);
245int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);
246int OPENSSL_gmtime_diff(int *pday, int *psec, const struct tm *from,
247 const struct tm *to);
248int asn1_time_time_t_to_tm(const time_t *time, struct tm *out_tm);
249int asn1_time_tm_to_time_t(const struct tm *tm, time_t *out);
250
251__END_HIDDEN_DECLS