sodium-javascript/crypto_generichash.js
2017-06-06 21:04:36 +02:00

28 lines
1.0 KiB
JavaScript

var assert = require('assert')
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
module.exports.crypto_generichash = function (output, input, key) {
blake2b(output, input, key)
}
module.exports.crypto_generichash_batch = function (output, inputArray, key) {
var ctx = blake2b.instance(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.instance(outlen, key)
}