Skip to content
Snippets Groups Projects
Commit 618cb30e authored by Christian Mehlis's avatar Christian Mehlis
Browse files

add the default wrapper for sha256

parent a02e00b6
No related branches found
No related tags found
No related merge requests found
...@@ -228,3 +228,19 @@ void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) ...@@ -228,3 +228,19 @@ void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
/* Clear the context state */ /* Clear the context state */
memset((void *) ctx, 0, sizeof(*ctx)); 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;
}
...@@ -65,4 +65,16 @@ void SHA256_Update(SHA256_CTX *ctx, const void *in, size_t len); ...@@ -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); 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_ */ #endif /* !_SHA256_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment