AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

constant-time-analysis

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.

Original source
trailofbits
License
CC-BY-SA-4.0
Pinned revision
2be6433b39e009cd2b6fd3be1895f6b1faa5af9a

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

This skill also requires local files or dependencies. Remote reading alone may not be enough.

Ask your assistant

Use Agentic Memory skills to read trailofbits--constant-time-analysis at revision 2be6433b39e009cd2b6fd3be1895f6b1faa5af9a, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 10

README.md

Constant-Time Analysis Skill

A Claude Code skill that detects timing side-channel vulnerabilities in cryptographic code by analyzing assembly or bytecode output for dangerous instructions.

What This Skill Does

When activated, this skill helps Claude:

  • Detect timing vulnerabilities - Identifies variable-time instructions (division, floating-point) that leak secrets through execution timing
  • Analyze across architectures - Tests compiled output for x86_64, ARM64, RISC-V, and other targets
  • Support scripting languages - Analyzes PHP, JavaScript/TypeScript, Python, and Ruby via bytecode
  • Guide constant-time fixes - Provides patterns for Barrett reduction, constant-time selection, and safe comparisons
  • Integrate with CI - Produces JSON output suitable for automated pipelines

Supported Languages

| Language | Analysis Method | Reference Guide | |----------|-----------------|-----------------| | C/C++ | Assembly (gcc/clang) | references/compiled.md | | Go | Assembly (go) | references/compiled.md | | Rust | Assembly (rustc) | references/compiled.md | | Swift | Assembly (swiftc) | references/swift.md | | Java | JVM bytecode (javap) | references/vm-compiled.md | | Kotlin | JVM bytecode (kotlinc + javap) | references/kotlin.md | | C# | CIL (ilspycmd) | references/vm-compiled.md | | PHP | Zend opcodes (VLD/OPcache) | references/php.md | | JavaScript | V8 bytecode (Node.js) | references/javascript.md | | TypeScript | V8 bytecode (tsc + Node.js) | references/javascript.md | | Python | CPython bytecode (dis) | references/python.md | | Ruby | YARV bytecode | references/ruby.md |

Supported Architectures (Compiled Languages)

| Architecture | Division Instructions | Common Use | |--------------|----------------------|------------| | x86_64 | DIV, IDIV | Servers, desktops | | ARM64 | UDIV, SDIV | Mobile, Apple Silicon | | ARM | UDIV, SDIV | Embedded | | RISC-V | DIV, DIVU, REM | Emerging platforms | | PowerPC | DIVW, DIVD | Legacy servers | | s390x | D, DR, DL | Mainframes | | i386 | DIV, IDIV | Legacy |

File Structure

skills/constant-time-analysis/
├── SKILL.md              # Entry point - routing, analyzer usage, triage
├── README.md             # This file
└── references/
    ├── compiled.md       # C, C++, Go, Rust analysis
    ├── swift.md          # Swift analysis
    ├── vm-compiled.md    # Java and C# bytecode, JVM/.NET setup
    ├── kotlin.md         # Kotlin analysis (Android/JVM)
    ├── php.md            # PHP analysis (VLD installation, opcodes)
    ├── javascript.md     # JavaScript/TypeScript analysis
    ├── python.md         # Python analysis (dis module)
    └── ruby.md           # Ruby analysis (YARV)

The analyzer tool is located at ct_analyzer/analyzer.py in the plugin root. Its test suite and samples live in ct_analyzer/tests/:

  • test_samples/ — vulnerable and constant-time inputs for detector tests
  • triage_samples/ — one known-answer fixture per supported language, each pairing true positives with false positives the analyzer cannot distinguish. expectations.json records the verdict and rationale for every case; TestTriageMatrix asserts the analyzer still reports both members of each pair, and fails rather than skipping if no fixture could be exercised.

Usage

The skill activates automatically when Claude detects:

  • Cryptographic code implementation (encryption, signing, key derivation)
  • Questions about timing attacks or constant-time programming
  • Code handling secret keys, tokens, or cryptographic material
  • Functions with division/modulo operations on potentially secret data

You can also invoke it explicitly by asking Claude to check code for timing vulnerabilities.

Example Prompts

"Check this crypto function for timing vulnerabilities"
"Is this signature verification constant-time?"
"Help me replace this division with Barrett reduction"
"Analyze this ML-KEM implementation for KyberSlash-style issues"
"What constant-time patterns should I use here?"

Quick Reference

| Vulnerability | Detection | Fix | |--------------|-----------|-----| | Secret division | DIV, IDIV, SDIV, UDIV | Barrett reduction | | Secret branches | JE, JNE, BEQ, BNE | Bit masking, cmov | | Secret comparison | Early-exit memcmp | crypto/subtle | | Variable-time FP | FDIV, FSQRT | Avoid in crypto |

Real-World Attacks

  • KyberSlash (2023) - Division in ML-KEM leaked keys
  • Lucky Thirteen (2013) - Padding timing in TLS
  • Timing attacks on RSA - Division in modular exponentiation