summaryrefslogtreecommitdiff
path: root/src/encryption.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/encryption.c')
-rw-r--r--src/encryption.c40
1 files changed, 14 insertions, 26 deletions
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 @@
19#if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 19#if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0
20void naclfaildefault(void *none) { 20void naclfaildefault(void *none) {
21 none = none; // Makes gcc happy 21 none = none; // Makes gcc happy
22 #if defined ___VXGG___VERBOSE_ERRORS___ && ___VXGG___VERBOSE_ERRORS___ > 0 22 if(___VXGG___VERBOSE_ERRORS___)
23 error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting..."); 23 error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting...");
24 #else 24 exit(EXIT_FAILURE);
25 exit(EXIT_FAILURE);
26 #endif
27} 25}
28 26
29int checksodiumcb(const vxgg_naclfailcb callback, void *data) { 27int checksodiumcb(const vxgg_naclfailcb callback, void *data) {
@@ -49,15 +47,14 @@ void vxgg_setsodiumfailcb(vxgg_naclfailcb cb, void *data) {
49#endif 47#endif
50 48
51void checksodium(void) { 49void checksodium(void) {
52 #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 50 #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0
53 checksodiumcb(NULL, NULL); 51 checksodiumcb(NULL, NULL);
54 #else 52 #else
55 if(sodium_init() < 0) 53 if(sodium_init() < 0) {
56 #if defined ___VXGG___VERBOSE_ERRORS___ && ___VXGG___VERBOSE_ERRORS___ > 0 54 if(___VXGG___VERBOSE_ERRORS___)
57 error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting..."); 55 error(1, ENOTSUP, "Couldn't initialize sodium for some reason. Quitting...");
58 #else 56 exit(EXIT_FAILURE);
59 exit(EXIT_FAILURE); 57 }
60 #endif
61 #endif 58 #endif
62 59
63 return; 60 return;
@@ -84,7 +81,7 @@ int maketmp(const char * const dest) {
84} 81}
85 82
86int encrypttotmp(const char * const target, const char * const output, const unsigned char key[crypto_secretstream_xchacha20poly1305_KEYBYTES]) { 83int encrypttotmp(const char * const target, const char * const output, const unsigned char key[crypto_secretstream_xchacha20poly1305_KEYBYTES]) {
87 #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 84 #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0
88 checksodium(); 85 checksodium();
89 #endif 86 #endif
90 87
@@ -176,7 +173,7 @@ int genpassword(char **str, unsigned int words) {
176 // Early returns 173 // Early returns
177 if(words < 1) 174 if(words < 1)
178 return 0; 175 return 0;
179 #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 176 #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0
180 checksodium(); 177 checksodium();
181 #endif 178 #endif
182 179
@@ -203,22 +200,13 @@ int genpassword(char **str, unsigned int words) {
203 200
204// 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` 201// 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`
205void* xsodium_malloc(size_t size) { 202void* xsodium_malloc(size_t size) {
206 #if defined ___VXGG___ALWAYS_CHECK_LIBSODIUM___ && ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 203 #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0
207 checksodium(); 204 checksodium();
208 #endif 205 #endif
209 206
210 void *mem = sodium_malloc(size); 207 void *mem = sodium_malloc(size);
211 if(mem == NULL) { 208 if(mem == NULL)
212 #if defined ___VXGG___XALLOC_EXIT_ON_ERROR___ && ___VXGG___XALLOC_EXIT_ON_ERROR___ > 0 209 XALLOC_EXIT("<xsodium_malloc> could not allocate memory... Quitting");
213 #if defined ___VXGG___VERBOSE_ERRORS___ && ___VXGG___VERBOSE_ERRORS___ > 0
214 error(1, errno, "<xsodium_malloc> could not allocate memory... Quitting");
215 #else
216 exit(EXIT_FAILURE);
217 #endif
218 #endif
219
220 abort();
221 }
222 210
223 return mem; 211 return mem;
224} 212}