2020-06-24 12:08:55 +00:00
|
|
|
/* eslint-disable camelcase */
|
2020-06-18 15:09:03 +00:00
|
|
|
const sha512 = require('sha512-wasm')
|
|
|
|
const assert = require('nanoassert')
|
|
|
|
|
|
|
|
if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
|
|
|
|
|
2020-06-24 12:08:55 +00:00
|
|
|
const crypto_hash_sha512_BYTES = 64
|
|
|
|
const crypto_hash_BYTES = crypto_hash_sha512_BYTES
|
2020-06-18 15:09:03 +00:00
|
|
|
|
|
|
|
function crypto_hash_sha512 (out, m, n) {
|
|
|
|
assert(out.byteLength === crypto_hash_sha512_BYTES, "out must be 'crypto_hash_sha512_BYTES' bytes long")
|
|
|
|
|
|
|
|
sha512().update(m.subarray(0, n)).digest(out)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function crypto_hash (out, m, n) {
|
|
|
|
return crypto_hash_sha512(out, m, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
crypto_hash,
|
|
|
|
crypto_hash_sha512,
|
|
|
|
crypto_hash_sha512_BYTES,
|
|
|
|
crypto_hash_BYTES
|
|
|
|
}
|