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
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 {
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) {' },
// 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)
}
// 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)) {