sodium-javascript/crypto_hash_sha256.js

19 lines
495 B
JavaScript
Raw Normal View History

2020-08-27 22:52:54 +00:00
const sha256 = require('sha256-universal')
const assert = require('nanoassert')
if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
var crypto_hash_sha256_BYTES = 32
function crypto_hash_sha256 (out, m, n) {
assert(out.byteLength === crypto_hash_sha256_BYTES, "out must be 'crypto_hash_sha256_BYTES' bytes long")
sha256().update(m.subarray(0, n)).digest(out)
return 0
}
module.exports = {
crypto_hash_sha256,
crypto_hash_sha256_BYTES
}