From d35d338fb1e8fa8280e687025b365167bd3d3c5f Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Tue, 12 Jul 2022 16:02:30 +0200 Subject: [PATCH] Fix: missing free --- Implementierung/src/md2_impls/md2_2.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Implementierung/src/md2_impls/md2_2.c b/Implementierung/src/md2_impls/md2_2.c index 874c097..1fac14a 100644 --- a/Implementierung/src/md2_impls/md2_2.c +++ b/Implementierung/src/md2_impls/md2_2.c @@ -27,13 +27,8 @@ void process_block_checksum(uint8_t block[16], uint8_t checksum[16], } } -void md2_checksum_2(size_t len, uint8_t* buf) { - uint8_t l = 0; - - for (size_t i = 0; i < len / 16; i++) { - process_block_checksum(buf + (i * 16), buf + len, &l); - } -} +// unused! +void md2_checksum_2(size_t, uint8_t*) {} void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) { // === step 1 === @@ -44,7 +39,7 @@ void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) { // printf("len: %d\n", len); // +16 for the checksum - uint8_t* newBuf = calloc(len + 16, sizeof(uint8_t)); + uint8_t* newBuf = calloc(len, sizeof(uint8_t)); // TODO: null check memcpy(newBuf, buf, len - paddingNeeded); @@ -62,15 +57,18 @@ void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) { // === step 4 === uint8_t l = 0; - // <= because we need to hash the last block too + uint8_t* checksum = calloc(16, sizeof(uint8_t)); + for (size_t i = 0; i < len / 16; i++) { - process_block_checksum(newBuf + (i * 16), newBuf + len, &l); + process_block_checksum(newBuf + (i * 16), checksum, &l); process_block_hash(newBuf + (i * 16), messageDigestBuf); } - process_block_hash(newBuf + len, messageDigestBuf); + process_block_hash(checksum, messageDigestBuf); memcpy(out, messageDigestBuf, 16); free(newBuf); + free(messageDigestBuf); + free(checksum); }