gra-projekt/Implementierung/src/md2.c

46 lines
962 B
C
Raw Normal View History

2022-06-29 15:41:56 +02:00
#include "../lib/md2.h"
2022-06-29 10:58:49 +02:00
2022-07-04 18:02:34 +02:00
// include all implementations
#include "../lib/md2_impls/md2_0.h"
2022-07-15 11:30:19 +02:00
#include "../lib/md2_impls/md2_1.h"
#include "../lib/md2_impls/md2_2.h"
2022-07-15 00:01:35 +02:00
#include "../lib/md2_impls/md2_3.h"
2022-06-29 15:53:46 +02:00
2022-07-04 18:02:34 +02:00
md2_hash_func md2_hash;
md2_checksum_func md2_checksum;
2022-06-29 15:41:56 +02:00
2022-07-04 18:02:34 +02:00
// The file "testfile" should lead to this hash:
// fc982e558db259f298b43cd4c1241c66
2022-06-29 15:53:46 +02:00
2022-07-04 18:02:34 +02:00
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]);
2022-06-29 15:53:46 +02:00
}
}
2022-06-29 10:58:49 +02:00
2022-07-04 18:02:34 +02:00
bool md2_choose_implementation(int i) {
switch (i) {
case 0:
md2_hash = md2_hash_0;
2022-07-04 18:17:03 +02:00
md2_checksum = md2_checksum_0;
2022-07-04 18:02:34 +02:00
return true;
2022-06-29 16:07:05 +02:00
2022-07-15 11:30:19 +02:00
case 1:
md2_hash = md2_hash_1;
md2_checksum = md2_checksum_1;
return true;
case 2:
md2_hash = md2_hash_2;
2022-07-20 10:36:19 +02:00
md2_checksum = NULL;
return true;
2022-07-15 00:01:35 +02:00
case 3:
md2_hash = md2_hash_3;
2022-07-20 10:36:19 +02:00
md2_checksum = NULL;
return true;
2022-07-04 18:02:34 +02:00
default:
return false;
2022-06-29 19:03:12 +02:00
}
2022-06-29 15:41:56 +02:00
}