← Lab /Security & privacy

LLVM constant-time intrinsics guarantee no timing leaks in compiled crypto code

The __builtin_ct_select intrinsics ensure compiled cryptographic code remains constant-time across all optimization levels and architectures.

Security & privacy Trail of Bits 2 Dec 2025 Defense Prototype evidence

Published as “Introducing constant-time support for LLVM to protect cryptographic code”

Why it matters

Provides a compiler-level mechanism to reliably write constant-time crypto code, reducing the risk of timing side-channel attacks.

Summary

Trail of Bits added a new family of LLVM intrinsics, __builtin_ct_select, that act as a barrier to compiler optimizations and guarantee constant-time execution. The intrinsics are lowered to architecture-specific instructions such as cmov on x86-64 and CSEL on AArch64, with generic fallbacks for other CPUs. Benchmarks conducted with ETH Zürich show 100% preservation of constant-time properties across all tested optimization levels and minimal performance overhead for typical cryptographic operations. The changes are under review for inclusion in LLVM 22 and have already been integrated into libraries like HACL*, Fiat-Crypto, and BoringSSL.

What they found 2

  1. 100% preservation of constant-time properties across all tested optimization levels

    “100% preservation of constant-time properties across all tested optimization levels”

  2. Minimal performance overhead for most cryptographic operations

    “Minimal performance overhead for most cryptographic operations”

Caveats 6

  • The intrinsics are not yet merged into an official LLVM release; they are still under review.
  • Performance impact is described only qualitatively as "minimal" without detailed numbers.
  • Benchmarks are performed by partners at ETH Zürich and may not represent independent evaluation.
  • Changes are pending upstream acceptance and not yet part of a stable LLVM release.
  • Quantitative performance data is not provided; overhead is only described qualitatively.
  • Fallback generic implementation may be less efficient on unsupported architectures.

What’s new here 4

  • Introduces __builtin_ct_select intrinsics to enforce constant-time semantics.
  • Provides architecture-specific lowering (cmov, CSEL) and generic fallback implementations.
  • Upstreaming effort includes community RFC and adoption interest from Rust Crypto, BearSSL, and PuTTY.
  • Benchmarking reports 100% constant-time preservation and minimal overhead across tested libraries.