both use the SelectInto method on the lookup tables, which performs a constant-time table lookup. But here we're already in a variable-time context, so we don't need to spend extra time to protect the table lookups. These calls could be replaced with direct array accesses for better performance.
In fact, the SelectInto methods could be removed entirely for the nafLookupTableN structures, since these structures are only useful in variable-time contexts, as computing the NAF is a variable-time computation.
Unfortunately(?), those SelectInto methods are already implemented as variable time lookups, and are getting inlined, so there is no extra performance to squeeze there.
The variable-time scalar multiplication methods,
VarTimeMultiScalarMult
https://github.com/FiloSottile/edwards25519/blob/main/scalarmult.go#L262-L270
and
VarTimeDoubleScalarBaseMult
https://github.com/FiloSottile/edwards25519/blob/main/scalarmult.go#L197-L215
both use the
SelectInto
method on the lookup tables, which performs a constant-time table lookup. But here we're already in a variable-time context, so we don't need to spend extra time to protect the table lookups. These calls could be replaced with direct array accesses for better performance.In fact, the
SelectInto
methods could be removed entirely for thenafLookupTableN
structures, since these structures are only useful in variable-time contexts, as computing the NAF is a variable-time computation.