summaryrefslogtreecommitdiff
path: root/toxencryptsave
diff options
context:
space:
mode:
Diffstat (limited to 'toxencryptsave')
-rw-r--r--toxencryptsave/toxencryptsave.c12
-rw-r--r--toxencryptsave/toxencryptsave.h8
2 files changed, 10 insertions, 10 deletions
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c
index e2f28a58..e6150ce2 100644
--- a/toxencryptsave/toxencryptsave.c
+++ b/toxencryptsave/toxencryptsave.c
@@ -82,7 +82,7 @@ bool tox_get_salt(const uint8_t *data, uint8_t *salt)
82 * 82 *
83 * returns true on success 83 * returns true on success
84 */ 84 */
85bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key, 85bool tox_derive_key_from_pass(const uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key,
86 TOX_ERR_KEY_DERIVATION *error) 86 TOX_ERR_KEY_DERIVATION *error)
87{ 87{
88 uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; 88 uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES];
@@ -93,10 +93,10 @@ bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, TOX_PASS_KEY
93/* Same as above, except with use the given salt for deterministic key derivation. 93/* Same as above, except with use the given salt for deterministic key derivation.
94 * The salt must be TOX_PASS_SALT_LENGTH bytes in length. 94 * The salt must be TOX_PASS_SALT_LENGTH bytes in length.
95 */ 95 */
96bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, TOX_PASS_KEY *out_key, 96bool tox_derive_key_with_salt(const uint8_t *passphrase, size_t pplength, const uint8_t *salt, TOX_PASS_KEY *out_key,
97 TOX_ERR_KEY_DERIVATION *error) 97 TOX_ERR_KEY_DERIVATION *error)
98{ 98{
99 if (pplength == 0 || !passphrase || !salt || !out_key) { 99 if (!salt || !out_key || (!passphrase && pplength != 0)) {
100 SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL); 100 SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL);
101 return 0; 101 return 0;
102 } 102 }
@@ -180,7 +180,7 @@ bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const TOX_PASS_K
180 * 180 *
181 * returns true on success 181 * returns true on success
182 */ 182 */
183bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, 183bool tox_pass_encrypt(const uint8_t *data, size_t data_len, const uint8_t *passphrase, size_t pplength, uint8_t *out,
184 TOX_ERR_ENCRYPTION *error) 184 TOX_ERR_ENCRYPTION *error)
185{ 185{
186 TOX_PASS_KEY key; 186 TOX_PASS_KEY key;
@@ -252,10 +252,10 @@ bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const TOX_PASS_KEY
252 * 252 *
253 * returns true on success 253 * returns true on success
254 */ 254 */
255bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, 255bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphrase, size_t pplength, uint8_t *out,
256 TOX_ERR_DECRYPTION *error) 256 TOX_ERR_DECRYPTION *error)
257{ 257{
258 if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH || pplength == 0) { 258 if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) {
259 SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); 259 SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH);
260 return 0; 260 return 0;
261 } 261 }
diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h
index c077d899..9e28b48e 100644
--- a/toxencryptsave/toxencryptsave.h
+++ b/toxencryptsave/toxencryptsave.h
@@ -143,7 +143,7 @@ typedef enum TOX_ERR_DECRYPTION {
143 * 143 *
144 * returns true on success 144 * returns true on success
145 */ 145 */
146bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, 146bool tox_pass_encrypt(const uint8_t *data, size_t data_len, const uint8_t *passphrase, size_t pplength, uint8_t *out,
147 TOX_ERR_ENCRYPTION *error); 147 TOX_ERR_ENCRYPTION *error);
148 148
149 149
@@ -155,7 +155,7 @@ bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase,
155 * 155 *
156 * returns true on success 156 * returns true on success
157 */ 157 */
158bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, 158bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphrase, size_t pplength, uint8_t *out,
159 TOX_ERR_DECRYPTION *error); 159 TOX_ERR_DECRYPTION *error);
160 160
161 161
@@ -183,13 +183,13 @@ typedef struct {
183 * 183 *
184 * returns true on success 184 * returns true on success
185 */ 185 */
186bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key, 186bool tox_derive_key_from_pass(const uint8_t *passphrase, size_t pplength, TOX_PASS_KEY *out_key,
187 TOX_ERR_KEY_DERIVATION *error); 187 TOX_ERR_KEY_DERIVATION *error);
188 188
189/* Same as above, except use the given salt for deterministic key derivation. 189/* Same as above, except use the given salt for deterministic key derivation.
190 * The salt must be TOX_PASS_SALT_LENGTH bytes in length. 190 * The salt must be TOX_PASS_SALT_LENGTH bytes in length.
191 */ 191 */
192bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, TOX_PASS_KEY *out_key, 192bool tox_derive_key_with_salt(const uint8_t *passphrase, size_t pplength, const uint8_t *salt, TOX_PASS_KEY *out_key,
193 TOX_ERR_KEY_DERIVATION *error); 193 TOX_ERR_KEY_DERIVATION *error);
194 194
195/* This retrieves the salt used to encrypt the given data, which can then be passed to 195/* This retrieves the salt used to encrypt the given data, which can then be passed to