Merge dev-branch 'trap' into 'master'

This commit is contained in:
Jeffrey Walton 2016-09-17 17:21:53 -04:00
commit 01b4ada148
123 changed files with 929 additions and 666 deletions

View File

@ -7,7 +7,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ThreeWay_TestInstantiations()
{
ThreeWay::Encryption x1;

View File

@ -263,6 +263,7 @@ strciphr.h
tea.cpp
tea.h
test.cpp
trap.h
tftables.cpp
tiger.cpp
tiger.h

View File

@ -46,8 +46,8 @@ void Adler32::Update(const byte *input, size_t length)
s2 %= BASE;
}
assert(s1 < BASE);
assert(s2 < BASE);
CRYPTOPP_ASSERT(s1 < BASE);
CRYPTOPP_ASSERT(s2 < BASE);
m_s1 = (word16)s1;
m_s2 = (word16)s2;

View File

@ -262,7 +262,7 @@ void AbstractGroup<T>::SimultaneousMultiply(T *results, const T &base, const Int
for (i=0; i<expCount; i++)
{
assert(expBegin->NotNegative());
CRYPTOPP_ASSERT(expBegin->NotNegative());
exponents.push_back(WindowSlider(*expBegin++, InversionIsFast(), 0));
exponents[i].FindNextWindow();
buckets[i].resize(((size_t) 1) << (exponents[i].windowSize-1), Identity());

View File

@ -22,7 +22,7 @@ bool CombinedNameValuePairs::GetVoidValue(const char *name, const std::type_info
void AlgorithmParametersBase::operator=(const AlgorithmParametersBase &rhs)
{
CRYPTOPP_UNUSED(rhs);
assert(false);
CRYPTOPP_ASSERT(false);
}
bool AlgorithmParametersBase::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const

View File

@ -74,7 +74,7 @@ public:
void Assign(const byte *data, size_t size, bool deepCopy)
{
// This fires, which means: no data with a size, or data with no size.
// assert((data && size) || !(data || size));
// CRYPTOPP_ASSERT((data && size) || !(data || size));
if (deepCopy)
m_block.Assign(data, size);
else

View File

@ -13,7 +13,7 @@
NAMESPACE_BEGIN(CryptoPP)
namespace Weak1 {
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ARC4_TestInstantiations()
{
ARC4 x;

View File

@ -244,7 +244,7 @@ size_t OID::DecodeValue(BufferedTransformation &bt, word32 &v)
void OID::DEREncode(BufferedTransformation &bt) const
{
assert(m_values.size() >= 2);
CRYPTOPP_ASSERT(m_values.size() >= 2);
ByteQueue temp;
temp.Put(byte(m_values[0] * 40 + m_values[1]));
for (size_t i=2; i<m_values.size(); i++)
@ -412,7 +412,7 @@ BERGeneralDecoder::~BERGeneralDecoder()
}
catch (const Exception&)
{
// assert(0);
// CRYPTOPP_ASSERT(0);
}
}
@ -506,7 +506,7 @@ DERGeneralEncoder::~DERGeneralEncoder()
}
catch (const Exception&)
{
assert(0);
CRYPTOPP_ASSERT(0);
}
}

4
asn.h
View File

@ -239,7 +239,7 @@ public:
~BERGeneralDecoder();
bool IsDefiniteLength() const {return m_definiteLength;}
lword RemainingLength() const {assert(m_definiteLength); return m_length;}
lword RemainingLength() const {CRYPTOPP_ASSERT(m_definiteLength); return m_length;}
bool EndReached() const;
byte PeekByte() const;
void CheckByte(byte b);
@ -258,7 +258,7 @@ protected:
private:
void Init(byte asnTag);
void StoreInitialize(const NameValuePairs &parameters)
{CRYPTOPP_UNUSED(parameters); assert(false);}
{CRYPTOPP_UNUSED(parameters); CRYPTOPP_ASSERT(false);}
lword ReduceLength(lword delta);
};

View File

@ -97,7 +97,7 @@ void AuthenticatedSymmetricCipherBase::Update(const byte *input, size_t length)
m_totalFooterLength += length;
break;
default:
assert(false);
CRYPTOPP_ASSERT(false);
}
}
@ -129,7 +129,7 @@ reswitch:
AuthenticateData(outString, length);
break;
default:
assert(false);
CRYPTOPP_ASSERT(false);
}
}
@ -169,7 +169,7 @@ void AuthenticatedSymmetricCipherBase::TruncatedFinal(byte *mac, size_t macSize)
break;
default:
assert(false);
CRYPTOPP_ASSERT(false);
}
m_state = State_KeySet;

View File

@ -31,7 +31,7 @@ public:
//! \param params additional parameters passed as NameValuePairs
//! \details key must be at least DEFAULT_KEYLENGTH in length.
void UncheckedSetKey(const byte * key, unsigned int length,const CryptoPP::NameValuePairs &params)
{CRYPTOPP_UNUSED(key), CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params); assert(false);}
{CRYPTOPP_UNUSED(key), CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params); CRYPTOPP_ASSERT(false);}
void SetKey(const byte *userKey, size_t keylength, const NameValuePairs &params);
void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}

View File

@ -57,7 +57,7 @@ size_t BaseN_Encoder::Put2(const byte *begin, size_t length, int messageEnd, boo
unsigned int b = begin[m_inputPosition++], bitsLeftInSource = 8;
while (true)
{
assert(m_bitsPerChar-m_bitPos >= 0);
CRYPTOPP_ASSERT(m_bitsPerChar-m_bitPos >= 0);
unsigned int bitsLeftInTarget = (unsigned int)(m_bitsPerChar-m_bitPos);
m_outBuf[m_bytePos] |= b >> (8-bitsLeftInTarget);
if (bitsLeftInSource >= bitsLeftInTarget)
@ -78,13 +78,13 @@ size_t BaseN_Encoder::Put2(const byte *begin, size_t length, int messageEnd, boo
}
}
assert(m_bytePos <= m_outputBlockSize);
CRYPTOPP_ASSERT(m_bytePos <= m_outputBlockSize);
if (m_bytePos == m_outputBlockSize)
{
int i;
for (i=0; i<m_bytePos; i++)
{
assert(m_outBuf[i] < (1 << m_bitsPerChar));
CRYPTOPP_ASSERT(m_outBuf[i] < (1 << m_bitsPerChar));
m_outBuf[i] = m_alphabet[m_outBuf[i]];
}
FILTER_OUTPUT(1, m_outBuf, m_outputBlockSize, 0);
@ -183,14 +183,14 @@ void BaseN_Decoder::InitializeDecodingLookupArray(int *lookup, const byte *alpha
{
if (caseInsensitive && isalpha(alphabet[i]))
{
assert(lookup[toupper(alphabet[i])] == -1);
CRYPTOPP_ASSERT(lookup[toupper(alphabet[i])] == -1);
lookup[toupper(alphabet[i])] = i;
assert(lookup[tolower(alphabet[i])] == -1);
CRYPTOPP_ASSERT(lookup[tolower(alphabet[i])] == -1);
lookup[tolower(alphabet[i])] = i;
}
else
{
assert(lookup[alphabet[i]] == -1);
CRYPTOPP_ASSERT(lookup[alphabet[i]] == -1);
lookup[alphabet[i]] = i;
}
}

View File

@ -385,9 +385,9 @@ void BenchmarkAll(double t, double hertz)
const time_t endTime = time(NULL);
err = localtime_s(&localTime, &endTime);
assert(err == 0);
CRYPTOPP_ASSERT(err == 0);
err = asctime_s(timeBuf, sizeof(timeBuf), &localTime);
assert(err == 0);
CRYPTOPP_ASSERT(err == 0);
cout << "\nTest ended at " << timeBuf;
#else

View File

@ -352,7 +352,7 @@ BLAKE2_Base<W, T_64bit>::BLAKE2_Base() : m_state(1), m_block(1), m_digestSize(DI
template <class W, bool T_64bit>
BLAKE2_Base<W, T_64bit>::BLAKE2_Base(bool treeMode, unsigned int digestSize) : m_state(1), m_block(1), m_digestSize(digestSize), m_treeMode(treeMode)
{
assert(digestSize <= DIGESTSIZE);
CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE);
UncheckedSetKey(NULL, 0, g_nullNameValuePairs);
Restart();
@ -363,10 +363,10 @@ BLAKE2_Base<W, T_64bit>::BLAKE2_Base(const byte *key, size_t keyLength, const by
const byte* personalization, size_t personalizationLength, bool treeMode, unsigned int digestSize)
: m_state(1), m_block(1), m_digestSize(digestSize), m_treeMode(treeMode)
{
assert(keyLength <= MAX_KEYLENGTH);
assert(digestSize <= DIGESTSIZE);
assert(saltLength <= SALTSIZE);
assert(personalizationLength <= PERSONALIZATIONSIZE);
CRYPTOPP_ASSERT(keyLength <= MAX_KEYLENGTH);
CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE);
CRYPTOPP_ASSERT(saltLength <= SALTSIZE);
CRYPTOPP_ASSERT(personalizationLength <= PERSONALIZATIONSIZE);
UncheckedSetKey(key, static_cast<unsigned int>(keyLength), MakeParameters(Name::DigestSize(),(int)digestSize)(Name::TreeMode(),treeMode, false)
(Name::Salt(), ConstByteArrayParameter(salt, saltLength))(Name::Personalization(), ConstByteArrayParameter(personalization, personalizationLength)));
@ -439,7 +439,7 @@ void BLAKE2_Base<W, T_64bit>::Update(const byte *input, size_t length)
// Copy tail bytes
if (input && length)
{
assert(length <= BLOCKSIZE - state.length);
CRYPTOPP_ASSERT(length <= BLOCKSIZE - state.length);
memcpy_s(&state.buffer[state.length], length, input, length);
state.length += static_cast<unsigned int>(length);
}
@ -3470,10 +3470,10 @@ static const int LANE_L64 = 0;
static void BLAKE2_NEON_Compress32(const byte* input, BLAKE2_State<word32, false>& state)
{
//assert(IsAlignedOn(input,GetAlignmentOf<uint8_t*>()));
assert(IsAlignedOn(&state.h[0],GetAlignmentOf<uint32x4_t>()));
assert(IsAlignedOn(&state.h[4],GetAlignmentOf<uint32x4_t>()));
assert(IsAlignedOn(&state.t[0],GetAlignmentOf<uint32x4_t>()));
//CRYPTOPP_ASSERT(IsAlignedOn(input,GetAlignmentOf<uint8_t*>()));
CRYPTOPP_ASSERT(IsAlignedOn(&state.h[0],GetAlignmentOf<uint32x4_t>()));
CRYPTOPP_ASSERT(IsAlignedOn(&state.h[4],GetAlignmentOf<uint32x4_t>()));
CRYPTOPP_ASSERT(IsAlignedOn(&state.t[0],GetAlignmentOf<uint32x4_t>()));
CRYPTOPP_ALIGN_DATA(16) uint32_t m0[4], m1[4], m2[4], m3[4], m4[4], m5[4], m6[4], m7[4];
CRYPTOPP_ALIGN_DATA(16) uint32_t m8[4], m9[4], m10[4], m11[4], m12[4], m13[4], m14[4], m15[4];
@ -3976,10 +3976,10 @@ static void BLAKE2_NEON_Compress32(const byte* input, BLAKE2_State<word32, false
static void BLAKE2_NEON_Compress64(const byte* input, BLAKE2_State<word64, true>& state)
{
//assert(IsAlignedOn(input,GetAlignmentOf<uint8_t*>()));
assert(IsAlignedOn(&state.h[0],GetAlignmentOf<uint64x2_t>()));
assert(IsAlignedOn(&state.h[4],GetAlignmentOf<uint64x2_t>()));
assert(IsAlignedOn(&state.t[0],GetAlignmentOf<uint64x2_t>()));
//CRYPTOPP_ASSERT(IsAlignedOn(input,GetAlignmentOf<uint8_t*>()));
CRYPTOPP_ASSERT(IsAlignedOn(&state.h[0],GetAlignmentOf<uint64x2_t>()));
CRYPTOPP_ASSERT(IsAlignedOn(&state.h[4],GetAlignmentOf<uint64x2_t>()));
CRYPTOPP_ASSERT(IsAlignedOn(&state.t[0],GetAlignmentOf<uint64x2_t>()));
uint64x2_t m0m1,m2m3,m4m5,m6m7,m8m9,m10m11,m12m13,m14m15;

View File

@ -72,7 +72,7 @@ struct CRYPTOPP_NO_VTABLE BLAKE2_ParameterBlock<true>
BLAKE2_ParameterBlock(size_t digestSize)
{
assert(digestSize <= DIGESTSIZE);
CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE);
memset(this, 0x00, sizeof(*this));
digestLength = (byte)digestSize;
fanout = depth = 1;
@ -107,7 +107,7 @@ struct CRYPTOPP_NO_VTABLE BLAKE2_ParameterBlock<false>
BLAKE2_ParameterBlock(size_t digestSize)
{
assert(digestSize <= DIGESTSIZE);
CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE);
memset(this, 0x00, sizeof(*this));
digestLength = (byte)digestSize;
fanout = depth = 1;

View File

@ -91,13 +91,13 @@ void Camellia::Base::UncheckedSetKey(const byte *key, unsigned int keylen, const
kwl = (word64(k0) << 32) | k1; \
kwr = (word64(k2) << 32) | k3
#define KS_ROUND_0(i) \
assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(0)),GetAlignmentOf<word64>())); \
assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(1)),GetAlignmentOf<word64>())); \
CRYPTOPP_ASSERT(IsAlignedOn(CALC_ADDR(ks32, i+EFI(0)),GetAlignmentOf<word64>())); \
CRYPTOPP_ASSERT(IsAlignedOn(CALC_ADDR(ks32, i+EFI(1)),GetAlignmentOf<word64>())); \
*(word64*)(void*)CALC_ADDR(ks32, i+EFI(0)) = kwl; \
*(word64*)(void*)CALC_ADDR(ks32, i+EFI(1)) = kwr
#define KS_ROUND(i, r, which) \
assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(r<64)),GetAlignmentOf<word64>())); \
assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(r>64)),GetAlignmentOf<word64>())); \
CRYPTOPP_ASSERT(IsAlignedOn(CALC_ADDR(ks32, i+EFI(r<64)),GetAlignmentOf<word64>())); \
CRYPTOPP_ASSERT(IsAlignedOn(CALC_ADDR(ks32, i+EFI(r>64)),GetAlignmentOf<word64>())); \
if (which & (1<<int(r<64))) *(word64*)(void*)CALC_ADDR(ks32, i+EFI(r<64)) = (kwr << (r%64)) | (kwl >> (64 - (r%64))); \
if (which & (1<<int(r>64))) *(word64*)(void*)CALC_ADDR(ks32, i+EFI(r>64)) = (kwl << (r%64)) | (kwr >> (64 - (r%64)))
#else
@ -222,7 +222,7 @@ void Camellia::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBloc
volatile word32 _u = 0;
word32 u = _u;
assert(IsAlignedOn(s1,GetAlignmentOf<word32>()));
CRYPTOPP_ASSERT(IsAlignedOn(s1,GetAlignmentOf<word32>()));
for (i=0; i<256; i+=cacheLineSize)
u &= *(const word32 *)(void*)(s1+i);
u &= *(const word32 *)(void*)(s1+252);

View File

@ -282,7 +282,7 @@ void CAST256::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength,
int i1=8*j+i;
int i2=8*(11-j)+i;
assert(i1<i2);
CRYPTOPP_ASSERT(i1<i2);
std::swap(K[i1],K[i2]);
std::swap(K[i1+4],K[i2+4]);

View File

@ -30,7 +30,7 @@ void CCM_Base::Resync(const byte *iv, size_t len)
BlockCipher &cipher = AccessBlockCipher();
m_L = REQUIRED_BLOCKSIZE-1-(int)len;
assert(m_L >= 2);
CRYPTOPP_ASSERT(m_L >= 2);
if (m_L > 8)
m_L = 8;
@ -66,7 +66,7 @@ void CCM_Base::UncheckedSpecifyDataLengths(lword headerLength, lword messageLeng
if (headerLength>0)
{
assert(m_bufferedDataLength == 0);
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
if (headerLength < ((1<<16) - (1<<8)))
{

View File

@ -18,7 +18,7 @@ NAMESPACE_BEGIN(CryptoPP)
a += b; d ^= a; d = rotlFixed<word32>(d, 8); \
c += d; b ^= c; b = rotlFixed<word32>(b, 7);
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ChaCha_TestInstantiations()
{
ChaCha8::Encryption x1;
@ -31,7 +31,7 @@ template <unsigned int R>
void ChaCha_Policy<R>::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
{
CRYPTOPP_UNUSED(params);
assert(length == 16 || length == 32);
CRYPTOPP_ASSERT(length == 16 || length == 32);
// "expand 16-byte k" or "expand 32-byte k"
m_state[0] = 0x61707865;
@ -50,7 +50,7 @@ template <unsigned int R>
void ChaCha_Policy<R>::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer), CRYPTOPP_UNUSED(length);
assert(length==8);
CRYPTOPP_ASSERT(length==8);
GetBlock<word32, LittleEndian> get(IV);
m_state[12] = m_state[13] = 0;

View File

@ -57,7 +57,7 @@ void CMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const Name
void CMAC_Base::Update(const byte *input, size_t length)
{
assert((input && length) || !(input || length));
CRYPTOPP_ASSERT((input && length) || !(input || length));
if (!length)
return;
@ -84,7 +84,7 @@ void CMAC_Base::Update(const byte *input, size_t length)
if (length > blockSize)
{
assert(m_counter == 0);
CRYPTOPP_ASSERT(m_counter == 0);
size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, input, m_reg, length-1, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
input += (length - leftOver);
length = leftOver;
@ -92,12 +92,12 @@ void CMAC_Base::Update(const byte *input, size_t length)
if (length > 0)
{
assert(m_counter + length <= blockSize);
CRYPTOPP_ASSERT(m_counter + length <= blockSize);
xorbuf(m_reg+m_counter, input, length);
m_counter += (unsigned int)length;
}
assert(m_counter > 0);
CRYPTOPP_ASSERT(m_counter > 0);
}
void CMAC_Base::TruncatedFinal(byte *mac, size_t size)

View File

@ -138,6 +138,16 @@
# define CRYPTOPP_USER_PRIORITY 250
#endif
// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT
// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT
// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike
// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to
// define it).
// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2010-4179
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG)
# define CRYPTOPP_DEBUG 1
#endif
// ***************** Important Settings Again ********************
// But the defaults should be ok.

View File

@ -138,6 +138,16 @@
# define CRYPTOPP_USER_PRIORITY 250
#endif
// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT
// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT
// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike
// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to
// define it).
// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2010-4179
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG)
# define CRYPTOPP_DEBUG 1
#endif
// ***************** Important Settings Again ********************
// But the defaults should be ok.

View File

@ -895,6 +895,7 @@ IF %ERRORLEVEL% EQU 0 (echo mac done &gt; "$(OutDir)"\cryptopp.mac.done)
<ClInclude Include="smartptr.h" />
<ClInclude Include="stdcpp.h" />
<ClInclude Include="strciphr.h" />
<ClInclude Include="trap.h" />
<ClInclude Include="trdlocal.h" />
<ClInclude Include="words.h" />
</ItemGroup>

View File

@ -370,6 +370,9 @@
<ClInclude Include="strciphr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trdlocal.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@ -109,7 +109,7 @@ if [[ "$IS_SOLARIS" -ne "0" ]]; then
IS_X86=0
fi
# Need something more powerful than the non-Posix versions
# Need something more powerful than the Posix versions
if [[ (-e "/usr/gnu/bin/grep") ]]; then
GREP=/usr/gnu/bin/grep;
fi
@ -1116,6 +1116,40 @@ TEST_BEGIN=$(date)
echo | tee -a "$TEST_RESULTS"
echo "Start time: $TEST_BEGIN" | tee -a "$TEST_RESULTS"
############################################
# Posix assert
if true; then
echo
echo "************************************" | tee -a "$TEST_RESULTS"
echo "Testing: No Posix assert" | tee -a "$TEST_RESULTS"
echo
FAILED=0
COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$GREP" -c '(assert.h|cassert)')
if [[ "$COUNT" -ne "0" ]]; then
FAILED=1
echo "Found Posix assert headers" | tee -a "$TEST_RESULTS"
fi
COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$GREP" -c 'assert[[:space:]]*\\(')
if [[ "$COUNT" -ne "0" ]]; then
FAILED=1
echo "Found use of Posix assert" | tee -a "$TEST_RESULTS"
fi
# Filter out use of C++ and Doxygen comments.
COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$GREP" -c 'NDEBUG')
if [[ "$COUNT" -ne "0" ]]; then
FAILED=1
echo "Found use of Posix NDEBUG" | tee -a "$TEST_RESULTS"
fi
if [[ ("$FAILED" -eq "0") ]]; then
echo "Verified no Posix NDEBUG or assert" | tee -a "$TEST_RESULTS"
fi
fi
############################################
# X86 code generation tests
if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; then

View File

@ -181,9 +181,9 @@ void SimpleKeyingInterface::GetNextIV(RandomNumberGenerator &rng, byte *IV)
size_t BlockTransformation::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const
{
assert(inBlocks);
assert(outBlocks);
assert(length);
CRYPTOPP_ASSERT(inBlocks);
CRYPTOPP_ASSERT(outBlocks);
CRYPTOPP_ASSERT(length);
size_t blockSize = BlockSize();
size_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize;
@ -192,7 +192,7 @@ size_t BlockTransformation::AdvancedProcessBlocks(const byte *inBlocks, const by
if (flags & BT_ReverseDirection)
{
assert(length % blockSize == 0);
CRYPTOPP_ASSERT(length % blockSize == 0);
inBlocks += length - blockSize;
xorBlocks += length - blockSize;
outBlocks += length - blockSize;
@ -206,7 +206,7 @@ size_t BlockTransformation::AdvancedProcessBlocks(const byte *inBlocks, const by
if (flags & BT_XorInput)
{
// Coverity finding. However, xorBlocks is never NULL if BT_XorInput.
assert(xorBlocks);
CRYPTOPP_ASSERT(xorBlocks);
#if defined(__COVERITY__)
if (xorBlocks)
#endif
@ -247,7 +247,7 @@ unsigned int HashTransformation::OptimalDataAlignment() const
void StreamTransformation::ProcessLastBlock(byte *outString, const byte *inString, size_t length)
{
assert(MinLastBlockSize() == 0); // this function should be overriden otherwise
CRYPTOPP_ASSERT(MinLastBlockSize() == 0); // this function should be overriden otherwise
if (length == MandatoryBlockSize())
ProcessData(outString, inString, length);
@ -320,7 +320,7 @@ word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max)
// see https://github.com/weidai11/cryptopp/issues/38.
//
// According to Wei, RandomNumberGenerator is an interface, and it should not
// be instantiable. Its now spilt milk, and we are going to assert it in Debug
// be instantiable. Its now spilt milk, and we are going to CRYPTOPP_ASSERT it in Debug
// builds to alert the programmer and throw in Release builds. Developers have
// a reference implementation in case its needed. If a programmer
// unintentionally lands here, then they should ensure use of a
@ -353,7 +353,7 @@ void RandomNumberGenerator::GenerateIntoBufferedTransformation(BufferedTransform
size_t len = UnsignedMin(buffer.size(), length);
GenerateBlock(buffer, len);
size_t rem = target.ChannelPut(channel, buffer, len);
CRYPTOPP_UNUSED(rem); assert(rem == 0);
CRYPTOPP_UNUSED(rem); CRYPTOPP_ASSERT(rem == 0);
length -= len;
}
}
@ -439,21 +439,21 @@ void BufferedTransformation::GetWaitObjects(WaitObjectContainer &container, Call
void BufferedTransformation::Initialize(const NameValuePairs &parameters, int propagation)
{
CRYPTOPP_UNUSED(propagation);
assert(!AttachedTransformation());
CRYPTOPP_ASSERT(!AttachedTransformation());
IsolatedInitialize(parameters);
}
bool BufferedTransformation::Flush(bool hardFlush, int propagation, bool blocking)
{
CRYPTOPP_UNUSED(propagation);
assert(!AttachedTransformation());
CRYPTOPP_ASSERT(!AttachedTransformation());
return IsolatedFlush(hardFlush, blocking);
}
bool BufferedTransformation::MessageSeriesEnd(int propagation, bool blocking)
{
CRYPTOPP_UNUSED(propagation);
assert(!AttachedTransformation());
CRYPTOPP_ASSERT(!AttachedTransformation());
return IsolatedMessageSeriesEnd(blocking);
}
@ -592,7 +592,7 @@ bool BufferedTransformation::GetNextMessage()
return AttachedTransformation()->GetNextMessage();
else
{
assert(!AnyMessages());
CRYPTOPP_ASSERT(!AnyMessages());
return false;
}
}
@ -629,7 +629,7 @@ size_t BufferedTransformation::TransferMessagesTo2(BufferedTransformation &targe
return 1;
bool result = GetNextMessage();
CRYPTOPP_UNUSED(result); assert(result);
CRYPTOPP_UNUSED(result); CRYPTOPP_ASSERT(result);
}
return 0;
}
@ -660,7 +660,7 @@ size_t BufferedTransformation::TransferAllTo2(BufferedTransformation &target, co
return AttachedTransformation()->TransferAllTo2(target, channel, blocking);
else
{
assert(!NumberOfMessageSeries());
CRYPTOPP_ASSERT(!NumberOfMessageSeries());
unsigned int messageCount;
do
@ -692,7 +692,7 @@ void BufferedTransformation::CopyAllTo(BufferedTransformation &target, const std
AttachedTransformation()->CopyAllTo(target, channel);
else
{
assert(!NumberOfMessageSeries());
CRYPTOPP_ASSERT(!NumberOfMessageSeries());
while (CopyMessagesTo(target, UINT_MAX, channel)) {}
}
}

View File

@ -85,6 +85,11 @@ and getting us started on the manual.
#include "config.h"
#include "stdcpp.h"
#include "trap.h"
#if defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE)
# include <signal.h>
#endif
#if CRYPTOPP_MSC_VERSION
# pragma warning(push)
@ -715,7 +720,7 @@ protected:
//! \brief Validates the key length
//! \param length the size of the keying material, in bytes
inline void AssertValidKeyLength(size_t length) const
{CRYPTOPP_UNUSED(length); assert(IsValidKeyLength(length));}
{CRYPTOPP_UNUSED(length); CRYPTOPP_ASSERT(IsValidKeyLength(length));}
};
//! \brief Interface for the data processing part of block ciphers
@ -895,11 +900,11 @@ public:
//! \param pos position to seek
//! \throws NotImplemented
//! \details The base class implementation throws NotImplemented. The function
//! asserts IsRandomAccess() in debug builds.
//! \ref CRYPTOPP_ASSERT "asserts" IsRandomAccess() in debug builds.
virtual void Seek(lword pos)
{
CRYPTOPP_UNUSED(pos);
assert(!IsRandomAccess());
CRYPTOPP_ASSERT(!IsRandomAccess());
throw NotImplemented("StreamTransformation: this object doesn't support random access");
}
@ -2001,7 +2006,7 @@ public:
//! \return the attached transformation
//! \details AttachedTransformation() returns NULL if there is no attachment. The non-const
//! version of AttachedTransformation() always returns NULL.
virtual BufferedTransformation *AttachedTransformation() {assert(!Attachable()); return 0;}
virtual BufferedTransformation *AttachedTransformation() {CRYPTOPP_ASSERT(!Attachable()); return 0;}
//! \brief Returns the object immediately attached to this object
//! \return the attached transformation
@ -2017,7 +2022,7 @@ public:
//! \details If a derived class does not override Detach, then the base class throws
//! NotImplemented.
virtual void Detach(BufferedTransformation *newAttachment = 0) {
CRYPTOPP_UNUSED(newAttachment); assert(!Attachable());
CRYPTOPP_UNUSED(newAttachment); CRYPTOPP_ASSERT(!Attachable());
throw NotImplemented("BufferedTransformation: this object is not attachable");
}
@ -2128,7 +2133,7 @@ public:
//! NotImplemented.
//! \sa SupportsPrecomputation(), LoadPrecomputation(), SavePrecomputation()
virtual void Precompute(unsigned int precomputationStorage) {
CRYPTOPP_UNUSED(precomputationStorage); assert(!SupportsPrecomputation());
CRYPTOPP_UNUSED(precomputationStorage); CRYPTOPP_ASSERT(!SupportsPrecomputation());
throw NotImplemented("CryptoMaterial: this object does not support precomputation");
}
@ -2137,13 +2142,13 @@ public:
//! \throws NotImplemented
//! \sa SupportsPrecomputation(), Precompute()
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
{CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");}
{CRYPTOPP_UNUSED(storedPrecomputation); CRYPTOPP_ASSERT(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");}
//! \brief Save precomputation for later use
//! \param storedPrecomputation BufferedTransformation to write the precomputation
//! \throws NotImplemented
//! \sa SupportsPrecomputation(), Precompute()
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
{CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");}
{CRYPTOPP_UNUSED(storedPrecomputation); CRYPTOPP_ASSERT(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");}
//! \brief Perform a quick sanity check
//! \details DoQuickSanityCheck() is for internal library use, and it should not be called by library users.

View File

@ -2391,6 +2391,7 @@ echo: &gt;&gt; adhoc.cpp.copied
<ClInclude Include="strciphr.h" />
<ClInclude Include="tea.h" />
<ClInclude Include="tiger.h" />
<ClInclude Include="trap.h" />
<ClInclude Include="trdlocal.h" />
<ClInclude Include="trunhash.h" />
<ClInclude Include="ttmac.h" />

View File

@ -768,6 +768,9 @@
<ClInclude Include="tiger.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trdlocal.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@ -300,12 +300,12 @@ void TestSignatureScheme(TestData &v)
else if (test == "RandomSign")
{
SignalTestError();
assert(false); // TODO: implement
CRYPTOPP_ASSERT(false); // TODO: implement
}
else
{
SignalTestError();
assert(false);
CRYPTOPP_ASSERT(false);
}
}
@ -345,7 +345,7 @@ void TestAsymmetricCipher(TestData &v)
else
{
SignalTestError();
assert(false);
CRYPTOPP_ASSERT(false);
}
}
@ -443,7 +443,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
while (ss.Pump(64)) {}
ss.PumpAll();
for (int i=0; i<z.length(); i++)
assert(encrypted[i] == z[i]);
CRYPTOPP_ASSERT(encrypted[i] == z[i]);
}*/
if (test != "EncryptXorDigest")
ciphertext = GetDecodedDatum(v, "Ciphertext");
@ -608,7 +608,7 @@ void TestDigestOrMAC(TestData &v, bool testDigest)
else
{
SignalTestError();
assert(false);
CRYPTOPP_ASSERT(false);
}
}
@ -618,7 +618,7 @@ void TestKeyDerivationFunction(TestData &v)
std::string test = GetRequiredDatum(v, "Test");
if(test == "Skip") return;
assert(test == "Verify");
CRYPTOPP_ASSERT(test == "Verify");
std::string key = GetDecodedDatum(v, "Key");
std::string salt = GetDecodedDatum(v, "Salt");
@ -722,7 +722,7 @@ void OutputPair(const NameValuePairs &v, const char *name)
{
Integer x;
bool b = v.GetValue(name, x);
CRYPTOPP_UNUSED(b); assert(b);
CRYPTOPP_UNUSED(b); CRYPTOPP_ASSERT(b);
cout << name << ": \\\n ";
x.Encode(HexEncoder(new FileSink(cout), false, 64, "\\\n ").Ref(), x.MinEncodedSize());
cout << endl;
@ -768,7 +768,7 @@ void TestDataFile(std::string filename, const NameValuePairs &overrideParameters
while (file)
{
while (file.peek() == '#')
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
file.ignore((std::numeric_limits<std::streamsize>::max)(), '\n');
if (file.peek() == '\n' || file.peek() == '\r')
v.clear();

2
dh.cpp
View File

@ -8,7 +8,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void DH_TestInstantiations()
{
DH dh1;

View File

@ -5,7 +5,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void DH2_TestInstantiations()
{
DH2 dh(*(SimpleKeyAgreementDomain*)NULL);

10
dll.h
View File

@ -47,15 +47,15 @@
#ifdef _DLL
// cause CRT DLL to be initialized before Crypto++ so that we can use malloc and free during DllMain()
#ifdef NDEBUG
#pragma comment(lib, "msvcrt")
#ifdef CRYPTOPP_DEBUG
# pragma comment(lib, "msvcrtd")
# pragma comment(lib, "cryptopp")
#else
#pragma comment(lib, "msvcrtd")
# pragma comment(lib, "msvcrt")
# pragma comment(lib, "cryptopp")
#endif
#endif
#pragma comment(lib, "cryptopp")
#endif // #ifdef CRYPTOPP_IMPORTS
#include <new> // for new_handler

View File

@ -133,7 +133,7 @@ void FIPS140_SampleApplication()
// sign and verify
byte signature[40];
DSA::Signer signer(dsaPrivateKey);
assert(signer.SignatureLength() == 40);
CRYPTOPP_ASSERT(signer.SignatureLength() == 40);
signer.SignMessage(rng, message, 3, signature);
DSA::Verifier verifier(dsaPublicKey);

View File

@ -34,7 +34,7 @@ size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
void EAX_Base::AuthenticateLastHeaderBlock()
{
assert(m_bufferedDataLength == 0);
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
MessageAuthenticationCode &mac = AccessMAC();
unsigned int blockSize = mac.TagSize();
@ -48,7 +48,7 @@ void EAX_Base::AuthenticateLastHeaderBlock()
void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
{
assert(m_bufferedDataLength == 0);
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
MessageAuthenticationCode &mac = AccessMAC();
unsigned int blockSize = mac.TagSize();

View File

@ -71,11 +71,11 @@ bool EC2N::DecodePoint(EC2N::Point &P, BufferedTransformation &bt, size_t encode
}
FieldElement z = m_field->Square(P.x);
assert(P.x == m_field->SquareRoot(z));
CRYPTOPP_ASSERT(P.x == m_field->SquareRoot(z));
P.y = m_field->Divide(m_field->Add(m_field->Multiply(z, m_field->Add(P.x, m_a)), m_b), z);
assert(P.x == m_field->Subtract(m_field->Divide(m_field->Subtract(m_field->Multiply(P.y, z), m_b), z), m_a));
CRYPTOPP_ASSERT(P.x == m_field->Subtract(m_field->Divide(m_field->Subtract(m_field->Multiply(P.y, z), m_b), z), m_a));
z = m_field->SolveQuadraticEquation(P.y);
assert(m_field->Add(m_field->Square(z), z) == P.y);
CRYPTOPP_ASSERT(m_field->Add(m_field->Square(z), z) == P.y);
z.SetCoefficient(0, type & 1);
P.y = m_field->Multiply(z, P.x);
@ -119,7 +119,7 @@ void EC2N::EncodePoint(byte *encodedPoint, const Point &P, bool compressed) cons
{
ArraySink sink(encodedPoint, EncodedPointSize(compressed));
EncodePoint(sink, P, compressed);
assert(sink.TotalPutLength() == EncodedPointSize(compressed));
CRYPTOPP_ASSERT(sink.TotalPutLength() == EncodedPointSize(compressed));
}
EC2N::Point EC2N::BERDecodePoint(BufferedTransformation &bt) const

View File

@ -31,7 +31,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if 0
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
static void ECDSA_TestInstantiations()
{
ECDSA<EC2N>::Signer t1;
@ -457,7 +457,7 @@ template <class EC> void DL_GroupParameters_EC<EC>::Initialize(const OID &oid)
this->SetSubgroupGenerator(G);
// TODO: this fails in practice. Should it throw?
CRYPTOPP_UNUSED(result); assert(result);
CRYPTOPP_UNUSED(result); CRYPTOPP_ASSERT(result);
StringSource ssN(param.n, true, new HexDecoder);
m_n.Decode(ssN, (size_t)ssN.MaxRetrievable());

View File

@ -140,7 +140,7 @@ void ECP::EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const
{
ArraySink sink(encodedPoint, EncodedPointSize(compressed));
EncodePoint(sink, P, compressed);
assert(sink.TotalPutLength() == EncodedPointSize(compressed));
CRYPTOPP_ASSERT(sink.TotalPutLength() == EncodedPointSize(compressed));
}
ECP::Point ECP::BERDecodePoint(BufferedTransformation &bt) const
@ -384,7 +384,7 @@ void ECP::SimultaneousMultiply(ECP::Point *results, const ECP::Point &P, const I
for (i=0; i<expCount; i++)
{
assert(expBegin->NotNegative());
CRYPTOPP_ASSERT(expBegin->NotNegative());
exponents.push_back(WindowSlider(*expBegin++, InversionIsFast(), 5));
exponents[i].FindNextWindow();
}

View File

@ -7,7 +7,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ElGamal_TestInstantiations()
{
ElGamalEncryptor test1(1, 1, 1);

View File

@ -13,7 +13,7 @@ void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator& /*rng*/,
byte *representative, size_t representativeBitLength) const
{
CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength), CRYPTOPP_UNUSED(representativeBitLength);
assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
CRYPTOPP_ASSERT(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
if (representativeBitLength % 8 != 7)
throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");

View File

@ -27,8 +27,8 @@ template <class T> void DL_FixedBasePrecomputationImpl<T>::SetBase(const DL_Grou
template <class T> void DL_FixedBasePrecomputationImpl<T>::Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage)
{
assert(m_bases.size() > 0);
assert(storage <= maxExpBits);
CRYPTOPP_ASSERT(m_bases.size() > 0);
CRYPTOPP_ASSERT(storage <= maxExpBits);
if (storage > 1)
{

View File

@ -18,7 +18,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ESIGN_TestInstantiations()
{
ESIGN<SHA>::Verifier x1(1, 1);
@ -125,7 +125,7 @@ void InvertibleESIGNFunction::GenerateRandom(RandomNumberGenerator &rng, const N
m_n = m_p * m_p * m_q;
assert(m_n.BitCount() == (unsigned int)modulusSize);
CRYPTOPP_ASSERT(m_n.BitCount() == (unsigned int)modulusSize);
}
void InvertibleESIGNFunction::BERDecode(BufferedTransformation &bt)
@ -174,7 +174,7 @@ Integer InvertibleESIGNFunction::CalculateRandomizedInverse(RandomNumberGenerato
ModularArithmetic modp(m_p);
Integer t = modp.Divide(w0 * r % m_p, m_e * re % m_p);
Integer s = r + t*pq;
assert(s < m_n);
CRYPTOPP_ASSERT(s < m_n);
#if 0
using namespace std;
cout << "f = " << x << endl;

View File

@ -171,7 +171,7 @@ public:
}
else
{
assert(0);
CRYPTOPP_ASSERT(0);
return false;
}
@ -248,7 +248,7 @@ protected:
{
HASH hash;
size_t idx = 0, req = dlen;
size_t blk = std::min(dlen, (size_t)HASH::DIGESTSIZE);
size_t blk = STDMIN(dlen, (size_t)HASH::DIGESTSIZE);
if(sigma)
{
@ -272,7 +272,7 @@ protected:
hash.Update(&digest[idx], (size_t)HASH::DIGESTSIZE);
idx += (size_t)HASH::DIGESTSIZE;
blk = std::min(req, (size_t)HASH::DIGESTSIZE);
blk = STDMIN(req, (size_t)HASH::DIGESTSIZE);
hash.TruncatedFinal(&digest[idx], blk);
req -= blk;

View File

@ -10,7 +10,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Files_TestInstantiations()
{
FileStore f0;
@ -141,7 +141,7 @@ size_t FileStore::CopyRangeTo2(BufferedTransformation &target, lword &begin, lwo
m_stream->seekg(newPosition);
try
{
assert(!m_waiting);
CRYPTOPP_ASSERT(!m_waiting);
lword copyMax = end-begin;
size_t blockedBytes = const_cast<FileStore *>(this)->TransferTo2(target, copyMax, channel, blocking);
begin += copyMax;

View File

@ -188,7 +188,7 @@ size_t MeterFilter::PutMaybeModifiable(byte *begin, size_t length, int messageEn
{
FILTER_OUTPUT_MAYBE_MODIFIABLE(1, m_begin, t = (size_t)SaturatingSubtract(m_rangesToSkip.front().position, m_currentMessageBytes), false, modifiable);
assert(t < m_length);
CRYPTOPP_ASSERT(t < m_length);
m_begin += t;
m_length -= t;
m_currentMessageBytes += t;
@ -199,7 +199,7 @@ size_t MeterFilter::PutMaybeModifiable(byte *begin, size_t length, int messageEn
else
{
t = (size_t)SaturatingSubtract(m_rangesToSkip.front().position + m_rangesToSkip.front().size, m_currentMessageBytes);
assert(t <= m_length);
CRYPTOPP_ASSERT(t <= m_length);
m_rangesToSkip.pop_front();
}
@ -303,7 +303,7 @@ void FilterWithBufferedInput::BlockQueue::Put(const byte *inString, size_t lengt
// Avoid passing NULL pointer to memcpy
if (!inString || !length) return;
assert(m_size + length <= m_buffer.size());
CRYPTOPP_ASSERT(m_size + length <= m_buffer.size());
byte *end = (m_size < size_t(m_buffer.end()-m_begin)) ? m_begin + m_size : m_begin + m_size - m_buffer.size();
size_t len = STDMIN(length, size_t(m_buffer.end()-end));
memcpy(end, inString, len);
@ -368,7 +368,7 @@ size_t FilterWithBufferedInput::PutMaybeModifiable(byte *inString, size_t length
size_t len = m_firstSize - m_queue.CurrentSize();
m_queue.Put(inString, len);
FirstPut(m_queue.GetContigousBlocks(m_firstSize));
assert(m_queue.CurrentSize() == 0);
CRYPTOPP_ASSERT(m_queue.CurrentSize() == 0);
m_queue.ResetQueue(m_blockSize, (2*m_blockSize+m_lastSize-2)/m_blockSize);
inString += len;
@ -406,7 +406,7 @@ size_t FilterWithBufferedInput::PutMaybeModifiable(byte *inString, size_t length
if (newLength >= m_blockSize + m_lastSize && m_queue.CurrentSize() > 0)
{
assert(m_queue.CurrentSize() < m_blockSize);
CRYPTOPP_ASSERT(m_queue.CurrentSize() < m_blockSize);
size_t len = m_blockSize - m_queue.CurrentSize();
m_queue.Put(inString, len);
inString += len;
@ -465,10 +465,10 @@ void FilterWithBufferedInput::ForceNextPut()
void FilterWithBufferedInput::NextPutMultiple(const byte *inString, size_t length)
{
assert(m_blockSize > 1); // m_blockSize = 1 should always override this function
CRYPTOPP_ASSERT(m_blockSize > 1); // m_blockSize = 1 should always override this function
while (length > 0)
{
assert(length >= m_blockSize);
CRYPTOPP_ASSERT(length >= m_blockSize);
NextPutSingle(inString);
inString += m_blockSize;
length -= m_blockSize;
@ -590,7 +590,7 @@ StreamTransformationFilter::StreamTransformationFilter(StreamTransformation &c,
: FilterWithBufferedInput(attachment)
, m_cipher(c), m_padding(DEFAULT_PADDING), m_optimalBufferSize(0)
{
assert(c.MinLastBlockSize() == 0 || c.MinLastBlockSize() > c.MandatoryBlockSize());
CRYPTOPP_ASSERT(c.MinLastBlockSize() == 0 || c.MinLastBlockSize() > c.MandatoryBlockSize());
if (!allowAuthenticatedSymmetricCipher && dynamic_cast<AuthenticatedSymmetricCipher *>(&c) != 0)
throw InvalidArgument("StreamTransformationFilter: please use AuthenticatedEncryptionFilter and AuthenticatedDecryptionFilter for AuthenticatedSymmetricCipher");
@ -710,15 +710,15 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
case ONE_AND_ZEROS_PADDING:
unsigned int s;
s = m_cipher.MandatoryBlockSize();
assert(s > 1);
CRYPTOPP_ASSERT(s > 1);
space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, s, m_optimalBufferSize);
if (m_cipher.IsForwardTransformation())
{
assert(length < s);
CRYPTOPP_ASSERT(length < s);
if (inString) {memcpy(space, inString, length);}
if (m_padding == PKCS_PADDING)
{
assert(s < 256);
CRYPTOPP_ASSERT(s < 256);
byte pad = byte(s-length);
memset(space+length, pad, s-length);
}
@ -754,7 +754,7 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
break;
default:
assert(false);
CRYPTOPP_ASSERT(false);
}
}
@ -836,7 +836,7 @@ void HashVerificationFilter::LastPut(const byte *inString, size_t length)
{
if (m_flags & HASH_AT_BEGIN)
{
assert(length == 0);
CRYPTOPP_ASSERT(length == 0);
m_verified = m_hashModule.TruncatedVerify(m_expectedHash, m_digestSize);
}
else
@ -860,7 +860,7 @@ AuthenticatedEncryptionFilter::AuthenticatedEncryptionFilter(AuthenticatedSymmet
: StreamTransformationFilter(c, attachment, padding, true)
, m_hf(c, new OutputProxy(*this, false), putAAD, truncatedDigestSize, AAD_CHANNEL, macChannel)
{
assert(c.IsForwardTransformation());
CRYPTOPP_ASSERT(c.IsForwardTransformation());
}
void AuthenticatedEncryptionFilter::IsolatedInitialize(const NameValuePairs &parameters)
@ -904,7 +904,7 @@ AuthenticatedDecryptionFilter::AuthenticatedDecryptionFilter(AuthenticatedSymmet
, m_hashVerifier(c, new OutputProxy(*this, false))
, m_streamFilter(c, new OutputProxy(*this, false), padding, true)
{
assert(!c.IsForwardTransformation() || c.IsSelfInverting());
CRYPTOPP_ASSERT(!c.IsForwardTransformation() || c.IsSelfInverting());
IsolatedInitialize(MakeParameters(Name::BlockPaddingScheme(), padding)(Name::AuthenticatedDecryptionFilterFlags(), flags)(Name::TruncatedDigestSize(), truncatedDigestSize));
}
@ -998,7 +998,7 @@ void SignatureVerificationFilter::InitializeDerivedAndReturnNewSizes(const NameV
m_flags = parameters.GetValueWithDefault(Name::SignatureVerificationFilterFlags(), (word32)DEFAULT_FLAGS);
m_messageAccumulator.reset(m_verifier.NewVerificationAccumulator());
size_t size = m_verifier.SignatureLength();
assert(size != 0); // TODO: handle recoverable signature scheme
CRYPTOPP_ASSERT(size != 0); // TODO: handle recoverable signature scheme
m_verified = false;
firstSize = m_flags & SIGNATURE_AT_BEGIN ? size : 0;
blockSize = 1;
@ -1022,7 +1022,7 @@ void SignatureVerificationFilter::FirstPut(const byte *inString)
}
else
{
assert(!m_verifier.SignatureUpfront());
CRYPTOPP_ASSERT(!m_verifier.SignatureUpfront());
}
}
@ -1037,7 +1037,7 @@ void SignatureVerificationFilter::LastPut(const byte *inString, size_t length)
{
if (m_flags & SIGNATURE_AT_BEGIN)
{
assert(length == 0);
CRYPTOPP_ASSERT(length == 0);
m_verifier.InputSignature(*m_messageAccumulator, m_signature, m_signature.size());
m_verified = m_verifier.VerifyAndRestart(*m_messageAccumulator);
}

View File

@ -176,7 +176,7 @@ struct CRYPTOPP_DLL FilterPutSpaceHelper
//! called \p m_tempSpace is resized and used for the caller.
byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
{
assert(desiredSize >= minSize && bufferSize >= minSize);
CRYPTOPP_ASSERT(desiredSize >= minSize && bufferSize >= minSize);
if (m_tempSpace.size() < minSize)
{
byte *result = target.ChannelCreatePutSpace(channel, desiredSize);
@ -362,7 +362,7 @@ protected:
virtual void FirstPut(const byte *inString) =0;
// NextPut() is called if totalLength >= firstSize+blockSize+lastSize
virtual void NextPutSingle(const byte *inString)
{CRYPTOPP_UNUSED(inString); assert(false);}
{CRYPTOPP_UNUSED(inString); CRYPTOPP_ASSERT(false);}
// Same as NextPut() except length can be a multiple of blockSize
// Either NextPut() or NextPutMultiple() must be overriden
virtual void NextPutMultiple(const byte *inString, size_t length);
@ -387,7 +387,7 @@ protected:
// This function should no longer be used, put this here to cause a compiler error
// if someone tries to override NextPut().
virtual int NextPut(const byte *inString, size_t length)
{CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); assert(false); return 0;}
{CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); CRYPTOPP_ASSERT(false); return 0;}
class BlockQueue
{
@ -965,7 +965,7 @@ public:
//! \brief Construct a StringSinkTemplate
//! \param output std::basic_string<char> type
StringSinkTemplate(T &output)
: m_output(&output) {assert(sizeof(output[0])==1);}
: m_output(&output) {CRYPTOPP_ASSERT(sizeof(output[0])==1);}
void IsolatedInitialize(const NameValuePairs &parameters)
{if (!parameters.GetValue("OutputStringPointer", m_output)) throw InvalidArgument("StringSink: OutputStringPointer not specified");}

View File

@ -54,7 +54,7 @@ bool PowerUpSelfTestInProgressOnThisThread()
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
return AccessPowerUpSelfTestInProgress().GetValue() != NULL;
#else
assert(false); // should not be called
CRYPTOPP_ASSERT(false); // should not be called
return false;
#endif
}

View File

@ -262,7 +262,7 @@ protected:
static inline void Xor(SecByteBlock &z, const SecByteBlock &x, const SecByteBlock &y)
{
assert(x.size() == y.size());
CRYPTOPP_ASSERT(x.size() == y.size());
z.resize(x.size());
xorbuf(z, x, y, x.size());
}
@ -637,7 +637,7 @@ protected:
}
else
{
assert(m_test == "Gen");
CRYPTOPP_ASSERT(m_test == "Gen");
int modLen = atol(m_bracketString.substr(6).c_str());
std::string &encodedKey = m_data["PrivKey"];
RSA::PrivateKey priv;
@ -1034,7 +1034,7 @@ protected:
}
else
{
assert(m_test == "KAT");
CRYPTOPP_ASSERT(m_test == "KAT");
SecByteBlock &input = m_data2[INPUT];
SecByteBlock result(input.size());
@ -1097,7 +1097,7 @@ protected:
if (m_line.substr(0, 2) == "H>")
{
assert(m_test == "sha");
CRYPTOPP_ASSERT(m_test == "sha");
m_bracketString = m_line.substr(2, m_line.size()-4);
m_line = m_line.substr(0, 13) + "Hashes<H";
copyLine = true;

View File

@ -20,7 +20,7 @@
#define FILTER_END_NO_MESSAGE_END_NO_RETURN \
break; \
default: \
assert(false); \
CRYPTOPP_ASSERT(false); \
}
#define FILTER_END_NO_MESSAGE_END \

20
gcm.cpp
View File

@ -95,9 +95,9 @@ __m128i _mm_clmulepi64_si128(const __m128i &a, const __m128i &b, int i)
inline static void SSE2_Xor16(byte *a, const byte *b, const byte *c)
{
#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
assert(IsAlignedOn(a,GetAlignmentOf<__m128i>()));
assert(IsAlignedOn(b,GetAlignmentOf<__m128i>()));
assert(IsAlignedOn(c,GetAlignmentOf<__m128i>()));
CRYPTOPP_ASSERT(IsAlignedOn(a,GetAlignmentOf<__m128i>()));
CRYPTOPP_ASSERT(IsAlignedOn(b,GetAlignmentOf<__m128i>()));
CRYPTOPP_ASSERT(IsAlignedOn(c,GetAlignmentOf<__m128i>()));
*(__m128i *)(void *)a = _mm_xor_si128(*(__m128i *)(void *)b, *(__m128i *)(void *)c);
#else
asm ("movdqa %1, %%xmm0; pxor %2, %%xmm0; movdqa %%xmm0, %0;" : "=m" (a[0]) : "m"(b[0]), "m"(c[0]));
@ -108,18 +108,18 @@ inline static void SSE2_Xor16(byte *a, const byte *b, const byte *c)
#if CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE
inline static void NEON_Xor16(byte *a, const byte *b, const byte *c)
{
assert(IsAlignedOn(a,GetAlignmentOf<uint64x2_t>()));
assert(IsAlignedOn(b,GetAlignmentOf<uint64x2_t>()));
assert(IsAlignedOn(c,GetAlignmentOf<uint64x2_t>()));
CRYPTOPP_ASSERT(IsAlignedOn(a,GetAlignmentOf<uint64x2_t>()));
CRYPTOPP_ASSERT(IsAlignedOn(b,GetAlignmentOf<uint64x2_t>()));
CRYPTOPP_ASSERT(IsAlignedOn(c,GetAlignmentOf<uint64x2_t>()));
*(uint64x2_t*)a = veorq_u64(*(uint64x2_t*)b, *(uint64x2_t*)c);
}
#endif
inline static void Xor16(byte *a, const byte *b, const byte *c)
{
assert(IsAlignedOn(a,GetAlignmentOf<word64>()));
assert(IsAlignedOn(b,GetAlignmentOf<word64>()));
assert(IsAlignedOn(c,GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(a,GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(b,GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(c,GetAlignmentOf<word64>()));
((word64 *)(void *)a)[0] = ((word64 *)(void *)b)[0] ^ ((word64 *)(void *)c)[0];
((word64 *)(void *)a)[1] = ((word64 *)(void *)b)[1] ^ ((word64 *)(void *)c)[1];
}
@ -641,7 +641,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len)
typedef BlockGetAndPut<word64, NativeByteOrder> Block;
word64 *hashBuffer = (word64 *)(void *)HashBuffer();
assert(IsAlignedOn(hashBuffer,GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(hashBuffer,GetAlignmentOf<word64>()));
switch (2*(m_buffer.size()>=64*1024)
#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)

View File

@ -52,7 +52,7 @@ GF2_32::Element GF2_32::MultiplicativeInverse(Element a) const
word32 g0=m_modulus, g1=a, g2=a;
word32 v0=0, v1=1, v2=1;
assert(g1);
CRYPTOPP_ASSERT(g1);
while (!(g2 & 0x80000000))
{
@ -70,25 +70,25 @@ GF2_32::Element GF2_32::MultiplicativeInverse(Element a) const
{
if (g1 < g0 || ((g0^g1) < g0 && (g0^g1) < g1))
{
assert(BitPrecision(g1) <= BitPrecision(g0));
CRYPTOPP_ASSERT(BitPrecision(g1) <= BitPrecision(g0));
g2 = g1;
v2 = v1;
}
else
{
assert(BitPrecision(g1) > BitPrecision(g0));
CRYPTOPP_ASSERT(BitPrecision(g1) > BitPrecision(g0));
g2 = g0; g0 = g1; g1 = g2;
v2 = v0; v0 = v1; v1 = v2;
}
while ((g0^g2) >= g2)
{
assert(BitPrecision(g0) > BitPrecision(g2));
CRYPTOPP_ASSERT(BitPrecision(g0) > BitPrecision(g2));
g2 <<= 1;
v2 <<= 1;
}
assert(BitPrecision(g0) == BitPrecision(g2));
CRYPTOPP_ASSERT(BitPrecision(g0) == BitPrecision(g2));
g0 ^= g2;
v0 ^= v2;
}

View File

@ -27,7 +27,7 @@ PolynomialMod2::PolynomialMod2()
PolynomialMod2::PolynomialMod2(word value, size_t bitLength)
: reg(BitsToWords(bitLength))
{
assert(value==0 || reg.size()>0);
CRYPTOPP_ASSERT(value==0 || reg.size()>0);
if (reg.size() > 0)
{
@ -325,9 +325,9 @@ PolynomialMod2 PolynomialMod2::Modulo(const PolynomialMod2 &b) const
PolynomialMod2& PolynomialMod2::operator<<=(unsigned int n)
{
#if !defined(NDEBUG)
#if CRYPTOPP_DEBUG
int x; CRYPTOPP_UNUSED(x);
assert(SafeConvert(n,x));
CRYPTOPP_ASSERT(SafeConvert(n,x));
#endif
if (!reg.size())
@ -561,7 +561,7 @@ GF2NP::Element GF2NP::SquareRoot(const Element &a) const
GF2NP::Element GF2NP::HalfTrace(const Element &a) const
{
assert(m%2 == 1);
CRYPTOPP_ASSERT(m%2 == 1);
Element h = a;
for (unsigned int i=1; i<=(m-1)/2; i++)
h = Add(Square(Square(h)), a);
@ -600,7 +600,7 @@ GF2NT::GF2NT(unsigned int c0, unsigned int c1, unsigned int c2)
, t0(c0), t1(c1)
, result((word)0, m)
{
assert(c0 > c1 && c1 > c2 && c2==0);
CRYPTOPP_ASSERT(c0 > c1 && c1 > c2 && c2==0);
}
const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
@ -618,7 +618,7 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
SetWords(T, 0, 3*m_modulus.reg.size());
b[0]=1;
assert(a.reg.size() <= m_modulus.reg.size());
CRYPTOPP_ASSERT(a.reg.size() <= m_modulus.reg.size());
CopyWords(f, a.reg, a.reg.size());
CopyWords(g, m_modulus.reg, m_modulus.reg.size());
@ -630,7 +630,7 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
ShiftWordsRightByWords(f, fgLen, 1);
if (c[bcLen-1])
bcLen++;
assert(bcLen <= m_modulus.reg.size());
CRYPTOPP_ASSERT(bcLen <= m_modulus.reg.size());
ShiftWordsLeftByWords(c, bcLen, 1);
k+=WORD_BITS;
t=f[0];
@ -661,7 +661,7 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
{
c[bcLen] = t;
bcLen++;
assert(bcLen <= m_modulus.reg.size());
CRYPTOPP_ASSERT(bcLen <= m_modulus.reg.size());
}
if (f[fgLen-1]==0 && g[fgLen-1]==0)
@ -717,7 +717,7 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
for (unsigned int j=0; j<WORD_BITS-t1; j++)
{
// Coverity finding on shift amount of 'word x << (t1+j)'.
assert(t1+j < WORD_BITS);
CRYPTOPP_ASSERT(t1+j < WORD_BITS);
temp ^= ((temp >> j) & 1) << (t1 + j);
}
}
@ -811,7 +811,7 @@ const GF2NT::Element& GF2NT::Reduced(const Element &a) const
if ((t0-t1)%WORD_BITS > t0%WORD_BITS)
b[i-(t0-t1)/WORD_BITS-1] ^= temp << (WORD_BITS - (t0-t1)%WORD_BITS);
else
assert(temp << (WORD_BITS - (t0-t1)%WORD_BITS) == 0);
CRYPTOPP_ASSERT(temp << (WORD_BITS - (t0-t1)%WORD_BITS) == 0);
}
else
b[i-(t0-t1)/WORD_BITS] ^= temp;

6
gf2n.h
View File

@ -286,16 +286,16 @@ public:
virtual GF2NP * Clone() const {return new GF2NP(*this);}
virtual void DEREncode(BufferedTransformation &bt) const
{CRYPTOPP_UNUSED(bt); assert(false);} // no ASN.1 syntax yet for general polynomial basis
{CRYPTOPP_UNUSED(bt); CRYPTOPP_ASSERT(false);} // no ASN.1 syntax yet for general polynomial basis
void DEREncodeElement(BufferedTransformation &out, const Element &a) const;
void BERDecodeElement(BufferedTransformation &in, Element &a) const;
bool Equal(const Element &a, const Element &b) const
{assert(a.Degree() < m_modulus.Degree() && b.Degree() < m_modulus.Degree()); return a.Equals(b);}
{CRYPTOPP_ASSERT(a.Degree() < m_modulus.Degree() && b.Degree() < m_modulus.Degree()); return a.Equals(b);}
bool IsUnit(const Element &a) const
{assert(a.Degree() < m_modulus.Degree()); return !!a;}
{CRYPTOPP_ASSERT(a.Degree() < m_modulus.Degree()); return !!a;}
unsigned int MaxElementBitLength() const
{return m;}

View File

@ -20,7 +20,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void TestInstantiations_gfpcrypt()
{
GDSA<SHA>::Signer test;
@ -82,8 +82,8 @@ void DL_SignatureMessageEncodingMethod_DSA::ComputeMessageRepresentative(RandomN
{
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);
CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
assert(recoverableMessageLength == 0);
assert(hashIdentifier.second == 0);
CRYPTOPP_ASSERT(recoverableMessageLength == 0);
CRYPTOPP_ASSERT(hashIdentifier.second == 0);
const size_t representativeByteLength = BitsToBytes(representativeBitLength);
const size_t digestSize = hash.DigestSize();
@ -109,8 +109,8 @@ void DL_SignatureMessageEncodingMethod_NR::ComputeMessageRepresentative(RandomNu
CRYPTOPP_UNUSED(hash); CRYPTOPP_UNUSED(hashIdentifier); CRYPTOPP_UNUSED(messageEmpty);
CRYPTOPP_UNUSED(representative); CRYPTOPP_UNUSED(representativeBitLength);
assert(recoverableMessageLength == 0);
assert(hashIdentifier.second == 0);
CRYPTOPP_ASSERT(recoverableMessageLength == 0);
CRYPTOPP_ASSERT(hashIdentifier.second == 0);
const size_t representativeByteLength = BitsToBytes(representativeBitLength);
const size_t digestSize = hash.DigestSize();
const size_t paddingLength = SaturatingSubtract(representativeByteLength, digestSize);

View File

@ -193,7 +193,7 @@ public:
r %= q;
Integer kInv = k.InverseMod(q);
s = (kInv * (x*r + e)) % q;
assert(!!r && !!s);
CRYPTOPP_ASSERT(!!r && !!s);
}
bool Verify(const DL_GroupParameters<T> &params, const DL_PublicKey<T> &publicKey, const Integer &e, const Integer &r, const Integer &s) const
@ -228,7 +228,7 @@ public:
const Integer &q = params.GetSubgroupOrder();
r = (r + e) % q;
s = (k - x*r) % q;
assert(!!r);
CRYPTOPP_ASSERT(!!r);
}
bool Verify(const DL_GroupParameters<T> &params, const DL_PublicKey<T> &publicKey, const Integer &e, const Integer &r, const Integer &s) const

6
hkdf.h
View File

@ -62,9 +62,9 @@ unsigned int HKDF<T>::DeriveKey(byte *derived, size_t derivedLen, const byte *se
static const size_t DIGEST_SIZE = static_cast<size_t>(T::DIGESTSIZE);
const unsigned int req = static_cast<unsigned int>(derivedLen);
assert(secret && secretLen);
assert(derived && derivedLen);
assert(derivedLen <= MaxDerivedKeyLength());
CRYPTOPP_ASSERT(secret && secretLen);
CRYPTOPP_ASSERT(derived && derivedLen);
CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength());
if (derivedLen > MaxDerivedKeyLength())
throw InvalidArgument("HKDF: derivedLen must be less than or equal to MaxDerivedKeyLength");

View File

@ -30,7 +30,7 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con
keylength = hash.DigestSize();
}
assert(keylength <= blockSize);
CRYPTOPP_ASSERT(keylength <= blockSize);
memset(AccessIpad()+keylength, 0, blockSize-keylength);
for (unsigned int i=0; i<blockSize; i++)
@ -42,7 +42,7 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con
void HMAC_Base::KeyInnerHash()
{
assert(!m_innerHashKeyed);
CRYPTOPP_ASSERT(!m_innerHashKeyed);
HashTransformation &hash = AccessHash();
hash.Update(AccessIpad(), hash.BlockSize());
m_innerHashKeyed = true;

10
hmqv.h
View File

@ -170,7 +170,7 @@ public:
}
else
{
assert(0);
CRYPTOPP_ASSERT(0);
return false;
}
@ -253,12 +253,12 @@ protected:
{
HASH hash;
size_t idx = 0, req = dlen;
size_t blk = std::min(dlen, (size_t)HASH::DIGESTSIZE);
size_t blk = STDMIN(dlen, (size_t)HASH::DIGESTSIZE);
if(sigma)
{
if (e1len != 0 || s1len != 0) {
assert(0);
CRYPTOPP_ASSERT(0);
}
Integer x = GetAbstractGroupParameters().ConvertElementToInteger(*sigma);
SecByteBlock sbb(x.MinEncodedSize());
@ -266,7 +266,7 @@ protected:
hash.Update(sbb.BytePtr(), sbb.SizeInBytes());
} else {
if (e1len == 0 || s1len == 0) {
assert(0);
CRYPTOPP_ASSERT(0);
}
hash.Update(e1, e1len);
hash.Update(s1, s1len);
@ -281,7 +281,7 @@ protected:
hash.Update(&digest[idx], (size_t)HASH::DIGESTSIZE);
idx += (size_t)HASH::DIGESTSIZE;
blk = std::min(req, (size_t)HASH::DIGESTSIZE);
blk = STDMIN(req, (size_t)HASH::DIGESTSIZE);
hash.TruncatedFinal(&digest[idx], blk);
req -= blk;

View File

@ -26,7 +26,7 @@
#include <unistd.h>
#endif
#include <assert.h>
#include "trap.h"
NAMESPACE_BEGIN(CryptoPP)
@ -53,7 +53,7 @@ double TimerBase::ConvertTo(TimerWord t, Unit unit)
static unsigned long unitsPerSecondTable[] = {1, 1000, 1000*1000, 1000*1000*1000};
// When 'unit' is an enum 'Unit', a Clang warning is generated.
assert(static_cast<unsigned int>(unit) < COUNTOF(unitsPerSecondTable));
CRYPTOPP_ASSERT(static_cast<unsigned int>(unit) < COUNTOF(unitsPerSecondTable));
return (double)CRYPTOPP_VC6_INT64 t * unitsPerSecondTable[unit] / CRYPTOPP_VC6_INT64 TicksPerSecond();
}
@ -83,7 +83,7 @@ double TimerBase::ElapsedTimeAsDouble()
unsigned long TimerBase::ElapsedTime()
{
double elapsed = ElapsedTimeAsDouble();
assert(elapsed <= (double)ULONG_MAX);
CRYPTOPP_ASSERT(elapsed <= (double)ULONG_MAX);
return (unsigned long)elapsed;
}

View File

@ -22,7 +22,7 @@ void RawIDA::IsolatedInitialize(const NameValuePairs &parameters)
if (!parameters.GetIntValue("RecoveryThreshold", m_threshold))
throw InvalidArgument("RawIDA: missing RecoveryThreshold argument");
assert(m_threshold > 0);
CRYPTOPP_ASSERT(m_threshold > 0);
if (m_threshold <= 0)
throw InvalidArgument("RawIDA: RecoveryThreshold must be greater than 0");
@ -43,7 +43,7 @@ void RawIDA::IsolatedInitialize(const NameValuePairs &parameters)
else
{
int nShares = parameters.GetIntValueWithDefault("NumberOfShares", m_threshold);
assert(nShares > 0);
CRYPTOPP_ASSERT(nShares > 0);
if (nShares <= 0) {nShares = m_threshold;}
for (unsigned int i=0; i< (unsigned int)(nShares); i++)
AddOutputChannel(i);
@ -152,7 +152,7 @@ void RawIDA::AddOutputChannel(word32 channelId)
void RawIDA::PrepareInterpolation()
{
assert(m_inputChannelIds.size() == size_t(m_threshold));
CRYPTOPP_ASSERT(m_inputChannelIds.size() == size_t(m_threshold));
PrepareBulkPolynomialInterpolation(field, m_w.begin(), &(m_inputChannelIds[0]), (unsigned int)(m_threshold));
for (unsigned int i=0; i<m_outputChannelIds.size(); i++)
ComputeV(i);

View File

@ -17,7 +17,7 @@ CRYPTOPP_COMPILE_ASSERT(sizeof(IDEA::Word) >= 2);
// should use an inline function but macros are still faster in MSVC 4.0
#define DirectMUL(a,b) \
{ \
assert(b <= 0xffff); \
CRYPTOPP_ASSERT(b <= 0xffff); \
\
word32 p=(word32)low16(a)*b; \
\

View File

@ -90,7 +90,7 @@ inline static int Compare(const word *A, const word *B, size_t N)
inline static int Increment(word *A, size_t N, word B=1)
{
assert(N);
CRYPTOPP_ASSERT(N);
word t = A[0];
A[0] = t+B;
if (A[0] >= t)
@ -103,7 +103,7 @@ inline static int Increment(word *A, size_t N, word B=1)
inline static int Decrement(word *A, size_t N, word B=1)
{
assert(N);
CRYPTOPP_ASSERT(N);
word t = A[0];
A[0] = t-B;
if (A[0] <= t)
@ -123,14 +123,14 @@ static void TwosComplement(word *A, size_t N)
static word AtomicInverseModPower2(word A)
{
assert(A%2==1);
CRYPTOPP_ASSERT(A%2==1);
word R=A%8;
for (unsigned i=3; i<WORD_BITS; i*=2)
R = R*(2-R*A);
assert(R*A==1);
CRYPTOPP_ASSERT(R*A==1);
return R;
}
@ -206,10 +206,10 @@ class DWord
public:
// Converity finding on default ctor. We've isntrumented the code,
// and cannot uncover a case where it affects a result.
#if (defined(__COVERITY__) || !defined(NDEBUG)) && defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
#if (defined(__COVERITY__) || CRYPTOPP_DEBUG) && defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
// Repeating pattern of 1010 for debug builds to break things...
DWord() : m_whole(0) {memset(&m_whole, 0xa, sizeof(m_whole));}
#elif (defined(__COVERITY__) || !defined(NDEBUG)) && !defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
#elif (defined(__COVERITY__) || CRYPTOPP_DEBUG) && !defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
// Repeating pattern of 1010 for debug builds to break things...
DWord() : m_halfs() {memset(&m_halfs, 0xaa, sizeof(m_halfs));}
#else
@ -240,7 +240,7 @@ public:
#elif defined(MultiplyWordsLoHi)
MultiplyWordsLoHi(r.m_halfs.low, r.m_halfs.high, a, b);
#else
assert(0);
CRYPTOPP_ASSERT(0);
#endif
return r;
}
@ -346,7 +346,7 @@ public:
// and cannot uncover a case where it affects a result.
#if defined(__COVERITY__)
Word() : m_whole(0) {}
#elif !defined(NDEBUG)
#elif CRYPTOPP_DEBUG
// Repeating pattern of 1010 for debug builds to break things...
Word() : m_whole(0) {memset(&m_whole, 0xaa, sizeof(m_whole));}
#else
@ -403,8 +403,8 @@ S DivideThreeWordsByTwo(S *A, S B0, S B1, D *dummy=NULL)
{
CRYPTOPP_UNUSED(dummy);
// assert {A[2],A[1]} < {B1,B0}, so quotient can fit in a S
assert(A[2] < B1 || (A[2]==B1 && A[1] < B0));
// CRYPTOPP_ASSERT {A[2],A[1]} < {B1,B0}, so quotient can fit in a S
CRYPTOPP_ASSERT(A[2] < B1 || (A[2]==B1 && A[1] < B0));
// estimate the quotient: do a 2 S by 1 S divide
S Q;
@ -432,7 +432,7 @@ S DivideThreeWordsByTwo(S *A, S B0, S B1, D *dummy=NULL)
A[1] = u.GetLowHalf();
A[2] += u.GetHighHalf();
Q++;
assert(Q); // shouldn't overflow
CRYPTOPP_ASSERT(Q); // shouldn't overflow
}
return Q;
@ -843,7 +843,7 @@ CRYPTOPP_NAKED int CRYPTOPP_FASTCALL SSE2_Sub(size_t N, word *C, const word *A,
#else
int CRYPTOPP_FASTCALL Baseline_Add(size_t N, word *C, const word *A, const word *B)
{
assert (N%2 == 0);
CRYPTOPP_ASSERT (N%2 == 0);
Declare2Words(u);
AssignWord(u, 0);
@ -859,7 +859,7 @@ int CRYPTOPP_FASTCALL Baseline_Add(size_t N, word *C, const word *A, const word
int CRYPTOPP_FASTCALL Baseline_Sub(size_t N, word *C, const word *A, const word *B)
{
assert (N%2 == 0);
CRYPTOPP_ASSERT (N%2 == 0);
Declare2Words(u);
AssignWord(u, 0);
@ -2076,7 +2076,7 @@ static void SetFunctionPointers()
#if CRYPTOPP_INTEGER_SSE2
if (HasSSE2())
{
#if _MSC_VER != 1200 || defined(NDEBUG)
#if _MSC_VER != 1200 || !(CRYPTOPP_DEBUG)
if (IsP4())
{
s_pAdd = &SSE2_Add;
@ -2171,7 +2171,7 @@ inline int Subtract(word *C, const word *A, const word *B, size_t N)
void RecursiveMultiply(word *R, word *T, const word *A, const word *B, size_t N)
{
assert(N>=2 && N%2==0);
CRYPTOPP_ASSERT(N>=2 && N%2==0);
if (N <= s_recursionLimit)
s_pMul[N/4](R, A, B);
@ -2202,7 +2202,7 @@ void RecursiveMultiply(word *R, word *T, const word *A, const word *B, size_t N)
c3 += Add(R1, R1, T0, N);
c3 += Increment(R2, N2, c2);
assert (c3 >= 0 && c3 <= 2);
CRYPTOPP_ASSERT (c3 >= 0 && c3 <= 2);
Increment(R3, N2, c3);
}
}
@ -2213,7 +2213,7 @@ void RecursiveMultiply(word *R, word *T, const word *A, const word *B, size_t N)
void RecursiveSquare(word *R, word *T, const word *A, size_t N)
{
assert(N && N%2==0);
CRYPTOPP_ASSERT(N && N%2==0);
if (N <= s_recursionLimit)
s_pSqu[N/4](R, A);
@ -2238,7 +2238,7 @@ void RecursiveSquare(word *R, word *T, const word *A, size_t N)
void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B, size_t N)
{
assert(N>=2 && N%2==0);
CRYPTOPP_ASSERT(N>=2 && N%2==0);
if (N <= s_recursionLimit)
s_pBot[N/4](R, A, B);
@ -2262,7 +2262,7 @@ void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B, siz
void MultiplyTop(word *R, word *T, const word *L, const word *A, const word *B, size_t N)
{
assert(N>=2 && N%2==0);
CRYPTOPP_ASSERT(N>=2 && N%2==0);
if (N <= s_recursionLimit)
s_pTop[N/4](R, A, B, L[N-1]);
@ -2304,7 +2304,7 @@ void MultiplyTop(word *R, word *T, const word *L, const word *A, const word *B,
c3 -= Decrement(T2, N2, -c2);
c3 += Add(R0, T2, R1, N2);
assert (c3 >= 0 && c3 <= 2);
CRYPTOPP_ASSERT (c3 >= 0 && c3 <= 2);
Increment(R1, N2, c3);
}
}
@ -2347,7 +2347,7 @@ void AsymmetricMultiply(word *R, word *T, const word *A, size_t NA, const word *
std::swap(NA, NB);
}
assert(NB % NA == 0);
CRYPTOPP_ASSERT(NB % NA == 0);
if (NA==2 && !A[1])
{
@ -2433,7 +2433,7 @@ void MontgomeryReduce(word *R, word *T, word *X, const word *M, const word *U, s
word borrow = Subtract(T, X+N, T, N);
// defend against timing attack by doing this Add even when not needed
word carry = Add(T+N, T, M, N);
assert(carry | !borrow);
CRYPTOPP_ASSERT(carry | !borrow);
CRYPTOPP_UNUSED(carry), CRYPTOPP_UNUSED(borrow);
CopyWords(R, T + ((0-borrow) & N), N);
#elif 0
@ -2501,7 +2501,7 @@ void MontgomeryReduce(word *R, word *T, word *X, const word *M, const word *U, s
void HalfMontgomeryReduce(word *R, word *T, const word *X, const word *M, const word *U, const word *V, size_t N)
{
assert(N%2==0 && N>=4);
CRYPTOPP_ASSERT(N%2==0 && N>=4);
#define M0 M
#define M1 (M+N2)
@ -2530,7 +2530,7 @@ void HalfMontgomeryReduce(word *R, word *T, const word *X, const word *M, const
else if (c2<0)
c3 -= Decrement(R1, N2, -c2);
assert(c3>=-1 && c3<=1);
CRYPTOPP_ASSERT(c3>=-1 && c3<=1);
if (c3>0)
Subtract(R, R, M, N);
else if (c3<0)
@ -2566,8 +2566,8 @@ void HalfMontgomeryReduce(word *R, word *T, const word *X, const word *M, const
// do a 3 word by 2 word divide, returns quotient and leaves remainder in A
static word SubatomicDivide(word *A, word B0, word B1)
{
// assert {A[2],A[1]} < {B1,B0}, so quotient can fit in a word
assert(A[2] < B1 || (A[2]==B1 && A[1] < B0));
// CRYPTOPP_ASSERT {A[2],A[1]} < {B1,B0}, so quotient can fit in a word
CRYPTOPP_ASSERT(A[2] < B1 || (A[2]==B1 && A[1] < B0));
// estimate the quotient: do a 2 word by 1 word divide
word Q;
@ -2593,7 +2593,7 @@ static word SubatomicDivide(word *A, word B0, word B1)
A[1] = u.GetLowHalf();
A[2] += u.GetHighHalf();
Q++;
assert(Q); // shouldn't overflow
CRYPTOPP_ASSERT(Q); // shouldn't overflow
}
return Q;
@ -2614,13 +2614,13 @@ static inline void AtomicDivide(word *Q, const word *A, const word *B)
Q[1] = SubatomicDivide(T+1, B[0], B[1]);
Q[0] = SubatomicDivide(T, B[0], B[1]);
#ifndef NDEBUG
#if CRYPTOPP_DEBUG
// multiply quotient and divisor and add remainder, make sure it equals dividend
assert(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
CRYPTOPP_ASSERT(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
word P[4];
LowLevel::Multiply2(P, Q, B);
Add(P, P, T, 4);
assert(memcmp(P, A, 4*WORD_SIZE)==0);
CRYPTOPP_ASSERT(memcmp(P, A, 4*WORD_SIZE)==0);
#endif
}
}
@ -2633,15 +2633,15 @@ static inline void AtomicDivide(word *Q, const word *A, const word *B)
Q[0] = q.GetLowHalf();
Q[1] = q.GetHighHalf();
#ifndef NDEBUG
#if CRYPTOPP_DEBUG
if (B[0] || B[1])
{
// multiply quotient and divisor and add remainder, make sure it equals dividend
assert(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
CRYPTOPP_ASSERT(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
word P[4];
s_pMul[0](P, Q, B);
Add(P, P, T, 4);
assert(memcmp(P, A, 4*WORD_SIZE)==0);
CRYPTOPP_ASSERT(memcmp(P, A, 4*WORD_SIZE)==0);
}
#endif
}
@ -2649,19 +2649,19 @@ static inline void AtomicDivide(word *Q, const word *A, const word *B)
// for use by Divide(), corrects the underestimated quotient {Q1,Q0}
static void CorrectQuotientEstimate(word *R, word *T, word *Q, const word *B, size_t N)
{
assert(N && N%2==0);
CRYPTOPP_ASSERT(N && N%2==0);
AsymmetricMultiply(T, T+N+2, Q, 2, B, N);
word borrow = Subtract(R, R, T, N+2);
assert(!borrow && !R[N+1]);
CRYPTOPP_ASSERT(!borrow && !R[N+1]);
CRYPTOPP_UNUSED(borrow);
while (R[N] || Compare(R, B, N) >= 0)
{
R[N] -= Subtract(R, R, B, N);
Q[1] += (++Q[0]==0);
assert(Q[0] || Q[1]); // no overflow
CRYPTOPP_ASSERT(Q[0] || Q[1]); // no overflow
}
}
@ -2673,9 +2673,9 @@ static void CorrectQuotientEstimate(word *R, word *T, word *Q, const word *B, si
void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B, size_t NB)
{
assert(NA && NB && NA%2==0 && NB%2==0);
assert(B[NB-1] || B[NB-2]);
assert(NB <= NA);
CRYPTOPP_ASSERT(NA && NB && NA%2==0 && NB%2==0);
CRYPTOPP_ASSERT(B[NB-1] || B[NB-2]);
CRYPTOPP_ASSERT(NB <= NA);
// set up temporary work space
word *const TA=T;
@ -2687,7 +2687,7 @@ void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B,
TB[0] = TB[NB-1] = 0;
CopyWords(TB+shiftWords, B, NB-shiftWords);
unsigned shiftBits = WORD_BITS - BitPrecision(TB[NB-1]);
assert(shiftBits < WORD_BITS);
CRYPTOPP_ASSERT(shiftBits < WORD_BITS);
ShiftWordsLeftByBits(TB, NB, shiftBits);
// copy A into TA and normalize it
@ -2707,7 +2707,7 @@ void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B,
else
{
NA+=2;
assert(Compare(TA+NA-NB, TB, NB) < 0);
CRYPTOPP_ASSERT(Compare(TA+NA-NB, TB, NB) < 0);
}
word BT[2];
@ -2741,7 +2741,7 @@ static inline size_t EvenWordCount(const word *X, size_t N)
unsigned int AlmostInverse(word *R, word *T, const word *A, size_t NA, const word *M, size_t N)
{
assert(NA<=N && N && N%2==0);
CRYPTOPP_ASSERT(NA<=N && N && N%2==0);
word *b = T;
word *c = T+N;
@ -2769,7 +2769,7 @@ unsigned int AlmostInverse(word *R, word *T, const word *A, size_t NA, const wor
ShiftWordsRightByWords(f, fgLen, 1);
bcLen += 2 * (c[bcLen-1] != 0);
assert(bcLen <= N);
CRYPTOPP_ASSERT(bcLen <= N);
ShiftWordsLeftByWords(c, bcLen, 1);
k+=WORD_BITS;
t=f[0];
@ -2793,7 +2793,7 @@ unsigned int AlmostInverse(word *R, word *T, const word *A, size_t NA, const wor
t = ShiftWordsLeftByBits(c, bcLen, i);
c[bcLen] += t;
bcLen += 2 * (t!=0);
assert(bcLen <= N);
CRYPTOPP_ASSERT(bcLen <= N);
bool swap = Compare(f, g, fgLen)==-1;
ConditionalSwapPointers(swap, f, g);
@ -2806,7 +2806,7 @@ unsigned int AlmostInverse(word *R, word *T, const word *A, size_t NA, const wor
t = Add(b, b, c, bcLen);
b[bcLen] += t;
bcLen += 2*t;
assert(bcLen <= N);
CRYPTOPP_ASSERT(bcLen <= N);
}
}
@ -2926,7 +2926,7 @@ bool Integer::IsConvertableToLong() const
signed long Integer::ConvertToLong() const
{
assert(IsConvertableToLong());
CRYPTOPP_ASSERT(IsConvertableToLong());
unsigned long value = (unsigned long)reg[0];
value += SafeLeftShift<WORD_BITS, unsigned long>((unsigned long)reg[1]);
@ -2935,7 +2935,7 @@ signed long Integer::ConvertToLong() const
Integer::Integer(BufferedTransformation &encodedInteger, size_t byteCount, Signedness s, ByteOrder o)
{
assert(o == BIG_ENDIAN_ORDER || o == LITTLE_ENDIAN_ORDER);
CRYPTOPP_ASSERT(o == BIG_ENDIAN_ORDER || o == LITTLE_ENDIAN_ORDER);
if(o == LITTLE_ENDIAN_ORDER)
{
@ -2952,7 +2952,7 @@ Integer::Integer(BufferedTransformation &encodedInteger, size_t byteCount, Signe
Integer::Integer(const byte *encodedInteger, size_t byteCount, Signedness s, ByteOrder o)
{
assert(o == BIG_ENDIAN_ORDER || o == LITTLE_ENDIAN_ORDER);
CRYPTOPP_ASSERT(o == BIG_ENDIAN_ORDER || o == LITTLE_ENDIAN_ORDER);
if(o == LITTLE_ENDIAN_ORDER)
{
@ -3074,7 +3074,7 @@ void Integer::SetByte(size_t n, byte value)
lword Integer::GetBits(size_t i, size_t n) const
{
lword v = 0;
assert(n <= sizeof(v)*8);
CRYPTOPP_ASSERT(n <= sizeof(v)*8);
for (unsigned int j=0; j<n; j++)
v |= lword(GetBit(i+j)) << j;
return v;
@ -3110,7 +3110,7 @@ Integer::Integer(word value, size_t length)
template <class T>
static Integer StringToInteger(const T *str, ByteOrder order)
{
assert( order == BIG_ENDIAN_ORDER || order == LITTLE_ENDIAN_ORDER );
CRYPTOPP_ASSERT( order == BIG_ENDIAN_ORDER || order == LITTLE_ENDIAN_ORDER );
int radix, sign = 1;
// GCC workaround
@ -3285,7 +3285,7 @@ void Integer::Decode(const byte *input, size_t inputLen, Signedness s)
void Integer::Decode(BufferedTransformation &bt, size_t inputLen, Signedness s)
{
assert(bt.MaxRetrievable() >= inputLen);
CRYPTOPP_ASSERT(bt.MaxRetrievable() >= inputLen);
byte b;
bt.Peek(b);
@ -3302,7 +3302,7 @@ void Integer::Decode(BufferedTransformation &bt, size_t inputLen, Signedness s)
const size_t size = RoundupSize(BytesToWords(inputLen));
reg.CleanNew(size);
assert(reg.SizeInBytes() >= inputLen);
CRYPTOPP_ASSERT(reg.SizeInBytes() >= inputLen);
for (size_t i=inputLen; i > 0; i--)
{
bt.Get(b);
@ -3331,7 +3331,7 @@ size_t Integer::MinEncodedSize(Signedness signedness) const
void Integer::Encode(byte *output, size_t outputLen, Signedness signedness) const
{
assert(output && outputLen);
CRYPTOPP_ASSERT(output && outputLen);
ArraySink sink(output, outputLen);
Encode(sink, outputLen, signedness);
}
@ -3669,7 +3669,7 @@ Integer& Integer::operator++()
else
{
word borrow = Decrement(reg, reg.size());
assert(!borrow);
CRYPTOPP_ASSERT(!borrow);
CRYPTOPP_UNUSED(borrow);
if (WordCount()==0)
@ -3747,7 +3747,7 @@ void PositiveSubtract(Integer &diff, const Integer &a, const Integer& b)
word borrow = Subtract(diff.reg, a.reg, b.reg, bSize);
CopyWords(diff.reg+bSize, a.reg+bSize, aSize-bSize);
borrow = Decrement(diff.reg+bSize, aSize-bSize, borrow);
assert(!borrow);
CRYPTOPP_ASSERT(!borrow);
diff.sign = Integer::POSITIVE;
}
else
@ -3755,7 +3755,7 @@ void PositiveSubtract(Integer &diff, const Integer &a, const Integer& b)
word borrow = Subtract(diff.reg, b.reg, a.reg, aSize);
CopyWords(diff.reg+aSize, b.reg+aSize, bSize-aSize);
borrow = Decrement(diff.reg+aSize, bSize-aSize, borrow);
assert(!borrow);
CRYPTOPP_ASSERT(!borrow);
diff.sign = Integer::NEGATIVE;
}
}
@ -4027,7 +4027,7 @@ void Integer::Divide(word &remainder, Integer &quotient, const Integer &dividend
if (!divisor)
throw Integer::DivideByZero();
assert(divisor);
CRYPTOPP_ASSERT(divisor);
if ((divisor & (divisor-1)) == 0) // divisor is a power of 2
{
@ -4071,7 +4071,7 @@ word Integer::Modulo(word divisor) const
if (!divisor)
throw Integer::DivideByZero();
assert(divisor);
CRYPTOPP_ASSERT(divisor);
word remainder;
@ -4143,7 +4143,7 @@ Integer Integer::SquareRoot() const
// overestimate square root
Integer x, y = Power2((BitCount()+1)/2);
assert(y*y >= *this);
CRYPTOPP_ASSERT(y*y >= *this);
do
{
@ -4188,7 +4188,7 @@ Integer Integer::Gcd(const Integer &a, const Integer &b)
Integer Integer::InverseMod(const Integer &m) const
{
assert(m.NotNegative());
CRYPTOPP_ASSERT(m.NotNegative());
if (IsNegative())
return Modulo(m).InverseMod(m);
@ -4404,7 +4404,7 @@ const Integer& MontgomeryRepresentation::Multiply(const Integer &a, const Intege
word *const T = m_workspace.begin();
word *const R = m_result.reg.begin();
const size_t N = m_modulus.reg.size();
assert(a.reg.size()<=N && b.reg.size()<=N);
CRYPTOPP_ASSERT(a.reg.size()<=N && b.reg.size()<=N);
AsymmetricMultiply(T, T+2*N, a.reg, a.reg.size(), b.reg, b.reg.size());
SetWords(T+a.reg.size()+b.reg.size(), 0, 2*N-a.reg.size()-b.reg.size());
@ -4417,7 +4417,7 @@ const Integer& MontgomeryRepresentation::Square(const Integer &a) const
word *const T = m_workspace.begin();
word *const R = m_result.reg.begin();
const size_t N = m_modulus.reg.size();
assert(a.reg.size()<=N);
CRYPTOPP_ASSERT(a.reg.size()<=N);
CryptoPP::Square(T, T+2*N, a.reg, a.reg.size());
SetWords(T+2*a.reg.size(), 0, 2*N-2*a.reg.size());
@ -4430,7 +4430,7 @@ Integer MontgomeryRepresentation::ConvertOut(const Integer &a) const
word *const T = m_workspace.begin();
word *const R = m_result.reg.begin();
const size_t N = m_modulus.reg.size();
assert(a.reg.size()<=N);
CRYPTOPP_ASSERT(a.reg.size()<=N);
CopyWords(T, a.reg, a.reg.size());
SetWords(T+a.reg.size(), 0, 2*N-a.reg.size());
@ -4444,7 +4444,7 @@ const Integer& MontgomeryRepresentation::MultiplicativeInverse(const Integer &a)
word *const T = m_workspace.begin();
word *const R = m_result.reg.begin();
const size_t N = m_modulus.reg.size();
assert(a.reg.size()<=N);
CRYPTOPP_ASSERT(a.reg.size()<=N);
CopyWords(T, a.reg, a.reg.size());
SetWords(T+a.reg.size(), 0, 2*N-a.reg.size());
@ -4474,7 +4474,7 @@ std::string IntToString<Integer>(Integer value, unsigned int base)
const char CH = UPPER ? 'A' : 'a';
base &= ~(BIT_32|BIT_31);
assert(base >= 2 && base <= 32);
CRYPTOPP_ASSERT(base >= 2 && base <= 32);
if (value == 0)
return "0";
@ -4537,7 +4537,7 @@ std::string IntToString<word64>(word64 value, unsigned int base)
const char CH = !!(base & HIGH_BIT) ? 'A' : 'a';
base &= ~HIGH_BIT;
assert(base >= 2);
CRYPTOPP_ASSERT(base >= 2);
if (value == 0)
return "0";

View File

@ -23,7 +23,7 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
T* dataBuf = this->DataBuf();
byte* data = (byte *)dataBuf;
assert(dataBuf && data);
CRYPTOPP_ASSERT(dataBuf && data);
if (num != 0) // process left over data
{
@ -48,7 +48,7 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
{
if (input == data)
{
assert(len == blockSize);
CRYPTOPP_ASSERT(len == blockSize);
HashBlock(dataBuf);
return;
}

View File

@ -251,7 +251,7 @@ static void KeccakF1600(word64 *state)
void Keccak::Update(const byte *input, size_t length)
{
assert((input && length) || !(input || length));
CRYPTOPP_ASSERT((input && length) || !(input || length));
if (!length)
return;

View File

@ -10,7 +10,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void LUC_TestInstantiations()
{
LUC_HMP<SHA>::Signer t1;

2
luc.h
View File

@ -134,7 +134,7 @@ typedef LUCSS<PKCS1v15, SHA>::Verifier LUCSSA_PKCS1v15_SHA_Verifier;
class DL_GroupPrecomputation_LUC : public DL_GroupPrecomputation<Integer>
{
public:
const AbstractGroup<Element> & GetGroup() const {assert(false); throw 0;}
const AbstractGroup<Element> & GetGroup() const {CRYPTOPP_ASSERT(false); throw 0;}
Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);}
void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);}

View File

@ -9,7 +9,7 @@
NAMESPACE_BEGIN(CryptoPP)
namespace Weak1 {
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void MD5_TestInstantiations()
{
MD5 x;

View File

@ -84,7 +84,7 @@ public:
case 2: output[1] = CRYPTOPP_GET_BYTE_AS_BYTE(temp, 2); /* fall through */
case 1: output[0] = CRYPTOPP_GET_BYTE_AS_BYTE(temp, 3); break;
default: assert(0); ;;
default: CRYPTOPP_ASSERT(0); ;;
}
// Wipe temp
@ -148,7 +148,7 @@ protected:
static const unsigned long magic[2]={0x0UL, K};
word32 kk, temp;
assert(N >= M);
CRYPTOPP_ASSERT(N >= M);
for (kk=0;kk<N-M;kk++)
{
temp = (m_state[kk] & 0x80000000)|(m_state[kk+1] & 0x7FFFFFFF);

View File

@ -27,9 +27,9 @@ NAMESPACE_BEGIN(CryptoPP)
void xorbuf(byte *buf, const byte *mask, size_t count)
{
assert(buf != NULL);
assert(mask != NULL);
assert(count > 0);
CRYPTOPP_ASSERT(buf != NULL);
CRYPTOPP_ASSERT(mask != NULL);
CRYPTOPP_ASSERT(count > 0);
size_t i=0;
if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
@ -60,9 +60,9 @@ void xorbuf(byte *buf, const byte *mask, size_t count)
void xorbuf(byte *output, const byte *input, const byte *mask, size_t count)
{
assert(output != NULL);
assert(input != NULL);
assert(count > 0);
CRYPTOPP_ASSERT(output != NULL);
CRYPTOPP_ASSERT(input != NULL);
CRYPTOPP_ASSERT(count > 0);
size_t i=0;
if (IsAligned<word32>(output) && IsAligned<word32>(input) && IsAligned<word32>(mask))
@ -95,9 +95,9 @@ void xorbuf(byte *output, const byte *input, const byte *mask, size_t count)
bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
{
assert(buf != NULL);
assert(mask != NULL);
assert(count > 0);
CRYPTOPP_ASSERT(buf != NULL);
CRYPTOPP_ASSERT(mask != NULL);
CRYPTOPP_ASSERT(count > 0);
size_t i=0;
byte acc8 = 0;
@ -136,7 +136,7 @@ bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
std::string StringNarrow(const wchar_t *str, bool throwOnError)
{
assert(str);
CRYPTOPP_ASSERT(str);
std::string result;
// Safer functions on Windows for C&A, https://github.com/weidai11/cryptopp/issues/55
@ -149,12 +149,12 @@ std::string StringNarrow(const wchar_t *str, bool throwOnError)
len = wcslen(str)+1;
err = wcstombs_s(&size, NULL, 0, str, len*sizeof(wchar_t));
assert(err == 0);
CRYPTOPP_ASSERT(err == 0);
if (err != 0) {goto CONVERSION_ERROR;}
result.resize(size);
err = wcstombs_s(&size, &result[0], size, str, len*sizeof(wchar_t));
assert(err == 0);
CRYPTOPP_ASSERT(err == 0);
if (err != 0)
{
@ -170,12 +170,12 @@ CONVERSION_ERROR:
result.erase(size - 1);
#else
size_t size = wcstombs(NULL, str, 0);
assert(size != (size_t)-1);
CRYPTOPP_ASSERT(size != (size_t)-1);
if (size == (size_t)-1) {goto CONVERSION_ERROR;}
result.resize(size);
size = wcstombs(&result[0], str, size);
assert(size != (size_t)-1);
CRYPTOPP_ASSERT(size != (size_t)-1);
if (size == (size_t)-1)
{
@ -232,7 +232,7 @@ void * AlignedAllocate(size_t size)
p[-1] = (byte)adjustment;
#endif
assert(IsAlignedOn(p, 16));
CRYPTOPP_ASSERT(IsAlignedOn(p, 16));
return p;
}

118
misc.h
View File

@ -117,10 +117,10 @@ class Integer;
// ************** compile-time assertion ***************
#if CRYPTOPP_DOXYGEN_PROCESSING
//! \brief Compile time assertion
//! \brief Compile time CRYPTOPP_ASSERTion
//! \param expr the expression to evaluate
//! \details Asserts the expression expr though a dummy struct.
#define CRYPTOPP_COMPILE_ASSERT(expr) ...
#define CRYPTOPP_COMPILE_ASSERT(expr) { ... }
#else // CRYPTOPP_DOXYGEN_PROCESSING
template <bool b>
struct CompileAssert
@ -129,18 +129,18 @@ struct CompileAssert
};
//! \endif
#define CRYPTOPP_COMPILE_ASSERT(assertion) CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, __LINE__)
#define CRYPTOPP_COMPILE_ASSERT(CRYPTOPP_ASSERTion) CRYPTOPP_COMPILE_ASSERT_INSTANCE(CRYPTOPP_ASSERTion, __LINE__)
#if defined(CRYPTOPP_EXPORTS) || defined(CRYPTOPP_IMPORTS)
#define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance)
#define CRYPTOPP_COMPILE_ASSERT_INSTANCE(CRYPTOPP_ASSERTion, instance)
#else
# if defined(__GNUC__)
# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
static CompileAssert<(assertion)> \
CRYPTOPP_ASSERT_JOIN(cryptopp_assert_, instance) __attribute__ ((unused))
# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(CRYPTOPP_ASSERTion, instance) \
static CompileAssert<(CRYPTOPP_ASSERTion)> \
CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance) __attribute__ ((unused))
# else
# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
static CompileAssert<(assertion)> \
CRYPTOPP_ASSERT_JOIN(cryptopp_assert_, instance)
# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(CRYPTOPP_ASSERTion, instance) \
static CompileAssert<(CRYPTOPP_ASSERTion)> \
CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance)
# endif // __GNUC__
#endif
#define CRYPTOPP_ASSERT_JOIN(X, Y) CRYPTOPP_DO_ASSERT_JOIN(X, Y)
@ -351,16 +351,16 @@ const T & Singleton<T, F, instance>::Ref(CRYPTOPP_NOINLINE_DOTDOTDOT) const
//! makes memcpy_s() and memmove_s() available. The library will also optionally
//! make the symbols available if <tt>CRYPTOPP_WANT_SECURE_LIB</tt> is defined.
//! <tt>CRYPTOPP_WANT_SECURE_LIB</tt> is in config.h, but it is disabled by default.
//! \details memcpy_s() will assert the pointers src and dest are not NULL
//! \details memcpy_s() will CRYPTOPP_ASSERT the pointers src and dest are not NULL
//! in debug builds. Passing NULL for either pointer is undefined behavior.
inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
{
// Safer functions on Windows for C&A, http://github.com/weidai11/cryptopp/issues/55
// Pointers must be valid; otherwise undefined behavior
assert(dest != NULL); assert(src != NULL);
CRYPTOPP_ASSERT(dest != NULL); CRYPTOPP_ASSERT(src != NULL);
// Destination buffer must be large enough to satsify request
assert(sizeInBytes >= count);
CRYPTOPP_ASSERT(sizeInBytes >= count);
if (count > sizeInBytes)
throw InvalidArgument("memcpy_s: buffer overflow");
@ -393,16 +393,16 @@ inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t cou
//! makes memcpy_s() and memmove_s() available. The library will also optionally
//! make the symbols available if <tt>CRYPTOPP_WANT_SECURE_LIB</tt> is defined.
//! <tt>CRYPTOPP_WANT_SECURE_LIB</tt> is in config.h, but it is disabled by default.
//! \details memmove_s() will assert the pointers src and dest are not NULL
//! \details memmove_s() will CRYPTOPP_ASSERT the pointers src and dest are not NULL
//! in debug builds. Passing NULL for either pointer is undefined behavior.
inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
{
// Safer functions on Windows for C&A, http://github.com/weidai11/cryptopp/issues/55
// Pointers must be valid; otherwise undefined behavior
assert(dest != NULL); assert(src != NULL);
CRYPTOPP_ASSERT(dest != NULL); CRYPTOPP_ASSERT(src != NULL);
// Destination buffer must be large enough to satsify request
assert(sizeInBytes >= count);
CRYPTOPP_ASSERT(sizeInBytes >= count);
if (count > sizeInBytes)
throw InvalidArgument("memmove_s: buffer overflow");
@ -534,7 +534,7 @@ std::string IntToString(T value, unsigned int base = 10)
const char CH = !!(base & HIGH_BIT) ? 'A' : 'a';
base &= ~HIGH_BIT;
assert(base >= 2);
CRYPTOPP_ASSERT(base >= 2);
if (value == 0)
return "0";
@ -672,7 +672,7 @@ inline unsigned int TrailingZeros(word32 v)
// GCC 4.7 and VS2012 provides tzcnt on AVX2/BMI enabled processors
// We don't enable for Microsoft because it requires a runtime check.
// http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx
assert(v != 0);
CRYPTOPP_ASSERT(v != 0);
#if defined(__GNUC__) && defined(__BMI__)
return (unsigned int)_tzcnt_u32(v);
#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
@ -703,7 +703,7 @@ inline unsigned int TrailingZeros(word64 v)
// GCC 4.7 and VS2012 provides tzcnt on AVX2/BMI enabled processors
// We don't enable for Microsoft because it requires a runtime check.
// http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx
assert(v != 0);
CRYPTOPP_ASSERT(v != 0);
#if defined(__GNUC__) && defined(__BMI__) && defined(__x86_64__)
return (unsigned int)_tzcnt_u64(v);
#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
@ -835,7 +835,7 @@ inline bool IsPowerOf2<word64>(const word64 &value)
template <class T1, class T2>
inline T2 ModPowerOf2(const T1 &a, const T2 &b)
{
assert(IsPowerOf2(b));
CRYPTOPP_ASSERT(IsPowerOf2(b));
return T2(a) & (b-1);
}
@ -1020,7 +1020,7 @@ CRYPTOPP_DLL void CRYPTOPP_API CallNewHandler();
//! \note The function is not constant time because it stops processing when the carry is 0.
inline void IncrementCounterByOne(byte *inout, unsigned int size)
{
assert(inout != NULL); assert(size < INT_MAX);
CRYPTOPP_ASSERT(inout != NULL); CRYPTOPP_ASSERT(size < INT_MAX);
for (int i=int(size-1), carry=1; i>=0 && carry; i--)
carry = !++inout[i];
}
@ -1034,7 +1034,7 @@ inline void IncrementCounterByOne(byte *inout, unsigned int size)
//! \details The function is \a close to near-constant time because it operates on all the bytes in the blocks.
inline void IncrementCounterByOne(byte *output, const byte *input, unsigned int size)
{
assert(output != NULL); assert(input != NULL); assert(size < INT_MAX);
CRYPTOPP_ASSERT(output != NULL); CRYPTOPP_ASSERT(input != NULL); CRYPTOPP_ASSERT(size < INT_MAX);
int i, carry;
for (i=int(size-1), carry=1; i>=0 && carry; i--)
@ -1210,7 +1210,7 @@ std::string StringNarrow(const wchar_t *str, bool throwOnError = true);
#else
static std::string StringNarrow(const wchar_t *str, bool throwOnError = true)
{
assert(str);
CRYPTOPP_ASSERT(str);
std::string result;
// Safer functions on Windows for C&A, https://github.com/weidai11/cryptopp/issues/55
@ -1223,12 +1223,12 @@ static std::string StringNarrow(const wchar_t *str, bool throwOnError = true)
len = wcslen(str)+1;
err = wcstombs_s(&size, NULL, 0, str, len*sizeof(wchar_t));
assert(err == 0);
CRYPTOPP_ASSERT(err == 0);
if (err != 0) {goto CONVERSION_ERROR;}
result.resize(size);
err = wcstombs_s(&size, &result[0], size, str, len*sizeof(wchar_t));
assert(err == 0);
CRYPTOPP_ASSERT(err == 0);
if (err != 0)
{
@ -1244,12 +1244,12 @@ CONVERSION_ERROR:
result.erase(size - 1);
#else
size_t size = wcstombs(NULL, str, 0);
assert(size != (size_t)-1);
CRYPTOPP_ASSERT(size != (size_t)-1);
if (size == (size_t)-1) {goto CONVERSION_ERROR;}
result.resize(size);
size = wcstombs(&result[0], str, size);
assert(size != (size_t)-1);
CRYPTOPP_ASSERT(size != (size_t)-1);
if (size == (size_t)-1)
{
@ -1318,7 +1318,7 @@ template <class T> inline T rotlFixed(T x, unsigned int y)
// and https://llvm.org/bugs/show_bug.cgi?id=24226
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
assert(y < THIS_SIZE);
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x<<y)|(x>>(-y&MASK)));
}
@ -1340,7 +1340,7 @@ template <class T> inline T rotrFixed(T x, unsigned int y)
// and https://llvm.org/bugs/show_bug.cgi?id=24226
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
assert(y < THIS_SIZE);
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x >> y)|(x<<(-y&MASK)));
}
@ -1358,7 +1358,7 @@ template <class T> inline T rotlVariable(T x, unsigned int y)
{
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
assert(y < THIS_SIZE);
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x<<y)|(x>>(-y&MASK)));
}
@ -1376,7 +1376,7 @@ template <class T> inline T rotrVariable(T x, unsigned int y)
{
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
assert(y < THIS_SIZE);
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x>>y)|(x<<(-y&MASK)));
}
@ -1417,11 +1417,11 @@ template <class T> inline T rotrMod(T x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
//! <stdlib.h>. The value x to be rotated is 32-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotlFixed will assert in Debug builds if is outside the allowed range.
//! \note rotlFixed will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word32 rotlFixed<word32>(word32 x, unsigned int y)
{
// Uses Microsoft <stdlib.h> call, bound to C/C++ language rules.
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return y ? _lrotl(x, static_cast<byte>(y)) : x;
}
@ -1432,11 +1432,11 @@ template<> inline word32 rotlFixed<word32>(word32 x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
//! <stdlib.h>. The value x to be rotated is 32-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotrFixed will assert in Debug builds if is outside the allowed range.
//! \note rotrFixed will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word32 rotrFixed<word32>(word32 x, unsigned int y)
{
// Uses Microsoft <stdlib.h> call, bound to C/C++ language rules.
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return y ? _lrotr(x, static_cast<byte>(y)) : x;
}
@ -1447,10 +1447,10 @@ template<> inline word32 rotrFixed<word32>(word32 x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
//! <stdlib.h>. The value x to be rotated is 32-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotlVariable will assert in Debug builds if is outside the allowed range.
//! \note rotlVariable will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word32 rotlVariable<word32>(word32 x, unsigned int y)
{
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return _lrotl(x, static_cast<byte>(y));
}
@ -1461,10 +1461,10 @@ template<> inline word32 rotlVariable<word32>(word32 x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
//! <stdlib.h>. The value x to be rotated is 32-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotrVariable will assert in Debug builds if is outside the allowed range.
//! \note rotrVariable will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word32 rotrVariable<word32>(word32 x, unsigned int y)
{
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return _lrotr(x, static_cast<byte>(y));
}
@ -1506,11 +1506,11 @@ template<> inline word32 rotrMod<word32>(word32 x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
//! <stdlib.h>. The value x to be rotated is 64-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotrFixed will assert in Debug builds if is outside the allowed range.
//! \note rotrFixed will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word64 rotlFixed<word64>(word64 x, unsigned int y)
{
// Uses Microsoft <stdlib.h> call, bound to C/C++ language rules.
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return y ? _rotl64(x, static_cast<byte>(y)) : x;
}
@ -1521,11 +1521,11 @@ template<> inline word64 rotlFixed<word64>(word64 x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
//! <stdlib.h>. The value x to be rotated is 64-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotrFixed will assert in Debug builds if is outside the allowed range.
//! \note rotrFixed will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word64 rotrFixed<word64>(word64 x, unsigned int y)
{
// Uses Microsoft <stdlib.h> call, bound to C/C++ language rules.
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return y ? _rotr64(x, static_cast<byte>(y)) : x;
}
@ -1536,10 +1536,10 @@ template<> inline word64 rotrFixed<word64>(word64 x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
//! <stdlib.h>. The value x to be rotated is 64-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotlVariable will assert in Debug builds if is outside the allowed range.
//! \note rotlVariable will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word64 rotlVariable<word64>(word64 x, unsigned int y)
{
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return _rotl64(x, static_cast<byte>(y));
}
@ -1550,10 +1550,10 @@ template<> inline word64 rotlVariable<word64>(word64 x, unsigned int y)
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
//! <stdlib.h>. The value x to be rotated is 64-bits. y must be in the range
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
//! \note rotrVariable will assert in Debug builds if is outside the allowed range.
//! \note rotrVariable will CRYPTOPP_ASSERT in Debug builds if is outside the allowed range.
template<> inline word64 rotrVariable<word64>(word64 x, unsigned int y)
{
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return y ? _rotr64(x, static_cast<byte>(y)) : x;
}
@ -1566,7 +1566,7 @@ template<> inline word64 rotrVariable<word64>(word64 x, unsigned int y)
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
template<> inline word64 rotlMod<word64>(word64 x, unsigned int y)
{
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return y ? _rotl64(x, static_cast<byte>(y)) : x;
}
@ -1579,7 +1579,7 @@ template<> inline word64 rotlMod<word64>(word64 x, unsigned int y)
//! <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
template<> inline word64 rotrMod<word64>(word64 x, unsigned int y)
{
assert(y < 8*sizeof(x));
CRYPTOPP_ASSERT(y < 8*sizeof(x));
return y ? _rotr64(x, static_cast<byte>(y)) : x;
}
@ -1658,25 +1658,25 @@ template<> inline byte rotrMod<byte>(byte x, unsigned int y)
template<> inline word32 rotlFixed<word32>(word32 x, unsigned int y)
{
assert(y < 32);
CRYPTOPP_ASSERT(y < 32);
return y ? __rlwinm(x,y,0,31) : x;
}
template<> inline word32 rotrFixed<word32>(word32 x, unsigned int y)
{
assert(y < 32);
CRYPTOPP_ASSERT(y < 32);
return y ? __rlwinm(x,32-y,0,31) : x;
}
template<> inline word32 rotlVariable<word32>(word32 x, unsigned int y)
{
assert(y < 32);
CRYPTOPP_ASSERT(y < 32);
return (__rlwnm(x,y,0,31));
}
template<> inline word32 rotrVariable<word32>(word32 x, unsigned int y)
{
assert(y < 32);
CRYPTOPP_ASSERT(y < 32);
return (__rlwnm(x,32-y,0,31));
}
@ -1841,7 +1841,7 @@ inline T BitReverse(T value)
return (T)BitReverse((word32)value);
else
{
assert(sizeof(T) == 8);
CRYPTOPP_ASSERT(sizeof(T) == 8);
return (T)BitReverse((word64)value);
}
}
@ -1897,7 +1897,7 @@ inline T ConditionalByteReverse(ByteOrder order, T value)
template <class T>
void ByteReverse(T *out, const T *in, size_t byteCount)
{
assert(byteCount % sizeof(T) == 0);
CRYPTOPP_ASSERT(byteCount % sizeof(T) == 0);
size_t count = byteCount/sizeof(T);
for (size_t i=0; i<count; i++)
out[i] = ByteReverse(in[i]);
@ -1929,7 +1929,7 @@ template <class T>
inline void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen)
{
const size_t U = sizeof(T);
assert(inlen <= outlen*U);
CRYPTOPP_ASSERT(inlen <= outlen*U);
memcpy_s(out, outlen*U, in, inlen);
memset_z((byte *)out+inlen, 0, outlen*U-inlen);
ConditionalByteReverse(order, out, out, RoundUpToMultipleOf(inlen, U));
@ -2114,7 +2114,7 @@ inline T GetWord(bool assumeAligned, ByteOrder order, const byte *block)
//#ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
// if (!assumeAligned)
// return UnalignedGetWordNonTemplate(order, block, (T*)NULL);
// assert(IsAligned<T>(block));
// CRYPTOPP_ASSERT(IsAligned<T>(block));
//#endif
// return ConditionalByteReverse(order, *reinterpret_cast<const T *>(block));
CRYPTOPP_UNUSED(assumeAligned);
@ -2139,8 +2139,8 @@ inline void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, c
//#ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
// if (!assumeAligned)
// return UnalignedbyteNonTemplate(order, block, value, xorBlock);
// assert(IsAligned<T>(block));
// assert(IsAligned<T>(xorBlock));
// CRYPTOPP_ASSERT(IsAligned<T>(block));
// CRYPTOPP_ASSERT(IsAligned<T>(xorBlock));
//#endif
// *reinterpret_cast<T *>(block) = ConditionalByteReverse(order, value) ^ (xorBlock ? *reinterpret_cast<const T *>(xorBlock) : 0);
CRYPTOPP_UNUSED(assumeAligned);

View File

@ -7,13 +7,13 @@
#include "modes.h"
#include "misc.h"
//#ifndef NDEBUG
//#if CRYPTOPP_DEBUG
#include "des.h"
//#endif
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Modes_TestInstantiations()
{
CFB_Mode<DES>::Encryption m0;
@ -35,10 +35,10 @@ void CipherModeBase::ResizeBuffers()
void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount)
{
assert(input);
assert(output);
assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
assert(m_feedbackSize == BlockSize());
CRYPTOPP_ASSERT(input);
CRYPTOPP_ASSERT(output);
CRYPTOPP_ASSERT(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
CRYPTOPP_ASSERT(m_feedbackSize == BlockSize());
const unsigned int s = BlockSize();
if (dir == ENCRYPTION)
@ -60,7 +60,7 @@ void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, siz
void CFB_ModePolicy::TransformRegister()
{
assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
CRYPTOPP_ASSERT(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
m_cipher->ProcessBlock(m_register, m_temp);
unsigned int updateSize = BlockSize()-m_feedbackSize;
memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize);
@ -69,7 +69,7 @@ void CFB_ModePolicy::TransformRegister()
void CFB_ModePolicy::CipherResynchronize(const byte *iv, size_t length)
{
assert(length == BlockSize());
CRYPTOPP_ASSERT(length == BlockSize());
CopyOrZero(m_register, iv, length);
TransformRegister();
}
@ -89,7 +89,7 @@ void CFB_ModePolicy::ResizeBuffers()
void OFB_ModePolicy::WriteKeystream(byte *keystreamBuffer, size_t iterationCount)
{
assert(m_cipher->IsForwardTransformation()); // OFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
CRYPTOPP_ASSERT(m_cipher->IsForwardTransformation()); // OFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
unsigned int s = BlockSize();
m_cipher->ProcessBlock(m_register, keystreamBuffer);
if (iterationCount > 1)
@ -100,7 +100,7 @@ void OFB_ModePolicy::WriteKeystream(byte *keystreamBuffer, size_t iterationCount
void OFB_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer), CRYPTOPP_UNUSED(length);
assert(length == BlockSize());
CRYPTOPP_ASSERT(length == BlockSize());
CopyOrZero(m_register, iv, length);
}
@ -124,7 +124,7 @@ void CTR_ModePolicy::IncrementCounterBy256()
void CTR_ModePolicy::OperateKeystream(KeystreamOperation /*operation*/, byte *output, const byte *input, size_t iterationCount)
{
assert(m_cipher->IsForwardTransformation()); // CTR mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
CRYPTOPP_ASSERT(m_cipher->IsForwardTransformation()); // CTR mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
unsigned int s = BlockSize();
unsigned int inputIncrement = input ? s : 0;
@ -145,7 +145,7 @@ void CTR_ModePolicy::OperateKeystream(KeystreamOperation /*operation*/, byte *ou
void CTR_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer), CRYPTOPP_UNUSED(length);
assert(length == BlockSize());
CRYPTOPP_ASSERT(length == BlockSize());
CopyOrZero(m_register, iv, length);
m_counterArray = m_register;
@ -174,7 +174,7 @@ void BlockOrientedCipherModeBase::ResizeBuffers()
void ECB_OneWay::ProcessData(byte *outString, const byte *inString, size_t length)
{
assert(length%BlockSize()==0);
CRYPTOPP_ASSERT(length%BlockSize()==0);
m_cipher->AdvancedProcessBlocks(inString, NULL, outString, length, BlockTransformation::BT_AllowParallel);
}
@ -182,7 +182,7 @@ void CBC_Encryption::ProcessData(byte *outString, const byte *inString, size_t l
{
if (!length)
return;
assert(length%BlockSize()==0);
CRYPTOPP_ASSERT(length%BlockSize()==0);
unsigned int blockSize = BlockSize();
m_cipher->AdvancedProcessBlocks(inString, m_register, outString, blockSize, BlockTransformation::BT_XorInput);
@ -231,7 +231,7 @@ void CBC_Decryption::ProcessData(byte *outString, const byte *inString, size_t l
{
if (!length)
return;
assert(length%BlockSize()==0);
CRYPTOPP_ASSERT(length%BlockSize()==0);
unsigned int blockSize = BlockSize();
memcpy(m_temp, inString+length-blockSize, blockSize); // save copy now in case of in-place decryption

View File

@ -66,7 +66,7 @@ public:
protected:
CipherModeBase() : m_cipher(NULL) {}
inline unsigned int BlockSize() const {assert(m_register.size() > 0); return (unsigned int)m_register.size();}
inline unsigned int BlockSize() const {CRYPTOPP_ASSERT(m_register.size() > 0); return (unsigned int)m_register.size();}
virtual void SetFeedbackSize(unsigned int feedbackSize)
{
if (!(feedbackSize == 0 || feedbackSize == BlockSize()))

View File

@ -9,7 +9,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void TestInstantiations_MQV()
{
MQV mqv;

View File

@ -75,7 +75,7 @@ bool TrialDivision(const Integer &p, unsigned bound)
unsigned int primeTableSize;
const word16 * primeTable = GetPrimeTable(primeTableSize);
assert(primeTable[primeTableSize-1] >= bound);
CRYPTOPP_ASSERT(primeTable[primeTableSize-1] >= bound);
unsigned int i;
for (i = 0; primeTable[i]<bound; i++)
@ -100,7 +100,7 @@ bool IsFermatProbablePrime(const Integer &n, const Integer &b)
if (n <= 3)
return n==2 || n==3;
assert(n>3 && b>1 && b<n-1);
CRYPTOPP_ASSERT(n>3 && b>1 && b<n-1);
return a_exp_b_mod_c(b, n-1, n)==1;
}
@ -109,7 +109,7 @@ bool IsStrongProbablePrime(const Integer &n, const Integer &b)
if (n <= 3)
return n==2 || n==3;
assert(n>3 && b>1 && b<n-1);
CRYPTOPP_ASSERT(n>3 && b>1 && b<n-1);
if ((n.IsEven() && n!=2) || GCD(b, n) != 1)
return false;
@ -142,7 +142,7 @@ bool RabinMillerTest(RandomNumberGenerator &rng, const Integer &n, unsigned int
if (n <= 3)
return n==2 || n==3;
assert(n>3);
CRYPTOPP_ASSERT(n>3);
Integer b;
for (unsigned int i=0; i<rounds; i++)
@ -162,7 +162,7 @@ bool IsLucasProbablePrime(const Integer &n)
if (n.IsEven())
return n==2;
assert(n>2);
CRYPTOPP_ASSERT(n>2);
Integer b=3;
unsigned int i=0;
@ -189,7 +189,7 @@ bool IsStrongLucasProbablePrime(const Integer &n)
if (n.IsEven())
return n==2;
assert(n>2);
CRYPTOPP_ASSERT(n>2);
Integer b=3;
unsigned int i=0;
@ -310,7 +310,7 @@ PrimeSieve::PrimeSieve(const Integer &first, const Integer &last, const Integer
bool PrimeSieve::NextCandidate(Integer &c)
{
bool safe = SafeConvert(std::find(m_sieve.begin()+m_next, m_sieve.end(), false) - m_sieve.begin(), m_next);
CRYPTOPP_UNUSED(safe); assert(safe);
CRYPTOPP_UNUSED(safe); CRYPTOPP_ASSERT(safe);
if (m_next == m_sieve.size())
{
m_first += long(m_sieve.size())*m_step;
@ -363,7 +363,7 @@ void PrimeSieve::DoSieve()
}
else
{
assert(m_step%2==0);
CRYPTOPP_ASSERT(m_step%2==0);
Integer qFirst = (m_first-m_delta) >> 1;
Integer halfStep = m_step >> 1;
for (unsigned int i = 0; i < primeTableSize; ++i)
@ -380,7 +380,7 @@ void PrimeSieve::DoSieve()
bool FirstPrime(Integer &p, const Integer &max, const Integer &equiv, const Integer &mod, const PrimeSelector *pSelector)
{
assert(!equiv.IsNegative() && equiv < mod);
CRYPTOPP_ASSERT(!equiv.IsNegative() && equiv < mod);
Integer gcd = GCD(equiv, mod);
if (gcd != Integer::One())
@ -420,7 +420,7 @@ bool FirstPrime(Integer &p, const Integer &max, const Integer &equiv, const Inte
p = primeTable[primeTableSize-1]+1;
}
assert(p > primeTable[primeTableSize-1]);
CRYPTOPP_ASSERT(p > primeTable[primeTableSize-1]);
if (mod.IsOdd())
return FirstPrime(p, max, CRT(equiv, mod, 1, 2, 1), mod<<1, pSelector);
@ -444,8 +444,8 @@ bool FirstPrime(Integer &p, const Integer &max, const Integer &equiv, const Inte
// the following two functions are based on code and comments provided by Preda Mihailescu
static bool ProvePrime(const Integer &p, const Integer &q)
{
assert(p < q*q*q);
assert(p % q == 1);
CRYPTOPP_ASSERT(p < q*q*q);
CRYPTOPP_ASSERT(p % q == 1);
// this is the Quisquater test. Numbers p having passed the Lucas - Lehmer test
// for q and verifying p < q^3 can only be built up of two factors, both = 1 mod q,
@ -459,7 +459,7 @@ static bool ProvePrime(const Integer &p, const Integer &q)
unsigned int primeTableSize;
const word16 * primeTable = GetPrimeTable(primeTableSize);
assert(primeTableSize >= 50);
CRYPTOPP_ASSERT(primeTableSize >= 50);
for (int i=0; i<50; i++)
{
Integer b = a_exp_b_mod_c(primeTable[i], r, p);
@ -616,7 +616,7 @@ Integer ModularSquareRoot(const Integer &a, const Integer &p)
b = tempb*y%p;
}
assert(x.Squared()%p == a);
CRYPTOPP_ASSERT(x.Squared()%p == a);
return x;
}
@ -626,21 +626,21 @@ bool SolveModularQuadraticEquation(Integer &r1, Integer &r2, const Integer &a, c
switch (Jacobi(D, p))
{
default:
assert(false); // not reached
CRYPTOPP_ASSERT(false); // not reached
return false;
case -1:
return false;
case 0:
r1 = r2 = (-b*(a+a).InverseMod(p)) % p;
assert(((r1.Squared()*a + r1*b + c) % p).IsZero());
CRYPTOPP_ASSERT(((r1.Squared()*a + r1*b + c) % p).IsZero());
return true;
case 1:
Integer s = ModularSquareRoot(D, p);
Integer t = (a+a).InverseMod(p);
r1 = (s-b)*t % p;
r2 = (-s-b)*t % p;
assert(((r1.Squared()*a + r1*b + c) % p).IsZero());
assert(((r2.Squared()*a + r2*b + c) % p).IsZero());
CRYPTOPP_ASSERT(((r1.Squared()*a + r1*b + c) % p).IsZero());
CRYPTOPP_ASSERT(((r2.Squared()*a + r2*b + c) % p).IsZero());
return true;
}
}
@ -666,7 +666,7 @@ Integer ModularRoot(const Integer &a, const Integer &e,
Integer dp = EuclideanMultiplicativeInverse(e, p-1);
Integer dq = EuclideanMultiplicativeInverse(e, q-1);
Integer u = EuclideanMultiplicativeInverse(p, q);
assert(!!dp && !!dq && !!u);
CRYPTOPP_ASSERT(!!dp && !!dq && !!u);
return ModularRoot(a, dp, dq, p, q, u);
}
@ -676,7 +676,7 @@ Integer GCDI(const Integer &x, const Integer &y)
Integer a=x, b=y;
unsigned k=0;
assert(!!a && !!b);
CRYPTOPP_ASSERT(!!a && !!b);
while (a[0]==0 && b[0]==0)
{
@ -711,14 +711,14 @@ Integer GCDI(const Integer &x, const Integer &y)
break;
default:
assert(false);
CRYPTOPP_ASSERT(false);
}
}
}
Integer EuclideanMultiplicativeInverse(const Integer &a, const Integer &b)
{
assert(b.Positive());
CRYPTOPP_ASSERT(b.Positive());
if (a.Negative())
return EuclideanMultiplicativeInverse(a%b, b);
@ -786,7 +786,7 @@ Integer EuclideanMultiplicativeInverse(const Integer &a, const Integer &b)
int Jacobi(const Integer &aIn, const Integer &bIn)
{
assert(bIn.IsOdd());
CRYPTOPP_ASSERT(bIn.IsOdd());
Integer b = bIn, a = aIn%bIn;
int result = 1;
@ -979,7 +979,7 @@ Integer Lucas(const Integer &n, const Integer &P, const Integer &modulus)
continue;
}
assert(em2 == 0);
CRYPTOPP_ASSERT(em2 == 0);
// #9
e >>= 1;
C = f(C, B, A);
@ -1038,8 +1038,8 @@ unsigned int DiscreteLogWorkFactor(unsigned int n)
void PrimeAndGenerator::Generate(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned int qbits)
{
// no prime exists for delta = -1, qbits = 4, and pbits = 5
assert(qbits > 4);
assert(pbits > qbits);
CRYPTOPP_ASSERT(qbits > 4);
CRYPTOPP_ASSERT(pbits > qbits);
if (qbits+1 == pbits)
{
@ -1054,9 +1054,9 @@ void PrimeAndGenerator::Generate(signed int delta, RandomNumberGenerator &rng, u
while (sieve.NextCandidate(p))
{
assert(IsSmallPrime(p) || SmallDivisorsTest(p));
CRYPTOPP_ASSERT(IsSmallPrime(p) || SmallDivisorsTest(p));
q = (p-delta) >> 1;
assert(IsSmallPrime(q) || SmallDivisorsTest(q));
CRYPTOPP_ASSERT(IsSmallPrime(q) || SmallDivisorsTest(q));
if (FastProbablePrimeTest(q) && FastProbablePrimeTest(p) && IsPrime(q) && IsPrime(p))
{
success = true;
@ -1071,11 +1071,11 @@ void PrimeAndGenerator::Generate(signed int delta, RandomNumberGenerator &rng, u
// g=4 always works, but this way we get the smallest quadratic residue (other than 1)
for (g=2; Jacobi(g, p) != 1; ++g) {}
// contributed by Walt Tuvell: g should be the following according to the Law of Quadratic Reciprocity
assert((p%8==1 || p%8==7) ? g==2 : (p%12==1 || p%12==11) ? g==3 : g==4);
CRYPTOPP_ASSERT((p%8==1 || p%8==7) ? g==2 : (p%12==1 || p%12==11) ? g==3 : g==4);
}
else
{
assert(delta == -1);
CRYPTOPP_ASSERT(delta == -1);
// find g such that g*g-4 is a quadratic non-residue,
// and such that g has order q
for (g=3; ; ++g)
@ -1103,11 +1103,11 @@ void PrimeAndGenerator::Generate(signed int delta, RandomNumberGenerator &rng, u
Integer h(rng, 2, p-2, Integer::ANY);
g = a_exp_b_mod_c(h, (p-1)/q, p);
} while (g <= 1);
assert(a_exp_b_mod_c(g, q, p)==1);
CRYPTOPP_ASSERT(a_exp_b_mod_c(g, q, p)==1);
}
else
{
assert(delta==-1);
CRYPTOPP_ASSERT(delta==-1);
do
{
Integer h(rng, 3, p-1, Integer::ANY);
@ -1115,7 +1115,7 @@ void PrimeAndGenerator::Generate(signed int delta, RandomNumberGenerator &rng, u
continue;
g = Lucas((p+1)/q, h, p);
} while (g <= 2);
assert(Lucas(q, g, p) == 2);
CRYPTOPP_ASSERT(Lucas(q, g, p) == 2);
}
}
}

View File

@ -435,7 +435,7 @@ size_t NetworkSink::Put2(const byte *inString, size_t length, int messageEnd, bo
{
if (m_skipBytes)
{
assert(length >= m_skipBytes);
CRYPTOPP_ASSERT(length >= m_skipBytes);
inString += m_skipBytes;
length -= m_skipBytes;
}
@ -451,7 +451,7 @@ size_t NetworkSink::Put2(const byte *inString, size_t length, int messageEnd, bo
if (m_buffer.CurrentSize() > targetSize)
{
assert(!blocking);
CRYPTOPP_ASSERT(!blocking);
m_wasBlocked = true;
m_skipBytes += length;
size_t blockedBytes = UnsignedMin(length, m_buffer.CurrentSize() - targetSize);

View File

@ -19,7 +19,7 @@ size_t OAEP_Base::MaxUnpaddedLength(size_t paddedLength) const
void OAEP_Base::Pad(RandomNumberGenerator &rng, const byte *input, size_t inputLength, byte *oaepBlock, size_t oaepBlockLen, const NameValuePairs &parameters) const
{
assert (inputLength <= MaxUnpaddedLength(oaepBlockLen));
CRYPTOPP_ASSERT (inputLength <= MaxUnpaddedLength(oaepBlockLen));
// convert from bit length to byte length
if (oaepBlockLen % 8 != 0)

111
ossig.h Normal file
View File

@ -0,0 +1,111 @@
// ossig.h - written and placed in the public domain by Jeffrey Walton
//
//! \file ossig.h
//! \brief Utility class for trapping OS signals.
//! \since Crypto++ 5.6.5
#ifndef CRYPTOPP_OS_SIGNAL_H
#define CRYPTOPP_OS_SIGNAL_H
#include "config.h"
#if defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE)
# include <signal.h>
#endif
NAMESPACE_BEGIN(CryptoPP)
// ************** Unix and Linux compatibles ***************
#if defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
//! \brief Signal handler function pointer
//! \sa SignalHandler
extern "C" {
typedef void (*SignalHandlerFn) (int);
};
//! Signal handler for Linux and Unix compatibles
//! \tparam S Signal number
//! \tparam O Flag indicating exsting handler should be overwriiten
//! \details SignalHandler() can be used to install a signal handler with the signature
//! <tt>void handler_fn(int)</tt>. If <tt>SignalHandlerFn</tt> is not <tt>NULL</tt>, then
//! the sigaction is set to the function and the sigaction flags is set to the flags.
//! If <tt>SignalHandlerFn</tt> is <tt>NULL</tt>, then a default handler is installed
//! using sigaction flags set to 0. The default handler only returns from the call.
//! \details Upon destruction the previous signal handler is restored if the former signal handler
//! was replaced.
//! \warning Do not use SignalHandler in a code block that uses <tt>setjmp</tt> or <tt>longjmp</tt>
//! because the destructor may not run.
//! \since Crypto++ 5.6.5
//! \sa SignalHandlerFn, \ref CRYPTOPP_ASSERT "CRYPTOPP_ASSERT", DebugTrapHandler
template <int S, bool O=false>
struct SignalHandler
{
//! \brief Construct a signal handler
//! \param pfn Pointer to a signal handler function
//! \param flags Flags to use with the signal handler
//! \details SignalHandler() installs a signal handler with the signature
//! <tt>void handler_fn(int)</tt>. If <tt>SignalHandlerFn</tt> is not <tt>NULL</tt>, then
//! the sigaction is set to the function and the sigaction flags is set to the flags.
//! If <tt>SignalHandlerFn</tt> is <tt>NULL</tt>, then a default handler is installed
//! using sigaction flags set to 0. The default handler only returns from the call.
//! \details Upon destruction the previous signal handler is restored if the former signal handler
//! was overwritten.
//! \warning Do not use SignalHandler in a code block that uses <tt>setjmp</tt> or <tt>longjmp</tt>
//! because the destructor may not run. <tt>setjmp</tt> is why cpu.cpp does not use SignalHandler
//! during CPU feature testing.
//! \since Crypto++ 5.6.5
SignalHandler(SignalHandlerFn pfn = 0, int flags = 0) : m_installed(false)
{
// http://pubs.opengroup.org/onlinepubs/007908799/xsh/sigaction.html
struct sigaction new_handler;
// memset(&new_handler, 0x00, sizeof(new_handler));
do
{
int ret = 0;
ret = sigaction (S, 0, &m_old);
if (ret != 0) break; // Failed
// Don't step on another's handler if Overwrite=false
if (m_old.sa_handler != 0 && !O) break;
// Set up the structure to specify the action.
new_handler.sa_handler = (pfn ? pfn : &SignalHandler::NullHandler);
new_handler.sa_flags = (pfn ? flags : 0);
ret = sigemptyset (&new_handler.sa_mask);
if (ret != 0) break; // Failed
// Install it
ret = sigaction (S, &new_handler, 0);
if (ret != 0) break; // Failed
m_installed = true;
} while(0);
}
~SignalHandler()
{
if (m_installed)
sigaction (S, &m_old, 0);
}
private:
struct sigaction m_old;
bool m_installed;
static void NullHandler(int /*unused*/) { /* continue*/ }
private:
// Not copyable
SignalHandler(const SignalHandler &);
void operator=(const SignalHandler &);
};
#endif
NAMESPACE_END
#endif // CRYPTOPP_OS_SIGNAL_H

View File

@ -326,7 +326,7 @@ void CRYPTOPP_NOINLINE Panama_SSE2_Pull(size_t count, word32 *state, word32 *z,
template <class B>
void Panama<B>::Iterate(size_t count, const word32 *p, byte *output, const byte *input, KeystreamOperation operation)
{
assert(IsAlignedOn(m_state,GetAlignmentOf<word32>()));
CRYPTOPP_ASSERT(IsAlignedOn(m_state,GetAlignmentOf<word32>()));
word32 bstart = m_state[17];
word32 *const aPtr = m_state;
word32 cPtr[17];
@ -452,7 +452,7 @@ template <class B>
void PanamaCipherPolicy<B>::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
{
CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(length);
assert(length==32);
CRYPTOPP_ASSERT(length==32);
memcpy(m_key, key, 32);
}
@ -460,8 +460,8 @@ template <class B>
void PanamaCipherPolicy<B>::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer); CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(length);
assert(IsAlignedOn(iv,GetAlignmentOf<word32>()));
assert(length==32);
CRYPTOPP_ASSERT(IsAlignedOn(iv,GetAlignmentOf<word32>()));
CRYPTOPP_ASSERT(length==32);
this->Reset();
this->Iterate(1, m_key);
@ -500,7 +500,7 @@ template <class B>
void PanamaCipherPolicy<B>::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
{
#if (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_PANAMA_ASM)
// No need for alignment assert. Panama_SSE2_Pull is ASM, and its not bound by C alignment requirements.
// No need for alignment CRYPTOPP_ASSERT. Panama_SSE2_Pull is ASM, and its not bound by C alignment requirements.
if (B::ToEnum() == LITTLE_ENDIAN_ORDER && HasSSE2())
Panama_SSE2_Pull(iterationCount, this->m_state, (word32 *)(void *)output, (const word32 *)(void *)input);
else

View File

@ -7,7 +7,7 @@
#include "pkcspad.h"
#include "misc.h"
#include <assert.h>
#include "trap.h"
NAMESPACE_BEGIN(CryptoPP)
@ -32,7 +32,7 @@ size_t PKCS_EncryptionPaddingScheme::MaxUnpaddedLength(size_t paddedLength) cons
void PKCS_EncryptionPaddingScheme::Pad(RandomNumberGenerator& rng, const byte *input, size_t inputLen, byte *pkcsBlock, size_t pkcsBlockLen, const NameValuePairs& parameters) const
{
CRYPTOPP_UNUSED(parameters);
assert (inputLen <= MaxUnpaddedLength(pkcsBlockLen)); // this should be checked by caller
CRYPTOPP_ASSERT (inputLen <= MaxUnpaddedLength(pkcsBlockLen)); // this should be checked by caller
// convert from bit length to byte length
if (pkcsBlockLen % 8 != 0)
@ -73,7 +73,7 @@ DecodingResult PKCS_EncryptionPaddingScheme::Unpad(const byte *pkcsBlock, size_t
size_t i=1;
while (i<pkcsBlockLen && pkcsBlock[i++]) { // null body
}
assert(i==pkcsBlockLen || pkcsBlock[i-1]==0);
CRYPTOPP_ASSERT(i==pkcsBlockLen || pkcsBlock[i-1]==0);
size_t outputLen = pkcsBlockLen - i;
invalid = (outputLen > maxOutputLen) || invalid;
@ -96,7 +96,7 @@ void PKCS1v15_SignatureMessageEncodingMethod::ComputeMessageRepresentative(Rando
{
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);
CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
CRYPTOPP_ASSERT(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
size_t pkcsBlockLen = representativeBitLength;
// convert from bit length to byte length

View File

@ -475,7 +475,7 @@ void RingOfPolynomialsOver<T>::CalculateAlpha(std::vector<CoefficientType> &alph
template <class T>
typename RingOfPolynomialsOver<T>::Element RingOfPolynomialsOver<T>::Interpolate(const CoefficientType x[], const CoefficientType y[], unsigned int n) const
{
assert(n > 0);
CRYPTOPP_ASSERT(n > 0);
std::vector<CoefficientType> alpha(n);
CalculateAlpha(alpha, x, y, n);
@ -497,7 +497,7 @@ typename RingOfPolynomialsOver<T>::Element RingOfPolynomialsOver<T>::Interpolate
template <class T>
typename RingOfPolynomialsOver<T>::CoefficientType RingOfPolynomialsOver<T>::InterpolateAt(const CoefficientType &position, const CoefficientType x[], const CoefficientType y[], unsigned int n) const
{
assert(n > 0);
CRYPTOPP_ASSERT(n > 0);
std::vector<CoefficientType> alpha(n);
CalculateAlpha(alpha, x, y, n);
@ -527,7 +527,7 @@ void PrepareBulkPolynomialInterpolation(const Ring &ring, Element *w, const Elem
template <class Ring, class Element>
void PrepareBulkPolynomialInterpolationAt(const Ring &ring, Element *v, const Element &position, const Element x[], const Element w[], unsigned int n)
{
assert(n > 0);
CRYPTOPP_ASSERT(n > 0);
std::vector<Element> a(2*n-1);
unsigned int i;

View File

@ -51,7 +51,7 @@ void PSSR_MEM_Base::ComputeMessageRepresentative(RandomNumberGenerator &rng,
{
CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);
CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
CRYPTOPP_ASSERT(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
const size_t u = hashIdentifier.second + 1;
const size_t representativeByteLength = BitsToBytes(representativeBitLength);
@ -99,7 +99,7 @@ DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative(
byte *recoverableMessage) const
{
CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
CRYPTOPP_ASSERT(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
const size_t u = hashIdentifier.second + 1;
const size_t representativeByteLength = BitsToBytes(representativeBitLength);

View File

@ -29,7 +29,7 @@
//! </ul>
//!
//! \details The \p TF_ prefix means an implementation using trapdoor functions on integers.
//! \details The \p DL_ prefix means an implementation using group operations (in groups where discrete log is hard).
//! \details The \p DL_ prefix means an implementation using group operations in groups where discrete log is hard.
#ifndef CRYPTOPP_PUBKEY_H
#define CRYPTOPP_PUBKEY_H
@ -56,9 +56,9 @@
#undef INTERFACE
#if defined(__SUNPRO_CC)
# define MAYBE_RETURN_FOR_SOLARIS(x) return x
# define MAYBE_RETURN(x) return x
#else
# define MAYBE_RETURN_FOR_SOLARIS(x) CRYPTOPP_UNUSED(x)
# define MAYBE_RETURN(x) CRYPTOPP_UNUSED(x)
#endif
NAMESPACE_BEGIN(CryptoPP)
@ -365,7 +365,7 @@ public:
CRYPTOPP_UNUSED(hash);CRYPTOPP_UNUSED(recoverableMessage); CRYPTOPP_UNUSED(recoverableMessageLength);
CRYPTOPP_UNUSED(presignature); CRYPTOPP_UNUSED(presignatureLength); CRYPTOPP_UNUSED(semisignature);
if (RecoverablePartFirst())
assert(!"ProcessRecoverableMessage() not implemented");
CRYPTOPP_ASSERT(!"ProcessRecoverableMessage() not implemented");
}
virtual void ComputeMessageRepresentative(RandomNumberGenerator &rng,
@ -1314,7 +1314,7 @@ public:
{
CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(publicKey); CRYPTOPP_UNUSED(r); CRYPTOPP_UNUSED(s);
throw NotImplemented("DL_ElgamalLikeSignatureAlgorithm: this signature scheme does not support message recovery");
MAYBE_RETURN_FOR_SOLARIS(Integer::Zero());
MAYBE_RETURN(Integer::Zero());
}
virtual size_t RLen(const DL_GroupParameters<T> &params) const
{return params.GetSubgroupOrder().ByteCount();}
@ -1420,7 +1420,7 @@ public:
//! \returns maximum recoverable length based on signature length, in bytes
//! \details this function is not implemented and always returns 0.
size_t MaxRecoverableLengthFromSignatureLength(size_t signatureLength) const
{CRYPTOPP_UNUSED(signatureLength); assert(false); return 0;} // TODO
{CRYPTOPP_UNUSED(signatureLength); CRYPTOPP_ASSERT(false); return 0;} // TODO
//! \brief Determines if the scheme is probabilistic
//! \returns true if the scheme is probabilistic, false otherwise
@ -2006,7 +2006,7 @@ public:
return params.ExponentiateElement(publicElement, privateExponent*params.GetCofactor());
else
{
assert(COFACTOR_OPTION::ToEnum() == NO_COFACTOR_MULTIPLICTION);
CRYPTOPP_ASSERT(COFACTOR_OPTION::ToEnum() == NO_COFACTOR_MULTIPLICTION);
if (!validateOtherPublicKey)
return params.ExponentiateElement(publicElement, privateExponent);

View File

@ -83,8 +83,8 @@ template <class T>
unsigned int PKCS5_PBKDF1<T>::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const
{
CRYPTOPP_UNUSED(purpose);
assert(derivedLen <= MaxDerivedKeyLength());
assert(iterations > 0 || timeInSeconds > 0);
CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength());
CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0);
if (!iterations)
iterations = 1;
@ -113,8 +113,8 @@ template <class T>
unsigned int PKCS5_PBKDF2_HMAC<T>::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const
{
CRYPTOPP_UNUSED(purpose);
assert(derivedLen <= MaxDerivedKeyLength());
assert(iterations > 0 || timeInSeconds > 0);
CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength());
CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0);
if (!iterations)
iterations = 1;
@ -183,8 +183,8 @@ public:
template <class T>
unsigned int PKCS12_PBKDF<T>::DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const
{
assert(derivedLen <= MaxDerivedKeyLength());
assert(iterations > 0 || timeInSeconds > 0);
CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength());
CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0);
if (!iterations)
iterations = 1;

View File

@ -464,7 +464,7 @@ byte ByteQueue::operator[](lword i) const
i -= current->CurrentSize();
}
assert(i < m_lazyLength);
CRYPTOPP_ASSERT(i < m_lazyLength);
return m_lazyString[i];
}

View File

@ -132,7 +132,7 @@ public:
LazyPutter(ByteQueue &bq, const byte *inString, size_t size)
: m_bq(bq) {bq.LazyPut(inString, size);}
~LazyPutter()
{try {m_bq.FinalizeLazyPut();} catch(const Exception&) {assert(0);}}
{try {m_bq.FinalizeLazyPut();} catch(const Exception&) {CRYPTOPP_ASSERT(0);}}
protected:
LazyPutter(ByteQueue &bq) : m_bq(bq) {}
private:

View File

@ -163,7 +163,7 @@ NAMESPACE_BEGIN(CryptoPP)
#if ALL_RDRAND_INTRIN_AVAILABLE
static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
assert((output && size) || !(output || size));
CRYPTOPP_ASSERT((output && size) || !(output || size));
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
word32 val;
#else
@ -186,7 +186,7 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
if (!safety--)
{
assert(0);
CRYPTOPP_ASSERT(0);
return 0;
}
}
@ -208,7 +208,7 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
if (!safety--)
{
assert(0);
CRYPTOPP_ASSERT(0);
return 0;
}
}
@ -223,7 +223,7 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
#if GCC_RDRAND_ASM_AVAILABLE
static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
assert((output && size) || !(output || size));
CRYPTOPP_ASSERT((output && size) || !(output || size));
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
word64 val;
#else
@ -268,7 +268,7 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
if (!safety--)
{
assert(0);
CRYPTOPP_ASSERT(0);
return 0;
}
}
@ -285,7 +285,7 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety)
void RDRAND::GenerateBlock(byte *output, size_t size)
{
CRYPTOPP_UNUSED(output), CRYPTOPP_UNUSED(size);
assert((output && size) || !(output || size));
CRYPTOPP_ASSERT((output && size) || !(output || size));
if(!HasRDRAND())
throw NotImplemented("RDRAND: rdrand is not available on this platform");
@ -313,7 +313,7 @@ void RDRAND::DiscardBytes(size_t n)
{
// RoundUpToMultipleOf is used because a full word is read, and its cheaper
// to discard full words. There's no sense in dealing with tail bytes.
assert(HasRDRAND());
CRYPTOPP_ASSERT(HasRDRAND());
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
FixedSizeSecBlock<word64, 16> discard;
n = RoundUpToMultipleOf(n, sizeof(word64));
@ -338,7 +338,7 @@ void RDRAND::DiscardBytes(size_t n)
#if ALL_RDSEED_INTRIN_AVAILABLE
static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
assert((output && size) || !(output || size));
CRYPTOPP_ASSERT((output && size) || !(output || size));
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
word32 val;
#else
@ -361,7 +361,7 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
if (!safety--)
{
assert(0);
CRYPTOPP_ASSERT(0);
return 0;
}
}
@ -383,7 +383,7 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
if (!safety--)
{
assert(0);
CRYPTOPP_ASSERT(0);
return 0;
}
}
@ -398,7 +398,7 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
#if GCC_RDSEED_ASM_AVAILABLE
static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
assert((output && size) || !(output || size));
CRYPTOPP_ASSERT((output && size) || !(output || size));
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
word64 val;
#else
@ -443,7 +443,7 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety)
{
if (!safety--)
{
assert(0);
CRYPTOPP_ASSERT(0);
return 0;
}
}
@ -459,7 +459,7 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety)
void RDSEED::GenerateBlock(byte *output, size_t size)
{
CRYPTOPP_UNUSED(output), CRYPTOPP_UNUSED(size);
assert((output && size) || !(output || size));
CRYPTOPP_ASSERT((output && size) || !(output || size));
if(!HasRDSEED())
throw NotImplemented("RDSEED: rdseed is not available on this platform");
@ -487,7 +487,7 @@ void RDSEED::DiscardBytes(size_t n)
{
// RoundUpToMultipleOf is used because a full word is read, and its cheaper
// to discard full words. There's no sense in dealing with tail bytes.
assert(HasRDSEED());
CRYPTOPP_ASSERT(HasRDSEED());
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
FixedSizeSecBlock<word64, 16> discard;
n = RoundUpToMultipleOf(n, sizeof(word64));

View File

@ -103,7 +103,7 @@ public:
{
// Override to avoid the base class' throw.
CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
// assert(0); // warn in debug builds
// CRYPTOPP_ASSERT(0); // warn in debug builds
}
private:
@ -187,7 +187,7 @@ public:
{
// Override to avoid the base class' throw.
CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
// assert(0); // warn in debug builds
// CRYPTOPP_ASSERT(0); // warn in debug builds
}
private:

View File

@ -1128,7 +1128,7 @@ inline size_t AESNI_AdvancedProcessBlocks(F1 func1, F4 func4, MAYBE_CONST __m128
if (flags & BlockTransformation::BT_ReverseDirection)
{
assert(length % blockSize == 0);
CRYPTOPP_ASSERT(length % blockSize == 0);
inBlocks += length - blockSize;
xorBlocks += length - blockSize;
outBlocks += length - blockSize;
@ -1267,7 +1267,7 @@ size_t Rijndael::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xo
size_t increment = BLOCKSIZE;
if (flags & BT_ReverseDirection)
{
assert(length % BLOCKSIZE == 0);
CRYPTOPP_ASSERT(length % BLOCKSIZE == 0);
inBlocks += length - BLOCKSIZE;
xorBlocks += length - BLOCKSIZE;
outBlocks += length - BLOCKSIZE;

View File

@ -10,7 +10,7 @@
#include "algparam.h"
#include "fips140.h"
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) && !defined(CRYPTOPP_IS_DLL)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING) && !defined(CRYPTOPP_IS_DLL)
#include "pssr.h"
NAMESPACE_BEGIN(CryptoPP)
void RSA_TestInstantiations()
@ -108,13 +108,13 @@ void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const Nam
int modulusSize = 2048;
alg.GetIntValue(Name::ModulusSize(), modulusSize) || alg.GetIntValue(Name::KeySize(), modulusSize);
assert(modulusSize >= 16);
CRYPTOPP_ASSERT(modulusSize >= 16);
if (modulusSize < 16)
throw InvalidArgument("InvertibleRSAFunction: specified modulus size is too small");
m_e = alg.GetValueWithDefault(Name::PublicExponent(), Integer(17));
assert(m_e >= 3); assert(!m_e.IsEven());
CRYPTOPP_ASSERT(m_e >= 3); CRYPTOPP_ASSERT(!m_e.IsEven());
if (m_e < 3 || m_e.IsEven())
throw InvalidArgument("InvertibleRSAFunction: invalid public exponent");
@ -125,7 +125,7 @@ void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const Nam
m_q.GenerateRandom(rng, primeParam);
m_d = m_e.InverseMod(LCM(m_p-1, m_q-1));
assert(m_d.IsPositive());
CRYPTOPP_ASSERT(m_d.IsPositive());
m_dp = m_d % (m_p-1);
m_dq = m_d % (m_q-1);

2
rw.cpp
View File

@ -239,7 +239,7 @@ Integer InvertibleRWFunction::CalculateInverse(RandomNumberGenerator &rng, const
// Signature
Integer s = modn.Multiply(modn.Square(Y), rInv);
assert((e * f * s.Squared()) % m_n == x);
CRYPTOPP_ASSERT((e * f * s.Squared()) % m_n == x);
// IEEE P1363, Section 8.2.8 IFSP-RW, p.44
s = STDMIN(s, m_n - s);

View File

@ -32,7 +32,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Salsa20_TestInstantiations()
{
Salsa20::Encryption x1;
@ -63,7 +63,7 @@ void Salsa20_Policy::CipherSetKey(const NameValuePairs &params, const byte *key,
void Salsa20_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer), CRYPTOPP_UNUSED(length);
assert(length==8);
CRYPTOPP_ASSERT(length==8);
GetBlock<word32, LittleEndian> get(IV);
get(m_state[14])(m_state[11]);
@ -592,7 +592,7 @@ void XSalsa20_Policy::CipherSetKey(const NameValuePairs &params, const byte *key
void XSalsa20_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer), CRYPTOPP_UNUSED(length);
assert(length==24);
CRYPTOPP_ASSERT(length==24);
word32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;

View File

@ -10,7 +10,7 @@
NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void SEAL_TestInstantiations()
{
SEAL<>::Encryption x;
@ -73,7 +73,7 @@ template <class B>
void SEAL_Policy<B>::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer), CRYPTOPP_UNUSED(IV), CRYPTOPP_UNUSED(length);
assert(length==4);
CRYPTOPP_ASSERT(length==4);
m_outsideCounter = IV ? GetWord<word32>(false, BIG_ENDIAN_ORDER, IV) : 0;
m_startCount = m_outsideCounter;
@ -93,7 +93,7 @@ void SEAL_Policy<B>::OperateKeystream(KeystreamOperation operation, byte *output
word32 a, b, c, d, n1, n2, n3, n4;
unsigned int p, q;
assert(IsAlignedOn(m_T.begin(),GetAlignmentOf<word32>()));
CRYPTOPP_ASSERT(IsAlignedOn(m_T.begin(),GetAlignmentOf<word32>()));
for (size_t iteration = 0; iteration < iterationCount; ++iteration)
{
#define Ttab(x) *(word32 *)(void*)((byte *)m_T.begin()+x)

View File

@ -118,7 +118,7 @@ typedef typename AllocatorBase<T>::const_reference const_reference;
template <class T, class A>
typename A::pointer StandardReallocate(A& alloc, T *oldPtr, typename A::size_type oldSize, typename A::size_type newSize, bool preserve)
{
assert((oldPtr && oldSize) || !(oldPtr || oldSize));
CRYPTOPP_ASSERT((oldPtr && oldSize) || !(oldPtr || oldSize));
if (oldSize == newSize)
return oldPtr;
@ -164,13 +164,13 @@ public:
//! \details AlignedAllocate() is used if T_Align16 is true.
//! UnalignedAllocate() used if T_Align16 is false.
//! \details This is the C++ *Placement New* operator. ptr is not used, and the function
//! asserts in Debug builds if ptr is non-NULL.
//! CRYPTOPP_ASSERTs in Debug builds if ptr is non-NULL.
//! \sa CallNewHandler() for the methods used to recover from a failed
//! allocation attempt.
//! \note size is the count of elements, and not the number of bytes
pointer allocate(size_type size, const void *ptr = NULL)
{
CRYPTOPP_UNUSED(ptr); assert(ptr == NULL);
CRYPTOPP_UNUSED(ptr); CRYPTOPP_ASSERT(ptr == NULL);
this->CheckSize(size);
if (size == 0)
return NULL;
@ -194,7 +194,7 @@ public:
//! UnalignedDeallocate() used if T_Align16 is false.
void deallocate(void *ptr, size_type size)
{
assert((ptr && size) || !(ptr || size));
CRYPTOPP_ASSERT((ptr && size) || !(ptr || size));
SecureWipeArray((pointer)ptr, size);
#if CRYPTOPP_BOOL_ALIGN16
@ -220,7 +220,7 @@ public:
//! number of bytes.
pointer reallocate(T *oldPtr, size_type oldSize, size_type newSize, bool preserve)
{
assert((oldPtr && oldSize) || !(oldPtr || oldSize));
CRYPTOPP_ASSERT((oldPtr && oldSize) || !(oldPtr || oldSize));
return StandardReallocate(*this, oldPtr, oldSize, newSize, preserve);
}
@ -272,13 +272,13 @@ public:
pointer allocate(size_type n, const void* unused = NULL)
{
CRYPTOPP_UNUSED(n); CRYPTOPP_UNUSED(unused);
assert(false); return NULL;
CRYPTOPP_ASSERT(false); return NULL;
}
void deallocate(void *p, size_type n)
{
CRYPTOPP_UNUSED(p); CRYPTOPP_UNUSED(n);
assert(false);
CRYPTOPP_ASSERT(false);
}
CRYPTOPP_CONSTEXPR size_type max_size() const {return 0;}
@ -320,7 +320,7 @@ public:
//! \sa reallocate(), SecBlockWithHint
pointer allocate(size_type size)
{
assert(IsAlignedOn(m_array, 8));
CRYPTOPP_ASSERT(IsAlignedOn(m_array, 8));
if (size <= S && !m_allocated)
{
@ -367,8 +367,8 @@ public:
{
if (ptr == GetAlignedArray())
{
assert(size <= S);
assert(m_allocated);
CRYPTOPP_ASSERT(size <= S);
CRYPTOPP_ASSERT(m_allocated);
m_allocated = false;
SecureWipeArray((pointer)ptr, size);
}
@ -397,7 +397,7 @@ public:
{
if (oldPtr == GetAlignedArray() && newSize <= S)
{
assert(oldSize <= S);
CRYPTOPP_ASSERT(oldSize <= S);
if (oldSize > newSize)
SecureWipeArray(oldPtr+newSize, oldSize-newSize);
return oldPtr;
@ -455,7 +455,7 @@ public:
//! \throws std::bad_alloc
SecBlock(const SecBlock<T, A> &t)
: m_size(t.m_size), m_ptr(m_alloc.allocate(t.m_size, NULL)) {
assert((!t.m_ptr && !m_size) || (t.m_ptr && m_size));
CRYPTOPP_ASSERT((!t.m_ptr && !m_size) || (t.m_ptr && m_size));
if (t.m_ptr) {memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T));}
}
@ -469,7 +469,7 @@ public:
//! \note size is the count of elements, and not the number of bytes
SecBlock(const T *ptr, size_type len)
: m_size(len), m_ptr(m_alloc.allocate(len, NULL)) {
assert((!m_ptr && !m_size) || (m_ptr && m_size));
CRYPTOPP_ASSERT((!m_ptr && !m_size) || (m_ptr && m_size));
if (ptr && m_ptr)
memcpy_s(m_ptr, m_size*sizeof(T), ptr, len*sizeof(T));
else if (m_size)
@ -578,7 +578,7 @@ public:
//! \details Internally, this SecBlock calls Grow and then appends t.
SecBlock<T, A>& operator+=(const SecBlock<T, A> &t)
{
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
CRYPTOPP_ASSERT((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
if(t.m_size)
{
@ -603,8 +603,8 @@ public:
//! \details Internally, a new SecBlock is created from this and a concatenation of t.
SecBlock<T, A> operator+(const SecBlock<T, A> &t)
{
assert((!m_ptr && !m_size) || (m_ptr && m_size));
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
CRYPTOPP_ASSERT((!m_ptr && !m_size) || (m_ptr && m_size));
CRYPTOPP_ASSERT((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
if(!t.m_size) return SecBlock(*this);
SecBlock<T, A> result(m_size+t.m_size);

View File

@ -886,8 +886,8 @@ CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state
void SHA512::Transform(word64 *state, const word64 *data)
{
assert(IsAlignedOn(state, GetAlignmentOf<word64>()));
assert(IsAlignedOn(data, GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(state, GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(data, GetAlignmentOf<word64>()));
#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32)
if (HasSSE2())

View File

@ -251,7 +251,7 @@ static void KeccakF1600(word64 *state)
void SHA3::Update(const byte *input, size_t length)
{
assert((input && length) || !(input || length));
CRYPTOPP_ASSERT((input && length) || !(input || length));
if (!length)
return;

View File

@ -96,7 +96,7 @@ template <const byte *sbox, const ArrayOf256Word64s *cbox>
struct SharkProcessAndXorBlock{ // VC60 workaround: problem with template functions
inline SharkProcessAndXorBlock(const word64 *roundKeys, unsigned int rounds, const byte *inBlock, const byte *xorBlock, byte *outBlock)
{
assert(IsAlignedOn(inBlock,GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(inBlock,GetAlignmentOf<word64>()));
word64 tmp = *(word64 *)(void *)inBlock ^ roundKeys[0];
ByteOrder order = GetNativeByteOrder();
@ -125,7 +125,7 @@ inline SharkProcessAndXorBlock(const word64 *roundKeys, unsigned int rounds, con
(sbox[GETBYTE(tmp, 1)])
(sbox[GETBYTE(tmp, 0)]);
assert(IsAlignedOn(outBlock,GetAlignmentOf<word64>()));
CRYPTOPP_ASSERT(IsAlignedOn(outBlock,GetAlignmentOf<word64>()));
*(word64 *)(void *)outBlock ^= roundKeys[rounds];
}};

View File

@ -97,7 +97,7 @@ public:
bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
{return ChannelFlush(DEFAULT_CHANNEL, completeFlush, propagation, blocking);}
bool IsolatedFlush(bool hardFlush, bool blocking)
{CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); assert(false); return false;}
{CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); CRYPTOPP_ASSERT(false); return false;}
bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
{
if (hardFlush && !InputBufferIsEmpty())
@ -167,7 +167,7 @@ public:
private:
bool IsolatedFlush(bool hardFlush, bool blocking)
{CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); assert(false); return false;}
{CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); CRYPTOPP_ASSERT(false); return false;}
};
//! \class CustomSignalPropagation
@ -182,7 +182,7 @@ public:
private:
void IsolatedInitialize(const NameValuePairs &parameters)
{CRYPTOPP_UNUSED(parameters); assert(false);}
{CRYPTOPP_UNUSED(parameters); CRYPTOPP_ASSERT(false);}
};
//! \class Multichannel

View File

@ -238,9 +238,9 @@ public:
{delete [] m_ptr;}
T& operator[](size_t index)
{assert(m_size && index<this->m_size); return this->m_ptr[index];}
{CRYPTOPP_ASSERT(m_size && index<this->m_size); return this->m_ptr[index];}
const T& operator[](size_t index) const
{assert(m_size && index<this->m_size); return this->m_ptr[index];}
{CRYPTOPP_ASSERT(m_size && index<this->m_size); return this->m_ptr[index];}
size_t size() const {return this->m_size;}
void resize(size_t newSize)
@ -293,9 +293,9 @@ public:
{delete [] this->m_ptr;}
member_ptr<T>& operator[](size_t index)
{assert(index<this->m_size); return this->m_ptr[index];}
{CRYPTOPP_ASSERT(index<this->m_size); return this->m_ptr[index];}
const member_ptr<T>& operator[](size_t index) const
{assert(index<this->m_size); return this->m_ptr[index];}
{CRYPTOPP_ASSERT(index<this->m_size); return this->m_ptr[index];}
size_t size() const {return this->m_size;}
void resize(size_t newSize)

View File

@ -68,7 +68,7 @@ Socket::~Socket()
}
catch (const Exception&)
{
assert(0);
CRYPTOPP_ASSERT(0);
}
}
}
@ -93,7 +93,7 @@ socket_t Socket::DetachSocket()
void Socket::Create(int nType)
{
assert(m_s == INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s == INVALID_SOCKET);
m_s = socket(AF_INET, nType, 0);
CheckAndHandleError("socket", m_s);
m_own = true;
@ -107,12 +107,12 @@ void Socket::CloseSocket()
#ifdef USE_WINDOWS_STYLE_SOCKETS
# if defined(USE_WINDOWS8_API)
BOOL result = CancelIoEx((HANDLE) m_s, NULL);
assert(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_ASSERT(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CheckAndHandleError_int("closesocket", closesocket(m_s));
CRYPTOPP_UNUSED(result); // Used by assert in debug builds
CRYPTOPP_UNUSED(result); // Used by CRYPTOPP_ASSERT in debug builds
# else
BOOL result = CancelIo((HANDLE) m_s);
assert(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_ASSERT(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CheckAndHandleError_int("closesocket", closesocket(m_s));
CRYPTOPP_UNUSED(result);
# endif
@ -150,20 +150,20 @@ void Socket::Bind(unsigned int port, const char *addr)
void Socket::Bind(const sockaddr *psa, socklen_t saLen)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
// cygwin workaround: needs const_cast
CheckAndHandleError_int("bind", bind(m_s, const_cast<sockaddr *>(psa), saLen));
}
void Socket::Listen(int backlog)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
CheckAndHandleError_int("listen", listen(m_s, backlog));
}
bool Socket::Connect(const char *addr, unsigned int port)
{
assert(addr != NULL);
CRYPTOPP_ASSERT(addr != NULL);
sockaddr_in sa;
memset(&sa, 0, sizeof(sa));
@ -180,7 +180,7 @@ bool Socket::Connect(const char *addr, unsigned int port)
}
else
{
assert(IsAlignedOn(lphost->h_addr,GetAlignmentOf<in_addr>()));
CRYPTOPP_ASSERT(IsAlignedOn(lphost->h_addr,GetAlignmentOf<in_addr>()));
sa.sin_addr.s_addr = ((in_addr *)(void *)lphost->h_addr)->s_addr;
}
}
@ -192,7 +192,7 @@ bool Socket::Connect(const char *addr, unsigned int port)
bool Socket::Connect(const sockaddr* psa, socklen_t saLen)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
int result = connect(m_s, const_cast<sockaddr*>(psa), saLen);
if (result == SOCKET_ERROR && GetLastError() == SOCKET_EWOULDBLOCK)
return false;
@ -202,7 +202,7 @@ bool Socket::Connect(const sockaddr* psa, socklen_t saLen)
bool Socket::Accept(Socket& target, sockaddr *psa, socklen_t *psaLen)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
socket_t s = accept(m_s, psa, psaLen);
if (s == INVALID_SOCKET && GetLastError() == SOCKET_EWOULDBLOCK)
return false;
@ -213,19 +213,19 @@ bool Socket::Accept(Socket& target, sockaddr *psa, socklen_t *psaLen)
void Socket::GetSockName(sockaddr *psa, socklen_t *psaLen)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
CheckAndHandleError_int("getsockname", getsockname(m_s, psa, psaLen));
}
void Socket::GetPeerName(sockaddr *psa, socklen_t *psaLen)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
CheckAndHandleError_int("getpeername", getpeername(m_s, psa, psaLen));
}
unsigned int Socket::Send(const byte* buf, size_t bufLen, int flags)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
int result = send(m_s, (const char *)buf, UnsignedMin(INT_MAX, bufLen), flags);
CheckAndHandleError_int("send", result);
return result;
@ -233,7 +233,7 @@ unsigned int Socket::Send(const byte* buf, size_t bufLen, int flags)
unsigned int Socket::Receive(byte* buf, size_t bufLen, int flags)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
int result = recv(m_s, (char *)buf, UnsignedMin(INT_MAX, bufLen), flags);
CheckAndHandleError_int("recv", result);
return result;
@ -241,14 +241,14 @@ unsigned int Socket::Receive(byte* buf, size_t bufLen, int flags)
void Socket::ShutDown(int how)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
int result = shutdown(m_s, how);
CheckAndHandleError_int("shutdown", result);
}
void Socket::IOCtl(long cmd, unsigned long *argp)
{
assert(m_s != INVALID_SOCKET);
CRYPTOPP_ASSERT(m_s != INVALID_SOCKET);
#ifdef USE_WINDOWS_STYLE_SOCKETS
CheckAndHandleError_int("ioctlsocket", ioctlsocket(m_s, cmd, argp));
#else
@ -369,11 +369,11 @@ SocketReceiver::~SocketReceiver()
#ifdef USE_WINDOWS_STYLE_SOCKETS
# if defined(USE_WINDOWS8_API)
BOOL result = CancelIoEx((HANDLE) m_s.GetSocket(), NULL);
assert(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_UNUSED(result); // Used by assert in debug builds
CRYPTOPP_ASSERT(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_UNUSED(result); // Used by CRYPTOPP_ASSERT in debug builds
# else
BOOL result = CancelIo((HANDLE) m_s.GetSocket());
assert(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_ASSERT(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_UNUSED(result);
# endif
#endif
@ -381,7 +381,7 @@ SocketReceiver::~SocketReceiver()
bool SocketReceiver::Receive(byte* buf, size_t bufLen)
{
assert(!m_resultPending && !m_eofReceived);
CRYPTOPP_ASSERT(!m_resultPending && !m_eofReceived);
DWORD flags = 0;
// don't queue too much at once, or we might use up non-paged memory
@ -459,11 +459,11 @@ SocketSender::~SocketSender()
#ifdef USE_WINDOWS_STYLE_SOCKETS
# if defined(USE_WINDOWS8_API)
BOOL result = CancelIoEx((HANDLE) m_s.GetSocket(), NULL);
assert(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_UNUSED(result); // Used by assert in debug builds
CRYPTOPP_ASSERT(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_UNUSED(result); // Used by CRYPTOPP_ASSERT in debug builds
# else
BOOL result = CancelIo((HANDLE) m_s.GetSocket());
assert(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_ASSERT(result || (!result && GetLastError() == ERROR_NOT_FOUND));
CRYPTOPP_UNUSED(result);
# endif
#endif
@ -471,7 +471,7 @@ SocketSender::~SocketSender()
void SocketSender::Send(const byte* buf, size_t bufLen)
{
assert(!m_resultPending);
CRYPTOPP_ASSERT(!m_resultPending);
DWORD written = 0;
// don't queue too much at once, or we might use up non-paged memory
WSABUF wsabuf = {UnsignedMin((u_long)128*1024, bufLen), (char *)buf};
@ -491,7 +491,7 @@ void SocketSender::Send(const byte* buf, size_t bufLen)
void SocketSender::SendEof()
{
assert(!m_resultPending);
CRYPTOPP_ASSERT(!m_resultPending);
m_s.ShutDown(SD_SEND);
m_s.CheckAndHandleError("ResetEvent", ResetEvent(m_event));
m_s.CheckAndHandleError_int("WSAEventSelect", WSAEventSelect(m_s, m_event, FD_CLOSE));

View File

@ -94,7 +94,7 @@ public:
{if (result == static_cast<socket_t>(SOCKET_ERROR)) HandleError(operation);}
#ifdef USE_WINDOWS_STYLE_SOCKETS
void CheckAndHandleError(const char *operation, BOOL result) const
{assert(result==TRUE || result==FALSE); if (!result) HandleError(operation);}
{CRYPTOPP_ASSERT(result==TRUE || result==FALSE); if (!result) HandleError(operation);}
void CheckAndHandleError(const char *operation, bool result) const
{if (!result) HandleError(operation);}
#endif
@ -121,7 +121,7 @@ class SocketsInitializer
{
public:
SocketsInitializer() {Socket::StartSockets();}
~SocketsInitializer() {try {Socket::ShutdownSockets();} catch (const Exception&) {assert(0);}}
~SocketsInitializer() {try {Socket::ShutdownSockets();} catch (const Exception&) {CRYPTOPP_ASSERT(0);}}
};
class SocketReceiver : public NetworkReceiver

Some files were not shown because too many files have changed in this diff Show More