diff options
Diffstat (limited to 'core/net_crypto.h')
-rw-r--r-- | core/net_crypto.h | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/core/net_crypto.h b/core/net_crypto.h index b497f1fb..b5bab17a 100644 --- a/core/net_crypto.h +++ b/core/net_crypto.h | |||
@@ -1,26 +1,26 @@ | |||
1 | /* net_crypto.h | 1 | /* net_crypto.h |
2 | * | 2 | * |
3 | * Functions for the core network crypto. | 3 | * Functions for the core network crypto. |
4 | * | 4 | * |
5 | 5 | * Copyright (C) 2013 Tox project All Rights Reserved. | |
6 | Copyright (C) 2013 Tox project All Rights Reserved. | 6 | * |
7 | 7 | * This file is part of Tox. | |
8 | This file is part of Tox. | 8 | * |
9 | 9 | * Tox is free software: you can redistribute it and/or modify | |
10 | Tox is free software: you can redistribute it and/or modify | 10 | * it under the terms of the GNU General Public License as published by |
11 | it under the terms of the GNU General Public License as published by | 11 | * the Free Software Foundation, either version 3 of the License, or |
12 | the Free Software Foundation, either version 3 of the License, or | 12 | * (at your option) any later version. |
13 | (at your option) any later version. | 13 | * |
14 | 14 | * Tox is distributed in the hope that it will be useful, | |
15 | Tox is distributed in the hope that it will be useful, | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | * GNU General Public License for more details. |
18 | GNU General Public License for more details. | 18 | * |
19 | 19 | * You should have received a copy of the GNU General Public License | |
20 | You should have received a copy of the GNU General Public License | 20 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. |
21 | along with Tox. If not, see <http://www.gnu.org/licenses/>. | 21 | * |
22 | 22 | */ | |
23 | */ | 23 | |
24 | #ifndef NET_CRYPTO_H | 24 | #ifndef NET_CRYPTO_H |
25 | #define NET_CRYPTO_H | 25 | #define NET_CRYPTO_H |
26 | 26 | ||
@@ -55,13 +55,11 @@ int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | |||
55 | /* fill the given nonce with random bytes. */ | 55 | /* fill the given nonce with random bytes. */ |
56 | void random_nonce(uint8_t * nonce); | 56 | void random_nonce(uint8_t * nonce); |
57 | 57 | ||
58 | |||
59 | /* return 0 if there is no received data in the buffer | 58 | /* return 0 if there is no received data in the buffer |
60 | return -1 if the packet was discarded. | 59 | return -1 if the packet was discarded. |
61 | return length of received data if successful */ | 60 | return length of received data if successful */ |
62 | int read_cryptpacket(int crypt_connection_id, uint8_t * data); | 61 | int read_cryptpacket(int crypt_connection_id, uint8_t * data); |
63 | 62 | ||
64 | |||
65 | /* return 0 if data could not be put in packet queue | 63 | /* return 0 if data could not be put in packet queue |
66 | return 1 if data was put into the queue */ | 64 | return 1 if data was put into the queue */ |
67 | int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length); | 65 | int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length); |
@@ -74,20 +72,17 @@ int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length); | |||
74 | returns the length of the created packet on success */ | 72 | returns the length of the created packet on success */ |
75 | int create_request(uint8_t * packet, uint8_t * public_key, uint8_t * data, uint32_t length, uint8_t request_id); | 73 | int create_request(uint8_t * packet, uint8_t * public_key, uint8_t * data, uint32_t length, uint8_t request_id); |
76 | 74 | ||
77 | |||
78 | /* puts the senders public key in the request in public_key, the data from the request | 75 | /* puts the senders public key in the request in public_key, the data from the request |
79 | in data if a friend or ping request was sent to us and returns the length of the data. | 76 | in data if a friend or ping request was sent to us and returns the length of the data. |
80 | packet is the request packet and length is its length | 77 | packet is the request packet and length is its length |
81 | return -1 if not valid request. */ | 78 | return -1 if not valid request. */ |
82 | int handle_request(uint8_t * public_key, uint8_t * data, uint8_t * packet, uint16_t length); | 79 | int handle_request(uint8_t * public_key, uint8_t * data, uint8_t * packet, uint16_t length); |
83 | 80 | ||
84 | |||
85 | /* Start a secure connection with other peer who has public_key and ip_port | 81 | /* Start a secure connection with other peer who has public_key and ip_port |
86 | returns -1 if failure | 82 | returns -1 if failure |
87 | returns crypt_connection_id of the initialized connection if everything went well. */ | 83 | returns crypt_connection_id of the initialized connection if everything went well. */ |
88 | int crypto_connect(uint8_t * public_key, IP_Port ip_port); | 84 | int crypto_connect(uint8_t * public_key, IP_Port ip_port); |
89 | 85 | ||
90 | |||
91 | /* kill a crypto connection | 86 | /* kill a crypto connection |
92 | return 0 if killed successfully | 87 | return 0 if killed successfully |
93 | return 1 if there was a problem. */ | 88 | return 1 if there was a problem. */ |
@@ -102,7 +97,6 @@ int crypto_kill(int crypt_connection_id); | |||
102 | to refuse it just call kill_connection(...) on the connection id */ | 97 | to refuse it just call kill_connection(...) on the connection id */ |
103 | int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key); | 98 | int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key); |
104 | 99 | ||
105 | |||
106 | /* accept an incoming connection using the parameters provided by crypto_inbound | 100 | /* accept an incoming connection using the parameters provided by crypto_inbound |
107 | return -1 if not successful | 101 | return -1 if not successful |
108 | returns the crypt_connection_id if successful */ | 102 | returns the crypt_connection_id if successful */ |