From 0faff24a65d000c648da0eaf8062c90c35492e5c Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Fri, 7 Aug 2020 13:02:35 -0500 Subject: [PATCH] refactor wc_curve25519_make_key() to use wc_curve25519_make_pub() to complete the pair. also, add call to fe_init() in the non-NXP codepath of wc_curve25519_make_pub() (note fe_init() is currently a no-op). --- wolfcrypt/src/curve25519.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/wolfcrypt/src/curve25519.c b/wolfcrypt/src/curve25519.c index ffad7f9c1..bc8ee90af 100644 --- a/wolfcrypt/src/curve25519.c +++ b/wolfcrypt/src/curve25519.c @@ -83,6 +83,7 @@ int wc_curve25519_make_pub(int public_size, byte* public, int private_size, cons XMEMCPY(public, wc_pub.point, CURVE25519_KEYSIZE); } #else + fe_init(); ret = curve25519(public, private, kCurve25519BasePoint); #endif @@ -91,10 +92,7 @@ int wc_curve25519_make_pub(int public_size, byte* public, int private_size, cons int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key) { -#ifdef FREESCALE_LTC_ECC - const ECPoint* basepoint = nxp_ltc_curve25519_GetBasePoint(); -#endif - int ret; + int ret; if (key == NULL || rng == NULL) return BAD_FUNC_ARG; @@ -103,10 +101,6 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key) if (keysize != CURVE25519_KEYSIZE) return ECC_BAD_ARG_E; -#ifndef FREESCALE_LTC_ECC - fe_init(); -#endif - /* random number for private key */ ret = wc_RNG_GenerateBlock(rng, key->k.point, keysize); if (ret != 0) @@ -117,19 +111,7 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key) key->k.point[CURVE25519_KEYSIZE-1] &= 63; /* same &=127 because |=64 after */ key->k.point[CURVE25519_KEYSIZE-1] |= 64; - /* compute public key */ - #ifdef FREESCALE_LTC_ECC - ret = nxp_ltc_curve25519(&key->p, key->k.point, basepoint, kLTC_Weierstrass); /* input basepoint on Weierstrass curve */ - #else - ret = curve25519(key->p.point, key->k.point, kCurve25519BasePoint); - #endif - if (ret != 0) { - ForceZero(key->k.point, keysize); - ForceZero(key->p.point, keysize); - return ret; - } - - return ret; + return wc_curve25519_make_pub((int)sizeof key->p.point, key->p.point, sizeof key->k.point, key->k.point); } #ifdef HAVE_CURVE25519_SHARED_SECRET