All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH V2 0/4] pytest: add a simple test to check the command aes
@ 2019-09-23 16:39 Philippe Reynes
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 1/4] sandbox: enable " Philippe Reynes
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Philippe Reynes @ 2019-09-23 16:39 UTC (permalink / raw)
  To: u-boot

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:
v2:
- add binary file (key128.bin, iv128.bin and plaintext.bin)

 cmd/aes.c                       |  9 ++++----
 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, 58 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

-- 
2.7.4

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

* [U-Boot] [PATCH V2 1/4] sandbox: enable command aes
  2019-09-23 16:39 [U-Boot] [PATCH V2 0/4] pytest: add a simple test to check the command aes Philippe Reynes
@ 2019-09-23 16:39 ` Philippe Reynes
  2019-10-21 15:25   ` Simon Glass
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 2/4] sandbox64: " Philippe Reynes
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Philippe Reynes @ 2019-09-23 16:39 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
 configs/sandbox_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 968ffda..d5872dd 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -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
-- 
2.7.4

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

* [U-Boot] [PATCH V2 2/4] sandbox64: enable command aes
  2019-09-23 16:39 [U-Boot] [PATCH V2 0/4] pytest: add a simple test to check the command aes Philippe Reynes
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 1/4] sandbox: enable " Philippe Reynes
@ 2019-09-23 16:39 ` Philippe Reynes
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 3/4] cmd: aes: use map_sysmem when accessing memory Philippe Reynes
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 4/4] pytest: add a new test for aes Philippe Reynes
  3 siblings, 0 replies; 7+ messages in thread
From: Philippe Reynes @ 2019-09-23 16:39 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
 configs/sandbox64_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index c177ff8..9332e34 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -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
-- 
2.7.4

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

* [U-Boot] [PATCH V2 3/4] cmd: aes: use map_sysmem when accessing memory
  2019-09-23 16:39 [U-Boot] [PATCH V2 0/4] pytest: add a simple test to check the command aes Philippe Reynes
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 1/4] sandbox: enable " Philippe Reynes
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 2/4] sandbox64: " Philippe Reynes
@ 2019-09-23 16:39 ` Philippe Reynes
  2019-09-23 17:33   ` Simon Glass
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 4/4] pytest: add a new test for aes Philippe Reynes
  3 siblings, 1 reply; 7+ messages in thread
From: Philippe Reynes @ 2019-09-23 16:39 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
 cmd/aes.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/cmd/aes.c b/cmd/aes.c
index 7ff4a71..3db110c 100644
--- a/cmd/aes.c
+++ b/cmd/aes.c
@@ -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);
-- 
2.7.4

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

* [U-Boot] [PATCH V2 4/4] pytest: add a new test for aes
  2019-09-23 16:39 [U-Boot] [PATCH V2 0/4] pytest: add a simple test to check the command aes Philippe Reynes
                   ` (2 preceding siblings ...)
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 3/4] cmd: aes: use map_sysmem when accessing memory Philippe Reynes
@ 2019-09-23 16:39 ` Philippe Reynes
  3 siblings, 0 replies; 7+ messages in thread
From: Philippe Reynes @ 2019-09-23 16:39 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
 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

diff --git a/test/py/tests/aes/iv128.bin b/test/py/tests/aes/iv128.bin
new file mode 100644
index 0000000..b7b5d5d
--- /dev/null
+++ b/test/py/tests/aes/iv128.bin
@@ -0,0 +1 @@
+�!�/�\x1c��\fa�P���r
\ No newline at end of file
diff --git a/test/py/tests/aes/key128.bin b/test/py/tests/aes/key128.bin
new file mode 100644
index 0000000..9e3ce60
--- /dev/null
+++ b/test/py/tests/aes/key128.bin
@@ -0,0 +1 @@
+��\x17��Ć皳��\x15�6}
\ No newline at end of file
diff --git a/test/py/tests/aes/plaintext.bin b/test/py/tests/aes/plaintext.bin
new file mode 100644
index 0000000..8598fd9
--- /dev/null
+++ b/test/py/tests/aes/plaintext.bin
@@ -0,0 +1 @@
+AES128 is working, amazing !!!!!
\ No newline at end of file
diff --git a/test/py/tests/test_aes.py b/test/py/tests/test_aes.py
new file mode 100644
index 0000000..408bd77
--- /dev/null
+++ b/test/py/tests/test_aes.py
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019, Softathome
+
+# Test U-Boot's "aes" command.
+
+import pytest
+
+def test_aes(u_boot_console):
+    """
+    Test the aes command, and validate that it can
+    cipher and uncipher a simple text
+    """
+
+    cons = u_boot_console
+    tmpdir = cons.config.result_dir + '/'
+    datadir = cons.config.source_dir + '/test/py/tests/aes/'
+
+    # Check that the option cmd_aes is enabled in the config
+    if cons.config.buildconfig.get('config_cmd_aes', 'n') != 'y':
+        pytest.skip('aes command not supported')
+
+    # Send a command with no argument ...
+    output = cons.run_command('aes')
+    assert('AES 128 CBC encryption' in ''.join(output))
+
+    # Load file from host
+    output = cons.run_command('host load hostfs - 1000 %skey128.bin' % datadir)
+    assert('16 bytes read' in ''.join(output))
+    output = cons.run_command('host load hostfs - 2000 %siv128.bin' % datadir)
+    assert('16 bytes read' in ''.join(output))
+    output = cons.run_command('host load hostfs - 3000 %splaintext.bin' % datadir)
+    assert('32 bytes read' in ''.join(output))
+
+    output = cons.run_command('md.b 3000 0x20')
+
+    output = cons.run_command('aes enc 1000 2000 3000 4000 0x20')
+
+    output = cons.run_command('cmp.b 3000 4000 0x20')
+    assert('Total of 0 byte(s) were the same' in ''.join(output))
+
+    output = cons.run_command('md.b 4000 0x20')
+
+    output = cons.run_command('aes dec 1000 2000 4000 5000 0x20')
+
+    output = cons.run_command('md.b 5000 0x20')
+
+    output = cons.run_command('cmp.b 3000 5000 0x20')
+    assert('Total of 32 byte(s) were the same' in ''.join(output))
-- 
2.7.4

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

* [U-Boot] [PATCH V2 3/4] cmd: aes: use map_sysmem when accessing memory
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 3/4] cmd: aes: use map_sysmem when accessing memory Philippe Reynes
@ 2019-09-23 17:33   ` Simon Glass
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Glass @ 2019-09-23 17:33 UTC (permalink / raw)
  To: u-boot

On Mon, 23 Sep 2019 at 09:39, Philippe Reynes
<philippe.reynes@softathome.com> wrote:
>
> The aes command used to segfault when accessing memory in sandbox.
> The pointer accesses should be mapped.
>
> Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
> ---
>  cmd/aes.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/cmd/aes.c b/cmd/aes.c
> index 7ff4a71..3db110c 100644
> --- a/cmd/aes.c
> +++ b/cmd/aes.c
> @@ -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);

Please can you unmap_sysmem() as well?

Regards,
SImon

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

* [U-Boot] [PATCH V2 1/4] sandbox: enable command aes
  2019-09-23 16:39 ` [U-Boot] [PATCH V2 1/4] sandbox: enable " Philippe Reynes
@ 2019-10-21 15:25   ` Simon Glass
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Glass @ 2019-10-21 15:25 UTC (permalink / raw)
  To: u-boot

On Mon, 23 Sep 2019 at 10:39, Philippe Reynes
<philippe.reynes@softathome.com> wrote:
>
> This commit enable the command aes on sandbox.
> Then, it may be used on pytest.
>
> Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
> ---
>  configs/sandbox_defconfig | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

end of thread, other threads:[~2019-10-21 15:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-23 16:39 [U-Boot] [PATCH V2 0/4] pytest: add a simple test to check the command aes Philippe Reynes
2019-09-23 16:39 ` [U-Boot] [PATCH V2 1/4] sandbox: enable " Philippe Reynes
2019-10-21 15:25   ` Simon Glass
2019-09-23 16:39 ` [U-Boot] [PATCH V2 2/4] sandbox64: " Philippe Reynes
2019-09-23 16:39 ` [U-Boot] [PATCH V2 3/4] cmd: aes: use map_sysmem when accessing memory Philippe Reynes
2019-09-23 17:33   ` Simon Glass
2019-09-23 16:39 ` [U-Boot] [PATCH V2 4/4] pytest: add a new test for aes Philippe Reynes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.