Skip to content

Commit ea65f36

Browse files
committed
obfuscate also length and offset
1 parent a208909 commit ea65f36

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

csrc/obfuscate.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,25 @@ void ObfuscatedHexDigest::allocate(std::size_t size, std::mt19937& rng) {
6666
if (size > PAGE_SIZE / 2) {
6767
throw std::runtime_error("target size too big");
6868
}
69-
if (Len != 0 || Offset != 0) {
69+
if (this->size() != 0) {
7070
throw std::runtime_error("already allocated");
7171
}
7272

7373
fill_random_hex(page_ptr(), PAGE_SIZE, rng);
74-
const std::size_t max_offset = PAGE_SIZE - size - 1;
75-
std::uniform_int_distribution<std::size_t> offset_dist(0, max_offset);
74+
const std::uintptr_t max_offset = PAGE_SIZE - size - 1;
75+
std::uniform_int_distribution<std::uintptr_t> offset_dist(0, max_offset);
7676

77-
Offset = offset_dist(rng);
78-
Len = size;
77+
const std::uintptr_t offset = offset_dist(rng);
78+
HashedOffset = slow_hash(offset);
79+
HashedLen = slow_hash(size ^ offset);
7980
}
8081

8182
char* ObfuscatedHexDigest::data() {
82-
return reinterpret_cast<char*>(page_ptr()) + Offset;
83+
return reinterpret_cast<char*>(page_ptr()) + slow_unhash(HashedOffset);
84+
}
85+
86+
std::size_t ObfuscatedHexDigest::size() const {
87+
return slow_unhash(HashedLen ^ slow_unhash(HashedOffset));
8388
}
8489

8590
void fill_random_hex(void* target, std::size_t size, std::mt19937& rng) {

csrc/obfuscate.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ class ObfuscatedHexDigest : ProtectablePage {
3535

3636
char* data();
3737

38-
[[nodiscard]] std::size_t size() const {
39-
return Len;
40-
}
38+
[[nodiscard]] std::size_t size() const;
39+
4140
private:
42-
std::size_t Len = 0;
43-
std::size_t Offset = 0;
41+
std::uintptr_t HashedLen = 0;
42+
std::uintptr_t HashedOffset = 0;
4443
};
4544

4645
void fill_random_hex(void* target, std::size_t size, std::mt19937& rng);

0 commit comments

Comments
 (0)