From adf3a6c114a95a2a0d7dbfddea427bee10c5e128 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 24 Nov 2024 14:52:48 -0800 Subject: [PATCH] Restore original hash function, and include nano blake version as new function. --- src/lib/workers/nano25519.ts | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/lib/workers/nano25519.ts b/src/lib/workers/nano25519.ts index 88b4246..0a4351d 100644 --- a/src/lib/workers/nano25519.ts +++ b/src/lib/workers/nano25519.ts @@ -1819,6 +1819,46 @@ import blake2b from 'blake2b' } function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; + + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; + + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; + + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; + + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; + + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); + + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + + return 0; + } + + function crypto_hash_blake2b(out, m, n) { const input = new Uint8Array(n) for (let i = 0; i < n; ++i) { input[i] = m[i] @@ -2370,4 +2410,4 @@ import blake2b from 'blake2b' } })(); - export { box, keyPair, getPublicKey, hash, message, randomBytes, scalarMult } \ No newline at end of file + export { box, keyPair, getPublicKey, hash, message, randomBytes, scalarMult } -- 2.34.1