From nobody Fri May 17 12:14:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90891+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90891+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530072; cv=none; d=zohomail.com; s=zohoarc; b=kQFxkW+beGj6lT/vbfdIuJp0AMMrtuWdLTdpuVEbMY1dpcOB1RAvpgpaavPfVGLtLUfLM2hu6M1ht/ZmrhV+ADYwzbxw09tkUR1bqwMUncL/UsNMfiO4oRax8Vk3UhDH3Ykq3fISCBbRSqvD2ttVbbAuBIteL5gZCvieHQWV1ts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530072; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=y2eTErBlFhu932ht10JEb0S+XQCMirn8YzOH53ixB0E=; b=A7MTZZtfmqSHzZMzXWLnMsIk9iGjd83/Ey1rMP8HwfnATA9JWy3bBoDVaaKzKAfq9j+6+2jPtIXHoAC6xH3BjvpBBai9kHmixXtFBZZAlEDHjnl9BczMp3S1Rm3pE0FO6v3THFvl21F4D5JuSawItTr9v3zZN/X4Eh8/eQzkSyw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90891+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656530072305896.3710479556288; Wed, 29 Jun 2022 12:14:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id I1FEYY1788612xBv9xgVbp9h; Wed, 29 Jun 2022 12:14:32 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.15640.1656530071033673988 for ; Wed, 29 Jun 2022 12:14:31 -0700 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 EB9C214BF; Wed, 29 Jun 2022 12:14:30 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 18B233F792; Wed, 29 Jun 2022 12:14:28 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Edward Pickup Subject: [edk2-devel] [PATCH RESEND v1 1/7] ArmPkg: Update Armpkg.ci.yaml Date: Wed, 29 Jun 2022 21:13:49 +0200 Message-Id: <20220629191355.2618844-2-Pierre.Gondois@arm.com> In-Reply-To: <20220629191355.2618844-1-Pierre.Gondois@arm.com> References: <20220629191355.2618844-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: T61cjjogbgZKgq8VFaLdeaf3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530072; bh=AUYS8zIH35tkzM5vaGZ6lKt6TnCvLEXe1ABmknFKxBg=; h=Cc:Date:From:Reply-To:Subject:To; b=iQySdVNxf3TG8vF1NwVlOVHlCXhLLXYCkfMbZjL9+ZNQHPgxV8PsiLmXujvps4jUQfM jaIn0XsPtQvhAbF9YNN4FIg9zlDhustVrRsNs77XkVONMEr+1O1xGHAVZe3IpVmFkRJIb 6etAacOv7ZwaPPsCdxT/61RPeNYkVCy87WY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530074124100005 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add word to the exception list for the spell check tool. Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ArmPkg/ArmPkg.ci.yaml b/ArmPkg/ArmPkg.ci.yaml index b7e07aaef675..ac50c30519f9 100644 --- a/ArmPkg/ArmPkg.ci.yaml +++ b/ArmPkg/ArmPkg.ci.yaml @@ -97,6 +97,7 @@ "ackintid", "actlr", "aeabi", + "aesimc", "asedis", "ashldi", "ashrdi", --=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 (#90891): https://edk2.groups.io/g/devel/message/90891 Mute This Topic: https://groups.io/mt/92072161/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 12:14:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90892+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90892+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530074; cv=none; d=zohomail.com; s=zohoarc; b=fhWtEyWo4eWwhWTlDbsGP6QwkzuuUNH+xczpO4HQQwpOT95tD3BrQwBcUhXidB+GgW+i7hRue6RkBnxeSczdKW4DaJgsG3yiELK6FF9HK4KdRjUmYcLimqFLHy3ad1c6i9GitQRMTMQKzp6QityXrO4/RJe14aTg6C8a4Uo0/T4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530074; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=mA8G48+VgmNT6b8jxDm+NvJFfOfcIItjV2tYF7ooASY=; b=UbEuILmGxQRCxbIFCjbsgW45Sz9Hz1y0FhpbYNWkbYbSO7oNDT9uJt5mEcc+sIL5ZBGpCPKNt81xWHFxLdK5dMzDlAgPpduylJ/PXAg+IGQpLZ/fKYWivKmfYhpxkbtwNVsaMkiWBoUghOHPNa8UyvafqIDpblRjSk5yQRHu03o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90892+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656530074446804.5524717549051; Wed, 29 Jun 2022 12:14:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id GMVgYY1788612xy2BNOm0E7j; Wed, 29 Jun 2022 12:14:34 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.15634.1656530073009232279 for ; Wed, 29 Jun 2022 12:14:33 -0700 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 E5CF6152B; Wed, 29 Jun 2022 12:14:32 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1D7F73F792; Wed, 29 Jun 2022 12:14:30 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Edward Pickup Subject: [edk2-devel] [PATCH RESEND v1 2/7] ArmPkg/ArmDisassemblerLib: Replace RotateRight() Date: Wed, 29 Jun 2022 21:13:50 +0200 Message-Id: <20220629191355.2618844-3-Pierre.Gondois@arm.com> In-Reply-To: <20220629191355.2618844-1-Pierre.Gondois@arm.com> References: <20220629191355.2618844-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: f0QkmIo3Ir4DlLZSOFMDcObWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530074; bh=mc2aVKElhhbnkOPph8BytARnP0O10eCboFPSxbpwICo=; h=Cc:Date:From:Reply-To:Subject:To; b=RAdMVdLmgvnRtwDnkwStEnQ6hJwoSa9MMpxo2fyCFXa3s4iqYcXMLmm1uWKusc7UExA iYaKxWTZs/A+jZWwyr33aD/iibvVcOeeqnLeIaUsq08acv6l3YIZq8XFzKau3s1Q8jQTc +VmW127RqIIpjdP9bx8jt8Z0AJJ8pFMbGCE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530076130100009 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois A local RotateRight() function is defined. The RRotU32() function available in the MdePkg/BaseLib does the same. Prefer the generic function and remove the local RotateRight(). Signed-off-by: Pierre Gondois --- ArmPkg/Library/ArmDisassemblerLib/ArmDisassembler.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/ArmPkg/Library/ArmDisassemblerLib/ArmDisassembler.c b/ArmPkg/L= ibrary/ArmDisassemblerLib/ArmDisassembler.c index 0e09062957b4..24a317a9c9f4 100644 --- a/ArmPkg/Library/ArmDisassemblerLib/ArmDisassembler.c +++ b/ArmPkg/Library/ArmDisassemblerLib/ArmDisassembler.c @@ -128,15 +128,6 @@ FieldMask ( return ""; } =20 -UINT32 -RotateRight ( - IN UINT32 Op, - IN UINT32 Shift - ) -{ - return (Op >> Shift) | (Op << (32 - Shift)); -} - /** Place a disassembly of **OpCodePtr into buffer, and update OpCodePtr to point to next instruction. @@ -409,7 +400,7 @@ DisassembleArmInstruction ( // A4.1.38 MSR{} CPSR_, # MSR{} CPSR_, if (Imm) { // MSR{} CPSR_, # - AsciiSPrint (Buf, Size, "MRS%a %a_%a, #0x%x", COND (OpCode), WriteBa= ck ? "SPSR" : "CPSR", FieldMask ((OpCode >> 16) & 0xf), RotateRight (OpCode= & 0xf, ((OpCode >> 8) & 0xf) *2)); + AsciiSPrint (Buf, Size, "MRS%a %a_%a, #0x%x", COND (OpCode), WriteBa= ck ? "SPSR" : "CPSR", FieldMask ((OpCode >> 16) & 0xf), RRotU32 (OpCode & 0= xf, ((OpCode >> 8) & 0xf) *2)); } else { // MSR{} CPSR_, AsciiSPrint (Buf, Size, "MRS%a %a_%a, %a", COND (OpCode), WriteBack = ? "SPSR" : "CPSR", gReg[Rd]); --=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 (#90892): https://edk2.groups.io/g/devel/message/90892 Mute This Topic: https://groups.io/mt/92072164/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 12:14:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90893+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90893+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530076; cv=none; d=zohomail.com; s=zohoarc; b=PK2652YOpcAQxAz3bhQ/TZ5l7Ghi8WZCpwm45FeSY5U9Ux6OwCTZeIGbhib9OHTDW2tIDhSFyx9GeQD6zXmoTgUeV9DLrqxk1T1METYIcVxfQupaQy5ZdbWvjBKGpIHH1NmZZnq6OrNIF8SYDBHHNPpqMdo7BwuddmkEGRp3i5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530076; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AiZR9aylbusdquyr0TivAFt/EOsbwr6ceCoEOLwkSRk=; b=gkF7YHmVFt2jBHKUMi1zvuN3lkwICzip3+x8Hvbo2vPXPGlpsF1hz6MK+3/iNoRXxZ42em7xmTimzG/sdDokn16NA0LyBI5F9a4onD5sLPJMuB/YEBeYafG6DpuYRj4t8U4U102xTfsgpSNHmn1n7Eg2fg8C95dmuklhZxGtROc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90893+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656530076630136.48042445334193; Wed, 29 Jun 2022 12:14:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KjBHYY1788612xsHXokAaAaT; Wed, 29 Jun 2022 12:14:36 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.15960.1656530075674516571 for ; Wed, 29 Jun 2022 12:14:35 -0700 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 5398D153B; Wed, 29 Jun 2022 12:14:35 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 108853F792; Wed, 29 Jun 2022 12:14:32 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Edward Pickup Subject: [edk2-devel] [PATCH RESEND v1 3/7] ArmPkg/ArmLib: Add ArmReadIdIsaR5() helper Date: Wed, 29 Jun 2022 21:13:51 +0200 Message-Id: <20220629191355.2618844-4-Pierre.Gondois@arm.com> In-Reply-To: <20220629191355.2618844-1-Pierre.Gondois@arm.com> References: <20220629191355.2618844-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: gyMbWW2Mmxb0xwxO9YoGUjYNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530076; bh=sYy35jUDDxoY2lV1Jl3o0kHpayssvlY5W4A3Ajr260w=; h=Cc:Date:From:Reply-To:Subject:To; b=RXaKYJJ+9aLs7Tt02YWeOoU+NkBCNNAtXkgnlUr9Cz2M3tiwotltaj+Ek04DpRGH8Di 5aTfX0G4IPlampSULhkuX6BmAw7mvRhkq0lom0KjgRpl0gG1aW+oKSAwY4ILf9D6O5p9V zPB5TfUmU0skRmkvXrcXeIayuLzWLPlBdF8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530078193100014 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add a ArmReadIdIsaR5() helper function to access the AArch32 ID_ISAR5 register. Signed-off-by: Pierre Gondois --- ArmPkg/Library/ArmLib/Arm/ArmLibSupport.S | 7 ++++++- ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ArmPkg/Library/ArmLib/Arm/ArmLibSupport.S b/ArmPkg/Library/Arm= Lib/Arm/ArmLibSupport.S index 0856740e3290..bc2be5331c7d 100644 --- a/ArmPkg/Library/ArmLib/Arm/ArmLibSupport.S +++ b/ArmPkg/Library/ArmLib/Arm/ArmLibSupport.S @@ -1,7 +1,7 @@ #-------------------------------------------------------------------------= ----- # # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
-# Copyright (c) 2011 - 2016, ARM Limited. All rights reserved. +# Copyright (c) 2011 - 2022, Arm Limited. All rights reserved. # Copyright (c) 2016, Linaro Limited. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -167,4 +167,9 @@ ASM_FUNC (ArmGetPhysicalAddressBits) movge r0, #40 // 40 bits if LPAE bx lr =20 +// UINTN ArmReadIdIsaR5(VOID) +ASM_FUNC(ArmReadIdIsaR5) + mrc p15, 0, r0, c0, c2, 5 + bx lr + ASM_FUNCTION_REMOVE_IF_UNREFERENCED diff --git a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h b/ArmPkg/Library/ArmLib/A= rm/ArmV7Lib.h index 404ff92c4e06..1cfd6e5f65ac 100644 --- a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h +++ b/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h @@ -1,6 +1,7 @@ /** @file =20 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+ Copyright (c) 2022, Arm Ltd. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -66,4 +67,14 @@ ArmReadIdPfr1 ( VOID ); =20 +/** Reads the ID_ISAR5 register. + + @return The contents of the ID_ISAR5 register. +**/ +UINTN +EFIAPI +ArmReadIdIsaR5 ( + VOID + ); + #endif // ARM_V7_LIB_H_ --=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 (#90893): https://edk2.groups.io/g/devel/message/90893 Mute This Topic: https://groups.io/mt/92072166/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 12:14:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90894+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90894+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530079; cv=none; d=zohomail.com; s=zohoarc; b=SdAbC/CEJ8m3X3xIL1ps4Ggx390V1Gz9wHDQxb/coDfHGqhyFIrUt3BN2RuWHW4SYr8cAcP0xDhQBccOJsFmGaBSuaNSmhBbLsjTYiL87dwxINKdQHWnWb2DszPffnSYsK042jQeFZeabxhRwjCPTqfurKl65C/7K/AQ3OZDY0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530079; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=+aamjVYAsl3WXpGeuBJDjuvGKCCy6sPpXO2OnpuQC6k=; b=FVUVcm9X7+yJz3tzuwhfd9GH/eQDeyPGRFxIv2FRArrhYSh7P2uh9ExA/4IPTouxwJxP26HyK9/j4QFnxrEuHgdsIw816RRZBR7O78QhXXsID1A5N6yFwHybZ773zn/tEg7OD0WFhka8UkDfRX3NxbLxKf08mTy5WUv46fej/HM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90894+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656530079086870.5432424787787; Wed, 29 Jun 2022 12:14:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pQRKYY1788612xMfuMvfTAA4; Wed, 29 Jun 2022 12:14:38 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.15869.1656530077789503846 for ; Wed, 29 Jun 2022 12:14:38 -0700 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 B015E1691; Wed, 29 Jun 2022 12:14:37 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 800AA3F792; Wed, 29 Jun 2022 12:14:35 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Edward Pickup Subject: [edk2-devel] [PATCH RESEND v1 4/7] ArmPkg/ArmLib: Add ArmHasAesExt() Date: Wed, 29 Jun 2022 21:13:52 +0200 Message-Id: <20220629191355.2618844-5-Pierre.Gondois@arm.com> In-Reply-To: <20220629191355.2618844-1-Pierre.Gondois@arm.com> References: <20220629191355.2618844-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: zd8CORoJvpUCuH6tPvGGu1ylx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530078; bh=rv7a85oVRpWy7TqkvhgmbTr8UtoKcpTtRO8OLh7hSd4=; h=Cc:Date:From:Reply-To:Subject:To; b=XcWX9ajJ3dQCJGDVWVdhOIGNgTkSsWqqIi63ikdBuX51AJNYfpS4REwPxY2jlzJlWS8 ZOTpZeJ6o5kXQUDMvYJw5cyUGmIhdOXG+WN7PtoirRiVD0erJ+HAfiSqTUqBfd1WC7/KW 3u1U/Nqo1hDt0RXWc7t53+tLWQa6/TYkoJk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530080180100018 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add a ArmHasAesExt() to check for the FEAT_AES extension. Signed-off-by: Pierre Gondois --- ArmPkg/Include/Library/ArmLib.h | 12 +++++++++++- ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c | 13 +++++++++++++ ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h | 1 + ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c | 13 +++++++++++++ ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLi= b.h index 8058634dbc53..5cd2bc1a26e5 100644 --- a/ArmPkg/Include/Library/ArmLib.h +++ b/ArmPkg/Include/Library/ArmLib.h @@ -1,7 +1,7 @@ /** @file =20 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Copyright (c) 2011 - 2022, Arm Limited. All rights reserved.
+ Copyright (c) 2011 - 2022, Arm Ltd. All rights reserved.
Copyright (c) 2020 - 2021, NUVIA Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -779,6 +779,16 @@ ArmHasRngExt ( VOID ); =20 +/** Check if FEAT_AES extension is available. + + @retval TRUE if FEAT_AES extension is available. + @retval FALSE otherwise. +**/ +BOOLEAN +ArmHasAesExt ( + VOID + ); + #ifdef MDE_CPU_ARM /// /// AArch32-only ID Register Helper functions diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c b/ArmPkg/Library/Ar= mLib/AArch64/AArch64Lib.c index 124b28e16874..dac406362114 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c @@ -117,3 +117,16 @@ ArmHasRngExt ( { return ArmReadIdIsar0 () & ID_AA64ISAR0_EL1_RNDR_MASK; } + +/** Check if FEAT_AES extension is available. + + @retval TRUE if FEAT_AES extension is available. + @retval FALSE otherwise. +**/ +BOOLEAN +ArmHasAesExt ( + VOID + ) +{ + return ArmReadIdIsar0 () & ID_AA64ISAR0_EL1_AES_MASK; +} diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h b/ArmPkg/Library/Ar= mLib/AArch64/AArch64Lib.h index 61a775ea27e8..9f5ad3e0214f 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h @@ -11,6 +11,7 @@ #ifndef AARCH64_LIB_H_ #define AARCH64_LIB_H_ =20 +#define ID_AA64ISAR0_EL1_AES_MASK ((UINT64)0xF << 4U) #define ID_AA64ISAR0_EL1_RNDR_MASK ((UINT64)0xF << 60U) =20 typedef VOID (*AARCH64_CACHE_OPERATION)( diff --git a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c b/ArmPkg/Library/ArmLib/A= rm/ArmV7Lib.c index a4ec23c8f8d8..ee3a847c1b50 100644 --- a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c +++ b/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c @@ -133,3 +133,16 @@ ArmHasRngExt ( // Not supported. return FALSE; } + +/** Check if FEAT_AES extension is available. + + @retval TRUE if FEAT_AES extension is available. + @retval FALSE otherwise. +**/ +BOOLEAN +ArmHasAesExt ( + VOID + ) +{ + return ArmReadIdIsaR5 () & ID_ISAR5_AES_MASK; +} diff --git a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h b/ArmPkg/Library/ArmLib/A= rm/ArmV7Lib.h index 1cfd6e5f65ac..1b91db66fb43 100644 --- a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h +++ b/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h @@ -10,6 +10,8 @@ #ifndef ARM_V7_LIB_H_ #define ARM_V7_LIB_H_ =20 +#define ID_ISAR5_AES_MASK (0xF << 4U) + #define ID_MMFR0_SHARELVL_SHIFT 12 #define ID_MMFR0_SHARELVL_MASK 0xf #define ID_MMFR0_SHARELVL_ONE 0 --=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 (#90894): https://edk2.groups.io/g/devel/message/90894 Mute This Topic: https://groups.io/mt/92072167/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 12:14:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90895+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90895+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530081; cv=none; d=zohomail.com; s=zohoarc; b=m32Q2bv+drc3A4zc1oetxvtLwU9OGX+l20SR8HqkoO6dOR+bj3+LXntdcroMhu6cqxsgGwVtnPFjaUsAOfDRW15DlME2zHMAEpQO0UZo40y+pt3WCzG99fp1/cbOJw4WEe3iIaCE22ze4LRIlx1ecRh8+CI1hU3tb12yBvdjoVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530081; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=/4qAzNZ6q9ltSxFqukWufQF+4dtsYrSbKcQEXJyAJ2w=; b=fQIg2ZLcLbKqR3oBG3B85BrN0HUefhaNUHZsQSPMRNTAj/Ivv/oxf0GYV30ler2blJvZM+r7dzytutUHCdYqEDpBG6sRxrIbzKnthh08kZ0fF/jpdiorkNY4h5aMWGJRLTmXO5oEia7E1W5VuGdFGIkS7PubtouMwtqhz4zfj+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90895+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16565300818171008.998911100197; Wed, 29 Jun 2022 12:14:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id z2ETYY1788612x3rl3kGM67i; Wed, 29 Jun 2022 12:14:40 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.15770.1656530079774291484 for ; Wed, 29 Jun 2022 12:14:40 -0700 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 A2D5614BF; Wed, 29 Jun 2022 12:14:39 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B5E723F792; Wed, 29 Jun 2022 12:14:37 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Edward Pickup Subject: [edk2-devel] [PATCH RESEND v1 5/7] MdePkg/AesLib: Definition for AES library class interface Date: Wed, 29 Jun 2022 21:13:53 +0200 Message-Id: <20220629191355.2618844-6-Pierre.Gondois@arm.com> In-Reply-To: <20220629191355.2618844-1-Pierre.Gondois@arm.com> References: <20220629191355.2618844-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: 9uwZOX9LUsZALbWgQPUKCjO0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530080; bh=EeboOL8tbXBYcnPmUCcypjcMZDTGHxEmt+UUh7pede0=; h=Cc:Date:From:Reply-To:Subject:To; b=HoLBDPiK4Is8miYyszhJfcsguH2RpLDLKYcR1S/SOZ4UGhD/Ns8vh7wUu7j5RMQ3UgM Ot5gyKEB7WQxtBrFCHQPsHTcnX4+TRq0JnNq+tAU6gBXdniuLs2K2nmLjBRUBWYkOPfTD M2Xh9slbZBtV0kVR7BzRHcKLnLeSHN1FBmA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530082199100022 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3970 The FIPS PUB 197: "Advanced Encryption Standard (AES)" details the AES algorithm. Add a library to allow different architecture specific implementations. Signed-off-by: Pierre Gondois --- MdePkg/Include/Library/AesLib.h | 104 ++++++++++++++++++++++++++++++++ MdePkg/MdePkg.dec | 4 ++ 2 files changed, 108 insertions(+) create mode 100644 MdePkg/Include/Library/AesLib.h diff --git a/MdePkg/Include/Library/AesLib.h b/MdePkg/Include/Library/AesLi= b.h new file mode 100644 index 000000000000..bc3408bb249b --- /dev/null +++ b/MdePkg/Include/Library/AesLib.h @@ -0,0 +1,104 @@ +/** @file + AES library. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - FIPS 197 November 26, 2001: + Specification for the ADVANCED ENCRYPTION STANDARD (AES) +**/ + +#ifndef AES_LIB_H_ +#define AES_LIB_H_ + +/// Key size in bytes. +#define AES_KEY_SIZE_128 16 +#define AES_KEY_SIZE_192 24 +#define AES_KEY_SIZE_256 32 +#define AES_BLOCK_SIZE 16 + +/* + The Key Expansion generates a total of Nb (Nr + 1) words with: + - Nb =3D 4: + Number of columns (32-bit words) comprising the State + - Nr =3D 10, 12, or 14: + Number of rounds. + */ +#define AES_MAX_KEYLENGTH_U32 (4 * (14 + 1)) + +/** A context holding information to for AES encryption/decryption. + */ +typedef struct { + /// Expanded encryption key. + UINT32 ExpEncKey[AES_MAX_KEYLENGTH_U32]; + /// Expanded decryption key. + UINT32 ExpDecKey[AES_MAX_KEYLENGTH_U32]; + /// Key size, in bytes. + /// Must be one of 16|24|32. + UINT32 KeySize; +} AES_CTX; + +/** Encrypt an AES block. + + Buffers are little-endian. Overlapping is not checked. + + @param [in] AesCtx AES context. + AesCtx is initialized with AesInitCtx (). + @param [in] InBlock Input Block. The block to cipher. + @param [out] OutBlock Output Block. The ciphered block. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Unsupported. +**/ +RETURN_STATUS +EFIAPI +AesEncrypt ( + IN AES_CTX *AesCtx, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ); + +/** Decrypt an AES block. + + Buffers are little-endian. Overlapping is not checked. + + @param [in] AesCtx AES context. + AesCtx is initialized with AesInitCtx (). + @param [in] InBlock Input Block. The block to de-cipher. + @param [out] OutBlock Output Block. The de-ciphered block. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Unsupported. +**/ +RETURN_STATUS +EFIAPI +AesDecrypt ( + IN AES_CTX *AesCtx, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ); + +/** Initialize an AES_CTX structure. + + @param [in] Key AES key. Buffer of KeySize bytes. + The buffer is little endian. + @param [in] KeySize Size of the key. Must be one of 128|192|256. + @param [in, out] AesCtx AES context to initialize. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Unsupported. +**/ +RETURN_STATUS +EFIAPI +AesInitCtx ( + IN UINT8 *Key, + IN UINT32 KeySize, + IN OUT AES_CTX *AesCtx + ); + +#endif // AES_LIB_H_ diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 7ff26e22f915..078ae9323ba6 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -280,6 +280,10 @@ [LibraryClasses] # TrngLib|Include/Library/TrngLib.h =20 + ## @libraryclass Provides AES encryption/decryption services. + # + AesLib|Include/Library/AesLib.h + [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64] ## @libraryclass Provides services to generate random number. # --=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 (#90895): https://edk2.groups.io/g/devel/message/90895 Mute This Topic: https://groups.io/mt/92072168/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 12:14:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90896+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90896+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530083; cv=none; d=zohomail.com; s=zohoarc; b=S5uFfKJGkkjh6TpprU4PU8X9k/iPKv4wlWC6xs8yDdfOV1qGYJr0awpCQ7kK70Q/A5l4UDrvn8qgwkvNDwKEFUfzu/uKrJvxygjVW9x97mmjTILrYz/9yWPh584r9nV1K/lIbIfOtsL8nrKxNozm1NchQGqunFLTRouL2UTJmds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530083; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wtnnzHnfpN3YqUSPpdXIO69YDLVE8c4w3xtxT9W0U9k=; b=O531ns/AQdK9wvC5CG19whIZAhrgtGFRxrZpzqzzKcdy8gzScd3WDVlQ8uWXXDVzP8vxl1mMNX5FvJXIwRS7Z7nipBs0z2tDjnLfkEYJ/ANfFWnomk4ZiUYupNQh/ivJQ+S//gqa1ay0RRxex3ReriovE1hjXvadFB2fPdWJV9g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90896+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656530083314504.913017214348; Wed, 29 Jun 2022 12:14:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tZaIYY1788612xZlzMCcfDfp; Wed, 29 Jun 2022 12:14:43 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.15962.1656530082235470369 for ; Wed, 29 Jun 2022 12:14:42 -0700 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 1EC4A1480; Wed, 29 Jun 2022 12:14:42 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C953B3F792; Wed, 29 Jun 2022 12:14:39 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Edward Pickup Subject: [edk2-devel] [PATCH RESEND v1 6/7] MdePkg/AesLib: Add NULL instance of AesLib Date: Wed, 29 Jun 2022 21:13:54 +0200 Message-Id: <20220629191355.2618844-7-Pierre.Gondois@arm.com> In-Reply-To: <20220629191355.2618844-1-Pierre.Gondois@arm.com> References: <20220629191355.2618844-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: qetyANy3eq44SMc5MZI0uvumx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530083; bh=zag1qA3/3h+9gLmtmTMr3GRs1iVgKbgGx/uT218u0nA=; h=Cc:Date:From:Reply-To:Subject:To; b=sC8IsHODM+pYQGNM4wUl6DLZ7QB7KwBqUZL/xMlASUxu9DKqjxLEtDZ9EFBEN6lY9zh IPMMhYbIq6U97xHvU2hNhFTin4JDNwnwEXolrKi9a9GFp7O0oIs2mfl34tt0JX7WmheBg FNgs3VScqc7lZJMyGzlTYTe/iY8OsLDobWA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530084195100026 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3970 The FIPS PUB 197: "Advanced Encryption Standard (AES)" details the AES algorithm. Add an AesLibNull implementation. Signed-off-by: Pierre Gondois --- MdePkg/Library/AesLibNull/AesLibNull.c | 87 ++++++++++++++++++++++++ MdePkg/Library/AesLibNull/AesLibNull.inf | 24 +++++++ MdePkg/MdePkg.dsc | 1 + 3 files changed, 112 insertions(+) create mode 100644 MdePkg/Library/AesLibNull/AesLibNull.c create mode 100644 MdePkg/Library/AesLibNull/AesLibNull.inf diff --git a/MdePkg/Library/AesLibNull/AesLibNull.c b/MdePkg/Library/AesLib= Null/AesLibNull.c new file mode 100644 index 000000000000..3dd680fe37e4 --- /dev/null +++ b/MdePkg/Library/AesLibNull/AesLibNull.c @@ -0,0 +1,87 @@ +/** @file + Null AES Library + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - FIPS 197 November 26, 2001: + Specification for the ADVANCED ENCRYPTION STANDARD (AES) +**/ + +#include +#include + +/** Encrypt an AES block. + + Buffers are little-endian. Overlapping is not checked. + + @param [in] AesCtx AES context. + AesCtx is initialized with AesInitCtx (). + @param [in] InBlock Input Block. The block to cipher. + @param [out] OutBlock Output Block. The ciphered block. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +AesEncrypt ( + IN AES_CTX *AesCtx, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ) +{ + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} + +/** Decrypt an AES block. + + Buffers are little-endian. Overlapping is not checked. + + @param [in] AesCtx AES context. + AesCtx is initialized with AesInitCtx (). + @param [in] InBlock Input Block. The block to de-cipher. + @param [out] OutBlock Output Block. The de-ciphered block. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +AesDecrypt ( + IN AES_CTX *AesCtx, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ) +{ + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} + +/** Initialize an AES_CTX structure. + + @param [in] Key AES key. Buffer of KeySize bytes. + The buffer is little endian. + @param [in] KeySize Size of the key. Must be one of 128|192|256. + @param [in, out] AesCtx AES context to initialize. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +AesInitCtx ( + IN UINT8 *Key, + IN UINT32 KeySize, + IN OUT AES_CTX *AesCtx + ) +{ + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} diff --git a/MdePkg/Library/AesLibNull/AesLibNull.inf b/MdePkg/Library/AesL= ibNull/AesLibNull.inf new file mode 100644 index 000000000000..3020e7b68571 --- /dev/null +++ b/MdePkg/Library/AesLibNull/AesLibNull.inf @@ -0,0 +1,24 @@ +## @file +# Null AES Library +# +# Copyright (c) 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D AesLibNull + FILE_GUID =3D F6DED279-FC26-40F6-88B2-05FF5E6E538F + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + LIBRARY_CLASS =3D AesLib + +[Sources] + AesLibNull.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 80e7233363d3..726350c215e5 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -68,6 +68,7 @@ [Components] MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf + MdePkg/Library/AesLibNull/AesLibNull.inf =20 MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf --=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 (#90896): https://edk2.groups.io/g/devel/message/90896 Mute This Topic: https://groups.io/mt/92072169/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 12:14:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90897+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90897+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530085; cv=none; d=zohomail.com; s=zohoarc; b=aXJDcIcYh4jCs3ebhiAhyrPoEFwQL2C5boZdWHilGI2wEAO3NfquDH9CsAtLbI917YrlSaV0ATXyO+H6AGVo8LuS4IYR/TRAGYzKFKD7+MTpGknrzWstLnMWZIXrHYiXutazk+AXa+PKgUNKou11qlnxB9lEtHhhwvkLZUC6vC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530085; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=A2ohZs/oF7iV6fAhyeGFfoZGss1aYptXOrecOdE1YLk=; b=YDtoX5OxuK0o4S+TXnqRsdCtdkGJnOYvbxqeSy3239UbzCTLQ6BmciDsnllZovcnLVwE22tE7bmMEWI9dsbCTJjjHGD0AZPe3VtzASw4SbtBQPnKT0F/DRYQZ+yJkCun4mK1uLHkIDxokIqypCQLzuT3+hO3bW/eiQvxjNpg+7w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90897+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656530085757758.6797519479602; Wed, 29 Jun 2022 12:14:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dY8cYY1788612xuUWlTCqpG9; Wed, 29 Jun 2022 12:14:45 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.15772.1656530084725520595 for ; Wed, 29 Jun 2022 12:14:44 -0700 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 A8496152B; Wed, 29 Jun 2022 12:14:44 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 44F7B3F792; Wed, 29 Jun 2022 12:14:42 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Edward Pickup Subject: [edk2-devel] [PATCH RESEND v1 7/7] ArmPkg/ArmAesLib: Add ArmAesLib Date: Wed, 29 Jun 2022 21:13:55 +0200 Message-Id: <20220629191355.2618844-8-Pierre.Gondois@arm.com> In-Reply-To: <20220629191355.2618844-1-Pierre.Gondois@arm.com> References: <20220629191355.2618844-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: EPExaO2NH9PaYBAYJEHfDs69x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530085; bh=PKNVSACA85Caa1mw83pP//uiO+Zk3vcb9kN1GEXQShU=; h=Cc:Date:From:Reply-To:Subject:To; b=UslSU0p62xiubk4PBGiFpe2JjbbwYPavoEcll4dyoiFPMMvRqLHpR/qKOBJSO1ebmMa vNKs1Q+tT00osYcpMmv4YuC7cIc9/b8SBBK4IvChAQrbx1+SazaUXkWstfghRzL1YVxFW oNfdb0PT560ji3BHhDXEB4pDi7MlOLrjmLs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530086262100030 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3970 The Armv8.0 Cryptographic Extension 'FEAT_AES' provides instructions for the acceleration of encryption and decryption. Add an ArmAesLib relying on this feature to implement the AES algorithm. Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dsc | 3 +- .../Library/ArmAesLib/AArch64/AArch64AesLib.S | 183 ++++++++++++ ArmPkg/Library/ArmAesLib/Arm/ArmAesLib.S | 183 ++++++++++++ ArmPkg/Library/ArmAesLib/ArmAesLib.c | 261 ++++++++++++++++++ ArmPkg/Library/ArmAesLib/ArmAesLib.h | 96 +++++++ ArmPkg/Library/ArmAesLib/ArmAesLib.inf | 34 +++ 6 files changed, 759 insertions(+), 1 deletion(-) create mode 100644 ArmPkg/Library/ArmAesLib/AArch64/AArch64AesLib.S create mode 100644 ArmPkg/Library/ArmAesLib/Arm/ArmAesLib.S create mode 100644 ArmPkg/Library/ArmAesLib/ArmAesLib.c create mode 100644 ArmPkg/Library/ArmAesLib/ArmAesLib.h create mode 100644 ArmPkg/Library/ArmAesLib/ArmAesLib.inf diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 02d1caa3ab40..72efeb77012e 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -2,7 +2,7 @@ # ARM processor package. # # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.
-# Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
+# Copyright (c) 2011 - 2022, Arm Limited. All rights reserved.
# Copyright (c) 2016, Linaro Ltd. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Copyright (c) 2021, Ampere Computing LLC. All rights reserved. @@ -139,6 +139,7 @@ [Components.common] ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/OpteeLib/OpteeLib.inf ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf + ArmPkg/Library/ArmAesLib/ArmAesLib.inf =20 ArmPkg/Filesystem/SemihostFs/SemihostFs.inf =20 diff --git a/ArmPkg/Library/ArmAesLib/AArch64/AArch64AesLib.S b/ArmPkg/Libr= ary/ArmAesLib/AArch64/AArch64AesLib.S new file mode 100644 index 000000000000..07d1d30e6e91 --- /dev/null +++ b/ArmPkg/Library/ArmAesLib/AArch64/AArch64AesLib.S @@ -0,0 +1,183 @@ +/** @file + AArch64 AES implementation. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +.arch_extension crypto + +// Generic notes: +// - In AArch64, the AESE/AESD/AESMC/AESIMC instructions are using registe= rs +// as .16B +// - For some CPUs, the latency of LD1 is 6, thus the unfolding. +// - The latency of the AESE/AESMC pair is 2. +// Cf. +// Arm Cortex-X1 Core Revision: r1p2 Software Optimization Guide +// Arm Cortex-X2 Core Revision: r2p0 Software Optimization Guide + +// /** Encrypt an AES block. +// +// @param [in] ExpEncKey Expanded encryption key. An array of 32-bits = words +// with the number of elements depending on the = key +// size: +// * 128-bits: 44 words +// * 192-bits: 52 words +// * 256-bits: 60 words +// @param [in] Rounds Number of rounds (depending on the key size). +// @param [in] InBlock Input Block. The block to cipher. +// @param [out] OutBlock Output Block. The ciphered block. +// **/ +// VOID +// ArmAesEncrypt ( +// IN UINT32 CONST *ExpEncKey, +// IN UINT32 Rounds, +// IN UINT8 CONST *InBlock, +// OUT UINT8 *OutBlock +// ); +ASM_FUNC(ArmAesEncrypt) + ld1 {v0.16b}, [x2] + cmp w1, #12 + beq 0f + + // Rounds =3D 10 or 14. Start loading the expanded key. + ld1 {v4.4s}, [x0], #16 + ld1 {v1.4s}, [x0], #16 + ld1 {v2.4s}, [x0], #16 + adds w1, w1, #1 + b 2f + + // Rounds =3D 12. Start loading the expanded key. +0: ld1 {v2.4s}, [x0], #16 + ld1 {v3.4s}, [x0], #16 + ld1 {v4.4s}, [x0], #16 + subs w1, w1, #1 + b 3f + + // Start of the loop (unfolded for 4 rounds). +1: ld1 {v4.4s}, [x0], #16 + aese v0.16b, v1.16b + aesmc v0.16b, v0.16b +3: ld1 {v1.4s}, [x0], #16 + aese v0.16b, v2.16b + aesmc v0.16b, v0.16b + ld1 {v2.4s}, [x0], #16 + aese v0.16b, v3.16b + aesmc v0.16b, v0.16b +2: subs w1, w1, #4 + ld1 {v3.4s}, [x0], #16 + aese v0.16b, v4.16b + aesmc v0.16b, v0.16b + bpl 1b + + // Final round. + aese v0.16b, v1.16b + eor v0.16b, v0.16b, v2.16b + st1 {v0.16b}, [x3] + ret + +// /** Decrypt an AES 128-bits block. +// +// @param [in] ExpDecKey Expanded decryption key. An array of 32-bits = words +// with the number of elements depending on the = key +// size: +// * 128-bits: 44 words +// * 192-bits: 52 words +// * 256-bits: 60 words +// @param [in] Rounds Number of rounds (depending on the key size). +// @param [in] InBlock Input Block. The block to de-cipher. +// @param [out] OutBlock Output Block. The de-ciphered block. +// **/ +// VOID +// ArmAesDecrypt ( +// IN UINT32 CONST *ExpDecKey, +// IN UINT32 Rounds, +// IN UINT8 CONST *InBlock, +// OUT UINT8 *OutBlock +// ); +ASM_FUNC(ArmAesDecrypt) + ld1 {v0.16b}, [x2] + cmp w1, #12 + beq 0f + + // Rounds =3D 10 or 14. Start loading the expanded key. + ld1 {v4.4s}, [x0], #16 + ld1 {v1.4s}, [x0], #16 + ld1 {v2.4s}, [x0], #16 + adds w1, w1, #1 + b 2f + + // Rounds =3D 12. Start loading the expanded key. +0: ld1 {v2.4s}, [x0], #16 + ld1 {v3.4s}, [x0], #16 + ld1 {v4.4s}, [x0], #16 + subs w1, w1, #1 + b 3f + + // Start of the loop (unfolded for 4 rounds). +1: ld1 {v4.4s}, [x0], #16 + aesd v0.16b, v1.16b + aesimc v0.16b, v0.16b +3: ld1 {v1.4s}, [x0], #16 + aesd v0.16b, v2.16b + aesimc v0.16b, v0.16b + ld1 {v2.4s}, [x0], #16 + aesd v0.16b, v3.16b + aesimc v0.16b, v0.16b +2: subs w1, w1, #4 + ld1 {v3.4s}, [x0], #16 + aesd v0.16b, v4.16b + aesimc v0.16b, v0.16b + bpl 1b + + // Final round. + aesd v0.16b, v1.16b + eor v0.16b, v0.16b, v2.16b + st1 {v0.16b}, [x3] + ret + +// /** Perform a SubWord() operation (applying AES Sbox) on a 32-bits word. +// +// The Arm AESE instruction performs the AddRoundKey(), ShiftRows() and +// SubBytes() AES steps in this order. +// +// During key expansion, only SubBytes() should be performed, so: +// - use a key of {0} so AddRoundKey() becomes an identity function; +// - the dup instruction allows to have a matrix with identic rows, +// so ShiftRows() has no effect. +// +// @param [in] InWord The 32-bits word to apply SubWord() on. +// +// @return SubWord(word). +// **/ +// UINT32 +// ArmAesSubWord ( +// IN UINT32 InWord +// ); +ASM_FUNC(ArmAesSubWord) + dup v1.4s, w0 + movi v0.16b, #0 + aese v0.16b, v1.16b + umov w0, v0.s[0] + ret + +// /** Perform a InvMixColumns() operation on an AES block (128-bits) using +// the Arm AESIMC instruction. +// +// This is usefull to get decryption key for the Equivalent Inverse Ciph= er. +// +// @param [in] InBlock Input block. +// @param [out] OutBlock Output blocked. +// **/ +// VOID +// ArmAesInvert ( +// IN AES_BLOCK CONST *InBlock, +// OUT AES_BLOCK *OutBlock +// ); +ASM_FUNC(ArmAesInvert) + ld1 {v0.4s}, [x1] + aesimc v1.16b, v0.16b + st1 {v1.4s}, [x0] + ret diff --git a/ArmPkg/Library/ArmAesLib/Arm/ArmAesLib.S b/ArmPkg/Library/ArmA= esLib/Arm/ArmAesLib.S new file mode 100644 index 000000000000..247d7c3d9ca2 --- /dev/null +++ b/ArmPkg/Library/ArmAesLib/Arm/ArmAesLib.S @@ -0,0 +1,183 @@ +/** @file + Arm(32) AES implementation. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +.fpu crypto-neon-fp-armv8 + +// Generic notes: +// - In Arm32, the AESE/AESD/AESMC/AESIMC instructions are using registers +// as qX +// - For some CPUs, the latency of VLD1 is 6, thus the unfolding. +// - The latency of the AESE/AESMC pair is 2. +// Cf. +// Arm Cortex-X1 Core Revision: r1p2 Software Optimization Guide +// Arm Cortex-X2 Core Revision: r2p0 Software Optimization Guide + +// /** Encrypt an AES block. +// +// @param [in] ExpEncKey Expanded encryption key. An array of 32-bits = words +// with the number of elements depending on the = key +// size: +// * 128-bits: 44 words +// * 192-bits: 52 words +// * 256-bits: 60 words +// @param [in] Rounds Number of rounds (depending on the key size). +// @param [in] InBlock Input Block. The block to cipher. +// @param [out] OutBlock Output Block. The ciphered block. +// **/ +// VOID +// ArmAesEncrypt ( +// IN UINT32 CONST *ExpEncKey, +// IN UINT32 Rounds, +// IN UINT8 CONST *InBlock, +// OUT UINT8 *OutBlock +// ); +ASM_FUNC(ArmAesEncrypt) + vld1.8 {q0}, [r2] + cmp r1, #12 + beq 0f + + // Rounds =3D 10 or 14. Start loading the expanded key. + vld1.8 {q4}, [r0]! + vld1.8 {q1}, [r0]! + vld1.8 {q2}, [r0]! + adds r1, r1, #1 + b 2f + + // Rounds =3D 12. Start loading the expanded key. +0: vld1.8 {q2}, [r0]! + vld1.8 {q3}, [r0]! + vld1.8 {q4}, [r0]! + subs r1, r1, #1 + b 3f + + // Start of the loop (unfolded for 4 rounds). +1: vld1.8 {q4}, [r0]! + aese.8 q0, q1 + aesmc.8 q0, q0 +3: vld1.8 {q1}, [r0]! + aese.8 q0, q2 + aesmc.8 q0, q0 + vld1.8 {q2}, [r0]! + aese.8 q0, q3 + aesmc.8 q0, q0 +2: subs r1, r1, #4 + vld1.8 {q3}, [r0]! + aese.8 q0, q4 + aesmc.8 q0, q0 + bpl 1b + + // Final round. + aese.8 q0, q1 + veor q0, q0, q2 + vst1.8 {q0}, [r3] + bx lr + +// /** Decrypt an AES 128-bits block. +// +// @param [in] ExpDecKey Expanded decryption key. An array of 32-bits = words +// with the number of elements depending on the = key +// size: +// * 128-bits: 44 words +// * 192-bits: 52 words +// * 256-bits: 60 words +// @param [in] Rounds Number of rounds (depending on the key size). +// @param [in] InBlock Input Block. The block to de-cipher. +// @param [out] OutBlock Output Block. The de-ciphered block. +// **/ +// VOID +// ArmAesDecrypt ( +// IN UINT32 CONST *ExpDecKey, +// IN UINT32 Rounds, +// IN UINT8 CONST *InBlock, +// OUT UINT8 *OutBlock +// ); +ASM_FUNC(ArmAesDecrypt) + vld1.8 {q0}, [r2] + cmp r1, #12 + beq 0f + + // Rounds =3D 10 or 14. Start loading the expanded key. + vld1.8 {q4}, [r0]! + vld1.8 {q1}, [r0]! + vld1.8 {q2}, [r0]! + adds r1, r1, #1 + b 2f + + // Rounds =3D 12. Start loading the expanded key. +0: vld1.8 {q2}, [r0]! + vld1.8 {q3}, [r0]! + vld1.8 {q4}, [r0]! + subs r1, r1, #1 + b 3f + + // Start of the loop (unfolded for 4 rounds). +1: vld1.8 {q4}, [r0]! + aesd.8 q0, q1 + aesimc.8 q0, q0 +3: vld1.8 {q1}, [r0]! + aesd.8 q0, q2 + aesimc.8 q0, q0 + vld1.8 {q2}, [r0]! + aesd.8 q0, q3 + aesimc.8 q0, q0 +2: subs r1, r1, #4 + vld1.8 {q3}, [r0]! + aesd.8 q0, q4 + aesimc.8 q0, q0 + bpl 1b + + // Final round. + aesd.8 q0, q1 + veor q0, q0, q2 + vst1.8 {q0}, [r3] + bx lr + +// /** Perform a SubWord() operation (applying AES Sbox) on a 32-bits word. +// +// The Arm AESE instruction performs the AddRoundKey(), ShiftRows() and +// SubBytes() AES steps in this order. +// +// During key expansion, only SubBytes() should be performed, so: +// - use a key of {0} so AddRoundKey() becomes an identity function; +// - the dup instruction allows to have a matrix with identic rows, +// so ShiftRows() has no effect. +// +// @param [in] InWord The 32-bits word to apply SubWord() on. +// +// @return SubWord(word). +// **/ +// UINT32 +// ArmAesSubWord ( +// IN UINT32 InWord +// ); +ASM_FUNC(ArmAesSubWord) + vdup.32 q1, r0 + vmov.i64 q0, #0 + aese.8 q0, q1 + vmov.f32 r0, s0 + bx lr + +// /** Perform a InvMixColumns() operation on an AES block (128-bits) using +// the Arm AESIMC instruction. +// +// This is usefull to get decryption key for the Equivalent Inverse Ciph= er. +// +// @param [in] InBlock Input block. +// @param [out] OutBlock Output blocked. +// **/ +// VOID +// ArmAesInvert ( +// IN AES_BLOCK CONST *InBlock, +// OUT AES_BLOCK *OutBlock +// ); +ASM_FUNC(ArmAesInvert) + vld1.8 {q0}, [r1] + aesimc.8 q1, q0 + vst1.8 {q1}, [r0] + bx lr diff --git a/ArmPkg/Library/ArmAesLib/ArmAesLib.c b/ArmPkg/Library/ArmAesLi= b/ArmAesLib.c new file mode 100644 index 000000000000..ff3cfce75b2b --- /dev/null +++ b/ArmPkg/Library/ArmAesLib/ArmAesLib.c @@ -0,0 +1,261 @@ +/** @file + Arm AES Library + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - FIPS 197 November 26, 2001: + Specification for the ADVANCED ENCRYPTION STANDARD (AES) +**/ + +#include +#include +#include +#include +#include +#include "ArmAesLib.h" + +/** The constructor checks that the FEAT_AES extension is available. + + @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS. +**/ +RETURN_STATUS +EFIAPI +AesLibConstructor ( + VOID + ) +{ + if (!ArmHasAesExt ()) { + DEBUG (( + DEBUG_ERROR, + "FEAT_AES extension is not available. " + "This library cannot be used.\n" + )); + ASSERT_RETURN_ERROR (RETURN_UNSUPPORTED); + } + + return RETURN_SUCCESS; +} + +/** + AES key schedule round constants. +*/ +STATIC +UINT8 CONST +mRoundConstants[] =3D { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, +}; + +/** Get the number of Rounds. + + AES needs to perform a different number of rounds depending on the key s= ize: + * 128-bits: 10 + * 192-bits: 12 + * 256-bits: 14 + So 6 + (n/4) rounds + + @param [in] AesCtx AES context struct. + + @return Number of rounds. +**/ +STATIC +UINT32 +GetNumRounds ( + IN AES_CTX CONST *AesCtx + ) +{ + return 6 + (AesCtx->KeySize >> 2); +} + +/** Encrypt an AES block. + + Buffers are little-endian. Overlapping is not checked. + + @param [in] AesCtx AES context. + AesCtx is initialized with AesInitCtx (). + @param [in] InBlock Input Block. The block to cipher. + @param [out] OutBlock Output Block. The ciphered block. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Unsupported. +**/ +RETURN_STATUS +EFIAPI +AesEncrypt ( + IN AES_CTX *AesCtx, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ) +{ + if ((AesCtx =3D=3D NULL) || + (InBlock =3D=3D NULL) || + (OutBlock =3D=3D NULL) || + (InBlock =3D=3D OutBlock)) + { + ASSERT (AesCtx !=3D NULL); + ASSERT (InBlock !=3D NULL); + ASSERT (OutBlock !=3D NULL); + ASSERT (InBlock !=3D OutBlock); + return RETURN_INVALID_PARAMETER; + } + + ArmAesEncrypt ( + AesCtx->ExpEncKey, + GetNumRounds (AesCtx), + InBlock, + OutBlock + ); + + return RETURN_SUCCESS; +} + +/** Decrypt an AES block. + + Buffers are little-endian. Overlapping is not checked. + + @param [in] AesCtx AES context. + AesCtx is initialized with AesInitCtx (). + @param [in] InBlock Input Block. The block to de-cipher. + @param [out] OutBlock Output Block. The de-ciphered block. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Unsupported. +**/ +RETURN_STATUS +EFIAPI +AesDecrypt ( + IN AES_CTX *AesCtx, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ) +{ + if ((AesCtx =3D=3D NULL) || + (InBlock =3D=3D NULL) || + (OutBlock =3D=3D NULL) || + (InBlock =3D=3D OutBlock)) + { + ASSERT (AesCtx !=3D NULL); + ASSERT (InBlock !=3D NULL); + ASSERT (OutBlock !=3D NULL); + ASSERT (InBlock !=3D OutBlock); + return RETURN_INVALID_PARAMETER; + } + + ArmAesDecrypt ( + AesCtx->ExpDecKey, + GetNumRounds (AesCtx), + InBlock, + OutBlock + ); + + return RETURN_SUCCESS; +} + +/** Initialize an AES_CTX structure. + + @param [in] Key AES key. Buffer of KeySize bytes. + The buffer is little endian. + @param [in] KeySize Size of the key. Must be one of 128|192|256. + @param [in, out] AesCtx AES context to initialize. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Unsupported. +**/ +RETURN_STATUS +EFIAPI +AesInitCtx ( + IN UINT8 *Key, + IN UINT32 KeySize, + IN OUT AES_CTX *AesCtx + ) +{ + UINTN Index; + UINTN RevIndex; + UINT32 KeyWords; + UINT32 *KeyIn; + UINT32 *KeyOut; + AES_BLOCK *InBlock; + AES_BLOCK *OutBlock; + + if ((Key =3D=3D NULL) || + ((KeySize !=3D 8 * AES_KEY_SIZE_128) && + (KeySize !=3D 8 * AES_KEY_SIZE_192) && + (KeySize !=3D 8 * AES_KEY_SIZE_256)) || + (AesCtx =3D=3D NULL)) + { + ASSERT (Key !=3D NULL); + ASSERT ( + !((KeySize !=3D 8 * AES_KEY_SIZE_128) && + (KeySize !=3D 8 * AES_KEY_SIZE_192) && + (KeySize !=3D 8 * AES_KEY_SIZE_256)) + ); + ASSERT (AesCtx !=3D NULL); + return RETURN_INVALID_PARAMETER; + } + + // Internally, use bytes. + KeySize =3D KeySize >> 3; + AesCtx->KeySize =3D KeySize; + KeyWords =3D KeySize >> 2; + + // The first part of the expanded key is the input key. + for (Index =3D 0; Index < KeyWords; Index++) { + AesCtx->ExpEncKey[Index] =3D ReadUnaligned32 ( + (UINT32 *)(Key + (Index * sizeof (UINT32)= )) + ); + } + + for (Index =3D 0; Index < sizeof (mRoundConstants); Index++) { + KeyIn =3D AesCtx->ExpEncKey + (Index * KeyWords); + KeyOut =3D KeyIn + KeyWords; + + KeyOut[0] =3D ArmAesSubWord (RRotU32 (KeyIn[KeyWords - 1], 8)); + KeyOut[0] ^=3D mRoundConstants[Index] ^ KeyIn[0]; + KeyOut[1] =3D KeyOut[0] ^ KeyIn[1]; + KeyOut[2] =3D KeyOut[1] ^ KeyIn[2]; + KeyOut[3] =3D KeyOut[2] ^ KeyIn[3]; + + if (KeySize =3D=3D AES_KEY_SIZE_192) { + if (Index >=3D 7) { + break; + } + + KeyOut[4] =3D KeyOut[3] ^ KeyIn[4]; + KeyOut[5] =3D KeyOut[4] ^ KeyIn[5]; + } else if (KeySize =3D=3D AES_KEY_SIZE_256) { + if (Index >=3D 6) { + break; + } + + KeyOut[4] =3D ArmAesSubWord (KeyOut[3]) ^ KeyIn[4]; + KeyOut[5] =3D KeyOut[4] ^ KeyIn[5]; + KeyOut[6] =3D KeyOut[5] ^ KeyIn[6]; + KeyOut[7] =3D KeyOut[6] ^ KeyIn[7]; + } + } + + /* + * Generate the decryption key for the Equivalent Inverse Cipher. + * First and last state of the expanded encryption key are copied + * to the expanded decryption key. + * The other ones are copied bottom up from the expanded encryption + * key and undergo an InvMixColumns(). + */ + InBlock =3D (AES_BLOCK *)AesCtx->ExpEncKey; + OutBlock =3D (AES_BLOCK *)AesCtx->ExpDecKey; + RevIndex =3D GetNumRounds (AesCtx); + + CopyMem (&OutBlock[0], &InBlock[RevIndex], sizeof (AES_BLOCK)); + for (Index =3D 1, RevIndex--; RevIndex > 0; Index++, RevIndex--) { + ArmAesInvert (OutBlock + Index, InBlock + RevIndex); + } + + CopyMem (&OutBlock[Index], &InBlock[0], sizeof (AES_BLOCK)); + + return RETURN_SUCCESS; +} diff --git a/ArmPkg/Library/ArmAesLib/ArmAesLib.h b/ArmPkg/Library/ArmAesLi= b/ArmAesLib.h new file mode 100644 index 000000000000..dd926491a816 --- /dev/null +++ b/ArmPkg/Library/ArmAesLib/ArmAesLib.h @@ -0,0 +1,96 @@ +/** @file + Arm AES Library + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - FIPS 197 November 26, 2001: + Specification for the ADVANCED ENCRYPTION STANDARD (AES) +**/ + +#ifndef ARM_AES_LIB_H_ +#define ARM_AES_LIB_H_ + +/* An AES block is 128-bits long and can be seen as a matrix of 4 * 4 byte= s. + */ +typedef struct AesBlock { + /// The AES block. + UINT8 Block[AES_BLOCK_SIZE]; +} AES_BLOCK; + +/** Encrypt an AES block. + + @param [in] ExpEncKey Expanded encryption key. An array of 32-bits wor= ds + with the number of elements depending on the key + size: + * 128-bits: 44 words + * 192-bits: 52 words + * 256-bits: 60 words + @param [in] Rounds Number of rounds (depending on the key size). + @param [in] InBlock Input Block. The block to cipher. + @param [out] OutBlock Output Block. The ciphered block. +**/ +VOID +ArmAesEncrypt ( + IN UINT32 CONST *ExpEncKey, + IN UINT32 Rounds, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ); + +/** Decrypt an AES 128-bits block. + + @param [in] ExpDecKey Expanded decryption key. An array of 32-bits wor= ds + with the number of elements depending on the key + size: + * 128-bits: 44 words + * 192-bits: 52 words + * 256-bits: 60 words + @param [in] Rounds Number of rounds (depending on the key size). + @param [in] InBlock Input Block. The block to de-cipher. + @param [out] OutBlock Output Block. The de-ciphered block. +**/ +VOID +ArmAesDecrypt ( + IN UINT32 CONST *ExpDecKey, + IN UINT32 Rounds, + IN UINT8 CONST *InBlock, + OUT UINT8 *OutBlock + ); + +/** Perform a SubWord() operation (applying AES Sbox) on a 32-bits word. + + The Arm AESE instruction performs the AddRoundKey(), ShiftRows() and + SubBytes() AES steps in this order. + + During key expansion, only SubBytes() should be performed, so: + - use a key of {0} so AddRoundKey() becomes an identity function; + - the dup instruction allows to have a matrix with identic rows, + so ShiftRows() has no effect. + + @param [in] InWord The 32-bits word to apply SubWord() on. + + @return SubWord(word). +**/ +UINT32 +ArmAesSubWord ( + IN UINT32 InWord + ); + +/** Perform a InvMixColumns() operation on an AES block (128-bits) using + the Arm AESIMC instruction. + + This is usefull to get decryption key for the Equivalent Inverse Cipher. + + @param [in] InBlock Input block. + @param [out] OutBlock Output blocked. +**/ +VOID +ArmAesInvert ( + IN AES_BLOCK CONST *InBlock, + OUT AES_BLOCK *OutBlock + ); + +#endif // ARM_AES_LIB_H_ diff --git a/ArmPkg/Library/ArmAesLib/ArmAesLib.inf b/ArmPkg/Library/ArmAes= Lib/ArmAesLib.inf new file mode 100644 index 000000000000..73c664a9f888 --- /dev/null +++ b/ArmPkg/Library/ArmAesLib/ArmAesLib.inf @@ -0,0 +1,34 @@ +## @file +# AES Library +# +# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D ArmAesLib + FILE_GUID =3D 585599F7-DA62-44F5-BA20-3D50AEF638B4 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D AesLib + CONSTRUCTOR =3D AesLibConstructor + +[Sources] + ArmAesLib.c + ArmAesLib.h + +[Sources.ARM] + Arm/ArmAesLib.S + +[Sources.AARCH64] + AArch64/AArch64AesLib.S + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmLib + BaseLib --=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 (#90897): https://edk2.groups.io/g/devel/message/90897 Mute This Topic: https://groups.io/mt/92072171/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-