From 446a365cbd4a00c468eaec986d2d9338389ffd59 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Fri, 11 Jan 2019 09:42:12 +0000 Subject: [PATCH] Run the ChaCha self-tests too. --- src/microcode/prchacha.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/microcode/prchacha.c b/src/microcode/prchacha.c index a68fd5fe2..0d2ffa6bf 100644 --- a/src/microcode/prchacha.c +++ b/src/microcode/prchacha.c @@ -29,7 +29,9 @@ USA. static void do_chacha_core (void (*core) (uint8_t *, const uint8_t *, const uint8_t *, - const uint8_t *)) + const uint8_t *), + int (*selftest) (void), + bool * selftestedp) { unsigned long noutput; uint8_t * output = (arg_bytevector (1, (&noutput))); @@ -53,6 +55,13 @@ do_chacha_core (void (*core) (uint8_t *, const uint8_t *, const uint8_t *, if (nconstant != 16) error_bad_range_arg (5); + if (! (*selftestedp)) + { + if (((*selftest) ()) != 0) + error_external_return (); + (*selftestedp) = true; + } + (*core) ((output + offset), input, key, constant); } @@ -62,7 +71,8 @@ Compute the ChaCha8 core hash function:\n\ OUTPUT[OFFSET, OFFSET+1, ..., OFFSET+63] := ChaCha8(INPUT, KEY, CONST).") { PRIMITIVE_HEADER (5); - do_chacha_core (&chacha8_core); + static bool selftestedp = false; + do_chacha_core ((&chacha8_core), (&chacha8_core_selftest), (&selftestedp)); PRIMITIVE_RETURN (UNSPECIFIC); } @@ -72,7 +82,8 @@ Compute the ChaCha12 core hash function:\n\ OUTPUT[OFFSET, OFFSET+1, ..., OFFSET+63] := ChaCha12(INPUT, KEY, CONST).") { PRIMITIVE_HEADER (5); - do_chacha_core (&chacha12_core); + static bool selftestedp = false; + do_chacha_core ((&chacha12_core), (&chacha12_core_selftest), (&selftestedp)); PRIMITIVE_RETURN (UNSPECIFIC); } @@ -82,6 +93,7 @@ Compute the ChaCha20 core hash function:\n\ OUTPUT[OFFSET, OFFSET+1, ..., OFFSET+63] := ChaCha20(INPUT, KEY, CONST).") { PRIMITIVE_HEADER (5); - do_chacha_core (&chacha20_core); + static bool selftestedp = false; + do_chacha_core ((&chacha20_core), (&chacha20_core_selftest), (&selftestedp)); PRIMITIVE_RETURN (UNSPECIFIC); } -- 2.25.1