Fix: Some minor bugs lol

This commit is contained in:
Dorian Zedler 2022-08-29 20:27:39 +02:00
parent 57910b718f
commit 8e5c5d2766
Signed by: dorian
GPG Key ID: 989DE36109AFA354
6 changed files with 16 additions and 10 deletions

View File

@ -72,8 +72,7 @@ void md2_checksum(size_t len, uint8_t* buf);
* @brief Calculates checksum of buf and writes it into a target
*
* @param len Length of data which the checksum should be calculated of
* @param buf Location of the data. Make sure to reserve 16 bytes more so the
* chechsum fits!
* @param buf Location of the data.
* @param checksum the output checksum
*/
void md2_checksum_with_target(size_t len, const uint8_t* buf,
@ -100,7 +99,7 @@ void md2_process_detailed_benchmark_step(enum md2_detailed_benchmark_step step);
* @brief Print the detailed benchmark result
*
*/
void md2_print_detailed_benchmark_result();
void md2_print_detailed_benchmark_result(void);
/**
* @brief Add padding and allocate extra space for the checksum

View File

@ -57,7 +57,7 @@ enum argumentParseResult parseArguments(int argc, char **argv,
static struct option longOptions[] = {
{"version", required_argument, NULL, 'V'},
{"benchmark", optional_argument, NULL, 'B'},
{"test", optional_argument, NULL, 'T'},
{"test", no_argument, NULL, 'T'},
{"help", no_argument, NULL, 'h'},
{NULL}};
int longOptionIndex = 0;
@ -101,7 +101,7 @@ enum argumentParseResult parseArguments(int argc, char **argv,
if (argc > optind) {
c->filename = argv[optind];
} else if (!c->runTests) {
fprintf(stderr, "%s: missing poisional argument -- 'file'\n", argv[0]);
fprintf(stderr, "%s: missing positional argument -- 'file'\n", argv[0]);
return RESULT_EXIT_FAILURE;
}

View File

@ -65,9 +65,9 @@ uint8_t* read_file(const char* path, size_t* size) {
return NULL;
}
size_t bytes_read = fread(data, 1, statOfFile.st_size, f);
fread(data, 1, statOfFile.st_size, f);
if (bytes_read == 0 || ferror(f)) {
if (ferror(f)) {
fclose(f);
if (errno == 0) errno = EIO;
return NULL;

View File

@ -51,6 +51,10 @@ void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) {
size_t size = fread(data, 1, bytes_left_to_process, file);
if (size == 0 || ferror(file) || feof(file)) {
if (errno == 0) errno = EIO;
fclose(file);
free(data);
free(messageDigestBuf);
free(checksum);
return;
}

View File

@ -20,7 +20,7 @@ void* process_hash(void* threadArgs) {
uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t));
if (messageDigestBuf == NULL) {
return NULL;
pthread_exit(NULL);
}
process_nothread_hash(args->len, args->buf, messageDigestBuf);
@ -32,7 +32,7 @@ void* process_checksum(void* threasdArgs) {
uint8_t* checksum = calloc(16, sizeof(uint8_t));
if (checksum == NULL) {
return NULL;
pthread_exit(NULL);
}
md2_checksum_with_target(args->len, args->buf, checksum);

View File

@ -108,12 +108,15 @@ void md2_second_loop(uint8_t* messageDigestBuf) {
u_int8_t t = 0;
SECOND_LOOP_START_MARK
for (int j = 0; j < 18; j++) {
for (int j = 0; j < 17; j++) {
for (int k = 0; k < 48; k++) {
t = messageDigestBuf[k] = messageDigestBuf[k] ^ MD2_PI_SUBST[t];
}
t = (t + j) & 255;
}
for (int k = 0; k < 16; k++) {
t = messageDigestBuf[k] = messageDigestBuf[k] ^ MD2_PI_SUBST[t];
}
SECOND_LOOP_END_MARK
}