Skip to contentSkip to conversation

ecc: make l_ecc_point_from_data fully constant time

PATCH Applied James Prestwood 2 participants 2 messages Feb 4, 2022 – Feb 7, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH v3 1/1 ecc: make l_ecc_point_from_data fully constant time

This was modified earlier to be constant time but there was one minor problem with how 'sub' was determined. That logic could short circuit which could alter the timing. The change in timing would be extremely small, especially compared to the previous fix making _vli_mod_sub() execute always but in any case there would be a small difference.

This patch uses l_secure_select_byte to select either of the two subtraction conditions which depend on the point type.

---
 ell/ecc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
ell/ecc.c +2 -4
index eba9aef..ad7628a 100644
@@ -562,10 +562,8 @@ LIB_EXPORT struct l_ecc_point *l_ecc_point_from_data(
 		if (!_ecc_compute_y(curve, p->y, p->x))
 			goto failed;
 
-		sub = ((type == L_ECC_POINT_TYPE_COMPRESSED_BIT0 &&
-				!(p->y[0] & 1)) ||
-				(type == L_ECC_POINT_TYPE_COMPRESSED_BIT1 &&
-				(p->y[0] & 1)));
+		sub = secure_select(type == L_ECC_POINT_TYPE_COMPRESSED_BIT0,
+					!(p->y[1] & 1), p->y[0] & 1);
 
 		_vli_mod_sub(tmp, curve->p, p->y, curve->p, curve->ndigits);
 
Signature · 1 line
2.31.1
Applied
#1 lore raw

Hi James,

Quoted 7 lines · James Prestwood

This was modified earlier to be constant time but there was one minor problem with how 'sub' was determined. That logic could short circuit which could alter the timing. The change in timing would be extremely small, especially compared to the previous fix making _vli_mod_sub() execute always but in any case there would be a small difference.

Quoted 6 lines

This patch uses l_secure_select_byte to select either of the two subtraction conditions which depend on the point type.

---
  ell/ecc.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)

Applied, thanks.

Regards,
-Denis