Skip to content

Commit a3a43ab

Browse files
committed
Proper constant-time Utils.equal()
1 parent de84365 commit a3a43ab

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/net/i2p/crypto/eddsa/Utils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ public class Utils {
1010
* @return 1 if b and c are equal, 0 otherwise.
1111
*/
1212
public static int equal(int b, int c) {
13-
return b == c ? 1 : 0;
13+
int result = 0;
14+
int xor = b ^ c;
15+
for (int i = 0; i < 8; i++) {
16+
result |= xor >> i;
17+
}
18+
return (result ^ 0x01) & 0x01;
1419
}
1520

1621
/**

0 commit comments

Comments
 (0)