From 4fa3a839108f7fa587f90706d650555d0eda1908 Mon Sep 17 00:00:00 2001 From: BytesGalore Date: Tue, 26 Jul 2016 10:16:27 +0200 Subject: [PATCH] hashes/md5: changed data-parameter types to `void*` --- sys/hashes/md5.c | 24 ++++++++++++++---------- sys/include/hashes/md5.h | 14 +++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/sys/hashes/md5.c b/sys/hashes/md5.c index 869d9fee5..ff6ad30b5 100644 --- a/sys/hashes/md5.c +++ b/sys/hashes/md5.c @@ -232,7 +232,7 @@ void md5_init(md5_ctx_t *ctx) ctx->abcd[3] = 0x10325476; } -void md5_update(md5_ctx_t *ctx, const uint8_t *data, size_t len) +void md5_update(md5_ctx_t *ctx, const void *data, size_t len) { /* Add the new block's length to the total length. */ ctx->len += (uint32_t)len; @@ -240,7 +240,9 @@ void md5_update(md5_ctx_t *ctx, const uint8_t *data, size_t len) /* Copy the new block's data into the context block. * Call the permute() function whenever the context block is full. */ for (size_t i = 0; i < len; i++) { - ctx->block[ctx->b_used] = data[i]; + const uint8_t *d = data; + + ctx->block[ctx->b_used] = d[i]; (ctx->b_used)++; if (64 == ctx->b_used) { permute(ctx->abcd, ctx->block); @@ -250,7 +252,7 @@ void md5_update(md5_ctx_t *ctx, const uint8_t *data, size_t len) } -void md5_final(md5_ctx_t *ctx, uint8_t *dst) +void md5_final(md5_ctx_t *ctx, void *digest) { uint32_t l; @@ -289,18 +291,20 @@ void md5_final(md5_ctx_t *ctx, uint8_t *dst) /* Now copy the result into the output buffer and we're done */ for (int i = 0; i < 4; i++) { - dst[ 0 + i] = GETBYTE(ctx->abcd[0], i); - dst[ 4 + i] = GETBYTE(ctx->abcd[1], i); - dst[ 8 + i] = GETBYTE(ctx->abcd[2], i); - dst[12 + i] = GETBYTE(ctx->abcd[3], i); + uint8_t *d = digest; + + d[ 0 + i] = GETBYTE(ctx->abcd[0], i); + d[ 4 + i] = GETBYTE(ctx->abcd[1], i); + d[ 8 + i] = GETBYTE(ctx->abcd[2], i); + d[12 + i] = GETBYTE(ctx->abcd[3], i); } } -void md5(uint8_t *dst, const uint8_t *src, size_t len) +void md5(void *digest, const void *data, size_t len) { md5_ctx_t ctx; md5_init(&ctx); - md5_update(&ctx, src, len); - md5_final(&ctx, dst); + md5_update(&ctx, data, len); + md5_final(&ctx, digest); } diff --git a/sys/include/hashes/md5.h b/sys/include/hashes/md5.h index 922f4d90c..ccb38a656 100644 --- a/sys/include/hashes/md5.h +++ b/sys/include/hashes/md5.h @@ -101,24 +101,24 @@ void md5_init(md5_ctx_t *ctx); * @param[in] data Input data * @param[in] len Length of @p data */ -void md5_update(md5_ctx_t *ctx, const uint8_t *data, size_t len); +void md5_update(md5_ctx_t *ctx, const void *data, size_t len); /** * @brief Finish up the current MD5 hash calculation generate the final hash * * @param[in] ctx Context of the current calculation - * @param[out] dst Result location, must be 16 byte + * @param[out] digest Result location, must be 16 byte */ -void md5_final(md5_ctx_t *ctx, uint8_t *dst); +void md5_final(md5_ctx_t *ctx, void *digest); /** * @brief Calculate a MD5 hash from the given data * - * @param[out] dst Result location, must be 16 byte - * @param[in] src Input data - * @param[in] len Length of @p src + * @param[out] digest Result location, must be 16 byte + * @param[in] data Input data + * @param[in] len Length of @p src */ -void md5(uint8_t *dst, const uint8_t *src, size_t len); +void md5(void *digest, const void *data, size_t len); #ifdef __cplusplus }