2020-06-16 12:15:33 +00:00
|
|
|
const sha512 = require('sha512-wasm')
|
2020-06-17 15:27:28 +00:00
|
|
|
const assert = require('nanoassert')
|
2020-05-23 11:37:54 +00:00
|
|
|
|
2020-06-18 12:09:12 +00:00
|
|
|
if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
|
|
|
|
|
2020-06-16 12:15:33 +00:00
|
|
|
var crypto_hash_sha512_BYTES = 64
|
|
|
|
var crypto_hash_BYTES = crypto_hash_sha512_BYTES
|
2020-05-23 11:37:54 +00:00
|
|
|
|
2020-06-16 12:15:33 +00:00
|
|
|
function crypto_hash_sha512 (out, m, n) {
|
2020-06-17 15:27:28 +00:00
|
|
|
assert(out.byteLength === crypto_hash_sha512_BYTES, "out must be 'crypto_hash_sha512_BYTES' bytes long")
|
2020-05-04 18:52:17 +00:00
|
|
|
|
2020-06-16 12:15:33 +00:00
|
|
|
sha512().update(m.subarray(0, n)).digest(out)
|
|
|
|
return 0
|
2020-05-04 18:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function crypto_hash (out, m, n) {
|
2020-06-16 12:15:33 +00:00
|
|
|
return crypto_hash_sha512(out, m, n)
|
2020-05-04 18:52:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-23 11:37:54 +00:00
|
|
|
module.exports = {
|
|
|
|
crypto_hash,
|
2020-06-16 12:15:33 +00:00
|
|
|
crypto_hash_sha512,
|
2020-06-18 12:22:32 +00:00
|
|
|
crypto_hash_sha512_BYTES,
|
2020-06-18 12:09:12 +00:00
|
|
|
crypto_hash_BYTES
|
2020-05-23 11:37:54 +00:00
|
|
|
}
|