summaryrefslogtreecommitdiff
path: root/misc.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-05-25 03:41:05 -0400
committerJeffrey Walton <noloader@gmail.com>2019-05-25 03:41:05 -0400
commit92df2a685f55a4777a897f0a921ed06e3e21401a (patch)
tree9593ae19b5d2d0d35337aa07b8b133f23ab40f56 /misc.h
parent1400757fea661d8e7f4a4b73465507054df4870d (diff)
downloadcryptopp-git-92df2a685f55a4777a897f0a921ed06e3e21401a.tar.gz
Clear Valgrind warnings on ARM
I don't believe these should have been findings. They were clear on x86, Aarch64 and PowerPC.
Diffstat (limited to 'misc.h')
-rw-r--r--misc.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/misc.h b/misc.h
index 7a12175f..52ece09c 100644
--- a/misc.h
+++ b/misc.h
@@ -1225,9 +1225,16 @@ 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); CRYPTOPP_ASSERT(size < INT_MAX);
- for (int i=int(size-1), carry=1; i>=0 && carry; i--)
- carry = !++inout[i];
+ unsigned int carry=1;
+ while (carry && size != 0)
+ {
+ // On wrap inout[n] equals 0
+ carry = ! ++inout[size-1];
+ size--;
+ }
+
+ if (carry && size == 0)
+ inout[0]++;
}
/// \brief Performs an addition with carry on a block of bytes