]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: dm: add AES engine test
authorSvyatoslav Ryhel <clamor95@gmail.com>
Sun, 29 Jun 2025 10:57:11 +0000 (13:57 +0300)
committerTom Rini <trini@konsulko.com>
Fri, 11 Jul 2025 16:43:29 +0000 (10:43 -0600)
Create a basic test suit for AES DM uclass that covers all available
operations.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
arch/sandbox/dts/test.dts
configs/sandbox64_defconfig
configs/sandbox_defconfig
configs/sandbox_flattree_defconfig
test/dm/Makefile
test/dm/aes.c [new file with mode: 0644]

index 7026c73bc69810135e9796f0c57b2e9e7a17059a..bb696c5ef7f4038150b4af2fcd9e84bd565a7c6b 100644 (file)
                        };
                };
        };
+
+       aes-engine {
+               compatible = "software-aes-engine";
+       };
 };
 
 #include "sandbox_pmic.dtsi"
index 34e89bf6b3ed0ec0cd40d38ec8bde86eca6cf308..8fdc581c205dfc842b8d243120daec11b3e2846e 100644 (file)
@@ -137,6 +137,8 @@ CONFIG_CLK_K210=y
 CONFIG_CLK_K210_SET_RATE=y
 CONFIG_SANDBOX_CLK_CCF=y
 CONFIG_CPU=y
+CONFIG_DM_AES=y
+CONFIG_AES_SOFTWARE=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
index 4f6943d1a4bfb974df50432fb71284dc6563f0c2..602397430f09a3a04395593c1cfb50eb81e66e89 100644 (file)
@@ -186,6 +186,8 @@ CONFIG_CLK_K210_SET_RATE=y
 CONFIG_SANDBOX_CLK_CCF=y
 CONFIG_CLK_SCMI=y
 CONFIG_CPU=y
+CONFIG_DM_AES=y
+CONFIG_AES_SOFTWARE=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
index 67c0ed7353efc252cb31b31d94415f37a1f74c99..317d7dc9c20d575278d340a7c0a6534e25c4703d 100644 (file)
@@ -75,6 +75,7 @@ CONFIG_CMD_QFW=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
+CONFIG_CMD_AES=y
 CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
 CONFIG_CMD_EXT4_WRITE=y
@@ -115,6 +116,8 @@ CONFIG_CLK_K210=y
 CONFIG_CLK_K210_SET_RATE=y
 CONFIG_SANDBOX_CLK_CCF=y
 CONFIG_CPU=y
+CONFIG_DM_AES=y
+CONFIG_AES_SOFTWARE=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
index 917dafe7d228a51fa58eab09445c2c12a4aa41b0..d15859eca30498e24d666228ad8805402c27070c 100644 (file)
@@ -29,6 +29,7 @@ obj-(CONFIG_DM_GPIO) += gpio.o
 obj-y += irq.o
 endif
 obj-$(CONFIG_ADC) += adc.o
+obj-$(CONFIG_AES_SOFTWARE) += aes.o
 obj-$(CONFIG_SOUND) += audio.o
 obj-$(CONFIG_AXI) += axi.o
 obj-$(CONFIG_BLK) += blk.o
diff --git a/test/dm/aes.c b/test/dm/aes.c
new file mode 100644 (file)
index 0000000..702e4db
--- /dev/null
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for the driver model AES API
+ *
+ * Copyright (c) 2025 Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <uboot_aes.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+#define AES128_KEYSIZE         128
+
+static int dm_test_aes(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       u8 test_key[AES128_KEY_LENGTH] = { 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+                                          0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69 };
+       u8 test_iv[AES128_KEY_LENGTH] = { 0 };
+
+       u8 test_input[AES_BLOCK_LENGTH] = { 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+                                           0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65 };
+       u8 exp_output[AES_BLOCK_LENGTH] = { 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
+                                           0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84 };
+       u8 exp_cmac[AES_BLOCK_LENGTH] = { 0xfc, 0x89, 0x20, 0xc8, 0x46, 0x97, 0xb1, 0x3d,
+                                         0x31, 0x2c, 0xc2, 0x49, 0x5c, 0x5a, 0x0b, 0x9f };
+       u8 test_output[AES_BLOCK_LENGTH];
+
+       ut_assertok(uclass_first_device_err(UCLASS_AES, &dev));
+
+       /* software AES exposes 2 key slots */
+       ut_asserteq(2, dm_aes_get_available_key_slots(dev));
+
+       ut_assertok(dm_aes_select_key_slot(dev, AES128_KEYSIZE, 0));
+       ut_assertok(dm_aes_set_key_for_key_slot(dev, AES128_KEYSIZE, test_key, 0));
+
+       ut_assertok(dm_aes_ecb_encrypt(dev, test_input, test_output, 1));
+       ut_assertok(memcmp(exp_output, test_output, 16));
+
+       ut_assertok(dm_aes_ecb_decrypt(dev, test_output, test_output, 1));
+       ut_assertok(memcmp(test_input, test_output, 16));
+
+       ut_assertok(dm_aes_cbc_encrypt(dev, test_iv, test_input, test_output, 1));
+       ut_assertok(memcmp(exp_output, test_output, 16));
+
+       ut_assertok(dm_aes_cbc_decrypt(dev, test_iv, test_output, test_output, 1));
+       ut_assertok(memcmp(test_input, test_output, 16));
+
+       ut_assertok(dm_aes_cmac(dev, test_input, test_output, 1));
+       ut_assertok(memcmp(exp_cmac, test_output, 16));
+
+       return 0;
+}
+
+DM_TEST(dm_test_aes, UTF_SCAN_FDT);