summaryrefslogtreecommitdiff
path: root/modes.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-03-26 21:50:44 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-03-26 21:50:44 +0000
commit0a0244dacface689335de6e0edf978b29ddb66e1 (patch)
treeef84fa621368e7bce53a7708b5188ae8df1d9ed3 /modes.cpp
parent79694912becd37f5f0077464350f3db55dd2ca7c (diff)
downloadcryptopp-0a0244dacface689335de6e0edf978b29ddb66e1.tar.gz
fix bugs in SEAL and Panama
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@54 57ff6487-cd31-0410-9ec3-f628ee90f5f0
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 70c2323..09c370e 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)