1 | var blake2b = require('blake2b')
|
2 |
|
3 | if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
|
4 |
|
5 | module.exports.crypto_generichash_PRIMITIVE = 'blake2b'
|
6 | module.exports.crypto_generichash_BYTES_MIN = blake2b.BYTES_MIN
|
7 | module.exports.crypto_generichash_BYTES_MAX = blake2b.BYTES_MAX
|
8 | module.exports.crypto_generichash_BYTES = blake2b.BYTES
|
9 | module.exports.crypto_generichash_KEYBYTES_MIN = blake2b.KEYBYTES_MIN
|
10 | module.exports.crypto_generichash_KEYBYTES_MAX = blake2b.KEYBYTES_MAX
|
11 | module.exports.crypto_generichash_KEYBYTES = blake2b.KEYBYTES
|
12 | module.exports.crypto_generichash_WASM_SUPPORTED = blake2b.WASM_SUPPORTED
|
13 | module.exports.crypto_generichash_WASM_LOADED = false
|
14 |
|
15 | module.exports.crypto_generichash = function (output, input, key) {
|
16 | blake2b(output.length, key).update(input).final(output)
|
17 | }
|
18 |
|
19 | module.exports.crypto_generichash_ready = blake2b.ready
|
20 |
|
21 | module.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 |
|
29 | module.exports.crypto_generichash_instance = function (key, outlen) {
|
30 | if (outlen == null) outlen = module.exports.crypto_generichash_BYTES
|
31 | return blake2b(outlen, key)
|
32 | }
|
33 |
|
34 | blake2b.ready(function (_) {
|
35 | module.exports.crypto_generichash_WASM_LOADED = blake2b.WASM_LOADED
|
36 | })
|