2022-06-29 10:58:49 +02:00
|
|
|
#ifndef HELPER_H
|
|
|
|
#define HELPER_H
|
2022-07-06 20:35:10 +02:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2022-06-29 10:58:49 +02:00
|
|
|
|
2022-06-29 10:50:55 +02:00
|
|
|
#include <errno.h>
|
2022-06-29 11:08:31 +02:00
|
|
|
#include <getopt.h>
|
2022-06-29 10:50:55 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2022-06-29 11:08:31 +02:00
|
|
|
#include <stdlib.h>
|
2022-07-06 20:35:10 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "md2.h"
|
2022-06-29 10:50:55 +02:00
|
|
|
|
|
|
|
enum argumentParseResult {
|
|
|
|
RESULT_OK = 0,
|
|
|
|
RESULT_EXIT_SUCCESS,
|
|
|
|
RESULT_EXIT_FAILURE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct configuration {
|
2022-06-29 11:08:31 +02:00
|
|
|
char* filename;
|
2022-06-29 10:50:55 +02:00
|
|
|
int implementationToUse;
|
2022-07-07 17:45:33 +02:00
|
|
|
bool doBenchmark;
|
2022-06-29 10:50:55 +02:00
|
|
|
int benchmarkingCycles;
|
2022-07-07 17:45:33 +02:00
|
|
|
bool runTests;
|
2022-06-29 10:50:55 +02:00
|
|
|
};
|
|
|
|
|
2022-06-29 11:08:31 +02:00
|
|
|
/**
|
|
|
|
* @brief parse commandline arguments to config and print errors, if any
|
|
|
|
*
|
|
|
|
* @param argc argc
|
|
|
|
* @param argv argv
|
|
|
|
* @param c pointer where the configuration should be stored
|
|
|
|
* @return enum argumentParseResult
|
|
|
|
*/
|
|
|
|
enum argumentParseResult parseArguments(int argc, char** argv,
|
|
|
|
struct configuration* c);
|
2022-06-29 10:58:49 +02:00
|
|
|
|
2022-07-06 20:35:10 +02:00
|
|
|
/**
|
|
|
|
* @brief Run an md2_hash_func with benchmark timing
|
|
|
|
*
|
2022-07-07 17:15:41 +02:00
|
|
|
* @param cycles the number of cycles to execute
|
2022-07-06 20:35:10 +02:00
|
|
|
* @param func the function to run
|
|
|
|
* @param len the lenght of buf
|
|
|
|
* @param buf the data to hash
|
|
|
|
* @param out the target array for the hash
|
|
|
|
* @return double
|
|
|
|
*/
|
2022-07-07 17:15:41 +02:00
|
|
|
double run_benchmark(unsigned cycles, md2_hash_func func, size_t len,
|
|
|
|
uint8_t* buf, uint8_t* out);
|
2022-07-06 20:35:10 +02:00
|
|
|
|
2022-06-29 11:08:31 +02:00
|
|
|
#endif // HELPER_H
|