Skip to content

Commit

Permalink
hashes/sha224: Remove static variables from sha224
Browse files Browse the repository at this point in the history
  • Loading branch information
bergzand committed Jan 16, 2024
1 parent bac3f48 commit 434e564
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
11 changes: 3 additions & 8 deletions sys/hashes/sha224.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include <string.h>
#include <assert.h>

#include "hashes/sha224.h"
#include "hashes/sha2xx_common.h"
Expand All @@ -40,18 +41,12 @@ void sha224_init(sha224_context_t *ctx)
ctx->state[7] = 0xBEFA4FA4;
}

void *sha224(const void *data, size_t len, void *digest)
void sha224(const void *data, size_t len, void *digest)
{
sha224_context_t c;
static unsigned char m[SHA224_DIGEST_LENGTH];

if (digest == NULL) {
digest = m;
}
assert(digest);

sha224_init(&c);
sha224_update(&c, data, len);
sha224_final(&c, digest);

return digest;
}
5 changes: 2 additions & 3 deletions sys/include/hashes/sha224.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ static inline void sha224_final(sha224_context_t *ctx, void *digest)
*
* @param[in] data pointer to the buffer to generate hash from
* @param[in] len length of the buffer
* @param[out] digest optional pointer to an array for the result, length must
* @param[out] digest Pointer to an array for the result, length must
* be SHA224_DIGEST_LENGTH
* if digest == NULL, one static buffer is used
*/
void *sha224(const void *data, size_t len, void *digest);
void sha224(const void *data, size_t len, void *digest);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 434e564

Please sign in to comment.