summaryrefslogtreecommitdiffstats
path: root/src/crypt/cryptclassevp.h
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-05-27 13:02:31 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-05-27 13:02:31 +0200
commit220702c05e5c67817e5ba45765fd75ead8e92bb3 (patch)
tree5daf0156e022c79d9fc4142995195435fe5b3f5d /src/crypt/cryptclassevp.h
parent5db765c2ee63f0ee6774817cf85fcb4b5078ca4a (diff)
downloadIT-Sicherheit-220702c05e5c67817e5ba45765fd75ead8e92bb3.tar.gz
IT-Sicherheit-220702c05e5c67817e5ba45765fd75ead8e92bb3.zip
Use an EVP base class to reduce repetition
Diffstat (limited to 'src/crypt/cryptclassevp.h')
-rw-r--r--src/crypt/cryptclassevp.h48
1 files changed, 48 insertions, 0 deletions
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 <openssl/evp.h>
+#include <openssl/err.h>
+#include <stdexcept>
+
+/**
+* @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