Skip to content

Add tests for the cryptographic primitives - #266

Merged
utelle merged 1 commit into
utelle:mainfrom
SchwarzDigits:test/crypto-kat
Sep 13, 2026
Merged

utelle merged 1 commit into
utelle:mainfrom
SchwarzDigits:test/crypto-kat

Conversation

@mtrossbach

Copy link
Copy Markdown
Contributor

Hi Ulrich,

as discussed in #262, this adds a test program for the cryptographic primitives and runs it in CI.

Type: Feature / Enhancement (tests)

What it checks

test/cryptotest.c includes the amalgamation, so it can call the internal functions directly:

  • AES-CBC with the NIST SP 800-38A vectors: the software core, the Rijndael CBC functions used by the cipher schemes and, if available, the hardware path,
  • ChaCha20 and Poly1305 with the RFC 8439 test vectors, for every implementation that is compiled for the target and supported by the CPU,
  • that all ChaCha20 and Poly1305 implementations return the same results for pseudo-random input of many lengths,
  • that all tag compare implementations detect equal tags and tags that differ in a single bit.

Without selectable implementations (currently main), only the default implementations are checked. The program returns 1 if a check fails.

Because the program calls internal functions such as sse2_poly1305() directly, it has to be adjusted when these functions are renamed or removed.

Why

The existing CI tests only exercise the implementations a runner selects by default. A hardware-specific implementation that computes wrong results, or results that differ from the other implementations, would not be noticed.

Build and CI

Makefile.am adds cryptotest as a check_PROGRAMS target with the flags of sqlite3shell, so a normal make doesn't build it. The host_unix job builds and runs it after the existing tests.

Tested

  • main (a393e13): the CI recipe (autoreconf, ./configure, make, then the new step) on Linux x86_64 and arm64 with GCC and Clang, plus direct builds on macOS arm64, the iOS simulator, Android (NDK r28) and WebAssembly. All checks pass.
  • hwaccel (8794b10): all 6669 checks pass on ARM64, including NEON, and all 9123 checks pass on x86_64, including SSSE3, AVX2 and SSE2.

The test vectors were cross-checked with OpenSSL.

Best regards,
Markus

test/cryptotest.c checks AES-CBC (NIST SP 800-38A), ChaCha20 and
Poly1305 (RFC 8439) for all implementations available on the target,
compares the implementations on pseudo-random input, and checks the
Poly1305 tag comparison.

The program is built like the shell by "make check" or "make cryptotest"
and runs in the host_unix CI job after the existing tests.
@utelle

utelle commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Hi Markus,

thank very much for this great contribution! 🥇

@utelle
utelle merged commit 34d681d into utelle:main Sep 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants