@@ -27,6 +27,7 @@ def test_aes_decryption_ECB(data, key, file_name, expected):
2727
2828 assert result == expected
2929
30+
3031@pytest .mark .parametrize ("data,key,file_name,iv,expected" , [
3132 # 128 bit
3233 (b'\xe4 \xa7 \x0e \xbd \x84 \xfa \xf5 \xd8 `\xb8 \xa1 \x10 \x0b ~\xad h\x89 Feso\xc5 ~_|\xe9 \x1b G\xd9 *\\ \x81 ' , "2b7e151628aed2a6abf7158809cf4f3c" , "tmp1.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890' ),
@@ -53,6 +54,7 @@ def test_aes_decryption_CBC(data, key, file_name, iv, expected):
5354
5455 assert result == expected
5556
57+
5658@pytest .mark .parametrize ("data,key,file_name,iv,expected" , [
5759 # 128 bit
5860 (b'\xe4 \xa7 \x0e \xbd \x84 \xfa \xf5 \xd8 `\xb8 \xa1 \x10 \x0b ~\xad hJ\xa9 8\x9f \xce Z\xd4 \x9f "\xde \x00 \xf6 w\xa9 \x1b \x05 ' , "2b7e151628aed2a6abf7158809cf4f3c" , "tmp1.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890' ),
@@ -78,3 +80,30 @@ def test_aes_decryption_PCBC(data, key, file_name, iv, expected):
7880 os .remove (file_name )
7981
8082 assert result == expected
83+
84+
85+ @pytest .mark .parametrize ("data,key,file_name,iv,expected" , [
86+ # 128 bit
87+ (b'a\xcc T\xf8 \xac [\x05 \x8e \xe3 97\xe9 \x9b \xaf \xec `\xd9 \xa4 \xda \xda \x08 \x92 #\x9f k\x8b =v\x80 \xe1 Vr' , "2b7e151628aed2a6abf7158809cf4f3c" , "tmp1.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890' ),
88+ (b'a\xcc T\xf8 \xac [\x05 \x8e \xe3 9\x06 \xdb \xa8 \x9b \xd9 V\xd9 \xa4 \xda \xda \x08 \x92 #\x9f k\x8b =v\x80 \xe1 Vt' , "2b7e151628aed2a6abf7158809cf4f3c" , "tmp2.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890123456' ),
89+ (b'a\xcc T\xf8 \xac [\x05 \x8e \xe3 9\x06 \xdb \xa8 \x9b \xd9 V\xee \x9c \xe3 \xea \x08 \x92 #\x9f k\x8b =v\x80 \xe1 Vt\xa7 \x88 \x19 X?\x03 \x08 \xe7 \xa6 \xbf 6\xb1 8j\xbf /' , "2b7e151628aed2a6abf7158809cf4f3c" , "tmp7.txt" , "000102030405060708090a0b0c0d0e0f" , b'12345678901234567890' ),
90+ (b"a\xcc T\xf8 \xac [\x05 \x8e \xe3 9\x06 \xdb \xa8 \x9b \xd9 V\xee \x9c \xe3 \xea 9\xa0 \x10 \xab ^\xbd \n N\xb9 \xd1 gF\x94 \xbc ,n\x08 ;1\xd7 \xa6 \xbf 6\xb1 8j\xbf #\xc6 \xd3 Am)\x16 \\ o\xcb \x8e Q\xa2 '\xba \x99 F" , "2b7e151628aed2a6abf7158809cf4f3c" , "tmp8.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890123456789012345678901234567890' ),
91+ # 192 bit
92+ (b"\x97 ;\x80 \xb9 \xc6 \x87 $\x05 \xe4 \xcf '\x18 \xba \t V^R\xef \x01 \xda R`/\xe0 \x97 _x\xac \x84 \xbf \x8a V" , "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b" , "tmp3.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890' ),
93+ (b'\x97 ;\x80 \xb9 \xc6 \x87 $\x05 \xe4 \xcf \x16 *\x89 =chR\xef \x01 \xda R`/\xe0 \x97 _x\xac \x84 \xbf \x8a P' , "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b" , "tmp4.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890123456' ),
94+ # 256 bit
95+ (b'\x86 \x8d \t i\xc1 \x0f \xbe \xe5 \xae \xc0 \xfa \x97 \xeb \xce /J\xe1 \xc6 V0^\xd1 \xa7 \xa6 V8\x05 to\xe0 >\xda ' , "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" , "tmp5.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890' ),
96+ (b'\x86 \x8d \t i\xc1 \x0f \xbe \xe5 \xae \xc0 \xcb \xa5 \xd8 \xfa \x1a |\xe1 \xc6 V0^\xd1 \xa7 \xa6 V8\x05 to\xe0 >\xdc ' , "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" , "tmp6.txt" , "000102030405060708090a0b0c0d0e0f" , b'1234567890123456' )
97+ ])
98+ def test_aes_decryption_OFB (data , key , file_name , iv , expected ):
99+ with open (f"{ file_name } .enc" , "wb" ) as file :
100+ file .write (data )
101+
102+ decrypt (key , f"{ file_name } .enc" , "OFB" , iv )
103+
104+ with open (file_name , "rb" ) as file :
105+ result = file .read ()
106+
107+ os .remove (file_name )
108+
109+ assert result == expected
0 commit comments