Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if(i < 8) {
d = Long.fromNumber(d ^ r).getLowBitsUnsigned();
} else {
b = Long.fromNumber(b ^ r).getLowBitsUnsigned();
}
a = b, b = c, c = d, d = t;
}
for(var i = 0; i < 8; i++) {
a = Long.fromNumber(a).subtract(Long.fromNumber((i%4 == 2) ? d : 0)).getLowBitsUnsigned();
a = Long.fromNumber(a).subtract(Long.fromNumber((i%4 == 3) ? b : 0)).getLowBitsUnsigned();
b = Long.fromNumber(b ^ S1(a)).getLowBitsUnsigned();
c = Long.fromNumber(c).subtract(Long.fromNumber(S0(a >>> 24))).getLowBitsUnsigned();
t = Long.fromNumber(util.rotl(a, 24)).getLowBitsUnsigned();
d = Long.fromNumber(Long.fromNumber(d).subtract(Long.fromNumber(S1(a >>> 16))).getLowBitsUnsigned() ^ S0(t)).getLowBitsUnsigned()
a = b, b = c, c = d, d =t;
}
d = Long.fromNumber(d - self.key[0]).getLowBitsUnsigned();
c = Long.fromNumber(c - self.key[1]).getLowBitsUnsigned();
b = Long.fromNumber(b - self.key[2]).getLowBitsUnsigned();
a = Long.fromNumber(a - self.key[3]).getLowBitsUnsigned();
// Return the encrypted bytes
util.inPlaceEncodeUInt32R(d, out, outOff);
util.inPlaceEncodeUInt32R(c, out, outOff + 4);
util.inPlaceEncodeUInt32R(b, out, outOff + 8);
util.inPlaceEncodeUInt32R(a, out, outOff + 12);
return BlockSize;
}
var decryptBlock = function(self, block, index, out, outOff) {
// Decode the integers
var d = Long.fromNumber(util.decodeUInt32R(block, index)).getLowBitsUnsigned();
var c = Long.fromNumber(util.decodeUInt32R(block, index + 4)).getLowBitsUnsigned();
var b = Long.fromNumber(util.decodeUInt32R(block, index + 8)).getLowBitsUnsigned();
var a = Long.fromNumber(util.decodeUInt32R(block, index + 12)).getLowBitsUnsigned();
var l = 0, m = 0, r = 0, t = 0;
d = Long.fromNumber(d + self.key[36]).getLowBitsUnsigned();
c = Long.fromNumber(c + self.key[37]).getLowBitsUnsigned();
b = Long.fromNumber(b + self.key[38]).getLowBitsUnsigned();
a = Long.fromNumber(a + self.key[39]).getLowBitsUnsigned();
for(var i = 0; i < 8; i++) {
b = Long.fromNumber(b ^ S0(a)).add(Long.fromNumber(S1(a >>> 8))).getLowBitsUnsigned()
c = Long.fromNumber(c + S0(a >>> 16)).getLowBitsUnsigned();
a = Long.fromNumber(util.rotr(a, 24)).getLowBitsUnsigned();
d = Long.fromNumber(d ^ S1(a)).getLowBitsUnsigned();
a = Long.fromNumber(a + ((i%4 == 0) ? d : 0)).getLowBitsUnsigned();
a = Long.fromNumber(a + ((i%4 == 1) ? b : 0)).getLowBitsUnsigned();
t = a, a = b, b = c, c = d, d = t;
}
for(var i = 0; i < 16; i++) {
t = Long.fromNumber(util.rotr(a, 13)).getLowBitsUnsigned();
var rInt = Long.fromNumber(a).multiply(Long.fromNumber(self.key[35-2*i])).getLowBitsUnsigned();
r = Long.fromNumber(util.rotl(rInt, 10)).getLowBitsUnsigned();
m = Long.fromNumber(t + self.key[34-2*i]).getLowBitsUnsigned();
var lInt1 = Long.fromNumber(S(m) ^ Long.fromNumber(util.rotr(r, 5)).getLowBitsUnsigned() ^ r).getLowBitsUnsigned();
l = Long.fromNumber(util.rotl(lInt1, r)).getLowBitsUnsigned();
var decRound = function(n, values, index) {
var x = g1(values[2], values[1][0]); // unpack a
var y = g2(values[2], values[1][1]); // unpack b
x = Long.fromNumber(x + y).getLowBitsUnsigned();
y = Long.fromNumber(y + x).getLowBitsUnsigned();
values[1][3] = Long.fromNumber(values[1][3] ^ (y + values[0][2 * (n) + 1 + index])).getLowBitsUnsigned();
values[1][3] = Long.fromNumber(util.rotr(values[1][3], 1)).getLowBitsUnsigned();
values[1][2] = Long.fromNumber(util.rotl(values[1][2], 1)).getLowBitsUnsigned();
values[1][2] = Long.fromNumber(values[1][2] ^ (x + values[0][2 * (n) + index])).getLowBitsUnsigned();
return values;
}
var index = 0;
var kInc = 2;
if(decrypt) {
index = index + 30;
kInc = 0 - kInc;
}
// Mix up the key
for(var i = 0; i < ROUNDS; i++) {
var t0 = Long.fromNumber(key01.shiftRightUnsigned(32).getLowBitsUnsigned()
+ key23.shiftRightUnsigned(32).getLowBitsUnsigned()
- s_kc[i]).getLowBitsUnsigned();
var t0 = key01.shiftRightUnsigned(32).add(key23.shiftRightUnsigned(32))
.subtract(Long.fromNumber(s_kc[i])).getLowBitsUnsigned();
var t1 = Long.fromNumber(key01.getLowBitsUnsigned() - key23.getLowBitsUnsigned() + s_kc[i]).getLowBitsUnsigned();
var k0 = G(t0);
var k1 = G(t1);
k[index + 0] = G(t0);
k[index + 1] = G(t1);
index = index + kInc;
if(i & 1) {
key23 = int64lrot(key23, 8);
} else {
key01 = int64rrot(key01, 8);
}
}
var A = regs[0];
var B = regs[1];
A = Long.fromNumber(A).add(S[0]).getLowBitsUnsigned();
B = Long.fromNumber(B).add(S[1]).getLowBitsUnsigned();
for(var i = 1; i <= (S.length - 2); i++) {
var br = Long.fromNumber(B - S[S.length - i]).getLowBitsUnsigned();
B = Long.fromNumber(A ^ util.rotr(br, A)).getLowBitsUnsigned();
A = Long.fromNumber(A^B).getLowBitsUnsigned();
B = Long.fromNumber(B^A).getLowBitsUnsigned();
A = Long.fromNumber(A^B).getLowBitsUnsigned();
}
A = Long.fromNumber((A - S[0] + MOD) % MOD).getLowBitsUnsigned();
B = Long.fromNumber((B - S[1] + MOD) % MOD).getLowBitsUnsigned();
// Save the encoded bytes
util.inPlaceEncodeUInt32R(A, out, outOff + 0);
util.inPlaceEncodeUInt32R(B, out, outOff + 4);
return BlockSize;
}
for(var i = 0; i < 4; i ++) {
regs[i] = Long.fromNumber(util.decodeUInt32R(input, index + (i * 4))).getLowBitsUnsigned();
}
var A = regs[0];
var B = regs[1];
var C = regs[2];
var D = regs[3];
B = Long.fromNumber(B + S[0]).getLowBitsUnsigned();
D = Long.fromNumber(D + S[1]).getLowBitsUnsigned();
for(var j = 1; j <= 20; j++) {
// Calculate t
var br = Long.fromNumber(B).multiply(Long.fromNumber(((B << 1) + 1)));
var t = Long.fromNumber(rotl(br.getLowBitsUnsigned(), 5)).getLowBitsUnsigned();
// Calculate u
var br = Long.fromNumber(D).multiply(Long.fromNumber(((D << 1) + 1)));
var u = Long.fromNumber(rotl(br.getLowBitsUnsigned(), 5)).getLowBitsUnsigned();
// Calculate A
A = Long.fromNumber(rotl(Long.fromNumber(A ^ t).getLowBitsUnsigned(), u))
.add(Long.fromNumber(S[j << 1])).getLowBitsUnsigned();
// Calculate C
C = Long.fromNumber(rotl(Long.fromNumber(C ^ u), t))
.add(Long.fromNumber(S[(j << 1) + 1])).getLowBitsUnsigned();
var temp = A;
A = B;
B = C;
C = D;
var w = function(bitblock256, i, tr, tm) {
bitblock256[6] = Long.fromNumber(bitblock256[6]).xor(Long.fromNumber(f1(bitblock256[7], tr[i][0], tm[i][0]))).toNumber();
bitblock256[5] = Long.fromNumber(bitblock256[5]).xor(Long.fromNumber(f2(bitblock256[6], tr[i][1], tm[i][1]))).toNumber();
bitblock256[4] = Long.fromNumber(bitblock256[4]).xor(Long.fromNumber(f3(bitblock256[5], tr[i][2], tm[i][2]))).toNumber();
bitblock256[3] = Long.fromNumber(bitblock256[3]).xor(Long.fromNumber(f1(bitblock256[4], tr[i][3], tm[i][3]))).toNumber();
bitblock256[2] = Long.fromNumber(bitblock256[2]).xor(Long.fromNumber(f2(bitblock256[3], tr[i][4], tm[i][4]))).toNumber();
bitblock256[1] = Long.fromNumber(bitblock256[1]).xor(Long.fromNumber(f3(bitblock256[2], tr[i][5], tm[i][5]))).toNumber();
bitblock256[0] = Long.fromNumber(bitblock256[0]).xor(Long.fromNumber(f1(bitblock256[1], tr[i][6], tm[i][6]))).toNumber();
bitblock256[7] = Long.fromNumber(bitblock256[7]).xor(Long.fromNumber(f2(bitblock256[0], tr[i][7], tm[i][7]))).toNumber();
}
var update = function(instance, b) {
instance.xBuf[instance.xBufOff++] = b;
if(instance.xBufOff === instance.xBuf.length) {
instance.processWord(instance.xBuf, 0);
instance.xBufOff = 0;
}
instance.byteCount1 = instance.byteCount1.add(Long.fromNumber(1));
}
var step = function(variables, outputs, x0index, x1index, x2index, x3index, x4index, x5index, x6index, x7index, x8index, x9index, vindex, uindex) {
outputs[uindex] = Long.fromNumber(Long.fromNumber(variables[x9index]).add(Long.fromNumber(r2(x0index, variables[10], variables[11]))).getLowBitsUnsigned() ^ r1(x0index, variables[10], variables[11])).getLowBitsUnsigned();
outputs[vindex] = variables[x0index];
variables[x0index] = Long.fromNumber(mula(variables[x0index]) ^ diva(variables[x3index]) ^ variables[x9index]).getLowBitsUnsigned();
if(x0index % 2) {
variables[11] = Long.fromNumber(variables[11]).add(Long.fromNumber(xmux(r2(x0index, variables[10], variables[11]), variables[x2index], variables[x9index]))).getLowBitsUnsigned();
} else {
variables[10] = Long.fromNumber(variables[10]).add(Long.fromNumber(xmux(r2(x0index, variables[10], variables[11]), variables[x2index], variables[x9index]))).getLowBitsUnsigned();
}
if(x0index % 2) {
variables[10] = Long.fromNumber(util.rotl(Long.fromNumber(r2(x0index, variables[10], variables[11])).multiply(Long.fromNumber(0x54655307)).getLowBitsUnsigned(), 7)).getLowBitsUnsigned();
} else {
variables[11] = Long.fromNumber(util.rotl(Long.fromNumber(r2(x0index, variables[10], variables[11])).multiply(Long.fromNumber(0x54655307)).getLowBitsUnsigned(), 7)).getLowBitsUnsigned();
}
}