MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_random_init_ex

Function mi_random_init_ex

3rd/mimalloc-2.0.9/src/random.c:323–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321}
322
323static void mi_random_init_ex(mi_random_ctx_t* ctx, bool use_weak) {
324 uint8_t key[32];
325 if (use_weak || !os_random_buf(key, sizeof(key))) {
326 // if we fail to get random data from the OS, we fall back to a
327 // weak random source based on the current time
328 #if !defined(__wasi__)
329 if (!use_weak) { _mi_warning_message("unable to use secure randomness\n"); }
330 #endif
331 uintptr_t x = _mi_os_random_weak(0);
332 for (size_t i = 0; i < 8; i++) { // key is eight 32-bit words.
333 x = _mi_random_shuffle(x);
334 ((uint32_t*)key)[i] = (uint32_t)x;
335 }
336 ctx->weak = true;
337 }
338 else {
339 ctx->weak = false;
340 }
341 chacha_init(ctx, key, (uintptr_t)ctx /*nonce*/ );
342}
343
344void _mi_random_init(mi_random_ctx_t* ctx) {
345 mi_random_init_ex(ctx, false);

Callers 2

_mi_random_initFunction · 0.85
_mi_random_init_weakFunction · 0.85

Calls 5

os_random_bufFunction · 0.85
_mi_warning_messageFunction · 0.85
_mi_os_random_weakFunction · 0.85
_mi_random_shuffleFunction · 0.85
chacha_initFunction · 0.85

Tested by

no test coverage detected