diff options
author | irungentoo <irungentoo@gmail.com> | 2013-09-02 15:59:28 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-09-02 15:59:28 -0400 |
commit | a4bf25801d510d606674afabf073f5eedf1b0efc (patch) | |
tree | cbfb093cdb2c694a861bdf86f73bcd3d3d8e676a /toxcore/net_crypto.h | |
parent | 25480852ac1cb868c2138eb7be5decc2b8271682 (diff) | |
parent | 61880ab9380f3a71ae1f51df7b6f4836059c041f (diff) |
Merge branch 'master' of https://github.com/JamoBox/ProjectTox-Core into JamoBox-master
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r-- | toxcore/net_crypto.h | 36 |
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 { | |||
80 | uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen); | 80 | uint8_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. */ |
114 | void random_nonce(uint8_t *nonce); | 116 | void 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 | */ |
120 | int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data); | 122 | int 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 | */ |
125 | int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); | 127 | int 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 | */ |
137 | int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key, | 139 | int 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 * | |||
142 | void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object); | 144 | void 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 | */ |
148 | int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port); | 151 | int 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 | */ |
154 | int crypto_kill(Net_Crypto *c, int crypt_connection_id); | 158 | int 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); | |||
165 | int crypto_inbound(Net_Crypto *c, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key); | 170 | int 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 | */ |
171 | int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key, uint8_t *secret_nonce, | 177 | int 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 | */ |
180 | int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id); | 186 | int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id); |
181 | 187 | ||