summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r--toxcore/net_crypto.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 0de66e98..38400ebc 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -27,6 +27,7 @@
27#include "Lossless_UDP.h" 27#include "Lossless_UDP.h"
28 28
29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */ 29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */
30#define CRYPTO_PACKET_HARDENING 48 /* Hardening crypto packet ID. */
30#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */ 31#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */
31#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2) 32#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2)
32 33
@@ -77,8 +78,6 @@ typedef struct {
77 78
78#include "DHT.h" 79#include "DHT.h"
79 80
80#define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
81
82/* return zero if the buffer contains only zeros. */ 81/* return zero if the buffer contains only zeros. */
83uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen); 82uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen);
84 83
@@ -114,10 +113,28 @@ int encrypt_data_fast(uint8_t *enc_key, uint8_t *nonce,
114int decrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, 113int decrypt_data_fast(uint8_t *enc_key, uint8_t *nonce,
115 uint8_t *encrypted, uint32_t length, uint8_t *plain); 114 uint8_t *encrypted, uint32_t length, uint8_t *plain);
116 115
116/* Encrypts plain of length length to encrypted of length + 16 using a
117 * secret key crypto_secretbox_KEYBYTES big and a 24 byte nonce.
118 *
119 * return -1 if there was a problem.
120 * return length of encrypted data if everything was fine.
121 */
122int encrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *plain, uint32_t length, uint8_t *encrypted);
123
124/* Decrypts encrypted of length length to plain of length length - 16 using a
125 * secret key crypto_secretbox_KEYBYTES big and a 24 byte nonce.
126 *
127 * return -1 if there was a problem (decryption failed).
128 * return length of plain data if everything was fine.
129 */
130int decrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *encrypted, uint32_t length, uint8_t *plain);
117 131
118/* Fill the given nonce with random bytes. */ 132/* Fill the given nonce with random bytes. */
119void random_nonce(uint8_t *nonce); 133void random_nonce(uint8_t *nonce);
120 134
135/* Fill a key crypto_secretbox_KEYBYTES big with random bytes */
136void new_symmetric_key(uint8_t *key);
137
121/*Gives a nonce guaranteed to be different from previous ones.*/ 138/*Gives a nonce guaranteed to be different from previous ones.*/
122void new_nonce(uint8_t *nonce); 139void new_nonce(uint8_t *nonce);
123 140