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).

This commit is contained in:
Daniel Pouzzner
2020-08-07 13:02:35 -05:00
parent f6acbd5f97
commit 0faff24a65

View File

@@ -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); XMEMCPY(public, wc_pub.point, CURVE25519_KEYSIZE);
} }
#else #else
fe_init();
ret = curve25519(public, private, kCurve25519BasePoint); ret = curve25519(public, private, kCurve25519BasePoint);
#endif #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) int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key)
{ {
#ifdef FREESCALE_LTC_ECC int ret;
const ECPoint* basepoint = nxp_ltc_curve25519_GetBasePoint();
#endif
int ret;
if (key == NULL || rng == NULL) if (key == NULL || rng == NULL)
return BAD_FUNC_ARG; 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) if (keysize != CURVE25519_KEYSIZE)
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
#ifndef FREESCALE_LTC_ECC
fe_init();
#endif
/* random number for private key */ /* random number for private key */
ret = wc_RNG_GenerateBlock(rng, key->k.point, keysize); ret = wc_RNG_GenerateBlock(rng, key->k.point, keysize);
if (ret != 0) 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] &= 63; /* same &=127 because |=64 after */
key->k.point[CURVE25519_KEYSIZE-1] |= 64; key->k.point[CURVE25519_KEYSIZE-1] |= 64;
/* compute public key */ return wc_curve25519_make_pub((int)sizeof key->p.point, key->p.point, sizeof key->k.point, key->k.point);
#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;
} }
#ifdef HAVE_CURVE25519_SHARED_SECRET #ifdef HAVE_CURVE25519_SHARED_SECRET