Apex › Cryptography

Exponentiation that doesn’t leak (Montgomery ladder)

Computing g^k or k·P bit by bit with square-and-multiply does an extra multiply only on the 1-bits — so a timing or power trace spells out the secret exponent. The Montgomery ladder keeps two registers with the invariant R1 = R0·g and does exactly one multiply + one square per bit, differing only in which register gets which result. Verified in node: the ladder’s result equals naive g^k mod p, and its op-count is always 2·(bit length) regardless of the key’s Hamming weight — a flat, key-independent trace. Used in X25519, ECDSA, and RSA. Compare the leaky and flat traces on any key.

More in Cryptography