diff options
Diffstat (limited to 'toxencryptsave/toxencryptsave.c')
-rw-r--r-- | toxencryptsave/toxencryptsave.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 13a34dea..b801e1ba 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "defines.h" | 29 | #include "defines.h" |
30 | #include "../toxcore/crypto_core.h" | 30 | #include "../toxcore/crypto_core.h" |
31 | #include "../toxcore/tox.h" | 31 | #include "../toxcore/tox.h" |
32 | #define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}} | ||
32 | 33 | ||
33 | #ifdef VANILLA_NACL | 34 | #ifdef VANILLA_NACL |
34 | #include "crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" | 35 | #include "crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" |
@@ -293,38 +294,42 @@ int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, | |||
293 | return tox_pass_key_decrypt(data, length, key, out); | 294 | return tox_pass_key_decrypt(data, length, key, out); |
294 | } | 295 | } |
295 | 296 | ||
296 | /* Load the messenger from encrypted data of size length. | 297 | /* Load the new messenger from encrypted data of size length. |
298 | * All other arguments are like toxcore/tox_new(). | ||
297 | * | 299 | * |
298 | * returns 0 on success | 300 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
299 | * returns -1 on failure | ||
300 | */ | 301 | */ |
301 | int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength) | 302 | Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, TOX_ERR_NEW *error) |
302 | { | 303 | { |
303 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 304 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
304 | uint8_t temp_data[decrypt_length]; | 305 | uint8_t temp_data[decrypt_length]; |
305 | 306 | ||
306 | if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) | 307 | if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) |
307 | != decrypt_length) | 308 | != decrypt_length) { |
308 | return -1; | 309 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); |
310 | return NULL; | ||
311 | } | ||
309 | 312 | ||
310 | return tox_load(tox, temp_data, decrypt_length); | 313 | return tox_new(options, temp_data, decrypt_length, error); |
311 | } | 314 | } |
312 | 315 | ||
313 | /* Load the messenger from encrypted data of size length, with key from tox_derive_key. | 316 | /* Load the messenger from encrypted data of size length, with key from tox_derive_key. |
317 | * All other arguments are like toxcore/tox_new(). | ||
314 | * | 318 | * |
315 | * returns 0 on success | 319 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
316 | * returns -1 on failure | ||
317 | */ | 320 | */ |
318 | int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key) | 321 | Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, TOX_ERR_NEW *error) |
319 | { | 322 | { |
320 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 323 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
321 | uint8_t temp_data[decrypt_length]; | 324 | uint8_t temp_data[decrypt_length]; |
322 | 325 | ||
323 | if (tox_pass_key_decrypt(data, length, key, temp_data) | 326 | if (tox_pass_key_decrypt(data, length, key, temp_data) |
324 | != decrypt_length) | 327 | != decrypt_length) { |
325 | return -1; | 328 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); |
329 | return NULL; | ||
330 | } | ||
326 | 331 | ||
327 | return tox_load(tox, temp_data, decrypt_length); | 332 | return tox_new(options, temp_data, decrypt_length, error); |
328 | } | 333 | } |
329 | 334 | ||
330 | /* Determines whether or not the given data is encrypted (by checking the magic number) | 335 | /* Determines whether or not the given data is encrypted (by checking the magic number) |
@@ -339,8 +344,3 @@ int tox_is_data_encrypted(const uint8_t *data) | |||
339 | else | 344 | else |
340 | return 0; | 345 | return 0; |
341 | } | 346 | } |
342 | |||
343 | int tox_is_save_encrypted(const uint8_t *data) | ||
344 | { | ||
345 | return tox_is_data_encrypted(data); | ||
346 | } | ||