diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_enc.c')
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_enc.c | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c index 54e3f7a94a..230164107d 100644 --- a/src/lib/libcrypto/asn1/tasn_enc.c +++ b/src/lib/libcrypto/asn1/tasn_enc.c | |||
@@ -82,14 +82,14 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
82 | 82 | ||
83 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, | 83 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, |
84 | const ASN1_ITEM *it) | 84 | const ASN1_ITEM *it) |
85 | { | 85 | { |
86 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); | 86 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); |
87 | } | 87 | } |
88 | 88 | ||
89 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | 89 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) |
90 | { | 90 | { |
91 | return asn1_item_flags_i2d(val, out, it, 0); | 91 | return asn1_item_flags_i2d(val, out, it, 0); |
92 | } | 92 | } |
93 | 93 | ||
94 | /* Encode an ASN1 item, this is use by the | 94 | /* Encode an ASN1 item, this is use by the |
95 | * standard 'i2d' function. 'out' points to | 95 | * standard 'i2d' function. 'out' points to |
@@ -102,9 +102,9 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | |||
102 | 102 | ||
103 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | 103 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, |
104 | const ASN1_ITEM *it, int flags) | 104 | const ASN1_ITEM *it, int flags) |
105 | { | 105 | { |
106 | if (out && !*out) | 106 | if (out && !*out) |
107 | { | 107 | { |
108 | unsigned char *p, *buf; | 108 | unsigned char *p, *buf; |
109 | int len; | 109 | int len; |
110 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); | 110 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); |
@@ -117,10 +117,10 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
117 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); | 117 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); |
118 | *out = buf; | 118 | *out = buf; |
119 | return len; | 119 | return len; |
120 | } | 120 | } |
121 | 121 | ||
122 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); | 122 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); |
123 | } | 123 | } |
124 | 124 | ||
125 | /* Encode an item, taking care of IMPLICIT tagging (if any). | 125 | /* Encode an item, taking care of IMPLICIT tagging (if any). |
126 | * This function performs the normal item handling: it can be | 126 | * This function performs the normal item handling: it can be |
@@ -129,7 +129,7 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
129 | 129 | ||
130 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | 130 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, |
131 | const ASN1_ITEM *it, int tag, int aclass) | 131 | const ASN1_ITEM *it, int tag, int aclass) |
132 | { | 132 | { |
133 | const ASN1_TEMPLATE *tt = NULL; | 133 | const ASN1_TEMPLATE *tt = NULL; |
134 | unsigned char *p = NULL; | 134 | unsigned char *p = NULL; |
135 | int i, seqcontlen, seqlen, ndef = 1; | 135 | int i, seqcontlen, seqlen, ndef = 1; |
@@ -145,7 +145,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
145 | asn1_cb = aux->asn1_cb; | 145 | asn1_cb = aux->asn1_cb; |
146 | 146 | ||
147 | switch(it->itype) | 147 | switch(it->itype) |
148 | { | 148 | { |
149 | 149 | ||
150 | case ASN1_ITYPE_PRIMITIVE: | 150 | case ASN1_ITYPE_PRIMITIVE: |
151 | if (it->templates) | 151 | if (it->templates) |
@@ -162,14 +162,14 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
162 | return 0; | 162 | return 0; |
163 | i = asn1_get_choice_selector(pval, it); | 163 | i = asn1_get_choice_selector(pval, it); |
164 | if ((i >= 0) && (i < it->tcount)) | 164 | if ((i >= 0) && (i < it->tcount)) |
165 | { | 165 | { |
166 | ASN1_VALUE **pchval; | 166 | ASN1_VALUE **pchval; |
167 | const ASN1_TEMPLATE *chtt; | 167 | const ASN1_TEMPLATE *chtt; |
168 | chtt = it->templates + i; | 168 | chtt = it->templates + i; |
169 | pchval = asn1_get_field_ptr(pval, chtt); | 169 | pchval = asn1_get_field_ptr(pval, chtt); |
170 | return asn1_template_ex_i2d(pchval, out, chtt, | 170 | return asn1_template_ex_i2d(pchval, out, chtt, |
171 | -1, aclass); | 171 | -1, aclass); |
172 | } | 172 | } |
173 | /* Fixme: error condition if selector out of range */ | 173 | /* Fixme: error condition if selector out of range */ |
174 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) | 174 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) |
175 | return 0; | 175 | return 0; |
@@ -210,17 +210,17 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
210 | seqcontlen = 0; | 210 | seqcontlen = 0; |
211 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | 211 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ |
212 | if (tag == -1) | 212 | if (tag == -1) |
213 | { | 213 | { |
214 | tag = V_ASN1_SEQUENCE; | 214 | tag = V_ASN1_SEQUENCE; |
215 | /* Retain any other flags in aclass */ | 215 | /* Retain any other flags in aclass */ |
216 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) | 216 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) |
217 | | V_ASN1_UNIVERSAL; | 217 | | V_ASN1_UNIVERSAL; |
218 | } | 218 | } |
219 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) | 219 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) |
220 | return 0; | 220 | return 0; |
221 | /* First work out sequence content length */ | 221 | /* First work out sequence content length */ |
222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
223 | { | 223 | { |
224 | const ASN1_TEMPLATE *seqtt; | 224 | const ASN1_TEMPLATE *seqtt; |
225 | ASN1_VALUE **pseqval; | 225 | ASN1_VALUE **pseqval; |
226 | seqtt = asn1_do_adb(pval, tt, 1); | 226 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -230,7 +230,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
230 | /* FIXME: check for errors in enhanced version */ | 230 | /* FIXME: check for errors in enhanced version */ |
231 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, | 231 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, |
232 | -1, aclass); | 232 | -1, aclass); |
233 | } | 233 | } |
234 | 234 | ||
235 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); | 235 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); |
236 | if (!out) | 236 | if (!out) |
@@ -238,7 +238,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
238 | /* Output SEQUENCE header */ | 238 | /* Output SEQUENCE header */ |
239 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); | 239 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); |
240 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 240 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
241 | { | 241 | { |
242 | const ASN1_TEMPLATE *seqtt; | 242 | const ASN1_TEMPLATE *seqtt; |
243 | ASN1_VALUE **pseqval; | 243 | ASN1_VALUE **pseqval; |
244 | seqtt = asn1_do_adb(pval, tt, 1); | 244 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -247,7 +247,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
247 | pseqval = asn1_get_field_ptr(pval, seqtt); | 247 | pseqval = asn1_get_field_ptr(pval, seqtt); |
248 | /* FIXME: check for errors in enhanced version */ | 248 | /* FIXME: check for errors in enhanced version */ |
249 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); | 249 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); |
250 | } | 250 | } |
251 | if (ndef == 2) | 251 | if (ndef == 2) |
252 | ASN1_put_eoc(out); | 252 | ASN1_put_eoc(out); |
253 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) | 253 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) |
@@ -257,19 +257,19 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
257 | default: | 257 | default: |
258 | return 0; | 258 | return 0; |
259 | 259 | ||
260 | } | ||
261 | return 0; | ||
262 | } | 260 | } |
261 | return 0; | ||
262 | } | ||
263 | 263 | ||
264 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, | 264 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, |
265 | const ASN1_TEMPLATE *tt) | 265 | const ASN1_TEMPLATE *tt) |
266 | { | 266 | { |
267 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); | 267 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); |
268 | } | 268 | } |
269 | 269 | ||
270 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | 270 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, |
271 | const ASN1_TEMPLATE *tt, int tag, int iclass) | 271 | const ASN1_TEMPLATE *tt, int tag, int iclass) |
272 | { | 272 | { |
273 | int i, ret, flags, ttag, tclass, ndef; | 273 | int i, ret, flags, ttag, tclass, ndef; |
274 | flags = tt->flags; | 274 | flags = tt->flags; |
275 | /* Work out tag and class to use: tagging may come | 275 | /* Work out tag and class to use: tagging may come |
@@ -279,7 +279,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
279 | * which should be noted and passed down to other levels. | 279 | * which should be noted and passed down to other levels. |
280 | */ | 280 | */ |
281 | if (flags & ASN1_TFLG_TAG_MASK) | 281 | if (flags & ASN1_TFLG_TAG_MASK) |
282 | { | 282 | { |
283 | /* Error if argument and template tagging */ | 283 | /* Error if argument and template tagging */ |
284 | if (tag != -1) | 284 | if (tag != -1) |
285 | /* FIXME: error code here */ | 285 | /* FIXME: error code here */ |
@@ -287,18 +287,18 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
287 | /* Get tagging from template */ | 287 | /* Get tagging from template */ |
288 | ttag = tt->tag; | 288 | ttag = tt->tag; |
289 | tclass = flags & ASN1_TFLG_TAG_CLASS; | 289 | tclass = flags & ASN1_TFLG_TAG_CLASS; |
290 | } | 290 | } |
291 | else if (tag != -1) | 291 | else if (tag != -1) |
292 | { | 292 | { |
293 | /* No template tagging, get from arguments */ | 293 | /* No template tagging, get from arguments */ |
294 | ttag = tag; | 294 | ttag = tag; |
295 | tclass = iclass & ASN1_TFLG_TAG_CLASS; | 295 | tclass = iclass & ASN1_TFLG_TAG_CLASS; |
296 | } | 296 | } |
297 | else | 297 | else |
298 | { | 298 | { |
299 | ttag = -1; | 299 | ttag = -1; |
300 | tclass = 0; | 300 | tclass = 0; |
301 | } | 301 | } |
302 | /* | 302 | /* |
303 | * Remove any class mask from iflag. | 303 | * Remove any class mask from iflag. |
304 | */ | 304 | */ |
@@ -315,7 +315,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
315 | else ndef = 1; | 315 | else ndef = 1; |
316 | 316 | ||
317 | if (flags & ASN1_TFLG_SK_MASK) | 317 | if (flags & ASN1_TFLG_SK_MASK) |
318 | { | 318 | { |
319 | /* SET OF, SEQUENCE OF */ | 319 | /* SET OF, SEQUENCE OF */ |
320 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | 320 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; |
321 | int isset, sktag, skaclass; | 321 | int isset, sktag, skaclass; |
@@ -326,39 +326,39 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
326 | return 0; | 326 | return 0; |
327 | 327 | ||
328 | if (flags & ASN1_TFLG_SET_OF) | 328 | if (flags & ASN1_TFLG_SET_OF) |
329 | { | 329 | { |
330 | isset = 1; | 330 | isset = 1; |
331 | /* 2 means we reorder */ | 331 | /* 2 means we reorder */ |
332 | if (flags & ASN1_TFLG_SEQUENCE_OF) | 332 | if (flags & ASN1_TFLG_SEQUENCE_OF) |
333 | isset = 2; | 333 | isset = 2; |
334 | } | 334 | } |
335 | else isset = 0; | 335 | else isset = 0; |
336 | 336 | ||
337 | /* Work out inner tag value: if EXPLICIT | 337 | /* Work out inner tag value: if EXPLICIT |
338 | * or no tagging use underlying type. | 338 | * or no tagging use underlying type. |
339 | */ | 339 | */ |
340 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) | 340 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) |
341 | { | 341 | { |
342 | sktag = ttag; | 342 | sktag = ttag; |
343 | skaclass = tclass; | 343 | skaclass = tclass; |
344 | } | 344 | } |
345 | else | 345 | else |
346 | { | 346 | { |
347 | skaclass = V_ASN1_UNIVERSAL; | 347 | skaclass = V_ASN1_UNIVERSAL; |
348 | if (isset) | 348 | if (isset) |
349 | sktag = V_ASN1_SET; | 349 | sktag = V_ASN1_SET; |
350 | else sktag = V_ASN1_SEQUENCE; | 350 | else sktag = V_ASN1_SEQUENCE; |
351 | } | 351 | } |
352 | 352 | ||
353 | /* Determine total length of items */ | 353 | /* Determine total length of items */ |
354 | skcontlen = 0; | 354 | skcontlen = 0; |
355 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 355 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
356 | { | 356 | { |
357 | skitem = sk_ASN1_VALUE_value(sk, i); | 357 | skitem = sk_ASN1_VALUE_value(sk, i); |
358 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, | 358 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, |
359 | ASN1_ITEM_ptr(tt->item), | 359 | ASN1_ITEM_ptr(tt->item), |
360 | -1, iclass); | 360 | -1, iclass); |
361 | } | 361 | } |
362 | sklen = ASN1_object_size(ndef, skcontlen, sktag); | 362 | sklen = ASN1_object_size(ndef, skcontlen, sktag); |
363 | /* If EXPLICIT need length of surrounding tag */ | 363 | /* If EXPLICIT need length of surrounding tag */ |
364 | if (flags & ASN1_TFLG_EXPTAG) | 364 | if (flags & ASN1_TFLG_EXPTAG) |
@@ -378,17 +378,17 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
378 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), | 378 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), |
379 | isset, iclass); | 379 | isset, iclass); |
380 | if (ndef == 2) | 380 | if (ndef == 2) |
381 | { | 381 | { |
382 | ASN1_put_eoc(out); | 382 | ASN1_put_eoc(out); |
383 | if (flags & ASN1_TFLG_EXPTAG) | 383 | if (flags & ASN1_TFLG_EXPTAG) |
384 | ASN1_put_eoc(out); | 384 | ASN1_put_eoc(out); |
385 | } | 385 | } |
386 | 386 | ||
387 | return ret; | 387 | return ret; |
388 | } | 388 | } |
389 | 389 | ||
390 | if (flags & ASN1_TFLG_EXPTAG) | 390 | if (flags & ASN1_TFLG_EXPTAG) |
391 | { | 391 | { |
392 | /* EXPLICIT tagging */ | 392 | /* EXPLICIT tagging */ |
393 | /* Find length of tagged item */ | 393 | /* Find length of tagged item */ |
394 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), | 394 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), |
@@ -398,16 +398,16 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
398 | /* Find length of EXPLICIT tag */ | 398 | /* Find length of EXPLICIT tag */ |
399 | ret = ASN1_object_size(ndef, i, ttag); | 399 | ret = ASN1_object_size(ndef, i, ttag); |
400 | if (out) | 400 | if (out) |
401 | { | 401 | { |
402 | /* Output tag and item */ | 402 | /* Output tag and item */ |
403 | ASN1_put_object(out, ndef, i, ttag, tclass); | 403 | ASN1_put_object(out, ndef, i, ttag, tclass); |
404 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | 404 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), |
405 | -1, iclass); | 405 | -1, iclass); |
406 | if (ndef == 2) | 406 | if (ndef == 2) |
407 | ASN1_put_eoc(out); | 407 | ASN1_put_eoc(out); |
408 | } | ||
409 | return ret; | ||
410 | } | 408 | } |
409 | return ret; | ||
410 | } | ||
411 | 411 | ||
412 | /* Either normal or IMPLICIT tagging: combine class and flags */ | 412 | /* Either normal or IMPLICIT tagging: combine class and flags */ |
413 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | 413 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), |
@@ -424,7 +424,7 @@ typedef struct { | |||
424 | } DER_ENC; | 424 | } DER_ENC; |
425 | 425 | ||
426 | static int der_cmp(const void *a, const void *b) | 426 | static int der_cmp(const void *a, const void *b) |
427 | { | 427 | { |
428 | const DER_ENC *d1 = a, *d2 = b; | 428 | const DER_ENC *d1 = a, *d2 = b; |
429 | int cmplen, i; | 429 | int cmplen, i; |
430 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; | 430 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; |
@@ -432,14 +432,14 @@ static int der_cmp(const void *a, const void *b) | |||
432 | if (i) | 432 | if (i) |
433 | return i; | 433 | return i; |
434 | return d1->length - d2->length; | 434 | return d1->length - d2->length; |
435 | } | 435 | } |
436 | 436 | ||
437 | /* Output the content octets of SET OF or SEQUENCE OF */ | 437 | /* Output the content octets of SET OF or SEQUENCE OF */ |
438 | 438 | ||
439 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | 439 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, |
440 | int skcontlen, const ASN1_ITEM *item, | 440 | int skcontlen, const ASN1_ITEM *item, |
441 | int do_sort, int iclass) | 441 | int do_sort, int iclass) |
442 | { | 442 | { |
443 | int i; | 443 | int i; |
444 | ASN1_VALUE *skitem; | 444 | ASN1_VALUE *skitem; |
445 | unsigned char *tmpdat = NULL, *p = NULL; | 445 | unsigned char *tmpdat = NULL, *p = NULL; |
@@ -450,7 +450,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | |||
450 | if (sk_ASN1_VALUE_num(sk) < 2) | 450 | if (sk_ASN1_VALUE_num(sk) < 2) |
451 | do_sort = 0; | 451 | do_sort = 0; |
452 | else | 452 | else |
453 | { | 453 | { |
454 | derlst = malloc(sk_ASN1_VALUE_num(sk) | 454 | derlst = malloc(sk_ASN1_VALUE_num(sk) |
455 | * sizeof(*derlst)); | 455 | * sizeof(*derlst)); |
456 | tmpdat = malloc(skcontlen); | 456 | tmpdat = malloc(skcontlen); |
@@ -458,54 +458,54 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | |||
458 | free(derlst); | 458 | free(derlst); |
459 | free(tmpdat); | 459 | free(tmpdat); |
460 | return 0; | 460 | return 0; |
461 | } | ||
462 | } | 461 | } |
462 | } | ||
463 | /* If not sorting just output each item */ | 463 | /* If not sorting just output each item */ |
464 | if (!do_sort) | 464 | if (!do_sort) |
465 | { | 465 | { |
466 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 466 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
467 | { | 467 | { |
468 | skitem = sk_ASN1_VALUE_value(sk, i); | 468 | skitem = sk_ASN1_VALUE_value(sk, i); |
469 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); | 469 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); |
470 | } | ||
471 | return 1; | ||
472 | } | 470 | } |
471 | return 1; | ||
472 | } | ||
473 | p = tmpdat; | 473 | p = tmpdat; |
474 | 474 | ||
475 | /* Doing sort: build up a list of each member's DER encoding */ | 475 | /* Doing sort: build up a list of each member's DER encoding */ |
476 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | 476 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) |
477 | { | 477 | { |
478 | skitem = sk_ASN1_VALUE_value(sk, i); | 478 | skitem = sk_ASN1_VALUE_value(sk, i); |
479 | tder->data = p; | 479 | tder->data = p; |
480 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); | 480 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); |
481 | tder->field = skitem; | 481 | tder->field = skitem; |
482 | } | 482 | } |
483 | 483 | ||
484 | /* Now sort them */ | 484 | /* Now sort them */ |
485 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); | 485 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); |
486 | /* Output sorted DER encoding */ | 486 | /* Output sorted DER encoding */ |
487 | p = *out; | 487 | p = *out; |
488 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | 488 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) |
489 | { | 489 | { |
490 | memcpy(p, tder->data, tder->length); | 490 | memcpy(p, tder->data, tder->length); |
491 | p += tder->length; | 491 | p += tder->length; |
492 | } | 492 | } |
493 | *out = p; | 493 | *out = p; |
494 | /* If do_sort is 2 then reorder the STACK */ | 494 | /* If do_sort is 2 then reorder the STACK */ |
495 | if (do_sort == 2) | 495 | if (do_sort == 2) |
496 | { | 496 | { |
497 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); | 497 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); |
498 | i++, tder++) | 498 | i++, tder++) |
499 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); | 499 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); |
500 | } | 500 | } |
501 | free(derlst); | 501 | free(derlst); |
502 | free(tmpdat); | 502 | free(tmpdat); |
503 | return 1; | 503 | return 1; |
504 | } | 504 | } |
505 | 505 | ||
506 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | 506 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, |
507 | const ASN1_ITEM *it, int tag, int aclass) | 507 | const ASN1_ITEM *it, int tag, int aclass) |
508 | { | 508 | { |
509 | int len; | 509 | int len; |
510 | int utype; | 510 | int utype; |
511 | int usetag; | 511 | int usetag; |
@@ -537,17 +537,17 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | |||
537 | 537 | ||
538 | /* -2 return is special meaning use ndef */ | 538 | /* -2 return is special meaning use ndef */ |
539 | if (len == -2) | 539 | if (len == -2) |
540 | { | 540 | { |
541 | ndef = 2; | 541 | ndef = 2; |
542 | len = 0; | 542 | len = 0; |
543 | } | 543 | } |
544 | 544 | ||
545 | /* If not implicitly tagged get tag from underlying type */ | 545 | /* If not implicitly tagged get tag from underlying type */ |
546 | if (tag == -1) tag = utype; | 546 | if (tag == -1) tag = utype; |
547 | 547 | ||
548 | /* Output tag+length followed by content octets */ | 548 | /* Output tag+length followed by content octets */ |
549 | if (out) | 549 | if (out) |
550 | { | 550 | { |
551 | if (usetag) | 551 | if (usetag) |
552 | ASN1_put_object(out, ndef, len, tag, aclass); | 552 | ASN1_put_object(out, ndef, len, tag, aclass); |
553 | asn1_ex_i2c(pval, *out, &utype, it); | 553 | asn1_ex_i2c(pval, *out, &utype, it); |
@@ -555,18 +555,18 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | |||
555 | ASN1_put_eoc(out); | 555 | ASN1_put_eoc(out); |
556 | else | 556 | else |
557 | *out += len; | 557 | *out += len; |
558 | } | 558 | } |
559 | 559 | ||
560 | if (usetag) | 560 | if (usetag) |
561 | return ASN1_object_size(ndef, len, tag); | 561 | return ASN1_object_size(ndef, len, tag); |
562 | return len; | 562 | return len; |
563 | } | 563 | } |
564 | 564 | ||
565 | /* Produce content octets from a structure */ | 565 | /* Produce content octets from a structure */ |
566 | 566 | ||
567 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | 567 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, |
568 | const ASN1_ITEM *it) | 568 | const ASN1_ITEM *it) |
569 | { | 569 | { |
570 | ASN1_BOOLEAN *tbool = NULL; | 570 | ASN1_BOOLEAN *tbool = NULL; |
571 | ASN1_STRING *strtmp; | 571 | ASN1_STRING *strtmp; |
572 | ASN1_OBJECT *otmp; | 572 | ASN1_OBJECT *otmp; |
@@ -582,30 +582,30 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
582 | /* Should type be omitted? */ | 582 | /* Should type be omitted? */ |
583 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) | 583 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) |
584 | || (it->utype != V_ASN1_BOOLEAN)) | 584 | || (it->utype != V_ASN1_BOOLEAN)) |
585 | { | 585 | { |
586 | if (!*pval) return -1; | 586 | if (!*pval) return -1; |
587 | } | 587 | } |
588 | 588 | ||
589 | if (it->itype == ASN1_ITYPE_MSTRING) | 589 | if (it->itype == ASN1_ITYPE_MSTRING) |
590 | { | 590 | { |
591 | /* If MSTRING type set the underlying type */ | 591 | /* If MSTRING type set the underlying type */ |
592 | strtmp = (ASN1_STRING *)*pval; | 592 | strtmp = (ASN1_STRING *)*pval; |
593 | utype = strtmp->type; | 593 | utype = strtmp->type; |
594 | *putype = utype; | 594 | *putype = utype; |
595 | } | 595 | } |
596 | else if (it->utype == V_ASN1_ANY) | 596 | else if (it->utype == V_ASN1_ANY) |
597 | { | 597 | { |
598 | /* If ANY set type and pointer to value */ | 598 | /* If ANY set type and pointer to value */ |
599 | ASN1_TYPE *typ; | 599 | ASN1_TYPE *typ; |
600 | typ = (ASN1_TYPE *)*pval; | 600 | typ = (ASN1_TYPE *)*pval; |
601 | utype = typ->type; | 601 | utype = typ->type; |
602 | *putype = utype; | 602 | *putype = utype; |
603 | pval = &typ->value.asn1_value; | 603 | pval = &typ->value.asn1_value; |
604 | } | 604 | } |
605 | else utype = *putype; | 605 | else utype = *putype; |
606 | 606 | ||
607 | switch(utype) | 607 | switch(utype) |
608 | { | 608 | { |
609 | case V_ASN1_OBJECT: | 609 | case V_ASN1_OBJECT: |
610 | otmp = (ASN1_OBJECT *)*pval; | 610 | otmp = (ASN1_OBJECT *)*pval; |
611 | cont = otmp->data; | 611 | cont = otmp->data; |
@@ -622,13 +622,13 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
622 | if (*tbool == -1) | 622 | if (*tbool == -1) |
623 | return -1; | 623 | return -1; |
624 | if (it->utype != V_ASN1_ANY) | 624 | if (it->utype != V_ASN1_ANY) |
625 | { | 625 | { |
626 | /* Default handling if value == size field then omit */ | 626 | /* Default handling if value == size field then omit */ |
627 | if (*tbool && (it->size > 0)) | 627 | if (*tbool && (it->size > 0)) |
628 | return -1; | 628 | return -1; |
629 | if (!*tbool && !it->size) | 629 | if (!*tbool && !it->size) |
630 | return -1; | 630 | return -1; |
631 | } | 631 | } |
632 | c = (unsigned char)*tbool; | 632 | c = (unsigned char)*tbool; |
633 | cont = &c; | 633 | cont = &c; |
634 | len = 1; | 634 | len = 1; |
@@ -672,22 +672,22 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
672 | /* Special handling for NDEF */ | 672 | /* Special handling for NDEF */ |
673 | if ((it->size == ASN1_TFLG_NDEF) | 673 | if ((it->size == ASN1_TFLG_NDEF) |
674 | && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) | 674 | && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) |
675 | { | 675 | { |
676 | if (cout) | 676 | if (cout) |
677 | { | 677 | { |
678 | strtmp->data = cout; | 678 | strtmp->data = cout; |
679 | strtmp->length = 0; | 679 | strtmp->length = 0; |
680 | } | 680 | } |
681 | /* Special return code */ | 681 | /* Special return code */ |
682 | return -2; | 682 | return -2; |
683 | } | 683 | } |
684 | cont = strtmp->data; | 684 | cont = strtmp->data; |
685 | len = strtmp->length; | 685 | len = strtmp->length; |
686 | 686 | ||
687 | break; | 687 | break; |
688 | 688 | ||
689 | } | 689 | } |
690 | if (cout && len) | 690 | if (cout && len) |
691 | memcpy(cout, cont, len); | 691 | memcpy(cout, cont, len); |
692 | return len; | 692 | return len; |
693 | } | 693 | } |