From 93aa7e3aa291f3328cf34a5a2f86172f41d0affd Mon Sep 17 00:00:00 2001 From: cirakg Date: Sun, 18 Oct 2026 23:44:18 +0200 Subject: test: add cross-checked crypto/OTP vectors, unit tests and stricter screenshots - gen_vectors.py: RFC/FIPS/NIST vectors recomputed with Python's stdlib (openssl for AES) before use, plus seeded cases around SHA padding boundaries, 2038 and 2100; generates test/data/Vectors.mc. - 31 Monkey C tests (hashes, HMAC, PBKDF2, HKDF, AES, sealed records incl. every-byte tamper detection, Base32 errors, 100 OTP and 12 Steam vectors, clock, jobs) and a benchmark; pass on all four test devices. - Screenshot tolerance 0.01 %: one changed character no longer passes. - Golden images updated for version 0.2.0. Co-Authored-By: Claude Opus 5.5 --- test/TestSupport.mc | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/TestSupport.mc (limited to 'test/TestSupport.mc') diff --git a/test/TestSupport.mc b/test/TestSupport.mc new file mode 100644 index 0000000..f6fa4b7 --- /dev/null +++ b/test/TestSupport.mc @@ -0,0 +1,53 @@ +// Author: cirakg & claude ai +// Summary: Small helpers shared by the Monkey C unit tests (reading vector rows, reporting mismatches). + +import Toybox.Lang; +import Toybox.Test; + +(:test) +module TestSupport { + + // One row of a TestVectors table. + function row(table as Array, index as Number) as Array { + return table[index] as Array; + } + + function str(r as Array, column as Number) as String { + return r[column] as String; + } + + function bytes(r as Array, column as Number) as ByteArray { + return Bytes.fromHex(r[column] as String); + } + + function num(r as Array, column as Number) as Number { + return r[column] as Number; + } + + // Numbers above 2^31 are stored as Long literals in the tables. + function long(r as Array, column as Number) as Long { + return (r[column] as Number or Long).toLong(); + } + + function alg(r as Array, column as Number) as Hashes.Algorithm { + return r[column] as Hashes.Algorithm; + } + + // Compare bytes; log both sides on mismatch. Returns true when equal. + function sameBytes(logger as Test.Logger, what as String, actual as ByteArray, expected as ByteArray) as Boolean { + if (Bytes.equal(actual, expected)) { + return true; + } + logger.error(what + ": got " + Bytes.toHex(actual) + ", expected " + Bytes.toHex(expected)); + return false; + } + + // Compare strings; log both sides on mismatch. + function sameString(logger as Test.Logger, what as String, actual as String, expected as String) as Boolean { + if (actual.equals(expected)) { + return true; + } + logger.error(what + ": got '" + actual + "', expected '" + expected + "'"); + return false; + } +} -- cgit v1.2.3