]> zoso.dev Git - libnemo.git/commitdiff
Restore original hash function, and include nano blake version as new function.
authorChris Duncan <chris@zoso.dev>
Sun, 24 Nov 2024 22:52:48 +0000 (14:52 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 24 Nov 2024 22:52:48 +0000 (14:52 -0800)
src/lib/workers/nano25519.ts

index 88b4246091521a62e92fb2b78ae6c97dc07bb885..0a4351dfea5f84b390e4db6a926fd3400faff981 100644 (file)
@@ -1819,6 +1819,46 @@ 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
+       }\r
+       \r
+       function crypto_hash_blake2b(out, m, n) {\r
                const input = new Uint8Array(n)\r
                for (let i = 0; i < n; ++i) {\r
                        input[i] = m[i]\r
@@ -2370,4 +2410,4 @@ import blake2b from 'blake2b'
                }\r
        })();\r
        \r
-       export { box, keyPair, getPublicKey, hash, message, randomBytes, scalarMult }
\ No newline at end of file
+       export { box, keyPair, getPublicKey, hash, message, randomBytes, scalarMult }\r