From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 9FD1B9414C4 for ; Thu, 15 Feb 2024 11:49:00 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=r9UXWgQO1ycsBjQCc2K1jZiNKfwrTWivJjnMjaFKWKA=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1707997739; v=1; b=gtJU2OHcaMueA2MIIdEUz1NegkvJ0mRUN8WfGmgNfHKqmtCIDDWP4kIYZxNHW50po3F5qgKg F6AqEnpdpxc+MAxx8Ub+eqOUDbJYmbB0CIDjMckaD0OzEPB1VPmlM62eLlakoe7xwVZ37sCKF7v mfJV4+wFwp2npBURyhI3pL58= X-Received: by 127.0.0.2 with SMTP id laCYYY7687511xg7lggHZnm8; Thu, 15 Feb 2024 03:48:59 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.12218.1707997738599136733 for ; Thu, 15 Feb 2024 03:48:58 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-ir_wDIdHN26MjzV-uYew_g-1; Thu, 15 Feb 2024 06:48:54 -0500 X-MC-Unique: ir_wDIdHN26MjzV-uYew_g-1 X-Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 77081848943; Thu, 15 Feb 2024 11:48:54 +0000 (UTC) X-Received: from [10.39.192.112] (unknown [10.39.192.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 102DC112131D; Thu, 15 Feb 2024 11:48:53 +0000 (UTC) Message-ID: <9db8ea7f-1d7d-3558-19e5-dbda730872ac@redhat.com> Date: Thu, 15 Feb 2024 12:48:52 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] The API in BaseCryptLib can't seed the pseudorandom number generator properly To: eddie wang , devel@edk2.groups.io References: <08efe7f7-b7d2-a806-39da-b3ebadd45ec4@redhat.com> From: "Laszlo Ersek" In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: mRRfyVwCYJb75mI7t4gSN6nXx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=gtJU2OHc; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 2/15/24 12:09, eddie wang wrote: > Hi Laszlo, > Thanks for your reply. How can I enable the DEBUGs at RandomSeed() ? Or > any suggesting information that I can provide? Sorry, upon a closer look, I see you had already narrowed it down to RAND_seed() and RAND_status(), which are direct OpenSSL APIs. So my suggestion would amount to adding DEBUGs to OpenSSL, such as to RAND_seed() in "CryptoPkg/Library/OpensslLib/openssl/crypto/rand/rand_lib.c". But, I think you may be able to do just that. "CryptoPkg/Library/Include/CrtLibSupport.h" already includes , and DebugLib is listed under [LibraryClasses] in each instance of OpensslLib. So if you modify your "CryptoPkg/Library/OpensslLib/openssl" submodule directory tree locally, with the following patch: | diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c | index 0fcf4fe3bc1e..e5f105268f52 100644 | --- a/crypto/rand/rand_lib.c | +++ b/crypto/rand/rand_lib.c | @@ -257,6 +257,8 @@ void RAND_seed(const void *buf, int num) | drbg = RAND_get0_primary(NULL); | if (drbg != NULL && num > 0) | EVP_RAND_reseed(drbg, 0, NULL, 0, buf, num); | + | + DEBUG ((DEBUG_INFO, "%a: hello\n", __func__)); | } | | void RAND_add(const void *buf, int num, double randomness) then you should get usable debug messages -- at least it builds for me. Inserting DEBUGs like this (over multiple rounds of testing / narrowing) should lead you to the exact location that is responsible for the initialization failure. You mention you have encountered the problem with a UEFI application. That is relevant for choosing your DebugLib instance. If you already have a function DebugLib instance for your platform (logging to the serial port, for example), then just use that. Otherwise, consider building your UEFI application with a module scope override in the DSC file, one that resolves DebugLib to MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf or MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf These will send DEBUG messages to the UEFI console or standard error devices, respectively. hth Laszlo > Laszlo Ersek > 於 2024年2月 > 8日 週四 上午5:03寫道: > > On 2/6/24 08:00, eddie wang wrote: > > Hi all, > > We had an UEFI application that used the EDK2(2023/12/05), and we > would > > like to take advantage of the services in BaseCryptLib .However, > the API > > in CryptPkg "*RandomSeed()*"(X64, in CryptRandTsc.c) always returned > > false because of the pseudorandom number generator set up failed. > I am > > not sure this issue is from the *openssl configuration in > OpensslLib(we > > use the default configuration)* or is from the *openssl 3.0.9*. > > > > Is there any comments about this issue? > > Can you narrow it down by inserting DEBUGs starting at RandomSeed() > [CryptoPkg/Library/BaseCryptLib/Rand/CryptRandTsc.c], and then digging > down as necessary? > > Laszlo > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115521): https://edk2.groups.io/g/devel/message/115521 Mute This Topic: https://groups.io/mt/104198931/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-