From 985dcfd6eec1a2b455c87ad2b951a3a5530b24c0 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Wed, 14 Oct 2020 17:57:40 +0200 Subject: [PATCH] FreeBSD compile fix. --- frontend/src/main.c | 26 ++++++++++---------------- frontend/src/platform.h | 6 ------ frontend/src/utils.c | 22 +++++++++++++++++----- libMCrypt/include/mcrypt.h | 8 ++++---- libMCrypt/src/mcrypt.c | 8 ++++---- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/frontend/src/main.c b/frontend/src/main.c index efec490..2ff035a 100644 --- a/frontend/src/main.c +++ b/frontend/src/main.c @@ -148,7 +148,7 @@ static int encrypt(const char* const passphrase, const CHR* const input, const C { crc_actual = crc64_update(crc_actual, buffer, count); bytes_read += count; - if (mcrypt_enc_process_inplace(ctx, buffer, count) != 0) + if (mcrypt_encrypt_inplace(ctx, buffer, count) != 0) { FPUTS(T("\n\nMCrypt error: Failed to encrypt data!\n\n"), stderr); goto clean_up; @@ -270,7 +270,7 @@ static int decrypt(const char* const passphrase, const CHR* const input, const C if (count > 0U) { bytes_read += count; - if (mcrypt_dec_process_inplace(ctx, buffer, count) != 0) + if (mcrypt_decrypt_inplace(ctx, buffer, count) != 0) { FPUTS(T("\n\nMCrypt error: Failed to decrypt data!\n\n"), stderr); goto clean_up; @@ -351,7 +351,7 @@ static int self_test(void) const size_t length = strlen(text_plain) + 1U; int result = 1; - mcrypt_t ctx_enc = MCRYPT_NULL, ctx_dec = MCRYPT_NULL; + mcrypt_t ctx = MCRYPT_NULL; FPUTS(T("Self-test is running, please be patient... "), stderr); @@ -369,14 +369,14 @@ static int self_test(void) goto clean_up; } - ctx_enc = mcrypt_alloc(seed, passphrase); - if (!ctx_enc) + ctx = mcrypt_alloc(seed, passphrase); + if (!ctx) { FPUTS(T("error!\n\nnWhoops: Failed to initialize encoder!\n\n"), stderr); goto clean_up; } - if (mcrypt_enc_process_inplace(ctx_enc, text_temp, length) != 0) + if (mcrypt_encrypt_inplace(ctx, (uint8_t*)text_temp, length) != 0) { FPUTS(T("error!\n\nWhoops: Failed to encrypt the message!\n\n"), stderr); goto clean_up; @@ -388,14 +388,13 @@ static int self_test(void) goto clean_up; } - ctx_dec = mcrypt_alloc(seed, passphrase); - if (!ctx_dec) + if (mcrypt_reset(ctx, seed, passphrase) != 0) { FPUTS(T("error!\n\nWhoops: Failed to initialize decoder!\n\n"), stderr); goto clean_up; } - if (mcrypt_dec_process_inplace(ctx_dec, text_temp, length) != 0) + if (mcrypt_decrypt_inplace(ctx, (uint8_t*)text_temp, length) != 0) { FPUTS(T("error!\n\nWhoops: Failed to decrypt the message!\n\n"), stderr); goto clean_up; @@ -412,14 +411,9 @@ static int self_test(void) clean_up: - if (ctx_enc) + if (ctx) { - mcrypt_free(ctx_enc); - } - - if (ctx_dec) - { - mcrypt_free(ctx_dec); + mcrypt_free(ctx); } if (text_temp) diff --git a/frontend/src/platform.h b/frontend/src/platform.h index f122442..944d66e 100644 --- a/frontend/src/platform.h +++ b/frontend/src/platform.h @@ -59,9 +59,6 @@ #define FPUTS(X,Y) fputws((X),(Y)) #define FPRINTF(X,Y,...) fwprintf((X),(Y),__VA_ARGS__) #define FOPEN(X,Y) _wfsopen((X),(Y),_SH_SECURE) -#define FILENO(X) _fileno((X)) -#define FSTAT64(X,Y) _fstati64((X),(Y)) -#define STAT64_T struct _stati64 #ifdef __MINGW32__ #define PRISTR "ls" #define PRIstr "hs" @@ -81,9 +78,6 @@ #define FPUTS(X,Y) fputs((X),(Y)) #define FPRINTF(X,Y,...) fprintf((X),(Y),__VA_ARGS__) #define FOPEN(X,Y) fopen((X),(Y)) -#define FILENO(X) fileno((X)) -#define FSTAT64(X,Y) fstat64((X),(Y)) -#define STAT64_T struct stat64 #define PRISTR "s" #define PRIstr "s" #define PRIwcs "ls" diff --git a/frontend/src/utils.c b/frontend/src/utils.c index 9237b12..dc40519 100644 --- a/frontend/src/utils.c +++ b/frontend/src/utils.c @@ -7,7 +7,7 @@ #define WIN32_LEAN_AND_MEAN 1 #define _CRT_SECURE_NO_WARNINGS 1 #else -#define _LARGEFILE64_SOURCE 1 +#define _GNU_SOURCE 1 #endif #include "utils.h" @@ -18,9 +18,21 @@ #include #include #include +#define STAT_T struct _stati64 +#define FSTAT(X,Y) _fstati64((X),(Y)) +#define FILENO(X) _fileno((X)) #define S_IFMT _S_IFMT #define S_IFDIR _S_IFDIR #define S_IFIFO _S_IFIFO +#else +#if defined(__USE_LARGEFILE64) && (__USE_LARGEFILE64) +#define STAT_T struct stat64 +#define FSTAT(X,Y) fstat64((X),(Y)) +#else +#define STAT_T struct stat +#define FSTAT(X,Y) fstat((X),(Y)) +#endif +#define FILENO(X) fileno((X)) #endif void init_terminal(void) @@ -64,8 +76,8 @@ char* CHR_to_utf8(const CHR*const input) uint64_t get_file_size(FILE* const file) { - STAT64_T stat; - if (FSTAT64(FILENO(file), &stat) != 0) + STAT_T stat; + if (FSTAT(FILENO(file), &stat) != 0) { return UINT64_MAX; } @@ -80,11 +92,11 @@ uint64_t get_file_size(FILE* const file) const CHR* get_file_name(const CHR* path) { const CHR* ptr; - while (ptr = STRRCHR(path, T('/'))) + while ((ptr = STRRCHR(path, T('/')))) { path = ptr + 1U; } - while (ptr = STRRCHR(path, T('\\'))) + while ((ptr = STRRCHR(path, T('\\')))) { path = ptr + 1U; } diff --git a/libMCrypt/include/mcrypt.h b/libMCrypt/include/mcrypt.h index 317c8f9..31dedf1 100644 --- a/libMCrypt/include/mcrypt.h +++ b/libMCrypt/include/mcrypt.h @@ -33,14 +33,14 @@ void mcrypt_free(const mcrypt_t context); /* * Encryption routines */ -int mcrypt_enc_process(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length); -int mcrypt_enc_process_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length); +int mcrypt_encrypt(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length); +int mcrypt_encrypt_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length); /* * Decryption routines */ -int mcrypt_dec_process(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length); -int mcrypt_dec_process_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length); +int mcrypt_decrypt(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length); +int mcrypt_decrypt_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length); /* * Auxiliary functions diff --git a/libMCrypt/src/mcrypt.c b/libMCrypt/src/mcrypt.c index 580350a..4e6f70a 100644 --- a/libMCrypt/src/mcrypt.c +++ b/libMCrypt/src/mcrypt.c @@ -209,7 +209,7 @@ int mcrypt_reset(const mcrypt_t context, const uint64_t salt, const char* const return 0; } -int mcrypt_enc_process(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length) +int mcrypt_encrypt(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length) { crypt_state_t* const state = (crypt_state_t*)context; if (!state) @@ -223,7 +223,7 @@ int mcrypt_enc_process(const mcrypt_t context, const uint8_t* const input, uint8 return 0; } -int mcrypt_enc_process_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length) +int mcrypt_encrypt_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length) { crypt_state_t* const state = (crypt_state_t*)context; if (!state) @@ -238,7 +238,7 @@ int mcrypt_enc_process_inplace(const mcrypt_t context, uint8_t* const buffer, si } -int mcrypt_dec_process(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length) +int mcrypt_decrypt(const mcrypt_t context, const uint8_t* const input, uint8_t* const output, size_t length) { crypt_state_t* const state = (crypt_state_t*)context; if (!state) @@ -252,7 +252,7 @@ int mcrypt_dec_process(const mcrypt_t context, const uint8_t* const input, uint8 return 0; } -int mcrypt_dec_process_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length) +int mcrypt_decrypt_inplace(const mcrypt_t context, uint8_t* const buffer, size_t length) { crypt_state_t* const state = (crypt_state_t*)context; if (!state)