summaryrefslogtreecommitdiff
path: root/lib/crypto/CipherContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto/CipherContext.cpp')
-rw-r--r--lib/crypto/CipherContext.cpp110
1 files changed, 0 insertions, 110 deletions
diff --git a/lib/crypto/CipherContext.cpp b/lib/crypto/CipherContext.cpp
index 6621f79a..fd149395 100644
--- a/lib/crypto/CipherContext.cpp
+++ b/lib/crypto/CipherContext.cpp
@@ -13,10 +13,7 @@
#include "CipherContext.h"
#include "CipherDescription.h"
#include "CipherException.h"
-<<<<<<< HEAD
-=======
#include "CryptoUtils.h"
->>>>>>> 0.12
#include "Random.h"
#include "MemLeakFindOn.h"
@@ -30,21 +27,12 @@
//
// --------------------------------------------------------------------------
CipherContext::CipherContext()
-<<<<<<< HEAD
- : mInitialised(false),
- mWithinTransform(false),
- mPaddingOn(true)
-#ifdef HAVE_OLD_SSL
- , mFunction(Decrypt),
- mpDescription(0)
-=======
: mInitialised(false),
mWithinTransform(false),
mPaddingOn(true),
mFunction(None)
#ifdef HAVE_OLD_SSL
, mpDescription(0)
->>>>>>> 0.12
#endif
{
}
@@ -77,8 +65,6 @@ CipherContext::~CipherContext()
// --------------------------------------------------------------------------
//
// Function
-<<<<<<< HEAD
-=======
// Name: CipherContext::LogError(const std::string& operation)
// Purpose: Logs and clears any OpenSSL errors, returning the
// most recent error message for use in exception
@@ -101,7 +87,6 @@ std::string CipherContext::LogError(const std::string& operation)
// --------------------------------------------------------------------------
//
// Function
->>>>>>> 0.12
// Name: CipherContext::Init(CipherContext::CipherFunction, const CipherDescription &)
// Purpose: Initialises the context, specifying the direction for the encryption, and a
// description of the cipher to use, it's keys, etc
@@ -120,28 +105,13 @@ void CipherContext::Init(CipherContext::CipherFunction Function, const CipherDes
THROW_EXCEPTION(CipherException, BadArguments)
}
-<<<<<<< HEAD
-=======
// Store function for later
mFunction = Function;
->>>>>>> 0.12
// Initialise the cipher
#ifndef HAVE_OLD_SSL
EVP_CIPHER_CTX_init(&ctx); // no error return code, even though the docs says it does
-<<<<<<< HEAD
- if(EVP_CipherInit_ex(&ctx, rDescription.GetCipher(), NULL, NULL, NULL, Function) != 1)
-#else
- // Store function for later
- mFunction = Function;
-
- // Use old version of init call
- if(EVP_CipherInit(&ctx, rDescription.GetCipher(), NULL, NULL, Function) != 1)
-#endif
- {
- THROW_EXCEPTION(CipherException, EVPInitFailure)
-=======
if(EVP_CipherInit_ex(&ctx, rDescription.GetCipher(), NULL, NULL, NULL,
(mFunction == Encrypt) ? 1 : 0) != 1)
#else
@@ -153,15 +123,11 @@ void CipherContext::Init(CipherContext::CipherFunction Function, const CipherDes
THROW_EXCEPTION_MESSAGE(CipherException, EVPInitFailure,
"Failed to initialise " << rDescription.GetFullName()
<< "cipher: " << LogError("initialising cipher"));
->>>>>>> 0.12
}
try
{
-<<<<<<< HEAD
-=======
mCipherName = rDescription.GetFullName();
->>>>>>> 0.12
#ifndef HAVE_OLD_SSL
// Let the description set up everything else
rDescription.SetupParameters(&ctx);
@@ -176,12 +142,9 @@ void CipherContext::Init(CipherContext::CipherFunction Function, const CipherDes
}
catch(...)
{
-<<<<<<< HEAD
-=======
THROW_EXCEPTION_MESSAGE(CipherException, EVPInitFailure,
"Failed to configure " << mCipherName << " cipher: " <<
LogError("configuring cipher"));
->>>>>>> 0.12
EVP_CIPHER_CTX_cleanup(&ctx);
throw;
}
@@ -242,13 +205,9 @@ void CipherContext::Begin()
// Initialise the cipher context again
if(EVP_CipherInit(&ctx, NULL, NULL, NULL, -1) != 1)
{
-<<<<<<< HEAD
- THROW_EXCEPTION(CipherException, EVPInitFailure)
-=======
THROW_EXCEPTION_MESSAGE(CipherException, EVPInitFailure,
"Failed to reset " << mCipherName << " cipher: " <<
LogError("resetting cipher"));
->>>>>>> 0.12
}
// Mark as being within a transform
@@ -301,13 +260,9 @@ int CipherContext::Transform(void *pOutBuffer, int OutLength, const void *pInBuf
int outLength = OutLength;
if(EVP_CipherUpdate(&ctx, (unsigned char*)pOutBuffer, &outLength, (unsigned char*)pInBuffer, InLength) != 1)
{
-<<<<<<< HEAD
- THROW_EXCEPTION(CipherException, EVPUpdateFailure)
-=======
THROW_EXCEPTION_MESSAGE(CipherException, EVPUpdateFailure,
"Failed to " << GetFunction() << " (update) " <<
mCipherName << " cipher: " << LogError(GetFunction()));
->>>>>>> 0.12
}
return outLength;
@@ -353,18 +308,12 @@ int CipherContext::Final(void *pOutBuffer, int OutLength)
// Do the transform
int outLength = OutLength;
#ifndef HAVE_OLD_SSL
-<<<<<<< HEAD
- if(EVP_CipherFinal_ex(&ctx, (unsigned char*)pOutBuffer, &outLength) != 1)
- {
- THROW_EXCEPTION(CipherException, EVPFinalFailure)
-=======
if(EVP_CipherFinal(&ctx, (unsigned char*)pOutBuffer, &outLength) != 1)
{
mWithinTransform = false;
THROW_EXCEPTION_MESSAGE(CipherException, EVPFinalFailure,
"Failed to " << GetFunction() << " (final) " <<
mCipherName << " cipher: " << LogError(GetFunction()));
->>>>>>> 0.12
}
#else
OldOpenSSLFinal((unsigned char*)pOutBuffer, outLength);
@@ -442,12 +391,8 @@ void CipherContext::OldOpenSSLFinal(unsigned char *Buffer, int &rOutLengthOut)
}
}
// Reinitialise the cipher for the next time around
-<<<<<<< HEAD
- if(EVP_CipherInit(&ctx, mpDescription->GetCipher(), NULL, NULL, mFunction) != 1)
-=======
if(EVP_CipherInit(&ctx, mpDescription->GetCipher(), NULL, NULL,
(mFunction == Encrypt) ? 1 : 0) != 1)
->>>>>>> 0.12
{
THROW_EXCEPTION(CipherException, EVPInitFailure)
}
@@ -545,39 +490,6 @@ int CipherContext::TransformBlock(void *pOutBuffer, int OutLength, const void *p
// Do the entire block
int outLength = 0;
-<<<<<<< HEAD
- try
- {
- // Update
- outLength = OutLength;
- if(EVP_CipherUpdate(&ctx, (unsigned char*)pOutBuffer, &outLength, (unsigned char*)pInBuffer, InLength) != 1)
- {
- THROW_EXCEPTION(CipherException, EVPUpdateFailure)
- }
- // Finalise
- int outLength2 = OutLength - outLength;
-#ifndef HAVE_OLD_SSL
- if(EVP_CipherFinal_ex(&ctx, ((unsigned char*)pOutBuffer) + outLength, &outLength2) != 1)
- {
- THROW_EXCEPTION(CipherException, EVPFinalFailure)
- }
-#else
- OldOpenSSLFinal(((unsigned char*)pOutBuffer) + outLength, outLength2);
-#endif
- outLength += outLength2;
- }
- catch(...)
- {
- // Finalise the context, so definately ready for the next caller
- int outs = OutLength;
-#ifndef HAVE_OLD_SSL
- EVP_CipherFinal_ex(&ctx, (unsigned char*)pOutBuffer, &outs);
-#else
- OldOpenSSLFinal((unsigned char*)pOutBuffer, outs);
-#endif
- throw;
- }
-=======
// Update
outLength = OutLength;
@@ -601,7 +513,6 @@ int CipherContext::TransformBlock(void *pOutBuffer, int OutLength, const void *p
OldOpenSSLFinal(((unsigned char*)pOutBuffer) + outLength, outLength2);
#endif
outLength += outLength2;
->>>>>>> 0.12
return outLength;
}
@@ -651,13 +562,9 @@ void CipherContext::SetIV(const void *pIV)
// Set IV
if(EVP_CipherInit(&ctx, NULL, NULL, (unsigned char *)pIV, -1) != 1)
{
-<<<<<<< HEAD
- THROW_EXCEPTION(CipherException, EVPInitFailure)
-=======
THROW_EXCEPTION_MESSAGE(CipherException, EVPInitFailure,
"Failed to " << GetFunction() << " (set IV) " <<
mCipherName << " cipher: " << LogError(GetFunction()));
->>>>>>> 0.12
}
#ifdef HAVE_OLD_SSL
@@ -702,24 +609,7 @@ const void *CipherContext::SetRandomIV(int &rLengthOut)
// Generate some random data
Random::Generate(mGeneratedIV, ivLen);
-<<<<<<< HEAD
-
- // Set IV
- if(EVP_CipherInit(&ctx, NULL, NULL, mGeneratedIV, -1) != 1)
- {
- THROW_EXCEPTION(CipherException, EVPInitFailure)
- }
-
-#ifdef HAVE_OLD_SSL
- // Update description
- if(mpDescription != 0)
- {
- mpDescription->SetIV(mGeneratedIV);
- }
-#endif
-=======
SetIV(mGeneratedIV);
->>>>>>> 0.12
// Return the IV and it's length
rLengthOut = ivLen;