From e9038d389ea3e26d6fb698660ca175f275279c89 Mon Sep 17 00:00:00 2001 From: jsing Date: Tue, 13 Oct 2015 15:25:18 +0000 Subject: [PATCH] Convert ECParameters_dup() from a macro that uses ASN1_dup_of() into an actual function. This removes the last ASN1_dup_of usage from the tree. Feedback from doug@ and miod@ --- lib/libcrypto/doc/ec.pod | 2 +- lib/libcrypto/ec/ec.h | 5 ++--- lib/libcrypto/ec/ec_lib.c | 18 +++++++++++++++++- lib/libssl/src/crypto/ec/ec.h | 5 ++--- lib/libssl/src/crypto/ec/ec_lib.c | 18 +++++++++++++++++- lib/libssl/src/doc/crypto/ec.pod | 2 +- 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lib/libcrypto/doc/ec.pod b/lib/libcrypto/doc/ec.pod index 7d57ba8ea07..891948e4f6e 100644 --- a/lib/libcrypto/doc/ec.pod +++ b/lib/libcrypto/doc/ec.pod @@ -158,7 +158,7 @@ ec - Elliptic Curve functions int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); int ECParameters_print_fp(FILE *fp, const EC_KEY *key); int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); - #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) + EC_KEY *ECParameters_dup(EC_KEY *key); #define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \ EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \ EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL) diff --git a/lib/libcrypto/ec/ec.h b/lib/libcrypto/ec/ec.h index 3b409ff92d1..a1ece2e0d56 100644 --- a/lib/libcrypto/ec/ec.h +++ b/lib/libcrypto/ec/ec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ec.h,v 1.10 2015/06/20 13:26:08 jsing Exp $ */ +/* $OpenBSD: ec.h,v 1.11 2015/10/13 15:25:18 jsing Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -945,8 +945,7 @@ int ECParameters_print_fp(FILE *fp, const EC_KEY *key); */ int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); - -#define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) +EC_KEY *ECParameters_dup(EC_KEY *key); #ifndef __cplusplus #if defined(__SUNPRO_C) diff --git a/lib/libcrypto/ec/ec_lib.c b/lib/libcrypto/ec/ec_lib.c index c28ab18fc00..2b5abbd4bbf 100644 --- a/lib/libcrypto/ec/ec_lib.c +++ b/lib/libcrypto/ec/ec_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_lib.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.20 2015/10/13 15:25:18 jsing Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -1102,3 +1102,19 @@ EC_GROUP_have_precompute_mult(const EC_GROUP * group) return 0; /* cannot tell whether precomputation has * been performed */ } + +EC_KEY * +ECParameters_dup(EC_KEY *key) +{ + unsigned char *p = NULL; + EC_KEY *k = NULL; + int len; + + if (key == NULL) + return (NULL); + + if ((len = i2d_ECParameters(key, &p)) > 0) + k = d2i_ECParameters(NULL, (const unsigned char **)&p, len); + + return (k); +} diff --git a/lib/libssl/src/crypto/ec/ec.h b/lib/libssl/src/crypto/ec/ec.h index 3b409ff92d1..a1ece2e0d56 100644 --- a/lib/libssl/src/crypto/ec/ec.h +++ b/lib/libssl/src/crypto/ec/ec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ec.h,v 1.10 2015/06/20 13:26:08 jsing Exp $ */ +/* $OpenBSD: ec.h,v 1.11 2015/10/13 15:25:18 jsing Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -945,8 +945,7 @@ int ECParameters_print_fp(FILE *fp, const EC_KEY *key); */ int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); - -#define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) +EC_KEY *ECParameters_dup(EC_KEY *key); #ifndef __cplusplus #if defined(__SUNPRO_C) diff --git a/lib/libssl/src/crypto/ec/ec_lib.c b/lib/libssl/src/crypto/ec/ec_lib.c index c28ab18fc00..2b5abbd4bbf 100644 --- a/lib/libssl/src/crypto/ec/ec_lib.c +++ b/lib/libssl/src/crypto/ec/ec_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_lib.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.20 2015/10/13 15:25:18 jsing Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -1102,3 +1102,19 @@ EC_GROUP_have_precompute_mult(const EC_GROUP * group) return 0; /* cannot tell whether precomputation has * been performed */ } + +EC_KEY * +ECParameters_dup(EC_KEY *key) +{ + unsigned char *p = NULL; + EC_KEY *k = NULL; + int len; + + if (key == NULL) + return (NULL); + + if ((len = i2d_ECParameters(key, &p)) > 0) + k = d2i_ECParameters(NULL, (const unsigned char **)&p, len); + + return (k); +} diff --git a/lib/libssl/src/doc/crypto/ec.pod b/lib/libssl/src/doc/crypto/ec.pod index 7d57ba8ea07..891948e4f6e 100644 --- a/lib/libssl/src/doc/crypto/ec.pod +++ b/lib/libssl/src/doc/crypto/ec.pod @@ -158,7 +158,7 @@ ec - Elliptic Curve functions int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); int ECParameters_print_fp(FILE *fp, const EC_KEY *key); int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); - #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) + EC_KEY *ECParameters_dup(EC_KEY *key); #define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \ EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \ EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL) -- 2.20.1