From 4fbc2e2a3aa83de683dd440f9036ced5d5879071 Mon Sep 17 00:00:00 2001 From: asterix Date: Fri, 2 Feb 2007 15:37:45 +0000 Subject: [PATCH] Change md2_end prototype. Remove a unneeded memcpy in md2_end. Add comments. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@754 38d2e660-2303-0410-9eaa-f027e97ec537 --- algos/md2.c | 32 ++++++++++++++++---------------- algos/md2.h | 5 ++++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/algos/md2.c b/algos/md2.c index 9b8ae63e..338005c4 100755 --- a/algos/md2.c +++ b/algos/md2.c @@ -13,6 +13,9 @@ /*#* *#* $Log$ + *#* Revision 1.10 2007/02/02 15:37:45 asterix + *#* Change md2_end prototype. Remove a unneeded memcpy in md2_end. Add comments. + *#* *#* Revision 1.9 2007/02/02 13:10:01 asterix *#* Fix some bugs in md2_pad and md2_update fuction. *#* @@ -196,36 +199,33 @@ void md2_update(Md2Context *context, void *_block_in, size_t block_len) } /** - * Ends MD2 message digest operation, writing the message digest and cleaning context. + * Ends an MD2 message digest operation. + * This fuction take an context and return a pointer + * to context state. + * + * \param context in input. + * \return a pointer to context state (message digest). */ -void md2_end(Md2Context *context, void *msg_digest) +uint8_t *md2_end(Md2Context *context) { + uint8_t buf[CONFIG_MD2_BLOCK_LEN]; /* - * Pad remaning context buffer. + * Fill remaning empty context buffer. */ md2_pad(buf, CONFIG_MD2_BLOCK_LEN - context->counter); /* - * Update context and checksum. + * Update context buffer and compute it. */ md2_update(context, buf, CONFIG_MD2_BLOCK_LEN - context->counter); - memcpy(buf, context->checksum, CONFIG_MD2_BLOCK_LEN); - - md2_update(context, buf, CONFIG_MD2_BLOCK_LEN); - /* - * Copy first CONFIG_MD2_BLOCK_LEN byte of context's state - * in msg_digest. The msg_digest is the message digest of - * MD2 algorithm. + * Add context checksum to message input. */ - memcpy(msg_digest, context->state, CONFIG_MD2_BLOCK_LEN); + md2_update(context, context->checksum, CONFIG_MD2_BLOCK_LEN); - /* - * Clean the context. - */ - memset(context, 0, sizeof(context)); + return context->state; //return a pointer to message digest. } diff --git a/algos/md2.h b/algos/md2.h index b56e12dd..f1ce3757 100755 --- a/algos/md2.h +++ b/algos/md2.h @@ -21,6 +21,9 @@ /*#* *#* $Log$ + *#* Revision 1.5 2007/02/02 15:37:45 asterix + *#* Change md2_end prototype. Remove a unneeded memcpy in md2_end. Add comments. + *#* *#* Revision 1.4 2007/01/31 13:53:36 asterix *#* Define COMPUTE_ARRAY_LEN. *#* @@ -58,6 +61,6 @@ typedef struct Md2Context void md2_init(Md2Context *context); void md2_update(Md2Context *context, void *block_in, size_t block_len); -void md2_end(Md2Context *context, void *msg_digest); +uint8_t *md2_end(Md2Context *context); #endif /* ALGOS_MD2_H */ -- 2.25.1