diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | auto_tests/encryptsave_test.c | 5 | ||||
-rw-r--r-- | toxcore/Messenger.c | 2 | ||||
-rw-r--r-- | toxcore/crypto_core.c | 11 | ||||
-rw-r--r-- | toxcore/tox.h | 3 | ||||
-rw-r--r-- | toxencryptsave/toxencryptsave.c | 17 | ||||
-rw-r--r-- | toxencryptsave/toxencryptsave.h | 15 |
7 files changed, 30 insertions, 25 deletions
@@ -38,6 +38,6 @@ The goal of this project is to create a configuration-free P2P Skype replacement | |||
38 | - [DHT Protocol](/docs/updates/DHT.md)<br /> | 38 | - [DHT Protocol](/docs/updates/DHT.md)<br /> |
39 | - [Crypto](/docs/updates/Crypto.md)<br /> | 39 | - [Crypto](/docs/updates/Crypto.md)<br /> |
40 | 40 | ||
41 | Additional developer documentation can be found in [tox.h.](/toxcore/tox.h) | 41 | Additional developer documentation can be found at [Libtoxcore.so](https://libtoxcore.so/) |
42 | 42 | ||
43 | [String]: https://en.wikipedia.org/wiki/String_(computer_science) | 43 | [String]: https://en.wikipedia.org/wiki/String_(computer_science) |
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 9ab29a27..13e06db4 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -68,7 +68,7 @@ START_TEST(test_save_friend) | |||
68 | size_t size = tox_get_savedata_size(tox1); | 68 | size_t size = tox_get_savedata_size(tox1); |
69 | uint8_t data[size]; | 69 | uint8_t data[size]; |
70 | tox_get_savedata(tox1, data); | 70 | tox_get_savedata(tox1, data); |
71 | size_t size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 71 | size_t size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
72 | uint8_t enc_data[size2]; | 72 | uint8_t enc_data[size2]; |
73 | TOX_ERR_ENCRYPTION error1; | 73 | TOX_ERR_ENCRYPTION error1; |
74 | bool ret = tox_pass_encrypt(data, size, "correcthorsebatterystaple", 25, enc_data, &error1); | 74 | bool ret = tox_pass_encrypt(data, size, "correcthorsebatterystaple", 25, enc_data, &error1); |
@@ -77,7 +77,8 @@ START_TEST(test_save_friend) | |||
77 | 77 | ||
78 | TOX_ERR_NEW err2; | 78 | TOX_ERR_NEW err2; |
79 | Tox *tox3 = tox_new(0, enc_data, size2, &err2); | 79 | Tox *tox3 = tox_new(0, enc_data, size2, &err2); |
80 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, TOX_ERR_NEW_LOAD_ENCRYPTED); | 80 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, |
81 | TOX_ERR_NEW_LOAD_ENCRYPTED); | ||
81 | uint8_t dec_data[size]; | 82 | uint8_t dec_data[size]; |
82 | TOX_ERR_DECRYPTION err3; | 83 | TOX_ERR_DECRYPTION err3; |
83 | ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); | 84 | ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 400782aa..3cc2f851 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2004,8 +2004,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2004 | 2004 | ||
2005 | case PACKET_ID_MESSAGE: | 2005 | case PACKET_ID_MESSAGE: |
2006 | case PACKET_ID_ACTION: { | 2006 | case PACKET_ID_ACTION: { |
2007 | const uint8_t *message_id = data; | ||
2008 | |||
2009 | if (data_length == 0) | 2007 | if (data_length == 0) |
2010 | break; | 2008 | break; |
2011 | 2009 | ||
diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 5c99a378..a364084a 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c | |||
@@ -194,19 +194,10 @@ void new_symmetric_key(uint8_t *key) | |||
194 | randombytes(key, crypto_box_KEYBYTES); | 194 | randombytes(key, crypto_box_KEYBYTES); |
195 | } | 195 | } |
196 | 196 | ||
197 | static uint8_t base_nonce[crypto_box_NONCEBYTES]; | ||
198 | static uint8_t nonce_set = 0; | ||
199 | |||
200 | /* Gives a nonce guaranteed to be different from previous ones.*/ | 197 | /* Gives a nonce guaranteed to be different from previous ones.*/ |
201 | void new_nonce(uint8_t *nonce) | 198 | void new_nonce(uint8_t *nonce) |
202 | { | 199 | { |
203 | if (nonce_set == 0) { | 200 | random_nonce(nonce); |
204 | random_nonce(base_nonce); | ||
205 | nonce_set = 1; | ||
206 | } | ||
207 | |||
208 | increment_nonce(base_nonce); | ||
209 | memcpy(nonce, base_nonce, crypto_box_NONCEBYTES); | ||
210 | } | 201 | } |
211 | 202 | ||
212 | /* Create a request to peer. | 203 | /* Create a request to peer. |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 8b06f6c3..96110d5f 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -928,6 +928,8 @@ typedef enum TOX_ERR_FRIEND_DELETE { | |||
928 | 928 | ||
929 | /** | 929 | /** |
930 | * Remove a friend from the friend list. | 930 | * Remove a friend from the friend list. |
931 | * Other friend numbers are unchanged. | ||
932 | * The friend_number can be reused by toxcore as a friend number for a new friend. | ||
931 | * | 933 | * |
932 | * This does not notify the friend of their deletion. After calling this | 934 | * This does not notify the friend of their deletion. After calling this |
933 | * function, this client will appear offline to the friend and no communication | 935 | * function, this client will appear offline to the friend and no communication |
@@ -936,6 +938,7 @@ typedef enum TOX_ERR_FRIEND_DELETE { | |||
936 | * @friend_number Friend number for the friend to be deleted. | 938 | * @friend_number Friend number for the friend to be deleted. |
937 | * | 939 | * |
938 | * @return true on success. | 940 | * @return true on success. |
941 | * @see tox_friend_add for detailed description of friend numbers. | ||
939 | */ | 942 | */ |
940 | bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *error); | 943 | bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *error); |
941 | 944 | ||
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index e7ec31f1..9b202f49 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c | |||
@@ -93,7 +93,8 @@ bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, uint8_t *out | |||
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_salt_length() bytes in length. | 94 | * The salt must be tox_salt_length() bytes in length. |
95 | */ | 95 | */ |
96 | bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, uint8_t *out_key, TOX_ERR_KEY_DERIVATION *error) | 96 | bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, uint8_t *out_key, |
97 | TOX_ERR_KEY_DERIVATION *error) | ||
97 | { | 98 | { |
98 | if (pplength == 0 || !passphrase || !salt || !out_key) { | 99 | if (pplength == 0 || !passphrase || !salt || !out_key) { |
99 | SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL); | 100 | SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL); |
@@ -133,7 +134,8 @@ bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *sal | |||
133 | * | 134 | * |
134 | * returns true on success | 135 | * returns true on success |
135 | */ | 136 | */ |
136 | bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const uint8_t *key, uint8_t *out, TOX_ERR_ENCRYPTION *error) | 137 | bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const uint8_t *key, uint8_t *out, |
138 | TOX_ERR_ENCRYPTION *error) | ||
137 | { | 139 | { |
138 | if (data_len == 0 || !data || !key || !out) { | 140 | if (data_len == 0 || !data || !key || !out) { |
139 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_NULL); | 141 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_NULL); |
@@ -179,7 +181,8 @@ bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const uint8_t *k | |||
179 | * | 181 | * |
180 | * returns true on success | 182 | * returns true on success |
181 | */ | 183 | */ |
182 | bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_ENCRYPTION *error) | 184 | bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, |
185 | TOX_ERR_ENCRYPTION *error) | ||
183 | { | 186 | { |
184 | uint8_t key[TOX_PASS_KEY_LENGTH]; | 187 | uint8_t key[TOX_PASS_KEY_LENGTH]; |
185 | TOX_ERR_KEY_DERIVATION _error; | 188 | TOX_ERR_KEY_DERIVATION _error; |
@@ -190,6 +193,7 @@ bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, | |||
190 | } else if (_error == TOX_ERR_KEY_DERIVATION_FAILED) { | 193 | } else if (_error == TOX_ERR_KEY_DERIVATION_FAILED) { |
191 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_KEY_DERIVATION_FAILED); | 194 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_KEY_DERIVATION_FAILED); |
192 | } | 195 | } |
196 | |||
193 | return 0; | 197 | return 0; |
194 | } | 198 | } |
195 | 199 | ||
@@ -203,12 +207,14 @@ bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, | |||
203 | * | 207 | * |
204 | * returns true on success | 208 | * returns true on success |
205 | */ | 209 | */ |
206 | bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const uint8_t *key, uint8_t *out, TOX_ERR_DECRYPTION *error) | 210 | bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const uint8_t *key, uint8_t *out, |
211 | TOX_ERR_DECRYPTION *error) | ||
207 | { | 212 | { |
208 | if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { | 213 | if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { |
209 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); | 214 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); |
210 | return 0; | 215 | return 0; |
211 | } | 216 | } |
217 | |||
212 | if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { | 218 | if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { |
213 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); | 219 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); |
214 | return 0; | 220 | return 0; |
@@ -245,7 +251,8 @@ bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const uint8_t *key | |||
245 | * | 251 | * |
246 | * returns true on success | 252 | * returns true on success |
247 | */ | 253 | */ |
248 | bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_DECRYPTION *error) | 254 | bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, |
255 | TOX_ERR_DECRYPTION *error) | ||
249 | { | 256 | { |
250 | if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { | 257 | if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { |
251 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); | 258 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); |
diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index ef1dfb5e..2ee4af46 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h | |||
@@ -134,7 +134,8 @@ typedef enum TOX_ERR_DECRYPTION { | |||
134 | * | 134 | * |
135 | * returns true on success | 135 | * returns true on success |
136 | */ | 136 | */ |
137 | bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_ENCRYPTION *error); | 137 | bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, size_t pplength, uint8_t *out, |
138 | TOX_ERR_ENCRYPTION *error); | ||
138 | 139 | ||
139 | 140 | ||
140 | /* Decrypts the given data with the given passphrase. The output array must be | 141 | /* Decrypts the given data with the given passphrase. The output array must be |
@@ -145,7 +146,8 @@ bool tox_pass_encrypt(const uint8_t *data, size_t data_len, uint8_t *passphrase, | |||
145 | * | 146 | * |
146 | * returns true on success | 147 | * returns true on success |
147 | */ | 148 | */ |
148 | bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, TOX_ERR_DECRYPTION *error); | 149 | bool tox_pass_decrypt(const uint8_t *data, size_t length, uint8_t *passphrase, size_t pplength, uint8_t *out, |
150 | TOX_ERR_DECRYPTION *error); | ||
149 | 151 | ||
150 | 152 | ||
151 | /******************************* BEGIN PART 1 ******************************* | 153 | /******************************* BEGIN PART 1 ******************************* |
@@ -169,7 +171,8 @@ bool tox_derive_key_from_pass(uint8_t *passphrase, size_t pplength, uint8_t *out | |||
169 | /* Same as above, except with use the given salt for deterministic key derivation. | 171 | /* Same as above, except with use the given salt for deterministic key derivation. |
170 | * The salt must be tox_salt_length() bytes in length. | 172 | * The salt must be tox_salt_length() bytes in length. |
171 | */ | 173 | */ |
172 | bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, uint8_t *out_key, TOX_ERR_KEY_DERIVATION *error); | 174 | bool tox_derive_key_with_salt(uint8_t *passphrase, size_t pplength, uint8_t *salt, uint8_t *out_key, |
175 | TOX_ERR_KEY_DERIVATION *error); | ||
173 | 176 | ||
174 | /* This retrieves the salt used to encrypt the given data, which can then be passed to | 177 | /* This retrieves the salt used to encrypt the given data, which can then be passed to |
175 | * derive_key_with_salt to produce the same key as was previously used. Any encrpyted | 178 | * derive_key_with_salt to produce the same key as was previously used. Any encrpyted |
@@ -191,7 +194,8 @@ bool tox_get_salt(const uint8_t *data, uint8_t *salt); | |||
191 | * | 194 | * |
192 | * returns true on success | 195 | * returns true on success |
193 | */ | 196 | */ |
194 | bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const uint8_t *key, uint8_t *out, TOX_ERR_ENCRYPTION *error); | 197 | bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const uint8_t *key, uint8_t *out, |
198 | TOX_ERR_ENCRYPTION *error); | ||
195 | 199 | ||
196 | /* This is the inverse of tox_pass_key_encrypt, also using only keys produced by | 200 | /* This is the inverse of tox_pass_key_encrypt, also using only keys produced by |
197 | * tox_derive_key_from_pass. | 201 | * tox_derive_key_from_pass. |
@@ -200,7 +204,8 @@ bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const uint8_t *k | |||
200 | * | 204 | * |
201 | * returns true on success | 205 | * returns true on success |
202 | */ | 206 | */ |
203 | bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const uint8_t *key, uint8_t *out, TOX_ERR_DECRYPTION *error); | 207 | bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const uint8_t *key, uint8_t *out, |
208 | TOX_ERR_DECRYPTION *error); | ||
204 | 209 | ||
205 | /* Determines whether or not the given data is encrypted (by checking the magic number) | 210 | /* Determines whether or not the given data is encrypted (by checking the magic number) |
206 | */ | 211 | */ |