From f1f5aee73d919e1ffc86d2d36ea9aa428d8c5287 Mon Sep 17 00:00:00 2001 From: asterix Date: Thu, 1 Feb 2007 14:45:56 +0000 Subject: [PATCH] Rewrite md2_update function and fix some bug. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@752 38d2e660-2303-0410-9eaa-f027e97ec537 --- algos/md2.c | 101 +++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/algos/md2.c b/algos/md2.c index f99434b3..ade05582 100755 --- a/algos/md2.c +++ b/algos/md2.c @@ -13,6 +13,9 @@ /*#* *#* $Log$ + *#* Revision 1.8 2007/02/01 14:45:56 asterix + *#* Rewrite md2_update function and fix some bug. + *#* *#* Revision 1.7 2007/01/31 18:04:15 asterix *#* Write md2_end function *#* @@ -29,7 +32,7 @@ #include "md2.h" -#include //memset(); +#include //memset(), memcpy(); #include /* @@ -62,40 +65,50 @@ static uint8_t md2_perm[256] = * lenght of block is equal to CONFIG_MD2_BLOCK_LEN. * */ -static void md2_pad(void *block, size_t len_pad) +static void md2_pad(void *_block, size_t len_pad) { + uint8_t *block; + + block = (uint8_t *)_block; + if (len_pad <= CONFIG_MD2_BLOCK_LEN) { - for(int i=(CONFIG_MD2_BLOCK_LEN-len_pad);icounter; - empty_block_len = CONFIG_MD2_BLOCK_LEN - store_block_len; + uint8_t *block_in; + size_t len = CONFIG_MD2_BLOCK_LEN; + size_t i = 0; - /* - * Fill context buffer with input block and compute it. - */ - if(block_len > empty_block_len) - { - memcpy(&context->buffer[store_block_len], block_in, empty_block_len); - md2_compute(context->state, context->checksum, context->buffer); - block_len -= empty_block_len; - } - else + block_in = (uint8_t *)_block_in; + + + while(block_len > 0) { + len -= context->counter; //Free space of buffer. - memcpy(&context->buffer[store_block_len], block_in, block_len); - context->counter += block_len; + if (block_len > len) + { + /* + * Fill or copy into buffer a input block length CONFIG_MD2_BLOCK_LEN and compute it. + */ + memcpy(&context->buffer[context->counter], &block_in[i],len); + md2_compute(context->state,context->checksum, context->buffer); + context->counter = 0; + block_len -= len; + } + else + { + /* + * Copy into buffer remaning input block. + */ + memcpy(&context->buffer[context->counter], &block_in[i], block_len); + context->counter += len; + break; + - } - - /* - * Split input in block long CONFIG_MD2_BLOCK_LEN and compute it. - */ - for(int i = empty_block_len + 1; i + CONFIG_MD2_BLOCK_LEN < block_len; i += CONFIG_MD2_BLOCK_LEN) - { - memcpy(context->buffer, &block_in[i], CONFIG_MD2_BLOCK_LEN); - md2_compute(context->state, context->checksum, context->buffer); + } + i = len; + len = CONFIG_MD2_BLOCK_LEN; } - /* - * Copy remaining block in context buffer and update context counter. - */ - memcpy(context->buffer,&block_in[i], block_len - i); - context->counter = block_len - i; } /** -- 2.25.1