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).
This commit is contained in:
Paul Sokolovsky 2018-01-07 15:15:05 +02:00 committed by Damien George
parent bf77f34819
commit bb634115fc
4 changed files with 35 additions and 0 deletions

View File

@ -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)

View File

@ -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')

View File

@ -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)

View File

@ -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')