Challenges
AES key from shared secret
Cryptography
Medium
DH + AES
Solves: 6
AES key from shared secret
Author: CyberSamSU
Points
50
Diffie-Hellman itself does not encrypt the message — it only generates a shared number. In practice, this number is not used directly as a key: it is first passed through a hash function to obtain a key of a specific length. This step is called KDF (Key Derivation Function).
In our session, the key was derived like this and the message was encrypted with AES-256-CBC:
import hashlib
def kdf(s: int) -> bytes:
return hashlib.sha256(str(s).encode()).digest() # 32 bayt
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
s = pow(B, a, p) # DH umumiy sir
kalit = kdf(s) # 32 bayt -> AES-256
shifr = AES.new(kalit, AES.MODE_CBC, iv).encrypt(pad(xabar, 16))
Alice's secret number a was recovered due to a weak random number generator, and it is provided in the sessiya.txt file along with other parameters. Decrypt the message.
The PyCryptodome library will be needed: pip install pycryptodome
Attached files
sessiya.txt
Log in to download
SHA-256 checksums
sessiya.txt: bf3653dbcb6c27504ec696ee4c8894f0bb17944fe34370b5186f6ebb1ad752d7
To submit a flag, log in.