crypto: better siphash addition.

This commit is contained in:
Christopher Jeffrey 2017-06-05 05:18:13 -07:00
parent f0b43764b1
commit 49976e7d6f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -153,14 +153,21 @@ function U64(hi, lo) {
U64.prototype.iadd = function iadd(b) {
var a = this;
var sum, c;
var hi, lo, as, bs, s, c;
// Credit to @indutny for this method.
sum = (a.lo >>> 0) + (b.lo >>> 0);
c = (sum >= 0x100000000) | 0;
lo = (a.lo + b.lo) | 0;
a.hi = (((a.hi + b.hi) | 0) + c) | 0;
a.lo = sum | 0;
s = lo >> 31;
as = a.lo >> 31;
bs = b.lo >> 31;
c = ((as & bs) | (~s & (as ^ bs))) & 1;
hi = ((a.hi + b.hi) | 0) + c;
a.hi = hi | 0;
a.lo = lo;
return a;
};