add the default wrapper for sha256

dev/timer
Christian Mehlis 10 years ago
parent a02e00b68b
commit 618cb30e30

@ -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;
}

@ -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_ */

Loading…
Cancel
Save