all repos — TinyCrypT @ c188635c506be3fa59259cfd18249cec1c1d0080

Short and sweet classical cryptographic primitives

Started work on testing
Juniper Beatitudes [email protected]
Thu, 01 Jan 2026 12:45:29 -0600
commit

c188635c506be3fa59259cfd18249cec1c1d0080

parent

f826d30d391235a9c9301386b86180a3ffadadc6

6 files changed, 101 insertions(+), 0 deletions(-)

jump to
M .gitignore.gitignore

@@ -52,3 +52,4 @@ Module.symvers

Mkfile.old dkms.conf +build/test-main
A Makefile

@@ -0,0 +1,13 @@

+CC ?= gcc +INCLUDE_PATH := . +SOURCE_FILES := tinycrypt/*.c +TEST_SOURCE_FILES := tinycrypt/tests/*.c + +build/test-main: $(SOURCE_FILES) $(TEST_SOURCE_FILES) + @ $(CC) -o build/test-main -I$(INCLUDE_PATH) $(SOURCE_FILES) $(TEST_SOURCE_FILES) + +tests: build/test-main + @ ./build/test-main + +memcheck: build/test-main + @ valgrind ./build/test-main
M flake.nixflake.nix

@@ -20,6 +20,8 @@ packages = with pkgs; [

cmake gcc clang-tools + gnumake + valgrind ]; }; in
A tinycrypt/tests/harness.c

@@ -0,0 +1,39 @@

+#include <stdbool.h> +#include <stddef.h> +#include <stdio.h> +#include <sys/time.h> + +#include "tinycrypt/tests/harness.h" + +void +tct_testing_init_ctx (struct tct_testing_ctx *ctx) +{ + ctx->tests_passed = 0; + ctx->tests_failed = 0; +} + +void +tct_testing_assert (struct tct_testing_ctx *ctx, bool value, const char *name) +{ + if (!value) + { + ctx->tests_failed++; + printf ("Test '%s' failed!\n", name); + } + else + { + ctx->tests_passed++; + } +} + +void +tct_testing_start (struct tct_testing_ctx *ctx) +{ + gettimeofday (&(ctx->start), NULL); +} + +void +tct_testing_end (struct tct_testing_ctx *ctx) +{ + gettimeofday (&(ctx->end), NULL); +}
A tinycrypt/tests/harness.h

@@ -0,0 +1,25 @@

+#ifndef TCT_TEST_HARNESS_H +#define TCT_TEST_HARNESS_H + +#include <stdbool.h> +#include <stddef.h> +#include <sys/time.h> + +struct tct_testing_ctx +{ + size_t tests_passed; + size_t tests_failed; + struct timeval start; + struct timeval end; +}; + +void tct_testing_init_ctx (struct tct_testing_ctx *ctx); + +void tct_testing_assert (struct tct_testing_ctx *ctx, bool value, + const char *name); + +void tct_testing_start (struct tct_testing_ctx *ctx); + +void tct_testing_end (struct tct_testing_ctx *ctx); + +#endif
A tinycrypt/tests/main.c

@@ -0,0 +1,21 @@

+#include <stdbool.h> +#include <stdio.h> + +#include "tinycrypt/tests/harness.h" + +int +main (int argc, const char **argv) +{ + struct tct_testing_ctx ctx; + tct_testing_init_ctx (&ctx); + printf ("Beginning tests\n"); + tct_testing_start (&ctx); + + // Tests go here + + tct_testing_end (&ctx); + printf ("%lu tests passed, %lu tests failed, %lu microseconds elapsed\n", + ctx.tests_passed, ctx.tests_failed, + (1000000 * ctx.end.tv_sec + ctx.end.tv_usec) + - (1000000 * ctx.start.tv_sec + ctx.start.tv_usec)); +}