开发者

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 slightl开发者_如何学JAVAy 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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜