add wc_curve25519_generic().

This commit is contained in:
Daniel Pouzzner
2020-09-18 16:17:27 -05:00
parent 4742a17006
commit 0f3283ce7b
2 changed files with 53 additions and 0 deletions

View File

@ -100,6 +100,54 @@ int wc_curve25519_make_pub(int public_size, byte* pub, int private_size,
return ret;
}
/* compute the public key from an existing private key, with supplied basepoint, using bare vectors.
*
* return value is propagated from curve25519() (0 on success),
* and the byte vectors are little endian.
*/
int wc_curve25519_generic(int public_size, byte* pub,
int private_size, const byte* priv,
int basepoint_size, const byte* basepoint) {
int ret;
if ((public_size != CURVE25519_KEYSIZE) ||
(private_size != CURVE25519_KEYSIZE) ||
(basepoint_size != CURVE25519_KEYSIZE)) {
return ECC_BAD_ARG_E;
}
if ((pub == NULL) || (priv == NULL) || (basepoint == NULL))
return ECC_BAD_ARG_E;
/* check clamping */
if ((priv[0] & ~248) ||
(priv[CURVE25519_KEYSIZE-1] & 128)) {
return ECC_BAD_ARG_E;
}
#ifdef FREESCALE_LTC_ECC
{
ECPoint wc_pub;
ret = nxp_ltc_curve25519(&wc_pub, priv, basepoint, basepoint);
if (ret == 0)
XMEMCPY(pub, wc_pub.point, CURVE25519_KEYSIZE);
}
#else
fe_init();
#if defined(USE_INTEL_SPEEDUP) || defined(WOLFSSL_ARMASM)
SAVE_VECTOR_REGISTERS();
#endif
ret = curve25519(pub, priv, basepoint);
#if defined(USE_INTEL_SPEEDUP) || defined(WOLFSSL_ARMASM)
RESTORE_VECTOR_REGISTERS();
#endif
#endif
return ret;
}
/* generate a new private key, as a bare vector.
*
* return value is propagated from wc_RNG_GenerateBlock(() (0 on success),

View File

@ -90,6 +90,11 @@ WOLFSSL_API
int wc_curve25519_make_pub(int public_size, byte* pub, int private_size,
const byte* priv);
WOLFSSL_API
int wc_curve25519_generic(int public_size, byte* pub,
int private_size, const byte* priv,
int basepoint_size, const byte* basepoint);
WOLFSSL_API
int wc_curve25519_make_priv(WC_RNG* rng, int keysize, byte* priv);