Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden constant-time equality on arrays and slices #120

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

AaronFeickert
Copy link

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.

Comments welcome!

@AaronFeickert AaronFeickert changed the base branch from main to develop March 5, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant