summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/Makefile.ssl1151
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c216
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c114
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c312
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c252
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c106
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c107
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c180
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c9
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c163
-rw-r--r--src/lib/libcrypto/asn1/a_int.c434
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c400
-rw-r--r--src/lib/libcrypto/asn1/a_object.c320
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c71
-rw-r--r--src/lib/libcrypto/asn1/a_print.c127
-rw-r--r--src/lib/libcrypto/asn1/a_set.c220
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c294
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c558
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c252
-rw-r--r--src/lib/libcrypto/asn1/a_time.c161
-rw-r--r--src/lib/libcrypto/asn1/a_type.c81
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c9
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c211
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c175
-rw-r--r--src/lib/libcrypto/asn1/asn1.h1104
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c240
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c430
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h560
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c423
-rw-r--r--src/lib/libcrypto/asn1/asn1t.h846
-rw-r--r--src/lib/libcrypto/asn1/asn_moid.c95
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c191
-rw-r--r--src/lib/libcrypto/asn1/charmap.h15
-rw-r--r--src/lib/libcrypto/asn1/charmap.pl80
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c145
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c122
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c185
-rw-r--r--src/lib/libcrypto/asn1/f.c80
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c207
-rw-r--r--src/lib/libcrypto/asn1/f_int.c220
-rw-r--r--src/lib/libcrypto/asn1/f_string.c212
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c90
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c88
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c333
-rw-r--r--src/lib/libcrypto/asn1/nsseq.c82
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c122
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c203
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c84
-rw-r--r--src/lib/libcrypto/asn1/t_bitst.c99
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c133
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c401
-rw-r--r--src/lib/libcrypto/asn1/t_req.c277
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c116
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c502
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c110
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c958
-rw-r--r--src/lib/libcrypto/asn1/tasn_enc.c497
-rw-r--r--src/lib/libcrypto/asn1/tasn_fre.c226
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c348
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c198
-rw-r--r--src/lib/libcrypto/asn1/tasn_typ.c133
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c253
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c73
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c118
-rw-r--r--src/lib/libcrypto/asn1/x_bignum.c137
-rw-r--r--src/lib/libcrypto/asn1/x_cinf.c201
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c162
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c71
-rw-r--r--src/lib/libcrypto/asn1/x_info.c114
-rw-r--r--src/lib/libcrypto/asn1/x_long.c169
-rw-r--r--src/lib/libcrypto/asn1/x_name.c272
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c151
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c334
-rw-r--r--src/lib/libcrypto/asn1/x_req.c112
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c69
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c81
-rw-r--r--src/lib/libcrypto/asn1/x_val.c69
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c189
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c151
79 files changed, 18796 insertions, 8 deletions
diff --git a/src/lib/libcrypto/asn1/Makefile.ssl b/src/lib/libcrypto/asn1/Makefile.ssl
new file mode 100644
index 0000000000..b5a186c904
--- /dev/null
+++ b/src/lib/libcrypto/asn1/Makefile.ssl
@@ -0,0 +1,1151 @@
1#
2# SSLeay/crypto/asn1/Makefile
3#
4
5DIR= asn1
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile README
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
27 a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \
28 a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c \
29 x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c \
30 x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c \
31 d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
32 t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c \
33 tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c \
34 f_int.c f_string.c n_pkey.c \
35 f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c \
36 asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \
37 evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c
38LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
39 a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \
40 a_enum.o a_utf8.o a_sign.o a_digest.o a_verify.o a_mbstr.o a_strex.o \
41 x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o x_bignum.o \
42 x_long.o x_name.o x_x509.o x_x509a.o x_crl.o x_info.o x_spki.o nsseq.o \
43 d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \
44 t_req.o t_x509.o t_x509a.o t_crl.o t_pkey.o t_spki.o t_bitst.o \
45 tasn_new.o tasn_fre.o tasn_enc.o tasn_dec.o tasn_utl.o tasn_typ.o \
46 f_int.o f_string.o n_pkey.o \
47 f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o \
48 asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o a_strnid.o \
49 evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o asn_moid.o
50
51SRC= $(LIBSRC)
52
53EXHEADER= asn1.h asn1_mac.h asn1t.h
54HEADER= $(EXHEADER)
55
56ALL= $(GENERAL) $(SRC) $(HEADER)
57
58top:
59 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
60
61test: test.c
62 cc -g -I../../include -c test.c
63 cc -g -I../../include -o test test.o -L../.. -lcrypto
64
65pk: pk.c
66 cc -g -I../../include -c pk.c
67 cc -g -I../../include -o pk pk.o -L../.. -lcrypto
68
69all: lib
70
71lib: $(LIBOBJ)
72 $(AR) $(LIB) $(LIBOBJ)
73 $(RANLIB) $(LIB) || echo Never mind.
74 @touch lib
75
76files:
77 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
78
79links:
80 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
81 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
82 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
83 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
84
85install:
86 @for i in $(EXHEADER) ; \
87 do \
88 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
89 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
90 done;
91
92tags:
93 ctags $(SRC)
94
95tests:
96
97lint:
98 lint -DLINT $(INCLUDES) $(SRC)>fluff
99
100depend:
101 $(MAKEDEPEND) $(CFLAG) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
102
103dclean:
104 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
105 mv -f Makefile.new $(MAKEFILE)
106
107clean:
108 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
109
110
111# DO NOT DELETE THIS LINE -- make depend depends on it.
112
113a_bitstr.o: ../../e_os.h ../../include/openssl/asn1.h
114a_bitstr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
115a_bitstr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
116a_bitstr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
117a_bitstr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
118a_bitstr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
119a_bitstr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
120a_bitstr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bitstr.c
121a_bool.o: ../../e_os.h ../../include/openssl/asn1.h
122a_bool.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
123a_bool.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
124a_bool.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
125a_bool.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
126a_bool.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
127a_bool.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
128a_bool.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
129a_bool.o: ../cryptlib.h a_bool.c
130a_bytes.o: ../../e_os.h ../../include/openssl/asn1.h
131a_bytes.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
132a_bytes.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
133a_bytes.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
134a_bytes.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
135a_bytes.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
136a_bytes.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
137a_bytes.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bytes.c
138a_d2i_fp.o: ../../e_os.h ../../include/openssl/asn1.h
139a_d2i_fp.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
140a_d2i_fp.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
141a_d2i_fp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
142a_d2i_fp.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
143a_d2i_fp.o: ../../include/openssl/opensslconf.h
144a_d2i_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
145a_d2i_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
146a_d2i_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_d2i_fp.c
147a_digest.o: ../../e_os.h ../../include/openssl/aes.h
148a_digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
149a_digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
150a_digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
151a_digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
152a_digest.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
153a_digest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
154a_digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
155a_digest.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
156a_digest.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
157a_digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
158a_digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
159a_digest.o: ../../include/openssl/opensslconf.h
160a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
161a_digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
162a_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
163a_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
164a_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
165a_digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
166a_digest.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
167a_digest.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
168a_digest.o: ../cryptlib.h a_digest.c
169a_dup.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
170a_dup.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
171a_dup.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
172a_dup.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
173a_dup.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
174a_dup.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
175a_dup.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
176a_dup.o: ../cryptlib.h a_dup.c
177a_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
178a_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
179a_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
180a_enum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
181a_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
182a_enum.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
183a_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
184a_enum.o: ../cryptlib.h a_enum.c
185a_gentm.o: ../../e_os.h ../../include/openssl/asn1.h
186a_gentm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
187a_gentm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
188a_gentm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
189a_gentm.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
190a_gentm.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
191a_gentm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
192a_gentm.o: ../../include/openssl/symhacks.h ../cryptlib.h ../o_time.h a_gentm.c
193a_hdr.o: ../../e_os.h ../../include/openssl/asn1.h
194a_hdr.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
195a_hdr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
196a_hdr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
197a_hdr.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
198a_hdr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
199a_hdr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
200a_hdr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
201a_hdr.o: ../cryptlib.h a_hdr.c
202a_i2d_fp.o: ../../e_os.h ../../include/openssl/asn1.h
203a_i2d_fp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
204a_i2d_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
205a_i2d_fp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
206a_i2d_fp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
207a_i2d_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
208a_i2d_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
209a_i2d_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_i2d_fp.c
210a_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
211a_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
212a_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
213a_int.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
214a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
215a_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
216a_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217a_int.o: ../cryptlib.h a_int.c
218a_mbstr.o: ../../e_os.h ../../include/openssl/asn1.h
219a_mbstr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
220a_mbstr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
221a_mbstr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
222a_mbstr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
223a_mbstr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
224a_mbstr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
225a_mbstr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_mbstr.c
226a_meth.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
227a_meth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
228a_meth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
229a_meth.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
230a_meth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
231a_meth.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
232a_meth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
233a_meth.o: ../cryptlib.h a_meth.c
234a_object.o: ../../e_os.h ../../include/openssl/asn1.h
235a_object.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
236a_object.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
237a_object.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
238a_object.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
239a_object.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
240a_object.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
241a_object.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
242a_object.o: ../../include/openssl/symhacks.h ../cryptlib.h a_object.c
243a_octet.o: ../../e_os.h ../../include/openssl/asn1.h
244a_octet.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
245a_octet.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
246a_octet.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
247a_octet.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
248a_octet.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
249a_octet.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
250a_octet.o: ../../include/openssl/symhacks.h ../cryptlib.h a_octet.c
251a_print.o: ../../e_os.h ../../include/openssl/asn1.h
252a_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
253a_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
254a_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
255a_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
256a_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
257a_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
258a_print.o: ../../include/openssl/symhacks.h ../cryptlib.h a_print.c
259a_set.o: ../../e_os.h ../../include/openssl/asn1.h
260a_set.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
261a_set.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
262a_set.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
263a_set.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
264a_set.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
265a_set.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
266a_set.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
267a_set.o: ../cryptlib.h a_set.c
268a_sign.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
269a_sign.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
270a_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
271a_sign.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
272a_sign.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
273a_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
274a_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
275a_sign.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
276a_sign.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
277a_sign.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
278a_sign.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
279a_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
280a_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
281a_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
282a_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
283a_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
284a_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
285a_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
286a_sign.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
287a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
288a_sign.o: ../cryptlib.h a_sign.c
289a_strex.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
290a_strex.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
291a_strex.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
292a_strex.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
293a_strex.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
294a_strex.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
295a_strex.o: ../../include/openssl/e_os2.h ../../include/openssl/evp.h
296a_strex.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
297a_strex.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
298a_strex.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
299a_strex.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
300a_strex.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
301a_strex.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
302a_strex.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
303a_strex.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
304a_strex.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
305a_strex.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
306a_strex.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
307a_strex.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
308a_strex.o: ../../include/openssl/x509_vfy.h a_strex.c charmap.h
309a_strnid.o: ../../e_os.h ../../include/openssl/asn1.h
310a_strnid.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
311a_strnid.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
312a_strnid.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
313a_strnid.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
314a_strnid.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
315a_strnid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
316a_strnid.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
317a_strnid.o: ../../include/openssl/symhacks.h ../cryptlib.h a_strnid.c
318a_time.o: ../../e_os.h ../../include/openssl/asn1.h
319a_time.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
320a_time.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
321a_time.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
322a_time.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
323a_time.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
324a_time.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
325a_time.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
326a_time.o: ../cryptlib.h ../o_time.h a_time.c
327a_type.o: ../../e_os.h ../../include/openssl/asn1.h
328a_type.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
329a_type.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
330a_type.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
331a_type.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
332a_type.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
333a_type.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
334a_type.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
335a_type.o: ../cryptlib.h a_type.c
336a_utctm.o: ../../e_os.h ../../include/openssl/asn1.h
337a_utctm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
338a_utctm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
339a_utctm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
340a_utctm.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
341a_utctm.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
342a_utctm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
343a_utctm.o: ../../include/openssl/symhacks.h ../cryptlib.h ../o_time.h a_utctm.c
344a_utf8.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
345a_utf8.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
346a_utf8.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
347a_utf8.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
348a_utf8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
349a_utf8.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
350a_utf8.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
351a_utf8.o: ../cryptlib.h a_utf8.c
352a_verify.o: ../../e_os.h ../../include/openssl/aes.h
353a_verify.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
354a_verify.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
355a_verify.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
356a_verify.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
357a_verify.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
358a_verify.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
359a_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
360a_verify.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
361a_verify.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
362a_verify.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
363a_verify.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
364a_verify.o: ../../include/openssl/opensslconf.h
365a_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
366a_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
367a_verify.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
368a_verify.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
369a_verify.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
370a_verify.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
371a_verify.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
372a_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
373a_verify.o: ../cryptlib.h a_verify.c
374asn1_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
375asn1_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
376asn1_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
377asn1_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
378asn1_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
379asn1_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
380asn1_err.o: ../../include/openssl/symhacks.h asn1_err.c
381asn1_lib.o: ../../e_os.h ../../include/openssl/asn1.h
382asn1_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
383asn1_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
384asn1_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
385asn1_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
386asn1_lib.o: ../../include/openssl/opensslconf.h
387asn1_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
388asn1_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
389asn1_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_lib.c
390asn1_par.o: ../../e_os.h ../../include/openssl/asn1.h
391asn1_par.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
392asn1_par.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
393asn1_par.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
394asn1_par.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
395asn1_par.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
396asn1_par.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
397asn1_par.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
398asn1_par.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_par.c
399asn_moid.o: ../../e_os.h ../../include/openssl/aes.h
400asn_moid.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
401asn_moid.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
402asn_moid.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
403asn_moid.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
404asn_moid.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
405asn_moid.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
406asn_moid.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
407asn_moid.o: ../../include/openssl/err.h ../../include/openssl/evp.h
408asn_moid.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
409asn_moid.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
410asn_moid.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
411asn_moid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
412asn_moid.o: ../../include/openssl/opensslconf.h
413asn_moid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
414asn_moid.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
415asn_moid.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
416asn_moid.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
417asn_moid.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
418asn_moid.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
419asn_moid.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
420asn_moid.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
421asn_moid.o: ../cryptlib.h asn_moid.c
422asn_pack.o: ../../e_os.h ../../include/openssl/asn1.h
423asn_pack.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
424asn_pack.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
425asn_pack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
426asn_pack.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
427asn_pack.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
428asn_pack.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
429asn_pack.o: ../../include/openssl/symhacks.h ../cryptlib.h asn_pack.c
430d2i_pr.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
431d2i_pr.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
432d2i_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
433d2i_pr.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
434d2i_pr.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
435d2i_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
436d2i_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
437d2i_pr.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
438d2i_pr.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
439d2i_pr.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
440d2i_pr.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
441d2i_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
442d2i_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
443d2i_pr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
444d2i_pr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
445d2i_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
446d2i_pr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
447d2i_pr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
448d2i_pr.o: ../../include/openssl/ui_compat.h ../cryptlib.h d2i_pr.c
449d2i_pu.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
450d2i_pu.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
451d2i_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
452d2i_pu.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
453d2i_pu.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
454d2i_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
455d2i_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
456d2i_pu.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
457d2i_pu.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
458d2i_pu.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
459d2i_pu.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
460d2i_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
461d2i_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
462d2i_pu.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
463d2i_pu.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
464d2i_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
465d2i_pu.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
466d2i_pu.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
467d2i_pu.o: ../../include/openssl/ui_compat.h ../cryptlib.h d2i_pu.c
468evp_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
469evp_asn1.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
470evp_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
471evp_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
472evp_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
473evp_asn1.o: ../../include/openssl/opensslconf.h
474evp_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
475evp_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
476evp_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_asn1.c
477f_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
478f_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
479f_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
480f_enum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
481f_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
482f_enum.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
483f_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
484f_enum.o: ../cryptlib.h f_enum.c
485f_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
486f_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
487f_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
488f_int.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
489f_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
490f_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
491f_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
492f_int.o: ../cryptlib.h f_int.c
493f_string.o: ../../e_os.h ../../include/openssl/asn1.h
494f_string.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
495f_string.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
496f_string.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
497f_string.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
498f_string.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
499f_string.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
500f_string.o: ../../include/openssl/symhacks.h ../cryptlib.h f_string.c
501i2d_pr.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
502i2d_pr.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
503i2d_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
504i2d_pr.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
505i2d_pr.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
506i2d_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
507i2d_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
508i2d_pr.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
509i2d_pr.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
510i2d_pr.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
511i2d_pr.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
512i2d_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
513i2d_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
514i2d_pr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
515i2d_pr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
516i2d_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
517i2d_pr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
518i2d_pr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
519i2d_pr.o: ../../include/openssl/ui_compat.h ../cryptlib.h i2d_pr.c
520i2d_pu.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
521i2d_pu.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
522i2d_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
523i2d_pu.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
524i2d_pu.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
525i2d_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
526i2d_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
527i2d_pu.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
528i2d_pu.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
529i2d_pu.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
530i2d_pu.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
531i2d_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
532i2d_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
533i2d_pu.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
534i2d_pu.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
535i2d_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
536i2d_pu.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
537i2d_pu.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
538i2d_pu.o: ../../include/openssl/ui_compat.h ../cryptlib.h i2d_pu.c
539n_pkey.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
540n_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/asn1t.h
541n_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
542n_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
543n_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
544n_pkey.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
545n_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
546n_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
547n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
548n_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
549n_pkey.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
550n_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
551n_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
552n_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
553n_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
554n_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
555n_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
556n_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
557n_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
558n_pkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
559n_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
560n_pkey.o: ../cryptlib.h n_pkey.c
561nsseq.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
562nsseq.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
563nsseq.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
564nsseq.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
565nsseq.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
566nsseq.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
567nsseq.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
568nsseq.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
569nsseq.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
570nsseq.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
571nsseq.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
572nsseq.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
573nsseq.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
574nsseq.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
575nsseq.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
576nsseq.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
577nsseq.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
578nsseq.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
579nsseq.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
580nsseq.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h nsseq.c
581p5_pbe.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
582p5_pbe.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
583p5_pbe.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
584p5_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
585p5_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
586p5_pbe.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
587p5_pbe.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
588p5_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h
589p5_pbe.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
590p5_pbe.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
591p5_pbe.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
592p5_pbe.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
593p5_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
594p5_pbe.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
595p5_pbe.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
596p5_pbe.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
597p5_pbe.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
598p5_pbe.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
599p5_pbe.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
600p5_pbe.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
601p5_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
602p5_pbe.o: ../cryptlib.h p5_pbe.c
603p5_pbev2.o: ../../e_os.h ../../include/openssl/aes.h
604p5_pbev2.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
605p5_pbev2.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
606p5_pbev2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
607p5_pbev2.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
608p5_pbev2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
609p5_pbev2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
610p5_pbev2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
611p5_pbev2.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
612p5_pbev2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
613p5_pbev2.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
614p5_pbev2.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
615p5_pbev2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
616p5_pbev2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
617p5_pbev2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
618p5_pbev2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
619p5_pbev2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
620p5_pbev2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
621p5_pbev2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
622p5_pbev2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
623p5_pbev2.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
624p5_pbev2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_pbev2.c
625p8_pkey.o: ../../e_os.h ../../include/openssl/aes.h
626p8_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
627p8_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
628p8_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
629p8_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
630p8_pkey.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
631p8_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
632p8_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
633p8_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
634p8_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
635p8_pkey.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
636p8_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
637p8_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
638p8_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
639p8_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
640p8_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
641p8_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
642p8_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
643p8_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
644p8_pkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
645p8_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
646p8_pkey.o: ../cryptlib.h p8_pkey.c
647t_bitst.o: ../../e_os.h ../../include/openssl/aes.h
648t_bitst.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
649t_bitst.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
650t_bitst.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
651t_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
652t_bitst.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
653t_bitst.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
654t_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
655t_bitst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
656t_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
657t_bitst.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
658t_bitst.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
659t_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
660t_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
661t_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
662t_bitst.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
663t_bitst.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
664t_bitst.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
665t_bitst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
666t_bitst.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
667t_bitst.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
668t_bitst.o: ../../include/openssl/x509v3.h ../cryptlib.h t_bitst.c
669t_crl.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
670t_crl.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
671t_crl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
672t_crl.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
673t_crl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
674t_crl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
675t_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
676t_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
677t_crl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
678t_crl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
679t_crl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
680t_crl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
681t_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
682t_crl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
683t_crl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
684t_crl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
685t_crl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
686t_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
687t_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
688t_crl.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
689t_crl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
690t_crl.o: ../cryptlib.h t_crl.c
691t_pkey.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
692t_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
693t_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
694t_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
695t_pkey.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
696t_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
697t_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
698t_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
699t_pkey.o: ../../include/openssl/symhacks.h ../cryptlib.h t_pkey.c
700t_req.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
701t_req.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
702t_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
703t_req.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
704t_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
705t_req.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
706t_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
707t_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
708t_req.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
709t_req.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
710t_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
711t_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
712t_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
713t_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
714t_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
715t_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
716t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
717t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
718t_req.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
719t_req.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
720t_req.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
721t_req.o: ../cryptlib.h t_req.c
722t_spki.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
723t_spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
724t_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
725t_spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
726t_spki.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
727t_spki.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
728t_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
729t_spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
730t_spki.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
731t_spki.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
732t_spki.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
733t_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
734t_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
735t_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
736t_spki.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
737t_spki.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
738t_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
739t_spki.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
740t_spki.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
741t_spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
742t_spki.o: ../cryptlib.h t_spki.c
743t_x509.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
744t_x509.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
745t_x509.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
746t_x509.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
747t_x509.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
748t_x509.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
749t_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
750t_x509.o: ../../include/openssl/err.h ../../include/openssl/evp.h
751t_x509.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
752t_x509.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
753t_x509.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
754t_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
755t_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
756t_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
757t_x509.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
758t_x509.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
759t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
760t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
761t_x509.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
762t_x509.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
763t_x509.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
764t_x509.o: ../cryptlib.h t_x509.c
765t_x509a.o: ../../e_os.h ../../include/openssl/aes.h
766t_x509a.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
767t_x509a.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
768t_x509a.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
769t_x509a.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
770t_x509a.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
771t_x509a.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
772t_x509a.o: ../../include/openssl/err.h ../../include/openssl/evp.h
773t_x509a.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
774t_x509a.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
775t_x509a.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
776t_x509a.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
777t_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
778t_x509a.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
779t_x509a.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
780t_x509a.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
781t_x509a.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
782t_x509a.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
783t_x509a.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
784t_x509a.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
785t_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h t_x509a.c
786tasn_dec.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
787tasn_dec.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
788tasn_dec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
789tasn_dec.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
790tasn_dec.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
791tasn_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
792tasn_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
793tasn_dec.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
794tasn_dec.o: ../../include/openssl/symhacks.h tasn_dec.c
795tasn_enc.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
796tasn_enc.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
797tasn_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
798tasn_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
799tasn_enc.o: ../../include/openssl/opensslconf.h
800tasn_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
801tasn_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
802tasn_enc.o: ../../include/openssl/symhacks.h tasn_enc.c
803tasn_fre.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
804tasn_fre.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
805tasn_fre.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
806tasn_fre.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
807tasn_fre.o: ../../include/openssl/opensslconf.h
808tasn_fre.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
809tasn_fre.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
810tasn_fre.o: ../../include/openssl/symhacks.h tasn_fre.c
811tasn_new.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
812tasn_new.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
813tasn_new.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
814tasn_new.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
815tasn_new.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
816tasn_new.o: ../../include/openssl/opensslconf.h
817tasn_new.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
818tasn_new.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
819tasn_new.o: ../../include/openssl/symhacks.h tasn_new.c
820tasn_typ.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
821tasn_typ.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
822tasn_typ.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
823tasn_typ.o: ../../include/openssl/opensslconf.h
824tasn_typ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
825tasn_typ.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
826tasn_typ.o: ../../include/openssl/symhacks.h tasn_typ.c
827tasn_utl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
828tasn_utl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
829tasn_utl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
830tasn_utl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
831tasn_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
832tasn_utl.o: ../../include/openssl/opensslconf.h
833tasn_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
834tasn_utl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
835tasn_utl.o: ../../include/openssl/symhacks.h tasn_utl.c
836x_algor.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
837x_algor.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
838x_algor.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
839x_algor.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
840x_algor.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
841x_algor.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
842x_algor.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
843x_algor.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
844x_algor.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
845x_algor.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
846x_algor.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
847x_algor.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
848x_algor.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
849x_algor.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
850x_algor.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
851x_algor.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
852x_algor.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
853x_algor.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
854x_algor.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
855x_algor.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
856x_algor.o: x_algor.c
857x_attrib.o: ../../e_os.h ../../include/openssl/aes.h
858x_attrib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
859x_attrib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
860x_attrib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
861x_attrib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
862x_attrib.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
863x_attrib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
864x_attrib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
865x_attrib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
866x_attrib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
867x_attrib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
868x_attrib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
869x_attrib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
870x_attrib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
871x_attrib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
872x_attrib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
873x_attrib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
874x_attrib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
875x_attrib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
876x_attrib.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
877x_attrib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
878x_attrib.o: ../cryptlib.h x_attrib.c
879x_bignum.o: ../../e_os.h ../../include/openssl/asn1.h
880x_bignum.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
881x_bignum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
882x_bignum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
883x_bignum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
884x_bignum.o: ../../include/openssl/opensslconf.h
885x_bignum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
886x_bignum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
887x_bignum.o: ../../include/openssl/symhacks.h ../cryptlib.h x_bignum.c
888x_crl.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
889x_crl.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
890x_crl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
891x_crl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
892x_crl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
893x_crl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
894x_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
895x_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
896x_crl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
897x_crl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
898x_crl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
899x_crl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
900x_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
901x_crl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
902x_crl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
903x_crl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
904x_crl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
905x_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
906x_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
907x_crl.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
908x_crl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_crl.c
909x_exten.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
910x_exten.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
911x_exten.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
912x_exten.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
913x_exten.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
914x_exten.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
915x_exten.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
916x_exten.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
917x_exten.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
918x_exten.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
919x_exten.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
920x_exten.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
921x_exten.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
922x_exten.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
923x_exten.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
924x_exten.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
925x_exten.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
926x_exten.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
927x_exten.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
928x_exten.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
929x_exten.o: x_exten.c
930x_info.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
931x_info.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
932x_info.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
933x_info.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
934x_info.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
935x_info.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
936x_info.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
937x_info.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
938x_info.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
939x_info.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
940x_info.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
941x_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
942x_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
943x_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
944x_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
945x_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
946x_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
947x_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
948x_info.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
949x_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
950x_info.o: ../cryptlib.h x_info.c
951x_long.o: ../../e_os.h ../../include/openssl/asn1.h
952x_long.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
953x_long.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
954x_long.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
955x_long.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
956x_long.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
957x_long.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
958x_long.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
959x_long.o: ../cryptlib.h x_long.c
960x_name.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
961x_name.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
962x_name.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
963x_name.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
964x_name.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
965x_name.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
966x_name.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
967x_name.o: ../../include/openssl/err.h ../../include/openssl/evp.h
968x_name.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
969x_name.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
970x_name.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
971x_name.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
972x_name.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
973x_name.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
974x_name.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
975x_name.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
976x_name.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
977x_name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
978x_name.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
979x_name.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
980x_name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_name.c
981x_pkey.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
982x_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
983x_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
984x_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
985x_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
986x_pkey.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
987x_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
988x_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
989x_pkey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
990x_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
991x_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
992x_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
993x_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
994x_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
995x_pkey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
996x_pkey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
997x_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
998x_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
999x_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1000x_pkey.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1001x_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_pkey.c
1002x_pubkey.o: ../../e_os.h ../../include/openssl/aes.h
1003x_pubkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
1004x_pubkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1005x_pubkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1006x_pubkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1007x_pubkey.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1008x_pubkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1009x_pubkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1010x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1011x_pubkey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1012x_pubkey.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1013x_pubkey.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1014x_pubkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1015x_pubkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1016x_pubkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1017x_pubkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1018x_pubkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1019x_pubkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1020x_pubkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1021x_pubkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1022x_pubkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1023x_pubkey.o: ../cryptlib.h x_pubkey.c
1024x_req.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1025x_req.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1026x_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1027x_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1028x_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1029x_req.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1030x_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1031x_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1032x_req.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1033x_req.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1034x_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1035x_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1036x_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1037x_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1038x_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1039x_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1040x_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1041x_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1042x_req.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1043x_req.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1044x_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_req.c
1045x_sig.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1046x_sig.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1047x_sig.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1048x_sig.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1049x_sig.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1050x_sig.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1051x_sig.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1052x_sig.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1053x_sig.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1054x_sig.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1055x_sig.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1056x_sig.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1057x_sig.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1058x_sig.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1059x_sig.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1060x_sig.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1061x_sig.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1062x_sig.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1063x_sig.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1064x_sig.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1065x_sig.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_sig.c
1066x_spki.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1067x_spki.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1068x_spki.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1069x_spki.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1070x_spki.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1071x_spki.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1072x_spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1073x_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1074x_spki.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1075x_spki.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1076x_spki.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1077x_spki.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1078x_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1079x_spki.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1080x_spki.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1081x_spki.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1082x_spki.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1083x_spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1084x_spki.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1085x_spki.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1086x_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_spki.c
1087x_val.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1088x_val.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1089x_val.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1090x_val.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1091x_val.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1092x_val.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1093x_val.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1094x_val.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1095x_val.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1096x_val.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1097x_val.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1098x_val.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1099x_val.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1100x_val.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1101x_val.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1102x_val.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1103x_val.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1104x_val.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1105x_val.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1106x_val.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1107x_val.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_val.c
1108x_x509.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1109x_x509.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1110x_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1111x_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1112x_x509.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
1113x_x509.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1114x_x509.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1115x_x509.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1116x_x509.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1117x_x509.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1118x_x509.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1119x_x509.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1120x_x509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1121x_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1122x_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1123x_x509.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1124x_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1125x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1126x_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1127x_x509.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1128x_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1129x_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h x_x509.c
1130x_x509a.o: ../../e_os.h ../../include/openssl/aes.h
1131x_x509a.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
1132x_x509a.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1133x_x509a.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1134x_x509a.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1135x_x509a.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1136x_x509a.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1137x_x509a.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1138x_x509a.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1139x_x509a.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1140x_x509a.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1141x_x509a.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1142x_x509a.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1143x_x509a.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1144x_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1145x_x509a.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1146x_x509a.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1147x_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1148x_x509a.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1149x_x509a.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1150x_x509a.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1151x_x509a.o: ../cryptlib.h x_x509a.c
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
new file mode 100644
index 0000000000..e0265f69d2
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -0,0 +1,216 @@
1/* crypto/asn1/a_bitstr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
64{ return M_ASN1_BIT_STRING_set(x, d, len); }
65
66int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
67 {
68 int ret,j,bits,len;
69 unsigned char *p,*d;
70
71 if (a == NULL) return(0);
72
73 len=a->length;
74
75 if (len > 0)
76 {
77 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
78 {
79 bits=(int)a->flags&0x07;
80 }
81 else
82 {
83 for ( ; len > 0; len--)
84 {
85 if (a->data[len-1]) break;
86 }
87 j=a->data[len-1];
88 if (j & 0x01) bits=0;
89 else if (j & 0x02) bits=1;
90 else if (j & 0x04) bits=2;
91 else if (j & 0x08) bits=3;
92 else if (j & 0x10) bits=4;
93 else if (j & 0x20) bits=5;
94 else if (j & 0x40) bits=6;
95 else if (j & 0x80) bits=7;
96 else bits=0; /* should not happen */
97 }
98 }
99 else
100 bits=0;
101
102 ret=1+len;
103 if (pp == NULL) return(ret);
104
105 p= *pp;
106
107 *(p++)=(unsigned char)bits;
108 d=a->data;
109 memcpy(p,d,len);
110 p+=len;
111 if (len > 0) p[-1]&=(0xff<<bits);
112 *pp=p;
113 return(ret);
114 }
115
116ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
117 long len)
118 {
119 ASN1_BIT_STRING *ret=NULL;
120 unsigned char *p,*s;
121 int i;
122
123 if (len < 1)
124 {
125 i=ASN1_R_STRING_TOO_SHORT;
126 goto err;
127 }
128
129 if ((a == NULL) || ((*a) == NULL))
130 {
131 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
132 }
133 else
134 ret=(*a);
135
136 p= *pp;
137 i= *(p++);
138 /* We do this to preserve the settings. If we modify
139 * the settings, via the _set_bit function, we will recalculate
140 * on output */
141 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
142 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
143
144 if (len-- > 1) /* using one because of the bits left byte */
145 {
146 s=(unsigned char *)OPENSSL_malloc((int)len);
147 if (s == NULL)
148 {
149 i=ERR_R_MALLOC_FAILURE;
150 goto err;
151 }
152 memcpy(s,p,(int)len);
153 s[len-1]&=(0xff<<i);
154 p+=len;
155 }
156 else
157 s=NULL;
158
159 ret->length=(int)len;
160 if (ret->data != NULL) OPENSSL_free(ret->data);
161 ret->data=s;
162 ret->type=V_ASN1_BIT_STRING;
163 if (a != NULL) (*a)=ret;
164 *pp=p;
165 return(ret);
166err:
167 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
168 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
169 M_ASN1_BIT_STRING_free(ret);
170 return(NULL);
171 }
172
173/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
174 */
175int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
176 {
177 int w,v,iv;
178 unsigned char *c;
179
180 w=n/8;
181 v=1<<(7-(n&0x07));
182 iv= ~v;
183 if (!value) v=0;
184
185 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
186
187 if (a == NULL) return(0);
188 if ((a->length < (w+1)) || (a->data == NULL))
189 {
190 if (!value) return(1); /* Don't need to set */
191 if (a->data == NULL)
192 c=(unsigned char *)OPENSSL_malloc(w+1);
193 else
194 c=(unsigned char *)OPENSSL_realloc(a->data,w+1);
195 if (c == NULL) return(0);
196 if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length);
197 a->data=c;
198 a->length=w+1;
199 }
200 a->data[w]=((a->data[w])&iv)|v;
201 while ((a->length > 0) && (a->data[a->length-1] == 0))
202 a->length--;
203 return(1);
204 }
205
206int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
207 {
208 int w,v;
209
210 w=n/8;
211 v=1<<(7-(n&0x07));
212 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
213 return(0);
214 return((a->data[w]&v) != 0);
215 }
216
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c
new file mode 100644
index 0000000000..24333ea4d5
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_bool.c
@@ -0,0 +1,114 @@
1/* crypto/asn1/a_bool.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
64 {
65 int r;
66 unsigned char *p;
67
68 r=ASN1_object_size(0,1,V_ASN1_BOOLEAN);
69 if (pp == NULL) return(r);
70 p= *pp;
71
72 ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL);
73 *(p++)= (unsigned char)a;
74 *pp=p;
75 return(r);
76 }
77
78int d2i_ASN1_BOOLEAN(int *a, unsigned char **pp, long length)
79 {
80 int ret= -1;
81 unsigned char *p;
82 long len;
83 int inf,tag,xclass;
84 int i=0;
85
86 p= *pp;
87 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
88 if (inf & 0x80)
89 {
90 i=ASN1_R_BAD_OBJECT_HEADER;
91 goto err;
92 }
93
94 if (tag != V_ASN1_BOOLEAN)
95 {
96 i=ASN1_R_EXPECTING_A_BOOLEAN;
97 goto err;
98 }
99
100 if (len != 1)
101 {
102 i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
103 goto err;
104 }
105 ret= (int)*(p++);
106 if (a != NULL) (*a)=ret;
107 *pp=p;
108 return(ret);
109err:
110 ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i);
111 return(ret);
112 }
113
114
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
new file mode 100644
index 0000000000..bb88660f58
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_bytes.c
@@ -0,0 +1,312 @@
1/* crypto/asn1/a_bytes.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c);
64/* type is a 'bitmap' of acceptable string types.
65 */
66ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
67 long length, int type)
68 {
69 ASN1_STRING *ret=NULL;
70 unsigned char *p,*s;
71 long len;
72 int inf,tag,xclass;
73 int i=0;
74
75 p= *pp;
76 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
77 if (inf & 0x80) goto err;
78
79 if (tag >= 32)
80 {
81 i=ASN1_R_TAG_VALUE_TOO_HIGH;;
82 goto err;
83 }
84 if (!(ASN1_tag2bit(tag) & type))
85 {
86 i=ASN1_R_WRONG_TYPE;
87 goto err;
88 }
89
90 /* If a bit-string, exit early */
91 if (tag == V_ASN1_BIT_STRING)
92 return(d2i_ASN1_BIT_STRING(a,pp,length));
93
94 if ((a == NULL) || ((*a) == NULL))
95 {
96 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
97 }
98 else
99 ret=(*a);
100
101 if (len != 0)
102 {
103 s=(unsigned char *)OPENSSL_malloc((int)len+1);
104 if (s == NULL)
105 {
106 i=ERR_R_MALLOC_FAILURE;
107 goto err;
108 }
109 memcpy(s,p,(int)len);
110 s[len]='\0';
111 p+=len;
112 }
113 else
114 s=NULL;
115
116 if (ret->data != NULL) OPENSSL_free(ret->data);
117 ret->length=(int)len;
118 ret->data=s;
119 ret->type=tag;
120 if (a != NULL) (*a)=ret;
121 *pp=p;
122 return(ret);
123err:
124 ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i);
125 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
126 ASN1_STRING_free(ret);
127 return(NULL);
128 }
129
130int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
131 {
132 int ret,r,constructed;
133 unsigned char *p;
134
135 if (a == NULL) return(0);
136
137 if (tag == V_ASN1_BIT_STRING)
138 return(i2d_ASN1_BIT_STRING(a,pp));
139
140 ret=a->length;
141 r=ASN1_object_size(0,ret,tag);
142 if (pp == NULL) return(r);
143 p= *pp;
144
145 if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
146 constructed=1;
147 else
148 constructed=0;
149 ASN1_put_object(&p,constructed,ret,tag,xclass);
150 memcpy(p,a->data,a->length);
151 p+=a->length;
152 *pp= p;
153 return(r);
154 }
155
156ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
157 int Ptag, int Pclass)
158 {
159 ASN1_STRING *ret=NULL;
160 unsigned char *p,*s;
161 long len;
162 int inf,tag,xclass;
163 int i=0;
164
165 if ((a == NULL) || ((*a) == NULL))
166 {
167 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
168 }
169 else
170 ret=(*a);
171
172 p= *pp;
173 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
174 if (inf & 0x80)
175 {
176 i=ASN1_R_BAD_OBJECT_HEADER;
177 goto err;
178 }
179
180 if (tag != Ptag)
181 {
182 i=ASN1_R_WRONG_TAG;
183 goto err;
184 }
185
186 if (inf & V_ASN1_CONSTRUCTED)
187 {
188 ASN1_CTX c;
189
190 c.pp=pp;
191 c.p=p;
192 c.inf=inf;
193 c.slen=len;
194 c.tag=Ptag;
195 c.xclass=Pclass;
196 c.max=(length == 0)?0:(p+length);
197 if (!asn1_collate_primitive(ret,&c))
198 goto err;
199 else
200 {
201 p=c.p;
202 }
203 }
204 else
205 {
206 if (len != 0)
207 {
208 if ((ret->length < len) || (ret->data == NULL))
209 {
210 if (ret->data != NULL) OPENSSL_free(ret->data);
211 s=(unsigned char *)OPENSSL_malloc((int)len + 1);
212 if (s == NULL)
213 {
214 i=ERR_R_MALLOC_FAILURE;
215 goto err;
216 }
217 }
218 else
219 s=ret->data;
220 memcpy(s,p,(int)len);
221 s[len] = '\0';
222 p+=len;
223 }
224 else
225 {
226 s=NULL;
227 if (ret->data != NULL) OPENSSL_free(ret->data);
228 }
229
230 ret->length=(int)len;
231 ret->data=s;
232 ret->type=Ptag;
233 }
234
235 if (a != NULL) (*a)=ret;
236 *pp=p;
237 return(ret);
238err:
239 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
240 ASN1_STRING_free(ret);
241 ASN1err(ASN1_F_D2I_ASN1_BYTES,i);
242 return(NULL);
243 }
244
245
246/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
247 * them into the one structure that is then returned */
248/* There have been a few bug fixes for this function from
249 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
250static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
251 {
252 ASN1_STRING *os=NULL;
253 BUF_MEM b;
254 int num;
255
256 b.length=0;
257 b.max=0;
258 b.data=NULL;
259
260 if (a == NULL)
261 {
262 c->error=ERR_R_PASSED_NULL_PARAMETER;
263 goto err;
264 }
265
266 num=0;
267 for (;;)
268 {
269 if (c->inf & 1)
270 {
271 c->eos=ASN1_check_infinite_end(&c->p,
272 (long)(c->max-c->p));
273 if (c->eos) break;
274 }
275 else
276 {
277 if (c->slen <= 0) break;
278 }
279
280 c->q=c->p;
281 if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass)
282 == NULL)
283 {
284 c->error=ERR_R_ASN1_LIB;
285 goto err;
286 }
287
288 if (!BUF_MEM_grow(&b,num+os->length))
289 {
290 c->error=ERR_R_BUF_LIB;
291 goto err;
292 }
293 memcpy(&(b.data[num]),os->data,os->length);
294 if (!(c->inf & 1))
295 c->slen-=(c->p-c->q);
296 num+=os->length;
297 }
298
299 if (!asn1_Finish(c)) goto err;
300
301 a->length=num;
302 if (a->data != NULL) OPENSSL_free(a->data);
303 a->data=(unsigned char *)b.data;
304 if (os != NULL) ASN1_STRING_free(os);
305 return(1);
306err:
307 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
308 if (os != NULL) ASN1_STRING_free(os);
309 if (b.data != NULL) OPENSSL_free(b.data);
310 return(0);
311 }
312
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c
new file mode 100644
index 0000000000..a80fbe9ff7
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_d2i_fp.c
@@ -0,0 +1,252 @@
1/* crypto/asn1/a_d2i_fp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1_mac.h>
63
64static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
65
66#ifndef NO_OLD_ASN1
67#ifndef OPENSSL_NO_FP_API
68
69char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
70 unsigned char **x)
71 {
72 BIO *b;
73 char *ret;
74
75 if ((b=BIO_new(BIO_s_file())) == NULL)
76 {
77 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
78 return(NULL);
79 }
80 BIO_set_fp(b,in,BIO_NOCLOSE);
81 ret=ASN1_d2i_bio(xnew,d2i,b,x);
82 BIO_free(b);
83 return(ret);
84 }
85#endif
86
87char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
88 unsigned char **x)
89 {
90 BUF_MEM *b = NULL;
91 unsigned char *p;
92 char *ret=NULL;
93 int len;
94
95 len = asn1_d2i_read_bio(in, &b);
96 if(len < 0) goto err;
97
98 p=(unsigned char *)b->data;
99 ret=d2i(x,&p,len);
100err:
101 if (b != NULL) BUF_MEM_free(b);
102 return(ret);
103 }
104
105#endif
106
107void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
108 {
109 BUF_MEM *b = NULL;
110 unsigned char *p;
111 void *ret=NULL;
112 int len;
113
114 len = asn1_d2i_read_bio(in, &b);
115 if(len < 0) goto err;
116
117 p=(unsigned char *)b->data;
118 ret=ASN1_item_d2i(x,&p,len, it);
119err:
120 if (b != NULL) BUF_MEM_free(b);
121 return(ret);
122 }
123
124#ifndef OPENSSL_NO_FP_API
125void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
126 {
127 BIO *b;
128 char *ret;
129
130 if ((b=BIO_new(BIO_s_file())) == NULL)
131 {
132 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
133 return(NULL);
134 }
135 BIO_set_fp(b,in,BIO_NOCLOSE);
136 ret=ASN1_item_d2i_bio(it,b,x);
137 BIO_free(b);
138 return(ret);
139 }
140#endif
141
142#define HEADER_SIZE 8
143static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
144 {
145 BUF_MEM *b;
146 unsigned char *p;
147 int i;
148 int ret=-1;
149 ASN1_CTX c;
150 int want=HEADER_SIZE;
151 int eos=0;
152 int off=0;
153 int len=0;
154
155 b=BUF_MEM_new();
156 if (b == NULL)
157 {
158 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
159 return -1;
160 }
161
162 ERR_clear_error();
163 for (;;)
164 {
165 if (want >= (len-off))
166 {
167 want-=(len-off);
168
169 if (!BUF_MEM_grow(b,len+want))
170 {
171 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
172 goto err;
173 }
174 i=BIO_read(in,&(b->data[len]),want);
175 if ((i < 0) && ((len-off) == 0))
176 {
177 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
178 goto err;
179 }
180 if (i > 0)
181 len+=i;
182 }
183 /* else data already loaded */
184
185 p=(unsigned char *)&(b->data[off]);
186 c.p=p;
187 c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass),
188 len-off);
189 if (c.inf & 0x80)
190 {
191 unsigned long e;
192
193 e=ERR_GET_REASON(ERR_peek_error());
194 if (e != ASN1_R_TOO_LONG)
195 goto err;
196 else
197 ERR_get_error(); /* clear error */
198 }
199 i=c.p-p;/* header length */
200 off+=i; /* end of data */
201
202 if (c.inf & 1)
203 {
204 /* no data body so go round again */
205 eos++;
206 want=HEADER_SIZE;
207 }
208 else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC))
209 {
210 /* eos value, so go back and read another header */
211 eos--;
212 if (eos <= 0)
213 break;
214 else
215 want=HEADER_SIZE;
216 }
217 else
218 {
219 /* suck in c.slen bytes of data */
220 want=(int)c.slen;
221 if (want > (len-off))
222 {
223 want-=(len-off);
224 if (!BUF_MEM_grow(b,len+want))
225 {
226 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
227 goto err;
228 }
229 i=BIO_read(in,&(b->data[len]),want);
230 if (i <= 0)
231 {
232 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
233 goto err;
234 }
235 len+=i;
236 }
237 off+=(int)c.slen;
238 if (eos <= 0)
239 {
240 break;
241 }
242 else
243 want=HEADER_SIZE;
244 }
245 }
246
247 *pb = b;
248 return off;
249err:
250 if (b != NULL) BUF_MEM_free(b);
251 return(ret);
252 }
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
new file mode 100644
index 0000000000..4931e222a0
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_digest.c
@@ -0,0 +1,106 @@
1/* crypto/asn1/a_digest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61
62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
68#include <openssl/evp.h>
69#include <openssl/buffer.h>
70#include <openssl/x509.h>
71
72#ifndef NO_ASN1_OLD
73
74int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
75 unsigned char *md, unsigned int *len)
76 {
77 int i;
78 unsigned char *str,*p;
79
80 i=i2d(data,NULL);
81 if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL) return(0);
82 p=str;
83 i2d(data,&p);
84
85 EVP_Digest(str, i, md, len, type, NULL);
86 OPENSSL_free(str);
87 return(1);
88 }
89
90#endif
91
92
93int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
94 unsigned char *md, unsigned int *len)
95 {
96 int i;
97 unsigned char *str = NULL;
98
99 i=ASN1_item_i2d(asn,&str, it);
100 if (!str) return(0);
101
102 EVP_Digest(str, i, md, len, type, NULL);
103 OPENSSL_free(str);
104 return(1);
105 }
106
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
new file mode 100644
index 0000000000..58a017884c
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_dup.c
@@ -0,0 +1,107 @@
1/* crypto/asn1/a_dup.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63#ifndef NO_OLD_ASN1
64
65char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x)
66 {
67 unsigned char *b,*p;
68 long i;
69 char *ret;
70
71 if (x == NULL) return(NULL);
72
73 i=(long)i2d(x,NULL);
74 b=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
75 if (b == NULL)
76 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
77 p= b;
78 i=i2d(x,&p);
79 p= b;
80 ret=d2i(NULL,&p,i);
81 OPENSSL_free(b);
82 return(ret);
83 }
84
85#endif
86
87/* ASN1_ITEM version of dup: this follows the model above except we don't need
88 * to allocate the buffer. At some point this could be rewritten to directly dup
89 * the underlying structure instead of doing and encode and decode.
90 */
91
92void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
93 {
94 unsigned char *b = NULL, *p;
95 long i;
96 void *ret;
97
98 if (x == NULL) return(NULL);
99
100 i=ASN1_item_i2d(x,&b,it);
101 if (b == NULL)
102 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
103 p= b;
104 ret=ASN1_item_d2i(NULL,&p,i, it);
105 OPENSSL_free(b);
106 return(ret);
107 }
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
new file mode 100644
index 0000000000..ad8f0ffd1a
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_enum.c
@@ -0,0 +1,180 @@
1/* crypto/asn1/a_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/*
64 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
65 * for comments on encoding see a_int.c
66 */
67
68int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
69 {
70 int i,j,k;
71 unsigned char buf[sizeof(long)+1];
72 long d;
73
74 a->type=V_ASN1_ENUMERATED;
75 if (a->length < (sizeof(long)+1))
76 {
77 if (a->data != NULL)
78 OPENSSL_free(a->data);
79 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL)
80 memset((char *)a->data,0,sizeof(long)+1);
81 }
82 if (a->data == NULL)
83 {
84 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
85 return(0);
86 }
87 d=v;
88 if (d < 0)
89 {
90 d= -d;
91 a->type=V_ASN1_NEG_ENUMERATED;
92 }
93
94 for (i=0; i<sizeof(long); i++)
95 {
96 if (d == 0) break;
97 buf[i]=(int)d&0xff;
98 d>>=8;
99 }
100 j=0;
101 for (k=i-1; k >=0; k--)
102 a->data[j++]=buf[k];
103 a->length=j;
104 return(1);
105 }
106
107long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
108 {
109 int neg=0,i;
110 long r=0;
111
112 if (a == NULL) return(0L);
113 i=a->type;
114 if (i == V_ASN1_NEG_ENUMERATED)
115 neg=1;
116 else if (i != V_ASN1_ENUMERATED)
117 return -1;
118
119 if (a->length > sizeof(long))
120 {
121 /* hmm... a bit ugly */
122 return(0xffffffffL);
123 }
124 if (a->data == NULL)
125 return 0;
126
127 for (i=0; i<a->length; i++)
128 {
129 r<<=8;
130 r|=(unsigned char)a->data[i];
131 }
132 if (neg) r= -r;
133 return(r);
134 }
135
136ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
137 {
138 ASN1_ENUMERATED *ret;
139 int len,j;
140
141 if (ai == NULL)
142 ret=M_ASN1_ENUMERATED_new();
143 else
144 ret=ai;
145 if (ret == NULL)
146 {
147 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
148 goto err;
149 }
150 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
151 else ret->type=V_ASN1_ENUMERATED;
152 j=BN_num_bits(bn);
153 len=((j == 0)?0:((j/8)+1));
154 if (ret->length < len+4)
155 {
156 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
157 if (!new_data)
158 {
159 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
160 goto err;
161 }
162 ret->data=new_data;
163 }
164
165 ret->length=BN_bn2bin(bn,ret->data);
166 return(ret);
167err:
168 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
169 return(NULL);
170 }
171
172BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
173 {
174 BIGNUM *ret;
175
176 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
177 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
178 else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1;
179 return(ret);
180 }
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c
index cd09f68b38..48b923de1f 100644
--- a/src/lib/libcrypto/asn1/a_gentm.c
+++ b/src/lib/libcrypto/asn1/a_gentm.c
@@ -208,6 +208,7 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
208 char *p; 208 char *p;
209 struct tm *ts; 209 struct tm *ts;
210 struct tm data; 210 struct tm data;
211 size_t len = 20;
211 212
212 if (s == NULL) 213 if (s == NULL)
213 s=M_ASN1_GENERALIZEDTIME_new(); 214 s=M_ASN1_GENERALIZEDTIME_new();
@@ -219,17 +220,17 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
219 return(NULL); 220 return(NULL);
220 221
221 p=(char *)s->data; 222 p=(char *)s->data;
222 if ((p == NULL) || (s->length < 16)) 223 if ((p == NULL) || (s->length < len))
223 { 224 {
224 p=OPENSSL_malloc(20); 225 p=OPENSSL_malloc(len);
225 if (p == NULL) return(NULL); 226 if (p == NULL) return(NULL);
226 if (s->data != NULL) 227 if (s->data != NULL)
227 OPENSSL_free(s->data); 228 OPENSSL_free(s->data);
228 s->data=(unsigned char *)p; 229 s->data=(unsigned char *)p;
229 } 230 }
230 231
231 sprintf(p,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, 232 snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
232 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); 233 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
233 s->length=strlen(p); 234 s->length=strlen(p);
234 s->type=V_ASN1_GENERALIZEDTIME; 235 s->type=V_ASN1_GENERALIZEDTIME;
235#ifdef CHARSET_EBCDIC_not 236#ifdef CHARSET_EBCDIC_not
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
new file mode 100644
index 0000000000..f4f1b73ebe
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_i2d_fp.c
@@ -0,0 +1,163 @@
1/* crypto/asn1/a_i2d_fp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64#ifndef NO_OLD_ASN1
65
66#ifndef OPENSSL_NO_FP_API
67int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x)
68 {
69 BIO *b;
70 int ret;
71
72 if ((b=BIO_new(BIO_s_file())) == NULL)
73 {
74 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
75 return(0);
76 }
77 BIO_set_fp(b,out,BIO_NOCLOSE);
78 ret=ASN1_i2d_bio(i2d,b,x);
79 BIO_free(b);
80 return(ret);
81 }
82#endif
83
84int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
85 {
86 char *b;
87 unsigned char *p;
88 int i,j=0,n,ret=1;
89
90 n=i2d(x,NULL);
91 b=(char *)OPENSSL_malloc(n);
92 if (b == NULL)
93 {
94 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
95 return(0);
96 }
97
98 p=(unsigned char *)b;
99 i2d(x,&p);
100
101 for (;;)
102 {
103 i=BIO_write(out,&(b[j]),n);
104 if (i == n) break;
105 if (i <= 0)
106 {
107 ret=0;
108 break;
109 }
110 j+=i;
111 n-=i;
112 }
113 OPENSSL_free(b);
114 return(ret);
115 }
116
117#endif
118
119#ifndef OPENSSL_NO_FP_API
120int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
121 {
122 BIO *b;
123 int ret;
124
125 if ((b=BIO_new(BIO_s_file())) == NULL)
126 {
127 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
128 return(0);
129 }
130 BIO_set_fp(b,out,BIO_NOCLOSE);
131 ret=ASN1_item_i2d_bio(it,b,x);
132 BIO_free(b);
133 return(ret);
134 }
135#endif
136
137int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
138 {
139 unsigned char *b = NULL;
140 int i,j=0,n,ret=1;
141
142 n = ASN1_item_i2d(x, &b, it);
143 if (b == NULL)
144 {
145 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
146 return(0);
147 }
148
149 for (;;)
150 {
151 i=BIO_write(out,&(b[j]),n);
152 if (i == n) break;
153 if (i <= 0)
154 {
155 ret=0;
156 break;
157 }
158 j+=i;
159 n-=i;
160 }
161 OPENSSL_free(b);
162 return(ret);
163 }
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
new file mode 100644
index 0000000000..edb243c021
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_int.c
@@ -0,0 +1,434 @@
1/* crypto/asn1/a_int.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
64{ return M_ASN1_INTEGER_dup(x);}
65
66int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
67{ return M_ASN1_INTEGER_cmp(x,y);}
68
69/*
70 * This converts an ASN1 INTEGER into its content encoding.
71 * The internal representation is an ASN1_STRING whose data is a big endian
72 * representation of the value, ignoring the sign. The sign is determined by
73 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
74 *
75 * Positive integers are no problem: they are almost the same as the DER
76 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
77 *
78 * Negative integers are a bit trickier...
79 * The DER representation of negative integers is in 2s complement form.
80 * The internal form is converted by complementing each octet and finally
81 * adding one to the result. This can be done less messily with a little trick.
82 * If the internal form has trailing zeroes then they will become FF by the
83 * complement and 0 by the add one (due to carry) so just copy as many trailing
84 * zeros to the destination as there are in the source. The carry will add one
85 * to the last none zero octet: so complement this octet and add one and finally
86 * complement any left over until you get to the start of the string.
87 *
88 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
89 * with 0xff. However if the first byte is 0x80 and one of the following bytes
90 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
91 * followed by optional zeros isn't padded.
92 */
93
94int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
95 {
96 int pad=0,ret,i,neg;
97 unsigned char *p,*n,pb=0;
98
99 if ((a == NULL) || (a->data == NULL)) return(0);
100 neg=a->type & V_ASN1_NEG;
101 if (a->length == 0)
102 ret=1;
103 else
104 {
105 ret=a->length;
106 i=a->data[0];
107 if (!neg && (i > 127)) {
108 pad=1;
109 pb=0;
110 } else if(neg) {
111 if(i>128) {
112 pad=1;
113 pb=0xFF;
114 } else if(i == 128) {
115 /*
116 * Special case: if any other bytes non zero we pad:
117 * otherwise we don't.
118 */
119 for(i = 1; i < a->length; i++) if(a->data[i]) {
120 pad=1;
121 pb=0xFF;
122 break;
123 }
124 }
125 }
126 ret+=pad;
127 }
128 if (pp == NULL) return(ret);
129 p= *pp;
130
131 if (pad) *(p++)=pb;
132 if (a->length == 0) *(p++)=0;
133 else if (!neg) memcpy(p,a->data,(unsigned int)a->length);
134 else {
135 /* Begin at the end of the encoding */
136 n=a->data + a->length - 1;
137 p += a->length - 1;
138 i = a->length;
139 /* Copy zeros to destination as long as source is zero */
140 while(!*n) {
141 *(p--) = 0;
142 n--;
143 i--;
144 }
145 /* Complement and increment next octet */
146 *(p--) = ((*(n--)) ^ 0xff) + 1;
147 i--;
148 /* Complement any octets left */
149 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
150 }
151
152 *pp+=ret;
153 return(ret);
154 }
155
156/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
157
158ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
159 long len)
160 {
161 ASN1_INTEGER *ret=NULL;
162 unsigned char *p,*to,*s, *pend;
163 int i;
164
165 if ((a == NULL) || ((*a) == NULL))
166 {
167 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
168 ret->type=V_ASN1_INTEGER;
169 }
170 else
171 ret=(*a);
172
173 p= *pp;
174 pend = p + len;
175
176 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it
177 * signifies a missing NULL parameter. */
178 s=(unsigned char *)OPENSSL_malloc((int)len+1);
179 if (s == NULL)
180 {
181 i=ERR_R_MALLOC_FAILURE;
182 goto err;
183 }
184 to=s;
185 if(!len) {
186 /* Strictly speaking this is an illegal INTEGER but we
187 * tolerate it.
188 */
189 ret->type=V_ASN1_INTEGER;
190 } else if (*p & 0x80) /* a negative number */
191 {
192 ret->type=V_ASN1_NEG_INTEGER;
193 if ((*p == 0xff) && (len != 1)) {
194 p++;
195 len--;
196 }
197 i = len;
198 p += i - 1;
199 to += i - 1;
200 while((!*p) && i) {
201 *(to--) = 0;
202 i--;
203 p--;
204 }
205 /* Special case: if all zeros then the number will be of
206 * the form FF followed by n zero bytes: this corresponds to
207 * 1 followed by n zero bytes. We've already written n zeros
208 * so we just append an extra one and set the first byte to
209 * a 1. This is treated separately because it is the only case
210 * where the number of bytes is larger than len.
211 */
212 if(!i) {
213 *s = 1;
214 s[len] = 0;
215 len++;
216 } else {
217 *(to--) = (*(p--) ^ 0xff) + 1;
218 i--;
219 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
220 }
221 } else {
222 ret->type=V_ASN1_INTEGER;
223 if ((*p == 0) && (len != 1))
224 {
225 p++;
226 len--;
227 }
228 memcpy(s,p,(int)len);
229 }
230
231 if (ret->data != NULL) OPENSSL_free(ret->data);
232 ret->data=s;
233 ret->length=(int)len;
234 if (a != NULL) (*a)=ret;
235 *pp=pend;
236 return(ret);
237err:
238 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
239 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
240 M_ASN1_INTEGER_free(ret);
241 return(NULL);
242 }
243
244
245/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
246 * ASN1 integers: some broken software can encode a positive INTEGER
247 * with its MSB set as negative (it doesn't add a padding zero).
248 */
249
250ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
251 long length)
252 {
253 ASN1_INTEGER *ret=NULL;
254 unsigned char *p,*to,*s;
255 long len;
256 int inf,tag,xclass;
257 int i;
258
259 if ((a == NULL) || ((*a) == NULL))
260 {
261 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
262 ret->type=V_ASN1_INTEGER;
263 }
264 else
265 ret=(*a);
266
267 p= *pp;
268 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
269 if (inf & 0x80)
270 {
271 i=ASN1_R_BAD_OBJECT_HEADER;
272 goto err;
273 }
274
275 if (tag != V_ASN1_INTEGER)
276 {
277 i=ASN1_R_EXPECTING_AN_INTEGER;
278 goto err;
279 }
280
281 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it
282 * signifies a missing NULL parameter. */
283 s=(unsigned char *)OPENSSL_malloc((int)len+1);
284 if (s == NULL)
285 {
286 i=ERR_R_MALLOC_FAILURE;
287 goto err;
288 }
289 to=s;
290 ret->type=V_ASN1_INTEGER;
291 if(len) {
292 if ((*p == 0) && (len != 1))
293 {
294 p++;
295 len--;
296 }
297 memcpy(s,p,(int)len);
298 p+=len;
299 }
300
301 if (ret->data != NULL) OPENSSL_free(ret->data);
302 ret->data=s;
303 ret->length=(int)len;
304 if (a != NULL) (*a)=ret;
305 *pp=p;
306 return(ret);
307err:
308 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
309 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
310 M_ASN1_INTEGER_free(ret);
311 return(NULL);
312 }
313
314int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
315 {
316 int i,j,k;
317 unsigned char buf[sizeof(long)+1];
318 long d;
319
320 a->type=V_ASN1_INTEGER;
321 if (a->length < (sizeof(long)+1))
322 {
323 if (a->data != NULL)
324 OPENSSL_free(a->data);
325 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL)
326 memset((char *)a->data,0,sizeof(long)+1);
327 }
328 if (a->data == NULL)
329 {
330 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
331 return(0);
332 }
333 d=v;
334 if (d < 0)
335 {
336 d= -d;
337 a->type=V_ASN1_NEG_INTEGER;
338 }
339
340 for (i=0; i<sizeof(long); i++)
341 {
342 if (d == 0) break;
343 buf[i]=(int)d&0xff;
344 d>>=8;
345 }
346 j=0;
347 for (k=i-1; k >=0; k--)
348 a->data[j++]=buf[k];
349 a->length=j;
350 return(1);
351 }
352
353long ASN1_INTEGER_get(ASN1_INTEGER *a)
354 {
355 int neg=0,i;
356 long r=0;
357
358 if (a == NULL) return(0L);
359 i=a->type;
360 if (i == V_ASN1_NEG_INTEGER)
361 neg=1;
362 else if (i != V_ASN1_INTEGER)
363 return -1;
364
365 if (a->length > sizeof(long))
366 {
367 /* hmm... a bit ugly */
368 return(0xffffffffL);
369 }
370 if (a->data == NULL)
371 return 0;
372
373 for (i=0; i<a->length; i++)
374 {
375 r<<=8;
376 r|=(unsigned char)a->data[i];
377 }
378 if (neg) r= -r;
379 return(r);
380 }
381
382ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
383 {
384 ASN1_INTEGER *ret;
385 int len,j;
386
387 if (ai == NULL)
388 ret=M_ASN1_INTEGER_new();
389 else
390 ret=ai;
391 if (ret == NULL)
392 {
393 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
394 goto err;
395 }
396 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
397 else ret->type=V_ASN1_INTEGER;
398 j=BN_num_bits(bn);
399 len=((j == 0)?0:((j/8)+1));
400 if (ret->length < len+4)
401 {
402 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
403 if (!new_data)
404 {
405 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
406 goto err;
407 }
408 ret->data=new_data;
409 }
410 ret->length=BN_bn2bin(bn,ret->data);
411 /* Correct zero case */
412 if(!ret->length)
413 {
414 ret->data[0] = 0;
415 ret->length = 1;
416 }
417 return(ret);
418err:
419 if (ret != ai) M_ASN1_INTEGER_free(ret);
420 return(NULL);
421 }
422
423BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
424 {
425 BIGNUM *ret;
426
427 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
428 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
429 else if(ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1;
430 return(ret);
431 }
432
433IMPLEMENT_STACK_OF(ASN1_INTEGER)
434IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER)
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
new file mode 100644
index 0000000000..58b437bc84
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -0,0 +1,400 @@
1/* a_mbstr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63
64static int traverse_string(const unsigned char *p, int len, int inform,
65 int (*rfunc)(unsigned long value, void *in), void *arg);
66static int in_utf8(unsigned long value, void *arg);
67static int out_utf8(unsigned long value, void *arg);
68static int type_str(unsigned long value, void *arg);
69static int cpy_asc(unsigned long value, void *arg);
70static int cpy_bmp(unsigned long value, void *arg);
71static int cpy_univ(unsigned long value, void *arg);
72static int cpy_utf8(unsigned long value, void *arg);
73static int is_printable(unsigned long value);
74
75/* These functions take a string in UTF8, ASCII or multibyte form and
76 * a mask of permissible ASN1 string types. It then works out the minimal
77 * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8)
78 * and creates a string of the correct type with the supplied data.
79 * Yes this is horrible: it has to be :-(
80 * The 'ncopy' form checks minimum and maximum size limits too.
81 */
82
83int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
84 int inform, unsigned long mask)
85{
86 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
87}
88
89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
90 int inform, unsigned long mask,
91 long minsize, long maxsize)
92{
93 int str_type;
94 int ret;
95 char free_out;
96 int outform, outlen;
97 ASN1_STRING *dest;
98 unsigned char *p;
99 int nchar;
100 char strbuf[32];
101 int (*cpyfunc)(unsigned long,void *) = NULL;
102 if(len == -1) len = strlen((const char *)in);
103 if(!mask) mask = DIRSTRING_TYPE;
104
105 /* First do a string check and work out the number of characters */
106 switch(inform) {
107
108 case MBSTRING_BMP:
109 if(len & 1) {
110 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
111 ASN1_R_INVALID_BMPSTRING_LENGTH);
112 return -1;
113 }
114 nchar = len >> 1;
115 break;
116
117 case MBSTRING_UNIV:
118 if(len & 3) {
119 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
120 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
121 return -1;
122 }
123 nchar = len >> 2;
124 break;
125
126 case MBSTRING_UTF8:
127 nchar = 0;
128 /* This counts the characters and does utf8 syntax checking */
129 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
130 if(ret < 0) {
131 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
132 ASN1_R_INVALID_UTF8STRING);
133 return -1;
134 }
135 break;
136
137 case MBSTRING_ASC:
138 nchar = len;
139 break;
140
141 default:
142 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
143 return -1;
144 }
145
146 if((minsize > 0) && (nchar < minsize)) {
147 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
148 snprintf(strbuf, sizeof strbuf, "%ld", minsize);
149 ERR_add_error_data(2, "minsize=", strbuf);
150 return -1;
151 }
152
153 if((maxsize > 0) && (nchar > maxsize)) {
154 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
155 snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
156 ERR_add_error_data(2, "maxsize=", strbuf);
157 return -1;
158 }
159
160 /* Now work out minimal type (if any) */
161 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
162 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
163 return -1;
164 }
165
166
167 /* Now work out output format and string type */
168 outform = MBSTRING_ASC;
169 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
170 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
171 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
172 else if(mask & B_ASN1_BMPSTRING) {
173 str_type = V_ASN1_BMPSTRING;
174 outform = MBSTRING_BMP;
175 } else if(mask & B_ASN1_UNIVERSALSTRING) {
176 str_type = V_ASN1_UNIVERSALSTRING;
177 outform = MBSTRING_UNIV;
178 } else {
179 str_type = V_ASN1_UTF8STRING;
180 outform = MBSTRING_UTF8;
181 }
182 if(!out) return str_type;
183 if(*out) {
184 free_out = 0;
185 dest = *out;
186 if(dest->data) {
187 dest->length = 0;
188 OPENSSL_free(dest->data);
189 dest->data = NULL;
190 }
191 dest->type = str_type;
192 } else {
193 free_out = 1;
194 dest = ASN1_STRING_type_new(str_type);
195 if(!dest) {
196 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
197 ERR_R_MALLOC_FAILURE);
198 return -1;
199 }
200 *out = dest;
201 }
202 /* If both the same type just copy across */
203 if(inform == outform) {
204 if(!ASN1_STRING_set(dest, in, len)) {
205 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
206 return -1;
207 }
208 return str_type;
209 }
210
211 /* Work out how much space the destination will need */
212 switch(outform) {
213 case MBSTRING_ASC:
214 outlen = nchar;
215 cpyfunc = cpy_asc;
216 break;
217
218 case MBSTRING_BMP:
219 outlen = nchar << 1;
220 cpyfunc = cpy_bmp;
221 break;
222
223 case MBSTRING_UNIV:
224 outlen = nchar << 2;
225 cpyfunc = cpy_univ;
226 break;
227
228 case MBSTRING_UTF8:
229 outlen = 0;
230 traverse_string(in, len, inform, out_utf8, &outlen);
231 cpyfunc = cpy_utf8;
232 break;
233 }
234 if(!(p = OPENSSL_malloc(outlen + 1))) {
235 if(free_out) ASN1_STRING_free(dest);
236 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
237 return -1;
238 }
239 dest->length = outlen;
240 dest->data = p;
241 p[outlen] = 0;
242 traverse_string(in, len, inform, cpyfunc, &p);
243 return str_type;
244}
245
246/* This function traverses a string and passes the value of each character
247 * to an optional function along with a void * argument.
248 */
249
250static int traverse_string(const unsigned char *p, int len, int inform,
251 int (*rfunc)(unsigned long value, void *in), void *arg)
252{
253 unsigned long value;
254 int ret;
255 while(len) {
256 if(inform == MBSTRING_ASC) {
257 value = *p++;
258 len--;
259 } else if(inform == MBSTRING_BMP) {
260 value = *p++ << 8;
261 value |= *p++;
262 len -= 2;
263 } else if(inform == MBSTRING_UNIV) {
264 value = ((unsigned long)*p++) << 24;
265 value |= ((unsigned long)*p++) << 16;
266 value |= *p++ << 8;
267 value |= *p++;
268 len -= 4;
269 } else {
270 ret = UTF8_getc(p, len, &value);
271 if(ret < 0) return -1;
272 len -= ret;
273 p += ret;
274 }
275 if(rfunc) {
276 ret = rfunc(value, arg);
277 if(ret <= 0) return ret;
278 }
279 }
280 return 1;
281}
282
283/* Various utility functions for traverse_string */
284
285/* Just count number of characters */
286
287static int in_utf8(unsigned long value, void *arg)
288{
289 int *nchar;
290 nchar = arg;
291 (*nchar)++;
292 return 1;
293}
294
295/* Determine size of output as a UTF8 String */
296
297static int out_utf8(unsigned long value, void *arg)
298{
299 long *outlen;
300 outlen = arg;
301 *outlen += UTF8_putc(NULL, -1, value);
302 return 1;
303}
304
305/* Determine the "type" of a string: check each character against a
306 * supplied "mask".
307 */
308
309static int type_str(unsigned long value, void *arg)
310{
311 unsigned long types;
312 types = *((unsigned long *)arg);
313 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
314 types &= ~B_ASN1_PRINTABLESTRING;
315 if((types & B_ASN1_IA5STRING) && (value > 127))
316 types &= ~B_ASN1_IA5STRING;
317 if((types & B_ASN1_T61STRING) && (value > 0xff))
318 types &= ~B_ASN1_T61STRING;
319 if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
320 types &= ~B_ASN1_BMPSTRING;
321 if(!types) return -1;
322 *((unsigned long *)arg) = types;
323 return 1;
324}
325
326/* Copy one byte per character ASCII like strings */
327
328static int cpy_asc(unsigned long value, void *arg)
329{
330 unsigned char **p, *q;
331 p = arg;
332 q = *p;
333 *q = (unsigned char) value;
334 (*p)++;
335 return 1;
336}
337
338/* Copy two byte per character BMPStrings */
339
340static int cpy_bmp(unsigned long value, void *arg)
341{
342 unsigned char **p, *q;
343 p = arg;
344 q = *p;
345 *q++ = (unsigned char) ((value >> 8) & 0xff);
346 *q = (unsigned char) (value & 0xff);
347 *p += 2;
348 return 1;
349}
350
351/* Copy four byte per character UniversalStrings */
352
353static int cpy_univ(unsigned long value, void *arg)
354{
355 unsigned char **p, *q;
356 p = arg;
357 q = *p;
358 *q++ = (unsigned char) ((value >> 24) & 0xff);
359 *q++ = (unsigned char) ((value >> 16) & 0xff);
360 *q++ = (unsigned char) ((value >> 8) & 0xff);
361 *q = (unsigned char) (value & 0xff);
362 *p += 4;
363 return 1;
364}
365
366/* Copy to a UTF8String */
367
368static int cpy_utf8(unsigned long value, void *arg)
369{
370 unsigned char **p;
371 int ret;
372 p = arg;
373 /* We already know there is enough room so pass 0xff as the length */
374 ret = UTF8_putc(*p, 0xff, value);
375 *p += ret;
376 return 1;
377}
378
379/* Return 1 if the character is permitted in a PrintableString */
380static int is_printable(unsigned long value)
381{
382 int ch;
383 if(value > 0x7f) return 0;
384 ch = (int) value;
385 /* Note: we can't use 'isalnum' because certain accented
386 * characters may count as alphanumeric in some environments.
387 */
388#ifndef CHARSET_EBCDIC
389 if((ch >= 'a') && (ch <= 'z')) return 1;
390 if((ch >= 'A') && (ch <= 'Z')) return 1;
391 if((ch >= '0') && (ch <= '9')) return 1;
392 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
393#else /*CHARSET_EBCDIC*/
394 if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1;
395 if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1;
396 if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1;
397 if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1;
398#endif /*CHARSET_EBCDIC*/
399 return 0;
400}
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
new file mode 100644
index 0000000000..71ce7c3896
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -0,0 +1,320 @@
1/* crypto/asn1/a_object.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
66 {
67 unsigned char *p;
68 int objsize;
69
70 if ((a == NULL) || (a->data == NULL)) return(0);
71
72 objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT);
73 if (pp == NULL) return objsize;
74
75 p= *pp;
76 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
77 memcpy(p,a->data,a->length);
78 p+=a->length;
79
80 *pp=p;
81 return(objsize);
82 }
83
84int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
85 {
86 int i,first,len=0,c;
87 char tmp[24];
88 const char *p;
89 unsigned long l;
90
91 if (num == 0)
92 return(0);
93 else if (num == -1)
94 num=strlen(buf);
95
96 p=buf;
97 c= *(p++);
98 num--;
99 if ((c >= '0') && (c <= '2'))
100 {
101 first=(c-'0')*40;
102 }
103 else
104 {
105 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
106 goto err;
107 }
108
109 if (num <= 0)
110 {
111 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
112 goto err;
113 }
114 c= *(p++);
115 num--;
116 for (;;)
117 {
118 if (num <= 0) break;
119 if ((c != '.') && (c != ' '))
120 {
121 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
122 goto err;
123 }
124 l=0;
125 for (;;)
126 {
127 if (num <= 0) break;
128 num--;
129 c= *(p++);
130 if ((c == ' ') || (c == '.'))
131 break;
132 if ((c < '0') || (c > '9'))
133 {
134 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
135 goto err;
136 }
137 l=l*10L+(long)(c-'0');
138 }
139 if (len == 0)
140 {
141 if ((first < 2) && (l >= 40))
142 {
143 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
144 goto err;
145 }
146 l+=(long)first;
147 }
148 i=0;
149 for (;;)
150 {
151 tmp[i++]=(unsigned char)l&0x7f;
152 l>>=7L;
153 if (l == 0L) break;
154 }
155 if (out != NULL)
156 {
157 if (len+i > olen)
158 {
159 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
160 goto err;
161 }
162 while (--i > 0)
163 out[len++]=tmp[i]|0x80;
164 out[len++]=tmp[0];
165 }
166 else
167 len+=i;
168 }
169 return(len);
170err:
171 return(0);
172 }
173
174int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
175{
176 return OBJ_obj2txt(buf, buf_len, a, 0);
177}
178
179int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
180 {
181 char buf[80];
182 int i;
183
184 if ((a == NULL) || (a->data == NULL))
185 return(BIO_write(bp,"NULL",4));
186 i=i2t_ASN1_OBJECT(buf,80,a);
187 if (i > 80) i=80;
188 BIO_write(bp,buf,i);
189 return(i);
190 }
191
192ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
193 long length)
194{
195 unsigned char *p;
196 long len;
197 int tag,xclass;
198 int inf,i;
199 ASN1_OBJECT *ret = NULL;
200 p= *pp;
201 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
202 if (inf & 0x80)
203 {
204 i=ASN1_R_BAD_OBJECT_HEADER;
205 goto err;
206 }
207
208 if (tag != V_ASN1_OBJECT)
209 {
210 i=ASN1_R_EXPECTING_AN_OBJECT;
211 goto err;
212 }
213 ret = c2i_ASN1_OBJECT(a, &p, len);
214 if(ret) *pp = p;
215 return ret;
216err:
217 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
218 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
219 ASN1_OBJECT_free(ret);
220 return(NULL);
221}
222ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
223 long len)
224 {
225 ASN1_OBJECT *ret=NULL;
226 unsigned char *p;
227 int i;
228
229 /* only the ASN1_OBJECTs from the 'table' will have values
230 * for ->sn or ->ln */
231 if ((a == NULL) || ((*a) == NULL) ||
232 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
233 {
234 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
235 }
236 else ret=(*a);
237
238 p= *pp;
239 if ((ret->data == NULL) || (ret->length < len))
240 {
241 if (ret->data != NULL) OPENSSL_free(ret->data);
242 ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1);
243 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
244 if (ret->data == NULL)
245 { i=ERR_R_MALLOC_FAILURE; goto err; }
246 }
247 memcpy(ret->data,p,(int)len);
248 ret->length=(int)len;
249 ret->sn=NULL;
250 ret->ln=NULL;
251 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
252 p+=len;
253
254 if (a != NULL) (*a)=ret;
255 *pp=p;
256 return(ret);
257err:
258 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
260 ASN1_OBJECT_free(ret);
261 return(NULL);
262 }
263
264ASN1_OBJECT *ASN1_OBJECT_new(void)
265 {
266 ASN1_OBJECT *ret;
267
268 ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT));
269 if (ret == NULL)
270 {
271 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
272 return(NULL);
273 }
274 ret->length=0;
275 ret->data=NULL;
276 ret->nid=0;
277 ret->sn=NULL;
278 ret->ln=NULL;
279 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
280 return(ret);
281 }
282
283void ASN1_OBJECT_free(ASN1_OBJECT *a)
284 {
285 if (a == NULL) return;
286 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
287 {
288#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
289 if (a->sn != NULL) OPENSSL_free((void *)a->sn);
290 if (a->ln != NULL) OPENSSL_free((void *)a->ln);
291#endif
292 a->sn=a->ln=NULL;
293 }
294 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
295 {
296 if (a->data != NULL) OPENSSL_free(a->data);
297 a->data=NULL;
298 a->length=0;
299 }
300 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
301 OPENSSL_free(a);
302 }
303
304ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
305 const char *sn, const char *ln)
306 {
307 ASN1_OBJECT o;
308
309 o.sn=sn;
310 o.ln=ln;
311 o.data=data;
312 o.nid=nid;
313 o.length=len;
314 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
315 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
316 return(OBJ_dup(&o));
317 }
318
319IMPLEMENT_STACK_OF(ASN1_OBJECT)
320IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT)
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c
new file mode 100644
index 0000000000..9690bae0f1
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_octet.c
@@ -0,0 +1,71 @@
1/* crypto/asn1/a_octet.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x)
64{ return M_ASN1_OCTET_STRING_dup(x); }
65
66int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
67{ return M_ASN1_OCTET_STRING_cmp(a, b); }
68
69int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)
70{ return M_ASN1_OCTET_STRING_set(x, d, len); }
71
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
new file mode 100644
index 0000000000..8035513f04
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_print.c
@@ -0,0 +1,127 @@
1/* crypto/asn1/a_print.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int ASN1_PRINTABLE_type(unsigned char *s, int len)
64 {
65 int c;
66 int ia5=0;
67 int t61=0;
68
69 if (len <= 0) len= -1;
70 if (s == NULL) return(V_ASN1_PRINTABLESTRING);
71
72 while ((*s) && (len-- != 0))
73 {
74 c= *(s++);
75#ifndef CHARSET_EBCDIC
76 if (!( ((c >= 'a') && (c <= 'z')) ||
77 ((c >= 'A') && (c <= 'Z')) ||
78 (c == ' ') ||
79 ((c >= '0') && (c <= '9')) ||
80 (c == ' ') || (c == '\'') ||
81 (c == '(') || (c == ')') ||
82 (c == '+') || (c == ',') ||
83 (c == '-') || (c == '.') ||
84 (c == '/') || (c == ':') ||
85 (c == '=') || (c == '?')))
86 ia5=1;
87 if (c&0x80)
88 t61=1;
89#else
90 if (!isalnum(c) && (c != ' ') &&
91 strchr("'()+,-./:=?", c) == NULL)
92 ia5=1;
93 if (os_toascii[c] & 0x80)
94 t61=1;
95#endif
96 }
97 if (t61) return(V_ASN1_T61STRING);
98 if (ia5) return(V_ASN1_IA5STRING);
99 return(V_ASN1_PRINTABLESTRING);
100 }
101
102int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
103 {
104 int i;
105 unsigned char *p;
106
107 if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
108 if ((s->length%4) != 0) return(0);
109 p=s->data;
110 for (i=0; i<s->length; i+=4)
111 {
112 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
113 break;
114 else
115 p+=4;
116 }
117 if (i < s->length) return(0);
118 p=s->data;
119 for (i=3; i<s->length; i+=4)
120 {
121 *(p++)=s->data[i];
122 }
123 *(p)='\0';
124 s->length/=4;
125 s->type=ASN1_PRINTABLE_type(s->data,s->length);
126 return(1);
127 }
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
new file mode 100644
index 0000000000..0f839822ff
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_set.c
@@ -0,0 +1,220 @@
1/* crypto/asn1/a_set.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62
63#ifndef NO_ASN1_OLD
64
65typedef struct
66 {
67 unsigned char *pbData;
68 int cbData;
69 } MYBLOB;
70
71/* SetBlobCmp
72 * This function compares two elements of SET_OF block
73 */
74static int SetBlobCmp(const void *elem1, const void *elem2 )
75 {
76 const MYBLOB *b1 = (const MYBLOB *)elem1;
77 const MYBLOB *b2 = (const MYBLOB *)elem2;
78 int r;
79
80 r = memcmp(b1->pbData, b2->pbData,
81 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
82 if(r != 0)
83 return r;
84 return b1->cbData-b2->cbData;
85 }
86
87/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
88int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
89 int ex_class, int is_set)
90 {
91 int ret=0,r;
92 int i;
93 unsigned char *p;
94 unsigned char *pStart, *pTempMem;
95 MYBLOB *rgSetBlob;
96 int totSize;
97
98 if (a == NULL) return(0);
99 for (i=sk_num(a)-1; i>=0; i--)
100 ret+=func(sk_value(a,i),NULL);
101 r=ASN1_object_size(1,ret,ex_tag);
102 if (pp == NULL) return(r);
103
104 p= *pp;
105 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
106
107/* Modified by gp@nsj.co.jp */
108 /* And then again by Ben */
109 /* And again by Steve */
110
111 if(!is_set || (sk_num(a) < 2))
112 {
113 for (i=0; i<sk_num(a); i++)
114 func(sk_value(a,i),&p);
115
116 *pp=p;
117 return(r);
118 }
119
120 pStart = p; /* Catch the beg of Setblobs*/
121 if (!(rgSetBlob = (MYBLOB *)OPENSSL_malloc( sk_num(a) * sizeof(MYBLOB)))) return 0; /* In this array
122we will store the SET blobs */
123
124 for (i=0; i<sk_num(a); i++)
125 {
126 rgSetBlob[i].pbData = p; /* catch each set encode blob */
127 func(sk_value(a,i),&p);
128 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
129SetBlob
130*/
131 }
132 *pp=p;
133 totSize = p - pStart; /* This is the total size of all set blobs */
134
135 /* Now we have to sort the blobs. I am using a simple algo.
136 *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
137 qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
138 if (!(pTempMem = OPENSSL_malloc(totSize))) return 0;
139
140/* Copy to temp mem */
141 p = pTempMem;
142 for(i=0; i<sk_num(a); ++i)
143 {
144 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
145 p += rgSetBlob[i].cbData;
146 }
147
148/* Copy back to user mem*/
149 memcpy(pStart, pTempMem, totSize);
150 OPENSSL_free(pTempMem);
151 OPENSSL_free(rgSetBlob);
152
153 return(r);
154 }
155
156STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
157 char *(*func)(), void (*free_func)(void *), int ex_tag, int ex_class)
158 {
159 ASN1_CTX c;
160 STACK *ret=NULL;
161
162 if ((a == NULL) || ((*a) == NULL))
163 { if ((ret=sk_new_null()) == NULL) goto err; }
164 else
165 ret=(*a);
166
167 c.p= *pp;
168 c.max=(length == 0)?0:(c.p+length);
169
170 c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);
171 if (c.inf & 0x80) goto err;
172 if (ex_class != c.xclass)
173 {
174 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
175 goto err;
176 }
177 if (ex_tag != c.tag)
178 {
179 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
180 goto err;
181 }
182 if ((c.slen+c.p) > c.max)
183 {
184 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
185 goto err;
186 }
187 /* check for infinite constructed - it can be as long
188 * as the amount of data passed to us */
189 if (c.inf == (V_ASN1_CONSTRUCTED+1))
190 c.slen=length+ *pp-c.p;
191 c.max=c.p+c.slen;
192
193 while (c.p < c.max)
194 {
195 char *s;
196
197 if (M_ASN1_D2I_end_sequence()) break;
198 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
199 {
200 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
201 asn1_add_error(*pp,(int)(c.q- *pp));
202 goto err;
203 }
204 if (!sk_push(ret,s)) goto err;
205 }
206 if (a != NULL) (*a)=ret;
207 *pp=c.p;
208 return(ret);
209err:
210 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
211 {
212 if (free_func != NULL)
213 sk_pop_free(ret,free_func);
214 else
215 sk_free(ret);
216 }
217 return(NULL);
218 }
219
220#endif
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
new file mode 100644
index 0000000000..de53b44144
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -0,0 +1,294 @@
1/* crypto/asn1/a_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <time.h>
114
115#include "cryptlib.h"
116
117#ifndef NO_SYS_TYPES_H
118# include <sys/types.h>
119#endif
120
121#include <openssl/bn.h>
122#include <openssl/evp.h>
123#include <openssl/x509.h>
124#include <openssl/objects.h>
125#include <openssl/buffer.h>
126
127#ifndef NO_ASN1_OLD
128
129int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
130 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
131 const EVP_MD *type)
132 {
133 EVP_MD_CTX ctx;
134 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
135 int i,inl=0,outl=0,outll=0;
136 X509_ALGOR *a;
137
138 EVP_MD_CTX_init(&ctx);
139 for (i=0; i<2; i++)
140 {
141 if (i == 0)
142 a=algor1;
143 else
144 a=algor2;
145 if (a == NULL) continue;
146 if (type->pkey_type == NID_dsaWithSHA1)
147 {
148 /* special case: RFC 2459 tells us to omit 'parameters'
149 * with id-dsa-with-sha1 */
150 ASN1_TYPE_free(a->parameter);
151 a->parameter = NULL;
152 }
153 else if ((a->parameter == NULL) ||
154 (a->parameter->type != V_ASN1_NULL))
155 {
156 ASN1_TYPE_free(a->parameter);
157 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
158 a->parameter->type=V_ASN1_NULL;
159 }
160 ASN1_OBJECT_free(a->algorithm);
161 a->algorithm=OBJ_nid2obj(type->pkey_type);
162 if (a->algorithm == NULL)
163 {
164 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
165 goto err;
166 }
167 if (a->algorithm->length == 0)
168 {
169 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
170 goto err;
171 }
172 }
173 inl=i2d(data,NULL);
174 buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl);
175 outll=outl=EVP_PKEY_size(pkey);
176 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
177 if ((buf_in == NULL) || (buf_out == NULL))
178 {
179 outl=0;
180 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
181 goto err;
182 }
183 p=buf_in;
184
185 i2d(data,&p);
186 EVP_SignInit_ex(&ctx,type, NULL);
187 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
188 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
189 (unsigned int *)&outl,pkey))
190 {
191 outl=0;
192 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
193 goto err;
194 }
195 if (signature->data != NULL) OPENSSL_free(signature->data);
196 signature->data=buf_out;
197 buf_out=NULL;
198 signature->length=outl;
199 /* In the interests of compatibility, I'll make sure that
200 * the bit string has a 'not-used bits' value of 0
201 */
202 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
203 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
204err:
205 EVP_MD_CTX_cleanup(&ctx);
206 if (buf_in != NULL)
207 { memset((char *)buf_in,0,(unsigned int)inl); OPENSSL_free(buf_in); }
208 if (buf_out != NULL)
209 { memset((char *)buf_out,0,outll); OPENSSL_free(buf_out); }
210 return(outl);
211 }
212
213#endif
214
215int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
216 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey,
217 const EVP_MD *type)
218 {
219 EVP_MD_CTX ctx;
220 unsigned char *buf_in=NULL,*buf_out=NULL;
221 int i,inl=0,outl=0,outll=0;
222 X509_ALGOR *a;
223
224 EVP_MD_CTX_init(&ctx);
225 for (i=0; i<2; i++)
226 {
227 if (i == 0)
228 a=algor1;
229 else
230 a=algor2;
231 if (a == NULL) continue;
232 if (type->pkey_type == NID_dsaWithSHA1)
233 {
234 /* special case: RFC 2459 tells us to omit 'parameters'
235 * with id-dsa-with-sha1 */
236 ASN1_TYPE_free(a->parameter);
237 a->parameter = NULL;
238 }
239 else if ((a->parameter == NULL) ||
240 (a->parameter->type != V_ASN1_NULL))
241 {
242 ASN1_TYPE_free(a->parameter);
243 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
244 a->parameter->type=V_ASN1_NULL;
245 }
246 ASN1_OBJECT_free(a->algorithm);
247 a->algorithm=OBJ_nid2obj(type->pkey_type);
248 if (a->algorithm == NULL)
249 {
250 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
251 goto err;
252 }
253 if (a->algorithm->length == 0)
254 {
255 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
256 goto err;
257 }
258 }
259 inl=ASN1_item_i2d(asn,&buf_in, it);
260 outll=outl=EVP_PKEY_size(pkey);
261 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
262 if ((buf_in == NULL) || (buf_out == NULL))
263 {
264 outl=0;
265 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
266 goto err;
267 }
268
269 EVP_SignInit_ex(&ctx,type, NULL);
270 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
271 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
272 (unsigned int *)&outl,pkey))
273 {
274 outl=0;
275 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
276 goto err;
277 }
278 if (signature->data != NULL) OPENSSL_free(signature->data);
279 signature->data=buf_out;
280 buf_out=NULL;
281 signature->length=outl;
282 /* In the interests of compatibility, I'll make sure that
283 * the bit string has a 'not-used bits' value of 0
284 */
285 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
286 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
287err:
288 EVP_MD_CTX_cleanup(&ctx);
289 if (buf_in != NULL)
290 { memset((char *)buf_in,0,(unsigned int)inl); OPENSSL_free(buf_in); }
291 if (buf_out != NULL)
292 { memset((char *)buf_out,0,outll); OPENSSL_free(buf_out); }
293 return(outl);
294 }
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
new file mode 100644
index 0000000000..7ddb7662f1
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -0,0 +1,558 @@
1/* a_strex.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 <stdio.h>
60#include <string.h>
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63#include <openssl/asn1.h>
64
65#include "charmap.h"
66
67/* ASN1_STRING_print_ex() and X509_NAME_print_ex().
68 * Enhanced string and name printing routines handling
69 * multibyte characters, RFC2253 and a host of other
70 * options.
71 */
72
73
74#define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253)
75
76
77/* Three IO functions for sending data to memory, a BIO and
78 * and a FILE pointer.
79 */
80#if 0 /* never used */
81static int send_mem_chars(void *arg, const void *buf, int len)
82{
83 unsigned char **out = arg;
84 if(!out) return 1;
85 memcpy(*out, buf, len);
86 *out += len;
87 return 1;
88}
89#endif
90
91static int send_bio_chars(void *arg, const void *buf, int len)
92{
93 if(!arg) return 1;
94 if(BIO_write(arg, buf, len) != len) return 0;
95 return 1;
96}
97
98static int send_fp_chars(void *arg, const void *buf, int len)
99{
100 if(!arg) return 1;
101 if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0;
102 return 1;
103}
104
105typedef int char_io(void *arg, const void *buf, int len);
106
107/* This function handles display of
108 * strings, one character at a time.
109 * It is passed an unsigned long for each
110 * character because it could come from 2 or even
111 * 4 byte forms.
112 */
113
114static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg)
115{
116 unsigned char chflgs, chtmp;
117 char tmphex[11];
118 if(c > 0xffff) {
119 BIO_snprintf(tmphex, 11, "\\W%08lX", c);
120 if(!io_ch(arg, tmphex, 10)) return -1;
121 return 10;
122 }
123 if(c > 0xff) {
124 BIO_snprintf(tmphex, 11, "\\U%04lX", c);
125 if(!io_ch(arg, tmphex, 6)) return -1;
126 return 6;
127 }
128 chtmp = (unsigned char)c;
129 if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB;
130 else chflgs = char_type[chtmp] & flags;
131 if(chflgs & CHARTYPE_BS_ESC) {
132 /* If we don't escape with quotes, signal we need quotes */
133 if(chflgs & ASN1_STRFLGS_ESC_QUOTE) {
134 if(do_quotes) *do_quotes = 1;
135 if(!io_ch(arg, &chtmp, 1)) return -1;
136 return 1;
137 }
138 if(!io_ch(arg, "\\", 1)) return -1;
139 if(!io_ch(arg, &chtmp, 1)) return -1;
140 return 2;
141 }
142 if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) {
143 BIO_snprintf(tmphex, 11, "\\%02X", chtmp);
144 if(!io_ch(arg, tmphex, 3)) return -1;
145 return 3;
146 }
147 if(!io_ch(arg, &chtmp, 1)) return -1;
148 return 1;
149}
150
151#define BUF_TYPE_WIDTH_MASK 0x7
152#define BUF_TYPE_CONVUTF8 0x8
153
154/* This function sends each character in a buffer to
155 * do_esc_char(). It interprets the content formats
156 * and converts to or from UTF8 as appropriate.
157 */
158
159static int do_buf(unsigned char *buf, int buflen,
160 int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg)
161{
162 int i, outlen, len;
163 unsigned char orflags, *p, *q;
164 unsigned long c;
165 p = buf;
166 q = buf + buflen;
167 outlen = 0;
168 while(p != q) {
169 if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
170 else orflags = 0;
171 switch(type & BUF_TYPE_WIDTH_MASK) {
172 case 4:
173 c = ((unsigned long)*p++) << 24;
174 c |= ((unsigned long)*p++) << 16;
175 c |= ((unsigned long)*p++) << 8;
176 c |= *p++;
177 break;
178
179 case 2:
180 c = ((unsigned long)*p++) << 8;
181 c |= *p++;
182 break;
183
184 case 1:
185 c = *p++;
186 break;
187
188 case 0:
189 i = UTF8_getc(p, buflen, &c);
190 if(i < 0) return -1; /* Invalid UTF8String */
191 p += i;
192 break;
193 }
194 if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
195 if(type & BUF_TYPE_CONVUTF8) {
196 unsigned char utfbuf[6];
197 int utflen;
198 utflen = UTF8_putc(utfbuf, 6, c);
199 for(i = 0; i < utflen; i++) {
200 /* We don't need to worry about setting orflags correctly
201 * because if utflen==1 its value will be correct anyway
202 * otherwise each character will be > 0x7f and so the
203 * character will never be escaped on first and last.
204 */
205 len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg);
206 if(len < 0) return -1;
207 outlen += len;
208 }
209 } else {
210 len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg);
211 if(len < 0) return -1;
212 outlen += len;
213 }
214 }
215 return outlen;
216}
217
218/* This function hex dumps a buffer of characters */
219
220static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
221{
222 const static char hexdig[] = "0123456789ABCDEF";
223 unsigned char *p, *q;
224 char hextmp[2];
225 if(arg) {
226 p = buf;
227 q = buf + buflen;
228 while(p != q) {
229 hextmp[0] = hexdig[*p >> 4];
230 hextmp[1] = hexdig[*p & 0xf];
231 if(!io_ch(arg, hextmp, 2)) return -1;
232 p++;
233 }
234 }
235 return buflen << 1;
236}
237
238/* "dump" a string. This is done when the type is unknown,
239 * or the flags request it. We can either dump the content
240 * octets or the entire DER encoding. This uses the RFC2253
241 * #01234 format.
242 */
243
244static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str)
245{
246 /* Placing the ASN1_STRING in a temp ASN1_TYPE allows
247 * the DER encoding to readily obtained
248 */
249 ASN1_TYPE t;
250 unsigned char *der_buf, *p;
251 int outlen, der_len;
252
253 if(!io_ch(arg, "#", 1)) return -1;
254 /* If we don't dump DER encoding just dump content octets */
255 if(!(lflags & ASN1_STRFLGS_DUMP_DER)) {
256 outlen = do_hex_dump(io_ch, arg, str->data, str->length);
257 if(outlen < 0) return -1;
258 return outlen + 1;
259 }
260 t.type = str->type;
261 t.value.ptr = (char *)str;
262 der_len = i2d_ASN1_TYPE(&t, NULL);
263 der_buf = OPENSSL_malloc(der_len);
264 if(!der_buf) return -1;
265 p = der_buf;
266 i2d_ASN1_TYPE(&t, &p);
267 outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
268 OPENSSL_free(der_buf);
269 if(outlen < 0) return -1;
270 return outlen + 1;
271}
272
273/* Lookup table to convert tags to character widths,
274 * 0 = UTF8 encoded, -1 is used for non string types
275 * otherwise it is the number of bytes per character
276 */
277
278const static char tag2nbyte[] = {
279 -1, -1, -1, -1, -1, /* 0-4 */
280 -1, -1, -1, -1, -1, /* 5-9 */
281 -1, -1, 0, -1, /* 10-13 */
282 -1, -1, -1, -1, /* 15-17 */
283 -1, 1, 1, /* 18-20 */
284 -1, 1, -1,-1, /* 21-24 */
285 -1, 1, -1, /* 25-27 */
286 4, -1, 2 /* 28-30 */
287};
288
289#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
290 ASN1_STRFLGS_ESC_QUOTE | \
291 ASN1_STRFLGS_ESC_CTRL | \
292 ASN1_STRFLGS_ESC_MSB)
293
294/* This is the main function, print out an
295 * ASN1_STRING taking note of various escape
296 * and display options. Returns number of
297 * characters written or -1 if an error
298 * occurred.
299 */
300
301static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str)
302{
303 int outlen, len;
304 int type;
305 char quotes;
306 unsigned char flags;
307 quotes = 0;
308 /* Keep a copy of escape flags */
309 flags = (unsigned char)(lflags & ESC_FLAGS);
310
311 type = str->type;
312
313 outlen = 0;
314
315
316 if(lflags & ASN1_STRFLGS_SHOW_TYPE) {
317 const char *tagname;
318 tagname = ASN1_tag2str(type);
319 outlen += strlen(tagname);
320 if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1;
321 outlen++;
322 }
323
324 /* Decide what to do with type, either dump content or display it */
325
326 /* Dump everything */
327 if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1;
328 /* Ignore the string type */
329 else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1;
330 else {
331 /* Else determine width based on type */
332 if((type > 0) && (type < 31)) type = tag2nbyte[type];
333 else type = -1;
334 if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1;
335 }
336
337 if(type == -1) {
338 len = do_dump(lflags, io_ch, arg, str);
339 if(len < 0) return -1;
340 outlen += len;
341 return outlen;
342 }
343
344 if(lflags & ASN1_STRFLGS_UTF8_CONVERT) {
345 /* Note: if string is UTF8 and we want
346 * to convert to UTF8 then we just interpret
347 * it as 1 byte per character to avoid converting
348 * twice.
349 */
350 if(!type) type = 1;
351 else type |= BUF_TYPE_CONVUTF8;
352 }
353
354 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
355 if(outlen < 0) return -1;
356 outlen += len;
357 if(quotes) outlen += 2;
358 if(!arg) return outlen;
359 if(quotes && !io_ch(arg, "\"", 1)) return -1;
360 do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
361 if(quotes && !io_ch(arg, "\"", 1)) return -1;
362 return outlen;
363}
364
365/* Used for line indenting: print 'indent' spaces */
366
367static int do_indent(char_io *io_ch, void *arg, int indent)
368{
369 int i;
370 for(i = 0; i < indent; i++)
371 if(!io_ch(arg, " ", 1)) return 0;
372 return 1;
373}
374
375#define FN_WIDTH_LN 25
376#define FN_WIDTH_SN 10
377
378static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
379 int indent, unsigned long flags)
380{
381 int i, prev = -1, orflags, cnt;
382 int fn_opt, fn_nid;
383 ASN1_OBJECT *fn;
384 ASN1_STRING *val;
385 X509_NAME_ENTRY *ent;
386 char objtmp[80];
387 const char *objbuf;
388 int outlen, len;
389 char *sep_dn, *sep_mv, *sep_eq;
390 int sep_dn_len, sep_mv_len, sep_eq_len;
391 if(indent < 0) indent = 0;
392 outlen = indent;
393 if(!do_indent(io_ch, arg, indent)) return -1;
394 switch (flags & XN_FLAG_SEP_MASK)
395 {
396 case XN_FLAG_SEP_MULTILINE:
397 sep_dn = "\n";
398 sep_dn_len = 1;
399 sep_mv = " + ";
400 sep_mv_len = 3;
401 break;
402
403 case XN_FLAG_SEP_COMMA_PLUS:
404 sep_dn = ",";
405 sep_dn_len = 1;
406 sep_mv = "+";
407 sep_mv_len = 1;
408 indent = 0;
409 break;
410
411 case XN_FLAG_SEP_CPLUS_SPC:
412 sep_dn = ", ";
413 sep_dn_len = 2;
414 sep_mv = " + ";
415 sep_mv_len = 3;
416 indent = 0;
417 break;
418
419 case XN_FLAG_SEP_SPLUS_SPC:
420 sep_dn = "; ";
421 sep_dn_len = 2;
422 sep_mv = " + ";
423 sep_mv_len = 3;
424 indent = 0;
425 break;
426
427 default:
428 return -1;
429 }
430
431 if(flags & XN_FLAG_SPC_EQ) {
432 sep_eq = " = ";
433 sep_eq_len = 3;
434 } else {
435 sep_eq = "=";
436 sep_eq_len = 1;
437 }
438
439 fn_opt = flags & XN_FLAG_FN_MASK;
440
441 cnt = X509_NAME_entry_count(n);
442 for(i = 0; i < cnt; i++) {
443 if(flags & XN_FLAG_DN_REV)
444 ent = X509_NAME_get_entry(n, cnt - i - 1);
445 else ent = X509_NAME_get_entry(n, i);
446 if(prev != -1) {
447 if(prev == ent->set) {
448 if(!io_ch(arg, sep_mv, sep_mv_len)) return -1;
449 outlen += sep_mv_len;
450 } else {
451 if(!io_ch(arg, sep_dn, sep_dn_len)) return -1;
452 outlen += sep_dn_len;
453 if(!do_indent(io_ch, arg, indent)) return -1;
454 outlen += indent;
455 }
456 }
457 prev = ent->set;
458 fn = X509_NAME_ENTRY_get_object(ent);
459 val = X509_NAME_ENTRY_get_data(ent);
460 fn_nid = OBJ_obj2nid(fn);
461 if(fn_opt != XN_FLAG_FN_NONE) {
462 int objlen, fld_len;
463 if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) {
464 OBJ_obj2txt(objtmp, 80, fn, 1);
465 fld_len = 0; /* XXX: what should this be? */
466 objbuf = objtmp;
467 } else {
468 if(fn_opt == XN_FLAG_FN_SN) {
469 fld_len = FN_WIDTH_SN;
470 objbuf = OBJ_nid2sn(fn_nid);
471 } else if(fn_opt == XN_FLAG_FN_LN) {
472 fld_len = FN_WIDTH_LN;
473 objbuf = OBJ_nid2ln(fn_nid);
474 } else {
475 fld_len = 0; /* XXX: what should this be? */
476 objbuf = "";
477 }
478 }
479 objlen = strlen(objbuf);
480 if(!io_ch(arg, objbuf, objlen)) return -1;
481 if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) {
482 if (!do_indent(io_ch, arg, fld_len - objlen)) return -1;
483 outlen += fld_len - objlen;
484 }
485 if(!io_ch(arg, sep_eq, sep_eq_len)) return -1;
486 outlen += objlen + sep_eq_len;
487 }
488 /* If the field name is unknown then fix up the DER dump
489 * flag. We might want to limit this further so it will
490 * DER dump on anything other than a few 'standard' fields.
491 */
492 if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS))
493 orflags = ASN1_STRFLGS_DUMP_ALL;
494 else orflags = 0;
495
496 len = do_print_ex(io_ch, arg, flags | orflags, val);
497 if(len < 0) return -1;
498 outlen += len;
499 }
500 return outlen;
501}
502
503/* Wrappers round the main functions */
504
505int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
506{
507 if(flags == XN_FLAG_COMPAT)
508 return X509_NAME_print(out, nm, indent);
509 return do_name_ex(send_bio_chars, out, nm, indent, flags);
510}
511
512
513int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
514{
515 if(flags == XN_FLAG_COMPAT)
516 {
517 BIO *btmp;
518 int ret;
519 btmp = BIO_new_fp(fp, BIO_NOCLOSE);
520 if(!btmp) return -1;
521 ret = X509_NAME_print(btmp, nm, indent);
522 BIO_free(btmp);
523 return ret;
524 }
525 return do_name_ex(send_fp_chars, fp, nm, indent, flags);
526}
527
528int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
529{
530 return do_print_ex(send_bio_chars, out, flags, str);
531}
532
533
534int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
535{
536 return do_print_ex(send_fp_chars, fp, flags, str);
537}
538
539/* Utility function: convert any string type to UTF8, returns number of bytes
540 * in output string or a negative error code
541 */
542
543int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
544{
545 ASN1_STRING stmp, *str = &stmp;
546 int mbflag, type, ret;
547 if(!in) return -1;
548 type = in->type;
549 if((type < 0) || (type > 30)) return -1;
550 mbflag = tag2nbyte[type];
551 if(mbflag == -1) return -1;
552 mbflag |= MBSTRING_FLAG;
553 stmp.data = NULL;
554 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
555 if(ret < 0) return ret;
556 *out = stmp.data;
557 return stmp.length;
558}
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
new file mode 100644
index 0000000000..04789d1c63
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_strnid.c
@@ -0,0 +1,252 @@
1/* a_strnid.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65
66static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
67static void st_free(ASN1_STRING_TABLE *tbl);
68static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
69 const ASN1_STRING_TABLE * const *b);
70static int table_cmp(const void *a, const void *b);
71
72
73/* This is the global mask for the mbstring functions: this is use to
74 * mask out certain types (such as BMPString and UTF8String) because
75 * certain software (e.g. Netscape) has problems with them.
76 */
77
78static unsigned long global_mask = 0xFFFFFFFFL;
79
80void ASN1_STRING_set_default_mask(unsigned long mask)
81{
82 global_mask = mask;
83}
84
85unsigned long ASN1_STRING_get_default_mask(void)
86{
87 return global_mask;
88}
89
90/* This function sets the default to various "flavours" of configuration.
91 * based on an ASCII string. Currently this is:
92 * MASK:XXXX : a numerical mask value.
93 * nobmp : Don't use BMPStrings (just Printable, T61).
94 * pkix : PKIX recommendation in RFC2459.
95 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
96 * default: the default value, Printable, T61, BMP.
97 */
98
99int ASN1_STRING_set_default_mask_asc(char *p)
100{
101 unsigned long mask;
102 char *end;
103 if(!strncmp(p, "MASK:", 5)) {
104 if(!p[5]) return 0;
105 mask = strtoul(p + 5, &end, 0);
106 if(*end) return 0;
107 } else if(!strcmp(p, "nombstr"))
108 mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING));
109 else if(!strcmp(p, "pkix"))
110 mask = ~((unsigned long)B_ASN1_T61STRING);
111 else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING;
112 else if(!strcmp(p, "default"))
113 mask = 0xFFFFFFFFL;
114 else return 0;
115 ASN1_STRING_set_default_mask(mask);
116 return 1;
117}
118
119/* The following function generates an ASN1_STRING based on limits in a table.
120 * Frequently the types and length of an ASN1_STRING are restricted by a
121 * corresponding OID. For example certificates and certificate requests.
122 */
123
124ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
125 int inlen, int inform, int nid)
126{
127 ASN1_STRING_TABLE *tbl;
128 ASN1_STRING *str = NULL;
129 unsigned long mask;
130 int ret;
131 if(!out) out = &str;
132 tbl = ASN1_STRING_TABLE_get(nid);
133 if(tbl) {
134 mask = tbl->mask;
135 if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask;
136 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
137 tbl->minsize, tbl->maxsize);
138 } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask);
139 if(ret <= 0) return NULL;
140 return *out;
141}
142
143/* Now the tables and helper functions for the string table:
144 */
145
146/* size limits: this stuff is taken straight from RFC2459 */
147
148#define ub_name 32768
149#define ub_common_name 64
150#define ub_locality_name 128
151#define ub_state_name 128
152#define ub_organization_name 64
153#define ub_organization_unit_name 64
154#define ub_title 64
155#define ub_email_address 128
156
157/* This table must be kept in NID order */
158
159static ASN1_STRING_TABLE tbl_standard[] = {
160{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
161{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
162{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
163{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
164{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
165{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
166{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
167{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
168{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
169{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
170{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
171{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
172{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
173{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
174{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
175{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
176{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}
177};
178
179static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
180 const ASN1_STRING_TABLE * const *b)
181{
182 return (*a)->nid - (*b)->nid;
183}
184
185static int table_cmp(const void *a, const void *b)
186{
187 const ASN1_STRING_TABLE *sa = a, *sb = b;
188 return sa->nid - sb->nid;
189}
190
191ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
192{
193 int idx;
194 ASN1_STRING_TABLE *ttmp;
195 ASN1_STRING_TABLE fnd;
196 fnd.nid = nid;
197 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
198 (char *)tbl_standard,
199 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
200 sizeof(ASN1_STRING_TABLE), table_cmp);
201 if(ttmp) return ttmp;
202 if(!stable) return NULL;
203 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
204 if(idx < 0) return NULL;
205 return sk_ASN1_STRING_TABLE_value(stable, idx);
206}
207
208int ASN1_STRING_TABLE_add(int nid,
209 long minsize, long maxsize, unsigned long mask,
210 unsigned long flags)
211{
212 ASN1_STRING_TABLE *tmp;
213 char new_nid = 0;
214 flags &= ~STABLE_FLAGS_MALLOC;
215 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
216 if(!stable) {
217 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
218 return 0;
219 }
220 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
221 tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
222 if(!tmp) {
223 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
224 ERR_R_MALLOC_FAILURE);
225 return 0;
226 }
227 tmp->flags = flags | STABLE_FLAGS_MALLOC;
228 tmp->nid = nid;
229 new_nid = 1;
230 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
231 if(minsize != -1) tmp->minsize = minsize;
232 if(maxsize != -1) tmp->maxsize = maxsize;
233 tmp->mask = mask;
234 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
235 return 1;
236}
237
238void ASN1_STRING_TABLE_cleanup(void)
239{
240 STACK_OF(ASN1_STRING_TABLE) *tmp;
241 tmp = stable;
242 if(!tmp) return;
243 stable = NULL;
244 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
245}
246
247static void st_free(ASN1_STRING_TABLE *tbl)
248{
249 if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl);
250}
251
252IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
new file mode 100644
index 0000000000..8216783aa8
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_time.c
@@ -0,0 +1,161 @@
1/* crypto/asn1/a_time.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57/* This is an implementation of the ASN1 Time structure which is:
58 * Time ::= CHOICE {
59 * utcTime UTCTime,
60 * generalTime GeneralizedTime }
61 * written by Steve Henson.
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include "cryptlib.h"
67#include "o_time.h"
68#include <openssl/asn1t.h>
69
70IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
71
72IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
73
74#if 0
75int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
76 {
77#ifdef CHARSET_EBCDIC
78 /* KLUDGE! We convert to ascii before writing DER */
79 char tmp[24];
80 ASN1_STRING tmpstr;
81
82 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
83 int len;
84
85 tmpstr = *(ASN1_STRING *)a;
86 len = tmpstr.length;
87 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
88 tmpstr.data = tmp;
89 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
90 }
91#endif
92 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
93 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
94 a->type ,V_ASN1_UNIVERSAL));
95 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
96 return -1;
97 }
98#endif
99
100
101ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
102 {
103 struct tm *ts;
104 struct tm data;
105
106 ts=OPENSSL_gmtime(&t,&data);
107 if (ts == NULL)
108 return NULL;
109 if((ts->tm_year >= 50) && (ts->tm_year < 150))
110 return ASN1_UTCTIME_set(s, t);
111 return ASN1_GENERALIZEDTIME_set(s,t);
112 }
113
114int ASN1_TIME_check(ASN1_TIME *t)
115 {
116 if (t->type == V_ASN1_GENERALIZEDTIME)
117 return ASN1_GENERALIZEDTIME_check(t);
118 else if (t->type == V_ASN1_UTCTIME)
119 return ASN1_UTCTIME_check(t);
120 return 0;
121 }
122
123/* Convert an ASN1_TIME structure to GeneralizedTime */
124ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
125 {
126 ASN1_GENERALIZEDTIME *ret;
127 char *str;
128 int newlen;
129
130 if (!ASN1_TIME_check(t)) return NULL;
131
132 if (!out || !*out)
133 {
134 if (!(ret = ASN1_GENERALIZEDTIME_new ()))
135 return NULL;
136 if (out) *out = ret;
137 }
138 else ret = *out;
139
140 /* If already GeneralizedTime just copy across */
141 if (t->type == V_ASN1_GENERALIZEDTIME)
142 {
143 if(!ASN1_STRING_set(ret, t->data, t->length))
144 return NULL;
145 return ret;
146 }
147
148 /* grow the string */
149 if (!ASN1_STRING_set(ret, NULL, t->length + 2))
150 return NULL;
151 /* ASN1_STRING_set() allocated 'len + 1' bytes. */
152 newlen = t->length + 2 + 1;
153 str = (char *)ret->data;
154 /* Work out the century and prepend */
155 if (t->data[0] >= '5') strlcpy(str, "19", newlen);
156 else strlcpy(str, "20", newlen);
157
158 strlcat(str, (char *)t->data, newlen);
159
160 return ret;
161 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
new file mode 100644
index 0000000000..96e111cf23
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_type.c
@@ -0,0 +1,81 @@
1/* crypto/asn1/a_type.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/asn1t.h>
61#include "cryptlib.h"
62
63int ASN1_TYPE_get(ASN1_TYPE *a)
64 {
65 if (a->value.ptr != NULL)
66 return(a->type);
67 else
68 return(0);
69 }
70
71void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
72 {
73 if (a->value.ptr != NULL)
74 ASN1_primitive_free((ASN1_VALUE **)&a, NULL);
75 a->type=type;
76 a->value.ptr=value;
77 }
78
79
80IMPLEMENT_STACK_OF(ASN1_TYPE)
81IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c
index dbb4a42c9d..41f6d421bb 100644
--- a/src/lib/libcrypto/asn1/a_utctm.c
+++ b/src/lib/libcrypto/asn1/a_utctm.c
@@ -188,6 +188,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
188 char *p; 188 char *p;
189 struct tm *ts; 189 struct tm *ts;
190 struct tm data; 190 struct tm data;
191 size_t len = 20;
191 192
192 if (s == NULL) 193 if (s == NULL)
193 s=M_ASN1_UTCTIME_new(); 194 s=M_ASN1_UTCTIME_new();
@@ -199,17 +200,17 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
199 return(NULL); 200 return(NULL);
200 201
201 p=(char *)s->data; 202 p=(char *)s->data;
202 if ((p == NULL) || (s->length < 14)) 203 if ((p == NULL) || (s->length < len))
203 { 204 {
204 p=OPENSSL_malloc(20); 205 p=OPENSSL_malloc(len);
205 if (p == NULL) return(NULL); 206 if (p == NULL) return(NULL);
206 if (s->data != NULL) 207 if (s->data != NULL)
207 OPENSSL_free(s->data); 208 OPENSSL_free(s->data);
208 s->data=(unsigned char *)p; 209 s->data=(unsigned char *)p;
209 } 210 }
210 211
211 sprintf(p,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, 212 snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100,
212 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); 213 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
213 s->length=strlen(p); 214 s->length=strlen(p);
214 s->type=V_ASN1_UTCTIME; 215 s->type=V_ASN1_UTCTIME;
215#ifdef CHARSET_EBCDIC_not 216#ifdef CHARSET_EBCDIC_not
diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c
new file mode 100644
index 0000000000..508e11e527
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_utf8.c
@@ -0,0 +1,211 @@
1/* crypto/asn1/a_utf8.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63
64/* UTF8 utilities */
65
66/* This parses a UTF8 string one character at a time. It is passed a pointer
67 * to the string and the length of the string. It sets 'value' to the value of
68 * the current character. It returns the number of characters read or a
69 * negative error code:
70 * -1 = string too short
71 * -2 = illegal character
72 * -3 = subsequent characters not of the form 10xxxxxx
73 * -4 = character encoded incorrectly (not minimal length).
74 */
75
76int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
77{
78 const unsigned char *p;
79 unsigned long value;
80 int ret;
81 if(len <= 0) return 0;
82 p = str;
83
84 /* Check syntax and work out the encoded value (if correct) */
85 if((*p & 0x80) == 0) {
86 value = *p++ & 0x7f;
87 ret = 1;
88 } else if((*p & 0xe0) == 0xc0) {
89 if(len < 2) return -1;
90 if((p[1] & 0xc0) != 0x80) return -3;
91 value = (*p++ & 0x1f) << 6;
92 value |= *p++ & 0x3f;
93 if(value < 0x80) return -4;
94 ret = 2;
95 } else if((*p & 0xf0) == 0xe0) {
96 if(len < 3) return -1;
97 if( ((p[1] & 0xc0) != 0x80)
98 || ((p[2] & 0xc0) != 0x80) ) return -3;
99 value = (*p++ & 0xf) << 12;
100 value |= (*p++ & 0x3f) << 6;
101 value |= *p++ & 0x3f;
102 if(value < 0x800) return -4;
103 ret = 3;
104 } else if((*p & 0xf8) == 0xf0) {
105 if(len < 4) return -1;
106 if( ((p[1] & 0xc0) != 0x80)
107 || ((p[2] & 0xc0) != 0x80)
108 || ((p[3] & 0xc0) != 0x80) ) return -3;
109 value = ((unsigned long)(*p++ & 0x7)) << 18;
110 value |= (*p++ & 0x3f) << 12;
111 value |= (*p++ & 0x3f) << 6;
112 value |= *p++ & 0x3f;
113 if(value < 0x10000) return -4;
114 ret = 4;
115 } else if((*p & 0xfc) == 0xf8) {
116 if(len < 5) return -1;
117 if( ((p[1] & 0xc0) != 0x80)
118 || ((p[2] & 0xc0) != 0x80)
119 || ((p[3] & 0xc0) != 0x80)
120 || ((p[4] & 0xc0) != 0x80) ) return -3;
121 value = ((unsigned long)(*p++ & 0x3)) << 24;
122 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
123 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
124 value |= (*p++ & 0x3f) << 6;
125 value |= *p++ & 0x3f;
126 if(value < 0x200000) return -4;
127 ret = 5;
128 } else if((*p & 0xfe) == 0xfc) {
129 if(len < 6) return -1;
130 if( ((p[1] & 0xc0) != 0x80)
131 || ((p[2] & 0xc0) != 0x80)
132 || ((p[3] & 0xc0) != 0x80)
133 || ((p[4] & 0xc0) != 0x80)
134 || ((p[5] & 0xc0) != 0x80) ) return -3;
135 value = ((unsigned long)(*p++ & 0x1)) << 30;
136 value |= ((unsigned long)(*p++ & 0x3f)) << 24;
137 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
138 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
139 value |= (*p++ & 0x3f) << 6;
140 value |= *p++ & 0x3f;
141 if(value < 0x4000000) return -4;
142 ret = 6;
143 } else return -2;
144 *val = value;
145 return ret;
146}
147
148/* This takes a character 'value' and writes the UTF8 encoded value in
149 * 'str' where 'str' is a buffer containing 'len' characters. Returns
150 * the number of characters written or -1 if 'len' is too small. 'str' can
151 * be set to NULL in which case it just returns the number of characters.
152 * It will need at most 6 characters.
153 */
154
155int UTF8_putc(unsigned char *str, int len, unsigned long value)
156{
157 if(!str) len = 6; /* Maximum we will need */
158 else if(len <= 0) return -1;
159 if(value < 0x80) {
160 if(str) *str = (unsigned char)value;
161 return 1;
162 }
163 if(value < 0x800) {
164 if(len < 2) return -1;
165 if(str) {
166 *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);
167 *str = (unsigned char)((value & 0x3f) | 0x80);
168 }
169 return 2;
170 }
171 if(value < 0x10000) {
172 if(len < 3) return -1;
173 if(str) {
174 *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0);
175 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
176 *str = (unsigned char)((value & 0x3f) | 0x80);
177 }
178 return 3;
179 }
180 if(value < 0x200000) {
181 if(len < 4) return -1;
182 if(str) {
183 *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0);
184 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
185 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
186 *str = (unsigned char)((value & 0x3f) | 0x80);
187 }
188 return 4;
189 }
190 if(value < 0x4000000) {
191 if(len < 5) return -1;
192 if(str) {
193 *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8);
194 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
195 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
196 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
197 *str = (unsigned char)((value & 0x3f) | 0x80);
198 }
199 return 5;
200 }
201 if(len < 6) return -1;
202 if(str) {
203 *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc);
204 *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80);
205 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
206 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
207 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
208 *str = (unsigned char)((value & 0x3f) | 0x80);
209 }
210 return 6;
211}
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
new file mode 100644
index 0000000000..bf41de5146
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -0,0 +1,175 @@
1/* crypto/asn1/a_verify.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61
62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
68#include <openssl/bn.h>
69#include <openssl/x509.h>
70#include <openssl/objects.h>
71#include <openssl/buffer.h>
72#include <openssl/evp.h>
73
74#ifndef NO_ASN1_OLD
75
76int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
77 char *data, EVP_PKEY *pkey)
78 {
79 EVP_MD_CTX ctx;
80 const EVP_MD *type;
81 unsigned char *p,*buf_in=NULL;
82 int ret= -1,i,inl;
83
84 EVP_MD_CTX_init(&ctx);
85 i=OBJ_obj2nid(a->algorithm);
86 type=EVP_get_digestbyname(OBJ_nid2sn(i));
87 if (type == NULL)
88 {
89 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
90 goto err;
91 }
92
93 inl=i2d(data,NULL);
94 buf_in=OPENSSL_malloc((unsigned int)inl);
95 if (buf_in == NULL)
96 {
97 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
98 goto err;
99 }
100 p=buf_in;
101
102 i2d(data,&p);
103 EVP_VerifyInit_ex(&ctx,type, NULL);
104 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
105
106 memset(buf_in,0,(unsigned int)inl);
107 OPENSSL_free(buf_in);
108
109 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
110 (unsigned int)signature->length,pkey) <= 0)
111 {
112 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
113 ret=0;
114 goto err;
115 }
116 /* we don't need to zero the 'ctx' because we just checked
117 * public information */
118 /* memset(&ctx,0,sizeof(ctx)); */
119 ret=1;
120err:
121 EVP_MD_CTX_cleanup(&ctx);
122 return(ret);
123 }
124
125#endif
126
127
128int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signature,
129 void *asn, EVP_PKEY *pkey)
130 {
131 EVP_MD_CTX ctx;
132 const EVP_MD *type;
133 unsigned char *buf_in=NULL;
134 int ret= -1,i,inl;
135
136 EVP_MD_CTX_init(&ctx);
137 i=OBJ_obj2nid(a->algorithm);
138 type=EVP_get_digestbyname(OBJ_nid2sn(i));
139 if (type == NULL)
140 {
141 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
142 goto err;
143 }
144
145 inl = ASN1_item_i2d(asn, &buf_in, it);
146
147 if (buf_in == NULL)
148 {
149 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
150 goto err;
151 }
152
153 EVP_VerifyInit_ex(&ctx,type, NULL);
154 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
155
156 memset(buf_in,0,(unsigned int)inl);
157 OPENSSL_free(buf_in);
158
159 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
160 (unsigned int)signature->length,pkey) <= 0)
161 {
162 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
163 ret=0;
164 goto err;
165 }
166 /* we don't need to zero the 'ctx' because we just checked
167 * public information */
168 /* memset(&ctx,0,sizeof(ctx)); */
169 ret=1;
170err:
171 EVP_MD_CTX_cleanup(&ctx);
172 return(ret);
173 }
174
175
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
new file mode 100644
index 0000000000..dbb30f4f22
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -0,0 +1,1104 @@
1/* crypto/asn1/asn1.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ASN1_H
60#define HEADER_ASN1_H
61
62#include <time.h>
63#ifndef OPENSSL_NO_BIO
64#include <openssl/bio.h>
65#endif
66#include <openssl/e_os2.h>
67#include <openssl/bn.h>
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70
71#include <openssl/symhacks.h>
72
73#include <openssl/e_os2.h>
74#include <openssl/ossl_typ.h>
75
76#ifdef OPENSSL_BUILD_SHLIBCRYPTO
77# undef OPENSSL_EXTERN
78# define OPENSSL_EXTERN OPENSSL_EXPORT
79#endif
80
81#ifdef __cplusplus
82extern "C" {
83#endif
84
85#define V_ASN1_UNIVERSAL 0x00
86#define V_ASN1_APPLICATION 0x40
87#define V_ASN1_CONTEXT_SPECIFIC 0x80
88#define V_ASN1_PRIVATE 0xc0
89
90#define V_ASN1_CONSTRUCTED 0x20
91#define V_ASN1_PRIMITIVE_TAG 0x1f
92#define V_ASN1_PRIMATIVE_TAG 0x1f
93
94#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
95#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */
96#define V_ASN1_ANY -4 /* used in ASN1 template code */
97
98#define V_ASN1_NEG 0x100 /* negative flag */
99
100#define V_ASN1_UNDEF -1
101#define V_ASN1_EOC 0
102#define V_ASN1_BOOLEAN 1 /**/
103#define V_ASN1_INTEGER 2
104#define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
105#define V_ASN1_BIT_STRING 3
106#define V_ASN1_OCTET_STRING 4
107#define V_ASN1_NULL 5
108#define V_ASN1_OBJECT 6
109#define V_ASN1_OBJECT_DESCRIPTOR 7
110#define V_ASN1_EXTERNAL 8
111#define V_ASN1_REAL 9
112#define V_ASN1_ENUMERATED 10
113#define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
114#define V_ASN1_UTF8STRING 12
115#define V_ASN1_SEQUENCE 16
116#define V_ASN1_SET 17
117#define V_ASN1_NUMERICSTRING 18 /**/
118#define V_ASN1_PRINTABLESTRING 19
119#define V_ASN1_T61STRING 20
120#define V_ASN1_TELETEXSTRING 20 /* alias */
121#define V_ASN1_VIDEOTEXSTRING 21 /**/
122#define V_ASN1_IA5STRING 22
123#define V_ASN1_UTCTIME 23
124#define V_ASN1_GENERALIZEDTIME 24 /**/
125#define V_ASN1_GRAPHICSTRING 25 /**/
126#define V_ASN1_ISO64STRING 26 /**/
127#define V_ASN1_VISIBLESTRING 26 /* alias */
128#define V_ASN1_GENERALSTRING 27 /**/
129#define V_ASN1_UNIVERSALSTRING 28 /**/
130#define V_ASN1_BMPSTRING 30
131
132/* For use with d2i_ASN1_type_bytes() */
133#define B_ASN1_NUMERICSTRING 0x0001
134#define B_ASN1_PRINTABLESTRING 0x0002
135#define B_ASN1_T61STRING 0x0004
136#define B_ASN1_TELETEXSTRING 0x0008
137#define B_ASN1_VIDEOTEXSTRING 0x0008
138#define B_ASN1_IA5STRING 0x0010
139#define B_ASN1_GRAPHICSTRING 0x0020
140#define B_ASN1_ISO64STRING 0x0040
141#define B_ASN1_VISIBLESTRING 0x0040
142#define B_ASN1_GENERALSTRING 0x0080
143#define B_ASN1_UNIVERSALSTRING 0x0100
144#define B_ASN1_OCTET_STRING 0x0200
145#define B_ASN1_BIT_STRING 0x0400
146#define B_ASN1_BMPSTRING 0x0800
147#define B_ASN1_UNKNOWN 0x1000
148#define B_ASN1_UTF8STRING 0x2000
149#define B_ASN1_UTCTIME 0x4000
150#define B_ASN1_GENERALIZEDTIME 0x8000
151
152/* For use with ASN1_mbstring_copy() */
153#define MBSTRING_FLAG 0x1000
154#define MBSTRING_ASC (MBSTRING_FLAG|1)
155#define MBSTRING_BMP (MBSTRING_FLAG|2)
156#define MBSTRING_UNIV (MBSTRING_FLAG|3)
157#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
158
159struct X509_algor_st;
160
161#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
162#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
163
164typedef struct asn1_ctx_st
165 {
166 unsigned char *p;/* work char pointer */
167 int eos; /* end of sequence read for indefinite encoding */
168 int error; /* error code to use when returning an error */
169 int inf; /* constructed if 0x20, indefinite is 0x21 */
170 int tag; /* tag from last 'get object' */
171 int xclass; /* class from last 'get object' */
172 long slen; /* length of last 'get object' */
173 unsigned char *max; /* largest value of p allowed */
174 unsigned char *q;/* temporary variable */
175 unsigned char **pp;/* variable */
176 int line; /* used in error processing */
177 } ASN1_CTX;
178
179/* These are used internally in the ASN1_OBJECT to keep track of
180 * whether the names and data need to be free()ed */
181#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
182#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
183#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
184#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
185typedef struct asn1_object_st
186 {
187 const char *sn,*ln;
188 int nid;
189 int length;
190 unsigned char *data;
191 int flags; /* Should we free this one */
192 } ASN1_OBJECT;
193
194#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
195/* This is the base type that holds just about everything :-) */
196typedef struct asn1_string_st
197 {
198 int length;
199 int type;
200 unsigned char *data;
201 /* The value of the following field depends on the type being
202 * held. It is mostly being used for BIT_STRING so if the
203 * input data has a non-zero 'unused bits' value, it will be
204 * handled correctly */
205 long flags;
206 } ASN1_STRING;
207
208/* ASN1_ENCODING structure: this is used to save the received
209 * encoding of an ASN1 type. This is useful to get round
210 * problems with invalid encodings which can break signatures.
211 */
212
213typedef struct ASN1_ENCODING_st
214 {
215 unsigned char *enc; /* DER encoding */
216 long len; /* Length of encoding */
217 int modified; /* set to 1 if 'enc' is invalid */
218 } ASN1_ENCODING;
219
220/* Used with ASN1 LONG type: if a long is set to this it is omitted */
221#define ASN1_LONG_UNDEF 0x7fffffffL
222
223#define STABLE_FLAGS_MALLOC 0x01
224#define STABLE_NO_MASK 0x02
225#define DIRSTRING_TYPE \
226 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
227#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
228
229typedef struct asn1_string_table_st {
230 int nid;
231 long minsize;
232 long maxsize;
233 unsigned long mask;
234 unsigned long flags;
235} ASN1_STRING_TABLE;
236
237DECLARE_STACK_OF(ASN1_STRING_TABLE)
238
239/* size limits: this stuff is taken straight from RFC2459 */
240
241#define ub_name 32768
242#define ub_common_name 64
243#define ub_locality_name 128
244#define ub_state_name 128
245#define ub_organization_name 64
246#define ub_organization_unit_name 64
247#define ub_title 64
248#define ub_email_address 128
249
250/* Declarations for template structures: for full definitions
251 * see asn1t.h
252 */
253typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
254typedef struct ASN1_ITEM_st ASN1_ITEM;
255typedef struct ASN1_TLC_st ASN1_TLC;
256/* This is just an opaque pointer */
257typedef struct ASN1_VALUE_st ASN1_VALUE;
258
259/* Declare ASN1 functions: the implement macro in in asn1t.h */
260
261#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
262
263#define DECLARE_ASN1_FUNCTIONS_name(type, name) \
264 type *name##_new(void); \
265 void name##_free(type *a); \
266 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
267
268#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
269 type *name##_new(void); \
270 void name##_free(type *a); \
271 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
272
273#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
274 type *d2i_##name(type **a, unsigned char **in, long len); \
275 int i2d_##name(type *a, unsigned char **out); \
276 DECLARE_ASN1_ITEM(itname)
277
278#define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
279 type *d2i_##name(type **a, const unsigned char **in, long len); \
280 int i2d_##name(const type *a, unsigned char **out); \
281 DECLARE_ASN1_ITEM(name)
282
283#define DECLARE_ASN1_FUNCTIONS_const(name) \
284 name *name##_new(void); \
285 void name##_free(name *a);
286
287
288/* The following macros and typedefs allow an ASN1_ITEM
289 * to be embedded in a structure and referenced. Since
290 * the ASN1_ITEM pointers need to be globally accessible
291 * (possibly from shared libraries) they may exist in
292 * different forms. On platforms that support it the
293 * ASN1_ITEM structure itself will be globally exported.
294 * Other platforms will export a function that returns
295 * an ASN1_ITEM pointer.
296 *
297 * To handle both cases transparently the macros below
298 * should be used instead of hard coding an ASN1_ITEM
299 * pointer in a structure.
300 *
301 * The structure will look like this:
302 *
303 * typedef struct SOMETHING_st {
304 * ...
305 * ASN1_ITEM_EXP *iptr;
306 * ...
307 * } SOMETHING;
308 *
309 * It would be initialised as e.g.:
310 *
311 * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
312 *
313 * and the actual pointer extracted with:
314 *
315 * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
316 *
317 * Finally an ASN1_ITEM pointer can be extracted from an
318 * appropriate reference with: ASN1_ITEM_rptr(X509). This
319 * would be used when a function takes an ASN1_ITEM * argument.
320 *
321 */
322
323#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
324
325/* ASN1_ITEM pointer exported type */
326typedef const ASN1_ITEM ASN1_ITEM_EXP;
327
328/* Macro to obtain ASN1_ITEM pointer from exported type */
329#define ASN1_ITEM_ptr(iptr) (iptr)
330
331/* Macro to include ASN1_ITEM pointer from base type */
332#define ASN1_ITEM_ref(iptr) (&(iptr##_it))
333
334#define ASN1_ITEM_rptr(ref) (&(ref##_it))
335
336#define DECLARE_ASN1_ITEM(name) \
337 OPENSSL_EXTERN const ASN1_ITEM name##_it;
338
339#else
340
341/* Platforms that can't easily handle shared global variables are declared
342 * as functions returning ASN1_ITEM pointers.
343 */
344
345/* ASN1_ITEM pointer exported type */
346typedef const ASN1_ITEM * ASN1_ITEM_EXP(void);
347
348/* Macro to obtain ASN1_ITEM pointer from exported type */
349#define ASN1_ITEM_ptr(iptr) (iptr())
350
351/* Macro to include ASN1_ITEM pointer from base type */
352#define ASN1_ITEM_ref(iptr) (iptr##_it)
353
354#define ASN1_ITEM_rptr(ref) (ref##_it())
355
356#define DECLARE_ASN1_ITEM(name) \
357 const ASN1_ITEM * name##_it(void);
358
359#endif
360
361/* Parameters used by ASN1_STRING_print_ex() */
362
363/* These determine which characters to escape:
364 * RFC2253 special characters, control characters and
365 * MSB set characters
366 */
367
368#define ASN1_STRFLGS_ESC_2253 1
369#define ASN1_STRFLGS_ESC_CTRL 2
370#define ASN1_STRFLGS_ESC_MSB 4
371
372
373/* This flag determines how we do escaping: normally
374 * RC2253 backslash only, set this to use backslash and
375 * quote.
376 */
377
378#define ASN1_STRFLGS_ESC_QUOTE 8
379
380
381/* These three flags are internal use only. */
382
383/* Character is a valid PrintableString character */
384#define CHARTYPE_PRINTABLESTRING 0x10
385/* Character needs escaping if it is the first character */
386#define CHARTYPE_FIRST_ESC_2253 0x20
387/* Character needs escaping if it is the last character */
388#define CHARTYPE_LAST_ESC_2253 0x40
389
390/* NB the internal flags are safely reused below by flags
391 * handled at the top level.
392 */
393
394/* If this is set we convert all character strings
395 * to UTF8 first
396 */
397
398#define ASN1_STRFLGS_UTF8_CONVERT 0x10
399
400/* If this is set we don't attempt to interpret content:
401 * just assume all strings are 1 byte per character. This
402 * will produce some pretty odd looking output!
403 */
404
405#define ASN1_STRFLGS_IGNORE_TYPE 0x20
406
407/* If this is set we include the string type in the output */
408#define ASN1_STRFLGS_SHOW_TYPE 0x40
409
410/* This determines which strings to display and which to
411 * 'dump' (hex dump of content octets or DER encoding). We can
412 * only dump non character strings or everything. If we
413 * don't dump 'unknown' they are interpreted as character
414 * strings with 1 octet per character and are subject to
415 * the usual escaping options.
416 */
417
418#define ASN1_STRFLGS_DUMP_ALL 0x80
419#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
420
421/* These determine what 'dumping' does, we can dump the
422 * content octets or the DER encoding: both use the
423 * RFC2253 #XXXXX notation.
424 */
425
426#define ASN1_STRFLGS_DUMP_DER 0x200
427
428/* All the string flags consistent with RFC2253,
429 * escaping control characters isn't essential in
430 * RFC2253 but it is advisable anyway.
431 */
432
433#define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
434 ASN1_STRFLGS_ESC_CTRL | \
435 ASN1_STRFLGS_ESC_MSB | \
436 ASN1_STRFLGS_UTF8_CONVERT | \
437 ASN1_STRFLGS_DUMP_UNKNOWN | \
438 ASN1_STRFLGS_DUMP_DER)
439
440DECLARE_STACK_OF(ASN1_INTEGER)
441DECLARE_ASN1_SET_OF(ASN1_INTEGER)
442
443DECLARE_STACK_OF(ASN1_GENERALSTRING)
444
445typedef struct asn1_type_st
446 {
447 int type;
448 union {
449 char *ptr;
450 ASN1_BOOLEAN boolean;
451 ASN1_STRING * asn1_string;
452 ASN1_OBJECT * object;
453 ASN1_INTEGER * integer;
454 ASN1_ENUMERATED * enumerated;
455 ASN1_BIT_STRING * bit_string;
456 ASN1_OCTET_STRING * octet_string;
457 ASN1_PRINTABLESTRING * printablestring;
458 ASN1_T61STRING * t61string;
459 ASN1_IA5STRING * ia5string;
460 ASN1_GENERALSTRING * generalstring;
461 ASN1_BMPSTRING * bmpstring;
462 ASN1_UNIVERSALSTRING * universalstring;
463 ASN1_UTCTIME * utctime;
464 ASN1_GENERALIZEDTIME * generalizedtime;
465 ASN1_VISIBLESTRING * visiblestring;
466 ASN1_UTF8STRING * utf8string;
467 /* set and sequence are left complete and still
468 * contain the set or sequence bytes */
469 ASN1_STRING * set;
470 ASN1_STRING * sequence;
471 } value;
472 } ASN1_TYPE;
473
474DECLARE_STACK_OF(ASN1_TYPE)
475DECLARE_ASN1_SET_OF(ASN1_TYPE)
476
477typedef struct asn1_method_st
478 {
479 int (*i2d)();
480 char *(*d2i)();
481 char *(*create)();
482 void (*destroy)();
483 } ASN1_METHOD;
484
485/* This is used when parsing some Netscape objects */
486typedef struct asn1_header_st
487 {
488 ASN1_OCTET_STRING *header;
489 char *data;
490 ASN1_METHOD *meth;
491 } ASN1_HEADER;
492
493/* This is used to contain a list of bit names */
494typedef struct BIT_STRING_BITNAME_st {
495 int bitnum;
496 const char *lname;
497 const char *sname;
498} BIT_STRING_BITNAME;
499
500
501#define M_ASN1_STRING_length(x) ((x)->length)
502#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
503#define M_ASN1_STRING_type(x) ((x)->type)
504#define M_ASN1_STRING_data(x) ((x)->data)
505
506/* Macros for string operations */
507#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
508 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
509#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
510#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
511 ASN1_STRING_dup((ASN1_STRING *)a)
512#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
513 (ASN1_STRING *)a,(ASN1_STRING *)b)
514#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
515
516#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
517 ASN1_STRING_type_new(V_ASN1_INTEGER)
518#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
519#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
520#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
521 (ASN1_STRING *)a,(ASN1_STRING *)b)
522
523#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
524 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
525#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
526#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
527#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
528 (ASN1_STRING *)a,(ASN1_STRING *)b)
529
530#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
531 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
532#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
533#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
534 ASN1_STRING_dup((ASN1_STRING *)a)
535#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
536 (ASN1_STRING *)a,(ASN1_STRING *)b)
537#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
538#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
539#define M_i2d_ASN1_OCTET_STRING(a,pp) \
540 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
541 V_ASN1_UNIVERSAL)
542
543#define B_ASN1_TIME \
544 B_ASN1_UTCTIME | \
545 B_ASN1_GENERALIZEDTIME
546
547#define B_ASN1_PRINTABLE \
548 B_ASN1_PRINTABLESTRING| \
549 B_ASN1_T61STRING| \
550 B_ASN1_IA5STRING| \
551 B_ASN1_BIT_STRING| \
552 B_ASN1_UNIVERSALSTRING|\
553 B_ASN1_BMPSTRING|\
554 B_ASN1_UTF8STRING|\
555 B_ASN1_UNKNOWN
556
557#define B_ASN1_DIRECTORYSTRING \
558 B_ASN1_PRINTABLESTRING| \
559 B_ASN1_TELETEXSTRING|\
560 B_ASN1_BMPSTRING|\
561 B_ASN1_UNIVERSALSTRING|\
562 B_ASN1_UTF8STRING
563
564#define B_ASN1_DISPLAYTEXT \
565 B_ASN1_IA5STRING| \
566 B_ASN1_VISIBLESTRING| \
567 B_ASN1_BMPSTRING|\
568 B_ASN1_UTF8STRING
569
570#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
571#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
572#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
573 pp,a->type,V_ASN1_UNIVERSAL)
574#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
575 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
576 B_ASN1_PRINTABLE)
577
578#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
579#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
580#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
581 pp,a->type,V_ASN1_UNIVERSAL)
582#define M_d2i_DIRECTORYSTRING(a,pp,l) \
583 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
584 B_ASN1_DIRECTORYSTRING)
585
586#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
587#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
588#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
589 pp,a->type,V_ASN1_UNIVERSAL)
590#define M_d2i_DISPLAYTEXT(a,pp,l) \
591 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
592 B_ASN1_DISPLAYTEXT)
593
594#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
595 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
596#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
597#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
598 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
599 V_ASN1_UNIVERSAL)
600#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
601 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
602 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
603
604#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
605 ASN1_STRING_type_new(V_ASN1_T61STRING)
606#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
607#define M_i2d_ASN1_T61STRING(a,pp) \
608 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
609 V_ASN1_UNIVERSAL)
610#define M_d2i_ASN1_T61STRING(a,pp,l) \
611 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
612 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
613
614#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
615 ASN1_STRING_type_new(V_ASN1_IA5STRING)
616#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
617#define M_ASN1_IA5STRING_dup(a) \
618 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
619#define M_i2d_ASN1_IA5STRING(a,pp) \
620 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
621 V_ASN1_UNIVERSAL)
622#define M_d2i_ASN1_IA5STRING(a,pp,l) \
623 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
624 B_ASN1_IA5STRING)
625
626#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
627 ASN1_STRING_type_new(V_ASN1_UTCTIME)
628#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
629#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
630
631#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
632 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
633#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
634#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
635 (ASN1_STRING *)a)
636
637#define M_ASN1_TIME_new() (ASN1_TIME *)\
638 ASN1_STRING_type_new(V_ASN1_UTCTIME)
639#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
640#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
641
642#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
643 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
644#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
645#define M_i2d_ASN1_GENERALSTRING(a,pp) \
646 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
647 V_ASN1_UNIVERSAL)
648#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
649 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
650 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
651
652#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
653 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
654#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
655#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
656 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
657 V_ASN1_UNIVERSAL)
658#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
659 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
660 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
661
662#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
663 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
664#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
665#define M_i2d_ASN1_BMPSTRING(a,pp) \
666 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
667 V_ASN1_UNIVERSAL)
668#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
669 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
670 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
671
672#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
673 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
674#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
675#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
676 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
677 V_ASN1_UNIVERSAL)
678#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
679 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
680 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
681
682#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
683 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
684#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
685#define M_i2d_ASN1_UTF8STRING(a,pp) \
686 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
687 V_ASN1_UNIVERSAL)
688#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
689 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
690 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
691
692 /* for the is_set parameter to i2d_ASN1_SET */
693#define IS_SEQUENCE 0
694#define IS_SET 1
695
696DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
697
698int ASN1_TYPE_get(ASN1_TYPE *a);
699void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
700
701ASN1_OBJECT * ASN1_OBJECT_new(void );
702void ASN1_OBJECT_free(ASN1_OBJECT *a);
703int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
704ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
705 long length);
706ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
707 long length);
708
709DECLARE_ASN1_ITEM(ASN1_OBJECT)
710
711DECLARE_STACK_OF(ASN1_OBJECT)
712DECLARE_ASN1_SET_OF(ASN1_OBJECT)
713
714ASN1_STRING * ASN1_STRING_new(void);
715void ASN1_STRING_free(ASN1_STRING *a);
716ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
717ASN1_STRING * ASN1_STRING_type_new(int type );
718int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
719 /* Since this is used to store all sorts of things, via macros, for now, make
720 its data void * */
721int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
722int ASN1_STRING_length(ASN1_STRING *x);
723void ASN1_STRING_length_set(ASN1_STRING *x, int n);
724int ASN1_STRING_type(ASN1_STRING *x);
725unsigned char * ASN1_STRING_data(ASN1_STRING *x);
726
727DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
728int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
729ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
730 long length);
731int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
732 int length );
733int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
734int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
735
736#ifndef OPENSSL_NO_BIO
737int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
738 BIT_STRING_BITNAME *tbl, int indent);
739#endif
740int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
741int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
742 BIT_STRING_BITNAME *tbl);
743
744int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
745int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
746
747DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
748int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
749ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
750 long length);
751ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
752 long length);
753ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
754int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
755
756DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
757
758int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
759ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
760int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
761int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
762#if 0
763time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
764#endif
765
766int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
767ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
768int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
769
770DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
771ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
772int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
773int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
774
775DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
776DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
777DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
778DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
779DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
780
781int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
782int UTF8_putc(unsigned char *str, int len, unsigned long value);
783
784DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
785
786DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
787DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
788DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
789DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
790DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
791DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
792DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
793DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
794DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
795
796ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
797int ASN1_TIME_check(ASN1_TIME *t);
798ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
799
800int i2d_ASN1_SET(STACK *a, unsigned char **pp,
801 int (*func)(), int ex_tag, int ex_class, int is_set);
802STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
803 char *(*func)(), void (*free_func)(void *),
804 int ex_tag, int ex_class);
805
806#ifndef OPENSSL_NO_BIO
807int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
808int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
809int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
810int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
811int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
812int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
813int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
814#endif
815int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
816
817int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
818ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
819 const char *sn, const char *ln);
820
821int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
822long ASN1_INTEGER_get(ASN1_INTEGER *a);
823ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
824BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
825
826int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
827long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
828ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
829BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
830
831/* General */
832/* given a string, return the correct type, max is the maximum length */
833int ASN1_PRINTABLE_type(unsigned char *s, int max);
834
835int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
836ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
837 long length, int Ptag, int Pclass);
838unsigned long ASN1_tag2bit(int tag);
839/* type is one or more of the B_ASN1_ values. */
840ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
841 long length,int type);
842
843/* PARSING */
844int asn1_Finish(ASN1_CTX *c);
845
846/* SPECIALS */
847int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
848 int *pclass, long omax);
849int ASN1_check_infinite_end(unsigned char **p,long len);
850void ASN1_put_object(unsigned char **pp, int constructed, int length,
851 int tag, int xclass);
852int ASN1_object_size(int constructed, int length, int tag);
853
854/* Used to implement other functions */
855char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
856
857void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
858
859#ifndef OPENSSL_NO_FP_API
860char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
861void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
862int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
863int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
864int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
865#endif
866
867int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
868
869#ifndef OPENSSL_NO_BIO
870char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
871void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
872int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
873int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
874int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
875int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
876int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
877int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
878int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
879int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
880int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump);
881#endif
882const char *ASN1_tag2str(int tag);
883
884/* Used to load and write netscape format cert/key */
885int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
886ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
887ASN1_HEADER *ASN1_HEADER_new(void );
888void ASN1_HEADER_free(ASN1_HEADER *a);
889
890int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
891
892/* Not used that much at this point, except for the first two */
893ASN1_METHOD *X509_asn1_meth(void);
894ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
895ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
896ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
897
898int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
899 unsigned char *data, int len);
900int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
901 unsigned char *data, int max_len);
902int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
903 unsigned char *data, int len);
904int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
905 unsigned char *data, int max_len);
906
907STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
908 void (*free_func)(void *) );
909unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
910 int *len );
911void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
912void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
913ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
914ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
915
916void ASN1_STRING_set_default_mask(unsigned long mask);
917int ASN1_STRING_set_default_mask_asc(char *p);
918unsigned long ASN1_STRING_get_default_mask(void);
919int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
920 int inform, unsigned long mask);
921int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
922 int inform, unsigned long mask,
923 long minsize, long maxsize);
924
925ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
926 const unsigned char *in, int inlen, int inform, int nid);
927ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
928int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
929void ASN1_STRING_TABLE_cleanup(void);
930
931/* ASN1 template functions */
932
933/* Old API compatible functions */
934ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
935void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
936ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it);
937int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
938
939void ASN1_add_oid_module(void);
940
941/* BEGIN ERROR CODES */
942/* The following lines are auto generated by the script mkerr.pl. Any changes
943 * made after this point may be overwritten when the script is next run.
944 */
945void ERR_load_ASN1_strings(void);
946
947/* Error codes for the ASN1 functions. */
948
949/* Function codes. */
950#define ASN1_F_A2D_ASN1_OBJECT 100
951#define ASN1_F_A2I_ASN1_ENUMERATED 101
952#define ASN1_F_A2I_ASN1_INTEGER 102
953#define ASN1_F_A2I_ASN1_STRING 103
954#define ASN1_F_ASN1_CHECK_TLEN 104
955#define ASN1_F_ASN1_COLLATE_PRIMITIVE 105
956#define ASN1_F_ASN1_COLLECT 106
957#define ASN1_F_ASN1_D2I_BIO 107
958#define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108
959#define ASN1_F_ASN1_D2I_FP 109
960#define ASN1_F_ASN1_DO_ADB 110
961#define ASN1_F_ASN1_DUP 111
962#define ASN1_F_ASN1_ENUMERATED_SET 112
963#define ASN1_F_ASN1_ENUMERATED_TO_BN 113
964#define ASN1_F_ASN1_GET_OBJECT 114
965#define ASN1_F_ASN1_HEADER_NEW 115
966#define ASN1_F_ASN1_I2D_BIO 116
967#define ASN1_F_ASN1_I2D_FP 117
968#define ASN1_F_ASN1_INTEGER_SET 118
969#define ASN1_F_ASN1_INTEGER_TO_BN 119
970#define ASN1_F_ASN1_ITEM_EX_D2I 120
971#define ASN1_F_ASN1_ITEM_NEW 121
972#define ASN1_F_ASN1_MBSTRING_COPY 122
973#define ASN1_F_ASN1_OBJECT_NEW 123
974#define ASN1_F_ASN1_PACK_STRING 124
975#define ASN1_F_ASN1_PBE_SET 125
976#define ASN1_F_ASN1_SEQ_PACK 126
977#define ASN1_F_ASN1_SEQ_UNPACK 127
978#define ASN1_F_ASN1_SIGN 128
979#define ASN1_F_ASN1_STRING_TABLE_ADD 129
980#define ASN1_F_ASN1_STRING_TYPE_NEW 130
981#define ASN1_F_ASN1_TEMPLATE_D2I 131
982#define ASN1_F_ASN1_TEMPLATE_EX_D2I 132
983#define ASN1_F_ASN1_TEMPLATE_NEW 133
984#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134
985#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135
986#define ASN1_F_ASN1_UNPACK_STRING 136
987#define ASN1_F_ASN1_VERIFY 137
988#define ASN1_F_BN_TO_ASN1_ENUMERATED 138
989#define ASN1_F_BN_TO_ASN1_INTEGER 139
990#define ASN1_F_COLLECT_DATA 140
991#define ASN1_F_D2I_ASN1_BIT_STRING 141
992#define ASN1_F_D2I_ASN1_BOOLEAN 142
993#define ASN1_F_D2I_ASN1_BYTES 143
994#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 144
995#define ASN1_F_D2I_ASN1_HEADER 145
996#define ASN1_F_D2I_ASN1_INTEGER 146
997#define ASN1_F_D2I_ASN1_OBJECT 147
998#define ASN1_F_D2I_ASN1_SET 148
999#define ASN1_F_D2I_ASN1_TYPE_BYTES 149
1000#define ASN1_F_D2I_ASN1_UINTEGER 150
1001#define ASN1_F_D2I_ASN1_UTCTIME 151
1002#define ASN1_F_D2I_NETSCAPE_RSA 152
1003#define ASN1_F_D2I_NETSCAPE_RSA_2 153
1004#define ASN1_F_D2I_PRIVATEKEY 154
1005#define ASN1_F_D2I_PUBLICKEY 155
1006#define ASN1_F_D2I_X509 156
1007#define ASN1_F_D2I_X509_CINF 157
1008#define ASN1_F_D2I_X509_NAME 158
1009#define ASN1_F_D2I_X509_PKEY 159
1010#define ASN1_F_I2D_ASN1_TIME 160
1011#define ASN1_F_I2D_DSA_PUBKEY 161
1012#define ASN1_F_I2D_NETSCAPE_RSA 162
1013#define ASN1_F_I2D_PRIVATEKEY 163
1014#define ASN1_F_I2D_PUBLICKEY 164
1015#define ASN1_F_I2D_RSA_PUBKEY 165
1016#define ASN1_F_LONG_C2I 166
1017#define ASN1_F_OID_MODULE_INIT 174
1018#define ASN1_F_PKCS5_PBE2_SET 167
1019#define ASN1_F_X509_CINF_NEW 168
1020#define ASN1_F_X509_CRL_ADD0_REVOKED 169
1021#define ASN1_F_X509_INFO_NEW 170
1022#define ASN1_F_X509_NAME_NEW 171
1023#define ASN1_F_X509_NEW 172
1024#define ASN1_F_X509_PKEY_NEW 173
1025
1026/* Reason codes. */
1027#define ASN1_R_ADDING_OBJECT 171
1028#define ASN1_R_AUX_ERROR 100
1029#define ASN1_R_BAD_CLASS 101
1030#define ASN1_R_BAD_OBJECT_HEADER 102
1031#define ASN1_R_BAD_PASSWORD_READ 103
1032#define ASN1_R_BAD_TAG 104
1033#define ASN1_R_BN_LIB 105
1034#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106
1035#define ASN1_R_BUFFER_TOO_SMALL 107
1036#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108
1037#define ASN1_R_DATA_IS_WRONG 109
1038#define ASN1_R_DECODE_ERROR 110
1039#define ASN1_R_DECODING_ERROR 111
1040#define ASN1_R_ENCODE_ERROR 112
1041#define ASN1_R_ERROR_LOADING_SECTION 172
1042#define ASN1_R_ERROR_PARSING_SET_ELEMENT 113
1043#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114
1044#define ASN1_R_EXPECTING_AN_INTEGER 115
1045#define ASN1_R_EXPECTING_AN_OBJECT 116
1046#define ASN1_R_EXPECTING_A_BOOLEAN 117
1047#define ASN1_R_EXPECTING_A_TIME 118
1048#define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119
1049#define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120
1050#define ASN1_R_FIELD_MISSING 121
1051#define ASN1_R_FIRST_NUM_TOO_LARGE 122
1052#define ASN1_R_HEADER_TOO_LONG 123
1053#define ASN1_R_ILLEGAL_CHARACTERS 124
1054#define ASN1_R_ILLEGAL_NULL 125
1055#define ASN1_R_ILLEGAL_OPTIONAL_ANY 126
1056#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170
1057#define ASN1_R_ILLEGAL_TAGGED_ANY 127
1058#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
1059#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
1060#define ASN1_R_INVALID_DIGIT 130
1061#define ASN1_R_INVALID_SEPARATOR 131
1062#define ASN1_R_INVALID_TIME_FORMAT 132
1063#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133
1064#define ASN1_R_INVALID_UTF8STRING 134
1065#define ASN1_R_IV_TOO_LARGE 135
1066#define ASN1_R_LENGTH_ERROR 136
1067#define ASN1_R_MISSING_EOC 137
1068#define ASN1_R_MISSING_SECOND_NUMBER 138
1069#define ASN1_R_MSTRING_NOT_UNIVERSAL 139
1070#define ASN1_R_MSTRING_WRONG_TAG 140
1071#define ASN1_R_NON_HEX_CHARACTERS 141
1072#define ASN1_R_NOT_ENOUGH_DATA 142
1073#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143
1074#define ASN1_R_NULL_IS_WRONG_LENGTH 144
1075#define ASN1_R_ODD_NUMBER_OF_CHARS 145
1076#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146
1077#define ASN1_R_SECOND_NUMBER_TOO_LARGE 147
1078#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148
1079#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149
1080#define ASN1_R_SHORT_LINE 150
1081#define ASN1_R_STRING_TOO_LONG 151
1082#define ASN1_R_STRING_TOO_SHORT 152
1083#define ASN1_R_TAG_VALUE_TOO_HIGH 153
1084#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
1085#define ASN1_R_TOO_LONG 155
1086#define ASN1_R_TYPE_NOT_CONSTRUCTED 156
1087#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157
1088#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158
1089#define ASN1_R_UNEXPECTED_EOC 159
1090#define ASN1_R_UNKNOWN_FORMAT 160
1091#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161
1092#define ASN1_R_UNKNOWN_OBJECT_TYPE 162
1093#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163
1094#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164
1095#define ASN1_R_UNSUPPORTED_CIPHER 165
1096#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166
1097#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167
1098#define ASN1_R_WRONG_TAG 168
1099#define ASN1_R_WRONG_TYPE 169
1100
1101#ifdef __cplusplus
1102}
1103#endif
1104#endif
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
new file mode 100644
index 0000000000..c4c3d2a91d
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_err.c
@@ -0,0 +1,240 @@
1/* crypto/asn1/asn1_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/asn1.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA ASN1_str_functs[]=
68 {
69{ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"},
70{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"},
71{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
72{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
73{ERR_PACK(0,ASN1_F_ASN1_CHECK_TLEN,0), "ASN1_CHECK_TLEN"},
74{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
75{ERR_PACK(0,ASN1_F_ASN1_COLLECT,0), "ASN1_COLLECT"},
76{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
77{ERR_PACK(0,ASN1_F_ASN1_D2I_EX_PRIMITIVE,0), "ASN1_D2I_EX_PRIMITIVE"},
78{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
79{ERR_PACK(0,ASN1_F_ASN1_DO_ADB,0), "ASN1_DO_ADB"},
80{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
81{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
82{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
83{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
84{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
85{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
86{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"},
87{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
88{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
89{ERR_PACK(0,ASN1_F_ASN1_ITEM_EX_D2I,0), "ASN1_ITEM_EX_D2I"},
90{ERR_PACK(0,ASN1_F_ASN1_ITEM_NEW,0), "ASN1_item_new"},
91{ERR_PACK(0,ASN1_F_ASN1_MBSTRING_COPY,0), "ASN1_mbstring_copy"},
92{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
93{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"},
94{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"},
95{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"},
96{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
97{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
98{ERR_PACK(0,ASN1_F_ASN1_STRING_TABLE_ADD,0), "ASN1_STRING_TABLE_add"},
99{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
100{ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_D2I,0), "ASN1_TEMPLATE_D2I"},
101{ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_EX_D2I,0), "ASN1_TEMPLATE_EX_D2I"},
102{ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_NEW,0), "ASN1_TEMPLATE_NEW"},
103{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
104{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
105{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
106{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
107{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
108{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
109{ERR_PACK(0,ASN1_F_COLLECT_DATA,0), "COLLECT_DATA"},
110{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "D2I_ASN1_BIT_STRING"},
111{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
112{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
113{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "D2I_ASN1_GENERALIZEDTIME"},
114{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
115{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "D2I_ASN1_INTEGER"},
116{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
117{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"},
118{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
119{ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"},
120{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "D2I_ASN1_UTCTIME"},
121{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"},
122{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "D2I_NETSCAPE_RSA_2"},
123{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"},
124{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"},
125{ERR_PACK(0,ASN1_F_D2I_X509,0), "D2I_X509"},
126{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "D2I_X509_CINF"},
127{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "D2I_X509_NAME"},
128{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"},
129{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "I2D_ASN1_TIME"},
130{ERR_PACK(0,ASN1_F_I2D_DSA_PUBKEY,0), "i2d_DSA_PUBKEY"},
131{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
132{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
133{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
134{ERR_PACK(0,ASN1_F_I2D_RSA_PUBKEY,0), "i2d_RSA_PUBKEY"},
135{ERR_PACK(0,ASN1_F_LONG_C2I,0), "LONG_C2I"},
136{ERR_PACK(0,ASN1_F_OID_MODULE_INIT,0), "OID_MODULE_INIT"},
137{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"},
138{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"},
139{ERR_PACK(0,ASN1_F_X509_CRL_ADD0_REVOKED,0), "X509_CRL_add0_revoked"},
140{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"},
141{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_NEW"},
142{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_NEW"},
143{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"},
144{0,NULL}
145 };
146
147static ERR_STRING_DATA ASN1_str_reasons[]=
148 {
149{ASN1_R_ADDING_OBJECT ,"adding object"},
150{ASN1_R_AUX_ERROR ,"aux error"},
151{ASN1_R_BAD_CLASS ,"bad class"},
152{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"},
153{ASN1_R_BAD_PASSWORD_READ ,"bad password read"},
154{ASN1_R_BAD_TAG ,"bad tag"},
155{ASN1_R_BN_LIB ,"bn lib"},
156{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
157{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
158{ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
159{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
160{ASN1_R_DECODE_ERROR ,"decode error"},
161{ASN1_R_DECODING_ERROR ,"decoding error"},
162{ASN1_R_ENCODE_ERROR ,"encode error"},
163{ASN1_R_ERROR_LOADING_SECTION ,"error loading section"},
164{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
165{ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"},
166{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
167{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
168{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
169{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
170{ASN1_R_EXPLICIT_LENGTH_MISMATCH ,"explicit length mismatch"},
171{ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED ,"explicit tag not constructed"},
172{ASN1_R_FIELD_MISSING ,"field missing"},
173{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
174{ASN1_R_HEADER_TOO_LONG ,"header too long"},
175{ASN1_R_ILLEGAL_CHARACTERS ,"illegal characters"},
176{ASN1_R_ILLEGAL_NULL ,"illegal null"},
177{ASN1_R_ILLEGAL_OPTIONAL_ANY ,"illegal optional any"},
178{ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE ,"illegal options on item template"},
179{ASN1_R_ILLEGAL_TAGGED_ANY ,"illegal tagged any"},
180{ASN1_R_INTEGER_TOO_LARGE_FOR_LONG ,"integer too large for long"},
181{ASN1_R_INVALID_BMPSTRING_LENGTH ,"invalid bmpstring length"},
182{ASN1_R_INVALID_DIGIT ,"invalid digit"},
183{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
184{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
185{ASN1_R_INVALID_UNIVERSALSTRING_LENGTH ,"invalid universalstring length"},
186{ASN1_R_INVALID_UTF8STRING ,"invalid utf8string"},
187{ASN1_R_IV_TOO_LARGE ,"iv too large"},
188{ASN1_R_LENGTH_ERROR ,"length error"},
189{ASN1_R_MISSING_EOC ,"missing eoc"},
190{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
191{ASN1_R_MSTRING_NOT_UNIVERSAL ,"mstring not universal"},
192{ASN1_R_MSTRING_WRONG_TAG ,"mstring wrong tag"},
193{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
194{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
195{ASN1_R_NO_MATCHING_CHOICE_TYPE ,"no matching choice type"},
196{ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"},
197{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
198{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
199{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
200{ASN1_R_SEQUENCE_LENGTH_MISMATCH ,"sequence length mismatch"},
201{ASN1_R_SEQUENCE_NOT_CONSTRUCTED ,"sequence not constructed"},
202{ASN1_R_SHORT_LINE ,"short line"},
203{ASN1_R_STRING_TOO_LONG ,"string too long"},
204{ASN1_R_STRING_TOO_SHORT ,"string too short"},
205{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
206{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
207{ASN1_R_TOO_LONG ,"too long"},
208{ASN1_R_TYPE_NOT_CONSTRUCTED ,"type not constructed"},
209{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
210{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"},
211{ASN1_R_UNEXPECTED_EOC ,"unexpected eoc"},
212{ASN1_R_UNKNOWN_FORMAT ,"unknown format"},
213{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
214{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
215{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
216{ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE ,"unsupported any defined by type"},
217{ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
218{ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"},
219{ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"},
220{ASN1_R_WRONG_TAG ,"wrong tag"},
221{ASN1_R_WRONG_TYPE ,"wrong type"},
222{0,NULL}
223 };
224
225#endif
226
227void ERR_load_ASN1_strings(void)
228 {
229 static int init=1;
230
231 if (init)
232 {
233 init=0;
234#ifndef OPENSSL_NO_ERR
235 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs);
236 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons);
237#endif
238
239 }
240 }
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
new file mode 100644
index 0000000000..60f36bb958
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -0,0 +1,430 @@
1/* crypto/asn1/asn1_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <limits.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64
65static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
66static void asn1_put_length(unsigned char **pp, int length);
67const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
68
69int ASN1_check_infinite_end(unsigned char **p, long len)
70 {
71 /* If there is 0 or 1 byte left, the length check should pick
72 * things up */
73 if (len <= 0)
74 return(1);
75 else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
76 {
77 (*p)+=2;
78 return(1);
79 }
80 return(0);
81 }
82
83
84int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
85 long omax)
86 {
87 int i,ret;
88 long l;
89 unsigned char *p= *pp;
90 int tag,xclass,inf;
91 long max=omax;
92
93 if (!max) goto err;
94 ret=(*p&V_ASN1_CONSTRUCTED);
95 xclass=(*p&V_ASN1_PRIVATE);
96 i= *p&V_ASN1_PRIMITIVE_TAG;
97 if (i == V_ASN1_PRIMITIVE_TAG)
98 { /* high-tag */
99 p++;
100 if (--max == 0) goto err;
101 l=0;
102 while (*p&0x80)
103 {
104 l<<=7L;
105 l|= *(p++)&0x7f;
106 if (--max == 0) goto err;
107 }
108 l<<=7L;
109 l|= *(p++)&0x7f;
110 tag=(int)l;
111 }
112 else
113 {
114 tag=i;
115 p++;
116 if (--max == 0) goto err;
117 }
118 *ptag=tag;
119 *pclass=xclass;
120 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
121
122#if 0
123 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
124 (int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
125 (int)(omax+ *pp));
126
127#endif
128 if (*plength > (omax - (p - *pp)))
129 {
130 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
131 /* Set this so that even if things are not long enough
132 * the values are set correctly */
133 ret|=0x80;
134 }
135 *pp=p;
136 return(ret|inf);
137err:
138 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
139 return(0x80);
140 }
141
142static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
143 {
144 unsigned char *p= *pp;
145 unsigned long ret=0;
146 int i;
147
148 if (max-- < 1) return(0);
149 if (*p == 0x80)
150 {
151 *inf=1;
152 ret=0;
153 p++;
154 }
155 else
156 {
157 *inf=0;
158 i= *p&0x7f;
159 if (*(p++) & 0x80)
160 {
161 if (i > sizeof(long))
162 return 0;
163 if (max-- == 0) return(0);
164 while (i-- > 0)
165 {
166 ret<<=8L;
167 ret|= *(p++);
168 if (max-- == 0) return(0);
169 }
170 }
171 else
172 ret=i;
173 }
174 if (ret > LONG_MAX)
175 return 0;
176 *pp=p;
177 *rl=(long)ret;
178 return(1);
179 }
180
181/* class 0 is constructed
182 * constructed == 2 for indefinite length constructed */
183void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
184 int xclass)
185 {
186 unsigned char *p= *pp;
187 int i, ttag;
188
189 i=(constructed)?V_ASN1_CONSTRUCTED:0;
190 i|=(xclass&V_ASN1_PRIVATE);
191 if (tag < 31)
192 *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
193 else
194 {
195 *(p++)=i|V_ASN1_PRIMITIVE_TAG;
196 for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
197 ttag = i;
198 while(i-- > 0)
199 {
200 p[i] = tag & 0x7f;
201 if(i != (ttag - 1)) p[i] |= 0x80;
202 tag >>= 7;
203 }
204 p += ttag;
205 }
206 if ((constructed == 2) && (length == 0))
207 *(p++)=0x80; /* der_put_length would output 0 instead */
208 else
209 asn1_put_length(&p,length);
210 *pp=p;
211 }
212
213static void asn1_put_length(unsigned char **pp, int length)
214 {
215 unsigned char *p= *pp;
216 int i,l;
217 if (length <= 127)
218 *(p++)=(unsigned char)length;
219 else
220 {
221 l=length;
222 for (i=0; l > 0; i++)
223 l>>=8;
224 *(p++)=i|0x80;
225 l=i;
226 while (i-- > 0)
227 {
228 p[i]=length&0xff;
229 length>>=8;
230 }
231 p+=l;
232 }
233 *pp=p;
234 }
235
236int ASN1_object_size(int constructed, int length, int tag)
237 {
238 int ret;
239
240 ret=length;
241 ret++;
242 if (tag >= 31)
243 {
244 while (tag > 0)
245 {
246 tag>>=7;
247 ret++;
248 }
249 }
250 if ((length == 0) && (constructed == 2))
251 ret+=2;
252 ret++;
253 if (length > 127)
254 {
255 while (length > 0)
256 {
257 length>>=8;
258 ret++;
259 }
260 }
261 return(ret);
262 }
263
264int asn1_Finish(ASN1_CTX *c)
265 {
266 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
267 {
268 if (!ASN1_check_infinite_end(&c->p,c->slen))
269 {
270 c->error=ERR_R_MISSING_ASN1_EOS;
271 return(0);
272 }
273 }
274 if ( ((c->slen != 0) && !(c->inf & 1)) ||
275 ((c->slen < 0) && (c->inf & 1)))
276 {
277 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
278 return(0);
279 }
280 return(1);
281 }
282
283int asn1_GetSequence(ASN1_CTX *c, long *length)
284 {
285 unsigned char *q;
286
287 q=c->p;
288 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
289 *length);
290 if (c->inf & 0x80)
291 {
292 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
293 return(0);
294 }
295 if (c->tag != V_ASN1_SEQUENCE)
296 {
297 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
298 return(0);
299 }
300 (*length)-=(c->p-q);
301 if (c->max && (*length < 0))
302 {
303 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
304 return(0);
305 }
306 if (c->inf == (1|V_ASN1_CONSTRUCTED))
307 c->slen= *length+ *(c->pp)-c->p;
308 c->eos=0;
309 return(1);
310 }
311
312ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
313 {
314 ASN1_STRING *ret;
315
316 if (str == NULL) return(NULL);
317 if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
318 return(NULL);
319 if (!ASN1_STRING_set(ret,str->data,str->length))
320 {
321 ASN1_STRING_free(ret);
322 return(NULL);
323 }
324 ret->flags = str->flags;
325 return(ret);
326 }
327
328int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
329 {
330 unsigned char *c;
331 const char *data=_data;
332
333 if (len < 0)
334 {
335 if (data == NULL)
336 return(0);
337 else
338 len=strlen(data);
339 }
340 if ((str->length < len) || (str->data == NULL))
341 {
342 c=str->data;
343 if (c == NULL)
344 str->data=OPENSSL_malloc(len+1);
345 else
346 str->data=OPENSSL_realloc(c,len+1);
347
348 if (str->data == NULL)
349 {
350 str->data=c;
351 return(0);
352 }
353 }
354 str->length=len;
355 if (data != NULL)
356 {
357 memcpy(str->data,data,len);
358 /* an allowance for strings :-) */
359 str->data[len]='\0';
360 }
361 return(1);
362 }
363
364ASN1_STRING *ASN1_STRING_new(void)
365 {
366 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
367 }
368
369
370ASN1_STRING *ASN1_STRING_type_new(int type)
371 {
372 ASN1_STRING *ret;
373
374 ret=(ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING));
375 if (ret == NULL)
376 {
377 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
378 return(NULL);
379 }
380 ret->length=0;
381 ret->type=type;
382 ret->data=NULL;
383 ret->flags=0;
384 return(ret);
385 }
386
387void ASN1_STRING_free(ASN1_STRING *a)
388 {
389 if (a == NULL) return;
390 if (a->data != NULL) OPENSSL_free(a->data);
391 OPENSSL_free(a);
392 }
393
394int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
395 {
396 int i;
397
398 i=(a->length-b->length);
399 if (i == 0)
400 {
401 i=memcmp(a->data,b->data,a->length);
402 if (i == 0)
403 return(a->type-b->type);
404 else
405 return(i);
406 }
407 else
408 return(i);
409 }
410
411void asn1_add_error(unsigned char *address, int offset)
412 {
413 char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1];
414
415 snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address);
416 snprintf(buf2,sizeof buf2,"%d",offset);
417 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
418 }
419
420int ASN1_STRING_length(ASN1_STRING *x)
421{ return M_ASN1_STRING_length(x); }
422
423void ASN1_STRING_length_set(ASN1_STRING *x, int len)
424{ M_ASN1_STRING_length_set(x, len); return; }
425
426int ASN1_STRING_type(ASN1_STRING *x)
427{ return M_ASN1_STRING_type(x); }
428
429unsigned char * ASN1_STRING_data(ASN1_STRING *x)
430{ return M_ASN1_STRING_data(x); }
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
new file mode 100644
index 0000000000..a48649ceeb
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_mac.h
@@ -0,0 +1,560 @@
1/* crypto/asn1/asn1_mac.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ASN1_MAC_H
60#define HEADER_ASN1_MAC_H
61
62#include <openssl/asn1.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifndef ASN1_MAC_ERR_LIB
69#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
70#endif
71
72#define ASN1_MAC_H_err(f,r,line) \
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
74
75#define M_ASN1_D2I_vars(a,type,func) \
76 ASN1_CTX c; \
77 type ret=NULL; \
78 \
79 c.pp=(unsigned char **)pp; \
80 c.q= *(unsigned char **)pp; \
81 c.error=ERR_R_NESTED_ASN1_ERROR; \
82 if ((a == NULL) || ((*a) == NULL)) \
83 { if ((ret=(type)func()) == NULL) \
84 { c.line=__LINE__; goto err; } } \
85 else ret=(*a);
86
87#define M_ASN1_D2I_Init() \
88 c.p= *(unsigned char **)pp; \
89 c.max=(length == 0)?0:(c.p+length);
90
91#define M_ASN1_D2I_Finish_2(a) \
92 if (!asn1_Finish(&c)) \
93 { c.line=__LINE__; goto err; } \
94 *(unsigned char **)pp=c.p; \
95 if (a != NULL) (*a)=ret; \
96 return(ret);
97
98#define M_ASN1_D2I_Finish(a,func,e) \
99 M_ASN1_D2I_Finish_2(a); \
100err:\
101 ASN1_MAC_H_err((e),c.error,c.line); \
102 asn1_add_error(*(unsigned char **)pp,(int)(c.q- *pp)); \
103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
104 return(NULL)
105
106#define M_ASN1_D2I_start_sequence() \
107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; }
109/* Begin reading ASN1 without a surrounding sequence */
110#define M_ASN1_D2I_begin() \
111 c.slen = length;
112
113/* End reading ASN1 with no check on length */
114#define M_ASN1_D2I_Finish_nolen(a, func, e) \
115 *pp=c.p; \
116 if (a != NULL) (*a)=ret; \
117 return(ret); \
118err:\
119 ASN1_MAC_H_err((e),c.error,c.line); \
120 asn1_add_error(*pp,(int)(c.q- *pp)); \
121 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
122 return(NULL)
123
124#define M_ASN1_D2I_end_sequence() \
125 (((c.inf&1) == 0)?(c.slen <= 0): \
126 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
127
128/* Don't use this with d2i_ASN1_BOOLEAN() */
129#define M_ASN1_D2I_get(b,func) \
130 c.q=c.p; \
131 if (func(&(b),&c.p,c.slen) == NULL) \
132 {c.line=__LINE__; goto err; } \
133 c.slen-=(c.p-c.q);
134
135/* use this instead () */
136#define M_ASN1_D2I_get_int(b,func) \
137 c.q=c.p; \
138 if (func(&(b),&c.p,c.slen) < 0) \
139 {c.line=__LINE__; goto err; } \
140 c.slen-=(c.p-c.q);
141
142#define M_ASN1_D2I_get_opt(b,func,type) \
143 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
144 == (V_ASN1_UNIVERSAL|(type)))) \
145 { \
146 M_ASN1_D2I_get(b,func); \
147 }
148
149#define M_ASN1_D2I_get_imp(b,func, type) \
150 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
151 c.q=c.p; \
152 if (func(&(b),&c.p,c.slen) == NULL) \
153 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
154 c.slen-=(c.p-c.q);\
155 M_ASN1_next_prev=_tmp;
156
157#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
158 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
159 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
160 { \
161 unsigned char _tmp = M_ASN1_next; \
162 M_ASN1_D2I_get_imp(b,func, type);\
163 }
164
165#define M_ASN1_D2I_get_set(r,func,free_func) \
166 M_ASN1_D2I_get_imp_set(r,func,free_func, \
167 V_ASN1_SET,V_ASN1_UNIVERSAL);
168
169#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
170 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
171 V_ASN1_SET,V_ASN1_UNIVERSAL);
172
173#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
174 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
175 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
176 { M_ASN1_D2I_get_set(r,func,free_func); }
177
178#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
179 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
180 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
181 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
182
183#define M_ASN1_I2D_len_SET_opt(a,f) \
184 if ((a != NULL) && (sk_num(a) != 0)) \
185 M_ASN1_I2D_len_SET(a,f);
186
187#define M_ASN1_I2D_put_SET_opt(a,f) \
188 if ((a != NULL) && (sk_num(a) != 0)) \
189 M_ASN1_I2D_put_SET(a,f);
190
191#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
192 if ((a != NULL) && (sk_num(a) != 0)) \
193 M_ASN1_I2D_put_SEQUENCE(a,f);
194
195#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
196 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
197 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
198
199#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
200 if ((c.slen != 0) && \
201 (M_ASN1_next == \
202 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
203 { \
204 M_ASN1_D2I_get_imp_set(b,func,free_func,\
205 tag,V_ASN1_CONTEXT_SPECIFIC); \
206 }
207
208#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
209 if ((c.slen != 0) && \
210 (M_ASN1_next == \
211 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
212 { \
213 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
214 tag,V_ASN1_CONTEXT_SPECIFIC); \
215 }
216
217#define M_ASN1_D2I_get_seq(r,func,free_func) \
218 M_ASN1_D2I_get_imp_set(r,func,free_func,\
219 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
220
221#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
222 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
223 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
224
225#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
226 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
227 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
228 { M_ASN1_D2I_get_seq(r,func,free_func); }
229
230#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
231 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
232 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
233 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
234
235#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
236 M_ASN1_D2I_get_imp_set(r,func,free_func,\
237 x,V_ASN1_CONTEXT_SPECIFIC);
238
239#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
240 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
241 x,V_ASN1_CONTEXT_SPECIFIC);
242
243#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
244 c.q=c.p; \
245 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
246 (void (*)())free_func,a,b) == NULL) \
247 { c.line=__LINE__; goto err; } \
248 c.slen-=(c.p-c.q);
249
250#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
251 c.q=c.p; \
252 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
253 free_func,a,b) == NULL) \
254 { c.line=__LINE__; goto err; } \
255 c.slen-=(c.p-c.q);
256
257#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
258 c.q=c.p; \
259 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
260 { c.line=__LINE__; goto err; } \
261 c.slen-=(c.p-c.q);
262
263#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
264 if ((c.slen != 0L) && (M_ASN1_next == \
265 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
266 { \
267 int Tinf,Ttag,Tclass; \
268 long Tlen; \
269 \
270 c.q=c.p; \
271 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
272 if (Tinf & 0x80) \
273 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
274 c.line=__LINE__; goto err; } \
275 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
276 Tlen = c.slen - (c.p - c.q) - 2; \
277 if (func(&(r),&c.p,Tlen) == NULL) \
278 { c.line=__LINE__; goto err; } \
279 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
280 Tlen = c.slen - (c.p - c.q); \
281 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
282 { c.error=ERR_R_MISSING_ASN1_EOS; \
283 c.line=__LINE__; goto err; } \
284 }\
285 c.slen-=(c.p-c.q); \
286 }
287
288#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
289 if ((c.slen != 0) && (M_ASN1_next == \
290 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
291 { \
292 int Tinf,Ttag,Tclass; \
293 long Tlen; \
294 \
295 c.q=c.p; \
296 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
297 if (Tinf & 0x80) \
298 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
299 c.line=__LINE__; goto err; } \
300 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
301 Tlen = c.slen - (c.p - c.q) - 2; \
302 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
303 (void (*)())free_func, \
304 b,V_ASN1_UNIVERSAL) == NULL) \
305 { c.line=__LINE__; goto err; } \
306 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
307 Tlen = c.slen - (c.p - c.q); \
308 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
309 { c.error=ERR_R_MISSING_ASN1_EOS; \
310 c.line=__LINE__; goto err; } \
311 }\
312 c.slen-=(c.p-c.q); \
313 }
314
315#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
316 if ((c.slen != 0) && (M_ASN1_next == \
317 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
318 { \
319 int Tinf,Ttag,Tclass; \
320 long Tlen; \
321 \
322 c.q=c.p; \
323 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
324 if (Tinf & 0x80) \
325 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
326 c.line=__LINE__; goto err; } \
327 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
328 Tlen = c.slen - (c.p - c.q) - 2; \
329 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
330 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
331 { c.line=__LINE__; goto err; } \
332 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
333 Tlen = c.slen - (c.p - c.q); \
334 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
335 { c.error=ERR_R_MISSING_ASN1_EOS; \
336 c.line=__LINE__; goto err; } \
337 }\
338 c.slen-=(c.p-c.q); \
339 }
340
341/* New macros */
342#define M_ASN1_New_Malloc(ret,type) \
343 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
344 { c.line=__LINE__; goto err2; }
345
346#define M_ASN1_New(arg,func) \
347 if (((arg)=func()) == NULL) return(NULL)
348
349#define M_ASN1_New_Error(a) \
350/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
351 return(NULL);*/ \
352 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
353 return(NULL)
354
355
356#define M_ASN1_next (*c.p)
357#define M_ASN1_next_prev (*c.q)
358
359/*************************************************/
360
361#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
362 unsigned char *p; \
363 if (a == NULL) return(0)
364
365/* Length Macros */
366#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
367#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
368
369#define M_ASN1_I2D_len_SET(a,f) \
370 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
371
372#define M_ASN1_I2D_len_SET_type(type,a,f) \
373 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
374 V_ASN1_UNIVERSAL,IS_SET);
375
376#define M_ASN1_I2D_len_SEQUENCE(a,f) \
377 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
378 IS_SEQUENCE);
379
380#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
381 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
382 V_ASN1_UNIVERSAL,IS_SEQUENCE)
383
384#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
385 if ((a != NULL) && (sk_num(a) != 0)) \
386 M_ASN1_I2D_len_SEQUENCE(a,f);
387
388#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
389 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
390 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
391
392#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
393 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
394
395#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
396 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
397 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
398
399#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
400 if ((a != NULL) && (sk_num(a) != 0)) \
401 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
402 IS_SET);
403
404#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
405 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
406 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
407 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
408
409#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
410 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
411 IS_SEQUENCE);
412
413#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
414 if ((a != NULL) && (sk_num(a) != 0)) \
415 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
416 IS_SEQUENCE);
417
418#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
419 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
420 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
421 V_ASN1_CONTEXT_SPECIFIC, \
422 IS_SEQUENCE);
423
424#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
425 if (a != NULL)\
426 { \
427 v=f(a,NULL); \
428 ret+=ASN1_object_size(1,v,mtag); \
429 }
430
431#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
432 if ((a != NULL) && (sk_num(a) != 0))\
433 { \
434 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
435 ret+=ASN1_object_size(1,v,mtag); \
436 }
437
438#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
439 if ((a != NULL) && (sk_num(a) != 0))\
440 { \
441 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
442 IS_SEQUENCE); \
443 ret+=ASN1_object_size(1,v,mtag); \
444 }
445
446#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
447 if ((a != NULL) && (sk_##type##_num(a) != 0))\
448 { \
449 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
450 V_ASN1_UNIVERSAL, \
451 IS_SEQUENCE); \
452 ret+=ASN1_object_size(1,v,mtag); \
453 }
454
455/* Put Macros */
456#define M_ASN1_I2D_put(a,f) f(a,&p)
457
458#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
459 if (a != NULL) \
460 { \
461 unsigned char *q=p; \
462 f(a,&p); \
463 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
464 }
465
466#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
467 V_ASN1_UNIVERSAL,IS_SET)
468#define M_ASN1_I2D_put_SET_type(type,a,f) \
469 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
470#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
471 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
472#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
473 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
474#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
475 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
476
477#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
478 V_ASN1_UNIVERSAL,IS_SEQUENCE)
479
480#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
481 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
482 IS_SEQUENCE)
483
484#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
485 if ((a != NULL) && (sk_num(a) != 0)) \
486 M_ASN1_I2D_put_SEQUENCE(a,f);
487
488#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
489 if ((a != NULL) && (sk_num(a) != 0)) \
490 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
491 IS_SET); }
492
493#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
494 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
495 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
496 V_ASN1_CONTEXT_SPECIFIC, \
497 IS_SET); }
498
499#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
500 if ((a != NULL) && (sk_num(a) != 0)) \
501 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
502 IS_SEQUENCE); }
503
504#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
505 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
506 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
507 V_ASN1_CONTEXT_SPECIFIC, \
508 IS_SEQUENCE); }
509
510#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
511 if (a != NULL) \
512 { \
513 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
514 f(a,&p); \
515 }
516
517#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
518 if ((a != NULL) && (sk_num(a) != 0)) \
519 { \
520 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
521 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
522 }
523
524#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
525 if ((a != NULL) && (sk_num(a) != 0)) \
526 { \
527 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
528 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
529 }
530
531#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
532 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
533 { \
534 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
535 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
536 IS_SEQUENCE); \
537 }
538
539#define M_ASN1_I2D_seq_total() \
540 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
541 if (pp == NULL) return(r); \
542 p= *pp; \
543 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
544
545#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
546 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
547 *(p++)=0x80
548
549#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
550
551#define M_ASN1_I2D_finish() *pp=p; \
552 return(r);
553
554int asn1_GetSequence(ASN1_CTX *c, long *length);
555void asn1_add_error(unsigned char *address,int offset);
556#ifdef __cplusplus
557}
558#endif
559
560#endif
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
new file mode 100644
index 0000000000..4223c9ae45
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_par.c
@@ -0,0 +1,423 @@
1/* crypto/asn1/asn1_par.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/asn1.h>
64
65static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed,
66 int indent);
67static int asn1_parse2(BIO *bp, unsigned char **pp, long length,
68 int offset, int depth, int indent, int dump);
69static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
70 int indent)
71 {
72 static const char fmt[]="%-18s";
73 static const char fmt2[]="%2d %-15s";
74 char str[128];
75 const char *p,*p2=NULL;
76
77 if (constructed & V_ASN1_CONSTRUCTED)
78 p="cons: ";
79 else
80 p="prim: ";
81 if (BIO_write(bp,p,6) < 6) goto err;
82 if (indent)
83 {
84 if (indent > 128) indent=128;
85 memset(str,' ',indent);
86 if (BIO_write(bp,str,indent) < indent) goto err;
87 }
88
89 p=str;
90 if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
91 snprintf(str,sizeof str,"priv [ %d ] ",tag);
92 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
93 snprintf(str,sizeof str,"cont [ %d ]",tag);
94 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
95 snprintf(str,sizeof str,"appl [ %d ]",tag);
96 else p = ASN1_tag2str(tag);
97
98 if (p2 != NULL)
99 {
100 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
101 }
102 else
103 {
104 if (BIO_printf(bp,fmt,p) <= 0) goto err;
105 }
106 return(1);
107err:
108 return(0);
109 }
110
111int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent)
112 {
113 return(asn1_parse2(bp,&pp,len,0,0,indent,0));
114 }
115
116int ASN1_parse_dump(BIO *bp, unsigned char *pp, long len, int indent, int dump)
117 {
118 return(asn1_parse2(bp,&pp,len,0,0,indent,dump));
119 }
120
121static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
122 int depth, int indent, int dump)
123 {
124 unsigned char *p,*ep,*tot,*op,*opp;
125 long len;
126 int tag,xclass,ret=0;
127 int nl,hl,j,r;
128 ASN1_OBJECT *o=NULL;
129 ASN1_OCTET_STRING *os=NULL;
130 /* ASN1_BMPSTRING *bmp=NULL;*/
131 int dump_indent;
132
133#if 0
134 dump_indent = indent;
135#else
136 dump_indent = 6; /* Because we know BIO_dump_indent() */
137#endif
138 p= *pp;
139 tot=p+length;
140 op=p-1;
141 while ((p < tot) && (op < p))
142 {
143 op=p;
144 j=ASN1_get_object(&p,&len,&tag,&xclass,length);
145#ifdef LINT
146 j=j;
147#endif
148 if (j & 0x80)
149 {
150 if (BIO_write(bp,"Error in encoding\n",18) <= 0)
151 goto end;
152 ret=0;
153 goto end;
154 }
155 hl=(p-op);
156 length-=hl;
157 /* if j == 0x21 it is a constructed indefinite length object */
158 if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
159 <= 0) goto end;
160
161 if (j != (V_ASN1_CONSTRUCTED | 1))
162 {
163 if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
164 depth,(long)hl,len) <= 0)
165 goto end;
166 }
167 else
168 {
169 if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
170 depth,(long)hl) <= 0)
171 goto end;
172 }
173 if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
174 goto end;
175 if (j & V_ASN1_CONSTRUCTED)
176 {
177 ep=p+len;
178 if (BIO_write(bp,"\n",1) <= 0) goto end;
179 if (len > length)
180 {
181 BIO_printf(bp,
182 "length is greater than %ld\n",length);
183 ret=0;
184 goto end;
185 }
186 if ((j == 0x21) && (len == 0))
187 {
188 for (;;)
189 {
190 r=asn1_parse2(bp,&p,(long)(tot-p),
191 offset+(p - *pp),depth+1,
192 indent,dump);
193 if (r == 0) { ret=0; goto end; }
194 if ((r == 2) || (p >= tot)) break;
195 }
196 }
197 else
198 while (p < ep)
199 {
200 r=asn1_parse2(bp,&p,(long)len,
201 offset+(p - *pp),depth+1,
202 indent,dump);
203 if (r == 0) { ret=0; goto end; }
204 }
205 }
206 else if (xclass != 0)
207 {
208 p+=len;
209 if (BIO_write(bp,"\n",1) <= 0) goto end;
210 }
211 else
212 {
213 nl=0;
214 if ( (tag == V_ASN1_PRINTABLESTRING) ||
215 (tag == V_ASN1_T61STRING) ||
216 (tag == V_ASN1_IA5STRING) ||
217 (tag == V_ASN1_VISIBLESTRING) ||
218 (tag == V_ASN1_UTCTIME) ||
219 (tag == V_ASN1_GENERALIZEDTIME))
220 {
221 if (BIO_write(bp,":",1) <= 0) goto end;
222 if ((len > 0) &&
223 BIO_write(bp,(char *)p,(int)len)
224 != (int)len)
225 goto end;
226 }
227 else if (tag == V_ASN1_OBJECT)
228 {
229 opp=op;
230 if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
231 {
232 if (BIO_write(bp,":",1) <= 0) goto end;
233 i2a_ASN1_OBJECT(bp,o);
234 }
235 else
236 {
237 if (BIO_write(bp,":BAD OBJECT",11) <= 0)
238 goto end;
239 }
240 }
241 else if (tag == V_ASN1_BOOLEAN)
242 {
243 int ii;
244
245 opp=op;
246 ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
247 if (ii < 0)
248 {
249 if (BIO_write(bp,"Bad boolean\n",12))
250 goto end;
251 }
252 BIO_printf(bp,":%d",ii);
253 }
254 else if (tag == V_ASN1_BMPSTRING)
255 {
256 /* do the BMP thang */
257 }
258 else if (tag == V_ASN1_OCTET_STRING)
259 {
260 int i,printable=1;
261
262 opp=op;
263 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
264 if (os != NULL)
265 {
266 opp=os->data;
267 for (i=0; i<os->length; i++)
268 {
269 if (( (opp[i] < ' ') &&
270 (opp[i] != '\n') &&
271 (opp[i] != '\r') &&
272 (opp[i] != '\t')) ||
273 (opp[i] > '~'))
274 {
275 printable=0;
276 break;
277 }
278 }
279 if (printable && (os->length > 0))
280 {
281 if (BIO_write(bp,":",1) <= 0)
282 goto end;
283 if (BIO_write(bp,(char *)opp,
284 os->length) <= 0)
285 goto end;
286 }
287 if (!printable && (os->length > 0)
288 && dump)
289 {
290 if (!nl)
291 {
292 if (BIO_write(bp,"\n",1) <= 0)
293 goto end;
294 }
295 if (BIO_dump_indent(bp,(char *)opp,
296 ((dump == -1 || dump > os->length)?os->length:dump),
297 dump_indent) <= 0)
298 goto end;
299 nl=1;
300 }
301 M_ASN1_OCTET_STRING_free(os);
302 os=NULL;
303 }
304 }
305 else if (tag == V_ASN1_INTEGER)
306 {
307 ASN1_INTEGER *bs;
308 int i;
309
310 opp=op;
311 bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
312 if (bs != NULL)
313 {
314 if (BIO_write(bp,":",1) <= 0) goto end;
315 if (bs->type == V_ASN1_NEG_INTEGER)
316 if (BIO_write(bp,"-",1) <= 0)
317 goto end;
318 for (i=0; i<bs->length; i++)
319 {
320 if (BIO_printf(bp,"%02X",
321 bs->data[i]) <= 0)
322 goto end;
323 }
324 if (bs->length == 0)
325 {
326 if (BIO_write(bp,"00",2) <= 0)
327 goto end;
328 }
329 }
330 else
331 {
332 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
333 goto end;
334 }
335 M_ASN1_INTEGER_free(bs);
336 }
337 else if (tag == V_ASN1_ENUMERATED)
338 {
339 ASN1_ENUMERATED *bs;
340 int i;
341
342 opp=op;
343 bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
344 if (bs != NULL)
345 {
346 if (BIO_write(bp,":",1) <= 0) goto end;
347 if (bs->type == V_ASN1_NEG_ENUMERATED)
348 if (BIO_write(bp,"-",1) <= 0)
349 goto end;
350 for (i=0; i<bs->length; i++)
351 {
352 if (BIO_printf(bp,"%02X",
353 bs->data[i]) <= 0)
354 goto end;
355 }
356 if (bs->length == 0)
357 {
358 if (BIO_write(bp,"00",2) <= 0)
359 goto end;
360 }
361 }
362 else
363 {
364 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
365 goto end;
366 }
367 M_ASN1_ENUMERATED_free(bs);
368 }
369 else if (len > 0 && dump)
370 {
371 if (!nl)
372 {
373 if (BIO_write(bp,"\n",1) <= 0)
374 goto end;
375 }
376 if (BIO_dump_indent(bp,(char *)p,
377 ((dump == -1 || dump > len)?len:dump),
378 dump_indent) <= 0)
379 goto end;
380 nl=1;
381 }
382
383 if (!nl)
384 {
385 if (BIO_write(bp,"\n",1) <= 0) goto end;
386 }
387 p+=len;
388 if ((tag == V_ASN1_EOC) && (xclass == 0))
389 {
390 ret=2; /* End of sequence */
391 goto end;
392 }
393 }
394 length-=len;
395 }
396 ret=1;
397end:
398 if (o != NULL) ASN1_OBJECT_free(o);
399 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
400 *pp=p;
401 return(ret);
402 }
403
404const char *ASN1_tag2str(int tag)
405{
406 const static char *tag2str[] = {
407 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
408 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
409 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */
410 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */
411 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */
412 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */
413 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */
414 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */
415 };
416
417 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
418 tag &= ~0x100;
419
420 if(tag < 0 || tag > 30) return "(unknown)";
421 return tag2str[tag];
422}
423
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h
new file mode 100644
index 0000000000..ed372f8554
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1t.h
@@ -0,0 +1,846 @@
1/* asn1t.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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#ifndef HEADER_ASN1T_H
59#define HEADER_ASN1T_H
60
61#include <stddef.h>
62#include <openssl/e_os2.h>
63#include <openssl/asn1.h>
64
65#ifdef OPENSSL_BUILD_SHLIBCRYPTO
66# undef OPENSSL_EXTERN
67# define OPENSSL_EXTERN OPENSSL_EXPORT
68#endif
69
70/* ASN1 template defines, structures and functions */
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76
77#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
78
79/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
80#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
81
82
83/* Macros for start and end of ASN1_ITEM definition */
84
85#define ASN1_ITEM_start(itname) \
86 OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
87
88#define ASN1_ITEM_end(itname) \
89 };
90
91#else
92
93/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
94#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
95
96
97/* Macros for start and end of ASN1_ITEM definition */
98
99#define ASN1_ITEM_start(itname) \
100 const ASN1_ITEM * itname##_it(void) \
101 { \
102 static const ASN1_ITEM local_it = { \
103
104#define ASN1_ITEM_end(itname) \
105 }; \
106 return &local_it; \
107 }
108
109#endif
110
111
112/* Macros to aid ASN1 template writing */
113
114#define ASN1_ITEM_TEMPLATE(tname) \
115 const static ASN1_TEMPLATE tname##_item_tt
116
117#define ASN1_ITEM_TEMPLATE_END(tname) \
118 ;\
119 ASN1_ITEM_start(tname) \
120 ASN1_ITYPE_PRIMITIVE,\
121 -1,\
122 &tname##_item_tt,\
123 0,\
124 NULL,\
125 0,\
126 #tname \
127 ASN1_ITEM_end(tname)
128
129
130/* This is a ASN1 type which just embeds a template */
131
132/* This pair helps declare a SEQUENCE. We can do:
133 *
134 * ASN1_SEQUENCE(stname) = {
135 * ... SEQUENCE components ...
136 * } ASN1_SEQUENCE_END(stname)
137 *
138 * This will produce an ASN1_ITEM called stname_it
139 * for a structure called stname.
140 *
141 * If you want the same structure but a different
142 * name then use:
143 *
144 * ASN1_SEQUENCE(itname) = {
145 * ... SEQUENCE components ...
146 * } ASN1_SEQUENCE_END_name(stname, itname)
147 *
148 * This will create an item called itname_it using
149 * a structure called stname.
150 */
151
152#define ASN1_SEQUENCE(tname) \
153 const static ASN1_TEMPLATE tname##_seq_tt[]
154
155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
156
157#define ASN1_SEQUENCE_END_name(stname, tname) \
158 ;\
159 ASN1_ITEM_start(tname) \
160 ASN1_ITYPE_SEQUENCE,\
161 V_ASN1_SEQUENCE,\
162 tname##_seq_tt,\
163 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
164 NULL,\
165 sizeof(stname),\
166 #stname \
167 ASN1_ITEM_end(tname)
168
169#define ASN1_SEQUENCE_cb(tname, cb) \
170 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
171 ASN1_SEQUENCE(tname)
172
173#define ASN1_BROKEN_SEQUENCE(tname) \
174 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
175 ASN1_SEQUENCE(tname)
176
177#define ASN1_SEQUENCE_ref(tname, cb, lck) \
178 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
179 ASN1_SEQUENCE(tname)
180
181#define ASN1_SEQUENCE_enc(tname, enc, cb) \
182 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
183 ASN1_SEQUENCE(tname)
184
185#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
186
187#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
188
189#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
190
191#define ASN1_SEQUENCE_END_ref(stname, tname) \
192 ;\
193 ASN1_ITEM_start(tname) \
194 ASN1_ITYPE_SEQUENCE,\
195 V_ASN1_SEQUENCE,\
196 tname##_seq_tt,\
197 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
198 &tname##_aux,\
199 sizeof(stname),\
200 #stname \
201 ASN1_ITEM_end(tname)
202
203
204/* This pair helps declare a CHOICE type. We can do:
205 *
206 * ASN1_CHOICE(chname) = {
207 * ... CHOICE options ...
208 * ASN1_CHOICE_END(chname)
209 *
210 * This will produce an ASN1_ITEM called chname_it
211 * for a structure called chname. The structure
212 * definition must look like this:
213 * typedef struct {
214 * int type;
215 * union {
216 * ASN1_SOMETHING *opt1;
217 * ASN1_SOMEOTHER *opt2;
218 * } value;
219 * } chname;
220 *
221 * the name of the selector must be 'type'.
222 * to use an alternative selector name use the
223 * ASN1_CHOICE_END_selector() version.
224 */
225
226#define ASN1_CHOICE(tname) \
227 const static ASN1_TEMPLATE tname##_ch_tt[]
228
229#define ASN1_CHOICE_cb(tname, cb) \
230 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
231 ASN1_CHOICE(tname)
232
233#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
234
235#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
236
237#define ASN1_CHOICE_END_selector(stname, tname, selname) \
238 ;\
239 ASN1_ITEM_start(tname) \
240 ASN1_ITYPE_CHOICE,\
241 offsetof(stname,selname) ,\
242 tname##_ch_tt,\
243 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
244 NULL,\
245 sizeof(stname),\
246 #stname \
247 ASN1_ITEM_end(tname)
248
249#define ASN1_CHOICE_END_cb(stname, tname, selname) \
250 ;\
251 ASN1_ITEM_start(tname) \
252 ASN1_ITYPE_CHOICE,\
253 offsetof(stname,selname) ,\
254 tname##_ch_tt,\
255 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
256 &tname##_aux,\
257 sizeof(stname),\
258 #stname \
259 ASN1_ITEM_end(tname)
260
261/* This helps with the template wrapper form of ASN1_ITEM */
262
263#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
264 (flags), (tag), 0,\
265 #name, ASN1_ITEM_ref(type) }
266
267/* These help with SEQUENCE or CHOICE components */
268
269/* used to declare other types */
270
271#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
272 (flags), (tag), offsetof(stname, field),\
273 #field, ASN1_ITEM_ref(type) }
274
275/* used when the structure is combined with the parent */
276
277#define ASN1_EX_COMBINE(flags, tag, type) { \
278 (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
279
280/* implicit and explicit helper macros */
281
282#define ASN1_IMP_EX(stname, field, type, tag, ex) \
283 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
284
285#define ASN1_EXP_EX(stname, field, type, tag, ex) \
286 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
287
288/* Any defined by macros: the field used is in the table itself */
289
290#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
291#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
292#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
293#else
294#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
295#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
296#endif
297/* Plain simple type */
298#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
299
300/* OPTIONAL simple type */
301#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
302
303/* IMPLICIT tagged simple type */
304#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
305
306/* IMPLICIT tagged OPTIONAL simple type */
307#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
308
309/* Same as above but EXPLICIT */
310
311#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
312#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
313
314/* SEQUENCE OF type */
315#define ASN1_SEQUENCE_OF(stname, field, type) \
316 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
317
318/* OPTIONAL SEQUENCE OF */
319#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
320 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
321
322/* Same as above but for SET OF */
323
324#define ASN1_SET_OF(stname, field, type) \
325 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
326
327#define ASN1_SET_OF_OPT(stname, field, type) \
328 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
329
330/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
331
332#define ASN1_IMP_SET_OF(stname, field, type, tag) \
333 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
334
335#define ASN1_EXP_SET_OF(stname, field, type, tag) \
336 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
337
338#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
339 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
340
341#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
342 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
343
344#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
345 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
346
347#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
348 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
349
350#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
351 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
352
353#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)
355
356/* Macros for the ASN1_ADB structure */
357
358#define ASN1_ADB(name) \
359 const static ASN1_ADB_TABLE name##_adbtbl[]
360
361#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
362
363#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
364 ;\
365 const static ASN1_ADB name##_adb = {\
366 flags,\
367 offsetof(name, field),\
368 app_table,\
369 name##_adbtbl,\
370 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
371 def,\
372 none\
373 }
374
375#else
376
377#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
378 ;\
379 const static ASN1_ITEM *name##_adb(void) \
380 { \
381 const static ASN1_ADB internal_adb = \
382 {\
383 flags,\
384 offsetof(name, field),\
385 app_table,\
386 name##_adbtbl,\
387 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
388 def,\
389 none\
390 }; \
391 return (const ASN1_ITEM *) &internal_adb; \
392 } \
393 void dummy_function(void)
394
395#endif
396
397#define ADB_ENTRY(val, template) {val, template}
398
399#define ASN1_ADB_TEMPLATE(name) \
400 const static ASN1_TEMPLATE name##_tt
401
402/* This is the ASN1 template structure that defines
403 * a wrapper round the actual type. It determines the
404 * actual position of the field in the value structure,
405 * various flags such as OPTIONAL and the field name.
406 */
407
408struct ASN1_TEMPLATE_st {
409unsigned long flags; /* Various flags */
410long tag; /* tag, not used if no tagging */
411unsigned long offset; /* Offset of this field in structure */
412#ifndef NO_ASN1_FIELD_NAMES
413char *field_name; /* Field name */
414#endif
415ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
416};
417
418/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
419
420#define ASN1_TEMPLATE_item(t) (t->item_ptr)
421#define ASN1_TEMPLATE_adb(t) (t->item_ptr)
422
423typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
424typedef struct ASN1_ADB_st ASN1_ADB;
425
426struct ASN1_ADB_st {
427 unsigned long flags; /* Various flags */
428 unsigned long offset; /* Offset of selector field */
429 STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */
430 const ASN1_ADB_TABLE *tbl; /* Table of possible types */
431 long tblcount; /* Number of entries in tbl */
432 const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
433 const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
434};
435
436struct ASN1_ADB_TABLE_st {
437 long value; /* NID for an object or value for an int */
438 const ASN1_TEMPLATE tt; /* item for this value */
439};
440
441/* template flags */
442
443/* Field is optional */
444#define ASN1_TFLG_OPTIONAL (0x1)
445
446/* Field is a SET OF */
447#define ASN1_TFLG_SET_OF (0x1 << 1)
448
449/* Field is a SEQUENCE OF */
450#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
451
452/* Special case: this refers to a SET OF that
453 * will be sorted into DER order when encoded *and*
454 * the corresponding STACK will be modified to match
455 * the new order.
456 */
457#define ASN1_TFLG_SET_ORDER (0x3 << 1)
458
459/* Mask for SET OF or SEQUENCE OF */
460#define ASN1_TFLG_SK_MASK (0x3 << 1)
461
462/* These flags mean the tag should be taken from the
463 * tag field. If EXPLICIT then the underlying type
464 * is used for the inner tag.
465 */
466
467/* IMPLICIT tagging */
468#define ASN1_TFLG_IMPTAG (0x1 << 3)
469
470
471/* EXPLICIT tagging, inner tag from underlying type */
472#define ASN1_TFLG_EXPTAG (0x2 << 3)
473
474#define ASN1_TFLG_TAG_MASK (0x3 << 3)
475
476/* context specific IMPLICIT */
477#define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
478
479/* context specific EXPLICIT */
480#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
481
482/* If tagging is in force these determine the
483 * type of tag to use. Otherwise the tag is
484 * determined by the underlying type. These
485 * values reflect the actual octet format.
486 */
487
488/* Universal tag */
489#define ASN1_TFLG_UNIVERSAL (0x0<<6)
490/* Application tag */
491#define ASN1_TFLG_APPLICATION (0x1<<6)
492/* Context specific tag */
493#define ASN1_TFLG_CONTEXT (0x2<<6)
494/* Private tag */
495#define ASN1_TFLG_PRIVATE (0x3<<6)
496
497#define ASN1_TFLG_TAG_CLASS (0x3<<6)
498
499/* These are for ANY DEFINED BY type. In this case
500 * the 'item' field points to an ASN1_ADB structure
501 * which contains a table of values to decode the
502 * relevant type
503 */
504
505#define ASN1_TFLG_ADB_MASK (0x3<<8)
506
507#define ASN1_TFLG_ADB_OID (0x1<<8)
508
509#define ASN1_TFLG_ADB_INT (0x1<<9)
510
511/* This flag means a parent structure is passed
512 * instead of the field: this is useful is a
513 * SEQUENCE is being combined with a CHOICE for
514 * example. Since this means the structure and
515 * item name will differ we need to use the
516 * ASN1_CHOICE_END_name() macro for example.
517 */
518
519#define ASN1_TFLG_COMBINE (0x1<<10)
520
521/* This is the actual ASN1 item itself */
522
523struct ASN1_ITEM_st {
524char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
525long utype; /* underlying type */
526const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */
527long tcount; /* Number of templates if SEQUENCE or CHOICE */
528const void *funcs; /* functions that handle this type */
529long size; /* Structure size (usually)*/
530#ifndef NO_ASN1_FIELD_NAMES
531const char *sname; /* Structure name */
532#endif
533};
534
535/* These are values for the itype field and
536 * determine how the type is interpreted.
537 *
538 * For PRIMITIVE types the underlying type
539 * determines the behaviour if items is NULL.
540 *
541 * Otherwise templates must contain a single
542 * template and the type is treated in the
543 * same way as the type specified in the template.
544 *
545 * For SEQUENCE types the templates field points
546 * to the members, the size field is the
547 * structure size.
548 *
549 * For CHOICE types the templates field points
550 * to each possible member (typically a union)
551 * and the 'size' field is the offset of the
552 * selector.
553 *
554 * The 'funcs' field is used for application
555 * specific functions.
556 *
557 * For COMPAT types the funcs field gives a
558 * set of functions that handle this type, this
559 * supports the old d2i, i2d convention.
560 *
561 * The EXTERN type uses a new style d2i/i2d.
562 * The new style should be used where possible
563 * because it avoids things like the d2i IMPLICIT
564 * hack.
565 *
566 * MSTRING is a multiple string type, it is used
567 * for a CHOICE of character strings where the
568 * actual strings all occupy an ASN1_STRING
569 * structure. In this case the 'utype' field
570 * has a special meaning, it is used as a mask
571 * of acceptable types using the B_ASN1 constants.
572 *
573 */
574
575#define ASN1_ITYPE_PRIMITIVE 0x0
576
577#define ASN1_ITYPE_SEQUENCE 0x1
578
579#define ASN1_ITYPE_CHOICE 0x2
580
581#define ASN1_ITYPE_COMPAT 0x3
582
583#define ASN1_ITYPE_EXTERN 0x4
584
585#define ASN1_ITYPE_MSTRING 0x5
586
587/* Cache for ASN1 tag and length, so we
588 * don't keep re-reading it for things
589 * like CHOICE
590 */
591
592struct ASN1_TLC_st{
593 char valid; /* Values below are valid */
594 int ret; /* return value */
595 long plen; /* length */
596 int ptag; /* class value */
597 int pclass; /* class value */
598 int hdrlen; /* header length */
599};
600
601/* Typedefs for ASN1 function pointers */
602
603typedef ASN1_VALUE * ASN1_new_func(void);
604typedef void ASN1_free_func(ASN1_VALUE *a);
605typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, unsigned char ** in, long length);
606typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
607
608typedef int ASN1_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
609 int tag, int aclass, char opt, ASN1_TLC *ctx);
610
611typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
612typedef 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);
614
615typedef 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);
617
618typedef struct ASN1_COMPAT_FUNCS_st {
619 ASN1_new_func *asn1_new;
620 ASN1_free_func *asn1_free;
621 ASN1_d2i_func *asn1_d2i;
622 ASN1_i2d_func *asn1_i2d;
623} ASN1_COMPAT_FUNCS;
624
625typedef struct ASN1_EXTERN_FUNCS_st {
626 void *app_data;
627 ASN1_ex_new_func *asn1_ex_new;
628 ASN1_ex_free_func *asn1_ex_free;
629 ASN1_ex_free_func *asn1_ex_clear;
630 ASN1_ex_d2i *asn1_ex_d2i;
631 ASN1_ex_i2d *asn1_ex_i2d;
632} ASN1_EXTERN_FUNCS;
633
634typedef struct ASN1_PRIMITIVE_FUNCS_st {
635 void *app_data;
636 unsigned long flags;
637 ASN1_ex_new_func *prim_new;
638 ASN1_ex_free_func *prim_free;
639 ASN1_ex_free_func *prim_clear;
640 ASN1_primitive_c2i *prim_c2i;
641 ASN1_primitive_i2c *prim_i2c;
642} ASN1_PRIMITIVE_FUNCS;
643
644/* This is the ASN1_AUX structure: it handles various
645 * miscellaneous requirements. For example the use of
646 * reference counts and an informational callback.
647 *
648 * The "informational callback" is called at various
649 * points during the ASN1 encoding and decoding. It can
650 * be used to provide minor customisation of the structures
651 * used. This is most useful where the supplied routines
652 * *almost* do the right thing but need some extra help
653 * at a few points. If the callback returns zero then
654 * it is assumed a fatal error has occurred and the
655 * main operation should be abandoned.
656 *
657 * If major changes in the default behaviour are required
658 * then an external type is more appropriate.
659 */
660
661typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);
662
663typedef struct ASN1_AUX_st {
664 void *app_data;
665 int flags;
666 int ref_offset; /* Offset of reference value */
667 int ref_lock; /* Lock type to use */
668 ASN1_aux_cb *asn1_cb;
669 int enc_offset; /* Offset of ASN1_ENCODING structure */
670} ASN1_AUX;
671
672/* Flags in ASN1_AUX */
673
674/* Use a reference count */
675#define ASN1_AFLG_REFCOUNT 1
676/* Save the encoding of structure (useful for signatures) */
677#define ASN1_AFLG_ENCODING 2
678/* The Sequence length is invalid */
679#define ASN1_AFLG_BROKEN 4
680
681/* operation values for asn1_cb */
682
683#define ASN1_OP_NEW_PRE 0
684#define ASN1_OP_NEW_POST 1
685#define ASN1_OP_FREE_PRE 2
686#define ASN1_OP_FREE_POST 3
687#define ASN1_OP_D2I_PRE 4
688#define ASN1_OP_D2I_POST 5
689#define ASN1_OP_I2D_PRE 6
690#define ASN1_OP_I2D_POST 7
691
692/* Macro to implement a primitive type */
693#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
694#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
695 ASN1_ITEM_start(itname) \
696 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
697 ASN1_ITEM_end(itname)
698
699/* Macro to implement a multi string type */
700#define IMPLEMENT_ASN1_MSTRING(itname, mask) \
701 ASN1_ITEM_start(itname) \
702 ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
703 ASN1_ITEM_end(itname)
704
705/* Macro to implement an ASN1_ITEM in terms of old style funcs */
706
707#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)
708
709#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \
710 static const ASN1_COMPAT_FUNCS sname##_ff = { \
711 (ASN1_new_func *)sname##_new, \
712 (ASN1_free_func *)sname##_free, \
713 (ASN1_d2i_func *)d2i_##sname, \
714 (ASN1_i2d_func *)i2d_##sname, \
715 }; \
716 ASN1_ITEM_start(sname) \
717 ASN1_ITYPE_COMPAT, \
718 tag, \
719 NULL, \
720 0, \
721 &sname##_ff, \
722 0, \
723 #sname \
724 ASN1_ITEM_end(sname)
725
726#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
727 ASN1_ITEM_start(sname) \
728 ASN1_ITYPE_EXTERN, \
729 tag, \
730 NULL, \
731 0, \
732 &fptrs, \
733 0, \
734 #sname \
735 ASN1_ITEM_end(sname)
736
737/* Macro to implement standard functions in terms of ASN1_ITEM structures */
738
739#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
740
741#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
742
743#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
744 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
745
746#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
747 stname *fname##_new(void) \
748 { \
749 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
750 } \
751 void fname##_free(stname *a) \
752 { \
753 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
754 }
755
756#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
757 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
758 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
759
760#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
761 stname *d2i_##fname(stname **a, unsigned char **in, long len) \
762 { \
763 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
764 } \
765 int i2d_##fname(stname *a, unsigned char **out) \
766 { \
767 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
768 }
769
770/* This includes evil casts to remove const: they will go away when full
771 * ASN1 constification is done.
772 */
773#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
774 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
775 { \
776 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, (unsigned char **)in, len, ASN1_ITEM_rptr(itname));\
777 } \
778 int i2d_##fname(const stname *a, unsigned char **out) \
779 { \
780 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
781 }
782
783#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
784 stname * stname##_dup(stname *x) \
785 { \
786 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
787 }
788
789#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
790 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
791
792#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
793 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
794 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
795
796/* external definitions for primitive types */
797
798DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
799DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
800DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
801DECLARE_ASN1_ITEM(ASN1_ANY)
802DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
803DECLARE_ASN1_ITEM(CBIGNUM)
804DECLARE_ASN1_ITEM(BIGNUM)
805DECLARE_ASN1_ITEM(LONG)
806DECLARE_ASN1_ITEM(ZLONG)
807
808DECLARE_STACK_OF(ASN1_VALUE)
809
810/* Functions used internally by the ASN1 code */
811
812int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
813void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
814int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
815int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
816
817void 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);
819int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
820 int tag, int aclass, char opt, ASN1_TLC *ctx);
821
822int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
823int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt);
824void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
825
826int 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);
828
829int 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);
831
832ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
833
834const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
835
836int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
837
838void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
839void 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);
841int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it);
842
843#ifdef __cplusplus
844}
845#endif
846#endif
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c
new file mode 100644
index 0000000000..be20db4bad
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn_moid.c
@@ -0,0 +1,95 @@
1/* asn_moid.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 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 <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65
66/* Simple ASN1 OID module: add all objects in a given section */
67
68static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
69 {
70 int i;
71 const char *oid_section;
72 STACK_OF(CONF_VALUE) *sktmp;
73 CONF_VALUE *oval;
74 oid_section = CONF_imodule_get_value(md);
75 if(!(sktmp = NCONF_get_section(cnf, oid_section)))
76 {
77 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
78 return 0;
79 }
80 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
81 {
82 oval = sk_CONF_VALUE_value(sktmp, i);
83 if(OBJ_create(oval->value, oval->name, oval->name) == NID_undef)
84 {
85 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
86 return 0;
87 }
88 }
89 return 1;
90}
91
92void ASN1_add_oid_module(void)
93 {
94 CONF_module_add("oid_section", oid_module_init, 0);
95 }
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
new file mode 100644
index 0000000000..e6051db2dc
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn_pack.c
@@ -0,0 +1,191 @@
1/* asn_pack.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63#ifndef NO_ASN1_OLD
64
65/* ASN1 packing and unpacking functions */
66
67/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
68
69STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
70 void (*free_func)(void *))
71{
72 STACK *sk;
73 unsigned char *pbuf;
74 pbuf = buf;
75 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
76 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
77 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
78 return sk;
79}
80
81/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
82 * OPENSSL_malloc'ed buffer
83 */
84
85unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
86 int *len)
87{
88 int safelen;
89 unsigned char *safe, *p;
90 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
91 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
92 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
93 return NULL;
94 }
95 if (!(safe = OPENSSL_malloc (safelen))) {
96 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
97 return NULL;
98 }
99 p = safe;
100 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
101 IS_SEQUENCE);
102 if (len) *len = safelen;
103 if (buf) *buf = safe;
104 return safe;
105}
106
107/* Extract an ASN1 object from an ASN1_STRING */
108
109void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
110{
111 unsigned char *p;
112 char *ret;
113
114 p = oct->data;
115 if(!(ret = d2i(NULL, &p, oct->length)))
116 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
117 return ret;
118}
119
120/* Pack an ASN1 object into an ASN1_STRING */
121
122ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_STRING **oct)
123{
124 unsigned char *p;
125 ASN1_STRING *octmp;
126
127 if (!oct || !*oct) {
128 if (!(octmp = ASN1_STRING_new ())) {
129 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
130 return NULL;
131 }
132 if (oct) *oct = octmp;
133 } else octmp = *oct;
134
135 if (!(octmp->length = i2d(obj, NULL))) {
136 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
137 return NULL;
138 }
139 if (!(p = OPENSSL_malloc (octmp->length))) {
140 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
141 return NULL;
142 }
143 octmp->data = p;
144 i2d (obj, &p);
145 return octmp;
146}
147
148#endif
149
150/* ASN1_ITEM versions of the above */
151
152ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
153{
154 ASN1_STRING *octmp;
155
156 if (!oct || !*oct) {
157 if (!(octmp = ASN1_STRING_new ())) {
158 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
159 return NULL;
160 }
161 if (oct) *oct = octmp;
162 } else octmp = *oct;
163
164 if(octmp->data) {
165 OPENSSL_free(octmp->data);
166 octmp->data = NULL;
167 }
168
169 if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
170 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
171 return NULL;
172 }
173 if (!octmp->data) {
174 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
175 return NULL;
176 }
177 return octmp;
178}
179
180/* Extract an ASN1 object from an ASN1_STRING */
181
182void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
183{
184 unsigned char *p;
185 void *ret;
186
187 p = oct->data;
188 if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
189 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
190 return ret;
191}
diff --git a/src/lib/libcrypto/asn1/charmap.h b/src/lib/libcrypto/asn1/charmap.h
new file mode 100644
index 0000000000..bd020a9562
--- /dev/null
+++ b/src/lib/libcrypto/asn1/charmap.h
@@ -0,0 +1,15 @@
1/* Auto generated with chartype.pl script.
2 * Mask of various character properties
3 */
4
5static unsigned char char_type[] = {
6 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
8120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16,
916,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16,
10 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1116,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0,
12 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1316,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2
14};
15
diff --git a/src/lib/libcrypto/asn1/charmap.pl b/src/lib/libcrypto/asn1/charmap.pl
new file mode 100644
index 0000000000..2875c59867
--- /dev/null
+++ b/src/lib/libcrypto/asn1/charmap.pl
@@ -0,0 +1,80 @@
1#!/usr/local/bin/perl -w
2
3use strict;
4
5my ($i, @arr);
6
7# Set up an array with the type of ASCII characters
8# Each set bit represents a character property.
9
10# RFC2253 character properties
11my $RFC2253_ESC = 1; # Character escaped with \
12my $ESC_CTRL = 2; # Escaped control character
13# These are used with RFC1779 quoting using "
14my $NOESC_QUOTE = 8; # Not escaped if quoted
15my $PSTRING_CHAR = 0x10; # Valid PrintableString character
16my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character
17my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character
18
19for($i = 0; $i < 128; $i++) {
20 # Set the RFC2253 escape characters (control)
21 $arr[$i] = 0;
22 if(($i < 32) || ($i > 126)) {
23 $arr[$i] |= $ESC_CTRL;
24 }
25
26 # Some PrintableString characters
27 if( ( ( $i >= ord("a")) && ( $i <= ord("z")) )
28 || ( ( $i >= ord("A")) && ( $i <= ord("Z")) )
29 || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) {
30 $arr[$i] |= $PSTRING_CHAR;
31 }
32}
33
34# Now setup the rest
35
36# Remaining RFC2253 escaped characters
37
38$arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC;
39$arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC;
40
41$arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC;
42$arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC;
43$arr[ord("\"")] |= $RFC2253_ESC;
44$arr[ord("\\")] |= $RFC2253_ESC;
45$arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC;
46$arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC;
47$arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC;
48
49# Remaining PrintableString characters
50
51$arr[ord(" ")] |= $PSTRING_CHAR;
52$arr[ord("'")] |= $PSTRING_CHAR;
53$arr[ord("(")] |= $PSTRING_CHAR;
54$arr[ord(")")] |= $PSTRING_CHAR;
55$arr[ord("+")] |= $PSTRING_CHAR;
56$arr[ord(",")] |= $PSTRING_CHAR;
57$arr[ord("-")] |= $PSTRING_CHAR;
58$arr[ord(".")] |= $PSTRING_CHAR;
59$arr[ord("/")] |= $PSTRING_CHAR;
60$arr[ord(":")] |= $PSTRING_CHAR;
61$arr[ord("=")] |= $PSTRING_CHAR;
62$arr[ord("?")] |= $PSTRING_CHAR;
63
64# Now generate the C code
65
66print <<EOF;
67/* Auto generated with chartype.pl script.
68 * Mask of various character properties
69 */
70
71static unsigned char char_type[] = {
72EOF
73
74for($i = 0; $i < 128; $i++) {
75 print("\n") if($i && (($i % 16) == 0));
76 printf("%2d", $arr[$i]);
77 print(",") if ($i != 127);
78}
79print("\n};\n\n");
80
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
new file mode 100644
index 0000000000..2e7d96af90
--- /dev/null
+++ b/src/lib/libcrypto/asn1/d2i_pr.c
@@ -0,0 +1,145 @@
1/* crypto/asn1/d2i_pr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/asn1.h>
65#ifndef OPENSSL_NO_RSA
66#include <openssl/rsa.h>
67#endif
68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h>
70#endif
71
72EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
73 long length)
74 {
75 EVP_PKEY *ret;
76
77 if ((a == NULL) || (*a == NULL))
78 {
79 if ((ret=EVP_PKEY_new()) == NULL)
80 {
81 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
82 return(NULL);
83 }
84 }
85 else ret= *a;
86
87 ret->save_type=type;
88 ret->type=EVP_PKEY_type(type);
89 switch (ret->type)
90 {
91#ifndef OPENSSL_NO_RSA
92 case EVP_PKEY_RSA:
93 if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,
94 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
95 {
96 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
97 goto err;
98 }
99 break;
100#endif
101#ifndef OPENSSL_NO_DSA
102 case EVP_PKEY_DSA:
103 if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,
104 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
105 {
106 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
107 goto err;
108 }
109 break;
110#endif
111 default:
112 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
113 goto err;
114 /* break; */
115 }
116 if (a != NULL) (*a)=ret;
117 return(ret);
118err:
119 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
120 return(NULL);
121 }
122
123/* This works like d2i_PrivateKey() except it automatically works out the type */
124
125EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
126 long length)
127{
128 STACK_OF(ASN1_TYPE) *inkey;
129 unsigned char *p;
130 int keytype;
131 p = *pp;
132 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
133 * by analyzing it we can determine the passed structure: this
134 * assumes the input is surrounded by an ASN1 SEQUENCE.
135 */
136 inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE,
137 ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
138 /* Since we only need to discern "traditional format" RSA and DSA
139 * keys we can just count the elements.
140 */
141 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
142 else keytype = EVP_PKEY_RSA;
143 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
144 return d2i_PrivateKey(keytype, a, pp, length);
145}
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c
new file mode 100644
index 0000000000..71f2eb361b
--- /dev/null
+++ b/src/lib/libcrypto/asn1/d2i_pu.c
@@ -0,0 +1,122 @@
1/* crypto/asn1/d2i_pu.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/asn1.h>
65#ifndef OPENSSL_NO_RSA
66#include <openssl/rsa.h>
67#endif
68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h>
70#endif
71
72EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
73 long length)
74 {
75 EVP_PKEY *ret;
76
77 if ((a == NULL) || (*a == NULL))
78 {
79 if ((ret=EVP_PKEY_new()) == NULL)
80 {
81 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
82 return(NULL);
83 }
84 }
85 else ret= *a;
86
87 ret->save_type=type;
88 ret->type=EVP_PKEY_type(type);
89 switch (ret->type)
90 {
91#ifndef OPENSSL_NO_RSA
92 case EVP_PKEY_RSA:
93 if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,
94 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
95 {
96 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
97 goto err;
98 }
99 break;
100#endif
101#ifndef OPENSSL_NO_DSA
102 case EVP_PKEY_DSA:
103 if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,
104 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
105 {
106 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
107 goto err;
108 }
109 break;
110#endif
111 default:
112 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
113 goto err;
114 /* break; */
115 }
116 if (a != NULL) (*a)=ret;
117 return(ret);
118err:
119 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
120 return(NULL);
121 }
122
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
new file mode 100644
index 0000000000..3506005a71
--- /dev/null
+++ b/src/lib/libcrypto/asn1/evp_asn1.c
@@ -0,0 +1,185 @@
1/* crypto/asn1/evp_asn1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63
64int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
65 {
66 ASN1_STRING *os;
67
68 if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0);
69 if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0);
70 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os);
71 return(1);
72 }
73
74/* int max_len: for returned value */
75int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data,
76 int max_len)
77 {
78 int ret,num;
79 unsigned char *p;
80
81 if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL))
82 {
83 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
84 return(-1);
85 }
86 p=M_ASN1_STRING_data(a->value.octet_string);
87 ret=M_ASN1_STRING_length(a->value.octet_string);
88 if (ret < max_len)
89 num=ret;
90 else
91 num=max_len;
92 memcpy(data,p,num);
93 return(ret);
94 }
95
96int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
97 int len)
98 {
99 int n,size;
100 ASN1_OCTET_STRING os,*osp;
101 ASN1_INTEGER in;
102 unsigned char *p;
103 unsigned char buf[32]; /* when they have 256bit longs,
104 * I'll be in trouble */
105 in.data=buf;
106 in.length=32;
107 os.data=data;
108 os.type=V_ASN1_OCTET_STRING;
109 os.length=len;
110 ASN1_INTEGER_set(&in,num);
111 n = i2d_ASN1_INTEGER(&in,NULL);
112 n+=M_i2d_ASN1_OCTET_STRING(&os,NULL);
113
114 size=ASN1_object_size(1,n,V_ASN1_SEQUENCE);
115
116 if ((osp=ASN1_STRING_new()) == NULL) return(0);
117 /* Grow the 'string' */
118 ASN1_STRING_set(osp,NULL,size);
119
120 M_ASN1_STRING_length_set(osp, size);
121 p=M_ASN1_STRING_data(osp);
122
123 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
124 i2d_ASN1_INTEGER(&in,&p);
125 M_i2d_ASN1_OCTET_STRING(&os,&p);
126
127 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp);
128 return(1);
129 }
130
131/* we return the actual length..., num may be missing, in which
132 * case, set it to zero */
133/* int max_len: for returned value */
134int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
135 int max_len)
136 {
137 int ret= -1,n;
138 ASN1_INTEGER *ai=NULL;
139 ASN1_OCTET_STRING *os=NULL;
140 unsigned char *p;
141 long length;
142 ASN1_CTX c;
143
144 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
145 {
146 goto err;
147 }
148 p=M_ASN1_STRING_data(a->value.sequence);
149 length=M_ASN1_STRING_length(a->value.sequence);
150
151 c.pp= &p;
152 c.p=p;
153 c.max=p+length;
154 c.error=ASN1_R_DATA_IS_WRONG;
155
156 M_ASN1_D2I_start_sequence();
157 c.q=c.p;
158 if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err;
159 c.slen-=(c.p-c.q);
160 c.q=c.p;
161 if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err;
162 c.slen-=(c.p-c.q);
163 if (!M_ASN1_D2I_end_sequence()) goto err;
164
165 if (num != NULL)
166 *num=ASN1_INTEGER_get(ai);
167
168 ret=M_ASN1_STRING_length(os);
169 if (max_len > ret)
170 n=ret;
171 else
172 n=max_len;
173
174 if (data != NULL)
175 memcpy(data,M_ASN1_STRING_data(os),n);
176 if (0)
177 {
178err:
179 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
180 }
181 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
182 if (ai != NULL) M_ASN1_INTEGER_free(ai);
183 return(ret);
184 }
185
diff --git a/src/lib/libcrypto/asn1/f.c b/src/lib/libcrypto/asn1/f.c
new file mode 100644
index 0000000000..82bccdfd51
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f.c
@@ -0,0 +1,80 @@
1/* crypto/asn1/f.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#include <stdio.h>
59#include <openssl/asn1.h>
60#include <openssl/err.h>
61
62main()
63 {
64 ASN1_TYPE *at;
65 char buf[512];
66 int n;
67 long l;
68
69 at=ASN1_TYPE_new();
70
71 n=ASN1_TYPE_set_int_octetstring(at,98736,"01234567",8);
72 printf("%d\n",n);
73 n=ASN1_TYPE_get_int_octetstring(at,&l,buf,8);
74 buf[8]='\0';
75 printf("%ld %d %d\n",l,n,buf[8]);
76 buf[8]='\0';
77 printf("%s\n",buf);
78 ERR_load_crypto_strings();
79 ERR_print_errors_fp(stderr);
80 }
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c
new file mode 100644
index 0000000000..56e3cc8df2
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f_enum.c
@@ -0,0 +1,207 @@
1/* crypto/asn1/f_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64/* Based on a_int.c: equivalent ENUMERATED functions */
65
66int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
67 {
68 int i,n=0;
69 static const char *h="0123456789ABCDEF";
70 char buf[2];
71
72 if (a == NULL) return(0);
73
74 if (a->length == 0)
75 {
76 if (BIO_write(bp,"00",2) != 2) goto err;
77 n=2;
78 }
79 else
80 {
81 for (i=0; i<a->length; i++)
82 {
83 if ((i != 0) && (i%35 == 0))
84 {
85 if (BIO_write(bp,"\\\n",2) != 2) goto err;
86 n+=2;
87 }
88 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
89 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
90 if (BIO_write(bp,buf,2) != 2) goto err;
91 n+=2;
92 }
93 }
94 return(n);
95err:
96 return(-1);
97 }
98
99int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
100 {
101 int ret=0;
102 int i,j,k,m,n,again,bufsize;
103 unsigned char *s=NULL,*sp;
104 unsigned char *bufp;
105 int num=0,slen=0,first=1;
106
107 bs->type=V_ASN1_ENUMERATED;
108
109 bufsize=BIO_gets(bp,buf,size);
110 for (;;)
111 {
112 if (bufsize < 1) goto err_sl;
113 i=bufsize;
114 if (buf[i-1] == '\n') buf[--i]='\0';
115 if (i == 0) goto err_sl;
116 if (buf[i-1] == '\r') buf[--i]='\0';
117 if (i == 0) goto err_sl;
118 again=(buf[i-1] == '\\');
119
120 for (j=0; j<i; j++)
121 {
122 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
123 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
124 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
125 {
126 i=j;
127 break;
128 }
129 }
130 buf[i]='\0';
131 /* We have now cleared all the crap off the end of the
132 * line */
133 if (i < 2) goto err_sl;
134
135 bufp=(unsigned char *)buf;
136 if (first)
137 {
138 first=0;
139 if ((bufp[0] == '0') && (buf[1] == '0'))
140 {
141 bufp+=2;
142 i-=2;
143 }
144 }
145 k=0;
146 i-=again;
147 if (i%2 != 0)
148 {
149 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS);
150 goto err;
151 }
152 i/=2;
153 if (num+i > slen)
154 {
155 if (s == NULL)
156 sp=(unsigned char *)OPENSSL_malloc(
157 (unsigned int)num+i*2);
158 else
159 sp=(unsigned char *)OPENSSL_realloc(s,
160 (unsigned int)num+i*2);
161 if (sp == NULL)
162 {
163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
164 if (s != NULL) OPENSSL_free(s);
165 goto err;
166 }
167 s=sp;
168 slen=num+i*2;
169 }
170 for (j=0; j<i; j++,k+=2)
171 {
172 for (n=0; n<2; n++)
173 {
174 m=bufp[k+n];
175 if ((m >= '0') && (m <= '9'))
176 m-='0';
177 else if ((m >= 'a') && (m <= 'f'))
178 m=m-'a'+10;
179 else if ((m >= 'A') && (m <= 'F'))
180 m=m-'A'+10;
181 else
182 {
183 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS);
184 goto err;
185 }
186 s[num+j]<<=4;
187 s[num+j]|=m;
188 }
189 }
190 num+=i;
191 if (again)
192 bufsize=BIO_gets(bp,buf,size);
193 else
194 break;
195 }
196 bs->length=num;
197 bs->data=s;
198 ret=1;
199err:
200 if (0)
201 {
202err_sl:
203 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE);
204 }
205 return(ret);
206 }
207
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c
new file mode 100644
index 0000000000..48cc3bfb90
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f_int.c
@@ -0,0 +1,220 @@
1/* crypto/asn1/f_int.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
65 {
66 int i,n=0;
67 static const char *h="0123456789ABCDEF";
68 char buf[2];
69
70 if (a == NULL) return(0);
71
72 if (a->type & V_ASN1_NEG)
73 {
74 if (BIO_write(bp, "-", 1) != 1) goto err;
75 n = 1;
76 }
77
78 if (a->length == 0)
79 {
80 if (BIO_write(bp,"00",2) != 2) goto err;
81 n += 2;
82 }
83 else
84 {
85 for (i=0; i<a->length; i++)
86 {
87 if ((i != 0) && (i%35 == 0))
88 {
89 if (BIO_write(bp,"\\\n",2) != 2) goto err;
90 n+=2;
91 }
92 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
93 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
94 if (BIO_write(bp,buf,2) != 2) goto err;
95 n+=2;
96 }
97 }
98 return(n);
99err:
100 return(-1);
101 }
102
103int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
104 {
105 int ret=0;
106 int i,j,k,m,n,again,bufsize;
107 unsigned char *s=NULL,*sp;
108 unsigned char *bufp;
109 int num=0,slen=0,first=1;
110
111 bs->type=V_ASN1_INTEGER;
112
113 bufsize=BIO_gets(bp,buf,size);
114 for (;;)
115 {
116 if (bufsize < 1) goto err_sl;
117 i=bufsize;
118 if (buf[i-1] == '\n') buf[--i]='\0';
119 if (i == 0) goto err_sl;
120 if (buf[i-1] == '\r') buf[--i]='\0';
121 if (i == 0) goto err_sl;
122 again=(buf[i-1] == '\\');
123
124 for (j=0; j<i; j++)
125 {
126#ifndef CHARSET_EBCDIC
127 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
128 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
129 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
130#else
131 /* This #ifdef is not strictly necessary, since
132 * the characters A...F a...f 0...9 are contiguous
133 * (yes, even in EBCDIC - but not the whole alphabet).
134 * Nevertheless, isxdigit() is faster.
135 */
136 if (!isxdigit(buf[j]))
137#endif
138 {
139 i=j;
140 break;
141 }
142 }
143 buf[i]='\0';
144 /* We have now cleared all the crap off the end of the
145 * line */
146 if (i < 2) goto err_sl;
147
148 bufp=(unsigned char *)buf;
149 if (first)
150 {
151 first=0;
152 if ((bufp[0] == '0') && (buf[1] == '0'))
153 {
154 bufp+=2;
155 i-=2;
156 }
157 }
158 k=0;
159 i-=again;
160 if (i%2 != 0)
161 {
162 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
163 goto err;
164 }
165 i/=2;
166 if (num+i > slen)
167 {
168 if (s == NULL)
169 sp=(unsigned char *)OPENSSL_malloc(
170 (unsigned int)num+i*2);
171 else
172 sp=(unsigned char *)OPENSSL_realloc(s,
173 (unsigned int)num+i*2);
174 if (sp == NULL)
175 {
176 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
177 if (s != NULL) OPENSSL_free(s);
178 goto err;
179 }
180 s=sp;
181 slen=num+i*2;
182 }
183 for (j=0; j<i; j++,k+=2)
184 {
185 for (n=0; n<2; n++)
186 {
187 m=bufp[k+n];
188 if ((m >= '0') && (m <= '9'))
189 m-='0';
190 else if ((m >= 'a') && (m <= 'f'))
191 m=m-'a'+10;
192 else if ((m >= 'A') && (m <= 'F'))
193 m=m-'A'+10;
194 else
195 {
196 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
197 goto err;
198 }
199 s[num+j]<<=4;
200 s[num+j]|=m;
201 }
202 }
203 num+=i;
204 if (again)
205 bufsize=BIO_gets(bp,buf,size);
206 else
207 break;
208 }
209 bs->length=num;
210 bs->data=s;
211 ret=1;
212err:
213 if (0)
214 {
215err_sl:
216 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
217 }
218 return(ret);
219 }
220
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
new file mode 100644
index 0000000000..968698a798
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f_string.c
@@ -0,0 +1,212 @@
1/* crypto/asn1/f_string.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
65 {
66 int i,n=0;
67 static const char *h="0123456789ABCDEF";
68 char buf[2];
69
70 if (a == NULL) return(0);
71
72 if (a->length == 0)
73 {
74 if (BIO_write(bp,"0",1) != 1) goto err;
75 n=1;
76 }
77 else
78 {
79 for (i=0; i<a->length; i++)
80 {
81 if ((i != 0) && (i%35 == 0))
82 {
83 if (BIO_write(bp,"\\\n",2) != 2) goto err;
84 n+=2;
85 }
86 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
87 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
88 if (BIO_write(bp,buf,2) != 2) goto err;
89 n+=2;
90 }
91 }
92 return(n);
93err:
94 return(-1);
95 }
96
97int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
98 {
99 int ret=0;
100 int i,j,k,m,n,again,bufsize;
101 unsigned char *s=NULL,*sp;
102 unsigned char *bufp;
103 int num=0,slen=0,first=1;
104
105 bufsize=BIO_gets(bp,buf,size);
106 for (;;)
107 {
108 if (bufsize < 1)
109 {
110 if (first)
111 break;
112 else
113 goto err_sl;
114 }
115 first=0;
116
117 i=bufsize;
118 if (buf[i-1] == '\n') buf[--i]='\0';
119 if (i == 0) goto err_sl;
120 if (buf[i-1] == '\r') buf[--i]='\0';
121 if (i == 0) goto err_sl;
122 again=(buf[i-1] == '\\');
123
124 for (j=i-1; j>0; j--)
125 {
126#ifndef CHARSET_EBCDIC
127 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
128 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
129 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
130#else
131 /* This #ifdef is not strictly necessary, since
132 * the characters A...F a...f 0...9 are contiguous
133 * (yes, even in EBCDIC - but not the whole alphabet).
134 * Nevertheless, isxdigit() is faster.
135 */
136 if (!isxdigit(buf[j]))
137#endif
138 {
139 i=j;
140 break;
141 }
142 }
143 buf[i]='\0';
144 /* We have now cleared all the crap off the end of the
145 * line */
146 if (i < 2) goto err_sl;
147
148 bufp=(unsigned char *)buf;
149
150 k=0;
151 i-=again;
152 if (i%2 != 0)
153 {
154 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS);
155 goto err;
156 }
157 i/=2;
158 if (num+i > slen)
159 {
160 if (s == NULL)
161 sp=(unsigned char *)OPENSSL_malloc(
162 (unsigned int)num+i*2);
163 else
164 sp=(unsigned char *)OPENSSL_realloc(s,
165 (unsigned int)num+i*2);
166 if (sp == NULL)
167 {
168 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
169 if (s != NULL) OPENSSL_free(s);
170 goto err;
171 }
172 s=sp;
173 slen=num+i*2;
174 }
175 for (j=0; j<i; j++,k+=2)
176 {
177 for (n=0; n<2; n++)
178 {
179 m=bufp[k+n];
180 if ((m >= '0') && (m <= '9'))
181 m-='0';
182 else if ((m >= 'a') && (m <= 'f'))
183 m=m-'a'+10;
184 else if ((m >= 'A') && (m <= 'F'))
185 m=m-'A'+10;
186 else
187 {
188 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS);
189 goto err;
190 }
191 s[num+j]<<=4;
192 s[num+j]|=m;
193 }
194 }
195 num+=i;
196 if (again)
197 bufsize=BIO_gets(bp,buf,size);
198 else
199 break;
200 }
201 bs->length=num;
202 bs->data=s;
203 ret=1;
204err:
205 if (0)
206 {
207err_sl:
208 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE);
209 }
210 return(ret);
211 }
212
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c
new file mode 100644
index 0000000000..1e951ae01d
--- /dev/null
+++ b/src/lib/libcrypto/asn1/i2d_pr.c
@@ -0,0 +1,90 @@
1/* crypto/asn1/i2d_pr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70
71int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
72 {
73#ifndef OPENSSL_NO_RSA
74 if (a->type == EVP_PKEY_RSA)
75 {
76 return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
77 }
78 else
79#endif
80#ifndef OPENSSL_NO_DSA
81 if (a->type == EVP_PKEY_DSA)
82 {
83 return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
84 }
85#endif
86
87 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
88 return(-1);
89 }
90
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c
new file mode 100644
index 0000000000..013d19bbf4
--- /dev/null
+++ b/src/lib/libcrypto/asn1/i2d_pu.c
@@ -0,0 +1,88 @@
1/* crypto/asn1/i2d_pu.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70
71int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
72 {
73 switch (a->type)
74 {
75#ifndef OPENSSL_NO_RSA
76 case EVP_PKEY_RSA:
77 return(i2d_RSAPublicKey(a->pkey.rsa,pp));
78#endif
79#ifndef OPENSSL_NO_DSA
80 case EVP_PKEY_DSA:
81 return(i2d_DSAPublicKey(a->pkey.dsa,pp));
82#endif
83 default:
84 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
85 return(-1);
86 }
87 }
88
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
new file mode 100644
index 0000000000..9146ee02c9
--- /dev/null
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -0,0 +1,333 @@
1/* crypto/asn1/n_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/asn1t.h>
65#include <openssl/asn1_mac.h>
66#include <openssl/evp.h>
67#include <openssl/x509.h>
68
69
70#ifndef OPENSSL_NO_RC4
71
72typedef struct netscape_pkey_st
73 {
74 long version;
75 X509_ALGOR *algor;
76 ASN1_OCTET_STRING *private_key;
77 } NETSCAPE_PKEY;
78
79typedef struct netscape_encrypted_pkey_st
80 {
81 ASN1_OCTET_STRING *os;
82 /* This is the same structure as DigestInfo so use it:
83 * although this isn't really anything to do with
84 * digests.
85 */
86 X509_SIG *enckey;
87 } NETSCAPE_ENCRYPTED_PKEY;
88
89
90ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = {
91 ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING),
92 ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG)
93} ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY)
94
95DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
96DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY)
97IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
98
99ASN1_SEQUENCE(NETSCAPE_PKEY) = {
100 ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG),
101 ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR),
102 ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING)
103} ASN1_SEQUENCE_END(NETSCAPE_PKEY)
104
105DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
106DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY)
107IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
108
109static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
110 int (*cb)(), int sgckey);
111
112int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)())
113{
114 return i2d_RSA_NET(a, pp, cb, 0);
115}
116
117int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey)
118 {
119 int i, j, ret = 0;
120 int rsalen, pkeylen, olen;
121 NETSCAPE_PKEY *pkey = NULL;
122 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
123 unsigned char buf[256],*zz;
124 unsigned char key[EVP_MAX_KEY_LENGTH];
125 EVP_CIPHER_CTX ctx;
126
127 if (a == NULL) return(0);
128
129 if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err;
130 if ((enckey=NETSCAPE_ENCRYPTED_PKEY_new()) == NULL) goto err;
131 pkey->version = 0;
132
133 pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption);
134 if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
135 pkey->algor->parameter->type=V_ASN1_NULL;
136
137 rsalen = i2d_RSAPrivateKey(a, NULL);
138
139 /* Fake some octet strings just for the initial length
140 * calculation.
141 */
142
143 pkey->private_key->length=rsalen;
144
145 pkeylen=i2d_NETSCAPE_PKEY(pkey,NULL);
146
147 enckey->enckey->digest->length = pkeylen;
148
149 enckey->os->length = 11; /* "private-key" */
150
151 enckey->enckey->algor->algorithm=OBJ_nid2obj(NID_rc4);
152 if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
153 enckey->enckey->algor->parameter->type=V_ASN1_NULL;
154
155 if (pp == NULL)
156 {
157 olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL);
158 NETSCAPE_PKEY_free(pkey);
159 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
160 return olen;
161 }
162
163
164 /* Since its RC4 encrypted length is actual length */
165 if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL)
166 {
167 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
168 goto err;
169 }
170
171 pkey->private_key->data = zz;
172 /* Write out private key encoding */
173 i2d_RSAPrivateKey(a,&zz);
174
175 if ((zz=OPENSSL_malloc(pkeylen)) == NULL)
176 {
177 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
178 goto err;
179 }
180
181 if (!ASN1_STRING_set(enckey->os, "private-key", -1))
182 {
183 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
184 goto err;
185 }
186 enckey->enckey->digest->data = zz;
187 i2d_NETSCAPE_PKEY(pkey,&zz);
188
189 /* Wipe the private key encoding */
190 memset(pkey->private_key->data, 0, rsalen);
191
192 if (cb == NULL)
193 cb=EVP_read_pw_string;
194 i=cb(buf,256,"Enter Private Key password:",1);
195 if (i != 0)
196 {
197 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
198 goto err;
199 }
200 i = strlen((char *)buf);
201 /* If the key is used for SGC the algorithm is modified a little. */
202 if(sgckey) {
203 EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL);
204 memcpy(buf + 16, "SGCKEYSALT", 10);
205 i = 26;
206 }
207
208 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
209 memset(buf,0,256);
210
211 /* Encrypt private key in place */
212 zz = enckey->enckey->digest->data;
213 EVP_CIPHER_CTX_init(&ctx);
214 EVP_EncryptInit_ex(&ctx,EVP_rc4(),NULL,key,NULL);
215 EVP_EncryptUpdate(&ctx,zz,&i,zz,pkeylen);
216 EVP_EncryptFinal_ex(&ctx,zz + i,&j);
217 EVP_CIPHER_CTX_cleanup(&ctx);
218
219 ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp);
220err:
221 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
222 NETSCAPE_PKEY_free(pkey);
223 return(ret);
224 }
225
226
227RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)())
228{
229 return d2i_RSA_NET(a, pp, length, cb, 0);
230}
231
232RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey)
233 {
234 RSA *ret=NULL;
235 const unsigned char *p, *kp;
236 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
237
238 p = *pp;
239
240 enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length);
241 if(!enckey) {
242 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR);
243 return NULL;
244 }
245
246 if ((enckey->os->length != 11) || (strncmp("private-key",
247 (char *)enckey->os->data,11) != 0))
248 {
249 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
250 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
251 return NULL;
252 }
253 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4)
254 {
255 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
256 goto err;
257 }
258 kp = enckey->enckey->digest->data;
259 if (cb == NULL)
260 cb=EVP_read_pw_string;
261 if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err;
262
263 *pp = p;
264
265 err:
266 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
267 return ret;
268
269 }
270
271static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
272 int (*cb)(), int sgckey)
273 {
274 NETSCAPE_PKEY *pkey=NULL;
275 RSA *ret=NULL;
276 int i,j;
277 unsigned char buf[256];
278 const unsigned char *zz;
279 unsigned char key[EVP_MAX_KEY_LENGTH];
280 EVP_CIPHER_CTX ctx;
281
282 i=cb(buf,256,"Enter Private Key password:",0);
283 if (i != 0)
284 {
285 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
286 goto err;
287 }
288
289 i = strlen((char *)buf);
290 if(sgckey){
291 EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL);
292 memcpy(buf + 16, "SGCKEYSALT", 10);
293 i = 26;
294 }
295
296 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
297 memset(buf,0,256);
298
299 EVP_CIPHER_CTX_init(&ctx);
300 EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL);
301 EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length);
302 EVP_DecryptFinal_ex(&ctx,&(os->data[i]),&j);
303 EVP_CIPHER_CTX_cleanup(&ctx);
304 os->length=i+j;
305
306 zz=os->data;
307
308 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
309 {
310 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
311 goto err;
312 }
313
314 zz=pkey->private_key->data;
315 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
316 {
317 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
318 goto err;
319 }
320err:
321 NETSCAPE_PKEY_free(pkey);
322 return(ret);
323 }
324
325#endif /* OPENSSL_NO_RC4 */
326
327#else /* !OPENSSL_NO_RSA */
328
329# if PEDANTIC
330static void *dummy=&dummy;
331# endif
332
333#endif
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c
new file mode 100644
index 0000000000..50e2d4d07a
--- /dev/null
+++ b/src/lib/libcrypto/asn1/nsseq.c
@@ -0,0 +1,82 @@
1/* nsseq.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include <stdlib.h>
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/objects.h>
64
65static int nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 if(operation == ASN1_OP_NEW_POST) {
68 NETSCAPE_CERT_SEQUENCE *nsseq;
69 nsseq = (NETSCAPE_CERT_SEQUENCE *)*pval;
70 nsseq->type = OBJ_nid2obj(NID_netscape_cert_sequence);
71 }
72 return 1;
73}
74
75/* Netscape certificate sequence structure */
76
77ASN1_SEQUENCE_cb(NETSCAPE_CERT_SEQUENCE, nsseq_cb) = {
78 ASN1_SIMPLE(NETSCAPE_CERT_SEQUENCE, type, ASN1_OBJECT),
79 ASN1_EXP_SEQUENCE_OF_OPT(NETSCAPE_CERT_SEQUENCE, certs, X509, 0)
80} ASN1_SEQUENCE_END_cb(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
81
82IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE)
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
new file mode 100644
index 0000000000..891150638e
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p5_pbe.c
@@ -0,0 +1,122 @@
1/* p5_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 password based encryption structure */
66
67ASN1_SEQUENCE(PBEPARAM) = {
68 ASN1_SIMPLE(PBEPARAM, salt, ASN1_OCTET_STRING),
69 ASN1_SIMPLE(PBEPARAM, iter, ASN1_INTEGER)
70} ASN1_SEQUENCE_END(PBEPARAM)
71
72IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM)
73
74/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
75
76X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
77 int saltlen)
78{
79 PBEPARAM *pbe;
80 ASN1_OBJECT *al;
81 X509_ALGOR *algor;
82 ASN1_TYPE *astype;
83
84 if (!(pbe = PBEPARAM_new ())) {
85 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
86 return NULL;
87 }
88 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
89 ASN1_INTEGER_set (pbe->iter, iter);
90 if (!saltlen) saltlen = PKCS5_SALT_LEN;
91 if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) {
92 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
93 return NULL;
94 }
95 pbe->salt->length = saltlen;
96 if (salt) memcpy (pbe->salt->data, salt, saltlen);
97 else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0)
98 return NULL;
99
100 if (!(astype = ASN1_TYPE_new())) {
101 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104
105 astype->type = V_ASN1_SEQUENCE;
106 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
107 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
108 return NULL;
109 }
110 PBEPARAM_free (pbe);
111
112 al = OBJ_nid2obj(alg); /* never need to free al */
113 if (!(algor = X509_ALGOR_new())) {
114 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
115 return NULL;
116 }
117 ASN1_OBJECT_free(algor->algorithm);
118 algor->algorithm = al;
119 algor->parameter = astype;
120
121 return (algor);
122}
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
new file mode 100644
index 0000000000..91e1c8987d
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -0,0 +1,203 @@
1/* p5_pbev2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 v2.0 password based encryption structures */
66
67ASN1_SEQUENCE(PBE2PARAM) = {
68 ASN1_SIMPLE(PBE2PARAM, keyfunc, X509_ALGOR),
69 ASN1_SIMPLE(PBE2PARAM, encryption, X509_ALGOR)
70} ASN1_SEQUENCE_END(PBE2PARAM)
71
72IMPLEMENT_ASN1_FUNCTIONS(PBE2PARAM)
73
74ASN1_SEQUENCE(PBKDF2PARAM) = {
75 ASN1_SIMPLE(PBKDF2PARAM, salt, ASN1_ANY),
76 ASN1_SIMPLE(PBKDF2PARAM, iter, ASN1_INTEGER),
77 ASN1_OPT(PBKDF2PARAM, keylength, ASN1_INTEGER),
78 ASN1_OPT(PBKDF2PARAM, prf, X509_ALGOR)
79} ASN1_SEQUENCE_END(PBKDF2PARAM)
80
81IMPLEMENT_ASN1_FUNCTIONS(PBKDF2PARAM)
82
83/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
84 * yes I know this is horrible!
85 */
86
87X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
88 unsigned char *salt, int saltlen)
89{
90 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
91 int alg_nid;
92 EVP_CIPHER_CTX ctx;
93 unsigned char iv[EVP_MAX_IV_LENGTH];
94 PBKDF2PARAM *kdf = NULL;
95 PBE2PARAM *pbe2 = NULL;
96 ASN1_OCTET_STRING *osalt = NULL;
97 ASN1_OBJECT *obj;
98
99 alg_nid = EVP_CIPHER_type(cipher);
100 if(alg_nid == NID_undef) {
101 ASN1err(ASN1_F_PKCS5_PBE2_SET,
102 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
103 goto err;
104 }
105 obj = OBJ_nid2obj(alg_nid);
106
107 if(!(pbe2 = PBE2PARAM_new())) goto merr;
108
109 /* Setup the AlgorithmIdentifier for the encryption scheme */
110 scheme = pbe2->encryption;
111
112 scheme->algorithm = obj;
113 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
114
115 /* Create random IV */
116 if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
117 goto err;
118
119 EVP_CIPHER_CTX_init(&ctx);
120
121 /* Dummy cipherinit to just setup the IV */
122 EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0);
123 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
124 ASN1err(ASN1_F_PKCS5_PBE2_SET,
125 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
126 goto err;
127 }
128 EVP_CIPHER_CTX_cleanup(&ctx);
129
130 if(!(kdf = PBKDF2PARAM_new())) goto merr;
131 if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr;
132
133 if (!saltlen) saltlen = PKCS5_SALT_LEN;
134 if (!(osalt->data = OPENSSL_malloc (saltlen))) goto merr;
135 osalt->length = saltlen;
136 if (salt) memcpy (osalt->data, salt, saltlen);
137 else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr;
138
139 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
140 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
141
142 /* Now include salt in kdf structure */
143 kdf->salt->value.octet_string = osalt;
144 kdf->salt->type = V_ASN1_OCTET_STRING;
145 osalt = NULL;
146
147 /* If its RC2 then we'd better setup the key length */
148
149 if(alg_nid == NID_rc2_cbc) {
150 if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr;
151 if(!ASN1_INTEGER_set (kdf->keylength,
152 EVP_CIPHER_key_length(cipher))) goto merr;
153 }
154
155 /* prf can stay NULL because we are using hmacWithSHA1 */
156
157 /* Now setup the PBE2PARAM keyfunc structure */
158
159 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
160
161 /* Encode PBKDF2PARAM into parameter of pbe2 */
162
163 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
164
165 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
166 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
167 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
168
169 PBKDF2PARAM_free(kdf);
170 kdf = NULL;
171
172 /* Now set up top level AlgorithmIdentifier */
173
174 if(!(ret = X509_ALGOR_new())) goto merr;
175 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
176
177 ret->algorithm = OBJ_nid2obj(NID_pbes2);
178
179 /* Encode PBE2PARAM into parameter */
180
181 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
182 &ret->parameter->value.sequence)) goto merr;
183 ret->parameter->type = V_ASN1_SEQUENCE;
184
185 PBE2PARAM_free(pbe2);
186 pbe2 = NULL;
187
188 return ret;
189
190 merr:
191 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
192
193 err:
194 PBE2PARAM_free(pbe2);
195 /* Note 'scheme' is freed as part of pbe2 */
196 M_ASN1_OCTET_STRING_free(osalt);
197 PBKDF2PARAM_free(kdf);
198 X509_ALGOR_free(kalg);
199 X509_ALGOR_free(ret);
200
201 return NULL;
202
203}
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
new file mode 100644
index 0000000000..b634d5bc85
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p8_pkey.c
@@ -0,0 +1,84 @@
1/* p8_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64/* Minor tweak to operation: zero private key data */
65static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 /* Since the structure must still be valid use ASN1_OP_FREE_PRE */
68 if(operation == ASN1_OP_FREE_PRE) {
69 PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval;
70 if (key->pkey->value.octet_string)
71 memset(key->pkey->value.octet_string->data,
72 0, key->pkey->value.octet_string->length);
73 }
74 return 1;
75}
76
77ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = {
78 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER),
79 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR),
80 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_ANY),
81 ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0)
82} ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
83
84IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c
new file mode 100644
index 0000000000..8ee789f082
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_bitst.c
@@ -0,0 +1,99 @@
1/* t_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
65 BIT_STRING_BITNAME *tbl, int indent)
66{
67 BIT_STRING_BITNAME *bnam;
68 char first = 1;
69 BIO_printf(out, "%*s", indent, "");
70 for(bnam = tbl; bnam->lname; bnam++) {
71 if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
72 if(!first) BIO_puts(out, ", ");
73 BIO_puts(out, bnam->lname);
74 first = 0;
75 }
76 }
77 BIO_puts(out, "\n");
78 return 1;
79}
80
81int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
82 BIT_STRING_BITNAME *tbl)
83{
84 int bitnum;
85 bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
86 if(bitnum < 0) return 0;
87 if(bs) ASN1_BIT_STRING_set_bit(bs, bitnum, value);
88 return 1;
89}
90
91int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
92{
93 BIT_STRING_BITNAME *bnam;
94 for(bnam = tbl; bnam->lname; bnam++) {
95 if(!strcmp(bnam->sname, name) ||
96 !strcmp(bnam->lname, name) ) return bnam->bitnum;
97 }
98 return -1;
99}
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
new file mode 100644
index 0000000000..60db305756
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -0,0 +1,133 @@
1/* t_crl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67#ifndef OPENSSL_NO_FP_API
68int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
69 {
70 BIO *b;
71 int ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=X509_CRL_print(b, x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85int X509_CRL_print(BIO *out, X509_CRL *x)
86{
87 char buf[256];
88 STACK_OF(X509_REVOKED) *rev;
89 X509_REVOKED *r;
90 long l;
91 int i, n;
92
93 BIO_printf(out, "Certificate Revocation List (CRL):\n");
94 l = X509_CRL_get_version(x);
95 BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
96 i = OBJ_obj2nid(x->sig_alg->algorithm);
97 BIO_printf(out, "%8sSignature Algorithm: %s\n", "",
98 (i == NID_undef) ? "NONE" : OBJ_nid2ln(i));
99 X509_NAME_oneline(X509_CRL_get_issuer(x),buf,256);
100 BIO_printf(out,"%8sIssuer: %s\n","",buf);
101 BIO_printf(out,"%8sLast Update: ","");
102 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
103 BIO_printf(out,"\n%8sNext Update: ","");
104 if (X509_CRL_get_nextUpdate(x))
105 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
106 else BIO_printf(out,"NONE");
107 BIO_printf(out,"\n");
108
109 n=X509_CRL_get_ext_count(x);
110 X509V3_extensions_print(out, "CRL extensions",
111 x->crl->extensions, 0, 8);
112
113 rev = X509_CRL_get_REVOKED(x);
114
115 if(sk_X509_REVOKED_num(rev) > 0)
116 BIO_printf(out, "Revoked Certificates:\n");
117 else BIO_printf(out, "No Revoked Certificates.\n");
118
119 for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
120 r = sk_X509_REVOKED_value(rev, i);
121 BIO_printf(out," Serial Number: ");
122 i2a_ASN1_INTEGER(out,r->serialNumber);
123 BIO_printf(out,"\n Revocation Date: ","");
124 ASN1_TIME_print(out,r->revocationDate);
125 BIO_printf(out,"\n");
126 X509V3_extensions_print(out, "CRL entry extensions",
127 r->extensions, 0, 8);
128 }
129 X509_signature_print(out, x->sig_alg, x->signature);
130
131 return 1;
132
133}
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
new file mode 100644
index 0000000000..b3f8364012
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_pkey.c
@@ -0,0 +1,401 @@
1/* crypto/asn1/t_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#ifndef OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_NO_DH
67#include <openssl/dh.h>
68#endif
69#ifndef OPENSSL_NO_DSA
70#include <openssl/dsa.h>
71#endif
72
73static int print(BIO *fp,const char *str,BIGNUM *num,
74 unsigned char *buf,int off);
75#ifndef OPENSSL_NO_RSA
76#ifndef OPENSSL_NO_FP_API
77int RSA_print_fp(FILE *fp, const RSA *x, int off)
78 {
79 BIO *b;
80 int ret;
81
82 if ((b=BIO_new(BIO_s_file())) == NULL)
83 {
84 RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
85 return(0);
86 }
87 BIO_set_fp(b,fp,BIO_NOCLOSE);
88 ret=RSA_print(b,x,off);
89 BIO_free(b);
90 return(ret);
91 }
92#endif
93
94int RSA_print(BIO *bp, const RSA *x, int off)
95 {
96 char str[128];
97 const char *s;
98 unsigned char *m=NULL;
99 int ret=0;
100 size_t buf_len=0, i;
101
102 if (x->n)
103 buf_len = (size_t)BN_num_bytes(x->n);
104 if (x->e)
105 if (buf_len < (i = (size_t)BN_num_bytes(x->e)))
106 buf_len = i;
107 if (x->d)
108 if (buf_len < (i = (size_t)BN_num_bytes(x->d)))
109 buf_len = i;
110 if (x->p)
111 if (buf_len < (i = (size_t)BN_num_bytes(x->p)))
112 buf_len = i;
113 if (x->q)
114 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
115 buf_len = i;
116 if (x->dmp1)
117 if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1)))
118 buf_len = i;
119 if (x->dmq1)
120 if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1)))
121 buf_len = i;
122 if (x->iqmp)
123 if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp)))
124 buf_len = i;
125
126 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
127 if (m == NULL)
128 {
129 RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
130 goto err;
131 }
132
133 if (off)
134 {
135 if (off > 128) off=128;
136 memset(str,' ',off);
137 }
138 if (x->d != NULL)
139 {
140 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
141 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n))
142 <= 0) goto err;
143 }
144
145 if (x->d == NULL)
146 snprintf(str,sizeof str,"Modulus (%d bit):",BN_num_bits(x->n));
147 else
148 strlcpy(str,"modulus:",sizeof str);
149 if (!print(bp,str,x->n,m,off)) goto err;
150 s=(x->d == NULL)?"Exponent:":"publicExponent:";
151 if (!print(bp,s,x->e,m,off)) goto err;
152 if (!print(bp,"privateExponent:",x->d,m,off)) goto err;
153 if (!print(bp,"prime1:",x->p,m,off)) goto err;
154 if (!print(bp,"prime2:",x->q,m,off)) goto err;
155 if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err;
156 if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err;
157 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
158 ret=1;
159err:
160 if (m != NULL) OPENSSL_free(m);
161 return(ret);
162 }
163#endif /* OPENSSL_NO_RSA */
164
165#ifndef OPENSSL_NO_DSA
166#ifndef OPENSSL_NO_FP_API
167int DSA_print_fp(FILE *fp, const DSA *x, int off)
168 {
169 BIO *b;
170 int ret;
171
172 if ((b=BIO_new(BIO_s_file())) == NULL)
173 {
174 DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
175 return(0);
176 }
177 BIO_set_fp(b,fp,BIO_NOCLOSE);
178 ret=DSA_print(b,x,off);
179 BIO_free(b);
180 return(ret);
181 }
182#endif
183
184int DSA_print(BIO *bp, const DSA *x, int off)
185 {
186 char str[128];
187 unsigned char *m=NULL;
188 int ret=0;
189 size_t buf_len=0,i;
190
191 if (x->p)
192 buf_len = (size_t)BN_num_bytes(x->p);
193 if (x->q)
194 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
195 buf_len = i;
196 if (x->g)
197 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
198 buf_len = i;
199 if (x->priv_key)
200 if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key)))
201 buf_len = i;
202 if (x->pub_key)
203 if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key)))
204 buf_len = i;
205
206 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
207 if (m == NULL)
208 {
209 DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
210 goto err;
211 }
212
213 if (off)
214 {
215 if (off > 128) off=128;
216 memset(str,' ',off);
217 }
218 if (x->priv_key != NULL)
219 {
220 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
221 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p))
222 <= 0) goto err;
223 }
224
225 if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off))
226 goto err;
227 if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off))
228 goto err;
229 if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err;
230 if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err;
231 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err;
232 ret=1;
233err:
234 if (m != NULL) OPENSSL_free(m);
235 return(ret);
236 }
237#endif /* !OPENSSL_NO_DSA */
238
239static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
240 int off)
241 {
242 int n,i;
243 char str[128];
244 const char *neg;
245
246 if (num == NULL) return(1);
247 neg=(num->neg)?"-":"";
248 if (off)
249 {
250 if (off > 128) off=128;
251 memset(str,' ',off);
252 if (BIO_write(bp,str,off) <= 0) return(0);
253 }
254
255 if (BN_num_bytes(num) <= BN_BYTES)
256 {
257 if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
258 (unsigned long)num->d[0],neg,(unsigned long)num->d[0])
259 <= 0) return(0);
260 }
261 else
262 {
263 buf[0]=0;
264 if (BIO_printf(bp,"%s%s",number,
265 (neg[0] == '-')?" (Negative)":"") <= 0)
266 return(0);
267 n=BN_bn2bin(num,&buf[1]);
268
269 if (buf[1] & 0x80)
270 n++;
271 else buf++;
272
273 for (i=0; i<n; i++)
274 {
275 if ((i%15) == 0)
276 {
277 str[0]='\n';
278 memset(&(str[1]),' ',off+4);
279 if (BIO_write(bp,str,off+1+4) <= 0) return(0);
280 }
281 if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")
282 <= 0) return(0);
283 }
284 if (BIO_write(bp,"\n",1) <= 0) return(0);
285 }
286 return(1);
287 }
288
289#ifndef OPENSSL_NO_DH
290#ifndef OPENSSL_NO_FP_API
291int DHparams_print_fp(FILE *fp, const DH *x)
292 {
293 BIO *b;
294 int ret;
295
296 if ((b=BIO_new(BIO_s_file())) == NULL)
297 {
298 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
299 return(0);
300 }
301 BIO_set_fp(b,fp,BIO_NOCLOSE);
302 ret=DHparams_print(b, x);
303 BIO_free(b);
304 return(ret);
305 }
306#endif
307
308int DHparams_print(BIO *bp, const DH *x)
309 {
310 unsigned char *m=NULL;
311 int reason=ERR_R_BUF_LIB,ret=0;
312 size_t buf_len=0, i;
313
314 if (x->p)
315 buf_len = (size_t)BN_num_bytes(x->p);
316 if (x->g)
317 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
318 buf_len = i;
319 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
320 if (m == NULL)
321 {
322 reason=ERR_R_MALLOC_FAILURE;
323 goto err;
324 }
325
326 if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
327 BN_num_bits(x->p)) <= 0)
328 goto err;
329 if (!print(bp,"prime:",x->p,m,4)) goto err;
330 if (!print(bp,"generator:",x->g,m,4)) goto err;
331 if (x->length != 0)
332 {
333 if (BIO_printf(bp," recommended-private-length: %d bits\n",
334 (int)x->length) <= 0) goto err;
335 }
336 ret=1;
337 if (0)
338 {
339err:
340 DHerr(DH_F_DHPARAMS_PRINT,reason);
341 }
342 if (m != NULL) OPENSSL_free(m);
343 return(ret);
344 }
345#endif
346
347#ifndef OPENSSL_NO_DSA
348#ifndef OPENSSL_NO_FP_API
349int DSAparams_print_fp(FILE *fp, const DSA *x)
350 {
351 BIO *b;
352 int ret;
353
354 if ((b=BIO_new(BIO_s_file())) == NULL)
355 {
356 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
357 return(0);
358 }
359 BIO_set_fp(b,fp,BIO_NOCLOSE);
360 ret=DSAparams_print(b, x);
361 BIO_free(b);
362 return(ret);
363 }
364#endif
365
366int DSAparams_print(BIO *bp, const DSA *x)
367 {
368 unsigned char *m=NULL;
369 int reason=ERR_R_BUF_LIB,ret=0;
370 size_t buf_len=0,i;
371
372 if (x->p)
373 buf_len = (size_t)BN_num_bytes(x->p);
374 if (x->q)
375 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
376 buf_len = i;
377 if (x->g)
378 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
379 buf_len = i;
380 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
381 if (m == NULL)
382 {
383 reason=ERR_R_MALLOC_FAILURE;
384 goto err;
385 }
386
387 if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n",
388 BN_num_bits(x->p)) <= 0)
389 goto err;
390 if (!print(bp,"p:",x->p,m,4)) goto err;
391 if (!print(bp,"q:",x->q,m,4)) goto err;
392 if (!print(bp,"g:",x->g,m,4)) goto err;
393 ret=1;
394err:
395 if (m != NULL) OPENSSL_free(m);
396 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
397 return(ret);
398 }
399
400#endif /* !OPENSSL_NO_DSA */
401
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
new file mode 100644
index 0000000000..eca97e00cb
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -0,0 +1,277 @@
1/* crypto/asn1/t_req.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67#ifndef OPENSSL_NO_FP_API
68int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
69 {
70 BIO *b;
71 int ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=X509_REQ_print(b, x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag)
86 {
87 unsigned long l;
88 int i;
89 const char *neg;
90 X509_REQ_INFO *ri;
91 EVP_PKEY *pkey;
92 STACK_OF(X509_ATTRIBUTE) *sk;
93 STACK_OF(X509_EXTENSION) *exts;
94 char str[128];
95 char mlch = ' ';
96 int nmindent = 0;
97
98 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
99 mlch = '\n';
100 nmindent = 12;
101 }
102
103 if(nmflags == X509_FLAG_COMPAT)
104 nmindent = 16;
105
106
107 ri=x->req_info;
108 if(!(cflag & X509_FLAG_NO_HEADER))
109 {
110 if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err;
111 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
112 }
113 if(!(cflag & X509_FLAG_NO_VERSION))
114 {
115 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
116 l=0;
117 for (i=0; i<ri->version->length; i++)
118 { l<<=8; l+=ri->version->data[i]; }
119 snprintf(str,sizeof str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,
120 l,neg,l);
121 if (BIO_puts(bp,str) <= 0) goto err;
122 }
123 if(!(cflag & X509_FLAG_NO_SUBJECT))
124 {
125 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
126 if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err;
127 if (BIO_write(bp,"\n",1) <= 0) goto err;
128 }
129 if(!(cflag & X509_FLAG_NO_PUBKEY))
130 {
131 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
132 goto err;
133 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
134 goto err;
135 if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
136 goto err;
137 if (BIO_puts(bp, "\n") <= 0)
138 goto err;
139
140 pkey=X509_REQ_get_pubkey(x);
141 if (pkey == NULL)
142 {
143 BIO_printf(bp,"%12sUnable to load Public Key\n","");
144 ERR_print_errors(bp);
145 }
146 else
147#ifndef OPENSSL_NO_RSA
148 if (pkey->type == EVP_PKEY_RSA)
149 {
150 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
151 BN_num_bits(pkey->pkey.rsa->n));
152 RSA_print(bp,pkey->pkey.rsa,16);
153 }
154 else
155#endif
156#ifndef OPENSSL_NO_DSA
157 if (pkey->type == EVP_PKEY_DSA)
158 {
159 BIO_printf(bp,"%12sDSA Public Key:\n","");
160 DSA_print(bp,pkey->pkey.dsa,16);
161 }
162 else
163#endif
164 BIO_printf(bp,"%12sUnknown Public Key:\n","");
165
166 EVP_PKEY_free(pkey);
167 }
168
169 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
170 {
171 /* may not be */
172 snprintf(str,sizeof str,"%8sAttributes:\n","");
173 if (BIO_puts(bp,str) <= 0) goto err;
174
175 sk=x->req_info->attributes;
176 if (sk_X509_ATTRIBUTE_num(sk) == 0)
177 {
178 snprintf(str,sizeof str,"%12sa0:00\n","");
179 if (BIO_puts(bp,str) <= 0) goto err;
180 }
181 else
182 {
183 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
184 {
185 ASN1_TYPE *at;
186 X509_ATTRIBUTE *a;
187 ASN1_BIT_STRING *bs=NULL;
188 ASN1_TYPE *t;
189 int j,type=0,count=1,ii=0;
190
191 a=sk_X509_ATTRIBUTE_value(sk,i);
192 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
193 continue;
194 snprintf(str,sizeof str,"%12s","");
195 if (BIO_puts(bp,str) <= 0) goto err;
196 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
197 {
198 if (a->single)
199 {
200 t=a->value.single;
201 type=t->type;
202 bs=t->value.bit_string;
203 }
204 else
205 {
206 ii=0;
207 count=sk_ASN1_TYPE_num(a->value.set);
208get_next:
209 at=sk_ASN1_TYPE_value(a->value.set,ii);
210 type=at->type;
211 bs=at->value.asn1_string;
212 }
213 }
214 for (j=25-j; j>0; j--)
215 if (BIO_write(bp," ",1) != 1) goto err;
216 if (BIO_puts(bp,":") <= 0) goto err;
217 if ( (type == V_ASN1_PRINTABLESTRING) ||
218 (type == V_ASN1_T61STRING) ||
219 (type == V_ASN1_IA5STRING))
220 {
221 if (BIO_write(bp,(char *)bs->data,bs->length)
222 != bs->length)
223 goto err;
224 BIO_puts(bp,"\n");
225 }
226 else
227 {
228 BIO_puts(bp,"unable to print attribute\n");
229 }
230 if (++ii < count) goto get_next;
231 }
232 }
233 }
234 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
235 {
236 exts = X509_REQ_get_extensions(x);
237 if(exts)
238 {
239 BIO_printf(bp,"%8sRequested Extensions:\n","");
240 for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
241 {
242 ASN1_OBJECT *obj;
243 X509_EXTENSION *ex;
244 int j;
245 ex=sk_X509_EXTENSION_value(exts, i);
246 if (BIO_printf(bp,"%12s","") <= 0) goto err;
247 obj=X509_EXTENSION_get_object(ex);
248 i2a_ASN1_OBJECT(bp,obj);
249 j=X509_EXTENSION_get_critical(ex);
250 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
251 goto err;
252 if(!X509V3_EXT_print(bp, ex, 0, 16))
253 {
254 BIO_printf(bp, "%16s", "");
255 M_ASN1_OCTET_STRING_print(bp,ex->value);
256 }
257 if (BIO_write(bp,"\n",1) <= 0) goto err;
258 }
259 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
260 }
261 }
262
263 if(!(cflag & X509_FLAG_NO_SIGDUMP))
264 {
265 if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;
266 }
267
268 return(1);
269err:
270 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
271 return(0);
272 }
273
274int X509_REQ_print(BIO *bp, X509_REQ *x)
275 {
276 return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
277 }
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
new file mode 100644
index 0000000000..5abfbc815e
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_spki.c
@@ -0,0 +1,116 @@
1/* t_spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1.h>
63
64/* Print out an SPKI */
65
66int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
67{
68 EVP_PKEY *pkey;
69 ASN1_IA5STRING *chal;
70 int i, n;
71 char *s;
72 BIO_printf(out, "Netscape SPKI:\n");
73 i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm);
74 BIO_printf(out," Public Key Algorithm: %s\n",
75 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
76 pkey = X509_PUBKEY_get(spki->spkac->pubkey);
77 if(!pkey) BIO_printf(out, " Unable to load public key\n");
78 else {
79#ifndef OPENSSL_NO_RSA
80 if (pkey->type == EVP_PKEY_RSA)
81 {
82 BIO_printf(out," RSA Public Key: (%d bit)\n",
83 BN_num_bits(pkey->pkey.rsa->n));
84 RSA_print(out,pkey->pkey.rsa,2);
85 }
86 else
87#endif
88#ifndef OPENSSL_NO_DSA
89 if (pkey->type == EVP_PKEY_DSA)
90 {
91 BIO_printf(out," DSA Public Key:\n");
92 DSA_print(out,pkey->pkey.dsa,2);
93 }
94 else
95#endif
96 BIO_printf(out," Unknown Public Key:\n");
97 EVP_PKEY_free(pkey);
98 }
99 chal = spki->spkac->challenge;
100 if(chal->length)
101 BIO_printf(out, " Challenge String: %s\n", chal->data);
102 i=OBJ_obj2nid(spki->sig_algor->algorithm);
103 BIO_printf(out," Signature Algorithm: %s",
104 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
105
106 n=spki->signature->length;
107 s=(char *)spki->signature->data;
108 for (i=0; i<n; i++)
109 {
110 if ((i%18) == 0) BIO_write(out,"\n ",7);
111 BIO_printf(out,"%02x%s",(unsigned char)s[i],
112 ((i+1) == n)?"":":");
113 }
114 BIO_write(out,"\n",1);
115 return 1;
116}
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
new file mode 100644
index 0000000000..5de4833ed0
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -0,0 +1,502 @@
1/* crypto/asn1/t_x509.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#ifndef OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_NO_DSA
67#include <openssl/dsa.h>
68#endif
69#include <openssl/objects.h>
70#include <openssl/x509.h>
71#include <openssl/x509v3.h>
72
73#ifndef OPENSSL_NO_FP_API
74int X509_print_fp(FILE *fp, X509 *x)
75 {
76 return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
77 }
78
79int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag)
80 {
81 BIO *b;
82 int ret;
83
84 if ((b=BIO_new(BIO_s_file())) == NULL)
85 {
86 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
87 return(0);
88 }
89 BIO_set_fp(b,fp,BIO_NOCLOSE);
90 ret=X509_print_ex(b, x, nmflag, cflag);
91 BIO_free(b);
92 return(ret);
93 }
94#endif
95
96int X509_print(BIO *bp, X509 *x)
97{
98 return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
99}
100
101int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
102 {
103 long l;
104 int ret=0,i;
105 char *m=NULL,mlch = ' ';
106 int nmindent = 0;
107 X509_CINF *ci;
108 ASN1_INTEGER *bs;
109 EVP_PKEY *pkey=NULL;
110 const char *neg;
111 ASN1_STRING *str=NULL;
112
113 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
114 mlch = '\n';
115 nmindent = 12;
116 }
117
118 if(nmflags == X509_FLAG_COMPAT)
119 nmindent = 16;
120
121 ci=x->cert_info;
122 if(!(cflag & X509_FLAG_NO_HEADER))
123 {
124 if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
125 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
126 }
127 if(!(cflag & X509_FLAG_NO_VERSION))
128 {
129 l=X509_get_version(x);
130 if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
131 }
132 if(!(cflag & X509_FLAG_NO_SERIAL))
133 {
134
135 if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
136
137 bs=X509_get_serialNumber(x);
138 if (bs->length <= 4)
139 {
140 l=ASN1_INTEGER_get(bs);
141 if (l < 0)
142 {
143 l= -l;
144 neg="-";
145 }
146 else
147 neg="";
148 if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
149 goto err;
150 }
151 else
152 {
153 neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
154 if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
155
156 for (i=0; i<bs->length; i++)
157 {
158 if (BIO_printf(bp,"%02x%c",bs->data[i],
159 ((i+1 == bs->length)?'\n':':')) <= 0)
160 goto err;
161 }
162 }
163
164 }
165
166 if(!(cflag & X509_FLAG_NO_SIGNAME))
167 {
168 if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0)
169 goto err;
170 if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0)
171 goto err;
172 if (BIO_puts(bp, "\n") <= 0)
173 goto err;
174 }
175
176 if(!(cflag & X509_FLAG_NO_ISSUER))
177 {
178 if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err;
179 if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err;
180 if (BIO_write(bp,"\n",1) <= 0) goto err;
181 }
182 if(!(cflag & X509_FLAG_NO_VALIDITY))
183 {
184 if (BIO_write(bp," Validity\n",17) <= 0) goto err;
185 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
186 if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
187 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
188 if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
189 if (BIO_write(bp,"\n",1) <= 0) goto err;
190 }
191 if(!(cflag & X509_FLAG_NO_SUBJECT))
192 {
193 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
194 if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err;
195 if (BIO_write(bp,"\n",1) <= 0) goto err;
196 }
197 if(!(cflag & X509_FLAG_NO_PUBKEY))
198 {
199 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
200 goto err;
201 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
202 goto err;
203 if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0)
204 goto err;
205 if (BIO_puts(bp, "\n") <= 0)
206 goto err;
207
208 pkey=X509_get_pubkey(x);
209 if (pkey == NULL)
210 {
211 BIO_printf(bp,"%12sUnable to load Public Key\n","");
212 ERR_print_errors(bp);
213 }
214 else
215#ifndef OPENSSL_NO_RSA
216 if (pkey->type == EVP_PKEY_RSA)
217 {
218 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
219 BN_num_bits(pkey->pkey.rsa->n));
220 RSA_print(bp,pkey->pkey.rsa,16);
221 }
222 else
223#endif
224#ifndef OPENSSL_NO_DSA
225 if (pkey->type == EVP_PKEY_DSA)
226 {
227 BIO_printf(bp,"%12sDSA Public Key:\n","");
228 DSA_print(bp,pkey->pkey.dsa,16);
229 }
230 else
231#endif
232 BIO_printf(bp,"%12sUnknown Public Key:\n","");
233
234 EVP_PKEY_free(pkey);
235 }
236
237 if (!(cflag & X509_FLAG_NO_EXTENSIONS))
238 X509V3_extensions_print(bp, "X509v3 extensions",
239 ci->extensions, cflag, 8);
240
241 if(!(cflag & X509_FLAG_NO_SIGDUMP))
242 {
243 if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err;
244 }
245 if(!(cflag & X509_FLAG_NO_AUX))
246 {
247 if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
248 }
249 ret=1;
250err:
251 if (str != NULL) ASN1_STRING_free(str);
252 if (m != NULL) OPENSSL_free(m);
253 return(ret);
254 }
255
256int X509_ocspid_print (BIO *bp, X509 *x)
257 {
258 unsigned char *der=NULL ;
259 unsigned char *dertmp;
260 int derlen;
261 int i;
262 unsigned char SHA1md[SHA_DIGEST_LENGTH];
263
264 /* display the hash of the subject as it would appear
265 in OCSP requests */
266 if (BIO_printf(bp," Subject OCSP hash: ") <= 0)
267 goto err;
268 derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
269 if ((der = dertmp = (unsigned char *)OPENSSL_malloc (derlen)) == NULL)
270 goto err;
271 i2d_X509_NAME(x->cert_info->subject, &dertmp);
272
273 EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL);
274 for (i=0; i < SHA_DIGEST_LENGTH; i++)
275 {
276 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
277 }
278 OPENSSL_free (der);
279 der=NULL;
280
281 /* display the hash of the public key as it would appear
282 in OCSP requests */
283 if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0)
284 goto err;
285
286 EVP_Digest(x->cert_info->key->public_key->data,
287 x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL);
288 for (i=0; i < SHA_DIGEST_LENGTH; i++)
289 {
290 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0)
291 goto err;
292 }
293 BIO_printf(bp,"\n");
294
295 return (1);
296err:
297 if (der != NULL) OPENSSL_free(der);
298 return(0);
299 }
300
301int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
302{
303 unsigned char *s;
304 int i, n;
305 if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0;
306 if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
307
308 n=sig->length;
309 s=sig->data;
310 for (i=0; i<n; i++)
311 {
312 if ((i%18) == 0)
313 if (BIO_write(bp,"\n ",9) <= 0) return 0;
314 if (BIO_printf(bp,"%02x%s",s[i],
315 ((i+1) == n)?"":":") <= 0) return 0;
316 }
317 if (BIO_write(bp,"\n",1) != 1) return 0;
318 return 1;
319}
320
321int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
322 {
323 int i,n;
324 char buf[80],*p;;
325
326 if (v == NULL) return(0);
327 n=0;
328 p=(char *)v->data;
329 for (i=0; i<v->length; i++)
330 {
331 if ((p[i] > '~') || ((p[i] < ' ') &&
332 (p[i] != '\n') && (p[i] != '\r')))
333 buf[n]='.';
334 else
335 buf[n]=p[i];
336 n++;
337 if (n >= 80)
338 {
339 if (BIO_write(bp,buf,n) <= 0)
340 return(0);
341 n=0;
342 }
343 }
344 if (n > 0)
345 if (BIO_write(bp,buf,n) <= 0)
346 return(0);
347 return(1);
348 }
349
350int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
351{
352 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
353 if(tm->type == V_ASN1_GENERALIZEDTIME)
354 return ASN1_GENERALIZEDTIME_print(bp, tm);
355 BIO_write(bp,"Bad time value",14);
356 return(0);
357}
358
359static const char *mon[12]=
360 {
361 "Jan","Feb","Mar","Apr","May","Jun",
362 "Jul","Aug","Sep","Oct","Nov","Dec"
363 };
364
365int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
366 {
367 char *v;
368 int gmt=0;
369 int i;
370 int y=0,M=0,d=0,h=0,m=0,s=0;
371
372 i=tm->length;
373 v=(char *)tm->data;
374
375 if (i < 12) goto err;
376 if (v[i-1] == 'Z') gmt=1;
377 for (i=0; i<12; i++)
378 if ((v[i] > '9') || (v[i] < '0')) goto err;
379 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
380 M= (v[4]-'0')*10+(v[5]-'0');
381 if ((M > 12) || (M < 1)) goto err;
382 d= (v[6]-'0')*10+(v[7]-'0');
383 h= (v[8]-'0')*10+(v[9]-'0');
384 m= (v[10]-'0')*10+(v[11]-'0');
385 if ( (v[12] >= '0') && (v[12] <= '9') &&
386 (v[13] >= '0') && (v[13] <= '9'))
387 s= (v[12]-'0')*10+(v[13]-'0');
388
389 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
390 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
391 return(0);
392 else
393 return(1);
394err:
395 BIO_write(bp,"Bad time value",14);
396 return(0);
397 }
398
399int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
400 {
401 char *v;
402 int gmt=0;
403 int i;
404 int y=0,M=0,d=0,h=0,m=0,s=0;
405
406 i=tm->length;
407 v=(char *)tm->data;
408
409 if (i < 10) goto err;
410 if (v[i-1] == 'Z') gmt=1;
411 for (i=0; i<10; i++)
412 if ((v[i] > '9') || (v[i] < '0')) goto err;
413 y= (v[0]-'0')*10+(v[1]-'0');
414 if (y < 50) y+=100;
415 M= (v[2]-'0')*10+(v[3]-'0');
416 if ((M > 12) || (M < 1)) goto err;
417 d= (v[4]-'0')*10+(v[5]-'0');
418 h= (v[6]-'0')*10+(v[7]-'0');
419 m= (v[8]-'0')*10+(v[9]-'0');
420 if ( (v[10] >= '0') && (v[10] <= '9') &&
421 (v[11] >= '0') && (v[11] <= '9'))
422 s= (v[10]-'0')*10+(v[11]-'0');
423
424 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
425 mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0)
426 return(0);
427 else
428 return(1);
429err:
430 BIO_write(bp,"Bad time value",14);
431 return(0);
432 }
433
434int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
435 {
436 char *s,*c;
437 int ret=0,l,ll,i,first=1;
438 char buf[256];
439
440 ll=80-2-obase;
441
442 s=X509_NAME_oneline(name,buf,256);
443 if (!*s)
444 return 1;
445 s++; /* skip the first slash */
446
447 l=ll;
448 c=s;
449 for (;;)
450 {
451#ifndef CHARSET_EBCDIC
452 if ( ((*s == '/') &&
453 ((s[1] >= 'A') && (s[1] <= 'Z') && (
454 (s[2] == '=') ||
455 ((s[2] >= 'A') && (s[2] <= 'Z') &&
456 (s[3] == '='))
457 ))) ||
458 (*s == '\0'))
459#else
460 if ( ((*s == '/') &&
461 (isupper(s[1]) && (
462 (s[2] == '=') ||
463 (isupper(s[2]) &&
464 (s[3] == '='))
465 ))) ||
466 (*s == '\0'))
467#endif
468 {
469 if ((l <= 0) && !first)
470 {
471 first=0;
472 if (BIO_write(bp,"\n",1) != 1) goto err;
473 for (i=0; i<obase; i++)
474 {
475 if (BIO_write(bp," ",1) != 1) goto err;
476 }
477 l=ll;
478 }
479 i=s-c;
480 if (BIO_write(bp,c,i) != i) goto err;
481 c+=i;
482 c++;
483 if (*s != '\0')
484 {
485 if (BIO_write(bp,", ",2) != 2) goto err;
486 }
487 l--;
488 }
489 if (*s == '\0') break;
490 s++;
491 l--;
492 }
493
494 ret=1;
495 if (0)
496 {
497err:
498 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
499 }
500 return(ret);
501 }
502
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
new file mode 100644
index 0000000000..7d4a6e6084
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_x509a.c
@@ -0,0 +1,110 @@
1/* t_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX and string set routines
66 */
67
68int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
69{
70 char oidstr[80], first;
71 int i;
72 if(!aux) return 1;
73 if(aux->trust) {
74 first = 1;
75 BIO_printf(out, "%*sTrusted Uses:\n%*s",
76 indent, "", indent + 2, "");
77 for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
78 if(!first) BIO_puts(out, ", ");
79 else first = 0;
80 OBJ_obj2txt(oidstr, 80,
81 sk_ASN1_OBJECT_value(aux->trust, i), 0);
82 BIO_puts(out, oidstr);
83 }
84 BIO_puts(out, "\n");
85 } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
86 if(aux->reject) {
87 first = 1;
88 BIO_printf(out, "%*sRejected Uses:\n%*s",
89 indent, "", indent + 2, "");
90 for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
91 if(!first) BIO_puts(out, ", ");
92 else first = 0;
93 OBJ_obj2txt(oidstr, 80,
94 sk_ASN1_OBJECT_value(aux->reject, i), 0);
95 BIO_puts(out, oidstr);
96 }
97 BIO_puts(out, "\n");
98 } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
99 if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "",
100 aux->alias->data);
101 if(aux->keyid) {
102 BIO_printf(out, "%*sKey Id: ", indent, "");
103 for(i = 0; i < aux->keyid->length; i++)
104 BIO_printf(out, "%s%02X",
105 i ? ":" : "",
106 aux->keyid->data[i]);
107 BIO_write(out,"\n",1);
108 }
109 return 1;
110}
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
new file mode 100644
index 0000000000..f87c08793a
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -0,0 +1,958 @@
1/* tasn_dec.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/buffer.h>
66#include <openssl/err.h>
67
68static int asn1_check_eoc(unsigned char **in, long len);
69static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass);
70static int collect_data(BUF_MEM *buf, unsigned char **p, long plen);
71static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
72 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx);
73static int asn1_template_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
74static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
75static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long len,
76 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
77
78/* Table to convert tags to bit values, used for MSTRING type */
79static unsigned long tag2bit[32]={
800, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
81B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
82B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
83B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
840, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
85B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */
86B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */
87B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */
88B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
89 };
90
91unsigned long ASN1_tag2bit(int tag)
92{
93 if((tag < 0) || (tag > 30)) return 0;
94 return tag2bit[tag];
95}
96
97/* Macro to initialize and invalidate the cache */
98
99#define asn1_tlc_clear(c) if(c) (c)->valid = 0
100
101/* Decode an ASN1 item, this currently behaves just
102 * like a standard 'd2i' function. 'in' points to
103 * a buffer to read the data from, in future we will
104 * have more advanced versions that can input data
105 * a piece at a time and this will simply be a special
106 * case.
107 */
108
109ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it)
110{
111 ASN1_TLC c;
112 ASN1_VALUE *ptmpval = NULL;
113 if(!pval) pval = &ptmpval;
114 asn1_tlc_clear(&c);
115 if(ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
116 return *pval;
117 return NULL;
118}
119
120int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt)
121{
122 ASN1_TLC c;
123 asn1_tlc_clear(&c);
124 return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
125}
126
127
128/* Decode an item, taking care of IMPLICIT tagging, if any.
129 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
130 */
131
132int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
133 int tag, int aclass, char opt, ASN1_TLC *ctx)
134{
135 const ASN1_TEMPLATE *tt, *errtt = NULL;
136 const ASN1_COMPAT_FUNCS *cf;
137 const ASN1_EXTERN_FUNCS *ef;
138 const ASN1_AUX *aux = it->funcs;
139 ASN1_aux_cb *asn1_cb;
140 unsigned char *p, *q, imphack = 0, oclass;
141 char seq_eoc, seq_nolen, cst, isopt;
142 long tmplen;
143 int i;
144 int otag;
145 int ret = 0;
146 ASN1_VALUE *pchval, **pchptr, *ptmpval;
147 if(!pval) return 0;
148 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
149 else asn1_cb = 0;
150
151 switch(it->itype) {
152
153 case ASN1_ITYPE_PRIMITIVE:
154 if(it->templates) {
155 /* tagging or OPTIONAL is currently illegal on an item template
156 * because the flags can't get passed down. In practice this isn't
157 * a problem: we include the relevant flags from the item template
158 * in the template itself.
159 */
160 if ((tag != -1) || opt) {
161 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
162 goto err;
163 }
164 return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx);
165 }
166 return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx);
167 break;
168
169 case ASN1_ITYPE_MSTRING:
170 p = *in;
171 /* Just read in tag and class */
172 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx);
173 if(!ret) {
174 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
175 goto err;
176 }
177 /* Must be UNIVERSAL class */
178 if(oclass != V_ASN1_UNIVERSAL) {
179 /* If OPTIONAL, assume this is OK */
180 if(opt) return -1;
181 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);
182 goto err;
183 }
184 /* Check tag matches bit map */
185 if(!(ASN1_tag2bit(otag) & it->utype)) {
186 /* If OPTIONAL, assume this is OK */
187 if(opt) return -1;
188 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG);
189 goto err;
190 }
191 return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);
192
193 case ASN1_ITYPE_EXTERN:
194 /* Use new style d2i */
195 ef = it->funcs;
196 return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
197
198 case ASN1_ITYPE_COMPAT:
199 /* we must resort to old style evil hackery */
200 cf = it->funcs;
201
202 /* If OPTIONAL see if it is there */
203 if(opt) {
204 int exptag;
205 p = *in;
206 if(tag == -1) exptag = it->utype;
207 else exptag = tag;
208 /* Don't care about anything other than presence of expected tag */
209 ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx);
210 if(!ret) {
211 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
212 goto err;
213 }
214 if(ret == -1) return -1;
215 }
216 /* This is the old style evil hack IMPLICIT handling:
217 * since the underlying code is expecting a tag and
218 * class other than the one present we change the
219 * buffer temporarily then change it back afterwards.
220 * This doesn't and never did work for tags > 30.
221 *
222 * Yes this is *horrible* but it is only needed for
223 * old style d2i which will hopefully not be around
224 * for much longer.
225 * FIXME: should copy the buffer then modify it so
226 * the input buffer can be const: we should *always*
227 * copy because the old style d2i might modify the
228 * buffer.
229 */
230
231 if(tag != -1) {
232 p = *in;
233 imphack = *p;
234 *p = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype);
235 }
236
237 ptmpval = cf->asn1_d2i(pval, in, len);
238
239 if(tag != -1) *p = imphack;
240
241 if(ptmpval) return 1;
242 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
243 goto err;
244
245
246 case ASN1_ITYPE_CHOICE:
247 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
248 goto auxerr;
249
250 /* Allocate structure */
251 if(!*pval) {
252 if(!ASN1_item_ex_new(pval, it)) {
253 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
254 goto err;
255 }
256 }
257 /* CHOICE type, try each possibility in turn */
258 pchval = NULL;
259 p = *in;
260 for(i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
261 pchptr = asn1_get_field_ptr(pval, tt);
262 /* We mark field as OPTIONAL so its absence
263 * can be recognised.
264 */
265 ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
266 /* If field not present, try the next one */
267 if(ret == -1) continue;
268 /* If positive return, read OK, break loop */
269 if(ret > 0) break;
270 /* Otherwise must be an ASN1 parsing error */
271 errtt = tt;
272 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
273 goto err;
274 }
275 /* Did we fall off the end without reading anything? */
276 if(i == it->tcount) {
277 /* If OPTIONAL, this is OK */
278 if(opt) {
279 /* Free and zero it */
280 ASN1_item_ex_free(pval, it);
281 return -1;
282 }
283 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);
284 goto err;
285 }
286 asn1_set_choice_selector(pval, i, it);
287 *in = p;
288 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
289 goto auxerr;
290 return 1;
291
292 case ASN1_ITYPE_SEQUENCE:
293 p = *in;
294 tmplen = len;
295
296 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
297 if(tag == -1) {
298 tag = V_ASN1_SEQUENCE;
299 aclass = V_ASN1_UNIVERSAL;
300 }
301 /* Get SEQUENCE length and update len, p */
302 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx);
303 if(!ret) {
304 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
305 goto err;
306 } else if(ret == -1) return -1;
307 if(aux && (aux->flags & ASN1_AFLG_BROKEN)) {
308 len = tmplen - (p - *in);
309 seq_nolen = 1;
310 } else seq_nolen = seq_eoc; /* If indefinite we don't do a length check */
311 if(!cst) {
312 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
313 goto err;
314 }
315
316 if(!*pval) {
317 if(!ASN1_item_ex_new(pval, it)) {
318 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
319 goto err;
320 }
321 }
322 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
323 goto auxerr;
324
325 /* Get each field entry */
326 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
327 const ASN1_TEMPLATE *seqtt;
328 ASN1_VALUE **pseqval;
329 seqtt = asn1_do_adb(pval, tt, 1);
330 if(!seqtt) goto err;
331 pseqval = asn1_get_field_ptr(pval, seqtt);
332 /* Have we ran out of data? */
333 if(!len) break;
334 q = p;
335 if(asn1_check_eoc(&p, len)) {
336 if(!seq_eoc) {
337 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC);
338 goto err;
339 }
340 len -= p - q;
341 seq_eoc = 0;
342 q = p;
343 break;
344 }
345 /* This determines the OPTIONAL flag value. The field cannot
346 * be omitted if it is the last of a SEQUENCE and there is
347 * still data to be read. This isn't strictly necessary but
348 * it increases efficiency in some cases.
349 */
350 if(i == (it->tcount - 1)) isopt = 0;
351 else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
352 /* attempt to read in field, allowing each to be OPTIONAL */
353 ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);
354 if(!ret) {
355 errtt = seqtt;
356 goto err;
357 } else if(ret == -1) {
358 /* OPTIONAL component absent. Free and zero the field
359 */
360 ASN1_template_free(pseqval, seqtt);
361 continue;
362 }
363 /* Update length */
364 len -= p - q;
365 }
366 /* Check for EOC if expecting one */
367 if(seq_eoc && !asn1_check_eoc(&p, len)) {
368 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC);
369 goto err;
370 }
371 /* Check all data read */
372 if(!seq_nolen && len) {
373 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
374 goto err;
375 }
376
377 /* If we get here we've got no more data in the SEQUENCE,
378 * however we may not have read all fields so check all
379 * remaining are OPTIONAL and clear any that are.
380 */
381 for(; i < it->tcount; tt++, i++) {
382 const ASN1_TEMPLATE *seqtt;
383 seqtt = asn1_do_adb(pval, tt, 1);
384 if(!seqtt) goto err;
385 if(seqtt->flags & ASN1_TFLG_OPTIONAL) {
386 ASN1_VALUE **pseqval;
387 pseqval = asn1_get_field_ptr(pval, seqtt);
388 ASN1_template_free(pseqval, seqtt);
389 } else {
390 errtt = seqtt;
391 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING);
392 goto err;
393 }
394 }
395 /* Save encoding */
396 if(!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr;
397 *in = p;
398 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
399 goto auxerr;
400 return 1;
401
402 default:
403 return 0;
404 }
405 auxerr:
406 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);
407 err:
408 ASN1_item_ex_free(pval, it);
409 if(errtt) ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
410 else ERR_add_error_data(2, "Type=", it->sname);
411 return 0;
412}
413
414/* Templates are handled with two separate functions. One handles any EXPLICIT tag and the other handles the
415 * rest.
416 */
417
418static int asn1_template_ex_d2i(ASN1_VALUE **val, unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
419{
420 int flags, aclass;
421 int ret;
422 long len;
423 unsigned char *p, *q;
424 char exp_eoc;
425 if(!val) return 0;
426 flags = tt->flags;
427 aclass = flags & ASN1_TFLG_TAG_CLASS;
428
429 p = *in;
430
431 /* Check if EXPLICIT tag expected */
432 if(flags & ASN1_TFLG_EXPTAG) {
433 char cst;
434 /* Need to work out amount of data available to the inner content and where it
435 * starts: so read in EXPLICIT header to get the info.
436 */
437 ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx);
438 q = p;
439 if(!ret) {
440 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
441 return 0;
442 } else if(ret == -1) return -1;
443 if(!cst) {
444 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
445 return 0;
446 }
447 /* We've found the field so it can't be OPTIONAL now */
448 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
449 if(!ret) {
450 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
451 return 0;
452 }
453 /* We read the field in OK so update length */
454 len -= p - q;
455 if(exp_eoc) {
456 /* If NDEF we must have an EOC here */
457 if(!asn1_check_eoc(&p, len)) {
458 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
459 goto err;
460 }
461 } else {
462 /* Otherwise we must hit the EXPLICIT tag end or its an error */
463 if(len) {
464 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
465 goto err;
466 }
467 }
468 } else
469 return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
470
471 *in = p;
472 return 1;
473
474 err:
475 ASN1_template_free(val, tt);
476 *val = NULL;
477 return 0;
478}
479
480static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
481{
482 int flags, aclass;
483 int ret;
484 unsigned char *p, *q;
485 if(!val) return 0;
486 flags = tt->flags;
487 aclass = flags & ASN1_TFLG_TAG_CLASS;
488
489 p = *in;
490 q = p;
491
492 if(flags & ASN1_TFLG_SK_MASK) {
493 /* SET OF, SEQUENCE OF */
494 int sktag, skaclass;
495 char sk_eoc;
496 /* First work out expected inner tag value */
497 if(flags & ASN1_TFLG_IMPTAG) {
498 sktag = tt->tag;
499 skaclass = aclass;
500 } else {
501 skaclass = V_ASN1_UNIVERSAL;
502 if(flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET;
503 else sktag = V_ASN1_SEQUENCE;
504 }
505 /* Get the tag */
506 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx);
507 if(!ret) {
508 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
509 return 0;
510 } else if(ret == -1) return -1;
511 if(!*val) *val = (ASN1_VALUE *)sk_new_null();
512 else {
513 /* We've got a valid STACK: free up any items present */
514 STACK *sktmp = (STACK *)*val;
515 ASN1_VALUE *vtmp;
516 while(sk_num(sktmp) > 0) {
517 vtmp = (ASN1_VALUE *)sk_pop(sktmp);
518 ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
519 }
520 }
521
522 if(!*val) {
523 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_MALLOC_FAILURE);
524 goto err;
525 }
526 /* Read as many items as we can */
527 while(len > 0) {
528 ASN1_VALUE *skfield;
529 q = p;
530 /* See if EOC found */
531 if(asn1_check_eoc(&p, len)) {
532 if(!sk_eoc) {
533 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_UNEXPECTED_EOC);
534 goto err;
535 }
536 len -= p - q;
537 sk_eoc = 0;
538 break;
539 }
540 skfield = NULL;
541 if(!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
542 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
543 goto err;
544 }
545 len -= p - q;
546 if(!sk_push((STACK *)*val, (char *)skfield)) {
547 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_MALLOC_FAILURE);
548 goto err;
549 }
550 }
551 if(sk_eoc) {
552 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
553 goto err;
554 }
555 } else if(flags & ASN1_TFLG_IMPTAG) {
556 /* IMPLICIT tagging */
557 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
558 if(!ret) {
559 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
560 goto err;
561 } else if(ret == -1) return -1;
562 } else {
563 /* Nothing special */
564 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx);
565 if(!ret) {
566 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
567 goto err;
568 } else if(ret == -1) return -1;
569 }
570
571 *in = p;
572 return 1;
573
574 err:
575 ASN1_template_free(val, tt);
576 *val = NULL;
577 return 0;
578}
579
580static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long inlen,
581 const ASN1_ITEM *it,
582 int tag, int aclass, char opt, ASN1_TLC *ctx)
583{
584 int ret = 0, utype;
585 long plen;
586 char cst, inf, free_cont = 0;
587 unsigned char *p;
588 BUF_MEM buf;
589 unsigned char *cont = NULL;
590 long len;
591 if(!pval) {
592 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
593 return 0; /* Should never happen */
594 }
595
596 if(it->itype == ASN1_ITYPE_MSTRING) {
597 utype = tag;
598 tag = -1;
599 } else utype = it->utype;
600
601 if(utype == V_ASN1_ANY) {
602 /* If type is ANY need to figure out type from tag */
603 unsigned char oclass;
604 if(tag >= 0) {
605 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY);
606 return 0;
607 }
608 if(opt) {
609 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY);
610 return 0;
611 }
612 p = *in;
613 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx);
614 if(!ret) {
615 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
616 return 0;
617 }
618 if(oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER;
619 }
620 if(tag == -1) {
621 tag = utype;
622 aclass = V_ASN1_UNIVERSAL;
623 }
624 p = *in;
625 /* Check header */
626 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx);
627 if(!ret) {
628 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
629 return 0;
630 } else if(ret == -1) return -1;
631 /* SEQUENCE, SET and "OTHER" are left in encoded form */
632 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
633 /* Clear context cache for type OTHER because the auto clear when
634 * we have a exact match wont work
635 */
636 if(utype == V_ASN1_OTHER) {
637 asn1_tlc_clear(ctx);
638 /* SEQUENCE and SET must be constructed */
639 } else if(!cst) {
640 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED);
641 return 0;
642 }
643
644 cont = *in;
645 /* If indefinite length constructed find the real end */
646 if(inf) {
647 if(!asn1_collect(NULL, &p, plen, inf, -1, -1)) goto err;
648 len = p - cont;
649 } else {
650 len = p - cont + plen;
651 p += plen;
652 buf.data = NULL;
653 }
654 } else if(cst) {
655 buf.length = 0;
656 buf.max = 0;
657 buf.data = NULL;
658 /* Should really check the internal tags are correct but
659 * some things may get this wrong. The relevant specs
660 * say that constructed string types should be OCTET STRINGs
661 * internally irrespective of the type. So instead just check
662 * for UNIVERSAL class and ignore the tag.
663 */
664 if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err;
665 len = buf.length;
666 /* Append a final null to string */
667 if(!BUF_MEM_grow(&buf, len + 1)) {
668 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
669 return 0;
670 }
671 buf.data[len] = 0;
672 cont = (unsigned char *)buf.data;
673 free_cont = 1;
674 } else {
675 cont = p;
676 len = plen;
677 p += plen;
678 }
679
680 /* We now have content length and type: translate into a structure */
681 if(!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) goto err;
682
683 *in = p;
684 ret = 1;
685 err:
686 if(free_cont && buf.data) OPENSSL_free(buf.data);
687 return ret;
688}
689
690/* Translate ASN1 content octets into a structure */
691
692int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
693{
694 ASN1_STRING *stmp;
695 ASN1_TYPE *typ = NULL;
696 int ret = 0;
697 const ASN1_PRIMITIVE_FUNCS *pf;
698 ASN1_INTEGER **tint;
699 pf = it->funcs;
700 if(pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
701 /* If ANY type clear type and set pointer to internal value */
702 if(it->utype == V_ASN1_ANY) {
703 if(!*pval) {
704 typ = ASN1_TYPE_new();
705 *pval = (ASN1_VALUE *)typ;
706 } else typ = (ASN1_TYPE *)*pval;
707 if(utype != typ->type) ASN1_TYPE_set(typ, utype, NULL);
708 pval = (ASN1_VALUE **)&typ->value.ptr;
709 }
710 switch(utype) {
711 case V_ASN1_OBJECT:
712 if(!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err;
713 break;
714
715 case V_ASN1_NULL:
716 if(len) {
717 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_NULL_IS_WRONG_LENGTH);
718 goto err;
719 }
720 *pval = (ASN1_VALUE *)1;
721 break;
722
723 case V_ASN1_BOOLEAN:
724 if(len != 1) {
725 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
726 goto err;
727 } else {
728 ASN1_BOOLEAN *tbool;
729 tbool = (ASN1_BOOLEAN *)pval;
730 *tbool = *cont;
731 }
732 break;
733
734 case V_ASN1_BIT_STRING:
735 if(!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err;
736 break;
737
738 case V_ASN1_INTEGER:
739 case V_ASN1_NEG_INTEGER:
740 case V_ASN1_ENUMERATED:
741 case V_ASN1_NEG_ENUMERATED:
742 tint = (ASN1_INTEGER **)pval;
743 if(!c2i_ASN1_INTEGER(tint, &cont, len)) goto err;
744 /* Fixup type to match the expected form */
745 (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
746 break;
747
748 case V_ASN1_OCTET_STRING:
749 case V_ASN1_NUMERICSTRING:
750 case V_ASN1_PRINTABLESTRING:
751 case V_ASN1_T61STRING:
752 case V_ASN1_VIDEOTEXSTRING:
753 case V_ASN1_IA5STRING:
754 case V_ASN1_UTCTIME:
755 case V_ASN1_GENERALIZEDTIME:
756 case V_ASN1_GRAPHICSTRING:
757 case V_ASN1_VISIBLESTRING:
758 case V_ASN1_GENERALSTRING:
759 case V_ASN1_UNIVERSALSTRING:
760 case V_ASN1_BMPSTRING:
761 case V_ASN1_UTF8STRING:
762 case V_ASN1_OTHER:
763 case V_ASN1_SET:
764 case V_ASN1_SEQUENCE:
765 default:
766 /* All based on ASN1_STRING and handled the same */
767 if(!*pval) {
768 stmp = ASN1_STRING_type_new(utype);
769 if(!stmp) {
770 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
771 goto err;
772 }
773 *pval = (ASN1_VALUE *)stmp;
774 } else {
775 stmp = (ASN1_STRING *)*pval;
776 stmp->type = utype;
777 }
778 /* If we've already allocated a buffer use it */
779 if(*free_cont) {
780 if(stmp->data) OPENSSL_free(stmp->data);
781 stmp->data = cont;
782 stmp->length = len;
783 *free_cont = 0;
784 } else {
785 if(!ASN1_STRING_set(stmp, cont, len)) {
786 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
787 ASN1_STRING_free(stmp);
788 *pval = NULL;
789 goto err;
790 }
791 }
792 break;
793 }
794 /* If ASN1_ANY and NULL type fix up value */
795 if(typ && utype==V_ASN1_NULL) typ->value.ptr = NULL;
796
797 ret = 1;
798 err:
799 if(!ret) ASN1_TYPE_free(typ);
800 return ret;
801}
802
803/* This function collects the asn1 data from a constructred string
804 * type into a buffer. The values of 'in' and 'len' should refer
805 * to the contents of the constructed type and 'inf' should be set
806 * if it is indefinite length. If 'buf' is NULL then we just want
807 * to find the end of the current structure: useful for indefinite
808 * length constructed stuff.
809 */
810
811static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass)
812{
813 unsigned char *p, *q;
814 long plen;
815 char cst, ininf;
816 p = *in;
817 inf &= 1;
818 /* If no buffer and not indefinite length constructed just pass over the encoded data */
819 if(!buf && !inf) {
820 *in += len;
821 return 1;
822 }
823 while(len > 0) {
824 q = p;
825 /* Check for EOC */
826 if(asn1_check_eoc(&p, len)) {
827 /* EOC is illegal outside indefinite length constructed form */
828 if(!inf) {
829 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC);
830 return 0;
831 }
832 inf = 0;
833 break;
834 }
835 if(!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass, 0, NULL)) {
836 ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
837 return 0;
838 }
839 /* If indefinite length constructed update max length */
840 if(cst) {
841 if(!asn1_collect(buf, &p, plen, ininf, tag, aclass)) return 0;
842 } else {
843 if(!collect_data(buf, &p, plen)) return 0;
844 }
845 len -= p - q;
846 }
847 if(inf) {
848 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
849 return 0;
850 }
851 *in = p;
852 return 1;
853}
854
855static int collect_data(BUF_MEM *buf, unsigned char **p, long plen)
856{
857 int len;
858 if(buf) {
859 len = buf->length;
860 if(!BUF_MEM_grow(buf, len + plen)) {
861 ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
862 return 0;
863 }
864 memcpy(buf->data + len, *p, plen);
865 }
866 *p += plen;
867 return 1;
868}
869
870/* Check for ASN1 EOC and swallow it if found */
871
872static int asn1_check_eoc(unsigned char **in, long len)
873{
874 unsigned char *p;
875 if(len < 2) return 0;
876 p = *in;
877 if(!p[0] && !p[1]) {
878 *in += 2;
879 return 1;
880 }
881 return 0;
882}
883
884/* Check an ASN1 tag and length: a bit like ASN1_get_object
885 * but it sets the length for indefinite length constructed
886 * form, we don't know the exact length but we can set an
887 * upper bound to the amount of data available minus the
888 * header length just read.
889 */
890
891static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
892 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx)
893{
894 int i;
895 int ptag, pclass;
896 long plen;
897 unsigned char *p, *q;
898 p = *in;
899 q = p;
900
901 if(ctx && ctx->valid) {
902 i = ctx->ret;
903 plen = ctx->plen;
904 pclass = ctx->pclass;
905 ptag = ctx->ptag;
906 p += ctx->hdrlen;
907 } else {
908 i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
909 if(ctx) {
910 ctx->ret = i;
911 ctx->plen = plen;
912 ctx->pclass = pclass;
913 ctx->ptag = ptag;
914 ctx->hdrlen = p - q;
915 ctx->valid = 1;
916 /* If definite length, and no error, length +
917 * header can't exceed total amount of data available.
918 */
919 if(!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
920 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);
921 asn1_tlc_clear(ctx);
922 return 0;
923 }
924 }
925 }
926
927 if(i & 0x80) {
928 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);
929 asn1_tlc_clear(ctx);
930 return 0;
931 }
932 if(exptag >= 0) {
933 if((exptag != ptag) || (expclass != pclass)) {
934 /* If type is OPTIONAL, not an error, but indicate missing
935 * type.
936 */
937 if(opt) return -1;
938 asn1_tlc_clear(ctx);
939 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);
940 return 0;
941 }
942 /* We have a tag and class match, so assume we are going to do something with it */
943 asn1_tlc_clear(ctx);
944 }
945
946 if(i & 1) plen = len - (p - q);
947
948 if(inf) *inf = i & 1;
949
950 if(cst) *cst = i & V_ASN1_CONSTRUCTED;
951
952 if(olen) *olen = plen;
953 if(oclass) *oclass = pclass;
954 if(otag) *otag = ptag;
955
956 *in = p;
957 return 1;
958}
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c
new file mode 100644
index 0000000000..f6c8ddef0a
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_enc.c
@@ -0,0 +1,497 @@
1/* tasn_enc.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65
66static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
67static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *seq, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int isset);
68
69/* Encode an ASN1 item, this is compatible with the
70 * standard 'i2d' function. 'out' points to
71 * a buffer to output the data to, in future we will
72 * have more advanced versions that can output data
73 * a piece at a time and this will simply be a special
74 * case.
75 *
76 * The new i2d has one additional feature. If the output
77 * buffer is NULL (i.e. *out == NULL) then a buffer is
78 * allocated and populated with the encoding.
79 */
80
81
82int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
83{
84 if(out && !*out) {
85 unsigned char *p, *buf;
86 int len;
87 len = ASN1_item_ex_i2d(&val, NULL, it, -1, 0);
88 if(len <= 0) return len;
89 buf = OPENSSL_malloc(len);
90 if(!buf) return -1;
91 p = buf;
92 ASN1_item_ex_i2d(&val, &p, it, -1, 0);
93 *out = buf;
94 return len;
95 }
96
97 return ASN1_item_ex_i2d(&val, out, it, -1, 0);
98}
99
100/* Encode an item, taking care of IMPLICIT tagging (if any).
101 * This function performs the normal item handling: it can be
102 * used in external types.
103 */
104
105int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
106{
107 const ASN1_TEMPLATE *tt = NULL;
108 unsigned char *p = NULL;
109 int i, seqcontlen, seqlen;
110 ASN1_STRING *strtmp;
111 const ASN1_COMPAT_FUNCS *cf;
112 const ASN1_EXTERN_FUNCS *ef;
113 const ASN1_AUX *aux = it->funcs;
114 ASN1_aux_cb *asn1_cb;
115 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return 0;
116 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
117 else asn1_cb = 0;
118
119 switch(it->itype) {
120
121 case ASN1_ITYPE_PRIMITIVE:
122 if(it->templates)
123 return ASN1_template_i2d(pval, out, it->templates);
124 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
125 break;
126
127 case ASN1_ITYPE_MSTRING:
128 strtmp = (ASN1_STRING *)*pval;
129 return asn1_i2d_ex_primitive(pval, out, it, -1, 0);
130
131 case ASN1_ITYPE_CHOICE:
132 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
133 return 0;
134 i = asn1_get_choice_selector(pval, it);
135 if((i >= 0) && (i < it->tcount)) {
136 ASN1_VALUE **pchval;
137 const ASN1_TEMPLATE *chtt;
138 chtt = it->templates + i;
139 pchval = asn1_get_field_ptr(pval, chtt);
140 return ASN1_template_i2d(pchval, out, chtt);
141 }
142 /* Fixme: error condition if selector out of range */
143 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
144 return 0;
145 break;
146
147 case ASN1_ITYPE_EXTERN:
148 /* If new style i2d it does all the work */
149 ef = it->funcs;
150 return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
151
152 case ASN1_ITYPE_COMPAT:
153 /* old style hackery... */
154 cf = it->funcs;
155 if(out) p = *out;
156 i = cf->asn1_i2d(*pval, out);
157 /* Fixup for IMPLICIT tag: note this messes up for tags > 30,
158 * but so did the old code. Tags > 30 are very rare anyway.
159 */
160 if(out && (tag != -1))
161 *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
162 return i;
163
164 case ASN1_ITYPE_SEQUENCE:
165 i = asn1_enc_restore(&seqcontlen, out, pval, it);
166 /* An error occurred */
167 if(i < 0) return 0;
168 /* We have a valid cached encoding... */
169 if(i > 0) return seqcontlen;
170 /* Otherwise carry on */
171 seqcontlen = 0;
172 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
173 if(tag == -1) {
174 tag = V_ASN1_SEQUENCE;
175 aclass = V_ASN1_UNIVERSAL;
176 }
177 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
178 return 0;
179 /* First work out sequence content length */
180 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
181 const ASN1_TEMPLATE *seqtt;
182 ASN1_VALUE **pseqval;
183 seqtt = asn1_do_adb(pval, tt, 1);
184 if(!seqtt) return 0;
185 pseqval = asn1_get_field_ptr(pval, seqtt);
186 /* FIXME: check for errors in enhanced version */
187 /* FIXME: special handling of indefinite length encoding */
188 seqcontlen += ASN1_template_i2d(pseqval, NULL, seqtt);
189 }
190 seqlen = ASN1_object_size(1, seqcontlen, tag);
191 if(!out) return seqlen;
192 /* Output SEQUENCE header */
193 ASN1_put_object(out, 1, seqcontlen, tag, aclass);
194 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
195 const ASN1_TEMPLATE *seqtt;
196 ASN1_VALUE **pseqval;
197 seqtt = asn1_do_adb(pval, tt, 1);
198 if(!seqtt) return 0;
199 pseqval = asn1_get_field_ptr(pval, seqtt);
200 /* FIXME: check for errors in enhanced version */
201 ASN1_template_i2d(pseqval, out, seqtt);
202 }
203 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
204 return 0;
205 return seqlen;
206
207 default:
208 return 0;
209 }
210 return 0;
211}
212
213int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt)
214{
215 int i, ret, flags, aclass;
216 flags = tt->flags;
217 aclass = flags & ASN1_TFLG_TAG_CLASS;
218 if(flags & ASN1_TFLG_SK_MASK) {
219 /* SET OF, SEQUENCE OF */
220 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
221 int isset, sktag, skaclass;
222 int skcontlen, sklen;
223 ASN1_VALUE *skitem;
224 if(!*pval) return 0;
225 if(flags & ASN1_TFLG_SET_OF) {
226 isset = 1;
227 /* 2 means we reorder */
228 if(flags & ASN1_TFLG_SEQUENCE_OF) isset = 2;
229 } else isset = 0;
230 /* First work out inner tag value */
231 if(flags & ASN1_TFLG_IMPTAG) {
232 sktag = tt->tag;
233 skaclass = aclass;
234 } else {
235 skaclass = V_ASN1_UNIVERSAL;
236 if(isset) sktag = V_ASN1_SET;
237 else sktag = V_ASN1_SEQUENCE;
238 }
239 /* Now work out length of items */
240 skcontlen = 0;
241 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
242 skitem = sk_ASN1_VALUE_value(sk, i);
243 skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
244 }
245 sklen = ASN1_object_size(1, skcontlen, sktag);
246 /* If EXPLICIT need length of surrounding tag */
247 if(flags & ASN1_TFLG_EXPTAG)
248 ret = ASN1_object_size(1, sklen, tt->tag);
249 else ret = sklen;
250
251 if(!out) return ret;
252
253 /* Now encode this lot... */
254 /* EXPLICIT tag */
255 if(flags & ASN1_TFLG_EXPTAG)
256 ASN1_put_object(out, 1, sklen, tt->tag, aclass);
257 /* SET or SEQUENCE and IMPLICIT tag */
258 ASN1_put_object(out, 1, skcontlen, sktag, skaclass);
259 /* And finally the stuff itself */
260 asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset);
261
262 return ret;
263 }
264
265 if(flags & ASN1_TFLG_EXPTAG) {
266 /* EXPLICIT tagging */
267 /* Find length of tagged item */
268 i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
269 if(!i) return 0;
270 /* Find length of EXPLICIT tag */
271 ret = ASN1_object_size(1, i, tt->tag);
272 if(out) {
273 /* Output tag and item */
274 ASN1_put_object(out, 1, i, tt->tag, aclass);
275 ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
276 }
277 return ret;
278 }
279 if(flags & ASN1_TFLG_IMPTAG) {
280 /* IMPLICIT tagging */
281 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), tt->tag, aclass);
282 }
283 /* Nothing special: treat as normal */
284 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
285}
286
287/* Temporary structure used to hold DER encoding of items for SET OF */
288
289typedef struct {
290 unsigned char *data;
291 int length;
292 ASN1_VALUE *field;
293} DER_ENC;
294
295static int der_cmp(const void *a, const void *b)
296{
297 const DER_ENC *d1 = a, *d2 = b;
298 int cmplen, i;
299 cmplen = (d1->length < d2->length) ? d1->length : d2->length;
300 i = memcmp(d1->data, d2->data, cmplen);
301 if(i) return i;
302 return d1->length - d2->length;
303}
304
305/* Output the content octets of SET OF or SEQUENCE OF */
306
307static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int do_sort)
308{
309 int i;
310 ASN1_VALUE *skitem;
311 unsigned char *tmpdat = NULL, *p = NULL;
312 DER_ENC *derlst = NULL, *tder;
313 if(do_sort) {
314 /* Don't need to sort less than 2 items */
315 if(sk_ASN1_VALUE_num(sk) < 2) do_sort = 0;
316 else {
317 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst));
318 tmpdat = OPENSSL_malloc(skcontlen);
319 if(!derlst || !tmpdat) return 0;
320 }
321 }
322 /* If not sorting just output each item */
323 if(!do_sort) {
324 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
325 skitem = sk_ASN1_VALUE_value(sk, i);
326 ASN1_item_i2d(skitem, out, item);
327 }
328 return 1;
329 }
330 p = tmpdat;
331 /* Doing sort: build up a list of each member's DER encoding */
332 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
333 skitem = sk_ASN1_VALUE_value(sk, i);
334 tder->data = p;
335 tder->length = ASN1_item_i2d(skitem, &p, item);
336 tder->field = skitem;
337 }
338 /* Now sort them */
339 qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
340 /* Output sorted DER encoding */
341 p = *out;
342 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
343 memcpy(p, tder->data, tder->length);
344 p += tder->length;
345 }
346 *out = p;
347 /* If do_sort is 2 then reorder the STACK */
348 if(do_sort == 2) {
349 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
350 sk_ASN1_VALUE_set(sk, i, tder->field);
351 }
352 OPENSSL_free(derlst);
353 OPENSSL_free(tmpdat);
354 return 1;
355}
356
357static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
358{
359 int len;
360 int utype;
361 int usetag;
362
363 utype = it->utype;
364
365 /* Get length of content octets and maybe find
366 * out the underlying type.
367 */
368
369 len = asn1_ex_i2c(pval, NULL, &utype, it);
370
371 /* If SEQUENCE, SET or OTHER then header is
372 * included in pseudo content octets so don't
373 * include tag+length. We need to check here
374 * because the call to asn1_ex_i2c() could change
375 * utype.
376 */
377 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
378 (utype == V_ASN1_OTHER))
379 usetag = 0;
380 else usetag = 1;
381
382 /* -1 means omit type */
383
384 if(len == -1) return 0;
385
386 /* If not implicitly tagged get tag from underlying type */
387 if(tag == -1) tag = utype;
388
389 /* Output tag+length followed by content octets */
390 if(out) {
391 if(usetag) ASN1_put_object(out, 0, len, tag, aclass);
392 asn1_ex_i2c(pval, *out, &utype, it);
393 *out += len;
394 }
395
396 if(usetag) return ASN1_object_size(0, len, tag);
397 return len;
398}
399
400/* Produce content octets from a structure */
401
402int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_ITEM *it)
403{
404 ASN1_BOOLEAN *tbool = NULL;
405 ASN1_STRING *strtmp;
406 ASN1_OBJECT *otmp;
407 int utype;
408 unsigned char *cont, c;
409 int len;
410 const ASN1_PRIMITIVE_FUNCS *pf;
411 pf = it->funcs;
412 if(pf && pf->prim_i2c) return pf->prim_i2c(pval, cout, putype, it);
413
414 /* Should type be omitted? */
415 if((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
416 if(!*pval) return -1;
417 }
418
419 if(it->itype == ASN1_ITYPE_MSTRING) {
420 /* If MSTRING type set the underlying type */
421 strtmp = (ASN1_STRING *)*pval;
422 utype = strtmp->type;
423 *putype = utype;
424 } else if(it->utype == V_ASN1_ANY) {
425 /* If ANY set type and pointer to value */
426 ASN1_TYPE *typ;
427 typ = (ASN1_TYPE *)*pval;
428 utype = typ->type;
429 *putype = utype;
430 pval = (ASN1_VALUE **)&typ->value.ptr;
431 } else utype = *putype;
432
433 switch(utype) {
434 case V_ASN1_OBJECT:
435 otmp = (ASN1_OBJECT *)*pval;
436 cont = otmp->data;
437 len = otmp->length;
438 break;
439
440 case V_ASN1_NULL:
441 cont = NULL;
442 len = 0;
443 break;
444
445 case V_ASN1_BOOLEAN:
446 tbool = (ASN1_BOOLEAN *)pval;
447 if(*tbool == -1) return -1;
448 /* Default handling if value == size field then omit */
449 if(*tbool && (it->size > 0)) return -1;
450 if(!*tbool && !it->size) return -1;
451 c = (unsigned char)*tbool;
452 cont = &c;
453 len = 1;
454 break;
455
456 case V_ASN1_BIT_STRING:
457 return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL);
458 break;
459
460 case V_ASN1_INTEGER:
461 case V_ASN1_NEG_INTEGER:
462 case V_ASN1_ENUMERATED:
463 case V_ASN1_NEG_ENUMERATED:
464 /* These are all have the same content format
465 * as ASN1_INTEGER
466 */
467 return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
468 break;
469
470 case V_ASN1_OCTET_STRING:
471 case V_ASN1_NUMERICSTRING:
472 case V_ASN1_PRINTABLESTRING:
473 case V_ASN1_T61STRING:
474 case V_ASN1_VIDEOTEXSTRING:
475 case V_ASN1_IA5STRING:
476 case V_ASN1_UTCTIME:
477 case V_ASN1_GENERALIZEDTIME:
478 case V_ASN1_GRAPHICSTRING:
479 case V_ASN1_VISIBLESTRING:
480 case V_ASN1_GENERALSTRING:
481 case V_ASN1_UNIVERSALSTRING:
482 case V_ASN1_BMPSTRING:
483 case V_ASN1_UTF8STRING:
484 case V_ASN1_SEQUENCE:
485 case V_ASN1_SET:
486 default:
487 /* All based on ASN1_STRING and handled the same */
488 strtmp = (ASN1_STRING *)*pval;
489 cont = strtmp->data;
490 len = strtmp->length;
491
492 break;
493
494 }
495 if(cout && len) memcpy(cout, cont, len);
496 return len;
497}
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c
new file mode 100644
index 0000000000..c7610776f2
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_fre.c
@@ -0,0 +1,226 @@
1/* tasn_fre.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63#include <openssl/objects.h>
64
65static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
66
67/* Free up an ASN1 structure */
68
69void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
70{
71 asn1_item_combine_free(&val, it, 0);
72}
73
74void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
75{
76 asn1_item_combine_free(pval, it, 0);
77}
78
79static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
80{
81 const ASN1_TEMPLATE *tt = NULL, *seqtt;
82 const ASN1_EXTERN_FUNCS *ef;
83 const ASN1_COMPAT_FUNCS *cf;
84 const ASN1_AUX *aux = it->funcs;
85 ASN1_aux_cb *asn1_cb;
86 int i;
87 if(!pval) return;
88 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return;
89 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
90 else asn1_cb = 0;
91
92 switch(it->itype) {
93
94 case ASN1_ITYPE_PRIMITIVE:
95 if(it->templates) ASN1_template_free(pval, it->templates);
96 else ASN1_primitive_free(pval, it);
97 break;
98
99 case ASN1_ITYPE_MSTRING:
100 ASN1_primitive_free(pval, it);
101 break;
102
103 case ASN1_ITYPE_CHOICE:
104 if(asn1_cb) {
105 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
106 if(i == 2) return;
107 }
108 i = asn1_get_choice_selector(pval, it);
109 if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it);
110 if((i >= 0) && (i < it->tcount)) {
111 ASN1_VALUE **pchval;
112 tt = it->templates + i;
113 pchval = asn1_get_field_ptr(pval, tt);
114 ASN1_template_free(pchval, tt);
115 }
116 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
117 if(!combine) {
118 OPENSSL_free(*pval);
119 *pval = NULL;
120 }
121 break;
122
123 case ASN1_ITYPE_COMPAT:
124 cf = it->funcs;
125 if(cf && cf->asn1_free) cf->asn1_free(*pval);
126 break;
127
128 case ASN1_ITYPE_EXTERN:
129 ef = it->funcs;
130 if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
131 break;
132
133 case ASN1_ITYPE_SEQUENCE:
134 if(asn1_do_lock(pval, -1, it) > 0) return;
135 if(asn1_cb) {
136 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
137 if(i == 2) return;
138 }
139 asn1_enc_free(pval, it);
140 /* If we free up as normal we will invalidate any
141 * ANY DEFINED BY field and we wont be able to
142 * determine the type of the field it defines. So
143 * free up in reverse order.
144 */
145 tt = it->templates + it->tcount - 1;
146 for(i = 0; i < it->tcount; tt--, i++) {
147 ASN1_VALUE **pseqval;
148 seqtt = asn1_do_adb(pval, tt, 0);
149 if(!seqtt) continue;
150 pseqval = asn1_get_field_ptr(pval, seqtt);
151 ASN1_template_free(pseqval, seqtt);
152 }
153 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
154 if(!combine) {
155 OPENSSL_free(*pval);
156 *pval = NULL;
157 }
158 break;
159 }
160}
161
162void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
163{
164 int i;
165 if(tt->flags & ASN1_TFLG_SK_MASK) {
166 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
167 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
168 ASN1_VALUE *vtmp;
169 vtmp = sk_ASN1_VALUE_value(sk, i);
170 asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
171 }
172 sk_ASN1_VALUE_free(sk);
173 *pval = NULL;
174 } else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
175 tt->flags & ASN1_TFLG_COMBINE);
176}
177
178void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
179{
180 int utype;
181 if(it) {
182 const ASN1_PRIMITIVE_FUNCS *pf;
183 pf = it->funcs;
184 if(pf && pf->prim_free) {
185 pf->prim_free(pval, it);
186 return;
187 }
188 }
189 /* Special case: if 'it' is NULL free contents of ASN1_TYPE */
190 if(!it) {
191 ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
192 utype = typ->type;
193 pval = (ASN1_VALUE **)&typ->value.ptr;
194 if(!*pval) return;
195 } else if(it->itype == ASN1_ITYPE_MSTRING) {
196 utype = -1;
197 if(!*pval) return;
198 } else {
199 utype = it->utype;
200 if((utype != V_ASN1_BOOLEAN) && !*pval) return;
201 }
202
203 switch(utype) {
204 case V_ASN1_OBJECT:
205 ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
206 break;
207
208 case V_ASN1_BOOLEAN:
209 *(ASN1_BOOLEAN *)pval = it->size;
210 return;
211
212 case V_ASN1_NULL:
213 break;
214
215 case V_ASN1_ANY:
216 ASN1_primitive_free(pval, NULL);
217 OPENSSL_free(*pval);
218 break;
219
220 default:
221 ASN1_STRING_free((ASN1_STRING *)*pval);
222 *pval = NULL;
223 break;
224 }
225 *pval = NULL;
226}
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
new file mode 100644
index 0000000000..e33861f864
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -0,0 +1,348 @@
1/* tasn_new.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/err.h>
64#include <openssl/asn1t.h>
65#include <string.h>
66
67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
68static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
70void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
71
72ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
73{
74 ASN1_VALUE *ret = NULL;
75 if(ASN1_item_ex_new(&ret, it) > 0) return ret;
76 return NULL;
77}
78
79/* Allocate an ASN1 structure */
80
81int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
82{
83 return asn1_item_ex_combine_new(pval, it, 0);
84}
85
86static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
87{
88 const ASN1_TEMPLATE *tt = NULL;
89 const ASN1_COMPAT_FUNCS *cf;
90 const ASN1_EXTERN_FUNCS *ef;
91 const ASN1_AUX *aux = it->funcs;
92 ASN1_aux_cb *asn1_cb;
93 ASN1_VALUE **pseqval;
94 int i;
95 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
96 else asn1_cb = 0;
97
98 if(!combine) *pval = NULL;
99
100#ifdef CRYPTO_MDEBUG
101 if(it->sname) CRYPTO_push_info(it->sname);
102#endif
103
104 switch(it->itype) {
105
106 case ASN1_ITYPE_EXTERN:
107 ef = it->funcs;
108 if(ef && ef->asn1_ex_new) {
109 if(!ef->asn1_ex_new(pval, it))
110 goto memerr;
111 }
112 break;
113
114 case ASN1_ITYPE_COMPAT:
115 cf = it->funcs;
116 if(cf && cf->asn1_new) {
117 *pval = cf->asn1_new();
118 if(!*pval) goto memerr;
119 }
120 break;
121
122 case ASN1_ITYPE_PRIMITIVE:
123 if(it->templates) {
124 if(!ASN1_template_new(pval, it->templates))
125 goto memerr;
126 } else {
127 if(!ASN1_primitive_new(pval, it))
128 goto memerr;
129 }
130 break;
131
132 case ASN1_ITYPE_MSTRING:
133 if(!ASN1_primitive_new(pval, it))
134 goto memerr;
135 break;
136
137 case ASN1_ITYPE_CHOICE:
138 if(asn1_cb) {
139 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
140 if(!i) goto auxerr;
141 if(i==2) {
142#ifdef CRYPTO_MDEBUG
143 if(it->sname) CRYPTO_pop_info();
144#endif
145 return 1;
146 }
147 }
148 if(!combine) {
149 *pval = OPENSSL_malloc(it->size);
150 if(!*pval) goto memerr;
151 memset(*pval, 0, it->size);
152 }
153 asn1_set_choice_selector(pval, -1, it);
154 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
155 goto auxerr;
156 break;
157
158 case ASN1_ITYPE_SEQUENCE:
159 if(asn1_cb) {
160 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
161 if(!i) goto auxerr;
162 if(i==2) {
163#ifdef CRYPTO_MDEBUG
164 if(it->sname) CRYPTO_pop_info();
165#endif
166 return 1;
167 }
168 }
169 if(!combine) {
170 *pval = OPENSSL_malloc(it->size);
171 if(!*pval) goto memerr;
172 memset(*pval, 0, it->size);
173 asn1_do_lock(pval, 0, it);
174 asn1_enc_init(pval, it);
175 }
176 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
177 pseqval = asn1_get_field_ptr(pval, tt);
178 if(!ASN1_template_new(pseqval, tt)) goto memerr;
179 }
180 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
181 goto auxerr;
182 break;
183 }
184#ifdef CRYPTO_MDEBUG
185 if(it->sname) CRYPTO_pop_info();
186#endif
187 return 1;
188
189 memerr:
190 ASN1err(ASN1_F_ASN1_ITEM_NEW, ERR_R_MALLOC_FAILURE);
191#ifdef CRYPTO_MDEBUG
192 if(it->sname) CRYPTO_pop_info();
193#endif
194 return 0;
195
196 auxerr:
197 ASN1err(ASN1_F_ASN1_ITEM_NEW, ASN1_R_AUX_ERROR);
198 ASN1_item_ex_free(pval, it);
199#ifdef CRYPTO_MDEBUG
200 if(it->sname) CRYPTO_pop_info();
201#endif
202 return 0;
203
204}
205
206static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
207{
208 const ASN1_EXTERN_FUNCS *ef;
209
210 switch(it->itype) {
211
212 case ASN1_ITYPE_EXTERN:
213 ef = it->funcs;
214 if(ef && ef->asn1_ex_clear)
215 ef->asn1_ex_clear(pval, it);
216 else *pval = NULL;
217 break;
218
219
220 case ASN1_ITYPE_PRIMITIVE:
221 if(it->templates)
222 asn1_template_clear(pval, it->templates);
223 else
224 asn1_primitive_clear(pval, it);
225 break;
226
227 case ASN1_ITYPE_MSTRING:
228 asn1_primitive_clear(pval, it);
229 break;
230
231 case ASN1_ITYPE_COMPAT:
232 case ASN1_ITYPE_CHOICE:
233 case ASN1_ITYPE_SEQUENCE:
234 *pval = NULL;
235 break;
236 }
237}
238
239
240int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
241{
242 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
243 int ret;
244 if(tt->flags & ASN1_TFLG_OPTIONAL) {
245 asn1_template_clear(pval, tt);
246 return 1;
247 }
248 /* If ANY DEFINED BY nothing to do */
249
250 if(tt->flags & ASN1_TFLG_ADB_MASK) {
251 *pval = NULL;
252 return 1;
253 }
254#ifdef CRYPTO_MDEBUG
255 if(tt->field_name) CRYPTO_push_info(tt->field_name);
256#endif
257 /* If SET OF or SEQUENCE OF, its a STACK */
258 if(tt->flags & ASN1_TFLG_SK_MASK) {
259 STACK_OF(ASN1_VALUE) *skval;
260 skval = sk_ASN1_VALUE_new_null();
261 if(!skval) {
262 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
263 ret = 0;
264 goto done;
265 }
266 *pval = (ASN1_VALUE *)skval;
267 ret = 1;
268 goto done;
269 }
270 /* Otherwise pass it back to the item routine */
271 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
272 done:
273#ifdef CRYPTO_MDEBUG
274 if(it->sname) CRYPTO_pop_info();
275#endif
276 return ret;
277}
278
279static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
280{
281 /* If ADB or STACK just NULL the field */
282 if(tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
283 *pval = NULL;
284 else
285 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
286}
287
288
289/* NB: could probably combine most of the real XXX_new() behaviour and junk all the old
290 * functions.
291 */
292
293int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
294{
295 ASN1_TYPE *typ;
296 int utype;
297 const ASN1_PRIMITIVE_FUNCS *pf;
298 pf = it->funcs;
299 if(pf && pf->prim_new) return pf->prim_new(pval, it);
300 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
301 else utype = it->utype;
302 switch(utype) {
303 case V_ASN1_OBJECT:
304 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
305 return 1;
306
307 case V_ASN1_BOOLEAN:
308 *(ASN1_BOOLEAN *)pval = it->size;
309 return 1;
310
311 case V_ASN1_NULL:
312 *pval = (ASN1_VALUE *)1;
313 return 1;
314
315 case V_ASN1_ANY:
316 typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
317 if(!typ) return 0;
318 typ->value.ptr = NULL;
319 typ->type = -1;
320 *pval = (ASN1_VALUE *)typ;
321 break;
322
323 default:
324 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
325 break;
326 }
327 if(*pval) return 1;
328 return 0;
329}
330
331void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
332{
333 int utype;
334 const ASN1_PRIMITIVE_FUNCS *pf;
335 pf = it->funcs;
336 if(pf) {
337 if(pf->prim_clear)
338 pf->prim_clear(pval, it);
339 else
340 *pval = NULL;
341 return;
342 }
343 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
344 else utype = it->utype;
345 if(utype == V_ASN1_BOOLEAN)
346 *(ASN1_BOOLEAN *)pval = it->size;
347 else *pval = NULL;
348}
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
new file mode 100644
index 0000000000..fab67ae5ac
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_prn.c
@@ -0,0 +1,198 @@
1/* tasn_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/buffer.h>
64#include <openssl/err.h>
65#include <openssl/nasn.h>
66
67/* Print routines. Print out a whole structure from a template.
68 */
69
70static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name);
71
72int ASN1_item_print(BIO *out, void *fld, int indent, const ASN1_ITEM *it)
73{
74 return asn1_item_print_nm(out, fld, indent, it, it->sname);
75}
76
77static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name)
78{
79 ASN1_STRING *str;
80 const ASN1_TEMPLATE *tt;
81 void *tmpfld;
82 int i;
83 if(!fld) {
84 BIO_printf(out, "%*s%s ABSENT\n", indent, "", name);
85 return 1;
86 }
87 switch(it->itype) {
88
89 case ASN1_ITYPE_PRIMITIVE:
90 if(it->templates)
91 return ASN1_template_print(out, fld, indent, it->templates);
92 return asn1_primitive_print(out, fld, it->utype, indent, name);
93 break;
94
95 case ASN1_ITYPE_MSTRING:
96 str = fld;
97 return asn1_primitive_print(out, fld, str->type, indent, name);
98
99 case ASN1_ITYPE_EXTERN:
100 BIO_printf(out, "%*s%s:EXTERNAL TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
101 return 1;
102 case ASN1_ITYPE_COMPAT:
103 BIO_printf(out, "%*s%s:COMPATIBLE TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
104 return 1;
105
106
107 case ASN1_ITYPE_CHOICE:
108 /* CHOICE type, get selector */
109 i = asn1_get_choice_selector(fld, it);
110 /* This should never happen... */
111 if((i < 0) || (i >= it->tcount)) {
112 BIO_printf(out, "%s selector [%d] out of range\n", it->sname, i);
113 return 1;
114 }
115 tt = it->templates + i;
116 tmpfld = asn1_get_field(fld, tt);
117 return ASN1_template_print(out, tmpfld, indent, tt);
118
119 case ASN1_ITYPE_SEQUENCE:
120 BIO_printf(out, "%*s%s {\n", indent, "", name);
121 /* Get each field entry */
122 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
123 tmpfld = asn1_get_field(fld, tt);
124 ASN1_template_print(out, tmpfld, indent + 2, tt);
125 }
126 BIO_printf(out, "%*s}\n", indent, "");
127 return 1;
128
129 default:
130 return 0;
131 }
132}
133
134int ASN1_template_print(BIO *out, void *fld, int indent, const ASN1_TEMPLATE *tt)
135{
136 int i, flags;
137#if 0
138 if(!fld) return 0;
139#endif
140 flags = tt->flags;
141 if(flags & ASN1_TFLG_SK_MASK) {
142 char *tname;
143 void *skitem;
144 /* SET OF, SEQUENCE OF */
145 if(flags & ASN1_TFLG_SET_OF) tname = "SET";
146 else tname = "SEQUENCE";
147 if(fld) {
148 BIO_printf(out, "%*s%s OF %s {\n", indent, "", tname, tt->field_name);
149 for(i = 0; i < sk_num(fld); i++) {
150 skitem = sk_value(fld, i);
151 asn1_item_print_nm(out, skitem, indent + 2, tt->item, "");
152 }
153 BIO_printf(out, "%*s}\n", indent, "");
154 } else
155 BIO_printf(out, "%*s%s OF %s ABSENT\n", indent, "", tname, tt->field_name);
156 return 1;
157 }
158 return asn1_item_print_nm(out, fld, indent, tt->item, tt->field_name);
159}
160
161static int asn1_primitive_print(BIO *out, void *fld, long utype, int indent, const char *name)
162{
163 ASN1_STRING *str = fld;
164 if(fld) {
165 if(utype == V_ASN1_BOOLEAN) {
166 int *bool = fld;
167if(*bool == -1) printf("BOOL MISSING\n");
168 BIO_printf(out, "%*s%s:%s", indent, "", "BOOLEAN", *bool ? "TRUE" : "FALSE");
169 } else if((utype == V_ASN1_INTEGER)
170 || (utype == V_ASN1_ENUMERATED)) {
171 char *s, *nm;
172 s = i2s_ASN1_INTEGER(NULL, fld);
173 if(utype == V_ASN1_INTEGER) nm = "INTEGER";
174 else nm = "ENUMERATED";
175 BIO_printf(out, "%*s%s:%s", indent, "", nm, s);
176 OPENSSL_free(s);
177 } else if(utype == V_ASN1_NULL) {
178 BIO_printf(out, "%*s%s", indent, "", "NULL");
179 } else if(utype == V_ASN1_UTCTIME) {
180 BIO_printf(out, "%*s%s:%s:", indent, "", name, "UTCTIME");
181 ASN1_UTCTIME_print(out, str);
182 } else if(utype == V_ASN1_GENERALIZEDTIME) {
183 BIO_printf(out, "%*s%s:%s:", indent, "", name, "GENERALIZEDTIME");
184 ASN1_GENERALIZEDTIME_print(out, str);
185 } else if(utype == V_ASN1_OBJECT) {
186 char objbuf[80], *ln;
187 ln = OBJ_nid2ln(OBJ_obj2nid(fld));
188 if(!ln) ln = "";
189 OBJ_obj2txt(objbuf, 80, fld, 1);
190 BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf);
191 } else {
192 BIO_printf(out, "%*s%s:", indent, "", name);
193 ASN1_STRING_print_ex(out, str, ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE);
194 }
195 BIO_printf(out, "\n");
196 } else BIO_printf(out, "%*s%s [ABSENT]\n", indent, "", name);
197 return 1;
198}
diff --git a/src/lib/libcrypto/asn1/tasn_typ.c b/src/lib/libcrypto/asn1/tasn_typ.c
new file mode 100644
index 0000000000..804d2eeba2
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_typ.c
@@ -0,0 +1,133 @@
1/* tasn_typ.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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#include <stdio.h>
59#include <openssl/asn1.h>
60#include <openssl/asn1t.h>
61
62/* Declarations for string types */
63
64
65IMPLEMENT_ASN1_TYPE(ASN1_INTEGER)
66IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER)
67
68IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED)
69IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED)
70
71IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING)
72IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING)
73
74IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING)
75IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
76
77IMPLEMENT_ASN1_TYPE(ASN1_NULL)
78IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
79
80IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
81
82IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING)
83IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING)
84
85IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING)
86IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
87
88IMPLEMENT_ASN1_TYPE(ASN1_T61STRING)
89IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING)
90
91IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING)
92IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING)
93
94IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING)
95IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
96
97IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME)
98IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME)
99
100IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME)
101IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
102
103IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING)
104IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
105
106IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING)
107IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
108
109IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING)
110IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING)
111
112IMPLEMENT_ASN1_TYPE(ASN1_ANY)
113
114/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
115IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
116
117IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
118
119/* Multistring types */
120
121IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
122IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
123
124IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
125IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
126
127IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
128IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
129
130/* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
131IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
132IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
133IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
new file mode 100644
index 0000000000..8996ce8c13
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_utl.c
@@ -0,0 +1,253 @@
1/* tasn_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/err.h>
66
67/* Utility functions for manipulating fields and offsets */
68
69/* Add 'offset' to 'addr' */
70#define offset2ptr(addr, offset) (void *)(((char *) addr) + offset)
71
72/* Given an ASN1_ITEM CHOICE type return
73 * the selector value
74 */
75
76int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
77{
78 int *sel = offset2ptr(*pval, it->utype);
79 return *sel;
80}
81
82/* Given an ASN1_ITEM CHOICE type set
83 * the selector value, return old value.
84 */
85
86int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
87{
88 int *sel, ret;
89 sel = offset2ptr(*pval, it->utype);
90 ret = *sel;
91 *sel = value;
92 return ret;
93}
94
95/* Do reference counting. The value 'op' decides what to do.
96 * if it is +1 then the count is incremented. If op is 0 count is
97 * set to 1. If op is -1 count is decremented and the return value
98 * is the current refrence count or 0 if no reference count exists.
99 */
100
101int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
102{
103 const ASN1_AUX *aux;
104 int *lck, ret;
105 if(it->itype != ASN1_ITYPE_SEQUENCE) return 0;
106 aux = it->funcs;
107 if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0;
108 lck = offset2ptr(*pval, aux->ref_offset);
109 if(op == 0) {
110 *lck = 1;
111 return 1;
112 }
113 ret = CRYPTO_add(lck, op, aux->ref_lock);
114#ifdef REF_PRINT
115 fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck);
116#endif
117#ifdef REF_CHECK
118 if(ret < 0)
119 fprintf(stderr, "%s, bad reference count\n", it->sname);
120#endif
121 return ret;
122}
123
124static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
125{
126 const ASN1_AUX *aux;
127 if(!pval || !*pval) return NULL;
128 aux = it->funcs;
129 if(!aux || !(aux->flags & ASN1_AFLG_ENCODING)) return NULL;
130 return offset2ptr(*pval, aux->enc_offset);
131}
132
133void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
134{
135 ASN1_ENCODING *enc;
136 enc = asn1_get_enc_ptr(pval, it);
137 if(enc) {
138 enc->enc = NULL;
139 enc->len = 0;
140 enc->modified = 1;
141 }
142}
143
144void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
145{
146 ASN1_ENCODING *enc;
147 enc = asn1_get_enc_ptr(pval, it);
148 if(enc) {
149 if(enc->enc) OPENSSL_free(enc->enc);
150 enc->enc = NULL;
151 enc->len = 0;
152 enc->modified = 1;
153 }
154}
155
156int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it)
157{
158 ASN1_ENCODING *enc;
159 enc = asn1_get_enc_ptr(pval, it);
160 if(!enc) return 1;
161
162 if(enc->enc) OPENSSL_free(enc->enc);
163 enc->enc = OPENSSL_malloc(inlen);
164 if(!enc->enc) return 0;
165 memcpy(enc->enc, in, inlen);
166 enc->len = inlen;
167 enc->modified = 0;
168
169 return 1;
170}
171
172int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it)
173{
174 ASN1_ENCODING *enc;
175 enc = asn1_get_enc_ptr(pval, it);
176 if(!enc || enc->modified) return 0;
177 if(out) {
178 memcpy(*out, enc->enc, enc->len);
179 *out += enc->len;
180 }
181 if(len) *len = enc->len;
182 return 1;
183}
184
185/* Given an ASN1_TEMPLATE get a pointer to a field */
186ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
187{
188 ASN1_VALUE **pvaltmp;
189 if(tt->flags & ASN1_TFLG_COMBINE) return pval;
190 pvaltmp = offset2ptr(*pval, tt->offset);
191 /* NOTE for BOOLEAN types the field is just a plain
192 * int so we can't return int **, so settle for
193 * (int *).
194 */
195 return pvaltmp;
196}
197
198/* Handle ANY DEFINED BY template, find the selector, look up
199 * the relevant ASN1_TEMPLATE in the table and return it.
200 */
201
202const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
203{
204 const ASN1_ADB *adb;
205 const ASN1_ADB_TABLE *atbl;
206 long selector;
207 ASN1_VALUE **sfld;
208 int i;
209 if(!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt;
210
211 /* Else ANY DEFINED BY ... get the table */
212 adb = ASN1_ADB_ptr(tt->item);
213
214 /* Get the selector field */
215 sfld = offset2ptr(*pval, adb->offset);
216
217 /* Check if NULL */
218 if(!sfld) {
219 if(!adb->null_tt) goto err;
220 return adb->null_tt;
221 }
222
223 /* Convert type to a long:
224 * NB: don't check for NID_undef here because it
225 * might be a legitimate value in the table
226 */
227 if(tt->flags & ASN1_TFLG_ADB_OID)
228 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
229 else
230 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
231
232 /* Try to find matching entry in table
233 * Maybe should check application types first to
234 * allow application override? Might also be useful
235 * to have a flag which indicates table is sorted and
236 * we can do a binary search. For now stick to a
237 * linear search.
238 */
239
240 for(atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
241 if(atbl->value == selector) return &atbl->tt;
242
243 /* FIXME: need to search application table too */
244
245 /* No match, return default type */
246 if(!adb->default_tt) goto err;
247 return adb->default_tt;
248
249 err:
250 /* FIXME: should log the value or OID of unsupported type */
251 if(nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
252 return NULL;
253}
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
new file mode 100644
index 0000000000..00b9ea54a1
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_algor.c
@@ -0,0 +1,73 @@
1/* x_algor.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 <stddef.h>
60#include <openssl/x509.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63
64ASN1_SEQUENCE(X509_ALGOR) = {
65 ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT),
66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
67} ASN1_SEQUENCE_END(X509_ALGOR)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
70IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
71
72IMPLEMENT_STACK_OF(X509_ALGOR)
73IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
new file mode 100644
index 0000000000..1e3713f18f
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_attrib.c
@@ -0,0 +1,118 @@
1/* crypto/asn1/x_attrib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/objects.h>
62#include <openssl/asn1t.h>
63#include <openssl/x509.h>
64
65/* X509_ATTRIBUTE: this has the following form:
66 *
67 * typedef struct x509_attributes_st
68 * {
69 * ASN1_OBJECT *object;
70 * int single;
71 * union {
72 * char *ptr;
73 * STACK_OF(ASN1_TYPE) *set;
74 * ASN1_TYPE *single;
75 * } value;
76 * } X509_ATTRIBUTE;
77 *
78 * this needs some extra thought because the CHOICE type is
79 * merged with the main structure and because the value can
80 * be anything at all we *must* try the SET OF first because
81 * the ASN1_ANY type will swallow anything including the whole
82 * SET OF structure.
83 */
84
85ASN1_CHOICE(X509_ATTRIBUTE_SET) = {
86 ASN1_SET_OF(X509_ATTRIBUTE, value.set, ASN1_ANY),
87 ASN1_SIMPLE(X509_ATTRIBUTE, value.single, ASN1_ANY)
88} ASN1_CHOICE_END_selector(X509_ATTRIBUTE, X509_ATTRIBUTE_SET, single)
89
90ASN1_SEQUENCE(X509_ATTRIBUTE) = {
91 ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT),
92 /* CHOICE type merged with parent */
93 ASN1_EX_COMBINE(0, 0, X509_ATTRIBUTE_SET)
94} ASN1_SEQUENCE_END(X509_ATTRIBUTE)
95
96IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
97IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
98
99X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
100 {
101 X509_ATTRIBUTE *ret=NULL;
102 ASN1_TYPE *val=NULL;
103
104 if ((ret=X509_ATTRIBUTE_new()) == NULL)
105 return(NULL);
106 ret->object=OBJ_nid2obj(nid);
107 ret->single=0;
108 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
109 if ((val=ASN1_TYPE_new()) == NULL) goto err;
110 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
111
112 ASN1_TYPE_set(val,atrtype,value);
113 return(ret);
114err:
115 if (ret != NULL) X509_ATTRIBUTE_free(ret);
116 if (val != NULL) ASN1_TYPE_free(val);
117 return(NULL);
118 }
diff --git a/src/lib/libcrypto/asn1/x_bignum.c b/src/lib/libcrypto/asn1/x_bignum.c
new file mode 100644
index 0000000000..848c7a0877
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_bignum.c
@@ -0,0 +1,137 @@
1/* x_bignum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a
64 * BIGNUM directly. Currently it ignores the sign which isn't a problem since all
65 * BIGNUMs used are non negative and anything that looks negative is normally due
66 * to an encoding error.
67 */
68
69#define BN_SENSITIVE 1
70
71static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
72static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
73
74static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
75static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
76
77static ASN1_PRIMITIVE_FUNCS bignum_pf = {
78 NULL, 0,
79 bn_new,
80 bn_free,
81 0,
82 bn_c2i,
83 bn_i2c
84};
85
86ASN1_ITEM_start(BIGNUM)
87 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM"
88ASN1_ITEM_end(BIGNUM)
89
90ASN1_ITEM_start(CBIGNUM)
91 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM"
92ASN1_ITEM_end(CBIGNUM)
93
94static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
95{
96 *pval = (ASN1_VALUE *)BN_new();
97 if(*pval) return 1;
98 else return 0;
99}
100
101static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
102{
103 if(!*pval) return;
104 if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval);
105 else BN_free((BIGNUM *)*pval);
106 *pval = NULL;
107}
108
109static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
110{
111 BIGNUM *bn;
112 int pad;
113 if(!*pval) return -1;
114 bn = (BIGNUM *)*pval;
115 /* If MSB set in an octet we need a padding byte */
116 if(BN_num_bits(bn) & 0x7) pad = 0;
117 else pad = 1;
118 if(cont) {
119 if(pad) *cont++ = 0;
120 BN_bn2bin(bn, cont);
121 }
122 return pad + BN_num_bytes(bn);
123}
124
125static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
126{
127 BIGNUM *bn;
128 if(!*pval) bn_new(pval, it);
129 bn = (BIGNUM *)*pval;
130 if(!BN_bin2bn(cont, len, bn)) {
131 bn_free(pval, it);
132 return 0;
133 }
134 return 1;
135}
136
137
diff --git a/src/lib/libcrypto/asn1/x_cinf.c b/src/lib/libcrypto/asn1/x_cinf.c
new file mode 100644
index 0000000000..339a110eef
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_cinf.c
@@ -0,0 +1,201 @@
1/* crypto/asn1/x_cinf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_CINF(X509_CINF *a, unsigned char **pp)
65 {
66 int v1=0,v2=0;
67 M_ASN1_I2D_vars(a);
68
69 M_ASN1_I2D_len_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1);
70 M_ASN1_I2D_len(a->serialNumber, i2d_ASN1_INTEGER);
71 M_ASN1_I2D_len(a->signature, i2d_X509_ALGOR);
72 M_ASN1_I2D_len(a->issuer, i2d_X509_NAME);
73 M_ASN1_I2D_len(a->validity, i2d_X509_VAL);
74 M_ASN1_I2D_len(a->subject, i2d_X509_NAME);
75 M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY);
76 M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING);
77 M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING);
78 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
79 i2d_X509_EXTENSION,3,
80 V_ASN1_SEQUENCE,v2);
81
82 M_ASN1_I2D_seq_total();
83
84 M_ASN1_I2D_put_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1);
85 M_ASN1_I2D_put(a->serialNumber, i2d_ASN1_INTEGER);
86 M_ASN1_I2D_put(a->signature, i2d_X509_ALGOR);
87 M_ASN1_I2D_put(a->issuer, i2d_X509_NAME);
88 M_ASN1_I2D_put(a->validity, i2d_X509_VAL);
89 M_ASN1_I2D_put(a->subject, i2d_X509_NAME);
90 M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY);
91 M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1);
92 M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2);
93 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
94 i2d_X509_EXTENSION,3,
95 V_ASN1_SEQUENCE,v2);
96
97 M_ASN1_I2D_finish();
98 }
99
100X509_CINF *d2i_X509_CINF(X509_CINF **a, unsigned char **pp, long length)
101 {
102 int ver=0;
103 M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new);
104
105 M_ASN1_D2I_Init();
106 M_ASN1_D2I_start_sequence();
107 /* we have the optional version field */
108 if (M_ASN1_next == (V_ASN1_CONTEXT_SPECIFIC | V_ASN1_CONSTRUCTED | 0))
109 {
110 M_ASN1_D2I_get_EXP_opt(ret->version,d2i_ASN1_INTEGER,0);
111 if (ret->version->data != NULL)
112 ver=ret->version->data[0];
113 }
114 else
115 {
116 if (ret->version != NULL)
117 {
118 M_ASN1_INTEGER_free(ret->version);
119 ret->version=NULL;
120 }
121 }
122 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER);
123 M_ASN1_D2I_get(ret->signature,d2i_X509_ALGOR);
124 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
125 M_ASN1_D2I_get(ret->validity,d2i_X509_VAL);
126 M_ASN1_D2I_get(ret->subject,d2i_X509_NAME);
127 M_ASN1_D2I_get(ret->key,d2i_X509_PUBKEY);
128 if (ver >= 1) /* version 2 extensions */
129 {
130 if (ret->issuerUID != NULL)
131 {
132 M_ASN1_BIT_STRING_free(ret->issuerUID);
133 ret->issuerUID=NULL;
134 }
135 if (ret->subjectUID != NULL)
136 {
137 M_ASN1_BIT_STRING_free(ret->subjectUID);
138 ret->subjectUID=NULL;
139 }
140 M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1,
141 V_ASN1_BIT_STRING);
142 M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2,
143 V_ASN1_BIT_STRING);
144 }
145/* Note: some broken certificates include extensions but don't set
146 * the version number properly. By bypassing this check they can
147 * be parsed.
148 */
149
150#ifdef VERSION_EXT_CHECK
151 if (ver >= 2) /* version 3 extensions */
152#endif
153 {
154 if (ret->extensions != NULL)
155 while (sk_X509_EXTENSION_num(ret->extensions))
156 X509_EXTENSION_free(
157 sk_X509_EXTENSION_pop(ret->extensions));
158 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
159 d2i_X509_EXTENSION,
160 X509_EXTENSION_free,3,
161 V_ASN1_SEQUENCE);
162 }
163 M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF);
164 }
165
166X509_CINF *X509_CINF_new(void)
167 {
168 X509_CINF *ret=NULL;
169 ASN1_CTX c;
170
171 M_ASN1_New_Malloc(ret,X509_CINF);
172 ret->version=NULL;
173 M_ASN1_New(ret->serialNumber,M_ASN1_INTEGER_new);
174 M_ASN1_New(ret->signature,X509_ALGOR_new);
175 M_ASN1_New(ret->issuer,X509_NAME_new);
176 M_ASN1_New(ret->validity,X509_VAL_new);
177 M_ASN1_New(ret->subject,X509_NAME_new);
178 M_ASN1_New(ret->key,X509_PUBKEY_new);
179 ret->issuerUID=NULL;
180 ret->subjectUID=NULL;
181 ret->extensions=NULL;
182 return(ret);
183 M_ASN1_New_Error(ASN1_F_X509_CINF_NEW);
184 }
185
186void X509_CINF_free(X509_CINF *a)
187 {
188 if (a == NULL) return;
189 M_ASN1_INTEGER_free(a->version);
190 M_ASN1_INTEGER_free(a->serialNumber);
191 X509_ALGOR_free(a->signature);
192 X509_NAME_free(a->issuer);
193 X509_VAL_free(a->validity);
194 X509_NAME_free(a->subject);
195 X509_PUBKEY_free(a->key);
196 M_ASN1_BIT_STRING_free(a->issuerUID);
197 M_ASN1_BIT_STRING_free(a->subjectUID);
198 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
199 OPENSSL_free(a);
200 }
201
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
new file mode 100644
index 0000000000..11fce96825
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -0,0 +1,162 @@
1/* crypto/asn1/x_crl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
65 const X509_REVOKED * const *b);
66static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a,
67 const X509_REVOKED * const *b);
68
69ASN1_SEQUENCE(X509_REVOKED) = {
70 ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER),
71 ASN1_SIMPLE(X509_REVOKED,revocationDate, ASN1_TIME),
72 ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION)
73} ASN1_SEQUENCE_END(X509_REVOKED)
74
75/* The X509_CRL_INFO structure needs a bit of customisation. This is actually
76 * mirroring the old behaviour: its purpose is to allow the use of
77 * sk_X509_REVOKED_find to lookup revoked certificates. Unfortunately
78 * this will zap the original order and the signature so we keep a copy
79 * of the original positions and reorder appropriately before encoding.
80 *
81 * Might want to see if there's a better way of doing this later...
82 */
83static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
84{
85 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
86 int i;
87 int (*old_cmp)(const X509_REVOKED * const *,
88 const X509_REVOKED * const *);
89
90 if(!a || !a->revoked) return 1;
91 switch(operation) {
92
93 /* Save original order */
94 case ASN1_OP_D2I_POST:
95 for (i=0; i<sk_X509_REVOKED_num(a->revoked); i++)
96 sk_X509_REVOKED_value(a->revoked,i)->sequence=i;
97 sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp);
98 break;
99
100 /* Restore original order */
101 case ASN1_OP_I2D_PRE:
102 old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp);
103 sk_X509_REVOKED_sort(a->revoked);
104 sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp);
105 break;
106 }
107 return 1;
108}
109
110
111ASN1_SEQUENCE_cb(X509_CRL_INFO, crl_inf_cb) = {
112 ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER),
113 ASN1_SIMPLE(X509_CRL_INFO, sig_alg, X509_ALGOR),
114 ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME),
115 ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME),
116 ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME),
117 ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED),
118 ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0)
119} ASN1_SEQUENCE_END_cb(X509_CRL_INFO, X509_CRL_INFO)
120
121ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = {
122 ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO),
123 ASN1_SIMPLE(X509_CRL, sig_alg, X509_ALGOR),
124 ASN1_SIMPLE(X509_CRL, signature, ASN1_BIT_STRING)
125} ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL)
126
127IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED)
128IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO)
129IMPLEMENT_ASN1_FUNCTIONS(X509_CRL)
130IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL)
131
132static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
133 const X509_REVOKED * const *b)
134 {
135 return(ASN1_STRING_cmp(
136 (ASN1_STRING *)(*a)->serialNumber,
137 (ASN1_STRING *)(*b)->serialNumber));
138 }
139
140static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a,
141 const X509_REVOKED * const *b)
142 {
143 return((*a)->sequence-(*b)->sequence);
144 }
145
146int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
147{
148 X509_CRL_INFO *inf;
149 inf = crl->crl;
150 if(!inf->revoked)
151 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
152 if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
153 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE);
154 return 0;
155 }
156 return 1;
157}
158
159IMPLEMENT_STACK_OF(X509_REVOKED)
160IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
161IMPLEMENT_STACK_OF(X509_CRL)
162IMPLEMENT_ASN1_SET_OF(X509_CRL)
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
new file mode 100644
index 0000000000..702421b6c8
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_exten.c
@@ -0,0 +1,71 @@
1/* x_exten.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 <stddef.h>
60#include <openssl/x509.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63
64ASN1_SEQUENCE(X509_EXTENSION) = {
65 ASN1_SIMPLE(X509_EXTENSION, object, ASN1_OBJECT),
66 ASN1_OPT(X509_EXTENSION, critical, ASN1_BOOLEAN),
67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
68} ASN1_SEQUENCE_END(X509_EXTENSION)
69
70IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
71IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION)
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
new file mode 100644
index 0000000000..d44f6cdb01
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_info.c
@@ -0,0 +1,114 @@
1/* crypto/asn1/x_info.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1.h>
63#include <openssl/x509.h>
64
65X509_INFO *X509_INFO_new(void)
66 {
67 X509_INFO *ret=NULL;
68
69 ret=(X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO));
70 if (ret == NULL)
71 {
72 ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE);
73 return(NULL);
74 }
75
76 ret->enc_cipher.cipher=NULL;
77 ret->enc_len=0;
78 ret->enc_data=NULL;
79
80 ret->references=1;
81 ret->x509=NULL;
82 ret->crl=NULL;
83 ret->x_pkey=NULL;
84 return(ret);
85 }
86
87void X509_INFO_free(X509_INFO *x)
88 {
89 int i;
90
91 if (x == NULL) return;
92
93 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO);
94#ifdef REF_PRINT
95 REF_PRINT("X509_INFO",x);
96#endif
97 if (i > 0) return;
98#ifdef REF_CHECK
99 if (i < 0)
100 {
101 fprintf(stderr,"X509_INFO_free, bad reference count\n");
102 abort();
103 }
104#endif
105
106 if (x->x509 != NULL) X509_free(x->x509);
107 if (x->crl != NULL) X509_CRL_free(x->crl);
108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey);
109 if (x->enc_data != NULL) OPENSSL_free(x->enc_data);
110 OPENSSL_free(x);
111 }
112
113IMPLEMENT_STACK_OF(X509_INFO)
114
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c
new file mode 100644
index 0000000000..c5f25956cb
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_long.c
@@ -0,0 +1,169 @@
1/* x_long.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for long handling. This converts between an ASN1_INTEGER
64 * and a long directly.
65 */
66
67
68static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
70
71static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
72static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
73
74static ASN1_PRIMITIVE_FUNCS long_pf = {
75 NULL, 0,
76 long_new,
77 long_free,
78 long_free, /* Clear should set to initial value */
79 long_c2i,
80 long_i2c
81};
82
83ASN1_ITEM_start(LONG)
84 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG"
85ASN1_ITEM_end(LONG)
86
87ASN1_ITEM_start(ZLONG)
88 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG"
89ASN1_ITEM_end(ZLONG)
90
91static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
92{
93 *(long *)pval = it->size;
94 return 1;
95}
96
97static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
98{
99 *(long *)pval = it->size;
100}
101
102static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
103{
104 long ltmp;
105 unsigned long utmp;
106 int clen, pad, i;
107 /* this exists to bypass broken gcc optimization */
108 char *cp = (char *)pval;
109
110 /* use memcpy, because we may not be long aligned */
111 memcpy(&ltmp, cp, sizeof(long));
112
113 if(ltmp == it->size) return -1;
114 /* Convert the long to positive: we subtract one if negative so
115 * we can cleanly handle the padding if only the MSB of the leading
116 * octet is set.
117 */
118 if(ltmp < 0) utmp = -ltmp - 1;
119 else utmp = ltmp;
120 clen = BN_num_bits_word(utmp);
121 /* If MSB of leading octet set we need to pad */
122 if(!(clen & 0x7)) pad = 1;
123 else pad = 0;
124
125 /* Convert number of bits to number of octets */
126 clen = (clen + 7) >> 3;
127
128 if(cont) {
129 if(pad) *cont++ = (ltmp < 0) ? 0xff : 0;
130 for(i = clen - 1; i >= 0; i--) {
131 cont[i] = (unsigned char)(utmp & 0xff);
132 if(ltmp < 0) cont[i] ^= 0xff;
133 utmp >>= 8;
134 }
135 }
136 return clen + pad;
137}
138
139static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
140{
141 int neg, i;
142 long ltmp;
143 unsigned long utmp = 0;
144 char *cp = (char *)pval;
145 if(len > sizeof(long)) {
146 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
147 return 0;
148 }
149 /* Is it negative? */
150 if(len && (cont[0] & 0x80)) neg = 1;
151 else neg = 0;
152 utmp = 0;
153 for(i = 0; i < len; i++) {
154 utmp <<= 8;
155 if(neg) utmp |= cont[i] ^ 0xff;
156 else utmp |= cont[i];
157 }
158 ltmp = (long)utmp;
159 if(neg) {
160 ltmp++;
161 ltmp = -ltmp;
162 }
163 if(ltmp == it->size) {
164 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
165 return 0;
166 }
167 memcpy(cp, &ltmp, sizeof(long));
168 return 1;
169}
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
new file mode 100644
index 0000000000..caece0f158
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -0,0 +1,272 @@
1/* crypto/asn1/x_name.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
65 int tag, int aclass, char opt, ASN1_TLC *ctx);
66
67static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
68static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it);
69static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it);
70
71static int x509_name_encode(X509_NAME *a);
72
73ASN1_SEQUENCE(X509_NAME_ENTRY) = {
74 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT),
75 ASN1_SIMPLE(X509_NAME_ENTRY, value, ASN1_PRINTABLE)
76} ASN1_SEQUENCE_END(X509_NAME_ENTRY)
77
78IMPLEMENT_ASN1_FUNCTIONS(X509_NAME_ENTRY)
79IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY)
80
81/* For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY }
82 * so declare two template wrappers for this
83 */
84
85ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) =
86 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY)
87ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES)
88
89ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) =
90 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES)
91ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL)
92
93/* Normally that's where it would end: we'd have two nested STACK structures
94 * representing the ASN1. Unfortunately X509_NAME uses a completely different
95 * form and caches encodings so we have to process the internal form and convert
96 * to the external form.
97 */
98
99const ASN1_EXTERN_FUNCS x509_name_ff = {
100 NULL,
101 x509_name_ex_new,
102 x509_name_ex_free,
103 0, /* Default clear behaviour is OK */
104 x509_name_ex_d2i,
105 x509_name_ex_i2d
106};
107
108IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff)
109
110IMPLEMENT_ASN1_FUNCTIONS(X509_NAME)
111IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)
112
113static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
114{
115 X509_NAME *ret = NULL;
116 ret = OPENSSL_malloc(sizeof(X509_NAME));
117 if(!ret) goto memerr;
118 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL)
119 goto memerr;
120 if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr;
121 ret->modified=1;
122 *val = (ASN1_VALUE *)ret;
123 return 1;
124
125 memerr:
126 ASN1err(ASN1_F_X509_NAME_NEW, ERR_R_MALLOC_FAILURE);
127 if (ret)
128 {
129 if (ret->entries)
130 sk_X509_NAME_ENTRY_free(ret->entries);
131 OPENSSL_free(ret);
132 }
133 return 0;
134}
135
136static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
137{
138 X509_NAME *a;
139 if(!pval || !*pval)
140 return;
141 a = (X509_NAME *)*pval;
142
143 BUF_MEM_free(a->bytes);
144 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
145 OPENSSL_free(a);
146 *pval = NULL;
147}
148
149/* Used with sk_pop_free() to free up the internal representation.
150 * NB: we only free the STACK and not its contents because it is
151 * already present in the X509_NAME structure.
152 */
153
154static void sk_internal_free(void *a)
155{
156 sk_free(a);
157}
158
159static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
160 int tag, int aclass, char opt, ASN1_TLC *ctx)
161{
162 unsigned char *p = *in, *q;
163 STACK *intname = NULL;
164 int i, j, ret;
165 X509_NAME *nm = NULL;
166 STACK_OF(X509_NAME_ENTRY) *entries;
167 X509_NAME_ENTRY *entry;
168 q = p;
169
170 /* Get internal representation of Name */
171 ret = ASN1_item_ex_d2i((ASN1_VALUE **)&intname, &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
172 tag, aclass, opt, ctx);
173
174 if(ret <= 0) return ret;
175
176 if(*val) x509_name_ex_free(val, NULL);
177 if(!x509_name_ex_new((ASN1_VALUE **)&nm, NULL)) goto err;
178 /* We've decoded it: now cache encoding */
179 if(!BUF_MEM_grow(nm->bytes, p - q)) goto err;
180 memcpy(nm->bytes->data, q, p - q);
181
182 /* Convert internal representation to X509_NAME structure */
183 for(i = 0; i < sk_num(intname); i++) {
184 entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname, i);
185 for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
186 entry = sk_X509_NAME_ENTRY_value(entries, j);
187 entry->set = i;
188 if(!sk_X509_NAME_ENTRY_push(nm->entries, entry))
189 goto err;
190 }
191 sk_X509_NAME_ENTRY_free(entries);
192 }
193 sk_free(intname);
194 nm->modified = 0;
195 *val = (ASN1_VALUE *)nm;
196 *in = p;
197 return ret;
198 err:
199 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_NESTED_ASN1_ERROR);
200 return 0;
201}
202
203static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
204{
205 int ret;
206 X509_NAME *a = (X509_NAME *)*val;
207 if(a->modified) {
208 ret = x509_name_encode((X509_NAME *)a);
209 if(ret < 0) return ret;
210 }
211 ret = a->bytes->length;
212 if(out != NULL) {
213 memcpy(*out,a->bytes->data,ret);
214 *out+=ret;
215 }
216 return ret;
217}
218
219static int x509_name_encode(X509_NAME *a)
220{
221 STACK *intname = NULL;
222 int len;
223 unsigned char *p;
224 STACK_OF(X509_NAME_ENTRY) *entries = NULL;
225 X509_NAME_ENTRY *entry;
226 int i, set = -1;
227 intname = sk_new_null();
228 if(!intname) goto memerr;
229 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
230 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
231 if(entry->set != set) {
232 entries = sk_X509_NAME_ENTRY_new_null();
233 if(!entries) goto memerr;
234 if(!sk_push(intname, (char *)entries)) goto memerr;
235 set = entry->set;
236 }
237 if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr;
238 }
239 len = ASN1_item_ex_i2d((ASN1_VALUE **)&intname, NULL, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
240 if (!BUF_MEM_grow(a->bytes,len)) goto memerr;
241 p=(unsigned char *)a->bytes->data;
242 ASN1_item_ex_i2d((ASN1_VALUE **)&intname, &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
243 sk_pop_free(intname, sk_internal_free);
244 a->modified = 0;
245 return len;
246 memerr:
247 sk_pop_free(intname, sk_internal_free);
248 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_MALLOC_FAILURE);
249 return -1;
250}
251
252
253int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
254 {
255 X509_NAME *in;
256
257 if (!xn || !name) return(0);
258
259 if (*xn != name)
260 {
261 in=X509_NAME_dup(name);
262 if (in != NULL)
263 {
264 X509_NAME_free(*xn);
265 *xn=in;
266 }
267 }
268 return(*xn != NULL);
269 }
270
271IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
272IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
new file mode 100644
index 0000000000..f1c6221ac3
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -0,0 +1,151 @@
1/* crypto/asn1/x_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509.h>
65
66/* need to implement */
67int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
68 {
69 return(0);
70 }
71
72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, unsigned char **pp, long length)
73 {
74 int i;
75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new);
76
77 M_ASN1_D2I_Init();
78 M_ASN1_D2I_start_sequence();
79 M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR);
80 M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING);
81
82 ret->cipher.cipher=EVP_get_cipherbyname(
83 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
84 if (ret->cipher.cipher == NULL)
85 {
86 c.error=ASN1_R_UNSUPPORTED_CIPHER;
87 c.line=__LINE__;
88 goto err;
89 }
90 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING)
91 {
92 i=ret->enc_algor->parameter->value.octet_string->length;
93 if (i > EVP_MAX_IV_LENGTH)
94 {
95 c.error=ASN1_R_IV_TOO_LARGE;
96 c.line=__LINE__;
97 goto err;
98 }
99 memcpy(ret->cipher.iv,
100 ret->enc_algor->parameter->value.octet_string->data,i);
101 }
102 else
103 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
104 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
105 }
106
107X509_PKEY *X509_PKEY_new(void)
108 {
109 X509_PKEY *ret=NULL;
110 ASN1_CTX c;
111
112 M_ASN1_New_Malloc(ret,X509_PKEY);
113 ret->version=0;
114 M_ASN1_New(ret->enc_algor,X509_ALGOR_new);
115 M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new);
116 ret->dec_pkey=NULL;
117 ret->key_length=0;
118 ret->key_data=NULL;
119 ret->key_free=0;
120 ret->cipher.cipher=NULL;
121 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
122 ret->references=1;
123 return(ret);
124 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
125 }
126
127void X509_PKEY_free(X509_PKEY *x)
128 {
129 int i;
130
131 if (x == NULL) return;
132
133 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY);
134#ifdef REF_PRINT
135 REF_PRINT("X509_PKEY",x);
136#endif
137 if (i > 0) return;
138#ifdef REF_CHECK
139 if (i < 0)
140 {
141 fprintf(stderr,"X509_PKEY_free, bad reference count\n");
142 abort();
143 }
144#endif
145
146 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor);
147 if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey);
148 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey);
149 if ((x->key_data != NULL) && (x->key_free)) OPENSSL_free(x->key_data);
150 OPENSSL_free(x);
151 }
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
new file mode 100644
index 0000000000..d958540120
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -0,0 +1,334 @@
1/* crypto/asn1/x_pubkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64/* Minor tweak to operation: free up EVP_PKEY */
65static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 if(operation == ASN1_OP_FREE_POST) {
68 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
69 EVP_PKEY_free(pubkey->pkey);
70 }
71 return 1;
72}
73
74ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = {
75 ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR),
76 ASN1_SIMPLE(X509_PUBKEY, public_key, ASN1_BIT_STRING)
77} ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY)
78
79IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
80
81int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
82 {
83 int ok=0;
84 X509_PUBKEY *pk;
85 X509_ALGOR *a;
86 ASN1_OBJECT *o;
87 unsigned char *s,*p = NULL;
88 int i;
89
90 if (x == NULL) return(0);
91
92 if ((pk=X509_PUBKEY_new()) == NULL) goto err;
93 a=pk->algor;
94
95 /* set the algorithm id */
96 if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
97 ASN1_OBJECT_free(a->algorithm);
98 a->algorithm=o;
99
100 /* Set the parameter list */
101 if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))
102 {
103 if ((a->parameter == NULL) ||
104 (a->parameter->type != V_ASN1_NULL))
105 {
106 ASN1_TYPE_free(a->parameter);
107 a->parameter=ASN1_TYPE_new();
108 a->parameter->type=V_ASN1_NULL;
109 }
110 }
111 else
112#ifndef OPENSSL_NO_DSA
113 if (pkey->type == EVP_PKEY_DSA)
114 {
115 unsigned char *pp;
116 DSA *dsa;
117
118 dsa=pkey->pkey.dsa;
119 dsa->write_params=0;
120 ASN1_TYPE_free(a->parameter);
121 i=i2d_DSAparams(dsa,NULL);
122 if ((p=(unsigned char *)OPENSSL_malloc(i)) == NULL) goto err;
123 pp=p;
124 i2d_DSAparams(dsa,&pp);
125 a->parameter=ASN1_TYPE_new();
126 a->parameter->type=V_ASN1_SEQUENCE;
127 a->parameter->value.sequence=ASN1_STRING_new();
128 ASN1_STRING_set(a->parameter->value.sequence,p,i);
129 OPENSSL_free(p);
130 }
131 else
132#endif
133 {
134 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
135 goto err;
136 }
137
138 if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
139 if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL)
140 {
141 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
142 goto err;
143 }
144 p=s;
145 i2d_PublicKey(pkey,&p);
146 if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
147 /* Set number of unused bits to zero */
148 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
149 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
150
151 OPENSSL_free(s);
152
153#if 0
154 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
155 pk->pkey=pkey;
156#endif
157
158 if (*x != NULL)
159 X509_PUBKEY_free(*x);
160
161 *x=pk;
162 pk=NULL;
163
164 ok=1;
165err:
166 if (pk != NULL) X509_PUBKEY_free(pk);
167 return(ok);
168 }
169
170EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
171 {
172 EVP_PKEY *ret=NULL;
173 long j;
174 int type;
175 unsigned char *p;
176#ifndef OPENSSL_NO_DSA
177 const unsigned char *cp;
178 X509_ALGOR *a;
179#endif
180
181 if (key == NULL) goto err;
182
183 if (key->pkey != NULL)
184 {
185 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
186 return(key->pkey);
187 }
188
189 if (key->public_key == NULL) goto err;
190
191 type=OBJ_obj2nid(key->algor->algorithm);
192 p=key->public_key->data;
193 j=key->public_key->length;
194 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
195 {
196 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
197 goto err;
198 }
199 ret->save_parameters=0;
200
201#ifndef OPENSSL_NO_DSA
202 a=key->algor;
203 if (ret->type == EVP_PKEY_DSA)
204 {
205 if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
206 {
207 ret->pkey.dsa->write_params=0;
208 cp=p=a->parameter->value.sequence->data;
209 j=a->parameter->value.sequence->length;
210 if (!d2i_DSAparams(&ret->pkey.dsa,&cp,(long)j))
211 goto err;
212 }
213 ret->save_parameters=1;
214 }
215#endif
216 key->pkey=ret;
217 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
218 return(ret);
219err:
220 if (ret != NULL)
221 EVP_PKEY_free(ret);
222 return(NULL);
223 }
224
225/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
226 * and encode or decode as X509_PUBKEY
227 */
228
229EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
230 long length)
231{
232 X509_PUBKEY *xpk;
233 EVP_PKEY *pktmp;
234 xpk = d2i_X509_PUBKEY(NULL, pp, length);
235 if(!xpk) return NULL;
236 pktmp = X509_PUBKEY_get(xpk);
237 X509_PUBKEY_free(xpk);
238 if(!pktmp) return NULL;
239 if(a) {
240 EVP_PKEY_free(*a);
241 *a = pktmp;
242 }
243 return pktmp;
244}
245
246int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
247{
248 X509_PUBKEY *xpk=NULL;
249 int ret;
250 if(!a) return 0;
251 if(!X509_PUBKEY_set(&xpk, a)) return 0;
252 ret = i2d_X509_PUBKEY(xpk, pp);
253 X509_PUBKEY_free(xpk);
254 return ret;
255}
256
257/* The following are equivalents but which return RSA and DSA
258 * keys
259 */
260#ifndef OPENSSL_NO_RSA
261RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
262 long length)
263{
264 EVP_PKEY *pkey;
265 RSA *key;
266 unsigned char *q;
267 q = *pp;
268 pkey = d2i_PUBKEY(NULL, &q, length);
269 if(!pkey) return NULL;
270 key = EVP_PKEY_get1_RSA(pkey);
271 EVP_PKEY_free(pkey);
272 if(!key) return NULL;
273 *pp = q;
274 if(a) {
275 RSA_free(*a);
276 *a = key;
277 }
278 return key;
279}
280
281int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
282{
283 EVP_PKEY *pktmp;
284 int ret;
285 if(!a) return 0;
286 pktmp = EVP_PKEY_new();
287 if(!pktmp) {
288 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
289 return 0;
290 }
291 EVP_PKEY_set1_RSA(pktmp, a);
292 ret = i2d_PUBKEY(pktmp, pp);
293 EVP_PKEY_free(pktmp);
294 return ret;
295}
296#endif
297
298#ifndef OPENSSL_NO_DSA
299DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
300 long length)
301{
302 EVP_PKEY *pkey;
303 DSA *key;
304 unsigned char *q;
305 q = *pp;
306 pkey = d2i_PUBKEY(NULL, &q, length);
307 if(!pkey) return NULL;
308 key = EVP_PKEY_get1_DSA(pkey);
309 EVP_PKEY_free(pkey);
310 if(!key) return NULL;
311 *pp = q;
312 if(a) {
313 DSA_free(*a);
314 *a = key;
315 }
316 return key;
317}
318
319int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
320{
321 EVP_PKEY *pktmp;
322 int ret;
323 if(!a) return 0;
324 pktmp = EVP_PKEY_new();
325 if(!pktmp) {
326 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
327 return 0;
328 }
329 EVP_PKEY_set1_DSA(pktmp, a);
330 ret = i2d_PUBKEY(pktmp, pp);
331 EVP_PKEY_free(pktmp);
332 return ret;
333}
334#endif
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
new file mode 100644
index 0000000000..b3f18ebc12
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_req.c
@@ -0,0 +1,112 @@
1/* crypto/asn1/x_req.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64/* X509_REQ_INFO is handled in an unusual way to get round
65 * invalid encodings. Some broken certificate requests don't
66 * encode the attributes field if it is empty. This is in
67 * violation of PKCS#10 but we need to tolerate it. We do
68 * this by making the attributes field OPTIONAL then using
69 * the callback to initialise it to an empty STACK.
70 *
71 * This means that the field will be correctly encoded unless
72 * we NULL out the field.
73 *
74 * As a result we no longer need the req_kludge field because
75 * the information is now contained in the attributes field:
76 * 1. If it is NULL then it's the invalid omission.
77 * 2. If it is empty it is the correct encoding.
78 * 3. If it is not empty then some attributes are present.
79 *
80 */
81
82static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
83{
84 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
85
86 if(operation == ASN1_OP_NEW_POST) {
87 rinf->attributes = sk_X509_ATTRIBUTE_new_null();
88 if(!rinf->attributes) return 0;
89 }
90 return 1;
91}
92
93ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = {
94 ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER),
95 ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME),
96 ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY),
97 /* This isn't really OPTIONAL but it gets round invalid
98 * encodings
99 */
100 ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0)
101} ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO)
102
103IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO)
104
105ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_INFO) = {
106 ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO),
107 ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR),
108 ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING)
109} ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ)
110
111IMPLEMENT_ASN1_FUNCTIONS(X509_REQ)
112IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ)
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
new file mode 100644
index 0000000000..42efa86c1c
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_sig.c
@@ -0,0 +1,69 @@
1/* crypto/asn1/x_sig.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64ASN1_SEQUENCE(X509_SIG) = {
65 ASN1_SIMPLE(X509_SIG, algor, X509_ALGOR),
66 ASN1_SIMPLE(X509_SIG, digest, ASN1_OCTET_STRING)
67} ASN1_SEQUENCE_END(X509_SIG)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c
new file mode 100644
index 0000000000..2aece077c5
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_spki.c
@@ -0,0 +1,81 @@
1/* crypto/asn1/x_spki.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59 /* This module was send to me my Pat Richards <patr@x509.com> who
60 * wrote it. It is under my Copyright with his permission
61 */
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include <openssl/x509.h>
66#include <openssl/asn1t.h>
67
68ASN1_SEQUENCE(NETSCAPE_SPKAC) = {
69 ASN1_SIMPLE(NETSCAPE_SPKAC, pubkey, X509_PUBKEY),
70 ASN1_SIMPLE(NETSCAPE_SPKAC, challenge, ASN1_IA5STRING)
71} ASN1_SEQUENCE_END(NETSCAPE_SPKAC)
72
73IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
74
75ASN1_SEQUENCE(NETSCAPE_SPKI) = {
76 ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC),
77 ASN1_SIMPLE(NETSCAPE_SPKI, sig_algor, X509_ALGOR),
78 ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING)
79} ASN1_SEQUENCE_END(NETSCAPE_SPKI)
80
81IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKI)
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c
new file mode 100644
index 0000000000..dc17c67758
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_val.c
@@ -0,0 +1,69 @@
1/* crypto/asn1/x_val.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64ASN1_SEQUENCE(X509_VAL) = {
65 ASN1_SIMPLE(X509_VAL, notBefore, ASN1_TIME),
66 ASN1_SIMPLE(X509_VAL, notAfter, ASN1_TIME)
67} ASN1_SEQUENCE_END(X509_VAL)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_VAL)
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
new file mode 100644
index 0000000000..b50167ce43
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_x509.c
@@ -0,0 +1,189 @@
1/* crypto/asn1/x_x509.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1t.h>
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(X509_CINF) = {
67 ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0),
68 ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER),
69 ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR),
70 ASN1_SIMPLE(X509_CINF, issuer, X509_NAME),
71 ASN1_SIMPLE(X509_CINF, validity, X509_VAL),
72 ASN1_SIMPLE(X509_CINF, subject, X509_NAME),
73 ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY),
74 ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1),
75 ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2),
76 ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3)
77} ASN1_SEQUENCE_END(X509_CINF)
78
79IMPLEMENT_ASN1_FUNCTIONS(X509_CINF)
80/* X509 top level structure needs a bit of customisation */
81
82static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
83{
84 X509 *ret = (X509 *)*pval;
85
86 switch(operation) {
87
88 case ASN1_OP_NEW_POST:
89 ret->valid=0;
90 ret->name = NULL;
91 ret->ex_flags = 0;
92 ret->ex_pathlen = -1;
93 ret->skid = NULL;
94 ret->akid = NULL;
95 ret->aux = NULL;
96 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
97 break;
98
99 case ASN1_OP_D2I_POST:
100 if (ret->name != NULL) OPENSSL_free(ret->name);
101 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
102 break;
103
104 case ASN1_OP_FREE_POST:
105 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
106 X509_CERT_AUX_free(ret->aux);
107 ASN1_OCTET_STRING_free(ret->skid);
108 AUTHORITY_KEYID_free(ret->akid);
109
110 if (ret->name != NULL) OPENSSL_free(ret->name);
111 break;
112
113 }
114
115 return 1;
116
117}
118
119ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
120 ASN1_SIMPLE(X509, cert_info, X509_CINF),
121 ASN1_SIMPLE(X509, sig_alg, X509_ALGOR),
122 ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING)
123} ASN1_SEQUENCE_END_ref(X509, X509)
124
125IMPLEMENT_ASN1_FUNCTIONS(X509)
126IMPLEMENT_ASN1_DUP_FUNCTION(X509)
127
128static ASN1_METHOD meth={
129 (int (*)()) i2d_X509,
130 (char *(*)())d2i_X509,
131 (char *(*)())X509_new,
132 (void (*)()) X509_free};
133
134ASN1_METHOD *X509_asn1_meth(void)
135 {
136 return(&meth);
137 }
138
139int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
140 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
141 {
142 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp,
143 new_func, dup_func, free_func);
144 }
145
146int X509_set_ex_data(X509 *r, int idx, void *arg)
147 {
148 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
149 }
150
151void *X509_get_ex_data(X509 *r, int idx)
152 {
153 return(CRYPTO_get_ex_data(&r->ex_data,idx));
154 }
155
156/* X509_AUX ASN1 routines. X509_AUX is the name given to
157 * a certificate with extra info tagged on the end. Since these
158 * functions set how a certificate is trusted they should only
159 * be used when the certificate comes from a reliable source
160 * such as local storage.
161 *
162 */
163
164X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
165{
166 unsigned char *q;
167 X509 *ret;
168 /* Save start position */
169 q = *pp;
170 ret = d2i_X509(a, pp, length);
171 /* If certificate unreadable then forget it */
172 if(!ret) return NULL;
173 /* update length */
174 length -= *pp - q;
175 if(!length) return ret;
176 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err;
177 return ret;
178 err:
179 X509_free(ret);
180 return NULL;
181}
182
183int i2d_X509_AUX(X509 *a, unsigned char **pp)
184{
185 int length;
186 length = i2d_X509(a, pp);
187 if(a) length += i2d_X509_CERT_AUX(a->aux, pp);
188 return length;
189}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
new file mode 100644
index 0000000000..f244768b7e
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_x509a.c
@@ -0,0 +1,151 @@
1/* a_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1t.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX routines. These are used to encode additional
66 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines
68 * are used. This means that the "traditional" X509 routines
69 * will simply ignore the extra data.
70 */
71
72static X509_CERT_AUX *aux_get(X509 *x);
73
74ASN1_SEQUENCE(X509_CERT_AUX) = {
75 ASN1_SEQUENCE_OF_OPT(X509_CERT_AUX, trust, ASN1_OBJECT),
76 ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0),
77 ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING),
78 ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING),
79 ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1)
80} ASN1_SEQUENCE_END(X509_CERT_AUX)
81
82IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
83
84static X509_CERT_AUX *aux_get(X509 *x)
85{
86 if(!x) return NULL;
87 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
88 return x->aux;
89}
90
91int X509_alias_set1(X509 *x, unsigned char *name, int len)
92{
93 X509_CERT_AUX *aux;
94 if(!(aux = aux_get(x))) return 0;
95 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
96 return ASN1_STRING_set(aux->alias, name, len);
97}
98
99int X509_keyid_set1(X509 *x, unsigned char *id, int len)
100{
101 X509_CERT_AUX *aux;
102 if(!(aux = aux_get(x))) return 0;
103 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0;
104 return ASN1_STRING_set(aux->keyid, id, len);
105}
106
107unsigned char *X509_alias_get0(X509 *x, int *len)
108{
109 if(!x->aux || !x->aux->alias) return NULL;
110 if(len) *len = x->aux->alias->length;
111 return x->aux->alias->data;
112}
113
114int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
115{
116 X509_CERT_AUX *aux;
117 ASN1_OBJECT *objtmp;
118 if(!(objtmp = OBJ_dup(obj))) return 0;
119 if(!(aux = aux_get(x))) return 0;
120 if(!aux->trust
121 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
122 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
123}
124
125int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
126{
127 X509_CERT_AUX *aux;
128 ASN1_OBJECT *objtmp;
129 if(!(objtmp = OBJ_dup(obj))) return 0;
130 if(!(aux = aux_get(x))) return 0;
131 if(!aux->reject
132 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
133 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
134}
135
136void X509_trust_clear(X509 *x)
137{
138 if(x->aux && x->aux->trust) {
139 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
140 x->aux->trust = NULL;
141 }
142}
143
144void X509_reject_clear(X509 *x)
145{
146 if(x->aux && x->aux->reject) {
147 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
148 x->aux->reject = NULL;
149 }
150}
151