summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2007-04-16 00:34:13 +0000
committerweidai <weidai11@users.noreply.github.com>2007-04-16 00:34:13 +0000
commitc46c9fbc2be9ff8d0d97236bd78b2be4a74b754b (patch)
tree56bf19a09990ed7a57c8d48da5ceaf509e7a8fdc
parentde8b060ea1c0ec0d6ec396707972b07db9911198 (diff)
downloadcryptopp-git-c46c9fbc2be9ff8d0d97236bd78b2be4a74b754b.tar.gz
rename STRUCTURED_IV to UNIQUE_IV. assert correct cipher direction
-rw-r--r--modes.cpp1
-rw-r--r--modes.h8
2 files changed, 7 insertions, 2 deletions
diff --git a/modes.cpp b/modes.cpp
index 295fc341..b51afe9b 100644
--- a/modes.cpp
+++ b/modes.cpp
@@ -61,6 +61,7 @@ inline void CTR_ModePolicy::ProcessMultipleBlocks(byte *output, const byte *inpu
void CTR_ModePolicy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
{
+ assert(m_cipher->IsForwardTransformation()); // CTR mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
unsigned int maxBlocks = m_cipher->OptimalNumberOfParallelBlocks();
if (maxBlocks == 1)
{
diff --git a/modes.h b/modes.h
index 98547d49..a4f5bbed 100644
--- a/modes.h
+++ b/modes.h
@@ -87,6 +87,7 @@ protected:
byte * GetRegisterBegin() {return m_register + BlockSize() - m_feedbackSize;}
void TransformRegister()
{
+ assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
m_cipher->ProcessBlock(m_register, m_temp);
unsigned int updateSize = BlockSize()-m_feedbackSize;
memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize);
@@ -125,7 +126,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTe
{
public:
bool IsRandomAccess() const {return false;}
- IV_Requirement IVRequirement() const {return STRUCTURED_IV;}
+ IV_Requirement IVRequirement() const {return UNIQUE_IV;}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "OFB";}
private:
@@ -134,6 +135,7 @@ private:
void WriteKeystream(byte *keystreamBuffer, size_t iterationCount)
{
assert(iterationCount == 1);
+ assert(m_cipher->IsForwardTransformation()); // OFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
m_cipher->ProcessBlock(keystreamBuffer);
memcpy_s(m_register, m_register.size(), keystreamBuffer, BlockSize());
}
@@ -147,7 +149,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTe
{
public:
bool IsRandomAccess() const {return true;}
- IV_Requirement IVRequirement() const {return STRUCTURED_IV;}
+ IV_Requirement IVRequirement() const {return UNIQUE_IV;}
void CipherGetNextIV(byte *IV);
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CTR";}
@@ -192,6 +194,8 @@ protected:
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase
{
public:
+ void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs)
+ {m_cipher->SetKey(key, length, params); BlockOrientedCipherModeBase::ResizeBuffers();}
IV_Requirement IVRequirement() const {return NOT_RESYNCHRONIZABLE;}
unsigned int OptimalBlockSize() const {return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();}
void ProcessBlocks(byte *outString, const byte *inString, size_t numberOfBlocks)