From bd4a9c69ddcb6cc7a29acf7b31d4a232ab314022 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 17 Jan 2020 11:56:46 -0700 Subject: [PATCH] convert name to oidsum to curve type for setting supported curves --- src/internal.c | 22 +++++++++++++--------- src/ssl.c | 15 +++++++++++++-- wolfssl/internal.h | 1 + 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/internal.c b/src/internal.c index b31524025..02e61f4ec 100644 --- a/src/internal.c +++ b/src/internal.c @@ -23272,15 +23272,9 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, #if defined(HAVE_ECC) - - static byte SetCurveId(ecc_key* key) - { - if (key == NULL || key->dp == NULL) { - WOLFSSL_MSG("SetCurveId: Invalid key!"); - return 0; - } - - switch(key->dp->oidSum) { + /* returns the WOLFSSL_* version of the curve from the OID sum */ + unsigned char GetCurveByOID(int oidSum) { + switch(oidSum) { #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES) #ifndef NO_ECC_SECP case ECC_SECP160R1_OID: @@ -23356,6 +23350,16 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, } } + static byte SetCurveId(ecc_key* key) + { + if (key == NULL || key->dp == NULL) { + WOLFSSL_MSG("SetCurveId: Invalid key!"); + return 0; + } + + return (byte)GetCurveByOID(key->dp->oidSum); + } + #endif /* HAVE_ECC || HAVE_CURVE25519 */ typedef struct SskeArgs { diff --git a/src/ssl.c b/src/ssl.c index 74efe13ea..5b16fdb84 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -44409,11 +44409,22 @@ int wolfSSL_CTX_set1_curves_list(WOLFSSL_CTX* ctx, const char* names) curve = WOLFSSL_ECC_X25519; } else { - int ret = wc_ecc_get_curve_id_from_name(name); + int ret; + const ecc_set_type *eccSet; + + ret = wc_ecc_get_curve_idx_from_name(name); if (ret < 0) { + WOLFSSL_MSG("Could not find name in set"); return WOLFSSL_FAILURE; } - curve = (word16)ret; + + eccSet = wc_ecc_get_curve_params(ret); + if (eccSet == NULL) { + WOLFSSL_MSG("NULL set returned"); + return WOLFSSL_FAILURE; + } + + curve = GetCurveByOID(eccSet->oidSum); } if (curve > (sizeof(word32) * WOLFSSL_BIT_SIZE)) { diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 2b00a3749..d50fa52ba 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -4465,6 +4465,7 @@ WOLFSSL_LOCAL int SetKeysSide(WOLFSSL*, enum encrypt_side); #ifdef HAVE_ECC WOLFSSL_LOCAL int EccMakeKey(WOLFSSL* ssl, ecc_key* key, ecc_key* peer); + WOLFSSL_LOCAL unsigned char GetCurveByOID(int oidSum); #endif WOLFSSL_LOCAL int InitHandshakeHashes(WOLFSSL* ssl);