gra-projekt/Implementierung/src/md2_impls/md2_0.c

33 lines
784 B
C
Raw Normal View History

2022-07-04 18:04:08 +02:00
#include "../../lib/md2_impls/md2_0.h"
#include "../../lib/md2_impls/md2_common.h"
void md2_hash_0(size_t len, const uint8_t buf[len], uint8_t out[16]) {
// === step 1 ===
2022-07-20 23:23:18 +02:00
uint8_t* newBuf = md2_add_padding_and_space_for_checksum(buf, &len);
if (newBuf == NULL) {
2022-07-20 12:11:16 +02:00
return;
}
2022-07-04 18:04:08 +02:00
// === step 2 ===
2022-07-20 23:23:18 +02:00
md2_checksum(len, newBuf);
2022-07-04 18:04:08 +02:00
// === step 3 ===
uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t));
if (messageDigestBuf == NULL) {
2022-07-20 12:11:16 +02:00
return;
}
2022-07-04 18:04:08 +02:00
// === step 4 ===
2022-07-20 23:23:18 +02:00
// <= because we need to hash the last block (the checksum) too
for (size_t i = 0; i <= (len) / 16; i++) {
md2_first_loop(newBuf, messageDigestBuf, i);
md2_second_loop(messageDigestBuf);
2022-07-04 18:04:08 +02:00
}
2022-07-20 17:46:35 +02:00
END_MARK
2022-07-04 18:04:08 +02:00
memcpy(out, messageDigestBuf, 16);
free(messageDigestBuf);
free(newBuf);
}