From 82ad9eedbb44fd0124424ef0b9e02ae2e16506b1 Mon Sep 17 00:00:00 2001 From: lwc-tester Date: Wed, 19 Feb 2020 17:13:26 +0100 Subject: [PATCH] still working on this --- test.py | 188 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- test_common.py | 34 ++++++++++++++++++---------------- 2 files changed, 18 insertions(+), 204 deletions(-) delete mode 100755 test.py diff --git a/test.py b/test.py deleted file mode 100755 index d19a447..0000000 --- a/test.py +++ /dev/null @@ -1,188 +0,0 @@ -#!/usr/bin/env python3 - -import re -import os -import sys -import struct -from subprocess import Popen, PIPE - - -def main(argv): - speed_test = True - - if len(argv) < 3: - print("Usage: test.py LWC_AEAD_KAT.txt program [arguments]") - - cmd = argv[2:] - - for attempt in range(3): - print("beginning test %d of '%s' using test vectors '%s'" % (attempt, ' '.join(cmd), argv[1])) - try: - if speed_test: - measurements = begin_measurement() - try: - test(argv[1], cmd) - finally: - if speed_test: - end_measurement(measurements) - print("TEST SUCCESSFUL") - return 0 - - except Exception as ex: - print(str(ex)) - print("TEST FAILED") - finally: - sys.stdout.flush() - sys.stderr.flush() - - return 1 - -def test(test_file, cmd, ram_test=False): - - test_file = open(test_file, 'r') - p = Popen(cmd, bufsize=0, stdin=PIPE, stdout=PIPE) - - def write(data): - l = p.stdin.write(data) - if len(data) != l: - raise Exception("could not write %d bytes of data (put %d)" % (len(data), l)) - - def read(l): - if l == 0: - return b"" - data = p.stdout.read(l) - if len(data) == 0: - print("Unexpected end of stream", file=sys.stderr) - #sys.exit(1) - if len(data) != l: - raise Exception("could not read %d bytes of data (got %d)" % (l, len(data))) - return data - - def submit(action, data): - h = struct.pack(" %s\n" % (' '.join(sys.argv), outfile)) - mdbfile.close() - return 0 - raise Exception("Capture didn't complete successfully") - -if __name__ == "__main__": - sys.exit(main(sys.argv)) diff --git a/test_common.py b/test_common.py index af4b938..1f918cb 100644 --- a/test_common.py +++ b/test_common.py @@ -34,8 +34,10 @@ class DeviceUnderTestAeadUARTP(DeviceUnderTest): self.ser = ser def prepare(self): - time.sleep(0.1) exp_hello = b"Hello, World!" + time.sleep(0.1) + if self.ser.in_waiting < 13: + time.sleep(2) hello = self.ser.read(self.ser.in_waiting) if hello[-13:] != exp_hello: raise Exception( @@ -100,7 +102,7 @@ class UARTP: fcs = (0xff - fcs) & 0xff self.uart_write(fcs) self.uart_write(UARTP.FIN) - eprint("sent frame '%s'" % buf.hex()) + # eprint("sent frame '%s'" % buf.hex()) def recv(self): tag_old = UARTP.FIN @@ -131,7 +133,7 @@ class UARTP: if fcs == 0xff: if tag == UARTP.FIN: buf = bytes(buf) - eprint("rcvd frame '%s'" % buf.hex()) + # eprint("rcvd frame '%s'" % buf.hex()) if len(buf) >= 1 and buf[0] == 0xde: sys.stderr.buffer.write(buf[1:]) sys.stderr.flush() @@ -140,20 +142,20 @@ class UARTP: def run_nist_aead_test(dut, kat): - dump_a = dut.dump_ram() + dump_a = dut.ram_dump() - for i, m, ad, k, npub, c in kat: - tool = SaleaeTimeMeasurements() - tool.begin_measurement() - try: + tool = SaleaeTimeMeasurements() + tool.begin_measurement() + try: + for i, m, ad, k, npub, c in kat: run_nist_aead_test_line(dut, i, m, ad, k, npub, c) - finally: - tool.end_measurement() - if dump_a is not None and i == 0: - dump_b = dut.dump_ram() - longest = compare_dumps(dump_a, dump_b) - print(" longest chunk of untouched memory = %d" % longest) + if dump_a is not None and i == 0: + dump_b = dut.ram_dump() + longest = compare_dumps(dump_a, dump_b) + print(" longest chunk of untouched memory = %d" % longest) + finally: + tool.end_measurement() def run_nist_aead_test_line(dut, i, m, ad, k, npub, c): @@ -174,7 +176,7 @@ def run_nist_aead_test_line(dut, i, m, ad, k, npub, c): dut.send_var(ord('p'), npub) dut.do_cmd(ord('e')) - output = dut.get_var(ord('C')) + output = dut.obtain_var(ord('C')) print(" c = %s" % output.hex()) if c != output: raise Exception("output of encryption is different from " + @@ -189,7 +191,7 @@ def run_nist_aead_test_line(dut, i, m, ad, k, npub, c): dut.send_var(ord('p'), npub) dut.do_cmd(ord('d')) - output = dut.get_var(ord('M')) + output = dut.obtain_var(ord('M')) print(" m = %s" % output.hex()) if m != output: raise Exception("output of encryption is different from " + -- libgit2 0.26.0