Feat: Step1 padding

This commit is contained in:
Dorian Zedler 2022-06-29 15:41:56 +02:00
parent d70243a62e
commit eeb4164610
Signed by: dorian
GPG key ID: 989DE36109AFA354
3 changed files with 35 additions and 2 deletions

View file

@ -2,6 +2,9 @@
#define MD2_H #define MD2_H
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h> #include <sys/types.h>
/** /**

View file

@ -20,5 +20,8 @@ int main(int argc, char** argv) {
"benchmark cycles: %d\n", "benchmark cycles: %d\n",
c.filename, c.implementationToUse, c.doBenchmark, c.benchmarkingCycles); c.filename, c.implementationToUse, c.doBenchmark, c.benchmarkingCycles);
uint8_t out[16];
md2_hash(3, "abc", out);
return 0; return 0;
} }

View file

@ -1,8 +1,35 @@
#include "io.h" #include "../lib/md2.h"
// The file "testfile" should lead to this hash: // The file "testfile" should lead to this hash:
// fc982e558db259f298b43cd4c1241c66 // fc982e558db259f298b43cd4c1241c66
void printBuf(size_t len, uint8_t buf[len]) {
for (int i = 0; i < len; i++) {
printf("'%lx',", buf[i]);
}
printf("\n");
}
void md2_checksum(size_t len, uint8_t* buf) {} void md2_checksum(size_t len, uint8_t* buf) {}
void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) {} void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) {
// add padding
int paddingNeeded = 16 - (len % 16);
uint8_t originalPadding = paddingNeeded;
len += paddingNeeded;
printf("len: %d\n", len);
uint8_t* newBuf = malloc(len);
memcpy(newBuf, buf, len - paddingNeeded);
newBuf[4] = 'f';
while (paddingNeeded > 0) {
newBuf[len - paddingNeeded] = originalPadding;
paddingNeeded--;
}
printBuf(len, newBuf);
free(newBuf);
}