crypto-protocol-diagram
できること
セキュアな通信プロトコルのソースコード、仕様書、形式モデルを読み、メッセージの流れの図にします。ハンドシェイクや鍵交換を理解する必要があるエンジニアとセキュリティのレビュー担当者向けです。
使う場面
- ✓ハンドシェイク、鍵交換、その他の複数当事者の暗号フローを図にする必要があるとき。
- ✓RFCや論文がプロトコルを説明していて、メッセージの順序を図にしたいとき。
- ✓ProVerifまたはTamarinのモデルがあり、その読みやすい図が欲しいとき。
スキルのリンク
https://github.com/trailofbits/skills/blob/main/plugins/trailmark/skills/crypto-protocol-diagram/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“この鍵交換コードのメッセージの流れを図にしてもらえますか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、誰が誰にどのメッセージを送り、各地点でどの暗号化または署名の処理が行われるかを見つけ、Mermaidのシーケンス図とテキスト版を書きます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Crypto Protocol Diagram
Produces a Mermaid sequenceDiagram (written to file) and an ASCII sequence
diagram (printed inline) from either:
- Source code implementing a cryptographic protocol, or
- A specification — RFC, academic paper, pseudocode, informal prose,
ProVerif (
.pv), or Tamarin (.spthy) model.
Tools used: Read, Write, Grep, Glob, Bash, WebFetch (for URL specs).
Unlike the diagramming-code skill (which visualizes code structure), this skill
extracts protocol semantics: who sends what to whom, what cryptographic
transformations occur at each step, and what protocol phases exist.
For call graphs, class hierarchies, or module dependency maps, use the
diagramming-code skill instead.
When to Use
- User asks to diagram, visualize, or extract a cryptographic protocol
- Input is source code implementing a handshake, key exchange, or multi-party protocol
- Input is an RFC, academic paper, pseudocode, or formal model (ProVerif/Tamarin)
- User names a specific protocol (TLS, Noise, Signal, X3DH, FROST)
When NOT to Use
- User wants a call graph, class hierarchy, or module dependency map — use
diagramming-code - User wants to formally verify a protocol — use
mermaid-to-proverif(after generating the diagram) - Input has no cryptographic protocol semantics (no parties, no message exchange)
Rationalizations to Reject
| Rationalization | Why It's Wrong | Required Action |
|---|---|---|
| "The protocol is simple, I can diagram from memory" | Memory-based diagrams miss steps and invert arrows | Read the source or spec systematically |
| "I'll skip the spec path since code exists" | Code may diverge from the spec — both paths catch different bugs | When both exist, run spec workflow first, then annotate code divergences |
| "Crypto annotations are optional decoration" | Without crypto annotations, the diagram is just a message flow — useless for security review | Annotate every cryptographic operation |
| "The abort path is obvious, no need for alt blocks" | Implicit abort handling hides missing error checks | Show every abort/error path with alt blocks |
| "I don't need to check the examples first" | The examples define the expected output quality bar | Study the relevant example before working on unfamiliar input |
| "ProVerif/Tamarin models are code, not specs" | Formal models are specifications — they describe intended behavior, not implementation | Use the spec workflow (S1–S5) for .pv and .spthy files |
Workflow
Protocol Diagram Progress:
- [ ] Step 0: Determine input type (code / spec / both)
- [ ] Step 1 (code) or S1–S5 (spec): Extract protocol structure
- [ ] Step 6: Generate sequenceDiagram
- [ ] Step 7: Verify and deliver
Step 0: Determine Input Type
Before doing anything else, classify the input:
| Signal | Input type |
|---|---|
Source file extensions (.py, .rs, .go, .ts, .js, .cpp, .c) |
Code |
| Function/class definitions, import statements | Code |
RFC-style section headers (§, Section X.Y, MUST/SHALL keywords) |
Spec |
Algorithm/Protocol/Figure labels, mathematical notation |
Spec |
ProVerif file (.pv) with process, let, in/out |
Spec |
Tamarin file (.spthy) with rule, --[...]-> |
Spec |
| Plain prose or numbered steps describing a protocol | Spec |
| Both source files and a spec document | Both (annotate divergences with ⚠️) |
- Code only → skip to Step 1 below
- Spec only → skip to Spec Workflow (S1–S5) below
- Both → run Spec Workflow first, then use the code-reading steps to verify
the implementation against the spec diagram and annotate any divergences with
⚠️ - Ambiguous → ask the user: "Is this a source code file, a specification document, or both?"
Step 1: Locate Protocol Entry Points
Grep for function names, type names, and comments that reveal the protocol:
# Find handshake, session, round, phase entry points
rg -l "handshake|session_init|round[_0-9]|setup|keygen|send_msg|recv_msg" {targetDir}
# Find crypto primitives in use
rg "sign|verify|encrypt|decrypt|dh|ecdh|kdf|hkdf|hmac|hash|commit|reveal|share" \
{targetDir} --type-add 'src:*.{py,rs,go,ts,js,cpp,c}' -t src -l
Start reading from the highest-level orchestration function — the one that calls into handshake phases or the main protocol loop.
Step 2: Identify Par
よくある質問
どの入力形式が使えますか?
ソースコード、RFC、学術論文、疑似コード、平文の説明、ProVerifとTamarinのモデルファイルが使えます。
図にはメッセージだけでなく暗号の処理も示されますか?
はい。各ステップには、署名や鍵導出などの暗号の操作を含められます。
コードの構造図と同じですか?
いいえ。関数呼び出しやクラスの構造ではなく、プロトコルのメッセージを示します。
詳細
作者による元の説明
Extracts protocol message flow from source code, RFCs, academic papers, pseudocode, informal prose, ProVerif (.pv), or Tamarin (.spthy) models and generates Mermaid sequenceDiagrams with cryptographic annotations. Use when diagramming a crypto protocol, visualizing a handshake or key exchange flow, extracting message flow from a spec or RFC, diagramming a ProVerif or Tamarin model, or drawing sequence diagrams for TLS, Noise, Signal, X3DH, Double Ratchet, FROST, DH, or ECDH protocols.
repo: trailofbits/skills
人気
- GitHubのスター
- 8.0k
- ランキング
- #12726
- ライセンス
- 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、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。