public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 0/7] Add AesLib and ArmAesLib
@ 2022-06-29 15:07 PierreGondois
  2022-06-29 15:07 ` [PATCH v1 1/7] ArmPkg: Update Armpkg.ci.yaml PierreGondois
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:07 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Leif Lindholm, Ard Biesheuvel, Rebecca Cran,
	Michael D Kinney, Liming Gao, Edward Pickup

From: Pierre Gondois <pierre.gondois@arm.com>

Bugzilla: Bug 3970 (https://bugzilla.tianocore.org/show_bug.cgi?id=3970)

To fasten AES encryption/decryption process or create a
Deterministic Random Bits Generator (Drbg), add a library using
Arm's AES instructions (AESE AESD, AESMC, AESIMC).

The test vectors available in the CTR_DRBG_AES256 sections of
https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/CTR_DRBG_noDF.pdf
were used for validation. Indeed, the Drbg implementation in a
following patch-set relies on the AES encryption.

This patch-set can seen at:
https://github.com/PierreARM/edk2/tree/Arm_Aes_v1

This patch has the following dependency:
- [PATCH v3 00/22] Add Raw algorithm support using Arm FW-TRNG interface
  https://edk2.groups.io/g/devel/message/90845


Pierre Gondois (7):
  ArmPkg: Update Armpkg.ci.yaml
  ArmPkg/ArmDisassemblerLib: Replace RotateRight()
  ArmPkg/ArmLib: Add ArmReadIdIsaR5() helper
  ArmPkg/ArmLib: Add ArmHasAesExt()
  MdePkg/AesLib: Definition for AES library class interface
  MdePkg/AesLib: Add NULL instance of AesLib
  ArmPkg/ArmAesLib: Add ArmAesLib

 ArmPkg/ArmPkg.ci.yaml                         |   1 +
 ArmPkg/ArmPkg.dsc                             |   3 +-
 ArmPkg/Include/Library/ArmLib.h               |  12 +-
 .../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 +++
 .../ArmDisassemblerLib/ArmDisassembler.c      |  11 +-
 ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c    |  13 +
 ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h    |   1 +
 ArmPkg/Library/ArmLib/Arm/ArmLibSupport.S     |   7 +-
 ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c          |  13 +
 ArmPkg/Library/ArmLib/Arm/ArmV7Lib.h          |  13 +
 MdePkg/Include/Library/AesLib.h               | 104 +++++++
 MdePkg/Library/AesLibNull/AesLibNull.c        |  87 ++++++
 MdePkg/Library/AesLibNull/AesLibNull.inf      |  24 ++
 MdePkg/MdePkg.dec                             |   4 +
 MdePkg/MdePkg.dsc                             |   1 +
 19 files changed, 1038 insertions(+), 13 deletions(-)
 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
 create mode 100644 MdePkg/Include/Library/AesLib.h
 create mode 100644 MdePkg/Library/AesLibNull/AesLibNull.c
 create mode 100644 MdePkg/Library/AesLibNull/AesLibNull.inf

-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 1/7] ArmPkg: Update Armpkg.ci.yaml
  2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
@ 2022-06-29 15:07 ` PierreGondois
  2022-06-29 15:07 ` [PATCH v1 2/7] ArmPkg/ArmDisassemblerLib: Replace RotateRight() PierreGondois
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:07 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Leif Lindholm, Ard Biesheuvel, Rebecca Cran,
	Michael D Kinney, Liming Gao, Edward Pickup

From: Pierre Gondois <Pierre.Gondois@arm.com>

Add word to the exception list for the spell check tool.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 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",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 2/7] ArmPkg/ArmDisassemblerLib: Replace RotateRight()
  2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
  2022-06-29 15:07 ` [PATCH v1 1/7] ArmPkg: Update Armpkg.ci.yaml PierreGondois
@ 2022-06-29 15:07 ` PierreGondois
  2022-06-29 15:07 ` [PATCH v1 3/7] ArmPkg/ArmLib: Add ArmReadIdIsaR5() helper PierreGondois
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:07 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Leif Lindholm, Ard Biesheuvel, Rebecca Cran,
	Michael D Kinney, Liming Gao, Edward Pickup

From: Pierre Gondois <Pierre.Gondois@arm.com>

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 <pierre.gondois@arm.com>
---
 ArmPkg/Library/ArmDisassemblerLib/ArmDisassembler.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/ArmPkg/Library/ArmDisassemblerLib/ArmDisassembler.c b/ArmPkg/Library/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 "";
 }
 
-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{<cond>} CPSR_<fields>, #<immediate> MSR{<cond>} CPSR_<fields>, <Rm>
     if (Imm) {
       // MSR{<cond>} CPSR_<fields>, #<immediate>
-      AsciiSPrint (Buf, Size, "MRS%a %a_%a, #0x%x", COND (OpCode), WriteBack ? "SPSR" : "CPSR", FieldMask ((OpCode >> 16) & 0xf), RotateRight (OpCode & 0xf, ((OpCode >> 8) & 0xf) *2));
+      AsciiSPrint (Buf, Size, "MRS%a %a_%a, #0x%x", COND (OpCode), WriteBack ? "SPSR" : "CPSR", FieldMask ((OpCode >> 16) & 0xf), RRotU32 (OpCode & 0xf, ((OpCode >> 8) & 0xf) *2));
     } else {
       // MSR{<cond>} CPSR_<fields>, <Rm>
       AsciiSPrint (Buf, Size, "MRS%a %a_%a, %a", COND (OpCode), WriteBack ? "SPSR" : "CPSR", gReg[Rd]);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 3/7] ArmPkg/ArmLib: Add ArmReadIdIsaR5() helper
  2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
  2022-06-29 15:07 ` [PATCH v1 1/7] ArmPkg: Update Armpkg.ci.yaml PierreGondois
  2022-06-29 15:07 ` [PATCH v1 2/7] ArmPkg/ArmDisassemblerLib: Replace RotateRight() PierreGondois
@ 2022-06-29 15:07 ` PierreGondois
  2022-06-29 15:07 ` [PATCH v1 4/7] ArmPkg/ArmLib: Add ArmHasAesExt() PierreGondois
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:07 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Leif Lindholm, Ard Biesheuvel, Rebecca Cran,
	Michael D Kinney, Liming Gao, Edward Pickup

From: Pierre Gondois <Pierre.Gondois@arm.com>

Add a ArmReadIdIsaR5() helper function to access the AArch32
ID_ISAR5 register.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 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/ArmLib/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.<BR>
-# 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
 
+// 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/Arm/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
 
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+  Copyright (c) 2022, Arm Ltd. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -66,4 +67,14 @@ ArmReadIdPfr1 (
   VOID
   );
 
+/** Reads the ID_ISAR5 register.
+
+   @return The contents of the ID_ISAR5 register.
+**/
+UINTN
+EFIAPI
+ArmReadIdIsaR5 (
+  VOID
+  );
+
 #endif // ARM_V7_LIB_H_
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 4/7] ArmPkg/ArmLib: Add ArmHasAesExt()
  2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
                   ` (2 preceding siblings ...)
  2022-06-29 15:07 ` [PATCH v1 3/7] ArmPkg/ArmLib: Add ArmReadIdIsaR5() helper PierreGondois
@ 2022-06-29 15:07 ` PierreGondois
  2022-06-29 15:07 ` [PATCH v1 5/7] MdePkg/AesLib: Definition for AES library class interface PierreGondois
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:07 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Leif Lindholm, Ard Biesheuvel, Rebecca Cran,
	Michael D Kinney, Liming Gao, Edward Pickup

From: Pierre Gondois <Pierre.Gondois@arm.com>

Add a ArmHasAesExt() to check for the FEAT_AES extension.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 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/ArmLib.h
index 8058634dbc53..5cd2bc1a26e5 100644
--- a/ArmPkg/Include/Library/ArmLib.h
+++ b/ArmPkg/Include/Library/ArmLib.h
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  Copyright (c) 2011 - 2022, Arm Limited. All rights reserved.<BR>
+  Copyright (c) 2011 - 2022, Arm Ltd. All rights reserved.<BR>
   Copyright (c) 2020 - 2021, NUVIA Inc. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -779,6 +779,16 @@ ArmHasRngExt (
   VOID
   );
 
+/** 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/ArmLib/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/ArmLib/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_
 
+#define ID_AA64ISAR0_EL1_AES_MASK   ((UINT64)0xF << 4U)
 #define ID_AA64ISAR0_EL1_RNDR_MASK  ((UINT64)0xF << 60U)
 
 typedef VOID (*AARCH64_CACHE_OPERATION)(
diff --git a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c b/ArmPkg/Library/ArmLib/Arm/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/Arm/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_
 
+#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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 5/7] MdePkg/AesLib: Definition for AES library class interface
  2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
                   ` (3 preceding siblings ...)
  2022-06-29 15:07 ` [PATCH v1 4/7] ArmPkg/ArmLib: Add ArmHasAesExt() PierreGondois
@ 2022-06-29 15:07 ` PierreGondois
  2022-06-29 15:07 ` [PATCH v1 6/7] MdePkg/AesLib: Add NULL instance of AesLib PierreGondois
  2022-06-29 15:22 ` [edk2-devel] [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
  6 siblings, 0 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:07 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Leif Lindholm, Ard Biesheuvel, Rebecca Cran,
	Michael D Kinney, Liming Gao, Edward Pickup

From: Pierre Gondois <Pierre.Gondois@arm.com>

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3970

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 <pierre.gondois@arm.com>
---
 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/AesLib.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.<BR>
+
+  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 = 4:
+      Number of columns (32-bit words) comprising the State
+    - Nr = 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
 
+  ##  @libraryclass  Provides AES encryption/decryption services.
+  #
+  AesLib|Include/Library/AesLib.h
+
 [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
   ##  @libraryclass  Provides services to generate random number.
   #
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 6/7] MdePkg/AesLib: Add NULL instance of AesLib
  2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
                   ` (4 preceding siblings ...)
  2022-06-29 15:07 ` [PATCH v1 5/7] MdePkg/AesLib: Definition for AES library class interface PierreGondois
@ 2022-06-29 15:07 ` PierreGondois
  2022-06-29 15:22 ` [edk2-devel] [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
  6 siblings, 0 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:07 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Leif Lindholm, Ard Biesheuvel, Rebecca Cran,
	Michael D Kinney, Liming Gao, Edward Pickup

From: Pierre Gondois <Pierre.Gondois@arm.com>

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3970

The FIPS PUB 197: "Advanced Encryption Standard (AES)"
details the AES algorithm.

Add an AesLibNull implementation.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 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/AesLibNull/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.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Reference(s):
+   - FIPS 197 November 26, 2001:
+     Specification for the ADVANCED ENCRYPTION STANDARD (AES)
+**/
+
+#include <Library/AesLib.h>
+#include <Library/DebugLib.h>
+
+/** 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/AesLibNull/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.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION    = 0x0001001B
+  BASE_NAME      = AesLibNull
+  FILE_GUID      = F6DED279-FC26-40F6-88B2-05FF5E6E538F
+  VERSION_STRING = 1.0
+  MODULE_TYPE    = DXE_DRIVER
+  LIBRARY_CLASS  = 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
 
   MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
   MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH v1 0/7] Add AesLib and ArmAesLib
  2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
                   ` (5 preceding siblings ...)
  2022-06-29 15:07 ` [PATCH v1 6/7] MdePkg/AesLib: Add NULL instance of AesLib PierreGondois
@ 2022-06-29 15:22 ` PierreGondois
  6 siblings, 0 replies; 8+ messages in thread
From: PierreGondois @ 2022-06-29 15:22 UTC (permalink / raw)
  To: PierreGondois, devel

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

This patch-set is incomplete. I will (re-)send the remaining patches later today as there is a limit in the number of messages that can be sent to <devel@edk2.groups.io>

<devel@edk2.groups.io> ( devel@edk2.groups.io ) : host lb01.groups.io[45.79.81.153] said: 500 We have
   received more than 40 messages in 30 minutes from you. To guard against
   autoresponder mail loops, we must reject additional messages from you
   temporarily. Please try again later. (in reply to RCPT TO command)

Regards,
Pierre

[-- Attachment #2: Type: text/html, Size: 631 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-29 15:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-29 15:07 [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois
2022-06-29 15:07 ` [PATCH v1 1/7] ArmPkg: Update Armpkg.ci.yaml PierreGondois
2022-06-29 15:07 ` [PATCH v1 2/7] ArmPkg/ArmDisassemblerLib: Replace RotateRight() PierreGondois
2022-06-29 15:07 ` [PATCH v1 3/7] ArmPkg/ArmLib: Add ArmReadIdIsaR5() helper PierreGondois
2022-06-29 15:07 ` [PATCH v1 4/7] ArmPkg/ArmLib: Add ArmHasAesExt() PierreGondois
2022-06-29 15:07 ` [PATCH v1 5/7] MdePkg/AesLib: Definition for AES library class interface PierreGondois
2022-06-29 15:07 ` [PATCH v1 6/7] MdePkg/AesLib: Add NULL instance of AesLib PierreGondois
2022-06-29 15:22 ` [edk2-devel] [PATCH v1 0/7] Add AesLib and ArmAesLib PierreGondois

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox