summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorMarc Schütz <schuetzm@gmx.net>2014-06-10 18:38:43 +0200
committerMarc Schütz <schuetzm@gmx.net>2014-06-10 18:38:43 +0200
commit55d986270b3af91019dabfb2169817cd894d84fe (patch)
tree0757f88a78e51dba49aab641dc74ba0892253d96 /toxcore
parent9e028b243a8eff03518e048b25a169166441df34 (diff)
Const correctness in toxcore/crypto_core.c
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/crypto_core.c24
-rw-r--r--toxcore/crypto_core.h24
2 files changed, 24 insertions, 24 deletions
diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c
index 6e92f5b6..50b217a0 100644
--- a/toxcore/crypto_core.c
+++ b/toxcore/crypto_core.c
@@ -33,7 +33,7 @@
33/* Use this instead of memcmp; not vulnerable to timing attacks. 33/* Use this instead of memcmp; not vulnerable to timing attacks.
34 returns 0 if both mem locations of length are equal, 34 returns 0 if both mem locations of length are equal,
35 return -1 if they are not. */ 35 return -1 if they are not. */
36int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length) 36int crypto_cmp(const uint8_t *mem1, const uint8_t *mem2, uint32_t length)
37{ 37{
38 if (length == 16) { 38 if (length == 16) {
39 return crypto_verify_16(mem1, mem2); 39 return crypto_verify_16(mem1, mem2);
@@ -71,12 +71,12 @@ uint64_t random_64b(void)
71 * encrypt/decrypt operation. 71 * encrypt/decrypt operation.
72 * enc_key has to be crypto_box_BEFORENMBYTES bytes long. 72 * enc_key has to be crypto_box_BEFORENMBYTES bytes long.
73 */ 73 */
74void encrypt_precompute(uint8_t *public_key, uint8_t *secret_key, uint8_t *enc_key) 74void encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key, uint8_t *enc_key)
75{ 75{
76 crypto_box_beforenm(enc_key, public_key, secret_key); 76 crypto_box_beforenm(enc_key, public_key, secret_key);
77} 77}
78 78
79int encrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *plain, uint32_t length, uint8_t *encrypted) 79int encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, const uint8_t *plain, uint32_t length, uint8_t *encrypted)
80{ 80{
81 if (length == 0) 81 if (length == 0)
82 return -1; 82 return -1;
@@ -95,7 +95,7 @@ int encrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *plain,
95 return length + crypto_box_MACBYTES; 95 return length + crypto_box_MACBYTES;
96} 96}
97 97
98int decrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *encrypted, uint32_t length, uint8_t *plain) 98int decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, const uint8_t *encrypted, uint32_t length, uint8_t *plain)
99{ 99{
100 if (length <= crypto_box_BOXZEROBYTES) 100 if (length <= crypto_box_BOXZEROBYTES)
101 return -1; 101 return -1;
@@ -113,16 +113,16 @@ int decrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *encrypt
113 return length - crypto_box_MACBYTES; 113 return length - crypto_box_MACBYTES;
114} 114}
115 115
116int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, 116int encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
117 uint8_t *plain, uint32_t length, uint8_t *encrypted) 117 const uint8_t *plain, uint32_t length, uint8_t *encrypted)
118{ 118{
119 uint8_t k[crypto_box_BEFORENMBYTES]; 119 uint8_t k[crypto_box_BEFORENMBYTES];
120 encrypt_precompute(public_key, secret_key, k); 120 encrypt_precompute(public_key, secret_key, k);
121 return encrypt_data_symmetric(k, nonce, plain, length, encrypted); 121 return encrypt_data_symmetric(k, nonce, plain, length, encrypted);
122} 122}
123 123
124int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, 124int decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
125 uint8_t *encrypted, uint32_t length, uint8_t *plain) 125 const uint8_t *encrypted, uint32_t length, uint8_t *plain)
126{ 126{
127 uint8_t k[crypto_box_BEFORENMBYTES]; 127 uint8_t k[crypto_box_BEFORENMBYTES];
128 encrypt_precompute(public_key, secret_key, k); 128 encrypt_precompute(public_key, secret_key, k);
@@ -202,8 +202,8 @@ void new_nonce(uint8_t *nonce)
202 * return -1 on failure. 202 * return -1 on failure.
203 * return the length of the created packet on success. 203 * return the length of the created packet on success.
204 */ 204 */
205int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key, 205int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_key, uint8_t *packet, const uint8_t *recv_public_key,
206 uint8_t *data, uint32_t length, uint8_t request_id) 206 const uint8_t *data, uint32_t length, uint8_t request_id)
207{ 207{
208 if (MAX_CRYPTO_REQUEST_SIZE < length + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + 208 if (MAX_CRYPTO_REQUEST_SIZE < length + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 +
209 crypto_box_MACBYTES) 209 crypto_box_MACBYTES)
@@ -234,8 +234,8 @@ int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *
234 * 234 *
235 * return -1 if not valid request. 235 * return -1 if not valid request.
236 */ 236 */
237int handle_request(uint8_t *self_public_key, uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, 237int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
238 uint8_t *request_id, uint8_t *packet, uint16_t length) 238 uint8_t *request_id, const uint8_t *packet, uint16_t length)
239{ 239{
240 if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES && 240 if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES &&
241 length <= MAX_CRYPTO_REQUEST_SIZE) { 241 length <= MAX_CRYPTO_REQUEST_SIZE) {
diff --git a/toxcore/crypto_core.h b/toxcore/crypto_core.h
index 6b69f917..578bd54a 100644
--- a/toxcore/crypto_core.h
+++ b/toxcore/crypto_core.h
@@ -43,7 +43,7 @@
43/* Use this instead of memcmp; not vulnerable to timing attacks. 43/* Use this instead of memcmp; not vulnerable to timing attacks.
44 returns 0 if both mem locations of length are equal, 44 returns 0 if both mem locations of length are equal,
45 return -1 if they are not. */ 45 return -1 if they are not. */
46int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length); 46int crypto_cmp(const uint8_t *mem1, const uint8_t *mem2, uint32_t length);
47 47
48/* return a random number. 48/* return a random number.
49 * 49 *
@@ -60,8 +60,8 @@ uint64_t random_64b(void);
60 * return -1 if there was a problem. 60 * return -1 if there was a problem.
61 * return length of encrypted data if everything was fine. 61 * return length of encrypted data if everything was fine.
62 */ 62 */
63int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, 63int encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
64 uint8_t *plain, uint32_t length, uint8_t *encrypted); 64 const uint8_t *plain, uint32_t length, uint8_t *encrypted);
65 65
66 66
67/* Decrypts encrypted of length length to plain of length length - 16 using the 67/* Decrypts encrypted of length length to plain of length length - 16 using the
@@ -70,13 +70,13 @@ int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
70 * return -1 if there was a problem (decryption failed). 70 * return -1 if there was a problem (decryption failed).
71 * return length of plain data if everything was fine. 71 * return length of plain data if everything was fine.
72 */ 72 */
73int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, 73int decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
74 uint8_t *encrypted, uint32_t length, uint8_t *plain); 74 const uint8_t *encrypted, uint32_t length, uint8_t *plain);
75 75
76/* Fast encrypt/decrypt operations. Use if this is not a one-time communication. 76/* Fast encrypt/decrypt operations. Use if this is not a one-time communication.
77 encrypt_precompute does the shared-key generation once so it does not have 77 encrypt_precompute does the shared-key generation once so it does not have
78 to be preformed on every encrypt/decrypt. */ 78 to be preformed on every encrypt/decrypt. */
79void encrypt_precompute(uint8_t *public_key, uint8_t *secret_key, uint8_t *enc_key); 79void encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key, uint8_t *enc_key);
80 80
81/* Encrypts plain of length length to encrypted of length + 16 using a 81/* Encrypts plain of length length to encrypted of length + 16 using a
82 * secret key crypto_box_KEYBYTES big and a 24 byte nonce. 82 * secret key crypto_box_KEYBYTES big and a 24 byte nonce.
@@ -84,7 +84,7 @@ void encrypt_precompute(uint8_t *public_key, uint8_t *secret_key, uint8_t *enc_k
84 * return -1 if there was a problem. 84 * return -1 if there was a problem.
85 * return length of encrypted data if everything was fine. 85 * return length of encrypted data if everything was fine.
86 */ 86 */
87int encrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *plain, uint32_t length, uint8_t *encrypted); 87int encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, const uint8_t *plain, uint32_t length, uint8_t *encrypted);
88 88
89/* Decrypts encrypted of length length to plain of length length - 16 using a 89/* Decrypts encrypted of length length to plain of length length - 16 using a
90 * secret key crypto_box_KEYBYTES big and a 24 byte nonce. 90 * secret key crypto_box_KEYBYTES big and a 24 byte nonce.
@@ -92,7 +92,7 @@ int encrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *plain,
92 * return -1 if there was a problem (decryption failed). 92 * return -1 if there was a problem (decryption failed).
93 * return length of plain data if everything was fine. 93 * return length of plain data if everything was fine.
94 */ 94 */
95int decrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *encrypted, uint32_t length, uint8_t *plain); 95int decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, const uint8_t *encrypted, uint32_t length, uint8_t *plain);
96 96
97/* Increment the given nonce by 1. */ 97/* Increment the given nonce by 1. */
98void increment_nonce(uint8_t *nonce); 98void increment_nonce(uint8_t *nonce);
@@ -128,15 +128,15 @@ void new_nonce(uint8_t *nonce);
128 * return -1 on failure. 128 * return -1 on failure.
129 * return the length of the created packet on success. 129 * return the length of the created packet on success.
130 */ 130 */
131int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key, 131int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_key, uint8_t *packet, const uint8_t *recv_public_key,
132 uint8_t *data, uint32_t length, uint8_t request_id); 132 const uint8_t *data, uint32_t length, uint8_t request_id);
133 133
134/* puts the senders public key in the request in public_key, the data from the request 134/* puts the senders public key in the request in public_key, the data from the request
135 in data if a friend or ping request was sent to us and returns the length of the data. 135 in data if a friend or ping request was sent to us and returns the length of the data.
136 packet is the request packet and length is its length 136 packet is the request packet and length is its length
137 return -1 if not valid request. */ 137 return -1 if not valid request. */
138int handle_request(uint8_t *self_public_key, uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, 138int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
139 uint8_t *request_id, uint8_t *packet, uint16_t length); 139 uint8_t *request_id, const uint8_t *packet, uint16_t length);
140 140
141 141
142#endif 142#endif