diff --git a/sys/crypto/sha256.c b/sys/crypto/sha256.c index ce4d615d89f47f3891c18af2fa89c28bed24c4b8..46b29b4b9cbb390c39c6754c49520ff10eacdd54 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 c5a1a6e0610da575456c519b3b17742a0ea80d76..288bb2d7e63e21200d2a9ece38636dfc3091782f 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_ */