Socket
Socket
Sign inDemoInstall

sha.js

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sha.js - npm Package Compare versions

Comparing version 2.4.4 to 2.4.5

4

package.json
{
"name": "sha.js",
"description": "streaming sha1 hash in pure javascript",
"version": "2.4.4",
"description": "Streamable SHA hashes in pure javascript",
"version": "2.4.5",
"homepage": "https://github.com/crypto-browserify/sha.js",

@@ -6,0 +6,0 @@ "repository": {

@@ -12,2 +12,6 @@ /*

var K = [
0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
]
var W = new Array(80)

@@ -25,7 +29,7 @@

Sha.prototype.init = function () {
this._a = 0x67452301 | 0
this._b = 0xefcdab89 | 0
this._c = 0x98badcfe | 0
this._d = 0x10325476 | 0
this._e = 0xc3d2e1f0 | 0
this._a = 0x67452301
this._b = 0xefcdab89
this._c = 0x98badcfe
this._d = 0x10325476
this._e = 0xc3d2e1f0

@@ -35,49 +39,39 @@ return this

/*
* Bitwise rotate a 32-bit number to the left.
*/
function rol (num, cnt) {
return (num << cnt) | (num >>> (32 - cnt))
function rotl5 (num) {
return (num << 5) | (num >>> 27)
}
function rotl30 (num) {
return (num << 30) | (num >>> 2)
}
function ft (s, b, c, d) {
if (s === 0) return (b & c) | ((~b) & d)
if (s === 2) return (b & c) | (b & d) | (c & d)
return b ^ c ^ d
}
Sha.prototype._update = function (M) {
var W = this._w
var a = this._a
var b = this._b
var c = this._c
var d = this._d
var e = this._e
var a = this._a | 0
var b = this._b | 0
var c = this._c | 0
var d = this._d | 0
var e = this._e | 0
var j = 0
var k
for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
/*
* SHA-1 has a bitwise rotate left operation. But, SHA is not
* function calcW() { return rol(W[j - 3] ^ W[j - 8] ^ W[j - 14] ^ W[j - 16], 1) }
*/
function calcW () { return W[j - 3] ^ W[j - 8] ^ W[j - 14] ^ W[j - 16] }
function loop (w, f) {
W[j] = w
for (var j = 0; j < 80; ++j) {
var s = ~~(j / 20)
var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
var t = rol(a, 5) + f + e + w + k
e = d
d = c
c = rol(b, 30)
c = rotl30(b)
b = a
a = t
j++
}
k = 1518500249
while (j < 16) loop(M.readInt32BE(j * 4), (b & c) | ((~b) & d))
while (j < 20) loop(calcW(), (b & c) | ((~b) & d))
k = 1859775393
while (j < 40) loop(calcW(), b ^ c ^ d)
k = -1894007588
while (j < 60) loop(calcW(), (b & c) | (b & d) | (c & d))
k = -899497514
while (j < 80) loop(calcW(), b ^ c ^ d)
this._a = (a + this._a) | 0

@@ -103,2 +97,1 @@ this._b = (b + this._b) | 0

module.exports = Sha

@@ -13,2 +13,6 @@ /*

var K = [
0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
]
var W = new Array(80)

@@ -26,7 +30,7 @@

Sha1.prototype.init = function () {
this._a = 0x67452301 | 0
this._b = 0xefcdab89 | 0
this._c = 0x98badcfe | 0
this._d = 0x10325476 | 0
this._e = 0xc3d2e1f0 | 0
this._a = 0x67452301
this._b = 0xefcdab89
this._c = 0x98badcfe
this._d = 0x10325476
this._e = 0xc3d2e1f0

@@ -36,45 +40,43 @@ return this

/*
* Bitwise rotate a 32-bit number to the left.
*/
function rol (num, cnt) {
return (num << cnt) | (num >>> (32 - cnt))
function rotl1 (num) {
return (num << 1) | (num >>> 31)
}
function rotl5 (num) {
return (num << 5) | (num >>> 27)
}
function rotl30 (num) {
return (num << 30) | (num >>> 2)
}
function ft (s, b, c, d) {
if (s === 0) return (b & c) | ((~b) & d)
if (s === 2) return (b & c) | (b & d) | (c & d)
return b ^ c ^ d
}
Sha1.prototype._update = function (M) {
var W = this._w
var a = this._a
var b = this._b
var c = this._c
var d = this._d
var e = this._e
var a = this._a | 0
var b = this._b | 0
var c = this._c | 0
var d = this._d | 0
var e = this._e | 0
var j = 0
var k
for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
function calcW () { return rol(W[j - 3] ^ W[j - 8] ^ W[j - 14] ^ W[j - 16], 1) }
function loop (w, f) {
W[j] = w
for (var j = 0; j < 80; ++j) {
var s = ~~(j / 20)
var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
var t = rol(a, 5) + f + e + w + k
e = d
d = c
c = rol(b, 30)
c = rotl30(b)
b = a
a = t
j++
}
k = 1518500249
while (j < 16) loop(M.readInt32BE(j * 4), (b & c) | ((~b) & d))
while (j < 20) loop(calcW(), (b & c) | ((~b) & d))
k = 1859775393
while (j < 40) loop(calcW(), b ^ c ^ d)
k = -1894007588
while (j < 60) loop(calcW(), (b & c) | (b & d) | (c & d))
k = -899497514
while (j < 80) loop(calcW(), b ^ c ^ d)
this._a = (a + this._a) | 0

@@ -81,0 +83,0 @@ this._b = (b + this._b) | 0

@@ -26,10 +26,10 @@ /**

Sha224.prototype.init = function () {
this._a = 0xc1059ed8 | 0
this._b = 0x367cd507 | 0
this._c = 0x3070dd17 | 0
this._d = 0xf70e5939 | 0
this._e = 0xffc00b31 | 0
this._f = 0x68581511 | 0
this._g = 0x64f98fa7 | 0
this._h = 0xbefa4fa4 | 0
this._a = 0xc1059ed8
this._b = 0x367cd507
this._c = 0x3070dd17
this._d = 0xf70e5939
this._e = 0xffc00b31
this._f = 0x68581511
this._g = 0x64f98fa7
this._h = 0xbefa4fa4

@@ -36,0 +36,0 @@ return this

@@ -44,10 +44,10 @@ /**

Sha256.prototype.init = function () {
this._a = 0x6a09e667 | 0
this._b = 0xbb67ae85 | 0
this._c = 0x3c6ef372 | 0
this._d = 0xa54ff53a | 0
this._e = 0x510e527f | 0
this._f = 0x9b05688c | 0
this._g = 0x1f83d9ab | 0
this._h = 0x5be0cd19 | 0
this._a = 0x6a09e667
this._b = 0xbb67ae85
this._c = 0x3c6ef372
this._d = 0xa54ff53a
this._e = 0x510e527f
this._f = 0x9b05688c
this._g = 0x1f83d9ab
this._h = 0x5be0cd19

@@ -57,23 +57,23 @@ return this

function Ch (x, y, z) {
function ch (x, y, z) {
return z ^ (x & (y ^ z))
}
function Maj (x, y, z) {
function maj (x, y, z) {
return (x & y) | (z & (x | y))
}
function Sigma0 (x) {
function sigma0 (x) {
return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
}
function Sigma1 (x) {
function sigma1 (x) {
return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
}
function Gamma0 (x) {
function gamma0 (x) {
return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
}
function Gamma1 (x) {
function gamma1 (x) {
return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)

@@ -94,26 +94,19 @@ }

var j = 0
for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
function calcW () { return Gamma1(W[j - 2]) + W[j - 7] + Gamma0(W[j - 15]) + W[j - 16] }
function loop (w) {
W[j] = w
for (var j = 0; j < 64; ++j) {
var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
var T2 = (sigma0(a) + maj(a, b, c)) | 0
var T1 = h + Sigma1(e) + Ch(e, f, g) + K[j] + w
var T2 = Sigma0(a) + Maj(a, b, c)
h = g
g = f
f = e
e = d + T1
e = (d + T1) | 0
d = c
c = b
b = a
a = T1 + T2
j++
a = (T1 + T2) | 0
}
while (j < 16) loop(M.readInt32BE(j * 4))
while (j < 64) loop(calcW())
this._a = (a + this._a) | 0

@@ -120,0 +113,0 @@ this._b = (b + this._b) | 0

@@ -17,19 +17,19 @@ var inherits = require('inherits')

Sha384.prototype.init = function () {
this._a = 0xcbbb9d5d | 0
this._b = 0x629a292a | 0
this._c = 0x9159015a | 0
this._d = 0x152fecd8 | 0
this._e = 0x67332667 | 0
this._f = 0x8eb44a87 | 0
this._g = 0xdb0c2e0d | 0
this._h = 0x47b5481d | 0
this._ah = 0xcbbb9d5d
this._bh = 0x629a292a
this._ch = 0x9159015a
this._dh = 0x152fecd8
this._eh = 0x67332667
this._fh = 0x8eb44a87
this._gh = 0xdb0c2e0d
this._hh = 0x47b5481d
this._al = 0xc1059ed8 | 0
this._bl = 0x367cd507 | 0
this._cl = 0x3070dd17 | 0
this._dl = 0xf70e5939 | 0
this._el = 0xffc00b31 | 0
this._fl = 0x68581511 | 0
this._gl = 0x64f98fa7 | 0
this._hl = 0xbefa4fa4 | 0
this._al = 0xc1059ed8
this._bl = 0x367cd507
this._cl = 0x3070dd17
this._dl = 0xf70e5939
this._el = 0xffc00b31
this._fl = 0x68581511
this._gl = 0x64f98fa7
this._hl = 0xbefa4fa4

@@ -47,8 +47,8 @@ return this

writeInt64BE(this._a, this._al, 0)
writeInt64BE(this._b, this._bl, 8)
writeInt64BE(this._c, this._cl, 16)
writeInt64BE(this._d, this._dl, 24)
writeInt64BE(this._e, this._el, 32)
writeInt64BE(this._f, this._fl, 40)
writeInt64BE(this._ah, this._al, 0)
writeInt64BE(this._bh, this._bl, 8)
writeInt64BE(this._ch, this._cl, 16)
writeInt64BE(this._dh, this._dl, 24)
writeInt64BE(this._eh, this._el, 32)
writeInt64BE(this._fh, this._fl, 40)

@@ -55,0 +55,0 @@ return H

@@ -59,19 +59,19 @@ var inherits = require('inherits')

Sha512.prototype.init = function () {
this._a = 0x6a09e667 | 0
this._b = 0xbb67ae85 | 0
this._c = 0x3c6ef372 | 0
this._d = 0xa54ff53a | 0
this._e = 0x510e527f | 0
this._f = 0x9b05688c | 0
this._g = 0x1f83d9ab | 0
this._h = 0x5be0cd19 | 0
this._ah = 0x6a09e667
this._bh = 0xbb67ae85
this._ch = 0x3c6ef372
this._dh = 0xa54ff53a
this._eh = 0x510e527f
this._fh = 0x9b05688c
this._gh = 0x1f83d9ab
this._hh = 0x5be0cd19
this._al = 0xf3bcc908 | 0
this._bl = 0x84caa73b | 0
this._cl = 0xfe94f82b | 0
this._dl = 0x5f1d36f1 | 0
this._el = 0xade682d1 | 0
this._fl = 0x2b3e6c1f | 0
this._gl = 0xfb41bd6b | 0
this._hl = 0x137e2179 | 0
this._al = 0xf3bcc908
this._bl = 0x84caa73b
this._cl = 0xfe94f82b
this._dl = 0x5f1d36f1
this._el = 0xade682d1
this._fl = 0x2b3e6c1f
this._gl = 0xfb41bd6b
this._hl = 0x137e2179

@@ -85,11 +85,11 @@ return this

function Maj (x, y, z) {
function maj (x, y, z) {
return (x & y) | (z & (x | y))
}
function Sigma0 (x, xl) {
function sigma0 (x, xl) {
return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
}
function Sigma1 (x, xl) {
function sigma1 (x, xl) {
return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)

@@ -114,13 +114,17 @@ }

function getCarry (a, b) {
return (a >>> 0) < (b >>> 0) ? 1 : 0
}
Sha512.prototype._update = function (M) {
var W = this._w
var a = this._a | 0
var b = this._b | 0
var c = this._c | 0
var d = this._d | 0
var e = this._e | 0
var f = this._f | 0
var g = this._g | 0
var h = this._h | 0
var ah = this._ah | 0
var bh = this._bh | 0
var ch = this._ch | 0
var dh = this._dh | 0
var eh = this._eh | 0
var fh = this._fh | 0
var gh = this._gh | 0
var hh = this._hh | 0

@@ -136,96 +140,85 @@ var al = this._al | 0

var i = 0
var j = 0
var Wi, Wil
function calcW () {
var x = W[j - 15 * 2]
var xl = W[j - 15 * 2 + 1]
var gamma0 = Gamma0(x, xl)
var gamma0l = Gamma0l(xl, x)
for (var i = 0; i < 32; i += 2) {
W[i] = M.readInt32BE(i * 4)
W[i + 1] = M.readInt32BE(i * 4 + 4)
}
for (; i < 160; i += 2) {
var xh = W[i - 15 * 2]
var xl = W[i - 15 * 2 + 1]
var gamma0 = Gamma0(xh, xl)
var gamma0l = Gamma0l(xl, xh)
x = W[j - 2 * 2]
xl = W[j - 2 * 2 + 1]
var gamma1 = Gamma1(x, xl)
var gamma1l = Gamma1l(xl, x)
xh = W[i - 2 * 2]
xl = W[i - 2 * 2 + 1]
var gamma1 = Gamma1(xh, xl)
var gamma1l = Gamma1l(xl, xh)
// W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
var Wi7 = W[j - 7 * 2]
var Wi7l = W[j - 7 * 2 + 1]
var Wi7h = W[i - 7 * 2]
var Wi7l = W[i - 7 * 2 + 1]
var Wi16 = W[j - 16 * 2]
var Wi16l = W[j - 16 * 2 + 1]
var Wi16h = W[i - 16 * 2]
var Wi16l = W[i - 16 * 2 + 1]
Wil = gamma0l + Wi7l
Wi = gamma0 + Wi7 + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0)
Wil = Wil + gamma1l
Wi = Wi + gamma1 + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0)
Wil = Wil + Wi16l
Wi = Wi + Wi16 + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0)
var Wil = (gamma0l + Wi7l) | 0
var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
Wil = (Wil + gamma1l) | 0
Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
Wil = (Wil + Wi16l) | 0
Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
W[i] = Wih
W[i + 1] = Wil
}
function loop () {
W[j] = Wi
W[j + 1] = Wil
for (var j = 0; j < 160; j += 2) {
Wih = W[j]
Wil = W[j + 1]
var maj = Maj(a, b, c)
var majl = Maj(al, bl, cl)
var majh = maj(ah, bh, ch)
var majl = maj(al, bl, cl)
var sigma0h = Sigma0(a, al)
var sigma0l = Sigma0(al, a)
var sigma1h = Sigma1(e, el)
var sigma1l = Sigma1(el, e)
var sigma0h = sigma0(ah, al)
var sigma0l = sigma0(al, ah)
var sigma1h = sigma1(eh, el)
var sigma1l = sigma1(el, eh)
// t1 = h + sigma1 + ch + K[i] + W[i]
var Ki = K[j]
// t1 = h + sigma1 + ch + K[j] + W[j]
var Kih = K[j]
var Kil = K[j + 1]
var ch = Ch(e, f, g)
var chh = Ch(eh, fh, gh)
var chl = Ch(el, fl, gl)
var t1l = hl + sigma1l
var t1 = h + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0)
t1l = t1l + chl
t1 = t1 + ch + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0)
t1l = t1l + Kil
t1 = t1 + Ki + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0)
t1l = t1l + Wil
t1 = t1 + Wi + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0)
var t1l = (hl + sigma1l) | 0
var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
t1l = (t1l + chl) | 0
t1h = (t1h + chh + getCarry(t1l, chl)) | 0
t1l = (t1l + Kil) | 0
t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
t1l = (t1l + Wil) | 0
t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
// t2 = sigma0 + maj
var t2l = sigma0l + majl
var t2 = sigma0h + maj + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0)
var t2l = (sigma0l + majl) | 0
var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
h = g
hh = gh
hl = gl
g = f
gh = fh
gl = fl
f = e
fh = eh
fl = el
el = (dl + t1l) | 0
e = (d + t1 + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
d = c
eh = (dh + t1h + getCarry(el, dl)) | 0
dh = ch
dl = cl
c = b
ch = bh
cl = bl
b = a
bh = ah
bl = al
al = (t1l + t2l) | 0
a = (t1 + t2 + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0
i++
j += 2
ah = (t1h + t2h + getCarry(al, t1l)) | 0
}
while (i < 16) {
Wi = M.readInt32BE(j * 4)
Wil = M.readInt32BE(j * 4 + 4)
loop()
}
while (i < 80) {
calcW()
loop()
}
this._al = (this._al + al) | 0

@@ -240,10 +233,10 @@ this._bl = (this._bl + bl) | 0

this._a = (this._a + a + ((this._al >>> 0) < (al >>> 0) ? 1 : 0)) | 0
this._b = (this._b + b + ((this._bl >>> 0) < (bl >>> 0) ? 1 : 0)) | 0
this._c = (this._c + c + ((this._cl >>> 0) < (cl >>> 0) ? 1 : 0)) | 0
this._d = (this._d + d + ((this._dl >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
this._e = (this._e + e + ((this._el >>> 0) < (el >>> 0) ? 1 : 0)) | 0
this._f = (this._f + f + ((this._fl >>> 0) < (fl >>> 0) ? 1 : 0)) | 0
this._g = (this._g + g + ((this._gl >>> 0) < (gl >>> 0) ? 1 : 0)) | 0
this._h = (this._h + h + ((this._hl >>> 0) < (hl >>> 0) ? 1 : 0)) | 0
this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
}

@@ -259,10 +252,10 @@

writeInt64BE(this._a, this._al, 0)
writeInt64BE(this._b, this._bl, 8)
writeInt64BE(this._c, this._cl, 16)
writeInt64BE(this._d, this._dl, 24)
writeInt64BE(this._e, this._el, 32)
writeInt64BE(this._f, this._fl, 40)
writeInt64BE(this._g, this._gl, 48)
writeInt64BE(this._h, this._hl, 56)
writeInt64BE(this._ah, this._al, 0)
writeInt64BE(this._bh, this._bl, 8)
writeInt64BE(this._ch, this._cl, 16)
writeInt64BE(this._dh, this._dl, 24)
writeInt64BE(this._eh, this._el, 32)
writeInt64BE(this._fh, this._fl, 40)
writeInt64BE(this._gh, this._gl, 48)
writeInt64BE(this._hh, this._hl, 56)

@@ -269,0 +262,0 @@ return H

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc