constant-time-analysis
它能做什么
检查编译后的加密代码,查找速度可能泄露秘密值的指令,然后厘清哪些真正重要。适用于开发或审查签名、加密和密钥处理的开发者和审查人员。
适用场景
- ✓开发者实现或审查签名、加密或密钥派生例程的时候。
- ✓代码对由密钥或秘密派生的值进行除法或取余运算的时候。
- ✓有人询问恒定时间编程或 KyberSlash 问题的时候。
技能链接
https://github.com/trailofbits/skills/blob/main/plugins/constant-time-analysis/skills/constant-time-analysis/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请检查我的签名函数,看看秘密值是否可能通过改变运行速度而造成计时泄露。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能会编译代码,并检查汇编或字节码中速度可变的慢指令。然后它判断被标记的操作是否真的涉及秘密值,并解释针对具体语言的修复方法。
技术内容(原始 SKILL.md)
作者在 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-testingskill from thetesting-handbook-skillsplugin, 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
常见问题
它会运行代码来测量时间吗?
不会。它只检查编译器输出,从不执行被测代码。
它支持哪些语言?
描述中列出的语言包括 C、C++、Go、Rust、Swift、Java、Kotlin、C#、PHP、JavaScript、TypeScript、Python 和 Ruby。
它能发现基于缓存的侧信道吗?
不能。汇编视图无法看到缓存和其他微架构侧信道。
详情
作者的原始描述
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
热度
- GitHub 星标
- 8.0k
- 排名
- #12672
- 许可证
- CC-BY-SA-4.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
audit-context-building
8.0k帮你的智能体在安全审查之前熟悉一个陌生的代码库,梳理每个函数的假设、保证和依赖关系。
algorand-vulnerability-scanner
8.0k帮你的智能体扫描 TEAL 或 PyTeal 编写的 Algorand 智能合约,检查 11 类常见安全问题,如重新密钥攻击和未校验费用。
audit-prep-assistant
8.0k帮你的智能体为外部安全审查做好代码准备,包括静态分析、测试覆盖、死代码清理和清晰的文档。
cairo-vulnerability-scanner
8.0k帮你的智能体扫描 StarkNet 上的 Cairo 智能合约,检查 6 类严重问题,包括算术溢出、有风险的跨层消息和签名重放。