summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/asn1t.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1t.h')
-rw-r--r--src/lib/libcrypto/asn1/asn1t.h109
1 files changed, 78 insertions, 31 deletions
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h
index ed372f8554..bf315e65ed 100644
--- a/src/lib/libcrypto/asn1/asn1t.h
+++ b/src/lib/libcrypto/asn1/asn1t.h
@@ -99,7 +99,7 @@ extern "C" {
99#define ASN1_ITEM_start(itname) \ 99#define ASN1_ITEM_start(itname) \
100 const ASN1_ITEM * itname##_it(void) \ 100 const ASN1_ITEM * itname##_it(void) \
101 { \ 101 { \
102 static const ASN1_ITEM local_it = { \ 102 static const ASN1_ITEM local_it = {
103 103
104#define ASN1_ITEM_end(itname) \ 104#define ASN1_ITEM_end(itname) \
105 }; \ 105 }; \
@@ -112,7 +112,7 @@ extern "C" {
112/* Macros to aid ASN1 template writing */ 112/* Macros to aid ASN1 template writing */
113 113
114#define ASN1_ITEM_TEMPLATE(tname) \ 114#define ASN1_ITEM_TEMPLATE(tname) \
115 const static ASN1_TEMPLATE tname##_item_tt 115 static const ASN1_TEMPLATE tname##_item_tt
116 116
117#define ASN1_ITEM_TEMPLATE_END(tname) \ 117#define ASN1_ITEM_TEMPLATE_END(tname) \
118 ;\ 118 ;\
@@ -150,7 +150,7 @@ extern "C" {
150 */ 150 */
151 151
152#define ASN1_SEQUENCE(tname) \ 152#define ASN1_SEQUENCE(tname) \
153 const static ASN1_TEMPLATE tname##_seq_tt[] 153 static const ASN1_TEMPLATE tname##_seq_tt[]
154 154
155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) 155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
156 156
@@ -166,22 +166,40 @@ extern "C" {
166 #stname \ 166 #stname \
167 ASN1_ITEM_end(tname) 167 ASN1_ITEM_end(tname)
168 168
169#define ASN1_NDEF_SEQUENCE(tname) \
170 ASN1_SEQUENCE(tname)
171
172#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
173 ASN1_SEQUENCE_cb(tname, cb)
174
169#define ASN1_SEQUENCE_cb(tname, cb) \ 175#define ASN1_SEQUENCE_cb(tname, cb) \
170 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ 176 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
171 ASN1_SEQUENCE(tname) 177 ASN1_SEQUENCE(tname)
172 178
173#define ASN1_BROKEN_SEQUENCE(tname) \ 179#define ASN1_BROKEN_SEQUENCE(tname) \
174 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ 180 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
175 ASN1_SEQUENCE(tname) 181 ASN1_SEQUENCE(tname)
176 182
177#define ASN1_SEQUENCE_ref(tname, cb, lck) \ 183#define ASN1_SEQUENCE_ref(tname, cb, lck) \
178 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \ 184 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
179 ASN1_SEQUENCE(tname) 185 ASN1_SEQUENCE(tname)
180 186
181#define ASN1_SEQUENCE_enc(tname, enc, cb) \ 187#define ASN1_SEQUENCE_enc(tname, enc, cb) \
182 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ 188 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
183 ASN1_SEQUENCE(tname) 189 ASN1_SEQUENCE(tname)
184 190
191#define ASN1_NDEF_SEQUENCE_END(tname) \
192 ;\
193 ASN1_ITEM_start(tname) \
194 ASN1_ITYPE_NDEF_SEQUENCE,\
195 V_ASN1_SEQUENCE,\
196 tname##_seq_tt,\
197 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
198 NULL,\
199 sizeof(tname),\
200 #tname \
201 ASN1_ITEM_end(tname)
202
185#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) 203#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
186 204
187#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) 205#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
@@ -224,10 +242,10 @@ extern "C" {
224 */ 242 */
225 243
226#define ASN1_CHOICE(tname) \ 244#define ASN1_CHOICE(tname) \
227 const static ASN1_TEMPLATE tname##_ch_tt[] 245 static const ASN1_TEMPLATE tname##_ch_tt[]
228 246
229#define ASN1_CHOICE_cb(tname, cb) \ 247#define ASN1_CHOICE_cb(tname, cb) \
230 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ 248 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
231 ASN1_CHOICE(tname) 249 ASN1_CHOICE(tname)
232 250
233#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) 251#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
@@ -353,16 +371,24 @@ extern "C" {
353#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ 371#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
354 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) 372 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
355 373
374/* EXPLICIT using indefinite length constructed form */
375#define ASN1_NDEF_EXP(stname, field, type, tag) \
376 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
377
378/* EXPLICIT OPTIONAL using indefinite length constructed form */
379#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
380 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
381
356/* Macros for the ASN1_ADB structure */ 382/* Macros for the ASN1_ADB structure */
357 383
358#define ASN1_ADB(name) \ 384#define ASN1_ADB(name) \
359 const static ASN1_ADB_TABLE name##_adbtbl[] 385 static const ASN1_ADB_TABLE name##_adbtbl[]
360 386
361#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION 387#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
362 388
363#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ 389#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
364 ;\ 390 ;\
365 const static ASN1_ADB name##_adb = {\ 391 static const ASN1_ADB name##_adb = {\
366 flags,\ 392 flags,\
367 offsetof(name, field),\ 393 offsetof(name, field),\
368 app_table,\ 394 app_table,\
@@ -376,9 +402,9 @@ extern "C" {
376 402
377#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ 403#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
378 ;\ 404 ;\
379 const static ASN1_ITEM *name##_adb(void) \ 405 static const ASN1_ITEM *name##_adb(void) \
380 { \ 406 { \
381 const static ASN1_ADB internal_adb = \ 407 static const ASN1_ADB internal_adb = \
382 {\ 408 {\
383 flags,\ 409 flags,\
384 offsetof(name, field),\ 410 offsetof(name, field),\
@@ -397,7 +423,7 @@ extern "C" {
397#define ADB_ENTRY(val, template) {val, template} 423#define ADB_ENTRY(val, template) {val, template}
398 424
399#define ASN1_ADB_TEMPLATE(name) \ 425#define ASN1_ADB_TEMPLATE(name) \
400 const static ASN1_TEMPLATE name##_tt 426 static const ASN1_TEMPLATE name##_tt
401 427
402/* This is the ASN1 template structure that defines 428/* This is the ASN1 template structure that defines
403 * a wrapper round the actual type. It determines the 429 * a wrapper round the actual type. It determines the
@@ -410,7 +436,7 @@ unsigned long flags; /* Various flags */
410long tag; /* tag, not used if no tagging */ 436long tag; /* tag, not used if no tagging */
411unsigned long offset; /* Offset of this field in structure */ 437unsigned long offset; /* Offset of this field in structure */
412#ifndef NO_ASN1_FIELD_NAMES 438#ifndef NO_ASN1_FIELD_NAMES
413char *field_name; /* Field name */ 439const char *field_name; /* Field name */
414#endif 440#endif
415ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ 441ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
416}; 442};
@@ -518,6 +544,13 @@ struct ASN1_ADB_TABLE_st {
518 544
519#define ASN1_TFLG_COMBINE (0x1<<10) 545#define ASN1_TFLG_COMBINE (0x1<<10)
520 546
547/* This flag when present in a SEQUENCE OF, SET OF
548 * or EXPLICIT causes indefinite length constructed
549 * encoding to be used if required.
550 */
551
552#define ASN1_TFLG_NDEF (0x1<<11)
553
521/* This is the actual ASN1 item itself */ 554/* This is the actual ASN1 item itself */
522 555
523struct ASN1_ITEM_st { 556struct ASN1_ITEM_st {
@@ -570,19 +603,25 @@ const char *sname; /* Structure name */
570 * has a special meaning, it is used as a mask 603 * has a special meaning, it is used as a mask
571 * of acceptable types using the B_ASN1 constants. 604 * of acceptable types using the B_ASN1 constants.
572 * 605 *
606 * NDEF_SEQUENCE is the same as SEQUENCE except
607 * that it will use indefinite length constructed
608 * encoding if requested.
609 *
573 */ 610 */
574 611
575#define ASN1_ITYPE_PRIMITIVE 0x0 612#define ASN1_ITYPE_PRIMITIVE 0x0
613
614#define ASN1_ITYPE_SEQUENCE 0x1
576 615
577#define ASN1_ITYPE_SEQUENCE 0x1 616#define ASN1_ITYPE_CHOICE 0x2
578 617
579#define ASN1_ITYPE_CHOICE 0x2 618#define ASN1_ITYPE_COMPAT 0x3
580 619
581#define ASN1_ITYPE_COMPAT 0x3 620#define ASN1_ITYPE_EXTERN 0x4
582 621
583#define ASN1_ITYPE_EXTERN 0x4 622#define ASN1_ITYPE_MSTRING 0x5
584 623
585#define ASN1_ITYPE_MSTRING 0x5 624#define ASN1_ITYPE_NDEF_SEQUENCE 0x6
586 625
587/* Cache for ASN1 tag and length, so we 626/* Cache for ASN1 tag and length, so we
588 * don't keep re-reading it for things 627 * don't keep re-reading it for things
@@ -602,10 +641,10 @@ struct ASN1_TLC_st{
602 641
603typedef ASN1_VALUE * ASN1_new_func(void); 642typedef ASN1_VALUE * ASN1_new_func(void);
604typedef void ASN1_free_func(ASN1_VALUE *a); 643typedef void ASN1_free_func(ASN1_VALUE *a);
605typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, unsigned char ** in, long length); 644typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length);
606typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); 645typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
607 646
608typedef int ASN1_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it, 647typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,
609 int tag, int aclass, char opt, ASN1_TLC *ctx); 648 int tag, int aclass, char opt, ASN1_TLC *ctx);
610 649
611typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); 650typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
@@ -613,7 +652,7 @@ typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
613typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); 652typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
614 653
615typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 654typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
616typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 655typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
617 656
618typedef struct ASN1_COMPAT_FUNCS_st { 657typedef struct ASN1_COMPAT_FUNCS_st {
619 ASN1_new_func *asn1_new; 658 ASN1_new_func *asn1_new;
@@ -743,6 +782,9 @@ typedef struct ASN1_AUX_st {
743#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ 782#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
744 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) 783 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
745 784
785#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
786 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
787
746#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ 788#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
747 stname *fname##_new(void) \ 789 stname *fname##_new(void) \
748 { \ 790 { \
@@ -758,7 +800,7 @@ typedef struct ASN1_AUX_st {
758 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) 800 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
759 801
760#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ 802#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
761 stname *d2i_##fname(stname **a, unsigned char **in, long len) \ 803 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
762 { \ 804 { \
763 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ 805 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
764 } \ 806 } \
@@ -767,13 +809,19 @@ typedef struct ASN1_AUX_st {
767 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ 809 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
768 } 810 }
769 811
812#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
813 int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
814 { \
815 return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
816 }
817
770/* This includes evil casts to remove const: they will go away when full 818/* This includes evil casts to remove const: they will go away when full
771 * ASN1 constification is done. 819 * ASN1 constification is done.
772 */ 820 */
773#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ 821#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
774 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ 822 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
775 { \ 823 { \
776 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, (unsigned char **)in, len, ASN1_ITEM_rptr(itname));\ 824 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
777 } \ 825 } \
778 int i2d_##fname(const stname *a, unsigned char **out) \ 826 int i2d_##fname(const stname *a, unsigned char **out) \
779 { \ 827 { \
@@ -798,7 +846,6 @@ typedef struct ASN1_AUX_st {
798DECLARE_ASN1_ITEM(ASN1_BOOLEAN) 846DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
799DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) 847DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
800DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) 848DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
801DECLARE_ASN1_ITEM(ASN1_ANY)
802DECLARE_ASN1_ITEM(ASN1_SEQUENCE) 849DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
803DECLARE_ASN1_ITEM(CBIGNUM) 850DECLARE_ASN1_ITEM(CBIGNUM)
804DECLARE_ASN1_ITEM(BIGNUM) 851DECLARE_ASN1_ITEM(BIGNUM)
@@ -815,8 +862,8 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
815int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it); 862int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
816 863
817void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); 864void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
818int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt); 865int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt);
819int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it, 866int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,
820 int tag, int aclass, char opt, ASN1_TLC *ctx); 867 int tag, int aclass, char opt, ASN1_TLC *ctx);
821 868
822int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); 869int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
@@ -824,7 +871,7 @@ int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLAT
824void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 871void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
825 872
826int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 873int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
827int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 874int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
828 875
829int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); 876int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
830int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); 877int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
@@ -838,7 +885,7 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
838void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); 885void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
839void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 886void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
840int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it); 887int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
841int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it); 888int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it);
842 889
843#ifdef __cplusplus 890#ifdef __cplusplus
844} 891}