wolfcrypt/src/curve25519.c: fix typo in wc_curve25519() -- CURVE25519_KEYSIZE, not CURVE25519_KEY_SIZE; add static kCurve25519BasePoint at top level

pull/3200/head
Daniel Pouzzner 2020-08-06 11:45:54 -05:00
parent 5cad0b10e5
commit 7ae789dbb0
1 changed files with 7 additions and 9 deletions

View File

@ -51,13 +51,16 @@ const curve25519_set_type curve25519_sets[] = {
} }
}; };
static const unsigned char kCurve25519BasePoint[CURVE25519_KEYSIZE] = {9};
/* compute the public key from an existing private key, using bare vectors. */ /* compute the public key from an existing private key, using bare vectors. */
int wc_curve25519(int public_size, byte* public, int private_size, const byte* private) { int wc_curve25519(int public_size, byte* public, int private_size, const byte* private) {
int ret; int ret;
if ((public_size != CURVE25519_KEYSIZE) || if ((public_size != CURVE25519_KEYSIZE) ||
(private_size != CURVE25519_KEYSIZE)) (private_size != CURVE25519_KEYSIZE)) {
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
}
if ((public == NULL) || (private == NULL)) if ((public == NULL) || (private == NULL))
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
@ -72,13 +75,10 @@ int wc_curve25519(int public_size, byte* public, int private_size, const byte* p
ECPoint wc_pub; ECPoint wc_pub;
ret = nxp_ltc_curve25519(&wc_pub, private, basepoint, kLTC_Weierstrass); /* input basepoint on Weierstrass curve */ ret = nxp_ltc_curve25519(&wc_pub, private, basepoint, kLTC_Weierstrass); /* input basepoint on Weierstrass curve */
if (ret == 0) if (ret == 0)
XMEMCPY(public, wc_pub.point, CURVE25519_KEY_SIZE); XMEMCPY(public, wc_pub.point, CURVE25519_KEYSIZE);
} }
#else #else
{ ret = curve25519(public, private, kCurve25519BasePoint);
static const unsigned char basepoint[CURVE25519_KEYSIZE] = {9};
ret = curve25519(public, private, basepoint);
}
#endif #endif
return ret; return ret;
@ -88,8 +88,6 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key)
{ {
#ifdef FREESCALE_LTC_ECC #ifdef FREESCALE_LTC_ECC
const ECPoint* basepoint = nxp_ltc_curve25519_GetBasePoint(); const ECPoint* basepoint = nxp_ltc_curve25519_GetBasePoint();
#else
static const unsigned char basepoint[CURVE25519_KEYSIZE] = {9};
#endif #endif
int ret; int ret;
@ -118,7 +116,7 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key)
#ifdef FREESCALE_LTC_ECC #ifdef FREESCALE_LTC_ECC
ret = nxp_ltc_curve25519(&key->p, key->k.point, basepoint, kLTC_Weierstrass); /* input basepoint on Weierstrass curve */ ret = nxp_ltc_curve25519(&key->p, key->k.point, basepoint, kLTC_Weierstrass); /* input basepoint on Weierstrass curve */
#else #else
ret = curve25519(key->p.point, key->k.point, basepoint); ret = curve25519(key->p.point, key->k.point, kCurve25519BasePoint);
#endif #endif
if (ret != 0) { if (ret != 0) {
ForceZero(key->k.point, keysize); ForceZero(key->k.point, keysize);