AES (Advanced Encryption Standard)
Simmetrik
Qiyin
AES nima?
AES — 2001 yilda NIST tomonidan standart sifatida qabul qilingan blok shifr. 128, 192 yoki 256 bitli kalit ishlatadi. Bugungi kunda Internet xavfsizligining asosi.
AES ishlash principi
1
SubBytes — S-box orqali baytlarni almashtirish
2
ShiftRows — qatorlarni siljitish
3
MixColumns — ustunlarni aralashtirish
4
AddRoundKey — kalit bilan XOR
Bu 4 qadam 10-14 marta (raund soni kalitga bog'liq) takrorlanadi.
AES rejimlari
ECB — Electronic Codebook (Xavfli!)
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
key = b"YELLOW SUBMARINE" # 16 bayt = 128 bit
# Shifrlash
cipher = AES.new(key, AES.MODE_ECB)
plaintext = b"Hello World!!!!!" # 16 bayt (blok o'lchami)
ciphertext = cipher.encrypt(plaintext)
print(ciphertext.hex())
# Deshifrlash
cipher = AES.new(key, AES.MODE_ECB)
decrypted = cipher.decrypt(ciphertext)
print(decrypted.decode())
# MUAMMO: bir xil plaintext → bir xil ciphertext!
# Shuning uchun ECB xavfli — naqsh ko'rinadi
CBC — Cipher Block Chaining (Yaxshiroq)
from Crypto.Random import get_random_bytes
key = get_random_bytes(16)
iv = get_random_bytes(16) # Initialization Vector
# Shifrlash
cipher = AES.new(key, AES.MODE_CBC, iv)
plaintext = b"Salom dunyo! Bu CBC rejimi testi!"
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
# Deshifrlash
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypted = unpad(cipher.decrypt(ciphertext), AES.block_size)
print(decrypted.decode())
CTR — Counter Mode (Zamonaviy)
from Crypto.Cipher import AES
from Crypto.Util import Counter
key = b"YELLOW SUBMARINE"
nonce = 0 # HECH QACHON bir xil nonce ni qayta ishlatmang!
ctr = Counter.new(128, initial_value=nonce)
cipher = AES.new(key, AES.MODE_CTR, counter=ctr)
ciphertext = cipher.encrypt(b"Salom CTR!")
# Xuddi shunday nonce bilan decrypt
ctr = Counter.new(128, initial_value=nonce)
cipher = AES.new(key, AES.MODE_CTR, counter=ctr)
plaintext = cipher.decrypt(ciphertext)
print(plaintext.decode())
CTF da AES hujumlari
🐧 ECB Penguin
ECB da naqshlar ko'rinadi. Rasm faylini AES-ECB bilan shifrlasang, naqsh saqlanadi.
🔮 Padding Oracle
Server padding xatosi bersa, CBC ni bir baytdan buzish mumkin.
♻️ CTR Nonce Reuse
Bir xil nonce ishlatilsa: ct1 XOR ct2 = pt1 XOR pt2
💡 Bu mavzu bo'yicha amaliy mashq qilishni istaysizmi?
Simmetrik challengelarini ko'rish →