diff --git a/src/pal/pal_open_enclave.h b/src/pal/pal_open_enclave.h index a9d926c..bbc1096 100644 --- a/src/pal/pal_open_enclave.h +++ b/src/pal/pal_open_enclave.h @@ -7,6 +7,7 @@ #include #ifdef OPEN_ENCLAVE extern "C" void* oe_memset_s(void* p, size_t p_size, int c, size_t size); +extern "C" int oe_random(void* data, size_t size); extern "C" [[noreturn]] void oe_abort(); namespace snmalloc @@ -37,7 +38,7 @@ namespace snmalloc * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. */ - static constexpr uint64_t pal_features = 0; + static constexpr uint64_t pal_features = Entropy; static constexpr size_t page_size = Aal::smallest_page_size; @@ -66,6 +67,17 @@ namespace snmalloc { oe_memset_s(p, size, 0, size); } + + /** + * Source of Entropy + */ + static uint64_t get_entropy64() + { + uint64_t result = 0; + if (oe_random(&result, sizeof(result)) != 0) + error("Failed to get system randomness"); + return result; + } }; } #endif diff --git a/src/test/func/fixed_region/fixed_region.cc b/src/test/func/fixed_region/fixed_region.cc index 87b6479..7e77d4b 100644 --- a/src/test/func/fixed_region/fixed_region.cc +++ b/src/test/func/fixed_region/fixed_region.cc @@ -15,6 +15,14 @@ extern "C" void* oe_memset_s(void* p, size_t p_size, int c, size_t size) return memset(p, c, size); } +extern "C" int oe_random(void* p, size_t p_size) +{ + UNUSED(p_size); + UNUSED(p); + // Stub for random data. + return 0; +} + extern "C" void oe_abort() { abort(); diff --git a/src/test/func/two_alloc_types/main.cc b/src/test/func/two_alloc_types/main.cc index 6996f3d..82a0328 100644 --- a/src/test/func/two_alloc_types/main.cc +++ b/src/test/func/two_alloc_types/main.cc @@ -11,6 +11,14 @@ extern "C" void* oe_memset_s(void* p, size_t p_size, int c, size_t size) return memset(p, c, size); } +extern "C" int oe_random(void* p, size_t p_size) +{ + UNUSED(p_size); + UNUSED(p); + // Stub for random data. + return 0; +} + extern "C" void oe_abort() { abort();