Fix various bugs relating to digest algorithm registration and wrapping

This commit is contained in:
Dag-Erling Smørgrav 2015-10-03 09:32:44 +00:00 committed by des
parent 8d087eeb64
commit 398abda6b0
7 changed files with 15 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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 *);

View file

@ -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 \

View file

@ -30,8 +30,10 @@
#include "cryb/impl.h"
#include <stdint.h>
#include <string.h>
#include <cryb/digest.h>
#include <cryb/md2.h>
#include <cryb/md4.h>
#include <cryb/md5.h>
@ -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);

View file

@ -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,

View file

@ -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,