4520eccee8
When looking through each of the extra methods exposed by this module I noticed lots of 'wasm' mentions, but since this method doesn't mention wasm it wasn't clear to me why this extra method was being exposed. This commit is a breaking change that renames crypto_generichash_ready to crypto_generichash_wasm_ready, which feels more clear to me.
37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
var blake2b = require('blake2b')
|
|
|
|
if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
|
|
|
|
module.exports.crypto_generichash_PRIMITIVE = 'blake2b'
|
|
module.exports.crypto_generichash_BYTES_MIN = blake2b.BYTES_MIN
|
|
module.exports.crypto_generichash_BYTES_MAX = blake2b.BYTES_MAX
|
|
module.exports.crypto_generichash_BYTES = blake2b.BYTES
|
|
module.exports.crypto_generichash_KEYBYTES_MIN = blake2b.KEYBYTES_MIN
|
|
module.exports.crypto_generichash_KEYBYTES_MAX = blake2b.KEYBYTES_MAX
|
|
module.exports.crypto_generichash_KEYBYTES = blake2b.KEYBYTES
|
|
module.exports.crypto_generichash_WASM_SUPPORTED = blake2b.WASM_SUPPORTED
|
|
module.exports.crypto_generichash_WASM_LOADED = false
|
|
|
|
module.exports.crypto_generichash = function (output, input, key) {
|
|
blake2b(output.length, key).update(input).final(output)
|
|
}
|
|
|
|
module.exports.crypto_generichash_wasm_ready = blake2b.ready
|
|
|
|
module.exports.crypto_generichash_batch = function (output, inputArray, key) {
|
|
var ctx = blake2b(output.length, key)
|
|
for (var i = 0; i < inputArray.length; i++) {
|
|
ctx.update(inputArray[i])
|
|
}
|
|
ctx.final(output)
|
|
}
|
|
|
|
module.exports.crypto_generichash_instance = function (key, outlen) {
|
|
if (outlen == null) outlen = module.exports.crypto_generichash_BYTES
|
|
return blake2b(outlen, key)
|
|
}
|
|
|
|
blake2b.ready(function (_) {
|
|
module.exports.crypto_generichash_WASM_LOADED = blake2b.WASM_LOADED
|
|
})
|