2017-06-06 19:04:36 +00:00
|
|
|
var blake2b = require('blake2b')
|
|
|
|
|
|
|
|
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
|
2017-06-12 08:15:52 +00:00
|
|
|
module.exports.crypto_generichash_WASM_SUPPORTED = blake2b.WASM_SUPPORTED
|
|
|
|
module.exports.crypto_generichash_WASM_LOADED = false
|
|
|
|
|
2017-06-06 19:04:36 +00:00
|
|
|
|
|
|
|
module.exports.crypto_generichash = function (output, input, key) {
|
2017-06-11 18:23:06 +00:00
|
|
|
blake2b(output.length, key).update(input).final(output)
|
2017-06-06 19:04:36 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 08:15:52 +00:00
|
|
|
module.exports.crypto_generichash_ready = blake2b.ready
|
|
|
|
|
2017-06-06 19:04:36 +00:00
|
|
|
module.exports.crypto_generichash_batch = function (output, inputArray, key) {
|
2017-06-11 18:23:06 +00:00
|
|
|
var ctx = blake2b(output.length, key)
|
2017-06-06 19:04:36 +00:00
|
|
|
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
|
2017-06-11 18:23:06 +00:00
|
|
|
return blake2b(outlen, key)
|
2017-06-06 19:04:36 +00:00
|
|
|
}
|
2017-06-12 08:15:52 +00:00
|
|
|
|
|
|
|
blake2b.ready(function (err) {
|
2017-06-12 08:29:16 +00:00
|
|
|
module.exports.crypto_generichash_WASM_LOADED = blake2b.WASM_LOADED
|
2017-06-12 08:15:52 +00:00
|
|
|
})
|