[U-Boot] [PATCH V3 4/4] pytest: add a new test for aes

Philippe Reynes philippe.reynes at softathome.com
Tue Sep 24 09:32:30 UTC 2019


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 at 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 @@
+â!‚/‡×ùaõ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 @@
+µ©„ñĆ皳žÏË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



More information about the U-Boot mailing list