88 lines
2.1 KiB
C
88 lines
2.1 KiB
C
|
#include <fcntl.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <stddef.h>
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <time.h>
|
||
|
#include <unistd.h>
|
||
|
#include <xmmintrin.h>
|
||
|
#include <errno.h>
|
||
|
#include <immintrin.h>
|
||
|
#include <stdint.h>
|
||
|
#include <getopt.h>
|
||
|
|
||
|
#include "helper.h"
|
||
|
|
||
|
// The file "testfile" should lead to this hash: fc982e558db259f298b43cd4c1241c66
|
||
|
|
||
|
void md2_checksum(size_t len, uint8_t* buf) {
|
||
|
|
||
|
}
|
||
|
|
||
|
void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) {
|
||
|
|
||
|
}
|
||
|
|
||
|
static uint8_t* read_file(const char* path, size_t* size) {
|
||
|
// Read the contents of the file specified by path into a heap-allocated
|
||
|
// buffer and return a pointer to that buffer.
|
||
|
FILE* f = fopen(path, "r");
|
||
|
if(f == NULL) {
|
||
|
printf("Fopen error: %d\n", errno);
|
||
|
fclose(f);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
struct stat statOfFile;
|
||
|
int status = fstat(fileno(f), &statOfFile);
|
||
|
if(status == -1) {
|
||
|
printf("Fstat error: %d\n", errno);
|
||
|
fclose(f);
|
||
|
return NULL;
|
||
|
};
|
||
|
|
||
|
if((statOfFile.st_mode & S_IFMT) != S_IFREG){
|
||
|
printf("File is not a regular file!\n");
|
||
|
fclose(f);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
uint8_t* data = malloc(statOfFile.st_size);
|
||
|
|
||
|
size_t bytesRead = fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f);
|
||
|
// Or: size_t bytesRead = fread(data, sizeof(char), statOfFile.st_size, f);
|
||
|
if(bytesRead != 0 && !feof(f)) {
|
||
|
printf("Error reading file!\n");
|
||
|
fclose(f);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
fclose(f);
|
||
|
|
||
|
(*size) = bytesRead;
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char** argv) {
|
||
|
|
||
|
struct configuration c;
|
||
|
enum argumentParseResult result = parseArguments(argc, argv, &c);
|
||
|
|
||
|
switch (result)
|
||
|
{
|
||
|
case RESULT_EXIT_SUCCESS:
|
||
|
return EXIT_SUCCESS;
|
||
|
case RESULT_EXIT_FAILURE:
|
||
|
return EXIT_FAILURE;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
printf("Hashing file: %s\nUsing implementation: %d, doing benchmark: %d, benchmark cycles: %d\n", c.filename, c.implementationToUse, c.doBenchmark, c.benchmarkingCycles);
|
||
|
|
||
|
return 0;
|
||
|
}
|