[PATCH 1/2] ecc: add l_ecc_scalar_clone

James Prestwood <[email protected]> Wed, 13 Mar 2024 09:44:24 -0700
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
---
 ell/ecc.c   | 8 ++++++++
 ell/ecc.h   | 1 +
 ell/ell.sym | 1 +
 3 files changed, 10 insertions(+)

diff --git a/ell/ecc.c b/ell/ecc.c
index 8302347..d8d9c1f 100644
--- a/ell/ecc.c
+++ b/ell/ecc.c
@@ -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
diff --git a/ell/ecc.h b/ell/ecc.h
index 5a8cf03..3502b98 100644
--- a/ell/ecc.h
+++ b/ell/ecc.h
@@ -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,
diff --git a/ell/ell.sym b/ell/ell.sym
index 2c207d6..28b55d3 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -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;
-- 
2.34.1