From c799f8fcf1210079a5f00fa944d8e8c59a37fc60 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 7 Jul 2022 14:05:03 +0200 Subject: Inline some output size functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- algorithm_output_size.c | 12 +----------- hmac_state_output_size.c | 6 +----- libsha1.h | 46 +++++++++++++++++++++++++++++++++------------- state_output_size.c | 6 +----- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/algorithm_output_size.c b/algorithm_output_size.c index ffba6d8..c91c23d 100644 --- a/algorithm_output_size.c +++ b/algorithm_output_size.c @@ -8,14 +8,4 @@ * @param algorithm The hashing algorithm * @return The number of bytes in the output, zero on error */ -size_t -libsha1_algorithm_output_size(enum libsha1_algorithm algorithm) -{ - switch (algorithm) { - case LIBSHA1_0: return 20; - case LIBSHA1_1: return 20; - default: - errno = EINVAL; - return 0; - } -} +extern inline size_t libsha1_algorithm_output_size(enum libsha1_algorithm); diff --git a/hmac_state_output_size.c b/hmac_state_output_size.c index 68e5ed2..71be1b2 100644 --- a/hmac_state_output_size.c +++ b/hmac_state_output_size.c @@ -8,8 +8,4 @@ * @param state The state * @return The number of bytes in the output, zero on error */ -size_t -libsha1_hmac_state_output_size(const struct libsha1_hmac_state *restrict state) -{ - return libsha1_algorithm_output_size(state->sha1_state.algorithm); -} +extern inline size_t libsha1_hmac_state_output_size(const struct libsha1_hmac_state *restrict); diff --git a/libsha1.h b/libsha1.h index 7e8e596..9865b3b 100644 --- a/libsha1.h +++ b/libsha1.h @@ -1,7 +1,8 @@ /* See LICENSE file for copyright and license details. */ #ifndef LIBSHA1_H -#define LIBSHA1_H 1 +#define LIBSHA1_H 1 +#include #include #include @@ -118,26 +119,41 @@ __attribute__((__leaf__, __nothrow__, __nonnull__)) int libsha1_init(struct libsha1_state *restrict, enum libsha1_algorithm); /** - * Get the output size of the algorithm specified for a state + * Get the output size of an algorithm * - * @param state The state - * @return The number of bytes in the output, zero on error + * @param algorithm The hashing algorithm + * @return The number of bytes in the output, zero on error */ #if defined(__GNUC__) -__attribute__((__nothrow__, __nonnull__, __pure__)) +__attribute__((__warn_unused_result__, __nothrow__)) #endif -size_t libsha1_state_output_size(const struct libsha1_state *restrict); +inline size_t +libsha1_algorithm_output_size(enum libsha1_algorithm algorithm__) +{ + switch (algorithm__) { + case LIBSHA1_0: return 20; + case LIBSHA1_1: return 20; + default: + errno = EINVAL; + return 0; + } +} /** - * Get the output size of an algorithm + * Get the output size of the algorithm specified for a state * - * @param algorithm The hashing algorithm - * @return The number of bytes in the output, zero on error + * @param state The state + * @return The number of bytes in the output, zero on error */ #if defined(__GNUC__) -__attribute__((__leaf__, __nothrow__, __const__)) +__attribute__((__warn_unused_result__, __nothrow__, __nonnull__)) #endif -size_t libsha1_algorithm_output_size(enum libsha1_algorithm); +inline size_t +libsha1_state_output_size(const struct libsha1_state *restrict state__) +{ + return libsha1_algorithm_output_size(state__->algorithm); +} + /** * Absorb more of the message @@ -261,9 +277,13 @@ int libsha1_hmac_init(struct libsha1_hmac_state *restrict, enum libsha1_algorith * @return The number of bytes in the output, zero on error */ #if defined(__GNUC__) -__attribute__((__nothrow__, __nonnull__, __pure__)) +__attribute__((__warn_unused_result__, __nothrow__, __nonnull__)) #endif -size_t libsha1_hmac_state_output_size(const struct libsha1_hmac_state *restrict); +inline size_t +libsha1_hmac_state_output_size(const struct libsha1_hmac_state *restrict state__) +{ + return libsha1_algorithm_output_size(state__->sha1_state.algorithm); +} /** * Feed data into the HMAC algorithm diff --git a/state_output_size.c b/state_output_size.c index 3b3d14d..c148a44 100644 --- a/state_output_size.c +++ b/state_output_size.c @@ -8,8 +8,4 @@ * @param state The state * @return The number of bytes in the output, zero on error */ -size_t -libsha1_state_output_size(const struct libsha1_state *restrict state) -{ - return libsha1_algorithm_output_size(state->algorithm); -} +extern inline size_t libsha1_state_output_size(const struct libsha1_state *restrict state); -- cgit v1.2.3-70-g09d2