All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Reynes <philippe.reynes@softathome.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2 4/4] pytest: add a new test for aes
Date: Mon, 23 Sep 2019 18:39:05 +0200	[thread overview]
Message-ID: <1569256745-15380-5-git-send-email-philippe.reynes@softathome.com> (raw)
In-Reply-To: <1569256745-15380-1-git-send-email-philippe.reynes@softathome.com>

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

      parent reply	other threads:[~2019-09-23 16:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Philippe Reynes [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1569256745-15380-5-git-send-email-philippe.reynes@softathome.com \
    --to=philippe.reynes@softathome.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.