summaryrefslogtreecommitdiff
path: root/core/net_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/net_crypto.c')
-rw-r--r--core/net_crypto.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 6536189e..044845f0 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -1,38 +1,35 @@
1/* net_crypto.c 1/* net_crypto.c
2* 2 *
3* Functions for the core network crypto. 3 * Functions for the core network crypto.
4* See also: docs/Crypto.txt 4 * See also: docs/Crypto.txt
5* 5 *
6* NOTE: This code has to be perfect. We don't mess around with encryption. 6 * NOTE: This code has to be perfect. We don't mess around with encryption.
7* 7 *
8 8 * Copyright (C) 2013 Tox project All Rights Reserved.
9 Copyright (C) 2013 Tox project All Rights Reserved. 9 *
10 10 * This file is part of Tox.
11 This file is part of Tox. 11 *
12 12 * Tox is free software: you can redistribute it and/or modify
13 Tox is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by
14 it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation, either version 3 of the License, or
15 the Free Software Foundation, either version 3 of the License, or 15 * (at your option) any later version.
16 (at your option) any later version. 16 *
17 17 * Tox is distributed in the hope that it will be useful,
18 Tox is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details.
21 GNU General Public License for more details. 21 *
22 22 * You should have received a copy of the GNU General Public License
23 You should have received a copy of the GNU General Public License 23 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
24 along with Tox. If not, see <http://www.gnu.org/licenses/>. 24 *
25 25 */
26*/
27 26
28#include "net_crypto.h" 27#include "net_crypto.h"
29 28
30
31/* Our public and secret keys. */ 29/* Our public and secret keys. */
32uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; 30uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
33uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; 31uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
34 32
35
36typedef struct 33typedef struct
37{ 34{
38 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* the real public key of the peer. */ 35 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* the real public key of the peer. */
@@ -178,7 +175,6 @@ int read_cryptpacket(int crypt_connection_id, uint8_t * data)
178 return -1; 175 return -1;
179} 176}
180 177
181
182/* return 0 if data could not be put in packet queue 178/* return 0 if data could not be put in packet queue
183 return 1 if data was put into the queue */ 179 return 1 if data was put into the queue */
184int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length) 180int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length)
@@ -268,7 +264,6 @@ int handle_request(uint8_t * public_key, uint8_t * data, uint8_t * packet, uint1
268 } 264 }
269} 265}
270 266
271
272/* Send a crypto handshake packet containing an encrypted secret nonce and session public key 267/* Send a crypto handshake packet containing an encrypted secret nonce and session public key
273 to peer with connection_id and public_key 268 to peer with connection_id and public_key
274 the packet is encrypted with a random nonce which is sent in plain text with the packet */ 269 the packet is encrypted with a random nonce which is sent in plain text with the packet */
@@ -328,9 +323,6 @@ int handle_cryptohandshake(uint8_t * public_key, uint8_t * secret_nonce,
328 return 1; 323 return 1;
329} 324}
330 325
331
332
333
334/* get crypto connection id from public key of peer 326/* get crypto connection id from public key of peer
335 return -1 if there are no connections like we are looking for 327 return -1 if there are no connections like we are looking for
336 return id if it found it */ 328 return id if it found it */
@@ -350,7 +342,6 @@ int getcryptconnection_id(uint8_t * public_key)
350 return -1; 342 return -1;
351} 343}
352 344
353
354/* Start a secure connection with other peer who has public_key and ip_port 345/* Start a secure connection with other peer who has public_key and ip_port
355 returns -1 if failure 346 returns -1 if failure
356 returns crypt_connection_id of the initialized connection if everything went well. */ 347 returns crypt_connection_id of the initialized connection if everything went well. */
@@ -448,7 +439,6 @@ int crypto_kill(int crypt_connection_id)
448 return 1; 439 return 1;
449} 440}
450 441
451
452/* accept an incoming connection using the parameters provided by crypto_inbound 442/* accept an incoming connection using the parameters provided by crypto_inbound
453 return -1 if not successful 443 return -1 if not successful
454 returns the crypt_connection_id if successful */ 444 returns the crypt_connection_id if successful */
@@ -506,7 +496,6 @@ int is_cryptoconnected(int crypt_connection_id)
506 return 0; 496 return 0;
507} 497}
508 498
509
510/* Generate our public and private keys 499/* Generate our public and private keys
511 Only call this function the first time the program starts. */ 500 Only call this function the first time the program starts. */
512void new_keys() 501void new_keys()
@@ -682,4 +671,4 @@ void doNetCrypto()
682 handle_incomings(); 671 handle_incomings();
683 receive_crypto(); 672 receive_crypto();
684 killTimedout(); 673 killTimedout();
685} 674} \ No newline at end of file