X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/3f8f973351d3273e6ef43e1029c0469508aa763c..5bf585d21927a684ae9c16eb2a28cd786cec433c:/keccak1600-test.c diff --git a/keccak1600-test.c b/keccak1600-test.c new file mode 100644 index 0000000..e0102ac --- /dev/null +++ b/keccak1600-test.c @@ -0,0 +1,72 @@ +/* + * keccak1600-test.c: test harness for Keccak primitive + * + * (The implementations originally came with different test arrangements, + * with complicated external dependencies. This file replicates the original + * tests, but without the dependencies.) + */ +/* + * This file is Free Software. It was originally written for secnet. + * + * Copyright 2019 Mark Wooding + * + * You may redistribute secnet as a whole and/or modify it under the + * terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3, or (at your option) any + * later version. + * + * You may redistribute this file and/or modify it under the terms of + * the GNU General Public License as published by the Free Software + * Foundation; either version 2, or (at your option) any later + * version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, see + * https://www.gnu.org/licenses/gpl.html. + */ + +#include + +#include "secnet.h" + +#include "keccak1600.h" +#include "crypto-test.h" + +enum { + RZ, NROUT, + RX = NROUT, RN, NREG +}; + +static void test_p(struct reg *out, const struct reg *in, void *ctx) +{ + keccak1600_state u; + kludge64 t[25]; + unsigned i; + + allocate_bytes(&out[RZ].v, 200); + keccak1600_init(&u); + for (i = 0; i < 25; i++) LOAD64_L_(t[i], in[RX].v.bytes.p + 8*i); + keccak1600_mix(&u, t, 25); + keccak1600_p(&u, &u, in[RN].v.u); + keccak1600_extract(&u, t, 25); + for (i = 0; i < 25; i++) STORE64_L_(out[RZ].v.bytes.p + 8*i, t[i]); +} + +#define REG_X { "x", RX, ®ty_bytes, 0 } +#define REG_N { "n", RN, ®ty_uint, 0 } +#define REG_Z { "z", RZ, ®ty_bytes, 0 } +static const struct regdef + p_regs[] = { REG_X, REG_N, REG_Z, REGLIST_END }; + +static const struct test tests[] = { + { "p", run_test, p_regs, test_p }, + { 0 } +}; + +int main(void) + { return run_test_suite(NROUT, NREG, sizeof(struct reg), tests, stdin); }