gra-projekt/Implementierung/src/md2.c

46 lines
962 B
C

#include "../lib/md2.h"
// include all implementations
#include "../lib/md2_impls/md2_0.h"
#include "../lib/md2_impls/md2_1.h"
#include "../lib/md2_impls/md2_2.h"
#include "../lib/md2_impls/md2_3.h"
md2_hash_func md2_hash;
md2_checksum_func md2_checksum;
// The file "testfile" should lead to this hash:
// fc982e558db259f298b43cd4c1241c66
void md2_encode_hash(uint8_t hash[16], char* string_hash) {
for (int i = 0; i < 16; i++) {
sprintf(string_hash + (2 * i), "%02x", hash[i]);
}
}
bool md2_choose_implementation(int i) {
switch (i) {
case 0:
md2_hash = md2_hash_0;
md2_checksum = md2_checksum_0;
return true;
case 1:
md2_hash = md2_hash_1;
md2_checksum = md2_checksum_1;
return true;
case 2:
md2_hash = md2_hash_2;
md2_checksum = NULL;
return true;
case 3:
md2_hash = md2_hash_3;
md2_checksum = NULL;
return true;
default:
return false;
}
}