aboutsummaryrefslogtreecommitdiff
path: root/src/memory.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-03-03 15:08:56 +0000
committerMark Haines <mark.haines@matrix.org>2015-03-03 15:08:56 +0000
commit8123ce62094bf88a4107506d7acd3e8e2866bc1f (patch)
treee7c4284ffbe620deebefc6c1a2db7d77c880553a /src/memory.cpp
parent2f2e0340ae46fb37421e13108fae71e710b5515b (diff)
Constant time comparison for mac
Diffstat (limited to 'src/memory.cpp')
-rw-r--r--src/memory.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/memory.cpp b/src/memory.cpp
index 14c95dd..07e8de2 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -1,11 +1,25 @@
#include "axolotl/memory.hh"
+
void axolotl::unset(
- volatile void * buffer, std::size_t buffer_length
+ void volatile * buffer, std::size_t buffer_length
) {
- volatile char * pos = reinterpret_cast<volatile char *>(buffer);
- volatile char * end = pos + buffer_length;
+ char volatile * pos = reinterpret_cast<char volatile *>(buffer);
+ char volatile * end = pos + buffer_length;
while (pos != end) {
*(pos++) = 0;
}
}
+
+
+bool axolotl::is_equal(
+ std::uint8_t const * buffer_a,
+ std::uint8_t const * buffer_b,
+ std::size_t length
+) {
+ std::uint8_t volatile result = 0;
+ while (length--) {
+ result |= (*(buffer_a++)) ^ (*(buffer_b++));
+ }
+ return result == 0;
+}