diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2023-04-15 18:19:07 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2023-04-15 18:19:07 +0000 |
commit | 1fc0664c913fa14c664e8ae57ca9ca51ad1169a4 (patch) | |
tree | 56475568275fb49bebde6afc425a2d17a1825b9c /lib/libcrypto/sha | |
parent | 3e120dee3ff8ed1bac0b073fc97abbee5d58af77 (diff) |
Pull constant tables out of sha3_keccakf().
Diffstat (limited to 'lib/libcrypto/sha')
-rw-r--r-- | lib/libcrypto/sha/sha3.c | 48 |
1 files 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__ |