Security audit: the constant-time checks
Part of the repository security audit (#363). The other crypto stages lean on
two tools to say their code is constant time: tests/ct-asm.js, which reads
the machine code clang -O2 writes for x86-64 and aarch64, and
tests/ct-timing.js, which times the same functions. A check that has never
been shown to fail proves nothing, so this record says what each one claims,
whether it was shown to catch each thing it claims, what it missed, and which
test now pins each property.
Scope
-
tests/ct-asm.js:ctSpecs(the// ct-check:lines),functionBody, theTaintmodel (registers, flags, the stack byte by byte, followed calls),stepX86andstepArm,ctViolations, and the corner lists that run when the module loads. tests/cases/ct_asm_refused: the functions written to fail.-
tests/ct-timing.jsandtests/ct-timing/dudect.c/dudect.h: the driver it generates, the classes, the t-tests, the threshold and the exit codes. -
Since WP38 S5 (at
ea34c4e):tests/ct-asm-runtime.js, its reading ofruntime/runtime-aes.c, and the negative casetests/simd/aes-leaky.c. -
Read, not changed (outside this stage): the
ct_asmblock oftests/run.js(lines 3346–3530 at the base),.github/workflows/ci.ymland.github/workflows/ct-timing.yml, and every othertests/cases/ct_asm_*fixture, each owned by its module's stage.
Threat model
The attacker is the one every constant-time claim is about: they choose public inputs, observe the running time of a secret-handling function (over the network or from a neighbouring process sharing caches and predictors) and want the secret. The function leaks if its control flow, the addresses it touches, or the latency of an instruction it runs depends on a secret.
The adversary of this stage is the checker's own blind spot: an instruction sequence a secret-dependent function compiles to that the checker reads as clean. A false alarm costs a fixture author an afternoon; a false negative is a pass nobody earned, so the model is held to err towards refusing.
Method
-
Read
tests/ct-asm.jsline by line against what it claims in its header: no conditional branch, no call it cannot follow (and so no jump out of the function), no load or store at a secret address. For each step table (X86_*,ARM_*) the question was which instructions it would read as something they are not — a prefix as a mnemonic, a write as a read, a load as an arithmetic op — and each suspicion was written as a hand-built snippet and run throughctViolationson the base checker. Every one that passed there is a finding below; each is now anAUDIT_CORNERSrow. -
Compiled real seeds. Each rule got a Nish function written to break it,
compiled with
build/nish-testandclang -O2 -Sfor both triples, and the listing read by hand to confirm the seed compiles to the violation and only by that route (for example, thatleakyRowstays a separate function on both targets, so the leak incallsLeakis found only by following the call). - Ran the base checker on the new fixture to show what it missed, and the branch's checker on every existing fixture to show no fixture regressed.
-
Read the timing harness against the dudect paper (Reparaz, Balasch,
Verbauwhede, DATE 2017) and its reference implementation's cropping and
second-order schedule; ran
node tests/ct-timing.js --quickand--samples 300000on this machine (Intel Xeon @ 2.80 GHz, a VM), with repeated seeds and with hand-rebuilt drivers to separate a function's own timing from the harness's. -
Read CI:
ci.ymlrunsnpm testonubuntu-latestwith Debian'sclang-18, which carries both targets (clang -print-targets), so both architectures' assembly is read on every pull request — cross-compiled on the x86-64 runner, not on aarch64 hardware.ct-timing.ymlruns the timing harness weekly onubuntu-latestandubuntu-24.04-arm.
Findings
| id | severity | file
|
description | disposition |
|---|---|---|---|---|
| CT-1 | Low | tests/cases/ct_asm_refused.ts, tests/run.js:3528 |
The fixture written to fail seeded two rules (a branch, a secret-indexed load). A store at a secret address, a call to code the checker does not read, a tail call out of the function, and a leak inside a followed call had never been shown refused in real compiler output, and the suite's coverage check asked only for branch and load. |
Fixed: eight seeds, each checked on both targets; SEEDED (tests/ct-asm.js:1314) fails the suite at load if one is deleted or its expect= loosened. |
| CT-2 | Low | tests/ct-asm.js:655, :838 |
No rule for an instruction whose latency follows its operands: a / (secret | 1) compiles to a bare divl / udiv and passed. Integer divide latency is data-dependent on the processors both targets cover (the KyberSlash class). No current fixture divides a secret. |
Fixed: new latency kind for div/idiv, udiv/sdiv and floating divide and square root of a secret; seed secretDivide; corners. |
| CT-3 | Low | tests/ct-asm.js:661 |
An x86 prefix on the instruction's line hid it: notrack jmpq *%rax (what -fcf-protection gives a jump table) read as a data move and passed; lock xaddl likewise. |
Fixed: prefixes are stripped and the instruction behind read; corners notrack jmpq, lock xaddl. |
| CT-4 | Low | tests/ct-asm.js:730 |
xchg, xadd and cmpxchg with memory write their register with what memory held; the model kept the register's own taint, so a secret read this way came out public. |
Fixed: refused as unmodelled; corner. |
| CT-5 | Low | tests/ct-asm.js:735 |
mulx multiplies by %rdx, which it does not name, and writes both registers it does; the model read neither, so a secret multiplier gave a public product. BMI2 is not in the baseline target, so CI never sees it. |
Fixed: modelled; two corners. |
| CT-6 | Low | tests/ct-asm.js:647, :663 |
AVX-512 merge masking ({%k1} without {z}) and instructions that read their destination (vpternlog, vpermt2/vpermi2, vpdp*, vpmadd52*, vpsh[lr]dv) were read as overwriting it, dropping its taint. Not in the baseline target. |
Fixed: read as merges; two corners. |
| CT-7 | Low | tests/ct-asm.js:828, :830 |
aarch64 pointer-authenticated calls and jumps (blraa, blraaz, braa, …) were not calls; blraaz x8 passed. Emitted under -mbranch-protection. |
Fixed; corners. |
| CT-8 | Low | tests/ct-asm.js:826 |
aarch64 bc.<cond> (FEAT_HBC) is a conditional branch and passed. |
Fixed; corner. |
| CT-9 | Low | tests/ct-asm.js:832, :925 |
aarch64 acquire and exclusive loads (ldaxr, ldapr) were not loads, so the register took its address's taint and a secret element came out public; atomics and exclusive stores (ldadd, swp, cas, stxr) were read as arithmetic. |
Fixed: the plain ones are loads; any other memory instruction but a prefetch is unmodelled; corners. |
| CT-10 | Low | tests/ct-asm.js:835 |
aarch64 fccmpe was not a compare: it was read as writing its first operand and left the flags clean, so a csetm after a secret float compare was public. |
Fixed; corner. |
| CT-11 | Low | tests/ct-asm.js:142 |
A ct-check whose secret=contents names a function with no array argument taints nothing and passes whatever the function does. |
Fixed: refused as a spec problem, checked at load. |
| CT-12 | Low | tests/ct-timing.js:73, :440 |
The timing harness had no positive control: every expect= function was left out, so a harness that timed nothing (a call the optimiser dropped, a timer that does not tick) would print "none above". |
Fixed: the expect=branch functions are timed as the control and must differ, or the run fails with exit 2; a filtered run still times them. Measured: naiveEqual |
| CT-13 | High if real; an artefact | tests/cases/ct_asm_x25519.ts:157 (at c8a00d6; ladderStep), std/crypto/x25519.ts, tests/ct-timing.js |
ladderStep measured |
t |
| CT-14 | Low | tests/run.js:3418 |
The check's name says "refused for a conditional branch" for every expect= other than load, so the new call and latency seeds are named as branches in the output (the assertion itself is right). |
Fixed after this stage: each check is named by the promise ctSpecs gives its spec in tests/ct-asm.js: the kind it expects, and the via= callee where there is one, both from the EXPECT_KINDS table ctSpecs also reads its kinds from, so a kind it accepts always has a name. |
| CT-15 | Low | tests/run.js:3376 |
A clang without the aarch64 target turns that half of the check into counted skips; npm test then exits 0 with a "Note", not the DEGRADED banner, since every tool is present. CI's clang has both targets today, but nothing requires it. |
Fixed after this stage: ct_asm: clang targets <target> is a check for each of the two targets, and fails with clang's answer when one is missing; the target's fixtures are not tried again. Shown with a clang that refuses --target=aarch64*: 9 skips and exit 0 before, one failure and exit 1 after. The wasm32 compile, which reads no branches, is still a counted skip. |
| CT-16 | Low | tests/run.js:6488; narrowed at tests/run.js:6441, :9970, tests/ct-asm-runtime.js:214 (at 37566813) |
The checker reads clang -O2 for the baseline CPU only. A program built with another profile or -march is not what was read, and the ISA extensions behind CT-5 and CT-6 never reach it. |
Narrowed (WP38 S2): --cpu x86-64-v3 is the one level a build may take besides the baseline (docs/LANGUAGE.md, "The CPU level"; every other value is refused), and x86-64 is now read at that level too, both the tests/cases/ct_asm_* fixtures and the runtime's kernels, so the AVX2, BMI2 and FMA encodings it permits reach the checker. Every other level, and a profile other than clang -O2, stays unread. x86-64-v4, armv8.2-a and armv8.4-a+crypto were measured for the flag and none is built, so none is accepted and none is read (#1432; wp38-simd.md §7). |
| CT-17 | Low | tests/ct-asm.js:653, :659, :666, :859 (at e3d4da1) |
Found reading vector code for WP38 S5 (below). Five instructions that read their destination were read as overwriting it, so a secret in the destination came out public: pshufb, which the v?pshuf overwrite pattern took with pshufd; the SSE forms of shufps and palignr, in the three-operand overwrite list; movhlps and movlhps, taken as moves; and aarch64's aese and aesd, which XOR their destination with the key before SubBytes. A pshufb by a public mask, the byte reversal every GHASH implementation runs, laundered the block it reversed. No Nish fixture compiles to any of them. |
Fixed: each is read as reading its destination; a corner each in AUDIT_CORNERS, which fail on the base. |
| CT-18 | Low | tests/ct-asm.js:790, :870 (at ea34c4e) |
Found in review of WP38 S5. The SSE4.2 string compares (pcmpistri, pcmpestri, pcmpistrm, pcmpestrm and their v forms) write CF, ZF, SF and OF from their operands, and a register they do not name: an index into %ecx (the i forms) or a mask into %xmm0 (the m forms). preciseFlags' list of instructions that leave the flags alone took them in with every other p… instruction, so a jc or setc after one on a secret read as public; and in either mode the implicit %ecx or %xmm0 kept the taint it had before. The kernels compile to none of them. |
Fixed: they are left out of the keep list, and the step writes %ecx or %xmm0 and the flags with their operands' taint (with %eax and %edx for the e forms); six AUDIT_CORNERS rows that each fail before the fix -- the flags under preciseFlags, the %ecx and %xmm0 writes, an e form whose only secret is the length in %eax, and a secret block read from memory -- each also shown to fail with its own arm of the step deleted where another row does not cover it, and a seventh, a compare on public operands, that must pass. |
| CT-19 | Low | tests/ct-timing.js:431 (at c8a00d6: const differs = r.max > THRESHOLD, one seed); tests/cases/ct_asm_mac.ts:14 (macEqual) |
The weekly run 38205978049 failed on macEqual: |
t |
| CT-20 | Low | tests/ct-asm.js:993 (ARM_READ_MODIFY_WRITE; before the fix it ended …|aese|aesd)$) |
Found reading the SHA-256 kernel for WP38 (crypto-sha256-hw.md). aarch64's sha256h, sha256h2, sha256su0 and sha256su1 accumulate into their destination, and the model read each as overwriting it, so a secret in the destination came out public and a load at its address passed: CT-17's gap, for the four SHA-256 instructions. The runtime check (tests/ct-asm-runtime.js) reads them as reading their destination already, and contents: true makes every word the kernel touches secret, so its verdict on nish_sha256_compress did not depend on it; no Nish fixture compiles to any of them. |
Fixed (#1055): each is read as reading its destination; a corner in AUDIT_CORNERS (sha256su0 into a load address), which fails before the fix. x86-64's sha256msg1, sha256msg2 and sha256rnds2 were already read as reading theirs; three more corners pin that. |
No fixture failed the stricter checker: every function in every
tests/cases/ct_asm_* passes on both targets after CT-2 to CT-11, so none of
those gaps was hiding a leak in code checked today.
Seeded violations
tests/cases/ct_asm_refused now holds one function for each rule, and
tests/run.js checks each on x86-64, on x86-64 at x86-64-v3 and on aarch64 (30 checks):
| function | rule | expected kind | what it compiles to |
|---|---|---|---|
naiveEqual |
conditional branch | branch |
the early-exit loop's jne / b.ne |
indexedLookup |
load at a secret address | load |
movl (%rax,%rsi,4), %eax / ldr w0, [x8, w9, uxtw #2] |
indexedStore |
store at a secret address | load (the kind covers both) |
movl $1, (%rax,%rsi,4) / str w10, [x8, w9, uxtw #2] |
unreadCall |
call to code not read | call |
callq nish_arena_mark, nish_str_from_u64 / bl |
secretText |
tail call out of the function | call |
jmp nish_str_from_u64@PLT / b nish_str_from_u64 |
callsLeak |
leak inside a followed call | load via leakyRow |
four callq leakyRow / bl leakyRow |
tailLeak |
leak inside a followed tail call | load via leakyRow |
jmp leakyRow@PLT / b leakyRow |
secretDivide |
variable-latency instruction | latency |
divl %esi / udiv w0, w0, w8 |
leakyBaseRead |
P-256 comb entry read at the digit's offset | load |
movl (%rcx,%rsi,4), %esi / ldr w11, [x9, w11, sxtw #2] |
leakyDivstep |
P-256 safegcd divstep that tests g's low bit with an if |
branch |
testb $1, %dl then je / tbz w2, #0 |
via=leakyRow is new: a violation found outside the named callee is reported
as load outside leakyRow, so if LLVM ever inlines leakyRow the two checks
fail instead of passing without following anything.
escape (a stack address stored off the stack) and unmodelled have no seed,
because no Nish source reliably compiles to either; they are held by the
hand-written corners in tests/ct-asm.js (STACK_CORNERS, AUDIT_CORNERS).
CT-13: the readings
#378 asked for ladderStep to be
timed on the inputs std/crypto/x25519.ts really gives it, in the full
seven-function driver and linked alone. Every reading below is max |t| over
the harness's tests at 300,000 samples a function, one run a seed, on an
Intel(R) Xeon(R) Processor @ 2.80GHz (/proc/cpuinfo), a 4-vCPU shared
cloud VM, with nothing else running. "Signed domain" is the one the harness
now holds the fixture to (below); "non-negative" is a first, narrower mask
(limbs in [0, 2^26) or [0, 2^25)) that the review of #537 found
under-stated the module's real inputs, and is kept here as a reading.
| fixture and compiler | inputs | driver | ladderStep max |t| |
|---|---|---|---|
this one, build/nish at 69e5fe8 |
signed domain | all seven | 1.90, 1.77, 2.24, 1.47 |
this one, build/nish at 69e5fe8 |
signed domain | ladderStep alone |
2.39, 2.12, 3.13, 2.52 |
this one, build/nish at 69e5fe8 |
non-negative | all seven | 1.66, 2.36, 2.33, 1.72 |
this one, build/nish at 69e5fe8 |
non-negative | ladderStep alone |
2.85, 1.74, 2.74, 1.99 |
this one, build/nish at 69e5fe8 |
out of domain | all seven | 2.09, 1.99, 1.46, 2.46, 2.27, 2.33, 3.22 |
this one, build/nish at 69e5fe8 |
out of domain | ladderStep alone |
2.18, 2.16, 1.56, 2.10 |
| the one CT-13 was read on (0d362c59), the 0.16.0 seed | out of domain | all seven | 2.26, 2.14, 2.36 |
| this one, plus two leaks of the fixture's own (below) | non-negative | all seven and the leaks | 2.07, 1.60 |
| this one, plus two leaks of the fixture's own (below) | out of domain | all seven and the leaks | 1.97, 2.31 |
How each row was taken. Only the "signed domain, all seven" row is a run of
the committed tests/ct-timing.js. Every other row was taken with a harness
that is not committed, and cannot be repeated with the one that is:
-
"out of domain, all seven": three runs with
tests/ct-timing.jsas it is onmainat 69e5fe8, beforeDOMAINSexisted, and four with a scratch copy of this harness whoseDOMAINSlookup was switched off. -
"non-negative": the first version of #537 (a commit squashed into f2fd9ab), whose single
ct_field25519mask is no longer in the tree. -
"
ladderStepalone", in every domain: a scratch copy of the harness that filtered the fixture's specs (and itsDOMAINSentry) toladderStepbefore it wrote the driver. -
the fixture CT-13 was read on:
tests/ct-timing.jsfrom a worktree at 0d362c59, with--nishnaming the 0.16.0 seed. -
the two rows with leaks: the first version of #537's harness, and the scratch copy without
DOMAINS, on the fixture with the two leaks added and then reverted.
The weekly ct-timing.yml run of 2026-10-05 (9552a94, 1,000,000 samples,
out of domain) is the second machine: 1.17 on an INTEL(R) XEON(R) PLATINUM 8573C and 2.09 on the aarch64 runner. In the signed-domain runs the other six
functions read at most 3.74 (fieldSub, once), and fieldSub's 11 did not
recur in any run.
What this establishes. On this VM, on today's fixture, ladderStep does
not differ between the classes, in its domain or out of it, in either link
layout. On the fixture CT-13 was read on, it did not differ in the one
configuration measured there: out of domain, in the full driver. On the two
CI runners it did not differ in the one reading each has: out of domain, in
the full driver, on today's fixture.
clang -O2 compiles ladderStep and the field functions it calls, for x86-64,
to mov, lea, add, sub, neg, and, xor, sar, SSE moves, paddq,
psubq and imulq, and calls to condSwap and fieldMul: no divide and no
branch, which tests/ct-asm.js already pins on both targets, and none of those
is documented as taking an operand-dependent time on current x86-64 cores.
What it did not, at 300,000. The 35–42 was never re-run on the host that
produced it. The harness has not changed since #377, but the fixture has (#426
rewrote its arithmetic in u64, which moves its code and the driver's
layout), and a layout effect on that host is an explanation, not a
measurement. The aarch64 code was not inventoried, and the CI runner's 2.09
was its only reading. So CT-13 stayed open at its severity.
At 1,000,000 samples, with the committed harness. Twenty runs of the
committed tests/ct-timing.js at c90d8fa, --samples 1000000, on the same
VM with nothing else running, one run a cell. "Alone" is --function ladderStep, which links ladderStep with the controls only; "out of domain"
is --out-of-domain, the whole range of the fixture's types, as CT-13 was
read.
| inputs | driver | seed 101 | seed 202 | seed 303 | seed 404 | seed 505 |
|---|---|---|---|---|---|---|
| the module's domain | all seven | 1.57 | 2.35 | 1.73 | 1.92 | 2.49 |
| the module's domain | ladderStep alone |
1.71 | 1.53 | 3.10 | 2.75 | 2.34 |
| out of domain | all seven | 1.59 | 1.78 | 1.84 | 2.13 | 2.22 |
| out of domain | ladderStep alone |
1.34 | 1.87 | 2.04 | 1.70 | 2.19 |
Every run exited 0, no function crossed 4.5 even once, and every control
differed: at seed 101 in the domain, naiveEqual read 2,590 and the three
domain controls 22,780, 25,733 and 699. The weekly runs since read 1.22
(ubuntu-latest, 39201550804) and the readings above it. A difference
between the classes the size of the 35–42 at 300,000 samples grows with the
square root of the sample count, to some 64–77 at 1,000,000; the largest of
these twenty is 3.10.
The aarch64 code is now inventoried too: clang-18 -O2 --target=aarch64-unknown-linux-gnu compiles ladderStep and the six functions
it calls to ldr, ldp, str, stp, add, sub, neg, and, eor,
asr, lsl, mov, movk, movi, dup, mul and madd, bl to the
field functions, and one unconditional b (fieldSquare's tail call into
fieldMul): no divide and no conditional branch, and every one of them is in
Arm's list of instructions whose timing does not depend on their data under
FEAT_DIT. Nothing sets PSTATE.DIT, which is 0 by default, so on aarch64 that
is the cores' behaviour rather than a guarantee.
The verdict: an artefact, not a leak. In 54 runs on this VM since (a VM
of the same class as the one that read 35–42, not that host),
on two versions of the fixture, in both link layouts and on both input ranges,
ladderStep has not read above 3.22, nor above 4.5 on the CI runners of
either architecture in three weekly runs; and its code
on both targets is made only of instructions whose time does not follow their
operands.
The 35–42 is not a property of the function. Its cause on the host that produced it is not measured, and cannot be now: the fixture and the driver it was read in are not the ones in the tree. CT-13 is closed as an artefact and is not counted as a finding. The re-measure rule (below) is not what closes it: the 35–42 repeated on every run, and would have repeated on a fresh seed too, so a reading like it still fails the run.
The harness's domain. A reading on 64-bit limbs is about a function the
module never runs, so DOMAINS in tests/ct-timing.js gives each function
the fixture times the inputs the module gives it, from the bounds
std/crypto/x25519.ts states: f25519Mul and f25519MulA24 are handed the
sum or difference of two reduced elements, signed and below 2^27 in magnitude
(fieldMul, fieldSquare, fieldMulA24); the other functions are handed
reduced elements, below 2^26 in magnitude, limb 1's final carry out of limb 0
included (f25519Carry); and the swap bit is 0 or 1.
ct_signed_limbs in tests/ct-timing/dudect.c makes each secret limb signed
with a magnitude below the bound, after ct_fill, in both classes, so zero
stays zero and the class is still only in ct_fill's mask. The run fails with
exit 2 when a fixture in DOMAINS is gone, when its entry names a function it
does not time or misses one it does, and when an entry narrows a secret its
function does not take or leaves one unnarrowed.
The domain's own controls. For each limb bound and scalar mask a domain
uses, the driver also times a leak written in C (ct_first_nonzero, which
stops at the first non-zero limb, and ct_work_if, which does extra work
when the scalar is non-zero) on a buffer or scalar of its own. Each must
differ like any expect=branch function. What they cover is the narrowing
itself: their prepare lines come from the same emitters as the fixture's
(fillArray, fillScalar), with the same bound or mask from DOMAINS, and
call the same ct_signed_limbs, so a narrowing that erases the secret fails
them.
They do not read the fixture's own lines back; that each of those
narrows the buffer it fills holds by construction, since the emitter is given
one name for both. They are also not the run's control: CT-12's
expect=branch functions are still required, and a run without them fails
with exit 2 whatever the domain controls read. In the signed-domain runs they
read |t| = 4,934–25,611 (limbs) and 380–430 (scalar). With ct_signed_limbs
changed to erase every limb, both limb controls read about 1.7, and with the
swap mask set to 0 the scalar control read 1.52; both runs failed with exit
2.
Two leaks added to the fixture for the first measurement, and not kept, read
the same way through the first mask: limbLeak, which returns at the first
non-zero limb, read |t| = 1,297 and 2,105 narrowed and 1,383 and 656 not;
highBitLeak, which does 200 extra multiplies when bit 40 of limb 0 is set,
read 791 and 1,088 unnarrowed and 1.77 and 0.98 narrowed, which failed the run
with exit 2 as a control that did not differ.
The re-measure rule
CT-19's 5.64 was one excursion in the tail of one percentile, on one seed. Each function is timed 102 ways (uncropped, 100 cropped percentiles and a second-order test), and the harness compares the largest |t| of the 102 with 4.5. The tests share their samples and the cycle counts are quantized, so only 10 to 76 of the 102 are distinct in a run, but that is still the largest of dozens of correlated statistics, on a machine that other tenants share.
The null rate, measured. --null prepares both classes as class 1, so no
class differs and every |t| it prints is noise. Twenty A/A runs on this VM at
1,000,000 samples (seeds 104,729 × 1 to 20) each printed "0 of 50 functions
above |t| = 4.5, 0 of them again". Leaving out the three domain controls, which
time a C leak rather than the fixture, that is 940 function-runs. Their max
|t| had a median of 1.91, a 90th percentile of 2.70, a 95th of 2.96 and a 99th
of 3.46; six were above 3.5, one above 4.0, the largest 4.08 (tableLookup).
None crossing in 940 bounds the rate on this VM below 0.32% a function-run (95%
upper bound); a Gaussian fit to the tail puts it near 0.012%, or about 1% of
weekly runs of some 92 function-runs on two runners.
On the runners themselves, dispatch run 39733213208 of ct-timing.yml
(aa_runs: 10, head 6717ff9) found 0 of 540 function-runs above 4.5 on the
x86-64 runner, an AMD EPYC 9V74, and 0 of 540 on the arm64 runner. None in 540
bounds each runner's rate below 0.55% a function-run (95% upper bound); it does
not make it zero, and CT-19's one crossing in the weekly runs before it stands.
Each timing run now measures its own runner's null as well (the CPU
fingerprint and the same-runner
null).
macEqual beside its neighbours. The 102 tests of each function, dumped
from six runs at 1,000,000 samples (seeds 11 to 66), on this VM:
| function | mean |t| | sd of t | runs' max |t| | tests above 2 |
|---|---|---|---|---|
macEqual |
0.76 | 0.90 | 1.42–2.55 | 1.8% |
tableLookup |
0.50 | 0.64 | 0.2% | |
timingSafeEqual32 |
0.47 | 0.66 | 0.5% | |
timingSafeEqual48 |
0.90 | 1.12 | 5.1% | |
timingSafeEqualAt16 |
0.90 | 1.03 | 9.0% |
macEqual sits inside the spread of the K1 comparisons, which nothing has
read as leaking, and on 20 more seeds (7,919 × 1 to 20) its max |t| was
0.79–2.89. The two classes hand it different answers (both arrays zero, so
0xFFFFFFFF; random, so 0), but it computes the answer with the same
instructions either way. Its 5.64 and 3.35 were both at upper cropped
percentiles (89 and 76) with the uncropped test near zero (-0.92 and 0.35):
the tail of the distribution moved, not its body, which is what an interrupt
or a frequency change on a shared host does.
The rule. A function above 4.5 is timed again, by itself, on a fresh seed:
the same linked driver run with the function's name as a filter, so the layout
it was read in is kept, rather than a driver linked for it alone. The seed is
derived from the run's (seed × 0x9e3779b97f4a7c15 mod 2^64, named on the
table's first line as "re-measured on seed").
The function is a finding, exit 1, only when it crosses on both. One that
crosses once and not again stays in the table with its second |t|, as "crossed
once, did not repeat", and is named in the summary line; the run passes, and
the report job comments on the open ct-timing issue, or opens one when none
is open, so that a function that crosses once every week is seen.
A re-measure seconds later on the same shared runner is not independent of the first, so the rule's own false-positive rate is not claimed beyond what the A/A runs above measured. A large leak is not hidden by it: every control and every leak this record has timed read |t| in the hundreds or thousands, and crosses on any seed. That shows the rule's power for large effects only: a weak leak near the threshold, |t| about 4 to 6, can cross once and not again by chance, which is why a crossed-once row is put in front of a person rather than dropped. The controls are never re-measured: each must differ on its first measurement, or the run fails with exit 2, so a harness that cannot see a leak cannot pass by asking twice. A reading like CT-13's, which repeated on every run, still fails it.
Both branches were shown with a scratch copy of the harness whose threshold
was 1.5, at --quick, seed 7: 21 of 46 functions crossed, 9 read "crossed
once, did not repeat" and were named as such, 12 crossed again and were
named as found on two seeds, the controls differed, and the run exited 1.
The CPU fingerprint and the same-runner null
A |t| means something only beside the machine it was read on and that
machine's noise, so each timing run now carries both (anchors at 1fab4c8,
the parent of the change that adds them; the names are in
tests/ct-timing.js).
The fingerprint. cpuFingerprint prints one line before the table,
ct-timing: CPU (cpu0, from /proc/cpuinfo and sysfs): …, read from the kernel
and never guessed. On x86-64 it names vendor_id, cpu family, model,
stepping, microcode and model name; on aarch64 CPU implementer, CPU part, CPU variant and CPU revision, and MIDR_EL1 from
/sys/devices/system/cpu/cpu0/regs/identification/midr_el1 when it is
readable. A part is named only where it can be cited (ARM_PARTS: implementer
0x41 with 0xd0c Neoverse N1, 0xd40 V1, 0xd49 N2, 0xd4f V2, from each core's
TRM and Linux's cputype.h); any other prints its raw values.
The line also gives the hypervisor flag, the cpufreq boost and intel_pstate
no_turbo state and the kernel release. A field the kernel does not give
prints "unreadable", never a default. On a host with no /proc/cpuinfo the
line reads ct-timing: CPU from os.cpus() only (…) and says what it fell back
to. On this VM it reads:
ct-timing: CPU (cpu0, from /proc/cpuinfo and sysfs): x64 GenuineIntel family 6 model 85 stepping 7 microcode 0x1 "Intel(R) Xeon(R) Processor @ 2.80GHz"; hypervisor flag set; cpufreq boost unreadable; intel_pstate no_turbo unreadable; kernel 6.18.44-fc-v140; 4 logical CPUs
The same-runner A/A pass. After the timing pass, every driver it linked is
run again with --null, on a seed derived from the run's (seed × 0xbf58476d1ce4e5b9 mod 2^64, named on the table's first line as "same-runner
A/A pass on seed"), and a function above 4.5 there is re-measured as the
timing pass's are.
The table gains an A/A |t| column, and a line beside it
reads ct-timing: the same-runner A/A pass: K of N functions above |t| = 4.5 (…), M of them again on a fresh seed. It is printed before the controls are
judged, so a run that fails on a control still says what its null read.
--no-aa leaves the pass out; --null runs never take it, since they are
the null.
It reports and never decides. The exit code is the timing pass's alone: a quiet null does not clear a finding, a noisy one does not excuse it, and the controls must still differ on their first measurement (exit 2).
When the A/A pass crosses on a function the timing pass flagged, once or twice,
the summary line says so: the same-runner A/A pass crossed on … too, so this machine's noise reaches the same function: re-run before reading it as a leak.
The report job of ct-timing.yml puts each runner's fingerprint line and A/A
line above its table in the issue comment, and files a run whose A/A pass
crossed as it files a function that crossed once.
Shown with a scratch copy of the harness whose threshold was 1.5, at
--quick: 38 of 54 functions crossed in the A/A pass and were named, 25 of
the timing pass's flagged functions were named as crossing in it too, and the
run exited 1 on the timing pass's 30 findings, as it would have without the
pass.
What this does not do. The test stays statistical. A same-machine null bounds the rate of false alarms on that machine, on that day; it never makes it zero, and a run with a quiet null can still cross on noise. It does not make a weak leak, |t| near the threshold, visible: such a leak and a noisy null look alike, which is why both are put in front of a person. It says nothing about a CPU the runners never drew (the fingerprint says which ones were), nor about inputs the fixtures never use.
Checked arithmetic and the fixtures
Signed + - * became a checked panic after this record was written
(docs/LANGUAGE.md, "Semantics decisions"), and the check is a conditional
branch, on a secret when the operands are secret.
So the constant-time code does its arithmetic where nothing is checked: secret
sums and products in u32 or u64, which wrap by definition and have the bits
the old signed arithmetic had wherever it did not overflow —
base64urlRangeMask, which both base64 alphabets' character maps in
std/crypto/base64url.ts share (x509's own copy, x509RangeMask, went when
its padded base64 moved there), those maps, and x25519's limbs through
f25519Add64, f25519Sub64 and f25519Mul64, whose bounds the module already
proves in its comments — and the public offsets of the loads and stores the
fixtures read (at + k) in u32 too.
Every fixture's copy changed with its module, and each still passes its link test against the module. A check the compiler proves away — a loop counter, a masked value — is no branch at all, and the fixtures rely on that too.
Loops read whole (WP34 ct-asm)
Until this stage the check refused every conditional branch, so a function
with a loop, even one whose trip count is public, could never pass it, and
every loop in K2, K3 and K4 was held by review. A fixture can now mark a spec
loops (// ct-check: ladderLoopScratch secret=contents loops), and the function
is read with its labels:
-
The walk settles. Each label's taint is the join of every edge into
it, the back edge included, and the walk repeats until no label's state
grows (
settleintests/ct-asm.js). A secret carried round the loop reaches the top of the next pass, so a load it indexes on the second pass is refused like one on the first. Followed callees are read the same way. -
A branch is refused only on secret flags. A loop on a public counter
passes; one that stops on a secret byte is refused as
branch. -
noloop. Aloopsspec must reach a back edge: a branch or jump to a label at or above it, in the function or in a callee the check follows (a callee's back edges count for its caller, sofieldInvert, whose loops are its callees', is read as a loop). One that reaches none is refused: a check that read no loop would pass whatever the loop did, so a spec cannot keep passing after clang unrolls its loop away. A forward branch is not a loop, so the bounds check or length guard an unrolled body keeps does not make one. A function clang does unroll whole is markedbranchesinstead ofloops: read the same way, its branches judged by their flags, no loop claimed for it. -
A panic does not return. A call to a
nish_panic_*function ends its path, since the branch that reaches it has already been judged; a bounds check on a public index passes, and one on a secret index is refused asbranch. Any other call out is stillcall. The model knows a panic by its symbol's name alone, not by anoreturnit reads, so a corner calls one unconditionally ahead of a loop and requiresnoloop: the loop after it is never reached, and its back edge is not counted.
Two rules of the model changed with it, each a false refusal the new targets
met, and each pinned by a STACK_CORNERS row that fails when the rule is
reverted:
-
set<cc>writes one byte. It carries no size suffix, and the model took the width from the operand it could not size:seto 7(%rsp), the spill ofchacha20XorInto's overflow check, smeared secret over the slots beside it. A secret byte it does write is still secret (setobyte, refused asload). -
A narrow read at an index the model cannot place is an element. Such a
read from the stack was taken to be possibly the frame's own pointer to a
stack array, so storing it off the stack was an
escape. Only an eight-byte read can be that pointer; a narrower one is an element of the array and may be stored anywhere. On aarch64 the width is the register's:ldr w9is a four-byte element and passes,ldr x9at the same index may be the pointer and is refused asescape(a pair of corners).
The back-edge rule has its own corners, each made to fail by reverting it:
an unrolled body with only a forward bounds check (noloop); a loop on a
public counter (passes); and a secret carried round the back edge to index a
load on the next pass, through a stack slot and through a register (load).
The functions now read this way, on x86-64, aarch64 and x86-64 at
x86-64-v3, each beside a variant written to leak that must fail:
| module | read with loops (or branches) |
written to fail |
|---|---|---|
std/crypto/chacha20poly1305.ts |
chacha20Core (the twenty rounds), chacha20XorInto, and poly1305Absorb's whole-block loop (ctPoly1305AbsorbWhole) |
ctChacha20XorIntoToZero (stops at a zero byte: branch), ctChacha20SboxStream (a table lookup: load) |
std/crypto/aes.ts |
aesEncryptBatch (the bitsliced block loop, every round); as branches, since clang unrolls them whole and leaves only the length guard, aesPack, aesUnpack and aesSubWord |
aesPackToZeroByte (branch), aesSubWordsByTable (load) |
std/crypto/x25519.ts |
x25519LadderLoop, the 255-step ladder (ladderLoopScratch), f25519SquareTimes, f25519Pow250, f25519Invert, f25519DecodeInto, f25519EncodeInto; with no branch at all, since clang unrolls them whole, x25519LadderStep (ladderStepScratch), f25519Mul (its ten rows written out as f25519MulRow calls, which keeps wide at stack offsets the model places; a rolled row loop stores to it at a counted index, which the model cannot place, and so taints every spill slot) and f25519Square |
ladderLoopToTopBit (branch), indexAfterMul and decodeThroughTable (load), fieldAddUnrolled (noloop) |
The ChaCha20 and AES functions are copies of the module's text, differing
only in export and, for ChaCha20, a ct prefix on each name, and
tests/run.js compares each with its function in the module ("ct_asm's
loop copies match std/crypto/chacha20poly1305.ts", "… std/crypto/aes.ts"),
so an edit to the module that the copy does not take fails the run. The
Absorb copy is the module's function up to its padded tail. The X25519
copies are the module's text through a fixed set of rewrites, each named in
the fixture's header (the module's names mapped to the fixture's, the
short-array early returns, comments and blank lines dropped, and a[i]
written as uncheckedGet or uncheckedSet), and tests/run.js applies them
to the module and requires every copy ("ct_asm_x25519's copies match
std/crypto/x25519.ts"); main also runs X25519 on them against RFC 7748's
vectors. For that, x25519Ladder's loop and step are their own functions in
the module, x25519LadderLoop and x25519LadderStep, and its decode and
encode are split from their allocations (f25519DecodeInto,
f25519EncodeInto). The step and loop take their scratch as ten arrays, past
the six parameters the check places in registers, so the fixture reads them
through ladderStepScratch and ladderLoopScratch, which allocate that
scratch on their own stack as x25519Ladder does. And f25519Mul calls
f25519MulRow once per row rather than looping over the rows: rolled, the
row loop stores into wide on the stack at a counted index, which the model
cannot place, so every spill slot after it (the out pointer among them)
would read as secret, the reason Poly1305's padded tail stays discipline
below. Written out, clang unrolls each row and every store has its offset.
What stays discipline, and why the model cannot read it:
-
Poly1305's padded tail (
poly1305Absorbafter its whole blocks). It copies the last partial block into a zeroed stack block at an index the model cannot place, so the frame's slots after it are taken as possibly secret and every later read of them refused. Only the whole-block loop is read. -
The AES key schedule (
aesScheduleInto,aesKey,aesKeyInto). It allocates its scratch throughnish_arena_mark,memsetandnish_arena_release, calls the model does not follow, and its loop reads those calls' results. Its one non-linear step, SubWord, is read (aesSubWord); the rest is XOR and rotation of words by public offsets. -
The CTR and GCM block loops (
aesCtrInto,aesGcmCtr,ghashBlocksInto,ghashUpdate). They allocate scratch the same way and loop for the message's length around what is read: the bitsliced batch (aesEncryptBatch) and one GHASH multiply (ghashMultiply). -
The seal and open drivers (
chacha20Poly1305SealandOpen,aesGcmSealandOpen, and the tag functions under them). Each allocates its scratch and output through the arena, a call the model does not follow, and branches on public lengths; the tag compare they end in is read (chacha20Poly1305TagMatch,aesGcmTagMask). -
The
wipecalls. A wipe is a volatile store the model does not need to read for constant time; that it survives-O2is pinned bytests/wipes/crypto.js. -
AEAD-4 (crypto-aead.md): what the AES kernels leave in
registers is a wipe question, not a timing one. tests/run.js's "the AES
kernels clear their registers" reads the same
-O2assembly for it: the clear before everyret, and no vector spill outside a wiped buffer. -
--cpubeyondx86-64-v3(WP38 S2): the check reads the baseline andx86-64-v3only.
Functions still held by discipline only
The assembly check reads a function only if a fixture names it. Without
loops it refuses every branch, so most fixtures are copies of each
module's straight-line cores (each kept honest by its .out or link test
against the module's own vectors); the loops copies above are held to the
module's text. What follows is every secret-handling function in std/crypto
that no fixture reads, as a copy or otherwise. Their constant time rests on
review.
-
std/crypto/ct.ts:timingSafeEqual,timingSafeEqualAt, whose loops run for a length. (ct_asm_k1_ctreads copies of their cores:timingSafeEqual's loop unrolled at 32 and 48 bytes, andtimingSafeEqualAt's at a 16-byte window.) -
std/crypto/base64url.ts:base64urlEncode,base64urlDecode: their length-driven loops, the decoder's store guard and the encoder's string building. (ct_asm_k1_base64urlreadsbase64urlCharOfandbase64urlSextetOfverbatim, and one encode group and one decode group, as copies.) -
std/crypto/hmac.ts:hmacPadInto,hmacPadBlock,hmacCheckKey,hmacPadsSha256/384/512,hmacKeySha256/384/512,hmacSha256,hmacSha384,hmacSha512, their*Secretforms,hmacSha256Verify,hmacSha384Verify,hmacSha512Verify,hmacCopySha256,hmacCopySha384, the classesHmacSha256,HmacSha384,HmacSha512,HmacSha256ScratchandHmacSha384Scratch, and PBKDF2:pbkdf2HmacSha256,pbkdf2HmacSha256Exposed,pbkdf2Finish(crypto-k1.md, K1-8). -
std/crypto/hkdf.ts:hkdfSalt,hkdfAppend,hkdfExtractSha256,hkdfExtractSha384,hkdfExpandSha256,hkdfExpandSha384. -
std/crypto/sha256.ts:sha256Compress,sha256LoadWord,sha256CopyBytes,sha256(secret whenever they hash a key, as in HMAC). -
std/crypto/sha512.ts:loadWord,storeWord, the round helpers,sha512,sha384. -
std/crypto/x25519.ts:x25519Ladderitself (its allocation and wipes; the loop it calls is read),f25519Decodeandf25519Encode(their allocations; the work they call is read),x25519Exposed,x25519,x25519Base. (f25519Add,f25519Sub,f25519MulA24,f25519Swap,f25519Mul,f25519Squareandx25519LadderStepare read as copies inct_asm_x25519, and withloopsf25519SquareTimes,f25519Pow250,f25519Invert,f25519DecodeInto,f25519EncodeIntoandx25519LadderLoop.) -
std/crypto/chacha20poly1305.ts:chacha20QuarterRound,chacha20State,chacha20Block,chacha20,chacha20HeaderMask,poly1305Absorb's padded tail,poly1305,poly1305KeyGen,chacha20Poly1305Tag,chacha20Poly1305Seal,chacha20Poly1305Open. (poly1305Clamp,poly1305Block,poly1305Finishandchacha20Poly1305TagMatchare read as copies, and withloopschacha20Core,chacha20XorIntoandpoly1305Absorb's whole blocks.) -
std/crypto/aes.ts: the key schedule (aesScheduleInto,aesKey,aesKeyInto),aesBlockInto,aesEncryptOne,aesEncryptBlock,aesHeaderMask,ghashBlocksInto,ghashUpdate,ghashLengths,aesGcmJ0,aesCtrInto,aesGcmCtr,aesGcmTag,aesGcmSeal,aesGcmOpen. (aesBitslicedRoundwith the helpers it inlines,ghashMultiplyandaesGcmTagMaskare read as copies, withloopsaesEncryptBatch, and asbranchesaesPack,aesUnpackandaesSubWord.) -
std/crypto/p256.ts:p256FiatNonzero,p256FieldInvert,p256ScalarMult,p256BaseMult,p256BaseMultWith,p256LimbsFromBytes,p256LimbsToBytes,p256ScalarInversewith its safegcd helpersp256Safegcd,p256ToSigned30,p256FromSigned30,p256Divsteps30,p256UpdateDe30,p256UpdateFg30,p256AddModulus30andp256Normalize30(shared withp256FieldInvertsince #1430),p256Below,p256ReduceOnce,p256AffineX,p256EncodePoint,p256DigestScalar,p256NonceKey,p256SignScalar,p256PublicKey,p256Sign,p256SignSha256.(The field and scalar multiplies, add, subtract and conditional move, the point doubling and addition, the table move and select, and one window step are read as copies or reshaped copies, as are the signed comb's recoding (
p256BaseRecode, withp256SubBorrow,p256FiatSelectznzandp256FiatScalarAdd, since ECC-7), digit, masked entry move (p256BaseMove), 32-entry signed select, mixed addition and one comb step, and safegcd's thirty divsteps and its two matrix updates:ct_asm_p256'sp256Divsteps30, the module's divstep loop unrolled thirty times, whichtests/run.jsholds to the module's loop body text, andp256UpdateDe30andp256UpdateFg30with their limb loops unrolled. Since ECC-8 the field multiply, square, add and subtract are fiat's 64-bit ones, and their copies read the 64-bit helpers as the module does:p256FiatMulxU64Hi, the add-with-carry and subtract-with-borrow pairs, andp256FiatCmovznzU64, withct-checklines markingp256FiatMulxU64Hi's operands andp256FiatCmovznzU64's condition and choices secret.)p256Verifyhandles only public data.
std/crypto/x509.ts handles public data and is not constant-time code.
The runtime's AES kernels
WP38 S5 adds C to the constant-time surface: runtime/runtime-aes.c (anchors
below at ea34c4e), AES-GCM on AES-NI and PCLMULQDQ or on the ARMv8 AES and
PMULL instructions, which the compiler calls in place of four functions of
std/crypto/aes.ts (the lowering, below, since 7890aee). Unlike every Nish fixture it loops over length, so
tests/ct-asm.js, which refuses every conditional branch, cannot read it.
tests/ct-asm-runtime.js does, on the same taint model: the Taint state and
the per-instruction steps are ct-asm.js's own, so a corner one learns the other
knows.
It compiles the file with clang -O2 -S -ffreestanding for x86-64 and
aarch64 and reads each of nish_aes_schedule (:288), nish_aes_block
(:323), nish_aes_ctr (:327) and nish_aes_ghash (:361), with every
array's elements secret and, for GHASH, hHi and hLo; rounds, length
and the array headers are public. It refuses a conditional branch whose flags
or tested register a secret reaches, and, as ct-asm.js does, a load or store at
a secret address, a call, and a divide of a secret. Two things are added for
code with loops:
-
Control flow. Each label keeps the join of every state that reaches it (a register secret on any edge is secret; a stack place the edges disagree on is unplaced), and the body is walked until no label changes, so what a back edge carries to a loop's head is seen there. The violations are the last walk's.
-
The flags per instruction. ct-asm.js's flags only gain a secret, which would refuse every loop once a block had been XORed. Here
cmp,test,add,sub,and,or,xor,neg,adc,sbb,ptestand(u)comisset the flags to their own taint, moves and the SSE, AES-NI and PCLMULQDQ instructions butptestand the string compares (pcmp[ei]str[im], CT-18) leave them, and everything else, the string compares among them, still only adds.On aarch64 only compares and
s-suffixed instructions write the flags, all four at once. The carry flag is followed apart from the rest (WP38 S10, crypto-chacha20-hw.md): x86-64'sincanddecwrite ZF, SF, OF and PF and leave CF, so a round counter'sdecl; jneafter a secret add reads public, while ajb,setb,adcor any condition that tests CF after it still sees the add's taint. Every other instruction that writes or adds to the flags does so to CF as well.
Each kernel must also show at least one conditional branch, all public, so a
listing with the loops gone cannot pass vacuously, and the functions the unit
exports (its .globl symbols) must be exactly the four kernels and
nish_aes_hw, so a fifth kernel cannot be added unread.
The model's corners for these additions (a public loop bound; a data byte as
the bound; a secret the back edge brings to an index; a forward jump past the
code that cleared a secret; a vector instruction between a compare and its
branch; a shift of a secret before a branch; cbz on a secret; GHASH's H as a
bound) run when the module loads.
tests/simd/aes-leaky.c is the negative case in real compiler
output: nish_aes_leaky_table indexes an S-box by a data byte and
nish_aes_leaky_branch stops at the first zero byte, and each must be refused
for its kind on both targets. Mutating runtime-aes.c itself showed the same:
a loop bound on a keystream byte in nish_aes_ctr was refused as a branch,
and a load from rk at an offset a schedule word picked as a load, on both
targets.
The one dispatch. nish_aes_hw (:446) is not read, and is the one
branch in the unit on anything but a loop bound: on its stored answer, then,
on the first call only, on NISH_AES (getenv, :451) and on the CPU's
feature bits (nish_aes_cpu: CPUID leaf 1's AES, PCLMULQDQ and SSSE3 bits at
:412, AT_HWCAP's AES and PMULL at :423).
Neither depends on a key or data, and the answer is fixed for the life of the
process, so whether a key's operations run the kernel or the bitsliced Nish
code is a property of the machine and its environment, not of the key.
NISH_AES=soft pins the bitsliced path, whose constant time is the Nish code's
own (above).
The lowering (anchors at 7890aee). The compiler asks nish_aes_hw again
in front of each of the four seam calls (src/emit.ts:1443,
emitKernelArm at :1737 today; the seams are recognised by isAesSeam,
src/kernels.ts:89), and branches on its answer: the kernel on one arm, the
bitsliced walker's own call on the other. The branch is the dispatch above,
asked once per call rather than once per process, and its answer is the
stored one after the first call, so it is a branch on the machine and the
environment, never on a key or data.
Every key a process makes is scheduled and used under that one answer, which is
what keeps the kernel's round-key layout and the bitsliced one from meeting in
one array. A wasm32 build (--target wasm32… or --profile wasi) emits the
call as written and references no nish_aes_ symbol. What the branch does not
change: which of the two bodies a call runs is read here (the kernel) or by
ct_asm_aes and the discipline in std/crypto/aes.ts's header (the walker),
and the lowering adds no secret-dependent instruction of its own, only the
call, a compare of its answer with zero and the branch.
What it does not model. The instructions' own timing: AESENC, AESENCLAST, AESKEYGENASSIST and PCLMULQDQ, and AESE, AESMC and PMULL, are taken as data-independent. Intel lists them among the instructions whose latency does not depend on their data (its data operand independent timing list), and Arm among those FEAT_DIT makes so; the kernels do not set PSTATE.DIT, so on aarch64 that is the cores' behaviour rather than a guarantee, and a core where it does not hold is outside this check.
Microcode, frequency effects of the AES units, and the cost of the resolver's
first call, which reads the environment and the CPU but nothing secret. A build
other than clang -O2 for the baseline CPU or x86-64-v3 (CT-16): the speed
profile's -O3 with LTO and the debug profile's -O0 are not what was read,
and -O0 keeps every value on the stack. And what the register allocator
spills: the stack model follows a spill and its reload, but whether a spill
leaves a secret behind is a wipe question. The AES kernels spill no vector
register, and clear the ones they use before they return, which tests/run.js's
"the AES kernels clear their registers" reads in this same assembly
(crypto-aead.md, AEAD-4).
Properties verified
| property | pinned by |
|---|---|
| Every rule the assembly check enforces refuses a real violation, on both targets | ct_asm: ct_asm_refused <fn> on x86-64 / x86-64 at x86-64-v3 / aarch64 (30 checks in npm test) |
No seed can be deleted, or its expect=/via= loosened, silently |
SEEDED in tests/ct-asm.js, checked when the module loads |
| A followed call's leak is found inside the callee, not in inlined code | via=leakyRow on callsLeak and tailLeak; CALL_CORNERS leakVia / leakElsewhere |
A chain of calls deeper than CALL_DEPTH is refused, not followed for ever |
CALL_CORNERS deep |
| Each gap in CT-2 to CT-10, CT-17, CT-18 and CT-20 is refused, and the shapes beside it still pass | AUDIT_CORNERS (37 rows: 19 for CT-2 to CT-10, 5 for CT-17, 7 for CT-18, 4 for CT-20, and 2 for the carry flag dec leaves, a sete that must pass and a setb that must be refused), checked when the module loads |
A loop is read whole: a secret carried round the back edge, a loop that stops on a secret and a secret table index on any pass are refused, a loop on a public counter passes, and a loops spec that reaches no back edge, in it or a callee, is refused (noloop) |
ct_asm: ${name} ${spec.name} on ${at}: ${spec.promise} for every loops and branches spec in ct_asm_chacha20poly1305, ct_asm_aes and ct_asm_x25519, those written to fail among them; the loops rows of STACK_CORNERS (a public and a secret bounds-check panic, an unconditional panic ahead of a loop, an unrolled body with only a bounds check, a public counter loop, a secret carried round the back edge through the stack and through a register, the same unrolled body under branches, and nish_abort still refused as call) |
set<cc> writes one byte, and a narrow read at an unplaceable stack index is an element, not the frame's pointer |
STACK_CORNERS in tests/ct-asm.js, each rule with a row that passes and one that is refused, checked when the module loads |
| The ChaCha20, AES and X25519 fixtures read with labels are the module's text | ct_asm: ct_asm_chacha20poly1305's loop copies match std/crypto/chacha20poly1305.ts, ct_asm: ct_asm_aes's loop copies match std/crypto/aes.ts, ct_asm: ct_asm_x25519's copies match std/crypto/x25519.ts |
| A spec that makes nothing secret is refused | seedMisses in tests/ct-asm.js |
| No existing fixture leaks by the stricter rules | every ct_asm: … no branch, call, secret-indexed access or secret-dependent latency check |
| Each refusal check is named for the kind it expects (CT-14) | EXPECT_KINDS and each spec's promise in tests/ct-asm.js |
| Both targets are read, or the run fails (CT-15) | ct_asm: clang targets x86-64 / aarch64 |
| The timing harness can see a leak it is shown | the control in tests/ct-timing.js; a quiet control is exit 2 |
| A reading above 4.5 is a finding only when it repeats on a fresh seed, and one that does not is still shown (CT-19) | the verdicts "crossed once, did not repeat" and "differs, and again on a fresh seed", the summary's "crossed once and not again: …", and the header's "re-measured on seed" in tests/ct-timing.js; --null's "the A/A run: X of N functions above |t| = 4.5, Y of them again on a fresh seed". Not in npm test: shown by the threshold-1.5 run in the re-measure rule, and run weekly by ct-timing.yml |
| Each timing run names the CPU it ran on and its own runner's null, and the null never changes the verdict | cpuFingerprint's "ct-timing: CPU (cpu0, from /proc/cpuinfo and sysfs)" and "ct-timing: CPU from os.cpus() only", "unreadable" for a field the kernel does not give; the A/A pass's "same-runner A/A pass on seed", "the same-runner A/A pass: " and "the same-runner A/A pass crossed on", and --no-aa, in tests/ct-timing.js; grep '^ct-timing: CPU' and grep 'same-runner A/A pass: ' in ct-timing.yml's report job. Not in npm test: shown by the threshold-1.5 run in the CPU fingerprint and the same-runner null, and run weekly by ct-timing.yml |
runtime/runtime-chacha20.c's nish_chacha20_xor, read the same way, branches only on public values and loads and stores only at public addresses, and the unit exports only it and nish_chacha20_hw (WP38 S10) |
ct_asm: runtime-chacha20.c nish_chacha20_xor on ${target}: no branch on a secret, call, secret-indexed access or secret-dependent latency and ct_asm: runtime-chacha20.c exports on ${target}: exports exactly the kernels read here and nish_chacha20_hw (3 checks each) |
Each runtime/runtime-aes.c kernel, read from clang -O2 for both targets, branches only on public values and loads and stores only at public addresses (WP38 S5) |
ct_asm: ${r.file} ${r.fn} on ${r.target}: ${promises[r.kind]}, the kernel promise "no branch on a secret, call, secret-indexed access or secret-dependent latency" (12 checks: both targets, and x86-64 at x86-64-v3) |
| The unit exports no function the reading leaves out, so a fifth kernel cannot go unread | the same, the exports promise "exports exactly the kernels read here and nish_aes_hw" (3 checks); and exportMisses in tests/ct-asm-runtime.js, which runs at load and requires a sixth .globl to be named unread and a missing kernel to be named missing |
| The runtime check refuses a table lookup and a branch on data in real compiler output | the same, the leak promise refused for ${r.expect} (6 checks, tests/simd/aes-leaky.c) |
| The runtime check's joins and per-instruction flags read loops as they run | CORNERS in tests/ct-asm-runtime.js, checked when the module loads |
| A destination-reading vector instruction keeps its destination's taint (CT-17, CT-20) | AUDIT_CORNERS in tests/ct-asm.js |
The lowered branch runs the kernel and the walker to the same bytes, end to end, and the kernel where the CPU has it (WP38 S5, at 7890aee) |
aes kernel: ${program} prints the same bytes with NISH_AES unset and with NISH_AES=soft, and they are its expected.out, aes kernel: ${program} under NISH_AES=soft calls no kernel and aes kernel: ${program} with NISH_AES unset calls all four kernels, which /proc/cpuinfo says this CPU runs, each for crypto_aes and crypto_aes_agree |
x86-64 is read at the one --cpu level as well as the baseline, or the run fails (CT-16) |
ct_asm: clang targets ${ctTargetName(target)} (${target.triple}), so that ${…} of the check runs, here ct_asm: clang targets x86-64 at x86-64-v3 (x86_64-unknown-linux-gnu), so that level of the check runs; ct_asm: ${name} ${spec.name} on ${at}: ${spec.promise} and ct_asm: ${r.file} ${r.fn} on ${r.target}: ${promises[r.kind]} with x86-64 at x86-64-v3 for the target |
| A wasm32 build references no kernel | aes kernel: --profile wasi compiles crypto_aes_agree to IR and a .wasm that reference no nish_aes_ symbol, and it prints its expected.out |
Doc corrections for the security-policy stage
-
std/README.md, wherever it describes the constant-time check: it also refuses a divide or square root of a secret (latency), and the functions listed above under "held by discipline only" are not read by it. -
docs/LANGUAGE.md, "Constant time": the same addition, and that the check readsclang -O2for the baseline CPU only (CT-16). Since narrowed: it reads x86-64 atx86-64-v3too, anddocs/LANGUAGE.mdsays so. -
tests/run.js:3418(CT-14) and:3376(CT-15) want a fix by whoever owns the harness: name the kind eachexpect=checks, and fail rather than skip when clang cannot target aarch64. Since made: see CT-14 and CT-15 above.

