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 7E695941539 for ; Tue, 21 Nov 2023 08:49:08 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=PKxk2H3D9tlzBNtRPc9IoMiPX6kHpZfYLizzMYyzLqY=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: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=1700556547; v=1; b=FH6TNr8viNdCmtXdsAw+vVLt3HsGFViuC9wQZ9QoYwSiFBY0LDZKDCDqoGsIVrY5rw7p/k/1 cZlbLfKq2FlhfvWDSlSydTS0pZDNaRT/lHDkyfiFasHCrUI0H/AjK2P961sSnvjAbecZ6l8lP+M SwsVfG65nEHDXAqF7Fi1K/x0= X-Received: by 127.0.0.2 with SMTP id vzl3YY7687511xZuG9Mre9JU; Tue, 21 Nov 2023 00:49:07 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.34300.1700556546408536768 for ; Tue, 21 Nov 2023 00:49:06 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C0AF01A32; Tue, 21 Nov 2023 00:49:52 -0800 (PST) X-Received: from [10.34.100.114] (e126645.nice.arm.com [10.34.100.114]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E13643F73F; Tue, 21 Nov 2023 00:49:04 -0800 (PST) Message-ID: <999c8c28-0ee8-4a05-aff6-3c774327e172@arm.com> Date: Tue, 21 Nov 2023 09:49:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [PATCH v4 5/6] CryptoPkg/OpensslLib: Add AArch64Cap for arch specific hooks To: Leif Lindholm Cc: devel@edk2.groups.io, Jiewen Yao , Yi Li , Xiaoyu Lu , Guomin Jiang , Ard Biesheuvel , Sami Mujawar , Gerd Hoffmann References: <20231120134826.1288260-1-pierre.gondois@arm.com> <20231120134826.1288260-6-pierre.gondois@arm.com> From: "PierreGondois" In-Reply-To: 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,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: UTLEukQdWBYLF0pID5DvRgSKx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=FH6TNr8v; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.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 11/20/23 19:39, Leif Lindholm wrote: > On Mon, Nov 20, 2023 at 14:48:25 +0100, Pierre Gondois wrote: >> Add AARCH64 specific implementations of: >> - OPENSSL_cpuid_setup(), probing hardware capabilitie >> (presence of FEAT_AES, etc.) >> - OPENSSL_rdtsc(), returning non-trusted entropy by accessing >> system counter. >> >> Acked-by: Gerd Hoffmann >> Signed-off-by: Pierre Gondois >> --- >> .../Library/OpensslLib/OpensslLibAccel.inf | 7 ++ >> .../OpensslLib/OpensslLibFullAccel.inf | 7 ++ >> .../OpensslLib/OpensslStub/AArch64Cap.c | 84 +++++++++++++++++++ >> 3 files changed, 98 insertions(+) >> create mode 100644 CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap= .c >> >> diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf b/CryptoPk= g/Library/OpensslLib/OpensslLibAccel.inf >> index 3d1a9638b1c1..08e8be6ea9e1 100644 >> --- a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf >> +++ b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf >> @@ -1329,6 +1329,7 @@ [Sources.X64] >> # Autogenerated files list ends here >> =20 >> [Sources.AARCH64] >> + OpensslStub/AArch64Cap.c >> # Autogenerated files list starts here >> $(OPENSSL_PATH)/crypto/aes/aes_cbc.c >> $(OPENSSL_PATH)/crypto/aes/aes_cfb.c >> @@ -1955,11 +1956,17 @@ [Packages] >> MdePkg/MdePkg.dec >> CryptoPkg/CryptoPkg.dec >> =20 >> +[Packages.AARCH64] >> + ArmPkg/ArmPkg.dec >> + >> [LibraryClasses] >> BaseLib >> DebugLib >> RngLib >> =20 >> +[LibraryClasses.AARCH64] >> + ArmLib >> + >> [BuildOptions] >> # >> # Disables the following Visual Studio compiler warnings brought by = openssl source, >> diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf b/Cryp= toPkg/Library/OpensslLib/OpensslLibFullAccel.inf >> index e7e83d419f4b..2a01ffe06bd7 100644 >> --- a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf >> +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf >> @@ -1432,6 +1432,7 @@ [Sources.X64] >> # Autogenerated files list ends here >> =20 >> [Sources.AARCH64] >> + OpensslStub/AArch64Cap.c >> # Autogenerated files list starts here >> $(OPENSSL_PATH)/crypto/aes/aes_cbc.c >> $(OPENSSL_PATH)/crypto/aes/aes_cfb.c >> @@ -2107,11 +2108,17 @@ [Packages] >> MdePkg/MdePkg.dec >> CryptoPkg/CryptoPkg.dec >> =20 >> +[Packages.AARCH64] >> + ArmPkg/ArmPkg.dec >> + >> [LibraryClasses] >> BaseLib >> DebugLib >> RngLib >> =20 >> +[LibraryClasses.AARCH64] >> + ArmLib >> + >> [BuildOptions] >> # >> # Disables the following Visual Studio compiler warnings brought by = openssl source, >> diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c b/Cry= ptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c >> new file mode 100644 >> index 000000000000..7468ef3ab54e >> --- /dev/null >> +++ b/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c >> @@ -0,0 +1,84 @@ >> +/** @file >> + Arm capabilities probing. >> + >> + Copyright (c) 2023, Arm Limited. All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> +**/ >> + >> +#include >> +#include "crypto/arm_arch.h" >> + >> +#include >> + >> +/** Get bits from a value. >> + >> + Shift the input value from 'shift' bits and apply 'mask'. >> + >> + @param value The value to get the bits from. >> + @param shift Index of the bits to read. >> + @param mask Mask to apply to the value once shifted. >> + >> + @return The desired bitfield from the value. >> +**/ >> +#define GET_BITFIELD(value, shift, mask) \ >> + ((value >> shift) & mask) >=20 > (This macro appears unused here now.) >=20 >> + >> +UINT32 OPENSSL_armcap_P =3D 0; >> + >> +void >> +OPENSSL_cpuid_setup ( >> + void >> + ) >> +{ >> + OPENSSL_armcap_P =3D 0; >> + >> + /* Access to EL0 registers is possible from higher ELx. */ >> + OPENSSL_armcap_P |=3D ARMV8_CPUID; >> + /* Access to Physical timer is possible. */ >> + OPENSSL_armcap_P |=3D ARMV7_TICK; >> + >> + /* Neon support is not guaranteed, but it is assumed to be present. >> + Arm ARM for Armv8, sA1.5 Advanced SIMD and floating-point support >> + */ >> + OPENSSL_armcap_P |=3D ARMV7_NEON; >> + >> + if (ArmHasAes ()) >> + { >=20 > And I think that curly bracket is supposed to be on the previous line > (and similarly below), but this may be intional to align with nearby > code? I think it was changed by uncrustify. I changed it back. Thanks for the review, Regards, Pierre >=20 > Anyway, this is a big readability improvement, thank you very much! > Acked-by: Leif Lindholm >=20 > / > Leif >=20 >> + OPENSSL_armcap_P |=3D ARMV8_AES; >> + } >> + >> + if (ArmHasSha1 ()) >> + { >> + OPENSSL_armcap_P |=3D ARMV8_SHA1; >> + } >> + >> + if (ArmHasSha256 ()) >> + { >> + OPENSSL_armcap_P |=3D ARMV8_SHA256; >> + } >> + >> + if (ArmHasPmull ()) >> + { >> + OPENSSL_armcap_P |=3D ARMV8_PMULL; >> + } >> + >> + if (ArmHasSha512 ()) >> + { >> + OPENSSL_armcap_P |=3D ARMV8_SHA512; >> + } >> +} >> + >> +/** Read system counter value. >> + >> + Used to get some non-trusted entropy. >> + >> + @return Lower bits of the physical counter. >> +**/ >> +uint32_t >> +OPENSSL_rdtsc ( >> + void >> + ) >> +{ >> + return (UINT32)ArmReadCntPct (); >> +} >> --=20 >> 2.25.1 >> -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111540): https://edk2.groups.io/g/devel/message/111540 Mute This Topic: https://groups.io/mt/102707267/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-