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.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 561ba866..1c56b95a 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -126,7 +126,7 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
126} 126}
127 127
128/* increment the given nonce by 1 */ 128/* increment the given nonce by 1 */
129void increment_nonce(uint8_t *nonce) 129static void increment_nonce(uint8_t *nonce)
130{ 130{
131 uint32_t i; 131 uint32_t i;
132 for (i = 0; i < crypto_box_NONCEBYTES; ++i) { 132 for (i = 0; i < crypto_box_NONCEBYTES; ++i) {
@@ -243,7 +243,7 @@ int handle_request(uint8_t *public_key, uint8_t *data, uint8_t *packet, uint16_t
243/* Send a crypto handshake packet containing an encrypted secret nonce and session public key 243/* Send a crypto handshake packet containing an encrypted secret nonce and session public key
244 to peer with connection_id and public_key 244 to peer with connection_id and public_key
245 the packet is encrypted with a random nonce which is sent in plain text with the packet */ 245 the packet is encrypted with a random nonce which is sent in plain text with the packet */
246int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key) 246static int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key)
247{ 247{
248 uint8_t temp_data[MAX_DATA_SIZE]; 248 uint8_t temp_data[MAX_DATA_SIZE];
249 uint8_t temp[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES]; 249 uint8_t temp[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES];
@@ -266,7 +266,7 @@ int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret
266/* Extract secret nonce, session public key and public_key from a packet(data) with length length 266/* Extract secret nonce, session public key and public_key from a packet(data) with length length
267 return 1 if successful 267 return 1 if successful
268 return 0 if failure */ 268 return 0 if failure */
269int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, 269static int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce,
270 uint8_t *session_key, uint8_t *data, uint16_t length) 270 uint8_t *session_key, uint8_t *data, uint16_t length)
271{ 271{
272 int pad = (- crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES); 272 int pad = (- crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES);
@@ -295,7 +295,7 @@ int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce,
295/* get crypto connection id from public key of peer 295/* get crypto connection id from public key of peer
296 return -1 if there are no connections like we are looking for 296 return -1 if there are no connections like we are looking for
297 return id if it found it */ 297 return id if it found it */
298int getcryptconnection_id(uint8_t *public_key) 298static int getcryptconnection_id(uint8_t *public_key)
299{ 299{
300 uint32_t i; 300 uint32_t i;
301 for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { 301 for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) {
@@ -440,7 +440,7 @@ int is_cryptoconnected(int crypt_connection_id)
440 440
441/* Generate our public and private keys 441/* Generate our public and private keys
442 Only call this function the first time the program starts. */ 442 Only call this function the first time the program starts. */
443void new_keys() 443void new_keys(void)
444{ 444{
445 crypto_box_keypair(self_public_key,self_secret_key); 445 crypto_box_keypair(self_public_key,self_secret_key);
446} 446}
@@ -465,7 +465,7 @@ void load_keys(uint8_t *keys)
465 adds an incoming connection to the incoming_connection list. 465 adds an incoming connection to the incoming_connection list.
466 returns 0 if successful 466 returns 0 if successful
467 returns 1 if failure */ 467 returns 1 if failure */
468int new_incoming(int id) 468static int new_incoming(int id)
469{ 469{
470 uint32_t i; 470 uint32_t i;
471 for (i = 0; i < MAX_INCOMING; ++i) { 471 for (i = 0; i < MAX_INCOMING; ++i) {
@@ -479,7 +479,7 @@ int new_incoming(int id)
479 479
480/* TODO: optimize this 480/* TODO: optimize this
481 handle all new incoming connections. */ 481 handle all new incoming connections. */
482static void handle_incomings() 482static void handle_incomings(void)
483{ 483{
484 int income; 484 int income;
485 while (1) { 485 while (1) {
@@ -490,7 +490,7 @@ static void handle_incomings()
490} 490}
491 491
492/* handle received packets for not yet established crypto connections. */ 492/* handle received packets for not yet established crypto connections. */
493static void receive_crypto() 493static void receive_crypto(void)
494{ 494{
495 uint32_t i; 495 uint32_t i;
496 for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { 496 for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) {
@@ -547,7 +547,7 @@ static void receive_crypto()
547 547
548/* run this to (re)initialize net_crypto 548/* run this to (re)initialize net_crypto
549 sets all the global connection variables to their default values. */ 549 sets all the global connection variables to their default values. */
550void initNetCrypto() 550void initNetCrypto(void)
551{ 551{
552 memset(crypto_connections, 0 ,sizeof(crypto_connections)); 552 memset(crypto_connections, 0 ,sizeof(crypto_connections));
553 memset(incoming_connections, -1 ,sizeof(incoming_connections)); 553 memset(incoming_connections, -1 ,sizeof(incoming_connections));
@@ -556,7 +556,7 @@ void initNetCrypto()
556 crypto_connections[i].number = ~0; 556 crypto_connections[i].number = ~0;
557} 557}
558 558
559static void killTimedout() 559static void killTimedout(void)
560{ 560{
561 uint32_t i; 561 uint32_t i;
562 for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { 562 for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) {
@@ -570,7 +570,7 @@ static void killTimedout()
570} 570}
571 571
572/* main loop */ 572/* main loop */
573void doNetCrypto() 573void doNetCrypto(void)
574{ 574{
575 /* TODO:check if friend requests were sent correctly 575 /* TODO:check if friend requests were sent correctly
576 handle new incoming connections 576 handle new incoming connections