Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Created December 19, 2012 17:19
Show Gist options
  • Save cupakromer/4338466 to your computer and use it in GitHub Desktop.
Save cupakromer/4338466 to your computer and use it in GitHub Desktop.
Attempt at SHA256 in C
Compile with `gcc -Wall -lssl -lcrypto shait.c`
// Compile with:
// gcc shait.c -lssl -lcrypto
#include <stdio.h>
#include <openssl/sha.h>
int main(int argc,char **argv)
{
SHA256_CTX context;
unsigned char md[SHA256_DIGEST_LENGTH];
int j;
SHA256_Init(&context);
SHA256_Update(&context, "hello world", 11);
SHA256_Final(md, &context);
printf("\n\n");
printf("Output should be: b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\n");
printf("Output is : ");
for (j=0;j<SHA256_DIGEST_LENGTH;j++) printf("%02x", md[j]);
printf("\n\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment