1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768openMirage_crypto_rngletsrc=Logs.Src.create"mirage-crypto-rng.lwt"~doc:"Mirage crypto RNG Lwt"moduleLog=(valLogs.src_logsrc:Logs.LOG)letperiodicfdelta=letopenLwt.InfixinLwt.async(fun()->letrecone()=f();Lwt_unix.sleep(Duration.to_fdelta)>>=oneinone())letgetrandom_taskdeltasource=lettask()=letper_pool=8inletsize=per_pool*poolsNoneinletrandom=Mirage_crypto_rng_unix.getrandomsizeinletidx=ref0inletf()=incridx;Cstruct.subrandom(per_pool*(pred!idx))per_poolinEntropy.feed_poolsNonesourcefinperiodictaskdeltaletrdrand_taskdelta=lettask()=Entropy.cpu_rngNoneinperiodictaskdeltaletrunning=reffalseletgetrandom_initi=letdata=Mirage_crypto_rng_unix.getrandom128inEntropy.headeridataletinitialize?(sleep=Duration.of_sec1)()=if!runningthenLog.debug(funm->m"Mirage_crypto_rng_lwt.initialize has already been called, \
ignoring this call.")elsebegin(trylet_=default_generator()inLog.warn(funm->m"Mirage_crypto_rng.default_generator has already \
been set (but not via \
Mirage_crypto_rng_lwt.initialize). Please check \
that this is intentional");withNo_default_generator->());running:=true;letseed=letinit=Entropy.[bootstrap;whirlwind_bootstrap;bootstrap;getrandom_init]inList.mapi(funif->fi)init|>Cstruct.concatinletrng=create~seed~time:Mtime_clock.elapsed_ns(moduleFortuna)inset_default_generatorrng;rdrand_tasksleep;letsource=Entropy.register_source"getrandom"ingetrandom_task(Int64.mulsleep10L)source;let_=Lwt_main.Enter_iter_hooks.add_first(Entropy.timer_accumulatorNone)in()end