From f1bfac5c0c9b216325ace4860e9de46713ed5a5c Mon Sep 17 00:00:00 2001 From: jsing <> Date: Fri, 4 Nov 2016 18:35:30 +0000 Subject: Kill a bunch of OLD_ASN1 usage by replacing ASN1_{d2i,i2d}_* with ASN1_item_{d2i,i2d}_* equivalents. ok guenther@ miod@ --- src/lib/libcrypto/dh/dh.h | 12 +++++------- src/lib/libcrypto/dh/dh_asn1.c | 26 +++++++++++++++++++++++++- src/lib/libcrypto/dsa/dsa.h | 13 +++++-------- src/lib/libcrypto/dsa/dsa_asn1.c | 26 +++++++++++++++++++++++++- src/lib/libcrypto/ocsp/ocsp.h | 18 +++++------------- src/lib/libcrypto/ocsp/ocsp_asn.c | 27 +++++++++++++++++++++++++-- src/lib/libcrypto/ts/ts_asn1.c | 38 +++++++++++++++++--------------------- 7 files changed, 107 insertions(+), 53 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h index 631cd5c685..920af3b92d 100644 --- a/src/lib/libcrypto/dh/dh.h +++ b/src/lib/libcrypto/dh/dh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dh.h,v 1.17 2016/06/30 02:02:06 bcook Exp $ */ +/* $OpenBSD: dh.h,v 1.18 2016/11/04 18:35:30 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -165,12 +165,10 @@ struct dh_st this for backward compatibility: */ #define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME -#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ - (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x)) -#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \ - (unsigned char *)(x)) -#define d2i_DHparams_bio(bp,x) ASN1_d2i_bio_of(DH,DH_new,d2i_DHparams,bp,x) -#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x) +DH *d2i_DHparams_bio(BIO *bp, DH **a); +int i2d_DHparams_bio(BIO *bp, DH *a); +DH *d2i_DHparams_fp(FILE *fp, DH **a); +int i2d_DHparams_fp(FILE *fp, DH *a); DH *DHparams_dup(DH *); diff --git a/src/lib/libcrypto/dh/dh_asn1.c b/src/lib/libcrypto/dh/dh_asn1.c index 7060130ed8..d7fd4f7d88 100644 --- a/src/lib/libcrypto/dh/dh_asn1.c +++ b/src/lib/libcrypto/dh/dh_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh_asn1.c,v 1.8 2015/02/14 15:06:55 jsing Exp $ */ +/* $OpenBSD: dh_asn1.c,v 1.9 2016/11/04 18:35:30 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -136,6 +136,30 @@ i2d_DHparams(const DH *a, unsigned char **out) return ASN1_item_i2d((ASN1_VALUE *)a, out, &DHparams_it); } +DH * +d2i_DHparams_bio(BIO *bp, DH **a) +{ + return ASN1_item_d2i_bio(&DHparams_it, bp, a); +} + +int +i2d_DHparams_bio(BIO *bp, DH *a) +{ + return ASN1_item_i2d_bio(&DHparams_it, bp, a); +} + +DH * +d2i_DHparams_fp(FILE *fp, DH **a) +{ + return ASN1_item_d2i_fp(&DHparams_it, fp, a); +} + +int +i2d_DHparams_fp(FILE *fp, DH *a) +{ + return ASN1_item_i2d_fp(&DHparams_it, fp, a); +} + DH * DHparams_dup(DH *dh) { diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h index b4d7c1ff0f..6ddd4c35d5 100644 --- a/src/lib/libcrypto/dsa/dsa.h +++ b/src/lib/libcrypto/dsa/dsa.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa.h,v 1.21 2016/06/30 02:02:06 bcook Exp $ */ +/* $OpenBSD: dsa.h,v 1.22 2016/11/04 18:35:30 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -173,13 +173,10 @@ struct dsa_st ENGINE *engine; }; -#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ - (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) -#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ - (unsigned char *)(x)) -#define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x) -#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x) - +DSA *d2i_DSAparams_bio(BIO *bp, DSA **a); +int i2d_DSAparams_bio(BIO *bp, DSA *a); +DSA *d2i_DSAparams_fp(FILE *fp, DSA **a); +int i2d_DSAparams_fp(FILE *fp, DSA *a); DSA *DSAparams_dup(DSA *x); DSA_SIG * DSA_SIG_new(void); diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c index 8c5d93105c..6366acdd79 100644 --- a/src/lib/libcrypto/dsa/dsa_asn1.c +++ b/src/lib/libcrypto/dsa/dsa_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_asn1.c,v 1.16 2015/02/14 15:06:55 jsing Exp $ */ +/* $OpenBSD: dsa_asn1.c,v 1.17 2016/11/04 18:35:30 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -283,6 +283,30 @@ i2d_DSAparams(const DSA *a, unsigned char **out) return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAparams_it); } +DSA * +d2i_DSAparams_bio(BIO *bp, DSA **a) +{ + return ASN1_item_d2i_bio(&DSAparams_it, bp, a); +} + +int +i2d_DSAparams_bio(BIO *bp, DSA *a) +{ + return ASN1_item_i2d_bio(&DSAparams_it, bp, a); +} + +DSA * +d2i_DSAparams_fp(FILE *fp, DSA **a) +{ + return ASN1_item_d2i_fp(&DSAparams_it, fp, a); +} + +int +i2d_DSAparams_fp(FILE *fp, DSA *a) +{ + return ASN1_item_i2d_fp(&DSAparams_it, fp, a); +} + /* * DSA public key is a bit trickier... its effectively a CHOICE type * decided by a field called write_params which can either write out diff --git a/src/lib/libcrypto/ocsp/ocsp.h b/src/lib/libcrypto/ocsp/ocsp.h index 90f0edf289..24592bc3cc 100644 --- a/src/lib/libcrypto/ocsp/ocsp.h +++ b/src/lib/libcrypto/ocsp/ocsp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ocsp.h,v 1.8 2016/09/04 17:18:18 jsing Exp $ */ +/* $OpenBSD: ocsp.h,v 1.9 2016/11/04 18:35:30 jsing Exp $ */ /* Written by Tom Titchener for the OpenSSL * project. */ @@ -343,12 +343,6 @@ typedef struct ocsp_service_locator_st { #define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" #define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" -#define d2i_OCSP_REQUEST_bio(bp,p) \ - ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p) - -#define d2i_OCSP_RESPONSE_bio(bp,p) \ - ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p) - #define PEM_read_bio_OCSP_REQUEST(bp,x,cb) \ (OCSP_REQUEST *)PEM_ASN1_read_bio((char *(*)())d2i_OCSP_REQUEST, \ PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL) @@ -365,12 +359,6 @@ typedef struct ocsp_service_locator_st { PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\ bp,(char *)o, NULL,NULL,0,NULL,NULL) -#define i2d_OCSP_RESPONSE_bio(bp,o) \ - ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o) - -#define i2d_OCSP_REQUEST_bio(bp,o) \ - ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o) - #define OCSP_REQUEST_sign(o,pkey,md) \ ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO), \ o->optionalSignature->signatureAlgorithm,NULL, \ @@ -560,6 +548,8 @@ OCSP_RESPONSE *OCSP_RESPONSE_new(void); void OCSP_RESPONSE_free(OCSP_RESPONSE *a); OCSP_RESPONSE *d2i_OCSP_RESPONSE(OCSP_RESPONSE **a, const unsigned char **in, long len); int i2d_OCSP_RESPONSE(OCSP_RESPONSE *a, unsigned char **out); +OCSP_RESPONSE *d2i_OCSP_RESPONSE_bio(BIO *bp, OCSP_RESPONSE **a); +int i2d_OCSP_RESPONSE_bio(BIO *bp, OCSP_RESPONSE *a); extern const ASN1_ITEM OCSP_RESPONSE_it; OCSP_RESPBYTES *OCSP_RESPBYTES_new(void); void OCSP_RESPBYTES_free(OCSP_RESPBYTES *a); @@ -580,6 +570,8 @@ OCSP_REQUEST *OCSP_REQUEST_new(void); void OCSP_REQUEST_free(OCSP_REQUEST *a); OCSP_REQUEST *d2i_OCSP_REQUEST(OCSP_REQUEST **a, const unsigned char **in, long len); int i2d_OCSP_REQUEST(OCSP_REQUEST *a, unsigned char **out); +OCSP_REQUEST *d2i_OCSP_REQUEST_bio(BIO *bp, OCSP_REQUEST **a); +int i2d_OCSP_REQUEST_bio(BIO *bp, OCSP_REQUEST *a); extern const ASN1_ITEM OCSP_REQUEST_it; OCSP_SIGNATURE *OCSP_SIGNATURE_new(void); void OCSP_SIGNATURE_free(OCSP_SIGNATURE *a); diff --git a/src/lib/libcrypto/ocsp/ocsp_asn.c b/src/lib/libcrypto/ocsp/ocsp_asn.c index 72e7638c75..bb58ca79ab 100644 --- a/src/lib/libcrypto/ocsp/ocsp_asn.c +++ b/src/lib/libcrypto/ocsp/ocsp_asn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ocsp_asn.c,v 1.8 2015/07/25 14:52:47 jsing Exp $ */ +/* $OpenBSD: ocsp_asn.c,v 1.9 2016/11/04 18:35:30 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -333,7 +333,6 @@ const ASN1_ITEM OCSP_REQUEST_it = { .sname = "OCSP_REQUEST", }; - OCSP_REQUEST * d2i_OCSP_REQUEST(OCSP_REQUEST **a, const unsigned char **in, long len) { @@ -347,6 +346,18 @@ i2d_OCSP_REQUEST(OCSP_REQUEST *a, unsigned char **out) return ASN1_item_i2d((ASN1_VALUE *)a, out, &OCSP_REQUEST_it); } +OCSP_REQUEST * +d2i_OCSP_REQUEST_bio(BIO *bp, OCSP_REQUEST **a) +{ + return ASN1_item_d2i_bio(&OCSP_REQUEST_it, bp, a); +} + +int +i2d_OCSP_REQUEST_bio(BIO *bp, OCSP_REQUEST *a) +{ + return ASN1_item_i2d_bio(&OCSP_REQUEST_it, bp, a); +} + OCSP_REQUEST * OCSP_REQUEST_new(void) { @@ -455,6 +466,18 @@ i2d_OCSP_RESPONSE(OCSP_RESPONSE *a, unsigned char **out) return ASN1_item_i2d((ASN1_VALUE *)a, out, &OCSP_RESPONSE_it); } +OCSP_RESPONSE * +d2i_OCSP_RESPONSE_bio(BIO *bp, OCSP_RESPONSE **a) +{ + return ASN1_item_d2i_bio(&OCSP_RESPONSE_it, bp, a); +} + +int +i2d_OCSP_RESPONSE_bio(BIO *bp, OCSP_RESPONSE *a) +{ + return ASN1_item_i2d_bio(&OCSP_RESPONSE_it, bp, a); +} + OCSP_RESPONSE * OCSP_RESPONSE_new(void) { diff --git a/src/lib/libcrypto/ts/ts_asn1.c b/src/lib/libcrypto/ts/ts_asn1.c index 1386483247..49232d8073 100644 --- a/src/lib/libcrypto/ts/ts_asn1.c +++ b/src/lib/libcrypto/ts/ts_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ts_asn1.c,v 1.9 2015/07/24 15:25:44 jsing Exp $ */ +/* $OpenBSD: ts_asn1.c,v 1.10 2016/11/04 18:35:30 jsing Exp $ */ /* Written by Nils Larsch for the OpenSSL project 2004. */ /* ==================================================================== @@ -124,28 +124,26 @@ TS_MSG_IMPRINT_dup(TS_MSG_IMPRINT *x) TS_MSG_IMPRINT * d2i_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT **a) { - return ASN1_d2i_bio_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new, - d2i_TS_MSG_IMPRINT, bp, a); + return ASN1_item_d2i_bio(&TS_MSG_IMPRINT_it, bp, a); } int i2d_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT *a) { - return ASN1_i2d_bio_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, bp, a); + return ASN1_item_i2d_bio(&TS_MSG_IMPRINT_it, bp, a); } #endif TS_MSG_IMPRINT * d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a) { - return ASN1_d2i_fp_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new, - d2i_TS_MSG_IMPRINT, fp, a); + return ASN1_item_d2i_fp(&TS_MSG_IMPRINT_it, fp, a); } int i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a) { - return ASN1_i2d_fp_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, fp, a); + return ASN1_item_i2d_fp(&TS_MSG_IMPRINT_it, fp, a); } static const ASN1_TEMPLATE TS_REQ_seq_tt[] = { @@ -239,26 +237,26 @@ TS_REQ_dup(TS_REQ *x) TS_REQ * d2i_TS_REQ_bio(BIO *bp, TS_REQ **a) { - return ASN1_d2i_bio_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, bp, a); + return ASN1_item_d2i_bio(&TS_REQ_it, bp, a); } int i2d_TS_REQ_bio(BIO *bp, TS_REQ *a) { - return ASN1_i2d_bio_of_const(TS_REQ, i2d_TS_REQ, bp, a); + return ASN1_item_i2d_bio(&TS_REQ_it, bp, a); } #endif TS_REQ * d2i_TS_REQ_fp(FILE *fp, TS_REQ **a) { - return ASN1_d2i_fp_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, fp, a); + return ASN1_item_d2i_fp(&TS_REQ_it, fp, a); } int i2d_TS_REQ_fp(FILE *fp, TS_REQ *a) { - return ASN1_i2d_fp_of_const(TS_REQ, i2d_TS_REQ, fp, a); + return ASN1_item_i2d_fp(&TS_REQ_it, fp, a); } static const ASN1_TEMPLATE TS_ACCURACY_seq_tt[] = { @@ -446,28 +444,26 @@ TS_TST_INFO_dup(TS_TST_INFO *x) TS_TST_INFO * d2i_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO **a) { - return ASN1_d2i_bio_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO, - bp, a); + return ASN1_item_d2i_bio(&TS_TST_INFO_it, bp, a); } int i2d_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO *a) { - return ASN1_i2d_bio_of_const(TS_TST_INFO, i2d_TS_TST_INFO, bp, a); + return ASN1_item_i2d_bio(&TS_TST_INFO_it, bp, a); } #endif TS_TST_INFO * d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a) { - return ASN1_d2i_fp_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO, - fp, a); + return ASN1_item_d2i_fp(&TS_TST_INFO_it, fp, a); } int i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a) { - return ASN1_i2d_fp_of_const(TS_TST_INFO, i2d_TS_TST_INFO, fp, a); + return ASN1_item_i2d_fp(&TS_TST_INFO_it, fp, a); } static const ASN1_TEMPLATE TS_STATUS_INFO_seq_tt[] = { @@ -652,26 +648,26 @@ TS_RESP_dup(TS_RESP *x) TS_RESP * d2i_TS_RESP_bio(BIO *bp, TS_RESP **a) { - return ASN1_d2i_bio_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, bp, a); + return ASN1_item_d2i_bio(&TS_RESP_it, bp, a); } int i2d_TS_RESP_bio(BIO *bp, TS_RESP *a) { - return ASN1_i2d_bio_of_const(TS_RESP, i2d_TS_RESP, bp, a); + return ASN1_item_i2d_bio(&TS_RESP_it, bp, a); } #endif TS_RESP * d2i_TS_RESP_fp(FILE *fp, TS_RESP **a) { - return ASN1_d2i_fp_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, fp, a); + return ASN1_item_d2i_fp(&TS_RESP_it, fp, a); } int i2d_TS_RESP_fp(FILE *fp, TS_RESP *a) { - return ASN1_i2d_fp_of_const(TS_RESP, i2d_TS_RESP, fp, a); + return ASN1_item_i2d_fp(&TS_RESP_it, fp, a); } static const ASN1_TEMPLATE ESS_ISSUER_SERIAL_seq_tt[] = { -- cgit v1.2.3-55-g6feb