Skip to content

Commit 92ff77c

Browse files
committed
backport from tweetnacl-fast.js for potential bug. good news.
1 parent bb90821 commit 92ff77c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/com/iwebpp/crypto/TweetNaclFast.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,20 @@ public poly1305 finish(byte [] mac, int macpos) {
17421742
}
17431743
g[9] -= (1 << 13); g[9] &= 0xffff;
17441744

1745-
mask = (g[9] >>> ((2 * 8) - 1)) - 1; mask &= 0xffff;
1745+
/*
1746+
backport from tweetnacl-fast.js https://github.com/dchest/tweetnacl-js/releases/tag/v0.14.3
1747+
<<<
1748+
"The issue was not properly detecting if st->h was >= 2^130 - 5,
1749+
coupled with [testing mistake] not catching the failure.
1750+
The chance of the bug affecting anything in the real world is essentially zero luckily,
1751+
but it's good to have it fixed."
1752+
>>>
1753+
*/
1754+
///change mask = (g[9] >>> ((2 * 8) - 1)) - 1; to as
1755+
mask = (c ^ 1) - 1;
1756+
mask &= 0xffff;
1757+
///////////////////////////////////////
1758+
17461759
for (i = 0; i < 10; i++) g[i] &= mask;
17471760
mask = ~mask;
17481761
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];

0 commit comments

Comments
 (0)