constant-time-testing
作者 trailofbitsconstant-time-testing 是一項實用技能,適合用來審查密碼學程式碼中的時間側信道。使用 constant-time-testing 技能可檢查是否存在依秘密資料而變動的分支、記憶體存取模式與微架構行為,再搭配聚焦的 constant-time-testing Security Audit 工作流程指南進行分析。
這個技能得分為 76/100,代表它對於需要密碼學程式碼 constant-time testing 指引的目錄使用者來說,是一個不錯的收錄候選。這個 repository 提供了足夠的實際工作流程內容與領域脈絡,足以支持安裝;不過由於缺少輔助 scripts 與安裝時自動化,使用者需要預期自行閱讀與導覽的比例較高。
- 明確聚焦於密碼學程式碼的 constant-time testing,使用情境清楚,也容易辨識是否適合。
- SKILL.md 內容量相當充足,包含 13 個 H2、24 個 H3 與 code fences,顯示這是實際工作流程而非空殼。
- 沒有 placeholder 或 experimental 標記;文件包含 repo/file 參考與多個工作流程/限制訊號。
- 沒有 install command、scripts 或支援檔案,因此 agents 只能依賴 markdown 指引,無法靠自動執行完成。
- description metadata 非常精簡,使用者可能需要閱讀正文才能確認確切適配度與限制。
constant-time-testing 技能概述
constant-time-testing 是一項實用技能,用來稽核密碼學程式碼是否存在 timing side channels。當你需要確認 secret-dependent branches、memory access patterns 或 microarchitectural behavior 會不會洩漏金鑰、nonce 或其他敏感值時,就該使用 constant-time-testing 技能。
誰適合使用 constant-time-testing
這項技能最適合 security auditors、crypto engineers,以及實作層級密碼學的審查者。當你手上已經有程式碼、測試 harness,或可疑的 hot path,並且需要的是一份聚焦的 constant-time-testing 指南,而不是通用的 secure-coding 清單時,它特別有用。
它解決的是什麼問題
真正要解決的,不是「理論上理解 timing attacks」,而是「找出這段程式在 secret 改變時會不會表現不同」。constant-time-testing 能幫你把這個問題轉成可重複的審查流程:找出敏感輸入、檢查它們影響了哪些 code paths,並設計能揭露 leakage 的測試。
為什麼它有用
它最大的價值在於夠具體。好的 constant-time-testing 技能會把你導向:
- 最關鍵的那幾段程式區域,
- 最容易洩漏的比較與查表型態,
- 以及在判定結果前,你真正需要的證據。
如何使用 constant-time-testing 技能
安裝並開啟來源檔案
進行 constant-time-testing install 時,先從 trailofbits/skills 加入這個技能,然後先讀 SKILL.md。如果你是在 agent workflow 裡使用,還要在撰寫 prompt 前,檢查定義行為或慣例的相鄰 repo 檔案。
先提供正確的輸入形狀
這項技能在你提供具體目標時效果最好,不適合模糊提問。好的輸入包括:
- 要審查的 repository 或檔案路徑,
- 必須保持隱藏的 secret values 或 API calls,
- threat model,例如 local attacker、remote timing observer 或 benchmark noise,
- 以及語言或平台,因為 C、Rust、assembly 與高階語言的洩漏型態不同。
一個強而有力的 prompt 會像這樣:Use constant-time-testing on src/crypto.rs to check whether verify_tag() branches on secret bytes. Assume a remote attacker and report likely leakage points, test ideas, and false positives.
建議的審查流程
實務上,constant-time-testing 的使用方式可以這樣走:
- 找出 secret 以及所有受其影響的 code paths。
- 檢查 branch、early return、table lookup 與 variable-time primitives。
- 測試在 secret-dependent inputs 變化時,行為是否也跟著改變。
- 把真正的 leakage 與 compiler、runtime 或 measurement noise 分開。
- 用精確的 inputs、code locations 與 confidence level 回報結果。
先看這些,效果會更好
優先讀 SKILL.md,接著看 repository 中任何關於 constant-time 檢查、measurement scripts 或 policy notes 的範例。如果 repo 同時包含多個 implementation target,先讀最接近 production stack 的那一個,才能讓 constant-time-testing 指南和你的環境保持一致。
constant-time-testing 技能 FAQ
constant-time-testing 只適用於 crypto libraries 嗎?
不是。只要是 secret-dependent timing 可能有影響的程式都適用,包括 authentication checks、key comparison、secret-bearing formats 的 parsing,以及 protocol logic。用於 Security Audit 的 constant-time-testing 範圍,比純密碼學更廣。
使用前一定要先準備 benchmark 環境嗎?
不一定。你可以先做靜態審查與針對性測試,再視程式路徑是否可疑加入 timing measurements。對許多稽核來說,第一輪重點是縮小可能存在 leakage 的範圍。
這跟一般 prompt 有什麼不同?
一般 prompt 常是在問對 timing attacks 的通用說明。constant-time-testing 更具行動性:它的目的,是推動你針對特定 codebase、特定 secret 與特定 threat model 進行審查,通常能產出更好的 audit 結果。
什麼情況下不該使用它?
如果你需要完整的 dynamic analysis infrastructure、formal verification,或硬體層級認證,就不要只依賴它。它最適合作為聚焦的審查與測試指南,而不是更深入保證方法的替代品。
如何提升 constant-time-testing 技能
把 secret 與不變條件講清楚
最大的品質提升,來自於明確指出哪些內容必須保密、哪些行為不能改變。告訴模型哪些值是敏感的、哪些操作允許變動、哪些 code paths 是 security-critical。這會讓 constant-time-testing 技能的輸出精準很多。
提供程式位置與可疑模式
如果你已經懷疑某個 function、branch 或 lookup table,請直接指出來。像這樣:Inspect verify(), ct_eq(), and the S-box lookup in src/aes.c. 這能減少猜測,並讓輸出更聚焦在最高風險的 leakage 路徑。
要求證據,不要只要判斷
好的結果通常會包含具體的測試計畫:要比較哪些 input pairs、在哪裡做 instrument、什麼情況算 leakage,以及如何解讀 noisy measurements。請明確要求這些產物,讓回答不只停留在「看起來是 constant-time」或「不是 constant-time」。
第一輪之後持續迭代
用第一輪結果來縮小範圍。如果它標出某個 branch,就針對那個 function 再做更窄的 constant-time-testing usage 檢查;如果看起來乾淨,就追問相鄰 helper、compiler effects,或仍可能洩漏的 platform-specific behavior。
