Skip to contentSkip to conversation

ecc: Add helper for multiplying a scalar with a curve generator

PATCH Applied Marcel Holtmann 2 participants 2 messages Nov 6, 2023 – Nov 8, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ecc: Add helper for multiplying a scalar with a curve generator

The SPAKE2+ key exchange protocol requires the ability to multiply a random number with the curve generator. Instead of exposing the curve generator expose a helper function that provides the multiplication.

---
 ell/ecc.c   | 12 ++++++++++++
 ell/ecc.h   |  2 ++
 ell/ell.sym |  1 +
 3 files changed, 15 insertions(+)
ell/ecc.c +12 -0
index 59bff7bd5af1..ff147b84ed74 100644
@@ -940,6 +940,18 @@ LIB_EXPORT bool l_ecc_point_multiply(struct l_ecc_point *ret,
 	return true;
 }
 
+LIB_EXPORT bool l_ecc_point_multiply_g(struct l_ecc_point *ret,
+					const struct l_ecc_scalar *scalar)
+{
+	if (unlikely(!ret || !scalar))
+		return false;
+
+	_ecc_point_mult(ret, &scalar->curve->g, scalar->c, NULL,
+						scalar->curve->p);
+
+	return true;
+}
+
 LIB_EXPORT bool l_ecc_point_add(struct l_ecc_point *ret,
 					const struct l_ecc_point *a,
 					const struct l_ecc_point *b)
ell/ecc.h +2 -0
index 2f6faa4e79cd..de116f018b44 100644
@@ -83,6 +83,8 @@ bool l_ecc_scalar_add(struct l_ecc_scalar *ret, const struct l_ecc_scalar *a,
 bool l_ecc_point_multiply(struct l_ecc_point *ret,
 				const struct l_ecc_scalar *scalar,
 				const struct l_ecc_point *point);
+bool l_ecc_point_multiply_g(struct l_ecc_point *ret,
+				const struct l_ecc_scalar *scalar);
 bool l_ecc_point_add(struct l_ecc_point *ret, const struct l_ecc_point *a,
 				const struct l_ecc_point *b);
 bool l_ecc_point_inverse(struct l_ecc_point *p);
ell/ell.sym +1 -0
index c457a7620376..0f593e1fc402 100644
@@ -593,6 +593,7 @@ global:
 	l_ecc_point_get_data;
 	l_ecc_point_inverse;
 	l_ecc_point_multiply;
+	l_ecc_point_multiply_g;
 	l_ecc_point_new;
 	l_ecc_point_from_sswu;
 	l_ecc_point_clone;
Signature · 1 line
2.41.0
#1 lore raw

Hi Marcel,

Quoted 9 lines · Marcel Holtmann

The SPAKE2+ key exchange protocol requires the ability to multiply a random number with the curve generator. Instead of exposing the curve generator expose a helper function that provides the multiplication.

---
  ell/ecc.c   | 12 ++++++++++++
  ell/ecc.h   |  2 ++
  ell/ell.sym |  1 +
  3 files changed, 15 insertions(+)

Applied, thanks.

Regards,
-Denis