From: Chris Duncan Date: Sat, 23 Nov 2024 08:50:30 +0000 (-0800) Subject: Replace hash function in 25519 implemention X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=7a8c4d465e11136a123a27d5b9e3e36741657e92;p=libnemo.git Replace hash function in 25519 implemention --- diff --git a/src/lib/workers/nano25519.ts b/src/lib/workers/nano25519.ts index dcf6560..d194a28 100644 --- a/src/lib/workers/nano25519.ts +++ b/src/lib/workers/nano25519.ts @@ -1820,43 +1820,15 @@ 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; + const input = new Uint8Array(n) + for (let i = 0; i < n; ++i) { + input[i] = m[i] + } + const hash = blake2b(64).update(input).digest() + for (let i = 0; i < 64; ++i) { + out[i] = hash[i] + } + return 0 } function add(p, q) {