summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2001-10-01 21:58:54 +0000
committercvs2svn <admin@example.com>2001-10-01 21:58:54 +0000
commit2b482d950b0e856294fcd4c1068c1b21939a7240 (patch)
treeaa05f6be64877f76547f1b54ad84f7bfcb291f5d /src/lib/libcrypto/asn1
parentd7b0aad33e28dafbbef67eb5b84ecb05a844fc88 (diff)
downloadopenbsd-OPENBSD_3_0_BASE.tar.gz
openbsd-OPENBSD_3_0_BASE.tar.bz2
openbsd-OPENBSD_3_0_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_3_0_BASE'.OPENBSD_3_0_BASE
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c259
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c112
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c323
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c195
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c90
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c83
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c224
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c113
-rw-r--r--src/lib/libcrypto/asn1/a_int.c473
-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.c95
-rw-r--r--src/lib/libcrypto/asn1/a_print.c197
-rw-r--r--src/lib/libcrypto/asn1/a_set.c217
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c148
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c533
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c250
-rw-r--r--src/lib/libcrypto/asn1/a_time.c127
-rw-r--r--src/lib/libcrypto/asn1/a_type.c352
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c238
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c119
-rw-r--r--src/lib/libcrypto/asn1/asn1.h1151
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c352
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c427
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h583
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c423
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c145
-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.c137
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c114
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c185
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c207
-rw-r--r--src/lib/libcrypto/asn1/f_int.c214
-rw-r--r--src/lib/libcrypto/asn1/f_string.c212
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c84
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c82
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c388
-rw-r--r--src/lib/libcrypto/asn1/nsseq.c118
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c157
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c282
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c127
-rw-r--r--src/lib/libcrypto/asn1/t_bitst.c99
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c166
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c361
-rw-r--r--src/lib/libcrypto/asn1/t_req.c254
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c116
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c411
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c110
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c118
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c165
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c348
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c139
-rw-r--r--src/lib/libcrypto/asn1/x_info.c114
-rw-r--r--src/lib/libcrypto/asn1/x_name.c281
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c151
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c366
-rw-r--r--src/lib/libcrypto/asn1/x_req.c257
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c110
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c166
-rw-r--r--src/lib/libcrypto/asn1/x_val.c109
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c216
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c208
63 files changed, 0 insertions, 14616 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
deleted file mode 100644
index 7013a407ad..0000000000
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ /dev/null
@@ -1,259 +0,0 @@
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
63ASN1_BIT_STRING *ASN1_BIT_STRING_new(void)
64{ return M_ASN1_BIT_STRING_new(); }
65
66void ASN1_BIT_STRING_free(ASN1_BIT_STRING *x)
67{ M_ASN1_BIT_STRING_free(x); }
68
69int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
70{ return M_ASN1_BIT_STRING_set(x, d, len); }
71
72int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
73{
74 int len, ret;
75 len = i2c_ASN1_BIT_STRING(a, NULL);
76 ret=ASN1_object_size(0,len,V_ASN1_BIT_STRING);
77 if(pp) {
78 ASN1_put_object(pp,0,len,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL);
79 i2c_ASN1_BIT_STRING(a, pp);
80 }
81 return ret;
82}
83
84int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
85 {
86 int ret,j,bits,len;
87 unsigned char *p,*d;
88
89 if (a == NULL) return(0);
90
91 len=a->length;
92 ret=1+len;
93 if (pp == NULL) return(ret);
94
95 if (len > 0)
96 {
97 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
98 {
99 bits=(int)a->flags&0x07;
100 }
101 else
102 {
103 for ( ; len > 0; len--)
104 {
105 if (a->data[len-1]) break;
106 }
107 j=a->data[len-1];
108 if (j & 0x01) bits=0;
109 else if (j & 0x02) bits=1;
110 else if (j & 0x04) bits=2;
111 else if (j & 0x08) bits=3;
112 else if (j & 0x10) bits=4;
113 else if (j & 0x20) bits=5;
114 else if (j & 0x40) bits=6;
115 else if (j & 0x80) bits=7;
116 else bits=0; /* should not happen */
117 }
118 }
119 else
120 bits=0;
121 p= *pp;
122
123 *(p++)=(unsigned char)bits;
124 d=a->data;
125 memcpy(p,d,len);
126 p+=len;
127 if (len > 0) p[-1]&=(0xff<<bits);
128 *pp=p;
129 return(ret);
130 }
131
132
133/* Convert DER encoded ASN1 BIT_STRING to ASN1_BIT_STRING structure */
134ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
135 long length)
136{
137 unsigned char *p;
138 long len;
139 int i;
140 int inf,tag,xclass;
141 ASN1_BIT_STRING *ret;
142
143 p= *pp;
144 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
145 if (inf & 0x80)
146 {
147 i=ASN1_R_BAD_OBJECT_HEADER;
148 goto err;
149 }
150
151 if (tag != V_ASN1_BIT_STRING)
152 {
153 i=ASN1_R_EXPECTING_A_BIT_STRING;
154 goto err;
155 }
156 if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; }
157 ret = c2i_ASN1_BIT_STRING(a, &p, len);
158 if(ret) *pp = p;
159 return ret;
160err:
161 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
162 return(NULL);
163
164}
165
166ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
167 long len)
168 {
169 ASN1_BIT_STRING *ret=NULL;
170 unsigned char *p,*s;
171 int i;
172
173 if ((a == NULL) || ((*a) == NULL))
174 {
175 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
176 }
177 else
178 ret=(*a);
179
180 p= *pp;
181 i= *(p++);
182 /* We do this to preserve the settings. If we modify
183 * the settings, via the _set_bit function, we will recalculate
184 * on output */
185 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
186 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
187
188 if (len-- > 1) /* using one because of the bits left byte */
189 {
190 s=(unsigned char *)OPENSSL_malloc((int)len);
191 if (s == NULL)
192 {
193 i=ERR_R_MALLOC_FAILURE;
194 goto err;
195 }
196 memcpy(s,p,(int)len);
197 s[len-1]&=(0xff<<i);
198 p+=len;
199 }
200 else
201 s=NULL;
202
203 ret->length=(int)len;
204 if (ret->data != NULL) OPENSSL_free(ret->data);
205 ret->data=s;
206 ret->type=V_ASN1_BIT_STRING;
207 if (a != NULL) (*a)=ret;
208 *pp=p;
209 return(ret);
210err:
211 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
212 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
213 M_ASN1_BIT_STRING_free(ret);
214 return(NULL);
215 }
216
217/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
218 */
219int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
220 {
221 int w,v,iv;
222 unsigned char *c;
223
224 w=n/8;
225 v=1<<(7-(n&0x07));
226 iv= ~v;
227
228 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
229
230 if (a == NULL) return(0);
231 if ((a->length < (w+1)) || (a->data == NULL))
232 {
233 if (!value) return(1); /* Don't need to set */
234 if (a->data == NULL)
235 c=(unsigned char *)OPENSSL_malloc(w+1);
236 else
237 c=(unsigned char *)OPENSSL_realloc(a->data,w+1);
238 if (c == NULL) return(0);
239 if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length);
240 a->data=c;
241 a->length=w+1;
242 }
243 a->data[w]=((a->data[w])&iv)|v;
244 while ((a->length > 0) && (a->data[a->length-1] == 0))
245 a->length--;
246 return(1);
247 }
248
249int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
250 {
251 int w,v;
252
253 w=n/8;
254 v=1<<(7-(n&0x07));
255 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
256 return(0);
257 return((a->data[w]&v) != 0);
258 }
259
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c
deleted file mode 100644
index 18fa61840b..0000000000
--- a/src/lib/libcrypto/asn1/a_bool.c
+++ /dev/null
@@ -1,112 +0,0 @@
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/asn1.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 }
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
deleted file mode 100644
index 3a0c0c7835..0000000000
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ /dev/null
@@ -1,323 +0,0 @@
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_mac.h>
62
63static unsigned long tag2bit[32]={
640, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
65B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
66B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
67B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
680, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING,
69B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0,
700,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,
71B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN,
72 };
73
74static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c);
75/* type is a 'bitmap' of acceptable string types.
76 */
77ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
78 long length, int type)
79 {
80 ASN1_STRING *ret=NULL;
81 unsigned char *p,*s;
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) goto err;
89
90 if (tag >= 32)
91 {
92 i=ASN1_R_TAG_VALUE_TOO_HIGH;;
93 goto err;
94 }
95 if (!(tag2bit[tag] & type))
96 {
97 i=ASN1_R_WRONG_TYPE;
98 goto err;
99 }
100
101 /* If a bit-string, exit early */
102 if (tag == V_ASN1_BIT_STRING)
103 return(d2i_ASN1_BIT_STRING(a,pp,length));
104
105 if ((a == NULL) || ((*a) == NULL))
106 {
107 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
108 }
109 else
110 ret=(*a);
111
112 if (len != 0)
113 {
114 s=(unsigned char *)OPENSSL_malloc((int)len+1);
115 if (s == NULL)
116 {
117 i=ERR_R_MALLOC_FAILURE;
118 goto err;
119 }
120 memcpy(s,p,(int)len);
121 s[len]='\0';
122 p+=len;
123 }
124 else
125 s=NULL;
126
127 if (ret->data != NULL) OPENSSL_free(ret->data);
128 ret->length=(int)len;
129 ret->data=s;
130 ret->type=tag;
131 if (a != NULL) (*a)=ret;
132 *pp=p;
133 return(ret);
134err:
135 ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i);
136 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
137 ASN1_STRING_free(ret);
138 return(NULL);
139 }
140
141int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
142 {
143 int ret,r,constructed;
144 unsigned char *p;
145
146 if (a == NULL) return(0);
147
148 if (tag == V_ASN1_BIT_STRING)
149 return(i2d_ASN1_BIT_STRING(a,pp));
150
151 ret=a->length;
152 r=ASN1_object_size(0,ret,tag);
153 if (pp == NULL) return(r);
154 p= *pp;
155
156 if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
157 constructed=1;
158 else
159 constructed=0;
160 ASN1_put_object(&p,constructed,ret,tag,xclass);
161 memcpy(p,a->data,a->length);
162 p+=a->length;
163 *pp= p;
164 return(r);
165 }
166
167ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
168 int Ptag, int Pclass)
169 {
170 ASN1_STRING *ret=NULL;
171 unsigned char *p,*s;
172 long len;
173 int inf,tag,xclass;
174 int i=0;
175
176 if ((a == NULL) || ((*a) == NULL))
177 {
178 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
179 }
180 else
181 ret=(*a);
182
183 p= *pp;
184 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
185 if (inf & 0x80)
186 {
187 i=ASN1_R_BAD_OBJECT_HEADER;
188 goto err;
189 }
190
191 if (tag != Ptag)
192 {
193 i=ASN1_R_WRONG_TAG;
194 goto err;
195 }
196
197 if (inf & V_ASN1_CONSTRUCTED)
198 {
199 ASN1_CTX c;
200
201 c.pp=pp;
202 c.p=p;
203 c.inf=inf;
204 c.slen=len;
205 c.tag=Ptag;
206 c.xclass=Pclass;
207 c.max=(length == 0)?0:(p+length);
208 if (!asn1_collate_primitive(ret,&c))
209 goto err;
210 else
211 {
212 p=c.p;
213 }
214 }
215 else
216 {
217 if (len != 0)
218 {
219 if ((ret->length < len) || (ret->data == NULL))
220 {
221 if (ret->data != NULL) OPENSSL_free(ret->data);
222 s=(unsigned char *)OPENSSL_malloc((int)len + 1);
223 if (s == NULL)
224 {
225 i=ERR_R_MALLOC_FAILURE;
226 goto err;
227 }
228 }
229 else
230 s=ret->data;
231 memcpy(s,p,(int)len);
232 s[len] = '\0';
233 p+=len;
234 }
235 else
236 {
237 s=NULL;
238 if (ret->data != NULL) OPENSSL_free(ret->data);
239 }
240
241 ret->length=(int)len;
242 ret->data=s;
243 ret->type=Ptag;
244 }
245
246 if (a != NULL) (*a)=ret;
247 *pp=p;
248 return(ret);
249err:
250 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
251 ASN1_STRING_free(ret);
252 ASN1err(ASN1_F_D2I_ASN1_BYTES,i);
253 return(NULL);
254 }
255
256
257/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
258 * them into the one structure that is then returned */
259/* There have been a few bug fixes for this function from
260 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
261static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
262 {
263 ASN1_STRING *os=NULL;
264 BUF_MEM b;
265 int num;
266
267 b.length=0;
268 b.max=0;
269 b.data=NULL;
270
271 if (a == NULL)
272 {
273 c->error=ERR_R_PASSED_NULL_PARAMETER;
274 goto err;
275 }
276
277 num=0;
278 for (;;)
279 {
280 if (c->inf & 1)
281 {
282 c->eos=ASN1_check_infinite_end(&c->p,
283 (long)(c->max-c->p));
284 if (c->eos) break;
285 }
286 else
287 {
288 if (c->slen <= 0) break;
289 }
290
291 c->q=c->p;
292 if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass)
293 == NULL)
294 {
295 c->error=ERR_R_ASN1_LIB;
296 goto err;
297 }
298
299 if (!BUF_MEM_grow(&b,num+os->length))
300 {
301 c->error=ERR_R_BUF_LIB;
302 goto err;
303 }
304 memcpy(&(b.data[num]),os->data,os->length);
305 if (!(c->inf & 1))
306 c->slen-=(c->p-c->q);
307 num+=os->length;
308 }
309
310 if (!asn1_Finish(c)) goto err;
311
312 a->length=num;
313 if (a->data != NULL) OPENSSL_free(a->data);
314 a->data=(unsigned char *)b.data;
315 if (os != NULL) ASN1_STRING_free(os);
316 return(1);
317err:
318 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
319 if (os != NULL) ASN1_STRING_free(os);
320 if (b.data != NULL) OPENSSL_free(b.data);
321 return(0);
322 }
323
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c
deleted file mode 100644
index a49d1cb289..0000000000
--- a/src/lib/libcrypto/asn1/a_d2i_fp.c
+++ /dev/null
@@ -1,195 +0,0 @@
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
64#define HEADER_SIZE 8
65
66#ifndef NO_FP_API
67char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
68 unsigned char **x)
69 {
70 BIO *b;
71 char *ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
76 return(NULL);
77 }
78 BIO_set_fp(b,in,BIO_NOCLOSE);
79 ret=ASN1_d2i_bio(xnew,d2i,b,x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
86 unsigned char **x)
87 {
88 BUF_MEM *b;
89 unsigned char *p;
90 int i;
91 char *ret=NULL;
92 ASN1_CTX c;
93 int want=HEADER_SIZE;
94 int eos=0;
95 int off=0;
96 int len=0;
97
98 b=BUF_MEM_new();
99 if (b == NULL)
100 {
101 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
102 return(NULL);
103 }
104
105 ERR_clear_error();
106 for (;;)
107 {
108 if (want >= (len-off))
109 {
110 want-=(len-off);
111
112 if (!BUF_MEM_grow(b,len+want))
113 {
114 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
115 goto err;
116 }
117 i=BIO_read(in,&(b->data[len]),want);
118 if ((i < 0) && ((len-off) == 0))
119 {
120 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
121 goto err;
122 }
123 if (i > 0)
124 len+=i;
125 }
126 /* else data already loaded */
127
128 p=(unsigned char *)&(b->data[off]);
129 c.p=p;
130 c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass),
131 len-off);
132 if (c.inf & 0x80)
133 {
134 unsigned long e;
135
136 e=ERR_GET_REASON(ERR_peek_error());
137 if (e != ASN1_R_TOO_LONG)
138 goto err;
139 else
140 ERR_get_error(); /* clear error */
141 }
142 i=c.p-p;/* header length */
143 off+=i; /* end of data */
144
145 if (c.inf & 1)
146 {
147 /* no data body so go round again */
148 eos++;
149 want=HEADER_SIZE;
150 }
151 else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC))
152 {
153 /* eos value, so go back and read another header */
154 eos--;
155 if (eos <= 0)
156 break;
157 else
158 want=HEADER_SIZE;
159 }
160 else
161 {
162 /* suck in c.slen bytes of data */
163 want=(int)c.slen;
164 if (want > (len-off))
165 {
166 want-=(len-off);
167 if (!BUF_MEM_grow(b,len+want))
168 {
169 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
170 goto err;
171 }
172 i=BIO_read(in,&(b->data[len]),want);
173 if (i <= 0)
174 {
175 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
176 goto err;
177 }
178 len+=i;
179 }
180 off+=(int)c.slen;
181 if (eos <= 0)
182 {
183 break;
184 }
185 else
186 want=HEADER_SIZE;
187 }
188 }
189
190 p=(unsigned char *)b->data;
191 ret=d2i(x,&p,off);
192err:
193 if (b != NULL) BUF_MEM_free(b);
194 return(ret);
195 }
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
deleted file mode 100644
index 8257b8639e..0000000000
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ /dev/null
@@ -1,90 +0,0 @@
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
72int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
73 unsigned char *md, unsigned int *len)
74 {
75 EVP_MD_CTX ctx;
76 int i;
77 unsigned char *str,*p;
78
79 i=i2d(data,NULL);
80 if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL) return(0);
81 p=str;
82 i2d(data,&p);
83
84 EVP_DigestInit(&ctx,type);
85 EVP_DigestUpdate(&ctx,str,i);
86 EVP_DigestFinal(&ctx,md,len);
87 OPENSSL_free(str);
88 return(1);
89 }
90
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
deleted file mode 100644
index c3bda58a5d..0000000000
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ /dev/null
@@ -1,83 +0,0 @@
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_mac.h>
62
63#define READ_CHUNK 2048
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 }
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
deleted file mode 100644
index 1428d1df7a..0000000000
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ /dev/null
@@ -1,224 +0,0 @@
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
68ASN1_ENUMERATED *ASN1_ENUMERATED_new(void)
69{ return M_ASN1_ENUMERATED_new(); }
70
71void ASN1_ENUMERATED_free(ASN1_ENUMERATED *x)
72{ M_ASN1_ENUMERATED_free(x); }
73
74
75int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
76{
77 int len, ret;
78 if(!a) return 0;
79 len = i2c_ASN1_INTEGER(a, NULL);
80 ret=ASN1_object_size(0,len,V_ASN1_ENUMERATED);
81 if(pp) {
82 ASN1_put_object(pp,0,len,V_ASN1_ENUMERATED,V_ASN1_UNIVERSAL);
83 i2c_ASN1_INTEGER(a, pp);
84 }
85 return ret;
86}
87
88ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
89 long length)
90{
91 unsigned char *p;
92 long len;
93 int i;
94 int inf,tag,xclass;
95 ASN1_ENUMERATED *ret;
96
97 p= *pp;
98 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
99 if (inf & 0x80)
100 {
101 i=ASN1_R_BAD_OBJECT_HEADER;
102 goto err;
103 }
104
105 if (tag != V_ASN1_ENUMERATED)
106 {
107 i=ASN1_R_EXPECTING_AN_ENUMERATED;
108 goto err;
109 }
110 ret = c2i_ASN1_INTEGER(a, &p, len);
111 if(ret) {
112 ret->type = (V_ASN1_NEG & ret->type) | V_ASN1_ENUMERATED;
113 *pp = p;
114 }
115 return ret;
116err:
117 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
118 return(NULL);
119
120}
121
122int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
123 {
124 int i,j,k;
125 unsigned char buf[sizeof(long)+1];
126 long d;
127
128 a->type=V_ASN1_ENUMERATED;
129 if (a->length < (sizeof(long)+1))
130 {
131 if (a->data != NULL)
132 OPENSSL_free(a->data);
133 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL)
134 memset((char *)a->data,0,sizeof(long)+1);
135 }
136 if (a->data == NULL)
137 {
138 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
139 return(0);
140 }
141 d=v;
142 if (d < 0)
143 {
144 d= -d;
145 a->type=V_ASN1_NEG_ENUMERATED;
146 }
147
148 for (i=0; i<sizeof(long); i++)
149 {
150 if (d == 0) break;
151 buf[i]=(int)d&0xff;
152 d>>=8;
153 }
154 j=0;
155 for (k=i-1; k >=0; k--)
156 a->data[j++]=buf[k];
157 a->length=j;
158 return(1);
159 }
160
161long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
162 {
163 int neg=0,i;
164 long r=0;
165
166 if (a == NULL) return(0L);
167 i=a->type;
168 if (i == V_ASN1_NEG_ENUMERATED)
169 neg=1;
170 else if (i != V_ASN1_ENUMERATED)
171 return(0);
172
173 if (a->length > sizeof(long))
174 {
175 /* hmm... a bit ugly */
176 return(0xffffffffL);
177 }
178 if (a->data == NULL)
179 return(0);
180
181 for (i=0; i<a->length; i++)
182 {
183 r<<=8;
184 r|=(unsigned char)a->data[i];
185 }
186 if (neg) r= -r;
187 return(r);
188 }
189
190ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
191 {
192 ASN1_ENUMERATED *ret;
193 int len,j;
194
195 if (ai == NULL)
196 ret=M_ASN1_ENUMERATED_new();
197 else
198 ret=ai;
199 if (ret == NULL)
200 {
201 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
202 goto err;
203 }
204 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
205 else ret->type=V_ASN1_ENUMERATED;
206 j=BN_num_bits(bn);
207 len=((j == 0)?0:((j/8)+1));
208 ret->data=(unsigned char *)OPENSSL_malloc(len+4);
209 ret->length=BN_bn2bin(bn,ret->data);
210 return(ret);
211err:
212 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
213 return(NULL);
214 }
215
216BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
217 {
218 BIGNUM *ret;
219
220 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
221 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
222 else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1;
223 return(ret);
224 }
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
deleted file mode 100644
index aee29a7790..0000000000
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ /dev/null
@@ -1,113 +0,0 @@
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_mac.h>
63
64#ifndef NO_FP_API
65int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x)
66 {
67 BIO *b;
68 int ret;
69
70 if ((b=BIO_new(BIO_s_file())) == NULL)
71 {
72 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
73 return(0);
74 }
75 BIO_set_fp(b,out,BIO_NOCLOSE);
76 ret=ASN1_i2d_bio(i2d,b,x);
77 BIO_free(b);
78 return(ret);
79 }
80#endif
81
82int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
83 {
84 char *b;
85 unsigned char *p;
86 int i,j=0,n,ret=1;
87
88 n=i2d(x,NULL);
89 b=(char *)OPENSSL_malloc(n);
90 if (b == NULL)
91 {
92 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
93 return(0);
94 }
95
96 p=(unsigned char *)b;
97 i2d(x,&p);
98
99 for (;;)
100 {
101 i=BIO_write(out,&(b[j]),n);
102 if (i == n) break;
103 if (i <= 0)
104 {
105 ret=0;
106 break;
107 }
108 j+=i;
109 n-=i;
110 }
111 OPENSSL_free(b);
112 return(ret);
113 }
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
deleted file mode 100644
index 6f0413f885..0000000000
--- a/src/lib/libcrypto/asn1/a_int.c
+++ /dev/null
@@ -1,473 +0,0 @@
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_new(void)
64{ return M_ASN1_INTEGER_new();}
65
66void ASN1_INTEGER_free(ASN1_INTEGER *x)
67{ M_ASN1_INTEGER_free(x);}
68
69ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
70{ return M_ASN1_INTEGER_dup(x);}
71
72int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
73{ return M_ASN1_INTEGER_cmp(x,y);}
74
75/* Output ASN1 INTEGER including tag+length */
76
77int i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
78{
79 int len, ret;
80 if(!a) return 0;
81 len = i2c_ASN1_INTEGER(a, NULL);
82 ret=ASN1_object_size(0,len,V_ASN1_INTEGER);
83 if(pp) {
84 ASN1_put_object(pp,0,len,V_ASN1_INTEGER,V_ASN1_UNIVERSAL);
85 i2c_ASN1_INTEGER(a, pp);
86 }
87 return ret;
88}
89
90/*
91 * This converts an ASN1 INTEGER into its content encoding.
92 * The internal representation is an ASN1_STRING whose data is a big endian
93 * representation of the value, ignoring the sign. The sign is determined by
94 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
95 *
96 * Positive integers are no problem: they are almost the same as the DER
97 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
98 *
99 * Negative integers are a bit trickier...
100 * The DER representation of negative integers is in 2s complement form.
101 * The internal form is converted by complementing each octet and finally
102 * adding one to the result. This can be done less messily with a little trick.
103 * If the internal form has trailing zeroes then they will become FF by the
104 * complement and 0 by the add one (due to carry) so just copy as many trailing
105 * zeros to the destination as there are in the source. The carry will add one
106 * to the last none zero octet: so complement this octet and add one and finally
107 * complement any left over until you get to the start of the string.
108 *
109 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
110 * with 0xff. However if the first byte is 0x80 and one of the following bytes
111 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
112 * followed by optional zeros isn't padded.
113 */
114
115int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
116 {
117 int pad=0,ret,i,neg;
118 unsigned char *p,*n,pb=0;
119
120 if ((a == NULL) || (a->data == NULL)) return(0);
121 neg=a->type & V_ASN1_NEG;
122 if (a->length == 0)
123 ret=1;
124 else
125 {
126 ret=a->length;
127 i=a->data[0];
128 if (!neg && (i > 127)) {
129 pad=1;
130 pb=0;
131 } else if(neg) {
132 if(i>128) {
133 pad=1;
134 pb=0xFF;
135 } else if(i == 128) {
136 /*
137 * Special case: if any other bytes non zero we pad:
138 * otherwise we don't.
139 */
140 for(i = 1; i < a->length; i++) if(a->data[i]) {
141 pad=1;
142 pb=0xFF;
143 break;
144 }
145 }
146 }
147 ret+=pad;
148 }
149 if (pp == NULL) return(ret);
150 p= *pp;
151
152 if (pad) *(p++)=pb;
153 if (a->length == 0) *(p++)=0;
154 else if (!neg) memcpy(p,a->data,(unsigned int)a->length);
155 else {
156 /* Begin at the end of the encoding */
157 n=a->data + a->length - 1;
158 p += a->length - 1;
159 i = a->length;
160 /* Copy zeros to destination as long as source is zero */
161 while(!*n) {
162 *(p--) = 0;
163 n--;
164 i--;
165 }
166 /* Complement and increment next octet */
167 *(p--) = ((*(n--)) ^ 0xff) + 1;
168 i--;
169 /* Complement any octets left */
170 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
171 }
172
173 *pp+=ret;
174 return(ret);
175 }
176
177/* Convert DER encoded ASN1 INTEGER to ASN1_INTEGER structure */
178ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
179 long length)
180{
181 unsigned char *p;
182 long len;
183 int i;
184 int inf,tag,xclass;
185 ASN1_INTEGER *ret;
186
187 p= *pp;
188 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
189 if (inf & 0x80)
190 {
191 i=ASN1_R_BAD_OBJECT_HEADER;
192 goto err;
193 }
194
195 if (tag != V_ASN1_INTEGER)
196 {
197 i=ASN1_R_EXPECTING_AN_INTEGER;
198 goto err;
199 }
200 ret = c2i_ASN1_INTEGER(a, &p, len);
201 if(ret) *pp = p;
202 return ret;
203err:
204 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
205 return(NULL);
206
207}
208
209
210/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
211
212ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
213 long len)
214 {
215 ASN1_INTEGER *ret=NULL;
216 unsigned char *p,*to,*s, *pend;
217 int i;
218
219 if ((a == NULL) || ((*a) == NULL))
220 {
221 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
222 ret->type=V_ASN1_INTEGER;
223 }
224 else
225 ret=(*a);
226
227 p= *pp;
228 pend = p + len;
229
230 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it
231 * signifies a missing NULL parameter. */
232 s=(unsigned char *)OPENSSL_malloc((int)len+1);
233 if (s == NULL)
234 {
235 i=ERR_R_MALLOC_FAILURE;
236 goto err;
237 }
238 to=s;
239 if(!len) {
240 /* Strictly speaking this is an illegal INTEGER but we
241 * tolerate it.
242 */
243 ret->type=V_ASN1_INTEGER;
244 } else if (*p & 0x80) /* a negative number */
245 {
246 ret->type=V_ASN1_NEG_INTEGER;
247 if ((*p == 0xff) && (len != 1)) {
248 p++;
249 len--;
250 }
251 i = len;
252 p += i - 1;
253 to += i - 1;
254 while((!*p) && i) {
255 *(to--) = 0;
256 i--;
257 p--;
258 }
259 /* Special case: if all zeros then the number will be of
260 * the form FF followed by n zero bytes: this corresponds to
261 * 1 followed by n zero bytes. We've already written n zeros
262 * so we just append an extra one and set the first byte to
263 * a 1. This is treated separately because it is the only case
264 * where the number of bytes is larger than len.
265 */
266 if(!i) {
267 *s = 1;
268 s[len] = 0;
269 len++;
270 } else {
271 *(to--) = (*(p--) ^ 0xff) + 1;
272 i--;
273 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
274 }
275 } else {
276 ret->type=V_ASN1_INTEGER;
277 if ((*p == 0) && (len != 1))
278 {
279 p++;
280 len--;
281 }
282 memcpy(s,p,(int)len);
283 }
284
285 if (ret->data != NULL) OPENSSL_free(ret->data);
286 ret->data=s;
287 ret->length=(int)len;
288 if (a != NULL) (*a)=ret;
289 *pp=pend;
290 return(ret);
291err:
292 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
293 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
294 M_ASN1_INTEGER_free(ret);
295 return(NULL);
296 }
297
298
299/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
300 * ASN1 integers: some broken software can encode a positive INTEGER
301 * with its MSB set as negative (it doesn't add a padding zero).
302 */
303
304ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
305 long length)
306 {
307 ASN1_INTEGER *ret=NULL;
308 unsigned char *p,*to,*s;
309 long len;
310 int inf,tag,xclass;
311 int i;
312
313 if ((a == NULL) || ((*a) == NULL))
314 {
315 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
316 ret->type=V_ASN1_INTEGER;
317 }
318 else
319 ret=(*a);
320
321 p= *pp;
322 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
323 if (inf & 0x80)
324 {
325 i=ASN1_R_BAD_OBJECT_HEADER;
326 goto err;
327 }
328
329 if (tag != V_ASN1_INTEGER)
330 {
331 i=ASN1_R_EXPECTING_AN_INTEGER;
332 goto err;
333 }
334
335 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it
336 * signifies a missing NULL parameter. */
337 s=(unsigned char *)OPENSSL_malloc((int)len+1);
338 if (s == NULL)
339 {
340 i=ERR_R_MALLOC_FAILURE;
341 goto err;
342 }
343 to=s;
344 ret->type=V_ASN1_INTEGER;
345 if(len) {
346 if ((*p == 0) && (len != 1))
347 {
348 p++;
349 len--;
350 }
351 memcpy(s,p,(int)len);
352 p+=len;
353 }
354
355 if (ret->data != NULL) OPENSSL_free(ret->data);
356 ret->data=s;
357 ret->length=(int)len;
358 if (a != NULL) (*a)=ret;
359 *pp=p;
360 return(ret);
361err:
362 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
363 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
364 M_ASN1_INTEGER_free(ret);
365 return(NULL);
366 }
367
368int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
369 {
370 int i,j,k;
371 unsigned char buf[sizeof(long)+1];
372 long d;
373
374 a->type=V_ASN1_INTEGER;
375 if (a->length < (sizeof(long)+1))
376 {
377 if (a->data != NULL)
378 OPENSSL_free(a->data);
379 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL)
380 memset((char *)a->data,0,sizeof(long)+1);
381 }
382 if (a->data == NULL)
383 {
384 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
385 return(0);
386 }
387 d=v;
388 if (d < 0)
389 {
390 d= -d;
391 a->type=V_ASN1_NEG_INTEGER;
392 }
393
394 for (i=0; i<sizeof(long); i++)
395 {
396 if (d == 0) break;
397 buf[i]=(int)d&0xff;
398 d>>=8;
399 }
400 j=0;
401 for (k=i-1; k >=0; k--)
402 a->data[j++]=buf[k];
403 a->length=j;
404 return(1);
405 }
406
407long ASN1_INTEGER_get(ASN1_INTEGER *a)
408 {
409 int neg=0,i;
410 long r=0;
411
412 if (a == NULL) return(0L);
413 i=a->type;
414 if (i == V_ASN1_NEG_INTEGER)
415 neg=1;
416 else if (i != V_ASN1_INTEGER)
417 return(0);
418
419 if (a->length > sizeof(long))
420 {
421 /* hmm... a bit ugly */
422 return(0xffffffffL);
423 }
424 if (a->data == NULL)
425 return(0);
426
427 for (i=0; i<a->length; i++)
428 {
429 r<<=8;
430 r|=(unsigned char)a->data[i];
431 }
432 if (neg) r= -r;
433 return(r);
434 }
435
436ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
437 {
438 ASN1_INTEGER *ret;
439 int len,j;
440
441 if (ai == NULL)
442 ret=M_ASN1_INTEGER_new();
443 else
444 ret=ai;
445 if (ret == NULL)
446 {
447 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
448 goto err;
449 }
450 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
451 else ret->type=V_ASN1_INTEGER;
452 j=BN_num_bits(bn);
453 len=((j == 0)?0:((j/8)+1));
454 ret->data=(unsigned char *)OPENSSL_malloc(len+4);
455 ret->length=BN_bn2bin(bn,ret->data);
456 return(ret);
457err:
458 if (ret != ai) M_ASN1_INTEGER_free(ret);
459 return(NULL);
460 }
461
462BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
463 {
464 BIGNUM *ret;
465
466 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
467 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
468 else if(ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1;
469 return(ret);
470 }
471
472IMPLEMENT_STACK_OF(ASN1_INTEGER)
473IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER)
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
deleted file mode 100644
index 5d981c6553..0000000000
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ /dev/null
@@ -1,400 +0,0 @@
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 sprintf(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 sprintf(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
deleted file mode 100644
index 20caa2d3bd..0000000000
--- a/src/lib/libcrypto/asn1/a_object.c
+++ /dev/null
@@ -1,320 +0,0 @@
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 char *sn, 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
deleted file mode 100644
index 2586f4327d..0000000000
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ /dev/null
@@ -1,95 +0,0 @@
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_new(void)
64{ return M_ASN1_OCTET_STRING_new(); }
65
66void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *x)
67{ M_ASN1_OCTET_STRING_free(x); }
68
69ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x)
70{ return M_ASN1_OCTET_STRING_dup(x); }
71
72int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
73{ return M_ASN1_OCTET_STRING_cmp(a, b); }
74
75int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)
76{ return M_ASN1_OCTET_STRING_set(x, d, len); }
77
78int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)
79{ return M_i2d_ASN1_OCTET_STRING(a, pp); }
80
81ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
82 unsigned char **pp, long length)
83 {
84 ASN1_OCTET_STRING *ret=NULL;
85
86 ret=(ASN1_OCTET_STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
87 pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL);
88 if (ret == NULL)
89 {
90 ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ERR_R_NESTED_ASN1_ERROR);
91 return(NULL);
92 }
93 return(ret);
94 }
95
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
deleted file mode 100644
index b7bd2bd18a..0000000000
--- a/src/lib/libcrypto/asn1/a_print.c
+++ /dev/null
@@ -1,197 +0,0 @@
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
63ASN1_IA5STRING *ASN1_IA5STRING_new(void)
64{ return M_ASN1_IA5STRING_new();}
65
66void ASN1_IA5STRING_free(ASN1_IA5STRING *x)
67{ M_ASN1_IA5STRING_free(x);}
68
69int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **pp)
70 { return(M_i2d_ASN1_IA5STRING(a,pp)); }
71
72ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, unsigned char **pp,
73 long l)
74 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); }
75
76ASN1_T61STRING *ASN1_T61STRING_new(void)
77{ return M_ASN1_T61STRING_new();}
78
79void ASN1_T61STRING_free(ASN1_T61STRING *x)
80{ M_ASN1_T61STRING_free(x);}
81
82ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp,
83 long l)
84 { return(M_d2i_ASN1_T61STRING(a,pp,l)); }
85
86ASN1_PRINTABLESTRING *ASN1_PRINTABLESTRING_new(void)
87{ return M_ASN1_PRINTABLESTRING_new();}
88
89void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *x)
90{ M_ASN1_PRINTABLESTRING_free(x);}
91
92ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
93 unsigned char **pp, long l)
94 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,
95 l)); }
96
97int i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **pp)
98 { return(M_i2d_ASN1_PRINTABLESTRING(a,pp)); }
99
100int i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **pp)
101 { return(M_i2d_ASN1_PRINTABLE(a,pp)); }
102
103ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, unsigned char **pp,
104 long l)
105 { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); }
106
107int ASN1_PRINTABLE_type(unsigned char *s, int len)
108 {
109 int c;
110 int ia5=0;
111 int t61=0;
112
113 if (len <= 0) len= -1;
114 if (s == NULL) return(V_ASN1_PRINTABLESTRING);
115
116 while ((*s) && (len-- != 0))
117 {
118 c= *(s++);
119#ifndef CHARSET_EBCDIC
120 if (!( ((c >= 'a') && (c <= 'z')) ||
121 ((c >= 'A') && (c <= 'Z')) ||
122 (c == ' ') ||
123 ((c >= '0') && (c <= '9')) ||
124 (c == ' ') || (c == '\'') ||
125 (c == '(') || (c == ')') ||
126 (c == '+') || (c == ',') ||
127 (c == '-') || (c == '.') ||
128 (c == '/') || (c == ':') ||
129 (c == '=') || (c == '?')))
130 ia5=1;
131 if (c&0x80)
132 t61=1;
133#else
134 if (!isalnum(c) && (c != ' ') &&
135 strchr("'()+,-./:=?", c) == NULL)
136 ia5=1;
137 if (os_toascii[c] & 0x80)
138 t61=1;
139#endif
140 }
141 if (t61) return(V_ASN1_T61STRING);
142 if (ia5) return(V_ASN1_IA5STRING);
143 return(V_ASN1_PRINTABLESTRING);
144 }
145
146int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
147 {
148 int i;
149 unsigned char *p;
150
151 if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
152 if ((s->length%4) != 0) return(0);
153 p=s->data;
154 for (i=0; i<s->length; i+=4)
155 {
156 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
157 break;
158 else
159 p+=4;
160 }
161 if (i < s->length) return(0);
162 p=s->data;
163 for (i=3; i<s->length; i+=4)
164 {
165 *(p++)=s->data[i];
166 }
167 *(p)='\0';
168 s->length/=4;
169 s->type=ASN1_PRINTABLE_type(s->data,s->length);
170 return(1);
171 }
172
173ASN1_STRING *DIRECTORYSTRING_new(void)
174{ return M_DIRECTORYSTRING_new();}
175
176void DIRECTORYSTRING_free(ASN1_STRING *x)
177{ M_DIRECTORYSTRING_free(x);}
178
179int i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **pp)
180 { return(M_i2d_DIRECTORYSTRING(a,pp)); }
181
182ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
183 long l)
184 { return(M_d2i_DIRECTORYSTRING(a,pp,l)); }
185
186ASN1_STRING *DISPLAYTEXT_new(void)
187{ return M_DISPLAYTEXT_new();}
188
189void DISPLAYTEXT_free(ASN1_STRING *x)
190{ M_DISPLAYTEXT_free(x);}
191
192int i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **pp)
193 { return(M_i2d_DISPLAYTEXT(a,pp)); }
194
195ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp,
196 long l)
197 { return(M_d2i_DISPLAYTEXT(a,pp,l)); }
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
deleted file mode 100644
index caf5a1419c..0000000000
--- a/src/lib/libcrypto/asn1/a_set.c
+++ /dev/null
@@ -1,217 +0,0 @@
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
63typedef struct
64 {
65 unsigned char *pbData;
66 int cbData;
67 } MYBLOB;
68
69/* SetBlobCmp
70 * This function compares two elements of SET_OF block
71 */
72static int SetBlobCmp(const void *elem1, const void *elem2 )
73 {
74 const MYBLOB *b1 = (const MYBLOB *)elem1;
75 const MYBLOB *b2 = (const MYBLOB *)elem2;
76 int r;
77
78 r = memcmp(b1->pbData, b2->pbData,
79 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
80 if(r != 0)
81 return r;
82 return b1->cbData-b2->cbData;
83 }
84
85/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
86int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
87 int ex_class, int is_set)
88 {
89 int ret=0,r;
90 int i;
91 unsigned char *p;
92 unsigned char *pStart, *pTempMem;
93 MYBLOB *rgSetBlob;
94 int totSize;
95
96 if (a == NULL) return(0);
97 for (i=sk_num(a)-1; i>=0; i--)
98 ret+=func(sk_value(a,i),NULL);
99 r=ASN1_object_size(1,ret,ex_tag);
100 if (pp == NULL) return(r);
101
102 p= *pp;
103 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
104
105/* Modified by gp@nsj.co.jp */
106 /* And then again by Ben */
107 /* And again by Steve */
108
109 if(!is_set || (sk_num(a) < 2))
110 {
111 for (i=0; i<sk_num(a); i++)
112 func(sk_value(a,i),&p);
113
114 *pp=p;
115 return(r);
116 }
117
118 pStart = p; /* Catch the beg of Setblobs*/
119 rgSetBlob = (MYBLOB *)OPENSSL_malloc( sk_num(a) * sizeof(MYBLOB)); /* In this array
120we will store the SET blobs */
121
122 for (i=0; i<sk_num(a); i++)
123 {
124 rgSetBlob[i].pbData = p; /* catch each set encode blob */
125 func(sk_value(a,i),&p);
126 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
127SetBlob
128*/
129 }
130 *pp=p;
131 totSize = p - pStart; /* This is the total size of all set blobs */
132
133 /* Now we have to sort the blobs. I am using a simple algo.
134 *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
135 qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
136 pTempMem = OPENSSL_malloc(totSize);
137
138/* Copy to temp mem */
139 p = pTempMem;
140 for(i=0; i<sk_num(a); ++i)
141 {
142 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
143 p += rgSetBlob[i].cbData;
144 }
145
146/* Copy back to user mem*/
147 memcpy(pStart, pTempMem, totSize);
148 OPENSSL_free(pTempMem);
149 OPENSSL_free(rgSetBlob);
150
151 return(r);
152 }
153
154STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
155 char *(*func)(), void (*free_func)(void *), int ex_tag, int ex_class)
156 {
157 ASN1_CTX c;
158 STACK *ret=NULL;
159
160 if ((a == NULL) || ((*a) == NULL))
161 { if ((ret=sk_new_null()) == NULL) goto err; }
162 else
163 ret=(*a);
164
165 c.p= *pp;
166 c.max=(length == 0)?0:(c.p+length);
167
168 c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);
169 if (c.inf & 0x80) goto err;
170 if (ex_class != c.xclass)
171 {
172 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
173 goto err;
174 }
175 if (ex_tag != c.tag)
176 {
177 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
178 goto err;
179 }
180 if ((c.slen+c.p) > c.max)
181 {
182 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
183 goto err;
184 }
185 /* check for infinite constructed - it can be as long
186 * as the amount of data passed to us */
187 if (c.inf == (V_ASN1_CONSTRUCTED+1))
188 c.slen=length+ *pp-c.p;
189 c.max=c.p+c.slen;
190
191 while (c.p < c.max)
192 {
193 char *s;
194
195 if (M_ASN1_D2I_end_sequence()) break;
196 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
197 {
198 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
199 asn1_add_error(*pp,(int)(c.q- *pp));
200 goto err;
201 }
202 if (!sk_push(ret,s)) goto err;
203 }
204 if (a != NULL) (*a)=ret;
205 *pp=c.p;
206 return(ret);
207err:
208 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
209 {
210 if (free_func != NULL)
211 sk_pop_free(ret,free_func);
212 else
213 sk_free(ret);
214 }
215 return(NULL);
216 }
217
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
deleted file mode 100644
index 4c651706d2..0000000000
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ /dev/null
@@ -1,148 +0,0 @@
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#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/evp.h>
70#include <openssl/x509.h>
71#include <openssl/objects.h>
72#include <openssl/buffer.h>
73
74int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
75 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
76 const EVP_MD *type)
77 {
78 EVP_MD_CTX ctx;
79 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
80 int i,inl=0,outl=0,outll=0;
81 X509_ALGOR *a;
82
83 for (i=0; i<2; i++)
84 {
85 if (i == 0)
86 a=algor1;
87 else
88 a=algor2;
89 if (a == NULL) continue;
90 if ( (a->parameter == NULL) ||
91 (a->parameter->type != V_ASN1_NULL))
92 {
93 ASN1_TYPE_free(a->parameter);
94 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
95 a->parameter->type=V_ASN1_NULL;
96 }
97 ASN1_OBJECT_free(a->algorithm);
98 a->algorithm=OBJ_nid2obj(type->pkey_type);
99 if (a->algorithm == NULL)
100 {
101 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
102 goto err;
103 }
104 if (a->algorithm->length == 0)
105 {
106 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
107 goto err;
108 }
109 }
110 inl=i2d(data,NULL);
111 buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl);
112 outll=outl=EVP_PKEY_size(pkey);
113 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
114 if ((buf_in == NULL) || (buf_out == NULL))
115 {
116 outl=0;
117 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
118 goto err;
119 }
120 p=buf_in;
121
122 i2d(data,&p);
123 EVP_SignInit(&ctx,type);
124 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
125 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
126 (unsigned int *)&outl,pkey))
127 {
128 outl=0;
129 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
130 goto err;
131 }
132 if (signature->data != NULL) OPENSSL_free(signature->data);
133 signature->data=buf_out;
134 buf_out=NULL;
135 signature->length=outl;
136 /* In the interests of compatibility, I'll make sure that
137 * the bit string has a 'not-used bits' value of 0
138 */
139 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
140 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
141err:
142 memset(&ctx,0,sizeof(ctx));
143 if (buf_in != NULL)
144 { memset((char *)buf_in,0,(unsigned int)inl); OPENSSL_free(buf_in); }
145 if (buf_out != NULL)
146 { memset((char *)buf_out,0,outll); OPENSSL_free(buf_out); }
147 return(outl);
148 }
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
deleted file mode 100644
index 569b811998..0000000000
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ /dev/null
@@ -1,533 +0,0 @@
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
81int 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
90int send_bio_chars(void *arg, const void *buf, int len)
91{
92 if(!arg) return 1;
93 if(BIO_write(arg, buf, len) != len) return 0;
94 return 1;
95}
96
97int send_fp_chars(void *arg, const void *buf, int len)
98{
99 if(!arg) return 1;
100 if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0;
101 return 1;
102}
103
104typedef int char_io(void *arg, const void *buf, int len);
105
106/* This function handles display of
107 * strings, one character at a time.
108 * It is passed an unsigned long for each
109 * character because it could come from 2 or even
110 * 4 byte forms.
111 */
112
113static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg)
114{
115 unsigned char chflgs, chtmp;
116 char tmphex[11];
117 if(c > 0xffff) {
118 BIO_snprintf(tmphex, 11, "\\W%08lX", c);
119 if(!io_ch(arg, tmphex, 10)) return -1;
120 return 10;
121 }
122 if(c > 0xff) {
123 BIO_snprintf(tmphex, 11, "\\U%04lX", c);
124 if(!io_ch(arg, tmphex, 6)) return -1;
125 return 6;
126 }
127 chtmp = (unsigned char)c;
128 if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB;
129 else chflgs = char_type[chtmp] & flags;
130 if(chflgs & CHARTYPE_BS_ESC) {
131 /* If we don't escape with quotes, signal we need quotes */
132 if(chflgs & ASN1_STRFLGS_ESC_QUOTE) {
133 if(do_quotes) *do_quotes = 1;
134 if(!io_ch(arg, &chtmp, 1)) return -1;
135 return 1;
136 }
137 if(!io_ch(arg, "\\", 1)) return -1;
138 if(!io_ch(arg, &chtmp, 1)) return -1;
139 return 2;
140 }
141 if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) {
142 BIO_snprintf(tmphex, 11, "\\%02X", chtmp);
143 if(!io_ch(arg, tmphex, 3)) return -1;
144 return 3;
145 }
146 if(!io_ch(arg, &chtmp, 1)) return -1;
147 return 1;
148}
149
150#define BUF_TYPE_WIDTH_MASK 0x7
151#define BUF_TYPE_CONVUTF8 0x8
152
153/* This function sends each character in a buffer to
154 * do_esc_char(). It interprets the content formats
155 * and converts to or from UTF8 as appropriate.
156 */
157
158static int do_buf(unsigned char *buf, int buflen,
159 int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg)
160{
161 int i, outlen, len;
162 unsigned char orflags, *p, *q;
163 unsigned long c;
164 p = buf;
165 q = buf + buflen;
166 outlen = 0;
167 while(p != q) {
168 if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
169 else orflags = 0;
170 switch(type & BUF_TYPE_WIDTH_MASK) {
171 case 4:
172 c = ((unsigned long)*p++) << 24;
173 c |= ((unsigned long)*p++) << 16;
174 c |= ((unsigned long)*p++) << 8;
175 c |= *p++;
176 break;
177
178 case 2:
179 c = ((unsigned long)*p++) << 8;
180 c |= *p++;
181 break;
182
183 case 1:
184 c = *p++;
185 break;
186
187 case 0:
188 i = UTF8_getc(p, buflen, &c);
189 if(i < 0) return -1; /* Invalid UTF8String */
190 p += i;
191 break;
192 }
193 if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
194 if(type & BUF_TYPE_CONVUTF8) {
195 unsigned char utfbuf[6];
196 int utflen;
197 utflen = UTF8_putc(utfbuf, 6, c);
198 for(i = 0; i < utflen; i++) {
199 /* We don't need to worry about setting orflags correctly
200 * because if utflen==1 its value will be correct anyway
201 * otherwise each character will be > 0x7f and so the
202 * character will never be escaped on first and last.
203 */
204 len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg);
205 if(len < 0) return -1;
206 outlen += len;
207 }
208 } else {
209 len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg);
210 if(len < 0) return -1;
211 outlen += len;
212 }
213 }
214 return outlen;
215}
216
217/* This function hex dumps a buffer of characters */
218
219static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
220{
221 const static char hexdig[] = "0123456789ABCDEF";
222 unsigned char *p, *q;
223 char hextmp[2];
224 if(arg) {
225 p = buf;
226 q = buf + buflen;
227 while(p != q) {
228 hextmp[0] = hexdig[*p >> 4];
229 hextmp[1] = hexdig[*p & 0xf];
230 if(!io_ch(arg, hextmp, 2)) return -1;
231 p++;
232 }
233 }
234 return buflen << 1;
235}
236
237/* "dump" a string. This is done when the type is unknown,
238 * or the flags request it. We can either dump the content
239 * octets or the entire DER encoding. This uses the RFC2253
240 * #01234 format.
241 */
242
243int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str)
244{
245 /* Placing the ASN1_STRING in a temp ASN1_TYPE allows
246 * the DER encoding to readily obtained
247 */
248 ASN1_TYPE t;
249 unsigned char *der_buf, *p;
250 int outlen, der_len;
251
252 if(!io_ch(arg, "#", 1)) return -1;
253 /* If we don't dump DER encoding just dump content octets */
254 if(!(lflags & ASN1_STRFLGS_DUMP_DER)) {
255 outlen = do_hex_dump(io_ch, arg, str->data, str->length);
256 if(outlen < 0) return -1;
257 return outlen + 1;
258 }
259 t.type = str->type;
260 t.value.ptr = (char *)str;
261 der_len = i2d_ASN1_TYPE(&t, NULL);
262 der_buf = OPENSSL_malloc(der_len);
263 if(!der_buf) return -1;
264 p = der_buf;
265 i2d_ASN1_TYPE(&t, &p);
266 outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
267 OPENSSL_free(der_buf);
268 if(outlen < 0) return -1;
269 return outlen + 1;
270}
271
272/* Lookup table to convert tags to character widths,
273 * 0 = UTF8 encoded, -1 is used for non string types
274 * otherwise it is the number of bytes per character
275 */
276
277const static char tag2nbyte[] = {
278 -1, -1, -1, -1, -1, /* 0-4 */
279 -1, -1, -1, -1, -1, /* 5-9 */
280 -1, -1, 0, -1, /* 10-13 */
281 -1, -1, -1, -1, /* 15-17 */
282 -1, 1, 1, /* 18-20 */
283 -1, 1, -1,-1, /* 21-24 */
284 -1, 1, -1, /* 25-27 */
285 4, -1, 2 /* 28-30 */
286};
287
288#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
289 ASN1_STRFLGS_ESC_QUOTE | \
290 ASN1_STRFLGS_ESC_CTRL | \
291 ASN1_STRFLGS_ESC_MSB)
292
293/* This is the main function, print out an
294 * ASN1_STRING taking note of various escape
295 * and display options. Returns number of
296 * characters written or -1 if an error
297 * occurred.
298 */
299
300static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str)
301{
302 int outlen, len;
303 int type;
304 char quotes;
305 unsigned char flags;
306 quotes = 0;
307 /* Keep a copy of escape flags */
308 flags = (unsigned char)(lflags & ESC_FLAGS);
309
310 type = str->type;
311
312 outlen = 0;
313
314
315 if(lflags & ASN1_STRFLGS_SHOW_TYPE) {
316 const char *tagname;
317 tagname = ASN1_tag2str(type);
318 outlen += strlen(tagname);
319 if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1;
320 outlen++;
321 }
322
323 /* Decide what to do with type, either dump content or display it */
324
325 /* Dump everything */
326 if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1;
327 /* Ignore the string type */
328 else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1;
329 else {
330 /* Else determine width based on type */
331 if((type > 0) && (type < 31)) type = tag2nbyte[type];
332 else type = -1;
333 if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1;
334 }
335
336 if(type == -1) {
337 len = do_dump(lflags, io_ch, arg, str);
338 if(len < 0) return -1;
339 outlen += len;
340 return outlen;
341 }
342
343 if(lflags & ASN1_STRFLGS_UTF8_CONVERT) {
344 /* Note: if string is UTF8 and we want
345 * to convert to UTF8 then we just interpret
346 * it as 1 byte per character to avoid converting
347 * twice.
348 */
349 if(!type) type = 1;
350 else type |= BUF_TYPE_CONVUTF8;
351 }
352
353 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
354 if(outlen < 0) return -1;
355 outlen += len;
356 if(quotes) outlen += 2;
357 if(!arg) return outlen;
358 if(quotes && !io_ch(arg, "\"", 1)) return -1;
359 do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
360 if(quotes && !io_ch(arg, "\"", 1)) return -1;
361 return outlen;
362}
363
364/* Used for line indenting: print 'indent' spaces */
365
366static int do_indent(char_io *io_ch, void *arg, int indent)
367{
368 int i;
369 for(i = 0; i < indent; i++)
370 if(!io_ch(arg, " ", 1)) return 0;
371 return 1;
372}
373
374
375static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
376 int indent, unsigned long flags)
377{
378 int i, prev = -1, orflags, cnt;
379 int fn_opt, fn_nid;
380 ASN1_OBJECT *fn;
381 ASN1_STRING *val;
382 X509_NAME_ENTRY *ent;
383 char objtmp[80];
384 const char *objbuf;
385 int outlen, len;
386 char *sep_dn, *sep_mv, *sep_eq;
387 int sep_dn_len, sep_mv_len, sep_eq_len;
388 if(indent < 0) indent = 0;
389 outlen = indent;
390 if(!do_indent(io_ch, arg, indent)) return -1;
391 switch (flags & XN_FLAG_SEP_MASK)
392 {
393 case XN_FLAG_SEP_MULTILINE:
394 sep_dn = "\n";
395 sep_dn_len = 1;
396 sep_mv = " + ";
397 sep_mv_len = 3;
398 break;
399
400 case XN_FLAG_SEP_COMMA_PLUS:
401 sep_dn = ",";
402 sep_dn_len = 1;
403 sep_mv = "+";
404 sep_mv_len = 1;
405 indent = 0;
406 break;
407
408 case XN_FLAG_SEP_CPLUS_SPC:
409 sep_dn = ", ";
410 sep_dn_len = 2;
411 sep_mv = " + ";
412 sep_mv_len = 3;
413 indent = 0;
414 break;
415
416 case XN_FLAG_SEP_SPLUS_SPC:
417 sep_dn = "; ";
418 sep_dn_len = 2;
419 sep_mv = " + ";
420 sep_mv_len = 3;
421 indent = 0;
422 break;
423
424 default:
425 return -1;
426 }
427
428 if(flags & XN_FLAG_SPC_EQ) {
429 sep_eq = " = ";
430 sep_eq_len = 3;
431 } else {
432 sep_eq = "=";
433 sep_eq_len = 1;
434 }
435
436 fn_opt = flags & XN_FLAG_FN_MASK;
437
438 cnt = X509_NAME_entry_count(n);
439 for(i = 0; i < cnt; i++) {
440 if(flags & XN_FLAG_DN_REV)
441 ent = X509_NAME_get_entry(n, cnt - i - 1);
442 else ent = X509_NAME_get_entry(n, i);
443 if(prev != -1) {
444 if(prev == ent->set) {
445 if(!io_ch(arg, sep_mv, sep_mv_len)) return -1;
446 outlen += sep_mv_len;
447 } else {
448 if(!io_ch(arg, sep_dn, sep_dn_len)) return -1;
449 outlen += sep_dn_len;
450 if(!do_indent(io_ch, arg, indent)) return -1;
451 outlen += indent;
452 }
453 }
454 prev = ent->set;
455 fn = X509_NAME_ENTRY_get_object(ent);
456 val = X509_NAME_ENTRY_get_data(ent);
457 fn_nid = OBJ_obj2nid(fn);
458 if(fn_opt != XN_FLAG_FN_NONE) {
459 int objlen;
460 if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) {
461 OBJ_obj2txt(objtmp, 80, fn, 1);
462 objbuf = objtmp;
463 } else {
464 if(fn_opt == XN_FLAG_FN_SN)
465 objbuf = OBJ_nid2sn(fn_nid);
466 else if(fn_opt == XN_FLAG_FN_LN)
467 objbuf = OBJ_nid2ln(fn_nid);
468 else objbuf = "";
469 }
470 objlen = strlen(objbuf);
471 if(!io_ch(arg, objbuf, objlen)) return -1;
472 if(!io_ch(arg, sep_eq, sep_eq_len)) return -1;
473 outlen += objlen + sep_eq_len;
474 }
475 /* If the field name is unknown then fix up the DER dump
476 * flag. We might want to limit this further so it will
477 * DER dump on anything other than a few 'standard' fields.
478 */
479 if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS))
480 orflags = ASN1_STRFLGS_DUMP_ALL;
481 else orflags = 0;
482
483 len = do_print_ex(io_ch, arg, flags | orflags, val);
484 if(len < 0) return -1;
485 outlen += len;
486 }
487 return outlen;
488}
489
490/* Wrappers round the main functions */
491
492int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
493{
494 return do_name_ex(send_bio_chars, out, nm, indent, flags);
495}
496
497
498int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
499{
500 return do_name_ex(send_fp_chars, fp, nm, indent, flags);
501}
502
503int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
504{
505 return do_print_ex(send_bio_chars, out, flags, str);
506}
507
508
509int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
510{
511 return do_print_ex(send_fp_chars, fp, flags, str);
512}
513
514/* Utility function: convert any string type to UTF8, returns number of bytes
515 * in output string or a negative error code
516 */
517
518int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
519{
520 ASN1_STRING stmp, *str = &stmp;
521 int mbflag, type, ret;
522 if(!*out || !in) return -1;
523 type = in->type;
524 if((type < 0) || (type > 30)) return -1;
525 mbflag = tag2nbyte[type];
526 if(mbflag == -1) return -1;
527 mbflag |= MBSTRING_FLAG;
528 stmp.data = NULL;
529 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
530 if(ret < 0) return ret;
531 if(out) *out = stmp.data;
532 return stmp.length;
533}
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
deleted file mode 100644
index 732e68fe46..0000000000
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ /dev/null
@@ -1,250 +0,0 @@
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 = ~(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING);
109 else if(!strcmp(p, "pkix"))
110 mask = ~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_name, 1, ub_name, DIRSTRING_TYPE, 0},
174{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}
175};
176
177static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
178 const ASN1_STRING_TABLE * const *b)
179{
180 return (*a)->nid - (*b)->nid;
181}
182
183static int table_cmp(const void *a, const void *b)
184{
185 const ASN1_STRING_TABLE *sa = a, *sb = b;
186 return sa->nid - sb->nid;
187}
188
189ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
190{
191 int idx;
192 ASN1_STRING_TABLE *ttmp;
193 ASN1_STRING_TABLE fnd;
194 fnd.nid = nid;
195 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
196 (char *)tbl_standard,
197 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
198 sizeof(ASN1_STRING_TABLE), table_cmp);
199 if(ttmp) return ttmp;
200 if(!stable) return NULL;
201 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
202 if(idx < 0) return NULL;
203 return sk_ASN1_STRING_TABLE_value(stable, idx);
204}
205
206int ASN1_STRING_TABLE_add(int nid,
207 long minsize, long maxsize, unsigned long mask,
208 unsigned long flags)
209{
210 ASN1_STRING_TABLE *tmp;
211 char new_nid = 0;
212 flags &= ~STABLE_FLAGS_MALLOC;
213 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
214 if(!stable) {
215 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
216 return 0;
217 }
218 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
219 tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
220 if(!tmp) {
221 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
222 ERR_R_MALLOC_FAILURE);
223 return 0;
224 }
225 tmp->flags = flags | STABLE_FLAGS_MALLOC;
226 tmp->nid = nid;
227 new_nid = 1;
228 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
229 if(minsize != -1) tmp->minsize = minsize;
230 if(maxsize != -1) tmp->maxsize = maxsize;
231 tmp->mask = mask;
232 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
233 return 1;
234}
235
236void ASN1_STRING_TABLE_cleanup(void)
237{
238 STACK_OF(ASN1_STRING_TABLE) *tmp;
239 tmp = stable;
240 if(!tmp) return;
241 stable = NULL;
242 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
243}
244
245static void st_free(ASN1_STRING_TABLE *tbl)
246{
247 if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl);
248}
249
250IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
deleted file mode 100644
index 8c0ddee4ac..0000000000
--- a/src/lib/libcrypto/asn1/a_time.c
+++ /dev/null
@@ -1,127 +0,0 @@
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 <openssl/asn1.h>
68
69ASN1_TIME *ASN1_TIME_new(void)
70{ return M_ASN1_TIME_new(); }
71
72void ASN1_TIME_free(ASN1_TIME *x)
73{ M_ASN1_TIME_free(x); }
74
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
99
100ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length)
101 {
102 unsigned char tag;
103 tag = **pp & ~V_ASN1_CONSTRUCTED;
104 if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL))
105 return d2i_ASN1_UTCTIME(a, pp, length);
106 if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL))
107 return d2i_ASN1_GENERALIZEDTIME(a, pp, length);
108 ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
109 return(NULL);
110 }
111
112
113ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
114 {
115 struct tm *ts;
116#if defined(THREADS) && !defined(WIN32) && !defined(__CYGWIN32__)
117 struct tm data;
118
119 gmtime_r(&t,&data);
120 ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
121#else
122 ts=gmtime(&t);
123#endif
124 if((ts->tm_year >= 50) && (ts->tm_year < 150))
125 return ASN1_UTCTIME_set(s, t);
126 return ASN1_GENERALIZEDTIME_set(s,t);
127 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
deleted file mode 100644
index e72a6b29e0..0000000000
--- a/src/lib/libcrypto/asn1/a_type.c
+++ /dev/null
@@ -1,352 +0,0 @@
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 "cryptlib.h"
61#include <openssl/asn1_mac.h>
62
63static void ASN1_TYPE_component_free(ASN1_TYPE *a);
64int i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **pp)
65 {
66 int r=0;
67
68 if (a == NULL) return(0);
69
70 switch (a->type)
71 {
72 case V_ASN1_NULL:
73 if (pp != NULL)
74 ASN1_put_object(pp,0,0,V_ASN1_NULL,V_ASN1_UNIVERSAL);
75 r=2;
76 break;
77 case V_ASN1_INTEGER:
78 case V_ASN1_NEG_INTEGER:
79 r=i2d_ASN1_INTEGER(a->value.integer,pp);
80 break;
81 case V_ASN1_ENUMERATED:
82 case V_ASN1_NEG_ENUMERATED:
83 r=i2d_ASN1_ENUMERATED(a->value.enumerated,pp);
84 break;
85 case V_ASN1_BIT_STRING:
86 r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp);
87 break;
88 case V_ASN1_OCTET_STRING:
89 r=i2d_ASN1_OCTET_STRING(a->value.octet_string,pp);
90 break;
91 case V_ASN1_OBJECT:
92 r=i2d_ASN1_OBJECT(a->value.object,pp);
93 break;
94 case V_ASN1_PRINTABLESTRING:
95 r=M_i2d_ASN1_PRINTABLESTRING(a->value.printablestring,pp);
96 break;
97 case V_ASN1_T61STRING:
98 r=M_i2d_ASN1_T61STRING(a->value.t61string,pp);
99 break;
100 case V_ASN1_IA5STRING:
101 r=M_i2d_ASN1_IA5STRING(a->value.ia5string,pp);
102 break;
103 case V_ASN1_GENERALSTRING:
104 r=M_i2d_ASN1_GENERALSTRING(a->value.generalstring,pp);
105 break;
106 case V_ASN1_UNIVERSALSTRING:
107 r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp);
108 break;
109 case V_ASN1_UTF8STRING:
110 r=M_i2d_ASN1_UTF8STRING(a->value.utf8string,pp);
111 break;
112 case V_ASN1_VISIBLESTRING:
113 r=M_i2d_ASN1_VISIBLESTRING(a->value.visiblestring,pp);
114 break;
115 case V_ASN1_BMPSTRING:
116 r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp);
117 break;
118 case V_ASN1_UTCTIME:
119 r=i2d_ASN1_UTCTIME(a->value.utctime,pp);
120 break;
121 case V_ASN1_GENERALIZEDTIME:
122 r=i2d_ASN1_GENERALIZEDTIME(a->value.generalizedtime,pp);
123 break;
124 case V_ASN1_SET:
125 case V_ASN1_SEQUENCE:
126 case V_ASN1_OTHER:
127 default:
128 if (a->value.set == NULL)
129 r=0;
130 else
131 {
132 r=a->value.set->length;
133 if (pp != NULL)
134 {
135 memcpy(*pp,a->value.set->data,r);
136 *pp+=r;
137 }
138 }
139 break;
140 }
141 return(r);
142 }
143
144ASN1_TYPE *d2i_ASN1_TYPE(ASN1_TYPE **a, unsigned char **pp, long length)
145 {
146 ASN1_TYPE *ret=NULL;
147 unsigned char *q,*p,*max;
148 int inf,tag,xclass;
149 long len;
150
151 if ((a == NULL) || ((*a) == NULL))
152 {
153 if ((ret=ASN1_TYPE_new()) == NULL) goto err;
154 }
155 else
156 ret=(*a);
157
158 p= *pp;
159 q=p;
160 max=(p+length);
161
162 inf=ASN1_get_object(&q,&len,&tag,&xclass,length);
163 if (inf & 0x80) goto err;
164 /* If not universal tag we've no idea what it is */
165 if(xclass != V_ASN1_UNIVERSAL) tag = V_ASN1_OTHER;
166
167 ASN1_TYPE_component_free(ret);
168
169 switch (tag)
170 {
171 case V_ASN1_NULL:
172 p=q;
173 ret->value.ptr=NULL;
174 break;
175 case V_ASN1_INTEGER:
176 if ((ret->value.integer=
177 d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL)
178 goto err;
179 break;
180 case V_ASN1_ENUMERATED:
181 if ((ret->value.enumerated=
182 d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL)
183 goto err;
184 break;
185 case V_ASN1_BIT_STRING:
186 if ((ret->value.bit_string=
187 d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL)
188 goto err;
189 break;
190 case V_ASN1_OCTET_STRING:
191 if ((ret->value.octet_string=
192 d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL)
193 goto err;
194 break;
195 case V_ASN1_VISIBLESTRING:
196 if ((ret->value.visiblestring=
197 d2i_ASN1_VISIBLESTRING(NULL,&p,max-p)) == NULL)
198 goto err;
199 break;
200 case V_ASN1_UTF8STRING:
201 if ((ret->value.utf8string=
202 d2i_ASN1_UTF8STRING(NULL,&p,max-p)) == NULL)
203 goto err;
204 break;
205 case V_ASN1_OBJECT:
206 if ((ret->value.object=
207 d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL)
208 goto err;
209 break;
210 case V_ASN1_PRINTABLESTRING:
211 if ((ret->value.printablestring=
212 d2i_ASN1_PRINTABLESTRING(NULL,&p,max-p)) == NULL)
213 goto err;
214 break;
215 case V_ASN1_T61STRING:
216 if ((ret->value.t61string=
217 M_d2i_ASN1_T61STRING(NULL,&p,max-p)) == NULL)
218 goto err;
219 break;
220 case V_ASN1_IA5STRING:
221 if ((ret->value.ia5string=
222 M_d2i_ASN1_IA5STRING(NULL,&p,max-p)) == NULL)
223 goto err;
224 break;
225 case V_ASN1_GENERALSTRING:
226 if ((ret->value.generalstring=
227 M_d2i_ASN1_GENERALSTRING(NULL,&p,max-p)) == NULL)
228 goto err;
229 break;
230 case V_ASN1_UNIVERSALSTRING:
231 if ((ret->value.universalstring=
232 M_d2i_ASN1_UNIVERSALSTRING(NULL,&p,max-p)) == NULL)
233 goto err;
234 break;
235 case V_ASN1_BMPSTRING:
236 if ((ret->value.bmpstring=
237 M_d2i_ASN1_BMPSTRING(NULL,&p,max-p)) == NULL)
238 goto err;
239 break;
240 case V_ASN1_UTCTIME:
241 if ((ret->value.utctime=
242 d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL)
243 goto err;
244 break;
245 case V_ASN1_GENERALIZEDTIME:
246 if ((ret->value.generalizedtime=
247 d2i_ASN1_GENERALIZEDTIME(NULL,&p,max-p)) == NULL)
248 goto err;
249 break;
250 case V_ASN1_SET:
251 case V_ASN1_SEQUENCE:
252 case V_ASN1_OTHER:
253 default:
254 /* Sets and sequences are left complete */
255 if ((ret->value.set=ASN1_STRING_new()) == NULL) goto err;
256 ret->value.set->type=tag;
257 len+=(q-p);
258 if (!ASN1_STRING_set(ret->value.set,p,(int)len)) goto err;
259 p+=len;
260 break;
261 }
262
263 ret->type=tag;
264 if (a != NULL) (*a)=ret;
265 *pp=p;
266 return(ret);
267err:
268 if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_TYPE_free(ret);
269 return(NULL);
270 }
271
272ASN1_TYPE *ASN1_TYPE_new(void)
273 {
274 ASN1_TYPE *ret=NULL;
275 ASN1_CTX c;
276
277 M_ASN1_New_Malloc(ret,ASN1_TYPE);
278 ret->type= -1;
279 ret->value.ptr=NULL;
280 return(ret);
281 M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW);
282 }
283
284void ASN1_TYPE_free(ASN1_TYPE *a)
285 {
286 if (a == NULL) return;
287 ASN1_TYPE_component_free(a);
288 OPENSSL_free(a);
289 }
290
291int ASN1_TYPE_get(ASN1_TYPE *a)
292 {
293 if (a->value.ptr != NULL)
294 return(a->type);
295 else
296 return(0);
297 }
298
299void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
300 {
301 if (a->value.ptr != NULL)
302 ASN1_TYPE_component_free(a);
303 a->type=type;
304 a->value.ptr=value;
305 }
306
307static void ASN1_TYPE_component_free(ASN1_TYPE *a)
308 {
309 if (a == NULL) return;
310
311 if (a->value.ptr != NULL)
312 {
313 switch (a->type)
314 {
315 case V_ASN1_OBJECT:
316 ASN1_OBJECT_free(a->value.object);
317 break;
318 case V_ASN1_NULL:
319 break;
320 case V_ASN1_INTEGER:
321 case V_ASN1_NEG_INTEGER:
322 case V_ASN1_ENUMERATED:
323 case V_ASN1_NEG_ENUMERATED:
324 case V_ASN1_BIT_STRING:
325 case V_ASN1_OCTET_STRING:
326 case V_ASN1_SEQUENCE:
327 case V_ASN1_SET:
328 case V_ASN1_NUMERICSTRING:
329 case V_ASN1_PRINTABLESTRING:
330 case V_ASN1_T61STRING:
331 case V_ASN1_VIDEOTEXSTRING:
332 case V_ASN1_IA5STRING:
333 case V_ASN1_UTCTIME:
334 case V_ASN1_GENERALIZEDTIME:
335 case V_ASN1_GRAPHICSTRING:
336 case V_ASN1_VISIBLESTRING:
337 case V_ASN1_GENERALSTRING:
338 case V_ASN1_UNIVERSALSTRING:
339 case V_ASN1_BMPSTRING:
340 case V_ASN1_UTF8STRING:
341 case V_ASN1_OTHER:
342 default:
343 ASN1_STRING_free((ASN1_STRING *)a->value.ptr);
344 break;
345 }
346 a->type=0;
347 a->value.ptr=NULL;
348 }
349 }
350
351IMPLEMENT_STACK_OF(ASN1_TYPE)
352IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c
deleted file mode 100644
index 854278f136..0000000000
--- a/src/lib/libcrypto/asn1/a_utf8.c
+++ /dev/null
@@ -1,238 +0,0 @@
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
63ASN1_UTF8STRING *ASN1_UTF8STRING_new(void)
64{ return M_ASN1_UTF8STRING_new();}
65
66void ASN1_UTF8STRING_free(ASN1_UTF8STRING *x)
67{ M_ASN1_UTF8STRING_free(x);}
68
69int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp)
70 {
71 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
72 V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL));
73 }
74
75ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, unsigned char **pp,
76 long length)
77 {
78 ASN1_UTF8STRING *ret=NULL;
79
80 ret=(ASN1_UTF8STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
81 pp,length,V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL);
82 if (ret == NULL)
83 {
84 ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_NESTED_ASN1_ERROR);
85 return(NULL);
86 }
87 return(ret);
88 }
89
90
91/* UTF8 utilities */
92
93/* This parses a UTF8 string one character at a time. It is passed a pointer
94 * to the string and the length of the string. It sets 'value' to the value of
95 * the current character. It returns the number of characters read or a
96 * negative error code:
97 * -1 = string too short
98 * -2 = illegal character
99 * -3 = subsequent characters not of the form 10xxxxxx
100 * -4 = character encoded incorrectly (not minimal length).
101 */
102
103int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
104{
105 const unsigned char *p;
106 unsigned long value;
107 int ret;
108 if(len <= 0) return 0;
109 p = str;
110
111 /* Check syntax and work out the encoded value (if correct) */
112 if((*p & 0x80) == 0) {
113 value = *p++ & 0x7f;
114 ret = 1;
115 } else if((*p & 0xe0) == 0xc0) {
116 if(len < 2) return -1;
117 if((p[1] & 0xc0) != 0x80) return -3;
118 value = (*p++ & 0x1f) << 6;
119 value |= *p++ & 0x3f;
120 if(value < 0x80) return -4;
121 ret = 2;
122 } else if((*p & 0xf0) == 0xe0) {
123 if(len < 3) return -1;
124 if( ((p[1] & 0xc0) != 0x80)
125 || ((p[2] & 0xc0) != 0x80) ) return -3;
126 value = (*p++ & 0xf) << 12;
127 value |= (*p++ & 0x3f) << 6;
128 value |= *p++ & 0x3f;
129 if(value < 0x800) return -4;
130 ret = 3;
131 } else if((*p & 0xf8) == 0xf0) {
132 if(len < 4) return -1;
133 if( ((p[1] & 0xc0) != 0x80)
134 || ((p[2] & 0xc0) != 0x80)
135 || ((p[3] & 0xc0) != 0x80) ) return -3;
136 value = ((unsigned long)(*p++ & 0x7)) << 18;
137 value |= (*p++ & 0x3f) << 12;
138 value |= (*p++ & 0x3f) << 6;
139 value |= *p++ & 0x3f;
140 if(value < 0x10000) return -4;
141 ret = 4;
142 } else if((*p & 0xfc) == 0xf8) {
143 if(len < 5) return -1;
144 if( ((p[1] & 0xc0) != 0x80)
145 || ((p[2] & 0xc0) != 0x80)
146 || ((p[3] & 0xc0) != 0x80)
147 || ((p[4] & 0xc0) != 0x80) ) return -3;
148 value = ((unsigned long)(*p++ & 0x3)) << 24;
149 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
150 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
151 value |= (*p++ & 0x3f) << 6;
152 value |= *p++ & 0x3f;
153 if(value < 0x200000) return -4;
154 ret = 5;
155 } else if((*p & 0xfe) == 0xfc) {
156 if(len < 6) return -1;
157 if( ((p[1] & 0xc0) != 0x80)
158 || ((p[2] & 0xc0) != 0x80)
159 || ((p[3] & 0xc0) != 0x80)
160 || ((p[4] & 0xc0) != 0x80)
161 || ((p[5] & 0xc0) != 0x80) ) return -3;
162 value = ((unsigned long)(*p++ & 0x1)) << 30;
163 value |= ((unsigned long)(*p++ & 0x3f)) << 24;
164 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
165 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
166 value |= (*p++ & 0x3f) << 6;
167 value |= *p++ & 0x3f;
168 if(value < 0x4000000) return -4;
169 ret = 6;
170 } else return -2;
171 *val = value;
172 return ret;
173}
174
175/* This takes a character 'value' and writes the UTF8 encoded value in
176 * 'str' where 'str' is a buffer containing 'len' characters. Returns
177 * the number of characters written or -1 if 'len' is too small. 'str' can
178 * be set to NULL in which case it just returns the number of characters.
179 * It will need at most 6 characters.
180 */
181
182int UTF8_putc(unsigned char *str, int len, unsigned long value)
183{
184 if(!str) len = 6; /* Maximum we will need */
185 else if(len <= 0) return -1;
186 if(value < 0x80) {
187 if(str) *str = (unsigned char)value;
188 return 1;
189 }
190 if(value < 0x800) {
191 if(len < 2) return -1;
192 if(str) {
193 *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);
194 *str = (unsigned char)((value & 0x3f) | 0x80);
195 }
196 return 2;
197 }
198 if(value < 0x10000) {
199 if(len < 3) return -1;
200 if(str) {
201 *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0);
202 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
203 *str = (unsigned char)((value & 0x3f) | 0x80);
204 }
205 return 3;
206 }
207 if(value < 0x200000) {
208 if(len < 4) return -1;
209 if(str) {
210 *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0);
211 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
212 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
213 *str = (unsigned char)((value & 0x3f) | 0x80);
214 }
215 return 4;
216 }
217 if(value < 0x4000000) {
218 if(len < 5) return -1;
219 if(str) {
220 *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8);
221 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
222 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
223 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
224 *str = (unsigned char)((value & 0x3f) | 0x80);
225 }
226 return 5;
227 }
228 if(len < 6) return -1;
229 if(str) {
230 *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc);
231 *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80);
232 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
233 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
234 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
235 *str = (unsigned char)((value & 0x3f) | 0x80);
236 }
237 return 6;
238}
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
deleted file mode 100644
index 2a11927e5c..0000000000
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ /dev/null
@@ -1,119 +0,0 @@
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
74int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
75 char *data, EVP_PKEY *pkey)
76 {
77 EVP_MD_CTX ctx;
78 const EVP_MD *type;
79 unsigned char *p,*buf_in=NULL;
80 int ret= -1,i,inl;
81
82 i=OBJ_obj2nid(a->algorithm);
83 type=EVP_get_digestbyname(OBJ_nid2sn(i));
84 if (type == NULL)
85 {
86 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
87 goto err;
88 }
89
90 inl=i2d(data,NULL);
91 buf_in=OPENSSL_malloc((unsigned int)inl);
92 if (buf_in == NULL)
93 {
94 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
95 goto err;
96 }
97 p=buf_in;
98
99 i2d(data,&p);
100 EVP_VerifyInit(&ctx,type);
101 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
102
103 memset(buf_in,0,(unsigned int)inl);
104 OPENSSL_free(buf_in);
105
106 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
107 (unsigned int)signature->length,pkey) <= 0)
108 {
109 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
110 ret=0;
111 goto err;
112 }
113 /* we don't need to zero the 'ctx' because we just checked
114 * public information */
115 /* memset(&ctx,0,sizeof(ctx)); */
116 ret=1;
117err:
118 return(ret);
119 }
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
deleted file mode 100644
index 6f956b1963..0000000000
--- a/src/lib/libcrypto/asn1/asn1.h
+++ /dev/null
@@ -1,1151 +0,0 @@
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 NO_BIO
64#include <openssl/bio.h>
65#endif
66#include <openssl/bn.h>
67#include <openssl/stack.h>
68#include <openssl/safestack.h>
69
70#include <openssl/symhacks.h>
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76#define V_ASN1_UNIVERSAL 0x00
77#define V_ASN1_APPLICATION 0x40
78#define V_ASN1_CONTEXT_SPECIFIC 0x80
79#define V_ASN1_PRIVATE 0xc0
80
81#define V_ASN1_CONSTRUCTED 0x20
82#define V_ASN1_PRIMITIVE_TAG 0x1f
83#define V_ASN1_PRIMATIVE_TAG 0x1f
84
85#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
86#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */
87
88#define V_ASN1_NEG 0x100 /* negative flag */
89
90#define V_ASN1_UNDEF -1
91#define V_ASN1_EOC 0
92#define V_ASN1_BOOLEAN 1 /**/
93#define V_ASN1_INTEGER 2
94#define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
95#define V_ASN1_BIT_STRING 3
96#define V_ASN1_OCTET_STRING 4
97#define V_ASN1_NULL 5
98#define V_ASN1_OBJECT 6
99#define V_ASN1_OBJECT_DESCRIPTOR 7
100#define V_ASN1_EXTERNAL 8
101#define V_ASN1_REAL 9
102#define V_ASN1_ENUMERATED 10
103#define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
104#define V_ASN1_UTF8STRING 12
105#define V_ASN1_SEQUENCE 16
106#define V_ASN1_SET 17
107#define V_ASN1_NUMERICSTRING 18 /**/
108#define V_ASN1_PRINTABLESTRING 19
109#define V_ASN1_T61STRING 20
110#define V_ASN1_TELETEXSTRING 20 /* alias */
111#define V_ASN1_VIDEOTEXSTRING 21 /**/
112#define V_ASN1_IA5STRING 22
113#define V_ASN1_UTCTIME 23
114#define V_ASN1_GENERALIZEDTIME 24 /**/
115#define V_ASN1_GRAPHICSTRING 25 /**/
116#define V_ASN1_ISO64STRING 26 /**/
117#define V_ASN1_VISIBLESTRING 26 /* alias */
118#define V_ASN1_GENERALSTRING 27 /**/
119#define V_ASN1_UNIVERSALSTRING 28 /**/
120#define V_ASN1_BMPSTRING 30
121
122/* For use with d2i_ASN1_type_bytes() */
123#define B_ASN1_NUMERICSTRING 0x0001
124#define B_ASN1_PRINTABLESTRING 0x0002
125#define B_ASN1_T61STRING 0x0004
126#define B_ASN1_TELETEXSTRING 0x0008
127#define B_ASN1_VIDEOTEXSTRING 0x0008
128#define B_ASN1_IA5STRING 0x0010
129#define B_ASN1_GRAPHICSTRING 0x0020
130#define B_ASN1_ISO64STRING 0x0040
131#define B_ASN1_VISIBLESTRING 0x0040
132#define B_ASN1_GENERALSTRING 0x0080
133#define B_ASN1_UNIVERSALSTRING 0x0100
134#define B_ASN1_OCTET_STRING 0x0200
135#define B_ASN1_BIT_STRING 0x0400
136#define B_ASN1_BMPSTRING 0x0800
137#define B_ASN1_UNKNOWN 0x1000
138#define B_ASN1_UTF8STRING 0x2000
139
140/* For use with ASN1_mbstring_copy() */
141#define MBSTRING_FLAG 0x1000
142#define MBSTRING_ASC (MBSTRING_FLAG|1)
143#define MBSTRING_BMP (MBSTRING_FLAG|2)
144#define MBSTRING_UNIV (MBSTRING_FLAG|3)
145#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
146
147struct X509_algor_st;
148
149#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
150#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
151
152typedef struct asn1_ctx_st
153 {
154 unsigned char *p;/* work char pointer */
155 int eos; /* end of sequence read for indefinite encoding */
156 int error; /* error code to use when returning an error */
157 int inf; /* constructed if 0x20, indefinite is 0x21 */
158 int tag; /* tag from last 'get object' */
159 int xclass; /* class from last 'get object' */
160 long slen; /* length of last 'get object' */
161 unsigned char *max; /* largest value of p allowed */
162 unsigned char *q;/* temporary variable */
163 unsigned char **pp;/* variable */
164 int line; /* used in error processing */
165 } ASN1_CTX;
166
167/* These are used internally in the ASN1_OBJECT to keep track of
168 * whether the names and data need to be free()ed */
169#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
170#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
171#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
172#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
173typedef struct asn1_object_st
174 {
175 const char *sn,*ln;
176 int nid;
177 int length;
178 unsigned char *data;
179 int flags; /* Should we free this one */
180 } ASN1_OBJECT;
181
182#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
183/* This is the base type that holds just about everything :-) */
184typedef struct asn1_string_st
185 {
186 int length;
187 int type;
188 unsigned char *data;
189 /* The value of the following field depends on the type being
190 * held. It is mostly being used for BIT_STRING so if the
191 * input data has a non-zero 'unused bits' value, it will be
192 * handled correctly */
193 long flags;
194 } ASN1_STRING;
195
196#define STABLE_FLAGS_MALLOC 0x01
197#define STABLE_NO_MASK 0x02
198#define DIRSTRING_TYPE \
199 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
200#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
201
202typedef struct asn1_string_table_st {
203 int nid;
204 long minsize;
205 long maxsize;
206 unsigned long mask;
207 unsigned long flags;
208} ASN1_STRING_TABLE;
209
210DECLARE_STACK_OF(ASN1_STRING_TABLE)
211
212/* size limits: this stuff is taken straight from RFC2459 */
213
214#define ub_name 32768
215#define ub_common_name 64
216#define ub_locality_name 128
217#define ub_state_name 128
218#define ub_organization_name 64
219#define ub_organization_unit_name 64
220#define ub_title 64
221#define ub_email_address 128
222
223#ifdef NO_ASN1_TYPEDEFS
224#define ASN1_INTEGER ASN1_STRING
225#define ASN1_ENUMERATED ASN1_STRING
226#define ASN1_BIT_STRING ASN1_STRING
227#define ASN1_OCTET_STRING ASN1_STRING
228#define ASN1_PRINTABLESTRING ASN1_STRING
229#define ASN1_T61STRING ASN1_STRING
230#define ASN1_IA5STRING ASN1_STRING
231#define ASN1_UTCTIME ASN1_STRING
232#define ASN1_GENERALIZEDTIME ASN1_STRING
233#define ASN1_TIME ASN1_STRING
234#define ASN1_GENERALSTRING ASN1_STRING
235#define ASN1_UNIVERSALSTRING ASN1_STRING
236#define ASN1_BMPSTRING ASN1_STRING
237#define ASN1_VISIBLESTRING ASN1_STRING
238#define ASN1_UTF8STRING ASN1_STRING
239#define ASN1_BOOLEAN int
240#else
241typedef struct asn1_string_st ASN1_INTEGER;
242typedef struct asn1_string_st ASN1_ENUMERATED;
243typedef struct asn1_string_st ASN1_BIT_STRING;
244typedef struct asn1_string_st ASN1_OCTET_STRING;
245typedef struct asn1_string_st ASN1_PRINTABLESTRING;
246typedef struct asn1_string_st ASN1_T61STRING;
247typedef struct asn1_string_st ASN1_IA5STRING;
248typedef struct asn1_string_st ASN1_GENERALSTRING;
249typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
250typedef struct asn1_string_st ASN1_BMPSTRING;
251typedef struct asn1_string_st ASN1_UTCTIME;
252typedef struct asn1_string_st ASN1_TIME;
253typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
254typedef struct asn1_string_st ASN1_VISIBLESTRING;
255typedef struct asn1_string_st ASN1_UTF8STRING;
256typedef int ASN1_BOOLEAN;
257#endif
258
259typedef int ASN1_NULL;
260
261/* Parameters used by ASN1_STRING_print_ex() */
262
263/* These determine which characters to escape:
264 * RFC2253 special characters, control characters and
265 * MSB set characters
266 */
267
268#define ASN1_STRFLGS_ESC_2253 1
269#define ASN1_STRFLGS_ESC_CTRL 2
270#define ASN1_STRFLGS_ESC_MSB 4
271
272
273/* This flag determines how we do escaping: normally
274 * RC2253 backslash only, set this to use backslash and
275 * quote.
276 */
277
278#define ASN1_STRFLGS_ESC_QUOTE 8
279
280
281/* These three flags are internal use only. */
282
283/* Character is a valid PrintableString character */
284#define CHARTYPE_PRINTABLESTRING 0x10
285/* Character needs escaping if it is the first character */
286#define CHARTYPE_FIRST_ESC_2253 0x20
287/* Character needs escaping if it is the last character */
288#define CHARTYPE_LAST_ESC_2253 0x40
289
290/* NB the internal flags are safely reused below by flags
291 * handled at the top level.
292 */
293
294/* If this is set we convert all character strings
295 * to UTF8 first
296 */
297
298#define ASN1_STRFLGS_UTF8_CONVERT 0x10
299
300/* If this is set we don't attempt to interpret content:
301 * just assume all strings are 1 byte per character. This
302 * will produce some pretty odd looking output!
303 */
304
305#define ASN1_STRFLGS_IGNORE_TYPE 0x20
306
307/* If this is set we include the string type in the output */
308#define ASN1_STRFLGS_SHOW_TYPE 0x40
309
310/* This determines which strings to display and which to
311 * 'dump' (hex dump of content octets or DER encoding). We can
312 * only dump non character strings or everything. If we
313 * don't dump 'unknown' they are interpreted as character
314 * strings with 1 octet per character and are subject to
315 * the usual escaping options.
316 */
317
318#define ASN1_STRFLGS_DUMP_ALL 0x80
319#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
320
321/* These determine what 'dumping' does, we can dump the
322 * content octets or the DER encoding: both use the
323 * RFC2253 #XXXXX notation.
324 */
325
326#define ASN1_STRFLGS_DUMP_DER 0x200
327
328/* All the string flags consistent with RFC2253,
329 * escaping control characters isn't essential in
330 * RFC2253 but it is advisable anyway.
331 */
332
333#define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
334 ASN1_STRFLGS_ESC_CTRL | \
335 ASN1_STRFLGS_ESC_MSB | \
336 ASN1_STRFLGS_UTF8_CONVERT | \
337 ASN1_STRFLGS_DUMP_UNKNOWN | \
338 ASN1_STRFLGS_DUMP_DER)
339
340DECLARE_STACK_OF(ASN1_INTEGER)
341DECLARE_ASN1_SET_OF(ASN1_INTEGER)
342
343typedef struct asn1_type_st
344 {
345 int type;
346 union {
347 char *ptr;
348 ASN1_BOOLEAN boolean;
349 ASN1_STRING * asn1_string;
350 ASN1_OBJECT * object;
351 ASN1_INTEGER * integer;
352 ASN1_ENUMERATED * enumerated;
353 ASN1_BIT_STRING * bit_string;
354 ASN1_OCTET_STRING * octet_string;
355 ASN1_PRINTABLESTRING * printablestring;
356 ASN1_T61STRING * t61string;
357 ASN1_IA5STRING * ia5string;
358 ASN1_GENERALSTRING * generalstring;
359 ASN1_BMPSTRING * bmpstring;
360 ASN1_UNIVERSALSTRING * universalstring;
361 ASN1_UTCTIME * utctime;
362 ASN1_GENERALIZEDTIME * generalizedtime;
363 ASN1_VISIBLESTRING * visiblestring;
364 ASN1_UTF8STRING * utf8string;
365 /* set and sequence are left complete and still
366 * contain the set or sequence bytes */
367 ASN1_STRING * set;
368 ASN1_STRING * sequence;
369 } value;
370 } ASN1_TYPE;
371
372DECLARE_STACK_OF(ASN1_TYPE)
373DECLARE_ASN1_SET_OF(ASN1_TYPE)
374
375typedef struct asn1_method_st
376 {
377 int (*i2d)();
378 char *(*d2i)();
379 char *(*create)();
380 void (*destroy)();
381 } ASN1_METHOD;
382
383/* This is used when parsing some Netscape objects */
384typedef struct asn1_header_st
385 {
386 ASN1_OCTET_STRING *header;
387 char *data;
388 ASN1_METHOD *meth;
389 } ASN1_HEADER;
390
391/* This is used to contain a list of bit names */
392typedef struct BIT_STRING_BITNAME_st {
393 int bitnum;
394 const char *lname;
395 const char *sname;
396} BIT_STRING_BITNAME;
397
398
399#define M_ASN1_STRING_length(x) ((x)->length)
400#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
401#define M_ASN1_STRING_type(x) ((x)->type)
402#define M_ASN1_STRING_data(x) ((x)->data)
403
404/* Macros for string operations */
405#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
406 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
407#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
408#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
409 ASN1_STRING_dup((ASN1_STRING *)a)
410#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
411 (ASN1_STRING *)a,(ASN1_STRING *)b)
412#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
413
414#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
415 ASN1_STRING_type_new(V_ASN1_INTEGER)
416#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
417#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
418#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
419 (ASN1_STRING *)a,(ASN1_STRING *)b)
420
421#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
422 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
423#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
424#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
425#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
426 (ASN1_STRING *)a,(ASN1_STRING *)b)
427
428#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
429 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
430#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
431#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
432 ASN1_STRING_dup((ASN1_STRING *)a)
433#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
434 (ASN1_STRING *)a,(ASN1_STRING *)b)
435#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
436#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
437#define M_i2d_ASN1_OCTET_STRING(a,pp) \
438 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
439 V_ASN1_UNIVERSAL)
440
441#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
442#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
443#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
444 pp,a->type,V_ASN1_UNIVERSAL)
445#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
446 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
447 B_ASN1_PRINTABLESTRING| \
448 B_ASN1_T61STRING| \
449 B_ASN1_IA5STRING| \
450 B_ASN1_BIT_STRING| \
451 B_ASN1_UNIVERSALSTRING|\
452 B_ASN1_BMPSTRING|\
453 B_ASN1_UTF8STRING|\
454 B_ASN1_UNKNOWN)
455
456#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
457#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
458#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
459 pp,a->type,V_ASN1_UNIVERSAL)
460#define M_d2i_DIRECTORYSTRING(a,pp,l) \
461 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
462 B_ASN1_PRINTABLESTRING| \
463 B_ASN1_TELETEXSTRING|\
464 B_ASN1_BMPSTRING|\
465 B_ASN1_UNIVERSALSTRING|\
466 B_ASN1_UTF8STRING)
467
468#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
469#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
470#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
471 pp,a->type,V_ASN1_UNIVERSAL)
472#define M_d2i_DISPLAYTEXT(a,pp,l) \
473 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
474 B_ASN1_VISIBLESTRING| \
475 B_ASN1_BMPSTRING|\
476 B_ASN1_UTF8STRING)
477
478#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
479 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
480#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
481#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
482 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
483 V_ASN1_UNIVERSAL)
484#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
485 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
486 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
487
488#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
489 ASN1_STRING_type_new(V_ASN1_T61STRING)
490#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
491#define M_i2d_ASN1_T61STRING(a,pp) \
492 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
493 V_ASN1_UNIVERSAL)
494#define M_d2i_ASN1_T61STRING(a,pp,l) \
495 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
496 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
497
498#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
499 ASN1_STRING_type_new(V_ASN1_IA5STRING)
500#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
501#define M_ASN1_IA5STRING_dup(a) \
502 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
503#define M_i2d_ASN1_IA5STRING(a,pp) \
504 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
505 V_ASN1_UNIVERSAL)
506#define M_d2i_ASN1_IA5STRING(a,pp,l) \
507 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
508 B_ASN1_IA5STRING)
509
510#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
511 ASN1_STRING_type_new(V_ASN1_UTCTIME)
512#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
513#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
514
515#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
516 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
517#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
518#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
519 (ASN1_STRING *)a)
520
521#define M_ASN1_TIME_new() (ASN1_TIME *)\
522 ASN1_STRING_type_new(V_ASN1_UTCTIME)
523#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
524#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
525
526#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
527 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
528#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
529#define M_i2d_ASN1_GENERALSTRING(a,pp) \
530 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
531 V_ASN1_UNIVERSAL)
532#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
533 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
534 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
535
536#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
537 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
538#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
539#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
540 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
541 V_ASN1_UNIVERSAL)
542#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
543 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
544 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
545
546#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
547 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
548#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
549#define M_i2d_ASN1_BMPSTRING(a,pp) \
550 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
551 V_ASN1_UNIVERSAL)
552#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
553 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
554 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
555
556#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
557 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
558#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
559#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
560 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
561 V_ASN1_UNIVERSAL)
562#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
563 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
564 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
565
566#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
567 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
568#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
569#define M_i2d_ASN1_UTF8STRING(a,pp) \
570 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
571 V_ASN1_UNIVERSAL)
572#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
573 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
574 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
575
576 /* for the is_set parameter to i2d_ASN1_SET */
577#define IS_SEQUENCE 0
578#define IS_SET 1
579
580ASN1_TYPE * ASN1_TYPE_new(void );
581void ASN1_TYPE_free(ASN1_TYPE *a);
582int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
583ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
584int ASN1_TYPE_get(ASN1_TYPE *a);
585void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
586
587ASN1_OBJECT * ASN1_OBJECT_new(void );
588void ASN1_OBJECT_free(ASN1_OBJECT *a);
589int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
590ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
591 long length);
592ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
593 long length);
594
595DECLARE_STACK_OF(ASN1_OBJECT)
596DECLARE_ASN1_SET_OF(ASN1_OBJECT)
597
598ASN1_STRING * ASN1_STRING_new(void);
599void ASN1_STRING_free(ASN1_STRING *a);
600ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
601ASN1_STRING * ASN1_STRING_type_new(int type );
602int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
603 /* Since this is used to store all sorts of things, via macros, for now, make
604 its data void * */
605int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
606int ASN1_STRING_length(ASN1_STRING *x);
607void ASN1_STRING_length_set(ASN1_STRING *x, int n);
608int ASN1_STRING_type(ASN1_STRING *x);
609unsigned char * ASN1_STRING_data(ASN1_STRING *x);
610
611ASN1_BIT_STRING * ASN1_BIT_STRING_new(void);
612void ASN1_BIT_STRING_free(ASN1_BIT_STRING *a);
613int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
614int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
615ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
616 long length);
617ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
618 long length);
619int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
620 int length );
621int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
622int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
623
624#ifndef NO_BIO
625int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
626 BIT_STRING_BITNAME *tbl, int indent);
627#endif
628int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
629int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
630 BIT_STRING_BITNAME *tbl);
631
632int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
633int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
634
635ASN1_INTEGER * ASN1_INTEGER_new(void);
636void ASN1_INTEGER_free(ASN1_INTEGER *a);
637int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
638int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
639ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
640 long length);
641ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
642 long length);
643ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
644 long length);
645ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
646int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
647
648ASN1_ENUMERATED * ASN1_ENUMERATED_new(void);
649void ASN1_ENUMERATED_free(ASN1_ENUMERATED *a);
650int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp);
651ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
652 long length);
653
654int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
655ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
656int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
657int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
658#if 0
659time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
660#endif
661
662int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
663ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
664int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
665
666ASN1_OCTET_STRING * ASN1_OCTET_STRING_new(void);
667void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a);
668int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
669ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
670 unsigned char **pp,long length);
671ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
672int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
673int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
674
675ASN1_VISIBLESTRING * ASN1_VISIBLESTRING_new(void);
676void ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *a);
677int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp);
678ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
679 unsigned char **pp,long length);
680
681ASN1_UTF8STRING * ASN1_UTF8STRING_new(void);
682void ASN1_UTF8STRING_free(ASN1_UTF8STRING *a);
683int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
684ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
685 unsigned char **pp,long length);
686
687ASN1_NULL * ASN1_NULL_new(void);
688void ASN1_NULL_free(ASN1_NULL *a);
689int i2d_ASN1_NULL(ASN1_NULL *a,unsigned char **pp);
690ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp,long length);
691
692ASN1_BMPSTRING * ASN1_BMPSTRING_new(void);
693void ASN1_BMPSTRING_free(ASN1_BMPSTRING *a);
694int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
695ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
696 long length);
697
698
699int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
700int UTF8_putc(unsigned char *str, int len, unsigned long value);
701
702int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
703ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
704 unsigned char **pp, long l);
705
706ASN1_PRINTABLESTRING * ASN1_PRINTABLESTRING_new(void);
707void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *a);
708ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
709 unsigned char **pp, long l);
710int i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **pp);
711
712ASN1_STRING * DIRECTORYSTRING_new(void);
713void DIRECTORYSTRING_free(ASN1_STRING *a);
714int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp);
715ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
716 long length);
717
718ASN1_STRING * DISPLAYTEXT_new(void);
719void DISPLAYTEXT_free(ASN1_STRING *a);
720int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp);
721ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length);
722
723ASN1_T61STRING * ASN1_T61STRING_new(void);
724void ASN1_T61STRING_free(ASN1_IA5STRING *a);
725ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
726 unsigned char **pp, long l);
727
728ASN1_IA5STRING * ASN1_IA5STRING_new(void);
729void ASN1_IA5STRING_free(ASN1_IA5STRING *a);
730int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
731ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
732 unsigned char **pp, long l);
733
734ASN1_UTCTIME * ASN1_UTCTIME_new(void);
735void ASN1_UTCTIME_free(ASN1_UTCTIME *a);
736int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
737ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
738 long length);
739
740ASN1_GENERALIZEDTIME * ASN1_GENERALIZEDTIME_new(void);
741void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *a);
742int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp);
743ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp,
744 long length);
745
746ASN1_TIME * ASN1_TIME_new(void);
747void ASN1_TIME_free(ASN1_TIME *a);
748int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
749ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
750ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
751
752int i2d_ASN1_SET(STACK *a, unsigned char **pp,
753 int (*func)(), int ex_tag, int ex_class, int is_set);
754STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
755 char *(*func)(), void (*free_func)(void *),
756 int ex_tag, int ex_class);
757
758#ifndef NO_BIO
759int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
760int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
761int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
762int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
763int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
764int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
765int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
766#endif
767int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
768
769int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
770ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
771 char *sn, char *ln);
772
773int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
774long ASN1_INTEGER_get(ASN1_INTEGER *a);
775ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
776BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
777
778int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
779long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
780ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
781BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
782
783/* General */
784/* given a string, return the correct type, max is the maximum length */
785int ASN1_PRINTABLE_type(unsigned char *s, int max);
786
787int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
788ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
789 long length, int Ptag, int Pclass);
790/* type is one or more of the B_ASN1_ values. */
791ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
792 long length,int type);
793
794/* PARSING */
795int asn1_Finish(ASN1_CTX *c);
796
797/* SPECIALS */
798int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
799 int *pclass, long omax);
800int ASN1_check_infinite_end(unsigned char **p,long len);
801void ASN1_put_object(unsigned char **pp, int constructed, int length,
802 int tag, int xclass);
803int ASN1_object_size(int constructed, int length, int tag);
804
805/* Used to implement other functions */
806char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
807
808#ifndef NO_FP_API
809char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
810int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
811int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
812#endif
813
814int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
815
816#ifndef NO_BIO
817char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
818int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
819int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
820int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
821int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
822int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
823int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
824int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
825int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump);
826#endif
827const char *ASN1_tag2str(int tag);
828
829/* Used to load and write netscape format cert/key */
830int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
831ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
832ASN1_HEADER *ASN1_HEADER_new(void );
833void ASN1_HEADER_free(ASN1_HEADER *a);
834
835int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
836
837void ERR_load_ASN1_strings(void);
838
839/* Not used that much at this point, except for the first two */
840ASN1_METHOD *X509_asn1_meth(void);
841ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
842ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
843ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
844
845int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
846 unsigned char *data, int len);
847int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
848 unsigned char *data, int max_len);
849int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
850 unsigned char *data, int len);
851int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
852 unsigned char *data, int max_len);
853
854STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
855 void (*free_func)(void *) );
856unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
857 int *len );
858void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
859ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
860
861void ASN1_STRING_set_default_mask(unsigned long mask);
862int ASN1_STRING_set_default_mask_asc(char *p);
863unsigned long ASN1_STRING_get_default_mask(void);
864int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
865 int inform, unsigned long mask);
866int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
867 int inform, unsigned long mask,
868 long minsize, long maxsize);
869
870ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
871 const unsigned char *in, int inlen, int inform, int nid);
872ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
873int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
874void ASN1_STRING_TABLE_cleanup(void);
875
876/* BEGIN ERROR CODES */
877/* The following lines are auto generated by the script mkerr.pl. Any changes
878 * made after this point may be overwritten when the script is next run.
879 */
880
881/* Error codes for the ASN1 functions. */
882
883/* Function codes. */
884#define ASN1_F_A2D_ASN1_OBJECT 100
885#define ASN1_F_A2I_ASN1_ENUMERATED 236
886#define ASN1_F_A2I_ASN1_INTEGER 101
887#define ASN1_F_A2I_ASN1_STRING 102
888#define ASN1_F_ACCESS_DESCRIPTION_NEW 291
889#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103
890#define ASN1_F_ASN1_D2I_BIO 104
891#define ASN1_F_ASN1_D2I_FP 105
892#define ASN1_F_ASN1_DUP 106
893#define ASN1_F_ASN1_ENUMERATED_SET 232
894#define ASN1_F_ASN1_ENUMERATED_TO_BN 233
895#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222
896#define ASN1_F_ASN1_GET_OBJECT 107
897#define ASN1_F_ASN1_HEADER_NEW 108
898#define ASN1_F_ASN1_I2D_BIO 109
899#define ASN1_F_ASN1_I2D_FP 110
900#define ASN1_F_ASN1_INTEGER_SET 111
901#define ASN1_F_ASN1_INTEGER_TO_BN 112
902#define ASN1_F_ASN1_MBSTRING_COPY 282
903#define ASN1_F_ASN1_OBJECT_NEW 113
904#define ASN1_F_ASN1_PACK_STRING 245
905#define ASN1_F_ASN1_PBE_SET 253
906#define ASN1_F_ASN1_SEQ_PACK 246
907#define ASN1_F_ASN1_SEQ_UNPACK 247
908#define ASN1_F_ASN1_SIGN 114
909#define ASN1_F_ASN1_STRING_NEW 115
910#define ASN1_F_ASN1_STRING_TABLE_ADD 283
911#define ASN1_F_ASN1_STRING_TYPE_NEW 116
912#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
913#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
914#define ASN1_F_ASN1_TYPE_NEW 119
915#define ASN1_F_ASN1_UNPACK_STRING 248
916#define ASN1_F_ASN1_UTCTIME_NEW 120
917#define ASN1_F_ASN1_VERIFY 121
918#define ASN1_F_AUTHORITY_KEYID_NEW 237
919#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
920#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
921#define ASN1_F_BN_TO_ASN1_INTEGER 122
922#define ASN1_F_D2I_ACCESS_DESCRIPTION 284
923#define ASN1_F_D2I_ASN1_BIT_STRING 123
924#define ASN1_F_D2I_ASN1_BMPSTRING 124
925#define ASN1_F_D2I_ASN1_BOOLEAN 125
926#define ASN1_F_D2I_ASN1_BYTES 126
927#define ASN1_F_D2I_ASN1_ENUMERATED 235
928#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
929#define ASN1_F_D2I_ASN1_HEADER 127
930#define ASN1_F_D2I_ASN1_INTEGER 128
931#define ASN1_F_D2I_ASN1_NULL 292
932#define ASN1_F_D2I_ASN1_OBJECT 129
933#define ASN1_F_D2I_ASN1_OCTET_STRING 130
934#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
935#define ASN1_F_D2I_ASN1_SET 132
936#define ASN1_F_D2I_ASN1_TIME 224
937#define ASN1_F_D2I_ASN1_TYPE 133
938#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
939#define ASN1_F_D2I_ASN1_UINTEGER 280
940#define ASN1_F_D2I_ASN1_UTCTIME 135
941#define ASN1_F_D2I_ASN1_UTF8STRING 266
942#define ASN1_F_D2I_ASN1_VISIBLESTRING 267
943#define ASN1_F_D2I_AUTHORITY_KEYID 238
944#define ASN1_F_D2I_BASIC_CONSTRAINTS 227
945#define ASN1_F_D2I_DHPARAMS 136
946#define ASN1_F_D2I_DIST_POINT 276
947#define ASN1_F_D2I_DIST_POINT_NAME 277
948#define ASN1_F_D2I_DSAPARAMS 137
949#define ASN1_F_D2I_DSAPRIVATEKEY 138
950#define ASN1_F_D2I_DSAPUBLICKEY 139
951#define ASN1_F_D2I_GENERAL_NAME 230
952#define ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE 228
953#define ASN1_F_D2I_NETSCAPE_PKEY 140
954#define ASN1_F_D2I_NETSCAPE_RSA 141
955#define ASN1_F_D2I_NETSCAPE_RSA_2 142
956#define ASN1_F_D2I_NETSCAPE_SPKAC 143
957#define ASN1_F_D2I_NETSCAPE_SPKI 144
958#define ASN1_F_D2I_NOTICEREF 268
959#define ASN1_F_D2I_OTHERNAME 287
960#define ASN1_F_D2I_PBE2PARAM 262
961#define ASN1_F_D2I_PBEPARAM 249
962#define ASN1_F_D2I_PBKDF2PARAM 263
963#define ASN1_F_D2I_PKCS12 254
964#define ASN1_F_D2I_PKCS12_BAGS 255
965#define ASN1_F_D2I_PKCS12_MAC_DATA 256
966#define ASN1_F_D2I_PKCS12_SAFEBAG 257
967#define ASN1_F_D2I_PKCS7 145
968#define ASN1_F_D2I_PKCS7_DIGEST 146
969#define ASN1_F_D2I_PKCS7_ENCRYPT 147
970#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148
971#define ASN1_F_D2I_PKCS7_ENVELOPE 149
972#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150
973#define ASN1_F_D2I_PKCS7_RECIP_INFO 151
974#define ASN1_F_D2I_PKCS7_SIGNED 152
975#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153
976#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154
977#define ASN1_F_D2I_PKCS8_PRIV_KEY_INFO 250
978#define ASN1_F_D2I_PKEY_USAGE_PERIOD 239
979#define ASN1_F_D2I_POLICYINFO 269
980#define ASN1_F_D2I_POLICYQUALINFO 270
981#define ASN1_F_D2I_PRIVATEKEY 155
982#define ASN1_F_D2I_PUBLICKEY 156
983#define ASN1_F_D2I_RSAPRIVATEKEY 157
984#define ASN1_F_D2I_RSAPUBLICKEY 158
985#define ASN1_F_D2I_SXNET 241
986#define ASN1_F_D2I_SXNETID 243
987#define ASN1_F_D2I_USERNOTICE 271
988#define ASN1_F_D2I_X509 159
989#define ASN1_F_D2I_X509_ALGOR 160
990#define ASN1_F_D2I_X509_ATTRIBUTE 161
991#define ASN1_F_D2I_X509_CERT_AUX 285
992#define ASN1_F_D2I_X509_CINF 162
993#define ASN1_F_D2I_X509_CRL 163
994#define ASN1_F_D2I_X509_CRL_INFO 164
995#define ASN1_F_D2I_X509_EXTENSION 165
996#define ASN1_F_D2I_X509_KEY 166
997#define ASN1_F_D2I_X509_NAME 167
998#define ASN1_F_D2I_X509_NAME_ENTRY 168
999#define ASN1_F_D2I_X509_PKEY 169
1000#define ASN1_F_D2I_X509_PUBKEY 170
1001#define ASN1_F_D2I_X509_REQ 171
1002#define ASN1_F_D2I_X509_REQ_INFO 172
1003#define ASN1_F_D2I_X509_REVOKED 173
1004#define ASN1_F_D2I_X509_SIG 174
1005#define ASN1_F_D2I_X509_VAL 175
1006#define ASN1_F_DIST_POINT_NAME_NEW 278
1007#define ASN1_F_DIST_POINT_NEW 279
1008#define ASN1_F_GENERAL_NAME_NEW 231
1009#define ASN1_F_I2D_ASN1_HEADER 176
1010#define ASN1_F_I2D_ASN1_TIME 225
1011#define ASN1_F_I2D_DHPARAMS 177
1012#define ASN1_F_I2D_DSAPARAMS 178
1013#define ASN1_F_I2D_DSAPRIVATEKEY 179
1014#define ASN1_F_I2D_DSAPUBLICKEY 180
1015#define ASN1_F_I2D_DSA_PUBKEY 290
1016#define ASN1_F_I2D_NETSCAPE_RSA 181
1017#define ASN1_F_I2D_PKCS7 182
1018#define ASN1_F_I2D_PRIVATEKEY 183
1019#define ASN1_F_I2D_PUBLICKEY 184
1020#define ASN1_F_I2D_RSAPRIVATEKEY 185
1021#define ASN1_F_I2D_RSAPUBLICKEY 186
1022#define ASN1_F_I2D_RSA_PUBKEY 289
1023#define ASN1_F_I2D_X509_ATTRIBUTE 187
1024#define ASN1_F_I2T_ASN1_OBJECT 188
1025#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229
1026#define ASN1_F_NETSCAPE_PKEY_NEW 189
1027#define ASN1_F_NETSCAPE_SPKAC_NEW 190
1028#define ASN1_F_NETSCAPE_SPKI_NEW 191
1029#define ASN1_F_NOTICEREF_NEW 272
1030#define ASN1_F_OTHERNAME_NEW 288
1031#define ASN1_F_PBE2PARAM_NEW 264
1032#define ASN1_F_PBEPARAM_NEW 251
1033#define ASN1_F_PBKDF2PARAM_NEW 265
1034#define ASN1_F_PKCS12_BAGS_NEW 258
1035#define ASN1_F_PKCS12_MAC_DATA_NEW 259
1036#define ASN1_F_PKCS12_NEW 260
1037#define ASN1_F_PKCS12_SAFEBAG_NEW 261
1038#define ASN1_F_PKCS5_PBE2_SET 281
1039#define ASN1_F_PKCS7_DIGEST_NEW 192
1040#define ASN1_F_PKCS7_ENCRYPT_NEW 193
1041#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194
1042#define ASN1_F_PKCS7_ENVELOPE_NEW 195
1043#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196
1044#define ASN1_F_PKCS7_NEW 197
1045#define ASN1_F_PKCS7_RECIP_INFO_NEW 198
1046#define ASN1_F_PKCS7_SIGNED_NEW 199
1047#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200
1048#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201
1049#define ASN1_F_PKCS8_PRIV_KEY_INFO_NEW 252
1050#define ASN1_F_PKEY_USAGE_PERIOD_NEW 240
1051#define ASN1_F_POLICYINFO_NEW 273
1052#define ASN1_F_POLICYQUALINFO_NEW 274
1053#define ASN1_F_SXNETID_NEW 244
1054#define ASN1_F_SXNET_NEW 242
1055#define ASN1_F_USERNOTICE_NEW 275
1056#define ASN1_F_X509_ALGOR_NEW 202
1057#define ASN1_F_X509_ATTRIBUTE_NEW 203
1058#define ASN1_F_X509_CERT_AUX_NEW 286
1059#define ASN1_F_X509_CINF_NEW 204
1060#define ASN1_F_X509_CRL_INFO_NEW 205
1061#define ASN1_F_X509_CRL_NEW 206
1062#define ASN1_F_X509_DHPARAMS_NEW 207
1063#define ASN1_F_X509_EXTENSION_NEW 208
1064#define ASN1_F_X509_INFO_NEW 209
1065#define ASN1_F_X509_KEY_NEW 210
1066#define ASN1_F_X509_NAME_ENTRY_NEW 211
1067#define ASN1_F_X509_NAME_NEW 212
1068#define ASN1_F_X509_NEW 213
1069#define ASN1_F_X509_PKEY_NEW 214
1070#define ASN1_F_X509_PUBKEY_NEW 215
1071#define ASN1_F_X509_REQ_INFO_NEW 216
1072#define ASN1_F_X509_REQ_NEW 217
1073#define ASN1_F_X509_REVOKED_NEW 218
1074#define ASN1_F_X509_SIG_NEW 219
1075#define ASN1_F_X509_VAL_FREE 220
1076#define ASN1_F_X509_VAL_NEW 221
1077
1078/* Reason codes. */
1079#define ASN1_R_BAD_CLASS 100
1080#define ASN1_R_BAD_OBJECT_HEADER 101
1081#define ASN1_R_BAD_PASSWORD_READ 102
1082#define ASN1_R_BAD_PKCS7_CONTENT 103
1083#define ASN1_R_BAD_PKCS7_TYPE 104
1084#define ASN1_R_BAD_TAG 105
1085#define ASN1_R_BAD_TYPE 106
1086#define ASN1_R_BN_LIB 107
1087#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108
1088#define ASN1_R_BUFFER_TOO_SMALL 109
1089#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 166
1090#define ASN1_R_DATA_IS_WRONG 110
1091#define ASN1_R_DECODE_ERROR 155
1092#define ASN1_R_DECODING_ERROR 111
1093#define ASN1_R_ENCODE_ERROR 156
1094#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112
1095#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 157
1096#define ASN1_R_EXPECTING_AN_ENUMERATED 154
1097#define ASN1_R_EXPECTING_AN_INTEGER 113
1098#define ASN1_R_EXPECTING_AN_OBJECT 114
1099#define ASN1_R_EXPECTING_AN_OCTET_STRING 115
1100#define ASN1_R_EXPECTING_A_BIT_STRING 116
1101#define ASN1_R_EXPECTING_A_BOOLEAN 117
1102#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151
1103#define ASN1_R_EXPECTING_A_NULL 164
1104#define ASN1_R_EXPECTING_A_TIME 152
1105#define ASN1_R_EXPECTING_A_UTCTIME 118
1106#define ASN1_R_FIRST_NUM_TOO_LARGE 119
1107#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153
1108#define ASN1_R_HEADER_TOO_LONG 120
1109#define ASN1_R_ILLEGAL_CHARACTERS 158
1110#define ASN1_R_INVALID_BMPSTRING_LENGTH 159
1111#define ASN1_R_INVALID_DIGIT 121
1112#define ASN1_R_INVALID_SEPARATOR 122
1113#define ASN1_R_INVALID_TIME_FORMAT 123
1114#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 160
1115#define ASN1_R_INVALID_UTF8STRING 161
1116#define ASN1_R_IV_TOO_LARGE 124
1117#define ASN1_R_LENGTH_ERROR 125
1118#define ASN1_R_MISSING_SECOND_NUMBER 126
1119#define ASN1_R_NON_HEX_CHARACTERS 127
1120#define ASN1_R_NOT_ENOUGH_DATA 128
1121#define ASN1_R_NULL_IS_WRONG_LENGTH 165
1122#define ASN1_R_ODD_NUMBER_OF_CHARS 129
1123#define ASN1_R_PARSING 130
1124#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131
1125#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132
1126#define ASN1_R_SHORT_LINE 133
1127#define ASN1_R_STRING_TOO_LONG 163
1128#define ASN1_R_STRING_TOO_SHORT 134
1129#define ASN1_R_TAG_VALUE_TOO_HIGH 135
1130#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136
1131#define ASN1_R_TOO_LONG 137
1132#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138
1133#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139
1134#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140
1135#define ASN1_R_UNKNOWN_FORMAT 162
1136#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141
1137#define ASN1_R_UNKNOWN_OBJECT_TYPE 142
1138#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143
1139#define ASN1_R_UNSUPPORTED_CIPHER 144
1140#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145
1141#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146
1142#define ASN1_R_UTCTIME_TOO_LONG 147
1143#define ASN1_R_WRONG_PRINTABLE_TYPE 148
1144#define ASN1_R_WRONG_TAG 149
1145#define ASN1_R_WRONG_TYPE 150
1146
1147#ifdef __cplusplus
1148}
1149#endif
1150#endif
1151
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
deleted file mode 100644
index cecd555c88..0000000000
--- a/src/lib/libcrypto/asn1/asn1_err.c
+++ /dev/null
@@ -1,352 +0,0 @@
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 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_ACCESS_DESCRIPTION_NEW,0), "ACCESS_DESCRIPTION_new"},
74{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
75{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
76{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
77{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
78{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
79{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
80{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_new"},
81{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
82{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
83{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
84{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"},
85{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
86{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
87{ERR_PACK(0,ASN1_F_ASN1_MBSTRING_COPY,0), "ASN1_mbstring_copy"},
88{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
89{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"},
90{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"},
91{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"},
92{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
93{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
94{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"},
95{ERR_PACK(0,ASN1_F_ASN1_STRING_TABLE_ADD,0), "ASN1_STRING_TABLE_add"},
96{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
97{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
98{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
99{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"},
100{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
101{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_new"},
102{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
103{ERR_PACK(0,ASN1_F_AUTHORITY_KEYID_NEW,0), "AUTHORITY_KEYID_new"},
104{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_new"},
105{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
106{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
107{ERR_PACK(0,ASN1_F_D2I_ACCESS_DESCRIPTION,0), "d2i_ACCESS_DESCRIPTION"},
108{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"},
109{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"},
110{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
111{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
112{ERR_PACK(0,ASN1_F_D2I_ASN1_ENUMERATED,0), "d2i_ASN1_ENUMERATED"},
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_NULL,0), "d2i_ASN1_NULL"},
117{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
118{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"},
119{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"},
120{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"},
121{ERR_PACK(0,ASN1_F_D2I_ASN1_TIME,0), "d2i_ASN1_TIME"},
122{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"},
123{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
124{ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"},
125{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"},
126{ERR_PACK(0,ASN1_F_D2I_ASN1_UTF8STRING,0), "d2i_ASN1_UTF8STRING"},
127{ERR_PACK(0,ASN1_F_D2I_ASN1_VISIBLESTRING,0), "d2i_ASN1_VISIBLESTRING"},
128{ERR_PACK(0,ASN1_F_D2I_AUTHORITY_KEYID,0), "d2i_AUTHORITY_KEYID"},
129{ERR_PACK(0,ASN1_F_D2I_BASIC_CONSTRAINTS,0), "d2i_BASIC_CONSTRAINTS"},
130{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "d2i_DHparams"},
131{ERR_PACK(0,ASN1_F_D2I_DIST_POINT,0), "d2i_DIST_POINT"},
132{ERR_PACK(0,ASN1_F_D2I_DIST_POINT_NAME,0), "d2i_DIST_POINT_NAME"},
133{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "d2i_DSAparams"},
134{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "d2i_DSAPrivateKey"},
135{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "d2i_DSAPublicKey"},
136{ERR_PACK(0,ASN1_F_D2I_GENERAL_NAME,0), "d2i_GENERAL_NAME"},
137{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE,0), "d2i_NETSCAPE_CERT_SEQUENCE"},
138{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"},
139{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"},
140{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "d2i_Netscape_RSA_2"},
141{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"},
142{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"},
143{ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"},
144{ERR_PACK(0,ASN1_F_D2I_OTHERNAME,0), "d2i_OTHERNAME"},
145{ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"},
146{ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"},
147{ERR_PACK(0,ASN1_F_D2I_PBKDF2PARAM,0), "d2i_PBKDF2PARAM"},
148{ERR_PACK(0,ASN1_F_D2I_PKCS12,0), "d2i_PKCS12"},
149{ERR_PACK(0,ASN1_F_D2I_PKCS12_BAGS,0), "d2i_PKCS12_BAGS"},
150{ERR_PACK(0,ASN1_F_D2I_PKCS12_MAC_DATA,0), "d2i_PKCS12_MAC_DATA"},
151{ERR_PACK(0,ASN1_F_D2I_PKCS12_SAFEBAG,0), "d2i_PKCS12_SAFEBAG"},
152{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "d2i_PKCS7"},
153{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "d2i_PKCS7_DIGEST"},
154{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "d2i_PKCS7_ENCRYPT"},
155{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "d2i_PKCS7_ENC_CONTENT"},
156{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "d2i_PKCS7_ENVELOPE"},
157{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "d2i_PKCS7_ISSUER_AND_SERIAL"},
158{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "d2i_PKCS7_RECIP_INFO"},
159{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "d2i_PKCS7_SIGNED"},
160{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "d2i_PKCS7_SIGNER_INFO"},
161{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "d2i_PKCS7_SIGN_ENVELOPE"},
162{ERR_PACK(0,ASN1_F_D2I_PKCS8_PRIV_KEY_INFO,0), "d2i_PKCS8_PRIV_KEY_INFO"},
163{ERR_PACK(0,ASN1_F_D2I_PKEY_USAGE_PERIOD,0), "d2i_PKEY_USAGE_PERIOD"},
164{ERR_PACK(0,ASN1_F_D2I_POLICYINFO,0), "d2i_POLICYINFO"},
165{ERR_PACK(0,ASN1_F_D2I_POLICYQUALINFO,0), "d2i_POLICYQUALINFO"},
166{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"},
167{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"},
168{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "d2i_RSAPrivateKey"},
169{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "d2i_RSAPublicKey"},
170{ERR_PACK(0,ASN1_F_D2I_SXNET,0), "d2i_SXNET"},
171{ERR_PACK(0,ASN1_F_D2I_SXNETID,0), "d2i_SXNETID"},
172{ERR_PACK(0,ASN1_F_D2I_USERNOTICE,0), "d2i_USERNOTICE"},
173{ERR_PACK(0,ASN1_F_D2I_X509,0), "d2i_X509"},
174{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "d2i_X509_ALGOR"},
175{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "d2i_X509_ATTRIBUTE"},
176{ERR_PACK(0,ASN1_F_D2I_X509_CERT_AUX,0), "d2i_X509_CERT_AUX"},
177{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "d2i_X509_CINF"},
178{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "d2i_X509_CRL"},
179{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "d2i_X509_CRL_INFO"},
180{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "d2i_X509_EXTENSION"},
181{ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"},
182{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "d2i_X509_NAME"},
183{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "d2i_X509_NAME_ENTRY"},
184{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"},
185{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "d2i_X509_PUBKEY"},
186{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "d2i_X509_REQ"},
187{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "d2i_X509_REQ_INFO"},
188{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "d2i_X509_REVOKED"},
189{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "d2i_X509_SIG"},
190{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "d2i_X509_VAL"},
191{ERR_PACK(0,ASN1_F_DIST_POINT_NAME_NEW,0), "DIST_POINT_NAME_new"},
192{ERR_PACK(0,ASN1_F_DIST_POINT_NEW,0), "DIST_POINT_new"},
193{ERR_PACK(0,ASN1_F_GENERAL_NAME_NEW,0), "GENERAL_NAME_new"},
194{ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"},
195{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "i2d_ASN1_TIME"},
196{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "i2d_DHparams"},
197{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "i2d_DSAparams"},
198{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "i2d_DSAPrivateKey"},
199{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "i2d_DSAPublicKey"},
200{ERR_PACK(0,ASN1_F_I2D_DSA_PUBKEY,0), "i2d_DSA_PUBKEY"},
201{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
202{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "i2d_PKCS7"},
203{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
204{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
205{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "i2d_RSAPrivateKey"},
206{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "i2d_RSAPublicKey"},
207{ERR_PACK(0,ASN1_F_I2D_RSA_PUBKEY,0), "i2d_RSA_PUBKEY"},
208{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "i2d_X509_ATTRIBUTE"},
209{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"},
210{ERR_PACK(0,ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW,0), "NETSCAPE_CERT_SEQUENCE_new"},
211{ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"},
212{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"},
213{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"},
214{ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"},
215{ERR_PACK(0,ASN1_F_OTHERNAME_NEW,0), "OTHERNAME_new"},
216{ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"},
217{ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"},
218{ERR_PACK(0,ASN1_F_PBKDF2PARAM_NEW,0), "PBKDF2PARAM_new"},
219{ERR_PACK(0,ASN1_F_PKCS12_BAGS_NEW,0), "PKCS12_BAGS_new"},
220{ERR_PACK(0,ASN1_F_PKCS12_MAC_DATA_NEW,0), "PKCS12_MAC_DATA_new"},
221{ERR_PACK(0,ASN1_F_PKCS12_NEW,0), "PKCS12_new"},
222{ERR_PACK(0,ASN1_F_PKCS12_SAFEBAG_NEW,0), "PKCS12_SAFEBAG_new"},
223{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"},
224{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_new"},
225{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_new"},
226{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_new"},
227{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_new"},
228{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_new"},
229{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_new"},
230{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_new"},
231{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_new"},
232{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_new"},
233{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_new"},
234{ERR_PACK(0,ASN1_F_PKCS8_PRIV_KEY_INFO_NEW,0), "PKCS8_PRIV_KEY_INFO_new"},
235{ERR_PACK(0,ASN1_F_PKEY_USAGE_PERIOD_NEW,0), "PKEY_USAGE_PERIOD_new"},
236{ERR_PACK(0,ASN1_F_POLICYINFO_NEW,0), "POLICYINFO_new"},
237{ERR_PACK(0,ASN1_F_POLICYQUALINFO_NEW,0), "POLICYQUALINFO_new"},
238{ERR_PACK(0,ASN1_F_SXNETID_NEW,0), "SXNETID_new"},
239{ERR_PACK(0,ASN1_F_SXNET_NEW,0), "SXNET_new"},
240{ERR_PACK(0,ASN1_F_USERNOTICE_NEW,0), "USERNOTICE_new"},
241{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_new"},
242{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_new"},
243{ERR_PACK(0,ASN1_F_X509_CERT_AUX_NEW,0), "X509_CERT_AUX_new"},
244{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_new"},
245{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_new"},
246{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_new"},
247{ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"},
248{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_new"},
249{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"},
250{ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"},
251{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_new"},
252{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_new"},
253{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_new"},
254{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"},
255{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_new"},
256{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_new"},
257{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_new"},
258{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_new"},
259{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_new"},
260{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_free"},
261{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_new"},
262{0,NULL}
263 };
264
265static ERR_STRING_DATA ASN1_str_reasons[]=
266 {
267{ASN1_R_BAD_CLASS ,"bad class"},
268{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"},
269{ASN1_R_BAD_PASSWORD_READ ,"bad password read"},
270{ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"},
271{ASN1_R_BAD_PKCS7_TYPE ,"bad pkcs7 type"},
272{ASN1_R_BAD_TAG ,"bad tag"},
273{ASN1_R_BAD_TYPE ,"bad type"},
274{ASN1_R_BN_LIB ,"bn lib"},
275{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
276{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
277{ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
278{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
279{ASN1_R_DECODE_ERROR ,"decode error"},
280{ASN1_R_DECODING_ERROR ,"decoding error"},
281{ASN1_R_ENCODE_ERROR ,"encode error"},
282{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
283{ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"},
284{ASN1_R_EXPECTING_AN_ENUMERATED ,"expecting an enumerated"},
285{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
286{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
287{ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"},
288{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"},
289{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
290{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"},
291{ASN1_R_EXPECTING_A_NULL ,"expecting a null"},
292{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
293{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"},
294{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
295{ASN1_R_GENERALIZEDTIME_TOO_LONG ,"generalizedtime too long"},
296{ASN1_R_HEADER_TOO_LONG ,"header too long"},
297{ASN1_R_ILLEGAL_CHARACTERS ,"illegal characters"},
298{ASN1_R_INVALID_BMPSTRING_LENGTH ,"invalid bmpstring length"},
299{ASN1_R_INVALID_DIGIT ,"invalid digit"},
300{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
301{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
302{ASN1_R_INVALID_UNIVERSALSTRING_LENGTH ,"invalid universalstring length"},
303{ASN1_R_INVALID_UTF8STRING ,"invalid utf8string"},
304{ASN1_R_IV_TOO_LARGE ,"iv too large"},
305{ASN1_R_LENGTH_ERROR ,"length error"},
306{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
307{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
308{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
309{ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"},
310{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
311{ASN1_R_PARSING ,"parsing"},
312{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
313{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
314{ASN1_R_SHORT_LINE ,"short line"},
315{ASN1_R_STRING_TOO_LONG ,"string too long"},
316{ASN1_R_STRING_TOO_SHORT ,"string too short"},
317{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
318{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
319{ASN1_R_TOO_LONG ,"too long"},
320{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
321{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"},
322{ASN1_R_UNKNOWN_ATTRIBUTE_TYPE ,"unknown attribute type"},
323{ASN1_R_UNKNOWN_FORMAT ,"unknown format"},
324{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
325{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
326{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
327{ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
328{ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"},
329{ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"},
330{ASN1_R_UTCTIME_TOO_LONG ,"utctime too long"},
331{ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"},
332{ASN1_R_WRONG_TAG ,"wrong tag"},
333{ASN1_R_WRONG_TYPE ,"wrong type"},
334{0,NULL}
335 };
336
337#endif
338
339void ERR_load_ASN1_strings(void)
340 {
341 static int init=1;
342
343 if (init)
344 {
345 init=0;
346#ifndef NO_ERR
347 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs);
348 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons);
349#endif
350
351 }
352 }
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
deleted file mode 100644
index a8b651e54e..0000000000
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ /dev/null
@@ -1,427 +0,0 @@
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 "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63
64static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
65static void asn1_put_length(unsigned char **pp, int length);
66const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
67
68int ASN1_check_infinite_end(unsigned char **p, long len)
69 {
70 /* If there is 0 or 1 byte left, the length check should pick
71 * things up */
72 if (len <= 0)
73 return(1);
74 else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
75 {
76 (*p)+=2;
77 return(1);
78 }
79 return(0);
80 }
81
82
83int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
84 long omax)
85 {
86 int i,ret;
87 long l;
88 unsigned char *p= *pp;
89 int tag,xclass,inf;
90 long max=omax;
91
92 if (!max) goto err;
93 ret=(*p&V_ASN1_CONSTRUCTED);
94 xclass=(*p&V_ASN1_PRIVATE);
95 i= *p&V_ASN1_PRIMITIVE_TAG;
96 if (i == V_ASN1_PRIMITIVE_TAG)
97 { /* high-tag */
98 p++;
99 if (--max == 0) goto err;
100 l=0;
101 while (*p&0x80)
102 {
103 l<<=7L;
104 l|= *(p++)&0x7f;
105 if (--max == 0) goto err;
106 }
107 l<<=7L;
108 l|= *(p++)&0x7f;
109 tag=(int)l;
110 }
111 else
112 {
113 tag=i;
114 p++;
115 if (--max == 0) goto err;
116 }
117 *ptag=tag;
118 *pclass=xclass;
119 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
120
121#if 0
122 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
123 (int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
124 (int)(omax+ *pp));
125
126#endif
127#if 0
128 if ((p+ *plength) > (omax+ *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#endif
136 *pp=p;
137 return(ret|inf);
138err:
139 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
140 return(0x80);
141 }
142
143static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
144 {
145 unsigned char *p= *pp;
146 long ret=0;
147 int i;
148
149 if (max-- < 1) return(0);
150 if (*p == 0x80)
151 {
152 *inf=1;
153 ret=0;
154 p++;
155 }
156 else
157 {
158 *inf=0;
159 i= *p&0x7f;
160 if (*(p++) & 0x80)
161 {
162 if (max-- == 0) return(0);
163 while (i-- > 0)
164 {
165 ret<<=8L;
166 ret|= *(p++);
167 if (max-- == 0) return(0);
168 }
169 }
170 else
171 ret=i;
172 }
173 *pp=p;
174 *rl=ret;
175 return(1);
176 }
177
178/* class 0 is constructed
179 * constructed == 2 for indefinite length constructed */
180void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
181 int xclass)
182 {
183 unsigned char *p= *pp;
184 int i, ttag;
185
186 i=(constructed)?V_ASN1_CONSTRUCTED:0;
187 i|=(xclass&V_ASN1_PRIVATE);
188 if (tag < 31)
189 *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
190 else
191 {
192 *(p++)=i|V_ASN1_PRIMITIVE_TAG;
193 for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
194 ttag = i;
195 while(i-- > 0)
196 {
197 p[i] = tag & 0x7f;
198 if(i != (ttag - 1)) p[i] |= 0x80;
199 tag >>= 7;
200 }
201 p += ttag;
202 }
203 if ((constructed == 2) && (length == 0))
204 *(p++)=0x80; /* der_put_length would output 0 instead */
205 else
206 asn1_put_length(&p,length);
207 *pp=p;
208 }
209
210static void asn1_put_length(unsigned char **pp, int length)
211 {
212 unsigned char *p= *pp;
213 int i,l;
214 if (length <= 127)
215 *(p++)=(unsigned char)length;
216 else
217 {
218 l=length;
219 for (i=0; l > 0; i++)
220 l>>=8;
221 *(p++)=i|0x80;
222 l=i;
223 while (i-- > 0)
224 {
225 p[i]=length&0xff;
226 length>>=8;
227 }
228 p+=l;
229 }
230 *pp=p;
231 }
232
233int ASN1_object_size(int constructed, int length, int tag)
234 {
235 int ret;
236
237 ret=length;
238 ret++;
239 if (tag >= 31)
240 {
241 while (tag > 0)
242 {
243 tag>>=7;
244 ret++;
245 }
246 }
247 if ((length == 0) && (constructed == 2))
248 ret+=2;
249 ret++;
250 if (length > 127)
251 {
252 while (length > 0)
253 {
254 length>>=8;
255 ret++;
256 }
257 }
258 return(ret);
259 }
260
261int asn1_Finish(ASN1_CTX *c)
262 {
263 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
264 {
265 if (!ASN1_check_infinite_end(&c->p,c->slen))
266 {
267 c->error=ERR_R_MISSING_ASN1_EOS;
268 return(0);
269 }
270 }
271 if ( ((c->slen != 0) && !(c->inf & 1)) ||
272 ((c->slen < 0) && (c->inf & 1)))
273 {
274 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
275 return(0);
276 }
277 return(1);
278 }
279
280int asn1_GetSequence(ASN1_CTX *c, long *length)
281 {
282 unsigned char *q;
283
284 q=c->p;
285 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
286 *length);
287 if (c->inf & 0x80)
288 {
289 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
290 return(0);
291 }
292 if (c->tag != V_ASN1_SEQUENCE)
293 {
294 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
295 return(0);
296 }
297 (*length)-=(c->p-q);
298 if (c->max && (*length < 0))
299 {
300 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
301 return(0);
302 }
303 if (c->inf == (1|V_ASN1_CONSTRUCTED))
304 c->slen= *length;
305 c->eos=0;
306 return(1);
307 }
308
309ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
310 {
311 ASN1_STRING *ret;
312
313 if (str == NULL) return(NULL);
314 if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
315 return(NULL);
316 if (!ASN1_STRING_set(ret,str->data,str->length))
317 {
318 ASN1_STRING_free(ret);
319 return(NULL);
320 }
321 ret->flags = str->flags;
322 return(ret);
323 }
324
325int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
326 {
327 unsigned char *c;
328 const char *data=_data;
329
330 if (len < 0)
331 {
332 if (data == NULL)
333 return(0);
334 else
335 len=strlen(data);
336 }
337 if ((str->length < len) || (str->data == NULL))
338 {
339 c=str->data;
340 if (c == NULL)
341 str->data=OPENSSL_malloc(len+1);
342 else
343 str->data=OPENSSL_realloc(c,len+1);
344
345 if (str->data == NULL)
346 {
347 str->data=c;
348 return(0);
349 }
350 }
351 str->length=len;
352 if (data != NULL)
353 {
354 memcpy(str->data,data,len);
355 /* an allowance for strings :-) */
356 str->data[len]='\0';
357 }
358 return(1);
359 }
360
361ASN1_STRING *ASN1_STRING_new(void)
362 {
363 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
364 }
365
366
367ASN1_STRING *ASN1_STRING_type_new(int type)
368 {
369 ASN1_STRING *ret;
370
371 ret=(ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING));
372 if (ret == NULL)
373 {
374 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
375 return(NULL);
376 }
377 ret->length=0;
378 ret->type=type;
379 ret->data=NULL;
380 ret->flags=0;
381 return(ret);
382 }
383
384void ASN1_STRING_free(ASN1_STRING *a)
385 {
386 if (a == NULL) return;
387 if (a->data != NULL) OPENSSL_free(a->data);
388 OPENSSL_free(a);
389 }
390
391int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
392 {
393 int i;
394
395 i=(a->length-b->length);
396 if (i == 0)
397 {
398 i=memcmp(a->data,b->data,a->length);
399 if (i == 0)
400 return(a->type-b->type);
401 else
402 return(i);
403 }
404 else
405 return(i);
406 }
407
408void asn1_add_error(unsigned char *address, int offset)
409 {
410 char buf1[16],buf2[16];
411
412 sprintf(buf1,"%lu",(unsigned long)address);
413 sprintf(buf2,"%d",offset);
414 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
415 }
416
417int ASN1_STRING_length(ASN1_STRING *x)
418{ return M_ASN1_STRING_length(x); }
419
420void ASN1_STRING_length_set(ASN1_STRING *x, int len)
421{ M_ASN1_STRING_length_set(x, len); return; }
422
423int ASN1_STRING_type(ASN1_STRING *x)
424{ return M_ASN1_STRING_type(x); }
425
426unsigned char * ASN1_STRING_data(ASN1_STRING *x)
427{ return M_ASN1_STRING_data(x); }
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
deleted file mode 100644
index af0e664b2d..0000000000
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ /dev/null
@@ -1,583 +0,0 @@
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),ERR_file_name,(line))
74
75#define M_ASN1_D2I_vars(a,type,func) \
76 ASN1_CTX c; \
77 type ret=NULL; \
78 \
79 c.pp=pp; \
80 c.q= *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= *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 *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(*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_I2D_put_SEQUENCE_opt_ex_type(type,a,f) \
200 if (a) M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
201
202#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
203 if ((c.slen != 0) && \
204 (M_ASN1_next == \
205 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
206 { \
207 M_ASN1_D2I_get_imp_set(b,func,free_func,\
208 tag,V_ASN1_CONTEXT_SPECIFIC); \
209 }
210
211#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
212 if ((c.slen != 0) && \
213 (M_ASN1_next == \
214 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
215 { \
216 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
217 tag,V_ASN1_CONTEXT_SPECIFIC); \
218 }
219
220#define M_ASN1_D2I_get_seq(r,func,free_func) \
221 M_ASN1_D2I_get_imp_set(r,func,free_func,\
222 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
223
224#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
225 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
226 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
227
228#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
229 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
230 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
231 { M_ASN1_D2I_get_seq(r,func,free_func); }
232
233#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
234 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
235 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
236 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
237
238#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
239 M_ASN1_D2I_get_imp_set(r,func,free_func,\
240 x,V_ASN1_CONTEXT_SPECIFIC);
241
242#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
243 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
244 x,V_ASN1_CONTEXT_SPECIFIC);
245
246#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
247 c.q=c.p; \
248 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
249 (void (*)())free_func,a,b) == NULL) \
250 { c.line=__LINE__; goto err; } \
251 c.slen-=(c.p-c.q);
252
253#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
254 c.q=c.p; \
255 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
256 free_func,a,b) == NULL) \
257 { c.line=__LINE__; goto err; } \
258 c.slen-=(c.p-c.q);
259
260#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
261 c.q=c.p; \
262 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
263 { c.line=__LINE__; goto err; } \
264 c.slen-=(c.p-c.q);
265
266#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
267 if ((c.slen != 0L) && (M_ASN1_next == \
268 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
269 { \
270 int Tinf,Ttag,Tclass; \
271 long Tlen; \
272 \
273 c.q=c.p; \
274 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
275 if (Tinf & 0x80) \
276 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
277 c.line=__LINE__; goto err; } \
278 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
279 Tlen = c.slen - (c.p - c.q) - 2; \
280 if (func(&(r),&c.p,Tlen) == NULL) \
281 { c.line=__LINE__; goto err; } \
282 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
283 Tlen = c.slen - (c.p - c.q); \
284 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
285 { c.error=ERR_R_MISSING_ASN1_EOS; \
286 c.line=__LINE__; goto err; } \
287 }\
288 c.slen-=(c.p-c.q); \
289 }
290
291#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
292 if ((c.slen != 0) && (M_ASN1_next == \
293 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
294 { \
295 int Tinf,Ttag,Tclass; \
296 long Tlen; \
297 \
298 c.q=c.p; \
299 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
300 if (Tinf & 0x80) \
301 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
302 c.line=__LINE__; goto err; } \
303 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
304 Tlen = c.slen - (c.p - c.q) - 2; \
305 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
306 (void (*)())free_func, \
307 b,V_ASN1_UNIVERSAL) == NULL) \
308 { c.line=__LINE__; goto err; } \
309 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
310 Tlen = c.slen - (c.p - c.q); \
311 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
312 { c.error=ERR_R_MISSING_ASN1_EOS; \
313 c.line=__LINE__; goto err; } \
314 }\
315 c.slen-=(c.p-c.q); \
316 }
317
318#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
319 if ((c.slen != 0) && (M_ASN1_next == \
320 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
321 { \
322 int Tinf,Ttag,Tclass; \
323 long Tlen; \
324 \
325 c.q=c.p; \
326 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
327 if (Tinf & 0x80) \
328 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
329 c.line=__LINE__; goto err; } \
330 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
331 Tlen = c.slen - (c.p - c.q) - 2; \
332 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
333 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
334 { c.line=__LINE__; goto err; } \
335 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
336 Tlen = c.slen - (c.p - c.q); \
337 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
338 { c.error=ERR_R_MISSING_ASN1_EOS; \
339 c.line=__LINE__; goto err; } \
340 }\
341 c.slen-=(c.p-c.q); \
342 }
343
344/* New macros */
345#define M_ASN1_New_Malloc(ret,type) \
346 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
347 { c.line=__LINE__; goto err2; }
348
349#define M_ASN1_New(arg,func) \
350 if (((arg)=func()) == NULL) return(NULL)
351
352#define M_ASN1_New_Error(a) \
353/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
354 return(NULL);*/ \
355 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
356 return(NULL)
357
358
359#define M_ASN1_next (*c.p)
360#define M_ASN1_next_prev (*c.q)
361
362/*************************************************/
363
364#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
365 unsigned char *p; \
366 if (a == NULL) return(0)
367
368/* Length Macros */
369#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
370#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
371
372#define M_ASN1_I2D_len_SET(a,f) \
373 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
374
375#define M_ASN1_I2D_len_SET_type(type,a,f) \
376 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
377 V_ASN1_UNIVERSAL,IS_SET);
378
379#define M_ASN1_I2D_len_SEQUENCE(a,f) \
380 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
381 IS_SEQUENCE);
382
383#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
384 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
385 V_ASN1_UNIVERSAL,IS_SEQUENCE)
386
387#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
388 if ((a != NULL) && (sk_num(a) != 0)) \
389 M_ASN1_I2D_len_SEQUENCE(a,f);
390
391#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
392 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
393 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
394
395#define M_ASN1_I2D_len_SEQUENCE_opt_ex_type(type,a,f) \
396 if (a) M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
397
398#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
399 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
400
401#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
402 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
403 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
404
405#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
406 if ((a != NULL) && (sk_num(a) != 0)) \
407 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
408 IS_SET);
409
410#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
411 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
412 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
413 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
414
415#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
416 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
417 IS_SEQUENCE);
418
419#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
420 if ((a != NULL) && (sk_num(a) != 0)) \
421 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
422 IS_SEQUENCE);
423
424#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
425 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
426 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
427 V_ASN1_CONTEXT_SPECIFIC, \
428 IS_SEQUENCE);
429
430#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
431 if (a != NULL)\
432 { \
433 v=f(a,NULL); \
434 ret+=ASN1_object_size(1,v,mtag); \
435 }
436
437#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
438 if ((a != NULL) && (sk_num(a) != 0))\
439 { \
440 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
441 ret+=ASN1_object_size(1,v,mtag); \
442 }
443
444#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
445 if ((a != NULL) && (sk_num(a) != 0))\
446 { \
447 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
448 IS_SEQUENCE); \
449 ret+=ASN1_object_size(1,v,mtag); \
450 }
451
452#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
453 if ((a != NULL) && (sk_##type##_num(a) != 0))\
454 { \
455 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
456 V_ASN1_UNIVERSAL, \
457 IS_SEQUENCE); \
458 ret+=ASN1_object_size(1,v,mtag); \
459 }
460
461#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_ex_type(type,a,f,mtag,tag,v) \
462 if (a)\
463 { \
464 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
465 V_ASN1_UNIVERSAL, \
466 IS_SEQUENCE); \
467 ret+=ASN1_object_size(1,v,mtag); \
468 }
469
470/* Put Macros */
471#define M_ASN1_I2D_put(a,f) f(a,&p)
472
473#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
474 if (a != NULL) \
475 { \
476 unsigned char *q=p; \
477 f(a,&p); \
478 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
479 }
480
481#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
482 V_ASN1_UNIVERSAL,IS_SET)
483#define M_ASN1_I2D_put_SET_type(type,a,f) \
484 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
485#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
486 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
487#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
488 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
489#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
490 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
491
492#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
493 V_ASN1_UNIVERSAL,IS_SEQUENCE)
494
495#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
496 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
497 IS_SEQUENCE)
498
499#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
500 if ((a != NULL) && (sk_num(a) != 0)) \
501 M_ASN1_I2D_put_SEQUENCE(a,f);
502
503#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
504 if ((a != NULL) && (sk_num(a) != 0)) \
505 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
506 IS_SET); }
507
508#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
509 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
510 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
511 V_ASN1_CONTEXT_SPECIFIC, \
512 IS_SET); }
513
514#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
515 if ((a != NULL) && (sk_num(a) != 0)) \
516 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
517 IS_SEQUENCE); }
518
519#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
520 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
521 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
522 V_ASN1_CONTEXT_SPECIFIC, \
523 IS_SEQUENCE); }
524
525#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
526 if (a != NULL) \
527 { \
528 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
529 f(a,&p); \
530 }
531
532#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
533 if ((a != NULL) && (sk_num(a) != 0)) \
534 { \
535 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
536 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
537 }
538
539#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
540 if ((a != NULL) && (sk_num(a) != 0)) \
541 { \
542 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
543 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
544 }
545
546#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
547 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
548 { \
549 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
550 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
551 IS_SEQUENCE); \
552 }
553
554#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_ex_type(type,a,f,mtag,tag,v) \
555 if (a) \
556 { \
557 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
558 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
559 IS_SEQUENCE); \
560 }
561
562#define M_ASN1_I2D_seq_total() \
563 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
564 if (pp == NULL) return(r); \
565 p= *pp; \
566 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
567
568#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
569 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
570 *(p++)=0x80
571
572#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
573
574#define M_ASN1_I2D_finish() *pp=p; \
575 return(r);
576
577int asn1_GetSequence(ASN1_CTX *c, long *length);
578void asn1_add_error(unsigned char *address,int offset);
579#ifdef __cplusplus
580}
581#endif
582
583#endif
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
deleted file mode 100644
index facfdd27fc..0000000000
--- a/src/lib/libcrypto/asn1/asn1_par.c
+++ /dev/null
@@ -1,423 +0,0 @@
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 sprintf(str,"priv [ %d ] ",tag);
92 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
93 sprintf(str,"cont [ %d ]",tag);
94 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
95 sprintf(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/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
deleted file mode 100644
index bdf5f130b3..0000000000
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ /dev/null
@@ -1,145 +0,0 @@
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/* ASN1 packing and unpacking functions */
64
65/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
66
67STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
68 void (*free_func)(void *))
69{
70 STACK *sk;
71 unsigned char *pbuf;
72 pbuf = buf;
73 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
74 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
75 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
76 return sk;
77}
78
79/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
80 * OPENSSL_malloc'ed buffer
81 */
82
83unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
84 int *len)
85{
86 int safelen;
87 unsigned char *safe, *p;
88 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
89 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
90 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
91 return NULL;
92 }
93 if (!(safe = OPENSSL_malloc (safelen))) {
94 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
95 return NULL;
96 }
97 p = safe;
98 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
99 IS_SEQUENCE);
100 if (len) *len = safelen;
101 if (buf) *buf = safe;
102 return safe;
103}
104
105/* Extract an ASN1 object from an ASN1_STRING */
106
107void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
108{
109 unsigned char *p;
110 char *ret;
111
112 p = oct->data;
113 if(!(ret = d2i(NULL, &p, oct->length)))
114 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
115 return ret;
116}
117
118/* Pack an ASN1 object into an ASN1_STRING */
119
120ASN1_STRING *ASN1_pack_string (void *obj, int (*i2d)(), ASN1_STRING **oct)
121{
122 unsigned char *p;
123 ASN1_STRING *octmp;
124
125 if (!oct || !*oct) {
126 if (!(octmp = ASN1_STRING_new ())) {
127 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 if (oct) *oct = octmp;
131 } else octmp = *oct;
132
133 if (!(octmp->length = i2d(obj, NULL))) {
134 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
135 return NULL;
136 }
137 if (!(p = OPENSSL_malloc (octmp->length))) {
138 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
139 return NULL;
140 }
141 octmp->data = p;
142 i2d (obj, &p);
143 return octmp;
144}
145
diff --git a/src/lib/libcrypto/asn1/charmap.h b/src/lib/libcrypto/asn1/charmap.h
deleted file mode 100644
index bd020a9562..0000000000
--- a/src/lib/libcrypto/asn1/charmap.h
+++ /dev/null
@@ -1,15 +0,0 @@
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
deleted file mode 100644
index 2875c59867..0000000000
--- a/src/lib/libcrypto/asn1/charmap.pl
+++ /dev/null
@@ -1,80 +0,0 @@
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
deleted file mode 100644
index c92b8325d8..0000000000
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ /dev/null
@@ -1,137 +0,0 @@
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
66EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
67 long length)
68 {
69 EVP_PKEY *ret;
70
71 if ((a == NULL) || (*a == NULL))
72 {
73 if ((ret=EVP_PKEY_new()) == NULL)
74 {
75 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
76 return(NULL);
77 }
78 }
79 else ret= *a;
80
81 ret->save_type=type;
82 ret->type=EVP_PKEY_type(type);
83 switch (ret->type)
84 {
85#ifndef NO_RSA
86 case EVP_PKEY_RSA:
87 if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,pp,length)) == NULL)
88 {
89 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
90 goto err;
91 }
92 break;
93#endif
94#ifndef NO_DSA
95 case EVP_PKEY_DSA:
96 if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,pp,length)) == NULL)
97 {
98 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
99 goto err;
100 }
101 break;
102#endif
103 default:
104 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
105 goto err;
106 /* break; */
107 }
108 if (a != NULL) (*a)=ret;
109 return(ret);
110err:
111 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
112 return(NULL);
113 }
114
115/* This works like d2i_PrivateKey() except it automatically works out the type */
116
117EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
118 long length)
119{
120 STACK_OF(ASN1_TYPE) *inkey;
121 unsigned char *p;
122 int keytype;
123 p = *pp;
124 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
125 * by analyzing it we can determine the passed structure: this
126 * assumes the input is surrounded by an ASN1 SEQUENCE.
127 */
128 inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE,
129 ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
130 /* Since we only need to discern "traditional format" RSA and DSA
131 * keys we can just count the elements.
132 */
133 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
134 else keytype = EVP_PKEY_RSA;
135 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
136 return d2i_PrivateKey(keytype, a, pp, length);
137}
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c
deleted file mode 100644
index e0d203cef7..0000000000
--- a/src/lib/libcrypto/asn1/d2i_pu.c
+++ /dev/null
@@ -1,114 +0,0 @@
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
66EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
67 long length)
68 {
69 EVP_PKEY *ret;
70
71 if ((a == NULL) || (*a == NULL))
72 {
73 if ((ret=EVP_PKEY_new()) == NULL)
74 {
75 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
76 return(NULL);
77 }
78 }
79 else ret= *a;
80
81 ret->save_type=type;
82 ret->type=EVP_PKEY_type(type);
83 switch (ret->type)
84 {
85#ifndef NO_RSA
86 case EVP_PKEY_RSA:
87 if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,pp,length)) == NULL)
88 {
89 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
90 goto err;
91 }
92 break;
93#endif
94#ifndef NO_DSA
95 case EVP_PKEY_DSA:
96 if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,pp,length)) == NULL)
97 {
98 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
99 goto err;
100 }
101 break;
102#endif
103 default:
104 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
105 goto err;
106 /* break; */
107 }
108 if (a != NULL) (*a)=ret;
109 return(ret);
110err:
111 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
112 return(NULL);
113 }
114
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
deleted file mode 100644
index 3506005a71..0000000000
--- a/src/lib/libcrypto/asn1/evp_asn1.c
+++ /dev/null
@@ -1,185 +0,0 @@
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_enum.c b/src/lib/libcrypto/asn1/f_enum.c
deleted file mode 100644
index 56e3cc8df2..0000000000
--- a/src/lib/libcrypto/asn1/f_enum.c
+++ /dev/null
@@ -1,207 +0,0 @@
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
deleted file mode 100644
index 6b090f6740..0000000000
--- a/src/lib/libcrypto/asn1/f_int.c
+++ /dev/null
@@ -1,214 +0,0 @@
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->length == 0)
73 {
74 if (BIO_write(bp,"00",2) != 2) goto err;
75 n=2;
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_INTEGER(BIO *bp, ASN1_INTEGER *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 bs->type=V_ASN1_INTEGER;
106
107 bufsize=BIO_gets(bp,buf,size);
108 for (;;)
109 {
110 if (bufsize < 1) goto err_sl;
111 i=bufsize;
112 if (buf[i-1] == '\n') buf[--i]='\0';
113 if (i == 0) goto err_sl;
114 if (buf[i-1] == '\r') buf[--i]='\0';
115 if (i == 0) goto err_sl;
116 again=(buf[i-1] == '\\');
117
118 for (j=0; j<i; j++)
119 {
120#ifndef CHARSET_EBCDIC
121 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
122 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
123 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
124#else
125 /* This #ifdef is not strictly necessary, since
126 * the characters A...F a...f 0...9 are contiguous
127 * (yes, even in EBCDIC - but not the whole alphabet).
128 * Nevertheless, isxdigit() is faster.
129 */
130 if (!isxdigit(buf[j]))
131#endif
132 {
133 i=j;
134 break;
135 }
136 }
137 buf[i]='\0';
138 /* We have now cleared all the crap off the end of the
139 * line */
140 if (i < 2) goto err_sl;
141
142 bufp=(unsigned char *)buf;
143 if (first)
144 {
145 first=0;
146 if ((bufp[0] == '0') && (buf[1] == '0'))
147 {
148 bufp+=2;
149 i-=2;
150 }
151 }
152 k=0;
153 i-=again;
154 if (i%2 != 0)
155 {
156 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
157 goto err;
158 }
159 i/=2;
160 if (num+i > slen)
161 {
162 if (s == NULL)
163 sp=(unsigned char *)OPENSSL_malloc(
164 (unsigned int)num+i*2);
165 else
166 sp=(unsigned char *)OPENSSL_realloc(s,
167 (unsigned int)num+i*2);
168 if (sp == NULL)
169 {
170 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
171 if (s != NULL) OPENSSL_free(s);
172 goto err;
173 }
174 s=sp;
175 slen=num+i*2;
176 }
177 for (j=0; j<i; j++,k+=2)
178 {
179 for (n=0; n<2; n++)
180 {
181 m=bufp[k+n];
182 if ((m >= '0') && (m <= '9'))
183 m-='0';
184 else if ((m >= 'a') && (m <= 'f'))
185 m=m-'a'+10;
186 else if ((m >= 'A') && (m <= 'F'))
187 m=m-'A'+10;
188 else
189 {
190 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
191 goto err;
192 }
193 s[num+j]<<=4;
194 s[num+j]|=m;
195 }
196 }
197 num+=i;
198 if (again)
199 bufsize=BIO_gets(bp,buf,size);
200 else
201 break;
202 }
203 bs->length=num;
204 bs->data=s;
205 ret=1;
206err:
207 if (0)
208 {
209err_sl:
210 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
211 }
212 return(ret);
213 }
214
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
deleted file mode 100644
index 968698a798..0000000000
--- a/src/lib/libcrypto/asn1/f_string.c
+++ /dev/null
@@ -1,212 +0,0 @@
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
deleted file mode 100644
index 71d6910204..0000000000
--- a/src/lib/libcrypto/asn1/i2d_pr.c
+++ /dev/null
@@ -1,84 +0,0 @@
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
65int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
66 {
67#ifndef NO_RSA
68 if (a->type == EVP_PKEY_RSA)
69 {
70 return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
71 }
72 else
73#endif
74#ifndef NO_DSA
75 if (a->type == EVP_PKEY_DSA)
76 {
77 return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
78 }
79#endif
80
81 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
82 return(-1);
83 }
84
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c
deleted file mode 100644
index 8f73d37d03..0000000000
--- a/src/lib/libcrypto/asn1/i2d_pu.c
+++ /dev/null
@@ -1,82 +0,0 @@
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
65int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
66 {
67 switch (a->type)
68 {
69#ifndef NO_RSA
70 case EVP_PKEY_RSA:
71 return(i2d_RSAPublicKey(a->pkey.rsa,pp));
72#endif
73#ifndef NO_DSA
74 case EVP_PKEY_DSA:
75 return(i2d_DSAPublicKey(a->pkey.dsa,pp));
76#endif
77 default:
78 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
79 return(-1);
80 }
81 }
82
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
deleted file mode 100644
index 9840193538..0000000000
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ /dev/null
@@ -1,388 +0,0 @@
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 NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/asn1_mac.h>
65#include <openssl/evp.h>
66#include <openssl/x509.h>
67
68
69#ifndef NO_RC4
70
71typedef struct netscape_pkey_st
72 {
73 ASN1_INTEGER *version;
74 X509_ALGOR *algor;
75 ASN1_OCTET_STRING *private_key;
76 } NETSCAPE_PKEY;
77
78static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp);
79static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length);
80static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void);
81static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *);
82
83int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)())
84{
85 return i2d_RSA_NET(a, pp, cb, 0);
86}
87
88int i2d_RSA_NET(RSA *a, unsigned char **pp, int (*cb)(), int sgckey)
89 {
90 int i,j,l[6];
91 NETSCAPE_PKEY *pkey;
92 unsigned char buf[256],*zz;
93 unsigned char key[EVP_MAX_KEY_LENGTH];
94 EVP_CIPHER_CTX ctx;
95 X509_ALGOR *alg=NULL;
96 ASN1_OCTET_STRING os,os2;
97 M_ASN1_I2D_vars(a);
98
99 if (a == NULL) return(0);
100
101#ifdef WIN32
102 r=r; /* shut the damn compiler up :-) */
103#endif
104
105 os.data=os2.data=NULL;
106 if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err;
107 if (!ASN1_INTEGER_set(pkey->version,0)) goto err;
108
109 if (pkey->algor->algorithm != NULL)
110 ASN1_OBJECT_free(pkey->algor->algorithm);
111 pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption);
112 if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
113 pkey->algor->parameter->type=V_ASN1_NULL;
114
115 l[0]=i2d_RSAPrivateKey(a,NULL);
116 pkey->private_key->length=l[0];
117
118 os2.length=i2d_NETSCAPE_PKEY(pkey,NULL);
119 l[1]=i2d_ASN1_OCTET_STRING(&os2,NULL);
120
121 if ((alg=X509_ALGOR_new()) == NULL) goto err;
122 if (alg->algorithm != NULL)
123 ASN1_OBJECT_free(alg->algorithm);
124 alg->algorithm=OBJ_nid2obj(NID_rc4);
125 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
126 alg->parameter->type=V_ASN1_NULL;
127
128 l[2]=i2d_X509_ALGOR(alg,NULL);
129 l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE);
130
131#ifndef CONST_STRICT
132 os.data=(unsigned char *)"private-key";
133#endif
134 os.length=11;
135 l[4]=i2d_ASN1_OCTET_STRING(&os,NULL);
136
137 l[5]=ASN1_object_size(1,l[4]+l[3],V_ASN1_SEQUENCE);
138
139 if (pp == NULL)
140 {
141 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
142 if (alg != NULL) X509_ALGOR_free(alg);
143 return(l[5]);
144 }
145
146 if (pkey->private_key->data != NULL)
147 OPENSSL_free(pkey->private_key->data);
148 if ((pkey->private_key->data=(unsigned char *)OPENSSL_malloc(l[0])) == NULL)
149 {
150 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
151 goto err;
152 }
153 zz=pkey->private_key->data;
154 i2d_RSAPrivateKey(a,&zz);
155
156 if ((os2.data=(unsigned char *)OPENSSL_malloc(os2.length)) == NULL)
157 {
158 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
159 goto err;
160 }
161 zz=os2.data;
162 i2d_NETSCAPE_PKEY(pkey,&zz);
163
164 if (cb == NULL)
165 cb=EVP_read_pw_string;
166 i=cb(buf,256,"Enter Private Key password:",1);
167 if (i != 0)
168 {
169 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
170 goto err;
171 }
172 i = strlen((char *)buf);
173 /* If the key is used for SGC the algorithm is modified a little. */
174 if(sgckey){
175 EVP_MD_CTX mctx;
176 EVP_DigestInit(&mctx, EVP_md5());
177 EVP_DigestUpdate(&mctx, buf, i);
178 EVP_DigestFinal(&mctx, buf, NULL);
179 memcpy(buf + 16, "SGCKEYSALT", 10);
180 i = 26;
181 }
182
183 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
184 memset(buf,0,256);
185
186 EVP_CIPHER_CTX_init(&ctx);
187 EVP_EncryptInit(&ctx,EVP_rc4(),key,NULL);
188 EVP_EncryptUpdate(&ctx,os2.data,&i,os2.data,os2.length);
189 EVP_EncryptFinal(&ctx,&(os2.data[i]),&j);
190 EVP_CIPHER_CTX_cleanup(&ctx);
191
192 p= *pp;
193 ASN1_put_object(&p,1,l[4]+l[3],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
194 i2d_ASN1_OCTET_STRING(&os,&p);
195 ASN1_put_object(&p,1,l[2]+l[1],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
196 i2d_X509_ALGOR(alg,&p);
197 i2d_ASN1_OCTET_STRING(&os2,&p);
198 ret=l[5];
199err:
200 if (os2.data != NULL) OPENSSL_free(os2.data);
201 if (alg != NULL) X509_ALGOR_free(alg);
202 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
203 r=r;
204 return(ret);
205 }
206
207
208RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)())
209{
210 return d2i_RSA_NET(a, pp, length, cb, 0);
211}
212
213RSA *d2i_RSA_NET(RSA **a, unsigned char **pp, long length, int (*cb)(), int sgckey)
214 {
215 RSA *ret=NULL;
216 ASN1_OCTET_STRING *os=NULL;
217 ASN1_CTX c;
218
219 c.pp=pp;
220 c.error=ASN1_R_DECODING_ERROR;
221
222 M_ASN1_D2I_Init();
223 M_ASN1_D2I_start_sequence();
224 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
225 if ((os->length != 11) || (strncmp("private-key",
226 (char *)os->data,os->length) != 0))
227 {
228 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
229 M_ASN1_BIT_STRING_free(os);
230 goto err;
231 }
232 M_ASN1_BIT_STRING_free(os);
233 c.q=c.p;
234 if ((ret=d2i_RSA_NET_2(a,&c.p,c.slen,cb, sgckey)) == NULL) goto err;
235 /* Note: some versions of IIS key files use length values that are
236 * too small for the surrounding SEQUENCEs. This following line
237 * effectively disable length checking.
238 */
239 c.slen = 0;
240
241 M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA);
242 }
243
244RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length,
245 int (*cb)())
246{
247 return d2i_RSA_NET_2(a, pp, length, cb, 0);
248}
249
250RSA *d2i_RSA_NET_2(RSA **a, unsigned char **pp, long length,
251 int (*cb)(), int sgckey)
252 {
253 NETSCAPE_PKEY *pkey=NULL;
254 RSA *ret=NULL;
255 int i,j;
256 unsigned char buf[256],*zz;
257 unsigned char key[EVP_MAX_KEY_LENGTH];
258 EVP_CIPHER_CTX ctx;
259 X509_ALGOR *alg=NULL;
260 ASN1_OCTET_STRING *os=NULL;
261 ASN1_CTX c;
262
263 c.error=ERR_R_NESTED_ASN1_ERROR;
264 c.pp=pp;
265
266 M_ASN1_D2I_Init();
267 M_ASN1_D2I_start_sequence();
268 M_ASN1_D2I_get(alg,d2i_X509_ALGOR);
269 if (OBJ_obj2nid(alg->algorithm) != NID_rc4)
270 {
271 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
272 goto err;
273 }
274 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
275 if (cb == NULL)
276 cb=EVP_read_pw_string;
277 i=cb(buf,256,"Enter Private Key password:",0);
278 if (i != 0)
279 {
280 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
281 goto err;
282 }
283
284 i = strlen((char *)buf);
285 if(sgckey){
286 EVP_MD_CTX mctx;
287 EVP_DigestInit(&mctx, EVP_md5());
288 EVP_DigestUpdate(&mctx, buf, i);
289 EVP_DigestFinal(&mctx, buf, NULL);
290 memcpy(buf + 16, "SGCKEYSALT", 10);
291 i = 26;
292 }
293
294 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
295 memset(buf,0,256);
296
297 EVP_CIPHER_CTX_init(&ctx);
298 EVP_DecryptInit(&ctx,EVP_rc4(),key,NULL);
299 EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length);
300 EVP_DecryptFinal(&ctx,&(os->data[i]),&j);
301 EVP_CIPHER_CTX_cleanup(&ctx);
302 os->length=i+j;
303
304 zz=os->data;
305
306 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
307 {
308 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
309 goto err;
310 }
311
312 zz=pkey->private_key->data;
313 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
314 {
315 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
316 goto err;
317 }
318 if (!asn1_Finish(&c)) goto err;
319 *pp=c.p;
320err:
321 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
322 if (os != NULL) M_ASN1_BIT_STRING_free(os);
323 if (alg != NULL) X509_ALGOR_free(alg);
324 return(ret);
325 }
326
327static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp)
328 {
329 M_ASN1_I2D_vars(a);
330
331
332 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
333 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
334 M_ASN1_I2D_len(a->private_key, i2d_ASN1_OCTET_STRING);
335
336 M_ASN1_I2D_seq_total();
337
338 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
339 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
340 M_ASN1_I2D_put(a->private_key, i2d_ASN1_OCTET_STRING);
341
342 M_ASN1_I2D_finish();
343 }
344
345static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, unsigned char **pp,
346 long length)
347 {
348 M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new);
349
350 M_ASN1_D2I_Init();
351 M_ASN1_D2I_start_sequence();
352 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
353 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
354 M_ASN1_D2I_get(ret->private_key,d2i_ASN1_OCTET_STRING);
355 M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY);
356 }
357
358static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
359 {
360 NETSCAPE_PKEY *ret=NULL;
361 ASN1_CTX c;
362
363 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY);
364 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
365 M_ASN1_New(ret->algor,X509_ALGOR_new);
366 M_ASN1_New(ret->private_key,M_ASN1_OCTET_STRING_new);
367 return(ret);
368 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW);
369 }
370
371static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a)
372 {
373 if (a == NULL) return;
374 M_ASN1_INTEGER_free(a->version);
375 X509_ALGOR_free(a->algor);
376 M_ASN1_OCTET_STRING_free(a->private_key);
377 OPENSSL_free(a);
378 }
379
380#endif /* NO_RC4 */
381
382#else /* !NO_RSA */
383
384# if PEDANTIC
385static void *dummy=&dummy;
386# endif
387
388#endif
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c
deleted file mode 100644
index 6e7f09ba23..0000000000
--- a/src/lib/libcrypto/asn1/nsseq.c
+++ /dev/null
@@ -1,118 +0,0 @@
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/asn1_mac.h>
62#include <openssl/err.h>
63#include <openssl/x509.h>
64#include <openssl/objects.h>
65
66/* Netscape certificate sequence structure */
67
68int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp)
69{
70 int v = 0;
71 M_ASN1_I2D_vars(a);
72 M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT);
73 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
74 V_ASN1_SEQUENCE,v);
75
76 M_ASN1_I2D_seq_total();
77
78 M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT);
79 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
80 V_ASN1_SEQUENCE,v);
81
82 M_ASN1_I2D_finish();
83}
84
85NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void)
86{
87 NETSCAPE_CERT_SEQUENCE *ret=NULL;
88 ASN1_CTX c;
89 M_ASN1_New_Malloc(ret, NETSCAPE_CERT_SEQUENCE);
90 /* Note hardcoded object type */
91 ret->type = OBJ_nid2obj(NID_netscape_cert_sequence);
92 ret->certs = NULL;
93 return (ret);
94 M_ASN1_New_Error(ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW);
95}
96
97NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a,
98 unsigned char **pp, long length)
99{
100 M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *,
101 NETSCAPE_CERT_SEQUENCE_new);
102 M_ASN1_D2I_Init();
103 M_ASN1_D2I_start_sequence();
104 M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
105 M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0,
106 V_ASN1_SEQUENCE);
107 M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free,
108 ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE);
109}
110
111void NETSCAPE_CERT_SEQUENCE_free (NETSCAPE_CERT_SEQUENCE *a)
112{
113 if (a == NULL) return;
114 ASN1_OBJECT_free(a->type);
115 if(a->certs)
116 sk_X509_pop_free(a->certs, X509_free);
117 OPENSSL_free (a);
118}
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
deleted file mode 100644
index b7ed538eb2..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ /dev/null
@@ -1,157 +0,0 @@
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/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 password based encryption structure */
66
67int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING);
71 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING);
76 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
77 M_ASN1_I2D_finish();
78}
79
80PBEPARAM *PBEPARAM_new(void)
81{
82 PBEPARAM *ret=NULL;
83 ASN1_CTX c;
84 M_ASN1_New_Malloc(ret, PBEPARAM);
85 M_ASN1_New(ret->iter,M_ASN1_INTEGER_new);
86 M_ASN1_New(ret->salt,M_ASN1_OCTET_STRING_new);
87 return (ret);
88 M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW);
89}
90
91PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length)
92{
93 M_ASN1_D2I_vars(a,PBEPARAM *,PBEPARAM_new);
94 M_ASN1_D2I_Init();
95 M_ASN1_D2I_start_sequence();
96 M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING);
97 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
98 M_ASN1_D2I_Finish(a, PBEPARAM_free, ASN1_F_D2I_PBEPARAM);
99}
100
101void PBEPARAM_free (PBEPARAM *a)
102{
103 if(a==NULL) return;
104 M_ASN1_OCTET_STRING_free(a->salt);
105 M_ASN1_INTEGER_free (a->iter);
106 OPENSSL_free (a);
107}
108
109/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
110
111X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
112 int saltlen)
113{
114 PBEPARAM *pbe;
115 ASN1_OBJECT *al;
116 X509_ALGOR *algor;
117 ASN1_TYPE *astype;
118
119 if (!(pbe = PBEPARAM_new ())) {
120 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
121 return NULL;
122 }
123 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
124 ASN1_INTEGER_set (pbe->iter, iter);
125 if (!saltlen) saltlen = PKCS5_SALT_LEN;
126 if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) {
127 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 pbe->salt->length = saltlen;
131 if (salt) memcpy (pbe->salt->data, salt, saltlen);
132 else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0)
133 return NULL;
134
135 if (!(astype = ASN1_TYPE_new())) {
136 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
137 return NULL;
138 }
139
140 astype->type = V_ASN1_SEQUENCE;
141 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
142 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
143 return NULL;
144 }
145 PBEPARAM_free (pbe);
146
147 al = OBJ_nid2obj(alg); /* never need to free al */
148 if (!(algor = X509_ALGOR_new())) {
149 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
150 return NULL;
151 }
152 ASN1_OBJECT_free(algor->algorithm);
153 algor->algorithm = al;
154 algor->parameter = astype;
155
156 return (algor);
157}
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
deleted file mode 100644
index 6a7b578c0e..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ /dev/null
@@ -1,282 +0,0 @@
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/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 v2.0 password based encryption structures */
66
67int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->keyfunc, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->encryption, i2d_X509_ALGOR);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->keyfunc, i2d_X509_ALGOR);
76 M_ASN1_I2D_put (a->encryption, i2d_X509_ALGOR);
77
78 M_ASN1_I2D_finish();
79}
80
81PBE2PARAM *PBE2PARAM_new(void)
82{
83 PBE2PARAM *ret=NULL;
84 ASN1_CTX c;
85 M_ASN1_New_Malloc(ret, PBE2PARAM);
86 M_ASN1_New(ret->keyfunc,X509_ALGOR_new);
87 M_ASN1_New(ret->encryption,X509_ALGOR_new);
88 return (ret);
89 M_ASN1_New_Error(ASN1_F_PBE2PARAM_NEW);
90}
91
92PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length)
93{
94 M_ASN1_D2I_vars(a,PBE2PARAM *,PBE2PARAM_new);
95 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get (ret->keyfunc, d2i_X509_ALGOR);
98 M_ASN1_D2I_get (ret->encryption, d2i_X509_ALGOR);
99 M_ASN1_D2I_Finish(a, PBE2PARAM_free, ASN1_F_D2I_PBE2PARAM);
100}
101
102void PBE2PARAM_free (PBE2PARAM *a)
103{
104 if(a==NULL) return;
105 X509_ALGOR_free(a->keyfunc);
106 X509_ALGOR_free(a->encryption);
107 OPENSSL_free (a);
108}
109
110int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp)
111{
112 M_ASN1_I2D_vars(a);
113 M_ASN1_I2D_len (a->salt, i2d_ASN1_TYPE);
114 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
115 M_ASN1_I2D_len (a->keylength, i2d_ASN1_INTEGER);
116 M_ASN1_I2D_len (a->prf, i2d_X509_ALGOR);
117
118 M_ASN1_I2D_seq_total ();
119
120 M_ASN1_I2D_put (a->salt, i2d_ASN1_TYPE);
121 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
122 M_ASN1_I2D_put (a->keylength, i2d_ASN1_INTEGER);
123 M_ASN1_I2D_put (a->prf, i2d_X509_ALGOR);
124
125 M_ASN1_I2D_finish();
126}
127
128PBKDF2PARAM *PBKDF2PARAM_new(void)
129{
130 PBKDF2PARAM *ret=NULL;
131 ASN1_CTX c;
132 M_ASN1_New_Malloc(ret, PBKDF2PARAM);
133 M_ASN1_New(ret->salt, ASN1_TYPE_new);
134 M_ASN1_New(ret->iter, M_ASN1_INTEGER_new);
135 ret->keylength = NULL;
136 ret->prf = NULL;
137 return (ret);
138 M_ASN1_New_Error(ASN1_F_PBKDF2PARAM_NEW);
139}
140
141PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp,
142 long length)
143{
144 M_ASN1_D2I_vars(a,PBKDF2PARAM *,PBKDF2PARAM_new);
145 M_ASN1_D2I_Init();
146 M_ASN1_D2I_start_sequence();
147 M_ASN1_D2I_get (ret->salt, d2i_ASN1_TYPE);
148 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
149 M_ASN1_D2I_get_opt (ret->keylength, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
150 M_ASN1_D2I_get_opt (ret->prf, d2i_X509_ALGOR, V_ASN1_SEQUENCE);
151 M_ASN1_D2I_Finish(a, PBKDF2PARAM_free, ASN1_F_D2I_PBKDF2PARAM);
152}
153
154void PBKDF2PARAM_free (PBKDF2PARAM *a)
155{
156 if(a==NULL) return;
157 ASN1_TYPE_free(a->salt);
158 M_ASN1_INTEGER_free(a->iter);
159 M_ASN1_INTEGER_free(a->keylength);
160 X509_ALGOR_free(a->prf);
161 OPENSSL_free (a);
162}
163
164/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
165 * yes I know this is horrible!
166 */
167
168X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
169 unsigned char *salt, int saltlen)
170{
171 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
172 int alg_nid;
173 EVP_CIPHER_CTX ctx;
174 unsigned char iv[EVP_MAX_IV_LENGTH];
175 PBKDF2PARAM *kdf = NULL;
176 PBE2PARAM *pbe2 = NULL;
177 ASN1_OCTET_STRING *osalt = NULL;
178 ASN1_OBJECT *obj;
179
180 alg_nid = EVP_CIPHER_type(cipher);
181 if(alg_nid == NID_undef) {
182 ASN1err(ASN1_F_PKCS5_PBE2_SET,
183 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
184 goto err;
185 }
186 obj = OBJ_nid2obj(alg_nid);
187
188 if(!(pbe2 = PBE2PARAM_new())) goto merr;
189
190 /* Setup the AlgorithmIdentifier for the encryption scheme */
191 scheme = pbe2->encryption;
192
193 scheme->algorithm = obj;
194 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
195
196 /* Create random IV */
197 if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
198 goto err;
199
200 /* Dummy cipherinit to just setup the IV */
201 EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
202 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
203 ASN1err(ASN1_F_PKCS5_PBE2_SET,
204 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
205 goto err;
206 }
207 EVP_CIPHER_CTX_cleanup(&ctx);
208
209 if(!(kdf = PBKDF2PARAM_new())) goto merr;
210 if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr;
211
212 if (!saltlen) saltlen = PKCS5_SALT_LEN;
213 if (!(osalt->data = OPENSSL_malloc (saltlen))) goto merr;
214 osalt->length = saltlen;
215 if (salt) memcpy (osalt->data, salt, saltlen);
216 else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr;
217
218 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
219 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
220
221 /* Now include salt in kdf structure */
222 kdf->salt->value.octet_string = osalt;
223 kdf->salt->type = V_ASN1_OCTET_STRING;
224 osalt = NULL;
225
226 /* If its RC2 then we'd better setup the key length */
227
228 if(alg_nid == NID_rc2_cbc) {
229 if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr;
230 if(!ASN1_INTEGER_set (kdf->keylength,
231 EVP_CIPHER_key_length(cipher))) goto merr;
232 }
233
234 /* prf can stay NULL because we are using hmacWithSHA1 */
235
236 /* Now setup the PBE2PARAM keyfunc structure */
237
238 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
239
240 /* Encode PBKDF2PARAM into parameter of pbe2 */
241
242 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
243
244 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
245 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
246 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
247
248 PBKDF2PARAM_free(kdf);
249 kdf = NULL;
250
251 /* Now set up top level AlgorithmIdentifier */
252
253 if(!(ret = X509_ALGOR_new())) goto merr;
254 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
255
256 ret->algorithm = OBJ_nid2obj(NID_pbes2);
257
258 /* Encode PBE2PARAM into parameter */
259
260 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
261 &ret->parameter->value.sequence)) goto merr;
262 ret->parameter->type = V_ASN1_SEQUENCE;
263
264 PBE2PARAM_free(pbe2);
265 pbe2 = NULL;
266
267 return ret;
268
269 merr:
270 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
271
272 err:
273 PBE2PARAM_free(pbe2);
274 /* Note 'scheme' is freed as part of pbe2 */
275 M_ASN1_OCTET_STRING_free(osalt);
276 PBKDF2PARAM_free(kdf);
277 X509_ALGOR_free(kalg);
278 X509_ALGOR_free(ret);
279
280 return NULL;
281
282}
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
deleted file mode 100644
index fa6cbfb6f8..0000000000
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ /dev/null
@@ -1,127 +0,0 @@
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/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_PKCS8_PRIV_KEY_INFO (PKCS8_PRIV_KEY_INFO *a, unsigned char **pp)
65{
66
67 M_ASN1_I2D_vars(a);
68
69 M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER);
70 M_ASN1_I2D_len (a->pkeyalg, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->pkey, i2d_ASN1_TYPE);
72 M_ASN1_I2D_len_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
73 i2d_X509_ATTRIBUTE, 0);
74
75 M_ASN1_I2D_seq_total ();
76
77 M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER);
78 M_ASN1_I2D_put (a->pkeyalg, i2d_X509_ALGOR);
79 M_ASN1_I2D_put (a->pkey, i2d_ASN1_TYPE);
80 M_ASN1_I2D_put_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
81 i2d_X509_ATTRIBUTE, 0);
82
83 M_ASN1_I2D_finish();
84}
85
86PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void)
87{
88 PKCS8_PRIV_KEY_INFO *ret=NULL;
89 ASN1_CTX c;
90 M_ASN1_New_Malloc(ret, PKCS8_PRIV_KEY_INFO);
91 M_ASN1_New (ret->version, M_ASN1_INTEGER_new);
92 M_ASN1_New (ret->pkeyalg, X509_ALGOR_new);
93 M_ASN1_New (ret->pkey, ASN1_TYPE_new);
94 ret->attributes = NULL;
95 ret->broken = PKCS8_OK;
96 return (ret);
97 M_ASN1_New_Error(ASN1_F_PKCS8_PRIV_KEY_INFO_NEW);
98}
99
100PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
101 unsigned char **pp, long length)
102{
103 M_ASN1_D2I_vars(a,PKCS8_PRIV_KEY_INFO *,PKCS8_PRIV_KEY_INFO_new);
104 M_ASN1_D2I_Init();
105 M_ASN1_D2I_start_sequence();
106 M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
107 M_ASN1_D2I_get (ret->pkeyalg, d2i_X509_ALGOR);
108 M_ASN1_D2I_get (ret->pkey, d2i_ASN1_TYPE);
109 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes,
110 d2i_X509_ATTRIBUTE,
111 X509_ATTRIBUTE_free, 0);
112 M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);
113}
114
115void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a)
116{
117 if (a == NULL) return;
118 M_ASN1_INTEGER_free (a->version);
119 X509_ALGOR_free(a->pkeyalg);
120 /* Clear sensitive data */
121 if (a->pkey->value.octet_string)
122 memset (a->pkey->value.octet_string->data,
123 0, a->pkey->value.octet_string->length);
124 ASN1_TYPE_free (a->pkey);
125 sk_X509_ATTRIBUTE_pop_free (a->attributes, X509_ATTRIBUTE_free);
126 OPENSSL_free (a);
127}
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c
deleted file mode 100644
index 8ee789f082..0000000000
--- a/src/lib/libcrypto/asn1/t_bitst.c
+++ /dev/null
@@ -1,99 +0,0 @@
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
deleted file mode 100644
index d78e4a8f88..0000000000
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ /dev/null
@@ -1,166 +0,0 @@
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
67static void ext_print(BIO *out, X509_EXTENSION *ex);
68#ifndef NO_FP_API
69int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
70 {
71 BIO *b;
72 int ret;
73
74 if ((b=BIO_new(BIO_s_file())) == NULL)
75 {
76 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
77 return(0);
78 }
79 BIO_set_fp(b,fp,BIO_NOCLOSE);
80 ret=X509_CRL_print(b, x);
81 BIO_free(b);
82 return(ret);
83 }
84#endif
85
86int X509_CRL_print(BIO *out, X509_CRL *x)
87{
88 char buf[256];
89 unsigned char *s;
90 STACK_OF(X509_REVOKED) *rev;
91 X509_REVOKED *r;
92 long l;
93 int i, j, n;
94
95 BIO_printf(out, "Certificate Revocation List (CRL):\n");
96 l = X509_CRL_get_version(x);
97 BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
98 i = OBJ_obj2nid(x->sig_alg->algorithm);
99 BIO_printf(out, "%8sSignature Algorithm: %s\n", "",
100 (i == NID_undef) ? "NONE" : OBJ_nid2ln(i));
101 X509_NAME_oneline(X509_CRL_get_issuer(x),buf,256);
102 BIO_printf(out,"%8sIssuer: %s\n","",buf);
103 BIO_printf(out,"%8sLast Update: ","");
104 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
105 BIO_printf(out,"\n%8sNext Update: ","");
106 if (X509_CRL_get_nextUpdate(x))
107 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
108 else BIO_printf(out,"NONE");
109 BIO_printf(out,"\n");
110
111 n=X509_CRL_get_ext_count(x);
112 if (n > 0) {
113 BIO_printf(out,"%8sCRL extensions:\n","");
114 for (i=0; i<n; i++) ext_print(out, X509_CRL_get_ext(x, i));
115 }
116
117
118 rev = X509_CRL_get_REVOKED(x);
119
120 if(sk_X509_REVOKED_num(rev))
121 BIO_printf(out, "Revoked Certificates:\n");
122 else BIO_printf(out, "No Revoked Certificates.\n");
123
124 for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
125 r = sk_X509_REVOKED_value(rev, i);
126 BIO_printf(out," Serial Number: ");
127 i2a_ASN1_INTEGER(out,r->serialNumber);
128 BIO_printf(out,"\n Revocation Date: ","");
129 ASN1_TIME_print(out,r->revocationDate);
130 BIO_printf(out,"\n");
131 for(j = 0; j < X509_REVOKED_get_ext_count(r); j++)
132 ext_print(out, X509_REVOKED_get_ext(r, j));
133 }
134
135 i=OBJ_obj2nid(x->sig_alg->algorithm);
136 BIO_printf(out," Signature Algorithm: %s",
137 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
138
139 s = x->signature->data;
140 n = x->signature->length;
141 for (i=0; i<n; i++, s++)
142 {
143 if ((i%18) == 0) BIO_write(out,"\n ",9);
144 BIO_printf(out,"%02x%s",*s, ((i+1) == n)?"":":");
145 }
146 BIO_write(out,"\n",1);
147
148 return 1;
149
150}
151
152static void ext_print(BIO *out, X509_EXTENSION *ex)
153{
154 ASN1_OBJECT *obj;
155 int j;
156 BIO_printf(out,"%12s","");
157 obj=X509_EXTENSION_get_object(ex);
158 i2a_ASN1_OBJECT(out,obj);
159 j=X509_EXTENSION_get_critical(ex);
160 BIO_printf(out, ": %s\n", j ? "critical":"","");
161 if(!X509V3_EXT_print(out, ex, 0, 16)) {
162 BIO_printf(out, "%16s", "");
163 M_ASN1_OCTET_STRING_print(out,ex->value);
164 }
165 BIO_write(out,"\n",1);
166}
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
deleted file mode 100644
index ae18da96e3..0000000000
--- a/src/lib/libcrypto/asn1/t_pkey.c
+++ /dev/null
@@ -1,361 +0,0 @@
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 NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef NO_DH
67#include <openssl/dh.h>
68#endif
69#ifndef 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 NO_RSA
76#ifndef NO_FP_API
77int RSA_print_fp(FILE *fp, 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, RSA *x, int off)
95 {
96 char str[128];
97 const char *s;
98 unsigned char *m=NULL;
99 int i,ret=0;
100
101 i=RSA_size(x);
102 m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
103 if (m == NULL)
104 {
105 RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
106 goto err;
107 }
108
109 if (off)
110 {
111 if (off > 128) off=128;
112 memset(str,' ',off);
113 }
114 if (x->d != NULL)
115 {
116 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
117 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n))
118 <= 0) goto err;
119 }
120
121 if (x->d == NULL)
122 sprintf(str,"Modulus (%d bit):",BN_num_bits(x->n));
123 else
124 strcpy(str,"modulus:");
125 if (!print(bp,str,x->n,m,off)) goto err;
126 s=(x->d == NULL)?"Exponent:":"publicExponent:";
127 if (!print(bp,s,x->e,m,off)) goto err;
128 if (!print(bp,"privateExponent:",x->d,m,off)) goto err;
129 if (!print(bp,"prime1:",x->p,m,off)) goto err;
130 if (!print(bp,"prime2:",x->q,m,off)) goto err;
131 if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err;
132 if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err;
133 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
134 ret=1;
135err:
136 if (m != NULL) OPENSSL_free(m);
137 return(ret);
138 }
139#endif /* NO_RSA */
140
141#ifndef NO_DSA
142#ifndef NO_FP_API
143int DSA_print_fp(FILE *fp, DSA *x, int off)
144 {
145 BIO *b;
146 int ret;
147
148 if ((b=BIO_new(BIO_s_file())) == NULL)
149 {
150 DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
151 return(0);
152 }
153 BIO_set_fp(b,fp,BIO_NOCLOSE);
154 ret=DSA_print(b,x,off);
155 BIO_free(b);
156 return(ret);
157 }
158#endif
159
160int DSA_print(BIO *bp, DSA *x, int off)
161 {
162 char str[128];
163 unsigned char *m=NULL;
164 int i,ret=0;
165 BIGNUM *bn=NULL;
166
167 if (x->p != NULL)
168 bn=x->p;
169 else if (x->priv_key != NULL)
170 bn=x->priv_key;
171 else if (x->pub_key != NULL)
172 bn=x->pub_key;
173
174 /* larger than needed but what the hell :-) */
175 if (bn != NULL)
176 i=BN_num_bytes(bn)*2;
177 else
178 i=256;
179 m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
180 if (m == NULL)
181 {
182 DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
183 goto err;
184 }
185
186 if (off)
187 {
188 if (off > 128) off=128;
189 memset(str,' ',off);
190 }
191 if (x->priv_key != NULL)
192 {
193 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
194 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p))
195 <= 0) goto err;
196 }
197
198 if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off))
199 goto err;
200 if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off))
201 goto err;
202 if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err;
203 if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err;
204 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err;
205 ret=1;
206err:
207 if (m != NULL) OPENSSL_free(m);
208 return(ret);
209 }
210#endif /* !NO_DSA */
211
212static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
213 int off)
214 {
215 int n,i;
216 char str[128];
217 const char *neg;
218
219 if (num == NULL) return(1);
220 neg=(num->neg)?"-":"";
221 if (off)
222 {
223 if (off > 128) off=128;
224 memset(str,' ',off);
225 if (BIO_write(bp,str,off) <= 0) return(0);
226 }
227
228 if (BN_num_bytes(num) <= BN_BYTES)
229 {
230 if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
231 (unsigned long)num->d[0],neg,(unsigned long)num->d[0])
232 <= 0) return(0);
233 }
234 else
235 {
236 buf[0]=0;
237 if (BIO_printf(bp,"%s%s",number,
238 (neg[0] == '-')?" (Negative)":"") <= 0)
239 return(0);
240 n=BN_bn2bin(num,&buf[1]);
241
242 if (buf[1] & 0x80)
243 n++;
244 else buf++;
245
246 for (i=0; i<n; i++)
247 {
248 if ((i%15) == 0)
249 {
250 str[0]='\n';
251 memset(&(str[1]),' ',off+4);
252 if (BIO_write(bp,str,off+1+4) <= 0) return(0);
253 }
254 if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")
255 <= 0) return(0);
256 }
257 if (BIO_write(bp,"\n",1) <= 0) return(0);
258 }
259 return(1);
260 }
261
262#ifndef NO_DH
263#ifndef NO_FP_API
264int DHparams_print_fp(FILE *fp, DH *x)
265 {
266 BIO *b;
267 int ret;
268
269 if ((b=BIO_new(BIO_s_file())) == NULL)
270 {
271 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
272 return(0);
273 }
274 BIO_set_fp(b,fp,BIO_NOCLOSE);
275 ret=DHparams_print(b, x);
276 BIO_free(b);
277 return(ret);
278 }
279#endif
280
281int DHparams_print(BIO *bp, DH *x)
282 {
283 unsigned char *m=NULL;
284 int reason=ERR_R_BUF_LIB,i,ret=0;
285
286 i=BN_num_bytes(x->p);
287 m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
288 if (m == NULL)
289 {
290 reason=ERR_R_MALLOC_FAILURE;
291 goto err;
292 }
293
294 if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
295 BN_num_bits(x->p)) <= 0)
296 goto err;
297 if (!print(bp,"prime:",x->p,m,4)) goto err;
298 if (!print(bp,"generator:",x->g,m,4)) goto err;
299 if (x->length != 0)
300 {
301 if (BIO_printf(bp," recommended-private-length: %d bits\n",
302 (int)x->length) <= 0) goto err;
303 }
304 ret=1;
305 if (0)
306 {
307err:
308 DHerr(DH_F_DHPARAMS_PRINT,reason);
309 }
310 if (m != NULL) OPENSSL_free(m);
311 return(ret);
312 }
313#endif
314
315#ifndef NO_DSA
316#ifndef NO_FP_API
317int DSAparams_print_fp(FILE *fp, DSA *x)
318 {
319 BIO *b;
320 int ret;
321
322 if ((b=BIO_new(BIO_s_file())) == NULL)
323 {
324 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
325 return(0);
326 }
327 BIO_set_fp(b,fp,BIO_NOCLOSE);
328 ret=DSAparams_print(b, x);
329 BIO_free(b);
330 return(ret);
331 }
332#endif
333
334int DSAparams_print(BIO *bp, DSA *x)
335 {
336 unsigned char *m=NULL;
337 int reason=ERR_R_BUF_LIB,i,ret=0;
338
339 i=BN_num_bytes(x->p);
340 m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
341 if (m == NULL)
342 {
343 reason=ERR_R_MALLOC_FAILURE;
344 goto err;
345 }
346
347 if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n",
348 BN_num_bits(x->p)) <= 0)
349 goto err;
350 if (!print(bp,"p:",x->p,m,4)) goto err;
351 if (!print(bp,"q:",x->q,m,4)) goto err;
352 if (!print(bp,"g:",x->g,m,4)) goto err;
353 ret=1;
354err:
355 if (m != NULL) OPENSSL_free(m);
356 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
357 return(ret);
358 }
359
360#endif /* !NO_DSA */
361
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
deleted file mode 100644
index ea1af092db..0000000000
--- a/src/lib/libcrypto/asn1/t_req.c
+++ /dev/null
@@ -1,254 +0,0 @@
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 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(BIO *bp, X509_REQ *x)
86 {
87 unsigned long l;
88 int i,n;
89 char *s;
90 const char *neg;
91 X509_REQ_INFO *ri;
92 EVP_PKEY *pkey;
93 STACK_OF(X509_ATTRIBUTE) *sk;
94 STACK_OF(X509_EXTENSION) *exts;
95 char str[128];
96
97 ri=x->req_info;
98 sprintf(str,"Certificate Request:\n");
99 if (BIO_puts(bp,str) <= 0) goto err;
100 sprintf(str,"%4sData:\n","");
101 if (BIO_puts(bp,str) <= 0) goto err;
102
103 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
104 l=0;
105 for (i=0; i<ri->version->length; i++)
106 { l<<=8; l+=ri->version->data[i]; }
107 sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l);
108 if (BIO_puts(bp,str) <= 0) goto err;
109 sprintf(str,"%8sSubject: ","");
110 if (BIO_puts(bp,str) <= 0) goto err;
111
112 X509_NAME_print(bp,ri->subject,16);
113 sprintf(str,"\n%8sSubject Public Key Info:\n","");
114 if (BIO_puts(bp,str) <= 0) goto err;
115 i=OBJ_obj2nid(ri->pubkey->algor->algorithm);
116 sprintf(str,"%12sPublic Key Algorithm: %s\n","",
117 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
118 if (BIO_puts(bp,str) <= 0) goto err;
119
120 pkey=X509_REQ_get_pubkey(x);
121#ifndef NO_RSA
122 if (pkey != NULL && pkey->type == EVP_PKEY_RSA)
123 {
124 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
125 BN_num_bits(pkey->pkey.rsa->n));
126 RSA_print(bp,pkey->pkey.rsa,16);
127 }
128 else
129#endif
130#ifndef NO_DSA
131 if (pkey != NULL && pkey->type == EVP_PKEY_DSA)
132 {
133 BIO_printf(bp,"%12sDSA Public Key:\n","");
134 DSA_print(bp,pkey->pkey.dsa,16);
135 }
136 else
137#endif
138 BIO_printf(bp,"%12sUnknown Public Key:\n","");
139
140 if (pkey != NULL)
141 EVP_PKEY_free(pkey);
142
143 /* may not be */
144 sprintf(str,"%8sAttributes:\n","");
145 if (BIO_puts(bp,str) <= 0) goto err;
146
147 sk=x->req_info->attributes;
148 if ((sk == NULL) || (sk_X509_ATTRIBUTE_num(sk) == 0))
149 {
150 if (!x->req_info->req_kludge)
151 {
152 sprintf(str,"%12sa0:00\n","");
153 if (BIO_puts(bp,str) <= 0) goto err;
154 }
155 }
156 else
157 {
158 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
159 {
160 ASN1_TYPE *at;
161 X509_ATTRIBUTE *a;
162 ASN1_BIT_STRING *bs=NULL;
163 ASN1_TYPE *t;
164 int j,type=0,count=1,ii=0;
165
166 a=sk_X509_ATTRIBUTE_value(sk,i);
167 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
168 continue;
169 sprintf(str,"%12s","");
170 if (BIO_puts(bp,str) <= 0) goto err;
171 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
172 {
173 if (a->set)
174 {
175 ii=0;
176 count=sk_ASN1_TYPE_num(a->value.set);
177get_next:
178 at=sk_ASN1_TYPE_value(a->value.set,ii);
179 type=at->type;
180 bs=at->value.asn1_string;
181 }
182 else
183 {
184 t=a->value.single;
185 type=t->type;
186 bs=t->value.bit_string;
187 }
188 }
189 for (j=25-j; j>0; j--)
190 if (BIO_write(bp," ",1) != 1) goto err;
191 if (BIO_puts(bp,":") <= 0) goto err;
192 if ( (type == V_ASN1_PRINTABLESTRING) ||
193 (type == V_ASN1_T61STRING) ||
194 (type == V_ASN1_IA5STRING))
195 {
196 if (BIO_write(bp,(char *)bs->data,bs->length)
197 != bs->length)
198 goto err;
199 BIO_puts(bp,"\n");
200 }
201 else
202 {
203 BIO_puts(bp,"unable to print attribute\n");
204 }
205 if (++ii < count) goto get_next;
206 }
207 }
208
209 exts = X509_REQ_get_extensions(x);
210 if(exts) {
211 BIO_printf(bp,"%8sRequested Extensions:\n","");
212 for (i=0; i<sk_X509_EXTENSION_num(exts); i++) {
213 ASN1_OBJECT *obj;
214 X509_EXTENSION *ex;
215 int j;
216 ex=sk_X509_EXTENSION_value(exts, i);
217 if (BIO_printf(bp,"%12s","") <= 0) goto err;
218 obj=X509_EXTENSION_get_object(ex);
219 i2a_ASN1_OBJECT(bp,obj);
220 j=X509_EXTENSION_get_critical(ex);
221 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
222 goto err;
223 if(!X509V3_EXT_print(bp, ex, 0, 16)) {
224 BIO_printf(bp, "%16s", "");
225 M_ASN1_OCTET_STRING_print(bp,ex->value);
226 }
227 if (BIO_write(bp,"\n",1) <= 0) goto err;
228 }
229 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
230 }
231
232 i=OBJ_obj2nid(x->sig_alg->algorithm);
233 sprintf(str,"%4sSignature Algorithm: %s","",
234 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
235 if (BIO_puts(bp,str) <= 0) goto err;
236
237 n=x->signature->length;
238 s=(char *)x->signature->data;
239 for (i=0; i<n; i++)
240 {
241 if ((i%18) == 0)
242 {
243 sprintf(str,"\n%8s","");
244 if (BIO_puts(bp,str) <= 0) goto err;
245 }
246 sprintf(str,"%02x%s",(unsigned char)s[i],((i+1) == n)?"":":");
247 if (BIO_puts(bp,str) <= 0) goto err;
248 }
249 if (BIO_puts(bp,"\n") <= 0) goto err;
250 return(1);
251err:
252 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
253 return(0);
254 }
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
deleted file mode 100644
index d708434fca..0000000000
--- a/src/lib/libcrypto/asn1/t_spki.c
+++ /dev/null
@@ -1,116 +0,0 @@
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_mac.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 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 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
deleted file mode 100644
index 89ae73a6de..0000000000
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ /dev/null
@@ -1,411 +0,0 @@
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 NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef 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 NO_FP_API
74int X509_print_fp(FILE *fp, X509 *x)
75 {
76 BIO *b;
77 int ret;
78
79 if ((b=BIO_new(BIO_s_file())) == NULL)
80 {
81 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
82 return(0);
83 }
84 BIO_set_fp(b,fp,BIO_NOCLOSE);
85 ret=X509_print(b, x);
86 BIO_free(b);
87 return(ret);
88 }
89#endif
90
91int X509_print(BIO *bp, X509 *x)
92 {
93 long l;
94 int ret=0,i,j,n;
95 char *m=NULL,*s;
96 X509_CINF *ci;
97 ASN1_INTEGER *bs;
98 EVP_PKEY *pkey=NULL;
99 const char *neg;
100 X509_EXTENSION *ex;
101 ASN1_STRING *str=NULL;
102
103 ci=x->cert_info;
104 if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
105 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
106 l=X509_get_version(x);
107 if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
108 if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
109
110 bs=X509_get_serialNumber(x);
111 if (bs->length <= 4)
112 {
113 l=ASN1_INTEGER_get(bs);
114 if (l < 0)
115 {
116 l= -l;
117 neg="-";
118 }
119 else
120 neg="";
121 if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
122 goto err;
123 }
124 else
125 {
126 neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
127 if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
128
129 for (i=0; i<bs->length; i++)
130 {
131 if (BIO_printf(bp,"%02x%c",bs->data[i],
132 ((i+1 == bs->length)?'\n':':')) <= 0)
133 goto err;
134 }
135 }
136
137 i=OBJ_obj2nid(ci->signature->algorithm);
138 if (BIO_printf(bp,"%8sSignature Algorithm: %s\n","",
139 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0)
140 goto err;
141
142 if (BIO_write(bp," Issuer: ",16) <= 0) goto err;
143 if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err;
144 if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err;
145 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
146 if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
147 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
148 if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
149 if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err;
150 if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err;
151 if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0)
152 goto err;
153 i=OBJ_obj2nid(ci->key->algor->algorithm);
154 if (BIO_printf(bp,"%12sPublic Key Algorithm: %s\n","",
155 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
156
157 pkey=X509_get_pubkey(x);
158 if (pkey == NULL)
159 {
160 BIO_printf(bp,"%12sUnable to load Public Key\n","");
161 ERR_print_errors(bp);
162 }
163 else
164#ifndef NO_RSA
165 if (pkey->type == EVP_PKEY_RSA)
166 {
167 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
168 BN_num_bits(pkey->pkey.rsa->n));
169 RSA_print(bp,pkey->pkey.rsa,16);
170 }
171 else
172#endif
173#ifndef NO_DSA
174 if (pkey->type == EVP_PKEY_DSA)
175 {
176 BIO_printf(bp,"%12sDSA Public Key:\n","");
177 DSA_print(bp,pkey->pkey.dsa,16);
178 }
179 else
180#endif
181 BIO_printf(bp,"%12sUnknown Public Key:\n","");
182
183 EVP_PKEY_free(pkey);
184
185 n=X509_get_ext_count(x);
186 if (n > 0)
187 {
188 BIO_printf(bp,"%8sX509v3 extensions:\n","");
189 for (i=0; i<n; i++)
190 {
191 ASN1_OBJECT *obj;
192 ex=X509_get_ext(x,i);
193 if (BIO_printf(bp,"%12s","") <= 0) goto err;
194 obj=X509_EXTENSION_get_object(ex);
195 i2a_ASN1_OBJECT(bp,obj);
196 j=X509_EXTENSION_get_critical(ex);
197 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
198 goto err;
199 if(!X509V3_EXT_print(bp, ex, 0, 16))
200 {
201 BIO_printf(bp, "%16s", "");
202 M_ASN1_OCTET_STRING_print(bp,ex->value);
203 }
204 if (BIO_write(bp,"\n",1) <= 0) goto err;
205 }
206 }
207
208 i=OBJ_obj2nid(x->sig_alg->algorithm);
209 if (BIO_printf(bp,"%4sSignature Algorithm: %s","",
210 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
211
212 n=x->signature->length;
213 s=(char *)x->signature->data;
214 for (i=0; i<n; i++)
215 {
216 if ((i%18) == 0)
217 if (BIO_write(bp,"\n ",9) <= 0) goto err;
218 if (BIO_printf(bp,"%02x%s",(unsigned char)s[i],
219 ((i+1) == n)?"":":") <= 0) goto err;
220 }
221 if (BIO_write(bp,"\n",1) != 1) goto err;
222 if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
223 ret=1;
224err:
225 if (str != NULL) ASN1_STRING_free(str);
226 if (m != NULL) OPENSSL_free(m);
227 return(ret);
228 }
229
230int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
231 {
232 int i,n;
233 char buf[80],*p;;
234
235 if (v == NULL) return(0);
236 n=0;
237 p=(char *)v->data;
238 for (i=0; i<v->length; i++)
239 {
240 if ((p[i] > '~') || ((p[i] < ' ') &&
241 (p[i] != '\n') && (p[i] != '\r')))
242 buf[n]='.';
243 else
244 buf[n]=p[i];
245 n++;
246 if (n >= 80)
247 {
248 if (BIO_write(bp,buf,n) <= 0)
249 return(0);
250 n=0;
251 }
252 }
253 if (n > 0)
254 if (BIO_write(bp,buf,n) <= 0)
255 return(0);
256 return(1);
257 }
258
259int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
260{
261 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
262 if(tm->type == V_ASN1_GENERALIZEDTIME)
263 return ASN1_GENERALIZEDTIME_print(bp, tm);
264 BIO_write(bp,"Bad time value",14);
265 return(0);
266}
267
268static const char *mon[12]=
269 {
270 "Jan","Feb","Mar","Apr","May","Jun",
271 "Jul","Aug","Sep","Oct","Nov","Dec"
272 };
273
274int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
275 {
276 char *v;
277 int gmt=0;
278 int i;
279 int y=0,M=0,d=0,h=0,m=0,s=0;
280
281 i=tm->length;
282 v=(char *)tm->data;
283
284 if (i < 12) goto err;
285 if (v[i-1] == 'Z') gmt=1;
286 for (i=0; i<12; i++)
287 if ((v[i] > '9') || (v[i] < '0')) goto err;
288 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
289 M= (v[4]-'0')*10+(v[5]-'0');
290 if ((M > 12) || (M < 1)) goto err;
291 d= (v[6]-'0')*10+(v[7]-'0');
292 h= (v[8]-'0')*10+(v[9]-'0');
293 m= (v[10]-'0')*10+(v[11]-'0');
294 if ( (v[12] >= '0') && (v[12] <= '9') &&
295 (v[13] >= '0') && (v[13] <= '9'))
296 s= (v[12]-'0')*10+(v[13]-'0');
297
298 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
299 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
300 return(0);
301 else
302 return(1);
303err:
304 BIO_write(bp,"Bad time value",14);
305 return(0);
306 }
307
308int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
309 {
310 char *v;
311 int gmt=0;
312 int i;
313 int y=0,M=0,d=0,h=0,m=0,s=0;
314
315 i=tm->length;
316 v=(char *)tm->data;
317
318 if (i < 10) goto err;
319 if (v[i-1] == 'Z') gmt=1;
320 for (i=0; i<10; i++)
321 if ((v[i] > '9') || (v[i] < '0')) goto err;
322 y= (v[0]-'0')*10+(v[1]-'0');
323 if (y < 50) y+=100;
324 M= (v[2]-'0')*10+(v[3]-'0');
325 if ((M > 12) || (M < 1)) goto err;
326 d= (v[4]-'0')*10+(v[5]-'0');
327 h= (v[6]-'0')*10+(v[7]-'0');
328 m= (v[8]-'0')*10+(v[9]-'0');
329 if ( (v[10] >= '0') && (v[10] <= '9') &&
330 (v[11] >= '0') && (v[11] <= '9'))
331 s= (v[10]-'0')*10+(v[11]-'0');
332
333 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
334 mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0)
335 return(0);
336 else
337 return(1);
338err:
339 BIO_write(bp,"Bad time value",14);
340 return(0);
341 }
342
343int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
344 {
345 char *s,*c;
346 int ret=0,l,ll,i,first=1;
347 char buf[256];
348
349 ll=80-2-obase;
350
351 s=X509_NAME_oneline(name,buf,256);
352 if (!*s)
353 return 1;
354 s++; /* skip the first slash */
355
356 l=ll;
357 c=s;
358 for (;;)
359 {
360#ifndef CHARSET_EBCDIC
361 if ( ((*s == '/') &&
362 ((s[1] >= 'A') && (s[1] <= 'Z') && (
363 (s[2] == '=') ||
364 ((s[2] >= 'A') && (s[2] <= 'Z') &&
365 (s[3] == '='))
366 ))) ||
367 (*s == '\0'))
368#else
369 if ( ((*s == '/') &&
370 (isupper(s[1]) && (
371 (s[2] == '=') ||
372 (isupper(s[2]) &&
373 (s[3] == '='))
374 ))) ||
375 (*s == '\0'))
376#endif
377 {
378 if ((l <= 0) && !first)
379 {
380 first=0;
381 if (BIO_write(bp,"\n",1) != 1) goto err;
382 for (i=0; i<obase; i++)
383 {
384 if (BIO_write(bp," ",1) != 1) goto err;
385 }
386 l=ll;
387 }
388 i=s-c;
389 if (BIO_write(bp,c,i) != i) goto err;
390 c+=i;
391 c++;
392 if (*s != '\0')
393 {
394 if (BIO_write(bp,", ",2) != 2) goto err;
395 }
396 l--;
397 }
398 if (*s == '\0') break;
399 s++;
400 l--;
401 }
402
403 ret=1;
404 if (0)
405 {
406err:
407 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
408 }
409 return(ret);
410 }
411
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
deleted file mode 100644
index f06af5b576..0000000000
--- a/src/lib/libcrypto/asn1/t_x509a.c
+++ /dev/null
@@ -1,110 +0,0 @@
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_mac.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/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
deleted file mode 100644
index 853a8dfeef..0000000000
--- a/src/lib/libcrypto/asn1/x_algor.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* crypto/asn1/x_algor.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_ALGOR(X509_ALGOR *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->algorithm,i2d_ASN1_OBJECT);
69 if (a->parameter != NULL)
70 { M_ASN1_I2D_len(a->parameter,i2d_ASN1_TYPE); }
71
72 M_ASN1_I2D_seq_total();
73 M_ASN1_I2D_put(a->algorithm,i2d_ASN1_OBJECT);
74 if (a->parameter != NULL)
75 { M_ASN1_I2D_put(a->parameter,i2d_ASN1_TYPE); }
76
77 M_ASN1_I2D_finish();
78 }
79
80X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length)
81 {
82 M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new);
83
84 M_ASN1_D2I_Init();
85 M_ASN1_D2I_start_sequence();
86 M_ASN1_D2I_get(ret->algorithm,d2i_ASN1_OBJECT);
87 if (!M_ASN1_D2I_end_sequence())
88 { M_ASN1_D2I_get(ret->parameter,d2i_ASN1_TYPE); }
89 else
90 {
91 ASN1_TYPE_free(ret->parameter);
92 ret->parameter=NULL;
93 }
94 M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR);
95 }
96
97X509_ALGOR *X509_ALGOR_new(void)
98 {
99 X509_ALGOR *ret=NULL;
100 ASN1_CTX c;
101
102 M_ASN1_New_Malloc(ret,X509_ALGOR);
103 ret->algorithm=OBJ_nid2obj(NID_undef);
104 ret->parameter=NULL;
105 return(ret);
106 M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW);
107 }
108
109void X509_ALGOR_free(X509_ALGOR *a)
110 {
111 if (a == NULL) return;
112 ASN1_OBJECT_free(a->algorithm);
113 ASN1_TYPE_free(a->parameter);
114 OPENSSL_free(a);
115 }
116
117IMPLEMENT_STACK_OF(X509_ALGOR)
118IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
deleted file mode 100644
index 14e5ea27aa..0000000000
--- a/src/lib/libcrypto/asn1/x_attrib.c
+++ /dev/null
@@ -1,165 +0,0 @@
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/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* sequence */
66int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **pp)
67 {
68 int k=0;
69 int r=0,ret=0;
70 unsigned char **p=NULL;
71
72 if (a == NULL) return(0);
73
74 p=NULL;
75 for (;;)
76 {
77 if (k)
78 {
79 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
80 if (pp == NULL) return(r);
81 p=pp;
82 ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
83 V_ASN1_UNIVERSAL);
84 }
85
86 ret+=i2d_ASN1_OBJECT(a->object,p);
87 if (a->set)
88 ret+=i2d_ASN1_SET_OF_ASN1_TYPE(a->value.set,p,i2d_ASN1_TYPE,
89 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
90 else
91 ret+=i2d_ASN1_TYPE(a->value.single,p);
92 if (k++) return(r);
93 }
94 }
95
96X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, unsigned char **pp,
97 long length)
98 {
99 M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new);
100
101 M_ASN1_D2I_Init();
102 M_ASN1_D2I_start_sequence();
103 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
104
105 if ((c.slen != 0) &&
106 (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET)))
107 {
108 ret->set=1;
109 M_ASN1_D2I_get_set_type(ASN1_TYPE,ret->value.set,d2i_ASN1_TYPE,
110 ASN1_TYPE_free);
111 }
112 else
113 {
114 ret->set=0;
115 M_ASN1_D2I_get(ret->value.single,d2i_ASN1_TYPE);
116 }
117
118 M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE);
119 }
120
121X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
122 {
123 X509_ATTRIBUTE *ret=NULL;
124 ASN1_TYPE *val=NULL;
125
126 if ((ret=X509_ATTRIBUTE_new()) == NULL)
127 return(NULL);
128 ret->object=OBJ_nid2obj(nid);
129 ret->set=1;
130 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
131 if ((val=ASN1_TYPE_new()) == NULL) goto err;
132 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
133
134 ASN1_TYPE_set(val,atrtype,value);
135 return(ret);
136err:
137 if (ret != NULL) X509_ATTRIBUTE_free(ret);
138 if (val != NULL) ASN1_TYPE_free(val);
139 return(NULL);
140 }
141
142X509_ATTRIBUTE *X509_ATTRIBUTE_new(void)
143 {
144 X509_ATTRIBUTE *ret=NULL;
145 ASN1_CTX c;
146
147 M_ASN1_New_Malloc(ret,X509_ATTRIBUTE);
148 ret->object=OBJ_nid2obj(NID_undef);
149 ret->set=0;
150 ret->value.ptr=NULL;
151 return(ret);
152 M_ASN1_New_Error(ASN1_F_X509_ATTRIBUTE_NEW);
153 }
154
155void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a)
156 {
157 if (a == NULL) return;
158 ASN1_OBJECT_free(a->object);
159 if (a->set)
160 sk_ASN1_TYPE_pop_free(a->value.set,ASN1_TYPE_free);
161 else
162 ASN1_TYPE_free(a->value.single);
163 OPENSSL_free(a);
164 }
165
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
deleted file mode 100644
index 51518cdf35..0000000000
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ /dev/null
@@ -1,348 +0,0 @@
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/asn1_mac.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);
68int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **pp)
69 {
70 M_ASN1_I2D_vars(a);
71
72 M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER);
73 M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_TIME);
74 M_ASN1_I2D_len_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
75 i2d_X509_EXTENSION);
76
77 M_ASN1_I2D_seq_total();
78
79 M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER);
80 M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_TIME);
81 M_ASN1_I2D_put_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
82 i2d_X509_EXTENSION);
83
84 M_ASN1_I2D_finish();
85 }
86
87X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **a, unsigned char **pp,
88 long length)
89 {
90 M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new);
91
92 M_ASN1_D2I_Init();
93 M_ASN1_D2I_start_sequence();
94 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER);
95 M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_TIME);
96 M_ASN1_D2I_get_seq_opt_type(X509_EXTENSION,ret->extensions,
97 d2i_X509_EXTENSION,X509_EXTENSION_free);
98 M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED);
99 }
100
101int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
102 {
103 int v1=0;
104 long l=0;
105 int (*old_cmp)(const X509_REVOKED * const *,
106 const X509_REVOKED * const *);
107 M_ASN1_I2D_vars(a);
108
109 old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp);
110 sk_X509_REVOKED_sort(a->revoked);
111 sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp);
112
113 if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0))
114 {
115 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
116 }
117 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
118 M_ASN1_I2D_len(a->issuer,i2d_X509_NAME);
119 M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_TIME);
120 if (a->nextUpdate != NULL)
121 { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_TIME); }
122 M_ASN1_I2D_len_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
123 i2d_X509_REVOKED);
124 M_ASN1_I2D_len_EXP_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
125 i2d_X509_EXTENSION,0,
126 V_ASN1_SEQUENCE,v1);
127
128 M_ASN1_I2D_seq_total();
129
130 if ((a->version != NULL) && (l != 0))
131 {
132 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
133 }
134 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
135 M_ASN1_I2D_put(a->issuer,i2d_X509_NAME);
136 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_TIME);
137 if (a->nextUpdate != NULL)
138 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_TIME); }
139 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
140 i2d_X509_REVOKED);
141 M_ASN1_I2D_put_EXP_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
142 i2d_X509_EXTENSION,0,
143 V_ASN1_SEQUENCE,v1);
144
145 M_ASN1_I2D_finish();
146 }
147
148X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp,
149 long length)
150 {
151 int i,ver=0;
152 M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new);
153
154
155 M_ASN1_D2I_Init();
156 M_ASN1_D2I_start_sequence();
157 M_ASN1_D2I_get_opt(ret->version,d2i_ASN1_INTEGER,V_ASN1_INTEGER);
158 if (ret->version != NULL)
159 ver=ret->version->data[0];
160
161 if ((ver == 0) && (ret->version != NULL))
162 {
163 M_ASN1_INTEGER_free(ret->version);
164 ret->version=NULL;
165 }
166 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
167 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
168 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME);
169 /* Manually handle the OPTIONAL ASN1_TIME stuff */
170 /* First try UTCTime */
171 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME, V_ASN1_UTCTIME);
172 /* If that doesn't work try GeneralizedTime */
173 if(!ret->nextUpdate)
174 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME,
175 V_ASN1_GENERALIZEDTIME);
176 if (ret->revoked != NULL)
177 {
178 while (sk_X509_REVOKED_num(ret->revoked))
179 X509_REVOKED_free(sk_X509_REVOKED_pop(ret->revoked));
180 }
181 M_ASN1_D2I_get_seq_opt_type(X509_REVOKED,ret->revoked,d2i_X509_REVOKED,
182 X509_REVOKED_free);
183
184 if (ret->revoked != NULL)
185 {
186 for (i=0; i<sk_X509_REVOKED_num(ret->revoked); i++)
187 {
188 sk_X509_REVOKED_value(ret->revoked,i)->sequence=i;
189 }
190 }
191
192 if (ret->extensions != NULL)
193 {
194 while (sk_X509_EXTENSION_num(ret->extensions))
195 X509_EXTENSION_free(
196 sk_X509_EXTENSION_pop(ret->extensions));
197 }
198
199 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
200 d2i_X509_EXTENSION,
201 X509_EXTENSION_free,0,
202 V_ASN1_SEQUENCE);
203
204 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO);
205 }
206
207int i2d_X509_CRL(X509_CRL *a, unsigned char **pp)
208 {
209 M_ASN1_I2D_vars(a);
210
211 M_ASN1_I2D_len(a->crl,i2d_X509_CRL_INFO);
212 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
213 M_ASN1_I2D_len(a->signature,i2d_ASN1_BIT_STRING);
214
215 M_ASN1_I2D_seq_total();
216
217 M_ASN1_I2D_put(a->crl,i2d_X509_CRL_INFO);
218 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
219 M_ASN1_I2D_put(a->signature,i2d_ASN1_BIT_STRING);
220
221 M_ASN1_I2D_finish();
222 }
223
224X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length)
225 {
226 M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new);
227
228 M_ASN1_D2I_Init();
229 M_ASN1_D2I_start_sequence();
230 M_ASN1_D2I_get(ret->crl,d2i_X509_CRL_INFO);
231 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
232 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
233
234 M_ASN1_D2I_Finish(a,X509_CRL_free,ASN1_F_D2I_X509_CRL);
235 }
236
237
238X509_REVOKED *X509_REVOKED_new(void)
239 {
240 X509_REVOKED *ret=NULL;
241 ASN1_CTX c;
242
243 M_ASN1_New_Malloc(ret,X509_REVOKED);
244 M_ASN1_New(ret->serialNumber,M_ASN1_INTEGER_new);
245 M_ASN1_New(ret->revocationDate,M_ASN1_UTCTIME_new);
246 ret->extensions=NULL;
247 return(ret);
248 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW);
249 }
250
251X509_CRL_INFO *X509_CRL_INFO_new(void)
252 {
253 X509_CRL_INFO *ret=NULL;
254 ASN1_CTX c;
255
256 M_ASN1_New_Malloc(ret,X509_CRL_INFO);
257 ret->version=NULL;
258 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
259 M_ASN1_New(ret->issuer,X509_NAME_new);
260 M_ASN1_New(ret->lastUpdate,M_ASN1_UTCTIME_new);
261 ret->nextUpdate=NULL;
262 M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null);
263 ret->extensions = NULL;
264 sk_X509_REVOKED_set_cmp_func(ret->revoked,X509_REVOKED_cmp);
265 return(ret);
266 M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW);
267 }
268
269X509_CRL *X509_CRL_new(void)
270 {
271 X509_CRL *ret=NULL;
272 ASN1_CTX c;
273
274 M_ASN1_New_Malloc(ret,X509_CRL);
275 ret->references=1;
276 M_ASN1_New(ret->crl,X509_CRL_INFO_new);
277 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
278 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
279 return(ret);
280 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW);
281 }
282
283void X509_REVOKED_free(X509_REVOKED *a)
284 {
285 if (a == NULL) return;
286 M_ASN1_INTEGER_free(a->serialNumber);
287 M_ASN1_UTCTIME_free(a->revocationDate);
288 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
289 OPENSSL_free(a);
290 }
291
292void X509_CRL_INFO_free(X509_CRL_INFO *a)
293 {
294 if (a == NULL) return;
295 M_ASN1_INTEGER_free(a->version);
296 X509_ALGOR_free(a->sig_alg);
297 X509_NAME_free(a->issuer);
298 M_ASN1_UTCTIME_free(a->lastUpdate);
299 if (a->nextUpdate)
300 M_ASN1_UTCTIME_free(a->nextUpdate);
301 sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free);
302 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
303 OPENSSL_free(a);
304 }
305
306void X509_CRL_free(X509_CRL *a)
307 {
308 int i;
309
310 if (a == NULL) return;
311
312 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_CRL);
313#ifdef REF_PRINT
314 REF_PRINT("X509_CRL",a);
315#endif
316 if (i > 0) return;
317#ifdef REF_CHECK
318 if (i < 0)
319 {
320 fprintf(stderr,"X509_CRL_free, bad reference count\n");
321 abort();
322 }
323#endif
324
325 X509_CRL_INFO_free(a->crl);
326 X509_ALGOR_free(a->sig_alg);
327 M_ASN1_BIT_STRING_free(a->signature);
328 OPENSSL_free(a);
329 }
330
331static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
332 const X509_REVOKED * const *b)
333 {
334 return(ASN1_STRING_cmp(
335 (ASN1_STRING *)(*a)->serialNumber,
336 (ASN1_STRING *)(*b)->serialNumber));
337 }
338
339static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a,
340 const X509_REVOKED * const *b)
341 {
342 return((*a)->sequence-(*b)->sequence);
343 }
344
345IMPLEMENT_STACK_OF(X509_REVOKED)
346IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
347IMPLEMENT_STACK_OF(X509_CRL)
348IMPLEMENT_ASN1_SET_OF(X509_CRL)
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
deleted file mode 100644
index fbfd963b40..0000000000
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/* crypto/asn1/x_exten.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/asn1_mac.h>
63#include <openssl/x509.h>
64
65int i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **pp)
66 {
67 int k=0;
68 int r=0,ret=0;
69 unsigned char **p=NULL;
70
71 if (a == NULL) return(0);
72
73 p=NULL;
74 for (;;)
75 {
76 if (k)
77 {
78 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
79 if (pp == NULL) return(r);
80 p=pp;
81 ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
82 V_ASN1_UNIVERSAL);
83 }
84
85 ret+=i2d_ASN1_OBJECT(a->object,p);
86 if ((a->critical) || a->netscape_hack)
87 ret+=i2d_ASN1_BOOLEAN(a->critical,p);
88 ret+=i2d_ASN1_OCTET_STRING(a->value,p);
89 if (k++) return(r);
90 }
91 }
92
93X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, unsigned char **pp,
94 long length)
95 {
96 int i;
97 M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new);
98
99 M_ASN1_D2I_Init();
100 M_ASN1_D2I_start_sequence();
101 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
102
103 ret->netscape_hack=0;
104 if ((c.slen != 0) &&
105 (M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN)))
106 {
107 c.q=c.p;
108 if (d2i_ASN1_BOOLEAN(&i,&c.p,c.slen) < 0) goto err;
109 ret->critical=i;
110 c.slen-=(c.p-c.q);
111 if (ret->critical == 0) ret->netscape_hack=1;
112 }
113 M_ASN1_D2I_get(ret->value,d2i_ASN1_OCTET_STRING);
114
115 M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION);
116 }
117
118X509_EXTENSION *X509_EXTENSION_new(void)
119 {
120 X509_EXTENSION *ret=NULL;
121 ASN1_CTX c;
122
123 M_ASN1_New_Malloc(ret,X509_EXTENSION);
124 ret->object=OBJ_nid2obj(NID_undef);
125 M_ASN1_New(ret->value,M_ASN1_OCTET_STRING_new);
126 ret->critical=0;
127 ret->netscape_hack=0;
128 return(ret);
129 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW);
130 }
131
132void X509_EXTENSION_free(X509_EXTENSION *a)
133 {
134 if (a == NULL) return;
135 ASN1_OBJECT_free(a->object);
136 M_ASN1_OCTET_STRING_free(a->value);
137 OPENSSL_free(a);
138 }
139
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
deleted file mode 100644
index 5e62fc2f6f..0000000000
--- a/src/lib/libcrypto/asn1/x_info.c
+++ /dev/null
@@ -1,114 +0,0 @@
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_mac.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_name.c b/src/lib/libcrypto/asn1/x_name.c
deleted file mode 100644
index 1885d699ef..0000000000
--- a/src/lib/libcrypto/asn1/x_name.c
+++ /dev/null
@@ -1,281 +0,0 @@
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/objects.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65static int i2d_X509_NAME_entries(X509_NAME *a);
66int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a, unsigned char **pp)
67 {
68 M_ASN1_I2D_vars(a);
69
70 M_ASN1_I2D_len(a->object,i2d_ASN1_OBJECT);
71 M_ASN1_I2D_len(a->value,i2d_ASN1_PRINTABLE);
72
73 M_ASN1_I2D_seq_total();
74
75 M_ASN1_I2D_put(a->object,i2d_ASN1_OBJECT);
76 M_ASN1_I2D_put(a->value,i2d_ASN1_PRINTABLE);
77
78 M_ASN1_I2D_finish();
79 }
80
81X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, unsigned char **pp,
82 long length)
83 {
84 M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new);
85
86 M_ASN1_D2I_Init();
87 M_ASN1_D2I_start_sequence();
88 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
89 M_ASN1_D2I_get(ret->value,d2i_ASN1_PRINTABLE);
90 ret->set=0;
91 M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY);
92 }
93
94int i2d_X509_NAME(X509_NAME *a, unsigned char **pp)
95 {
96 int ret;
97
98 if (a == NULL) return(0);
99 if (a->modified)
100 {
101 ret=i2d_X509_NAME_entries(a);
102 if (ret < 0) return(ret);
103 }
104
105 ret=a->bytes->length;
106 if (pp != NULL)
107 {
108 memcpy(*pp,a->bytes->data,ret);
109 *pp+=ret;
110 }
111 return(ret);
112 }
113
114static int i2d_X509_NAME_entries(X509_NAME *a)
115 {
116 X509_NAME_ENTRY *ne,*fe=NULL;
117 STACK_OF(X509_NAME_ENTRY) *sk;
118 BUF_MEM *buf=NULL;
119 int set=0,r,ret=0;
120 int i;
121 unsigned char *p;
122 int size=0;
123
124 sk=a->entries;
125 for (i=0; i<sk_X509_NAME_ENTRY_num(sk); i++)
126 {
127 ne=sk_X509_NAME_ENTRY_value(sk,i);
128 if (fe == NULL)
129 {
130 fe=ne;
131 size=0;
132 }
133
134 if (ne->set != set)
135 {
136 ret+=ASN1_object_size(1,size,V_ASN1_SET);
137 fe->size=size;
138 fe=ne;
139 size=0;
140 set=ne->set;
141 }
142 size+=i2d_X509_NAME_ENTRY(ne,NULL);
143 }
144 if (fe != NULL)
145 {
146 /* SET OF needed only if entries is non empty */
147 ret+=ASN1_object_size(1,size,V_ASN1_SET);
148 fe->size=size;
149 }
150
151 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
152
153 buf=a->bytes;
154 if (!BUF_MEM_grow(buf,r)) goto err;
155 p=(unsigned char *)buf->data;
156
157 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
158
159 set= -1;
160 for (i=0; i<sk_X509_NAME_ENTRY_num(sk); i++)
161 {
162 ne=sk_X509_NAME_ENTRY_value(sk,i);
163 if (set != ne->set)
164 {
165 set=ne->set;
166 ASN1_put_object(&p,1,ne->size,
167 V_ASN1_SET,V_ASN1_UNIVERSAL);
168 }
169 i2d_X509_NAME_ENTRY(ne,&p);
170 }
171 a->modified=0;
172 return(r);
173err:
174 return(-1);
175 }
176
177X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length)
178 {
179 int set=0,i;
180 int idx=0;
181 unsigned char *orig;
182 M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new);
183
184 orig= *pp;
185 if (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
186 {
187 while (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
188 X509_NAME_ENTRY_free(
189 sk_X509_NAME_ENTRY_pop(ret->entries));
190 }
191
192 M_ASN1_D2I_Init();
193 M_ASN1_D2I_start_sequence();
194 for (;;)
195 {
196 if (M_ASN1_D2I_end_sequence()) break;
197 M_ASN1_D2I_get_set_type(X509_NAME_ENTRY,ret->entries,
198 d2i_X509_NAME_ENTRY,
199 X509_NAME_ENTRY_free);
200 for (; idx < sk_X509_NAME_ENTRY_num(ret->entries); idx++)
201 {
202 sk_X509_NAME_ENTRY_value(ret->entries,idx)->set=set;
203 }
204 set++;
205 }
206
207 i=(int)(c.p-orig);
208 if (!BUF_MEM_grow(ret->bytes,i)) goto err;
209 memcpy(ret->bytes->data,orig,i);
210 ret->bytes->length=i;
211 ret->modified=0;
212
213 M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME);
214 }
215
216X509_NAME *X509_NAME_new(void)
217 {
218 X509_NAME *ret=NULL;
219 ASN1_CTX c;
220
221 M_ASN1_New_Malloc(ret,X509_NAME);
222 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL)
223 { c.line=__LINE__; goto err2; }
224 M_ASN1_New(ret->bytes,BUF_MEM_new);
225 ret->modified=1;
226 return(ret);
227 M_ASN1_New_Error(ASN1_F_X509_NAME_NEW);
228 }
229
230X509_NAME_ENTRY *X509_NAME_ENTRY_new(void)
231 {
232 X509_NAME_ENTRY *ret=NULL;
233 ASN1_CTX c;
234
235 M_ASN1_New_Malloc(ret,X509_NAME_ENTRY);
236/* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/
237 ret->object=NULL;
238 ret->set=0;
239 M_ASN1_New(ret->value,ASN1_STRING_new);
240 return(ret);
241 M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW);
242 }
243
244void X509_NAME_free(X509_NAME *a)
245 {
246 if(a == NULL)
247 return;
248
249 BUF_MEM_free(a->bytes);
250 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
251 OPENSSL_free(a);
252 }
253
254void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)
255 {
256 if (a == NULL) return;
257 ASN1_OBJECT_free(a->object);
258 M_ASN1_BIT_STRING_free(a->value);
259 OPENSSL_free(a);
260 }
261
262int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
263 {
264 X509_NAME *in;
265
266 if (*xn == NULL) return(0);
267
268 if (*xn != name)
269 {
270 in=X509_NAME_dup(name);
271 if (in != NULL)
272 {
273 X509_NAME_free(*xn);
274 *xn=in;
275 }
276 }
277 return(*xn != NULL);
278 }
279
280IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
281IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
deleted file mode 100644
index f1c6221ac3..0000000000
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ /dev/null
@@ -1,151 +0,0 @@
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
deleted file mode 100644
index 4397a404b5..0000000000
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ /dev/null
@@ -1,366 +0,0 @@
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/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_PUBKEY(X509_PUBKEY *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
69 M_ASN1_I2D_len(a->public_key, i2d_ASN1_BIT_STRING);
70
71 M_ASN1_I2D_seq_total();
72
73 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
74 M_ASN1_I2D_put(a->public_key, i2d_ASN1_BIT_STRING);
75
76 M_ASN1_I2D_finish();
77 }
78
79X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **a, unsigned char **pp,
80 long length)
81 {
82 M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new);
83
84 M_ASN1_D2I_Init();
85 M_ASN1_D2I_start_sequence();
86 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
87 M_ASN1_D2I_get(ret->public_key,d2i_ASN1_BIT_STRING);
88 if (ret->pkey != NULL)
89 {
90 EVP_PKEY_free(ret->pkey);
91 ret->pkey=NULL;
92 }
93 M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY);
94 }
95
96X509_PUBKEY *X509_PUBKEY_new(void)
97 {
98 X509_PUBKEY *ret=NULL;
99 ASN1_CTX c;
100
101 M_ASN1_New_Malloc(ret,X509_PUBKEY);
102 M_ASN1_New(ret->algor,X509_ALGOR_new);
103 M_ASN1_New(ret->public_key,M_ASN1_BIT_STRING_new);
104 ret->pkey=NULL;
105 return(ret);
106 M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW);
107 }
108
109void X509_PUBKEY_free(X509_PUBKEY *a)
110 {
111 if (a == NULL) return;
112 X509_ALGOR_free(a->algor);
113 M_ASN1_BIT_STRING_free(a->public_key);
114 if (a->pkey != NULL) EVP_PKEY_free(a->pkey);
115 OPENSSL_free(a);
116 }
117
118int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
119 {
120 int ok=0;
121 X509_PUBKEY *pk;
122 X509_ALGOR *a;
123 ASN1_OBJECT *o;
124 unsigned char *s,*p;
125 int i;
126
127 if (x == NULL) return(0);
128
129 if ((pk=X509_PUBKEY_new()) == NULL) goto err;
130 a=pk->algor;
131
132 /* set the algorithm id */
133 if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
134 ASN1_OBJECT_free(a->algorithm);
135 a->algorithm=o;
136
137 /* Set the parameter list */
138 if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))
139 {
140 if ((a->parameter == NULL) ||
141 (a->parameter->type != V_ASN1_NULL))
142 {
143 ASN1_TYPE_free(a->parameter);
144 a->parameter=ASN1_TYPE_new();
145 a->parameter->type=V_ASN1_NULL;
146 }
147 }
148 else
149#ifndef NO_DSA
150 if (pkey->type == EVP_PKEY_DSA)
151 {
152 unsigned char *pp;
153 DSA *dsa;
154
155 dsa=pkey->pkey.dsa;
156 dsa->write_params=0;
157 ASN1_TYPE_free(a->parameter);
158 i=i2d_DSAparams(dsa,NULL);
159 p=(unsigned char *)OPENSSL_malloc(i);
160 pp=p;
161 i2d_DSAparams(dsa,&pp);
162 a->parameter=ASN1_TYPE_new();
163 a->parameter->type=V_ASN1_SEQUENCE;
164 a->parameter->value.sequence=ASN1_STRING_new();
165 ASN1_STRING_set(a->parameter->value.sequence,p,i);
166 OPENSSL_free(p);
167 }
168 else
169#endif
170 {
171 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
172 goto err;
173 }
174
175 if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
176 if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL) goto err;
177 p=s;
178 i2d_PublicKey(pkey,&p);
179 if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
180 /* Set number of unused bits to zero */
181 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
182 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
183
184 OPENSSL_free(s);
185
186#if 0
187 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
188 pk->pkey=pkey;
189#endif
190
191 if (*x != NULL)
192 X509_PUBKEY_free(*x);
193
194 *x=pk;
195 pk=NULL;
196
197 ok=1;
198err:
199 if (pk != NULL) X509_PUBKEY_free(pk);
200 return(ok);
201 }
202
203EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
204 {
205 EVP_PKEY *ret=NULL;
206 long j;
207 int type;
208 unsigned char *p;
209#ifndef NO_DSA
210 X509_ALGOR *a;
211#endif
212
213 if (key == NULL) goto err;
214
215 if (key->pkey != NULL)
216 {
217 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
218 return(key->pkey);
219 }
220
221 if (key->public_key == NULL) goto err;
222
223 type=OBJ_obj2nid(key->algor->algorithm);
224 p=key->public_key->data;
225 j=key->public_key->length;
226 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
227 {
228 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
229 goto err;
230 }
231 ret->save_parameters=0;
232
233#ifndef NO_DSA
234 a=key->algor;
235 if (ret->type == EVP_PKEY_DSA)
236 {
237 if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
238 {
239 ret->pkey.dsa->write_params=0;
240 p=a->parameter->value.sequence->data;
241 j=a->parameter->value.sequence->length;
242 if (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))
243 goto err;
244 }
245 ret->save_parameters=1;
246 }
247#endif
248 key->pkey=ret;
249 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
250 return(ret);
251err:
252 if (ret != NULL)
253 EVP_PKEY_free(ret);
254 return(NULL);
255 }
256
257/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
258 * and encode or decode as X509_PUBKEY
259 */
260
261EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
262 long length)
263{
264 X509_PUBKEY *xpk;
265 EVP_PKEY *pktmp;
266 xpk = d2i_X509_PUBKEY(NULL, pp, length);
267 if(!xpk) return NULL;
268 pktmp = X509_PUBKEY_get(xpk);
269 X509_PUBKEY_free(xpk);
270 if(!pktmp) return NULL;
271 if(a) {
272 EVP_PKEY_free(*a);
273 *a = pktmp;
274 }
275 return pktmp;
276}
277
278int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
279{
280 X509_PUBKEY *xpk=NULL;
281 int ret;
282 if(!a) return 0;
283 if(!X509_PUBKEY_set(&xpk, a)) return 0;
284 ret = i2d_X509_PUBKEY(xpk, pp);
285 X509_PUBKEY_free(xpk);
286 return ret;
287}
288
289/* The following are equivalents but which return RSA and DSA
290 * keys
291 */
292#ifndef NO_RSA
293RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
294 long length)
295{
296 EVP_PKEY *pkey;
297 RSA *key;
298 unsigned char *q;
299 q = *pp;
300 pkey = d2i_PUBKEY(NULL, &q, length);
301 if(!pkey) return NULL;
302 key = EVP_PKEY_get1_RSA(pkey);
303 EVP_PKEY_free(pkey);
304 if(!key) return NULL;
305 *pp = q;
306 if(a) {
307 RSA_free(*a);
308 *a = key;
309 }
310 return key;
311}
312
313int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
314{
315 EVP_PKEY *pktmp;
316 int ret;
317 if(!a) return 0;
318 pktmp = EVP_PKEY_new();
319 if(!pktmp) {
320 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
321 return 0;
322 }
323 EVP_PKEY_set1_RSA(pktmp, a);
324 ret = i2d_PUBKEY(pktmp, pp);
325 EVP_PKEY_free(pktmp);
326 return ret;
327}
328#endif
329
330#ifndef NO_DSA
331DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
332 long length)
333{
334 EVP_PKEY *pkey;
335 DSA *key;
336 unsigned char *q;
337 q = *pp;
338 pkey = d2i_PUBKEY(NULL, &q, length);
339 if(!pkey) return NULL;
340 key = EVP_PKEY_get1_DSA(pkey);
341 EVP_PKEY_free(pkey);
342 if(!key) return NULL;
343 *pp = q;
344 if(a) {
345 DSA_free(*a);
346 *a = key;
347 }
348 return key;
349}
350
351int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
352{
353 EVP_PKEY *pktmp;
354 int ret;
355 if(!a) return 0;
356 pktmp = EVP_PKEY_new();
357 if(!pktmp) {
358 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
359 return 0;
360 }
361 EVP_PKEY_set1_DSA(pktmp, a);
362 ret = i2d_PUBKEY(pktmp, pp);
363 EVP_PKEY_free(pktmp);
364 return ret;
365}
366#endif
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
deleted file mode 100644
index 6dddd4f653..0000000000
--- a/src/lib/libcrypto/asn1/x_req.c
+++ /dev/null
@@ -1,257 +0,0 @@
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/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 if(a->asn1) {
69 if(pp) {
70 memcpy(*pp, a->asn1, a->length);
71 *pp += a->length;
72 }
73 return a->length;
74 }
75
76 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
77 M_ASN1_I2D_len(a->subject, i2d_X509_NAME);
78 M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY);
79
80 /* this is a *nasty* hack reported to be required to
81 * allow some CA Software to accept the cert request.
82 * It is not following the PKCS standards ...
83 * PKCS#10 pg 5
84 * attributes [0] IMPLICIT Attributes
85 * NOTE: no OPTIONAL ... so it *must* be there
86 */
87 if (a->req_kludge)
88 {
89 M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,i2d_X509_ATTRIBUTE,0);
90 }
91 else
92 {
93 M_ASN1_I2D_len_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
94 i2d_X509_ATTRIBUTE,0);
95 }
96
97 M_ASN1_I2D_seq_total();
98 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
99 M_ASN1_I2D_put(a->subject, i2d_X509_NAME);
100 M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY);
101
102 /* this is a *nasty* hack reported to be required by some CA's.
103 * It is not following the PKCS standards ...
104 * PKCS#10 pg 5
105 * attributes [0] IMPLICIT Attributes
106 * NOTE: no OPTIONAL ... so it *must* be there
107 */
108 if (a->req_kludge)
109 {
110 M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,
111 i2d_X509_ATTRIBUTE,0);
112 }
113 else
114 {
115 M_ASN1_I2D_put_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
116 i2d_X509_ATTRIBUTE,0);
117 }
118
119 M_ASN1_I2D_finish();
120 }
121
122X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, unsigned char **pp,
123 long length)
124 {
125 M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new);
126
127 M_ASN1_D2I_Init();
128 M_ASN1_D2I_start_sequence();
129 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
130 M_ASN1_D2I_get(ret->subject,d2i_X509_NAME);
131 M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY);
132
133 /* this is a *nasty* hack to allow for some CA's that
134 * have been reported as requiring it.
135 * It is not following the PKCS standards ...
136 * PKCS#10 pg 5
137 * attributes [0] IMPLICIT Attributes
138 * NOTE: no OPTIONAL ... so it *must* be there
139 */
140 if (asn1_Finish(&c))
141 ret->req_kludge=1;
142 else
143 {
144 M_ASN1_D2I_get_IMP_set_type(X509_ATTRIBUTE,ret->attributes,
145 d2i_X509_ATTRIBUTE,
146 X509_ATTRIBUTE_free,0);
147 }
148
149 M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO);
150 }
151
152X509_REQ_INFO *X509_REQ_INFO_new(void)
153 {
154 X509_REQ_INFO *ret=NULL;
155 ASN1_CTX c;
156
157 M_ASN1_New_Malloc(ret,X509_REQ_INFO);
158 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
159 M_ASN1_New(ret->subject,X509_NAME_new);
160 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
161 M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null);
162 ret->req_kludge=0;
163 ret->asn1 = NULL;
164 return(ret);
165 M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW);
166 }
167
168void X509_REQ_INFO_free(X509_REQ_INFO *a)
169 {
170 if (a == NULL) return;
171 if(a->asn1) OPENSSL_free(a->asn1);
172 M_ASN1_INTEGER_free(a->version);
173 X509_NAME_free(a->subject);
174 X509_PUBKEY_free(a->pubkey);
175 sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free);
176 OPENSSL_free(a);
177 }
178
179int i2d_X509_REQ(X509_REQ *a, unsigned char **pp)
180 {
181 M_ASN1_I2D_vars(a);
182 M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO);
183 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
184 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
185
186 M_ASN1_I2D_seq_total();
187
188 M_ASN1_I2D_put(a->req_info, i2d_X509_REQ_INFO);
189 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
190 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
191
192 M_ASN1_I2D_finish();
193 }
194
195X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length)
196 {
197 M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new);
198
199 M_ASN1_D2I_Init();
200 M_ASN1_D2I_start_sequence();
201 M_ASN1_D2I_get(ret->req_info,d2i_X509_REQ_INFO);
202
203 /* Keep a copy of the original encoding for signature checking */
204 ret->req_info->length = c.p - c.q;
205 if(!(ret->req_info->asn1 = OPENSSL_malloc(ret->req_info->length))) {
206 c.line=__LINE__;
207 c.error = ERR_R_MALLOC_FAILURE;
208 goto err;
209 }
210
211 memcpy(ret->req_info->asn1, c.q, ret->req_info->length);
212
213 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
214 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
215 M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ);
216 }
217
218X509_REQ *X509_REQ_new(void)
219 {
220 X509_REQ *ret=NULL;
221 ASN1_CTX c;
222
223 M_ASN1_New_Malloc(ret,X509_REQ);
224 ret->references=1;
225 M_ASN1_New(ret->req_info,X509_REQ_INFO_new);
226 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
227 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
228 return(ret);
229 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW);
230 }
231
232void X509_REQ_free(X509_REQ *a)
233 {
234 int i;
235
236 if (a == NULL) return;
237
238 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_REQ);
239#ifdef REF_PRINT
240 REF_PRINT("X509_REQ",a);
241#endif
242 if (i > 0) return;
243#ifdef REF_CHECK
244 if (i < 0)
245 {
246 fprintf(stderr,"X509_REQ_free, bad reference count\n");
247 abort();
248 }
249#endif
250
251 X509_REQ_INFO_free(a->req_info);
252 X509_ALGOR_free(a->sig_alg);
253 M_ASN1_BIT_STRING_free(a->signature);
254 OPENSSL_free(a);
255 }
256
257
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
deleted file mode 100644
index d79f147647..0000000000
--- a/src/lib/libcrypto/asn1/x_sig.c
+++ /dev/null
@@ -1,110 +0,0 @@
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/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_SIG(X509_SIG *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
69 M_ASN1_I2D_len(a->digest, i2d_ASN1_OCTET_STRING);
70
71 M_ASN1_I2D_seq_total();
72
73 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
74 M_ASN1_I2D_put(a->digest, i2d_ASN1_OCTET_STRING);
75
76 M_ASN1_I2D_finish();
77 }
78
79X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length)
80 {
81 M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new);
82
83 M_ASN1_D2I_Init();
84 M_ASN1_D2I_start_sequence();
85 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
86 M_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING);
87 M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG);
88 }
89
90X509_SIG *X509_SIG_new(void)
91 {
92 X509_SIG *ret=NULL;
93 ASN1_CTX c;
94
95 M_ASN1_New_Malloc(ret,X509_SIG);
96 M_ASN1_New(ret->algor,X509_ALGOR_new);
97 M_ASN1_New(ret->digest,M_ASN1_OCTET_STRING_new);
98 return(ret);
99 M_ASN1_New_Error(ASN1_F_X509_SIG_NEW);
100 }
101
102void X509_SIG_free(X509_SIG *a)
103 {
104 if (a == NULL) return;
105 X509_ALGOR_free(a->algor);
106 M_ASN1_OCTET_STRING_free(a->digest);
107 OPENSSL_free(a);
108 }
109
110
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c
deleted file mode 100644
index 4f01888f7d..0000000000
--- a/src/lib/libcrypto/asn1/x_spki.c
+++ /dev/null
@@ -1,166 +0,0 @@
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/asn1_mac.h>
67
68int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a, unsigned char **pp)
69 {
70 M_ASN1_I2D_vars(a);
71
72 M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY);
73 M_ASN1_I2D_len(a->challenge, i2d_ASN1_IA5STRING);
74
75 M_ASN1_I2D_seq_total();
76
77 M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY);
78 M_ASN1_I2D_put(a->challenge, i2d_ASN1_IA5STRING);
79
80 M_ASN1_I2D_finish();
81 }
82
83NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a, unsigned char **pp,
84 long length)
85 {
86 M_ASN1_D2I_vars(a,NETSCAPE_SPKAC *,NETSCAPE_SPKAC_new);
87
88 M_ASN1_D2I_Init();
89 M_ASN1_D2I_start_sequence();
90 M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY);
91 M_ASN1_D2I_get(ret->challenge,d2i_ASN1_IA5STRING);
92 M_ASN1_D2I_Finish(a,NETSCAPE_SPKAC_free,ASN1_F_D2I_NETSCAPE_SPKAC);
93 }
94
95NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void)
96 {
97 NETSCAPE_SPKAC *ret=NULL;
98 ASN1_CTX c;
99
100 M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC);
101 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
102 M_ASN1_New(ret->challenge,M_ASN1_IA5STRING_new);
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW);
105 }
106
107void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a)
108 {
109 if (a == NULL) return;
110 X509_PUBKEY_free(a->pubkey);
111 M_ASN1_IA5STRING_free(a->challenge);
112 OPENSSL_free(a);
113 }
114
115int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **pp)
116 {
117 M_ASN1_I2D_vars(a);
118
119 M_ASN1_I2D_len(a->spkac, i2d_NETSCAPE_SPKAC);
120 M_ASN1_I2D_len(a->sig_algor, i2d_X509_ALGOR);
121 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
122
123 M_ASN1_I2D_seq_total();
124
125 M_ASN1_I2D_put(a->spkac, i2d_NETSCAPE_SPKAC);
126 M_ASN1_I2D_put(a->sig_algor, i2d_X509_ALGOR);
127 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
128
129 M_ASN1_I2D_finish();
130 }
131
132NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a, unsigned char **pp,
133 long length)
134 {
135 M_ASN1_D2I_vars(a,NETSCAPE_SPKI *,NETSCAPE_SPKI_new);
136
137 M_ASN1_D2I_Init();
138 M_ASN1_D2I_start_sequence();
139 M_ASN1_D2I_get(ret->spkac,d2i_NETSCAPE_SPKAC);
140 M_ASN1_D2I_get(ret->sig_algor,d2i_X509_ALGOR);
141 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
142 M_ASN1_D2I_Finish(a,NETSCAPE_SPKI_free,ASN1_F_D2I_NETSCAPE_SPKI);
143 }
144
145NETSCAPE_SPKI *NETSCAPE_SPKI_new(void)
146 {
147 NETSCAPE_SPKI *ret=NULL;
148 ASN1_CTX c;
149
150 M_ASN1_New_Malloc(ret,NETSCAPE_SPKI);
151 M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new);
152 M_ASN1_New(ret->sig_algor,X509_ALGOR_new);
153 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
154 return(ret);
155 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW);
156 }
157
158void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a)
159 {
160 if (a == NULL) return;
161 NETSCAPE_SPKAC_free(a->spkac);
162 X509_ALGOR_free(a->sig_algor);
163 M_ASN1_BIT_STRING_free(a->signature);
164 OPENSSL_free(a);
165 }
166
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c
deleted file mode 100644
index 0f8f020b57..0000000000
--- a/src/lib/libcrypto/asn1/x_val.c
+++ /dev/null
@@ -1,109 +0,0 @@
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/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_VAL(X509_VAL *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->notBefore,i2d_ASN1_TIME);
69 M_ASN1_I2D_len(a->notAfter,i2d_ASN1_TIME);
70
71 M_ASN1_I2D_seq_total();
72
73 M_ASN1_I2D_put(a->notBefore,i2d_ASN1_TIME);
74 M_ASN1_I2D_put(a->notAfter,i2d_ASN1_TIME);
75
76 M_ASN1_I2D_finish();
77 }
78
79X509_VAL *d2i_X509_VAL(X509_VAL **a, unsigned char **pp, long length)
80 {
81 M_ASN1_D2I_vars(a,X509_VAL *,X509_VAL_new);
82
83 M_ASN1_D2I_Init();
84 M_ASN1_D2I_start_sequence();
85 M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_TIME);
86 M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_TIME);
87 M_ASN1_D2I_Finish(a,X509_VAL_free,ASN1_F_D2I_X509_VAL);
88 }
89
90X509_VAL *X509_VAL_new(void)
91 {
92 X509_VAL *ret=NULL;
93 ASN1_CTX c;
94
95 M_ASN1_New_Malloc(ret,X509_VAL);
96 M_ASN1_New(ret->notBefore,M_ASN1_TIME_new);
97 M_ASN1_New(ret->notAfter,M_ASN1_TIME_new);
98 return(ret);
99 M_ASN1_New_Error(ASN1_F_X509_VAL_NEW);
100 }
101
102void X509_VAL_free(X509_VAL *a)
103 {
104 if (a == NULL) return;
105 M_ASN1_TIME_free(a->notBefore);
106 M_ASN1_TIME_free(a->notAfter);
107 OPENSSL_free(a);
108 }
109
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
deleted file mode 100644
index 61ba856b17..0000000000
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ /dev/null
@@ -1,216 +0,0 @@
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/asn1_mac.h>
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66static int x509_meth_num = 0;
67static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_meth = NULL;
68
69static ASN1_METHOD meth={
70 (int (*)()) i2d_X509,
71 (char *(*)())d2i_X509,
72 (char *(*)())X509_new,
73 (void (*)()) X509_free};
74
75ASN1_METHOD *X509_asn1_meth(void)
76 {
77 return(&meth);
78 }
79
80int i2d_X509(X509 *a, unsigned char **pp)
81 {
82 M_ASN1_I2D_vars(a);
83
84 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
85 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
86 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
87
88 M_ASN1_I2D_seq_total();
89
90 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
91 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
92 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
93
94 M_ASN1_I2D_finish();
95 }
96
97X509 *d2i_X509(X509 **a, unsigned char **pp, long length)
98 {
99 M_ASN1_D2I_vars(a,X509 *,X509_new);
100
101 M_ASN1_D2I_Init();
102 M_ASN1_D2I_start_sequence();
103 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
104 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
105 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
106 if (ret->name != NULL) OPENSSL_free(ret->name);
107 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
108
109 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
110 }
111
112X509 *X509_new(void)
113 {
114 X509 *ret=NULL;
115 ASN1_CTX c;
116
117 M_ASN1_New_Malloc(ret,X509);
118 ret->valid=0;
119 ret->references=1;
120 ret->name = NULL;
121 ret->ex_flags = 0;
122 ret->ex_pathlen = -1;
123 ret->skid = NULL;
124 ret->akid = NULL;
125 ret->aux = NULL;
126 M_ASN1_New(ret->cert_info,X509_CINF_new);
127 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
128 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
129 CRYPTO_new_ex_data(x509_meth, ret, &ret->ex_data);
130 return(ret);
131 M_ASN1_New_Error(ASN1_F_X509_NEW);
132 }
133
134void X509_free(X509 *a)
135 {
136 int i;
137
138 if (a == NULL) return;
139
140 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509);
141#ifdef REF_PRINT
142 REF_PRINT("X509",a);
143#endif
144 if (i > 0) return;
145#ifdef REF_CHECK
146 if (i < 0)
147 {
148 fprintf(stderr,"X509_free, bad reference count\n");
149 abort();
150 }
151#endif
152
153 CRYPTO_free_ex_data(x509_meth,a,&a->ex_data);
154 X509_CINF_free(a->cert_info);
155 X509_ALGOR_free(a->sig_alg);
156 M_ASN1_BIT_STRING_free(a->signature);
157 X509_CERT_AUX_free(a->aux);
158 ASN1_OCTET_STRING_free(a->skid);
159 AUTHORITY_KEYID_free(a->akid);
160
161 if (a->name != NULL) OPENSSL_free(a->name);
162 OPENSSL_free(a);
163 }
164
165int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
166 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
167 {
168 x509_meth_num++;
169 return(CRYPTO_get_ex_new_index(x509_meth_num-1,
170 &x509_meth,argl,argp,new_func,dup_func,free_func));
171 }
172
173int X509_set_ex_data(X509 *r, int idx, void *arg)
174 {
175 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
176 }
177
178void *X509_get_ex_data(X509 *r, int idx)
179 {
180 return(CRYPTO_get_ex_data(&r->ex_data,idx));
181 }
182
183/* X509_AUX ASN1 routines. X509_AUX is the name given to
184 * a certificate with extra info tagged on the end. Since these
185 * functions set how a certificate is trusted they should only
186 * be used when the certificate comes from a reliable source
187 * such as local storage.
188 *
189 */
190
191X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
192{
193 unsigned char *q;
194 X509 *ret;
195 /* Save start position */
196 q = *pp;
197 ret = d2i_X509(a, pp, length);
198 /* If certificate unreadable then forget it */
199 if(!ret) return NULL;
200 /* update length */
201 length -= *pp - q;
202 if(!length) return ret;
203 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err;
204 return ret;
205 err:
206 X509_free(ret);
207 return NULL;
208}
209
210int i2d_X509_AUX(X509 *a, unsigned char **pp)
211{
212 int length;
213 length = i2d_X509(a, pp);
214 if(a) length += i2d_X509_CERT_AUX(a->aux, pp);
215 return length;
216}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
deleted file mode 100644
index ebcce87bf2..0000000000
--- a/src/lib/libcrypto/asn1/x_x509a.c
+++ /dev/null
@@ -1,208 +0,0 @@
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/asn1_mac.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
74X509_CERT_AUX *d2i_X509_CERT_AUX(X509_CERT_AUX **a, unsigned char **pp, long length)
75{
76 M_ASN1_D2I_vars(a, X509_CERT_AUX *, X509_CERT_AUX_new);
77
78 M_ASN1_D2I_Init();
79 M_ASN1_D2I_start_sequence();
80
81 M_ASN1_D2I_get_seq_opt_type(ASN1_OBJECT, ret->trust,
82 d2i_ASN1_OBJECT, ASN1_OBJECT_free);
83 M_ASN1_D2I_get_IMP_set_opt_type(ASN1_OBJECT, ret->reject,
84 d2i_ASN1_OBJECT, ASN1_OBJECT_free, 0);
85 M_ASN1_D2I_get_opt(ret->alias, d2i_ASN1_UTF8STRING, V_ASN1_UTF8STRING);
86 M_ASN1_D2I_get_opt(ret->keyid, d2i_ASN1_OCTET_STRING, V_ASN1_OCTET_STRING);
87 M_ASN1_D2I_get_IMP_set_opt_type(X509_ALGOR, ret->other,
88 d2i_X509_ALGOR, X509_ALGOR_free, 1);
89
90 M_ASN1_D2I_Finish(a, X509_CERT_AUX_free, ASN1_F_D2I_X509_CERT_AUX);
91}
92
93X509_CERT_AUX *X509_CERT_AUX_new()
94{
95 X509_CERT_AUX *ret = NULL;
96 ASN1_CTX c;
97 M_ASN1_New_Malloc(ret, X509_CERT_AUX);
98 ret->trust = NULL;
99 ret->reject = NULL;
100 ret->alias = NULL;
101 ret->keyid = NULL;
102 ret->other = NULL;
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_CERT_AUX_NEW);
105}
106
107void X509_CERT_AUX_free(X509_CERT_AUX *a)
108{
109 if(a == NULL) return;
110 sk_ASN1_OBJECT_pop_free(a->trust, ASN1_OBJECT_free);
111 sk_ASN1_OBJECT_pop_free(a->reject, ASN1_OBJECT_free);
112 ASN1_UTF8STRING_free(a->alias);
113 ASN1_OCTET_STRING_free(a->keyid);
114 sk_X509_ALGOR_pop_free(a->other, X509_ALGOR_free);
115 OPENSSL_free(a);
116}
117
118int i2d_X509_CERT_AUX(X509_CERT_AUX *a, unsigned char **pp)
119{
120 M_ASN1_I2D_vars(a);
121
122 M_ASN1_I2D_len_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
123 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
124
125 M_ASN1_I2D_len(a->alias, i2d_ASN1_UTF8STRING);
126 M_ASN1_I2D_len(a->keyid, i2d_ASN1_OCTET_STRING);
127 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
128
129 M_ASN1_I2D_seq_total();
130
131 M_ASN1_I2D_put_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
132 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
133
134 M_ASN1_I2D_put(a->alias, i2d_ASN1_UTF8STRING);
135 M_ASN1_I2D_put(a->keyid, i2d_ASN1_OCTET_STRING);
136 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
137
138 M_ASN1_I2D_finish();
139}
140
141static X509_CERT_AUX *aux_get(X509 *x)
142{
143 if(!x) return NULL;
144 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
145 return x->aux;
146}
147
148int X509_alias_set1(X509 *x, unsigned char *name, int len)
149{
150 X509_CERT_AUX *aux;
151 if(!(aux = aux_get(x))) return 0;
152 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
153 return ASN1_STRING_set(aux->alias, name, len);
154}
155
156int X509_keyid_set1(X509 *x, unsigned char *id, int len)
157{
158 X509_CERT_AUX *aux;
159 if(!(aux = aux_get(x))) return 0;
160 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0;
161 return ASN1_STRING_set(aux->keyid, id, len);
162}
163
164unsigned char *X509_alias_get0(X509 *x, int *len)
165{
166 if(!x->aux || !x->aux->alias) return NULL;
167 if(len) *len = x->aux->alias->length;
168 return x->aux->alias->data;
169}
170
171int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
172{
173 X509_CERT_AUX *aux;
174 ASN1_OBJECT *objtmp;
175 if(!(objtmp = OBJ_dup(obj))) return 0;
176 if(!(aux = aux_get(x))) return 0;
177 if(!aux->trust
178 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
179 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
180}
181
182int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
183{
184 X509_CERT_AUX *aux;
185 ASN1_OBJECT *objtmp;
186 if(!(objtmp = OBJ_dup(obj))) return 0;
187 if(!(aux = aux_get(x))) return 0;
188 if(!aux->reject
189 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
190 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
191}
192
193void X509_trust_clear(X509 *x)
194{
195 if(x->aux && x->aux->trust) {
196 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
197 x->aux->trust = NULL;
198 }
199}
200
201void X509_reject_clear(X509 *x)
202{
203 if(x->aux && x->aux->reject) {
204 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
205 x->aux->reject = NULL;
206 }
207}
208