On Thu, Jan 4, 2024 at 11:19 AM Johannes Winkler <jwin...@gmail.com> wrote: > > I am working on a GUI programme for crypto++. When selecting block ciphers > dynamically (from GUI), there is a problem to choose the cipher dynamically > 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 > CryptoPP::AES in a variable. Is there a possibility to choose the algorithm > like > CryptoPP::A<B>::C obj; with A=CBC_Mode, B=AES, C=Decryption > Or a string-based approach like Cipher("AES-CBC-Decryption") > > Currently, I have a if-else tree with 6 algorithms, 5 modes, Encrypt/Decrypt, > therefore, 6x5x2=60 branches, which is annoying. Is there a better solution?
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::Encryption modes.h:struct CFB_Mode_ExternalCipher : public CipherModeDocumentation modes.h:struct CFB_FIPS_Mode_ExternalCipher : public CipherModeDocumentation 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 CipherModeDocumentation Jeff -- 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 email to cryptopp-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8nx%2Bma5ZeYJO%3D1zmBHCunW5VrD63RNwzapL1sqw_q8%3DGQ%40mail.gmail.com.