'use strict'
-// Implementation derived from blake2b@2.1.4
-// Copyright 2017 Emil Bay <github@tixz.dk>
-// Used with permission. See LICENSES/ISC.txt
-// See for details: https://github.com/emilbayes/blake2b
-//
-// Modified in 2024 by Chris Duncan to eliminate dependencies, port to
-// TypeScript, and bundle into web workers.
-// Original source commit: https://github.com/emilbayes/blake2b/blob/1f63e02e3f226642959506cdaa67c8819ff145cd/index.js
-
+/**
+* Implementation derived from blake2b@2.1.4
+* Copyright 2017 Emil Bay <github@tixz.dk>
+* Used with permission. See LICENSES/ISC.txt
+* See for details: https://github.com/emilbayes/blake2b
+*
+* Modified in 2024 by Chris Duncan to eliminate dependencies, port to
+* TypeScript, and bundle into web workers.
+* Original source commit: https://github.com/emilbayes/blake2b/blob/1f63e02e3f226642959506cdaa67c8819ff145cd/index.js
+*/
const BYTES_MIN = 16
const BYTES_MAX = 64
const KEYBYTES_MIN = 16
const SALTBYTES = 16
const PERSONALBYTES = 16
-// 64-bit unsigned addition
-// Sets v[a,a+1] += v[b,b+1]
-// v should be a Uint32Array
+/**
+* 64-bit unsigned addition
+* Sets v[a,a+1] += v[b,b+1]
+* v should be a Uint32Array
+*/
function ADD64AA (v, a, b) {
var o0 = v[a] + v[b]
var o1 = v[a + 1] + v[b + 1]
v[a + 1] = o1
}
-// 64-bit unsigned addition
-// Sets v[a,a+1] += b
-// b0 is the low 32 bits of b, b1 represents the high 32 bits
+/**
+* 64-bit unsigned addition
+* Sets v[a,a+1] += b
+* b0 is the low 32 bits of b, b1 represents the high 32 bits
+*/
function ADD64AC (v, a, b0, b1) {
var o0 = v[a] + b0
if (b0 < 0) {
(arr[i + 3] << 24))
}
-// G Mixing function
-// The ROTRs are inlined for speed
+/**
+* G Mixing function
+* The ROTRs are inlined for speed
+*/
function B2B_G (a, b, c, d, ix, iy) {
var x0 = m[ix]
var x1 = m[ix + 1]
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
]
-// These are offsets into a uint64 buffer.
-// Multiply them all by 2 to make them offsets into a uint32 buffer,
-// because this is Javascript and we don't have uint64s
+/**
+* These are offsets into a uint64 buffer.
+* Multiply them all by 2 to make them offsets into a uint32 buffer,
+* because this is Javascript and we don't have uint64s
+*/
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }))
-// Compression function. 'last' flag indicates last block.
-// Note we're representing 16 uint64s as 32 uint32s
+/**
+* Compression function. 'last' flag indicates last block.
+* Note we're representing 16 uint64s as 32 uint32s
+*/
var v = new Uint32Array(32)
var m = new Uint32Array(32)
function blake2bCompress (ctx, last) {
0, 0, 0, 0 // 60: personal
])
-// Creates a BLAKE2b hashing context
-// Requires an output length between 1 and 64 bytes
-// Takes an optional Uint8Array key
+/**
+* Creates a BLAKE2b hashing context
+* Requires an output length between 1 and 64 bytes
+* Takes an optional Uint8Array key
+*/
function Blake2b (outlen: number, key?: Uint8Array, salt?: Uint8Array, personal?: Uint8Array) {
// zero out parameter_block before usage
parameter_block.fill(0)
Blake2b.prototype.final = Blake2b.prototype.digest
-// Updates a BLAKE2b streaming hash
-// Requires hash context and Uint8Array (byte array)
+/**
+* Updates a BLAKE2b streaming hash
+* Requires hash context and Uint8Array (byte array)
+*/
function blake2bUpdate (ctx, input: Uint8Array) {
for (var i = 0; i < input.length; i++) {
if (ctx.c === 128) { // buffer full ?
}
}
-// Completes a BLAKE2b streaming hash
-// Returns a Uint8Array containing the message digest
+/**
+* Completes a BLAKE2b streaming hash
+* Returns a Uint8Array containing the message digest
+*/
function blake2bFinal (ctx, out: Uint8Array) {
ctx.t += ctx.c // mark last block offset
function toHex (n: number) {
if (typeof n !== 'number')
- throw new TypeError(`expected number to convert to hex, received convert ${typeof n}`)
+ throw new TypeError(`expected number to convert to hex, received convert ${typeof n}`)
if (n < 0 || n > 255)
throw new RangeError(`expected byte value 0-255, received ${n}`)
return n.toString(16).padStart(2, '0')