Feat: Step1 padding
This commit is contained in:
parent
d70243a62e
commit
eeb4164610
3 changed files with 35 additions and 2 deletions
|
@ -2,6 +2,9 @@
|
|||
#define MD2_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,5 +20,8 @@ int main(int argc, char** argv) {
|
|||
"benchmark cycles: %d\n",
|
||||
c.filename, c.implementationToUse, c.doBenchmark, c.benchmarkingCycles);
|
||||
|
||||
uint8_t out[16];
|
||||
md2_hash(3, "abc", out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,35 @@
|
|||
#include "io.h"
|
||||
#include "../lib/md2.h"
|
||||
|
||||
// The file "testfile" should lead to this hash:
|
||||
// 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_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);
|
||||
}
|
Loading…
Reference in a new issue