diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-07 15:18:51 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-07 15:18:51 +0200 |
commit | 77e0e09222fdc121d9044289229a6f19c0ba406b (patch) | |
tree | a81363e9a94fdf92c1065fd926f6afa790c33169 | |
parent | Add libsha2.7 (diff) | |
download | libsha2-77e0e09222fdc121d9044289229a6f19c0ba406b.tar.gz libsha2-77e0e09222fdc121d9044289229a6f19c0ba406b.tar.bz2 libsha2-77e0e09222fdc121d9044289229a6f19c0ba406b.tar.xz |
Inline the output size functions
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | algorithm_output_size.c | 16 | ||||
-rw-r--r-- | hmac_state_output_size.c | 6 | ||||
-rw-r--r-- | libsha2.h | 47 | ||||
-rw-r--r-- | state_output_size.c | 12 |
4 files changed, 38 insertions, 43 deletions
diff --git a/algorithm_output_size.c b/algorithm_output_size.c index f7a0352..4457c49 100644 --- a/algorithm_output_size.c +++ b/algorithm_output_size.c @@ -8,18 +8,4 @@ * @param algorithm The hashing algorithm * @return The number of bytes in the output, zero on error */ -size_t -libsha2_algorithm_output_size(enum libsha2_algorithm algorithm) -{ - switch (algorithm) { - case LIBSHA2_224: return 28; - case LIBSHA2_256: return 32; - case LIBSHA2_384: return 48; - case LIBSHA2_512: return 64; - case LIBSHA2_512_224: return 28; - case LIBSHA2_512_256: return 32; - default: - errno = EINVAL; - return 0; - } -} +extern inline size_t libsha2_algorithm_output_size(enum libsha2_algorithm); diff --git a/hmac_state_output_size.c b/hmac_state_output_size.c index d1a94dd..eff86b9 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 -libsha2_hmac_state_output_size(const struct libsha2_hmac_state *restrict state) -{ - return libsha2_algorithm_output_size(state->sha2_state.algorithm); -} +extern inline size_t libsha2_hmac_state_output_size(const struct libsha2_hmac_state *restrict); @@ -2,6 +2,7 @@ #ifndef LIBSHA2_H #define LIBSHA2_H 1 +#include <errno.h> #include <stdint.h> #include <stddef.h> @@ -195,26 +196,44 @@ __attribute__((__leaf__, __nothrow__, __nonnull__)) int libsha2_init(struct libsha2_state *restrict, enum libsha2_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 libsha2_state_output_size(const struct libsha2_state *restrict); +inline size_t +libsha2_algorithm_output_size(enum libsha2_algorithm algorithm__) +{ + switch (algorithm__) { + case LIBSHA2_224: return 28; + case LIBSHA2_256: return 32; + case LIBSHA2_384: return 48; + case LIBSHA2_512: return 64; + case LIBSHA2_512_224: return 28; + case LIBSHA2_512_256: return 32; + 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 libsha2_algorithm_output_size(enum libsha2_algorithm); +inline size_t +libsha2_state_output_size(const struct libsha2_state *restrict state__) +{ + return libsha2_algorithm_output_size(state__->algorithm); +} /** * Absorb more of the message @@ -338,9 +357,13 @@ int libsha2_hmac_init(struct libsha2_hmac_state *restrict, enum libsha2_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 libsha2_hmac_state_output_size(const struct libsha2_hmac_state *restrict); +inline size_t +libsha2_hmac_state_output_size(const struct libsha2_hmac_state *restrict state__) +{ + return libsha2_algorithm_output_size(state__->sha2_state.algorithm); +} /** * Feed data into the HMAC algorithm diff --git a/state_output_size.c b/state_output_size.c index 85da7c2..9ab0f51 100644 --- a/state_output_size.c +++ b/state_output_size.c @@ -2,14 +2,4 @@ #include "common.h" -/** - * Get the output size of the algorithm specified for a state - * - * @param state The state - * @return The number of bytes in the output, zero on error - */ -size_t -libsha2_state_output_size(const struct libsha2_state *restrict state) -{ - return libsha2_algorithm_output_size(state->algorithm); -} +extern inline size_t libsha2_state_output_size(const struct libsha2_state *restrict); |