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