Skip to content

Commit

Permalink
Fix ptr addition
Browse files Browse the repository at this point in the history
  • Loading branch information
moex3 committed Jan 4, 2022
1 parent 0b41258 commit 6771029
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions md4.c
Expand Up @@ -82,16 +82,17 @@ void md4_init(struct md4_ctx *ctx) {
*/
void md4_update(struct md4_ctx *ctx, const void *data, unsigned long len) {
unsigned char * byte_data = (unsigned char *)data;
unsigned char * byte_block = (unsigned char *)ctx->block;
// block中空余的字节数
const u32 avail = sizeof(ctx->block) - (ctx->byte_count & 0x3f);
ctx->byte_count += len;
// data不足以装满一个block则存入后直接返回
if (avail > len) {
memcpy(ctx->block + (sizeof(ctx->block) - avail), byte_data, len);
memcpy(byte_block + (sizeof(ctx->block) - avail), byte_data, len);
return;
}
// 装满一个block后更新状态寄存器
memcpy(ctx->block + (sizeof(ctx->block) - avail), byte_data, avail);
memcpy(byte_block + (sizeof(ctx->block) - avail), byte_data, avail);
// TODO
md4_transform(ctx->hash, ctx->block);
byte_data += avail;
Expand Down Expand Up @@ -144,4 +145,4 @@ void md4(const unsigned char *data, unsigned long len, unsigned char *hash) {
md4_init(&ctx);
md4_update(&ctx, data, len);
md4_final(&ctx, hash);
}
}

0 comments on commit 6771029

Please sign in to comment.