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_digest.c27
-rw-r--r--src/lib/libcrypto/asn1/a_set.c241
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c88
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c59
-rw-r--r--src/lib/libcrypto/asn1/asn1.h25
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h137
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c87
7 files changed, 0 insertions, 664 deletions
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
index cbdeea6ac0..8a4b24a06b 100644
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ b/src/lib/libcrypto/asn1/a_digest.c
@@ -70,32 +70,6 @@
70#include <openssl/buffer.h> 70#include <openssl/buffer.h>
71#include <openssl/x509.h> 71#include <openssl/x509.h>
72 72
73#ifndef NO_ASN1_OLD
74
75int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
76 unsigned char *md, unsigned int *len)
77 {
78 int i;
79 unsigned char *str,*p;
80
81 i=i2d(data,NULL);
82 if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL)
83 {
84 ASN1err(ASN1_F_ASN1_DIGEST,ERR_R_MALLOC_FAILURE);
85 return(0);
86 }
87 p=str;
88 i2d(data,&p);
89
90 if (!EVP_Digest(str, i, md, len, type, NULL))
91 return 0;
92 OPENSSL_free(str);
93 return(1);
94 }
95
96#endif
97
98
99int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, 73int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
100 unsigned char *md, unsigned int *len) 74 unsigned char *md, unsigned int *len)
101 { 75 {
@@ -110,4 +84,3 @@ int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
110 OPENSSL_free(str); 84 OPENSSL_free(str);
111 return(1); 85 return(1);
112 } 86 }
113
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
deleted file mode 100644
index d726c8d3a8..0000000000
--- a/src/lib/libcrypto/asn1/a_set.c
+++ /dev/null
@@ -1,241 +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
63#ifndef NO_ASN1_OLD
64
65typedef struct
66 {
67 unsigned char *pbData;
68 int cbData;
69 } MYBLOB;
70
71/* SetBlobCmp
72 * This function compares two elements of SET_OF block
73 */
74static int SetBlobCmp(const void *elem1, const void *elem2 )
75 {
76 const MYBLOB *b1 = (const MYBLOB *)elem1;
77 const MYBLOB *b2 = (const MYBLOB *)elem2;
78 int r;
79
80 r = memcmp(b1->pbData, b2->pbData,
81 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
82 if(r != 0)
83 return r;
84 return b1->cbData-b2->cbData;
85 }
86
87/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
88int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
89 i2d_of_void *i2d, int ex_tag, int ex_class,
90 int is_set)
91 {
92 int ret=0,r;
93 int i;
94 unsigned char *p;
95 unsigned char *pStart, *pTempMem;
96 MYBLOB *rgSetBlob;
97 int totSize;
98
99 if (a == NULL) return(0);
100 for (i=sk_OPENSSL_BLOCK_num(a)-1; i>=0; i--)
101 ret+=i2d(sk_OPENSSL_BLOCK_value(a,i),NULL);
102 r=ASN1_object_size(1,ret,ex_tag);
103 if (pp == NULL) return(r);
104
105 p= *pp;
106 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
107
108/* Modified by gp@nsj.co.jp */
109 /* And then again by Ben */
110 /* And again by Steve */
111
112 if(!is_set || (sk_OPENSSL_BLOCK_num(a) < 2))
113 {
114 for (i=0; i<sk_OPENSSL_BLOCK_num(a); i++)
115 i2d(sk_OPENSSL_BLOCK_value(a,i),&p);
116
117 *pp=p;
118 return(r);
119 }
120
121 pStart = p; /* Catch the beg of Setblobs*/
122 /* In this array we will store the SET blobs */
123 rgSetBlob = OPENSSL_malloc(sk_OPENSSL_BLOCK_num(a) * sizeof(MYBLOB));
124 if (rgSetBlob == NULL)
125 {
126 ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
127 return(0);
128 }
129
130 for (i=0; i<sk_OPENSSL_BLOCK_num(a); i++)
131 {
132 rgSetBlob[i].pbData = p; /* catch each set encode blob */
133 i2d(sk_OPENSSL_BLOCK_value(a,i),&p);
134 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
135SetBlob
136*/
137 }
138 *pp=p;
139 totSize = p - pStart; /* This is the total size of all set blobs */
140
141 /* Now we have to sort the blobs. I am using a simple algo.
142 *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
143 qsort( rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp);
144 if (!(pTempMem = OPENSSL_malloc(totSize)))
145 {
146 ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
147 return(0);
148 }
149
150/* Copy to temp mem */
151 p = pTempMem;
152 for(i=0; i<sk_OPENSSL_BLOCK_num(a); ++i)
153 {
154 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
155 p += rgSetBlob[i].cbData;
156 }
157
158/* Copy back to user mem*/
159 memcpy(pStart, pTempMem, totSize);
160 OPENSSL_free(pTempMem);
161 OPENSSL_free(rgSetBlob);
162
163 return(r);
164 }
165
166STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
167 const unsigned char **pp,
168 long length, d2i_of_void *d2i,
169 void (*free_func)(OPENSSL_BLOCK), int ex_tag,
170 int ex_class)
171 {
172 ASN1_const_CTX c;
173 STACK_OF(OPENSSL_BLOCK) *ret=NULL;
174
175 if ((a == NULL) || ((*a) == NULL))
176 {
177 if ((ret=sk_OPENSSL_BLOCK_new_null()) == NULL)
178 {
179 ASN1err(ASN1_F_D2I_ASN1_SET,ERR_R_MALLOC_FAILURE);
180 goto err;
181 }
182 }
183 else
184 ret=(*a);
185
186 c.p= *pp;
187 c.max=(length == 0)?0:(c.p+length);
188
189 c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);
190 if (c.inf & 0x80) goto err;
191 if (ex_class != c.xclass)
192 {
193 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
194 goto err;
195 }
196 if (ex_tag != c.tag)
197 {
198 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
199 goto err;
200 }
201 if ((c.slen+c.p) > c.max)
202 {
203 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
204 goto err;
205 }
206 /* check for infinite constructed - it can be as long
207 * as the amount of data passed to us */
208 if (c.inf == (V_ASN1_CONSTRUCTED+1))
209 c.slen=length+ *pp-c.p;
210 c.max=c.p+c.slen;
211
212 while (c.p < c.max)
213 {
214 char *s;
215
216 if (M_ASN1_D2I_end_sequence()) break;
217 /* XXX: This was called with 4 arguments, incorrectly, it seems
218 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) */
219 if ((s=d2i(NULL,&c.p,c.slen)) == NULL)
220 {
221 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
222 asn1_add_error(*pp,(int)(c.p- *pp));
223 goto err;
224 }
225 if (!sk_OPENSSL_BLOCK_push(ret,s)) goto err;
226 }
227 if (a != NULL) (*a)=ret;
228 *pp=c.p;
229 return(ret);
230err:
231 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
232 {
233 if (free_func != NULL)
234 sk_OPENSSL_BLOCK_pop_free(ret,free_func);
235 else
236 sk_OPENSSL_BLOCK_free(ret);
237 }
238 return(NULL);
239 }
240
241#endif
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
index 7b4a193d6b..01b6292b65 100644
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -125,94 +125,6 @@
125#include <openssl/buffer.h> 125#include <openssl/buffer.h>
126#include "asn1_locl.h" 126#include "asn1_locl.h"
127 127
128#ifndef NO_ASN1_OLD
129
130int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
131 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
132 const EVP_MD *type)
133 {
134 EVP_MD_CTX ctx;
135 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
136 int i,inl=0,outl=0,outll=0;
137 X509_ALGOR *a;
138
139 EVP_MD_CTX_init(&ctx);
140 for (i=0; i<2; i++)
141 {
142 if (i == 0)
143 a=algor1;
144 else
145 a=algor2;
146 if (a == NULL) continue;
147 if (type->pkey_type == NID_dsaWithSHA1)
148 {
149 /* special case: RFC 2459 tells us to omit 'parameters'
150 * with id-dsa-with-sha1 */
151 ASN1_TYPE_free(a->parameter);
152 a->parameter = NULL;
153 }
154 else if ((a->parameter == NULL) ||
155 (a->parameter->type != V_ASN1_NULL))
156 {
157 ASN1_TYPE_free(a->parameter);
158 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
159 a->parameter->type=V_ASN1_NULL;
160 }
161 ASN1_OBJECT_free(a->algorithm);
162 a->algorithm=OBJ_nid2obj(type->pkey_type);
163 if (a->algorithm == NULL)
164 {
165 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
166 goto err;
167 }
168 if (a->algorithm->length == 0)
169 {
170 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
171 goto err;
172 }
173 }
174 inl=i2d(data,NULL);
175 buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl);
176 outll=outl=EVP_PKEY_size(pkey);
177 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
178 if ((buf_in == NULL) || (buf_out == NULL))
179 {
180 outl=0;
181 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
182 goto err;
183 }
184 p=buf_in;
185
186 i2d(data,&p);
187 if (!EVP_SignInit_ex(&ctx,type, NULL)
188 || !EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl)
189 || !EVP_SignFinal(&ctx,(unsigned char *)buf_out,
190 (unsigned int *)&outl,pkey))
191 {
192 outl=0;
193 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
194 goto err;
195 }
196 if (signature->data != NULL) OPENSSL_free(signature->data);
197 signature->data=buf_out;
198 buf_out=NULL;
199 signature->length=outl;
200 /* In the interests of compatibility, I'll make sure that
201 * the bit string has a 'not-used bits' value of 0
202 */
203 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
204 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
205err:
206 EVP_MD_CTX_cleanup(&ctx);
207 if (buf_in != NULL)
208 { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); }
209 if (buf_out != NULL)
210 { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); }
211 return(outl);
212 }
213
214#endif
215
216int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, 128int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
217 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, 129 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey,
218 const EVP_MD *type) 130 const EVP_MD *type)
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
index fc84cd3d19..5eb47d768c 100644
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -72,65 +72,6 @@
72#include <openssl/buffer.h> 72#include <openssl/buffer.h>
73#include <openssl/evp.h> 73#include <openssl/evp.h>
74 74
75#ifndef NO_ASN1_OLD
76
77int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
78 char *data, EVP_PKEY *pkey)
79 {
80 EVP_MD_CTX ctx;
81 const EVP_MD *type;
82 unsigned char *p,*buf_in=NULL;
83 int ret= -1,i,inl;
84
85 EVP_MD_CTX_init(&ctx);
86 i=OBJ_obj2nid(a->algorithm);
87 type=EVP_get_digestbyname(OBJ_nid2sn(i));
88 if (type == NULL)
89 {
90 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
91 goto err;
92 }
93
94 inl=i2d(data,NULL);
95 buf_in=OPENSSL_malloc((unsigned int)inl);
96 if (buf_in == NULL)
97 {
98 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
99 goto err;
100 }
101 p=buf_in;
102
103 i2d(data,&p);
104 if (!EVP_VerifyInit_ex(&ctx,type, NULL)
105 || !EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl))
106 {
107 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
108 ret=0;
109 goto err;
110 }
111
112 OPENSSL_cleanse(buf_in,(unsigned int)inl);
113 OPENSSL_free(buf_in);
114
115 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
116 (unsigned int)signature->length,pkey) <= 0)
117 {
118 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
119 ret=0;
120 goto err;
121 }
122 /* we don't need to zero the 'ctx' because we just checked
123 * public information */
124 /* memset(&ctx,0,sizeof(ctx)); */
125 ret=1;
126err:
127 EVP_MD_CTX_cleanup(&ctx);
128 return(ret);
129 }
130
131#endif
132
133
134int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, 75int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
135 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) 76 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey)
136 { 77 {
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index c48ce3cb92..c4fa8c649b 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -765,10 +765,6 @@ typedef struct BIT_STRING_BITNAME_st {
765 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\ 765 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
766 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING) 766 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
767 767
768 /* for the is_set parameter to i2d_ASN1_SET */
769#define IS_SEQUENCE 0
770#define IS_SET 1
771
772DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) 768DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
773 769
774int ASN1_TYPE_get(ASN1_TYPE *a); 770int ASN1_TYPE_get(ASN1_TYPE *a);
@@ -888,15 +884,6 @@ int ASN1_TIME_check(ASN1_TIME *t);
888ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); 884ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
889int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); 885int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
890 886
891int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
892 i2d_of_void *i2d, int ex_tag, int ex_class,
893 int is_set);
894STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
895 const unsigned char **pp,
896 long length, d2i_of_void *d2i,
897 void (*free_func)(OPENSSL_BLOCK), int ex_tag,
898 int ex_class);
899
900#ifndef OPENSSL_NO_BIO 887#ifndef OPENSSL_NO_BIO
901int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); 888int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
902int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); 889int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
@@ -1047,19 +1034,7 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
1047int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, 1034int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
1048 unsigned char *data, int max_len); 1035 unsigned char *data, int max_len);
1049 1036
1050STACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len,
1051 d2i_of_void *d2i, void (*free_func)(OPENSSL_BLOCK));
1052unsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
1053 unsigned char **buf, int *len );
1054void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i);
1055void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); 1037void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
1056ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d,
1057 ASN1_OCTET_STRING **oct);
1058
1059#define ASN1_pack_string_of(type,obj,i2d,oct) \
1060 (ASN1_pack_string(CHECKED_PTR_OF(type, obj), \
1061 CHECKED_I2D_OF(type, i2d), \
1062 oct))
1063 1038
1064ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct); 1039ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
1065 1040
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
index 87bd0e9e1d..c60b197552 100644
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ b/src/lib/libcrypto/asn1/asn1_mac.h
@@ -176,19 +176,10 @@ err:\
176 M_ASN1_D2I_get_imp(b,func, type);\ 176 M_ASN1_D2I_get_imp(b,func, type);\
177 } 177 }
178 178
179#define M_ASN1_D2I_get_set(r,func,free_func) \
180 M_ASN1_D2I_get_imp_set(r,func,free_func, \
181 V_ASN1_SET,V_ASN1_UNIVERSAL);
182
183#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ 179#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
184 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ 180 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
185 V_ASN1_SET,V_ASN1_UNIVERSAL); 181 V_ASN1_SET,V_ASN1_UNIVERSAL);
186 182
187#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
188 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
189 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
190 { M_ASN1_D2I_get_set(r,func,free_func); }
191
192#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ 183#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
193 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ 184 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
194 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ 185 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
@@ -210,15 +201,6 @@ err:\
210 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 201 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
211 M_ASN1_I2D_put_SEQUENCE_type(type,a,f); 202 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
212 203
213#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
214 if ((c.slen != 0) && \
215 (M_ASN1_next == \
216 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
217 { \
218 M_ASN1_D2I_get_imp_set(b,func,free_func,\
219 tag,V_ASN1_CONTEXT_SPECIFIC); \
220 }
221
222#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ 204#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
223 if ((c.slen != 0) && \ 205 if ((c.slen != 0) && \
224 (M_ASN1_next == \ 206 (M_ASN1_next == \
@@ -228,39 +210,19 @@ err:\
228 tag,V_ASN1_CONTEXT_SPECIFIC); \ 210 tag,V_ASN1_CONTEXT_SPECIFIC); \
229 } 211 }
230 212
231#define M_ASN1_D2I_get_seq(r,func,free_func) \
232 M_ASN1_D2I_get_imp_set(r,func,free_func,\
233 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
234
235#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ 213#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
236 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ 214 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
237 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) 215 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
238 216
239#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
240 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
241 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
242 { M_ASN1_D2I_get_seq(r,func,free_func); }
243
244#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ 217#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
245 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ 218 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
246 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ 219 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
247 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } 220 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
248 221
249#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
250 M_ASN1_D2I_get_imp_set(r,func,free_func,\
251 x,V_ASN1_CONTEXT_SPECIFIC);
252
253#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ 222#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
254 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ 223 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
255 x,V_ASN1_CONTEXT_SPECIFIC); 224 x,V_ASN1_CONTEXT_SPECIFIC);
256 225
257#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
258 c.q=c.p; \
259 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
260 (void (*)())free_func,a,b) == NULL) \
261 { c.line=__LINE__; goto err; } \
262 c.slen-=(c.p-c.q);
263
264#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ 226#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
265 c.q=c.p; \ 227 c.q=c.p; \
266 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ 228 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
@@ -299,33 +261,6 @@ err:\
299 c.slen-=(c.p-c.q); \ 261 c.slen-=(c.p-c.q); \
300 } 262 }
301 263
302#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
303 if ((c.slen != 0) && (M_ASN1_next == \
304 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
305 { \
306 int Tinf,Ttag,Tclass; \
307 long Tlen; \
308 \
309 c.q=c.p; \
310 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
311 if (Tinf & 0x80) \
312 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
313 c.line=__LINE__; goto err; } \
314 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
315 Tlen = c.slen - (c.p - c.q) - 2; \
316 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
317 (void (*)())free_func, \
318 b,V_ASN1_UNIVERSAL) == NULL) \
319 { c.line=__LINE__; goto err; } \
320 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
321 Tlen = c.slen - (c.p - c.q); \
322 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
323 { c.error=ERR_R_MISSING_ASN1_EOS; \
324 c.line=__LINE__; goto err; } \
325 }\
326 c.slen-=(c.p-c.q); \
327 }
328
329#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ 264#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
330 if ((c.slen != 0) && (M_ASN1_next == \ 265 if ((c.slen != 0) && (M_ASN1_next == \
331 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ 266 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
@@ -384,17 +319,10 @@ err:\
384#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) 319#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
385#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) 320#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
386 321
387#define M_ASN1_I2D_len_SET(a,f) \
388 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
389
390#define M_ASN1_I2D_len_SET_type(type,a,f) \ 322#define M_ASN1_I2D_len_SET_type(type,a,f) \
391 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ 323 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
392 V_ASN1_UNIVERSAL,IS_SET); 324 V_ASN1_UNIVERSAL,IS_SET);
393 325
394#define M_ASN1_I2D_len_SEQUENCE(a,f) \
395 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
396 IS_SEQUENCE);
397
398#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ 326#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
399 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ 327 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
400 V_ASN1_UNIVERSAL,IS_SEQUENCE) 328 V_ASN1_UNIVERSAL,IS_SEQUENCE)
@@ -407,32 +335,15 @@ err:\
407 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 335 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
408 M_ASN1_I2D_len_SEQUENCE_type(type,a,f); 336 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
409 337
410#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
411 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
412
413#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ 338#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
414 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ 339 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
415 V_ASN1_CONTEXT_SPECIFIC,IS_SET); 340 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
416 341
417#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
418 if ((a != NULL) && (sk_num(a) != 0)) \
419 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
420 IS_SET);
421
422#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ 342#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
423 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 343 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
424 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ 344 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
425 V_ASN1_CONTEXT_SPECIFIC,IS_SET); 345 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
426 346
427#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
428 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
429 IS_SEQUENCE);
430
431#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
432 if ((a != NULL) && (sk_num(a) != 0)) \
433 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
434 IS_SEQUENCE);
435
436#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ 347#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
437 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 348 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
438 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ 349 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
@@ -446,21 +357,6 @@ err:\
446 ret+=ASN1_object_size(1,v,mtag); \ 357 ret+=ASN1_object_size(1,v,mtag); \
447 } 358 }
448 359
449#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
450 if ((a != NULL) && (sk_num(a) != 0))\
451 { \
452 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
453 ret+=ASN1_object_size(1,v,mtag); \
454 }
455
456#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
457 if ((a != NULL) && (sk_num(a) != 0))\
458 { \
459 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
460 IS_SEQUENCE); \
461 ret+=ASN1_object_size(1,v,mtag); \
462 }
463
464#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ 360#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
465 if ((a != NULL) && (sk_##type##_num(a) != 0))\ 361 if ((a != NULL) && (sk_##type##_num(a) != 0))\
466 { \ 362 { \
@@ -481,19 +377,10 @@ err:\
481 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ 377 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
482 } 378 }
483 379
484#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
485 V_ASN1_UNIVERSAL,IS_SET)
486#define M_ASN1_I2D_put_SET_type(type,a,f) \ 380#define M_ASN1_I2D_put_SET_type(type,a,f) \
487 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) 381 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
488#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
489 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
490#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ 382#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
491 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) 383 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
492#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
493 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
494
495#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
496 V_ASN1_UNIVERSAL,IS_SEQUENCE)
497 384
498#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ 385#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
499 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ 386 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
@@ -503,22 +390,12 @@ err:\
503 if ((a != NULL) && (sk_num(a) != 0)) \ 390 if ((a != NULL) && (sk_num(a) != 0)) \
504 M_ASN1_I2D_put_SEQUENCE(a,f); 391 M_ASN1_I2D_put_SEQUENCE(a,f);
505 392
506#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
507 if ((a != NULL) && (sk_num(a) != 0)) \
508 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
509 IS_SET); }
510
511#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ 393#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
512 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 394 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
513 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ 395 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
514 V_ASN1_CONTEXT_SPECIFIC, \ 396 V_ASN1_CONTEXT_SPECIFIC, \
515 IS_SET); } 397 IS_SET); }
516 398
517#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
518 if ((a != NULL) && (sk_num(a) != 0)) \
519 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
520 IS_SEQUENCE); }
521
522#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ 399#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
523 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 400 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
524 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ 401 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
@@ -532,20 +409,6 @@ err:\
532 f(a,&p); \ 409 f(a,&p); \
533 } 410 }
534 411
535#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
536 if ((a != NULL) && (sk_num(a) != 0)) \
537 { \
538 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
539 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
540 }
541
542#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
543 if ((a != NULL) && (sk_num(a) != 0)) \
544 { \
545 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
546 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
547 }
548
549#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ 412#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
550 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 413 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
551 { \ 414 { \
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
index ad738217d7..1886508654 100644
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ b/src/lib/libcrypto/asn1/asn_pack.c
@@ -60,93 +60,6 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63#ifndef NO_ASN1_OLD
64
65/* ASN1 packing and unpacking functions */
66
67/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
68
69STACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len,
70 d2i_of_void *d2i, void (*free_func)(OPENSSL_BLOCK))
71{
72 STACK_OF(OPENSSL_BLOCK) *sk;
73 const unsigned char *pbuf;
74 pbuf = buf;
75 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
76 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
77 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
78 return sk;
79}
80
81/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
82 * OPENSSL_malloc'ed buffer
83 */
84
85unsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
86 unsigned char **buf, int *len)
87{
88 int safelen;
89 unsigned char *safe, *p;
90 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
91 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
92 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
93 return NULL;
94 }
95 if (!(safe = OPENSSL_malloc (safelen))) {
96 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
97 return NULL;
98 }
99 p = safe;
100 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
101 IS_SEQUENCE);
102 if (len) *len = safelen;
103 if (buf) *buf = safe;
104 return safe;
105}
106
107/* Extract an ASN1 object from an ASN1_STRING */
108
109void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i)
110{
111 const unsigned char *p;
112 char *ret;
113
114 p = oct->data;
115 if(!(ret = d2i(NULL, &p, oct->length)))
116 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
117 return ret;
118}
119
120/* Pack an ASN1 object into an ASN1_STRING */
121
122ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct)
123{
124 unsigned char *p;
125 ASN1_STRING *octmp;
126
127 if (!oct || !*oct) {
128 if (!(octmp = ASN1_STRING_new ())) {
129 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
130 return NULL;
131 }
132 if (oct) *oct = octmp;
133 } else octmp = *oct;
134
135 if (!(octmp->length = i2d(obj, NULL))) {
136 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
137 return NULL;
138 }
139 if (!(p = OPENSSL_malloc (octmp->length))) {
140 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
141 return NULL;
142 }
143 octmp->data = p;
144 i2d (obj, &p);
145 return octmp;
146}
147
148#endif
149
150/* ASN1_ITEM versions of the above */ 63/* ASN1_ITEM versions of the above */
151 64
152ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) 65ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)