subtle icon indicating copy to clipboard operation
subtle copied to clipboard

Harden constant-time equality on arrays and slices

Open AaronFeickert opened this issue 1 year ago • 0 comments

The current implementation of ConstantTimeEquality for arrays and slices will short-circuit if the lengths are different. This PR does a constant-time length check before the componentwise check, and then uses a constant-time BitAnd for the final result.

This still strikes me as controversial, since both the existing implementation and this update leak something about length:

  • The existing implementation leaks if the slices/arrays have different lengths, as well as the length itself via timing.
  • The updated implementation leaks only the length via timing.

This seems like at worst no improvement, and at best a reasonable improvement.

AaronFeickert avatar Feb 12 '24 21:02 AaronFeickert