From 2529ce21b05956e4ea57133d8b8f3b950860f758 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 30 Mar 2020 14:14:05 +0200 Subject: [PATCH] Implement wolfSSL_EC_GROUP_dup --- src/ssl.c | 7 +++++++ tests/api.c | 3 +++ wolfssl/openssl/ec.h | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/ssl.c b/src/ssl.c index 0c08a8aef..bfd5f86c3 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -32453,6 +32453,13 @@ int wolfSSL_EC_GROUP_cmp(const WOLFSSL_EC_GROUP *a, const WOLFSSL_EC_GROUP *b, return 1; } +WOLFSSL_EC_GROUP *wolfSSL_EC_GROUP_dup(const WOLFSSL_EC_GROUP *src) +{ + if (!src) + return NULL; + return wolfSSL_EC_GROUP_new_by_curve_name(src->curve_nid); +} + #endif /* HAVE_ECC */ #endif /* OPENSSL_EXTRA */ diff --git a/tests/api.c b/tests/api.c index 3139e3c7c..e823d30d6 100644 --- a/tests/api.c +++ b/tests/api.c @@ -1884,6 +1884,7 @@ static void test_wolfSSL_EC(void) #if defined(HAVE_ECC) BN_CTX *ctx; EC_GROUP *group; + EC_GROUP *group2; EC_POINT *Gxy, *new_point, *set_point; BIGNUM *k = NULL, *Gx = NULL, *Gy = NULL, *Gz = NULL; BIGNUM *X, *Y; @@ -1923,6 +1924,7 @@ static void test_wolfSSL_EC(void) AssertNotNull(ctx = BN_CTX_new()); AssertNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1)); + AssertNotNull(group2 = EC_GROUP_dup(group)); AssertIntEQ((group_bits = EC_GROUP_order_bits(group)), 256); AssertNotNull(Gxy = EC_POINT_new(group)); AssertNotNull(new_point = EC_POINT_new(group)); @@ -2074,6 +2076,7 @@ static void test_wolfSSL_EC(void) EC_POINT_free(set_point); EC_POINT_free(Gxy); EC_GROUP_free(group); + EC_GROUP_free(group2); BN_CTX_free(ctx); #endif /* HAVE_ECC */ } diff --git a/wolfssl/openssl/ec.h b/wolfssl/openssl/ec.h index 283151d58..4f5c0841c 100644 --- a/wolfssl/openssl/ec.h +++ b/wolfssl/openssl/ec.h @@ -204,6 +204,8 @@ WOLFSSL_API int wolfSSL_EC_GROUP_cmp(const WOLFSSL_EC_GROUP *a, const WOLFSSL_EC_GROUP *b, WOLFSSL_BN_CTX *ctx); WOLFSSL_API +WOLFSSL_EC_GROUP *wolfSSL_EC_GROUP_dup(const WOLFSSL_EC_GROUP *src); +WOLFSSL_API int wolfSSL_EC_GROUP_get_curve_name(const WOLFSSL_EC_GROUP *group); WOLFSSL_API int wolfSSL_EC_GROUP_get_degree(const WOLFSSL_EC_GROUP *group); @@ -283,6 +285,7 @@ char* wolfSSL_EC_POINT_point2hex(const WOLFSSL_EC_GROUP* group, #define EC_GROUP_set_asn1_flag wolfSSL_EC_GROUP_set_asn1_flag #define EC_GROUP_new_by_curve_name wolfSSL_EC_GROUP_new_by_curve_name #define EC_GROUP_cmp wolfSSL_EC_GROUP_cmp +#define EC_GROUP_dup wolfSSL_EC_GROUP_dup #define EC_GROUP_get_curve_name wolfSSL_EC_GROUP_get_curve_name #define EC_GROUP_get_degree wolfSSL_EC_GROUP_get_degree #define EC_GROUP_get_order wolfSSL_EC_GROUP_get_order