refactor: extract GLV endomorphism and wNAF encoding into Glv.kt

Splits the 914-line Point.kt into two focused files:

- Glv.kt (248 lines): GLV endomorphism constants, scalar decomposition
  (splitScalar), Babai rounding (mulShift384), and wNAF encoding. This is
  a self-contained algorithm that only operates on scalars (no EC points).

- Point.kt (683 lines): EC point types, core operations (double, addMixed,
  addPoints), scalar multiplication (mul, mulG, mulDoubleG), coordinate
  conversion (toAffine, liftX), and key serialization.

Each file has a comprehensive header explaining its purpose and the
algorithms it implements. The Point.kt header is updated to reflect the
current state (GLV and wNAF are implemented, not "future optimizations").

mulDoubleG now references Glv.splitScalar and Glv.wnaf instead of local
methods. GlvTest updated to use the Glv object directly.

No functional changes — pure file reorganization with updated documentation.

https://claude.ai/code/session_01BhU63WUe9AhikZxRdw3Lpg
This commit is contained in:
Claude
2026-04-05 20:03:38 +00:00
parent 3cbe6ee73b
commit 7a96a11f6e
3 changed files with 278 additions and 250 deletions
@@ -48,7 +48,7 @@ class GlvTest {
.map { it.toInt(16).toByte() }
.toByteArray(),
)
val split = ECPoint.scalarSplitLambda(k)
val split = Glv.splitScalar(k)
val k1 = if (split.negK1) ScalarN.neg(split.k1) else split.k1
val k2 = if (split.negK2) ScalarN.neg(split.k2) else split.k2
val reconstructed = ScalarN.add(k1, ScalarN.mul(k2, LAMBDA))
@@ -88,9 +88,9 @@ class GlvTest {
.map { it.toInt(16).toByte() }
.toByteArray(),
)
val split = ECPoint.scalarSplitLambda(k)
val split = Glv.splitScalar(k)
val gOdd = Array(8) { ECPoint.gTable[it * 2] }
val digits = ECPoint.wnaf(split.k1, 5, 129)
val digits = Glv.wnaf(split.k1, 5, 129)
var bits = digits.size
while (bits > 0 && digits[bits - 1] == 0) bits--