- Category: Crypto
- Score: 500/500
- Solves: 4/286
- Solves(MFCTF): 1/124
Recommended readings: https://en.wikipedia.org/wiki/Digital_Signature_Algorithm https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm
這題可以使用 DSA sign 任意的資料 16 次,目標是要取得 private key 把 flag 解密。DSA nonce k 的部分使用的是一個特殊的方法生成的 deterministic nonce:
def H(m: bytes):
return sha1(m).digest()
def gen_k(m: bytes, x: int):
# generate a deterministic nonce
k = H(m + long_to_bytes(x))
while len(k) < 256:
# ensure k is long enough to prevent lattice attacks
k += H(k + long_to_bytes(x))
return bytes_to_long(k) % q
DSA 中只要知道一個 signature 的
解題關鍵在於
可見
儘管 server 限制了訊息的長度不可超過 512 bytes,這限制了你直接把整個 pdf 當作訊息傳給 server。但從這邊的圖片可以知道其實 collision 的是 pdf 的前 320 bytes 而已,因此將兩個 pdf 的前 320 bytes 作為
而出現重複的
其中
唯一要注意的一個小地方是
詳見 solve.py。