]> git.codecow.com Git - nano25519.git/commitdiff
Update test and agent file.
authorChris Duncan <chris@codecow.com>
Thu, 5 Nov 2026 08:14:45 +0000 (00:14 -0800)
committerChris Duncan <chris@codecow.com>
Thu, 5 Nov 2026 08:14:45 +0000 (00:14 -0800)
AGENTS.md
test/arithmetic.mjs

index ec28a3ab7ef2eaaeef1a3d8283d2c098d63041aa..70423739e20c30d5472ea846f1c8932f18c7aeca 100644 (file)
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -945,7 +945,7 @@ results with `test/reference.mjs`. It covers:
 Point inputs are tight signed limbs, as real callers produce: the
 canonical non-negative form overflows `fe_mul`'s i32 `19·g` lanes on a sum like
 `Y + X`, a false mismatch no caller can trigger. It is seeded, so a failure
-reproduces. Its controls drop `p3_0(r)`, recompute `T` as `X·Y`, and, in one
+reproduces. Its controls make `p1p1_0` leave `T = 0`, recompute `T` as `X·Y`, and, in one
 probe, drop both canonicity checks and the malformed-point term from each of
 the two small-order predicates; each of the six must be seen.
 
index 647ea2c8694982a4bcea5692ce3d5bde720c835e..57104a6b38822e2ceb7c7e16e003fa18aa25eddc 100644 (file)
@@ -69,6 +69,7 @@ import { ge_cache_odd_multiples, ge_double_scalarmult_vartime_to_p3, ge_frombyte
 import { p3, p3_dbl_to_p3, p3_sub_cached_to_p3, p3_tobytes, p_cached } from './ed25519/p'
 import { fe_invert, fe_pow22523 } from './ed25519/z'
 import { sc_is_canonical, sc_muladd, sc_reduce } from './ed25519/sc'
+import { ge_double_scalarmult_vartime_to_cached } from './ed25519/ge/double_scalarmult'
 import { verify_pubkey, verify_signature } from './crypto_verify'
 
 // operand slots for the field operations, addressed by index so any of them can alias
@@ -76,7 +77,7 @@ const F: StaticArray<FieldElement> = StaticArray.fromArray<FieldElement>([fe(),
 const FA = F[0], FB = F[1], FH = F[2]
 const U8A = new StaticArray<u8>(32), U8B = new StaticArray<u8>(32), U8C = new StaticArray<u8>(32), U8D = new StaticArray<u8>(32)
 const U8W = new StaticArray<u8>(64)
-const PA = new p3(), PB = new p3(), PC = new p3(), A2 = new p3()
+const PA = new p3(), PB = new p3(), PC = new p3(), A2 = new p3(), CB = new p_cached()
 const AI: StaticArray<p_cached> = StaticArray.fromArray<p_cached>([new p_cached(), new p_cached(), new p_cached(), new p_cached(), new p_cached(), new p_cached(), new p_cached(), new p_cached()])
 
 export function ptr (id: i32): usize {
@@ -159,13 +160,17 @@ export function ge_double_scalarmult_ (): void {
        ge_cache_odd_multiples(AI, A2, PA)
        ge_double_scalarmult_vartime_to_p3(PB, U8A, AI, U8B)
 }
-export function p3_sub_cached_to_p3_ (): void { p3_sub_cached_to_p3(PC, PA, PB) }
+// as crypto_verify_sodium does it: the same scalars and table into a cached point, subtracted from R in PA
+export function p3_sub_cached_to_p3_ (): void {
+       ge_double_scalarmult_vartime_to_cached(CB, U8A, AI, U8B)
+       p3_sub_cached_to_p3(PC, PA, CB)
+}
 export function verify_pubkey_ (): i32 { return verify_pubkey(U8A) ? 1 : 0 }
 export function verify_signature_ (): i32 { return verify_signature(U8W) ? 1 : 0 }
 `
 
 /** Seeded controls: each `from` must occur once inside its `fn`; an optional `import` line is added to the file. */
-const NO_IDENTITY = [{ file: 'src/assembly/ed25519/ge/double_scalarmult.ts', fn: 'ge_double_scalarmult_vartime_to_p3', from: '\n\tp3_0(r)', to: '' }]
+const NO_IDENTITY = [{ file: 'src/assembly/ed25519/p.ts', fn: 'p1p1_0', from: 'fe_1(h.T)', to: 'fe_0(h.T)' }]
 const STALE_T = [{ file: 'src/assembly/ed25519/ge/double_scalarmult.ts', fn: 'ge_double_scalarmult_vartime_to_p3', from: 'p1p1_to_p3(r, t)', to: 'p1p1_to_p3(r, t)\n\t\t\tfe_mul(r.T, r.X, r.Y)', import: "import { fe_mul } from '../fe'" }]
 const NO_PRECONDITIONS = [
        { file: 'src/assembly/crypto_verify.ts', fn: 'verify_pubkey', from: 'if (ge_is_canonical(pub) != 0) {', to: 'if (false) {' },
@@ -289,7 +294,7 @@ function doubleScalarmult (h, note, count) {
                // R - ([a]A + [b]B), as verify() computes it, with R decoded so Z = 1
                const R = mul(B, randomInt(L))
                setPoint(PA, R)
-               x.p3_sub_cached_to_p3()
+               x.p3_sub_cached_to_p3_()
                const diff = getPoint(PC)
                note('p3_sub_cached_to_p3 of the double scalar multiplication', equal(diff, add(R, negate(want))) && isExtended(diff), k)
        }
@@ -408,7 +413,7 @@ try {
 
        // positive controls
        for (const [name, compiled, expect] of [
-               ['sees [0]A + [0]B left as the previous result without p3_0(r)', noIdentity, { 'ge_double_scalarmult_vartime_to_p3: [0]A + [0]B is the identity': false }],
+               ['sees [0]A + [0]B as a malformed point when p1p1_0 is not the identity', noIdentity, { 'ge_double_scalarmult_vartime_to_p3: [0]A + [0]B is the identity': false }],
                ['sees T recomputed as X·Y, which the point comparison alone does not', staleT, { 'ge_double_scalarmult_vartime_to_p3: point': true, 'ge_double_scalarmult_vartime_to_p3: XY = ZT': false }],
        ]) {
                if (!(compiled instanceof WebAssembly.Module)) {