Prof. Falken
Prof. Falken

Reputation: 24937

Are there any easy way to use libraries for hashing data arrays?

I am thinking about using CRC-32 or SHA-1, possibly both in a C program I develop on Linux (Ubuntu).

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

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

Upvotes: 1

Views: 742

Answers (3)

caf
caf

Reputation: 239311

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.

Upvotes: 2

Jonathan Leffler
Jonathan Leffler

Reputation: 754820

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.

Upvotes: 1

Klark
Klark

Reputation: 8280

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

Upvotes: 1

Related Questions