summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2018-01-07 15:15:05 +0200
committerDamien George <damien.p.george@gmail.com>2018-06-27 14:56:46 +1000
commitbb634115fc7bb22aee34454eb127d50a3a9795b4 (patch)
tree0b21c114acffdd6366b1c40b9928371c6c5f7f72
parentbf77f348196c5f34e48093e5e6db9bee0e8cd42c (diff)
tests/extmod/ucryptolib*: Add into and inplace tests for ucryptolib.
Tests for separate input and output buffer (alloc-free operation) and the same writable buffer used as input and output (inplace operation).
-rw-r--r--tests/extmod/ucryptolib_aes128_ecb_inpl.py15
-rw-r--r--tests/extmod/ucryptolib_aes128_ecb_inpl.py.exp2
-rw-r--r--tests/extmod/ucryptolib_aes128_ecb_into.py16
-rw-r--r--tests/extmod/ucryptolib_aes128_ecb_into.py.exp2
4 files changed, 35 insertions, 0 deletions
diff --git a/tests/extmod/ucryptolib_aes128_ecb_inpl.py b/tests/extmod/ucryptolib_aes128_ecb_inpl.py
new file mode 100644
index 000000000..88ccb02da
--- /dev/null
+++ b/tests/extmod/ucryptolib_aes128_ecb_inpl.py
@@ -0,0 +1,15 @@
+# Inplace operations (input and output buffer is the same)
+try:
+ from ucryptolib import aes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+crypto = aes(b"1234" * 4, 1)
+buf = bytearray(bytes(range(32)))
+crypto.encrypt(buf, buf)
+print(buf)
+
+crypto = aes(b"1234" * 4, 1)
+crypto.decrypt(buf, buf)
+print(buf)
diff --git a/tests/extmod/ucryptolib_aes128_ecb_inpl.py.exp b/tests/extmod/ucryptolib_aes128_ecb_inpl.py.exp
new file mode 100644
index 000000000..b7f7bf540
--- /dev/null
+++ b/tests/extmod/ucryptolib_aes128_ecb_inpl.py.exp
@@ -0,0 +1,2 @@
+bytearray(b'Iz\xfe9\x17\xac\xa4X\x12\x04\x10\xf5K~#\xc7\xac;\xf9\xc6E\xa8\xca~\xf1\xee\xd3f%\xf1\x8d\xfe')
+bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f')
diff --git a/tests/extmod/ucryptolib_aes128_ecb_into.py b/tests/extmod/ucryptolib_aes128_ecb_into.py
new file mode 100644
index 000000000..ff832d7ef
--- /dev/null
+++ b/tests/extmod/ucryptolib_aes128_ecb_into.py
@@ -0,0 +1,16 @@
+# Operations with pre-allocated output buffer
+try:
+ from ucryptolib import aes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+crypto = aes(b"1234" * 4, 1)
+enc = bytearray(32)
+crypto.encrypt(bytes(range(32)), enc)
+print(enc)
+
+crypto = aes(b"1234" * 4, 1)
+dec = bytearray(32)
+crypto.decrypt(enc, dec)
+print(dec)
diff --git a/tests/extmod/ucryptolib_aes128_ecb_into.py.exp b/tests/extmod/ucryptolib_aes128_ecb_into.py.exp
new file mode 100644
index 000000000..b7f7bf540
--- /dev/null
+++ b/tests/extmod/ucryptolib_aes128_ecb_into.py.exp
@@ -0,0 +1,2 @@
+bytearray(b'Iz\xfe9\x17\xac\xa4X\x12\x04\x10\xf5K~#\xc7\xac;\xf9\xc6E\xa8\xca~\xf1\xee\xd3f%\xf1\x8d\xfe')
+bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f')