From nobody Wed Feb 11 01:00:00 2026 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+90883+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+90883+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515284; cv=none; d=zohomail.com; s=zohoarc; b=dP1XJ58R1ZXddRKannF7YebPMH98KAVqq49jIA+74jUqycM15PEta7a3zb/BWQnLl0T3XDJy4vcDx+HV9VgHfrS2Uvog8rOwQdHhyMjKzeV6o+J+b2P659evs5/f5ykndBXgBPDxYOx5ZFU9yc6fDntHtv9E/zrkMQuzqSQKTzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515284; 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=5ZgtyRFY1EjGvhlfLJAo70ScgzGru/Vq1RpThncoJFM=; b=Ll90M1g/25oin83EnI/Jg/h6mSuiWnwLo2kZNIyJrhFwr1kQdD/tAgeyLs+BpQ/KcJiPPIOU+0MDIyIGndreLD0RxM9aKz+yVlXYWahwhw0a4jgDDck2dQlO/2zJJkbQ5Ebwfx9kFCGHHNKIn40CR+qSzSwy2wzWQ6SEBJ7khMY= 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+90883+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 1656515284693165.63953648153802; Wed, 29 Jun 2022 08:08:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Ph99YY1788612xo2u2YqBHH3; Wed, 29 Jun 2022 08:08:04 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12776.1656515283539439382 for ; Wed, 29 Jun 2022 08:08:03 -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 689861764; Wed, 29 Jun 2022 08:08:03 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5197D3F93E; Wed, 29 Jun 2022 08:08:01 -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 v1 5/7] MdePkg/AesLib: Definition for AES library class interface Date: Wed, 29 Jun 2022 17:07:11 +0200 Message-Id: <20220629150713.2600465-6-Pierre.Gondois@arm.com> In-Reply-To: <20220629150713.2600465-1-Pierre.Gondois@arm.com> References: <20220629150713.2600465-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: ZxKo1cOe2YuNrlEegYPbdj73x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515284; bh=nN2vwX0ajobyU1UGiOsmoeA2bMPZmpEe220qLVTnf6s=; h=Cc:Date:From:Reply-To:Subject:To; b=LUb60zatzlMC0gsF9LXNIABLBdyYKEpNFLA3Nq/yj5ve3iW1jL37YXxezI+HLIVes5U K8+2ehn38+AG+Dhy/Zet5/wlyD8nyg713DzehnYC5bKtaUr6WynZcQ0jIN+6QFbTQDIaC e/6v4PsE5hdeQqvf9tHZzEpXSYwGuhMPaCQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515286169100013 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 (#90883): https://edk2.groups.io/g/devel/message/90883 Mute This Topic: https://groups.io/mt/92066833/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-