From 618cb30e307321ecda4cca4e5472d406c93ba384 Mon Sep 17 00:00:00 2001 From: Christian Mehlis <mehlis@inf.fu-berlin.de> Date: Mon, 12 Aug 2013 18:26:17 +0200 Subject: [PATCH] add the default wrapper for sha256 --- sys/crypto/sha256.c | 16 ++++++++++++++++ sys/include/sha256.h | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sys/crypto/sha256.c b/sys/crypto/sha256.c index ce4d615d89..46b29b4b9c 100644 --- a/sys/crypto/sha256.c +++ b/sys/crypto/sha256.c @@ -228,3 +228,19 @@ void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) /* Clear the context state */ memset((void *) ctx, 0, sizeof(*ctx)); } + +unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md) +{ + SHA256_CTX c; + static unsigned char m[SHA256_DIGEST_LENGTH]; + + if (md == NULL) { + md = m; + } + + SHA256_Init(&c); + SHA256_Update(&c, d, n); + SHA256_Final(md, &c); + + return md; +} diff --git a/sys/include/sha256.h b/sys/include/sha256.h index c5a1a6e061..288bb2d7e6 100644 --- a/sys/include/sha256.h +++ b/sys/include/sha256.h @@ -65,4 +65,16 @@ void SHA256_Update(SHA256_CTX *ctx, const void *in, size_t len); */ void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx); +/** + * @brief A wrapper function to simplify the generation of a hash, this is + * usefull for generating sha256 for one buffer + * + * @param d pointer to the buffer to generate hash from + * @param n length of the buffer + * @param md optional pointer to an array for the result, length must be + * SHA256_DIGEST_LENGTH + * if md == NULL, one static buffer is used + */ +unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md); + #endif /* !_SHA256_H_ */ -- GitLab