Skip to contentSkip to conversation

ecc: enforce strict length with l_ecc_point_from_data

PATCH In review James Prestwood 2 participants 3 messages Jan 21, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH v2 1/2 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
author
#1 lore raw

PATCH v2 2/2 tls-suites: use exact length on l_ecc_point_from_data

This was passing the remaining length in but prior this length was only checked if less than point_bytes. If it was greater the recent update to l_ecc_point_from_data will cause an error return.

Instead use point_bytes directly.

---
 ell/tls-suites.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ell/tls-suites.c +1 -1
index 055ee80..1c1ca07 100644
@@ -534,7 +534,7 @@ static void tls_handle_ecdhe_server_key_xchg(struct l_tls *tls,
 	params->curve = l_ecc_curve_from_tls_group(tls->negotiated_curve->id);
 	params->public = l_ecc_point_from_data(params->curve,
 						L_ECC_POINT_TYPE_FULL,
-						buf, len);
+						buf, point_bytes);
 	tls->pending.key_xchg_params = params;
 	buf += point_bytes;
 	len -= point_bytes;
Signature · 1 line
2.31.1
#2 lore raw
In reply to James Prestwood

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(-)

Both applied, thanks.

Regards,
-Denis