olm/src/memory.cpp

26 lines
550 B
C++
Raw Normal View History

#include "axolotl/memory.hh"
2015-03-03 16:08:56 +01:00
void axolotl::unset(
2015-03-03 16:08:56 +01:00
void volatile * buffer, std::size_t buffer_length
) {
2015-03-03 16:08:56 +01:00
char volatile * pos = reinterpret_cast<char volatile *>(buffer);
char volatile * end = pos + buffer_length;
while (pos != end) {
*(pos++) = 0;
}
}
2015-03-03 16:08:56 +01:00
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;
}