liveBook · Manning

Branching on secret values

As explained in Hacking Cryptography

Branching on secret values is control flow whose selected path depends on private or sensitive data.

Branching on secret values makes control flow depend on private data. Different paths can take measurably different times, allowing timing attacks to recover secrets through side-channel analysis—even without physical probes. section 10.5

Modern processors predict branch directions to keep their pipelines full. Wrong predictions flush pipelines and caches, so speculative execution can preserve timing differences that reveal which path depended on the secret. section 10.5

Branching versus branchless summation

A C loop sums array elements above a threshold with `if (array[i] > threshold)`. A branchless variant uses comparison and conditional-move instructions instead. On an unsorted 100-million-element array, the branchless version runs faster in the recorded test; after sorting, predictable branching runs faster. The performance difference illustrates why predictability matters and why sensitive values should not select control flow.

How Hacking Cryptography covers it

How deep it goes
Explains timing leakage through branch prediction and speculative execution, then demonstrates branchless replacement and measured behavior.
Examples
Uses C array summation, threshold checks, conditional moves, sorting, and measured execution times.
What you can do after
Diagnose secret-dependent control flow and apply branchless implementations when sensitive data influences computation.
How it connects
Connects secret-dependent branching with timing attacks, side-channel analysis, branch prediction, and speculative execution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hacking Cryptography. The section links point to the parts of the book it draws on.