UNPKG

1.39 kBJavaScriptView Raw
1var blake2b = require('blake2b')
2
3if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
4
5module.exports.crypto_generichash_PRIMITIVE = 'blake2b'
6module.exports.crypto_generichash_BYTES_MIN = blake2b.BYTES_MIN
7module.exports.crypto_generichash_BYTES_MAX = blake2b.BYTES_MAX
8module.exports.crypto_generichash_BYTES = blake2b.BYTES
9module.exports.crypto_generichash_KEYBYTES_MIN = blake2b.KEYBYTES_MIN
10module.exports.crypto_generichash_KEYBYTES_MAX = blake2b.KEYBYTES_MAX
11module.exports.crypto_generichash_KEYBYTES = blake2b.KEYBYTES
12module.exports.crypto_generichash_WASM_SUPPORTED = blake2b.WASM_SUPPORTED
13module.exports.crypto_generichash_WASM_LOADED = false
14
15module.exports.crypto_generichash = function (output, input, key) {
16 blake2b(output.length, key).update(input).final(output)
17}
18
19module.exports.crypto_generichash_ready = blake2b.ready
20
21module.exports.crypto_generichash_batch = function (output, inputArray, key) {
22 var ctx = blake2b(output.length, key)
23 for (var i = 0; i < inputArray.length; i++) {
24 ctx.update(inputArray[i])
25 }
26 ctx.final(output)
27}
28
29module.exports.crypto_generichash_instance = function (key, outlen) {
30 if (outlen == null) outlen = module.exports.crypto_generichash_BYTES
31 return blake2b(outlen, key)
32}
33
34blake2b.ready(function (_) {
35 module.exports.crypto_generichash_WASM_LOADED = blake2b.WASM_LOADED
36})