public class ECConstantTimeMultiplier extends AbstractECMultiplier
WNafL2RMultiplier - the default multiplier for most curves - is not suitable for a
secret scalar: it selects between two precomputed tables on the sign of a wNAF digit, indexes
those tables directly with the digit's magnitude, and performs a run of doublings whose length
is the number of zeros in the recoding. All three depend on the scalar.
FixedPointCombMultiplier is constant-time but fixed-base only, and its precomputation
is far too expensive to pay per call on the varying point of a key agreement.
This multiplier uses a fixed window instead:
ECLookupTable.lookup(int), which
ECCurve.createCacheSafeLookupTable(ECPoint[], int, int) implements as a masked scan
over the whole table, so the index does not steer a memory access.BigInteger computation on the secret.
The point must lie in the subgroup of the given order: forcing the scalar odd computes
(k + n)P in place of an even kP, and the two agree exactly when the
order of P divides n. Points validated against domain parameters
satisfy this (ECPoint.isValid() includes the order check); a point decoded straight off
the wire on a cofactor curve need not, and for such a point the result differs from
ECPoint.multiply(BigInteger) by nP on even scalars. For the same reason the
order must be odd - true of every standard EC group order, and enforced here, since an even one
would break the recoding silently.
NOTE: every step below is written to avoid branching on, or indexing with, the scalar. Do not
"simplify" the masked selections into conditionals. This class addresses the point arithmetic
only; a caller whose scalar arrives as a BigInteger still exposes that value's
magnitude through the length of its internal representation, and reduction of the scalar
before it reaches here (for example a cofactor adjustment) is outside the guarantee. The
guarantee also stops at the field layer: on the custom curves the field arithmetic is
fixed-length limb arithmetic, but on a generic ECCurve.Fp or F2m curve - brainpool,
the GOST curves, or a caller-built curve - the field operations under the point arithmetic
are BigInteger-based and their timing can vary with operand values.
| Constructor and Description |
|---|
ECConstantTimeMultiplier()
Take the group order from the curve.
|
ECConstantTimeMultiplier(java.math.BigInteger order) |
| Modifier and Type | Method and Description |
|---|---|
protected int |
getWidth(int size)
Window width.
|
protected ECPoint |
multiplyPositive(ECPoint p,
java.math.BigInteger k) |
checkResult, multiplypublic ECConstantTimeMultiplier()
ECNamedCurveTable and
CustomNamedCurves carries one, but a caller-built ECCurve need not - see
ECConstantTimeMultiplier(BigInteger).public ECConstantTimeMultiplier(java.math.BigInteger order)
order - the group order, or null to take it from the curve; must be odd. The recoding
needs the order to force the scalar odd, and ECCurve.getOrder() is null
for a curve built without one - domain parameters always carry it separately,
so a caller that has ECDomainParameters should pass its getN().protected ECPoint multiplyPositive(ECPoint p, java.math.BigInteger k)
multiplyPositive in class AbstractECMultiplierprotected int getWidth(int size)
WNafUtil picks for comparable scalar sizes.