summaryrefslogtreecommitdiff
path: root/lib/crypto
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2012-04-28 18:13:19 +0000
committerChris Wilson <chris+github@qwirx.com>2012-04-28 18:13:19 +0000
commit26c898448b0c88c9a9b1cd7609847d0df9ab52bf (patch)
treeeafa7290f1d1c7e6074173e19a351650cbe3e69b /lib/crypto
parent3c60fe12ad2b8cb476991a3a7c7822782ce80953 (diff)
Allow ciphers to identify themselves for debugging.
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/CipherAES.h9
-rw-r--r--lib/crypto/CipherBlowfish.h9
-rw-r--r--lib/crypto/CipherContext.h14
-rw-r--r--lib/crypto/CipherDescription.h19
4 files changed, 47 insertions, 4 deletions
diff --git a/lib/crypto/CipherAES.h b/lib/crypto/CipherAES.h
index 50b96dc3..d2c9ed65 100644
--- a/lib/crypto/CipherAES.h
+++ b/lib/crypto/CipherAES.h
@@ -37,6 +37,15 @@ public:
// Setup any other parameters
virtual void SetupParameters(EVP_CIPHER_CTX *pCipherContext) const;
+ virtual std::string GetCipherName() const
+ {
+ std::ostringstream out;
+ out << "AES";
+ out << mKeyLength;
+ return out.str();
+ }
+ virtual CipherMode GetCipherMode() const { return mMode; }
+
private:
CipherDescription::CipherMode mMode;
const void *mpKey;
diff --git a/lib/crypto/CipherBlowfish.h b/lib/crypto/CipherBlowfish.h
index b3bcf028..152a265c 100644
--- a/lib/crypto/CipherBlowfish.h
+++ b/lib/crypto/CipherBlowfish.h
@@ -38,6 +38,15 @@ public:
// Setup any other parameters
virtual void SetupParameters(EVP_CIPHER_CTX *pCipherContext) const;
+ virtual std::string GetCipherName() const
+ {
+ std::ostringstream out;
+ out << "AES";
+ out << mKeyLength;
+ return out.str();
+ }
+ virtual CipherMode GetCipherMode() const { return mMode; }
+
#ifdef HAVE_OLD_SSL
CipherDescription *Clone() const;
void SetIV(const void *pIV);
diff --git a/lib/crypto/CipherContext.h b/lib/crypto/CipherContext.h
index 64ce52d8..93c889d6 100644
--- a/lib/crypto/CipherContext.h
+++ b/lib/crypto/CipherContext.h
@@ -35,12 +35,15 @@ public:
private:
CipherContext(const CipherContext &); // no copying
CipherContext &operator=(const CipherContext &); // no assignment
+protected:
+ std::string LogError(const std::string& operation);
public:
typedef enum
{
- Decrypt = 0,
- Encrypt = 1
+ None = 0,
+ Decrypt,
+ Encrypt
} CipherFunction;
void Init(CipherContext::CipherFunction Function, const CipherDescription &rDescription);
@@ -61,6 +64,10 @@ public:
const void *SetRandomIV(int &rLengthOut);
void UsePadding(bool Padding = true);
+ const char* GetFunction() const
+ {
+ return (mFunction == Encrypt) ? "encrypt" : "decrypt";
+ }
#ifdef HAVE_OLD_SSL
void OldOpenSSLFinal(unsigned char *Buffer, int &rOutLengthOut);
@@ -72,8 +79,9 @@ private:
bool mWithinTransform;
bool mPaddingOn;
uint8_t mGeneratedIV[CIPHERCONTEXT_MAX_GENERATED_IV_LENGTH];
-#ifdef HAVE_OLD_SSL
CipherFunction mFunction;
+ std::string mCipherName;
+#ifdef HAVE_OLD_SSL
CipherDescription *mpDescription;
#endif
};
diff --git a/lib/crypto/CipherDescription.h b/lib/crypto/CipherDescription.h
index f825eefa..813df2ce 100644
--- a/lib/crypto/CipherDescription.h
+++ b/lib/crypto/CipherDescription.h
@@ -34,7 +34,7 @@ public:
// Return OpenSSL cipher object
virtual const EVP_CIPHER *GetCipher() const = 0;
-
+
// Setup any other parameters
virtual void SetupParameters(EVP_CIPHER_CTX *pCipherContext) const = 0;
@@ -47,6 +47,23 @@ public:
Mode_OFB = 3
} CipherMode;
+ virtual std::string GetCipherName() const = 0;
+ virtual CipherMode GetCipherMode() const = 0;
+ virtual std::string GetFullName() const
+ {
+ std::ostringstream out;
+ out << GetCipherName() << "-";
+ switch (GetCipherMode())
+ {
+ case Mode_ECB: out << "ECB"; break;
+ case Mode_CBC: out << "CBC"; break;
+ case Mode_CFB: out << "CFB"; break;
+ case Mode_OFB: out << "OFB"; break;
+ default: out << "unknown";
+ }
+ return out.str();
+ }
+
#ifdef HAVE_OLD_SSL
// For the old version of OpenSSL, we need to be able to store cipher descriptions.
virtual CipherDescription *Clone() const = 0;