summaryrefslogtreecommitdiff
path: root/toxencryptsave/toxencryptsave.h
diff options
context:
space:
mode:
authordubslow <bunslow@gmail.com>2014-10-08 18:14:23 -0500
committerdubslow <bunslow@gmail.com>2014-10-08 18:50:40 -0500
commite6f30694d32a81f9171b2057d9c873cc16f6dca1 (patch)
tree198d595c26c7eb714e6f032d43638dd9408c9bea /toxencryptsave/toxencryptsave.h
parenteee37b5767488b8d21c0fb918ae8bf974e66d27d (diff)
refactor toxencryptedsave to allow passphrase encryption of arbitrary data
also a minor API change for clarity
Diffstat (limited to 'toxencryptsave/toxencryptsave.h')
-rw-r--r--toxencryptsave/toxencryptsave.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h
index 75094a2b..e3f998af 100644
--- a/toxencryptsave/toxencryptsave.h
+++ b/toxencryptsave/toxencryptsave.h
@@ -35,6 +35,8 @@ extern "C" {
35typedef struct Tox Tox; 35typedef struct Tox Tox;
36#endif 36#endif
37 37
38#define TOX_PASS_ENCRYPTION_EXTRA_LENGTH (crypto_box_MACBYTES + crypto_box_NONCEBYTES \
39 + crypto_pwhash_scryptsalsa208sha256_SALTBYTES)
38 40
39/* This "module" provides functions analogous to tox_load and tox_save in toxcore 41/* This "module" provides functions analogous to tox_load and tox_save in toxcore
40 * Clients should consider alerting their users that, unlike plain data, if even one bit 42 * Clients should consider alerting their users that, unlike plain data, if even one bit
@@ -45,6 +47,16 @@ typedef struct Tox Tox;
45/* return size of the messenger data (for encrypted saving). */ 47/* return size of the messenger data (for encrypted saving). */
46uint32_t tox_encrypted_size(const Tox *tox); 48uint32_t tox_encrypted_size(const Tox *tox);
47 49
50/* Encrypts the given data with the given passphrase. The output array must be
51 * at least data_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes long.
52 *
53 * tox_encrypted_save() is a good example of how to use this function.
54 *
55 * returns 0 on success
56 * returns -1 on failure
57 */
58int tox_pass_encrypt(uint8_t* data, uint32_t data_len, uint8_t* passphrase, uint32_t pplength, uint8_t* out);
59
48/* Save the messenger data encrypted with the given password. 60/* Save the messenger data encrypted with the given password.
49 * data must be at least tox_encrypted_size(). 61 * data must be at least tox_encrypted_size().
50 * 62 *
@@ -53,6 +65,16 @@ uint32_t tox_encrypted_size(const Tox *tox);
53 */ 65 */
54int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint32_t pplength); 66int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint32_t pplength);
55 67
68/* Decrypts the given data with the given passphrase. The output array must be
69 * at least data_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes long.
70 *
71 * tox_encrypted_load() is a good example of how to use this function.
72 *
73 * returns the length of the output data (== data_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH) on success
74 * returns -1 on failure
75 */
76int tox_pass_decrypt(const uint8_t* data, uint32_t length, uint8_t* passphrase, uint32_t pplength, uint8_t* out);
77
56/* Load the messenger from encrypted data of size length. 78/* Load the messenger from encrypted data of size length.
57 * 79 *
58 * returns 0 on success 80 * returns 0 on success
@@ -65,7 +87,7 @@ int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *
65 * returns 1 if it is encrypted 87 * returns 1 if it is encrypted
66 * returns 0 otherwise 88 * returns 0 otherwise
67 */ 89 */
68int tox_is_data_encrypted(const uint8_t *data); 90int tox_is_save_encrypted(const uint8_t *data);
69 91
70#ifdef __cplusplus 92#ifdef __cplusplus
71} 93}