diff options
author | weidai <weidai11@users.noreply.github.com> | 2003-03-26 21:50:44 +0000 |
---|---|---|
committer | weidai <weidai11@users.noreply.github.com> | 2003-03-26 21:50:44 +0000 |
commit | b4f6ef8e16db0be6ebc3e8aa01bf51ee52082aeb (patch) | |
tree | ef84fa621368e7bce53a7708b5188ae8df1d9ed3 /modes.cpp | |
parent | 2ccaf2ef1d78727194b59d986b491e717c508917 (diff) | |
download | cryptopp-git-b4f6ef8e16db0be6ebc3e8aa01bf51ee52082aeb.tar.gz |
fix bugs in SEAL and Panama
Diffstat (limited to 'modes.cpp')
-rw-r--r-- | modes.cpp | 28 |
1 files changed, 6 insertions, 22 deletions
@@ -32,7 +32,7 @@ template class AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstrac void CipherModeBase::SetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) { - 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 ¶ms, const byte *key, unsigned int length) +void BlockOrientedCipherModeBase::UncheckedSetKey(const NameValuePairs ¶ms, 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) |