1 |
|
2 | const sha512 = require('sha512-wasm')
|
3 | const assert = require('nanoassert')
|
4 |
|
5 | if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
|
6 |
|
7 | const crypto_hash_sha512_BYTES = 64
|
8 | const crypto_hash_BYTES = crypto_hash_sha512_BYTES
|
9 |
|
10 | function crypto_hash_sha512 (out, m, n) {
|
11 | assert(out.byteLength === crypto_hash_sha512_BYTES, "out must be 'crypto_hash_sha512_BYTES' bytes long")
|
12 |
|
13 | sha512().update(m.subarray(0, n)).digest(out)
|
14 | return 0
|
15 | }
|
16 |
|
17 | function crypto_hash (out, m, n) {
|
18 | return crypto_hash_sha512(out, m, n)
|
19 | }
|
20 |
|
21 | module.exports = {
|
22 | crypto_hash,
|
23 | crypto_hash_sha512,
|
24 | crypto_hash_sha512_BYTES,
|
25 | crypto_hash_BYTES
|
26 | }
|