Fix: missing free
This commit is contained in:
parent
1e1f4450e8
commit
d35d338fb1
1 changed files with 9 additions and 11 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue