Re: AES, ECB mode decrypt error

Catherine Issabel <[email protected]> Thu, 2 Nov 2023 11:21:26 -0700 (PDT)
Newsgroups gmane.comp.encryption.cryptopp
Message-ID <[email protected]>
------=_Part_292_596259116.1698949286223
Content-Type: multipart/alternative; 
	boundary="----=_Part_293_708127478.1698949286223"

------=_Part_293_708127478.1698949286223
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable


$500 million dollars available only for good and trusted receiver or=20
mandate=20
Kindly contact the sender for more information:+1 (336) 345-9681
On Friday, October 13, 2023 at 4:26:19=E2=80=AFAM UTC+1 Jeffrey Walton wrot=
e:

> On Thu, Oct 12, 2023 at 5:55=E2=80=AFPM Dwight Kulkarni <dwi...@realtime-=
7.com>=20
> wrote:
> >
> > Hello,
> >
> > I had Crypto PP code that was previously working and recently stopped=
=20
> working. We moved to a new version of our BSP.
> >
> > Error is:
> > terminate called after throwing an instance of=20
> '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 mod=
e.
> >
> > Also, I don't know why it's falling through the catch statement and=20
> kills my program.
> >
> > should I have a generic catch statement Exception e to prevent this ?
> >
> > std::string decrypt_aes(std::string cipherbytes, SecByteBlock key,=20
> SecByteBlock iv) {
> > try {
> > AlgorithmParameters params =3D MakeParameters(Name::FeedbackSize(),=20
> 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=
=20
> StringSink(recovered), CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
> > return recovered;
> > }
> > catch (CryptoPP::Exception e) {
> > std::cerr << e.what() << std::endl;
> > return "";
> > }
> > }
>
> BlockPaddingSchemeDef::PKCS_PADDING is incorrect for ECB mode. ECB
> mode does not use padding. The programmer is responsible for padding
> to block size.
>
> Jeff
>

--=20
You received this message because you are subscribed to the Google Groups "=
Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
cryptopp-users/d2cee403-c881-4d42-a07b-caeacc5c87ffn%40googlegroups.com.

------=_Part_293_708127478.1698949286223
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<br />$500 million dollars available only for good and trusted receiver or =
mandate <br />Kindly contact the sender for more information:+1 (336) 345-9=
681<br /><div class=3D"gmail_quote"><div dir=3D"auto" class=3D"gmail_attr">=
On Friday, October 13, 2023 at 4:26:19=E2=80=AFAM UTC+1 Jeffrey Walton wrot=
e:<br/></div><blockquote class=3D"gmail_quote" style=3D"margin: 0 0 0 0.8ex=
; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">On Thu, Oc=
t 12, 2023 at 5:55=E2=80=AFPM Dwight Kulkarni &lt;<a href data-email-masked=
 rel=3D"nofollow">[email protected]</a>&gt; wrote:
<br>&gt;
<br>&gt; Hello,
<br>&gt;
<br>&gt; I had Crypto PP code that was previously working and recently stop=
ped working. We moved to a new version of our BSP.
<br>&gt;
<br>&gt; Error is:
<br>&gt; terminate called after throwing an instance of &#39;CryptoPP::Algo=
rithmParametersBase::ParameterNotUsed&#39;
<br>&gt;   what():  AlgorithmParametersBase: parameter &quot;IV&quot; not u=
sed
<br>&gt;
<br>&gt; Error is traced to this particular function below.
<br>&gt;
<br>&gt; I had it running with the Params in ECB mode still passing in the =
IV.
<br>&gt; d.SetKey(key, key.size(),params);
<br>&gt;
<br>&gt; Then I commented it out with:
<br>&gt; d.SetKey(key, key.size());
<br>&gt;
<br>&gt; Previously, it wasn&#39;t throwing an error even if IV is passed i=
n ECB mode.
<br>&gt;
<br>&gt; Also, I don&#39;t know why it&#39;s falling through the catch stat=
ement and kills my program.
<br>&gt;
<br>&gt; should I have a generic catch statement Exception e  to prevent th=
is ?
<br>&gt;
<br>&gt; std::string decrypt_aes(std::string cipherbytes, SecByteBlock key,=
 SecByteBlock iv) {
<br>&gt; try {
<br>&gt; AlgorithmParameters params =3D MakeParameters(Name::FeedbackSize()=
, 1/*8-bits*/)
<br>&gt; (Name::IV(), ConstByteArrayParameter(iv));
<br>&gt; //CFB_Mode&lt;AES&gt;::Decryption d;
<br>&gt; ECB_Mode&lt;AES&gt;::Decryption d;
<br>&gt; std::string recovered;
<br>&gt; //d.SetKey(key, key.size(),params);
<br>&gt; d.SetKey(key, key.size());
<br>&gt; StringSource s(cipherbytes, true, new StreamTransformationFilter(d=
, new StringSink(recovered), CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING)=
);
<br>&gt; return recovered;
<br>&gt; }
<br>&gt; catch (CryptoPP::Exception e) {
<br>&gt; std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
<br>&gt; return &quot;&quot;;
<br>&gt; }
<br>&gt; }
<br>
<br>BlockPaddingSchemeDef::PKCS_PADDING is incorrect for ECB mode. ECB
<br>mode does not use padding. The programmer is responsible for padding
<br>to block size.
<br>
<br>Jeff
<br></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Crypto++ Users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">cryp=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/cryptopp-users/d2cee403-c881-4d42-a07b-caeacc5c87ffn%40googlegro=
ups.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d=
/msgid/cryptopp-users/d2cee403-c881-4d42-a07b-caeacc5c87ffn%40googlegroups.=
com</a>.<br />

------=_Part_293_708127478.1698949286223--

------=_Part_292_596259116.1698949286223--