summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-09 15:02:45 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-09 19:30:50 +0100
commit406d292107f66a06f8db695645345b13ae8acc8b (patch)
tree6ef7cf318f973b5026637815b7f56311be88e376
parent769db9dd9a73208d32c22c52c8eef7446e026f81 (diff)
Minor cleanups: header reordering, adding {}.
I hadn't done this for the "fun" code, yet. Also, we should include system headers after our own headers. "In general, a module should be implemented by one or more .cpp files. Each of these .cpp files should include the header that defines their interface first. This ensures that all of the dependences of the module header have been properly added to the module header itself, and are not implicit. System headers should be included after user headers for a translation unit." -- http://llvm.org/docs/CodingStandards.html#a-public-header-file-is-a-module
-rw-r--r--auto_tests/crypto_test.c2
-rw-r--r--auto_tests/messenger_test.c4
-rw-r--r--other/bootstrap_daemon/src/config.c2
-rw-r--r--other/fun/cracker.c13
-rw-r--r--other/fun/sign.c17
-rw-r--r--toxav/bwcontroller.c2
-rw-r--r--toxcore/assoc.c2
-rw-r--r--toxcore/net_crypto.h2
8 files changed, 26 insertions, 18 deletions
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c
index ff8ab41d..f39ee8d4 100644
--- a/auto_tests/crypto_test.c
+++ b/auto_tests/crypto_test.c
@@ -2,13 +2,13 @@
2#include "config.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include "../toxcore/net_crypto.h"
5#include <check.h> 6#include <check.h>
6#include <stdint.h> 7#include <stdint.h>
7#include <stdlib.h> 8#include <stdlib.h>
8#include <string.h> 9#include <string.h>
9#include <sys/types.h> 10#include <sys/types.h>
10#include <time.h> 11#include <time.h>
11#include "../toxcore/net_crypto.h"
12 12
13#include "helpers.h" 13#include "helpers.h"
14 14
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index f7dc92d5..8f904ed1 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -14,12 +14,12 @@
14#include "config.h" 14#include "config.h"
15#endif 15#endif
16 16
17#include "../testing/misc_tools.c" // hex_string_to_bin
18#include "../toxcore/Messenger.h"
17#include <check.h> 19#include <check.h>
18#include <stdint.h> 20#include <stdint.h>
19#include <string.h> 21#include <string.h>
20#include <sys/types.h> 22#include <sys/types.h>
21#include "../testing/misc_tools.c" // hex_string_to_bin
22#include "../toxcore/Messenger.h"
23 23
24#include "helpers.h" 24#include "helpers.h"
25 25
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c
index a0c6045d..27d1364a 100644
--- a/other/bootstrap_daemon/src/config.c
+++ b/other/bootstrap_daemon/src/config.c
@@ -403,7 +403,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
403 goto next; 403 goto next;
404 } 404 }
405 405
406 uint8_t *bs_public_key_bin = hex_string_to_bin((const char *)bs_public_key); 406 uint8_t *bs_public_key_bin = hex_string_to_bin(bs_public_key);
407 const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), 407 const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port),
408 bs_public_key_bin); 408 bs_public_key_bin);
409 free(bs_public_key_bin); 409 free(bs_public_key_bin);
diff --git a/other/fun/cracker.c b/other/fun/cracker.c
index 843b9359..7b020bb7 100644
--- a/other/fun/cracker.c
+++ b/other/fun/cracker.c
@@ -13,8 +13,8 @@
13#include <time.h> 13#include <time.h>
14 14
15/* NaCl includes*/ 15/* NaCl includes*/
16#include <crypto_scalarmult_curve25519.h> 16#include <sodium/crypto_scalarmult_curve25519.h>
17#include <randombytes.h> 17#include <sodium/randombytes.h>
18 18
19/* Sodium include*/ 19/* Sodium include*/
20//#include <sodium.h> 20//#include <sodium.h>
@@ -42,8 +42,9 @@ int main(int argc, char *argv[])
42 unsigned char *key = hex_string_to_bin(argv[1]); 42 unsigned char *key = hex_string_to_bin(argv[1]);
43 uint8_t pub_key[32], priv_key[32], c_key[32]; 43 uint8_t pub_key[32], priv_key[32], c_key[32];
44 44
45 if (len > 32) 45 if (len > 32) {
46 len = 32; 46 len = 32;
47 }
47 48
48 memcpy(c_key, key, len); 49 memcpy(c_key, key, len);
49 free(key); 50 free(key);
@@ -53,14 +54,16 @@ int main(int argc, char *argv[])
53 crypto_scalarmult_curve25519_base(pub_key, priv_key); 54 crypto_scalarmult_curve25519_base(pub_key, priv_key);
54 uint32_t i; 55 uint32_t i;
55 56
56 if (memcmp(c_key, pub_key, len) == 0) 57 if (memcmp(c_key, pub_key, len) == 0) {
57 break; 58 break;
59 }
58 60
59 for (i = 32; i != 0; --i) { 61 for (i = 32; i != 0; --i) {
60 priv_key[i - 1] += 1; 62 priv_key[i - 1] += 1;
61 63
62 if (priv_key[i - 1] != 0) 64 if (priv_key[i - 1] != 0) {
63 break; 65 break;
66 }
64 } 67 }
65 68
66 ++num_tries; 69 ++num_tries;
diff --git a/other/fun/sign.c b/other/fun/sign.c
index 56a9d1e2..0cd8f38e 100644
--- a/other/fun/sign.c
+++ b/other/fun/sign.c
@@ -15,9 +15,9 @@
15 * 15 *
16 * NOTE: The signature is appended to the end of the file. 16 * NOTE: The signature is appended to the end of the file.
17 */ 17 */
18#include "../../testing/misc_tools.c" // hex_string_to_bin
18#include <sodium.h> 19#include <sodium.h>
19#include <string.h> 20#include <string.h>
20#include "../../testing/misc_tools.c" // hex_string_to_bin
21 21
22int load_file(char *filename, char **result) 22int load_file(char *filename, char **result)
23{ 23{
@@ -73,26 +73,30 @@ int main(int argc, char *argv[])
73 char *data; 73 char *data;
74 int size = load_file(argv[3], &data); 74 int size = load_file(argv[3], &data);
75 75
76 if (size < 0) 76 if (size < 0) {
77 goto fail; 77 goto fail;
78 }
78 79
79 unsigned long long smlen; 80 unsigned long long smlen;
80 char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); 81 char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2);
81 crypto_sign_ed25519(sm, &smlen, data, size, secret_key); 82 crypto_sign_ed25519(sm, &smlen, data, size, secret_key);
82 free(secret_key); 83 free(secret_key);
83 84
84 if (smlen - size != crypto_sign_ed25519_BYTES) 85 if (smlen - size != crypto_sign_ed25519_BYTES) {
85 goto fail; 86 goto fail;
87 }
86 88
87 FILE *f = fopen(argv[4], "wb"); 89 FILE *f = fopen(argv[4], "wb");
88 90
89 if (f == NULL) 91 if (f == NULL) {
90 goto fail; 92 goto fail;
93 }
91 94
92 memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file. 95 memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file.
93 96
94 if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) 97 if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) {
95 goto fail; 98 goto fail;
99 }
96 100
97 fclose(f); 101 fclose(f);
98 printf("Signed successfully.\n"); 102 printf("Signed successfully.\n");
@@ -103,8 +107,9 @@ int main(int argc, char *argv[])
103 char *data; 107 char *data;
104 int size = load_file(argv[3], &data); 108 int size = load_file(argv[3], &data);
105 109
106 if (size < 0) 110 if (size < 0) {
107 goto fail; 111 goto fail;
112 }
108 113
109 char *signe = malloc(size + crypto_sign_ed25519_BYTES); 114 char *signe = malloc(size + crypto_sign_ed25519_BYTES);
110 memcpy(signe, data + size - crypto_sign_ed25519_BYTES, 115 memcpy(signe, data + size - crypto_sign_ed25519_BYTES,
diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c
index 34d97408..49a2d9e1 100644
--- a/toxav/bwcontroller.c
+++ b/toxav/bwcontroller.c
@@ -23,10 +23,10 @@
23#include "config.h" 23#include "config.h"
24#endif /* HAVE_CONFIG_H */ 24#endif /* HAVE_CONFIG_H */
25 25
26#include <assert.h>
27#include "../toxcore/logger.h" 26#include "../toxcore/logger.h"
28#include "../toxcore/util.h" 27#include "../toxcore/util.h"
29#include "bwcontroller.h" 28#include "bwcontroller.h"
29#include <assert.h>
30 30
31#define BWC_PACKET_ID 196 31#define BWC_PACKET_ID 196
32#define BWC_SEND_INTERVAL_MS 1000 32#define BWC_SEND_INTERVAL_MS 1000
diff --git a/toxcore/assoc.c b/toxcore/assoc.c
index d99786b0..0a3845bc 100644
--- a/toxcore/assoc.c
+++ b/toxcore/assoc.c
@@ -10,8 +10,8 @@
10 10
11#include "LAN_discovery.h" 11#include "LAN_discovery.h"
12 12
13#include <assert.h>
14#include "util.h" 13#include "util.h"
14#include <assert.h>
15 15
16/* 16/*
17 * BASIC OVERVIEW: 17 * BASIC OVERVIEW:
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index c42463fc..c5eb3ecb 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -24,11 +24,11 @@
24#ifndef NET_CRYPTO_H 24#ifndef NET_CRYPTO_H
25#define NET_CRYPTO_H 25#define NET_CRYPTO_H
26 26
27#include <pthread.h>
28#include "DHT.h" 27#include "DHT.h"
29#include "LAN_discovery.h" 28#include "LAN_discovery.h"
30#include "TCP_connection.h" 29#include "TCP_connection.h"
31#include "logger.h" 30#include "logger.h"
31#include <pthread.h>
32 32
33#define CRYPTO_CONN_NO_CONNECTION 0 33#define CRYPTO_CONN_NO_CONNECTION 0
34#define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets 34#define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets