Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Updated constantTimeIsEqual to use binary addition to address a possible issue of summing up negative and positive sub-results of XOR operations to 0. #21

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

Conversation

bitnot
Copy link

@bitnot bitnot commented Jul 9, 2018

Related to #1

I think the current implementation of constantTimeIsEqual might have an issue:

The r + (ab._1 ^ ab._2) part is not exactly the same as result |= a[i] ^ b[i] from the article, as it uses addition of signed bytes as opposed to binary addition (OR), where sign does not matter.
So it is possible to get say a 1 and a -1 via XORing and then add them up to a 0. Array(-3,-2,4,1).sum is also 0, but Array(-3,-2,4,1).foldLeft(0){ (r,n) => r | n } is not. Hope this illustrates the point.


PS. Just noticed deprecation warning. Keeping PR open for anyone who wants to use/fork the library.

...to address a possible issue of summing up negative and positive sub-results of XOR operations to `0`.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant