Skip to contentSkip to conversation

pytest: add a simple test to check the command aes

PATCH New Philippe Reynes 3 participants 12 messages Sep 24, 2019 – Sep 27, 2019

lore
Share & tools
lore
#0 lore raw

v3 cover pytest: add a simple test to check the command aes

This serie fix the command aes on sandbox and add a simple pytest for aes.

The first and second patch enable the command aes on sandbox and sandbox64. Thr third patch fix the command aes on sandbox (adding map_sysmem to avoid a segfault), the forth patch add a simple pytest for the command aes.

Philippe Reynes (4):
sandbox: enable command aes
sandbox64: enable command aes
cmd: aes: use map_sysmem when accessing memory
pytest: add a new test for aes

Changelog:
v3:
- add unmap_sysmem (thanks Simon)
v2:
- add binary file (key128.bin, iv128.bin and plaintext.bin)

 cmd/aes.c                       | 14 ++++++++----
 configs/sandbox64_defconfig     |  1 +
 configs/sandbox_defconfig       |  1 +
 test/py/tests/aes/iv128.bin     |  1 +
 test/py/tests/aes/key128.bin    |  1 +
 test/py/tests/aes/plaintext.bin |  1 +
 test/py/tests/test_aes.py       | 48 +++++++++++++++++++++++++++++++++++++++++
 7 files changed, 63 insertions(+), 4 deletions(-)
 create mode 100644 test/py/tests/aes/iv128.bin
 create mode 100644 test/py/tests/aes/key128.bin
 create mode 100644 test/py/tests/aes/plaintext.bin
 create mode 100644 test/py/tests/test_aes.py
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/4 sandbox: enable command aes

This commit enable the command aes on sandbox.
Then, it may be used on pytest.

---
 configs/sandbox_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
index f77b9e8..4b9cce5 100644
@@ -67,6 +67,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_BTRFS=y
Signature · 1 line
2.7.4
#4 lore raw

PATCH v3 2/4 sandbox64: enable command aes

In reply to Philippe Reynes

This commit add the support of command aes.
Then, it may be used on pytest.

---
 configs/sandbox64_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/sandbox64_defconfig +1 -0
index 7aa2d38..1fea683 100644
@@ -59,6 +59,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_BTRFS=y
Signature · 1 line
2.7.4
#7 lore raw

PATCH v3 3/4 cmd: aes: use map_sysmem when accessing memory

In reply to Philippe Reynes

The aes command used to segfault when accessing memory in sandbox. The pointer accesses should be mapped.

---
 cmd/aes.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
cmd/aes.c +10 -4
index 7ff4a71..8c61cee 100644
@@ -11,6 +11,7 @@
 #include <malloc.h>
 #include <asm/byteorder.h>
 #include <linux/compiler.h>
+#include <mapmem.h>
 
 /**
  * do_aes() - Handle the "aes" command-line command
@@ -46,10 +47,10 @@ static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 	dst_addr = simple_strtoul(argv[5], NULL, 16);
 	len = simple_strtoul(argv[6], NULL, 16);
 
-	key_ptr = (uint8_t *)key_addr;
-	iv_ptr = (uint8_t *)iv_addr;
-	src_ptr = (uint8_t *)src_addr;
-	dst_ptr = (uint8_t *)dst_addr;
+	key_ptr = (uint8_t *)map_sysmem(key_addr, 128 / 8);
+	iv_ptr = (uint8_t *)map_sysmem(iv_addr, 128 / 8);
+	src_ptr = (uint8_t *)map_sysmem(src_addr, len);
+	dst_ptr = (uint8_t *)map_sysmem(dst_addr, len);
 
 	/* First we expand the key. */
 	aes_expand_key(key_ptr, key_exp);
@@ -64,6 +65,11 @@ static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 		aes_cbc_decrypt_blocks(key_exp, iv_ptr, src_ptr, dst_ptr,
 				       aes_blocks);
 
+	unmap_sysmem(key_ptr);
+	unmap_sysmem(iv_ptr);
+	unmap_sysmem(src_ptr);
+	unmap_sysmem(dst_ptr);
+
 	return 0;
 }
 
Signature · 1 line
2.7.4
#8 lore raw

PATCH v3 3/4 cmd: aes: use map_sysmem when accessing memory

Quoted 8 lines · Philippe Reynes

The aes command used to segfault when accessing memory in sandbox. The pointer accesses should be mapped.

---
 cmd/aes.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

I don't see change logs on these patches. Do you use patman?

Regards,
SImon

#9 lore raw

PATCH v3 3/4 cmd: aes: use map_sysmem when accessing memory

Quoted 8 lines · Philippe Reynes

The aes command used to segfault when accessing memory in sandbox. The pointer accesses should be mapped.

---
 cmd/aes.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

I don't see change logs on these patches. Do you use patman?

Regards,
SImon

Applied to u-boot-dm/next, thanks!

#10 lore raw

PATCH v3 4/4 pytest: add a new test for aes

In reply to Philippe Reynes

This commit add a simple test to check that
a text may be ciphered and unciphered. Each
step are checked with the known result.

---
 test/py/tests/aes/iv128.bin     |  1 +
 test/py/tests/aes/key128.bin    |  1 +
 test/py/tests/aes/plaintext.bin |  1 +
 test/py/tests/test_aes.py       | 48 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 test/py/tests/aes/iv128.bin
 create mode 100644 test/py/tests/aes/key128.bin
 create mode 100644 test/py/tests/aes/plaintext.bin
 create mode 100644 test/py/tests/test_aes.py
test/py/tests/aes/iv128.bin new file +1 -0
new file mode 100644
index 0000000..b7b5d5d
@@ -0,0 +1 @@
+�!�/���a�P���r
\ No newline at end of file
test/py/tests/aes/key128.bin new file +1 -0
new file mode 100644
index 0000000..9e3ce60
@@ -0,0 +1 @@
+����Ć皳���6}
\ No newline at end of file
test/py/tests/aes/plaintext.bin new file +1 -0
new file mode 100644
index 0000000..8598fd9
@@ -0,0 +1 @@
+AES128 is working, amazing !!!!!
\ No newline at end of file
test/py/tests/test_aes.py new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.7.4
#11 lore raw

PATCH v3 4/4 pytest: add a new test for aes

Quoted 6 lines · Philippe Reynes

This commit add a simple test to check that
a text may be ciphered and unciphered. Each
step are checked with the known result.

Quoted 10 lines
---
 test/py/tests/aes/iv128.bin     |  1 +
 test/py/tests/aes/key128.bin    |  1 +
 test/py/tests/aes/plaintext.bin |  1 +
 test/py/tests/test_aes.py       | 48 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 test/py/tests/aes/iv128.bin
 create mode 100644 test/py/tests/aes/key128.bin
 create mode 100644 test/py/tests/aes/plaintext.bin
 create mode 100644 test/py/tests/test_aes.py