diff --git a/test_common.py b/test_common.py index 6084606..88458a6 100644 --- a/test_common.py +++ b/test_common.py @@ -149,7 +149,7 @@ class UARTP: return buf -def run_nist_aead_test_line(dut, i, m, ad, k, npub, c): +def run_nist_aead_test_line(dut, i, m, ad, k, npub, c=None): eprint() eprint("Count = %d" % i) eprint(" m = %s" % m.hex()) @@ -668,7 +668,39 @@ def run_nist_lws_aead_test(dut, vectors_file, build_dir, sys.stdout.write("Board prepared\n") sys.stdout.flush() + # For targets that support memory utilization testing, the RAM should now + # contain a known pattern pattern that is identical for all algorithms, + # minus the differences in static memory. Now we dump the RAM before and + # after running the first test vector, to measure how much of the memory + # was affected by one execution of encryption and decryption + ram_dumps = [dut.dump_ram()] + if ram_dumps[0] is not None: + i, m, ad, k, npub, c = kat[0] + run_nist_aead_test_line(dut, i, m, ad, k, npub, c) + ram_dumps.append(dut.dump_ram()) + + # This is a dummy test to ensure the encryption and decryption code is in + # the cache for devices that make use of a slow flash for storing the code. + # The duration of this test is not measured. + # It uses the same length for the message and AD as the last line of the + # test vector file, which is assumed to be the longest. + + i, m, ad, k, npub, c = kat[-1] + run_nist_aead_test_line( + dut, + -1, + b"m" * len(m), + b"a" * len(ad), + b"k" * len(k), + b"n" * len(npub), + None + ) + + # Now we do the encryption and decryption speed test. The tool object + # provides an abstraction to the logic analyzer that will check how long + # the encryption/decryption takes by mean of the CRYPTO_BUSY GPIO on the + # board. tool = LogicMultiplexerTimeMeasurements(logic_mask) try: @@ -679,9 +711,6 @@ def run_nist_lws_aead_test(dut, vectors_file, build_dir, run_nist_aead_test_line(dut, i, m, ad, k, npub, c) tool.unarm() - if i == 1 and ram_dumps[0] is not None: - ram_dumps.append(dut.dump_ram()) - except Exception as ex: print("TEST FAILED") raise ex