diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-07 14:05:03 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-07 14:05:03 +0200 |
commit | c799f8fcf1210079a5f00fa944d8e8c59a37fc60 (patch) | |
tree | e0056c8e10c2e29be0c42e0a2187e9b2405f444a /libsha1.h | |
parent | Use malloc by default but allow bounded alloca (diff) | |
download | libsha1-c799f8fcf1210079a5f00fa944d8e8c59a37fc60.tar.gz libsha1-c799f8fcf1210079a5f00fa944d8e8c59a37fc60.tar.bz2 libsha1-c799f8fcf1210079a5f00fa944d8e8c59a37fc60.tar.xz |
Inline some output size functions
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libsha1.h')
-rw-r--r-- | libsha1.h | 46 |
1 files changed, 33 insertions, 13 deletions
@@ -1,7 +1,8 @@ /* See LICENSE file for copyright and license details. */ #ifndef LIBSHA1_H -#define LIBSHA1_H 1 +#define LIBSHA1_H 1 +#include <errno.h> #include <stdint.h> #include <stddef.h> @@ -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 |