From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.22689.1669131552695710740 for ; Tue, 22 Nov 2022 07:39:12 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=Ck5BBJcK; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: srs0=2rl2=3w=zx2c4.com=jason@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B034461751 for ; Tue, 22 Nov 2022 15:39:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0EE3C433C1 for ; Tue, 22 Nov 2022 15:39:10 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Ck5BBJcK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1669131548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fcrypuWBsR2Swk98k5o7o2NHwmAMis9lOLl5P+As8Vg=; b=Ck5BBJcKmwz0+ZMk+ij3i0naitYT0RAQmZ9yX1RIhwSMQ38r4UNGVLc9g0jyRjahMc7xKu rzWn5iMlO/8fV2DY7yc4ZGMM1zYWpb/D9VqnupyXnVam77csGOSyxrpWQblm+jswKxRuf4 c9ZlrhdlIuyhCKyRcdmQNymxTyJGpVs= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id e546cc22 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 22 Nov 2022 15:39:08 +0000 (UTC) Received: by mail-vs1-f41.google.com with SMTP id 128so14799680vsz.12 for ; Tue, 22 Nov 2022 07:39:08 -0800 (PST) X-Gm-Message-State: ANoB5pmepXxE5iBtS9kkYL0acLL8DUVaEz58tLDNeITh9EbUcN4yk8Pz cqZaPNQzI7r4BJ9zaeDGDOp7S7YLSQe/TOvgt7Y= X-Google-Smtp-Source: AA0mqf5cVvZdX0a1dhr1yyD7tO+cy+m0s6FDoynVtfMYPXedUhNsVn92eQCEF3JVX7wHxZSiZJTNTk11n+/65nPHX+g= X-Received: by 2002:a05:6102:3fab:b0:3b0:5751:1840 with SMTP id o43-20020a0561023fab00b003b057511840mr4511713vsv.21.1669131548307; Tue, 22 Nov 2022 07:39:08 -0800 (PST) MIME-Version: 1.0 References: <20221122153212.570984-1-pedro.falcato@gmail.com> In-Reply-To: <20221122153212.570984-1-pedro.falcato@gmail.com> From: "Jason A. Donenfeld" Date: Tue, 22 Nov 2022 16:38:57 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/1] MdePkg/BaseRngLib: Add a smoketest for RDRAND and check CPUID To: Pedro Falcato Cc: devel@edk2.groups.io, Michael D Kinney , Liming Gao , Zhiguang Liu Content-Type: text/plain; charset="UTF-8" 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. :) > + 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". Jason