refactor: move util::Xor to Obfuscation().Xor

This is meant to focus the usages to narrow the scope of the obfuscation optimization.

`Obfuscation::Xor` is mostly a move.

Co-authored-by: maflcko <6399679+maflcko@users.noreply.github.com>
This commit is contained in:
Lőrincandmaflcko committed 2025-07-16 14:33:07 -07:00
1 parent fa5d296e3b
commit 377aab8e5a
5 files changed
+26 -28

No files matched your search

+2 -22
View File
@@ -11,6 +11,7 @@
#include <span.h>
#include <support/allocators/zeroafterfree.h>
#include <util/check.h>
#include <util/obfuscation.h>
#include <util/overflow.h>
#include <util/syserror.h>
@@ -27,27 +28,6 @@
#include <utility>
#include <vector>
namespace util {
inline void Xor(std::span<std::byte> write, std::span<const std::byte> key, size_t key_offset = 0)
{
if (key.size() == 0) {
return;
}
key_offset %= key.size();
for (size_t i = 0, j = key_offset; i != write.size(); i++) {
write[i] ^= key[j++];
// This potentially acts on very many bytes of data, so it's
// important that we calculate `j`, i.e. the `key` index in this
// way instead of doing a %, which would effectively be a division
// for each byte Xor'd -- much slower than need be.
if (j == key.size())
j = 0;
}
}
} // namespace util
/* Minimal stream for overwriting and/or appending to an existing byte vector
*
* The referenced vector will grow as necessary
@@ -279,7 +259,7 @@ public:
*/
void Xor(const std::vector<unsigned char>& key)
{
util::Xor(MakeWritableByteSpan(*this), MakeByteSpan(key));
Obfuscation().Xor(MakeWritableByteSpan(*this), MakeByteSpan(key));
}
/** Compute total memory usage of this object (own memory + any dynamic memory). */