diff --git a/compile_all.py b/compile_all.py index 1dbbbcc..d408c68 100755 --- a/compile_all.py +++ b/compile_all.py @@ -156,13 +156,12 @@ def main(argv): try: b = build(d, template_dir) test_script.write("echo \"TESTING %s\"\n" % d) - test_script.write("./test.py %s %s 2> %s | tee %s\n" % ( + test_script.write("python3 -u ./test.py %s %s 2> %s | tee %s\n" % ( t, os.path.join(b, 'test'), os.path.join(b, 'test_stderr.log'), os.path.join(b, 'test_stdout.log')) - - #./test.py all-lwc-submission-files/tinyjambu/Implementations/crypto_aead/tinyjambu192/LWC_AEAD_KAT_192_96.txt build/731759111/test 2> build/731759111/test_stderr.log | tee build/731759111/test_stdout.log + ) print("COMPILATION SUCCESS FOR %s" % d) except Exception: diff --git a/templates/uno/src/main.ino b/templates/uno/src/main.ino index c3545de..0e9dd3b 100644 --- a/templates/uno/src/main.ino +++ b/templates/uno/src/main.ino @@ -5,6 +5,7 @@ #define MAX_BYTES 100 //#define DEBUG +#define CRYPTO_BUSY 12 uint8_t npub[CRYPTO_NPUBBYTES]; uint8_t nsec[CRYPTO_NSECBYTES]; @@ -70,8 +71,8 @@ void assert(bool b) { void setup() { Serial.begin(115200); - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); + pinMode(CRYPTO_BUSY, OUTPUT); + digitalWrite(CRYPTO_BUSY, HIGH); delay(100); Serial.print("Hello, World!"); } @@ -98,18 +99,18 @@ void loop() { case 'e': noInterrupts(); asm("nop"); - digitalWrite(LED_BUILTIN, LOW); + digitalWrite(CRYPTO_BUSY, LOW); res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k); - digitalWrite(LED_BUILTIN, HIGH); + digitalWrite(CRYPTO_BUSY, HIGH); asm("nop"); interrupts(); break; case 'd': noInterrupts(); asm("nop"); - digitalWrite(LED_BUILTIN, LOW); + digitalWrite(CRYPTO_BUSY, LOW); res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k); - digitalWrite(LED_BUILTIN, HIGH); + digitalWrite(CRYPTO_BUSY, HIGH); asm("nop"); interrupts(); break; diff --git a/test.py b/test.py index 8d1f3cd..fd89d59 100755 --- a/test.py +++ b/test.py @@ -15,17 +15,19 @@ def main(argv): for attempt in range(3): print("beginning test %d of '%s' using test vectors '%s'" % (attempt, ' '.join(cmd), argv[1])) - measurements = begin_measurement() try: - test(argv[1], cmd) + measurements = begin_measurement() + try: + test(argv[1], cmd) + finally: + end_measurement(measurements) print("TEST SUCCESSFUL") return 0 + except Exception as ex: print(str(ex)) print("TEST FAILED") finally: - end_measurement(measurements) - sys.stdout.flush() sys.stderr.flush() @@ -135,29 +137,36 @@ def begin_measurement(): import saleae import time sal = saleae.Saleae() - sal.set_active_channels([0, 1], []) + sal.set_active_channels([0, 1, 2, 3], []) sal.set_sample_rate(sal.get_all_sample_rates()[0]) - sal.set_capture_seconds(6000) + sal.set_capture_seconds(1000) sal.capture_start() time.sleep(1) + if sal.is_processing_complete(): + raise Exception("Capture didn't start successfully") return sal def end_measurement(sal): import time time.sleep(1) sal.capture_stop(); - while not sal.is_processing_complete(): - pass - outfile = "measurement_%s.csv" % time.strftime("%Y%m%d-%H%M%S") - outfile = os.path.join("measurements", outfile) - if os.path.isfile(outfile): - os.unlink(outfile) - sal.export_data2(os.path.abspath(outfile)) - print("Measurements written to '%s'" % outfile) - mdbfile = os.path.join("measurements", "measurements.txt") - mdbfile = open(mdbfile, "a") - mdbfile.write("%s > %s\n" % (' '.join(sys.argv), outfile)) - mdbfile.close() + for attempt in range(3): + if not sal.is_processing_complete(): + print("waiting for capture to complete") + time.sleep(1) + continue + outfile = "measurement_%s.csv" % time.strftime("%Y%m%d-%H%M%S") + outfile = os.path.join("measurements", outfile) + if os.path.isfile(outfile): + os.unlink(outfile) + sal.export_data2(os.path.abspath(outfile)) + print("Measurements written to '%s'" % outfile) + mdbfile = os.path.join("measurements", "measurements.txt") + mdbfile = open(mdbfile, "a") + mdbfile.write("%s > %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))