Legrandin / pycryptodome

A self-contained cryptographic library for Python
https://www.pycryptodome.org
Other
2.74k stars 492 forks source link

AES CFB mode and AES OFB mode have different first block given same key and IV. #785

Closed trung109 closed 7 months ago

trung109 commented 7 months ago

Hello, I tried the code AES encryption with 2 modes CFB and OFB:

from Crypto.Cipher import AES

key = bytes.fromhex('00112233445566778899aabbccddeeff')
iv = bytes.fromhex('00112233445566778899aabbccddeeff')
msg = bytes.fromhex('00112233445566778899aabbccddeeff')

def encrypt(mode, msg):
    cipher = AES.new(key,mode, iv=iv)
    enc = cipher.encrypt(msg)
    return enc.hex()

print(encrypt(AES.MODE_CFB, msg))
print(encrypt(AES.MODE_OFB, msg))

But i got 2 different ciphertexts, wouldn't it be the same according to Wiki?

62a121ba20c02a034a5d5986c2ecbdb6
62e75b8d6fa5bf46ec87a9276f9df54d