diff options
Diffstat (limited to 'src/encryption.h')
| -rw-r--r-- | src/encryption.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/encryption.h b/src/encryption.h index 1bdd2b9..1f04dae 100644 --- a/src/encryption.h +++ b/src/encryption.h | |||
| @@ -3,21 +3,33 @@ | |||
| 3 | 3 | ||
| 4 | #include <sodium.h> | 4 | #include <sodium.h> |
| 5 | 5 | ||
| 6 | #define CHUNKSIZE (1 << 9) | ||
| 7 | |||
| 8 | |||
| 6 | // Determines whether any function that calls libsodium functions also checks to make sure libsodium is actually initialized. May | 9 | // Determines whether any function that calls libsodium functions also checks to make sure libsodium is actually initialized. May |
| 7 | // cause unexpected issues with early exiting due to libsodium failing to initialize properly. It's recommended that you just | 10 | // cause unexpected issues with early exiting due to libsodium failing to initialize properly. It's recommended that you just |
| 8 | // manually run `sodium_init()` in some main or init function of your own so that you can deal with a potential error yourself | 11 | // manually run `sodium_init()` in some main or init function of your own so that you can deal with a potential error yourself |
| 9 | #define ___VXGG___ALWAYS_CHECK_LIBSODIUM___ 0 | 12 | #define ___VXGG___ALWAYS_CHECK_LIBSODIUM___ 1 |
| 13 | |||
| 14 | // Grants access to the `vxgg_setsodiumfailcb` function, which can be used to set a custom callback for what to do when libsodium | ||
| 15 | // fails upon initialization | ||
| 16 | #define ___VXGG___USE_CLS_CALLBACK___ 1 | ||
| 17 | |||
| 18 | |||
| 10 | 19 | ||
| 11 | #define CHUNKSIZE (1 << 9) | ||
| 12 | 20 | ||
| 13 | // TODO: What the fuck was I thinking when I did any of this callback shit? Make this a different macro and decouple it from ALWAYS_CHECK | ||
| 14 | #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 | 21 | #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 |
| 15 | 22 | ||
| 23 | // 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 | ||
| 24 | void checksodium(void); | ||
| 25 | |||
| 26 | #if ___VXGG___USE_CLS_CALLBACK___ > 0 | ||
| 16 | // Definition for the callback function that fires when a call to checksodium fails | 27 | // Definition for the callback function that fires when a call to checksodium fails |
| 17 | typedef void (*vxgg_naclfailcb)(void*); | 28 | typedef void (*vxgg_naclfailcb)(void*); |
| 18 | 29 | ||
| 19 | // Sets the error callback for when libsodium fails. Runs `cb(data)` if `(sodium_init() < 0)` | 30 | // Sets the error callback for when libsodium fails. Runs `cb(data)` if `(sodium_init() < 0)` |
| 20 | void vxgg_setsodiumfailcb(const vxgg_naclfailcb cb, void *data); | 31 | void vxgg_setsodiumfailcb(const vxgg_naclfailcb cb, void *data); |
| 32 | #endif | ||
| 21 | 33 | ||
| 22 | #endif | 34 | #endif |
| 23 | 35 | ||
| @@ -78,9 +90,6 @@ void vxgg_setsodiumfailcb(const vxgg_naclfailcb cb, void *data); | |||
| 78 | ) | 90 | ) |
| 79 | #define PASSWORD_WORDS_LEN (STATIC_ARRAY_LEN(PASSWORD_WORDS)) | 91 | #define PASSWORD_WORDS_LEN (STATIC_ARRAY_LEN(PASSWORD_WORDS)) |
| 80 | 92 | ||
| 81 | // 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 | ||
| 82 | void checksodium(void); | ||
| 83 | |||
| 84 | // open() with the flags O_TMPFILE, O_WRONLY, O_CLOEXEC, and O_SYNC. Opened with mode S_IRUSR, S_IWUSR | 93 | // open() with the flags O_TMPFILE, O_WRONLY, O_CLOEXEC, and O_SYNC. Opened with mode S_IRUSR, S_IWUSR |
| 85 | int maketmp(const char * const dest); | 94 | int maketmp(const char * const dest); |
| 86 | 95 | ||
