← Back to section · Foundations of Cryptography
Scalar Multiplication: How Double-and-Add Computes kP
Scalar multiplication is the engine of elliptic-curve cryptography. This article walks through binary double-and-add, the Montgomery ladder, windowing and NAF representations, and explains why side channels force implementations to make the operation sequence independent of the secret.
Every elliptic-curve protocol ultimately reduces to one operation: given a base point and an integer of about 256 bits, compute , that is, add to itself times. The difficulty is the size of — adding one by one would take about point additions, more than the age of the universe allows; and the inverse problem, ECDLP, demands that recovering from be equally infeasible. The forward direction must be fast and the reverse direction slow, and this seemingly contradictory pair of requirements is met simultaneously by the binary method. This article covers the forward half: how is actually computed.
Binary expansion: the double-and-add method
The idea is isomorphic to fast exponentiation. Write in binary as ; then , and the values can be generated iteratively — — each step requiring just one doubling of the previous result. There are two equivalent ways to run the algorithm: scanning from the most significant bit down, maintain an accumulator, doubling at each step and adding the base point whenever the current bit is 1; or scanning from the least significant bit up, repeatedly doubling the base point while accumulating the selected multiples into the result.
The cost is immediately computable: a 256-bit scalar needs about 256 doublings, and the number of additions equals the number of 1 bits in the binary representation, about 128 on average. Fewer than four hundred point operations in total, against naive additions — a leap from “impossible” to “microseconds”. ECDLP is hard precisely because this forward shortcut has no reversible counterpart: given and , there is no analogous “bit-by-bit peeling” that reads out the bits of one at a time.
The Montgomery ladder: making the trace independent of the secret
Double-and-add has a detail that is fatal in engineering terms: when a bit is 0 only a doubling happens, and when it is 1 an extra addition happens, so the operation sequence directly leaks the Hamming weight and even the bit pattern of the scalar. Timing and power measurements can read this trace with ease — it is the classic entry point for side-channel attacks against smart cards and embedded chips.
The Montgomery ladder is the standard remedy. The algorithm always maintains a pair of points preserving the invariant , processing bits from the most significant down: whether the current bit is 0 or 1, exactly one doubling and one addition are performed, only the order and the targets are swapped. The work per bit and the shape of the timing are therefore identical for every bit, and the trace no longer contains any information about the scalar. Curve25519’s Montgomery form is a natural match for this ladder: the ladder advances using only the x-coordinate of points, eliminating even the storage and recovery of y-coordinates, which is why X25519 implementations can be both short and naturally constant-time. Of course, the ladder only settles the question of whether the sequence depends on the secret; the field arithmetic inside each individual point operation must also be constant-time, or the bits will leak at a finer granularity.
Two other roads to speed: precomputation and representations
When the base point is fixed (for example, when both parties in ECDH multiply the same base point ), one can precompute tables of and process the scalar in windows of width , looking up and accumulating segment by segment — this is the window method: larger windows mean fewer additions, at the price of bigger precomputation tables and storage. When the base point is arbitrary, sliding windows and signed representations are more common. NAF (non-adjacent form) deserves a mention: it rewrites the scalar using digits with no two nonzero digits adjacent, reducing the nonzero density from one half to one third; since subtracting a point costs almost the same as adding it (just negate the y-coordinate), the number of additions drops by about a quarter. For specific curves there are even more specialized tricks: curves with an efficiently computable endomorphism, such as secp256k1, can use the GLV method to split one 256-bit scalar into two roughly 128-bit “half-scalars” processed in parallel, saving nearly half the doublings again.
Coordinate systems: expelling division from the loop
Every point addition in the formulas requires one field inversion, and an inversion in a 256-bit modular field costs as much as dozens of multiplications. If every addition inverted, inversions would dominate the total bill for scalar multiplication. The standard practice is to switch to projective or Jacobian coordinates: represent an affine point by a triple and rewrite the formulas using only multiplications and additions, so that the entire scalar-multiplication loop performs no inversion at all and inverts exactly once at the end to convert back to affine coordinates. The price is more multiplications per point operation, but the total bill drops dramatically. The geometric picture is completely indifferent to this — projective coordinates are just another way of bookkeeping the same points — yet it is an indispensable part of every high-performance implementation.
The scalar itself needs handling: reduction and segmentation
There is one more easily overlooked layer of preprocessing. The scalar does not need to be aligned with the group order : by the periodicity of the group, always holds, so a scalar of any length can first be reduced modulo before entering the main loop, capping the loop length at the bit length of . Conversely, if an implementation skips the reduction and processes an over-long scalar directly, it not only wastes work but may leak information through an input-dependent loop length. Another common technique is to cut the scalar into fixed-width segments processed in parallel pipelines, or, in multi-scalar multiplication settings (such as computing simultaneously during batch verification), to use a joint sparse representation so that two scalars share one chain of doublings and each decides its own additions — this “multi-scalar multiplication” is key to the performance of pairing and aggregated-signature verification, and its intellectual source is still the binary expansion of this article: do the doublings once, distribute the additions as needed.
Summary
The story of scalar multiplication is a chain of compressions: binary expansion presses an exponential accumulation down to a few hundred point operations, the change of coordinates expels inversion from each point operation, windowing and NAF shave off a substantial constant factor, and the Montgomery ladder ensures that the trace of all this computation does not leak the scalar itself. The hardness of ECDLP gives elliptic-curve cryptography its security; this body of algorithm engineering gives it speed and implementation safety — lacking either, ECC would not be what it is today. The next article changes perspective to the curve itself: how are the field, coefficients, base point and order chosen, and where do different curves disagree?
Tags: Elliptic CurvesScalar MultiplicationSide Channels