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)));
if (nconstant != 16)
error_bad_range_arg (5);
+ if (! (*selftestedp))
+ {
+ if (((*selftest) ()) != 0)
+ error_external_return ();
+ (*selftestedp) = true;
+ }
+
(*core) ((output + offset), input, key, constant);
}
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);
}
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);
}
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);
}