]> git.codecow.com Git - nano25519.git/commitdiff
Fix constant time zero check that was incorrect due to AssemblyScript shift operand...
authorChris Duncan <chris@zoso.dev>
Sun, 16 Aug 2026 05:48:43 +0000 (22:48 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 16 Aug 2026 05:48:43 +0000 (22:48 -0700)
src/assembly/utils.ts

index dee20aa97c45f98957252abd63539e2fc2607c63..13c535723595220a80549c804b9015d7f7f286d0 100644 (file)
@@ -37,9 +37,10 @@ export function negative (b: i8): u8 {
 //@ts-expect-error
 @inline
 export function sodium_is_zero (n: StaticArray<u8>, nlen: i32): u8 {
-       let d: u8 = 0
+       let d: i32 = 0
        for (let i: i32 = 0; i < nlen; i++) {
                d |= n[i]
        }
-       return 1 & ((d - 1) >> 8)
+       d &= 255
+       return u8(((d - 1) >> 8) & 1)
 }