From b3bd3df103a5a75d267b2b79e85558768b1dc4bb Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sun, 23 Mar 2025 22:11:15 -0500 Subject: Fix a whole bunch of shit, create an arena implementation --- src/encryption.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'src/encryption.c') diff --git a/src/encryption.c b/src/encryption.c index 8b0ac83..9b8715e 100644 --- a/src/encryption.c +++ b/src/encryption.c @@ -19,11 +19,9 @@ #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 void naclfaildefault(void *none) { none = none; // Makes gcc happy - #if defined ___VXGG___VERBOSE_ERRORS___ && ___VXGG___VERBOSE_ERRORS___ > 0 + if(___VXGG___VERBOSE_ERRORS___) error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting..."); - #else - exit(EXIT_FAILURE); - #endif + exit(EXIT_FAILURE); } int checksodiumcb(const vxgg_naclfailcb callback, void *data) { @@ -49,15 +47,14 @@ void vxgg_setsodiumfailcb(vxgg_naclfailcb cb, void *data) { #endif void checksodium(void) { - #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 - checksodiumcb(NULL, NULL); + #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 + checksodiumcb(NULL, NULL); #else - if(sodium_init() < 0) - #if defined ___VXGG___VERBOSE_ERRORS___ && ___VXGG___VERBOSE_ERRORS___ > 0 - error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting..."); - #else - exit(EXIT_FAILURE); - #endif + if(sodium_init() < 0) { + if(___VXGG___VERBOSE_ERRORS___) + error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting..."); + exit(EXIT_FAILURE); + } #endif return; @@ -84,7 +81,7 @@ int maketmp(const char * const dest) { } int encrypttotmp(const char * const target, const char * const output, const unsigned char key[crypto_secretstream_xchacha20poly1305_KEYBYTES]) { - #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 + #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 checksodium(); #endif @@ -176,7 +173,7 @@ int genpassword(char **str, unsigned int words) { // Early returns if(words < 1) return 0; - #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 + #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 checksodium(); #endif @@ -203,22 +200,13 @@ int genpassword(char **str, unsigned int words) { // sodium_malloc wrapper. Calls `error()` or `abort()` depnding on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___`. Will make sure libsodium is initialized if `___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0` void* xsodium_malloc(size_t size) { - #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 + #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 checksodium(); #endif void *mem = sodium_malloc(size); - if(mem == NULL) { - #if defined ___VXGG___XALLOC_EXIT_ON_ERROR___ && ___VXGG___XALLOC_EXIT_ON_ERROR___ > 0 - #if defined ___VXGG___VERBOSE_ERRORS___ && ___VXGG___VERBOSE_ERRORS___ > 0 - error(1, errno, " could not allocate memory... Quitting"); - #else - exit(EXIT_FAILURE); - #endif - #endif - - abort(); - } + if(mem == NULL) + XALLOC_EXIT(" could not allocate memory... Quitting"); return mem; } -- cgit v1.2.3