summaryrefslogtreecommitdiff
path: root/misc.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-05-25 19:49:49 -0400
committerJeffrey Walton <noloader@gmail.com>2019-05-25 19:49:49 -0400
commit9a3c1e351dceffaac780c27d2120754f89164a51 (patch)
tree25c27c5ee51438f892e29b40960b8f90c36a4670 /misc.h
parentca11105a40d0ddb38bc48e0dbf23e09184b39e43 (diff)
downloadcryptopp-git-9a3c1e351dceffaac780c27d2120754f89164a51.tar.gz
Clear Valgrind finding in IncrementCounterByOne
The single buffer IncrementCounterByOne generated a Valgrind finding on ARM. This commit uses the same pattern for both overloads in case Valgrind wants to fire on the two-buffer version.
Diffstat (limited to 'misc.h')
-rw-r--r--misc.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/misc.h b/misc.h
index d836aaa2..2cdabfbe 100644
--- a/misc.h
+++ b/misc.h
@@ -1225,10 +1225,12 @@ 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)
{
+ CRYPTOPP_ASSERT(inout != NULLPTR);
+
unsigned int carry=1;
while (carry && size != 0)
{
- // On wrap inout[n] equals 0
+ // On carry inout[n] equals 0
carry = ! ++inout[size-1];
size--;
}
@@ -1243,12 +1245,22 @@ inline void IncrementCounterByOne(byte *inout, unsigned int size)
/// \details The function is 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)
{
- CRYPTOPP_ASSERT(output != NULLPTR); CRYPTOPP_ASSERT(input != NULLPTR); CRYPTOPP_ASSERT(size < INT_MAX);
+ CRYPTOPP_ASSERT(output != NULLPTR);
+ CRYPTOPP_ASSERT(input != NULLPTR);
+
+ unsigned int carry=1;
+ while (carry && size != 0)
+ {
+ // On carry output[n] equals 0
+ carry = ! (output[size-1] = input[size-1] + 1);
+ size--;
+ }
- int i, carry;
- for (i=int(size-1), carry=1; i>=0 && carry; i--)
- carry = ((output[i] = input[i]+1) == 0);
- memcpy_s(output, size, input, size_t(i)+1);
+ while (size != 0)
+ {
+ output[size-1] = input[size-1];
+ size--;
+ }
}
/// \brief Performs a branchless swap of values a and b if condition c is true