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に貼り付けるだけ。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つの深刻な問題について検査できるよう支援します。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。