summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c231
-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.c337
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c113
-rw-r--r--src/lib/libcrypto/asn1/a_int.c435
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c390
-rw-r--r--src/lib/libcrypto/asn1/a_object.c304
-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_strnid.c247
-rw-r--r--src/lib/libcrypto/asn1/a_time.c129
-rw-r--r--src/lib/libcrypto/asn1/a_type.c348
-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.h1067
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c352
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c424
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h560
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c385
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c145
-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.c348
-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.c409
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c102
-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.c343
-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.c279
-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.c236
-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.c210
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c200
60 files changed, 0 insertions, 13764 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
deleted file mode 100644
index c77456b315..0000000000
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ /dev/null
@@ -1,231 +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 ret,j,r,bits,len;
75 unsigned char *p,*d;
76
77 if (a == NULL) return(0);
78
79 len=a->length;
80
81 if (len > 0)
82 {
83 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
84 {
85 bits=(int)a->flags&0x07;
86 }
87 else
88 {
89 for ( ; len > 0; len--)
90 {
91 if (a->data[len-1]) break;
92 }
93 j=a->data[len-1];
94 if (j & 0x01) bits=0;
95 else if (j & 0x02) bits=1;
96 else if (j & 0x04) bits=2;
97 else if (j & 0x08) bits=3;
98 else if (j & 0x10) bits=4;
99 else if (j & 0x20) bits=5;
100 else if (j & 0x40) bits=6;
101 else if (j & 0x80) bits=7;
102 else bits=0; /* should not happen */
103 }
104 }
105 else
106 bits=0;
107 ret=1+len;
108 r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING);
109 if (pp == NULL) return(r);
110 p= *pp;
111
112 ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL);
113 *(p++)=(unsigned char)bits;
114 d=a->data;
115 memcpy(p,d,len);
116 p+=len;
117 if (len > 0) p[-1]&=(0xff<<bits);
118 *pp=p;
119 return(r);
120 }
121
122ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
123 long length)
124 {
125 ASN1_BIT_STRING *ret=NULL;
126 unsigned char *p,*s;
127 long len;
128 int inf,tag,xclass;
129 int i;
130
131 if ((a == NULL) || ((*a) == NULL))
132 {
133 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
134 }
135 else
136 ret=(*a);
137
138 p= *pp;
139 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
140 if (inf & 0x80)
141 {
142 i=ASN1_R_BAD_OBJECT_HEADER;
143 goto err;
144 }
145
146 if (tag != V_ASN1_BIT_STRING)
147 {
148 i=ASN1_R_EXPECTING_A_BIT_STRING;
149 goto err;
150 }
151 if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; }
152
153 i= *(p++);
154 /* We do this to preserve the settings. If we modify
155 * the settings, via the _set_bit function, we will recalculate
156 * on output */
157 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
158 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
159
160 if (len-- > 1) /* using one because of the bits left byte */
161 {
162 s=(unsigned char *)Malloc((int)len);
163 if (s == NULL)
164 {
165 i=ERR_R_MALLOC_FAILURE;
166 goto err;
167 }
168 memcpy(s,p,(int)len);
169 s[len-1]&=(0xff<<i);
170 p+=len;
171 }
172 else
173 s=NULL;
174
175 ret->length=(int)len;
176 if (ret->data != NULL) Free(ret->data);
177 ret->data=s;
178 ret->type=V_ASN1_BIT_STRING;
179 if (a != NULL) (*a)=ret;
180 *pp=p;
181 return(ret);
182err:
183 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
184 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
185 M_ASN1_BIT_STRING_free(ret);
186 return(NULL);
187 }
188
189/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
190 */
191int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
192 {
193 int w,v,iv;
194 unsigned char *c;
195
196 w=n/8;
197 v=1<<(7-(n&0x07));
198 iv= ~v;
199
200 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
201
202 if (a == NULL) return(0);
203 if ((a->length < (w+1)) || (a->data == NULL))
204 {
205 if (!value) return(1); /* Don't need to set */
206 if (a->data == NULL)
207 c=(unsigned char *)Malloc(w+1);
208 else
209 c=(unsigned char *)Realloc(a->data,w+1);
210 if (c == NULL) return(0);
211 a->data=c;
212 a->length=w+1;
213 c[w]=0;
214 }
215 a->data[w]=((a->data[w])&iv)|v;
216 while ((a->length > 0) && (a->data[a->length-1] == 0))
217 a->length--;
218 return(1);
219 }
220
221int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
222 {
223 int w,v;
224
225 w=n/8;
226 v=1<<(7-(n&0x07));
227 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
228 return(0);
229 return((a->data[w]&v) != 0);
230 }
231
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 8cde695804..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 *)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) 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) Free(ret->data);
222 s=(unsigned char *)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) 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) 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) 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 3370aae998..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 *)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 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 3202a816d0..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 *)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 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 ccf62e5a04..0000000000
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ /dev/null
@@ -1,337 +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
74int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
75 {
76 int pad=0,ret,r,i,t;
77 unsigned char *p,*n,pb=0;
78
79 if ((a == NULL) || (a->data == NULL)) return(0);
80 t=a->type;
81 if (a->length == 0)
82 ret=1;
83 else
84 {
85 ret=a->length;
86 i=a->data[0];
87 if ((t == V_ASN1_ENUMERATED) && (i > 127)) {
88 pad=1;
89 pb=0;
90 } else if(t == V_ASN1_NEG_ENUMERATED) {
91 if(i>128) {
92 pad=1;
93 pb=0xFF;
94 } else if(i == 128) {
95 for(i = 1; i < a->length; i++) if(a->data[i]) {
96 pad=1;
97 pb=0xFF;
98 break;
99 }
100 }
101 }
102 ret+=pad;
103 }
104 r=ASN1_object_size(0,ret,V_ASN1_ENUMERATED);
105 if (pp == NULL) return(r);
106 p= *pp;
107
108 ASN1_put_object(&p,0,ret,V_ASN1_ENUMERATED,V_ASN1_UNIVERSAL);
109 if (pad) *(p++)=pb;
110 if (a->length == 0)
111 *(p++)=0;
112 else if (t == V_ASN1_ENUMERATED)
113 {
114 memcpy(p,a->data,(unsigned int)a->length);
115 p+=a->length;
116 }
117 else {
118 /* Begin at the end of the encoding */
119 n=a->data + a->length - 1;
120 p += a->length - 1;
121 i = a->length;
122 /* Copy zeros to destination as long as source is zero */
123 while(!*n) {
124 *(p--) = 0;
125 n--;
126 i--;
127 }
128 /* Complement and increment next octet */
129 *(p--) = ((*(n--)) ^ 0xff) + 1;
130 i--;
131 /* Complement any octets left */
132 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
133 p += a->length;
134 }
135
136 *pp=p;
137 return(r);
138 }
139
140ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
141 long length)
142 {
143 ASN1_ENUMERATED *ret=NULL;
144 unsigned char *p,*to,*s;
145 long len;
146 int inf,tag,xclass;
147 int i;
148
149 if ((a == NULL) || ((*a) == NULL))
150 {
151 if ((ret=M_ASN1_ENUMERATED_new()) == NULL) return(NULL);
152 ret->type=V_ASN1_ENUMERATED;
153 }
154 else
155 ret=(*a);
156
157 p= *pp;
158 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
159 if (inf & 0x80)
160 {
161 i=ASN1_R_BAD_OBJECT_HEADER;
162 goto err;
163 }
164
165 if (tag != V_ASN1_ENUMERATED)
166 {
167 i=ASN1_R_EXPECTING_AN_ENUMERATED;
168 goto err;
169 }
170
171 /* We must Malloc stuff, even for 0 bytes otherwise it
172 * signifies a missing NULL parameter. */
173 s=(unsigned char *)Malloc((int)len+1);
174 if (s == NULL)
175 {
176 i=ERR_R_MALLOC_FAILURE;
177 goto err;
178 }
179 to=s;
180 if(!len) {
181 /* Strictly speaking this is an illegal ENUMERATED but we
182 * tolerate it.
183 */
184 ret->type=V_ASN1_ENUMERATED;
185 } else if (*p & 0x80) /* a negative number */
186 {
187 ret->type=V_ASN1_NEG_ENUMERATED;
188 if ((*p == 0xff) && (len != 1)) {
189 p++;
190 len--;
191 }
192 i = len;
193 p += i - 1;
194 to += i - 1;
195 while((!*p) && i) {
196 *(to--) = 0;
197 i--;
198 p--;
199 }
200 if(!i) {
201 *s = 1;
202 s[len] = 0;
203 p += len;
204 len++;
205 } else {
206 *(to--) = (*(p--) ^ 0xff) + 1;
207 i--;
208 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
209 p += len;
210 }
211 } else {
212 ret->type=V_ASN1_ENUMERATED;
213 if ((*p == 0) && (len != 1))
214 {
215 p++;
216 len--;
217 }
218 memcpy(s,p,(int)len);
219 p+=len;
220 }
221
222 if (ret->data != NULL) Free(ret->data);
223 ret->data=s;
224 ret->length=(int)len;
225 if (a != NULL) (*a)=ret;
226 *pp=p;
227 return(ret);
228err:
229 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
230 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
231 M_ASN1_ENUMERATED_free(ret);
232 return(NULL);
233 }
234
235int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
236 {
237 int i,j,k;
238 unsigned char buf[sizeof(long)+1];
239 long d;
240
241 a->type=V_ASN1_ENUMERATED;
242 if (a->length < (sizeof(long)+1))
243 {
244 if (a->data != NULL)
245 Free(a->data);
246 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
247 memset((char *)a->data,0,sizeof(long)+1);
248 }
249 if (a->data == NULL)
250 {
251 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
252 return(0);
253 }
254 d=v;
255 if (d < 0)
256 {
257 d= -d;
258 a->type=V_ASN1_NEG_ENUMERATED;
259 }
260
261 for (i=0; i<sizeof(long); i++)
262 {
263 if (d == 0) break;
264 buf[i]=(int)d&0xff;
265 d>>=8;
266 }
267 j=0;
268 for (k=i-1; k >=0; k--)
269 a->data[j++]=buf[k];
270 a->length=j;
271 return(1);
272 }
273
274long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
275 {
276 int neg=0,i;
277 long r=0;
278
279 if (a == NULL) return(0L);
280 i=a->type;
281 if (i == V_ASN1_NEG_ENUMERATED)
282 neg=1;
283 else if (i != V_ASN1_ENUMERATED)
284 return(0);
285
286 if (a->length > sizeof(long))
287 {
288 /* hmm... a bit ugly */
289 return(0xffffffffL);
290 }
291 if (a->data == NULL)
292 return(0);
293
294 for (i=0; i<a->length; i++)
295 {
296 r<<=8;
297 r|=(unsigned char)a->data[i];
298 }
299 if (neg) r= -r;
300 return(r);
301 }
302
303ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
304 {
305 ASN1_ENUMERATED *ret;
306 int len,j;
307
308 if (ai == NULL)
309 ret=M_ASN1_ENUMERATED_new();
310 else
311 ret=ai;
312 if (ret == NULL)
313 {
314 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
315 goto err;
316 }
317 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
318 else ret->type=V_ASN1_ENUMERATED;
319 j=BN_num_bits(bn);
320 len=((j == 0)?0:((j/8)+1));
321 ret->data=(unsigned char *)Malloc(len+4);
322 ret->length=BN_bn2bin(bn,ret->data);
323 return(ret);
324err:
325 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
326 return(NULL);
327 }
328
329BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
330 {
331 BIGNUM *ret;
332
333 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
334 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
335 if(ai->type == V_ASN1_NEG_ENUMERATED) bn->neg = 1;
336 return(ret);
337 }
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 d9b8035e17..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 *)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 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 8b6794e8c1..0000000000
--- a/src/lib/libcrypto/asn1/a_int.c
+++ /dev/null
@@ -1,435 +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/*
76 * This converts an ASN1 INTEGER into its DER encoding.
77 * The internal representation is an ASN1_STRING whose data is a big endian
78 * representation of the value, ignoring the sign. The sign is determined by
79 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
80 *
81 * Positive integers are no problem: they are almost the same as the DER
82 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
83 *
84 * Negative integers are a bit trickier...
85 * The DER representation of negative integers is in 2s complement form.
86 * The internal form is converted by complementing each octet and finally
87 * adding one to the result. This can be done less messily with a little trick.
88 * If the internal form has trailing zeroes then they will become FF by the
89 * complement and 0 by the add one (due to carry) so just copy as many trailing
90 * zeros to the destination as there are in the source. The carry will add one
91 * to the last none zero octet: so complement this octet and add one and finally
92 * complement any left over until you get to the start of the string.
93 *
94 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
95 * with 0xff. However if the first byte is 0x80 and one of the following bytes
96 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
97 * followed by optional zeros isn't padded.
98 */
99
100int i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
101 {
102 int pad=0,ret,r,i,t;
103 unsigned char *p,*n,pb=0;
104
105 if ((a == NULL) || (a->data == NULL)) return(0);
106 t=a->type;
107 if (a->length == 0)
108 ret=1;
109 else
110 {
111 ret=a->length;
112 i=a->data[0];
113 if ((t == V_ASN1_INTEGER) && (i > 127)) {
114 pad=1;
115 pb=0;
116 } else if(t == V_ASN1_NEG_INTEGER) {
117 if(i>128) {
118 pad=1;
119 pb=0xFF;
120 } else if(i == 128) {
121 /*
122 * Special case: if any other bytes non zero we pad:
123 * otherwise we don't.
124 */
125 for(i = 1; i < a->length; i++) if(a->data[i]) {
126 pad=1;
127 pb=0xFF;
128 break;
129 }
130 }
131 }
132 ret+=pad;
133 }
134 r=ASN1_object_size(0,ret,V_ASN1_INTEGER);
135 if (pp == NULL) return(r);
136 p= *pp;
137
138 ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL);
139 if (pad) *(p++)=pb;
140 if (a->length == 0) *(p++)=0;
141 else if (t == V_ASN1_INTEGER) memcpy(p,a->data,(unsigned int)a->length);
142 else {
143 /* Begin at the end of the encoding */
144 n=a->data + a->length - 1;
145 p += a->length - 1;
146 i = a->length;
147 /* Copy zeros to destination as long as source is zero */
148 while(!*n) {
149 *(p--) = 0;
150 n--;
151 i--;
152 }
153 /* Complement and increment next octet */
154 *(p--) = ((*(n--)) ^ 0xff) + 1;
155 i--;
156 /* Complement any octets left */
157 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
158 }
159
160 *pp+=r;
161 return(r);
162 }
163
164ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
165 long length)
166 {
167 ASN1_INTEGER *ret=NULL;
168 unsigned char *p,*to,*s, *pend;
169 long len;
170 int inf,tag,xclass;
171 int i;
172
173 if ((a == NULL) || ((*a) == NULL))
174 {
175 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
176 ret->type=V_ASN1_INTEGER;
177 }
178 else
179 ret=(*a);
180
181 p= *pp;
182 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
183 pend = p + len;
184 if (inf & 0x80)
185 {
186 i=ASN1_R_BAD_OBJECT_HEADER;
187 goto err;
188 }
189
190 if (tag != V_ASN1_INTEGER)
191 {
192 i=ASN1_R_EXPECTING_AN_INTEGER;
193 goto err;
194 }
195
196 /* We must Malloc stuff, even for 0 bytes otherwise it
197 * signifies a missing NULL parameter. */
198 s=(unsigned char *)Malloc((int)len+1);
199 if (s == NULL)
200 {
201 i=ERR_R_MALLOC_FAILURE;
202 goto err;
203 }
204 to=s;
205 if(!len) {
206 /* Strictly speaking this is an illegal INTEGER but we
207 * tolerate it.
208 */
209 ret->type=V_ASN1_INTEGER;
210 } else if (*p & 0x80) /* a negative number */
211 {
212 ret->type=V_ASN1_NEG_INTEGER;
213 if ((*p == 0xff) && (len != 1)) {
214 p++;
215 len--;
216 }
217 i = len;
218 p += i - 1;
219 to += i - 1;
220 while((!*p) && i) {
221 *(to--) = 0;
222 i--;
223 p--;
224 }
225 /* Special case: if all zeros then the number will be of
226 * the form FF followed by n zero bytes: this corresponds to
227 * 1 followed by n zero bytes. We've already written n zeros
228 * so we just append an extra one and set the first byte to
229 * a 1. This is treated separately because it is the only case
230 * where the number of bytes is larger than len.
231 */
232 if(!i) {
233 *s = 1;
234 s[len] = 0;
235 len++;
236 } else {
237 *(to--) = (*(p--) ^ 0xff) + 1;
238 i--;
239 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
240 }
241 } else {
242 ret->type=V_ASN1_INTEGER;
243 if ((*p == 0) && (len != 1))
244 {
245 p++;
246 len--;
247 }
248 memcpy(s,p,(int)len);
249 }
250
251 if (ret->data != NULL) Free(ret->data);
252 ret->data=s;
253 ret->length=(int)len;
254 if (a != NULL) (*a)=ret;
255 *pp=pend;
256 return(ret);
257err:
258 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
260 M_ASN1_INTEGER_free(ret);
261 return(NULL);
262 }
263
264/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
265 * ASN1 integers: some broken software can encode a positive INTEGER
266 * with its MSB set as negative (it doesn't add a padding zero).
267 */
268
269ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
270 long length)
271 {
272 ASN1_INTEGER *ret=NULL;
273 unsigned char *p,*to,*s;
274 long len;
275 int inf,tag,xclass;
276 int i;
277
278 if ((a == NULL) || ((*a) == NULL))
279 {
280 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
281 ret->type=V_ASN1_INTEGER;
282 }
283 else
284 ret=(*a);
285
286 p= *pp;
287 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
288 if (inf & 0x80)
289 {
290 i=ASN1_R_BAD_OBJECT_HEADER;
291 goto err;
292 }
293
294 if (tag != V_ASN1_INTEGER)
295 {
296 i=ASN1_R_EXPECTING_AN_INTEGER;
297 goto err;
298 }
299
300 /* We must Malloc stuff, even for 0 bytes otherwise it
301 * signifies a missing NULL parameter. */
302 s=(unsigned char *)Malloc((int)len+1);
303 if (s == NULL)
304 {
305 i=ERR_R_MALLOC_FAILURE;
306 goto err;
307 }
308 to=s;
309 ret->type=V_ASN1_INTEGER;
310 if(len) {
311 if ((*p == 0) && (len != 1))
312 {
313 p++;
314 len--;
315 }
316 memcpy(s,p,(int)len);
317 p+=len;
318 }
319
320 if (ret->data != NULL) Free(ret->data);
321 ret->data=s;
322 ret->length=(int)len;
323 if (a != NULL) (*a)=ret;
324 *pp=p;
325 return(ret);
326err:
327 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
328 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
329 M_ASN1_INTEGER_free(ret);
330 return(NULL);
331 }
332
333int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
334 {
335 int i,j,k;
336 unsigned char buf[sizeof(long)+1];
337 long d;
338
339 a->type=V_ASN1_INTEGER;
340 if (a->length < (sizeof(long)+1))
341 {
342 if (a->data != NULL)
343 Free(a->data);
344 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
345 memset((char *)a->data,0,sizeof(long)+1);
346 }
347 if (a->data == NULL)
348 {
349 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
350 return(0);
351 }
352 d=v;
353 if (d < 0)
354 {
355 d= -d;
356 a->type=V_ASN1_NEG_INTEGER;
357 }
358
359 for (i=0; i<sizeof(long); i++)
360 {
361 if (d == 0) break;
362 buf[i]=(int)d&0xff;
363 d>>=8;
364 }
365 j=0;
366 for (k=i-1; k >=0; k--)
367 a->data[j++]=buf[k];
368 a->length=j;
369 return(1);
370 }
371
372long ASN1_INTEGER_get(ASN1_INTEGER *a)
373 {
374 int neg=0,i;
375 long r=0;
376
377 if (a == NULL) return(0L);
378 i=a->type;
379 if (i == V_ASN1_NEG_INTEGER)
380 neg=1;
381 else if (i != V_ASN1_INTEGER)
382 return(0);
383
384 if (a->length > sizeof(long))
385 {
386 /* hmm... a bit ugly */
387 return(0xffffffffL);
388 }
389 if (a->data == NULL)
390 return(0);
391
392 for (i=0; i<a->length; i++)
393 {
394 r<<=8;
395 r|=(unsigned char)a->data[i];
396 }
397 if (neg) r= -r;
398 return(r);
399 }
400
401ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
402 {
403 ASN1_INTEGER *ret;
404 int len,j;
405
406 if (ai == NULL)
407 ret=M_ASN1_INTEGER_new();
408 else
409 ret=ai;
410 if (ret == NULL)
411 {
412 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
413 goto err;
414 }
415 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
416 else ret->type=V_ASN1_INTEGER;
417 j=BN_num_bits(bn);
418 len=((j == 0)?0:((j/8)+1));
419 ret->data=(unsigned char *)Malloc(len+4);
420 ret->length=BN_bn2bin(bn,ret->data);
421 return(ret);
422err:
423 if (ret != ai) M_ASN1_INTEGER_free(ret);
424 return(NULL);
425 }
426
427BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
428 {
429 BIGNUM *ret;
430
431 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
432 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
433 if(ai->type == V_ASN1_NEG_INTEGER) bn->neg = 1;
434 return(ret);
435 }
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
deleted file mode 100644
index 7a710d5459..0000000000
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ /dev/null
@@ -1,390 +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 int outform, outlen;
96 ASN1_STRING *dest;
97 unsigned char *p;
98 int nchar;
99 char strbuf[32];
100 int (*cpyfunc)(unsigned long,void *) = NULL;
101 if(len == -1) len = strlen((const char *)in);
102 if(!mask) mask = DIRSTRING_TYPE;
103
104 /* First do a string check and work out the number of characters */
105 switch(inform) {
106
107 case MBSTRING_BMP:
108 if(len & 1) {
109 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
110 ASN1_R_INVALID_BMPSTRING_LENGTH);
111 return -1;
112 }
113 nchar = len >> 1;
114 break;
115
116 case MBSTRING_UNIV:
117 if(len & 3) {
118 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
119 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
120 return -1;
121 }
122 nchar = len >> 2;
123 break;
124
125 case MBSTRING_UTF8:
126 nchar = 0;
127 /* This counts the characters and does utf8 syntax checking */
128 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
129 if(ret < 0) {
130 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
131 ASN1_R_INVALID_UTF8STRING);
132 return -1;
133 }
134 break;
135
136 case MBSTRING_ASC:
137 nchar = len;
138 break;
139
140 default:
141 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
142 return -1;
143 }
144
145 if((minsize > 0) && (nchar < minsize)) {
146 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
147 sprintf(strbuf, "%ld", minsize);
148 ERR_add_error_data(2, "minsize=", strbuf);
149 return -1;
150 }
151
152 if((maxsize > 0) && (nchar > maxsize)) {
153 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
154 sprintf(strbuf, "%ld", maxsize);
155 ERR_add_error_data(2, "maxsize=", strbuf);
156 return -1;
157 }
158
159 /* Now work out minimal type (if any) */
160 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
161 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
162 return -1;
163 }
164
165
166 /* Now work out output format and string type */
167 outform = MBSTRING_ASC;
168 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
169 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
170 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
171 else if(mask & B_ASN1_BMPSTRING) {
172 str_type = V_ASN1_BMPSTRING;
173 outform = MBSTRING_BMP;
174 } else if(mask & B_ASN1_UNIVERSALSTRING) {
175 str_type = V_ASN1_UNIVERSALSTRING;
176 outform = MBSTRING_UNIV;
177 } else {
178 str_type = V_ASN1_UTF8STRING;
179 outform = MBSTRING_UTF8;
180 }
181 if(!out) return str_type;
182 if(*out) {
183 dest = *out;
184 if(dest->data) {
185 dest->length = 0;
186 Free(dest->data);
187 dest->data = NULL;
188 }
189 dest->type = str_type;
190 } else {
191 dest = ASN1_STRING_type_new(str_type);
192 if(!dest) {
193 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
194 ERR_R_MALLOC_FAILURE);
195 return -1;
196 }
197 *out = dest;
198 }
199 /* If both the same type just copy across */
200 if(inform == outform) {
201 if(!ASN1_STRING_set(dest, in, len)) {
202 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
203 return -1;
204 }
205 return str_type;
206 }
207
208 /* Work out how much space the destination will need */
209 switch(outform) {
210 case MBSTRING_ASC:
211 outlen = nchar;
212 cpyfunc = cpy_asc;
213 break;
214
215 case MBSTRING_BMP:
216 outlen = nchar << 1;
217 cpyfunc = cpy_bmp;
218 break;
219
220 case MBSTRING_UNIV:
221 outlen = nchar << 2;
222 cpyfunc = cpy_univ;
223 break;
224
225 case MBSTRING_UTF8:
226 outlen = 0;
227 traverse_string(in, len, inform, out_utf8, &outlen);
228 cpyfunc = cpy_utf8;
229 break;
230 }
231 if(!(p = Malloc(outlen + 1))) {
232 ASN1_STRING_free(dest);
233 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
234 return -1;
235 }
236 dest->length = outlen;
237 dest->data = p;
238 p[outlen] = 0;
239 traverse_string(in, len, inform, cpyfunc, &p);
240 return str_type;
241}
242
243/* This function traverses a string and passes the value of each character
244 * to an optional function along with a void * argument.
245 */
246
247static int traverse_string(const unsigned char *p, int len, int inform,
248 int (*rfunc)(unsigned long value, void *in), void *arg)
249{
250 unsigned long value;
251 int ret;
252 while(len) {
253 if(inform == MBSTRING_ASC) {
254 value = *p++;
255 len--;
256 } else if(inform == MBSTRING_BMP) {
257 value = *p++ << 8;
258 value |= *p++;
259 len -= 2;
260 } else if(inform == MBSTRING_UNIV) {
261 value = *p++ << 24;
262 value |= *p++ << 16;
263 value |= *p++ << 8;
264 value |= *p++;
265 len -= 4;
266 } else {
267 ret = UTF8_getc(p, len, &value);
268 if(ret < 0) return -1;
269 len -= ret;
270 p += ret;
271 }
272 if(rfunc) {
273 ret = rfunc(value, arg);
274 if(ret <= 0) return ret;
275 }
276 }
277 return 1;
278}
279
280/* Various utility functions for traverse_string */
281
282/* Just count number of characters */
283
284static int in_utf8(unsigned long value, void *arg)
285{
286 int *nchar;
287 nchar = arg;
288 (*nchar)++;
289 return 1;
290}
291
292/* Determine size of output as a UTF8 String */
293
294static int out_utf8(unsigned long value, void *arg)
295{
296 long *outlen;
297 outlen = arg;
298 *outlen += UTF8_putc(NULL, -1, value);
299 return 1;
300}
301
302/* Determine the "type" of a string: check each character against a
303 * supplied "mask".
304 */
305
306static int type_str(unsigned long value, void *arg)
307{
308 unsigned long types;
309 types = *((unsigned long *)arg);
310 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
311 types &= ~B_ASN1_PRINTABLESTRING;
312 if((types & B_ASN1_IA5STRING) && (value > 127))
313 types &= ~B_ASN1_IA5STRING;
314 if((types & B_ASN1_T61STRING) && (value > 0xff))
315 types &= ~B_ASN1_T61STRING;
316 if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
317 types &= ~B_ASN1_BMPSTRING;
318 if(!types) return -1;
319 *((unsigned long *)arg) = types;
320 return 1;
321}
322
323/* Copy one byte per character ASCII like strings */
324
325static int cpy_asc(unsigned long value, void *arg)
326{
327 unsigned char **p, *q;
328 p = arg;
329 q = *p;
330 *q = (unsigned char) value;
331 (*p)++;
332 return 1;
333}
334
335/* Copy two byte per character BMPStrings */
336
337static int cpy_bmp(unsigned long value, void *arg)
338{
339 unsigned char **p, *q;
340 p = arg;
341 q = *p;
342 *q++ = (unsigned char) ((value >> 8) & 0xff);
343 *q = (unsigned char) (value & 0xff);
344 *p += 2;
345 return 1;
346}
347
348/* Copy four byte per character UniversalStrings */
349
350static int cpy_univ(unsigned long value, void *arg)
351{
352 unsigned char **p, *q;
353 p = arg;
354 q = *p;
355 *q++ = (unsigned char) ((value >> 24) & 0xff);
356 *q++ = (unsigned char) ((value >> 16) & 0xff);
357 *q++ = (unsigned char) ((value >> 8) & 0xff);
358 *q = (unsigned char) (value & 0xff);
359 *p += 4;
360 return 1;
361}
362
363/* Copy to a UTF8String */
364
365static int cpy_utf8(unsigned long value, void *arg)
366{
367 unsigned char **p;
368 int ret;
369 p = arg;
370 /* We already know there is enough room so pass 0xff as the length */
371 ret = UTF8_putc(*p, 0xff, value);
372 *p += ret;
373 return 1;
374}
375
376/* Return 1 if the character is permitted in a PrintableString */
377static int is_printable(unsigned long value)
378{
379 int ch;
380 if(value > 0x7f) return 0;
381 ch = (int) value;
382 /* Note: we can't use 'isalnum' because certain accented
383 * characters may count as alphanumeric in some environments.
384 */
385 if((ch >= 'a') && (ch <= 'z')) return 1;
386 if((ch >= 'A') && (ch <= 'Z')) return 1;
387 if((ch >= '0') && (ch <= '9')) return 1;
388 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
389 return 0;
390}
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
deleted file mode 100644
index 09d56fb669..0000000000
--- a/src/lib/libcrypto/asn1/a_object.c
+++ /dev/null
@@ -1,304 +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
69 if ((a == NULL) || (a->data == NULL)) return(0);
70
71 if (pp == NULL)
72 return(ASN1_object_size(0,a->length,V_ASN1_OBJECT));
73
74 p= *pp;
75 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
76 memcpy(p,a->data,a->length);
77 p+=a->length;
78
79 *pp=p;
80 return(a->length);
81 }
82
83int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
84 {
85 int i,first,len=0,c;
86 char tmp[24];
87 const char *p;
88 unsigned long l;
89
90 if (num == 0)
91 return(0);
92 else if (num == -1)
93 num=strlen(buf);
94
95 p=buf;
96 c= *(p++);
97 num--;
98 if ((c >= '0') && (c <= '2'))
99 {
100 first=(c-'0')*40;
101 }
102 else
103 {
104 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
105 goto err;
106 }
107
108 if (num <= 0)
109 {
110 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
111 goto err;
112 }
113 c= *(p++);
114 num--;
115 for (;;)
116 {
117 if (num <= 0) break;
118 if ((c != '.') && (c != ' '))
119 {
120 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
121 goto err;
122 }
123 l=0;
124 for (;;)
125 {
126 if (num <= 0) break;
127 num--;
128 c= *(p++);
129 if ((c == ' ') || (c == '.'))
130 break;
131 if ((c < '0') || (c > '9'))
132 {
133 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
134 goto err;
135 }
136 l=l*10L+(long)(c-'0');
137 }
138 if (len == 0)
139 {
140 if ((first < 2) && (l >= 40))
141 {
142 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
143 goto err;
144 }
145 l+=(long)first;
146 }
147 i=0;
148 for (;;)
149 {
150 tmp[i++]=(unsigned char)l&0x7f;
151 l>>=7L;
152 if (l == 0L) break;
153 }
154 if (out != NULL)
155 {
156 if (len+i > olen)
157 {
158 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
159 goto err;
160 }
161 while (--i > 0)
162 out[len++]=tmp[i]|0x80;
163 out[len++]=tmp[0];
164 }
165 else
166 len+=i;
167 }
168 return(len);
169err:
170 return(0);
171 }
172
173int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
174{
175 return OBJ_obj2txt(buf, buf_len, a, 0);
176}
177
178int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
179 {
180 char buf[80];
181 int i;
182
183 if ((a == NULL) || (a->data == NULL))
184 return(BIO_write(bp,"NULL",4));
185 i=i2t_ASN1_OBJECT(buf,80,a);
186 if (i > 80) i=80;
187 BIO_write(bp,buf,i);
188 return(i);
189 }
190
191ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
192 long length)
193 {
194 ASN1_OBJECT *ret=NULL;
195 unsigned char *p;
196 long len;
197 int tag,xclass;
198 int inf,i;
199
200 /* only the ASN1_OBJECTs from the 'table' will have values
201 * for ->sn or ->ln */
202 if ((a == NULL) || ((*a) == NULL) ||
203 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
204 {
205 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
206 }
207 else ret=(*a);
208
209 p= *pp;
210
211 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
212 if (inf & 0x80)
213 {
214 i=ASN1_R_BAD_OBJECT_HEADER;
215 goto err;
216 }
217
218 if (tag != V_ASN1_OBJECT)
219 {
220 i=ASN1_R_EXPECTING_AN_OBJECT;
221 goto err;
222 }
223 if ((ret->data == NULL) || (ret->length < len))
224 {
225 if (ret->data != NULL) Free(ret->data);
226 ret->data=(unsigned char *)Malloc(len ? (int)len : 1);
227 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
228 if (ret->data == NULL)
229 { i=ERR_R_MALLOC_FAILURE; goto err; }
230 }
231 memcpy(ret->data,p,(int)len);
232 ret->length=(int)len;
233 ret->sn=NULL;
234 ret->ln=NULL;
235 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
236 p+=len;
237
238 if (a != NULL) (*a)=ret;
239 *pp=p;
240 return(ret);
241err:
242 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
243 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
244 ASN1_OBJECT_free(ret);
245 return(NULL);
246 }
247
248ASN1_OBJECT *ASN1_OBJECT_new(void)
249 {
250 ASN1_OBJECT *ret;
251
252 ret=(ASN1_OBJECT *)Malloc(sizeof(ASN1_OBJECT));
253 if (ret == NULL)
254 {
255 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
256 return(NULL);
257 }
258 ret->length=0;
259 ret->data=NULL;
260 ret->nid=0;
261 ret->sn=NULL;
262 ret->ln=NULL;
263 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
264 return(ret);
265 }
266
267void ASN1_OBJECT_free(ASN1_OBJECT *a)
268 {
269 if (a == NULL) return;
270 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
271 {
272#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
273 if (a->sn != NULL) Free((void *)a->sn);
274 if (a->ln != NULL) Free((void *)a->ln);
275#endif
276 a->sn=a->ln=NULL;
277 }
278 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
279 {
280 if (a->data != NULL) Free(a->data);
281 a->data=NULL;
282 a->length=0;
283 }
284 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
285 Free(a);
286 }
287
288ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
289 char *sn, char *ln)
290 {
291 ASN1_OBJECT o;
292
293 o.sn=sn;
294 o.ln=ln;
295 o.data=data;
296 o.nid=nid;
297 o.length=len;
298 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
299 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
300 return(OBJ_dup(&o));
301 }
302
303IMPLEMENT_STACK_OF(ASN1_OBJECT)
304IMPLEMENT_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 c2481e7597..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 *)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 = 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 Free(pTempMem);
149 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)(), 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 cfb4bca4f1..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 *)Malloc((unsigned int)inl);
112 outll=outl=EVP_PKEY_size(pkey);
113 buf_out=(unsigned char *)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) 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); Free(buf_in); }
145 if (buf_out != NULL)
146 { memset((char *)buf_out,0,outll); Free(buf_out); }
147 return(outl);
148 }
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
deleted file mode 100644
index ab8417ffab..0000000000
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ /dev/null
@@ -1,247 +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(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b);
69static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b);
70
71
72/* This is the global mask for the mbstring functions: this is use to
73 * mask out certain types (such as BMPString and UTF8String) because
74 * certain software (e.g. Netscape) has problems with them.
75 */
76
77static unsigned long global_mask = 0xFFFFFFFFL;
78
79void ASN1_STRING_set_default_mask(unsigned long mask)
80{
81 global_mask = mask;
82}
83
84unsigned long ASN1_STRING_get_default_mask(void)
85{
86 return global_mask;
87}
88
89/* This function sets the default to various "flavours" of configuration.
90 * based on an ASCII string. Currently this is:
91 * MASK:XXXX : a numerical mask value.
92 * nobmp : Don't use BMPStrings (just Printable, T61).
93 * pkix : PKIX recommendation in RFC2459.
94 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
95 * default: the default value, Printable, T61, BMP.
96 */
97
98int ASN1_STRING_set_default_mask_asc(char *p)
99{
100 unsigned long mask;
101 char *end;
102 if(!strncmp(p, "MASK:", 5)) {
103 if(!p[5]) return 0;
104 mask = strtoul(p + 5, &end, 0);
105 if(*end) return 0;
106 } else if(!strcmp(p, "nombstr"))
107 mask = ~(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING);
108 else if(!strcmp(p, "pkix"))
109 mask = ~B_ASN1_T61STRING;
110 else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING;
111 else if(!strcmp(p, "default"))
112 mask = 0xFFFFFFFFL;
113 else return 0;
114 ASN1_STRING_set_default_mask(mask);
115 return 1;
116}
117
118/* The following function generates an ASN1_STRING based on limits in a table.
119 * Frequently the types and length of an ASN1_STRING are restricted by a
120 * corresponding OID. For example certificates and certificate requests.
121 */
122
123ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
124 int inlen, int inform, int nid)
125{
126 ASN1_STRING_TABLE *tbl;
127 ASN1_STRING *str = NULL;
128 unsigned long mask;
129 int ret;
130 if(!out) out = &str;
131 tbl = ASN1_STRING_TABLE_get(nid);
132 if(tbl) {
133 mask = tbl->mask;
134 if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask;
135 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, tbl->mask,
136 tbl->minsize, tbl->maxsize);
137 } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask);
138 if(ret <= 0) return NULL;
139 return *out;
140}
141
142/* Now the tables and helper functions for the string table:
143 */
144
145/* size limits: this stuff is taken straight from RFC2459 */
146
147#define ub_name 32768
148#define ub_common_name 64
149#define ub_locality_name 128
150#define ub_state_name 128
151#define ub_organization_name 64
152#define ub_organization_unit_name 64
153#define ub_title 64
154#define ub_email_address 128
155
156/* This table must be kept in NID order */
157
158static ASN1_STRING_TABLE tbl_standard[] = {
159{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
160{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
161{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
162{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
163{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
164{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
165{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
166{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
167{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
168{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
169{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
170{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
171{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
172{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
173{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}
174};
175
176static int sk_table_cmp(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b)
177{
178 return (*a)->nid - (*b)->nid;
179}
180
181static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b)
182{
183 return a->nid - b->nid;
184}
185
186ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
187{
188 int idx;
189 ASN1_STRING_TABLE *ttmp;
190 ASN1_STRING_TABLE fnd;
191 fnd.nid = nid;
192 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
193 (char *)tbl_standard,
194 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
195 sizeof(ASN1_STRING_TABLE), (int(*)())table_cmp);
196 if(ttmp) return ttmp;
197 if(!stable) return NULL;
198 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
199 if(idx < 0) return NULL;
200 return sk_ASN1_STRING_TABLE_value(stable, idx);
201}
202
203int ASN1_STRING_TABLE_add(int nid,
204 long minsize, long maxsize, unsigned long mask,
205 unsigned long flags)
206{
207 ASN1_STRING_TABLE *tmp;
208 char new_nid = 0;
209 flags &= ~STABLE_FLAGS_MALLOC;
210 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
211 if(!stable) {
212 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
213 return 0;
214 }
215 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
216 tmp = Malloc(sizeof(ASN1_STRING_TABLE));
217 if(!tmp) {
218 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
219 ERR_R_MALLOC_FAILURE);
220 return 0;
221 }
222 tmp->flags = flags | STABLE_FLAGS_MALLOC;
223 tmp->nid = nid;
224 new_nid = 1;
225 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
226 if(minsize != -1) tmp->minsize = minsize;
227 if(maxsize != -1) tmp->maxsize = maxsize;
228 tmp->mask = mask;
229 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
230 return 1;
231}
232
233void ASN1_STRING_TABLE_cleanup(void)
234{
235 STACK_OF(ASN1_STRING_TABLE) *tmp;
236 tmp = stable;
237 if(!tmp) return;
238 stable = NULL;
239 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
240}
241
242static void st_free(ASN1_STRING_TABLE *tbl)
243{
244 if(tbl->flags & STABLE_FLAGS_MALLOC) Free(tbl);
245}
246
247IMPLEMENT_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 b193f1c71f..0000000000
--- a/src/lib/libcrypto/asn1/a_time.c
+++ /dev/null
@@ -1,129 +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)
117 struct tm data;
118#endif
119
120#if defined(THREADS) && !defined(WIN32)
121 gmtime_r(&t,&data);
122 ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
123#else
124 ts=gmtime(&t);
125#endif
126 if((ts->tm_year >= 50) && (ts->tm_year < 150))
127 return ASN1_UTCTIME_set(s, t);
128 return ASN1_GENERALIZEDTIME_set(s,t);
129 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
deleted file mode 100644
index 161ef81197..0000000000
--- a/src/lib/libcrypto/asn1/a_type.c
+++ /dev/null
@@ -1,348 +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 if (a->value.set == NULL)
127 r=0;
128 else
129 {
130 r=a->value.set->length;
131 if (pp != NULL)
132 {
133 memcpy(*pp,a->value.set->data,r);
134 *pp+=r;
135 }
136 }
137 break;
138 }
139 return(r);
140 }
141
142ASN1_TYPE *d2i_ASN1_TYPE(ASN1_TYPE **a, unsigned char **pp, long length)
143 {
144 ASN1_TYPE *ret=NULL;
145 unsigned char *q,*p,*max;
146 int inf,tag,xclass;
147 long len;
148
149 if ((a == NULL) || ((*a) == NULL))
150 {
151 if ((ret=ASN1_TYPE_new()) == NULL) goto err;
152 }
153 else
154 ret=(*a);
155
156 p= *pp;
157 q=p;
158 max=(p+length);
159
160 inf=ASN1_get_object(&q,&len,&tag,&xclass,length);
161 if (inf & 0x80) goto err;
162
163 ASN1_TYPE_component_free(ret);
164
165 switch (tag)
166 {
167 case V_ASN1_NULL:
168 p=q;
169 ret->value.ptr=NULL;
170 break;
171 case V_ASN1_INTEGER:
172 if ((ret->value.integer=
173 d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL)
174 goto err;
175 break;
176 case V_ASN1_ENUMERATED:
177 if ((ret->value.enumerated=
178 d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL)
179 goto err;
180 break;
181 case V_ASN1_BIT_STRING:
182 if ((ret->value.bit_string=
183 d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL)
184 goto err;
185 break;
186 case V_ASN1_OCTET_STRING:
187 if ((ret->value.octet_string=
188 d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL)
189 goto err;
190 break;
191 case V_ASN1_VISIBLESTRING:
192 if ((ret->value.visiblestring=
193 d2i_ASN1_VISIBLESTRING(NULL,&p,max-p)) == NULL)
194 goto err;
195 break;
196 case V_ASN1_UTF8STRING:
197 if ((ret->value.utf8string=
198 d2i_ASN1_UTF8STRING(NULL,&p,max-p)) == NULL)
199 goto err;
200 break;
201 case V_ASN1_OBJECT:
202 if ((ret->value.object=
203 d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL)
204 goto err;
205 break;
206 case V_ASN1_PRINTABLESTRING:
207 if ((ret->value.printablestring=
208 d2i_ASN1_PRINTABLESTRING(NULL,&p,max-p)) == NULL)
209 goto err;
210 break;
211 case V_ASN1_T61STRING:
212 if ((ret->value.t61string=
213 M_d2i_ASN1_T61STRING(NULL,&p,max-p)) == NULL)
214 goto err;
215 break;
216 case V_ASN1_IA5STRING:
217 if ((ret->value.ia5string=
218 M_d2i_ASN1_IA5STRING(NULL,&p,max-p)) == NULL)
219 goto err;
220 break;
221 case V_ASN1_GENERALSTRING:
222 if ((ret->value.generalstring=
223 M_d2i_ASN1_GENERALSTRING(NULL,&p,max-p)) == NULL)
224 goto err;
225 break;
226 case V_ASN1_UNIVERSALSTRING:
227 if ((ret->value.universalstring=
228 M_d2i_ASN1_UNIVERSALSTRING(NULL,&p,max-p)) == NULL)
229 goto err;
230 break;
231 case V_ASN1_BMPSTRING:
232 if ((ret->value.bmpstring=
233 M_d2i_ASN1_BMPSTRING(NULL,&p,max-p)) == NULL)
234 goto err;
235 break;
236 case V_ASN1_UTCTIME:
237 if ((ret->value.utctime=
238 d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL)
239 goto err;
240 break;
241 case V_ASN1_GENERALIZEDTIME:
242 if ((ret->value.generalizedtime=
243 d2i_ASN1_GENERALIZEDTIME(NULL,&p,max-p)) == NULL)
244 goto err;
245 break;
246 case V_ASN1_SET:
247 case V_ASN1_SEQUENCE:
248 /* Sets and sequences are left complete */
249 if ((ret->value.set=ASN1_STRING_new()) == NULL) goto err;
250 ret->value.set->type=tag;
251 len+=(q-p);
252 if (!ASN1_STRING_set(ret->value.set,p,(int)len)) goto err;
253 p+=len;
254 break;
255 default:
256 ASN1err(ASN1_F_D2I_ASN1_TYPE,ASN1_R_BAD_TYPE);
257 goto err;
258 }
259
260 ret->type=tag;
261 if (a != NULL) (*a)=ret;
262 *pp=p;
263 return(ret);
264err:
265 if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_TYPE_free(ret);
266 return(NULL);
267 }
268
269ASN1_TYPE *ASN1_TYPE_new(void)
270 {
271 ASN1_TYPE *ret=NULL;
272 ASN1_CTX c;
273
274 M_ASN1_New_Malloc(ret,ASN1_TYPE);
275 ret->type= -1;
276 ret->value.ptr=NULL;
277 return(ret);
278 M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW);
279 }
280
281void ASN1_TYPE_free(ASN1_TYPE *a)
282 {
283 if (a == NULL) return;
284 ASN1_TYPE_component_free(a);
285 Free(a);
286 }
287
288int ASN1_TYPE_get(ASN1_TYPE *a)
289 {
290 if (a->value.ptr != NULL)
291 return(a->type);
292 else
293 return(0);
294 }
295
296void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
297 {
298 if (a->value.ptr != NULL)
299 ASN1_TYPE_component_free(a);
300 a->type=type;
301 a->value.ptr=value;
302 }
303
304static void ASN1_TYPE_component_free(ASN1_TYPE *a)
305 {
306 if (a == NULL) return;
307
308 if (a->value.ptr != NULL)
309 {
310 switch (a->type)
311 {
312 case V_ASN1_OBJECT:
313 ASN1_OBJECT_free(a->value.object);
314 break;
315 case V_ASN1_INTEGER:
316 case V_ASN1_NEG_INTEGER:
317 case V_ASN1_ENUMERATED:
318 case V_ASN1_NEG_ENUMERATED:
319 case V_ASN1_BIT_STRING:
320 case V_ASN1_OCTET_STRING:
321 case V_ASN1_SEQUENCE:
322 case V_ASN1_SET:
323 case V_ASN1_NUMERICSTRING:
324 case V_ASN1_PRINTABLESTRING:
325 case V_ASN1_T61STRING:
326 case V_ASN1_VIDEOTEXSTRING:
327 case V_ASN1_IA5STRING:
328 case V_ASN1_UTCTIME:
329 case V_ASN1_GENERALIZEDTIME:
330 case V_ASN1_GRAPHICSTRING:
331 case V_ASN1_VISIBLESTRING:
332 case V_ASN1_GENERALSTRING:
333 case V_ASN1_UNIVERSALSTRING:
334 case V_ASN1_BMPSTRING:
335 case V_ASN1_UTF8STRING:
336 ASN1_STRING_free((ASN1_STRING *)a->value.ptr);
337 break;
338 default:
339 /* MEMORY LEAK */
340 break;
341 }
342 a->type=0;
343 a->value.ptr=NULL;
344 }
345 }
346
347IMPLEMENT_STACK_OF(ASN1_TYPE)
348IMPLEMENT_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 b5125af224..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 = (*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 = (*p++ & 0x3) << 24;
149 value |= (*p++ & 0x3f) << 18;
150 value |= (*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 = (*p++ & 0x1) << 30;
163 value |= (*p++ & 0x3f) << 24;
164 value |= (*p++ & 0x3f) << 18;
165 value |= (*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 d4aede85c3..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=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 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 99bd64a11e..0000000000
--- a/src/lib/libcrypto/asn1/asn1.h
+++ /dev/null
@@ -1,1067 +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#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <time.h>
67#include <openssl/bn.h>
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70
71#ifdef VMS
72#include <openssl/vms_idhacks.h>
73#endif
74
75#define V_ASN1_UNIVERSAL 0x00
76#define V_ASN1_APPLICATION 0x40
77#define V_ASN1_CONTEXT_SPECIFIC 0x80
78#define V_ASN1_PRIVATE 0xc0
79
80#define V_ASN1_CONSTRUCTED 0x20
81#define V_ASN1_PRIMITIVE_TAG 0x1f
82#define V_ASN1_PRIMATIVE_TAG 0x1f
83
84#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
85
86#define V_ASN1_UNDEF -1
87#define V_ASN1_EOC 0
88#define V_ASN1_BOOLEAN 1 /**/
89#define V_ASN1_INTEGER 2
90#define V_ASN1_NEG_INTEGER (2+0x100)
91#define V_ASN1_BIT_STRING 3
92#define V_ASN1_OCTET_STRING 4
93#define V_ASN1_NULL 5
94#define V_ASN1_OBJECT 6
95#define V_ASN1_OBJECT_DESCRIPTOR 7
96#define V_ASN1_EXTERNAL 8
97#define V_ASN1_REAL 9
98#define V_ASN1_ENUMERATED 10
99#define V_ASN1_NEG_ENUMERATED (10+0x100)
100#define V_ASN1_UTF8STRING 12
101#define V_ASN1_SEQUENCE 16
102#define V_ASN1_SET 17
103#define V_ASN1_NUMERICSTRING 18 /**/
104#define V_ASN1_PRINTABLESTRING 19
105#define V_ASN1_T61STRING 20
106#define V_ASN1_TELETEXSTRING 20 /* alias */
107#define V_ASN1_VIDEOTEXSTRING 21 /**/
108#define V_ASN1_IA5STRING 22
109#define V_ASN1_UTCTIME 23
110#define V_ASN1_GENERALIZEDTIME 24 /**/
111#define V_ASN1_GRAPHICSTRING 25 /**/
112#define V_ASN1_ISO64STRING 26 /**/
113#define V_ASN1_VISIBLESTRING 26 /* alias */
114#define V_ASN1_GENERALSTRING 27 /**/
115#define V_ASN1_UNIVERSALSTRING 28 /**/
116#define V_ASN1_BMPSTRING 30
117
118/* For use with d2i_ASN1_type_bytes() */
119#define B_ASN1_NUMERICSTRING 0x0001
120#define B_ASN1_PRINTABLESTRING 0x0002
121#define B_ASN1_T61STRING 0x0004
122#define B_ASN1_TELETEXSTRING 0x0008
123#define B_ASN1_VIDEOTEXSTRING 0x0008
124#define B_ASN1_IA5STRING 0x0010
125#define B_ASN1_GRAPHICSTRING 0x0020
126#define B_ASN1_ISO64STRING 0x0040
127#define B_ASN1_VISIBLESTRING 0x0040
128#define B_ASN1_GENERALSTRING 0x0080
129#define B_ASN1_UNIVERSALSTRING 0x0100
130#define B_ASN1_OCTET_STRING 0x0200
131#define B_ASN1_BIT_STRING 0x0400
132#define B_ASN1_BMPSTRING 0x0800
133#define B_ASN1_UNKNOWN 0x1000
134#define B_ASN1_UTF8STRING 0x2000
135
136/* For use with ASN1_mbstring_copy() */
137#define MBSTRING_FLAG 0x1000
138#define MBSTRING_ASC (MBSTRING_FLAG|1)
139#define MBSTRING_BMP (MBSTRING_FLAG|2)
140#define MBSTRING_UNIV (MBSTRING_FLAG|3)
141#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
142
143#define DECLARE_ASN1_SET_OF(type) \
144int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
145 int (*func)(type *,unsigned char **), int ex_tag, \
146 int ex_class, int is_set); \
147STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
148 long length, \
149 type *(*func)(type **, \
150 unsigned char **,long), \
151 void (*free_func)(type *), \
152 int ex_tag,int ex_class);
153
154#define IMPLEMENT_ASN1_SET_OF(type) \
155int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
156 int (*func)(type *,unsigned char **), int ex_tag, \
157 int ex_class, int is_set) \
158 { return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \
159STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
160 long length, \
161 type *(*func)(type **, \
162 unsigned char **,long), \
163 void (*free_func)(type *), \
164 int ex_tag,int ex_class) \
165 { return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \
166 (char *(*)())func, \
167 (void (*)())free_func, \
168 ex_tag,ex_class); }
169
170typedef struct asn1_ctx_st
171 {
172 unsigned char *p;/* work char pointer */
173 int eos; /* end of sequence read for indefinite encoding */
174 int error; /* error code to use when returning an error */
175 int inf; /* constructed if 0x20, indefinite is 0x21 */
176 int tag; /* tag from last 'get object' */
177 int xclass; /* class from last 'get object' */
178 long slen; /* length of last 'get object' */
179 unsigned char *max; /* largest value of p allowed */
180 unsigned char *q;/* temporary variable */
181 unsigned char **pp;/* variable */
182 int line; /* used in error processing */
183 } ASN1_CTX;
184
185/* These are used internally in the ASN1_OBJECT to keep track of
186 * whether the names and data need to be free()ed */
187#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
188#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
189#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
190#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
191typedef struct asn1_object_st
192 {
193 const char *sn,*ln;
194 int nid;
195 int length;
196 unsigned char *data;
197 int flags; /* Should we free this one */
198 } ASN1_OBJECT;
199
200#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
201/* This is the base type that holds just about everything :-) */
202typedef struct asn1_string_st
203 {
204 int length;
205 int type;
206 unsigned char *data;
207 /* The value of the following field depends on the type being
208 * held. It is mostly being used for BIT_STRING so if the
209 * input data has a non-zero 'unused bits' value, it will be
210 * handled correctly */
211 long flags;
212 } ASN1_STRING;
213
214#define STABLE_FLAGS_MALLOC 0x01
215#define STABLE_NO_MASK 0x02
216#define DIRSTRING_TYPE \
217 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
218#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
219
220typedef struct asn1_string_table_st {
221 int nid;
222 long minsize;
223 long maxsize;
224 unsigned long mask;
225 unsigned long flags;
226} ASN1_STRING_TABLE;
227
228DECLARE_STACK_OF(ASN1_STRING_TABLE)
229
230/* size limits: this stuff is taken straight from RFC2459 */
231
232#define ub_name 32768
233#define ub_common_name 64
234#define ub_locality_name 128
235#define ub_state_name 128
236#define ub_organization_name 64
237#define ub_organization_unit_name 64
238#define ub_title 64
239#define ub_email_address 128
240
241#ifdef NO_ASN1_TYPEDEFS
242#define ASN1_INTEGER ASN1_STRING
243#define ASN1_ENUMERATED ASN1_STRING
244#define ASN1_BIT_STRING ASN1_STRING
245#define ASN1_OCTET_STRING ASN1_STRING
246#define ASN1_PRINTABLESTRING ASN1_STRING
247#define ASN1_T61STRING ASN1_STRING
248#define ASN1_IA5STRING ASN1_STRING
249#define ASN1_UTCTIME ASN1_STRING
250#define ASN1_GENERALIZEDTIME ASN1_STRING
251#define ASN1_TIME ASN1_STRING
252#define ASN1_GENERALSTRING ASN1_STRING
253#define ASN1_UNIVERSALSTRING ASN1_STRING
254#define ASN1_BMPSTRING ASN1_STRING
255#define ASN1_VISIBLESTRING ASN1_STRING
256#define ASN1_UTF8STRING ASN1_STRING
257#else
258typedef struct asn1_string_st ASN1_INTEGER;
259typedef struct asn1_string_st ASN1_ENUMERATED;
260typedef struct asn1_string_st ASN1_BIT_STRING;
261typedef struct asn1_string_st ASN1_OCTET_STRING;
262typedef struct asn1_string_st ASN1_PRINTABLESTRING;
263typedef struct asn1_string_st ASN1_T61STRING;
264typedef struct asn1_string_st ASN1_IA5STRING;
265typedef struct asn1_string_st ASN1_GENERALSTRING;
266typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
267typedef struct asn1_string_st ASN1_BMPSTRING;
268typedef struct asn1_string_st ASN1_UTCTIME;
269typedef struct asn1_string_st ASN1_TIME;
270typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
271typedef struct asn1_string_st ASN1_VISIBLESTRING;
272typedef struct asn1_string_st ASN1_UTF8STRING;
273#endif
274
275typedef int ASN1_NULL;
276
277typedef struct asn1_type_st
278 {
279 int type;
280 union {
281 char *ptr;
282 ASN1_STRING * asn1_string;
283 ASN1_OBJECT * object;
284 ASN1_INTEGER * integer;
285 ASN1_ENUMERATED * enumerated;
286 ASN1_BIT_STRING * bit_string;
287 ASN1_OCTET_STRING * octet_string;
288 ASN1_PRINTABLESTRING * printablestring;
289 ASN1_T61STRING * t61string;
290 ASN1_IA5STRING * ia5string;
291 ASN1_GENERALSTRING * generalstring;
292 ASN1_BMPSTRING * bmpstring;
293 ASN1_UNIVERSALSTRING * universalstring;
294 ASN1_UTCTIME * utctime;
295 ASN1_GENERALIZEDTIME * generalizedtime;
296 ASN1_VISIBLESTRING * visiblestring;
297 ASN1_UTF8STRING * utf8string;
298 /* set and sequence are left complete and still
299 * contain the set or sequence bytes */
300 ASN1_STRING * set;
301 ASN1_STRING * sequence;
302 } value;
303 } ASN1_TYPE;
304
305DECLARE_STACK_OF(ASN1_TYPE)
306DECLARE_ASN1_SET_OF(ASN1_TYPE)
307
308typedef struct asn1_method_st
309 {
310 int (*i2d)();
311 char *(*d2i)();
312 char *(*create)();
313 void (*destroy)();
314 } ASN1_METHOD;
315
316/* This is used when parsing some Netscape objects */
317typedef struct asn1_header_st
318 {
319 ASN1_OCTET_STRING *header;
320 char *data;
321 ASN1_METHOD *meth;
322 } ASN1_HEADER;
323
324/* This is used to contain a list of bit names */
325typedef struct BIT_STRING_BITNAME_st {
326 int bitnum;
327 const char *lname;
328 const char *sname;
329} BIT_STRING_BITNAME;
330
331
332#define M_ASN1_STRING_length(x) ((x)->length)
333#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
334#define M_ASN1_STRING_type(x) ((x)->type)
335#define M_ASN1_STRING_data(x) ((x)->data)
336
337/* Macros for string operations */
338#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
339 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
340#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
341#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
342 ASN1_STRING_dup((ASN1_STRING *)a)
343#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
344 (ASN1_STRING *)a,(ASN1_STRING *)b)
345#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
346
347#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
348 ASN1_STRING_type_new(V_ASN1_INTEGER)
349#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
350#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
351#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
352 (ASN1_STRING *)a,(ASN1_STRING *)b)
353
354#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
355 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
356#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
357#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
358#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
359 (ASN1_STRING *)a,(ASN1_STRING *)b)
360
361#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
362 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
363#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
364#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
365 ASN1_STRING_dup((ASN1_STRING *)a)
366#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
367 (ASN1_STRING *)a,(ASN1_STRING *)b)
368#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
369#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
370#define M_i2d_ASN1_OCTET_STRING(a,pp) \
371 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
372 V_ASN1_UNIVERSAL)
373
374#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
375#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
376#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
377 pp,a->type,V_ASN1_UNIVERSAL)
378#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
379 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
380 B_ASN1_PRINTABLESTRING| \
381 B_ASN1_T61STRING| \
382 B_ASN1_IA5STRING| \
383 B_ASN1_BIT_STRING| \
384 B_ASN1_UNIVERSALSTRING|\
385 B_ASN1_BMPSTRING|\
386 B_ASN1_UTF8STRING|\
387 B_ASN1_UNKNOWN)
388
389#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
390#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
391#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
392 pp,a->type,V_ASN1_UNIVERSAL)
393#define M_d2i_DIRECTORYSTRING(a,pp,l) \
394 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
395 B_ASN1_PRINTABLESTRING| \
396 B_ASN1_TELETEXSTRING|\
397 B_ASN1_BMPSTRING|\
398 B_ASN1_UNIVERSALSTRING|\
399 B_ASN1_UTF8STRING)
400
401#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
402#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
403#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
404 pp,a->type,V_ASN1_UNIVERSAL)
405#define M_d2i_DISPLAYTEXT(a,pp,l) \
406 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
407 B_ASN1_VISIBLESTRING| \
408 B_ASN1_BMPSTRING|\
409 B_ASN1_UTF8STRING)
410
411#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
412 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
413#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
414#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
415 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
416 V_ASN1_UNIVERSAL)
417#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
418 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
419 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
420
421#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
422 ASN1_STRING_type_new(V_ASN1_T61STRING)
423#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
424#define M_i2d_ASN1_T61STRING(a,pp) \
425 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
426 V_ASN1_UNIVERSAL)
427#define M_d2i_ASN1_T61STRING(a,pp,l) \
428 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
429 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
430
431#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
432 ASN1_STRING_type_new(V_ASN1_IA5STRING)
433#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
434#define M_ASN1_IA5STRING_dup(a) \
435 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
436#define M_i2d_ASN1_IA5STRING(a,pp) \
437 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
438 V_ASN1_UNIVERSAL)
439#define M_d2i_ASN1_IA5STRING(a,pp,l) \
440 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
441 B_ASN1_IA5STRING)
442
443#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
444 ASN1_STRING_type_new(V_ASN1_UTCTIME)
445#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
446#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
447
448#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
449 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
450#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
451#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
452 (ASN1_STRING *)a)
453
454#define M_ASN1_TIME_new() (ASN1_TIME *)\
455 ASN1_STRING_type_new(V_ASN1_UTCTIME)
456#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
457#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
458
459#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
460 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
461#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
462#define M_i2d_ASN1_GENERALSTRING(a,pp) \
463 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
464 V_ASN1_UNIVERSAL)
465#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
466 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
467 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
468
469#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
470 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
471#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
472#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
473 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
474 V_ASN1_UNIVERSAL)
475#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
476 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
477 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
478
479#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
480 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
481#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
482#define M_i2d_ASN1_BMPSTRING(a,pp) \
483 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
484 V_ASN1_UNIVERSAL)
485#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
486 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
487 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
488
489#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
490 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
491#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
492#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
493 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
494 V_ASN1_UNIVERSAL)
495#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
496 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
497 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
498
499#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
500 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
501#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
502#define M_i2d_ASN1_UTF8STRING(a,pp) \
503 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
504 V_ASN1_UNIVERSAL)
505#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
506 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
507 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
508
509 /* for the is_set parameter to i2d_ASN1_SET */
510#define IS_SEQUENCE 0
511#define IS_SET 1
512
513ASN1_TYPE * ASN1_TYPE_new(void );
514void ASN1_TYPE_free(ASN1_TYPE *a);
515int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
516ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
517int ASN1_TYPE_get(ASN1_TYPE *a);
518void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
519
520ASN1_OBJECT * ASN1_OBJECT_new(void );
521void ASN1_OBJECT_free(ASN1_OBJECT *a);
522int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
523ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
524 long length);
525
526DECLARE_STACK_OF(ASN1_OBJECT)
527DECLARE_ASN1_SET_OF(ASN1_OBJECT)
528
529ASN1_STRING * ASN1_STRING_new(void);
530void ASN1_STRING_free(ASN1_STRING *a);
531ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
532ASN1_STRING * ASN1_STRING_type_new(int type );
533int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
534 /* Since this is used to store all sorts of things, via macros, for now, make
535 its data void * */
536int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
537int ASN1_STRING_length(ASN1_STRING *x);
538void ASN1_STRING_length_set(ASN1_STRING *x, int n);
539int ASN1_STRING_type(ASN1_STRING *x);
540unsigned char * ASN1_STRING_data(ASN1_STRING *x);
541
542ASN1_BIT_STRING * ASN1_BIT_STRING_new(void);
543void ASN1_BIT_STRING_free(ASN1_BIT_STRING *a);
544int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
545ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
546 long length);
547int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
548 int length );
549int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
550int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
551
552#ifdef HEADER_BIO_H
553int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
554 BIT_STRING_BITNAME *tbl, int indent);
555#endif
556int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
557int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
558 BIT_STRING_BITNAME *tbl);
559
560int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
561int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
562
563ASN1_INTEGER * ASN1_INTEGER_new(void);
564void ASN1_INTEGER_free(ASN1_INTEGER *a);
565int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
566ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
567 long length);
568ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
569 long length);
570ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
571int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
572
573ASN1_ENUMERATED * ASN1_ENUMERATED_new(void);
574void ASN1_ENUMERATED_free(ASN1_ENUMERATED *a);
575int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp);
576ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
577 long length);
578
579int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
580ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
581int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
582
583int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
584ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
585int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
586
587ASN1_OCTET_STRING * ASN1_OCTET_STRING_new(void);
588void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a);
589int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
590ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
591 unsigned char **pp,long length);
592ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
593int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
594int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
595
596ASN1_VISIBLESTRING * ASN1_VISIBLESTRING_new(void);
597void ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *a);
598int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp);
599ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
600 unsigned char **pp,long length);
601
602ASN1_UTF8STRING * ASN1_UTF8STRING_new(void);
603void ASN1_UTF8STRING_free(ASN1_UTF8STRING *a);
604int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
605ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
606 unsigned char **pp,long length);
607
608ASN1_NULL * ASN1_NULL_new(void);
609void ASN1_NULL_free(ASN1_NULL *a);
610int i2d_ASN1_NULL(ASN1_NULL *a,unsigned char **pp);
611ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp,long length);
612
613ASN1_BMPSTRING * ASN1_BMPSTRING_new(void);
614void ASN1_BMPSTRING_free(ASN1_BMPSTRING *a);
615int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
616ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
617 long length);
618
619
620int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
621int UTF8_putc(unsigned char *str, int len, unsigned long value);
622
623int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
624ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
625 unsigned char **pp, long l);
626
627ASN1_PRINTABLESTRING * ASN1_PRINTABLESTRING_new(void);
628void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *a);
629ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
630 unsigned char **pp, long l);
631int i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **pp);
632
633ASN1_STRING * DIRECTORYSTRING_new(void);
634void DIRECTORYSTRING_free(ASN1_STRING *a);
635int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp);
636ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
637 long length);
638
639ASN1_STRING * DISPLAYTEXT_new(void);
640void DISPLAYTEXT_free(ASN1_STRING *a);
641int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp);
642ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length);
643
644ASN1_T61STRING * ASN1_T61STRING_new(void);
645void ASN1_T61STRING_free(ASN1_IA5STRING *a);
646ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
647 unsigned char **pp, long l);
648
649ASN1_IA5STRING * ASN1_IA5STRING_new(void);
650void ASN1_IA5STRING_free(ASN1_IA5STRING *a);
651int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
652ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
653 unsigned char **pp, long l);
654
655ASN1_UTCTIME * ASN1_UTCTIME_new(void);
656void ASN1_UTCTIME_free(ASN1_UTCTIME *a);
657int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
658ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
659 long length);
660
661ASN1_GENERALIZEDTIME * ASN1_GENERALIZEDTIME_new(void);
662void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *a);
663int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp);
664ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp,
665 long length);
666
667ASN1_TIME * ASN1_TIME_new(void);
668void ASN1_TIME_free(ASN1_TIME *a);
669int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
670ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
671ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
672
673int i2d_ASN1_SET(STACK *a, unsigned char **pp,
674 int (*func)(), int ex_tag, int ex_class, int is_set);
675STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
676 char *(*func)(), void (*free_func)(),
677 int ex_tag, int ex_class);
678
679#ifdef HEADER_BIO_H
680int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
681int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
682int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
683int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
684int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
685int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
686int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
687#endif
688int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
689
690int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
691ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
692 char *sn, char *ln);
693
694int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
695long ASN1_INTEGER_get(ASN1_INTEGER *a);
696ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
697BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
698
699int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
700long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
701ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
702BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
703
704/* General */
705/* given a string, return the correct type, max is the maximum length */
706int ASN1_PRINTABLE_type(unsigned char *s, int max);
707
708int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
709ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
710 long length, int Ptag, int Pclass);
711/* type is one or more of the B_ASN1_ values. */
712ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
713 long length,int type);
714
715/* PARSING */
716int asn1_Finish(ASN1_CTX *c);
717
718/* SPECIALS */
719int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
720 int *pclass, long omax);
721int ASN1_check_infinite_end(unsigned char **p,long len);
722void ASN1_put_object(unsigned char **pp, int constructed, int length,
723 int tag, int xclass);
724int ASN1_object_size(int constructed, int length, int tag);
725
726/* Used to implement other functions */
727char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
728
729#ifndef NO_FP_API
730char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
731int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
732#endif
733
734#ifdef HEADER_BIO_H
735char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
736int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
737int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
738int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
739int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
740int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
741int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
742#endif
743const char *ASN1_tag2str(int tag);
744
745/* Used to load and write netscape format cert/key */
746int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
747ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
748ASN1_HEADER *ASN1_HEADER_new(void );
749void ASN1_HEADER_free(ASN1_HEADER *a);
750
751int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
752
753void ERR_load_ASN1_strings(void);
754
755/* Not used that much at this point, except for the first two */
756ASN1_METHOD *X509_asn1_meth(void);
757ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
758ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
759ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
760
761int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
762 unsigned char *data, int len);
763int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
764 unsigned char *data, int max_len);
765int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
766 unsigned char *data, int len);
767int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
768 unsigned char *data, int max_len);
769
770STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
771 void (*free_func)() );
772unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
773 int *len );
774void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
775ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
776
777void ASN1_STRING_set_default_mask(unsigned long mask);
778int ASN1_STRING_set_default_mask_asc(char *p);
779unsigned long ASN1_STRING_get_default_mask(void);
780int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
781 int inform, unsigned long mask);
782int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
783 int inform, unsigned long mask,
784 long minsize, long maxsize);
785
786ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
787 const unsigned char *in, int inlen, int inform, int nid);
788ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
789int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
790void ASN1_STRING_TABLE_cleanup(void);
791
792/* BEGIN ERROR CODES */
793/* The following lines are auto generated by the script mkerr.pl. Any changes
794 * made after this point may be overwritten when the script is next run.
795 */
796
797/* Error codes for the ASN1 functions. */
798
799/* Function codes. */
800#define ASN1_F_A2D_ASN1_OBJECT 100
801#define ASN1_F_A2I_ASN1_ENUMERATED 236
802#define ASN1_F_A2I_ASN1_INTEGER 101
803#define ASN1_F_A2I_ASN1_STRING 102
804#define ASN1_F_ACCESS_DESCRIPTION_NEW 291
805#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103
806#define ASN1_F_ASN1_D2I_BIO 104
807#define ASN1_F_ASN1_D2I_FP 105
808#define ASN1_F_ASN1_DUP 106
809#define ASN1_F_ASN1_ENUMERATED_SET 232
810#define ASN1_F_ASN1_ENUMERATED_TO_BN 233
811#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222
812#define ASN1_F_ASN1_GET_OBJECT 107
813#define ASN1_F_ASN1_HEADER_NEW 108
814#define ASN1_F_ASN1_I2D_BIO 109
815#define ASN1_F_ASN1_I2D_FP 110
816#define ASN1_F_ASN1_INTEGER_SET 111
817#define ASN1_F_ASN1_INTEGER_TO_BN 112
818#define ASN1_F_ASN1_MBSTRING_COPY 282
819#define ASN1_F_ASN1_OBJECT_NEW 113
820#define ASN1_F_ASN1_PACK_STRING 245
821#define ASN1_F_ASN1_PBE_SET 253
822#define ASN1_F_ASN1_SEQ_PACK 246
823#define ASN1_F_ASN1_SEQ_UNPACK 247
824#define ASN1_F_ASN1_SIGN 114
825#define ASN1_F_ASN1_STRING_NEW 115
826#define ASN1_F_ASN1_STRING_TABLE_ADD 283
827#define ASN1_F_ASN1_STRING_TYPE_NEW 116
828#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
829#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
830#define ASN1_F_ASN1_TYPE_NEW 119
831#define ASN1_F_ASN1_UNPACK_STRING 248
832#define ASN1_F_ASN1_UTCTIME_NEW 120
833#define ASN1_F_ASN1_VERIFY 121
834#define ASN1_F_AUTHORITY_KEYID_NEW 237
835#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
836#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
837#define ASN1_F_BN_TO_ASN1_INTEGER 122
838#define ASN1_F_D2I_ACCESS_DESCRIPTION 284
839#define ASN1_F_D2I_ASN1_BIT_STRING 123
840#define ASN1_F_D2I_ASN1_BMPSTRING 124
841#define ASN1_F_D2I_ASN1_BOOLEAN 125
842#define ASN1_F_D2I_ASN1_BYTES 126
843#define ASN1_F_D2I_ASN1_ENUMERATED 235
844#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
845#define ASN1_F_D2I_ASN1_HEADER 127
846#define ASN1_F_D2I_ASN1_INTEGER 128
847#define ASN1_F_D2I_ASN1_NULL 292
848#define ASN1_F_D2I_ASN1_OBJECT 129
849#define ASN1_F_D2I_ASN1_OCTET_STRING 130
850#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
851#define ASN1_F_D2I_ASN1_SET 132
852#define ASN1_F_D2I_ASN1_TIME 224
853#define ASN1_F_D2I_ASN1_TYPE 133
854#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
855#define ASN1_F_D2I_ASN1_UINTEGER 280
856#define ASN1_F_D2I_ASN1_UTCTIME 135
857#define ASN1_F_D2I_ASN1_UTF8STRING 266
858#define ASN1_F_D2I_ASN1_VISIBLESTRING 267
859#define ASN1_F_D2I_AUTHORITY_KEYID 238
860#define ASN1_F_D2I_BASIC_CONSTRAINTS 227
861#define ASN1_F_D2I_DHPARAMS 136
862#define ASN1_F_D2I_DIST_POINT 276
863#define ASN1_F_D2I_DIST_POINT_NAME 277
864#define ASN1_F_D2I_DSAPARAMS 137
865#define ASN1_F_D2I_DSAPRIVATEKEY 138
866#define ASN1_F_D2I_DSAPUBLICKEY 139
867#define ASN1_F_D2I_GENERAL_NAME 230
868#define ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE 228
869#define ASN1_F_D2I_NETSCAPE_PKEY 140
870#define ASN1_F_D2I_NETSCAPE_RSA 141
871#define ASN1_F_D2I_NETSCAPE_RSA_2 142
872#define ASN1_F_D2I_NETSCAPE_SPKAC 143
873#define ASN1_F_D2I_NETSCAPE_SPKI 144
874#define ASN1_F_D2I_NOTICEREF 268
875#define ASN1_F_D2I_OTHERNAME 287
876#define ASN1_F_D2I_PBE2PARAM 262
877#define ASN1_F_D2I_PBEPARAM 249
878#define ASN1_F_D2I_PBKDF2PARAM 263
879#define ASN1_F_D2I_PKCS12 254
880#define ASN1_F_D2I_PKCS12_BAGS 255
881#define ASN1_F_D2I_PKCS12_MAC_DATA 256
882#define ASN1_F_D2I_PKCS12_SAFEBAG 257
883#define ASN1_F_D2I_PKCS7 145
884#define ASN1_F_D2I_PKCS7_DIGEST 146
885#define ASN1_F_D2I_PKCS7_ENCRYPT 147
886#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148
887#define ASN1_F_D2I_PKCS7_ENVELOPE 149
888#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150
889#define ASN1_F_D2I_PKCS7_RECIP_INFO 151
890#define ASN1_F_D2I_PKCS7_SIGNED 152
891#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153
892#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154
893#define ASN1_F_D2I_PKCS8_PRIV_KEY_INFO 250
894#define ASN1_F_D2I_PKEY_USAGE_PERIOD 239
895#define ASN1_F_D2I_POLICYINFO 269
896#define ASN1_F_D2I_POLICYQUALINFO 270
897#define ASN1_F_D2I_PRIVATEKEY 155
898#define ASN1_F_D2I_PUBLICKEY 156
899#define ASN1_F_D2I_RSAPRIVATEKEY 157
900#define ASN1_F_D2I_RSAPUBLICKEY 158
901#define ASN1_F_D2I_SXNET 241
902#define ASN1_F_D2I_SXNETID 243
903#define ASN1_F_D2I_USERNOTICE 271
904#define ASN1_F_D2I_X509 159
905#define ASN1_F_D2I_X509_ALGOR 160
906#define ASN1_F_D2I_X509_ATTRIBUTE 161
907#define ASN1_F_D2I_X509_CERT_AUX 285
908#define ASN1_F_D2I_X509_CINF 162
909#define ASN1_F_D2I_X509_CRL 163
910#define ASN1_F_D2I_X509_CRL_INFO 164
911#define ASN1_F_D2I_X509_EXTENSION 165
912#define ASN1_F_D2I_X509_KEY 166
913#define ASN1_F_D2I_X509_NAME 167
914#define ASN1_F_D2I_X509_NAME_ENTRY 168
915#define ASN1_F_D2I_X509_PKEY 169
916#define ASN1_F_D2I_X509_PUBKEY 170
917#define ASN1_F_D2I_X509_REQ 171
918#define ASN1_F_D2I_X509_REQ_INFO 172
919#define ASN1_F_D2I_X509_REVOKED 173
920#define ASN1_F_D2I_X509_SIG 174
921#define ASN1_F_D2I_X509_VAL 175
922#define ASN1_F_DIST_POINT_NAME_NEW 278
923#define ASN1_F_DIST_POINT_NEW 279
924#define ASN1_F_GENERAL_NAME_NEW 231
925#define ASN1_F_I2D_ASN1_HEADER 176
926#define ASN1_F_I2D_ASN1_TIME 225
927#define ASN1_F_I2D_DHPARAMS 177
928#define ASN1_F_I2D_DSAPARAMS 178
929#define ASN1_F_I2D_DSAPRIVATEKEY 179
930#define ASN1_F_I2D_DSAPUBLICKEY 180
931#define ASN1_F_I2D_DSA_PUBKEY 290
932#define ASN1_F_I2D_NETSCAPE_RSA 181
933#define ASN1_F_I2D_PKCS7 182
934#define ASN1_F_I2D_PRIVATEKEY 183
935#define ASN1_F_I2D_PUBLICKEY 184
936#define ASN1_F_I2D_RSAPRIVATEKEY 185
937#define ASN1_F_I2D_RSAPUBLICKEY 186
938#define ASN1_F_I2D_RSA_PUBKEY 289
939#define ASN1_F_I2D_X509_ATTRIBUTE 187
940#define ASN1_F_I2T_ASN1_OBJECT 188
941#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229
942#define ASN1_F_NETSCAPE_PKEY_NEW 189
943#define ASN1_F_NETSCAPE_SPKAC_NEW 190
944#define ASN1_F_NETSCAPE_SPKI_NEW 191
945#define ASN1_F_NOTICEREF_NEW 272
946#define ASN1_F_OTHERNAME_NEW 288
947#define ASN1_F_PBE2PARAM_NEW 264
948#define ASN1_F_PBEPARAM_NEW 251
949#define ASN1_F_PBKDF2PARAM_NEW 265
950#define ASN1_F_PKCS12_BAGS_NEW 258
951#define ASN1_F_PKCS12_MAC_DATA_NEW 259
952#define ASN1_F_PKCS12_NEW 260
953#define ASN1_F_PKCS12_SAFEBAG_NEW 261
954#define ASN1_F_PKCS5_PBE2_SET 281
955#define ASN1_F_PKCS7_DIGEST_NEW 192
956#define ASN1_F_PKCS7_ENCRYPT_NEW 193
957#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194
958#define ASN1_F_PKCS7_ENVELOPE_NEW 195
959#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196
960#define ASN1_F_PKCS7_NEW 197
961#define ASN1_F_PKCS7_RECIP_INFO_NEW 198
962#define ASN1_F_PKCS7_SIGNED_NEW 199
963#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200
964#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201
965#define ASN1_F_PKCS8_PRIV_KEY_INFO_NEW 252
966#define ASN1_F_PKEY_USAGE_PERIOD_NEW 240
967#define ASN1_F_POLICYINFO_NEW 273
968#define ASN1_F_POLICYQUALINFO_NEW 274
969#define ASN1_F_SXNETID_NEW 244
970#define ASN1_F_SXNET_NEW 242
971#define ASN1_F_USERNOTICE_NEW 275
972#define ASN1_F_X509_ALGOR_NEW 202
973#define ASN1_F_X509_ATTRIBUTE_NEW 203
974#define ASN1_F_X509_CERT_AUX_NEW 286
975#define ASN1_F_X509_CINF_NEW 204
976#define ASN1_F_X509_CRL_INFO_NEW 205
977#define ASN1_F_X509_CRL_NEW 206
978#define ASN1_F_X509_DHPARAMS_NEW 207
979#define ASN1_F_X509_EXTENSION_NEW 208
980#define ASN1_F_X509_INFO_NEW 209
981#define ASN1_F_X509_KEY_NEW 210
982#define ASN1_F_X509_NAME_ENTRY_NEW 211
983#define ASN1_F_X509_NAME_NEW 212
984#define ASN1_F_X509_NEW 213
985#define ASN1_F_X509_PKEY_NEW 214
986#define ASN1_F_X509_PUBKEY_NEW 215
987#define ASN1_F_X509_REQ_INFO_NEW 216
988#define ASN1_F_X509_REQ_NEW 217
989#define ASN1_F_X509_REVOKED_NEW 218
990#define ASN1_F_X509_SIG_NEW 219
991#define ASN1_F_X509_VAL_FREE 220
992#define ASN1_F_X509_VAL_NEW 221
993
994/* Reason codes. */
995#define ASN1_R_BAD_CLASS 100
996#define ASN1_R_BAD_OBJECT_HEADER 101
997#define ASN1_R_BAD_PASSWORD_READ 102
998#define ASN1_R_BAD_PKCS7_CONTENT 103
999#define ASN1_R_BAD_PKCS7_TYPE 104
1000#define ASN1_R_BAD_TAG 105
1001#define ASN1_R_BAD_TYPE 106
1002#define ASN1_R_BN_LIB 107
1003#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108
1004#define ASN1_R_BUFFER_TOO_SMALL 109
1005#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 166
1006#define ASN1_R_DATA_IS_WRONG 110
1007#define ASN1_R_DECODE_ERROR 155
1008#define ASN1_R_DECODING_ERROR 111
1009#define ASN1_R_ENCODE_ERROR 156
1010#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112
1011#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 157
1012#define ASN1_R_EXPECTING_AN_ENUMERATED 154
1013#define ASN1_R_EXPECTING_AN_INTEGER 113
1014#define ASN1_R_EXPECTING_AN_OBJECT 114
1015#define ASN1_R_EXPECTING_AN_OCTET_STRING 115
1016#define ASN1_R_EXPECTING_A_BIT_STRING 116
1017#define ASN1_R_EXPECTING_A_BOOLEAN 117
1018#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151
1019#define ASN1_R_EXPECTING_A_NULL 164
1020#define ASN1_R_EXPECTING_A_TIME 152
1021#define ASN1_R_EXPECTING_A_UTCTIME 118
1022#define ASN1_R_FIRST_NUM_TOO_LARGE 119
1023#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153
1024#define ASN1_R_HEADER_TOO_LONG 120
1025#define ASN1_R_ILLEGAL_CHARACTERS 158
1026#define ASN1_R_INVALID_BMPSTRING_LENGTH 159
1027#define ASN1_R_INVALID_DIGIT 121
1028#define ASN1_R_INVALID_SEPARATOR 122
1029#define ASN1_R_INVALID_TIME_FORMAT 123
1030#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 160
1031#define ASN1_R_INVALID_UTF8STRING 161
1032#define ASN1_R_IV_TOO_LARGE 124
1033#define ASN1_R_LENGTH_ERROR 125
1034#define ASN1_R_MISSING_SECOND_NUMBER 126
1035#define ASN1_R_NON_HEX_CHARACTERS 127
1036#define ASN1_R_NOT_ENOUGH_DATA 128
1037#define ASN1_R_NULL_IS_WRONG_LENGTH 165
1038#define ASN1_R_ODD_NUMBER_OF_CHARS 129
1039#define ASN1_R_PARSING 130
1040#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131
1041#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132
1042#define ASN1_R_SHORT_LINE 133
1043#define ASN1_R_STRING_TOO_LONG 163
1044#define ASN1_R_STRING_TOO_SHORT 134
1045#define ASN1_R_TAG_VALUE_TOO_HIGH 135
1046#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136
1047#define ASN1_R_TOO_LONG 137
1048#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138
1049#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139
1050#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140
1051#define ASN1_R_UNKNOWN_FORMAT 162
1052#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141
1053#define ASN1_R_UNKNOWN_OBJECT_TYPE 142
1054#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143
1055#define ASN1_R_UNSUPPORTED_CIPHER 144
1056#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145
1057#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146
1058#define ASN1_R_UTCTIME_TOO_LONG 147
1059#define ASN1_R_WRONG_PRINTABLE_TYPE 148
1060#define ASN1_R_WRONG_TAG 149
1061#define ASN1_R_WRONG_TYPE 150
1062
1063#ifdef __cplusplus
1064}
1065#endif
1066#endif
1067
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 be8daa8688..0000000000
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ /dev/null
@@ -1,424 +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;
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 while (tag > 0x7f)
194 {
195 *(p++)=(tag&0x7f)|0x80;
196 tag>>=7;
197 }
198 *(p++)=(tag&0x7f);
199 }
200 if ((constructed == 2) && (length == 0))
201 *(p++)=0x80; /* der_put_length would output 0 instead */
202 else
203 asn1_put_length(&p,length);
204 *pp=p;
205 }
206
207static void asn1_put_length(unsigned char **pp, int length)
208 {
209 unsigned char *p= *pp;
210 int i,l;
211 if (length <= 127)
212 *(p++)=(unsigned char)length;
213 else
214 {
215 l=length;
216 for (i=0; l > 0; i++)
217 l>>=8;
218 *(p++)=i|0x80;
219 l=i;
220 while (i-- > 0)
221 {
222 p[i]=length&0xff;
223 length>>=8;
224 }
225 p+=l;
226 }
227 *pp=p;
228 }
229
230int ASN1_object_size(int constructed, int length, int tag)
231 {
232 int ret;
233
234 ret=length;
235 ret++;
236 if (tag >= 31)
237 {
238 while (tag > 0)
239 {
240 tag>>=7;
241 ret++;
242 }
243 }
244 if ((length == 0) && (constructed == 2))
245 ret+=2;
246 ret++;
247 if (length > 127)
248 {
249 while (length > 0)
250 {
251 length>>=8;
252 ret++;
253 }
254 }
255 return(ret);
256 }
257
258int asn1_Finish(ASN1_CTX *c)
259 {
260 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
261 {
262 if (!ASN1_check_infinite_end(&c->p,c->slen))
263 {
264 c->error=ERR_R_MISSING_ASN1_EOS;
265 return(0);
266 }
267 }
268 if ( ((c->slen != 0) && !(c->inf & 1)) ||
269 ((c->slen < 0) && (c->inf & 1)))
270 {
271 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
272 return(0);
273 }
274 return(1);
275 }
276
277int asn1_GetSequence(ASN1_CTX *c, long *length)
278 {
279 unsigned char *q;
280
281 q=c->p;
282 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
283 *length);
284 if (c->inf & 0x80)
285 {
286 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
287 return(0);
288 }
289 if (c->tag != V_ASN1_SEQUENCE)
290 {
291 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
292 return(0);
293 }
294 (*length)-=(c->p-q);
295 if (c->max && (*length < 0))
296 {
297 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
298 return(0);
299 }
300 if (c->inf == (1|V_ASN1_CONSTRUCTED))
301 c->slen= *length+ *(c->pp)-c->p;
302 c->eos=0;
303 return(1);
304 }
305
306ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
307 {
308 ASN1_STRING *ret;
309
310 if (str == NULL) return(NULL);
311 if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
312 return(NULL);
313 if (!ASN1_STRING_set(ret,str->data,str->length))
314 {
315 ASN1_STRING_free(ret);
316 return(NULL);
317 }
318 ret->flags = str->flags;
319 return(ret);
320 }
321
322int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
323 {
324 unsigned char *c;
325 const char *data=_data;
326
327 if (len < 0)
328 {
329 if (data == NULL)
330 return(0);
331 else
332 len=strlen(data);
333 }
334 if ((str->length < len) || (str->data == NULL))
335 {
336 c=str->data;
337 if (c == NULL)
338 str->data=Malloc(len+1);
339 else
340 str->data=Realloc(c,len+1);
341
342 if (str->data == NULL)
343 {
344 str->data=c;
345 return(0);
346 }
347 }
348 str->length=len;
349 if (data != NULL)
350 {
351 memcpy(str->data,data,len);
352 /* an allowance for strings :-) */
353 str->data[len]='\0';
354 }
355 return(1);
356 }
357
358ASN1_STRING *ASN1_STRING_new(void)
359 {
360 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
361 }
362
363
364ASN1_STRING *ASN1_STRING_type_new(int type)
365 {
366 ASN1_STRING *ret;
367
368 ret=(ASN1_STRING *)Malloc(sizeof(ASN1_STRING));
369 if (ret == NULL)
370 {
371 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
372 return(NULL);
373 }
374 ret->length=0;
375 ret->type=type;
376 ret->data=NULL;
377 ret->flags=0;
378 return(ret);
379 }
380
381void ASN1_STRING_free(ASN1_STRING *a)
382 {
383 if (a == NULL) return;
384 if (a->data != NULL) Free(a->data);
385 Free(a);
386 }
387
388int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
389 {
390 int i;
391
392 i=(a->length-b->length);
393 if (i == 0)
394 {
395 i=memcmp(a->data,b->data,a->length);
396 if (i == 0)
397 return(a->type-b->type);
398 else
399 return(i);
400 }
401 else
402 return(i);
403 }
404
405void asn1_add_error(unsigned char *address, int offset)
406 {
407 char buf1[16],buf2[16];
408
409 sprintf(buf1,"%lu",(unsigned long)address);
410 sprintf(buf2,"%d",offset);
411 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
412 }
413
414int ASN1_STRING_length(ASN1_STRING *x)
415{ return M_ASN1_STRING_length(x); }
416
417void ASN1_STRING_length_set(ASN1_STRING *x, int len)
418{ M_ASN1_STRING_length_set(x, len); return; }
419
420int ASN1_STRING_type(ASN1_STRING *x)
421{ return M_ASN1_STRING_type(x); }
422
423unsigned char * ASN1_STRING_data(ASN1_STRING *x)
424{ 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 4f2a82d340..0000000000
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ /dev/null
@@ -1,560 +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#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <openssl/asn1.h>
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_D2I_get_IMP_set_opt(b,func,free_func,tag) \
200 if ((c.slen != 0) && \
201 (M_ASN1_next == \
202 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
203 { \
204 M_ASN1_D2I_get_imp_set(b,func,free_func,\
205 tag,V_ASN1_CONTEXT_SPECIFIC); \
206 }
207
208#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
209 if ((c.slen != 0) && \
210 (M_ASN1_next == \
211 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
212 { \
213 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
214 tag,V_ASN1_CONTEXT_SPECIFIC); \
215 }
216
217#define M_ASN1_D2I_get_seq(r,func,free_func) \
218 M_ASN1_D2I_get_imp_set(r,func,free_func,\
219 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
220
221#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
222 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
223 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
224
225#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
226 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
227 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
228 { M_ASN1_D2I_get_seq(r,func,free_func); }
229
230#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
231 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
232 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
233 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
234
235#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
236 M_ASN1_D2I_get_imp_set(r,func,free_func,\
237 x,V_ASN1_CONTEXT_SPECIFIC);
238
239#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
240 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
241 x,V_ASN1_CONTEXT_SPECIFIC);
242
243#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
244 c.q=c.p; \
245 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
246 (void (*)())free_func,a,b) == NULL) \
247 { c.line=__LINE__; goto err; } \
248 c.slen-=(c.p-c.q);
249
250#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
251 c.q=c.p; \
252 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
253 free_func,a,b) == NULL) \
254 { c.line=__LINE__; goto err; } \
255 c.slen-=(c.p-c.q);
256
257#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
258 c.q=c.p; \
259 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
260 { c.line=__LINE__; goto err; } \
261 c.slen-=(c.p-c.q);
262
263#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
264 if ((c.slen != 0L) && (M_ASN1_next == \
265 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
266 { \
267 int Tinf,Ttag,Tclass; \
268 long Tlen; \
269 \
270 c.q=c.p; \
271 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
272 if (Tinf & 0x80) \
273 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
274 c.line=__LINE__; goto err; } \
275 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
276 Tlen = c.slen - (c.p - c.q) - 2; \
277 if (func(&(r),&c.p,Tlen) == NULL) \
278 { c.line=__LINE__; goto err; } \
279 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
280 Tlen = c.slen - (c.p - c.q); \
281 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
282 { c.error=ERR_R_MISSING_ASN1_EOS; \
283 c.line=__LINE__; goto err; } \
284 }\
285 c.slen-=(c.p-c.q); \
286 }
287
288#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
289 if ((c.slen != 0) && (M_ASN1_next == \
290 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
291 { \
292 int Tinf,Ttag,Tclass; \
293 long Tlen; \
294 \
295 c.q=c.p; \
296 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
297 if (Tinf & 0x80) \
298 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
299 c.line=__LINE__; goto err; } \
300 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
301 Tlen = c.slen - (c.p - c.q) - 2; \
302 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
303 (void (*)())free_func, \
304 b,V_ASN1_UNIVERSAL) == NULL) \
305 { c.line=__LINE__; goto err; } \
306 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
307 Tlen = c.slen - (c.p - c.q); \
308 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
309 { c.error=ERR_R_MISSING_ASN1_EOS; \
310 c.line=__LINE__; goto err; } \
311 }\
312 c.slen-=(c.p-c.q); \
313 }
314
315#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
316 if ((c.slen != 0) && (M_ASN1_next == \
317 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
318 { \
319 int Tinf,Ttag,Tclass; \
320 long Tlen; \
321 \
322 c.q=c.p; \
323 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
324 if (Tinf & 0x80) \
325 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
326 c.line=__LINE__; goto err; } \
327 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
328 Tlen = c.slen - (c.p - c.q) - 2; \
329 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
330 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
331 { c.line=__LINE__; goto err; } \
332 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
333 Tlen = c.slen - (c.p - c.q); \
334 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
335 { c.error=ERR_R_MISSING_ASN1_EOS; \
336 c.line=__LINE__; goto err; } \
337 }\
338 c.slen-=(c.p-c.q); \
339 }
340
341/* New macros */
342#define M_ASN1_New_Malloc(ret,type) \
343 if ((ret=(type *)Malloc(sizeof(type))) == NULL) \
344 { c.line=__LINE__; goto err2; }
345
346#define M_ASN1_New(arg,func) \
347 if (((arg)=func()) == NULL) return(NULL)
348
349#define M_ASN1_New_Error(a) \
350/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
351 return(NULL);*/ \
352 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
353 return(NULL)
354
355
356#define M_ASN1_next (*c.p)
357#define M_ASN1_next_prev (*c.q)
358
359/*************************************************/
360
361#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
362 unsigned char *p; \
363 if (a == NULL) return(0)
364
365/* Length Macros */
366#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
367#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
368
369#define M_ASN1_I2D_len_SET(a,f) \
370 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
371
372#define M_ASN1_I2D_len_SET_type(type,a,f) \
373 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
374 V_ASN1_UNIVERSAL,IS_SET);
375
376#define M_ASN1_I2D_len_SEQUENCE(a,f) \
377 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
378 IS_SEQUENCE);
379
380#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
381 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
382 V_ASN1_UNIVERSAL,IS_SEQUENCE)
383
384#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
385 if ((a != NULL) && (sk_num(a) != 0)) \
386 M_ASN1_I2D_len_SEQUENCE(a,f);
387
388#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
389 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
390 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
391
392#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
393 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
394
395#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
396 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
397 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
398
399#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
400 if ((a != NULL) && (sk_num(a) != 0)) \
401 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
402 IS_SET);
403
404#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
405 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
406 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
407 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
408
409#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
410 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
411 IS_SEQUENCE);
412
413#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
414 if ((a != NULL) && (sk_num(a) != 0)) \
415 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
416 IS_SEQUENCE);
417
418#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
419 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
420 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
421 V_ASN1_CONTEXT_SPECIFIC, \
422 IS_SEQUENCE);
423
424#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
425 if (a != NULL)\
426 { \
427 v=f(a,NULL); \
428 ret+=ASN1_object_size(1,v,mtag); \
429 }
430
431#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
432 if ((a != NULL) && (sk_num(a) != 0))\
433 { \
434 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
435 ret+=ASN1_object_size(1,v,mtag); \
436 }
437
438#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
439 if ((a != NULL) && (sk_num(a) != 0))\
440 { \
441 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
442 IS_SEQUENCE); \
443 ret+=ASN1_object_size(1,v,mtag); \
444 }
445
446#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
447 if ((a != NULL) && (sk_##type##_num(a) != 0))\
448 { \
449 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
450 V_ASN1_UNIVERSAL, \
451 IS_SEQUENCE); \
452 ret+=ASN1_object_size(1,v,mtag); \
453 }
454
455/* Put Macros */
456#define M_ASN1_I2D_put(a,f) f(a,&p)
457
458#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
459 if (a != NULL) \
460 { \
461 unsigned char *q=p; \
462 f(a,&p); \
463 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
464 }
465
466#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
467 V_ASN1_UNIVERSAL,IS_SET)
468#define M_ASN1_I2D_put_SET_type(type,a,f) \
469 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
470#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
471 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
472#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
473 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
474#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
475 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
476
477#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
478 V_ASN1_UNIVERSAL,IS_SEQUENCE)
479
480#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
481 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
482 IS_SEQUENCE)
483
484#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
485 if ((a != NULL) && (sk_num(a) != 0)) \
486 M_ASN1_I2D_put_SEQUENCE(a,f);
487
488#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
489 if ((a != NULL) && (sk_num(a) != 0)) \
490 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
491 IS_SET); }
492
493#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
494 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
495 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
496 V_ASN1_CONTEXT_SPECIFIC, \
497 IS_SET); }
498
499#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
500 if ((a != NULL) && (sk_num(a) != 0)) \
501 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
502 IS_SEQUENCE); }
503
504#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
505 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
506 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
507 V_ASN1_CONTEXT_SPECIFIC, \
508 IS_SEQUENCE); }
509
510#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
511 if (a != NULL) \
512 { \
513 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
514 f(a,&p); \
515 }
516
517#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
518 if ((a != NULL) && (sk_num(a) != 0)) \
519 { \
520 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
521 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
522 }
523
524#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
525 if ((a != NULL) && (sk_num(a) != 0)) \
526 { \
527 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
528 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
529 }
530
531#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
532 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
533 { \
534 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
535 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
536 IS_SEQUENCE); \
537 }
538
539#define M_ASN1_I2D_seq_total() \
540 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
541 if (pp == NULL) return(r); \
542 p= *pp; \
543 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
544
545#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
546 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
547 *(p++)=0x80
548
549#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
550
551#define M_ASN1_I2D_finish() *pp=p; \
552 return(r);
553
554int asn1_GetSequence(ASN1_CTX *c, long *length);
555void asn1_add_error(unsigned char *address,int offset);
556#ifdef __cplusplus
557}
558#endif
559
560#endif
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
deleted file mode 100644
index d1e9816bad..0000000000
--- a/src/lib/libcrypto/asn1/asn1_par.c
+++ /dev/null
@@ -1,385 +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);
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));
114 }
115
116static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
117 int depth, int indent)
118 {
119 unsigned char *p,*ep,*tot,*op,*opp;
120 long len;
121 int tag,xclass,ret=0;
122 int nl,hl,j,r;
123 ASN1_OBJECT *o=NULL;
124 ASN1_OCTET_STRING *os=NULL;
125 /* ASN1_BMPSTRING *bmp=NULL;*/
126
127 p= *pp;
128 tot=p+length;
129 op=p-1;
130 while ((p < tot) && (op < p))
131 {
132 op=p;
133 j=ASN1_get_object(&p,&len,&tag,&xclass,length);
134#ifdef LINT
135 j=j;
136#endif
137 if (j & 0x80)
138 {
139 if (BIO_write(bp,"Error in encoding\n",18) <= 0)
140 goto end;
141 ret=0;
142 goto end;
143 }
144 hl=(p-op);
145 length-=hl;
146 /* if j == 0x21 it is a constructed indefinite length object */
147 if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
148 <= 0) goto end;
149
150 if (j != (V_ASN1_CONSTRUCTED | 1))
151 {
152 if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
153 depth,(long)hl,len) <= 0)
154 goto end;
155 }
156 else
157 {
158 if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
159 depth,(long)hl) <= 0)
160 goto end;
161 }
162 if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
163 goto end;
164 if (j & V_ASN1_CONSTRUCTED)
165 {
166 ep=p+len;
167 if (BIO_write(bp,"\n",1) <= 0) goto end;
168 if (len > length)
169 {
170 BIO_printf(bp,
171 "length is greater than %ld\n",length);
172 ret=0;
173 goto end;
174 }
175 if ((j == 0x21) && (len == 0))
176 {
177 for (;;)
178 {
179 r=asn1_parse2(bp,&p,(long)(tot-p),
180 offset+(p - *pp),depth+1,
181 indent);
182 if (r == 0) { ret=0; goto end; }
183 if ((r == 2) || (p >= tot)) break;
184 }
185 }
186 else
187 while (p < ep)
188 {
189 r=asn1_parse2(bp,&p,(long)len,
190 offset+(p - *pp),depth+1,
191 indent);
192 if (r == 0) { ret=0; goto end; }
193 }
194 }
195 else if (xclass != 0)
196 {
197 p+=len;
198 if (BIO_write(bp,"\n",1) <= 0) goto end;
199 }
200 else
201 {
202 nl=0;
203 if ( (tag == V_ASN1_PRINTABLESTRING) ||
204 (tag == V_ASN1_T61STRING) ||
205 (tag == V_ASN1_IA5STRING) ||
206 (tag == V_ASN1_VISIBLESTRING) ||
207 (tag == V_ASN1_UTCTIME) ||
208 (tag == V_ASN1_GENERALIZEDTIME))
209 {
210 if (BIO_write(bp,":",1) <= 0) goto end;
211 if ((len > 0) &&
212 BIO_write(bp,(char *)p,(int)len)
213 != (int)len)
214 goto end;
215 }
216 else if (tag == V_ASN1_OBJECT)
217 {
218 opp=op;
219 if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
220 {
221 if (BIO_write(bp,":",1) <= 0) goto end;
222 i2a_ASN1_OBJECT(bp,o);
223 }
224 else
225 {
226 if (BIO_write(bp,":BAD OBJECT",11) <= 0)
227 goto end;
228 }
229 }
230 else if (tag == V_ASN1_BOOLEAN)
231 {
232 int ii;
233
234 opp=op;
235 ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
236 if (ii < 0)
237 {
238 if (BIO_write(bp,"Bad boolean\n",12))
239 goto end;
240 }
241 BIO_printf(bp,":%d",ii);
242 }
243 else if (tag == V_ASN1_BMPSTRING)
244 {
245 /* do the BMP thang */
246 }
247 else if (tag == V_ASN1_OCTET_STRING)
248 {
249 int i,printable=1;
250
251 opp=op;
252 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
253 if (os != NULL)
254 {
255 opp=os->data;
256 for (i=0; i<os->length; i++)
257 {
258 if (( (opp[i] < ' ') &&
259 (opp[i] != '\n') &&
260 (opp[i] != '\r') &&
261 (opp[i] != '\t')) ||
262 (opp[i] > '~'))
263 {
264 printable=0;
265 break;
266 }
267 }
268 if (printable && (os->length > 0))
269 {
270 if (BIO_write(bp,":",1) <= 0)
271 goto end;
272 if (BIO_write(bp,(char *)opp,
273 os->length) <= 0)
274 goto end;
275 }
276 M_ASN1_OCTET_STRING_free(os);
277 os=NULL;
278 }
279 }
280 else if (tag == V_ASN1_INTEGER)
281 {
282 ASN1_INTEGER *bs;
283 int i;
284
285 opp=op;
286 bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
287 if (bs != NULL)
288 {
289 if (BIO_write(bp,":",1) <= 0) goto end;
290 if (bs->type == V_ASN1_NEG_INTEGER)
291 if (BIO_write(bp,"-",1) <= 0)
292 goto end;
293 for (i=0; i<bs->length; i++)
294 {
295 if (BIO_printf(bp,"%02X",
296 bs->data[i]) <= 0)
297 goto end;
298 }
299 if (bs->length == 0)
300 {
301 if (BIO_write(bp,"00",2) <= 0)
302 goto end;
303 }
304 }
305 else
306 {
307 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
308 goto end;
309 }
310 M_ASN1_INTEGER_free(bs);
311 }
312 else if (tag == V_ASN1_ENUMERATED)
313 {
314 ASN1_ENUMERATED *bs;
315 int i;
316
317 opp=op;
318 bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
319 if (bs != NULL)
320 {
321 if (BIO_write(bp,":",1) <= 0) goto end;
322 if (bs->type == V_ASN1_NEG_ENUMERATED)
323 if (BIO_write(bp,"-",1) <= 0)
324 goto end;
325 for (i=0; i<bs->length; i++)
326 {
327 if (BIO_printf(bp,"%02X",
328 bs->data[i]) <= 0)
329 goto end;
330 }
331 if (bs->length == 0)
332 {
333 if (BIO_write(bp,"00",2) <= 0)
334 goto end;
335 }
336 }
337 else
338 {
339 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
340 goto end;
341 }
342 M_ASN1_ENUMERATED_free(bs);
343 }
344
345 if (!nl)
346 {
347 if (BIO_write(bp,"\n",1) <= 0) goto end;
348 }
349 p+=len;
350 if ((tag == V_ASN1_EOC) && (xclass == 0))
351 {
352 ret=2; /* End of sequence */
353 goto end;
354 }
355 }
356 length-=len;
357 }
358 ret=1;
359end:
360 if (o != NULL) ASN1_OBJECT_free(o);
361 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
362 *pp=p;
363 return(ret);
364 }
365
366const char *ASN1_tag2str(int tag)
367{
368 const static char *tag2str[] = {
369 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
370 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
371 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */
372 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */
373 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */
374 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */
375 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */
376 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */
377 };
378
379 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
380 tag &= ~0x100;
381
382 if(tag < 0 || tag > 30) return "(unknown)";
383 return tag2str[tag];
384}
385
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
deleted file mode 100644
index 662a2626a1..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)())
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 * 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 = 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 = 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/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 3d0b1107cb..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 *)Malloc(
157 (unsigned int)num+i*2);
158 else
159 sp=(unsigned char *)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) 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 cd57331c3f..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 *)Malloc(
164 (unsigned int)num+i*2);
165 else
166 sp=(unsigned char *)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) 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 088313689a..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 *)Malloc(
162 (unsigned int)num+i*2);
163 else
164 sp=(unsigned char *)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) 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 d804986b73..0000000000
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ /dev/null
@@ -1,348 +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 int i,j,l[6];
86 NETSCAPE_PKEY *pkey;
87 unsigned char buf[256],*zz;
88 unsigned char key[EVP_MAX_KEY_LENGTH];
89 EVP_CIPHER_CTX ctx;
90 X509_ALGOR *alg=NULL;
91 ASN1_OCTET_STRING os,os2;
92 M_ASN1_I2D_vars(a);
93
94 if (a == NULL) return(0);
95
96#ifdef WIN32
97 r=r; /* shut the damn compiler up :-) */
98#endif
99
100 os.data=os2.data=NULL;
101 if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err;
102 if (!ASN1_INTEGER_set(pkey->version,0)) goto err;
103
104 if (pkey->algor->algorithm != NULL)
105 ASN1_OBJECT_free(pkey->algor->algorithm);
106 pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption);
107 if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
108 pkey->algor->parameter->type=V_ASN1_NULL;
109
110 l[0]=i2d_RSAPrivateKey(a,NULL);
111 pkey->private_key->length=l[0];
112
113 os2.length=i2d_NETSCAPE_PKEY(pkey,NULL);
114 l[1]=i2d_ASN1_OCTET_STRING(&os2,NULL);
115
116 if ((alg=X509_ALGOR_new()) == NULL) goto err;
117 if (alg->algorithm != NULL)
118 ASN1_OBJECT_free(alg->algorithm);
119 alg->algorithm=OBJ_nid2obj(NID_rc4);
120 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
121 alg->parameter->type=V_ASN1_NULL;
122
123 l[2]=i2d_X509_ALGOR(alg,NULL);
124 l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE);
125
126#ifndef CONST_STRICT
127 os.data=(unsigned char *)"private-key";
128#endif
129 os.length=11;
130 l[4]=i2d_ASN1_OCTET_STRING(&os,NULL);
131
132 l[5]=ASN1_object_size(1,l[4]+l[3],V_ASN1_SEQUENCE);
133
134 if (pp == NULL)
135 {
136 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
137 if (alg != NULL) X509_ALGOR_free(alg);
138 return(l[5]);
139 }
140
141 if (pkey->private_key->data != NULL)
142 Free(pkey->private_key->data);
143 if ((pkey->private_key->data=(unsigned char *)Malloc(l[0])) == NULL)
144 {
145 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
146 goto err;
147 }
148 zz=pkey->private_key->data;
149 i2d_RSAPrivateKey(a,&zz);
150
151 if ((os2.data=(unsigned char *)Malloc(os2.length)) == NULL)
152 {
153 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
154 goto err;
155 }
156 zz=os2.data;
157 i2d_NETSCAPE_PKEY(pkey,&zz);
158
159 if (cb == NULL)
160 cb=EVP_read_pw_string;
161 i=cb(buf,256,"Enter Private Key password:",1);
162 if (i != 0)
163 {
164 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
165 goto err;
166 }
167 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,
168 strlen((char *)buf),1,key,NULL);
169 memset(buf,0,256);
170
171 EVP_CIPHER_CTX_init(&ctx);
172 EVP_EncryptInit(&ctx,EVP_rc4(),key,NULL);
173 EVP_EncryptUpdate(&ctx,os2.data,&i,os2.data,os2.length);
174 EVP_EncryptFinal(&ctx,&(os2.data[i]),&j);
175 EVP_CIPHER_CTX_cleanup(&ctx);
176
177 p= *pp;
178 ASN1_put_object(&p,1,l[4]+l[3],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
179 i2d_ASN1_OCTET_STRING(&os,&p);
180 ASN1_put_object(&p,1,l[2]+l[1],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
181 i2d_X509_ALGOR(alg,&p);
182 i2d_ASN1_OCTET_STRING(&os2,&p);
183 ret=l[5];
184err:
185 if (os2.data != NULL) Free(os2.data);
186 if (alg != NULL) X509_ALGOR_free(alg);
187 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
188 r=r;
189 return(ret);
190 }
191
192RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)())
193 {
194 RSA *ret=NULL;
195 ASN1_OCTET_STRING *os=NULL;
196 ASN1_CTX c;
197
198 c.pp=pp;
199 c.error=ASN1_R_DECODING_ERROR;
200
201 M_ASN1_D2I_Init();
202 M_ASN1_D2I_start_sequence();
203 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
204 if ((os->length != 11) || (strncmp("private-key",
205 (char *)os->data,os->length) != 0))
206 {
207 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
208 M_ASN1_BIT_STRING_free(os);
209 goto err;
210 }
211 M_ASN1_BIT_STRING_free(os);
212 c.q=c.p;
213 if ((ret=d2i_Netscape_RSA_2(a,&c.p,c.slen,cb)) == NULL) goto err;
214 c.slen-=(c.p-c.q);
215
216 M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA);
217 }
218
219RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length,
220 int (*cb)())
221 {
222 NETSCAPE_PKEY *pkey=NULL;
223 RSA *ret=NULL;
224 int i,j;
225 unsigned char buf[256],*zz;
226 unsigned char key[EVP_MAX_KEY_LENGTH];
227 EVP_CIPHER_CTX ctx;
228 X509_ALGOR *alg=NULL;
229 ASN1_OCTET_STRING *os=NULL;
230 ASN1_CTX c;
231
232 c.error=ERR_R_NESTED_ASN1_ERROR;
233 c.pp=pp;
234
235 M_ASN1_D2I_Init();
236 M_ASN1_D2I_start_sequence();
237 M_ASN1_D2I_get(alg,d2i_X509_ALGOR);
238 if (OBJ_obj2nid(alg->algorithm) != NID_rc4)
239 {
240 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
241 goto err;
242 }
243 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
244 if (cb == NULL)
245 cb=EVP_read_pw_string;
246 i=cb(buf,256,"Enter Private Key password:",0);
247 if (i != 0)
248 {
249 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
250 goto err;
251 }
252
253 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,
254 strlen((char *)buf),1,key,NULL);
255 memset(buf,0,256);
256
257 EVP_CIPHER_CTX_init(&ctx);
258 EVP_DecryptInit(&ctx,EVP_rc4(),key,NULL);
259 EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length);
260 EVP_DecryptFinal(&ctx,&(os->data[i]),&j);
261 EVP_CIPHER_CTX_cleanup(&ctx);
262 os->length=i+j;
263
264 zz=os->data;
265
266 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
267 {
268 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
269 goto err;
270 }
271
272 zz=pkey->private_key->data;
273 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
274 {
275 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
276 goto err;
277 }
278 if (!asn1_Finish(&c)) goto err;
279 *pp=c.p;
280err:
281 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
282 if (os != NULL) M_ASN1_BIT_STRING_free(os);
283 if (alg != NULL) X509_ALGOR_free(alg);
284 return(ret);
285 }
286
287static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp)
288 {
289 M_ASN1_I2D_vars(a);
290
291
292 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
293 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
294 M_ASN1_I2D_len(a->private_key, i2d_ASN1_OCTET_STRING);
295
296 M_ASN1_I2D_seq_total();
297
298 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
299 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
300 M_ASN1_I2D_put(a->private_key, i2d_ASN1_OCTET_STRING);
301
302 M_ASN1_I2D_finish();
303 }
304
305static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, unsigned char **pp,
306 long length)
307 {
308 M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new);
309
310 M_ASN1_D2I_Init();
311 M_ASN1_D2I_start_sequence();
312 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
313 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
314 M_ASN1_D2I_get(ret->private_key,d2i_ASN1_OCTET_STRING);
315 M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY);
316 }
317
318static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
319 {
320 NETSCAPE_PKEY *ret=NULL;
321 ASN1_CTX c;
322
323 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY);
324 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
325 M_ASN1_New(ret->algor,X509_ALGOR_new);
326 M_ASN1_New(ret->private_key,M_ASN1_OCTET_STRING_new);
327 return(ret);
328 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW);
329 }
330
331static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a)
332 {
333 if (a == NULL) return;
334 M_ASN1_INTEGER_free(a->version);
335 X509_ALGOR_free(a->algor);
336 M_ASN1_OCTET_STRING_free(a->private_key);
337 Free(a);
338 }
339
340#endif /* NO_RC4 */
341
342#else /* !NO_RSA */
343
344# if PEDANTIC
345static void *dummy=&dummy;
346# endif
347
348#endif
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c
deleted file mode 100644
index 417d024b81..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 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 a147ac3295..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 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 = 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 1bbdb10c71..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 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 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 = 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 59cfbe7f28..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 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 e570ed1c47..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 *)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) 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 *)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) 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 *)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) 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 *)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) 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 6ee1065ce9..0000000000
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ /dev/null
@@ -1,409 +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) 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 s++; /* skip the first slash */
353
354 l=ll;
355 c=s;
356 for (;;)
357 {
358#ifndef CHARSET_EBCDIC
359 if ( ((*s == '/') &&
360 ((s[1] >= 'A') && (s[1] <= 'Z') && (
361 (s[2] == '=') ||
362 ((s[2] >= 'A') && (s[2] <= 'Z') &&
363 (s[3] == '='))
364 ))) ||
365 (*s == '\0'))
366#else
367 if ( ((*s == '/') &&
368 (isupper(s[1]) && (
369 (s[2] == '=') ||
370 (isupper(s[2]) &&
371 (s[3] == '='))
372 ))) ||
373 (*s == '\0'))
374#endif
375 {
376 if ((l <= 0) && !first)
377 {
378 first=0;
379 if (BIO_write(bp,"\n",1) != 1) goto err;
380 for (i=0; i<obase; i++)
381 {
382 if (BIO_write(bp," ",1) != 1) goto err;
383 }
384 l=ll;
385 }
386 i=s-c;
387 if (BIO_write(bp,c,i) != i) goto err;
388 c+=i;
389 c++;
390 if (*s != '\0')
391 {
392 if (BIO_write(bp,", ",2) != 2) goto err;
393 }
394 l--;
395 }
396 if (*s == '\0') break;
397 s++;
398 l--;
399 }
400
401 ret=1;
402 if (0)
403 {
404err:
405 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
406 }
407 return(ret);
408 }
409
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
deleted file mode 100644
index a18ebb586c..0000000000
--- a/src/lib/libcrypto/asn1/t_x509a.c
+++ /dev/null
@@ -1,102 +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 return 1;
102}
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
deleted file mode 100644
index fe023842f8..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 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 a874df79db..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 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 12a42d04c7..0000000000
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ /dev/null
@@ -1,343 +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(X509_REVOKED **a,X509_REVOKED **b);
65static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b);
66int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **pp)
67 {
68 M_ASN1_I2D_vars(a);
69
70 M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER);
71 M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_TIME);
72 M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
73 i2d_X509_EXTENSION);
74
75 M_ASN1_I2D_seq_total();
76
77 M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER);
78 M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_TIME);
79 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
80 i2d_X509_EXTENSION);
81
82 M_ASN1_I2D_finish();
83 }
84
85X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **a, unsigned char **pp,
86 long length)
87 {
88 M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new);
89
90 M_ASN1_D2I_Init();
91 M_ASN1_D2I_start_sequence();
92 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER);
93 M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_TIME);
94 M_ASN1_D2I_get_seq_opt_type(X509_EXTENSION,ret->extensions,
95 d2i_X509_EXTENSION,X509_EXTENSION_free);
96 M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED);
97 }
98
99int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
100 {
101 int v1=0;
102 long l=0;
103 int (*old_cmp)(X509_REVOKED **,X509_REVOKED **);
104 M_ASN1_I2D_vars(a);
105
106 old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp);
107 sk_X509_REVOKED_sort(a->revoked);
108 sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp);
109
110 if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0))
111 {
112 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
113 }
114 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
115 M_ASN1_I2D_len(a->issuer,i2d_X509_NAME);
116 M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_TIME);
117 if (a->nextUpdate != NULL)
118 { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_TIME); }
119 M_ASN1_I2D_len_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
120 i2d_X509_REVOKED);
121 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
122 i2d_X509_EXTENSION,0,
123 V_ASN1_SEQUENCE,v1);
124
125 M_ASN1_I2D_seq_total();
126
127 if ((a->version != NULL) && (l != 0))
128 {
129 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
130 }
131 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
132 M_ASN1_I2D_put(a->issuer,i2d_X509_NAME);
133 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_TIME);
134 if (a->nextUpdate != NULL)
135 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_TIME); }
136 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
137 i2d_X509_REVOKED);
138 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
139 i2d_X509_EXTENSION,0,
140 V_ASN1_SEQUENCE,v1);
141
142 M_ASN1_I2D_finish();
143 }
144
145X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp,
146 long length)
147 {
148 int i,ver=0;
149 M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new);
150
151
152 M_ASN1_D2I_Init();
153 M_ASN1_D2I_start_sequence();
154 M_ASN1_D2I_get_opt(ret->version,d2i_ASN1_INTEGER,V_ASN1_INTEGER);
155 if (ret->version != NULL)
156 ver=ret->version->data[0];
157
158 if ((ver == 0) && (ret->version != NULL))
159 {
160 M_ASN1_INTEGER_free(ret->version);
161 ret->version=NULL;
162 }
163 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
164 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
165 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME);
166 /* Manually handle the OPTIONAL ASN1_TIME stuff */
167 /* First try UTCTime */
168 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME, V_ASN1_UTCTIME);
169 /* If that doesn't work try GeneralizedTime */
170 if(!ret->nextUpdate)
171 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME,
172 V_ASN1_GENERALIZEDTIME);
173 if (ret->revoked != NULL)
174 {
175 while (sk_X509_REVOKED_num(ret->revoked))
176 X509_REVOKED_free(sk_X509_REVOKED_pop(ret->revoked));
177 }
178 M_ASN1_D2I_get_seq_opt_type(X509_REVOKED,ret->revoked,d2i_X509_REVOKED,
179 X509_REVOKED_free);
180
181 if (ret->revoked != NULL)
182 {
183 for (i=0; i<sk_X509_REVOKED_num(ret->revoked); i++)
184 {
185 sk_X509_REVOKED_value(ret->revoked,i)->sequence=i;
186 }
187 }
188
189 if (ret->extensions != NULL)
190 {
191 while (sk_X509_EXTENSION_num(ret->extensions))
192 X509_EXTENSION_free(
193 sk_X509_EXTENSION_pop(ret->extensions));
194 }
195
196 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
197 d2i_X509_EXTENSION,
198 X509_EXTENSION_free,0,
199 V_ASN1_SEQUENCE);
200
201 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO);
202 }
203
204int i2d_X509_CRL(X509_CRL *a, unsigned char **pp)
205 {
206 M_ASN1_I2D_vars(a);
207
208 M_ASN1_I2D_len(a->crl,i2d_X509_CRL_INFO);
209 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
210 M_ASN1_I2D_len(a->signature,i2d_ASN1_BIT_STRING);
211
212 M_ASN1_I2D_seq_total();
213
214 M_ASN1_I2D_put(a->crl,i2d_X509_CRL_INFO);
215 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
216 M_ASN1_I2D_put(a->signature,i2d_ASN1_BIT_STRING);
217
218 M_ASN1_I2D_finish();
219 }
220
221X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length)
222 {
223 M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new);
224
225 M_ASN1_D2I_Init();
226 M_ASN1_D2I_start_sequence();
227 M_ASN1_D2I_get(ret->crl,d2i_X509_CRL_INFO);
228 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
229 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
230
231 M_ASN1_D2I_Finish(a,X509_CRL_free,ASN1_F_D2I_X509_CRL);
232 }
233
234
235X509_REVOKED *X509_REVOKED_new(void)
236 {
237 X509_REVOKED *ret=NULL;
238 ASN1_CTX c;
239
240 M_ASN1_New_Malloc(ret,X509_REVOKED);
241 M_ASN1_New(ret->serialNumber,M_ASN1_INTEGER_new);
242 M_ASN1_New(ret->revocationDate,M_ASN1_UTCTIME_new);
243 ret->extensions=NULL;
244 return(ret);
245 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW);
246 }
247
248X509_CRL_INFO *X509_CRL_INFO_new(void)
249 {
250 X509_CRL_INFO *ret=NULL;
251 ASN1_CTX c;
252
253 M_ASN1_New_Malloc(ret,X509_CRL_INFO);
254 ret->version=NULL;
255 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
256 M_ASN1_New(ret->issuer,X509_NAME_new);
257 M_ASN1_New(ret->lastUpdate,M_ASN1_UTCTIME_new);
258 ret->nextUpdate=NULL;
259 M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null);
260 M_ASN1_New(ret->extensions,sk_X509_EXTENSION_new_null);
261 sk_X509_REVOKED_set_cmp_func(ret->revoked,X509_REVOKED_cmp);
262 return(ret);
263 M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW);
264 }
265
266X509_CRL *X509_CRL_new(void)
267 {
268 X509_CRL *ret=NULL;
269 ASN1_CTX c;
270
271 M_ASN1_New_Malloc(ret,X509_CRL);
272 ret->references=1;
273 M_ASN1_New(ret->crl,X509_CRL_INFO_new);
274 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
275 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
276 return(ret);
277 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW);
278 }
279
280void X509_REVOKED_free(X509_REVOKED *a)
281 {
282 if (a == NULL) return;
283 M_ASN1_INTEGER_free(a->serialNumber);
284 M_ASN1_UTCTIME_free(a->revocationDate);
285 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
286 Free(a);
287 }
288
289void X509_CRL_INFO_free(X509_CRL_INFO *a)
290 {
291 if (a == NULL) return;
292 M_ASN1_INTEGER_free(a->version);
293 X509_ALGOR_free(a->sig_alg);
294 X509_NAME_free(a->issuer);
295 M_ASN1_UTCTIME_free(a->lastUpdate);
296 if (a->nextUpdate)
297 M_ASN1_UTCTIME_free(a->nextUpdate);
298 sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free);
299 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
300 Free(a);
301 }
302
303void X509_CRL_free(X509_CRL *a)
304 {
305 int i;
306
307 if (a == NULL) return;
308
309 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_CRL);
310#ifdef REF_PRINT
311 REF_PRINT("X509_CRL",a);
312#endif
313 if (i > 0) return;
314#ifdef REF_CHECK
315 if (i < 0)
316 {
317 fprintf(stderr,"X509_CRL_free, bad reference count\n");
318 abort();
319 }
320#endif
321
322 X509_CRL_INFO_free(a->crl);
323 X509_ALGOR_free(a->sig_alg);
324 M_ASN1_BIT_STRING_free(a->signature);
325 Free(a);
326 }
327
328static int X509_REVOKED_cmp(X509_REVOKED **a, X509_REVOKED **b)
329 {
330 return(ASN1_STRING_cmp(
331 (ASN1_STRING *)(*a)->serialNumber,
332 (ASN1_STRING *)(*b)->serialNumber));
333 }
334
335static int X509_REVOKED_seq_cmp(X509_REVOKED **a, X509_REVOKED **b)
336 {
337 return((*a)->sequence-(*b)->sequence);
338 }
339
340IMPLEMENT_STACK_OF(X509_REVOKED)
341IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
342IMPLEMENT_STACK_OF(X509_CRL)
343IMPLEMENT_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 185cbd78a0..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 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 7fdc6f9dc8..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 *)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) Free(x->enc_data);
110 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 64baf5719d..0000000000
--- a/src/lib/libcrypto/asn1/x_name.c
+++ /dev/null
@@ -1,279 +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
145 ret+=ASN1_object_size(1,size,V_ASN1_SET);
146 if (fe != NULL)
147 fe->size=size;
148
149 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
150
151 buf=a->bytes;
152 if (!BUF_MEM_grow(buf,r)) goto err;
153 p=(unsigned char *)buf->data;
154
155 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
156
157 set= -1;
158 for (i=0; i<sk_X509_NAME_ENTRY_num(sk); i++)
159 {
160 ne=sk_X509_NAME_ENTRY_value(sk,i);
161 if (set != ne->set)
162 {
163 set=ne->set;
164 ASN1_put_object(&p,1,ne->size,
165 V_ASN1_SET,V_ASN1_UNIVERSAL);
166 }
167 i2d_X509_NAME_ENTRY(ne,&p);
168 }
169 a->modified=0;
170 return(r);
171err:
172 return(-1);
173 }
174
175X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length)
176 {
177 int set=0,i;
178 int idx=0;
179 unsigned char *orig;
180 M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new);
181
182 orig= *pp;
183 if (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
184 {
185 while (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
186 X509_NAME_ENTRY_free(
187 sk_X509_NAME_ENTRY_pop(ret->entries));
188 }
189
190 M_ASN1_D2I_Init();
191 M_ASN1_D2I_start_sequence();
192 for (;;)
193 {
194 if (M_ASN1_D2I_end_sequence()) break;
195 M_ASN1_D2I_get_set_type(X509_NAME_ENTRY,ret->entries,
196 d2i_X509_NAME_ENTRY,
197 X509_NAME_ENTRY_free);
198 for (; idx < sk_X509_NAME_ENTRY_num(ret->entries); idx++)
199 {
200 sk_X509_NAME_ENTRY_value(ret->entries,idx)->set=set;
201 }
202 set++;
203 }
204
205 i=(int)(c.p-orig);
206 if (!BUF_MEM_grow(ret->bytes,i)) goto err;
207 memcpy(ret->bytes->data,orig,i);
208 ret->bytes->length=i;
209 ret->modified=0;
210
211 M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME);
212 }
213
214X509_NAME *X509_NAME_new(void)
215 {
216 X509_NAME *ret=NULL;
217 ASN1_CTX c;
218
219 M_ASN1_New_Malloc(ret,X509_NAME);
220 if ((ret->entries=sk_X509_NAME_ENTRY_new(NULL)) == NULL)
221 { c.line=__LINE__; goto err2; }
222 M_ASN1_New(ret->bytes,BUF_MEM_new);
223 ret->modified=1;
224 return(ret);
225 M_ASN1_New_Error(ASN1_F_X509_NAME_NEW);
226 }
227
228X509_NAME_ENTRY *X509_NAME_ENTRY_new(void)
229 {
230 X509_NAME_ENTRY *ret=NULL;
231 ASN1_CTX c;
232
233 M_ASN1_New_Malloc(ret,X509_NAME_ENTRY);
234/* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/
235 ret->object=NULL;
236 ret->set=0;
237 M_ASN1_New(ret->value,ASN1_STRING_new);
238 return(ret);
239 M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW);
240 }
241
242void X509_NAME_free(X509_NAME *a)
243 {
244 if(a == NULL)
245 return;
246
247 BUF_MEM_free(a->bytes);
248 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
249 Free(a);
250 }
251
252void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)
253 {
254 if (a == NULL) return;
255 ASN1_OBJECT_free(a->object);
256 M_ASN1_BIT_STRING_free(a->value);
257 Free(a);
258 }
259
260int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
261 {
262 X509_NAME *in;
263
264 if (*xn == NULL) return(0);
265
266 if (*xn != name)
267 {
268 in=X509_NAME_dup(name);
269 if (in != NULL)
270 {
271 X509_NAME_free(*xn);
272 *xn=in;
273 }
274 }
275 return(*xn != NULL);
276 }
277
278IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
279IMPLEMENT_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 fe58919dbb..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)) Free(x->key_data);
150 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 7a05d575c9..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 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 *)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 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 *)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 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->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 0cd572ee73..0000000000
--- a/src/lib/libcrypto/asn1/x_req.c
+++ /dev/null
@@ -1,236 +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 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
69 M_ASN1_I2D_len(a->subject, i2d_X509_NAME);
70 M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY);
71
72 /* this is a *nasty* hack reported to be required to
73 * allow some CA Software to accept the cert request.
74 * It is not following the PKCS standards ...
75 * PKCS#10 pg 5
76 * attributes [0] IMPLICIT Attributes
77 * NOTE: no OPTIONAL ... so it *must* be there
78 */
79 if (a->req_kludge)
80 {
81 M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,i2d_X509_ATTRIBUTE,0);
82 }
83 else
84 {
85 M_ASN1_I2D_len_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
86 i2d_X509_ATTRIBUTE,0);
87 }
88
89 M_ASN1_I2D_seq_total();
90 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
91 M_ASN1_I2D_put(a->subject, i2d_X509_NAME);
92 M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY);
93
94 /* this is a *nasty* hack reported to be required by some CA's.
95 * It is not following the PKCS standards ...
96 * PKCS#10 pg 5
97 * attributes [0] IMPLICIT Attributes
98 * NOTE: no OPTIONAL ... so it *must* be there
99 */
100 if (a->req_kludge)
101 {
102 M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,
103 i2d_X509_ATTRIBUTE,0);
104 }
105 else
106 {
107 M_ASN1_I2D_put_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
108 i2d_X509_ATTRIBUTE,0);
109 }
110
111 M_ASN1_I2D_finish();
112 }
113
114X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, unsigned char **pp,
115 long length)
116 {
117 M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new);
118
119 M_ASN1_D2I_Init();
120 M_ASN1_D2I_start_sequence();
121 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
122 M_ASN1_D2I_get(ret->subject,d2i_X509_NAME);
123 M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY);
124
125 /* this is a *nasty* hack to allow for some CA's that
126 * have been reported as requiring it.
127 * It is not following the PKCS standards ...
128 * PKCS#10 pg 5
129 * attributes [0] IMPLICIT Attributes
130 * NOTE: no OPTIONAL ... so it *must* be there
131 */
132 if (asn1_Finish(&c))
133 ret->req_kludge=1;
134 else
135 {
136 M_ASN1_D2I_get_IMP_set_type(X509_ATTRIBUTE,ret->attributes,
137 d2i_X509_ATTRIBUTE,
138 X509_ATTRIBUTE_free,0);
139 }
140
141 M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO);
142 }
143
144X509_REQ_INFO *X509_REQ_INFO_new(void)
145 {
146 X509_REQ_INFO *ret=NULL;
147 ASN1_CTX c;
148
149 M_ASN1_New_Malloc(ret,X509_REQ_INFO);
150 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
151 M_ASN1_New(ret->subject,X509_NAME_new);
152 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
153 M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null);
154 ret->req_kludge=0;
155 return(ret);
156 M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW);
157 }
158
159void X509_REQ_INFO_free(X509_REQ_INFO *a)
160 {
161 if (a == NULL) return;
162 M_ASN1_INTEGER_free(a->version);
163 X509_NAME_free(a->subject);
164 X509_PUBKEY_free(a->pubkey);
165 sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free);
166 Free(a);
167 }
168
169int i2d_X509_REQ(X509_REQ *a, unsigned char **pp)
170 {
171 M_ASN1_I2D_vars(a);
172 M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO);
173 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
174 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
175
176 M_ASN1_I2D_seq_total();
177
178 M_ASN1_I2D_put(a->req_info, i2d_X509_REQ_INFO);
179 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
180 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
181
182 M_ASN1_I2D_finish();
183 }
184
185X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length)
186 {
187 M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new);
188
189 M_ASN1_D2I_Init();
190 M_ASN1_D2I_start_sequence();
191 M_ASN1_D2I_get(ret->req_info,d2i_X509_REQ_INFO);
192 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
193 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
194 M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ);
195 }
196
197X509_REQ *X509_REQ_new(void)
198 {
199 X509_REQ *ret=NULL;
200 ASN1_CTX c;
201
202 M_ASN1_New_Malloc(ret,X509_REQ);
203 ret->references=1;
204 M_ASN1_New(ret->req_info,X509_REQ_INFO_new);
205 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
206 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
207 return(ret);
208 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW);
209 }
210
211void X509_REQ_free(X509_REQ *a)
212 {
213 int i;
214
215 if (a == NULL) return;
216
217 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_REQ);
218#ifdef REF_PRINT
219 REF_PRINT("X509_REQ",a);
220#endif
221 if (i > 0) return;
222#ifdef REF_CHECK
223 if (i < 0)
224 {
225 fprintf(stderr,"X509_REQ_free, bad reference count\n");
226 abort();
227 }
228#endif
229
230 X509_REQ_INFO_free(a->req_info);
231 X509_ALGOR_free(a->sig_alg);
232 M_ASN1_BIT_STRING_free(a->signature);
233 Free(a);
234 }
235
236
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
deleted file mode 100644
index 3559bd5368..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 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 8f5e7e6380..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 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 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 1a2f49ffdf..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 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 11e564ea30..0000000000
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ /dev/null
@@ -1,210 +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
65static int x509_meth_num = 0;
66static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_meth = NULL;
67
68static ASN1_METHOD meth={
69 (int (*)()) i2d_X509,
70 (char *(*)())d2i_X509,
71 (char *(*)())X509_new,
72 (void (*)()) X509_free};
73
74ASN1_METHOD *X509_asn1_meth(void)
75 {
76 return(&meth);
77 }
78
79int i2d_X509(X509 *a, unsigned char **pp)
80 {
81 M_ASN1_I2D_vars(a);
82
83 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
84 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
85 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
86
87 M_ASN1_I2D_seq_total();
88
89 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
90 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
91 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
92
93 M_ASN1_I2D_finish();
94 }
95
96X509 *d2i_X509(X509 **a, unsigned char **pp, long length)
97 {
98 M_ASN1_D2I_vars(a,X509 *,X509_new);
99
100 M_ASN1_D2I_Init();
101 M_ASN1_D2I_start_sequence();
102 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
103 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
104 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
105 if (ret->name != NULL) Free(ret->name);
106 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
107
108 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
109 }
110
111X509 *X509_new(void)
112 {
113 X509 *ret=NULL;
114 ASN1_CTX c;
115
116 M_ASN1_New_Malloc(ret,X509);
117 ret->references=1;
118 ret->valid=0;
119 ret->ex_flags = 0;
120 ret->name=NULL;
121 ret->aux=NULL;
122 M_ASN1_New(ret->cert_info,X509_CINF_new);
123 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
124 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
125 CRYPTO_new_ex_data(x509_meth, ret, &ret->ex_data);
126 return(ret);
127 M_ASN1_New_Error(ASN1_F_X509_NEW);
128 }
129
130void X509_free(X509 *a)
131 {
132 int i;
133
134 if (a == NULL) return;
135
136 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509);
137#ifdef REF_PRINT
138 REF_PRINT("X509",a);
139#endif
140 if (i > 0) return;
141#ifdef REF_CHECK
142 if (i < 0)
143 {
144 fprintf(stderr,"X509_free, bad reference count\n");
145 abort();
146 }
147#endif
148
149 CRYPTO_free_ex_data(x509_meth,a,&a->ex_data);
150 X509_CINF_free(a->cert_info);
151 X509_ALGOR_free(a->sig_alg);
152 M_ASN1_BIT_STRING_free(a->signature);
153 X509_CERT_AUX_free(a->aux);
154
155 if (a->name != NULL) Free(a->name);
156 Free(a);
157 }
158
159int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
160 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
161 {
162 x509_meth_num++;
163 return(CRYPTO_get_ex_new_index(x509_meth_num-1,
164 &x509_meth,argl,argp,new_func,dup_func,free_func));
165 }
166
167int X509_set_ex_data(X509 *r, int idx, void *arg)
168 {
169 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
170 }
171
172void *X509_get_ex_data(X509 *r, int idx)
173 {
174 return(CRYPTO_get_ex_data(&r->ex_data,idx));
175 }
176
177/* X509_AUX ASN1 routines. X509_AUX is the name given to
178 * a certificate with extra info tagged on the end. Since these
179 * functions set how a certificate is trusted they should only
180 * be used when the certificate comes from a reliable source
181 * such as local storage.
182 *
183 */
184
185X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
186{
187 unsigned char *q;
188 X509 *ret;
189 /* Save start position */
190 q = *pp;
191 ret = d2i_X509(a, pp, length);
192 /* If certificate unreadable then forget it */
193 if(!ret) return NULL;
194 /* update length */
195 length -= *pp - q;
196 if(!length) return ret;
197 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err;
198 return ret;
199 err:
200 X509_free(ret);
201 return NULL;
202}
203
204int i2d_X509_AUX(X509 *a, unsigned char **pp)
205{
206 int length;
207 length = i2d_X509(a, pp);
208 if(a) length += i2d_X509_CERT_AUX(a->aux, pp);
209 return length;
210}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
deleted file mode 100644
index b9987ea968..0000000000
--- a/src/lib/libcrypto/asn1/x_x509a.c
+++ /dev/null
@@ -1,200 +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 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
156unsigned char *X509_alias_get0(X509 *x, int *len)
157{
158 if(!x->aux || !x->aux->alias) return NULL;
159 if(len) *len = x->aux->alias->length;
160 return x->aux->alias->data;
161}
162
163int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
164{
165 X509_CERT_AUX *aux;
166 ASN1_OBJECT *objtmp;
167 if(!(objtmp = OBJ_dup(obj))) return 0;
168 if(!(aux = aux_get(x))) return 0;
169 if(!aux->trust
170 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
171 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
172}
173
174int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
175{
176 X509_CERT_AUX *aux;
177 ASN1_OBJECT *objtmp;
178 if(!(objtmp = OBJ_dup(obj))) return 0;
179 if(!(aux = aux_get(x))) return 0;
180 if(!aux->reject
181 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
182 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
183}
184
185void X509_trust_clear(X509 *x)
186{
187 if(x->aux && x->aux->trust) {
188 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
189 x->aux->trust = NULL;
190 }
191}
192
193void X509_reject_clear(X509 *x)
194{
195 if(x->aux && x->aux->reject) {
196 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
197 x->aux->reject = NULL;
198 }
199}
200