]> git.codecow.com Git - nano25519.git/commitdiff
Reorder methods.
authorChris Duncan <chris@codecow.com>
Thu, 8 Oct 2026 15:51:13 +0000 (08:51 -0700)
committerChris Duncan <chris@codecow.com>
Thu, 8 Oct 2026 15:51:13 +0000 (08:51 -0700)
scripts/blake2b-gen.mjs
src/assembly/ed25519/blake2b.ts

index 528e98d87d345eb9a6982fe71facd7a4e41e16ed..ef53f62df7d93e43009a24bab09794178ec9bc01 100644 (file)
@@ -229,8 +229,8 @@ const BLAKE2b = `//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.co
 
 export class Blake2b {
 ${DECLARATIONS}
-${INIT}
 ${COMPRESS}
+${INIT}
        // input: variable-length message bytes passed by user to be hashed
        update (input: StaticArray<u8>, length: i32): Blake2b {
                const input_ptr: usize = changetype<usize>(input)
index 4d77d677ee8b0344330f3965721edf8dd0b475de..119918a0c4eb3641b68d95667c03680effeb1178 100644 (file)
@@ -17,35 +17,6 @@ export class Blake2b {
        c: u8 = 0
        t: u64 = 0
 
-       init (): Blake2b {
-               // reset buffers and counters
-               this.b.fill(0)
-               this.h.fill(0)
-               this.p.fill(0)
-               this.c = 0
-               this.t = 0
-
-               // initialize parameter block
-               this.p[0] = 64 // always 64 bytes for this implementation
-               this.p[1] = 0 // no key
-               this.p[2] = 1 // fanout
-               this.p[3] = 1 // depth
-
-               // initialize hash state
-               const p_ptr = changetype<usize>(this.p)
-
-               this.h[0] = 0x6a09e667f3bcc908 ^ load<u64>(p_ptr, 0)
-               this.h[1] = 0xbb67ae8584caa73b ^ load<u64>(p_ptr, 8)
-               this.h[2] = 0x3c6ef372fe94f82b ^ load<u64>(p_ptr, 16)
-               this.h[3] = 0xa54ff53a5f1d36f1 ^ load<u64>(p_ptr, 24)
-               this.h[4] = 0x510e527fade682d1 ^ load<u64>(p_ptr, 32)
-               this.h[5] = 0x9b05688c2b3e6c1f ^ load<u64>(p_ptr, 40)
-               this.h[6] = 0x1f83d9abfb41bd6b ^ load<u64>(p_ptr, 48)
-               this.h[7] = 0x5be0cd19137e2179 ^ load<u64>(p_ptr, 56)
-
-               return this
-       }
-
        // COMPRESS
        // Defined in BLAKE2 section 2.4
        compress (src: usize, isFinal: u64): void {
@@ -985,6 +956,34 @@ export class Blake2b {
                this.h[7] ^= v7 ^ v15
        }
 
+       init (): Blake2b {
+               // reset buffers and counters
+               this.b.fill(0)
+               this.h.fill(0)
+               this.p.fill(0)
+               this.c = 0
+               this.t = 0
+
+               // initialize parameter block
+               this.p[0] = 64 // always 64 bytes for this implementation
+               this.p[1] = 0 // no key
+               this.p[2] = 1 // fanout
+               this.p[3] = 1 // depth
+
+               // initialize hash state
+               const p_ptr = changetype<usize>(this.p)
+
+               this.h[0] = 0x6a09e667f3bcc908 ^ load<u64>(p_ptr, 0)
+               this.h[1] = 0xbb67ae8584caa73b ^ load<u64>(p_ptr, 8)
+               this.h[2] = 0x3c6ef372fe94f82b ^ load<u64>(p_ptr, 16)
+               this.h[3] = 0xa54ff53a5f1d36f1 ^ load<u64>(p_ptr, 24)
+               this.h[4] = 0x510e527fade682d1 ^ load<u64>(p_ptr, 32)
+               this.h[5] = 0x9b05688c2b3e6c1f ^ load<u64>(p_ptr, 40)
+               this.h[6] = 0x1f83d9abfb41bd6b ^ load<u64>(p_ptr, 48)
+               this.h[7] = 0x5be0cd19137e2179 ^ load<u64>(p_ptr, 56)
+
+               return this
+       }
        // input: variable-length message bytes passed by user to be hashed
        update (input: StaticArray<u8>, length: i32): Blake2b {
                const input_ptr: usize = changetype<usize>(input)