diff options
author | Mikhail Gusarov <dottedmag@dottedmag.net> | 2009-10-29 01:54:00 +0600 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2009-10-28 15:49:38 -0700 |
commit | ccf4a69db747b000aee09072aac0a2891bde139a (patch) | |
tree | 8d30f6c94d8fd37bb5288ca933e56101de87913f /os/xsha1.c | |
parent | 8613e4b0eb04150b1e377871f02b164be5d001e9 (diff) |
os: Add libsha1 as a choice of SHA1 implementation
There are small systems which don't need OpenSSL or gcrypt.
Add libsha1 (http://github.com/dottedmag/libsha1) as an alternative
small SHA1 implementation.
Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'os/xsha1.c')
-rw-r--r-- | os/xsha1.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/os/xsha1.c b/os/xsha1.c index 723521e05..94092caa7 100644 --- a/os/xsha1.c +++ b/os/xsha1.c @@ -72,6 +72,32 @@ int x_sha1_final(void *ctx, unsigned char result[20]) return 1; } +#elif defined(HAVE_SHA1_IN_LIBSHA1) /* Use libsha1 */ + +# include <libsha1.h> + +void *x_sha1_init(void) +{ + sha1_ctx *ctx = xalloc(sizeof(*ctx)); + if(!ctx) + return NULL; + sha1_begin(ctx); + return ctx; +} + +int x_sha1_update(void *ctx, void *data, int size) +{ + sha1_hash(data, size, ctx); + return 1; +} + +int x_sha1_final(void *ctx, unsigned char result[20]) +{ + sha1_end(result, ctx); + xfree(ctx); + return 1; +} + #else /* Use OpenSSL's libcrypto */ # include <stddef.h> /* buggy openssl/sha.h wants size_t */ |