From 0a0244dacface689335de6e0edf978b29ddb66e1 Mon Sep 17 00:00:00 2001 From: weidai Date: Wed, 26 Mar 2003 21:50:44 +0000 Subject: 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 --- strciphr.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'strciphr.h') diff --git a/strciphr.h b/strciphr.h index 2a297bb..8b3c9aa 100644 --- a/strciphr.h +++ b/strciphr.h @@ -30,6 +30,7 @@ #include "seckey.h" #include "secblock.h" +#include "argnames.h" NAMESPACE_BEGIN(CryptoPP) @@ -134,7 +135,7 @@ public: typedef typename BASE::PolicyInterface PolicyInterface; protected: - void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length); + void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv); unsigned int GetBufferByteSize(const PolicyInterface &policy) const {return policy.GetBytesPerIteration() * policy.GetIterationsToBuffer();} @@ -226,7 +227,7 @@ public: protected: virtual void CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, unsigned int length) =0; - void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length); + void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv); unsigned int m_leftOver; }; @@ -255,31 +256,38 @@ public: SymmetricCipherFinalTemplate(const byte *key, unsigned int length) {SetKey(key, length);} SymmetricCipherFinalTemplate(const byte *key, unsigned int length, const byte *iv) - {SetKey(key, length); Resynchronize(iv);} + {SetKeyWithIV(key, length, iv);} void SetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms = g_nullNameValuePairs) { ThrowIfInvalidKeyLength(length); - UncheckedSetKey(params, key, length); + UncheckedSetKey(params, key, length, GetIVAndThrowIfInvalid(params)); } Clonable * Clone() const {return static_cast(new SymmetricCipherFinalTemplate(*this));} }; template -void AdditiveCipherTemplate::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length) +void AdditiveCipherTemplate::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv) { PolicyInterface &policy = AccessPolicy(); policy.CipherSetKey(params, key, length); - m_buffer.New(GetBufferByteSize(policy)); m_leftOver = 0; + m_buffer.New(GetBufferByteSize(policy)); + + if (IsResynchronizable()) + policy.CipherResynchronize(m_buffer, iv); } template -void CFB_CipherTemplate::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length) +void CFB_CipherTemplate::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv) { PolicyInterface &policy = AccessPolicy(); policy.CipherSetKey(params, key, length); + + if (IsResynchronizable()) + policy.CipherResynchronize(iv); + m_leftOver = policy.GetBytesPerIteration(); } -- cgit v1.2.1