From d0d48c2182c35c69ef65be8d783bab5a0f9cf9fa Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 3 Mar 2025 06:56:20 -0800 Subject: [PATCH] Create DataView on hash message to enable setting endianness. --- src/classes/cpu.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/classes/cpu.ts b/src/classes/cpu.ts index 133b6ea..44fea21 100644 --- a/src/classes/cpu.ts +++ b/src/classes/cpu.ts @@ -14,6 +14,7 @@ export class NanoPowCpu { static #blake2b_sigma: number[][] static #v: BigUint64Array static #m: BigUint64Array + static #mView: DataView static async init (): Promise { if (this.#busy) return @@ -45,6 +46,7 @@ export class NanoPowCpu { ] this.#v = new BigUint64Array(16) this.#m = new BigUint64Array(16) + this.#mView = new DataView(this.#m.buffer) console.log(`NanoPow CPU initialized.`) } catch (err) { throw new Error('NanoPow CPU initialization failed.', { cause: err }) @@ -124,11 +126,11 @@ export class NanoPowCpu { this.#v[12] ^= 40n // Output length // Set up input buffers - this.#m[0] = seed - if (this.#debug) console.log(`seed: ${this.#m[0].toString(16).padStart(16, '0')}`) + this.#mView.setBigUint64(0, seed, true) + if (this.#debug) console.log(`seed: ${this.#m[0].toString(16).padStart(16, '0')} (${this.#m[0]})`) for (let i = 0; i < hash.length; i += 16) { const u64 = hash.slice(i, i + 16) - this.#m[i / 16 + 1] = BigInt(`0x${u64}`) + this.#mView.setBigUint64(i / 2 + 8, BigInt(`0x${u64}`)) } if (this.#debug) console.log('m', this.#m) -- 2.34.1