From d7e0d0b1f55c43c9627cd84ae6ec820cb629ad90 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 14 Feb 2026 22:59:58 -0800 Subject: [PATCH] Simplify index calculations with addition and bitwise ops instead of multiplication. --- src/lib/crypto/blake2b.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/crypto/blake2b.ts b/src/lib/crypto/blake2b.ts index 871b0c2..71253f9 100644 --- a/src/lib/crypto/blake2b.ts +++ b/src/lib/crypto/blake2b.ts @@ -77,13 +77,13 @@ export class Blake2b { } #G (r: number, i: number, a: number, b: number, c: number, d: number): void { - this.#v[a] += this.#v[b] + this.#m[(this.constructor as typeof Blake2b).SIGMA[r][2 * i + 0]] + this.#v[a] += this.#v[b] + this.#m[(this.constructor as typeof Blake2b).SIGMA[r][i + i]] 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[(this.constructor as typeof Blake2b).SIGMA[r][2 * i + 1]] + this.#v[a] += this.#v[b] + this.#m[(this.constructor as typeof Blake2b).SIGMA[r][i + 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] @@ -130,7 +130,7 @@ export class Blake2b { // copy input buffer to message block const buf = new DataView(this.#b.buffer) for (let i = 0; i < 16; i++) { - this.#m[i] = buf.getBigUint64(i * 8, true) + this.#m[i] = buf.getBigUint64(i << 3, true) } // twelve rounds of mixing @@ -266,7 +266,7 @@ export class Blake2b { // initialize hash state for (let i = 0; i < 8; i++) { - this.#h[i] = B.IV[i] ^ this.#parameter_view.getBigUint64(i * 8, true) + this.#h[i] = B.IV[i] ^ this.#parameter_view.getBigUint64(i << 3, true) } // key the hash, if applicable -- 2.47.3