From 398abda6b0c11b42c5967bbb26055ccc1a93b5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sat, 3 Oct 2015 09:32:44 +0000 Subject: [PATCH] Fix various bugs relating to digest algorithm registration and wrapping --- include/cryb/digest.h | 2 +- include/cryb/md2.h | 2 +- include/cryb/sha1.h | 2 -- lib/digest/Makefile.am | 1 + lib/digest/digest.c | 18 ++++++++++-------- lib/digest/md2.c | 2 +- lib/digest/md4.c | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/cryb/digest.h b/include/cryb/digest.h index 5cec278..42ae568 100644 --- a/include/cryb/digest.h +++ b/include/cryb/digest.h @@ -66,6 +66,6 @@ const digest_algorithm *get_digest_algorithm(const char *); #define digest_final(alg, ctx, md) \ (alg)->final((ctx), (md)) #define digest_complete(alg, buf, len, md) \ - (alg)->update((buf), (len), (md)) + (alg)->complete((buf), (len), (md)) #endif diff --git a/include/cryb/md2.h b/include/cryb/md2.h index 8365ea1..3766ff3 100644 --- a/include/cryb/md2.h +++ b/include/cryb/md2.h @@ -42,7 +42,7 @@ #define md2_final cryb_md2_final #define md2_complete cryb_md2_complete -extern digest_algorithm md2_algorithm; +extern digest_algorithm md2_digest; /** * \brief MD2 context structure diff --git a/include/cryb/sha1.h b/include/cryb/sha1.h index 2d04aad..0c30567 100644 --- a/include/cryb/sha1.h +++ b/include/cryb/sha1.h @@ -52,8 +52,6 @@ typedef struct { uint64_t bitlen; } sha1_ctx; -extern digest_algorithm sha1_algorithm; - void sha1_init(sha1_ctx *); void sha1_update(sha1_ctx *, const void *, size_t); void sha1_final(sha1_ctx *, uint8_t *); diff --git a/lib/digest/Makefile.am b/lib/digest/Makefile.am index 96d5779..38e3465 100644 --- a/lib/digest/Makefile.am +++ b/lib/digest/Makefile.am @@ -3,6 +3,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include lib_LTLIBRARIES = libcryb-digest.la libcryb_digest_la_SOURCES = \ + digest.c \ md2.c \ md4.c \ md5.c \ diff --git a/lib/digest/digest.c b/lib/digest/digest.c index d2638a2..2f6f2e4 100644 --- a/lib/digest/digest.c +++ b/lib/digest/digest.c @@ -30,8 +30,10 @@ #include "cryb/impl.h" +#include #include +#include #include #include #include @@ -46,13 +48,13 @@ static void init_digest_algorithms(void) { static const digest_algorithm *algorithms[] = { - &md2_algorithm, - &md4_algorithm, - &md5_algorithm, - &sha1_algorithm, - &sha256_algorithm, - &sha384_algorithm, - &sha512_algorithm, + &md2_digest, + &md4_digest, + &md5_digest, + &sha1_digest, + &sha256_digest, + &sha384_digest, + &sha512_digest, NULL }; cryb_digest_algorithms = algorithms; @@ -64,7 +66,7 @@ get_digest_algorithm(const char *name) const digest_algorithm **algp; if (cryb_digest_algorithms == NULL) - cryb_init_digest_algorithms(); + init_digest_algorithms(); for (algp = cryb_digest_algorithms; *algp != NULL; ++algp) if (strcasecmp((*algp)->name, name) == 0) return (*algp); diff --git a/lib/digest/md2.c b/lib/digest/md2.c index 255be34..07b6fe5 100644 --- a/lib/digest/md2.c +++ b/lib/digest/md2.c @@ -175,7 +175,7 @@ void md2_complete( const void *input, int ilen, uint8_t *output ) memset( &ctx, 0, sizeof( md2_ctx ) ); } -digest_algorithm md2_algorithm = { +digest_algorithm md2_digest = { .name = "md2", .contextlen = sizeof(md2_ctx), .blocklen = MD2_BLOCK_LEN, diff --git a/lib/digest/md4.c b/lib/digest/md4.c index e28ce73..755ed79 100644 --- a/lib/digest/md4.c +++ b/lib/digest/md4.c @@ -250,7 +250,7 @@ void md4_complete( const void *input, int ilen, uint8_t *output ) memset( &ctx, 0, sizeof( md4_ctx ) ); } -digest_algorithm md4_algorithm = { +digest_algorithm md4_digest = { .name = "md4", .contextlen = sizeof(md4_ctx), .blocklen = MD4_BLOCK_LEN,