1/*
2 * WARNING: do not edit!
3 * Generated by Makefile from include/openssl/asn1.h.in
4 *
5 * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
6 *
7 * Licensed under the Apache License 2.0 (the "License"). You may not use
8 * this file except in compliance with the License. You can obtain a copy
9 * in the file LICENSE in the source distribution or at
10 * https://www.openssl.org/source/license.html
11 */
12
13
14
15#ifndef OPENSSL_ASN1_H
16# define OPENSSL_ASN1_H
17# pragma once
18
19# include <openssl/macros.h>
20# ifndef OPENSSL_NO_DEPRECATED_3_0
21# define HEADER_ASN1_H
22# endif
23
24# ifndef OPENSSL_NO_STDIO
25# include <stdio.h>
26# endif
27# include <time.h>
28# include <openssl/e_os2.h>
29# include <openssl/opensslconf.h>
30# include <openssl/bio.h>
31# include <openssl/safestack.h>
32# include <openssl/asn1err.h>
33# include <openssl/symhacks.h>
34
35# include <openssl/types.h>
36# include <openssl/bn.h>
37
38# ifdef OPENSSL_BUILD_SHLIBCRYPTO
39# undef OPENSSL_EXTERN
40# define OPENSSL_EXTERN OPENSSL_EXPORT
41# endif
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47# define V_ASN1_UNIVERSAL 0x00
48# define V_ASN1_APPLICATION 0x40
49# define V_ASN1_CONTEXT_SPECIFIC 0x80
50# define V_ASN1_PRIVATE 0xc0
51
52# define V_ASN1_CONSTRUCTED 0x20
53# define V_ASN1_PRIMITIVE_TAG 0x1f
54# define V_ASN1_PRIMATIVE_TAG /*compat*/ V_ASN1_PRIMITIVE_TAG
55
56# define V_ASN1_APP_CHOOSE -2/* let the recipient choose */
57# define V_ASN1_OTHER -3/* used in ASN1_TYPE */
58# define V_ASN1_ANY -4/* used in ASN1 template code */
59
60# define V_ASN1_UNDEF -1
61/* ASN.1 tag values */
62# define V_ASN1_EOC 0
63# define V_ASN1_BOOLEAN 1 /**/
64# define V_ASN1_INTEGER 2
65# define V_ASN1_BIT_STRING 3
66# define V_ASN1_OCTET_STRING 4
67# define V_ASN1_NULL 5
68# define V_ASN1_OBJECT 6
69# define V_ASN1_OBJECT_DESCRIPTOR 7
70# define V_ASN1_EXTERNAL 8
71# define V_ASN1_REAL 9
72# define V_ASN1_ENUMERATED 10
73# define V_ASN1_UTF8STRING 12
74# define V_ASN1_SEQUENCE 16
75# define V_ASN1_SET 17
76# define V_ASN1_NUMERICSTRING 18 /**/
77# define V_ASN1_PRINTABLESTRING 19
78# define V_ASN1_T61STRING 20
79# define V_ASN1_TELETEXSTRING 20/* alias */
80# define V_ASN1_VIDEOTEXSTRING 21 /**/
81# define V_ASN1_IA5STRING 22
82# define V_ASN1_UTCTIME 23
83# define V_ASN1_GENERALIZEDTIME 24 /**/
84# define V_ASN1_GRAPHICSTRING 25 /**/
85# define V_ASN1_ISO64STRING 26 /**/
86# define V_ASN1_VISIBLESTRING 26/* alias */
87# define V_ASN1_GENERALSTRING 27 /**/
88# define V_ASN1_UNIVERSALSTRING 28 /**/
89# define V_ASN1_BMPSTRING 30
90
91/*
92 * NB the constants below are used internally by ASN1_INTEGER
93 * and ASN1_ENUMERATED to indicate the sign. They are *not* on
94 * the wire tag values.
95 */
96
97# define V_ASN1_NEG 0x100
98# define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
99# define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
100
101/* For use with d2i_ASN1_type_bytes() */
102# define B_ASN1_NUMERICSTRING 0x0001
103# define B_ASN1_PRINTABLESTRING 0x0002
104# define B_ASN1_T61STRING 0x0004
105# define B_ASN1_TELETEXSTRING 0x0004
106# define B_ASN1_VIDEOTEXSTRING 0x0008
107# define B_ASN1_IA5STRING 0x0010
108# define B_ASN1_GRAPHICSTRING 0x0020
109# define B_ASN1_ISO64STRING 0x0040
110# define B_ASN1_VISIBLESTRING 0x0040
111# define B_ASN1_GENERALSTRING 0x0080
112# define B_ASN1_UNIVERSALSTRING 0x0100
113# define B_ASN1_OCTET_STRING 0x0200
114# define B_ASN1_BIT_STRING 0x0400
115# define B_ASN1_BMPSTRING 0x0800
116# define B_ASN1_UNKNOWN 0x1000
117# define B_ASN1_UTF8STRING 0x2000
118# define B_ASN1_UTCTIME 0x4000
119# define B_ASN1_GENERALIZEDTIME 0x8000
120# define B_ASN1_SEQUENCE 0x10000
121/* For use with ASN1_mbstring_copy() */
122# define MBSTRING_FLAG 0x1000
123# define MBSTRING_UTF8 (MBSTRING_FLAG)
124# define MBSTRING_ASC (MBSTRING_FLAG|1)
125# define MBSTRING_BMP (MBSTRING_FLAG|2)
126# define MBSTRING_UNIV (MBSTRING_FLAG|4)
127# define SMIME_OLDMIME 0x400
128# define SMIME_CRLFEOL 0x800
129# define SMIME_STREAM 0x1000
130
131/* Stacks for types not otherwise defined in this header */
132SKM_DEFINE_STACK_OF_INTERNAL(X509_ALGOR, X509_ALGOR, X509_ALGOR)
133#define sk_X509_ALGOR_num(sk) OPENSSL_sk_num(ossl_check_const_X509_ALGOR_sk_type(sk))
134#define sk_X509_ALGOR_value(sk, idx) ((X509_ALGOR *)OPENSSL_sk_value(ossl_check_const_X509_ALGOR_sk_type(sk), (idx)))
135#define sk_X509_ALGOR_new(cmp) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_new(ossl_check_X509_ALGOR_compfunc_type(cmp)))
136#define sk_X509_ALGOR_new_null() ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_new_null())
137#define sk_X509_ALGOR_new_reserve(cmp, n) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_new_reserve(ossl_check_X509_ALGOR_compfunc_type(cmp), (n)))
138#define sk_X509_ALGOR_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_X509_ALGOR_sk_type(sk), (n))
139#define sk_X509_ALGOR_free(sk) OPENSSL_sk_free(ossl_check_X509_ALGOR_sk_type(sk))
140#define sk_X509_ALGOR_zero(sk) OPENSSL_sk_zero(ossl_check_X509_ALGOR_sk_type(sk))
141#define sk_X509_ALGOR_delete(sk, i) ((X509_ALGOR *)OPENSSL_sk_delete(ossl_check_X509_ALGOR_sk_type(sk), (i)))
142#define sk_X509_ALGOR_delete_ptr(sk, ptr) ((X509_ALGOR *)OPENSSL_sk_delete_ptr(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr)))
143#define sk_X509_ALGOR_push(sk, ptr) OPENSSL_sk_push(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
144#define sk_X509_ALGOR_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
145#define sk_X509_ALGOR_pop(sk) ((X509_ALGOR *)OPENSSL_sk_pop(ossl_check_X509_ALGOR_sk_type(sk)))
146#define sk_X509_ALGOR_shift(sk) ((X509_ALGOR *)OPENSSL_sk_shift(ossl_check_X509_ALGOR_sk_type(sk)))
147#define sk_X509_ALGOR_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_X509_ALGOR_sk_type(sk),ossl_check_X509_ALGOR_freefunc_type(freefunc))
148#define sk_X509_ALGOR_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr), (idx))
149#define sk_X509_ALGOR_set(sk, idx, ptr) ((X509_ALGOR *)OPENSSL_sk_set(ossl_check_X509_ALGOR_sk_type(sk), (idx), ossl_check_X509_ALGOR_type(ptr)))
150#define sk_X509_ALGOR_find(sk, ptr) OPENSSL_sk_find(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
151#define sk_X509_ALGOR_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
152#define sk_X509_ALGOR_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr), pnum)
153#define sk_X509_ALGOR_sort(sk) OPENSSL_sk_sort(ossl_check_X509_ALGOR_sk_type(sk))
154#define sk_X509_ALGOR_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_X509_ALGOR_sk_type(sk))
155#define sk_X509_ALGOR_dup(sk) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_dup(ossl_check_const_X509_ALGOR_sk_type(sk)))
156#define sk_X509_ALGOR_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_copyfunc_type(copyfunc), ossl_check_X509_ALGOR_freefunc_type(freefunc)))
157#define sk_X509_ALGOR_set_cmp_func(sk, cmp) ((sk_X509_ALGOR_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_compfunc_type(cmp)))
158
159
160
161# define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
162/*
163 * This indicates that the ASN1_STRING is not a real value but just a place
164 * holder for the location where indefinite length constructed data should be
165 * inserted in the memory buffer
166 */
167# define ASN1_STRING_FLAG_NDEF 0x010
168
169/*
170 * This flag is used by the CMS code to indicate that a string is not
171 * complete and is a place holder for content when it had all been accessed.
172 * The flag will be reset when content has been written to it.
173 */
174
175# define ASN1_STRING_FLAG_CONT 0x020
176/*
177 * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING
178 * type.
179 */
180# define ASN1_STRING_FLAG_MSTRING 0x040
181/* String is embedded and only content should be freed */
182# define ASN1_STRING_FLAG_EMBED 0x080
183/* String should be parsed in RFC 5280's time format */
184# define ASN1_STRING_FLAG_X509_TIME 0x100
185/* This is the base type that holds just about everything :-) */
186struct asn1_string_st {
187 int length;
188 int type;
189 unsigned char *data;
190 /*
191 * The value of the following field depends on the type being held. It
192 * is mostly being used for BIT_STRING so if the input data has a
193 * non-zero 'unused bits' value, it will be handled correctly
194 */
195 long flags;
196};
197
198/*
199 * ASN1_ENCODING structure: this is used to save the received encoding of an
200 * ASN1 type. This is useful to get round problems with invalid encodings
201 * which can break signatures.
202 */
203
204typedef struct ASN1_ENCODING_st {
205 unsigned char *enc; /* DER encoding */
206 long len; /* Length of encoding */
207 int modified; /* set to 1 if 'enc' is invalid */
208} ASN1_ENCODING;
209
210/* Used with ASN1 LONG type: if a long is set to this it is omitted */
211# define ASN1_LONG_UNDEF 0x7fffffffL
212
213# define STABLE_FLAGS_MALLOC 0x01
214/*
215 * A zero passed to ASN1_STRING_TABLE_new_add for the flags is interpreted
216 * as "don't change" and STABLE_FLAGS_MALLOC is always set. By setting
217 * STABLE_FLAGS_MALLOC only we can clear the existing value. Use the alias
218 * STABLE_FLAGS_CLEAR to reflect this.
219 */
220# define STABLE_FLAGS_CLEAR STABLE_FLAGS_MALLOC
221# define STABLE_NO_MASK 0x02
222# define DIRSTRING_TYPE \
223 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
224# define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
225
226struct asn1_string_table_st {
227 int nid;
228 long minsize;
229 long maxsize;
230 unsigned long mask;
231 unsigned long flags;
232};
233
234SKM_DEFINE_STACK_OF_INTERNAL(ASN1_STRING_TABLE, ASN1_STRING_TABLE, ASN1_STRING_TABLE)
235#define sk_ASN1_STRING_TABLE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk))
236#define sk_ASN1_STRING_TABLE_value(sk, idx) ((ASN1_STRING_TABLE *)OPENSSL_sk_value(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk), (idx)))
237#define sk_ASN1_STRING_TABLE_new(cmp) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_new(ossl_check_ASN1_STRING_TABLE_compfunc_type(cmp)))
238#define sk_ASN1_STRING_TABLE_new_null() ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_new_null())
239#define sk_ASN1_STRING_TABLE_new_reserve(cmp, n) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_STRING_TABLE_compfunc_type(cmp), (n)))
240#define sk_ASN1_STRING_TABLE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_STRING_TABLE_sk_type(sk), (n))
241#define sk_ASN1_STRING_TABLE_free(sk) OPENSSL_sk_free(ossl_check_ASN1_STRING_TABLE_sk_type(sk))
242#define sk_ASN1_STRING_TABLE_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_STRING_TABLE_sk_type(sk))
243#define sk_ASN1_STRING_TABLE_delete(sk, i) ((ASN1_STRING_TABLE *)OPENSSL_sk_delete(ossl_check_ASN1_STRING_TABLE_sk_type(sk), (i)))
244#define sk_ASN1_STRING_TABLE_delete_ptr(sk, ptr) ((ASN1_STRING_TABLE *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr)))
245#define sk_ASN1_STRING_TABLE_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
246#define sk_ASN1_STRING_TABLE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
247#define sk_ASN1_STRING_TABLE_pop(sk) ((ASN1_STRING_TABLE *)OPENSSL_sk_pop(ossl_check_ASN1_STRING_TABLE_sk_type(sk)))
248#define sk_ASN1_STRING_TABLE_shift(sk) ((ASN1_STRING_TABLE *)OPENSSL_sk_shift(ossl_check_ASN1_STRING_TABLE_sk_type(sk)))
249#define sk_ASN1_STRING_TABLE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_STRING_TABLE_sk_type(sk),ossl_check_ASN1_STRING_TABLE_freefunc_type(freefunc))
250#define sk_ASN1_STRING_TABLE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr), (idx))
251#define sk_ASN1_STRING_TABLE_set(sk, idx, ptr) ((ASN1_STRING_TABLE *)OPENSSL_sk_set(ossl_check_ASN1_STRING_TABLE_sk_type(sk), (idx), ossl_check_ASN1_STRING_TABLE_type(ptr)))
252#define sk_ASN1_STRING_TABLE_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
253#define sk_ASN1_STRING_TABLE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
254#define sk_ASN1_STRING_TABLE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr), pnum)
255#define sk_ASN1_STRING_TABLE_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_STRING_TABLE_sk_type(sk))
256#define sk_ASN1_STRING_TABLE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk))
257#define sk_ASN1_STRING_TABLE_dup(sk) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_dup(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk)))
258#define sk_ASN1_STRING_TABLE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_copyfunc_type(copyfunc), ossl_check_ASN1_STRING_TABLE_freefunc_type(freefunc)))
259#define sk_ASN1_STRING_TABLE_set_cmp_func(sk, cmp) ((sk_ASN1_STRING_TABLE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_compfunc_type(cmp)))
260
261
262/* size limits: this stuff is taken straight from RFC2459 */
263
264# define ub_name 32768
265# define ub_common_name 64
266# define ub_locality_name 128
267# define ub_state_name 128
268# define ub_organization_name 64
269# define ub_organization_unit_name 64
270# define ub_title 64
271# define ub_email_address 128
272
273/*
274 * Declarations for template structures: for full definitions see asn1t.h
275 */
276typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
277typedef struct ASN1_TLC_st ASN1_TLC;
278/* This is just an opaque pointer */
279typedef struct ASN1_VALUE_st ASN1_VALUE;
280
281/* Declare ASN1 functions: the implement macro in in asn1t.h */
282
283/*
284 * The mysterious 'extern' that's passed to some macros is innocuous,
285 * and is there to quiet pre-C99 compilers that may complain about empty
286 * arguments in macro calls.
287 */
288
289# define DECLARE_ASN1_FUNCTIONS_attr(attr, type) \
290 DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, type)
291# define DECLARE_ASN1_FUNCTIONS(type) \
292 DECLARE_ASN1_FUNCTIONS_attr(extern, type)
293
294# define DECLARE_ASN1_ALLOC_FUNCTIONS_attr(attr, type) \
295 DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, type)
296# define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \
297 DECLARE_ASN1_ALLOC_FUNCTIONS_attr(extern, type)
298
299# define DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, name) \
300 DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \
301 DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name)
302# define DECLARE_ASN1_FUNCTIONS_name(type, name) \
303 DECLARE_ASN1_FUNCTIONS_name_attr(extern, type, name)
304
305# define DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, itname, name) \
306 DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \
307 DECLARE_ASN1_ITEM_attr(attr, itname)
308# define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
309 DECLARE_ASN1_ENCODE_FUNCTIONS_attr(extern, type, itname, name)
310
311# define DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name) \
312 DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, name, name)
313# define DECLARE_ASN1_ENCODE_FUNCTIONS_name(type, name) \
314 DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(extern, type, name)
315
316# define DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \
317 attr type *d2i_##name(type **a, const unsigned char **in, long len); \
318 attr int i2d_##name(const type *a, unsigned char **out);
319# define DECLARE_ASN1_ENCODE_FUNCTIONS_only(type, name) \
320 DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(extern, type, name)
321
322# define DECLARE_ASN1_NDEF_FUNCTION_attr(attr, name) \
323 attr int i2d_##name##_NDEF(const name *a, unsigned char **out);
324# define DECLARE_ASN1_NDEF_FUNCTION(name) \
325 DECLARE_ASN1_NDEF_FUNCTION_attr(extern, name)
326
327# define DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \
328 attr type *name##_new(void); \
329 attr void name##_free(type *a);
330# define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
331 DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(extern, type, name)
332
333# define DECLARE_ASN1_DUP_FUNCTION_attr(attr, type) \
334 DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, type)
335# define DECLARE_ASN1_DUP_FUNCTION(type) \
336 DECLARE_ASN1_DUP_FUNCTION_attr(extern, type)
337
338# define DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, name) \
339 attr type *name##_dup(const type *a);
340# define DECLARE_ASN1_DUP_FUNCTION_name(type, name) \
341 DECLARE_ASN1_DUP_FUNCTION_name_attr(extern, type, name)
342
343# define DECLARE_ASN1_PRINT_FUNCTION_attr(attr, stname) \
344 DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, stname)
345# define DECLARE_ASN1_PRINT_FUNCTION(stname) \
346 DECLARE_ASN1_PRINT_FUNCTION_attr(extern, stname)
347
348# define DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, fname) \
349 attr int fname##_print_ctx(BIO *out, const stname *x, int indent, \
350 const ASN1_PCTX *pctx);
351# define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \
352 DECLARE_ASN1_PRINT_FUNCTION_fname_attr(extern, stname, fname)
353
354# define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
355# define I2D_OF(type) int (*)(const type *,unsigned char **)
356
357# define CHECKED_D2I_OF(type, d2i) \
358 ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0)))
359# define CHECKED_I2D_OF(type, i2d) \
360 ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0)))
361# define CHECKED_NEW_OF(type, xnew) \
362 ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0)))
363# define CHECKED_PTR_OF(type, p) \
364 ((void*) (1 ? p : (type*)0))
365# define CHECKED_PPTR_OF(type, p) \
366 ((void**) (1 ? p : (type**)0))
367
368# define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
369# define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(const type *,unsigned char **)
370# define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)
371
372typedef void *d2i_of_void(void **, const unsigned char **, long);
373typedef int i2d_of_void(const void *, unsigned char **);
374
375/*-
376 * The following macros and typedefs allow an ASN1_ITEM
377 * to be embedded in a structure and referenced. Since
378 * the ASN1_ITEM pointers need to be globally accessible
379 * (possibly from shared libraries) they may exist in
380 * different forms. On platforms that support it the
381 * ASN1_ITEM structure itself will be globally exported.
382 * Other platforms will export a function that returns
383 * an ASN1_ITEM pointer.
384 *
385 * To handle both cases transparently the macros below
386 * should be used instead of hard coding an ASN1_ITEM
387 * pointer in a structure.
388 *
389 * The structure will look like this:
390 *
391 * typedef struct SOMETHING_st {
392 * ...
393 * ASN1_ITEM_EXP *iptr;
394 * ...
395 * } SOMETHING;
396 *
397 * It would be initialised as e.g.:
398 *
399 * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
400 *
401 * and the actual pointer extracted with:
402 *
403 * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
404 *
405 * Finally an ASN1_ITEM pointer can be extracted from an
406 * appropriate reference with: ASN1_ITEM_rptr(X509). This
407 * would be used when a function takes an ASN1_ITEM * argument.
408 *
409 */
410
411
412/*
413 * Platforms that can't easily handle shared global variables are declared as
414 * functions returning ASN1_ITEM pointers.
415 */
416
417/* ASN1_ITEM pointer exported type */
418typedef const ASN1_ITEM *ASN1_ITEM_EXP (void);
419
420/* Macro to obtain ASN1_ITEM pointer from exported type */
421# define ASN1_ITEM_ptr(iptr) (iptr())
422
423/* Macro to include ASN1_ITEM pointer from base type */
424# define ASN1_ITEM_ref(iptr) (iptr##_it)
425
426# define ASN1_ITEM_rptr(ref) (ref##_it())
427
428# define DECLARE_ASN1_ITEM_attr(attr, name) \
429 attr const ASN1_ITEM * name##_it(void);
430# define DECLARE_ASN1_ITEM(name) \
431 DECLARE_ASN1_ITEM_attr(extern, name)
432
433/* Parameters used by ASN1_STRING_print_ex() */
434
435/*
436 * These determine which characters to escape: RFC2253 special characters,
437 * control characters and MSB set characters
438 */
439
440# define ASN1_STRFLGS_ESC_2253 1
441# define ASN1_STRFLGS_ESC_CTRL 2
442# define ASN1_STRFLGS_ESC_MSB 4
443
444/* Lower 8 bits are reserved as an output type specifier */
445# define ASN1_DTFLGS_TYPE_MASK 0x0FUL
446# define ASN1_DTFLGS_RFC822 0x00UL
447# define ASN1_DTFLGS_ISO8601 0x01UL
448
449/*
450 * This flag determines how we do escaping: normally RC2253 backslash only,
451 * set this to use backslash and quote.
452 */
453
454# define ASN1_STRFLGS_ESC_QUOTE 8
455
456/* These three flags are internal use only. */
457
458/* Character is a valid PrintableString character */
459# define CHARTYPE_PRINTABLESTRING 0x10
460/* Character needs escaping if it is the first character */
461# define CHARTYPE_FIRST_ESC_2253 0x20
462/* Character needs escaping if it is the last character */
463# define CHARTYPE_LAST_ESC_2253 0x40
464
465/*
466 * NB the internal flags are safely reused below by flags handled at the top
467 * level.
468 */
469
470/*
471 * If this is set we convert all character strings to UTF8 first
472 */
473
474# define ASN1_STRFLGS_UTF8_CONVERT 0x10
475
476/*
477 * If this is set we don't attempt to interpret content: just assume all
478 * strings are 1 byte per character. This will produce some pretty odd
479 * looking output!
480 */
481
482# define ASN1_STRFLGS_IGNORE_TYPE 0x20
483
484/* If this is set we include the string type in the output */
485# define ASN1_STRFLGS_SHOW_TYPE 0x40
486
487/*
488 * This determines which strings to display and which to 'dump' (hex dump of
489 * content octets or DER encoding). We can only dump non character strings or
490 * everything. If we don't dump 'unknown' they are interpreted as character
491 * strings with 1 octet per character and are subject to the usual escaping
492 * options.
493 */
494
495# define ASN1_STRFLGS_DUMP_ALL 0x80
496# define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
497
498/*
499 * These determine what 'dumping' does, we can dump the content octets or the
500 * DER encoding: both use the RFC2253 #XXXXX notation.
501 */
502
503# define ASN1_STRFLGS_DUMP_DER 0x200
504
505/*
506 * This flag specifies that RC2254 escaping shall be performed.
507 */
508#define ASN1_STRFLGS_ESC_2254 0x400
509
510/*
511 * All the string flags consistent with RFC2253, escaping control characters
512 * isn't essential in RFC2253 but it is advisable anyway.
513 */
514
515# define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
516 ASN1_STRFLGS_ESC_CTRL | \
517 ASN1_STRFLGS_ESC_MSB | \
518 ASN1_STRFLGS_UTF8_CONVERT | \
519 ASN1_STRFLGS_DUMP_UNKNOWN | \
520 ASN1_STRFLGS_DUMP_DER)
521
522
523struct asn1_type_st {
524 int type;
525 union {
526 char *ptr;
527 ASN1_BOOLEAN boolean;
528 ASN1_STRING *asn1_string;
529 ASN1_OBJECT *object;
530 ASN1_INTEGER *integer;
531 ASN1_ENUMERATED *enumerated;
532 ASN1_BIT_STRING *bit_string;
533 ASN1_OCTET_STRING *octet_string;
534 ASN1_PRINTABLESTRING *printablestring;
535 ASN1_T61STRING *t61string;
536 ASN1_IA5STRING *ia5string;
537 ASN1_GENERALSTRING *generalstring;
538 ASN1_BMPSTRING *bmpstring;
539 ASN1_UNIVERSALSTRING *universalstring;
540 ASN1_UTCTIME *utctime;
541 ASN1_GENERALIZEDTIME *generalizedtime;
542 ASN1_VISIBLESTRING *visiblestring;
543 ASN1_UTF8STRING *utf8string;
544 /*
545 * set and sequence are left complete and still contain the set or
546 * sequence bytes
547 */
548 ASN1_STRING *set;
549 ASN1_STRING *sequence;
550 ASN1_VALUE *asn1_value;
551 } value;
552};
553
554SKM_DEFINE_STACK_OF_INTERNAL(ASN1_TYPE, ASN1_TYPE, ASN1_TYPE)
555#define sk_ASN1_TYPE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_TYPE_sk_type(sk))
556#define sk_ASN1_TYPE_value(sk, idx) ((ASN1_TYPE *)OPENSSL_sk_value(ossl_check_const_ASN1_TYPE_sk_type(sk), (idx)))
557#define sk_ASN1_TYPE_new(cmp) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_new(ossl_check_ASN1_TYPE_compfunc_type(cmp)))
558#define sk_ASN1_TYPE_new_null() ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_new_null())
559#define sk_ASN1_TYPE_new_reserve(cmp, n) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_TYPE_compfunc_type(cmp), (n)))
560#define sk_ASN1_TYPE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_TYPE_sk_type(sk), (n))
561#define sk_ASN1_TYPE_free(sk) OPENSSL_sk_free(ossl_check_ASN1_TYPE_sk_type(sk))
562#define sk_ASN1_TYPE_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_TYPE_sk_type(sk))
563#define sk_ASN1_TYPE_delete(sk, i) ((ASN1_TYPE *)OPENSSL_sk_delete(ossl_check_ASN1_TYPE_sk_type(sk), (i)))
564#define sk_ASN1_TYPE_delete_ptr(sk, ptr) ((ASN1_TYPE *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr)))
565#define sk_ASN1_TYPE_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
566#define sk_ASN1_TYPE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
567#define sk_ASN1_TYPE_pop(sk) ((ASN1_TYPE *)OPENSSL_sk_pop(ossl_check_ASN1_TYPE_sk_type(sk)))
568#define sk_ASN1_TYPE_shift(sk) ((ASN1_TYPE *)OPENSSL_sk_shift(ossl_check_ASN1_TYPE_sk_type(sk)))
569#define sk_ASN1_TYPE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_TYPE_sk_type(sk),ossl_check_ASN1_TYPE_freefunc_type(freefunc))
570#define sk_ASN1_TYPE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr), (idx))
571#define sk_ASN1_TYPE_set(sk, idx, ptr) ((ASN1_TYPE *)OPENSSL_sk_set(ossl_check_ASN1_TYPE_sk_type(sk), (idx), ossl_check_ASN1_TYPE_type(ptr)))
572#define sk_ASN1_TYPE_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
573#define sk_ASN1_TYPE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
574#define sk_ASN1_TYPE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr), pnum)
575#define sk_ASN1_TYPE_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_TYPE_sk_type(sk))
576#define sk_ASN1_TYPE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_TYPE_sk_type(sk))
577#define sk_ASN1_TYPE_dup(sk) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_dup(ossl_check_const_ASN1_TYPE_sk_type(sk)))
578#define sk_ASN1_TYPE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_copyfunc_type(copyfunc), ossl_check_ASN1_TYPE_freefunc_type(freefunc)))
579#define sk_ASN1_TYPE_set_cmp_func(sk, cmp) ((sk_ASN1_TYPE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_compfunc_type(cmp)))
580
581
582typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;
583
584DECLARE_ASN1_ENCODE_FUNCTIONS_name(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
585DECLARE_ASN1_ENCODE_FUNCTIONS_name(ASN1_SEQUENCE_ANY, ASN1_SET_ANY)
586
587/* This is used to contain a list of bit names */
588typedef struct BIT_STRING_BITNAME_st {
589 int bitnum;
590 const char *lname;
591 const char *sname;
592} BIT_STRING_BITNAME;
593
594# define B_ASN1_TIME \
595 B_ASN1_UTCTIME | \
596 B_ASN1_GENERALIZEDTIME
597
598# define B_ASN1_PRINTABLE \
599 B_ASN1_NUMERICSTRING| \
600 B_ASN1_PRINTABLESTRING| \
601 B_ASN1_T61STRING| \
602 B_ASN1_IA5STRING| \
603 B_ASN1_BIT_STRING| \
604 B_ASN1_UNIVERSALSTRING|\
605 B_ASN1_BMPSTRING|\
606 B_ASN1_UTF8STRING|\
607 B_ASN1_SEQUENCE|\
608 B_ASN1_UNKNOWN
609
610# define B_ASN1_DIRECTORYSTRING \
611 B_ASN1_PRINTABLESTRING| \
612 B_ASN1_TELETEXSTRING|\
613 B_ASN1_BMPSTRING|\
614 B_ASN1_UNIVERSALSTRING|\
615 B_ASN1_UTF8STRING
616
617# define B_ASN1_DISPLAYTEXT \
618 B_ASN1_IA5STRING| \
619 B_ASN1_VISIBLESTRING| \
620 B_ASN1_BMPSTRING|\
621 B_ASN1_UTF8STRING
622
623DECLARE_ASN1_ALLOC_FUNCTIONS_name(ASN1_TYPE, ASN1_TYPE)
624DECLARE_ASN1_ENCODE_FUNCTIONS(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
625
626int ASN1_TYPE_get(const ASN1_TYPE *a);
627void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
628int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
629int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
630
631ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t);
632void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t);
633
634SKM_DEFINE_STACK_OF_INTERNAL(ASN1_OBJECT, ASN1_OBJECT, ASN1_OBJECT)
635#define sk_ASN1_OBJECT_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_OBJECT_sk_type(sk))
636#define sk_ASN1_OBJECT_value(sk, idx) ((ASN1_OBJECT *)OPENSSL_sk_value(ossl_check_const_ASN1_OBJECT_sk_type(sk), (idx)))
637#define sk_ASN1_OBJECT_new(cmp) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_new(ossl_check_ASN1_OBJECT_compfunc_type(cmp)))
638#define sk_ASN1_OBJECT_new_null() ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_new_null())
639#define sk_ASN1_OBJECT_new_reserve(cmp, n) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_OBJECT_compfunc_type(cmp), (n)))
640#define sk_ASN1_OBJECT_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_OBJECT_sk_type(sk), (n))
641#define sk_ASN1_OBJECT_free(sk) OPENSSL_sk_free(ossl_check_ASN1_OBJECT_sk_type(sk))
642#define sk_ASN1_OBJECT_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_OBJECT_sk_type(sk))
643#define sk_ASN1_OBJECT_delete(sk, i) ((ASN1_OBJECT *)OPENSSL_sk_delete(ossl_check_ASN1_OBJECT_sk_type(sk), (i)))
644#define sk_ASN1_OBJECT_delete_ptr(sk, ptr) ((ASN1_OBJECT *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr)))
645#define sk_ASN1_OBJECT_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
646#define sk_ASN1_OBJECT_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
647#define sk_ASN1_OBJECT_pop(sk) ((ASN1_OBJECT *)OPENSSL_sk_pop(ossl_check_ASN1_OBJECT_sk_type(sk)))
648#define sk_ASN1_OBJECT_shift(sk) ((ASN1_OBJECT *)OPENSSL_sk_shift(ossl_check_ASN1_OBJECT_sk_type(sk)))
649#define sk_ASN1_OBJECT_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_OBJECT_sk_type(sk),ossl_check_ASN1_OBJECT_freefunc_type(freefunc))
650#define sk_ASN1_OBJECT_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr), (idx))
651#define sk_ASN1_OBJECT_set(sk, idx, ptr) ((ASN1_OBJECT *)OPENSSL_sk_set(ossl_check_ASN1_OBJECT_sk_type(sk), (idx), ossl_check_ASN1_OBJECT_type(ptr)))
652#define sk_ASN1_OBJECT_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
653#define sk_ASN1_OBJECT_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
654#define sk_ASN1_OBJECT_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr), pnum)
655#define sk_ASN1_OBJECT_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_OBJECT_sk_type(sk))
656#define sk_ASN1_OBJECT_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_OBJECT_sk_type(sk))
657#define sk_ASN1_OBJECT_dup(sk) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_dup(ossl_check_const_ASN1_OBJECT_sk_type(sk)))
658#define sk_ASN1_OBJECT_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_copyfunc_type(copyfunc), ossl_check_ASN1_OBJECT_freefunc_type(freefunc)))
659#define sk_ASN1_OBJECT_set_cmp_func(sk, cmp) ((sk_ASN1_OBJECT_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_compfunc_type(cmp)))
660
661
662DECLARE_ASN1_FUNCTIONS(ASN1_OBJECT)
663
664ASN1_STRING *ASN1_STRING_new(void);
665void ASN1_STRING_free(ASN1_STRING *a);
666void ASN1_STRING_clear_free(ASN1_STRING *a);
667int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
668DECLARE_ASN1_DUP_FUNCTION(ASN1_STRING)
669ASN1_STRING *ASN1_STRING_type_new(int type);
670int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
671 /*
672 * Since this is used to store all sorts of things, via macros, for now,
673 * make its data void *
674 */
675int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
676void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
677int ASN1_STRING_length(const ASN1_STRING *x);
678# ifndef OPENSSL_NO_DEPRECATED_3_0
679OSSL_DEPRECATEDIN_3_0 void ASN1_STRING_length_set(ASN1_STRING *x, int n);
680# endif
681int ASN1_STRING_type(const ASN1_STRING *x);
682# ifndef OPENSSL_NO_DEPRECATED_1_1_0
683OSSL_DEPRECATEDIN_1_1_0 unsigned char *ASN1_STRING_data(ASN1_STRING *x);
684# endif
685const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x);
686
687DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
688int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length);
689int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
690int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n);
691int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a,
692 const unsigned char *flags, int flags_len);
693
694int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
695 BIT_STRING_BITNAME *tbl, int indent);
696int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl);
697int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
698 BIT_STRING_BITNAME *tbl);
699
700SKM_DEFINE_STACK_OF_INTERNAL(ASN1_INTEGER, ASN1_INTEGER, ASN1_INTEGER)
701#define sk_ASN1_INTEGER_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_INTEGER_sk_type(sk))
702#define sk_ASN1_INTEGER_value(sk, idx) ((ASN1_INTEGER *)OPENSSL_sk_value(ossl_check_const_ASN1_INTEGER_sk_type(sk), (idx)))
703#define sk_ASN1_INTEGER_new(cmp) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_new(ossl_check_ASN1_INTEGER_compfunc_type(cmp)))
704#define sk_ASN1_INTEGER_new_null() ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_new_null())
705#define sk_ASN1_INTEGER_new_reserve(cmp, n) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_INTEGER_compfunc_type(cmp), (n)))
706#define sk_ASN1_INTEGER_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_INTEGER_sk_type(sk), (n))
707#define sk_ASN1_INTEGER_free(sk) OPENSSL_sk_free(ossl_check_ASN1_INTEGER_sk_type(sk))
708#define sk_ASN1_INTEGER_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_INTEGER_sk_type(sk))
709#define sk_ASN1_INTEGER_delete(sk, i) ((ASN1_INTEGER *)OPENSSL_sk_delete(ossl_check_ASN1_INTEGER_sk_type(sk), (i)))
710#define sk_ASN1_INTEGER_delete_ptr(sk, ptr) ((ASN1_INTEGER *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr)))
711#define sk_ASN1_INTEGER_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
712#define sk_ASN1_INTEGER_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
713#define sk_ASN1_INTEGER_pop(sk) ((ASN1_INTEGER *)OPENSSL_sk_pop(ossl_check_ASN1_INTEGER_sk_type(sk)))
714#define sk_ASN1_INTEGER_shift(sk) ((ASN1_INTEGER *)OPENSSL_sk_shift(ossl_check_ASN1_INTEGER_sk_type(sk)))
715#define sk_ASN1_INTEGER_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_INTEGER_sk_type(sk),ossl_check_ASN1_INTEGER_freefunc_type(freefunc))
716#define sk_ASN1_INTEGER_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr), (idx))
717#define sk_ASN1_INTEGER_set(sk, idx, ptr) ((ASN1_INTEGER *)OPENSSL_sk_set(ossl_check_ASN1_INTEGER_sk_type(sk), (idx), ossl_check_ASN1_INTEGER_type(ptr)))
718#define sk_ASN1_INTEGER_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
719#define sk_ASN1_INTEGER_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
720#define sk_ASN1_INTEGER_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr), pnum)
721#define sk_ASN1_INTEGER_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_INTEGER_sk_type(sk))
722#define sk_ASN1_INTEGER_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_INTEGER_sk_type(sk))
723#define sk_ASN1_INTEGER_dup(sk) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_dup(ossl_check_const_ASN1_INTEGER_sk_type(sk)))
724#define sk_ASN1_INTEGER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_copyfunc_type(copyfunc), ossl_check_ASN1_INTEGER_freefunc_type(freefunc)))
725#define sk_ASN1_INTEGER_set_cmp_func(sk, cmp) ((sk_ASN1_INTEGER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_compfunc_type(cmp)))
726
727
728
729DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
730ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
731 long length);
732DECLARE_ASN1_DUP_FUNCTION(ASN1_INTEGER)
733int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
734
735DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
736
737int ASN1_UTCTIME_check(const ASN1_UTCTIME *a);
738ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
739ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
740 int offset_day, long offset_sec);
741int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
742int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
743
744int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a);
745ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
746 time_t t);
747ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
748 time_t t, int offset_day,
749 long offset_sec);
750int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);
751
752int ASN1_TIME_diff(int *pday, int *psec,
753 const ASN1_TIME *from, const ASN1_TIME *to);
754
755DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
756DECLARE_ASN1_DUP_FUNCTION(ASN1_OCTET_STRING)
757int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
758 const ASN1_OCTET_STRING *b);
759int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data,
760 int len);
761
762SKM_DEFINE_STACK_OF_INTERNAL(ASN1_UTF8STRING, ASN1_UTF8STRING, ASN1_UTF8STRING)
763#define sk_ASN1_UTF8STRING_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_UTF8STRING_sk_type(sk))
764#define sk_ASN1_UTF8STRING_value(sk, idx) ((ASN1_UTF8STRING *)OPENSSL_sk_value(ossl_check_const_ASN1_UTF8STRING_sk_type(sk), (idx)))
765#define sk_ASN1_UTF8STRING_new(cmp) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_new(ossl_check_ASN1_UTF8STRING_compfunc_type(cmp)))
766#define sk_ASN1_UTF8STRING_new_null() ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_new_null())
767#define sk_ASN1_UTF8STRING_new_reserve(cmp, n) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_UTF8STRING_compfunc_type(cmp), (n)))
768#define sk_ASN1_UTF8STRING_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_UTF8STRING_sk_type(sk), (n))
769#define sk_ASN1_UTF8STRING_free(sk) OPENSSL_sk_free(ossl_check_ASN1_UTF8STRING_sk_type(sk))
770#define sk_ASN1_UTF8STRING_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_UTF8STRING_sk_type(sk))
771#define sk_ASN1_UTF8STRING_delete(sk, i) ((ASN1_UTF8STRING *)OPENSSL_sk_delete(ossl_check_ASN1_UTF8STRING_sk_type(sk), (i)))
772#define sk_ASN1_UTF8STRING_delete_ptr(sk, ptr) ((ASN1_UTF8STRING *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr)))
773#define sk_ASN1_UTF8STRING_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
774#define sk_ASN1_UTF8STRING_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
775#define sk_ASN1_UTF8STRING_pop(sk) ((ASN1_UTF8STRING *)OPENSSL_sk_pop(ossl_check_ASN1_UTF8STRING_sk_type(sk)))
776#define sk_ASN1_UTF8STRING_shift(sk) ((ASN1_UTF8STRING *)OPENSSL_sk_shift(ossl_check_ASN1_UTF8STRING_sk_type(sk)))
777#define sk_ASN1_UTF8STRING_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_UTF8STRING_sk_type(sk),ossl_check_ASN1_UTF8STRING_freefunc_type(freefunc))
778#define sk_ASN1_UTF8STRING_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr), (idx))
779#define sk_ASN1_UTF8STRING_set(sk, idx, ptr) ((ASN1_UTF8STRING *)OPENSSL_sk_set(ossl_check_ASN1_UTF8STRING_sk_type(sk), (idx), ossl_check_ASN1_UTF8STRING_type(ptr)))
780#define sk_ASN1_UTF8STRING_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
781#define sk_ASN1_UTF8STRING_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
782#define sk_ASN1_UTF8STRING_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr), pnum)
783#define sk_ASN1_UTF8STRING_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_UTF8STRING_sk_type(sk))
784#define sk_ASN1_UTF8STRING_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_UTF8STRING_sk_type(sk))
785#define sk_ASN1_UTF8STRING_dup(sk) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_dup(ossl_check_const_ASN1_UTF8STRING_sk_type(sk)))
786#define sk_ASN1_UTF8STRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_copyfunc_type(copyfunc), ossl_check_ASN1_UTF8STRING_freefunc_type(freefunc)))
787#define sk_ASN1_UTF8STRING_set_cmp_func(sk, cmp) ((sk_ASN1_UTF8STRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_compfunc_type(cmp)))
788
789
790DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
791DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
792DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
793DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
794DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
795
796int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
797int UTF8_putc(unsigned char *str, int len, unsigned long value);
798
799SKM_DEFINE_STACK_OF_INTERNAL(ASN1_GENERALSTRING, ASN1_GENERALSTRING, ASN1_GENERALSTRING)
800#define sk_ASN1_GENERALSTRING_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk))
801#define sk_ASN1_GENERALSTRING_value(sk, idx) ((ASN1_GENERALSTRING *)OPENSSL_sk_value(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk), (idx)))
802#define sk_ASN1_GENERALSTRING_new(cmp) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_new(ossl_check_ASN1_GENERALSTRING_compfunc_type(cmp)))
803#define sk_ASN1_GENERALSTRING_new_null() ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_new_null())
804#define sk_ASN1_GENERALSTRING_new_reserve(cmp, n) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_GENERALSTRING_compfunc_type(cmp), (n)))
805#define sk_ASN1_GENERALSTRING_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_GENERALSTRING_sk_type(sk), (n))
806#define sk_ASN1_GENERALSTRING_free(sk) OPENSSL_sk_free(ossl_check_ASN1_GENERALSTRING_sk_type(sk))
807#define sk_ASN1_GENERALSTRING_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_GENERALSTRING_sk_type(sk))
808#define sk_ASN1_GENERALSTRING_delete(sk, i) ((ASN1_GENERALSTRING *)OPENSSL_sk_delete(ossl_check_ASN1_GENERALSTRING_sk_type(sk), (i)))
809#define sk_ASN1_GENERALSTRING_delete_ptr(sk, ptr) ((ASN1_GENERALSTRING *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr)))
810#define sk_ASN1_GENERALSTRING_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
811#define sk_ASN1_GENERALSTRING_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
812#define sk_ASN1_GENERALSTRING_pop(sk) ((ASN1_GENERALSTRING *)OPENSSL_sk_pop(ossl_check_ASN1_GENERALSTRING_sk_type(sk)))
813#define sk_ASN1_GENERALSTRING_shift(sk) ((ASN1_GENERALSTRING *)OPENSSL_sk_shift(ossl_check_ASN1_GENERALSTRING_sk_type(sk)))
814#define sk_ASN1_GENERALSTRING_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_GENERALSTRING_sk_type(sk),ossl_check_ASN1_GENERALSTRING_freefunc_type(freefunc))
815#define sk_ASN1_GENERALSTRING_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr), (idx))
816#define sk_ASN1_GENERALSTRING_set(sk, idx, ptr) ((ASN1_GENERALSTRING *)OPENSSL_sk_set(ossl_check_ASN1_GENERALSTRING_sk_type(sk), (idx), ossl_check_ASN1_GENERALSTRING_type(ptr)))
817#define sk_ASN1_GENERALSTRING_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
818#define sk_ASN1_GENERALSTRING_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
819#define sk_ASN1_GENERALSTRING_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr), pnum)
820#define sk_ASN1_GENERALSTRING_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_GENERALSTRING_sk_type(sk))
821#define sk_ASN1_GENERALSTRING_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk))
822#define sk_ASN1_GENERALSTRING_dup(sk) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_dup(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk)))
823#define sk_ASN1_GENERALSTRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_copyfunc_type(copyfunc), ossl_check_ASN1_GENERALSTRING_freefunc_type(freefunc)))
824#define sk_ASN1_GENERALSTRING_set_cmp_func(sk, cmp) ((sk_ASN1_GENERALSTRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_compfunc_type(cmp)))
825
826
827DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
828
829DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
830DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
831DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
832DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
833DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
834DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
835DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
836DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
837DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
838
839DECLARE_ASN1_DUP_FUNCTION(ASN1_TIME)
840DECLARE_ASN1_DUP_FUNCTION(ASN1_UTCTIME)
841DECLARE_ASN1_DUP_FUNCTION(ASN1_GENERALIZEDTIME)
842
843DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
844
845ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
846ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
847 int offset_day, long offset_sec);
848int ASN1_TIME_check(const ASN1_TIME *t);
849ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
850 ASN1_GENERALIZEDTIME **out);
851int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
852int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str);
853int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm);
854int ASN1_TIME_normalize(ASN1_TIME *s);
855int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t);
856int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b);
857
858int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a);
859int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size);
860int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a);
861int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size);
862int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a);
863int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size);
864int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type);
865int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
866
867int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num);
868ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
869 const char *sn, const char *ln);
870
871int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a);
872int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r);
873int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a);
874int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r);
875
876int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
877long ASN1_INTEGER_get(const ASN1_INTEGER *a);
878ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
879BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
880
881int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a);
882int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r);
883
884
885int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
886long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
887ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai);
888BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn);
889
890/* General */
891/* given a string, return the correct type, max is the maximum length */
892int ASN1_PRINTABLE_type(const unsigned char *s, int max);
893
894unsigned long ASN1_tag2bit(int tag);
895
896/* SPECIALS */
897int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
898 int *pclass, long omax);
899int ASN1_check_infinite_end(unsigned char **p, long len);
900int ASN1_const_check_infinite_end(const unsigned char **p, long len);
901void ASN1_put_object(unsigned char **pp, int constructed, int length,
902 int tag, int xclass);
903int ASN1_put_eoc(unsigned char **pp);
904int ASN1_object_size(int constructed, int length, int tag);
905
906/* Used to implement other functions */
907void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x);
908
909# define ASN1_dup_of(type,i2d,d2i,x) \
910 ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
911 CHECKED_D2I_OF(type, d2i), \
912 CHECKED_PTR_OF(const type, x)))
913
914void *ASN1_item_dup(const ASN1_ITEM *it, const void *x);
915int ASN1_item_sign_ex(const ASN1_ITEM *it, X509_ALGOR *algor1,
916 X509_ALGOR *algor2, ASN1_BIT_STRING *signature,
917 const void *data, const ASN1_OCTET_STRING *id,
918 EVP_PKEY *pkey, const EVP_MD *md, OSSL_LIB_CTX *libctx,
919 const char *propq);
920int ASN1_item_verify_ex(const ASN1_ITEM *it, const X509_ALGOR *alg,
921 const ASN1_BIT_STRING *signature, const void *data,
922 const ASN1_OCTET_STRING *id, EVP_PKEY *pkey,
923 OSSL_LIB_CTX *libctx, const char *propq);
924
925/* ASN1 alloc/free macros for when a type is only used internally */
926
927# define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
928# define M_ASN1_free_of(x, type) \
929 ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
930
931# ifndef OPENSSL_NO_STDIO
932void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x);
933
934# define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
935 ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \
936 CHECKED_D2I_OF(type, d2i), \
937 in, \
938 CHECKED_PPTR_OF(type, x)))
939
940void *ASN1_item_d2i_fp_ex(const ASN1_ITEM *it, FILE *in, void *x,
941 OSSL_LIB_CTX *libctx, const char *propq);
942void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
943int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, const void *x);
944
945# define ASN1_i2d_fp_of(type,i2d,out,x) \
946 (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \
947 out, \
948 CHECKED_PTR_OF(const type, x)))
949
950int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, const void *x);
951int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags);
952# endif
953
954int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in);
955
956void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x);
957
958# define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \
959 ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \
960 CHECKED_D2I_OF(type, d2i), \
961 in, \
962 CHECKED_PPTR_OF(type, x)))
963
964void *ASN1_item_d2i_bio_ex(const ASN1_ITEM *it, BIO *in, void *pval,
965 OSSL_LIB_CTX *libctx, const char *propq);
966void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *pval);
967int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x);
968
969# define ASN1_i2d_bio_of(type,i2d,out,x) \
970 (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \
971 out, \
972 CHECKED_PTR_OF(const type, x)))
973
974int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x);
975BIO *ASN1_item_i2d_mem_bio(const ASN1_ITEM *it, const ASN1_VALUE *val);
976int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
977int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
978int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm);
979int ASN1_TIME_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags);
980int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
981int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags);
982int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int off);
983int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
984 unsigned char *buf, int off);
985int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
986int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent,
987 int dump);
988const char *ASN1_tag2str(int tag);
989
990/* Used to load and write Netscape format cert */
991
992int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
993
994int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len);
995int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len);
996int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
997 unsigned char *data, int len);
998int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num,
999 unsigned char *data, int max_len);
1000
1001void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it);
1002void *ASN1_item_unpack_ex(const ASN1_STRING *oct, const ASN1_ITEM *it,
1003 OSSL_LIB_CTX *libctx, const char *propq);
1004
1005ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it,
1006 ASN1_OCTET_STRING **oct);
1007
1008void ASN1_STRING_set_default_mask(unsigned long mask);
1009int ASN1_STRING_set_default_mask_asc(const char *p);
1010unsigned long ASN1_STRING_get_default_mask(void);
1011int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
1012 int inform, unsigned long mask);
1013int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
1014 int inform, unsigned long mask,
1015 long minsize, long maxsize);
1016
1017ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
1018 const unsigned char *in, int inlen,
1019 int inform, int nid);
1020ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
1021int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
1022void ASN1_STRING_TABLE_cleanup(void);
1023
1024/* ASN1 template functions */
1025
1026/* Old API compatible functions */
1027ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
1028ASN1_VALUE *ASN1_item_new_ex(const ASN1_ITEM *it, OSSL_LIB_CTX *libctx,
1029 const char *propq);
1030void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
1031ASN1_VALUE *ASN1_item_d2i_ex(ASN1_VALUE **val, const unsigned char **in,
1032 long len, const ASN1_ITEM *it,
1033 OSSL_LIB_CTX *libctx, const char *propq);
1034ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in,
1035 long len, const ASN1_ITEM *it);
1036int ASN1_item_i2d(const ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
1037int ASN1_item_ndef_i2d(const ASN1_VALUE *val, unsigned char **out,
1038 const ASN1_ITEM *it);
1039
1040void ASN1_add_oid_module(void);
1041void ASN1_add_stable_module(void);
1042
1043ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf);
1044ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf);
1045int ASN1_str2mask(const char *str, unsigned long *pmask);
1046
1047/* ASN1 Print flags */
1048
1049/* Indicate missing OPTIONAL fields */
1050# define ASN1_PCTX_FLAGS_SHOW_ABSENT 0x001
1051/* Mark start and end of SEQUENCE */
1052# define ASN1_PCTX_FLAGS_SHOW_SEQUENCE 0x002
1053/* Mark start and end of SEQUENCE/SET OF */
1054# define ASN1_PCTX_FLAGS_SHOW_SSOF 0x004
1055/* Show the ASN1 type of primitives */
1056# define ASN1_PCTX_FLAGS_SHOW_TYPE 0x008
1057/* Don't show ASN1 type of ANY */
1058# define ASN1_PCTX_FLAGS_NO_ANY_TYPE 0x010
1059/* Don't show ASN1 type of MSTRINGs */
1060# define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE 0x020
1061/* Don't show field names in SEQUENCE */
1062# define ASN1_PCTX_FLAGS_NO_FIELD_NAME 0x040
1063/* Show structure names of each SEQUENCE field */
1064# define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME 0x080
1065/* Don't show structure name even at top level */
1066# define ASN1_PCTX_FLAGS_NO_STRUCT_NAME 0x100
1067
1068int ASN1_item_print(BIO *out, const ASN1_VALUE *ifld, int indent,
1069 const ASN1_ITEM *it, const ASN1_PCTX *pctx);
1070ASN1_PCTX *ASN1_PCTX_new(void);
1071void ASN1_PCTX_free(ASN1_PCTX *p);
1072unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p);
1073void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags);
1074unsigned long ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p);
1075void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags);
1076unsigned long ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p);
1077void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags);
1078unsigned long ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p);
1079void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags);
1080unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p);
1081void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
1082
1083ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx));
1084void ASN1_SCTX_free(ASN1_SCTX *p);
1085const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p);
1086const ASN1_TEMPLATE *ASN1_SCTX_get_template(ASN1_SCTX *p);
1087unsigned long ASN1_SCTX_get_flags(ASN1_SCTX *p);
1088void ASN1_SCTX_set_app_data(ASN1_SCTX *p, void *data);
1089void *ASN1_SCTX_get_app_data(ASN1_SCTX *p);
1090
1091const BIO_METHOD *BIO_f_asn1(void);
1092
1093/* cannot constify val because of CMS_stream() */
1094BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
1095
1096int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1097 const ASN1_ITEM *it);
1098int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1099 const char *hdr, const ASN1_ITEM *it);
1100/* cannot constify val because of CMS_dataFinal() */
1101int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
1102 int ctype_nid, int econt_nid,
1103 STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it);
1104int SMIME_write_ASN1_ex(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
1105 int ctype_nid, int econt_nid,
1106 STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it,
1107 OSSL_LIB_CTX *libctx, const char *propq);
1108ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
1109ASN1_VALUE *SMIME_read_ASN1_ex(BIO *bio, int flags, BIO **bcont,
1110 const ASN1_ITEM *it, ASN1_VALUE **x,
1111 OSSL_LIB_CTX *libctx, const char *propq);
1112int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
1113int SMIME_text(BIO *in, BIO *out);
1114
1115const ASN1_ITEM *ASN1_ITEM_lookup(const char *name);
1116const ASN1_ITEM *ASN1_ITEM_get(size_t i);
1117
1118/* Legacy compatibility */
1119# define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
1120 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
1121 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
1122# define DECLARE_ASN1_FUNCTIONS_const(type) DECLARE_ASN1_FUNCTIONS(type)
1123# define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
1124 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name)
1125# define I2D_OF_const(type) I2D_OF(type)
1126# define ASN1_dup_of_const(type,i2d,d2i,x) ASN1_dup_of(type,i2d,d2i,x)
1127# define ASN1_i2d_fp_of_const(type,i2d,out,x) ASN1_i2d_fp_of(type,i2d,out,x)
1128# define ASN1_i2d_bio_of_const(type,i2d,out,x) ASN1_i2d_bio_of(type,i2d,out,x)
1129
1130# ifdef __cplusplus
1131}
1132# endif
1133#endif
1134