Class ECConstantTimeMultiplier
- All Implemented Interfaces:
ECMultiplier
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:
- the scalar is forced odd (by adding the group order, which is odd, under a mask) and recoded into a fixed number of odd signed digits, so no digit is zero, and both the iteration count and the number of doublings are independent of the scalar;
- the precomputed table holds the odd multiples and their negations, so a digit's sign is folded into its table index and no conditional point negation is needed;
- table entries are fetched with
ECLookupTable.lookup(int), whichECCurve.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.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTake the group order from the curve. -
Method Summary
Methods inherited from class AbstractECMultiplier
checkResult, multiply
-
Constructor Details
-
ECConstantTimeMultiplier
public ECConstantTimeMultiplier()Take the group order from the curve. Every curve inECNamedCurveTableandCustomNamedCurvescarries one, but a caller-builtECCurveneed not - seeECConstantTimeMultiplier(BigInteger). -
ECConstantTimeMultiplier
- Parameters:
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, andECCurve.getOrder()is null for a curve built without one - domain parameters always carry it separately, so a caller that hasECDomainParametersshould pass itsgetN().
-
-
Method Details
-
multiplyPositive
- Specified by:
multiplyPositivein classAbstractECMultiplier
-
getWidth
protected int getWidth(int size) Window width. The table costs 2^(width-1) point additions to build and the main loop runs ceil(size / width) iterations, so the useful range is narrow; these follow the same shape as the widthsWNafUtilpicks for comparable scalar sizes.
-