Skip to content

Commit bdc7ce6

Browse files
authored
Merge pull request #10 from kkuehlz/kkuehler/sha3_consolidate
consolidate sha configs
2 parents b748799 + a3c496b commit bdc7ce6

File tree

5 files changed

+13
-32
lines changed

5 files changed

+13
-32
lines changed

include/cthash/sha3/common.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ template <typename Config> struct keccak_hasher: basic_keccak_hasher<Config> {
308308
using super::final;
309309
};
310310

311+
template <size_t DigestBits>
312+
struct sha_config {
313+
static constexpr size_t digest_length_bit = DigestBits;
314+
static constexpr size_t capacity_bit = DigestBits * 2u;
315+
static constexpr size_t rate_bit = 1600u - capacity_bit;
316+
317+
static constexpr auto suffix = keccak_suffix(2, 0b0000'0010u); // in reverse
318+
};
319+
311320
} // namespace cthash
312321

313322
#endif

include/cthash/sha3/sha3-224.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55

66
namespace cthash {
77

8-
struct sha3_224_config {
9-
static constexpr size_t digest_length_bit = 224u;
10-
static constexpr size_t capacity_bit = digest_length_bit * 2u;
11-
static constexpr size_t rate_bit = 1600u - capacity_bit;
12-
13-
static constexpr auto suffix = keccak_suffix(2, 0b0000'0010u); // in reverse
14-
};
15-
8+
using sha3_224_config = sha_config<224u>;
169
static_assert((sha3_224_config::capacity_bit + sha3_224_config::rate_bit) == 1600u);
1710

1811
using sha3_224 = cthash::keccak_hasher<sha3_224_config>;

include/cthash/sha3/sha3-256.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55

66
namespace cthash {
77

8-
struct sha3_256_config {
9-
static constexpr size_t digest_length_bit = 256u;
10-
static constexpr size_t capacity_bit = digest_length_bit * 2u;
11-
static constexpr size_t rate_bit = 1600u - capacity_bit;
12-
13-
static constexpr auto suffix = keccak_suffix(2, 0b0000'0010u); // in reverse
14-
};
15-
8+
using sha3_256_config = sha_config<256u>;
169
static_assert((sha3_256_config::capacity_bit + sha3_256_config::rate_bit) == 1600u);
1710

1811
using sha3_256 = cthash::keccak_hasher<sha3_256_config>;

include/cthash/sha3/sha3-384.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55

66
namespace cthash {
77

8-
struct sha3_384_config {
9-
static constexpr size_t digest_length_bit = 384u;
10-
static constexpr size_t capacity_bit = digest_length_bit * 2u;
11-
static constexpr size_t rate_bit = 1600u - capacity_bit;
12-
13-
static constexpr auto suffix = keccak_suffix(2, 0b0000'0010u); // in reverse
14-
};
15-
8+
using sha3_384_config = sha_config<384u>;
169
static_assert((sha3_384_config::capacity_bit + sha3_384_config::rate_bit) == 1600u);
1710

1811
using sha3_384 = cthash::keccak_hasher<sha3_384_config>;

include/cthash/sha3/sha3-512.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55

66
namespace cthash {
77

8-
struct sha3_512_config {
9-
static constexpr size_t digest_length_bit = 512u;
10-
static constexpr size_t capacity_bit = digest_length_bit * 2u;
11-
static constexpr size_t rate_bit = 1600u - capacity_bit;
12-
13-
static constexpr auto suffix = keccak_suffix(2, 0b0000'0010u); // in reverse
14-
};
15-
8+
using sha3_512_config = sha_config<512u>;
169
static_assert((sha3_512_config::capacity_bit + sha3_512_config::rate_bit) == 1600u);
1710

1811
using sha3_512 = cthash::keccak_hasher<sha3_512_config>;

0 commit comments

Comments
 (0)