UNPKG

687 BJavaScriptView Raw
1/* eslint-disable camelcase */
2const sha512 = require('sha512-wasm')
3const assert = require('nanoassert')
4
5if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
6
7const crypto_hash_sha512_BYTES = 64
8const crypto_hash_BYTES = crypto_hash_sha512_BYTES
9
10function 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
17function crypto_hash (out, m, n) {
18 return crypto_hash_sha512(out, m, n)
19}
20
21module.exports = {
22 crypto_hash,
23 crypto_hash_sha512,
24 crypto_hash_sha512_BYTES,
25 crypto_hash_BYTES
26}