diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-05 16:10:48 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-06 11:54:37 +0100 |
commit | ad2656051697899e960694bb68ac104fcc5e92f1 (patch) | |
tree | 7e69fcd03db88b3839ee523f5d1b51ef9a38c372 /auto_tests/encryptsave_test.c | |
parent | 4e6c86d1cb228308678f89ff6e4e09b3f46347aa (diff) |
Improve static and const correctness.
- Any non-externally-visible declarations should be `static`.
- Casting away the `const` qualifier from pointers-to-const is
dangerous. All but one instance of this are now correct. The one
instance where we can't keep `const` is one where toxav code actually
writes to a chunk of memory marked as `const`. This code also assumes
4 byte alignment of data packets. I don't know whether that is a valid
assumption, but it's likely unportable, and *not* obviously correct.
- Replaced empty parameter lists with `(void)` to avoid passing
parameters to it. Empty parameter lists are old style declarations for
unknown number and type of arguments.
- Commented out (as `#if DHT_HARDENING` block) the hardening code that
was never executed.
- Minor style fix: don't use `default` in enum-switches unless the number
of enumerators in the default case is very large. In this case, it was
2, so we want to list them both explicitly to be warned about missing
one if we add one in the future.
- Removed the only two function declarations from nTox.h and put them
into nTox.c. They are not used outside and nTox is not a library.
Diffstat (limited to 'auto_tests/encryptsave_test.c')
-rw-r--r-- | auto_tests/encryptsave_test.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 02a29016..f1e768d6 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -19,16 +19,16 @@ | |||
19 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" | 19 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | unsigned char salt[32] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; | 22 | static unsigned char salt[32] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; |
23 | unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8}; | 23 | static unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8}; |
24 | const char *pw = "hunter2"; | 24 | static const char *pw = "hunter2"; |
25 | unsigned int pwlen = 7; | 25 | static unsigned int pwlen = 7; |
26 | 26 | ||
27 | unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; | 27 | static unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; |
28 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat | 28 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat |
29 | 29 | ||
30 | /* cause I'm shameless */ | 30 | /* cause I'm shameless */ |
31 | void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 31 | static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
32 | { | 32 | { |
33 | if (*((uint32_t *)userdata) != 974536) { | 33 | if (*((uint32_t *)userdata) != 974536) { |
34 | return; | 34 | return; |
@@ -63,7 +63,7 @@ START_TEST(test_save_friend) | |||
63 | tox_callback_friend_request(tox2, accept_friend_request); | 63 | tox_callback_friend_request(tox2, accept_friend_request); |
64 | uint8_t address[TOX_ADDRESS_SIZE]; | 64 | uint8_t address[TOX_ADDRESS_SIZE]; |
65 | tox_self_get_address(tox2, address); | 65 | tox_self_get_address(tox2, address); |
66 | uint32_t test = tox_friend_add(tox1, address, (uint8_t *)"Gentoo", 7, 0); | 66 | uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)"Gentoo", 7, 0); |
67 | ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); | 67 | ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); |
68 | 68 | ||
69 | size_t size = tox_get_savedata_size(tox1); | 69 | size_t size = tox_get_savedata_size(tox1); |
@@ -186,7 +186,7 @@ START_TEST(test_keys) | |||
186 | } | 186 | } |
187 | END_TEST | 187 | END_TEST |
188 | 188 | ||
189 | Suite *encryptsave_suite(void) | 189 | static Suite *encryptsave_suite(void) |
190 | { | 190 | { |
191 | Suite *s = suite_create("encryptsave"); | 191 | Suite *s = suite_create("encryptsave"); |
192 | 192 | ||
@@ -212,4 +212,3 @@ int main(int argc, char *argv[]) | |||
212 | 212 | ||
213 | return number_failed; | 213 | return number_failed; |
214 | } | 214 | } |
215 | |||