[Assorted-commits] SF.net SVN: assorted:[1361] sandbox/trunk/src/c/sha1.c
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-05-05 05:43:55
|
Revision: 1361 http://assorted.svn.sourceforge.net/assorted/?rev=1361&view=rev Author: yangzhang Date: 2009-05-05 05:43:42 +0000 (Tue, 05 May 2009) Log Message: ----------- added demo of sha1 hashing using openssl Added Paths: ----------- sandbox/trunk/src/c/sha1.c Added: sandbox/trunk/src/c/sha1.c =================================================================== --- sandbox/trunk/src/c/sha1.c (rev 0) +++ sandbox/trunk/src/c/sha1.c 2009-05-05 05:43:42 UTC (rev 1361) @@ -0,0 +1,20 @@ +#include <openssl/sha.h> +#include <stdio.h> +void run(const char *data, size_t len) { + SHA_CTX c; + unsigned char md[SHA_DIGEST_LENGTH]; + SHA1_Init(&c); + SHA1_Update(&c, data, len); + SHA1_Final(md, &c); + int i; + for (i = 0; i < SHA_DIGEST_LENGTH; ++i) + printf("%02x ", md[i]); + printf("\n"); +} +int main() { + run("hello", 5); + run("hello", 6); + run("hello\n", 6); + run("hello\n", 7); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |