💼 ConstantTime分析
暗号化されたプログラムを分析し、処理
📺 まず動画で見る(YouTube)
▶ 【自動化】AIガチ勢の最新活用術6選がこれ1本で丸分かり!【ClaudeCode・AIエージェント・AI経営・Skills・MCP】 ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Analyze cryptographic code to detect operations that leak secret data through execution timing variations.
🇯🇵 日本人クリエイター向け解説
暗号化されたプログラムを分析し、処理
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o constant-time-analysis.zip https://jpskill.com/download/2683.zip && unzip -o constant-time-analysis.zip && rm constant-time-analysis.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/2683.zip -OutFile "$d\constant-time-analysis.zip"; Expand-Archive "$d\constant-time-analysis.zip" -DestinationPath $d -Force; ri "$d\constant-time-analysis.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
constant-time-analysis.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
constant-time-analysisフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Constant Time Analysis で、私のビジネスを分析して改善案を3つ提案して
- › Constant Time Analysis を使って、来週の会議用の資料を作って
- › Constant Time Analysis で、現状の課題を整理してアクションプランに落として
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
定数時間解析
暗号コードを分析し、実行時間の変動を通じて秘密データを漏洩させる操作を検出します。
使用する場面
ユーザーが暗号コードを記述していますか? ──はい──> このスキルを使用します
│
いいえ
│
v
ユーザーがタイミング攻撃について尋ねていますか? ──はい──> このスキルを使用します
│
いいえ
│
v
コードが秘密鍵/トークンを扱っていますか? ──はい──> このスキルを使用します
│
いいえ
│
v
このスキルはスキップします
具体的なトリガー:
- ユーザーが署名、暗号化、または鍵導出を実装している場合
- コードに秘密から派生した値に対する
/または%演算子が含まれている場合 - ユーザーが「constant-time」、「timing attack」、「side-channel」、「KyberSlash」に言及している場合
sign、verify、encrypt、decrypt、derive_keyという名前の関数をレビューしている場合
使用しない場面
- 非暗号コード(ビジネスロジック、UIなど)
- タイミングの漏洩が問題とならない公開データの処理
- 秘密、鍵、または認証トークンを扱わないコード
- タイミングがライブラリによって処理される高レベルAPIの使用
言語の選択
ファイル拡張子または言語のコンテキストに基づいて、適切なガイドを参照してください。
| 言語 | ファイル拡張子 | ガイド |
|---|---|---|
| C, C++ | .c, .h, .cpp, .cc, .hpp |
references/compiled.md |
| Go | .go |
references/compiled.md |
| Rust | .rs |
references/compiled.md |
| Swift | .swift |
references/swift.md |
| Java | .java |
references/vm-compiled.md |
| Kotlin | .kt, .kts |
references/kotlin.md |
| C# | .cs |
references/vm-compiled.md |
| PHP | .php |
references/php.md |
| JavaScript | .js, .mjs, .cjs |
references/javascript.md |
| TypeScript | .ts, .tsx |
references/javascript.md |
| Python | .py |
references/python.md |
| Ruby | .rb |
references/ruby.md |
クイックスタート
# サポートされている任意のファイルタイプを分析します
uv run {baseDir}/ct_analyzer/analyzer.py <source_file>
# 条件分岐の警告を含めます
uv run {baseDir}/ct_analyzer/analyzer.py --warnings <source_file>
# 特定の関数にフィルタリングします
uv run {baseDir}/ct_analyzer/analyzer.py --func 'sign|verify' <source_file>
# CI 用の JSON 出力
uv run {baseDir}/ct_analyzer/analyzer.py --json <source_file>
ネイティブコンパイル言語のみ (C, C++, Go, Rust)
# クロスアーキテクチャテスト (推奨)
uv run {baseDir}/ct_analyzer/analyzer.py --arch x86_64 crypto.c
uv run {baseDir}/ct_analyzer/analyzer.py --arch arm64 crypto.c
# 複数の最適化レベル
uv run {baseDir}/ct_analyzer/analyzer.py --opt-level O0 crypto.c
uv run {baseDir}/ct_analyzer/analyzer.py --opt-level O3 crypto.c
VMコンパイル言語 (Java, Kotlin, C#)
# Java バイトコードを分析します
uv run {baseDir}/ct_analyzer/analyzer.py CryptoUtils.java
# Kotlin バイトコード (Android/JVM) を分析します
uv run {baseDir}/ct_analyzer/analyzer.py CryptoUtils.kt
# C# IL を分析します
uv run {baseDir}/ct_analyzer/analyzer.py CryptoUtils.cs
注: Java、Kotlin、C# は、JIT コンパイルを備えた仮想マシン上で実行されるバイトコード (JVM/CIL) にコンパイルされます。アナライザーは、JIT コンパイルされたネイティブコードではなく、バイトコードを直接検査します。--arch および --opt-level フラグはこれらの言語には適用されません。
Swift (iOS/macOS)
# ネイティブアーキテクチャ用の Swift を分析します
uv run {baseDir}/ct_analyzer/analyzer.py crypto.swift
# 特定のアーキテクチャ (iOS デバイス) 用に分析します
uv run {baseDir}/ct_analyzer/analyzer.py --arch arm64 crypto.swift
# 異なる最適化レベルで分析します
uv run {baseDir}/ct_analyzer/analyzer.py --opt-level O0 crypto.swift
注: Swift は C/C++/Go/Rust と同様にネイティブコードにコンパイルされるため、アセンブリレベルの分析を使用し、--arch および --opt-level フラグをサポートしています。
前提条件
| 言語 | 要件 |
|---|---|
| C, C++, Go, Rust | PATH にコンパイラ (gcc/clang, go, rustc) |
| Swift | Xcode または Swift ツールチェーン (PATH に swiftc) |
| Java | PATH に javac と javap を含む JDK |
| Kotlin | PATH に Kotlin コンパイラ (kotlinc) + JDK (javap) |
| C# | .NET SDK + ilspycmd (dotnet tool install -g ilspycmd) |
| PHP | VLD 拡張機能または OPcache を備えた PHP |
| JavaScript/TypeScript | PATH に Node.js |
| Python | PATH に Python 3.x |
| Ruby | --dump=insns サポート付きの Ruby |
macOS ユーザー: Homebrew は Java と .NET を「keg-only」としてインストールします。これらを PATH に追加する必要があります。
# Java の場合 (~/.zshrc に追加)
export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"
# .NET ツールの追加 (~/.zshrc に追加)
export PATH="$HOME/.dotnet/tools:$PATH"
詳細なセットアップ手順とトラブルシューティングについては、references/vm-compiled.md を参照してください。
クイックリファレンス
| 問題 | 検出 | 修正 |
|---|---|---|
| 秘密に対する除算 | DIV, IDIV, SDIV, UDIV | Barrett reduction または逆数による乗算 |
| 秘密に対する分岐 | JE, JNE, BEQ, BNE |
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Constant-Time Analysis
Analyze cryptographic code to detect operations that leak secret data through execution timing variations.
When to Use
User writing crypto code? ──yes──> Use this skill
│
no
│
v
User asking about timing attacks? ──yes──> Use this skill
│
no
│
v
Code handles secret keys/tokens? ──yes──> Use this skill
│
no
│
v
Skip this skill
Concrete triggers:
- User implements signature, encryption, or key derivation
- Code contains
/or%operators on secret-derived values - User mentions "constant-time", "timing attack", "side-channel", "KyberSlash"
- Reviewing functions named
sign,verify,encrypt,decrypt,derive_key
When NOT to Use
- Non-cryptographic code (business logic, UI, etc.)
- Public data processing where timing leaks don't matter
- Code that doesn't handle secrets, keys, or authentication tokens
- High-level API usage where timing is handled by the library
Language Selection
Based on the file extension or language context, refer to the appropriate guide:
| Language | File Extensions | Guide |
|---|---|---|
| C, C++ | .c, .h, .cpp, .cc, .hpp |
references/compiled.md |
| Go | .go |
references/compiled.md |
| Rust | .rs |
references/compiled.md |
| Swift | .swift |
references/swift.md |
| Java | .java |
references/vm-compiled.md |
| Kotlin | .kt, .kts |
references/kotlin.md |
| C# | .cs |
references/vm-compiled.md |
| PHP | .php |
references/php.md |
| JavaScript | .js, .mjs, .cjs |
references/javascript.md |
| TypeScript | .ts, .tsx |
references/javascript.md |
| Python | .py |
references/python.md |
| Ruby | .rb |
references/ruby.md |
Quick Start
# Analyze any supported file type
uv run {baseDir}/ct_analyzer/analyzer.py <source_file>
# Include conditional branch warnings
uv run {baseDir}/ct_analyzer/analyzer.py --warnings <source_file>
# Filter to specific functions
uv run {baseDir}/ct_analyzer/analyzer.py --func 'sign|verify' <source_file>
# JSON output for CI
uv run {baseDir}/ct_analyzer/analyzer.py --json <source_file>
Native Compiled Languages Only (C, C++, Go, Rust)
# Cross-architecture testing (RECOMMENDED)
uv run {baseDir}/ct_analyzer/analyzer.py --arch x86_64 crypto.c
uv run {baseDir}/ct_analyzer/analyzer.py --arch arm64 crypto.c
# Multiple optimization levels
uv run {baseDir}/ct_analyzer/analyzer.py --opt-level O0 crypto.c
uv run {baseDir}/ct_analyzer/analyzer.py --opt-level O3 crypto.c
VM-Compiled Languages (Java, Kotlin, C#)
# Analyze Java bytecode
uv run {baseDir}/ct_analyzer/analyzer.py CryptoUtils.java
# Analyze Kotlin bytecode (Android/JVM)
uv run {baseDir}/ct_analyzer/analyzer.py CryptoUtils.kt
# Analyze C# IL
uv run {baseDir}/ct_analyzer/analyzer.py CryptoUtils.cs
Note: Java, Kotlin, and C# compile to bytecode (JVM/CIL) that runs on a virtual machine with JIT compilation. The analyzer examines the bytecode directly, not the JIT-compiled native code. The --arch and --opt-level flags do not apply to these languages.
Swift (iOS/macOS)
# Analyze Swift for native architecture
uv run {baseDir}/ct_analyzer/analyzer.py crypto.swift
# Analyze for specific architecture (iOS devices)
uv run {baseDir}/ct_analyzer/analyzer.py --arch arm64 crypto.swift
# Analyze with different optimization levels
uv run {baseDir}/ct_analyzer/analyzer.py --opt-level O0 crypto.swift
Note: Swift compiles to native code like C/C++/Go/Rust, so it uses assembly-level analysis and supports --arch and --opt-level flags.
Prerequisites
| Language | Requirements |
|---|---|
| C, C++, Go, Rust | Compiler in PATH (gcc/clang, go, rustc) |
| Swift | Xcode or Swift toolchain (swiftc in PATH) |
| Java | JDK with javac and javap in PATH |
| Kotlin | Kotlin compiler (kotlinc) + JDK (javap) in PATH |
| C# | .NET SDK + ilspycmd (dotnet tool install -g ilspycmd) |
| PHP | PHP with VLD extension or OPcache |
| JavaScript/TypeScript | Node.js in PATH |
| Python | Python 3.x in PATH |
| Ruby | Ruby with --dump=insns support |
macOS users: Homebrew installs Java and .NET as "keg-only". You must add them to your PATH:
# For Java (add to ~/.zshrc)
export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"
# For .NET tools (add to ~/.zshrc)
export PATH="$HOME/.dotnet/tools:$PATH"
See references/vm-compiled.md for detailed setup instructions and troubleshooting.
Quick Reference
| Problem | Detection | Fix |
|---|---|---|
| Division on secrets | DIV, IDIV, SDIV, UDIV | Barrett reduction or multiply-by-inverse |
| Branch on secrets | JE, JNE, BEQ, BNE | Constant-time selection (cmov, bit masking) |
| Secret comparison | Early-exit memcmp | Use crypto/subtle or constant-time compare |
| Weak RNG | rand(), mt_rand, Math.random | Use crypto-secure RNG |
| Table lookup by secret | Array subscript on secret index | Bit-sliced lookups |
Interpreting Results
PASSED - No variable-time operations detected.
FAILED - Dangerous instructions found. Example:
[ERROR] SDIV
Function: decompose_vulnerable
Reason: SDIV has early termination optimization; execution time depends on operand values
Verifying Results (Avoiding False Positives)
CRITICAL: Not every flagged operation is a vulnerability. The tool has no data flow analysis - it flags ALL potentially dangerous operations regardless of whether they involve secrets.
For each flagged violation, ask: Does this operation's input depend on secret data?
-
Identify the secret inputs to the function (private keys, plaintext, signatures, tokens)
-
Trace data flow from the flagged instruction back to inputs
-
Common false positive patterns:
// FALSE POSITIVE: Division uses public constant, not secret int num_blocks = data_len / 16; // data_len is length, not content // TRUE POSITIVE: Division involves secret-derived value int32_t q = secret_coef / GAMMA2; // secret_coef from private key -
Document your analysis for each flagged item
Quick Triage Questions
| Question | If Yes | If No |
|---|---|---|
| Is the operand a compile-time constant? | Likely false positive | Continue |
| Is the operand a public parameter (length, count)? | Likely false positive | Continue |
| Is the operand derived from key/plaintext/secret? | TRUE POSITIVE | Likely false positive |
| Can an attacker influence the operand value? | TRUE POSITIVE | Likely false positive |
Limitations
-
Static Analysis Only: Analyzes assembly/bytecode, not runtime behavior. Cannot detect cache timing or microarchitectural side-channels.
-
No Data Flow Analysis: Flags all dangerous operations regardless of whether they process secrets. Manual review required.
-
Compiler/Runtime Variations: Different compilers, optimization levels, and runtime versions may produce different output.
Real-World Impact
- KyberSlash (2023): Division instructions in post-quantum ML-KEM implementations allowed key recovery
- Lucky Thirteen (2013): Timing differences in CBC padding validation enabled plaintext recovery
- RSA Timing Attacks: Early implementations leaked private key bits through division timing
References
- Cryptocoding Guidelines - Defensive coding for crypto
- KyberSlash - Division timing in post-quantum crypto
- BearSSL Constant-Time - Practical constant-time techniques