summaryrefslogtreecommitdiff
path: root/modes.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2003-03-26 21:50:44 +0000
committerweidai <weidai11@users.noreply.github.com>2003-03-26 21:50:44 +0000
commitb4f6ef8e16db0be6ebc3e8aa01bf51ee52082aeb (patch)
treeef84fa621368e7bce53a7708b5188ae8df1d9ed3 /modes.cpp
parent2ccaf2ef1d78727194b59d986b491e717c508917 (diff)
downloadcryptopp-git-b4f6ef8e16db0be6ebc3e8aa01bf51ee52082aeb.tar.gz
fix bugs in SEAL and Panama
Diffstat (limited to 'modes.cpp')
-rw-r--r--modes.cpp28
1 files changed, 6 insertions, 22 deletions
diff --git a/modes.cpp b/modes.cpp
index 70c23234..09c370ee 100644
--- a/modes.cpp
+++ b/modes.cpp
@@ -32,7 +32,7 @@ template class AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstrac
void CipherModeBase::SetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
- UncheckedSetKey(params, key, length); // the underlying cipher will check the key length
+ UncheckedSetKey(params, key, length, GetIVAndThrowIfInvalid(params)); // the underlying cipher will check the key length
}
void CipherModeBase::GetNextIV(byte *IV)
@@ -44,22 +44,6 @@ void CipherModeBase::GetNextIV(byte *IV)
memcpy(IV, m_register, BlockSize());
}
-void CipherModeBase::SetIV(const byte *iv)
-{
- if (iv)
- Resynchronize(iv);
- else if (IsResynchronizable())
- {
- if (!CanUseStructuredIVs())
- throw InvalidArgument("CipherModeBase: this cipher mode cannot use a null IV");
-
- // use all zeros as default IV
- SecByteBlock iv(BlockSize());
- memset(iv, 0, iv.size());
- Resynchronize(iv);
- }
-}
-
void CTR_ModePolicy::SeekToIteration(dword iterationCount)
{
int carry=0;
@@ -126,17 +110,17 @@ void CTR_ModePolicy::OperateKeystream(KeystreamOperation operation, byte *output
void CTR_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv)
{
unsigned int s = BlockSize();
- memcpy(m_register, iv, s);
+ CopyOrZero(m_register, iv, s);
m_counterArray.New(s * m_cipher->OptimalNumberOfParallelBlocks());
- memcpy(m_counterArray, iv, s);
+ CopyOrZero(m_counterArray, iv, s);
}
-void BlockOrientedCipherModeBase::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length)
+void BlockOrientedCipherModeBase::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv)
{
m_cipher->SetKey(key, length, params);
ResizeBuffers();
- const byte *iv = params.GetValueWithDefault(Name::IV(), (const byte *)NULL);
- SetIV(iv);
+ if (IsResynchronizable())
+ Resynchronize(iv);
}
void BlockOrientedCipherModeBase::ProcessData(byte *outString, const byte *inString, unsigned int length)