AES, ECB mode decrypt error

64 views
Skip to first unread message

Dwight Kulkarni

unread,
Oct 12, 2023, 5:55:44 PM10/12/23
to Crypto++ Users
Hello,

I had Crypto PP code that was previously working and recently stopped working. We moved to a new version of our BSP.

Error is:
terminate called after throwing an instance of 'CryptoPP::AlgorithmParametersBase::ParameterNotUsed'
  what():  AlgorithmParametersBase: parameter "IV" not used

Error is traced to this particular function below. 

I had it running with the Params in ECB mode still passing in the IV.
d.SetKey(key, key.size(),params);

Then I commented it out with:
d.SetKey(key, key.size());

Previously, it wasn't throwing an error even if IV is passed in ECB mode. 

Also, I don't know why it's falling through the catch statement and kills my program.

should I have a generic catch statement Exception e  to prevent this ?

std::string decrypt_aes(std::string cipherbytes, SecByteBlock key, SecByteBlock iv) {
try {
AlgorithmParameters params = MakeParameters(Name::FeedbackSize(), 1/*8-bits*/)
(Name::IV(), ConstByteArrayParameter(iv));
//CFB_Mode<AES>::Decryption d;
ECB_Mode<AES>::Decryption d;
std::string recovered;
//d.SetKey(key, key.size(),params);
d.SetKey(key, key.size());
StringSource s(cipherbytes, true, new StreamTransformationFilter(d, new StringSink(recovered), CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
return recovered;
}
catch (CryptoPP::Exception e) {
std::cerr << e.what() << std::endl;
return "";
}
} 

Dwight Kulkarni

unread,
Oct 12, 2023, 6:38:37 PM10/12/23
to Crypto++ Users
Hi,

It started working after I commented out the AlgorithmParameters params line.

I thought the d.SetKey(..) change would fix it, but it didn't seem to.

Jeffrey Walton

unread,
Oct 12, 2023, 11:26:19 PM10/12/23
to cryptop...@googlegroups.com
BlockPaddingSchemeDef::PKCS_PADDING is incorrect for ECB mode. ECB
mode does not use padding. The programmer is responsible for padding
to block size.

Jeff
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages