2 * keccak1600-test.c: test harness for Keccak primitive
4 * (The implementations originally came with different test arrangements,
5 * with complicated external dependencies. This file replicates the original
6 * tests, but without the dependencies.)
9 * This file is Free Software. It was originally written for secnet.
11 * Copyright 2019 Mark Wooding
13 * You may redistribute secnet as a whole and/or modify it under the
14 * terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 3, or (at your option) any
18 * You may redistribute this file and/or modify it under the terms of
19 * the GNU General Public License as published by the Free Software
20 * Foundation; either version 2, or (at your option) any later
23 * This software is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this software; if not, see
30 * https://www.gnu.org/licenses/gpl.html.
37 #include "keccak1600.h"
38 #include "crypto-test.h"
45 static void test_p(struct reg
*out
, const struct reg
*in
, void *ctx
)
51 allocate_bytes(&out
[RZ
].v
, 200);
53 for (i
= 0; i
< 25; i
++) LOAD64_L_(t
[i
], in
[RX
].v
.bytes
.p
+ 8*i
);
54 keccak1600_mix(&u
, t
, 25);
55 keccak1600_p(&u
, &u
, in
[RN
].v
.u
);
56 keccak1600_extract(&u
, t
, 25);
57 for (i
= 0; i
< 25; i
++) STORE64_L_(out
[RZ
].v
.bytes
.p
+ 8*i
, t
[i
]);
60 #define REG_X { "x", RX, ®ty_bytes, 0 }
61 #define REG_N { "n", RN, ®ty_uint, 0 }
62 #define REG_Z { "z", RZ, ®ty_bytes, 0 }
63 static const struct regdef
64 p_regs
[] = { REG_X
, REG_N
, REG_Z
, REGLIST_END
};
66 static const struct test tests
[] = {
67 { "p", run_test
, p_regs
, test_p
},
72 { return run_test_suite(NROUT
, NREG
, sizeof(struct reg
), tests
, stdin
); }