summaryrefslogtreecommitdiff
path: root/toxencryptsave
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-03-01 20:14:01 -0500
committerirungentoo <irungentoo@gmail.com>2015-03-01 20:14:01 -0500
commit680c7c2ecd1fd8b9ee4e7951f032438c1028eed6 (patch)
treebaf0d3b3f6985b51a30e37b8c64e3203e5ca87c9 /toxencryptsave
parent8e59a826cb326e1c2cfefb775d9e0762c6ffe79b (diff)
parent2d3077904ec9360eb1f753643a16a15f0fb739c5 (diff)
Merge branch 'new_api' of https://github.com/dubslow/toxcore into new_api
Diffstat (limited to 'toxencryptsave')
-rw-r--r--toxencryptsave/toxencryptsave.c38
-rw-r--r--toxencryptsave/toxencryptsave.h27
2 files changed, 39 insertions, 26 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 */
301int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength) 302Tox *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 */
318int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key) 322Tox *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
343int 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..5ceeefdd 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
35typedef struct Tox Tox; 36typedef struct Tox Tox;
37struct Tox_Options;
38typedef 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,13 @@ int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint3
104 */ 110 */
105int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); 111int 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 */
112int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength); 118Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase,
119 size_t pplength, TOX_ERR_NEW *error);
113 120
114 121
115/******************************* BEGIN PART 1 ******************************* 122/******************************* BEGIN PART 1 *******************************
@@ -161,6 +168,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. 168/* Save the messenger data encrypted with the given key from tox_derive_key.
162 * data must be at least tox_encrypted_size(). 169 * data must be at least tox_encrypted_size().
163 * 170 *
171 * NOTE: Unlike tox_save(), this function may fail. Be sure to check its return
172 * value.
173 *
164 * returns 0 on success 174 * returns 0 on success
165 * returns -1 on failure 175 * returns -1 on failure
166 */ 176 */
@@ -175,11 +185,13 @@ int tox_encrypted_key_save(const Tox *tox, uint8_t *data, uint8_t *key);
175int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out); 185int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out);
176 186
177/* Load the messenger from encrypted data of size length, with key from tox_derive_key. 187/* Load the messenger from encrypted data of size length, with key from tox_derive_key.
188 * All other arguments are like toxcore/tox_new().
178 * 189 *
179 * returns 0 on success 190 * returns NULL on failure; see the documentation in toxcore/tox.h.
180 * returns -1 on failure
181 */ 191 */
182int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key); 192Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key,
193 TOX_ERR_NEW *error);
194
183 195
184/* Determines whether or not the given data is encrypted (by checking the magic number) 196/* Determines whether or not the given data is encrypted (by checking the magic number)
185 * 197 *
@@ -187,7 +199,6 @@ int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8
187 * returns 0 otherwise 199 * returns 0 otherwise
188 */ 200 */
189int tox_is_data_encrypted(const uint8_t *data); 201int tox_is_data_encrypted(const uint8_t *data);
190int tox_is_save_encrypted(const uint8_t *data); // poorly-named alias for backwards compat (oh irony...)
191 202
192#ifdef __cplusplus 203#ifdef __cplusplus
193} 204}