feat: implement step 3 & 4

This commit is contained in:
Thomas Florian 2022-06-29 16:07:05 +02:00
parent 3940ee3a21
commit 76a685d1b7
1 changed files with 24 additions and 1 deletions

View File

@ -51,7 +51,7 @@ void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) {
printf("len: %d\n", len);
uint8_t* newBuf = malloc(len + 16); // 16 = Checksum
uint8_t* newBuf = calloc(len + 16, sizeof(uint8_t)); // +16 = Checksum
memcpy(newBuf, buf, len - paddingNeeded);
newBuf[4] = 'f';
@ -65,5 +65,28 @@ void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) {
printBuf(len + 16, newBuf);
// implement step 3
u_int8_t messageDigestBuf = calloc(48, sizeof(uint8_t));
for (int i = 0; i <= len / 16; i++) { // <= because we need to hash the last block too
for (int j = 0; j < 16; j++) {
messageDigestBuf[16 + j] = newBuf[i * 16 + j];
messageDigestBuf[32 + j] = (newBuf[16 + j] ^ messageDigestBuf[j]);
}
u_int8_t t = 0;
for (int j = 0; j < 18; j++) {
for (int k = 0; k < 48; k++) {
t = messageDigestBuf[k] = messageDigestBuf[k] ^ PI_SUBST[t];
}
t = (t + j) % 256;
}
}
printf("messageDigestBuf: \n");
printBuf(16, messageDigestBuf);
free(messageDigestBuf);
free(newBuf);
}