diff options
author | Andrew <AndehMor@gmail.com> | 2013-07-20 11:02:43 -0400 |
---|---|---|
committer | Andrew <AndehMor@gmail.com> | 2013-07-20 11:02:43 -0400 |
commit | 9616cc6a89247e0b13eb575f070467ba72a2024c (patch) | |
tree | 26f6d2818f60bdc69f7dfce36d248d6f460fc1e7 /core/net_crypto.c | |
parent | 5101ef756a18baf5d7e794d15577fa73ef2a18fa (diff) |
More changes made to comments, as requested by jvrv
Diffstat (limited to 'core/net_crypto.c')
-rw-r--r-- | core/net_crypto.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c index c819c8c4..b3c752e0 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c | |||
@@ -39,11 +39,11 @@ typedef struct | |||
39 | uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* nonce of received packets */ | 39 | uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* nonce of received packets */ |
40 | uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* nonce of sent packets. */ | 40 | uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* nonce of sent packets. */ |
41 | uint8_t sessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* our public key for this session. */ | 41 | uint8_t sessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* our public key for this session. */ |
42 | uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES];our private key for this session. | 42 | uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES]; /* our private key for this session. */ |
43 | uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */ | 43 | uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */ |
44 | uint8_t status;/* 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet | 44 | uint8_t status; /* 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet |
45 | (we have received a handshake but no empty data packet), 3 if the connection is established. | 45 | (we have received a handshake but no empty data packet), 3 if the connection is established. |
46 | 4 if the connection is timed out. */ | 46 | 4 if the connection is timed out. */ |
47 | uint16_t number; /* Lossless_UDP connection number corresponding to this connection. */ | 47 | uint16_t number; /* Lossless_UDP connection number corresponding to this connection. */ |
48 | 48 | ||
49 | }Crypto_Connection; | 49 | }Crypto_Connection; |
@@ -65,7 +65,7 @@ static int incoming_connections[MAX_INCOMING]; | |||
65 | /* encrypts plain of length length to encrypted of length + 16 using the | 65 | /* encrypts plain of length length to encrypted of length + 16 using the |
66 | public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce | 66 | public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce |
67 | return -1 if there was a problem. | 67 | return -1 if there was a problem. |
68 | return length of encrypted data if everything was fine. */ | 68 | return length of encrypted data if everything was fine. */ |
69 | int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | 69 | int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, |
70 | uint8_t * plain, uint32_t length, uint8_t * encrypted) | 70 | uint8_t * plain, uint32_t length, uint8_t * encrypted) |
71 | { | 71 | { |
@@ -128,9 +128,9 @@ int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | |||
128 | void increment_nonce(uint8_t * nonce) | 128 | void increment_nonce(uint8_t * nonce) |
129 | { | 129 | { |
130 | uint32_t i; | 130 | uint32_t i; |
131 | for(i = 0; i < crypto_box_NONCEBYTES; ++i) | 131 | for(i = 0; i < crypto_box_NONCEBYTES; i++) |
132 | { | 132 | { |
133 | ++nonce[i]; | 133 | nonce[i]++; |
134 | if(nonce[i] != 0) | 134 | if(nonce[i] != 0) |
135 | { | 135 | { |
136 | break; | 136 | break; |
@@ -143,7 +143,7 @@ void increment_nonce(uint8_t * nonce) | |||
143 | void random_nonce(uint8_t * nonce) | 143 | void random_nonce(uint8_t * nonce) |
144 | { | 144 | { |
145 | uint32_t i; | 145 | uint32_t i; |
146 | for(i = 0; i < crypto_box_NONCEBYTES; ++i) | 146 | for(i = 0; i < crypto_box_NONCEBYTES; i++) |
147 | { | 147 | { |
148 | nonce[i] = random_int() % 256; | 148 | nonce[i] = random_int() % 256; |
149 | } | 149 | } |
@@ -228,7 +228,7 @@ int send_friendrequest(uint8_t * public_key, IP_Port ip_port, uint8_t * data, ui | |||
228 | return -1; | 228 | return -1; |
229 | } | 229 | } |
230 | uint32_t i; | 230 | uint32_t i; |
231 | for(i = 0; i < MAX_FRIEND_REQUESTS; ++i) | 231 | for(i = 0; i < MAX_FRIEND_REQUESTS; i++) |
232 | { | 232 | { |
233 | if(outbound_friendrequests[i] == -1) | 233 | if(outbound_friendrequests[i] == -1) |
234 | { | 234 | { |
@@ -365,7 +365,7 @@ int handle_cryptohandshake(uint8_t * public_key, uint8_t * secret_nonce, | |||
365 | int handle_friendrequest(uint8_t * public_key, uint8_t * data) | 365 | int handle_friendrequest(uint8_t * public_key, uint8_t * data) |
366 | { | 366 | { |
367 | uint32_t i; | 367 | uint32_t i; |
368 | for(i = 0; i < MAX_INCOMING; ++i) | 368 | for(i = 0; i < MAX_INCOMING; i++) |
369 | { | 369 | { |
370 | if(incoming_connections[i] != -1) | 370 | if(incoming_connections[i] != -1) |
371 | { | 371 | { |
@@ -403,7 +403,7 @@ int handle_friendrequest(uint8_t * public_key, uint8_t * data) | |||
403 | int getcryptconnection_id(uint8_t * public_key) | 403 | int getcryptconnection_id(uint8_t * public_key) |
404 | { | 404 | { |
405 | uint32_t i; | 405 | uint32_t i; |
406 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) | 406 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
407 | { | 407 | { |
408 | if(crypto_connections[i].status > 0) | 408 | if(crypto_connections[i].status > 0) |
409 | { | 409 | { |
@@ -432,7 +432,7 @@ int crypto_connect(uint8_t * public_key, IP_Port ip_port) | |||
432 | return -1; | 432 | return -1; |
433 | } | 433 | } |
434 | } | 434 | } |
435 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) | 435 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
436 | { | 436 | { |
437 | if(crypto_connections[i].status == 0) | 437 | if(crypto_connections[i].status == 0) |
438 | { | 438 | { |
@@ -469,7 +469,7 @@ int crypto_connect(uint8_t * public_key, IP_Port ip_port) | |||
469 | int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key) | 469 | int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key) |
470 | { | 470 | { |
471 | uint32_t i; | 471 | uint32_t i; |
472 | for(i = 0; i < MAX_INCOMING; ++i) | 472 | for(i = 0; i < MAX_INCOMING; i++) |
473 | { | 473 | { |
474 | if(incoming_connections[i] != -1) | 474 | if(incoming_connections[i] != -1) |
475 | { | 475 | { |
@@ -530,7 +530,7 @@ int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * sec | |||
530 | { | 530 | { |
531 | return -1; | 531 | return -1; |
532 | }*/ | 532 | }*/ |
533 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) | 533 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
534 | { | 534 | { |
535 | if(crypto_connections[i].status == 0) | 535 | if(crypto_connections[i].status == 0) |
536 | { | 536 | { |
@@ -603,7 +603,7 @@ void load_keys(uint8_t * keys) | |||
603 | int new_incoming(int id) | 603 | int new_incoming(int id) |
604 | { | 604 | { |
605 | uint32_t i; | 605 | uint32_t i; |
606 | for(i = 0; i < MAX_INCOMING; ++i) | 606 | for(i = 0; i < MAX_INCOMING; i++) |
607 | { | 607 | { |
608 | if(incoming_connections[i] == -1) | 608 | if(incoming_connections[i] == -1) |
609 | { | 609 | { |
@@ -633,7 +633,7 @@ static void handle_incomings() | |||
633 | static void receive_crypto() | 633 | static void receive_crypto() |
634 | { | 634 | { |
635 | uint32_t i; | 635 | uint32_t i; |
636 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) | 636 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
637 | { | 637 | { |
638 | if(crypto_connections[i].status == 1) | 638 | if(crypto_connections[i].status == 1) |
639 | { | 639 | { |
@@ -717,7 +717,7 @@ void initNetCrypto() | |||
717 | memset(outbound_friendrequests, -1 ,sizeof(outbound_friendrequests)); | 717 | memset(outbound_friendrequests, -1 ,sizeof(outbound_friendrequests)); |
718 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); | 718 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); |
719 | uint32_t i; | 719 | uint32_t i; |
720 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) | 720 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
721 | { | 721 | { |
722 | crypto_connections[i].number = ~0; | 722 | crypto_connections[i].number = ~0; |
723 | } | 723 | } |