@@ -169,7 +169,26 @@ bool BotanSymmetricAlgorithm::encryptInit(const SymmetricKey* key, const SymMode
169
169
try
170
170
{
171
171
Botan::SymmetricKey botanKey = Botan::SymmetricKey (key->getKeyBits ().const_byte_str (), key->getKeyBits ().size ());
172
- if (mode == SymMode::GCM)
172
+ if (mode == SymMode::ECB)
173
+ {
174
+ // ECB cipher mode was dropped in Botan 2.0
175
+ const std::vector<std::string> algo_parts = split_on_delim (cipherName, ' /' );
176
+ const std::string cipher_name = algo_parts[0 ];
177
+ bool with_pkcs7_padding;
178
+ if (algo_parts.size () == 3 && algo_parts[2 ] == " PKCS7" )
179
+ {
180
+ with_pkcs7_padding = true ;
181
+ }
182
+ else
183
+ {
184
+ with_pkcs7_padding = false ;
185
+ }
186
+ std::unique_ptr<Botan::BlockCipher> bc (Botan::BlockCipher::create (cipher_name));
187
+ Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter (new Botan::ECB_Encryption (bc.release (), with_pkcs7_padding));
188
+ cipher->set_key (botanKey);
189
+ cryption = new Botan::Pipe (cipher);
190
+ }
191
+ else if (mode == SymMode::GCM)
173
192
{
174
193
Botan::AEAD_Mode* aead = Botan::get_aead (cipherName, Botan::ENCRYPTION);
175
194
aead->set_key (botanKey);
@@ -385,7 +404,26 @@ bool BotanSymmetricAlgorithm::decryptInit(const SymmetricKey* key, const SymMode
385
404
try
386
405
{
387
406
Botan::SymmetricKey botanKey = Botan::SymmetricKey (key->getKeyBits ().const_byte_str (), key->getKeyBits ().size ());
388
- if (mode == SymMode::GCM)
407
+ if (mode == SymMode::ECB)
408
+ {
409
+ // ECB cipher mode was dropped in Botan 2.0
410
+ const std::vector<std::string> algo_parts = split_on_delim (cipherName, ' /' );
411
+ const std::string cipher_name = algo_parts[0 ];
412
+ bool with_pkcs7_padding;
413
+ if (algo_parts.size () == 3 && algo_parts[2 ] == " PKCS7" )
414
+ {
415
+ with_pkcs7_padding = true ;
416
+ }
417
+ else
418
+ {
419
+ with_pkcs7_padding = false ;
420
+ }
421
+ std::unique_ptr<Botan::BlockCipher> bc (Botan::BlockCipher::create (cipher_name));
422
+ Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter (new Botan::ECB_Decryption (bc.release (),with_pkcs7_padding));
423
+ cipher->set_key (botanKey);
424
+ cryption = new Botan::Pipe (cipher);
425
+ }
426
+ else if (mode == SymMode::GCM)
389
427
{
390
428
Botan::AEAD_Mode* aead = Botan::get_aead (cipherName, Botan::DECRYPTION);
391
429
aead->set_key (botanKey);
0 commit comments