summaryrefslogtreecommitdiff
path: root/auto_tests/crypto_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-05 16:10:48 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-06 11:54:37 +0100
commitad2656051697899e960694bb68ac104fcc5e92f1 (patch)
tree7e69fcd03db88b3839ee523f5d1b51ef9a38c372 /auto_tests/crypto_test.c
parent4e6c86d1cb228308678f89ff6e4e09b3f46347aa (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/crypto_test.c')
-rw-r--r--auto_tests/crypto_test.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c
index 30cc2178..ff8ab41d 100644
--- a/auto_tests/crypto_test.c
+++ b/auto_tests/crypto_test.c
@@ -12,7 +12,7 @@
12 12
13#include "helpers.h" 13#include "helpers.h"
14 14
15void rand_bytes(uint8_t *b, size_t blen) 15static void rand_bytes(uint8_t *b, size_t blen)
16{ 16{
17 size_t i; 17 size_t i;
18 18
@@ -23,27 +23,27 @@ void rand_bytes(uint8_t *b, size_t blen)
23 23
24// These test vectors are from libsodium's test suite 24// These test vectors are from libsodium's test suite
25 25
26unsigned char alicesk[32] = { 26static const unsigned char alicesk[32] = {
27 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 27 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d,
28 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45, 28 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45,
29 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a, 29 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a,
30 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a 30 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a
31}; 31};
32 32
33unsigned char bobpk[32] = { 33static const unsigned char bobpk[32] = {
34 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, 34 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4,
35 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, 35 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37,
36 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d, 36 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d,
37 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f 37 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f
38}; 38};
39 39
40unsigned char nonce[24] = { 40static const unsigned char nonce[24] = {
41 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73, 41 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
42 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6, 42 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
43 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 43 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
44}; 44};
45 45
46unsigned char test_m[131] = { 46static const unsigned char test_m[131] = {
47 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5, 47 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5,
48 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b, 48 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b,
49 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4, 49 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4,
@@ -63,7 +63,7 @@ unsigned char test_m[131] = {
63 0x5e, 0x07, 0x05 63 0x5e, 0x07, 0x05
64}; 64};
65 65
66unsigned char test_c[147] = { 66static const unsigned char test_c[147] = {
67 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, 67 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
68 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, 68 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9,
69 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, 69 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73,
@@ -271,7 +271,7 @@ START_TEST(test_large_data_symmetric)
271} 271}
272END_TEST 272END_TEST
273 273
274void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) 274static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
275{ 275{
276 uint32_t num1, num2; 276 uint32_t num1, num2;
277 memcpy(&num1, nonce + (crypto_box_NONCEBYTES - sizeof(num1)), sizeof(num1)); 277 memcpy(&num1, nonce + (crypto_box_NONCEBYTES - sizeof(num1)), sizeof(num1));
@@ -323,7 +323,7 @@ START_TEST(test_increment_nonce)
323} 323}
324END_TEST 324END_TEST
325 325
326Suite *crypto_suite(void) 326static Suite *crypto_suite(void)
327{ 327{
328 Suite *s = suite_create("Crypto"); 328 Suite *s = suite_create("Crypto");
329 329