diff --git a/Implementierung/src/md2.c b/Implementierung/src/md2.c index 1b3e0a3..bd21615 100644 --- a/Implementierung/src/md2.c +++ b/Implementierung/src/md2.c @@ -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); } \ No newline at end of file