From 7bb7d04b4561545d3be1c82abfb87bd01b28a0c1 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 29 Apr 2024 18:34:32 -0400 Subject: sha3.[hc]: add sha3_backend() --- sha3.c | 10 +++++++++- sha3.h | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sha3.c b/sha3.c index 26ac022..6b4c2fd 100644 --- a/sha3.c +++ b/sha3.c @@ -751,7 +751,6 @@ static inline size_t absorb12(sha3_state_t * const a, size_t num_bytes, const si return num_bytes; } - // Get rate (number of bytes that can be absorbed before the internal // state is permuted). // @@ -2094,6 +2093,15 @@ void k12_once(const uint8_t *src, const size_t src_len, uint8_t *dst, const size k12_custom_once(src, src_len, NULL, 0, dst, dst_len); } +// Return backend name. +const char *sha3_backend(void) { +#if SHA3_BACKEND == SHA3_BACKEND_AVX512 + return "avx512"; +#elif SHA3_BACKEND == SHA3_BACKEND_SCALAR + return "scalar"; +#endif /* SHA3_BACKEND */ +} + #ifdef SHA3_TEST #include // printf() #include // malloc() (used in test_kangarootwelve()) diff --git a/sha3.h b/sha3.h index c9b6f44..1937b26 100644 --- a/sha3.h +++ b/sha3.h @@ -2352,6 +2352,23 @@ void k12_init(k12_t *k12, const uint8_t *src, const size_t src_len, const uint8_ */ void k12_squeeze(k12_t *k12, uint8_t *dst, const size_t len); +/** + * @defgroup misc Miscellaneous + * @brief Miscellaneous functions. + */ + +/** + * @brief Get name of backend. + * @ingroup misc + * + * @note Returns a read-only string which much not be freed by the + * caller. + * + * Example: + * @snippet{trimleft} 06-all/all-fns.c sha3_backend + */ +const char *sha3_backend(void); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit v1.2.3