diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-16 13:11:09 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-16 13:11:09 -0400 |
commit | 88ff81d9def5efe69cbaf91aa41906177ba7dde9 (patch) | |
tree | cb9f149e438bcd1f18d8c1eb5d8be6b0a22f58a4 /core/net_crypto.h | |
parent | c5af8f44a9d040a0bbe0442ec074d9fc8562dd32 (diff) |
Passed everything through astyle.
Diffstat (limited to 'core/net_crypto.h')
-rw-r--r-- | core/net_crypto.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/core/net_crypto.h b/core/net_crypto.h index 570b9373..742d9fdc 100644 --- a/core/net_crypto.h +++ b/core/net_crypto.h | |||
@@ -38,14 +38,14 @@ extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | |||
38 | #define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) | 38 | #define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) |
39 | 39 | ||
40 | /* returns zero if the buffer contains only zeros */ | 40 | /* returns zero if the buffer contains only zeros */ |
41 | uint8_t crypto_iszero(uint8_t* buffer, uint32_t blen); | 41 | uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen); |
42 | 42 | ||
43 | /* encrypts plain of length length to encrypted of length + 16 using the | 43 | /* encrypts plain of length length to encrypted of length + 16 using the |
44 | public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce | 44 | public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce |
45 | return -1 if there was a problem. | 45 | return -1 if there was a problem. |
46 | return length of encrypted data if everything was fine. */ | 46 | return length of encrypted data if everything was fine. */ |
47 | int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, | 47 | int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, |
48 | uint8_t *plain, uint32_t length, uint8_t *encrypted); | 48 | uint8_t *plain, uint32_t length, uint8_t *encrypted); |
49 | 49 | ||
50 | 50 | ||
51 | /* decrypts encrypted of length length to plain of length length - 16 using the | 51 | /* decrypts encrypted of length length to plain of length length - 16 using the |
@@ -53,15 +53,15 @@ int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, | |||
53 | return -1 if there was a problem(decryption failed) | 53 | return -1 if there was a problem(decryption failed) |
54 | return length of plain data if everything was fine. */ | 54 | return length of plain data if everything was fine. */ |
55 | int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, | 55 | int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, |
56 | uint8_t *encrypted, uint32_t length, uint8_t *plain); | 56 | uint8_t *encrypted, uint32_t length, uint8_t *plain); |
57 | 57 | ||
58 | /* Fast encrypt/decrypt operations. Use if this is not a one-time communication. | 58 | /* Fast encrypt/decrypt operations. Use if this is not a one-time communication. |
59 | encrypt_precompute does the shared-key generation once so it does not have | 59 | encrypt_precompute does the shared-key generation once so it does not have |
60 | to be preformed on every encrypt/decrypt. */ | 60 | to be preformed on every encrypt/decrypt. */ |
61 | void encrypt_precompute(uint8_t *public_key, uint8_t *secret_key, uint8_t *enc_key); | 61 | void encrypt_precompute(uint8_t *public_key, uint8_t *secret_key, uint8_t *enc_key); |
62 | 62 | ||
63 | /* Fast encrypt. Depends on enc_key from encrypt_precompute. */ | 63 | /* Fast encrypt. Depends on enc_key from encrypt_precompute. */ |
64 | int encrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, | 64 | int encrypt_data_fast(uint8_t *enc_key, uint8_t *nonce, |
65 | uint8_t *plain, uint32_t length, uint8_t *encrypted); | 65 | uint8_t *plain, uint32_t length, uint8_t *encrypted); |
66 | 66 | ||
67 | /* Fast decrypt. Depends on enc_ley from encrypt_precompute. */ | 67 | /* Fast decrypt. Depends on enc_ley from encrypt_precompute. */ |
@@ -87,10 +87,10 @@ int write_cryptpacket(int crypt_connection_id, uint8_t *data, uint32_t length); | |||
87 | request_id is the id of the request (32 = friend request, 254 = ping request) | 87 | request_id is the id of the request (32 = friend request, 254 = ping request) |
88 | returns -1 on failure | 88 | returns -1 on failure |
89 | returns the length of the created packet on success */ | 89 | returns the length of the created packet on success */ |
90 | int create_request(uint8_t *packet, uint8_t * public_key, uint8_t *data, uint32_t length, uint8_t request_id); | 90 | int create_request(uint8_t *packet, uint8_t *public_key, uint8_t *data, uint32_t length, uint8_t request_id); |
91 | 91 | ||
92 | 92 | ||
93 | typedef int (*cryptopacket_handler_callback)(IP_Port ip_port, uint8_t * source_pubkey, uint8_t *data, uint32_t len); | 93 | typedef int (*cryptopacket_handler_callback)(IP_Port ip_port, uint8_t *source_pubkey, uint8_t *data, uint32_t len); |
94 | /* Function to call when request beginning with byte is received */ | 94 | /* Function to call when request beginning with byte is received */ |
95 | void cryptopacket_registerhandler(uint8_t byte, cryptopacket_handler_callback cb); | 95 | void cryptopacket_registerhandler(uint8_t byte, cryptopacket_handler_callback cb); |
96 | 96 | ||
@@ -111,12 +111,12 @@ int crypto_kill(int crypt_connection_id); | |||
111 | and the session public key for the connection in session_key | 111 | and the session public key for the connection in session_key |
112 | to accept it see: accept_crypto_inbound(...) | 112 | to accept it see: accept_crypto_inbound(...) |
113 | to refuse it just call kill_connection(...) on the connection id */ | 113 | to refuse it just call kill_connection(...) on the connection id */ |
114 | int crypto_inbound(uint8_t *public_key, uint8_t * secret_nonce, uint8_t *session_key); | 114 | int crypto_inbound(uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key); |
115 | 115 | ||
116 | /* accept an incoming connection using the parameters provided by crypto_inbound | 116 | /* accept an incoming connection using the parameters provided by crypto_inbound |
117 | return -1 if not successful | 117 | return -1 if not successful |
118 | returns the crypt_connection_id if successful */ | 118 | returns the crypt_connection_id if successful */ |
119 | int accept_crypto_inbound(int connection_id, uint8_t *public_key, uint8_t * secret_nonce, uint8_t *session_key); | 119 | int accept_crypto_inbound(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key); |
120 | 120 | ||
121 | /* return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet | 121 | /* return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet |
122 | (we have received a handshake but no empty data packet), 3 if the connection is established. | 122 | (we have received a handshake but no empty data packet), 3 if the connection is established. |
@@ -130,11 +130,11 @@ void new_keys(void); | |||
130 | 130 | ||
131 | /* save the public and private keys to the keys array | 131 | /* save the public and private keys to the keys array |
132 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ | 132 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ |
133 | void save_keys(uint8_t * keys); | 133 | void save_keys(uint8_t *keys); |
134 | 134 | ||
135 | /* load the public and private keys from the keys array | 135 | /* load the public and private keys from the keys array |
136 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ | 136 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ |
137 | void load_keys(uint8_t * keys); | 137 | void load_keys(uint8_t *keys); |
138 | 138 | ||
139 | /* run this to (re)initialize net_crypto | 139 | /* run this to (re)initialize net_crypto |
140 | sets all the global connection variables to their default values. */ | 140 | sets all the global connection variables to their default values. */ |