summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/tasn_new.c
diff options
context:
space:
mode:
authordjm <>2008-09-06 12:17:54 +0000
committerdjm <>2008-09-06 12:17:54 +0000
commit38ce604e3cc97706b876b0525ddff0121115456d (patch)
tree7ccc28afe1789ea3dbedf72365f955d5b8e105b5 /src/lib/libcrypto/asn1/tasn_new.c
parent12867252827c8efaa8ddd1fa3b3d6e321e2bcdef (diff)
downloadopenbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.gz
openbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.bz2
openbsd-38ce604e3cc97706b876b0525ddff0121115456d.zip
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_new.c')
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c234
1 files changed, 139 insertions, 95 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
index a0e3db574f..531dad365c 100644
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -64,27 +64,30 @@
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <string.h> 65#include <string.h>
66 66
67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine); 67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
68 int combine);
68static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 69static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); 70static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
70void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 71void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
71 72
72ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) 73ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
73{ 74 {
74 ASN1_VALUE *ret = NULL; 75 ASN1_VALUE *ret = NULL;
75 if(ASN1_item_ex_new(&ret, it) > 0) return ret; 76 if (ASN1_item_ex_new(&ret, it) > 0)
77 return ret;
76 return NULL; 78 return NULL;
77} 79 }
78 80
79/* Allocate an ASN1 structure */ 81/* Allocate an ASN1 structure */
80 82
81int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 83int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
82{ 84 {
83 return asn1_item_ex_combine_new(pval, it, 0); 85 return asn1_item_ex_combine_new(pval, it, 0);
84} 86 }
85 87
86static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) 88static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
87{ 89 int combine)
90 {
88 const ASN1_TEMPLATE *tt = NULL; 91 const ASN1_TEMPLATE *tt = NULL;
89 const ASN1_COMPAT_FUNCS *cf; 92 const ASN1_COMPAT_FUNCS *cf;
90 const ASN1_EXTERN_FUNCS *ef; 93 const ASN1_EXTERN_FUNCS *ef;
@@ -92,133 +95,155 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int
92 ASN1_aux_cb *asn1_cb; 95 ASN1_aux_cb *asn1_cb;
93 ASN1_VALUE **pseqval; 96 ASN1_VALUE **pseqval;
94 int i; 97 int i;
95 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; 98 if (aux && aux->asn1_cb)
96 else asn1_cb = 0; 99 asn1_cb = aux->asn1_cb;
100 else
101 asn1_cb = 0;
97 102
98 if(!combine) *pval = NULL; 103 if (!combine) *pval = NULL;
99 104
100#ifdef CRYPTO_MDEBUG 105#ifdef CRYPTO_MDEBUG
101 if(it->sname) CRYPTO_push_info(it->sname); 106 if (it->sname)
107 CRYPTO_push_info(it->sname);
102#endif 108#endif
103 109
104 switch(it->itype) { 110 switch(it->itype)
111 {
105 112
106 case ASN1_ITYPE_EXTERN: 113 case ASN1_ITYPE_EXTERN:
107 ef = it->funcs; 114 ef = it->funcs;
108 if(ef && ef->asn1_ex_new) { 115 if (ef && ef->asn1_ex_new)
109 if(!ef->asn1_ex_new(pval, it)) 116 {
117 if (!ef->asn1_ex_new(pval, it))
110 goto memerr; 118 goto memerr;
111 } 119 }
112 break; 120 break;
113 121
114 case ASN1_ITYPE_COMPAT: 122 case ASN1_ITYPE_COMPAT:
115 cf = it->funcs; 123 cf = it->funcs;
116 if(cf && cf->asn1_new) { 124 if (cf && cf->asn1_new) {
117 *pval = cf->asn1_new(); 125 *pval = cf->asn1_new();
118 if(!*pval) goto memerr; 126 if (!*pval)
127 goto memerr;
119 } 128 }
120 break; 129 break;
121 130
122 case ASN1_ITYPE_PRIMITIVE: 131 case ASN1_ITYPE_PRIMITIVE:
123 if(it->templates) { 132 if (it->templates)
124 if(!ASN1_template_new(pval, it->templates)) 133 {
134 if (!ASN1_template_new(pval, it->templates))
125 goto memerr; 135 goto memerr;
126 } else { 136 }
127 if(!ASN1_primitive_new(pval, it)) 137 else if (!ASN1_primitive_new(pval, it))
128 goto memerr; 138 goto memerr;
129 }
130 break; 139 break;
131 140
132 case ASN1_ITYPE_MSTRING: 141 case ASN1_ITYPE_MSTRING:
133 if(!ASN1_primitive_new(pval, it)) 142 if (!ASN1_primitive_new(pval, it))
134 goto memerr; 143 goto memerr;
135 break; 144 break;
136 145
137 case ASN1_ITYPE_CHOICE: 146 case ASN1_ITYPE_CHOICE:
138 if(asn1_cb) { 147 if (asn1_cb)
148 {
139 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); 149 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
140 if(!i) goto auxerr; 150 if (!i)
141 if(i==2) { 151 goto auxerr;
152 if (i==2)
153 {
142#ifdef CRYPTO_MDEBUG 154#ifdef CRYPTO_MDEBUG
143 if(it->sname) CRYPTO_pop_info(); 155 if (it->sname)
156 CRYPTO_pop_info();
144#endif 157#endif
145 return 1; 158 return 1;
159 }
146 } 160 }
147 } 161 if (!combine)
148 if(!combine) { 162 {
149 *pval = OPENSSL_malloc(it->size); 163 *pval = OPENSSL_malloc(it->size);
150 if(!*pval) goto memerr; 164 if (!*pval)
165 goto memerr;
151 memset(*pval, 0, it->size); 166 memset(*pval, 0, it->size);
152 } 167 }
153 asn1_set_choice_selector(pval, -1, it); 168 asn1_set_choice_selector(pval, -1, it);
154 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) 169 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
155 goto auxerr; 170 goto auxerr;
156 break; 171 break;
157 172
173 case ASN1_ITYPE_NDEF_SEQUENCE:
158 case ASN1_ITYPE_SEQUENCE: 174 case ASN1_ITYPE_SEQUENCE:
159 if(asn1_cb) { 175 if (asn1_cb)
176 {
160 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); 177 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
161 if(!i) goto auxerr; 178 if (!i)
162 if(i==2) { 179 goto auxerr;
180 if (i==2)
181 {
163#ifdef CRYPTO_MDEBUG 182#ifdef CRYPTO_MDEBUG
164 if(it->sname) CRYPTO_pop_info(); 183 if (it->sname)
184 CRYPTO_pop_info();
165#endif 185#endif
166 return 1; 186 return 1;
187 }
167 } 188 }
168 } 189 if (!combine)
169 if(!combine) { 190 {
170 *pval = OPENSSL_malloc(it->size); 191 *pval = OPENSSL_malloc(it->size);
171 if(!*pval) goto memerr; 192 if (!*pval)
193 goto memerr;
172 memset(*pval, 0, it->size); 194 memset(*pval, 0, it->size);
173 asn1_do_lock(pval, 0, it); 195 asn1_do_lock(pval, 0, it);
174 asn1_enc_init(pval, it); 196 asn1_enc_init(pval, it);
175 } 197 }
176 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) { 198 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
199 {
177 pseqval = asn1_get_field_ptr(pval, tt); 200 pseqval = asn1_get_field_ptr(pval, tt);
178 if(!ASN1_template_new(pseqval, tt)) goto memerr; 201 if (!ASN1_template_new(pseqval, tt))
179 } 202 goto memerr;
180 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) 203 }
204 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
181 goto auxerr; 205 goto auxerr;
182 break; 206 break;
183 } 207 }
184#ifdef CRYPTO_MDEBUG 208#ifdef CRYPTO_MDEBUG
185 if(it->sname) CRYPTO_pop_info(); 209 if (it->sname) CRYPTO_pop_info();
186#endif 210#endif
187 return 1; 211 return 1;
188 212
189 memerr: 213 memerr:
190 ASN1err(ASN1_F_ASN1_ITEM_NEW, ERR_R_MALLOC_FAILURE); 214 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE);
191#ifdef CRYPTO_MDEBUG 215#ifdef CRYPTO_MDEBUG
192 if(it->sname) CRYPTO_pop_info(); 216 if (it->sname) CRYPTO_pop_info();
193#endif 217#endif
194 return 0; 218 return 0;
195 219
196 auxerr: 220 auxerr:
197 ASN1err(ASN1_F_ASN1_ITEM_NEW, ASN1_R_AUX_ERROR); 221 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR);
198 ASN1_item_ex_free(pval, it); 222 ASN1_item_ex_free(pval, it);
199#ifdef CRYPTO_MDEBUG 223#ifdef CRYPTO_MDEBUG
200 if(it->sname) CRYPTO_pop_info(); 224 if (it->sname) CRYPTO_pop_info();
201#endif 225#endif
202 return 0; 226 return 0;
203 227
204} 228 }
205 229
206static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 230static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
207{ 231 {
208 const ASN1_EXTERN_FUNCS *ef; 232 const ASN1_EXTERN_FUNCS *ef;
209 233
210 switch(it->itype) { 234 switch(it->itype)
235 {
211 236
212 case ASN1_ITYPE_EXTERN: 237 case ASN1_ITYPE_EXTERN:
213 ef = it->funcs; 238 ef = it->funcs;
214 if(ef && ef->asn1_ex_clear) 239 if (ef && ef->asn1_ex_clear)
215 ef->asn1_ex_clear(pval, it); 240 ef->asn1_ex_clear(pval, it);
216 else *pval = NULL; 241 else *pval = NULL;
217 break; 242 break;
218 243
219 244
220 case ASN1_ITYPE_PRIMITIVE: 245 case ASN1_ITYPE_PRIMITIVE:
221 if(it->templates) 246 if (it->templates)
222 asn1_template_clear(pval, it->templates); 247 asn1_template_clear(pval, it->templates);
223 else 248 else
224 asn1_primitive_clear(pval, it); 249 asn1_primitive_clear(pval, it);
@@ -231,75 +256,90 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
231 case ASN1_ITYPE_COMPAT: 256 case ASN1_ITYPE_COMPAT:
232 case ASN1_ITYPE_CHOICE: 257 case ASN1_ITYPE_CHOICE:
233 case ASN1_ITYPE_SEQUENCE: 258 case ASN1_ITYPE_SEQUENCE:
259 case ASN1_ITYPE_NDEF_SEQUENCE:
234 *pval = NULL; 260 *pval = NULL;
235 break; 261 break;
262 }
236 } 263 }
237}
238 264
239 265
240int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 266int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
241{ 267 {
242 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); 268 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
243 int ret; 269 int ret;
244 if(tt->flags & ASN1_TFLG_OPTIONAL) { 270 if (tt->flags & ASN1_TFLG_OPTIONAL)
271 {
245 asn1_template_clear(pval, tt); 272 asn1_template_clear(pval, tt);
246 return 1; 273 return 1;
247 } 274 }
248 /* If ANY DEFINED BY nothing to do */ 275 /* If ANY DEFINED BY nothing to do */
249 276
250 if(tt->flags & ASN1_TFLG_ADB_MASK) { 277 if (tt->flags & ASN1_TFLG_ADB_MASK)
278 {
251 *pval = NULL; 279 *pval = NULL;
252 return 1; 280 return 1;
253 } 281 }
254#ifdef CRYPTO_MDEBUG 282#ifdef CRYPTO_MDEBUG
255 if(tt->field_name) CRYPTO_push_info(tt->field_name); 283 if (tt->field_name)
284 CRYPTO_push_info(tt->field_name);
256#endif 285#endif
257 /* If SET OF or SEQUENCE OF, its a STACK */ 286 /* If SET OF or SEQUENCE OF, its a STACK */
258 if(tt->flags & ASN1_TFLG_SK_MASK) { 287 if (tt->flags & ASN1_TFLG_SK_MASK)
288 {
259 STACK_OF(ASN1_VALUE) *skval; 289 STACK_OF(ASN1_VALUE) *skval;
260 skval = sk_ASN1_VALUE_new_null(); 290 skval = sk_ASN1_VALUE_new_null();
261 if(!skval) { 291 if (!skval)
292 {
262 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); 293 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
263 ret = 0; 294 ret = 0;
264 goto done; 295 goto done;
265 } 296 }
266 *pval = (ASN1_VALUE *)skval; 297 *pval = (ASN1_VALUE *)skval;
267 ret = 1; 298 ret = 1;
268 goto done; 299 goto done;
269 } 300 }
270 /* Otherwise pass it back to the item routine */ 301 /* Otherwise pass it back to the item routine */
271 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); 302 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
272 done: 303 done:
273#ifdef CRYPTO_MDEBUG 304#ifdef CRYPTO_MDEBUG
274 if(it->sname) CRYPTO_pop_info(); 305 if (it->sname)
306 CRYPTO_pop_info();
275#endif 307#endif
276 return ret; 308 return ret;
277} 309 }
278 310
279static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 311static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
280{ 312 {
281 /* If ADB or STACK just NULL the field */ 313 /* If ADB or STACK just NULL the field */
282 if(tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) 314 if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
283 *pval = NULL; 315 *pval = NULL;
284 else 316 else
285 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); 317 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
286} 318 }
287 319
288 320
289/* NB: could probably combine most of the real XXX_new() behaviour and junk all the old 321/* NB: could probably combine most of the real XXX_new() behaviour and junk
290 * functions. 322 * all the old functions.
291 */ 323 */
292 324
293int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 325int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
294{ 326 {
295 ASN1_TYPE *typ; 327 ASN1_TYPE *typ;
296 int utype; 328 int utype;
297 const ASN1_PRIMITIVE_FUNCS *pf; 329
298 pf = it->funcs; 330 if (it && it->funcs)
299 if(pf && pf->prim_new) return pf->prim_new(pval, it); 331 {
300 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1; 332 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
301 else utype = it->utype; 333 if (pf->prim_new)
302 switch(utype) { 334 return pf->prim_new(pval, it);
335 }
336
337 if (!it || (it->itype == ASN1_ITYPE_MSTRING))
338 utype = -1;
339 else
340 utype = it->utype;
341 switch(utype)
342 {
303 case V_ASN1_OBJECT: 343 case V_ASN1_OBJECT:
304 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); 344 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
305 return 1; 345 return 1;
@@ -317,7 +357,8 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
317 357
318 case V_ASN1_ANY: 358 case V_ASN1_ANY:
319 typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); 359 typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
320 if(!typ) return 0; 360 if (!typ)
361 return 0;
321 typ->value.ptr = NULL; 362 typ->value.ptr = NULL;
322 typ->type = -1; 363 typ->type = -1;
323 *pval = (ASN1_VALUE *)typ; 364 *pval = (ASN1_VALUE *)typ;
@@ -326,26 +367,29 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
326 default: 367 default:
327 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype); 368 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
328 break; 369 break;
329 } 370 }
330 if(*pval) return 1; 371 if (*pval)
372 return 1;
331 return 0; 373 return 0;
332} 374 }
333 375
334void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 376void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
335{ 377 {
336 int utype; 378 int utype;
337 const ASN1_PRIMITIVE_FUNCS *pf; 379 if (it && it->funcs)
338 pf = it->funcs; 380 {
339 if(pf) { 381 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
340 if(pf->prim_clear) 382 if (pf->prim_clear)
341 pf->prim_clear(pval, it); 383 pf->prim_clear(pval, it);
342 else 384 else
343 *pval = NULL; 385 *pval = NULL;
344 return; 386 return;
345 } 387 }
346 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1; 388 if (!it || (it->itype == ASN1_ITYPE_MSTRING))
347 else utype = it->utype; 389 utype = -1;
348 if(utype == V_ASN1_BOOLEAN) 390 else
391 utype = it->utype;
392 if (utype == V_ASN1_BOOLEAN)
349 *(ASN1_BOOLEAN *)pval = it->size; 393 *(ASN1_BOOLEAN *)pval = it->size;
350 else *pval = NULL; 394 else *pval = NULL;
351} 395 }