From 5c0ae387c82c85dd5285885195e92f0daed1c814 Mon Sep 17 00:00:00 2001 From: jsing Date: Sat, 15 Apr 2023 18:19:06 +0000 Subject: [PATCH] Pull constant tables out of sha3_keccakf(). --- lib/libcrypto/sha/sha3.c | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/libcrypto/sha/sha3.c b/lib/libcrypto/sha/sha3.c index ef53ecbc0ac..a3ef95f8154 100644 --- a/lib/libcrypto/sha/sha3.c +++ b/lib/libcrypto/sha/sha3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sha3.c,v 1.5 2023/04/15 18:14:21 jsing Exp $ */ +/* $OpenBSD: sha3.c,v 1.6 2023/04/15 18:19:06 jsing Exp $ */ /* * The MIT License (MIT) * @@ -25,30 +25,30 @@ #include "sha3_internal.h" +static const uint64_t sha3_keccakf_rndc[24] = { + 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, + 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, + 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 +}; +static const int sha3_keccakf_rotc[24] = { + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 +}; +static const int sha3_keccakf_piln[24] = { + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 +}; + void sha3_keccakf(uint64_t st[25]) { - const uint64_t keccakf_rndc[24] = { - 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, - 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, - 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, - 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, - 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, - 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, - 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, - 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 - }; - const int keccakf_rotc[24] = { - 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, - 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 - }; - const int keccakf_piln[24] = { - 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, - 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 - }; - - int i, j, r; uint64_t t, bc[5]; + int i, j, r; #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ uint8_t *v; @@ -77,9 +77,9 @@ sha3_keccakf(uint64_t st[25]) /* Rho Pi */ t = st[1]; for (i = 0; i < 24; i++) { - j = keccakf_piln[i]; + j = sha3_keccakf_piln[i]; bc[0] = st[j]; - st[j] = ROTL64(t, keccakf_rotc[i]); + st[j] = ROTL64(t, sha3_keccakf_rotc[i]); t = bc[0]; } @@ -92,7 +92,7 @@ sha3_keccakf(uint64_t st[25]) } /* Iota */ - st[0] ^= keccakf_rndc[r]; + st[0] ^= sha3_keccakf_rndc[r]; } #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ -- 2.20.1