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 --- modes.h | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'modes.h') diff --git a/modes.h b/modes.h index 46e8dd2..9a94f37 100644 --- a/modes.h +++ b/modes.h @@ -47,7 +47,6 @@ public: protected: inline unsigned int BlockSize() const {assert(m_register.size() > 0); return m_register.size();} - void SetIV(const byte *iv); virtual void SetFeedbackSize(unsigned int feedbackSize) { if (!(feedbackSize == 0 || feedbackSize == BlockSize())) @@ -57,7 +56,7 @@ protected: { m_register.New(m_cipher->BlockSize()); } - virtual void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length) =0; + virtual void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv) =0; BlockCipher *m_cipher; SecByteBlock m_register; @@ -73,8 +72,6 @@ class ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE ResizeBuffers(); int feedbackSize = params.GetIntValueWithDefault(Name::FeedbackSize(), 0); SetFeedbackSize(feedbackSize); - const byte *iv = params.GetValueWithDefault(Name::IV(), (const byte *)NULL); - SetIV(iv); } }; @@ -113,6 +110,14 @@ protected: unsigned int m_feedbackSize; }; +inline void CopyOrZero(void *dest, const void *src, size_t s) +{ + if (src) + memcpy(dest, src, s); + else + memset(dest, 0, s); +} + class OFB_ModePolicy : public ModePolicyCommonTemplate { unsigned int GetBytesPerIteration() const {return BlockSize();} @@ -124,7 +129,7 @@ class OFB_ModePolicy : public ModePolicyCommonTemplate class CipherModeFinalTemplate_ExternalCipher : public BASE { public: - CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv = NULL, int feedbackSize = 0) + CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher) + { + ThrowIfResynchronizable(); + m_cipher = &cipher; + ResizeBuffers(); + } + + CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize = 0) { + ThrowIfInvalidIV(iv); m_cipher = &cipher; ResizeBuffers(); SetFeedbackSize(feedbackSize); - SetIV(iv); + if (IsResynchronizable()) + Resynchronize(iv); } }; -- cgit v1.2.1