Elliptic Arithmetic 07: Side-Channel Safe Group Operations
Elliptic arithmetic notes / 07
Side-channel safe group operations
Algebraic correctness determines the returned point. A leakage contract additionally controls what the execution reveals about the scalar and intermediate coordinates.
For fixed public inputs, the constant-time model used here requires the branch trace and memory addresses to be independent of secrets. The supported target must also avoid secret-dependent instruction timing. Returned values and error signals form a separate observable interface, whose permitted information is specified by the protocol.
Constant-time swap
static void fe256_swap(fe256_t *a, fe256_t *b, uint32_t bit) {
uint32_t mask = 0u - bit;
for (uint32_t i = 0; i < P256_WORDS; i++) {
word_t t = mask & (a->v[i] ^ b->v[i]);
a->v[i] ^= t;
b->v[i] ^= t;
}
}
Preconditions: bit is 0 or 1, and a and b designate disjoint fe256_t objects or the same object; partial overlap is excluded. Identical pointers give t = 0 in every iteration and leave the object unchanged. The compiler must preserve the secret-independent branch and memory-access pattern; inspect generated code for the target toolchain when this primitive protects secrets.
Incomplete formulas and secret states
A branching wrapper for the mixed Jacobian formula tests whether \(H=0\). If \(H\) is secret, that branch reveals whether the two finite input points have the same affine x-coordinate, hence whether they are equal or inverse. Three ways to handle the exceptional states are:
- prove the exceptional cases cannot occur in the scalar algorithm;
- use complete formulas for the selected curve/model;
- compute the generic, doubling, and infinity candidates as needed and select with masks.
For the first option, the scalar-loop invariant must imply the formula’s preconditions at every iteration, including initialization and leading zero bits.
Two failure examples
Secret bit branch. A left-to-right double-and-add loop with if (bit) add() performs one addition per nonzero scalar bit. Total timing can reveal the Hamming weight, while sufficiently detailed branch or power traces can reveal the positions of those bits.
Secret table index. A fixed-window routine that reads table[window] exposes a secret-dependent address. Cache observations can distinguish the accessed locations at the cache’s observable granularity. A full scan with conditional moves makes the sequence of table addresses independent of the window.
Public versus secret data
Public-key validation can branch on decoded public coordinates. Multiplication by a secret scalar must also protect intermediate point states: a fixed scalar-bit loop does not justify branches on whether an accumulator is infinity. ECDSA verification may use variable-time arithmetic when the signature, public key, and message-derived scalars are public; signing requires protection for its secret nonce and private key.
API rule
int p256_mul_public(p256_affine_t *r, const word_t k_public[P256_WORDS], const p256_affine_t *p_public);
int p256_mul_secret(p256_affine_t *r, const word_t k_secret[P256_WORDS], const p256_affine_t *p_public);
Separate APIs make review easier. If a function accepts a secret scalar, its documentation must state the leakage model, supported targets, and constant-time guarantees.
Algebraic and leakage checks
SageMath checks group-law results against exact arithmetic. C-level analysis, compiler inspection, and platform measurements check the leakage-sensitive execution paths. The two forms of evidence establish different parts of the implementation contract.
p = 17
E = EllipticCurve(GF(p), [2, 2])
P = E(5, 1)
print(13*P)
print(14*P)
