new DataView(b).setUint32(0, index, false)
const s = new Uint8Array(seed)
const i = new Uint8Array(b)
- const sk = new Blake2b(32).update(s).update(i).digest()
+ const sk = new this(32).update(s).update(i).digest()
return Promise.resolve(sk.buffer)
}
}
#G (r: number, i: number, a: number, b: number, c: number, d: number): void {
- this.#v[a] += this.#v[b] + this.#m[Blake2b.SIGMA[r][2 * i + 0]]
+ this.#v[a] += this.#v[b] + this.#m[(this.constructor as typeof Blake2b).SIGMA[r][2 * i + 0]]
this.#v[d] ^= this.#v[a]
this.#v[d] = (this.#v[d] >> 32n) | (this.#v[d] << 32n)
this.#v[c] += this.#v[d]
this.#v[b] ^= this.#v[c]
this.#v[b] = (this.#v[b] >> 24n) | (this.#v[b] << 40n)
- this.#v[a] += this.#v[b] + this.#m[Blake2b.SIGMA[r][2 * i + 1]]
+ this.#v[a] += this.#v[b] + this.#m[(this.constructor as typeof Blake2b).SIGMA[r][2 * i + 1]]
this.#v[d] ^= this.#v[a]
this.#v[d] = (this.#v[d] >> 16n) | (this.#v[d] << 48n)
this.#v[c] += this.#v[d]
// init work variables
for (let i = 0; i < 8; i++) {
this.#v[i] = this.#h[i]
- this.#v[i + 8] = Blake2b.IV[i]
+ this.#v[i + 8] = (this.constructor as typeof Blake2b).IV[i]
}
// lo 64 bits of counter
*/
constructor (length: number, key?: Uint8Array<ArrayBuffer>, salt?: Uint8Array<ArrayBuffer>, personal?: Uint8Array<ArrayBuffer>)
constructor (length: unknown, key?: unknown, salt?: unknown, personal?: unknown) {
+ const B = this.constructor as typeof Blake2b
if (length == null) {
throw new TypeError(`length is required`)
}
if (typeof length !== 'number') {
throw new TypeError(`length must be number`)
}
- if (length < Blake2b.OUTBYTES_MIN || length > Blake2b.OUTBYTES_MAX) {
- throw new RangeError(`length must be ${Blake2b.OUTBYTES_MIN}-${Blake2b.OUTBYTES_MAX} bytes`)
+ if (length < B.OUTBYTES_MIN || length > B.OUTBYTES_MAX) {
+ throw new RangeError(`length must be ${B.OUTBYTES_MIN}-${B.OUTBYTES_MAX} bytes`)
}
if (key != null) {
if (!(key instanceof Uint8Array)) {
throw new TypeError(`key must be Uint8Array or Buffer`)
}
- if (key.length < Blake2b.KEYBYTES_MIN || key.length > Blake2b.KEYBYTES_MAX) {
- throw new RangeError(`key must be ${Blake2b.KEYBYTES_MIN}-${Blake2b.KEYBYTES_MAX} bytes`)
+ if (key.length < B.KEYBYTES_MIN || key.length > B.KEYBYTES_MAX) {
+ throw new RangeError(`key must be ${B.KEYBYTES_MIN}-${B.KEYBYTES_MAX} bytes`)
}
}
if (salt != null) {
if (!(salt instanceof Uint8Array)) {
throw new TypeError(`salt must be Uint8Array or Buffer`)
}
- if (salt.length !== Blake2b.SALTBYTES) {
- throw new RangeError(`salt must be ${Blake2b.SALTBYTES} bytes`)
+ if (salt.length !== B.SALTBYTES) {
+ throw new RangeError(`salt must be ${B.SALTBYTES} bytes`)
}
}
if (personal != null) {
if (!(personal instanceof Uint8Array)) {
throw new TypeError(`personal must be Uint8Array or Buffer`)
}
- if (personal.length !== Blake2b.PERSONALBYTES) {
- throw new RangeError(`personal must be ${Blake2b.PERSONALBYTES} bytes`)
+ if (personal.length !== B.PERSONALBYTES) {
+ throw new RangeError(`personal must be ${B.PERSONALBYTES} bytes`)
}
}
// initialize hash state
for (let i = 0; i < 8; i++) {
- this.#h[i] = Blake2b.IV[i] ^ this.#parameter_view.getBigUint64(i * 8, true)
+ this.#h[i] = B.IV[i] ^ this.#parameter_view.getBigUint64(i * 8, true)
}
// key the hash, if applicable