Skip to content
Skillpedia
Security8.0k · #12672

constant-time-analysis

What it does

Inspects compiled crypto code for instructions whose speed could reveal secret values, then sorts out which ones really matter. It is for developers and reviewers working on signatures, encryption and key handling.

When to use it

  • ✓When a developer implements or reviews a signature, encryption or key derivation routine.
  • ✓When code divides or takes a remainder of a value derived from a key or secret.
  • ✓When someone asks about constant-time programming or the KyberSlash issue.

Skill link

https://github.com/trailofbits/skills/blob/main/plugins/constant-time-analysis/skills/constant-time-analysis/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/trailofbits/skills/blob/main/plugins/constant-time-analysis/skills/constant-time-analysis/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Check my signing function for timing leaks where secret values might change how fast it runs.”

5 new skills a week. 1 minute to read.

How it works

The skill compiles the code and inspects the assembly or bytecode for slow, variable-time instructions. It then decides which flagged operations actually touch secret values, and explains the language-specific fixes.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Constant-Time Analysis

Compile the code, inspect the emitted assembly or bytecode for variable-time instructions, then decide which of the flagged operations actually touch secrets. The compilation step is mechanical; the triage step is the work.

When to Use

  • Implementing or reviewing a signature, encryption, KEM, or key derivation routine
  • Code applies / or % to a value derived from a key, plaintext, nonce, or token
  • The user mentions "constant-time", "timing attack", "side-channel", or "KyberSlash"
  • Reviewing functions named sign, verify, encrypt, decrypt, derive_key

When NOT to Use

  • Measuring timing variance on a running binary — use the constant-time-testing skill from the testing-handbook-skills plugin, which covers dudect and statistical approaches and may not be installed. This skill inspects compiler output statically and never executes the code under test.
  • Non-cryptographic code, or crypto code where every input is public
  • High-level API usage where a vetted library owns the constant-time guarantees
  • Cache and other microarchitectural side channels — the assembly view cannot see them

Language Routing

Read the guide for the target language before interpreting any findings; each one lists that language's dangerous instructions and the idiomatic constant-time replacements.

Guide Languages
references/compiled.md C, C++, Go, Rust
references/swift.md Swift
references/vm-compiled.md Java, C#
references/kotlin.md Kotlin
references/php.md PHP
references/javascript.md JavaScript, TypeScript
references/python.md Python
references/ruby.md Ruby

Running the Analyzer

The analyzer takes one file and detects the language from its extension. Always pass --warnings:

uv run {baseDir}/ct_analyzer/analyzer.py --warnings <source_file>

Without it the analyzer reports only error-severity findings, which means division, modulo and weak RNG. Four detector families are warning severity and stay silent: secret-dependent branches, early-exit comparison (memcmp, strcmp, .equals, ==), table lookups indexed by a secret, and variable-time encoding. Early-exit comparison of an authentication tag is the most common timing bug in real code — Lucky Thirteen was exactly that — so a default run is quiet about the finding you are most likely to have.

Flag Effect
--warnings Add the four warning-severity families above. Pass it every time
--func <regex> Restrict output to function names matching the regex
--json Machine-readable output
--github GitHub Actions annotations
--arch <target> Target architecture (x86_64, arm64, riscv64, ...) — native languages only
--opt-level <level> Optimization level (O0 through O3, Os, Oz) — native languages only
--compiler <name> Override compiler choice (gcc, clang, go, rustc, swiftc)

Narrow a large file to the routines that handle secrets with a regex, for example --func 'sign|verify'.

Run natively compiled code (C, C++, Go, Rust, Swift) at more than one --arch and --opt-level. Division timing and branch lowering are architecture- and optimization-dependent: x86_64 IDIV and arm64 SDIV differ, and a cmov at -O2 can become a branch at -O0. A single clean run proves one configuration safe, not the code.

How --arch crosses depends on the toolchain. clang crosses with --target and needs no second compiler, but any source that includes libc headers also needs that target's C library headers — libc6-dev-riscv64-cross and friends — or it fails with bits/libc-header-start.h file not found. Go cross-builds through GOARCH, though go tool objdump has no riscv64 disassembler. A GNU cross toolchain is a separate binary, so gcc needs it named explicitly — --compiler x86_64-linux-gnu-gcc, --compiler riscv64-linux-gnu-gcc — and nothing is substituted for you, so the report always names the binary that ran. rustc needs the target's standard library (rustup target add), and Swift on Linux targets only the host. Compare against the toolchain that builds your product, not whichever cross build a distribution packages.

**Re-run the whole

FAQ

Does it run the code to measure timing?

No. It inspects compiler output and never executes the code under test.

Which languages does it support?

The description lists C, C++, Go, Rust, Swift, Java, Kotlin, C#, PHP, JavaScript, TypeScript, Python and Ruby.

Does it find cache-based side channels?

No. The assembly view cannot see cache and other microarchitectural side channels.

Details

Original description by the author

Detects timing side-channel vulnerabilities in cryptographic code. Use when implementing or reviewing crypto code, encountering division on secrets, secret-dependent branches, or constant-time programming questions in C, C++, Go, Rust, Swift, Java, Kotlin, C#, PHP, JavaScript, TypeScript, Python, or Ruby.

repo: trailofbits/skills

Popularity

GitHub stars
8.0k
Ranking position
#12672
License
CC-BY-SA-4.0
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills