From d8e03b1a1d929f6afeac72d475183d0218656b48 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sat, 11 Jan 2025 16:57:57 -0600 Subject: First pass at genpassword --- src/encryption.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/encryption.h') diff --git a/src/encryption.h b/src/encryption.h index 675ef18..2c8f976 100644 --- a/src/encryption.h +++ b/src/encryption.h @@ -1,6 +1,21 @@ #ifndef __VXGG_REWRITE___ENCRYPTION_H___1481879318188___ #define __VXGG_REWRITE___ENCRYPTION_H___1481879318188___ +// Determines whether any function that calls libsodium functions also checks to make sure libsodium is actually initialized. May +// cause unexpected issues with early exiting due to libsodium failing to initialize properly. It's recommended that you just +// manually run `sodium_init()` in some main or init function of your own so that you can deal with a potential error yourself +#define ___VXGG___ALWAYS_CHECK_LIBSODIUM___ 1 + +#if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 + +// Definition for the callback function that fires when a call to checksodium fails +typedef void (*vxgg_naclfailcb)(void*); + +// Sets the error callback for when libsodium fails. Runs `cb(data)` if `(sodium_init() < 0)` +void vxgg_setsodiumfailcb(const vxgg_naclfailcb cb, void *data); + +#endif + // I need to store a dictionary of valid words for generating a password, and I don't want to read it in from another file, so I'm experimenting with this #define PASSWORD_WORDS (\ (const char *[]){\ @@ -56,9 +71,10 @@ "reliance", "divine", "providence", "mutually", "pledge", "each", "fortunes", "sacred", "honor"\ }\ ) +#define PASSWORD_WORDS_LEN (STATICARR_SIZE(PASSWORD_WORDS)) -// Checks if sodium is initialized. Initializes it if not -int checkSodium(void); +// Checks if sodium is initialized. Initializes it if not. If `___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0`, it's possible to set an error callback to avoid exiting the entire program. Otherwise calls `error()` if libsodium can't initialize +void checksodium(void); // open() with the flags O_TMPFILE, O_WRONLY, O_CLOEXEC, and O_SYNC. Opened with mode S_IRUSR, S_IWUSR int maketmp(const char *dest); -- cgit v1.2.3