Created
April 2, 2009 23:45
-
-
Save cschamp/89566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <openssl/evp.h> | |
unsigned char * | |
sha1digest(unsigned char *buf, unsigned int len, unsigned int *olen) | |
{ | |
EVP_MD_CTX ctx; | |
const EVP_MD *md; | |
unsigned char *retval; | |
if (buf == NULL) { | |
return NULL; // XXX NEED BETTER ERROR PROPAGATION | |
} | |
md = EVP_sha1(); | |
if (md == NULL) | |
return NULL; // XXX NEED BETTER ERROR PROPAGATION | |
retval = malloc(EVP_MAX_MD_SIZE); | |
if (retval == NULL) | |
return NULL; // XXX NEED BETTER ERROR PROPAGATION | |
EVP_DigestInit(&ctx, md); | |
EVP_DigestUpdate(&ctx, buf, len); | |
EVP_DigestFinal(&ctx, retval, olen); | |
return retval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment