@@ -115,3 +115,29 @@ fn test_block_cipher(
115
115
rc5_cipher2. encrypt_block ( data. into ( ) ) ;
116
116
rc5_cipher2. decrypt_block ( data. into ( ) ) ;
117
117
}
118
+
119
+ type MyDesEncryptor = cbc:: Encryptor < des:: Des > ;
120
+
121
+ fn test_cbc (
122
+ key : & [ u8 ] , key128 : & [ u8 ; 16 ] , iv : & [ u8 ] , iv128 : & [ u8 ; 16 ] ,
123
+ input : & [ u8 ] , data : & mut [ u8 ]
124
+ ) {
125
+ let data_len = data. len ( ) ;
126
+
127
+ // aes
128
+ let aes_cipher1 = cbc:: Encryptor :: < aes:: Aes128 > :: new ( key128. into ( ) , iv128. into ( ) ) ;
129
+ _ = aes_cipher1. encrypt_padded_mut :: < aes:: cipher:: block_padding:: Pkcs7 > ( data, data_len) . unwrap ( ) ;
130
+
131
+ // des (broken)
132
+ let des_cipher1 = cbc:: Encryptor :: < des:: Des > :: new ( key. into ( ) , iv. into ( ) ) ; // $ MISSING: Alert[rust/weak-cryptographic-algorithm]
133
+ _ = des_cipher1. encrypt_padded_mut :: < des:: cipher:: block_padding:: Pkcs7 > ( data, data_len) . unwrap ( ) ;
134
+
135
+ let des_cipher2 = MyDesEncryptor :: new ( key. into ( ) , iv. into ( ) ) ; // $ MISSING: Alert[rust/weak-cryptographic-algorithm]
136
+ _ = des_cipher2. encrypt_padded_mut :: < des:: cipher:: block_padding:: Pkcs7 > ( data, data_len) . unwrap ( ) ;
137
+
138
+ let des_cipher3 = cbc:: Encryptor :: < des:: Des > :: new_from_slices ( & key, & iv) . unwrap ( ) ; // $ MISSING: Alert[rust/weak-cryptographic-algorithm]
139
+ _ = des_cipher3. encrypt_padded_mut :: < des:: cipher:: block_padding:: Pkcs7 > ( data, data_len) . unwrap ( ) ;
140
+
141
+ let des_cipher4 = cbc:: Encryptor :: < des:: Des > :: new ( key. into ( ) , iv. into ( ) ) ; // $ MISSING: Alert[rust/weak-cryptographic-algorithm]
142
+ _ = des_cipher4. encrypt_padded_b2b_mut :: < des:: cipher:: block_padding:: Pkcs7 > ( input, data) . unwrap ( ) ;
143
+ }
0 commit comments