diff options
Diffstat (limited to 'src/encryption.c')
| -rw-r--r-- | src/encryption.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/encryption.c b/src/encryption.c index 3530eed..3bf9dd4 100644 --- a/src/encryption.c +++ b/src/encryption.c | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | // TODO: Go back and make sure every function has proper error handling | ||
| 2 | |||
| 1 | #define _GNU_SOURCE | 3 | #define _GNU_SOURCE |
| 2 | 4 | ||
| 3 | #include "encryption.h" | 5 | #include "encryption.h" |
| @@ -70,12 +72,13 @@ void checksodium(void) { | |||
| 70 | #endif | 72 | #endif |
| 71 | 73 | ||
| 72 | int maketmp(const char * const dest) { | 74 | int maketmp(const char * const dest) { |
| 73 | if(!dest) | 75 | if(!dest) ERRRET(EINVAL, -1); |
| 74 | RETURNWERR(EINVAL, -1); | ||
| 75 | return open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR)); | 76 | return open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR)); |
| 76 | } | 77 | } |
| 77 | 78 | ||
| 78 | int linkto(const char * const target, int tgfd) { | 79 | int linkto(const char * const target, int tgfd) { |
| 80 | if(!target) ERRRET(EINVAL, -1); | ||
| 81 | |||
| 79 | char *path = NULL; | 82 | char *path = NULL; |
| 80 | asprintf(&path, "/proc/self/fd/%d", tgfd); | 83 | asprintf(&path, "/proc/self/fd/%d", tgfd); |
| 81 | if(!path) | 84 | if(!path) |
| @@ -129,11 +132,11 @@ int decryptto(const char * const encrypted, const char * const target, const uns | |||
| 129 | #endif | 132 | #endif |
| 130 | 133 | ||
| 131 | if(!encrypted) | 134 | if(!encrypted) |
| 132 | RETURNWERR(EINVAL, -1); | 135 | ERRRET(EINVAL, -1); |
| 133 | if(!target) | 136 | if(!target) |
| 134 | RETURNWERR(EINVAL, -1); | 137 | ERRRET(EINVAL, -1); |
| 135 | if(!key) | 138 | if(!key) |
| 136 | RETURNWERR(EINVAL, -1); | 139 | ERRRET(EINVAL, -1); |
| 137 | 140 | ||
| 138 | FILE *src, *dst; | 141 | FILE *src, *dst; |
| 139 | if(!(src = fopen(encrypted, "rb"))) | 142 | if(!(src = fopen(encrypted, "rb"))) |
| @@ -174,11 +177,11 @@ int encrypttofile(FILE *src, FILE *dst, const unsigned char key[crypto_secretstr | |||
| 174 | #endif | 177 | #endif |
| 175 | 178 | ||
| 176 | if(!src) | 179 | if(!src) |
| 177 | RETURNWERR(EINVAL, -1); | 180 | ERRRET(EINVAL, -1); |
| 178 | if(!dst) | 181 | if(!dst) |
| 179 | RETURNWERR(EINVAL, -1); | 182 | ERRRET(EINVAL, -1); |
| 180 | if(!key) | 183 | if(!key) |
| 181 | RETURNWERR(EINVAL, -1); | 184 | ERRRET(EINVAL, -1); |
| 182 | 185 | ||
| 183 | // Write the header | 186 | // Write the header |
| 184 | crypto_secretstream_xchacha20poly1305_init_push(&state, header, key); | 187 | crypto_secretstream_xchacha20poly1305_init_push(&state, header, key); |
| @@ -217,11 +220,11 @@ int decrypttofile(FILE *src, FILE *dst, const unsigned char key[crypto_secretstr | |||
| 217 | #endif | 220 | #endif |
| 218 | 221 | ||
| 219 | if(!src) | 222 | if(!src) |
| 220 | RETURNWERR(EINVAL, -1); | 223 | ERRRET(EINVAL, -1); |
| 221 | if(!dst) | 224 | if(!dst) |
| 222 | RETURNWERR(EINVAL, -1); | 225 | ERRRET(EINVAL, -1); |
| 223 | if(!key) | 226 | if(!key) |
| 224 | RETURNWERR(EINVAL, -1); | 227 | ERRRET(EINVAL, -1); |
| 225 | 228 | ||
| 226 | // Read the header | 229 | // Read the header |
| 227 | if(fread(header, 1, sizeof(header), src) < sizeof(header)) | 230 | if(fread(header, 1, sizeof(header), src) < sizeof(header)) |
