| 1 | /* |
| 2 | * keccak1600-test.c: test harness for Keccak primitive |
| 3 | * |
| 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.) |
| 7 | */ |
| 8 | /* |
| 9 | * This file is Free Software. It was originally written for secnet. |
| 10 | * |
| 11 | * Copyright 2019 Mark Wooding |
| 12 | * |
| 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 |
| 16 | * later version. |
| 17 | * |
| 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 |
| 21 | * version. |
| 22 | * |
| 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. |
| 27 | * |
| 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. |
| 31 | */ |
| 32 | |
| 33 | #include <stdio.h> |
| 34 | |
| 35 | #include "secnet.h" |
| 36 | |
| 37 | #include "keccak1600.h" |
| 38 | #include "crypto-test.h" |
| 39 | |
| 40 | enum { |
| 41 | RZ, NROUT, |
| 42 | RX = NROUT, RN, NREG |
| 43 | }; |
| 44 | |
| 45 | static void test_p(struct reg *out, const struct reg *in, void *ctx) |
| 46 | { |
| 47 | keccak1600_state u; |
| 48 | kludge64 t[25]; |
| 49 | unsigned i; |
| 50 | |
| 51 | allocate_bytes(&out[RZ].v, 200); |
| 52 | keccak1600_init(&u); |
| 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]); |
| 58 | } |
| 59 | |
| 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 }; |
| 65 | |
| 66 | static const struct test tests[] = { |
| 67 | { "p", run_test, p_regs, test_p }, |
| 68 | { 0 } |
| 69 | }; |
| 70 | |
| 71 | int main(void) |
| 72 | { return run_test_suite(NROUT, NREG, sizeof(struct reg), tests, stdin); } |