diff options
author | irungentoo <irungentoo@gmail.com> | 2015-03-01 20:14:01 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-03-01 20:14:01 -0500 |
commit | 680c7c2ecd1fd8b9ee4e7951f032438c1028eed6 (patch) | |
tree | baf0d3b3f6985b51a30e37b8c64e3203e5ca87c9 /toxencryptsave/toxencryptsave.c | |
parent | 8e59a826cb326e1c2cfefb775d9e0762c6ffe79b (diff) | |
parent | 2d3077904ec9360eb1f753643a16a15f0fb739c5 (diff) |
Merge branch 'new_api' of https://github.com/dubslow/toxcore into new_api
Diffstat (limited to 'toxencryptsave/toxencryptsave.c')
-rw-r--r-- | toxencryptsave/toxencryptsave.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 13a34dea..f9846ac9 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,44 @@ 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, |
303 | size_t pplength, TOX_ERR_NEW *error) | ||
302 | { | 304 | { |
303 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 305 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
304 | uint8_t temp_data[decrypt_length]; | 306 | uint8_t temp_data[decrypt_length]; |
305 | 307 | ||
306 | if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) | 308 | if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) |
307 | != decrypt_length) | 309 | != decrypt_length) { |
308 | return -1; | 310 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); |
311 | return NULL; | ||
312 | } | ||
309 | 313 | ||
310 | return tox_load(tox, temp_data, decrypt_length); | 314 | return tox_new(options, temp_data, decrypt_length, error); |
311 | } | 315 | } |
312 | 316 | ||
313 | /* Load the messenger from encrypted data of size length, with key from tox_derive_key. | 317 | /* Load the messenger from encrypted data of size length, with key from tox_derive_key. |
318 | * All other arguments are like toxcore/tox_new(). | ||
314 | * | 319 | * |
315 | * returns 0 on success | 320 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
316 | * returns -1 on failure | ||
317 | */ | 321 | */ |
318 | int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key) | 322 | Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, |
323 | TOX_ERR_NEW *error) | ||
319 | { | 324 | { |
320 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 325 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
321 | uint8_t temp_data[decrypt_length]; | 326 | uint8_t temp_data[decrypt_length]; |
322 | 327 | ||
323 | if (tox_pass_key_decrypt(data, length, key, temp_data) | 328 | if (tox_pass_key_decrypt(data, length, key, temp_data) |
324 | != decrypt_length) | 329 | != decrypt_length) { |
325 | return -1; | 330 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); |
331 | return NULL; | ||
332 | } | ||
326 | 333 | ||
327 | return tox_load(tox, temp_data, decrypt_length); | 334 | return tox_new(options, temp_data, decrypt_length, error); |
328 | } | 335 | } |
329 | 336 | ||
330 | /* Determines whether or not the given data is encrypted (by checking the magic number) | 337 | /* Determines whether or not the given data is encrypted (by checking the magic number) |
@@ -339,8 +346,3 @@ int tox_is_data_encrypted(const uint8_t *data) | |||
339 | else | 346 | else |
340 | return 0; | 347 | return 0; |
341 | } | 348 | } |
342 | |||
343 | int tox_is_save_encrypted(const uint8_t *data) | ||
344 | { | ||
345 | return tox_is_data_encrypted(data); | ||
346 | } | ||