summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2021-12-03 16:46:50 +0000
committerjsing <>2021-12-03 16:46:50 +0000
commitbd56135d9ad11bc1eb15ab9e1a278d7cdc43e626 (patch)
tree83b9735206e772a25a55c5db205cb59e19ab92c9 /src
parent40cbc758c79bfc275f06d4fb3761a882fe316ebf (diff)
downloadopenbsd-bd56135d9ad11bc1eb15ab9e1a278d7cdc43e626.tar.gz
openbsd-bd56135d9ad11bc1eb15ab9e1a278d7cdc43e626.tar.bz2
openbsd-bd56135d9ad11bc1eb15ab9e1a278d7cdc43e626.zip
Convert {i2d,d2i}_{,EC_,DSA_,RSA_}PUBKEY{,_bio,_fp}() to templated ASN1
These functions previously used the old ASN1_{d2i,i2d}_{bio,fp}() interfaces. ok inoguchi@ tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c554
-rw-r--r--src/lib/libcrypto/x509/x_all.c98
2 files changed, 430 insertions, 222 deletions
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index cb16d03301..3efe61db48 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pubkey.c,v 1.28 2021/11/01 20:53:08 tb Exp $ */ 1/* $OpenBSD: x_pubkey.c,v 1.29 2021/12/03 16:46:50 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -111,7 +111,6 @@ const ASN1_ITEM X509_PUBKEY_it = {
111 .sname = "X509_PUBKEY", 111 .sname = "X509_PUBKEY",
112}; 112};
113 113
114
115X509_PUBKEY * 114X509_PUBKEY *
116d2i_X509_PUBKEY(X509_PUBKEY **a, const unsigned char **in, long len) 115d2i_X509_PUBKEY(X509_PUBKEY **a, const unsigned char **in, long len)
117{ 116{
@@ -240,168 +239,473 @@ X509_PUBKEY_get(X509_PUBKEY *key)
240 return pkey; 239 return pkey;
241} 240}
242 241
243/* Now two pseudo ASN1 routines that take an EVP_PKEY structure 242/*
244 * and encode or decode as X509_PUBKEY 243 * Decode an X509_PUBKEY into the specified key type.
245 */ 244 */
245static int
246pubkey_ex_d2i(int pkey_type, ASN1_VALUE **pval, const unsigned char **in,
247 long len, const ASN1_ITEM *it)
248{
249 const ASN1_EXTERN_FUNCS *ef = it->funcs;
250 const unsigned char *p = *in;
251 X509_PUBKEY *xpk = NULL;
252 ASN1_VALUE *key = NULL;
253 EVP_PKEY *pkey = NULL;
254 int ret = 0;
255
256 if ((xpk = d2i_X509_PUBKEY(NULL, &p, len)) == NULL)
257 goto err;
258 if ((pkey = X509_PUBKEY_get(xpk)) == NULL)
259 goto err;
260
261 switch (pkey_type) {
262 case EVP_PKEY_NONE:
263 key = (ASN1_VALUE *)pkey;
264 pkey = NULL;
265 break;
266
267 case EVP_PKEY_DSA:
268 key = (ASN1_VALUE *)EVP_PKEY_get1_DSA(pkey);
269 break;
270
271 case EVP_PKEY_RSA:
272 key = (ASN1_VALUE *)EVP_PKEY_get1_RSA(pkey);
273 break;
274
275 case EVP_PKEY_EC:
276 key = (ASN1_VALUE *)EVP_PKEY_get1_EC_KEY(pkey);
277 break;
278
279 default:
280 goto err;
281 }
246 282
247EVP_PKEY * 283 if (key == NULL)
248d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length) 284 goto err;
249{ 285
250 X509_PUBKEY *xpk; 286 ef->asn1_ex_free(pval, it);
251 EVP_PKEY *pktmp; 287
252 xpk = d2i_X509_PUBKEY(NULL, pp, length); 288 *pval = key;
253 if (!xpk) 289 *in = p;
254 return NULL; 290 ret = 1;
255 pktmp = X509_PUBKEY_get(xpk); 291
292 err:
293 EVP_PKEY_free(pkey);
256 X509_PUBKEY_free(xpk); 294 X509_PUBKEY_free(xpk);
257 if (!pktmp) 295
258 return NULL; 296 return ret;
259 if (a) {
260 EVP_PKEY_free(*a);
261 *a = pktmp;
262 }
263 return pktmp;
264} 297}
265 298
266int 299/*
267i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) 300 * Encode the specified key type into an X509_PUBKEY.
301 */
302static int
303pubkey_ex_i2d(int pkey_type, ASN1_VALUE **pval, unsigned char **out,
304 const ASN1_ITEM *it)
268{ 305{
269 X509_PUBKEY *xpk = NULL; 306 X509_PUBKEY *xpk = NULL;
270 int ret; 307 EVP_PKEY *pkey, *pktmp;
271 if (!a) 308 int ret = -1;
272 return 0; 309
273 if (!X509_PUBKEY_set(&xpk, a)) 310 if ((pkey = pktmp = EVP_PKEY_new()) == NULL)
274 return 0; 311 goto err;
275 ret = i2d_X509_PUBKEY(xpk, pp); 312
313 switch (pkey_type) {
314 case EVP_PKEY_NONE:
315 pkey = (EVP_PKEY *)*pval;
316 break;
317
318 case EVP_PKEY_DSA:
319 if (!EVP_PKEY_set1_DSA(pkey, (DSA *)*pval))
320 goto err;
321 break;
322
323 case EVP_PKEY_RSA:
324 if (!EVP_PKEY_set1_RSA(pkey, (RSA *)*pval))
325 goto err;
326 break;
327
328 case EVP_PKEY_EC:
329 if (!EVP_PKEY_set1_EC_KEY(pkey, (EC_KEY*)*pval))
330 goto err;
331 break;
332
333 default:
334 goto err;
335 }
336
337 if (!X509_PUBKEY_set(&xpk, pkey))
338 goto err;
339
340 ret = i2d_X509_PUBKEY(xpk, out);
341
342 err:
343 EVP_PKEY_free(pktmp);
276 X509_PUBKEY_free(xpk); 344 X509_PUBKEY_free(xpk);
345
277 return ret; 346 return ret;
278} 347}
279 348
280/* The following are equivalents but which return RSA and DSA 349static int
281 * keys 350pkey_pubkey_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
351{
352 if ((*pval = (ASN1_VALUE *)EVP_PKEY_new()) == NULL)
353 return 0;
354
355 return 1;
356}
357
358static void
359pkey_pubkey_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
360{
361 EVP_PKEY_free((EVP_PKEY *)*pval);
362 *pval = NULL;
363}
364
365static int
366pkey_pubkey_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
367 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
368{
369 return pubkey_ex_d2i(EVP_PKEY_NONE, pval, in, len, it);
370}
371
372static int
373pkey_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
374 int tag, int aclass)
375{
376 return pubkey_ex_i2d(EVP_PKEY_NONE, pval, out, it);
377}
378
379const ASN1_EXTERN_FUNCS pkey_pubkey_asn1_ff = {
380 .app_data = NULL,
381 .asn1_ex_new = pkey_pubkey_ex_new,
382 .asn1_ex_free = pkey_pubkey_ex_free,
383 .asn1_ex_clear = NULL,
384 .asn1_ex_d2i = pkey_pubkey_ex_d2i,
385 .asn1_ex_i2d = pkey_pubkey_ex_i2d,
386 .asn1_ex_print = NULL,
387};
388
389const ASN1_ITEM EVP_PKEY_PUBKEY_it = {
390 .itype = ASN1_ITYPE_EXTERN,
391 .utype = 0,
392 .templates = NULL,
393 .tcount = 0,
394 .funcs = &pkey_pubkey_asn1_ff,
395 .size = 0,
396 .sname = NULL,
397};
398
399EVP_PKEY *
400d2i_PUBKEY(EVP_PKEY **pkey, const unsigned char **in, long len)
401{
402 return (EVP_PKEY *)ASN1_item_d2i((ASN1_VALUE **)pkey, in, len,
403 &EVP_PKEY_PUBKEY_it);
404}
405
406int
407i2d_PUBKEY(EVP_PKEY *pkey, unsigned char **out)
408{
409 return ASN1_item_i2d((ASN1_VALUE *)pkey, out, &EVP_PKEY_PUBKEY_it);
410}
411
412EVP_PKEY *
413d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **pkey)
414{
415 return (EVP_PKEY *)ASN1_item_d2i_bio(&EVP_PKEY_PUBKEY_it, bp,
416 (ASN1_VALUE **)pkey);
417}
418
419int
420i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey)
421{
422 return ASN1_item_i2d_bio(&EVP_PKEY_PUBKEY_it, bp, (ASN1_VALUE *)pkey);
423}
424
425EVP_PKEY *
426d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **pkey)
427{
428 return (EVP_PKEY *)ASN1_item_d2i_fp(&EVP_PKEY_PUBKEY_it, fp,
429 (ASN1_VALUE **)pkey);
430}
431
432int
433i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey)
434{
435 return ASN1_item_i2d_fp(&EVP_PKEY_PUBKEY_it, fp, (ASN1_VALUE *)pkey);
436}
437
438/*
439 * The following are equivalents but which return RSA and DSA keys.
282 */ 440 */
283#ifndef OPENSSL_NO_RSA 441#ifndef OPENSSL_NO_RSA
442
443static int
444rsa_pubkey_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
445{
446 if ((*pval = (ASN1_VALUE *)RSA_new()) == NULL)
447 return 0;
448
449 return 1;
450}
451
452static void
453rsa_pubkey_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
454{
455 RSA_free((RSA *)*pval);
456 *pval = NULL;
457}
458
459static int
460rsa_pubkey_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
461 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
462{
463 return pubkey_ex_d2i(EVP_PKEY_RSA, pval, in, len, it);
464}
465
466static int
467rsa_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
468 int tag, int aclass)
469{
470 return pubkey_ex_i2d(EVP_PKEY_RSA, pval, out, it);
471}
472
473const ASN1_EXTERN_FUNCS rsa_pubkey_asn1_ff = {
474 .app_data = NULL,
475 .asn1_ex_new = rsa_pubkey_ex_new,
476 .asn1_ex_free = rsa_pubkey_ex_free,
477 .asn1_ex_clear = NULL,
478 .asn1_ex_d2i = rsa_pubkey_ex_d2i,
479 .asn1_ex_i2d = rsa_pubkey_ex_i2d,
480 .asn1_ex_print = NULL,
481};
482
483const ASN1_ITEM RSA_PUBKEY_it = {
484 .itype = ASN1_ITYPE_EXTERN,
485 .utype = 0,
486 .templates = NULL,
487 .tcount = 0,
488 .funcs = &rsa_pubkey_asn1_ff,
489 .size = 0,
490 .sname = NULL,
491};
492
284RSA * 493RSA *
285d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length) 494d2i_RSA_PUBKEY(RSA **rsa, const unsigned char **in, long len)
286{ 495{
287 EVP_PKEY *pkey; 496 return (RSA *)ASN1_item_d2i((ASN1_VALUE **)rsa, in, len,
288 RSA *key; 497 &RSA_PUBKEY_it);
289 const unsigned char *q;
290 q = *pp;
291 pkey = d2i_PUBKEY(NULL, &q, length);
292 if (!pkey)
293 return NULL;
294 key = EVP_PKEY_get1_RSA(pkey);
295 EVP_PKEY_free(pkey);
296 if (!key)
297 return NULL;
298 *pp = q;
299 if (a) {
300 RSA_free(*a);
301 *a = key;
302 }
303 return key;
304} 498}
305 499
306int 500int
307i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) 501i2d_RSA_PUBKEY(RSA *rsa, unsigned char **out)
308{ 502{
309 EVP_PKEY *pktmp; 503 return ASN1_item_i2d((ASN1_VALUE *)rsa, out, &RSA_PUBKEY_it);
310 int ret; 504}
311 if (!a) 505
312 return 0; 506RSA *
313 pktmp = EVP_PKEY_new(); 507d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
314 if (!pktmp) { 508{
315 ASN1error(ERR_R_MALLOC_FAILURE); 509 return (RSA *)ASN1_item_d2i_bio(&RSA_PUBKEY_it, bp, (ASN1_VALUE **)rsa);
316 return 0; 510}
317 } 511
318 EVP_PKEY_set1_RSA(pktmp, a); 512int
319 ret = i2d_PUBKEY(pktmp, pp); 513i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
320 EVP_PKEY_free(pktmp); 514{
321 return ret; 515 return ASN1_item_i2d_bio(&RSA_PUBKEY_it, bp, (ASN1_VALUE *)rsa);
516}
517
518RSA *
519d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
520{
521 return (RSA *)ASN1_item_d2i_fp(&RSA_PUBKEY_it, fp, (ASN1_VALUE **)rsa);
522}
523
524int
525i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
526{
527 return ASN1_item_i2d_fp(&RSA_PUBKEY_it, fp, (ASN1_VALUE *)rsa);
322} 528}
323#endif 529#endif
324 530
325#ifndef OPENSSL_NO_DSA 531#ifndef OPENSSL_NO_DSA
532
533static int
534dsa_pubkey_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
535{
536 if ((*pval = (ASN1_VALUE *)DSA_new()) == NULL)
537 return 0;
538
539 return 1;
540}
541
542static void
543dsa_pubkey_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
544{
545 DSA_free((DSA *)*pval);
546 *pval = NULL;
547}
548
549static int
550dsa_pubkey_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
551 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
552{
553 return pubkey_ex_d2i(EVP_PKEY_DSA, pval, in, len, it);
554}
555
556static int
557dsa_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
558 int tag, int aclass)
559{
560 return pubkey_ex_i2d(EVP_PKEY_DSA, pval, out, it);
561}
562
563const ASN1_EXTERN_FUNCS dsa_pubkey_asn1_ff = {
564 .app_data = NULL,
565 .asn1_ex_new = dsa_pubkey_ex_new,
566 .asn1_ex_free = dsa_pubkey_ex_free,
567 .asn1_ex_clear = NULL,
568 .asn1_ex_d2i = dsa_pubkey_ex_d2i,
569 .asn1_ex_i2d = dsa_pubkey_ex_i2d,
570 .asn1_ex_print = NULL,
571};
572
573const ASN1_ITEM DSA_PUBKEY_it = {
574 .itype = ASN1_ITYPE_EXTERN,
575 .utype = 0,
576 .templates = NULL,
577 .tcount = 0,
578 .funcs = &dsa_pubkey_asn1_ff,
579 .size = 0,
580 .sname = NULL,
581};
582
326DSA * 583DSA *
327d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length) 584d2i_DSA_PUBKEY(DSA **dsa, const unsigned char **in, long len)
328{ 585{
329 EVP_PKEY *pkey; 586 return (DSA *)ASN1_item_d2i((ASN1_VALUE **)dsa, in, len,
330 DSA *key; 587 &DSA_PUBKEY_it);
331 const unsigned char *q;
332 q = *pp;
333 pkey = d2i_PUBKEY(NULL, &q, length);
334 if (!pkey)
335 return NULL;
336 key = EVP_PKEY_get1_DSA(pkey);
337 EVP_PKEY_free(pkey);
338 if (!key)
339 return NULL;
340 *pp = q;
341 if (a) {
342 DSA_free(*a);
343 *a = key;
344 }
345 return key;
346} 588}
347 589
348int 590int
349i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) 591i2d_DSA_PUBKEY(DSA *dsa, unsigned char **out)
350{ 592{
351 EVP_PKEY *pktmp; 593 return ASN1_item_i2d((ASN1_VALUE *)dsa, out, &DSA_PUBKEY_it);
352 int ret; 594}
353 if (!a) 595
354 return 0; 596DSA *
355 pktmp = EVP_PKEY_new(); 597d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
356 if (!pktmp) { 598{
357 ASN1error(ERR_R_MALLOC_FAILURE); 599 return (DSA *)ASN1_item_d2i_bio(&DSA_PUBKEY_it, bp, (ASN1_VALUE **)dsa);
358 return 0; 600}
359 } 601
360 EVP_PKEY_set1_DSA(pktmp, a); 602int
361 ret = i2d_PUBKEY(pktmp, pp); 603i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
362 EVP_PKEY_free(pktmp); 604{
363 return ret; 605 return ASN1_item_i2d_bio(&DSA_PUBKEY_it, bp, (ASN1_VALUE *)dsa);
606}
607
608DSA *
609d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
610{
611 return (DSA *)ASN1_item_d2i_fp(&DSA_PUBKEY_it, fp, (ASN1_VALUE **)dsa);
364} 612}
613
614int
615i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
616{
617 return ASN1_item_i2d_fp(&DSA_PUBKEY_it, fp, (ASN1_VALUE *)dsa);
618}
619
365#endif 620#endif
366 621
367#ifndef OPENSSL_NO_EC 622#ifndef OPENSSL_NO_EC
623
624static int
625ec_pubkey_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
626{
627 if ((*pval = (ASN1_VALUE *)EC_KEY_new()) == NULL)
628 return 0;
629
630 return 1;
631}
632
633static void
634ec_pubkey_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
635{
636 EC_KEY_free((EC_KEY *)*pval);
637 *pval = NULL;
638}
639
640static int
641ec_pubkey_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
642 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
643{
644 return pubkey_ex_d2i(EVP_PKEY_EC, pval, in, len, it);
645}
646
647static int
648ec_pubkey_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
649 int tag, int aclass)
650{
651 return pubkey_ex_i2d(EVP_PKEY_EC, pval, out, it);
652}
653
654const ASN1_EXTERN_FUNCS ec_pubkey_asn1_ff = {
655 .app_data = NULL,
656 .asn1_ex_new = ec_pubkey_ex_new,
657 .asn1_ex_free = ec_pubkey_ex_free,
658 .asn1_ex_clear = NULL,
659 .asn1_ex_d2i = ec_pubkey_ex_d2i,
660 .asn1_ex_i2d = ec_pubkey_ex_i2d,
661 .asn1_ex_print = NULL,
662};
663
664const ASN1_ITEM EC_PUBKEY_it = {
665 .itype = ASN1_ITYPE_EXTERN,
666 .utype = 0,
667 .templates = NULL,
668 .tcount = 0,
669 .funcs = &ec_pubkey_asn1_ff,
670 .size = 0,
671 .sname = NULL,
672};
673
368EC_KEY * 674EC_KEY *
369d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) 675d2i_EC_PUBKEY(EC_KEY **ec, const unsigned char **in, long len)
370{ 676{
371 EVP_PKEY *pkey; 677 return (EC_KEY *)ASN1_item_d2i((ASN1_VALUE **)ec, in, len,
372 EC_KEY *key; 678 &EC_PUBKEY_it);
373 const unsigned char *q;
374 q = *pp;
375 pkey = d2i_PUBKEY(NULL, &q, length);
376 if (!pkey)
377 return (NULL);
378 key = EVP_PKEY_get1_EC_KEY(pkey);
379 EVP_PKEY_free(pkey);
380 if (!key)
381 return (NULL);
382 *pp = q;
383 if (a) {
384 EC_KEY_free(*a);
385 *a = key;
386 }
387 return (key);
388} 679}
389 680
390int 681int
391i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) 682i2d_EC_PUBKEY(EC_KEY *ec, unsigned char **out)
392{ 683{
393 EVP_PKEY *pktmp; 684 return ASN1_item_i2d((ASN1_VALUE *)ec, out, &EC_PUBKEY_it);
394 int ret; 685}
395 if (!a) 686
396 return (0); 687EC_KEY *
397 if ((pktmp = EVP_PKEY_new()) == NULL) { 688d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **ec)
398 ASN1error(ERR_R_MALLOC_FAILURE); 689{
399 return (0); 690 return (EC_KEY *)ASN1_item_d2i_bio(&EC_PUBKEY_it, bp, (ASN1_VALUE **)ec);
400 } 691}
401 EVP_PKEY_set1_EC_KEY(pktmp, a); 692
402 ret = i2d_PUBKEY(pktmp, pp); 693int
403 EVP_PKEY_free(pktmp); 694i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ec)
404 return (ret); 695{
696 return ASN1_item_i2d_bio(&EC_PUBKEY_it, bp, (ASN1_VALUE *)ec);
697}
698
699EC_KEY *
700d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **ec)
701{
702 return (EC_KEY *)ASN1_item_d2i_fp(&EC_PUBKEY_it, fp, (ASN1_VALUE **)ec);
703}
704
705int
706i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *ec)
707{
708 return ASN1_item_i2d_fp(&EC_PUBKEY_it, fp, (ASN1_VALUE *)ec);
405} 709}
406#endif 710#endif
407 711
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c
index c06e74c915..9bcb0c3bbe 100644
--- a/src/lib/libcrypto/x509/x_all.c
+++ b/src/lib/libcrypto/x509/x_all.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_all.c,v 1.24 2021/11/01 20:53:08 tb Exp $ */ 1/* $OpenBSD: x_all.c,v 1.25 2021/12/03 16:46:50 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -219,31 +219,6 @@ i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
219{ 219{
220 return ASN1_item_i2d_fp(&RSAPublicKey_it, fp, rsa); 220 return ASN1_item_i2d_fp(&RSAPublicKey_it, fp, rsa);
221} 221}
222
223RSA *
224d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
225{
226 return ASN1_d2i_bio_of(RSA, RSA_new, d2i_RSA_PUBKEY, bp, rsa);
227}
228
229int
230i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
231{
232 return ASN1_i2d_bio_of(RSA, i2d_RSA_PUBKEY, bp, rsa);
233}
234
235int
236i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
237{
238 return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY, fp, rsa);
239}
240
241RSA *
242d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
243{
244 return ASN1_d2i_fp((void *(*)(void))RSA_new,
245 (D2I_OF(void))d2i_RSA_PUBKEY, fp, (void **)rsa);
246}
247#endif 222#endif
248 223
249#ifndef OPENSSL_NO_DSA 224#ifndef OPENSSL_NO_DSA
@@ -270,30 +245,6 @@ i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
270{ 245{
271 return ASN1_item_i2d_fp(&DSAPrivateKey_it, fp, dsa); 246 return ASN1_item_i2d_fp(&DSAPrivateKey_it, fp, dsa);
272} 247}
273
274DSA *
275d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
276{
277 return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSA_PUBKEY, bp, dsa);
278}
279
280int
281i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
282{
283 return ASN1_i2d_bio_of(DSA, i2d_DSA_PUBKEY, bp, dsa);
284}
285
286DSA *
287d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
288{
289 return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSA_PUBKEY, fp, dsa);
290}
291
292int
293i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
294{
295 return ASN1_i2d_fp_of(DSA, i2d_DSA_PUBKEY, fp, dsa);
296}
297#endif 248#endif
298 249
299#ifndef OPENSSL_NO_EC 250#ifndef OPENSSL_NO_EC
@@ -320,29 +271,6 @@ i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey)
320{ 271{
321 return ASN1_i2d_fp_of(EC_KEY, i2d_ECPrivateKey, fp, eckey); 272 return ASN1_i2d_fp_of(EC_KEY, i2d_ECPrivateKey, fp, eckey);
322} 273}
323
324EC_KEY *
325d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey)
326{
327 return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, bp, eckey);
328}
329
330int
331i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa)
332{
333 return ASN1_i2d_bio_of(EC_KEY, i2d_EC_PUBKEY, bp, ecdsa);
334}
335EC_KEY *
336d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey)
337{
338 return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, fp, eckey);
339}
340
341int
342i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey)
343{
344 return ASN1_i2d_fp_of(EC_KEY, i2d_EC_PUBKEY, fp, eckey);
345}
346#endif 274#endif
347 275
348X509_SIG * 276X509_SIG *
@@ -423,30 +351,6 @@ i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey)
423 return ASN1_i2d_fp_of(EVP_PKEY, i2d_PrivateKey, fp, pkey); 351 return ASN1_i2d_fp_of(EVP_PKEY, i2d_PrivateKey, fp, pkey);
424} 352}
425 353
426EVP_PKEY *
427d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a)
428{
429 return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, bp, a);
430}
431
432int
433i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey)
434{
435 return ASN1_i2d_bio_of(EVP_PKEY, i2d_PUBKEY, bp, pkey);
436}
437
438int
439i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey)
440{
441 return ASN1_i2d_fp_of(EVP_PKEY, i2d_PUBKEY, fp, pkey);
442}
443
444EVP_PKEY *
445d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a)
446{
447 return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, fp, a);
448}
449
450int 354int
451i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) 355i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
452{ 356{