diff options
author | Marc Schütz <schuetzm@gmx.net> | 2014-06-10 18:38:43 +0200 |
---|---|---|
committer | Marc Schütz <schuetzm@gmx.net> | 2014-06-10 18:38:43 +0200 |
commit | 55d986270b3af91019dabfb2169817cd894d84fe (patch) | |
tree | 0757f88a78e51dba49aab641dc74ba0892253d96 /toxcore/crypto_core.c | |
parent | 9e028b243a8eff03518e048b25a169166441df34 (diff) |
Const correctness in toxcore/crypto_core.c
Diffstat (limited to 'toxcore/crypto_core.c')
-rw-r--r-- | toxcore/crypto_core.c | 24 |
1 files changed, 12 insertions, 12 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. */ |
36 | int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length) | 36 | int 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 | */ |
74 | void encrypt_precompute(uint8_t *public_key, uint8_t *secret_key, uint8_t *enc_key) | 74 | void 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 | ||
79 | int encrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *plain, uint32_t length, uint8_t *encrypted) | 79 | int 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 | ||
98 | int decrypt_data_symmetric(uint8_t *secret_key, uint8_t *nonce, uint8_t *encrypted, uint32_t length, uint8_t *plain) | 98 | int 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 | ||
116 | int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, | 116 | int 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 | ||
124 | int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, | 124 | int 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 | */ |
205 | int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key, | 205 | int 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 | */ |
237 | int handle_request(uint8_t *self_public_key, uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, | 237 | int 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) { |