summaryrefslogtreecommitdiff
path: root/core/net_crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/net_crypto.h')
-rw-r--r--core/net_crypto.h108
1 files changed, 54 insertions, 54 deletions
diff --git a/core/net_crypto.h b/core/net_crypto.h
index df2cb9ca..0bf21f60 100644
--- a/core/net_crypto.h
+++ b/core/net_crypto.h
@@ -26,111 +26,111 @@
26 26
27#include "Lossless_UDP.h" 27#include "Lossless_UDP.h"
28 28
29//Our public key. 29/* Our public key. */
30extern uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; 30extern uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
31extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; 31extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
32 32
33#define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) 33#define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
34 34
35//encrypts plain of length length to encrypted of length + 16 using the 35/* encrypts plain of length length to encrypted of length + 16 using the
36//public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce 36 public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce
37//return -1 if there was a problem. 37 return -1 if there was a problem.
38//return length of encrypted data if everything was fine. 38 return length of encrypted data if everything was fine. */
39int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, 39int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce,
40 uint8_t * plain, uint32_t length, uint8_t * encrypted); 40 uint8_t * plain, uint32_t length, uint8_t * encrypted);
41 41
42 42
43//decrypts encrypted of length length to plain of length length - 16 using the 43/* decrypts encrypted of length length to plain of length length - 16 using the
44//public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce 44 public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce
45//return -1 if there was a problem(decryption failed) 45 return -1 if there was a problem(decryption failed)
46//return length of plain data if everything was fine. 46 return length of plain data if everything was fine. */
47int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, 47int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce,
48 uint8_t * encrypted, uint32_t length, uint8_t * plain); 48 uint8_t * encrypted, uint32_t length, uint8_t * plain);
49 49
50 50
51//fill the given nonce with random bytes. 51/* fill the given nonce with random bytes. */
52void random_nonce(uint8_t * nonce); 52void random_nonce(uint8_t * nonce);
53 53
54 54
55//return 0 if there is no received data in the buffer 55/* return 0 if there is no received data in the buffer
56//return -1 if the packet was discarded. 56 return -1 if the packet was discarded.
57//return length of received data if successful 57 return length of received data if successful */
58int read_cryptpacket(int crypt_connection_id, uint8_t * data); 58int read_cryptpacket(int crypt_connection_id, uint8_t * data);
59 59
60 60
61//return 0 if data could not be put in packet queue 61/* return 0 if data could not be put in packet queue
62//return 1 if data was put into the queue 62 return 1 if data was put into the queue */
63int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length); 63int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length);
64 64
65//send a friend request to peer with public_key and ip_port. 65/* send a friend request to peer with public_key and ip_port.
66//Data represents the data we send with the friends request. 66 Data represents the data we send with the friends request.
67//returns -1 on failure 67 returns -1 on failure
68//returns a positive friend request id that can be used later to see if it was sent correctly on success. 68 returns a positive friend request id that can be used later to see if it was sent correctly on success. */
69int send_friendrequest(uint8_t * public_key, IP_Port ip_port, uint8_t * data, uint32_t length); 69int send_friendrequest(uint8_t * public_key, IP_Port ip_port, uint8_t * data, uint32_t length);
70 70
71 71
72//return -1 if failure 72/* return -1 if failure
73//return 0 if connection is still trying to send the request. 73 return 0 if connection is still trying to send the request.
74//return 1 if sent correctly 74 return 1 if sent correctly
75//return 2 if connection timed out 75 return 2 if connection timed out */
76int check_friendrequest(int friend_request); 76int check_friendrequest(int friend_request);
77 77
78 78
79//puts the public key of the friend if public_key, the data from the request 79/* puts the public key of the friend if public_key, the data from the request
80//in data if a friend request was sent to us and returns the length of the data. 80 in data if a friend request was sent to us and returns the length of the data.
81//return -1 if no valid friend requests. 81 return -1 if no valid friend requests. */
82int handle_friendrequest(uint8_t * public_key, uint8_t * data); 82int handle_friendrequest(uint8_t * public_key, uint8_t * data);
83 83
84 84
85//Start a secure connection with other peer who has public_key and ip_port 85/* Start a secure connection with other peer who has public_key and ip_port
86//returns -1 if failure 86 returns -1 if failure
87//returns crypt_connection_id of the initialized connection if everything went well. 87 returns crypt_connection_id of the initialized connection if everything went well. */
88int crypto_connect(uint8_t * public_key, IP_Port ip_port); 88int crypto_connect(uint8_t * public_key, IP_Port ip_port);
89 89
90 90
91//kill a crypto connection 91/* kill a crypto connection
92//return 0 if killed successfully 92 return 0 if killed successfully
93//return 1 if there was a problem. 93 return 1 if there was a problem. */
94int crypto_kill(int crypt_connection_id); 94int crypto_kill(int crypt_connection_id);
95 95
96//handle an incoming connection 96/* handle an incoming connection
97//return -1 if no crypto inbound connection 97 return -1 if no crypto inbound connection
98//return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection 98 return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection
99//Put the public key of the peer in public_key, the secret_nonce from the handshake into secret_nonce 99 Put the public key of the peer in public_key, the secret_nonce from the handshake into secret_nonce
100//and the session public key for the connection in session_key 100 and the session public key for the connection in session_key
101//to accept it see: accept_crypto_inbound(...) 101 to accept it see: accept_crypto_inbound(...)
102//to refuse it just call kill_connection(...) on the connection id 102 to refuse it just call kill_connection(...) on the connection id */
103int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key); 103int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key);
104 104
105 105
106//accept an incoming connection using the parameters provided by crypto_inbound 106/* accept an incoming connection using the parameters provided by crypto_inbound
107//return -1 if not successful 107 return -1 if not successful
108//returns the crypt_connection_id if successful 108 returns the crypt_connection_id if successful */
109int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key); 109int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key);
110 110
111//return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet 111/* return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet
112//(we have received a handshake but no empty data packet), 3 if the connection is established. 112 (we have received a handshake but no empty data packet), 3 if the connection is established.
113//4 if the connection is timed out and waiting to be killed 113 4 if the connection is timed out and waiting to be killed */
114int is_cryptoconnected(int crypt_connection_id); 114int is_cryptoconnected(int crypt_connection_id);
115 115
116 116
117//Generate our public and private keys 117/* Generate our public and private keys
118//Only call this function the first time the program starts. 118 Only call this function the first time the program starts. */
119void new_keys(); 119void new_keys();
120 120
121//save the public and private keys to the keys array 121/* save the public and private keys to the keys array
122//Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES 122 Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */
123void save_keys(uint8_t * keys); 123void save_keys(uint8_t * keys);
124 124
125//load the public and private keys from the keys array 125/* load the public and private keys from the keys array
126//Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES 126 Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */
127void load_keys(uint8_t * keys); 127void load_keys(uint8_t * keys);
128 128
129//run this to (re)initialize net_crypto 129/* run this to (re)initialize net_crypto
130//sets all the global connection variables to their default values. 130 sets all the global connection variables to their default values. */
131void initNetCrypto(); 131void initNetCrypto();
132 132
133//main loop 133/* main loop */
134void doNetCrypto(); 134void doNetCrypto();
135 135
136 136