Re: selecting blockcipher+mode in an easier way.
Jeffrey Walton <[email protected]> Thu, 4 Jan 2024 13:34:08 -0500
| Newsgroups | gmane.comp.encryption.cryptopp |
|---|---|
| Message-ID | <CAH8yC8nx+ma5ZeYJO=1zmBHCunW5VrD63RNwzapL1sqw_q8=GQ@mail.gmail.com> |
On Thu, Jan 4, 2024 at 11:19=E2=80=AFAM Johannes Winkler <[email protected]= > wrote: > > I am working on a GUI programme for crypto++. When selecting block cipher= s dynamically (from GUI), there is a problem to choose the cipher dynamical= ly in code. > > Here is an example: > let's do AES-CFB-Encryption > CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption obj; > > However, if I want to switch to Twofish-OFB-Decryption > CryptoPP::OFB_Mode<CryptoPP::Twofish>::Decryption obj; > I have to change 3 spots in this line. Unfortunately, I cannot put Crypto= PP::AES in a variable. Is there a possibility to choose the algorithm like > CryptoPP::A<B>::C obj; with A=3DCBC_Mode, B=3DAES, C=3DDecryption > Or a string-based approach like Cipher("AES-CBC-Decryption") > > Currently, I have a if-else tree with 6 algorithms, 5 modes, Encrypt/Decr= ypt, therefore, 6x5x2=3D60 branches, which is annoying. Is there a better s= olution? Yeah, the if-then-else is the way I do it, in code for PEM parsing. See <https://github.com/noloader/cryptopp-pem/blob/master/pem_read.cpp#L312= >. You might be able to do it with an External Mode Cipher. Take a look at CFB_Mode_ExternalCipher and friends: $ grep Mode_ExternalCipher *.h ccm.h: CTR_Mode_ExternalCipher::Encryption m_ctr; eax.h: CTR_Mode_ExternalCipher::Encryption m_ctr; gcm.h: class CRYPTOPP_DLL GCTR : public CTR_Mode_ExternalCipher::Encryp= tion modes.h:struct CFB_Mode_ExternalCipher : public CipherModeDocumentation modes.h:struct CFB_FIPS_Mode_ExternalCipher : public CipherModeDocumenta= tion modes.h:struct OFB_Mode_ExternalCipher : public CipherModeDocumentation modes.h:struct CTR_Mode_ExternalCipher : public CipherModeDocumentation modes.h:struct ECB_Mode_ExternalCipher : public CipherModeDocumentation modes.h:struct CBC_Mode_ExternalCipher : public CipherModeDocumentation modes.h:struct CBC_CTS_Mode_ExternalCipher : public CipherModeDocumentat= ion 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/CAH8yC8nx%2Bma5ZeYJO%3D1zmBHCunW5VrD63RNwzapL1sqw_q8%3DGQ%40= mail.gmail.com.