From 220702c05e5c67817e5ba45765fd75ead8e92bb3 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Wed, 27 May 2015 13:02:31 +0200 Subject: Use an EVP base class to reduce repetition --- src/crypt/cryptclassevp.h | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/crypt/cryptclassevp.h (limited to 'src/crypt/cryptclassevp.h') diff --git a/src/crypt/cryptclassevp.h b/src/crypt/cryptclassevp.h new file mode 100644 index 0000000..8e9c66c --- /dev/null +++ b/src/crypt/cryptclassevp.h @@ -0,0 +1,48 @@ +#ifndef CRYPTCLASSEVP_H +#define CRYPTCLASSEVP_H + +#include "cryptclassbase.h" + +#include +#include +#include + +/** +* @author Walter Roth, 2015 +* @brief The CryptClassEvp is a class for symmetric cryptography using OpenSSL's EVP API. +* Subclasses must overwrite the algorithm function to specify the algorithm to be used. +* The implementation of algorithm in this class returns a NULL-Cipher object (no encryption). +* This is quite useful for debugging. +* +*/ +class CryptClassEvp : public CryptClassBase +{ +public: + CryptClassEvp(); + virtual ~CryptClassEvp(); + + /** + * @brief setAlgorithm Overwrite this function to specify the algorithm to be used. + * @param cipher The cipher object e.g. EVP_bf_cbc() for Blowfish in CBC mode. + */ + virtual const EVP_CIPHER *algorithm() = 0; + + /** + * @brief encrypt Setup context and key and encrypt m_clearText into m_cryptText. + */ + void encrypt(); + + /** + * @brief encrypt Setup context and key and decrypt m_cryptText into m_clearText. + */ + void decrypt(); + + /** + * @brief handleOpenSslError Calls ERR_get_error and sends debug output to stderr. + * @param file The __FILE__ makro + * @param line The __LINE__ makro + * @return + */ + void handleOpenSslError(); +}; +#endif // CRYPTCLASSEVP_H -- cgit v1.2.3-70-g09d2