Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some widely used cryptography / hash libraries in C?

Tags:

c

cryptography

I've been working on cryptography implementations in C. I am required to use hash a message using any one of the popular hash functions like SHA,MD5, etc.

In Java, there is a security library which takes care of these things.
But how do I do the same in C?

for example: char *str = "this is a message"; char *hash = SHA(str);

Something of this sort. It would be of great help if some one can point me to some library which has already implemented these functions which i can call for my program.

Thanks!

like image 603
Maverickgugu Avatar asked Apr 12 '11 15:04

Maverickgugu


2 Answers

sphlib is an opensource library which provides optimized (but portable) implementations in C of many hash functions.

OpenSSL is a more generic cryptographic library, which is widely deployed and provides implementations of hash functions, too (less hash functions than sphlib, but it also includes other cryptographic primitives).

like image 168
Thomas Pornin Avatar answered Sep 19 '22 11:09

Thomas Pornin


OpenSSL is indeed widely available. For your example you could use

unsigned char digest[SHA_DIGEST_LENGTH]; 
char *str = "this is a string";
SHA1(str, strlen(str), digest);
like image 32
Henno Brandsma Avatar answered Sep 22 '22 11:09

Henno Brandsma