diff --git a/Readme.txt b/Readme.txt index 09239172..c7e1c650 100644 --- a/Readme.txt +++ b/Readme.txt @@ -1,5 +1,5 @@ Crypto++: a C++ Class Library of Cryptographic Primitives -Version 5.1 (in development) +Version 5.1 3/20/2003 This library includes: @@ -242,11 +242,11 @@ History 5.01 (special FIPS 140-2 release, in development) - added known answer test for X9.17 RNG in FIPS 140 power-up self test -5.1 (in development) - - added PSS padding and changed PSSR to track IEEE P1363a draft standard +5.1 - added PSS padding and changed PSSR to track IEEE P1363a draft standard - added blinding for RSA and Rabin to defend against timing attacks + against decryption operations (required API changes for decryption) - fixed a bug in CBC and ECB modes with processing non-aligned data - fixed standard conformance bugs in DLIES (DHAES mode) and RW/EMSA2 - signature scheme (these fixes are not backwards compatible) - - fixed a number of minor bugs and portability problems - - removed Sapphire + signature scheme (these fixes are not backwards compatible) + - fixed a number of minor bugs and portability problems + - removed Sapphire diff --git a/blumshub.cpp b/blumshub.cpp index f715c84e..40c654af 100644 --- a/blumshub.cpp +++ b/blumshub.cpp @@ -41,9 +41,11 @@ BlumBlumShub::BlumBlumShub(const Integer &p, const Integer &q, const Integer &se void BlumBlumShub::Seek(dword index) { - Integer e = a_exp_b_mod_c (2, ((index*8) / maxBits + 1), (p-1)*(q-1)); + Integer i(Integer::POSITIVE, HIGH_WORD(index), word(index)); + i *= 8; + Integer e = a_exp_b_mod_c (2, i / maxBits + 1, (p-1)*(q-1)); current = modn.Exponentiate(x0, e); - bitsLeft = maxBits - int((index*8) % maxBits); + bitsLeft = maxBits - i % maxBits; } NAMESPACE_END diff --git a/blumshub.h b/blumshub.h index 10b3cac3..dbbb8be4 100644 --- a/blumshub.h +++ b/blumshub.h @@ -29,7 +29,7 @@ public: protected: const ModularArithmetic modn; - const int maxBits; + const word maxBits; Integer current; int bitsLeft; diff --git a/datatest.cpp b/datatest.cpp index eac1d7f1..5d84c017 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -281,6 +281,7 @@ void TestDigestOrMAC(TestData &v, bool testDigest) bool GetField(std::istream &is, std::string &name, std::string &value) { + name.clear(); is >> name; if (name.empty()) return false; @@ -293,8 +294,8 @@ bool GetField(std::istream &is, std::string &name, std::string &value) is.ignore(1); // VC60 workaround: getline bug - char buffer[4]; - value.resize(0); + char buffer[128]; + value.clear(); bool continueLine; do @@ -421,7 +422,7 @@ void TestDataFile(const std::string &filename, unsigned int &totalTests, unsigne failedTests++; } else - cout << "."; + cout << "." << flush; totalTests++; } diff --git a/ida.cpp b/ida.cpp index d52e443b..3bec9f80 100644 --- a/ida.cpp +++ b/ida.cpp @@ -45,7 +45,7 @@ void RawIDA::ChannelInitialize(const string &channel, const NameValuePairs ¶ else { int nShares = parameters.GetIntValueWithDefault("NumberOfShares", m_threshold); - for (unsigned int i=0; i 0 : m_channelsReady == m_threshold) { @@ -181,7 +181,7 @@ void RawIDA::ProcessInputQueues() m_channelsReady += queue.NumberOfMessages() > 0 || queue.MaxRetrievable() >= 4; } - for (i=0; i(value)); } +Integer::Integer(Sign s, word high, word low) + : reg(2), sign(s) +{ + reg[0] = low; + reg[1] = high; +} + bool Integer::IsConvertableToLong() const { if (ByteCount() > sizeof(long)) diff --git a/integer.h b/integer.h index b79c07cc..fcf3ebef 100644 --- a/integer.h +++ b/integer.h @@ -66,6 +66,9 @@ public: RandomNumberNotFound() : Exception(OTHER_ERROR, "Integer: no integer satisfies the given parameters") {} }; + //! + enum Sign {POSITIVE=0, NEGATIVE=1}; + //! enum Signedness { //! @@ -92,6 +95,9 @@ public: //! convert from signed long Integer(signed long value); + //! convert from two words + Integer(Sign s, word highWord, word lowWord); + //! convert from string /*! str can be in base 2, 8, 10, or 16. Base is determined by a case insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10. @@ -390,8 +396,6 @@ private: friend void PositiveMultiply(Integer &product, const Integer &a, const Integer &b); friend void PositiveDivide(Integer &remainder, Integer "ient, const Integer ÷nd, const Integer &divisor); - enum Sign {POSITIVE=0, NEGATIVE=1}; - SecAlignedWordBlock reg; Sign sign; }; diff --git a/pssr.cpp b/pssr.cpp index 020cb989..5dc959aa 100644 --- a/pssr.cpp +++ b/pssr.cpp @@ -68,7 +68,7 @@ void PSSR_MEM_Base::ComputeMessageRepresentative(RandomNumberGenerator &rng, memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second); representative[representativeByteLength - 1] = hashIdentifier.second ? 0xcc : 0xbc; if (representativeBitLength % 8 != 0) - representative[0] = Crop(representative[0], representativeBitLength % 8); + representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); } DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative( @@ -94,12 +94,12 @@ DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative( GetMGF().GenerateAndMask(hash, representative, representativeByteLength - u - digestSize, h, digestSize); if (representativeBitLength % 8 != 0) - representative[0] = Crop(representative[0], representativeBitLength % 8); + representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); // extract salt and recoverableMessage from DB = 00 ... || 01 || M || salt byte *salt = representative + representativeByteLength - u - digestSize - saltSize; byte *M = std::find_if(representative, salt-1, std::bind2nd(std::not_equal_to(), 0)); - if (*M == 0x01 && M - representative - (representativeBitLength % 8 != 0) >= MinPadLen(digestSize)) + if (*M == 0x01 && (unsigned int)(M - representative - (representativeBitLength % 8 != 0)) >= MinPadLen(digestSize)) { recoverableMessageLength = salt-M-1; memcpy(recoverableMessage, M+1, recoverableMessageLength); diff --git a/rsa.cpp b/rsa.cpp index 9d690b95..62e95921 100644 --- a/rsa.cpp +++ b/rsa.cpp @@ -26,17 +26,17 @@ void RSA_TestInstantiations() RSASS::Verifier x3(x2); RSASS::Verifier x4(x2.GetKey()); RSASS::Verifier x5(x3); +#ifndef __MWERKS__ RSASS::Signer x6 = x2; + x3 = x2; + x6 = x2; +#endif RSAES::Encryptor x7(x2); #ifndef __GNUC__ RSAES::Encryptor x8(x3); #endif RSAES >::Encryptor x9(x2); - x6 = x2; -#ifndef __MWERKS__ - x3 = x2; -#endif x4 = x2.GetKey(); } #endif diff --git a/seal.cpp b/seal.cpp index eaae7a77..97362233 100644 --- a/seal.cpp +++ b/seal.cpp @@ -77,8 +77,8 @@ void SEAL_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV) template void SEAL_Policy::SeekToIteration(dword iterationCount) { - m_outsideCounter = m_startCount + iterationCount / m_iterationsPerCount; - m_insideCounter = iterationCount % m_iterationsPerCount; + m_outsideCounter = m_startCount + (unsigned int)(iterationCount / m_iterationsPerCount); + m_insideCounter = (unsigned int)(iterationCount % m_iterationsPerCount); } template diff --git a/shark.cpp b/shark.cpp index fff3bfda..0408d8e1 100644 --- a/shark.cpp +++ b/shark.cpp @@ -28,7 +28,7 @@ static word64 SHARKTransform(word64 a) GF256 gf256(0xf5); for (unsigned int i=0; i<8; i++) for(unsigned int j=0; j<8; j++) - result ^= word64(gf256.Multiply(iG[i][j], a>>(56-8*j))) << (56-8*i); + result ^= word64(gf256.Multiply(iG[i][j], GF256::Element(a>>(56-8*j)))) << (56-8*i); return result; } diff --git a/strciphr.cpp b/strciphr.cpp index 78e1a3f0..d948c579 100644 --- a/strciphr.cpp +++ b/strciphr.cpp @@ -99,7 +99,7 @@ void AdditiveCipherTemplate::Seek(dword position) if (position > 0) { policy.WriteKeystream(m_buffer, 1); - m_leftOver = bytesPerIteration - position; + m_leftOver = bytesPerIteration - (unsigned int)position; } else m_leftOver = 0; diff --git a/test.cpp b/test.cpp index f12b199a..21eb4f3c 100644 --- a/test.cpp +++ b/test.cpp @@ -638,7 +638,7 @@ void SecretShareFile(int threshold, int nShares, const char *filename, const cha vector_member_ptrs fileSinks(nShares); string channel; - for (unsigned int i=0; i fileSources(threshold); SecByteBlock channel(4); - unsigned int i; + int i; for (i=0; i t1)) + while (total < 16 && (t1 < 10 || total*8 > (unsigned long)t1)) { test.Pump(1); total += 1; diff --git a/wait.cpp b/wait.cpp index c97d7140..99a2ad49 100644 --- a/wait.cpp +++ b/wait.cpp @@ -94,7 +94,7 @@ DWORD WINAPI WaitingThread(LPVOID lParam) handles[0] = thread.stopWaiting; std::copy(thread.waitHandles, thread.waitHandles+thread.count, handles.begin()+1); - DWORD result = ::WaitForMultipleObjects(handles.size(), handles.begin(), FALSE, INFINITE); + DWORD result = ::WaitForMultipleObjects(handles.size(), &handles[0], FALSE, INFINITE); if (result == WAIT_OBJECT_0) continue; // another thread finished waiting first, so do nothing @@ -154,7 +154,7 @@ bool WaitObjectContainer::Wait(unsigned long milliseconds) Sleep(0); if (i