summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r--toxcore/net_crypto.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 778837f4..030cc678 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -80,7 +80,8 @@ typedef struct {
80uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen); 80uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen);
81 81
82/* Encrypts plain of length length to encrypted of length + 16 using the 82/* Encrypts plain of length length to encrypted of length + 16 using the
83 * public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce. 83 * public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce.
84 *
84 * return -1 if there was a problem. 85 * return -1 if there was a problem.
85 * return length of encrypted data if everything was fine. 86 * return length of encrypted data if everything was fine.
86 */ 87 */
@@ -89,7 +90,8 @@ int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
89 90
90 91
91/* Decrypts encrypted of length length to plain of length length - 16 using the 92/* Decrypts encrypted of length length to plain of length length - 16 using the
92 * public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce. 93 * public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce.
94 *
93 * return -1 if there was a problem (decryption failed). 95 * return -1 if there was a problem (decryption failed).
94 * return length of plain data if everything was fine. 96 * return length of plain data if everything was fine.
95 */ 97 */
@@ -113,14 +115,14 @@ int decrypt_data_fast(uint8_t *enc_key, uint8_t *nonce,
113/* Fill the given nonce with random bytes. */ 115/* Fill the given nonce with random bytes. */
114void random_nonce(uint8_t *nonce); 116void random_nonce(uint8_t *nonce);
115 117
116/* return 0 if there is no received data in the buffer. 118/* return 0 if there is no received data in the buffer.
117 * return -1 if the packet was discarded. 119 * return -1 if the packet was discarded.
118 * return length of received data if successful. 120 * return length of received data if successful.
119 */ 121 */
120int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data); 122int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data);
121 123
122/* return 0 if data could not be put in packet queue 124/* return 0 if data could not be put in packet queue.
123 * return 1 if data was put into the queue 125 * return 1 if data was put into the queue.
124 */ 126 */
125int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); 127int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length);
126 128
@@ -131,8 +133,8 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin
131 * Data represents the data we send with the request with length being the length of the data. 133 * Data represents the data we send with the request with length being the length of the data.
132 * request_id is the id of the request (32 = friend request, 254 = ping request). 134 * request_id is the id of the request (32 = friend request, 254 = ping request).
133 * 135 *
134 * returns -1 on failure. 136 * return -1 on failure.
135 * returns the length of the created packet on success. 137 * return the length of the created packet on success.
136 */ 138 */
137int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key, 139int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key,
138 uint8_t *data, uint32_t length, uint8_t request_id); 140 uint8_t *data, uint32_t length, uint8_t request_id);
@@ -142,18 +144,21 @@ int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *
142void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object); 144void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object);
143 145
144/* Start a secure connection with other peer who has public_key and ip_port. 146/* Start a secure connection with other peer who has public_key and ip_port.
145 * returns -1 if failure. 147 *
146 * returns crypt_connection_id of the initialized connection if everything went well. 148 * return -1 if failure.
149 * return crypt_connection_id of the initialized connection if everything went well.
147 */ 150 */
148int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port); 151int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port);
149 152
150/* Kill a crypto connection. 153/* Kill a crypto connection.
154 *
151 * return 0 if killed successfully. 155 * return 0 if killed successfully.
152 * return 1 if there was a problem. 156 * return 1 if there was a problem.
153 */ 157 */
154int crypto_kill(Net_Crypto *c, int crypt_connection_id); 158int crypto_kill(Net_Crypto *c, int crypt_connection_id);
155 159
156/* Handle an incoming connection. 160/* Handle an incoming connection.
161 *
157 * return -1 if no crypto inbound connection. 162 * return -1 if no crypto inbound connection.
158 * return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection. 163 * return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection.
159 * 164 *
@@ -165,17 +170,18 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
165int crypto_inbound(Net_Crypto *c, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key); 170int crypto_inbound(Net_Crypto *c, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key);
166 171
167/* Accept an incoming connection using the parameters provided by crypto_inbound. 172/* Accept an incoming connection using the parameters provided by crypto_inbound.
173 *
168 * return -1 if not successful. 174 * return -1 if not successful.
169 * returns the crypt_connection_id if successful. 175 * return crypt_connection_id if successful.
170 */ 176 */
171int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key, uint8_t *secret_nonce, 177int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key, uint8_t *secret_nonce,
172 uint8_t *session_key); 178 uint8_t *session_key);
173 179
174/* return 0 if no connection. 180/* return 0 if no connection.
175 * return 1 we have sent a handshake 181 * return 1 we have sent a handshake
176 * return 2 if connexion is not confirmed yet (we have received a handshake but no empty data packet). 182 * return 2 if connexion is not confirmed yet (we have received a handshake but no empty data packet).
177 * return 3 if the connection is established. 183 * return 3 if the connection is established.
178 * return 4 if the connection is timed out and waiting to be killed. 184 * return 4 if the connection is timed out and waiting to be killed.
179 */ 185 */
180int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id); 186int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id);
181 187