diff --git a/templates/bluepill/test b/templates/bluepill/test index 28f0da8..fc96646 100755 --- a/templates/bluepill/test +++ b/templates/bluepill/test @@ -4,14 +4,11 @@ import os import sys import serial.tools.list_ports from test_common import ( - LogicMultiplexerTimeMeasurements, - parse_nist_aead_test_vectors, DeviceUnderTestAeadUARTP, - compare_dumps, eprint, OpenOcd, FileMutex, - run_nist_aead_test_line, + run_nist_lws_aead_test ) @@ -109,38 +106,8 @@ def main(argv): print("Usage: test LWC_AEAD_KAT.txt build_dir") return 1 - kat = list(parse_nist_aead_test_vectors(argv[1])) - build_dir = argv[2] - - dut = BluePill(build_dir) - - dut.flash() - dut.prepare() - sys.stdout.write("Board prepared\n") - sys.stdout.flush() - - dump_a = dut.dump_ram() - - try: - tool = LogicMultiplexerTimeMeasurements(0x0002) - tool.begin_measurement() - - for i, m, ad, k, npub, c in kat: - tool.arm() - run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - tool.unarm() - - if i == 1 and dump_a is not None: - dump_b = dut.dump_ram() - longest = compare_dumps(dump_a, dump_b) - print(" longest chunk of untouched memory = %d" % longest) - - except Exception as ex: - print("TEST FAILED") - raise ex - - finally: - tool.end_measurement() + run_nist_lws_aead_test(argv[1], argv[2], 0x0002, BluePill) + return 0 if __name__ == "__main__": diff --git a/templates/esp32/test b/templates/esp32/test index 3e5180c..30eb858 100755 --- a/templates/esp32/test +++ b/templates/esp32/test @@ -6,12 +6,10 @@ import time import subprocess import serial.tools.list_ports from test_common import ( - LogicMultiplexerTimeMeasurements, - parse_nist_aead_test_vectors, DeviceUnderTestAeadUARTP, eprint, FileMutex, - run_nist_aead_test_line, + run_nist_lws_aead_test, ) @@ -74,30 +72,8 @@ def main(argv): print("Usage: test LWC_AEAD_KAT.txt build_dir") return 1 - kat = list(parse_nist_aead_test_vectors(argv[1])) - build_dir = argv[2] - - dut = ESP32(build_dir) - dut.flash() - dut.prepare() - sys.stdout.write("Board prepared\n") - sys.stdout.flush() - - try: - tool = LogicMultiplexerTimeMeasurements(0x0020) - tool.begin_measurement() - - for i, m, ad, k, npub, c in kat: - tool.arm() - run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - tool.unarm() - - except Exception as ex: - print("TEST FAILED") - raise ex - - finally: - tool.end_measurement() + run_nist_lws_aead_test(argv[1], argv[2], 0x0020, ESP32) + return 0 if __name__ == "__main__": diff --git a/templates/f7/test b/templates/f7/test index ea44f48..ff1aafc 100755 --- a/templates/f7/test +++ b/templates/f7/test @@ -5,13 +5,10 @@ import sys import pylink import serial.tools.list_ports from test_common import ( - LogicMultiplexerTimeMeasurements, - parse_nist_aead_test_vectors, DeviceUnderTestAeadUARTP, - compare_dumps, eprint, FileMutex, - run_nist_aead_test_line, + run_nist_lws_aead_test, ) @@ -66,38 +63,8 @@ def main(argv): print("Usage: test LWC_AEAD_KAT.txt build_dir") return 1 - kat = list(parse_nist_aead_test_vectors(argv[1])) - build_dir = argv[2] - - dut = F7(build_dir) - - dut.flash() - dut.prepare() - sys.stdout.write("Board prepared\n") - sys.stdout.flush() - - dump_a = dut.dump_ram() - - try: - tool = LogicMultiplexerTimeMeasurements(0x0008) - tool.begin_measurement() - - for i, m, ad, k, npub, c in kat: - tool.arm() - run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - tool.unarm() - - if i == 1: - dump_b = dut.dump_ram() - longest = compare_dumps(dump_a, dump_b) - print(" longest chunk of untouched memory = %d" % longest) - - except Exception as ex: - print("TEST FAILED") - raise ex - - finally: - tool.end_measurement() + run_nist_lws_aead_test(argv[1], argv[2], 0x0008, F7) + return 0 if __name__ == "__main__": diff --git a/templates/maixduino/test b/templates/maixduino/test index ddefb16..60c1634 100755 --- a/templates/maixduino/test +++ b/templates/maixduino/test @@ -6,12 +6,10 @@ import time import subprocess import serial.tools.list_ports from test_common import ( - LogicMultiplexerTimeMeasurements, - parse_nist_aead_test_vectors, DeviceUnderTestAeadUARTP, FileMutex, eprint, - run_nist_aead_test_line, + run_nist_lws_aead_test, ) @@ -76,30 +74,8 @@ def main(argv): print("Usage: test LWC_AEAD_KAT.txt build_dir") return 1 - kat = list(parse_nist_aead_test_vectors(argv[1])) - build_dir = argv[2] - - dut = Maixduino(build_dir) - dut.flash() - dut.prepare() - sys.stdout.write("Board prepared\n") - sys.stdout.flush() - - try: - tool = LogicMultiplexerTimeMeasurements(0x0080) - tool.begin_measurement() - - for i, m, ad, k, npub, c in kat: - tool.arm() - run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - tool.unarm() - - except Exception as ex: - print("TEST FAILED") - raise ex - - finally: - tool.end_measurement() + run_nist_lws_aead_test(argv[1], argv[2], 0x0080, Maixduino) + return 0 if __name__ == "__main__": diff --git a/templates/uno/test b/templates/uno/test index c2b983f..3e0b89d 100755 --- a/templates/uno/test +++ b/templates/uno/test @@ -6,12 +6,10 @@ import time import subprocess import serial.tools.list_ports from test_common import ( - LogicMultiplexerTimeMeasurements, - parse_nist_aead_test_vectors, DeviceUnderTestAeadUARTP, eprint, FileMutex, - run_nist_aead_test_line, + run_nist_lws_aead_test, ) @@ -72,31 +70,8 @@ def main(argv): print("Usage: test LWC_AEAD_KAT.txt build_dir") return 1 - kat = list(parse_nist_aead_test_vectors(argv[1])) - build_dir = argv[2] - - dut = Uno(build_dir) - - dut.flash() - dut.prepare() - sys.stdout.write("Board prepared\n") - sys.stdout.flush() - - try: - tool = LogicMultiplexerTimeMeasurements(0x0800) - tool.begin_measurement() - - for i, m, ad, k, npub, c in kat: - tool.arm() - run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - tool.unarm() - - except Exception as ex: - print("TEST FAILED") - raise ex - - finally: - tool.end_measurement() + run_nist_lws_aead_test(argv[1], argv[2], 0x0800, Uno) + return 0 if __name__ == "__main__": diff --git a/test_common.py b/test_common.py index 5bea950..03c061b 100644 --- a/test_common.py +++ b/test_common.py @@ -368,53 +368,6 @@ class SaleaeTimeMeasurements(TimeMeasurementTool): raise Exception("Capture didn't complete successfully") -def main(argv): - if len(argv) < 3: - print("Usage: test_common.py port LWC_AEAD_KAT.txt") - - eprint(argv[0]) - script_dir = os.path.split(argv[0])[0] - if len(script_dir) > 0: - os.chdir(script_dir) - - kat = list(parse_nist_aead_test_vectors(argv[2])) - - dev = argv[1] - ser = serial.Serial(dev, baudrate=115200, timeout=5) - dut = DeviceUnderTestAeadUARTP(ser) - - try: - tool = SaleaeTimeMeasurements() - tool.begin_measurement() - dut.flash() - eprint("Flashed") - dut.prepare() - eprint("Prepared") - sys.stdout.write("Hello, World!\n") - sys.stdout.flush() - - dump_a = dut.dump_ram() - - for i, m, ad, k, npub, c in kat: - tool.arm() - run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - tool.unarm() - - if dump_a is not None and i == 1: - dump_b = dut.dump_ram() - longest = compare_dumps(dump_a, dump_b) - print(" longest chunk of untouched memory = %d" % longest) - - except Exception as ex: - print("TEST FAILED") - raise ex - - finally: - tool.end_measurement() - sys.stdout.flush() - sys.stderr.flush() - - class FileMutex: def __init__(self, lock_path): self.lock_path = lock_path @@ -495,5 +448,96 @@ class OpenOcd: return data.decode('ascii') +def run_nist_lws_aead_test(vectors_file, build_dir, + logic_mask=0xffff, + basecls=DeviceUnderTestAeadUARTP): + kat = list(parse_nist_aead_test_vectors(vectors_file)) + + dut = basecls(build_dir) + + dut.flash() + dut.prepare() + sys.stdout.write("Board prepared\n") + sys.stdout.flush() + + dump_a = dut.dump_ram() + time_dips = None + ram_utilization = None + rom_utilization = None + + try: + tool = LogicMultiplexerTimeMeasurements(logic_mask) + tool.begin_measurement() + + for i, m, ad, k, npub, c in kat: + tool.arm() + run_nist_aead_test_line(dut, i, m, ad, k, npub, c) + tool.unarm() + + if i == 1 and dump_a is not None: + dump_b = dut.dump_ram() + longest = compare_dumps(dump_a, dump_b) + print(" longest chunk of untouched memory = %d" % longest) + ram_utilization = longest + + time_dips = tool.capture + + except Exception as ex: + print("TEST FAILED") + raise ex + + finally: + tool.end_measurement() + + return time_dips, ram_utilization, rom_utilization + + +def main(argv): + if len(argv) < 3: + print("Usage: test_common.py port LWC_AEAD_KAT.txt") + + eprint(argv[0]) + script_dir = os.path.split(argv[0])[0] + if len(script_dir) > 0: + os.chdir(script_dir) + + kat = list(parse_nist_aead_test_vectors(argv[2])) + + dev = argv[1] + ser = serial.Serial(dev, baudrate=115200, timeout=5) + dut = DeviceUnderTestAeadUARTP(ser) + + try: + tool = SaleaeTimeMeasurements() + tool.begin_measurement() + dut.flash() + eprint("Flashed") + dut.prepare() + eprint("Prepared") + sys.stdout.write("Hello, World!\n") + sys.stdout.flush() + + dump_a = dut.dump_ram() + + for i, m, ad, k, npub, c in kat: + tool.arm() + run_nist_aead_test_line(dut, i, m, ad, k, npub, c) + tool.unarm() + + if dump_a is not None and i == 1: + dump_b = dut.dump_ram() + longest = compare_dumps(dump_a, dump_b) + print(" longest chunk of untouched memory = %d" % longest) + + except Exception as ex: + print("TEST FAILED") + raise ex + + finally: + tool.end_measurement() + sys.stdout.flush() + sys.stderr.flush() + + if __name__ == "__main__": sys.exit(main(sys.argv))