Skip to content

Instantly share code, notes, and snippets.

@devi
Last active August 29, 2015 14:02
Show Gist options
  • Save devi/c4e486480efbeedc1fd8 to your computer and use it in GitHub Desktop.
Save devi/c4e486480efbeedc1fd8 to your computer and use it in GitHub Desktop.
sha512.js
/* sha512 */
// Written in 2014 by Devi Mandiri. Public domain.
//
// Implementation derived from TweetNaCl version 20140427.
// See for details: http://tweetnacl.cr.yp.to/
//
var u64 = function (h, l) {
h = h|0; l = l|0;
this.hi = h >>> 0;
this.lo = l >>> 0;
};
function dl64(x, i) {
var h = (x[i] << 24) | (x[i+1] << 16) | (x[i+2] << 8) | x[i+3];
var l = (x[i+4] << 24) | (x[i+5] << 16) | (x[i+6] << 8) | x[i+7];
return new u64(h, l);
}
function ts64(x, i, u) {
x[i] = (u.hi >>> 24) & 0xff;
x[i+1] = (u.hi >>> 16) & 0xff;
x[i+2] = (u.hi >>> 8) & 0xff;
x[i+3] = u.hi & 0xff;
x[i+4] = (u.lo >>> 24) & 0xff;
x[i+5] = (u.lo >>> 16) & 0xff;
x[i+6] = (u.lo >>> 8) & 0xff;
x[i+7] = u.lo & 0xff;
}
function add64() {
var l = 0, h = 0, c;
for (var i = 0; i < arguments.length; i++) {
l = (l + arguments[i].lo)>>>0;
c = (l < (arguments[i].lo>>>0))|0;
h = (h + arguments[i].hi + c)>>>0;
}
return new u64(h, l);
}
function shr(x, c) {
var h = 0, l = 0;
if (c < 32) {
l = (x.lo >>> c) | (x.hi & (((1 << c) - 1)|0)) << (32 - c);
h = x.hi >>> c;
} else {
l = x.hi >>> (c - 32);
}
return new u64(h, l);
}
function R(x, c) {
var h = 0, l = 0, t = shr(x, c), c = 64 - c;
if (c < 32) {
h = (x.hi << c) | ((x.lo & (((1 << c) - 1)|0) << (32 - c)) >>> (32 - c));
l = x.lo << c;
} else {
h = x.lo << (c - 32);
}
return new u64(t.hi | h, t.lo | l);
}
function Ch(x, y, z) {
var h = (x.hi & y.hi) ^ (~x.hi & z.hi),
l = (x.lo & y.lo) ^ (~x.lo & z.lo);
return new u64(h, l);
}
function Maj(x, y, z) {
var h = (x.hi & y.hi) ^ (x.hi & z.hi) ^ (y.hi & z.hi),
l = (x.lo & y.lo) ^ (x.lo & z.lo) ^ (y.lo & z.lo);
return new u64(h, l);
}
function Sigma0(x) {
var s = [], h, l;
s[0] = R(x, 28); s[1] = R(x, 34); s[2] = R(x, 39);
h = s[0].hi ^ s[1].hi ^ s[2].hi;
l = s[0].lo ^ s[1].lo ^ s[2].lo;
return new u64(h, l);
}
function Sigma1(x) {
var s = [], h, l;
s[0] = R(x, 14); s[1] = R(x, 18); s[2] = R(x, 41);
h = s[0].hi ^ s[1].hi ^ s[2].hi;
l = s[0].lo ^ s[1].lo ^ s[2].lo;
return new u64(h, l);
}
function sigma0(x) {
var s = [], h, l;
s[0] = R(x, 1); s[1] = R(x, 8); s[2] = shr(x, 7);
h = s[0].hi ^ s[1].hi ^ s[2].hi;
l = s[0].lo ^ s[1].lo ^ s[2].lo;
return new u64(h, l);
}
function sigma1(x) {
var s = [], h, l;
s[0] = R(x, 19); s[1] = R(x, 61); s[2] = shr(x, 6);
h = s[0].hi ^ s[1].hi ^ s[2].hi;
l = s[0].lo ^ s[1].lo ^ s[2].lo;
return new u64(h, l);
}
var K = [
new u64(0x428a2f98, 0xd728ae22), new u64(0x71374491, 0x23ef65cd),
new u64(0xb5c0fbcf, 0xec4d3b2f), new u64(0xe9b5dba5, 0x8189dbbc),
new u64(0x3956c25b, 0xf348b538), new u64(0x59f111f1, 0xb605d019),
new u64(0x923f82a4, 0xaf194f9b), new u64(0xab1c5ed5, 0xda6d8118),
new u64(0xd807aa98, 0xa3030242), new u64(0x12835b01, 0x45706fbe),
new u64(0x243185be, 0x4ee4b28c), new u64(0x550c7dc3, 0xd5ffb4e2),
new u64(0x72be5d74, 0xf27b896f), new u64(0x80deb1fe, 0x3b1696b1),
new u64(0x9bdc06a7, 0x25c71235), new u64(0xc19bf174, 0xcf692694),
new u64(0xe49b69c1, 0x9ef14ad2), new u64(0xefbe4786, 0x384f25e3),
new u64(0x0fc19dc6, 0x8b8cd5b5), new u64(0x240ca1cc, 0x77ac9c65),
new u64(0x2de92c6f, 0x592b0275), new u64(0x4a7484aa, 0x6ea6e483),
new u64(0x5cb0a9dc, 0xbd41fbd4), new u64(0x76f988da, 0x831153b5),
new u64(0x983e5152, 0xee66dfab), new u64(0xa831c66d, 0x2db43210),
new u64(0xb00327c8, 0x98fb213f), new u64(0xbf597fc7, 0xbeef0ee4),
new u64(0xc6e00bf3, 0x3da88fc2), new u64(0xd5a79147, 0x930aa725),
new u64(0x06ca6351, 0xe003826f), new u64(0x14292967, 0x0a0e6e70),
new u64(0x27b70a85, 0x46d22ffc), new u64(0x2e1b2138, 0x5c26c926),
new u64(0x4d2c6dfc, 0x5ac42aed), new u64(0x53380d13, 0x9d95b3df),
new u64(0x650a7354, 0x8baf63de), new u64(0x766a0abb, 0x3c77b2a8),
new u64(0x81c2c92e, 0x47edaee6), new u64(0x92722c85, 0x1482353b),
new u64(0xa2bfe8a1, 0x4cf10364), new u64(0xa81a664b, 0xbc423001),
new u64(0xc24b8b70, 0xd0f89791), new u64(0xc76c51a3, 0x0654be30),
new u64(0xd192e819, 0xd6ef5218), new u64(0xd6990624, 0x5565a910),
new u64(0xf40e3585, 0x5771202a), new u64(0x106aa070, 0x32bbd1b8),
new u64(0x19a4c116, 0xb8d2d0c8), new u64(0x1e376c08, 0x5141ab53),
new u64(0x2748774c, 0xdf8eeb99), new u64(0x34b0bcb5, 0xe19b48a8),
new u64(0x391c0cb3, 0xc5c95a63), new u64(0x4ed8aa4a, 0xe3418acb),
new u64(0x5b9cca4f, 0x7763e373), new u64(0x682e6ff3, 0xd6b2b8a3),
new u64(0x748f82ee, 0x5defb2fc), new u64(0x78a5636f, 0x43172f60),
new u64(0x84c87814, 0xa1f0ab72), new u64(0x8cc70208, 0x1a6439ec),
new u64(0x90befffa, 0x23631e28), new u64(0xa4506ceb, 0xde82bde9),
new u64(0xbef9a3f7, 0xb2c67915), new u64(0xc67178f2, 0xe372532b),
new u64(0xca273ece, 0xea26619c), new u64(0xd186b8c7, 0x21c0c207),
new u64(0xeada7dd6, 0xcde0eb1e), new u64(0xf57d4f7f, 0xee6ed178),
new u64(0x06f067aa, 0x72176fba), new u64(0x0a637dc5, 0xa2c898a6),
new u64(0x113f9804, 0xbef90dae), new u64(0x1b710b35, 0x131c471b),
new u64(0x28db77f5, 0x23047d84), new u64(0x32caab7b, 0x40c72493),
new u64(0x3c9ebe0a, 0x15c9bebc), new u64(0x431d67c4, 0x9c100d4c),
new u64(0x4cc5d4be, 0xcb3e42b6), new u64(0x597f299c, 0xfc657e2a),
new u64(0x5fcb6fab, 0x3ad6faec), new u64(0x6c44198c, 0x4a475817)
];
var iv = [
0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
];
function crypto_hashblocks(x, m, n) {
var z = [], b = [], a = [], w = [], t, i, j;
for (i = 0; i < 8; i++) z[i] = a[i] = dl64(x, 8*i);
var pos = 0;
while (n >= 128) {
for (i = 0; i < 16; i++) w[i] = dl64(m, 8*i+pos);
for (i = 0; i < 80; i++) {
for (j = 0; j < 8; j++) b[j] = a[j];
t = add64(a[7], Sigma1(a[4]), Ch(a[4], a[5], a[6]), K[i], w[i%16]);
b[7] = add64(t, Sigma0(a[0]), Maj(a[0], a[1], a[2]));
b[3] = add64(b[3], t);
for (j = 0; j < 8; j++) a[(j+1)%8] = b[j];
if (i%16 == 15) {
for (j = 0; j < 16; j++) {
w[j] = add64(w[j], w[(j+9)%16], sigma0(w[(j+1)%16]), sigma1(w[(j+14)%16]));
}
}
}
for (i = 0; i < 8; i++) {
a[i] = add64(a[i], z[i]);
z[i] = a[i];
}
pos += 128;
n -= 128;
}
for (i = 0; i < 8; i++) ts64(x, 8*i, z[i]);
return n;
}
function crypto_hash(out, m, n) {
var h = iv.slice(0), x = new Array(256);
var i, b = n;
crypto_hashblocks(h, m, n);
n &= 127;
for (i = 0; i < 256; i++) x[i] = 0;
for (i = 0; i < n; i++) x[i] = m[b-n+i];
x[n] = 128;
n = 256-128*(n<112);
x[n-9] = b >> 61;
ts64(x, n-8, new u64(0, b << 3));
crypto_hashblocks(h, x, n);
for (i = 0; i < 64; i++) out[i] = h[i];
}
function bytesEqual(a, b) {
var dif = 0;
if (a.length !== b.length) return 0;
for (var i = 0; i < a.length; i++) {
dif |= (a[i] ^ b[i]);
}
dif = (dif - 1) >>> 31;
return (dif & 1);
}
function crypto_hash_test() {
// golden taken from https://code.google.com/p/go/source/browse/src/pkg/crypto/sha512/sha512_test.go
var golden = [
[[207,131,225,53,126,239,184,189,241,84,40,80,214,109,128,7,214,32,228,5,11,87,21,220,131,244,169,33,211,108,233,206,71,208,209,60,93,133,242,176,255,131,24,210,135,126,236,47,99,185,49,189,71,65,122,129,165,56,50,122,249,39,218,62 ],[]],
[[31,64,252,146,218,36,22,148,117,9,121,238,108,245,130,242,213,215,210,142,24,51,93,224,90,188,84,208,86,14,15,83,2,134,12,101,43,240,141,86,2,82,170,94,116,33,5,70,243,105,251,187,206,140,18,207,199,149,123,38,82,254,154,117 ],[ 97]],
[[45,64,138,7,23,236,24,129,88,39,138,121,108,104,144,68,54,29,198,253,222,40,214,240,73,115,184,8,150,225,130,57,117,205,191,18,235,99,249,224,89,19,40,238,35,93,128,233,181,191,26,166,164,79,70,23,255,60,175,100,0,235,23,45 ],[ 97,98]],
[[221,175,53,161,147,97,122,186,204,65,115,73,174,32,65,49,18,230,250,78,137,169,126,162,10,158,238,230,75,85,211,154,33,146,153,42,39,79,193,168,54,186,60,35,163,254,235,189,69,77,68,35,100,60,232,14,42,154,201,79,165,76,164,159 ],[ 97,98,99]],
[[216,2,47,32,96,173,110,253,41,122,183,61,204,83,85,201,178,20,5,75,13,23,118,161,54,166,105,210,106,125,59,20,247,58,160,208,235,255,25,238,51,51,104,240,22,75,100,25,169,109,164,158,62,72,23,83,231,233,107,113,107,220,203,111 ],[ 97,98,99,100]],
[[135,138,230,90,146,232,108,172,1,26,87,13,76,48,167,234,236,68,43,133,206,142,202,12,41,82,181,227,204,6,40,194,231,157,136,154,212,213,199,198,38,152,109,69,45,216,99,116,182,255,170,124,216,182,118,101,190,242,40,154,92,112,176,161 ],[ 97,98,99,100,101]],
[[227,46,241,150,35,232,237,157,38,127,101,122,129,148,75,61,7,173,187,118,133,24,6,142,136,67,87,69,86,78,141,65,80,160,167,3,190,42,125,136,182,30,61,57,12,43,185,126,45,76,49,31,220,105,214,177,38,127,5,245,154,169,32,231 ],[ 97,98,99,100,101,102]],
[[215,22,164,24,133,105,182,138,177,182,223,172,23,142,87,1,20,205,240,234,58,28,192,227,20,134,195,228,18,65,188,106,118,66,78,140,55,171,38,240,150,252,133,239,152,134,200,203,99,65,135,244,253,223,246,69,251,9,159,31,245,76,107,140 ],[ 97,98,99,100,101,102,103]],
[[163,168,200,27,201,124,37,96,1,13,115,137,188,136,170,201,116,161,4,224,226,56,18,32,198,224,132,196,220,205,29,45,23,212,248,109,179,28,42,133,29,200,14,102,129,215,71,51,197,93,205,3,221,150,246,6,44,221,161,42,41,26,230,206 ],[ 97,98,99,100,101,102,103,104]],
[[242,45,81,210,82,146,202,29,15,104,246,154,237,199,137,112,25,48,140,201,219,70,239,183,90,3,221,73,79,199,241,38,192,16,232,173,230,160,10,12,26,95,27,117,216,30,14,213,169,60,233,141,201,184,51,219,120,57,36,123,29,156,36,254 ],[ 97,98,99,100,101,102,103,104,105]],
[[239,107,151,50,31,52,177,254,162,22,154,125,185,225,150,11,71,26,161,51,2,169,136,8,115,87,197,32,190,149,124,161,25,195,186,104,230,180,152,44,1,158,200,157,227,134,92,207,106,60,218,31,225,30,89,249,141,153,241,80,44,139,151,69 ],[ 97,98,99,100,101,102,103,104,105,106]],
[[34,16,217,154,249,200,189,236,218,27,75,239,248,34,19,103,83,216,52,37,5,221,206,55,241,49,78,44,219,180,136,198,1,107,218,169,189,47,250,81,61,213,222,46,75,80,240,49,57,61,138,182,31,119,59,14,1,48,215,56,30,15,138,29 ],[ 68,105,115,99,97,114,100,32,109,101,100,105,99,105,110,101,32,109,111,114,101,32,116,104,97,110,32,116,119,111,32,121,101,97,114,115,32,111,108,100,46]],
[[166,135,168,152,91,77,141,10,36,241,21,254,39,34,85,198,175,175,57,9,34,88,56,84,97,89,193,237,104,92,33,26,32,55,150,174,142,204,76,129,165,182,49,89,25,179,166,79,16,113,61,160,126,52,31,205,187,8,84,27,240,48,102,206 ],[ 72,101,32,119,104,111,32,104,97,115,32,97,32,115,104,97,100,121,32,112,97,115,116,32,107,110,111,119,115,32,116,104,97,116,32,110,105,99,101,32,103,117,121,115,32,102,105,110,105,115,104,32,108,97,115,116,46]],
[[141,219,3,146,232,24,183,213,133,171,34,118,154,80,223,102,13,159,109,85,156,202,58,252,86,145,184,202,145,184,69,19,116,228,43,205,171,214,69,137,237,124,145,216,95,98,101,150,34,138,92,133,114,103,126,185,139,198,182,36,190,251,122,248 ],[ 73,32,119,111,117,108,100,110,39,116,32,109,97,114,114,121,32,104,105,109,32,119,105,116,104,32,97,32,116,101,110,32,102,111,111,116,32,112,111,108,101,46]],
[[38,237,143,108,167,248,212,75,106,138,84,174,57,100,15,168,173,92,103,63,112,238,156,224,116,186,78,240,212,131,238,160,11,171,47,97,216,105,93,107,52,223,156,108,72,174,54,36,99,98,32,14,216,32,68,139,220,3,167,32,54,106,135,198 ],[ 70,114,101,101,33,32,70,114,101,101,33,47,65,32,116,114,105,112,47,116,111,32,77,97,114,115,47,102,111,114,32,57,48,48,47,101,109,112,116,121,32,106,97,114,115,47,66,117,114,109,97,32,83,104,97,118,101]],
[[229,161,75,240,68,190,105,97,90,173,232,154,252,241,171,3,137,213,252,48,42,136,77,64,53,121,209,56,106,36,0,192,137,176,219,179,135,237,15,70,63,158,227,66,248,36,77,90,56,207,188,14,129,157,169,82,159,191,247,131,104,201,169,130 ],[ 84,104,101,32,100,97,121,115,32,111,102,32,116,104,101,32,100,105,103,105,116,97,108,32,119,97,116,99,104,32,97,114,101,32,110,117,109,98,101,114,101,100,46,32,32,45,84,111,109,32,83,116,111,112,112,97,114,100]],
[[66,10,31,170,72,145,158,20,101,27,237,69,114,90,190,15,122,88,224,240,153,66,76,78,90,73,25,73,70,227,139,70,193,248,3,75,24,239,22,155,46,49,5,13,22,72,224,185,130,56,101,149,247,223,71,218,75,111,209,142,85,51,48,21 ],[ 78,101,112,97,108,32,112,114,101,109,105,101,114,32,119,111,110,39,116,32,114,101,115,105,103,110,46]],
[[217,38,168,99,190,173,178,1,52,219,7,104,53,53,199,32,7,176,230,149,4,88,118,37,79,52,29,220,204,222,19,42,144,140,90,245,123,170,106,106,156,99,230,100,155,186,12,33,61,192,95,173,207,154,188,206,160,159,35,220,251,99,127,190 ],[ 70,111,114,32,101,118,101,114,121,32,97,99,116,105,111,110,32,116,104,101,114,101,32,105,115,32,97,110,32,101,113,117,97,108,32,97,110,100,32,111,112,112,111,115,105,116,101,32,103,111,118,101,114,110,109,101,110,116,32,112,114,111,103,114,97,109,46]],
[[154,152,221,155,182,125,13,167,191,131,218,83,19,223,244,253,96,164,186,192,9,79,27,5,99,54,144,255,167,246,214,29,233,161,212,248,97,121,55,213,96,131,58,154,170,156,202,254,63,210,77,180,24,208,231,40,131,53,69,202,221,58,217,45 ],[ 72,105,115,32,109,111,110,101,121,32,105,115,32,116,119,105,99,101,32,116,97,105,110,116,101,100,58,32,39,116,97,105,110,116,32,121,111,117,114,115,32,97,110,100,32,39,116,97,105,110,116,32,109,105,110,101,46]],
[[215,253,226,210,53,30,250,222,82,244,33,29,55,70,160,120,10,38,238,195,223,155,46,213,117,54,138,138,28,9,236,69,36,2,41,58,142,164,236,235,90,79,96,6,78,162,155,19,205,216,105,24,205,122,79,175,54,97,96,176,9,128,65,7 ],[ 84,104,101,114,101,32,105,115,32,110,111,32,114,101,97,115,111,110,32,102,111,114,32,97,110,121,32,105,110,100,105,118,105,100,117,97,108,32,116,111,32,104,97,118,101,32,97,32,99,111,109,112,117,116,101,114,32,105,110,32,116,104,101,105,114,32,104,111,109,101,46,32,45,75,101,110,32,79,108,115,101,110,44,32,49,57,55,55]],
[[176,243,95,250,38,151,53,156,51,165,111,92,12,247,21,199,174,237,150,218,153,5,202,38,152,172,173,176,143,188,158,102,155,245,102,182,189,93,97,163,232,109,194,41,153,188,201,242,34,78,51,209,212,243,42,34,140,249,208,52,158,45,181,24 ],[ 73,116,39,115,32,97,32,116,105,110,121,32,99,104,97,110,103,101,32,116,111,32,116,104,101,32,99,111,100,101,32,97,110,100,32,110,111,116,32,99,111,109,112,108,101,116,101,108,121,32,100,105,115,103,117,115,116,105,110,103,46,32,45,32,66,111,98,32,77,97,110,99,104,101,107]],
[[61,46,95,145,119,140,158,102,247,224,97,41,58,170,138,143,199,66,221,59,46,79,72,55,114,70,75,17,68,24,155,73,39,62,97,14,92,204,215,168,26,25,202,31,167,15,22,177,15,26,16,10,77,140,19,114,51,107,232,72,76,100,179,17 ],[ 115,105,122,101,58,32,32,97,46,111,117,116,58,32,32,98,97,100,32,109,97,103,105,99]],
[[178,246,143,245,138,192,21,239,177,201,76,144,139,13,140,43,240,111,73,30,77,232,230,48,44,73,1,111,127,138,51,234,195,233,89,133,108,127,221,188,70,77,230,24,112,19,56,164,180,111,118,219,250,249,161,229,38,43,95,64,99,151,113,199 ],[ 84,104,101,32,109,97,106,111,114,32,112,114,111,98,108,101,109,32,105,115,32,119,105,116,104,32,115,101,110,100,109,97,105,108,46,32,32,45,77,97,114,107,32,72,111,114,116,111,110]],
[[216,201,45,181,253,245,44,248,33,94,77,243,180,144,157,41,32,63,244,208,14,154,208,182,74,106,78,4,222,197,231,79,98,231,195,92,127,184,129,189,93,233,84,66,18,61,248,245,122,72,155,10,230,22,189,50,111,132,209,0,33,18,28,87 ],[ 71,105,118,101,32,109,101,32,97,32,114,111,99,107,44,32,112,97,112,101,114,32,97,110,100,32,115,99,105,115,115,111,114,115,32,97,110,100,32,73,32,119,105,108,108,32,109,111,118,101,32,116,104,101,32,119,111,114,108,100,46,32,32,67,67,70,101,115,116,111,111,110]],
[[25,169,248,220,10,35,62,70,78,133,102,173,60,169,185,30,69,154,123,140,71,128,152,91,1,87,118,225,191,35,154,25,188,35,61,5,86,52,62,43,10,155,194,32,144,11,78,191,79,139,223,137,255,142,254,175,121,96,45,104,73,230,247,46 ],[ 73,102,32,116,104,101,32,101,110,101,109,121,32,105,115,32,119,105,116,104,105,110,32,114,97,110,103,101,44,32,116,104,101,110,32,115,111,32,97,114,101,32,121,111,117,46]],
[[0,180,196,31,48,123,222,135,48,28,220,91,90,177,174,154,89,46,142,203,178,2,29,215,188,75,52,226,172,230,7,65,204,54,37,96,190,197,102,186,53,23,133,149,169,25,50,184,213,53,126,44,156,236,146,211,147,176,250,120,49,133,36,118 ],[ 73,116,39,115,32,119,101,108,108,32,119,101,32,99,97,110,110,111,116,32,104,101,97,114,32,116,104,101,32,115,99,114,101,97,109,115,47,84,104,97,116,32,119,101,32,99,114,101,97,116,101,32,105,110,32,111,116,104,101,114,115,39,32,100,114,101,97,109,115,46]],
[[145,236,204,61,83,117,253,2,110,77,103,135,135,75,29,206,32,28,236,216,162,125,189,237,80,101,114,140,178,208,156,88,163,212,103,187,31,175,53,59,247,186,86,126,0,82,69,213,50,27,85,188,52,79,124,7,185,28,182,242,108,149,155,231 ],[ 89,111,117,32,114,101,109,105,110,100,32,109,101,32,111,102,32,97,32,84,86,32,115,104,111,119,44,32,98,117,116,32,116,104,97,116,39,115,32,97,108,108,32,114,105,103,104,116,58,32,73,32,119,97,116,99,104,32,105,116,32,97,110,121,119,97,121,46]],
[[250,187,190,34,24,15,31,19,124,253,201,85,109,37,112,231,117,209,174,2,165,151,222,212,58,114,164,15,155,72,93,80,0,67,183,190,18,143,185,252,217,130,184,49,89,160,217,154,168,85,169,231,204,66,64,192,13,192,26,155,223,130,24,215 ],[ 67,32,105,115,32,97,115,32,112,111,114,116,97,98,108,101,32,97,115,32,83,116,111,110,101,104,101,100,103,101,33,33]],
[[46,205,236,35,92,31,164,252,42,21,77,143,186,29,221,184,167,42,26,215,56,56,181,29,121,35,49,209,67,248,185,106,159,111,203,15,52,215,202,163,81,254,109,136,119,28,79,16,80,64,224,57,47,6,224,98,22,137,211,59,47,59,169,46 ],[ 69,118,101,110,32,105,102,32,73,32,99,111,117,108,100,32,98,101,32,83,104,97,107,101,115,112,101,97,114,101,44,32,73,32,116,104,105,110,107,32,73,32,115,104,111,117,108,100,32,115,116,105,108,108,32,99,104,111,111,115,101,32,116,111,32,98,101,32,70,97,114,97,100,97,121,46,32,45,32,65,46,32,72,117,120,108,101,121]],
[[122,214,129,246,249,111,130,247,171,250,126,204,3,52,232,250,22,211,220,28,220,69,182,11,122,244,63,228,7,93,35,87,192,193,214,14,152,53,15,26,251,31,47,231,164,215,205,42,213,91,136,228,88,224,107,115,196,11,67,115,49,245,218,180 ],[ 84,104,101,32,102,117,103,97,99,105,116,121,32,111,102,32,97,32,99,111,110,115,116,105,116,117,101,110,116,32,105,110,32,97,32,109,105,120,116,117,114,101,32,111,102,32,103,97,115,101,115,32,97,116,32,97,32,103,105,118,101,110,32,116,101,109,112,101,114,97,116,117,114,101,32,105,115,32,112,114,111,112,111,114,116,105,111,110,97,108,32,116,111,32,105,116,115,32,109,111,108,101,32,102,114,97,99,116,105,111,110,46,32,32,76,101,119,105,115,45,82,97,110,100,97,108,108,32,82,117,108,101]],
[[131,63,146,72,171,74,59,158,81,49,247,69,253,161,255,210,221,67,91,48,233,101,149,126,120,41,28,122,183,54,5,253,25,18,176,121,78,92,35,58,176,161,45,32,90,57,119,141,25,184,53,21,214,164,112,3,241,156,222,229,29,152,199,224 ],[ 72,111,119,32,99,97,110,32,121,111,117,32,119,114,105,116,101,32,97,32,98,105,103,32,115,121,115,116,101,109,32,119,105,116,104,111,117,116,32,67,43,43,63,32,32,45,80,97,117,108,32,71,108,105,99,107]],
];
for (var i = 0; i < golden.length; i++) {
var out = [];
crypto_hash(out, golden[i][1], golden[i][1].length);
if (!bytesEqual(out, golden[i][0])) {
console.log(i, 'differ');
} else {
console.log(i, 'OK');
}
}
}
crypto_hash_test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment