]> git.codecow.com Git - nano25519.git/commitdiff
Update canonical group tests.
authorChris Duncan <chris@codecow.com>
Tue, 6 Oct 2026 03:36:02 +0000 (20:36 -0700)
committerChris Duncan <chris@codecow.com>
Tue, 6 Oct 2026 03:36:02 +0000 (20:36 -0700)
src/assembly/tests.ts

index 865677e26f3c784fb1bf1ca37cee172d4e9caad0..5a818123840e13045756417fdc3ac7506f4e03ef 100644 (file)
@@ -84,9 +84,9 @@ function xpass_ge_is_canonical (vector: i32, data: StaticArray<u8>): void {
        }
 }
 
-function xfail_ge_is_canonical_one (vector: i32, position: i32, mask: i32, data: StaticArray<u8>): void {
+function xfail_ge_is_canonical (vector: i32, t: i32, data: StaticArray<u8>): void {
        if (ge_is_canonical(data)) {
-               raise(ERROR_SELFTEST_XFAIL_ONE, vector, (position << 8) | mask)
+               raise(ERROR_SELFTEST_XFAIL_ONE, vector, t)
        }
 }
 
@@ -97,7 +97,9 @@ function xfail_ge_is_canonical_pair (vector: i32, i: i32, j: i32, data: StaticAr
 }
 
 /**
- * ge_is_canonical must report "non-canonical" for every difference regardless of shape
+ * ge_is_canonical must report "canonical" for every `s` less than `p` and
+ * "non-canonical" for every `s` equal to or greater than `p`.
+ *
  * - `zeros`: lower boundary with every bit cleared
  * - `ones`: upper boundary with every bit set
  * - `spread`: all bytes distinct from each other and setting each bit to 0 or 1
@@ -111,14 +113,14 @@ for (let v = 0; v < expected_ge_is_canonical.length; v++) {
        memory.copy(changetype<usize>(actual), changetype<usize>(expected), KEY_BYTELENGTH)
        xpass_ge_is_canonical(v, actual)
 
-       for (let i = 0; i < KEY_BYTELENGTH; i++) {
+       // verify all 19 non-canonical encodings fail
+       for (let i = 0; i <= 19; i++) {
+               actual[31] -= u8(i)
+               xfail_ge_is_canonical(v, i, actual)
+               actual[31] = expected[i]
+       }
 
-               // verify any individual bit difference fails
-               for (let j = 1; j < 256; j++) {
-                       actual[i] ^= u8(j)
-                       xfail_ge_is_canonical_one(v, i, j, actual)
-                       actual[i] = expected[i]
-               }
+       for (let i = 0; i < KEY_BYTELENGTH; i++) {
 
                // verify |= was not replaced by ^= or += due to a typo
                // invisible to single byte checks, caught only by comparing byte pairs