]> git.codecow.com Git - nano25519.git/commitdiff
Pass ge object instead of pointer for A.
authorChris Duncan <chris@zoso.dev>
Sat, 29 Aug 2026 07:25:22 +0000 (00:25 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 29 Aug 2026 07:25:22 +0000 (00:25 -0700)
src/assembly/crypto_verify.ts
src/assembly/index.ts

index d2876f553d5b8a75581df03e65cdec2a4708a065..b10df30d7419cc13ee0a49ec44ddb404d346258d 100644 (file)
@@ -24,10 +24,9 @@ const check_r = new StaticArray<u8>(32)
  * Verify public key `pub` can be decoded.
  * @returns 0 if public key fails to decode, else return pointer to A
  */
-export function crypto_verify_decodepubkey (pub: StaticArray<u8>): usize {
+export function crypto_verify_decodepubkey (pub: StaticArray<u8>): ge_p3 | null {
        // fail if public key cannot be decoded
-       if (ge_frombytes_negate_vartime(A, pub) != 0) return 0
-       return changetype<usize>(A)
+       return (ge_frombytes_negate_vartime(A, pub) != 0) ? null : A
 }
 
 /**
@@ -43,7 +42,7 @@ export function crypto_verify_decodepubkey (pub: StaticArray<u8>): usize {
  * set `A` for the scalar multiplication step before checking `sB = R + hA`.
  * @returns -1 if signature fails to verify, else return 0 if signature is good
  */
-export function crypto_verify_relaxed (s: StaticArray<u8>, M: StaticArray<u8>, A: usize, pub: StaticArray<u8>): i32 {
+export function crypto_verify_relaxed (s: StaticArray<u8>, M: StaticArray<u8>, A: ge_p3, pub: StaticArray<u8>): i32 {
 
        // fail if private scalar `S` is out of range (`2²⁵³ ≤ S`)
        if ((s[63] & 224) != 0) return -1
index c66fd8b065af475e4afbf391a72b06d19e2d7ff9..8905fad2892aa35af90970b536d8c84ceddca954 100644 (file)
@@ -218,7 +218,7 @@ export function verify_blocks (count: i32): void {
 
        // Verify public key before proceeding with signature verification
        const A = crypto_verify_decodepubkey(pub)
-       if (A != 0) {
+       if (A != null) {
                // Iterate over block signature/hash pairs
                for (let i = 0, ptr = changetype<usize>(INPUT_MSG); i < count; i++, ptr += SIGNEDBLOCK_BYTELENGTH) {
                        // Copy block signature/hash from message buffer to locals