Skip to contentSkip to conversation

ecc: enforce strict length with l_ecc_point_from_data

PATCH Superseded James Prestwood 2 participants 3 messages Jan 21, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/1 ecc: enforce strict length with l_ecc_point_from_data

This add some extra convenience to users of l_ecc_point_from_data allowing the exact length to be verified in addition to creating the point.

---
 ell/ecc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
ell/ecc.c +5 -5
index a16b1c0..f1adcc4 100644
@@ -538,8 +538,11 @@ LIB_EXPORT struct l_ecc_point *l_ecc_point_from_data(
 	if (!data)
 		return NULL;
 
-	/* In all cases there should be an X coordinate in data */
-	if (len < bytes)
+	/* Verify the data length matches a full point or X coordinate */
+	if (type == L_ECC_POINT_TYPE_FULL) {
+		if (len != bytes * 2)
+			return NULL;
+	} else if (len != bytes)
 		return NULL;
 
 	p = l_ecc_point_new(curve);
@@ -570,9 +573,6 @@ LIB_EXPORT struct l_ecc_point *l_ecc_point_from_data(
 
 		break;
 	case L_ECC_POINT_TYPE_FULL:
-		if (len < bytes * 2)
-			goto failed;
-
 		_ecc_be2native(p->y, (void *) data + bytes, curve->ndigits);
 
 		if (!ecc_valid_point(p))
Signature · 1 line
2.31.1
#1 lore raw

Hi James,

Quoted 7 lines · James Prestwood

This add some extra convenience to users of l_ecc_point_from_data allowing the exact length to be verified in addition to creating the point.

---
  ell/ecc.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

This seems to break test-sae?

Regards,
-Denis

author
#2 lore raw
Quoted 11 lines · Denis Kenzior

Hi James,

Quoted 7 lines · James Prestwood

This add some extra convenience to users of l_ecc_point_from_data allowing the exact length to be verified in addition to creating the point.
---
  ell/ecc.c | 10 +++++-----

  1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 1 line

This seems to break test-sae?

Yes patch coming. Every other use passed the exact bytes except SAE.

Quoted 4 lines

Regards,
-Denis