Clear Coverity findings CID 186951, 186950, 186947

Coverity does not realize xorBlocks is always non-NULL when BT_XorInput is set
This commit is contained in:
Jeffrey Walton 2018-01-19 19:42:03 -05:00
parent 5c5d3e4c26
commit e4e1fbe0ed
No known key found for this signature in database
GPG Key ID: B36AB348921B1838

View File

@ -54,6 +54,8 @@
ANONYMOUS_NAMESPACE_BEGIN
using CryptoPP::byte;
using CryptoPP::word32;
using CryptoPP::BlockTransformation;
CRYPTOPP_CONSTANT(BT_XorInput = BlockTransformation::BT_XorInput)
@ -62,6 +64,18 @@ CRYPTOPP_CONSTANT(BT_InBlockIsCounter = BlockTransformation::BT_InBlockIsCounter
CRYPTOPP_CONSTANT(BT_ReverseDirection = BlockTransformation::BT_ReverseDirection)
CRYPTOPP_CONSTANT(BT_DontIncrementInOutPointers = BlockTransformation::BT_DontIncrementInOutPointers)
// Coverity finding on xorBlocks. While not obvious, xorBlocks is
// always non-NULL when BT_XorInput is set. All callers follow the
// convention. Also see https://stackoverflow.com/q/33719379/608639.
inline word32 XorBlocksToFlags(const byte* xorBlocks, word32 flags)
{
#if defined(__COVERITY__)
return xorBlocks ? (flags) : (flags &= ~BT_XorInput);
#else
return CRYPTOPP_UNUSED(xorBlocks), flags;
#endif
}
ANONYMOUS_NAMESPACE_END
// *************************** ARM NEON ************************** //
@ -109,6 +123,7 @@ inline size_t AdvancedProcessBlocks64_6x2_NEON(F2 func2, F6 func6,
ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : neonBlockSize;
ptrdiff_t xorIncrement = xorBlocks ? neonBlockSize : 0;
ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : neonBlockSize;
flags = XorBlocksToFlags(xorBlocks, flags); // Coverity hack
if (flags & BT_ReverseDirection)
{
@ -337,6 +352,7 @@ size_t AdvancedProcessBlocks128_NEON1x6(F1 func1, F6 func6,
ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize;
ptrdiff_t xorIncrement = xorBlocks ? blockSize : 0;
ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize;
flags = XorBlocksToFlags(xorBlocks, flags); // Coverity hack
if (flags & BT_ReverseDirection)
{
@ -476,6 +492,7 @@ size_t AdvancedProcessBlocks128_6x2_NEON(F2 func2, F6 func6,
ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize;
ptrdiff_t xorIncrement = xorBlocks ? blockSize : 0;
ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize;
flags = XorBlocksToFlags(xorBlocks, flags); // Coverity hack
if (flags & BT_ReverseDirection)
{
@ -711,6 +728,7 @@ inline size_t GCC_NO_UBSAN AdvancedProcessBlocks64_6x2_SSE(F2 func2, F6 func6,
ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : xmmBlockSize;
ptrdiff_t xorIncrement = xorBlocks ? xmmBlockSize : 0;
ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : xmmBlockSize;
flags = XorBlocksToFlags(xorBlocks, flags); // Coverity hack
if (flags & BT_ReverseDirection)
{
@ -765,8 +783,6 @@ inline size_t GCC_NO_UBSAN AdvancedProcessBlocks64_6x2_SSE(F2 func2, F6 func6,
if (flags & BT_XorInput)
{
// Coverity finding, appears to be false positive. Assert the condition.
CRYPTOPP_ASSERT(xorBlocks);
block0 = _mm_xor_si128(block0, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
xorBlocks += xorIncrement;
block1 = _mm_xor_si128(block1, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
@ -844,8 +860,6 @@ inline size_t GCC_NO_UBSAN AdvancedProcessBlocks64_6x2_SSE(F2 func2, F6 func6,
if (flags & BT_XorInput)
{
// Coverity finding, appears to be false positive. Assert the condition.
CRYPTOPP_ASSERT(xorBlocks);
block0 = _mm_xor_si128(block0, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
xorBlocks += xorIncrement;
block1 = _mm_xor_si128(block1, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
@ -945,6 +959,7 @@ inline size_t AdvancedProcessBlocks128_6x2_SSE(F2 func2, F6 func6,
ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize;
ptrdiff_t xorIncrement = xorBlocks ? blockSize : 0;
ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize;
flags = XorBlocksToFlags(xorBlocks, flags); // Coverity hack
if (flags & BT_ReverseDirection)
{
@ -990,8 +1005,6 @@ inline size_t AdvancedProcessBlocks128_6x2_SSE(F2 func2, F6 func6,
if (flags & BT_XorInput)
{
// Coverity finding, appears to be false positive. Assert the condition.
CRYPTOPP_ASSERT(xorBlocks);
block0 = _mm_xor_si128(block0, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
xorBlocks += xorIncrement;
block1 = _mm_xor_si128(block1, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
@ -1060,8 +1073,6 @@ inline size_t AdvancedProcessBlocks128_6x2_SSE(F2 func2, F6 func6,
if (flags & BT_XorInput)
{
// Coverity finding, appears to be false positive. Assert the condition.
CRYPTOPP_ASSERT(xorBlocks);
block0 = _mm_xor_si128(block0, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
xorBlocks += xorIncrement;
block1 = _mm_xor_si128(block1, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
@ -1130,6 +1141,7 @@ inline size_t AdvancedProcessBlocks128_4x1_SSE(F1 func1, F4 func4,
ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize;
ptrdiff_t xorIncrement = xorBlocks ? blockSize : 0;
ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize;
flags = XorBlocksToFlags(xorBlocks, flags); // Coverity hack
if (flags & BT_ReverseDirection)
{
@ -1169,8 +1181,6 @@ inline size_t AdvancedProcessBlocks128_4x1_SSE(F1 func1, F4 func4,
if (flags & BT_XorInput)
{
// Coverity finding, appears to be false positive. Assert the condition.
CRYPTOPP_ASSERT(xorBlocks);
block0 = _mm_xor_si128(block0, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
xorBlocks += xorIncrement;
block1 = _mm_xor_si128(block1, _mm_loadu_si128(CONST_M128_CAST(xorBlocks)));
@ -1271,12 +1281,13 @@ size_t AdvancedProcessBlocks128_6x1_ALTIVEC(F1 func1, F6 func6, const word32 *su
ptrdiff_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize;
ptrdiff_t xorIncrement = xorBlocks ? blockSize : 0;
ptrdiff_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize;
flags = XorBlocksToFlags(xorBlocks, flags); // Coverity hack
if (flags & BT_ReverseDirection)
{
inBlocks += length - blockSize;
xorBlocks += length - blockSize;
outBlocks += length - blockSize;
inBlocks += static_cast<ptrdiff_t>(length) - blockSize;
xorBlocks += static_cast<ptrdiff_t>(length) - blockSize;
outBlocks += static_cast<ptrdiff_t>(length) - blockSize;
inIncrement = 0-inIncrement;
xorIncrement = 0-xorIncrement;
outIncrement = 0-outIncrement;