Skip to content

Instantly share code, notes, and snippets.

@cschamp
Created April 2, 2009 23:45
Show Gist options
  • Save cschamp/89566 to your computer and use it in GitHub Desktop.
Save cschamp/89566 to your computer and use it in GitHub Desktop.
#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