Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

配布ファイルに署名する

リリース情報を書いたファイルを配布し、利用者がその内容と署名者を検証できるようにします。配布元は署名鍵を保管し、利用者は信頼できる経路で検証鍵を入手します。ファイル、署名、検証鍵をまとめて差し替えられる経路だけに頼ると、配布元を識別できません。

Python 環境を準備してから、リポジトリのルートで実行します。

python docs/examples/sign.py
from quantaegis import MlDsa65, VerificationError

verify_key, signing_key = MlDsa65.keygen()
manifest = b"release=1.0"
context = b"release-manifest-v1"
signature = MlDsa65.sign(signing_key, manifest, ctx=context)

# Recipient
MlDsa65.verify(verify_key, manifest, signature, ctx=context)
print("Verified signature")

try:
    MlDsa65.verify(verify_key, b"release=2.0", signature, ctx=context)
except VerificationError:
    print("Rejected modified manifest")
else:
    raise AssertionError("Unexpected success with a different message")

最初の検証は正常に終了してVerified signatureと表示されます。次は同じ署名でバージョン番号だけを変えた本文を検証するため、VerificationError が発生します。ctx はアプリケーションが定める用途名で、検証側も同じ値を指定します。実ファイルを扱う場合は両側でファイルをバイト列として読み込み、改行や文字コードも含めて署名時の内容を保ちます。ML-DSA の仕組み · Python API