diff options
author | Dubslow <bunslow@gmail.com> | 2015-02-27 17:42:36 -0600 |
---|---|---|
committer | Dubslow <bunslow@gmail.com> | 2015-02-27 17:42:36 -0600 |
commit | e632ef8a478ebb964b855c641e2ba14b279c78e1 (patch) | |
tree | d0f0126ac5697864b2a6ea77f62330d66a6a09fb /toxencryptsave | |
parent | c5b03cdd9a5c24d31870dfd474507a097f93b60b (diff) |
Realign toxencryptsave with new API
Diffstat (limited to 'toxencryptsave')
-rw-r--r-- | toxencryptsave/toxencryptsave.c | 36 | ||||
-rw-r--r-- | toxencryptsave/toxencryptsave.h | 25 |
2 files changed, 35 insertions, 26 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 | } | ||
diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index da13f312..ea5f4eab 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h | |||
@@ -29,10 +29,13 @@ extern "C" { | |||
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | #include <stdint.h> | 31 | #include <stdint.h> |
32 | #include <stddef.h> | ||
32 | 33 | ||
33 | #ifndef TOX_DEFINED | 34 | #ifndef TOX_DEFINED |
34 | #define TOX_DEFINED | 35 | #define TOX_DEFINED |
35 | typedef struct Tox Tox; | 36 | typedef struct Tox Tox; |
37 | struct Tox_Options; | ||
38 | typedef uint8_t TOX_ERR_NEW; | ||
36 | #endif | 39 | #endif |
37 | 40 | ||
38 | // these functions provide access to these defines in toxencryptsave.c, which | 41 | // these functions provide access to these defines in toxencryptsave.c, which |
@@ -88,6 +91,9 @@ int tox_pass_encrypt(const uint8_t *data, uint32_t data_len, uint8_t *passphrase | |||
88 | /* Save the messenger data encrypted with the given password. | 91 | /* Save the messenger data encrypted with the given password. |
89 | * data must be at least tox_encrypted_size(). | 92 | * data must be at least tox_encrypted_size(). |
90 | * | 93 | * |
94 | * NOTE: Unlike tox_save(), this function may fail. Be sure to check its return | ||
95 | * value. | ||
96 | * | ||
91 | * returns 0 on success | 97 | * returns 0 on success |
92 | * returns -1 on failure | 98 | * returns -1 on failure |
93 | */ | 99 | */ |
@@ -104,12 +110,12 @@ int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint3 | |||
104 | */ | 110 | */ |
105 | int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); | 111 | int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); |
106 | 112 | ||
107 | /* Load the messenger from encrypted data of size length. | 113 | /* Load the new messenger from encrypted data of size length. |
114 | * All other arguments are like toxcore/tox_new(). | ||
108 | * | 115 | * |
109 | * returns 0 on success | 116 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
110 | * returns -1 on failure | ||
111 | */ | 117 | */ |
112 | int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength); | 118 | 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); |
113 | 119 | ||
114 | 120 | ||
115 | /******************************* BEGIN PART 1 ******************************* | 121 | /******************************* BEGIN PART 1 ******************************* |
@@ -161,6 +167,9 @@ int tox_pass_key_encrypt(const uint8_t *data, uint32_t data_len, const uint8_t * | |||
161 | /* Save the messenger data encrypted with the given key from tox_derive_key. | 167 | /* Save the messenger data encrypted with the given key from tox_derive_key. |
162 | * data must be at least tox_encrypted_size(). | 168 | * data must be at least tox_encrypted_size(). |
163 | * | 169 | * |
170 | * NOTE: Unlike tox_save(), this function may fail. Be sure to check its return | ||
171 | * value. | ||
172 | * | ||
164 | * returns 0 on success | 173 | * returns 0 on success |
165 | * returns -1 on failure | 174 | * returns -1 on failure |
166 | */ | 175 | */ |
@@ -175,11 +184,12 @@ int tox_encrypted_key_save(const Tox *tox, uint8_t *data, uint8_t *key); | |||
175 | int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out); | 184 | int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out); |
176 | 185 | ||
177 | /* Load the messenger from encrypted data of size length, with key from tox_derive_key. | 186 | /* Load the messenger from encrypted data of size length, with key from tox_derive_key. |
187 | * All other arguments are like toxcore/tox_new(). | ||
178 | * | 188 | * |
179 | * returns 0 on success | 189 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
180 | * returns -1 on failure | ||
181 | */ | 190 | */ |
182 | int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key); | 191 | Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, TOX_ERR_NEW *error); |
192 | |||
183 | 193 | ||
184 | /* Determines whether or not the given data is encrypted (by checking the magic number) | 194 | /* Determines whether or not the given data is encrypted (by checking the magic number) |
185 | * | 195 | * |
@@ -187,7 +197,6 @@ int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8 | |||
187 | * returns 0 otherwise | 197 | * returns 0 otherwise |
188 | */ | 198 | */ |
189 | int tox_is_data_encrypted(const uint8_t *data); | 199 | int tox_is_data_encrypted(const uint8_t *data); |
190 | int tox_is_save_encrypted(const uint8_t *data); // poorly-named alias for backwards compat (oh irony...) | ||
191 | 200 | ||
192 | #ifdef __cplusplus | 201 | #ifdef __cplusplus |
193 | } | 202 | } |