tags:

views:

63

answers:

3

I am thinking about using CRC32 or SHA1, possibly both in C program I develop on Linux (Ubuntu).

Are there any easy to use libraries for either? Cutting and pasting a CRC32 algorithm into the source code of my program seems simple enough, but doing the same for SHA1 feels slightly shaky. Are there any easy to use libraries, preferably in Ubuntu but not necessarily?

I am using C, but C++ would be OK if I had to.

+1  A: 

You have a lot of free libraries for SHA. For example this one is great: http://www.cryptopp.com/ (C++)

Klark
Amigable Clark Kant
+1  A: 

Consider using LibTomCrypt, which is pure C. You'd have to download, compile and install that, of course. You'd probably find that the OpenSSL libraries are already installed - but the interface to those is more complex (more flexible too, but you probably don't need the flexibility). Offhand, I think they're pure C too.

Jonathan Leffler
+1  A: 

The OpenSSL interface is pretty simple:

#include <openssl/sha.h>

unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md);

d is a pointer to the input to be hashed, with length n. md is a pointer to SHA_DIGEST_LENGTH bytes where the SHA1 hash will be stored.

caf