fix: console warnings
This commit is contained in:
parent
94a4e5332a
commit
74746a91b4
7 changed files with 17 additions and 37 deletions
|
@ -18,6 +18,5 @@
|
|||
* @param out
|
||||
*/
|
||||
void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]);
|
||||
void md2_checksum_2(size_t len, uint8_t* buf);
|
||||
|
||||
#endif // MD2_2_H
|
|
@ -8,7 +8,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
|
@ -19,6 +18,5 @@
|
|||
* @param out
|
||||
*/
|
||||
void md2_hash_3(size_t len, const uint8_t buf[len], uint8_t out[16]);
|
||||
void md2_checksum_3(size_t len, uint8_t* buf);
|
||||
|
||||
#endif // MD2_3_H
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef MD2_COMMON_H
|
||||
#define MD2_COMMON_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "../lib/io.h"
|
||||
#include "../lib/md2.h"
|
||||
|
||||
// Returns true when val is approx. equal to exp.
|
||||
static bool runTest(struct configuration* c, const char* message,
|
||||
const char* expectedHash) {
|
||||
uint8_t out[16];
|
||||
|
|
|
@ -26,12 +26,12 @@ bool md2_choose_implementation(int i) {
|
|||
|
||||
case 2:
|
||||
md2_hash = md2_hash_2;
|
||||
md2_checksum = md2_checksum_2;
|
||||
md2_checksum = NULL;
|
||||
return true;
|
||||
|
||||
case 3:
|
||||
md2_hash = md2_hash_3;
|
||||
md2_checksum = md2_checksum_3;
|
||||
md2_checksum = NULL;
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
|
|
@ -38,9 +38,6 @@ void apply_padding(size_t len, uint8_t buf[16]) {
|
|||
}
|
||||
}
|
||||
|
||||
// unused!
|
||||
void md2_checksum_2(size_t _, uint8_t* __) {}
|
||||
|
||||
void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) {
|
||||
FILE* file;
|
||||
struct stat file_stat;
|
||||
|
@ -62,8 +59,8 @@ void md2_hash_2(size_t len, const uint8_t buf[len], uint8_t out[16]) {
|
|||
while (bytes_left_to_read != 0) {
|
||||
bytes_left_to_process = bytes_left_to_read >= 16 ? 16 : bytes_left_to_read;
|
||||
|
||||
fread(data, 1, bytes_left_to_process, file);
|
||||
if (ferror(file) || feof(file)) {
|
||||
size_t size = fread(data, 1, bytes_left_to_process, file);
|
||||
if (size == 0 || ferror(file) || feof(file)) {
|
||||
if (errno == 0) errno = EIO;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ struct thread_args {
|
|||
const uint8_t* buf;
|
||||
};
|
||||
|
||||
void process_nothread_hash(size_t len, uint8_t buf[len],
|
||||
void process_nothread_hash(size_t len, const uint8_t buf[len],
|
||||
uint8_t messageDigestBuf[48]) {
|
||||
for (size_t i = 0; i < (len + 16) / 16 - 1; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
|
@ -32,25 +32,10 @@ void* process_hash(void* threadArgs) {
|
|||
|
||||
uint8_t* messageDigestBuf = calloc(48, sizeof(uint8_t));
|
||||
if (messageDigestBuf == NULL) {
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < (args->len + 16) / 16 - 1; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
messageDigestBuf[16 + j] = args->buf[i * 16 + j];
|
||||
messageDigestBuf[32 + j] =
|
||||
(messageDigestBuf[16 + j] ^ messageDigestBuf[j]);
|
||||
}
|
||||
|
||||
u_int8_t t = 0;
|
||||
|
||||
for (int j = 0; j < 18; j++) {
|
||||
for (int k = 0; k < 48; k++) {
|
||||
t = messageDigestBuf[k] = messageDigestBuf[k] ^ MD2_PI_SUBST[t];
|
||||
}
|
||||
t = (t + j) % 256;
|
||||
}
|
||||
}
|
||||
process_nothread_hash(args->len, args->buf, messageDigestBuf);
|
||||
pthread_exit(messageDigestBuf);
|
||||
}
|
||||
|
||||
|
@ -59,7 +44,7 @@ void* process_checksum(void* threasdArgs) {
|
|||
|
||||
uint8_t* checksum = calloc(16, sizeof(uint8_t));
|
||||
if (checksum == NULL) {
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t l = 0;
|
||||
|
@ -74,9 +59,6 @@ void* process_checksum(void* threasdArgs) {
|
|||
pthread_exit(checksum);
|
||||
}
|
||||
|
||||
// unused!
|
||||
void md2_checksum_3(size_t _, uint8_t* __) {}
|
||||
|
||||
void md2_hash_3(size_t len, const uint8_t buf[len], uint8_t out[16]) {
|
||||
int paddingNeeded = 16 - (len % 16);
|
||||
uint8_t originalPadding = paddingNeeded;
|
||||
|
@ -100,12 +82,14 @@ void md2_hash_3(size_t len, const uint8_t buf[len], uint8_t out[16]) {
|
|||
|
||||
if (pthread_create(&thread_1, NULL, process_hash, (void*)&thread_args) != 0) {
|
||||
printf("Error creating thread 1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (errno == 0) errno = EAGAIN;
|
||||
return;
|
||||
}
|
||||
if (pthread_create(&thread_2, NULL, process_checksum, (void*)&thread_args) !=
|
||||
0) {
|
||||
printf("Error creating thread 2\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (errno == 0) errno = EAGAIN;
|
||||
return;
|
||||
}
|
||||
|
||||
u_int8_t* messageDigestBuf;
|
||||
|
@ -113,11 +97,13 @@ void md2_hash_3(size_t len, const uint8_t buf[len], uint8_t out[16]) {
|
|||
|
||||
if (pthread_join(thread_1, (void**)&messageDigestBuf) != 0) {
|
||||
printf("Error joining thread 1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (errno == 0) errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
if (pthread_join(thread_2, (void**)&checksum) != 0) {
|
||||
printf("Error joining thread 2\n");
|
||||
exit(EXIT_FAILURE);
|
||||
if (errno == 0) errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
process_nothread_hash(16, checksum, messageDigestBuf);
|
||||
|
|
Loading…
Reference in a new issue