summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/asn1.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/asn1/asn1.h233
1 files changed, 15 insertions, 218 deletions
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index e3bebe45a6..7861c9cd51 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1.h,v 1.49 2018/05/19 10:46:28 tb Exp $ */ 1/* $OpenBSD: asn1.h,v 1.50 2018/10/24 17:57:22 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -125,7 +125,6 @@ extern "C" {
125#define V_ASN1_UNIVERSALSTRING 28 /**/ 125#define V_ASN1_UNIVERSALSTRING 28 /**/
126#define V_ASN1_BMPSTRING 30 126#define V_ASN1_BMPSTRING 30
127 127
128/* For use with d2i_ASN1_type_bytes() */
129#define B_ASN1_NUMERICSTRING 0x0001 128#define B_ASN1_NUMERICSTRING 0x0001
130#define B_ASN1_PRINTABLESTRING 0x0002 129#define B_ASN1_PRINTABLESTRING 0x0002
131#define B_ASN1_T61STRING 0x0004 130#define B_ASN1_T61STRING 0x0004
@@ -543,178 +542,6 @@ typedef struct BIT_STRING_BITNAME_st {
543 const char *sname; 542 const char *sname;
544} BIT_STRING_BITNAME; 543} BIT_STRING_BITNAME;
545 544
546#ifndef LIBRESSL_INTERNAL
547
548#define M_ASN1_STRING_length(x) ((x)->length)
549#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
550#define M_ASN1_STRING_type(x) ((x)->type)
551#define M_ASN1_STRING_data(x) ((x)->data)
552
553/* Macros for string operations */
554#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
555 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
556#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
557#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
558 ASN1_STRING_dup((const ASN1_STRING *)a)
559#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
560 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
561#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
562
563#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
564 ASN1_STRING_type_new(V_ASN1_INTEGER)
565#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
566#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)\
567 ASN1_STRING_dup((const ASN1_STRING *)a)
568#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
569 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
570
571#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
572 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
573#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
574#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)\
575 ASN1_STRING_dup((const ASN1_STRING *)a)
576#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
577 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
578
579#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
580 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
581#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
582#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
583 ASN1_STRING_dup((const ASN1_STRING *)a)
584#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
585 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
586#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
587#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
588#define M_i2d_ASN1_OCTET_STRING(a,pp) \
589 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
590 V_ASN1_UNIVERSAL)
591
592#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
593#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
594#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
595 pp,a->type,V_ASN1_UNIVERSAL)
596#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
597 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
598 B_ASN1_PRINTABLE)
599
600#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
601#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
602#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
603 pp,a->type,V_ASN1_UNIVERSAL)
604#define M_d2i_DIRECTORYSTRING(a,pp,l) \
605 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
606 B_ASN1_DIRECTORYSTRING)
607
608#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
609#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
610#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
611 pp,a->type,V_ASN1_UNIVERSAL)
612#define M_d2i_DISPLAYTEXT(a,pp,l) \
613 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
614 B_ASN1_DISPLAYTEXT)
615
616#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
617 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
618#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
619#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
620 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
621 V_ASN1_UNIVERSAL)
622#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
623 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
624 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
625
626#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
627 ASN1_STRING_type_new(V_ASN1_T61STRING)
628#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
629#define M_i2d_ASN1_T61STRING(a,pp) \
630 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
631 V_ASN1_UNIVERSAL)
632#define M_d2i_ASN1_T61STRING(a,pp,l) \
633 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
634 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
635
636#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
637 ASN1_STRING_type_new(V_ASN1_IA5STRING)
638#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
639#define M_ASN1_IA5STRING_dup(a) \
640 (ASN1_IA5STRING *)ASN1_STRING_dup((const ASN1_STRING *)a)
641#define M_i2d_ASN1_IA5STRING(a,pp) \
642 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
643 V_ASN1_UNIVERSAL)
644#define M_d2i_ASN1_IA5STRING(a,pp,l) \
645 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
646 B_ASN1_IA5STRING)
647
648#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
649 ASN1_STRING_type_new(V_ASN1_UTCTIME)
650#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
651#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)\
652 ASN1_STRING_dup((const ASN1_STRING *)a)
653
654#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
655 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
656#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
657#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
658 (const ASN1_STRING *)a)
659
660#define M_ASN1_TIME_new() (ASN1_TIME *)\
661 ASN1_STRING_type_new(V_ASN1_UTCTIME)
662#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
663#define M_ASN1_TIME_dup(a) (ASN1_TIME *)\
664 ASN1_STRING_dup((const ASN1_STRING *)a)
665
666#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
667 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
668#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
669#define M_i2d_ASN1_GENERALSTRING(a,pp) \
670 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
671 V_ASN1_UNIVERSAL)
672#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
673 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
674 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
675
676#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
677 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
678#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
679#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
680 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
681 V_ASN1_UNIVERSAL)
682#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
683 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
684 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
685
686#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
687 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
688#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
689#define M_i2d_ASN1_BMPSTRING(a,pp) \
690 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
691 V_ASN1_UNIVERSAL)
692#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
693 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
694 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
695
696#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
697 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
698#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
699#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
700 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
701 V_ASN1_UNIVERSAL)
702#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
703 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
704 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
705
706#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
707 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
708#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
709#define M_i2d_ASN1_UTF8STRING(a,pp) \
710 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
711 V_ASN1_UNIVERSAL)
712#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
713 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
714 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
715
716#endif /* !LIBRESSL_INTERNAL */
717
718#define B_ASN1_TIME \ 545#define B_ASN1_TIME \
719 B_ASN1_UTCTIME | \ 546 B_ASN1_UTCTIME | \
720 B_ASN1_GENERALIZEDTIME 547 B_ASN1_GENERALIZEDTIME
@@ -744,9 +571,18 @@ typedef struct BIT_STRING_BITNAME_st {
744 B_ASN1_BMPSTRING|\ 571 B_ASN1_BMPSTRING|\
745 B_ASN1_UTF8STRING 572 B_ASN1_UTF8STRING
746 573
747/* for the is_set parameter to i2d_ASN1_SET */ 574#ifndef LIBRESSL_INTERNAL
748#define IS_SEQUENCE 0 575#define M_ASN1_IA5STRING_new ASN1_IA5STRING_new
749#define IS_SET 1 576
577#define M_ASN1_INTEGER_free ASN1_INTEGER_free
578#define M_ASN1_ENUMERATED_free ASN1_ENUMERATED_free
579#define M_ASN1_OCTET_STRING_free ASN1_OCTET_STRING_free
580
581#define M_ASN1_OCTET_STRING_print ASN1_STRING_print
582
583#define M_ASN1_STRING_data ASN1_STRING_data
584#define M_ASN1_STRING_length ASN1_STRING_length
585#endif
750 586
751ASN1_TYPE *ASN1_TYPE_new(void); 587ASN1_TYPE *ASN1_TYPE_new(void);
752void ASN1_TYPE_free(ASN1_TYPE *a); 588void ASN1_TYPE_free(ASN1_TYPE *a);
@@ -948,12 +784,6 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
948 ASN1_GENERALIZEDTIME **out); 784 ASN1_GENERALIZEDTIME **out);
949int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); 785int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
950 786
951int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
952 i2d_of_void *i2d, int ex_tag, int ex_class, int is_set);
953STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
954 const unsigned char **pp, long length, d2i_of_void *d2i,
955 void (*free_func)(OPENSSL_BLOCK), int ex_tag, int ex_class);
956
957#ifndef OPENSSL_NO_BIO 787#ifndef OPENSSL_NO_BIO
958int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a); 788int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a);
959int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size); 789int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size);
@@ -983,18 +813,6 @@ BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn);
983/* given a string, return the correct type, max is the maximum length */ 813/* given a string, return the correct type, max is the maximum length */
984int ASN1_PRINTABLE_type(const unsigned char *s, int max); 814int ASN1_PRINTABLE_type(const unsigned char *s, int max);
985 815
986int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
987ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
988 long length, int Ptag, int Pclass);
989unsigned long ASN1_tag2bit(int tag);
990/* type is one or more of the B_ASN1_ values. */
991ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
992 long length, int type);
993
994/* PARSING */
995int asn1_Finish(ASN1_CTX *c);
996int asn1_const_Finish(ASN1_const_CTX *c);
997
998/* SPECIALS */ 816/* SPECIALS */
999int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, 817int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
1000 int *pclass, long omax); 818 int *pclass, long omax);
@@ -1007,29 +825,6 @@ int ASN1_object_size(int constructed, int length, int tag);
1007 825
1008void *ASN1_item_dup(const ASN1_ITEM *it, void *x); 826void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
1009 827
1010#ifndef LIBRESSL_INTERNAL
1011
1012/* Used to implement other functions */
1013void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x);
1014
1015#define ASN1_dup_of(type,i2d,d2i,x) \
1016 ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
1017 CHECKED_D2I_OF(type, d2i), \
1018 CHECKED_PTR_OF(type, x)))
1019
1020#define ASN1_dup_of_const(type,i2d,d2i,x) \
1021 ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \
1022 CHECKED_D2I_OF(type, d2i), \
1023 CHECKED_PTR_OF(const type, x)))
1024
1025/* ASN1 alloc/free macros for when a type is only used internally */
1026
1027#define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
1028#define M_ASN1_free_of(x, type) \
1029 ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
1030
1031#endif /* !LIBRESSL_INTERNAL */
1032
1033void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x); 828void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x);
1034 829
1035#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \ 830#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
@@ -1090,6 +885,8 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
1090int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent); 885int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
1091int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump); 886int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump);
1092#endif 887#endif
888
889unsigned long ASN1_tag2bit(int tag);
1093const char *ASN1_tag2str(int tag); 890const char *ASN1_tag2str(int tag);
1094 891
1095/* Used to load and write netscape format cert */ 892/* Used to load and write netscape format cert */