From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mx.groups.io with SMTP id smtpd.web11.23156.1669132573363313932 for ; Tue, 22 Nov 2022 07:56:13 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NQx+9Zwl; spf=pass (domain: gmail.com, ip: 209.85.210.176, mailfrom: pedro.falcato@gmail.com) Received: by mail-pf1-f176.google.com with SMTP id y203so14753063pfb.4 for ; Tue, 22 Nov 2022 07:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=T8jz0YXqQcl+toRd6+C3nwRpBIF0qTvUjwGk3iedtyc=; b=NQx+9ZwlaZNPHm05SCNM3Fg5GSwmO5S6leTiyI8SwgbTBu942DRJdBh9/pQeFKxG8/ iHHBiDcOoRnP5JRvM9EWo2ixQmfHYOqDzT9eTxed1otDhPtg+om7mqfCe698C402pdkf tHbPSf61qaistV1qI0zFpKi8eKAFnpq9GF9LJbvqP8udQYhsSZj0fl/9JXkwQlUUfzGb NECEn3G43clmrsATELpmEajAdjSLQHBUUfZFsykZVcr7xjwVOJjj0WMF19xMSPS6Xa2b 4eyibuFgUiFBaTOocKaUxydNCcrSoWZjfw0vPPGlk0EuqxR2L8br0c/UlT6lMAP9jh2N SMTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=T8jz0YXqQcl+toRd6+C3nwRpBIF0qTvUjwGk3iedtyc=; b=vZzD65qaooCekYx9vURFnEB9RFxpsye937K6kOd0kAUjERWRxmgGeD2deMa6WY95gc dfLyxdCXIAXGrV9CZJeGg1L5l1mTrvIjfJANl0lKDNRwlg5Le6cif7UU3GC+I+Ut/Nde LfGExq8EPKT6NP2rV/KbC4jEUlNPYxR3KDPT5JrAsH6xhpOi8R/xfI5w5n9yZ0S31NOA qhnpnxmRkVqExCXk7DgMfsDiOqYyf7H13Pe4GGElhMqTLq+O5mqGOnGW9qHjk+w06E7M 29bbfWS14srDo9DJyo8wNQVNp/v1NG5gQzO6BbwZE1RAnRQRayfpq/aet0tJ7zuNePTz RbLw== X-Gm-Message-State: ANoB5plwSlx6ouoS1uyt3lGou8xP4amSQYIdI5nm0YFHusLgnKLHvM9E N0+5UtE3YqlWuzk9szY5kr26vSn2THWKojMJk10= X-Google-Smtp-Source: AA0mqf6yNZEdfy7NgvVV2Le3bV5qfVFtJiDh/iCASCqo520y9eDS0fhbHlbwP3i9vXsthJ2J4bc+7FuSMpaIy3+YcnY= X-Received: by 2002:a05:6a00:15d1:b0:572:4ea6:ddc7 with SMTP id o17-20020a056a0015d100b005724ea6ddc7mr4935518pfu.26.1669132572828; Tue, 22 Nov 2022 07:56:12 -0800 (PST) MIME-Version: 1.0 References: <20221122153212.570984-1-pedro.falcato@gmail.com> In-Reply-To: From: "Pedro Falcato" Date: Tue, 22 Nov 2022 15:56:01 +0000 Message-ID: Subject: Re: [PATCH v2 1/1] MdePkg/BaseRngLib: Add a smoketest for RDRAND and check CPUID To: "Jason A. Donenfeld" Cc: devel@edk2.groups.io, Michael D Kinney , Liming Gao , Zhiguang Liu Content-Type: multipart/alternative; boundary="00000000000016284205ee113623" --00000000000016284205ee113623 Content-Type: text/plain; charset="UTF-8" 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 --00000000000016284205ee113623 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Nov 22, 2022 at 3:39 PM Jason A. = Donenfeld <Jason@zx2c4.com> wr= ote:
On Tue, Nov 22, 2022 at 4:32 PM Pedro Falcato <pedro.falcato@gmail.com= > wrote:
> +=C2=A0 // Testing algorithm inspired by linux's arch/x86/kernel/c= pu/rdrand.c:x86_init_rdrand
> +=C2=A0 // as relicensed by the author, Jason Donenfeld, in the EDK2 m= ailing list.
> +=C2=A0 // As is, the algorithm samples rdrand $RDRAND_TEST_SAMPLES ti= mes and expects
> +=C2=A0 // a different result $RDRAND_MIN_CHANGE times for reliable RD= RAND 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.=C2=A0

> +=C2=A0 for (TestIteration =3D 0; TestIteration < RDRAND_TEST_SAMPL= ES; TestIteration++) {
> +=C2=A0 =C2=A0 UINT32=C2=A0 Sample;
> +=C2=A0 =C2=A0 //
> +=C2=A0 =C2=A0 // Note: We use a retry loop for rdrand. Normal users g= et this in BaseRng.c
> +=C2=A0 =C2=A0 // Any failure to get a random number will assume RDRAN= D does not work.
> +=C2=A0 =C2=A0 //
> +=C2=A0 =C2=A0 for (Idx =3D 0; Idx < RDRAND_RETRIES; Idx++) {
> +=C2=A0 =C2=A0 =C2=A0 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".
=C2=A0
Hmm, do you reckon= it makes a difference? I'm not intimately familiar with HWRNG internal= s. Unfortunately there's no AsmRdRandUintn
so this would take= some per-bitness #define's which... yeah, I'd rather not.

Pedro
--00000000000016284205ee113623--