X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=md5.c;h=1c87b53f6e9510e0e3592a7123720dc9e03ac4f2;hb=6bd58d7909b89a3e05003a63cdc642638fa653e6;hp=5ae22e60dbc1a4fc879caea2b684f895711efe45;hpb=24a9a8cfc423d4bfc2ce4b5fba8ebf5eb372938e;p=avr-crypto-lib.git diff --git a/md5.c b/md5.c index 5ae22e6..1c87b53 100644 --- a/md5.c +++ b/md5.c @@ -1,9 +1,28 @@ +/* md5.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ /* - * File: md5.h - * Author: Daniel Otte - * Date: 31.07.2006 - * License: GPL - * Description: Implementation of the MD5 hash algorithm as described in RFC 1321 + * \file md5.c + * \author Daniel Otte + * \date 2006-07-31 + * \par License: + * GPLv3 or later + * \brief Implementation of the MD5 hash algorithm as described in RFC 1321 * */ @@ -113,32 +132,32 @@ void md5_nextBlock(md5_ctx_t *state, void* block){ state->counter++; } -void md5_lastBlock(md5_ctx_t *state, void* block, uint16_t length){ +void md5_lastBlock(md5_ctx_t *state, void* block, uint16_t length_b){ uint16_t l; uint8_t b[64]; - while (length >= 512){ + while (length_b >= 512){ md5_nextBlock(state, block); - length -= 512; - block += 512/8; + length_b -= 512; + block = ((uint8_t*)block) + 512/8; } memset(b, 0, 64); - memcpy(b, block, length/8); + memcpy(b, block, length_b/8); /* insert padding one */ - l=length/8; - if(length%8){ + l=length_b/8; + if(length_b%8){ uint8_t t; t = ((uint8_t*)block)[l]; - t |= (0x80>>(length%8)); + t |= (0x80>>(length_b%8)); b[l]=t; }else{ b[l]=0x80; } /* insert length value */ - if(l+sizeof(uint64_t) > 512/8){ + if(l+sizeof(uint64_t) >= 512/8){ md5_nextBlock(state, b); state->counter--; memset(b, 0, 64); } - *((uint64_t*)&b[64-sizeof(uint64_t)]) = (state->counter * 512) + length; + *((uint64_t*)&b[64-sizeof(uint64_t)]) = (state->counter * 512) + length_b; md5_nextBlock(state, b); }