ecc: add l_ecc_scalar_clone
PATCH 1/2 ecc: add l_ecc_scalar_clone
--- ell/ecc.c | 8 ++++++++ ell/ecc.h | 1 + ell/ell.sym | 1 + 3 files changed, 10 insertions(+)
ell/ecc.c +8 -0
@@ -806,6 +806,14 @@ LIB_EXPORT struct l_ecc_scalar *l_ecc_scalar_new(return NULL ; } +LIB_EXPORT struct l_ecc_scalar *l_ecc_scalar_clone(const struct l_ecc_scalar *s) +{ +if (!s) +return NULL ; + +return l_memdup (s,sizeof (*s)); +} +/* * Build a scalar = value modulo p where p is the prime number for a given * curve. bytes can contain a number with up to 2x number of digits as the
ell/ecc.h +1 -0
@@ -62,6 +62,7 @@ DEFINE_CLEANUP_FUNC(l_ecc_point_free);struct l_ecc_scalar *l_ecc_scalar_new (const struct l_ecc_curve *curve,const void *buf,size_t len); +struct l_ecc_scalar *l_ecc_scalar_clone (const struct l_ecc_scalar *s);struct l_ecc_scalar *l_ecc_scalar_new_random (const struct l_ecc_curve *curve); struct l_ecc_scalar *l_ecc_scalar_new_modp(const struct l_ecc_curve *curve,
ell/ell.sym +1 -0
@@ -611,6 +611,7 @@ global: l_ecc_scalar_legendre; l_ecc_scalar_multiply; l_ecc_scalar_new; + l_ecc_scalar_clone; l_ecc_scalar_new_random; l_ecc_scalar_new_modp; l_ecc_scalar_new_modn;
Signature · 1 line
2.34.1
PATCH 2/2 ecdh: add unlikely() check for NULL parameters
--- ell/ecdh.c | 7 +++++++ 1 file changed, 7 insertions(+)
ell/ecdh.c +7 -0
@@ -16,6 +16,7 @@#include "ecc.h" #include "ecdh.h" #include "random.h" +#include "useful.h" /* * Some sane maximum for calculating the public key.
@@ -41,6 +42,9 @@ LIB_EXPORT bool l_ecdh_generate_key_pair(const struct l_ecc_curve *curve,int iter =0 ;uint64_t p2[L_ECC_MAX_DIGITS ]; +if (unlikely (!curve || !out_private || !out_public)) +return false; +_ecc_calculate_p2 (curve, p2); *out_public =l_ecc_point_new (curve);
@@ -77,6 +81,9 @@ LIB_EXPORT bool l_ecdh_generate_shared_secret(struct l_ecc_scalar *z;struct l_ecc_point *product; +if (unlikely (!private_key || !other_public || !secret)) +return false; + z =l_ecc_scalar_new_random (curve); product =l_ecc_point_new (curve);
Signature · 1 line
2.34.1
Hi James,
Quoted 5 lines · James Prestwood
--- ell/ecc.c | 8 ++++++++ ell/ecc.h | 1 + ell/ell.sym | 1 + 3 files changed, 10 insertions(+)
All applied, thanks.
Regards,
-Denis