]> zoso.dev Git - libnemo.git/commitdiff
Replace hash function in 25519 implemention
authorChris Duncan <chris@zoso.dev>
Sat, 23 Nov 2024 08:50:30 +0000 (00:50 -0800)
committerChris Duncan <chris@zoso.dev>
Sat, 23 Nov 2024 08:50:30 +0000 (00:50 -0800)
src/lib/workers/nano25519.ts

index dcf656045b3c2b6e59640835949e2723194f73e6..d194a283ae303cdf1ad0d3d05aa667c799b8678f 100644 (file)
@@ -1820,43 +1820,15 @@ import blake2b from 'blake2b'
        }\r
        \r
        function crypto_hash(out, m, n) {\r
-               var hh = new Int32Array(8),\r
-                               hl = new Int32Array(8),\r
-                               x = new Uint8Array(256),\r
-                               i, b = n;\r
-       \r
-               hh[0] = 0x6a09e667;\r
-               hh[1] = 0xbb67ae85;\r
-               hh[2] = 0x3c6ef372;\r
-               hh[3] = 0xa54ff53a;\r
-               hh[4] = 0x510e527f;\r
-               hh[5] = 0x9b05688c;\r
-               hh[6] = 0x1f83d9ab;\r
-               hh[7] = 0x5be0cd19;\r
-       \r
-               hl[0] = 0xf3bcc908;\r
-               hl[1] = 0x84caa73b;\r
-               hl[2] = 0xfe94f82b;\r
-               hl[3] = 0x5f1d36f1;\r
-               hl[4] = 0xade682d1;\r
-               hl[5] = 0x2b3e6c1f;\r
-               hl[6] = 0xfb41bd6b;\r
-               hl[7] = 0x137e2179;\r
-       \r
-               crypto_hashblocks_hl(hh, hl, m, n);\r
-               n %= 128;\r
-       \r
-               for (i = 0; i < n; i++) x[i] = m[b-n+i];\r
-               x[n] = 128;\r
-       \r
-               n = 256-128*(n<112?1:0);\r
-               x[n-9] = 0;\r
-               ts64(x, n-8,  (b / 0x20000000) | 0, b << 3);\r
-               crypto_hashblocks_hl(hh, hl, x, n);\r
-       \r
-               for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);\r
-       \r
-               return 0;\r
+               const input = new Uint8Array(n)\r
+               for (let i = 0; i < n; ++i) {\r
+                       input[i] = m[i]\r
+               }\r
+               const hash = blake2b(64).update(input).digest()\r
+               for (let i = 0; i < 64; ++i) {\r
+                       out[i] = hash[i]\r
+               }\r
+               return 0\r
        }\r
        \r
        function add(p, q) {\r