aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-07-07 14:05:03 +0200
committerMattias Andrée <maandree@kth.se>2022-07-07 14:05:03 +0200
commitc799f8fcf1210079a5f00fa944d8e8c59a37fc60 (patch)
treee0056c8e10c2e29be0c42e0a2187e9b2405f444a
parentUse malloc by default but allow bounded alloca (diff)
downloadlibsha1-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>
-rw-r--r--algorithm_output_size.c12
-rw-r--r--hmac_state_output_size.c6
-rw-r--r--libsha1.h46
-rw-r--r--state_output_size.c6
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 <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
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);