From 572fe07633123ce38abf28c6426356e37aef3a99 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 4 Jul 2003 00:17:37 +0000 Subject: create DLL version, fix GetNextIV() bug in CTR and OFB modes git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@87 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- modes.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'modes.cpp') diff --git a/modes.cpp b/modes.cpp index 09c370e..0d163cb 100644 --- a/modes.cpp +++ b/modes.cpp @@ -1,14 +1,18 @@ // modes.cpp - written and placed in the public domain by Wei Dai #include "pch.h" + +#ifndef CRYPTOPP_IMPORTS + #include "modes.h" +#ifndef NDEBUG #include "des.h" - -#include "strciphr.cpp" +#endif NAMESPACE_BEGIN(CryptoPP) +#ifndef NDEBUG void Modes_TestInstantiations() { CFB_Mode::Encryption m0; @@ -18,17 +22,7 @@ void Modes_TestInstantiations() ECB_Mode::Encryption m4; CBC_Mode::Encryption m5; } - -// explicit instantiations for Darwin gcc-932.1 -template class CFB_CipherTemplate >; -template class CFB_EncryptionTemplate<>; -template class CFB_DecryptionTemplate<>; -template class AdditiveCipherTemplate<>; -template class CFB_CipherTemplate >; -template class CFB_EncryptionTemplate >; -template class CFB_DecryptionTemplate >; -template class AdditiveCipherTemplate >; -template class AdditiveCipherTemplate >; +#endif void CipherModeBase::SetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) { @@ -64,8 +58,15 @@ static inline void IncrementCounterByOne(byte *inout, unsigned int s) static inline void IncrementCounterByOne(byte *output, const byte *input, unsigned int s) { - for (int i=s-1, carry=1; i>=0; i--) - carry = !(output[i] = input[i]+carry) && carry; + int i, carry; + for (i=s-1, carry=1; i>=0 && carry; i--) + carry = !(output[i] = input[i]+1); + memcpy(output, input, i+1); +} + +void CTR_ModePolicy::GetNextIV(byte *IV) +{ + IncrementCounterByOne(IV, m_counterArray, BlockSize()); } inline void CTR_ModePolicy::ProcessMultipleBlocks(byte *output, const byte *input, unsigned int n) @@ -248,3 +249,5 @@ void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString, } NAMESPACE_END + +#endif -- cgit v1.2.1