Hi Pedro, Pointers to external content that were used to create the code change can be captured in the BZ and the commit message. Thanks, Mike From: devel@edk2.groups.io On Behalf Of Pedro Falcato Sent: Tuesday, November 22, 2022 7:56 AM To: Jason A. Donenfeld Cc: devel@edk2.groups.io; Kinney, Michael D ; Gao, Liming ; Liu, Zhiguang Subject: Re: [edk2-devel] [PATCH v2 1/1] MdePkg/BaseRngLib: Add a smoketest for RDRAND and check CPUID On Tue, Nov 22, 2022 at 3:39 PM Jason A. Donenfeld > wrote: On Tue, Nov 22, 2022 at 4:32 PM Pedro Falcato > wrote: > + // Testing algorithm inspired by linux's arch/x86/kernel/cpu/rdrand.c:x86_init_rdrand > + // as relicensed by the author, Jason Donenfeld, in the EDK2 mailing list. > + // As is, the algorithm samples rdrand $RDRAND_TEST_SAMPLES times and expects > + // a different result $RDRAND_MIN_CHANGE times for reliable RDRAND usage. You don't need to pepper my name all over the source. :) I just wanted to properly credit you :) If you're not okay with it I can remove it in a v3. > + for (TestIteration = 0; TestIteration < RDRAND_TEST_SAMPLES; TestIteration++) { > + UINT32 Sample; > + // > + // Note: We use a retry loop for rdrand. Normal users get this in BaseRng.c > + // Any failure to get a random number will assume RDRAND does not work. > + // > + for (Idx = 0; Idx < RDRAND_RETRIES; Idx++) { > + if (AsmRdRand32 (&Sample)) { The linux code will use a 64bit value on 64bit machines. I suggest you do the same here -- use native word size. I think EFI calls this a "UINTN". Hmm, do you reckon it makes a difference? I'm not intimately familiar with HWRNG internals. Unfortunately there's no AsmRdRandUintn so this would take some per-bitness #define's which... yeah, I'd rather not. Pedro