ffi-tox 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ProjectTox-Core/AUTHORS +0 -0
- data/ProjectTox-Core/ChangeLog +0 -0
- data/ProjectTox-Core/INSTALL +370 -0
- data/ProjectTox-Core/INSTALL.md +455 -56
- data/ProjectTox-Core/Makefile.am +35 -0
- data/ProjectTox-Core/NEWS +0 -0
- data/ProjectTox-Core/README +43 -0
- data/ProjectTox-Core/README.md +34 -44
- data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
- data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
- data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
- data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
- data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
- data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
- data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
- data/ProjectTox-Core/auto_tests/helpers.h +15 -0
- data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
- data/ProjectTox-Core/auto_tests/network_test.c +171 -0
- data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
- data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
- data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
- data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
- data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
- data/ProjectTox-Core/autogen.sh +6 -0
- data/ProjectTox-Core/build/Makefile.am +14 -0
- data/ProjectTox-Core/configure.ac +694 -0
- data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
- data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
- data/ProjectTox-Core/dist-build/android-build.sh +59 -0
- data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
- data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
- data/ProjectTox-Core/docs/Group-Chats.md +71 -0
- data/ProjectTox-Core/docs/Hardening.txt +60 -0
- data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
- data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
- data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
- data/ProjectTox-Core/docs/TODO +62 -0
- data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
- data/ProjectTox-Core/docs/av_api.md +194 -0
- data/ProjectTox-Core/libtoxav.pc.in +11 -0
- data/ProjectTox-Core/libtoxcore.pc.in +11 -0
- data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
- data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
- data/ProjectTox-Core/m4/pkg.m4 +199 -0
- data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
- data/ProjectTox-Core/other/DHTnodes +3 -0
- data/ProjectTox-Core/other/Makefile.inc +20 -0
- data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
- data/ProjectTox-Core/other/tox.png +0 -0
- data/ProjectTox-Core/testing/DHT_test.c +170 -98
- data/ProjectTox-Core/testing/Makefile.inc +112 -0
- data/ProjectTox-Core/testing/Messenger_test.c +133 -69
- data/ProjectTox-Core/testing/dns3_test.c +115 -0
- data/ProjectTox-Core/testing/misc_tools.c +59 -13
- data/ProjectTox-Core/testing/nTox.c +1127 -264
- data/ProjectTox-Core/testing/nTox.h +10 -19
- data/ProjectTox-Core/testing/tox_shell.c +159 -0
- data/ProjectTox-Core/testing/tox_sync.c +299 -0
- data/ProjectTox-Core/tools/README +11 -0
- data/ProjectTox-Core/tools/astylerc +11 -0
- data/ProjectTox-Core/tools/pre-commit +17 -0
- data/ProjectTox-Core/toxav/Makefile.inc +36 -0
- data/ProjectTox-Core/toxav/codec.c +357 -0
- data/ProjectTox-Core/toxav/codec.h +116 -0
- data/ProjectTox-Core/toxav/msi.c +1949 -0
- data/ProjectTox-Core/toxav/msi.h +267 -0
- data/ProjectTox-Core/toxav/rtp.c +600 -0
- data/ProjectTox-Core/toxav/rtp.h +196 -0
- data/ProjectTox-Core/toxav/toxav.c +1148 -0
- data/ProjectTox-Core/toxav/toxav.h +389 -0
- data/ProjectTox-Core/toxcore/DHT.c +2521 -0
- data/ProjectTox-Core/toxcore/DHT.h +412 -0
- data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
- data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
- data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
- data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
- data/ProjectTox-Core/toxcore/Messenger.h +818 -0
- data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
- data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
- data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
- data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
- data/ProjectTox-Core/toxcore/assoc.c +1033 -0
- data/ProjectTox-Core/toxcore/assoc.h +104 -0
- data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
- data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
- data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
- data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
- data/ProjectTox-Core/toxcore/group_chats.c +837 -0
- data/ProjectTox-Core/toxcore/group_chats.h +199 -0
- data/ProjectTox-Core/toxcore/list.c +256 -0
- data/ProjectTox-Core/toxcore/list.h +85 -0
- data/ProjectTox-Core/toxcore/logger.c +153 -0
- data/ProjectTox-Core/toxcore/logger.h +84 -0
- data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
- data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
- data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
- data/ProjectTox-Core/toxcore/network.c +979 -0
- data/ProjectTox-Core/toxcore/network.h +367 -0
- data/ProjectTox-Core/toxcore/onion.c +540 -0
- data/ProjectTox-Core/toxcore/onion.h +150 -0
- data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
- data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
- data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
- data/ProjectTox-Core/toxcore/onion_client.h +253 -0
- data/ProjectTox-Core/toxcore/ping.c +346 -0
- data/ProjectTox-Core/toxcore/ping.h +47 -0
- data/ProjectTox-Core/toxcore/ping_array.c +162 -0
- data/ProjectTox-Core/toxcore/ping_array.h +75 -0
- data/ProjectTox-Core/toxcore/tox.c +940 -0
- data/ProjectTox-Core/toxcore/tox.h +734 -0
- data/ProjectTox-Core/toxcore/util.c +193 -0
- data/ProjectTox-Core/toxcore/util.h +63 -0
- data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
- data/ProjectTox-Core/toxdns/toxdns.c +238 -0
- data/ProjectTox-Core/toxdns/toxdns.h +88 -0
- data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
- data/interfaces/libtox.i +2 -6
- data/lib/ffi-tox/libtox.rb +406 -28
- metadata +124 -46
- data/ProjectTox-Core/CMakeLists.txt +0 -50
- data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
- data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
- data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
- data/ProjectTox-Core/core/CMakeLists.txt +0 -19
- data/ProjectTox-Core/core/DHT.c +0 -1104
- data/ProjectTox-Core/core/DHT.h +0 -111
- data/ProjectTox-Core/core/LAN_discovery.c +0 -79
- data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
- data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
- data/ProjectTox-Core/core/Messenger.c +0 -596
- data/ProjectTox-Core/core/Messenger.h +0 -165
- data/ProjectTox-Core/core/friend_requests.c +0 -131
- data/ProjectTox-Core/core/friend_requests.h +0 -51
- data/ProjectTox-Core/core/net_crypto.c +0 -575
- data/ProjectTox-Core/core/net_crypto.h +0 -134
- data/ProjectTox-Core/core/network.c +0 -205
- data/ProjectTox-Core/core/network.h +0 -134
- data/ProjectTox-Core/docs/commands.md +0 -25
- data/ProjectTox-Core/docs/start_guide.de.md +0 -40
- data/ProjectTox-Core/docs/start_guide.md +0 -38
- data/ProjectTox-Core/other/CMakeLists.txt +0 -9
- data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
- data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
- data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
- data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
- data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
- data/ProjectTox-Core/testing/misc_tools.h +0 -29
- data/ProjectTox-Core/testing/nTox_win32.c +0 -387
- data/ProjectTox-Core/testing/nTox_win32.h +0 -40
- data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,160 @@
|
|
1
|
+
#ifdef HAVE_CONFIG_H
|
2
|
+
#include "config.h"
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#define AUTO_TEST
|
6
|
+
#include "../toxcore/DHT.h"
|
7
|
+
#include "../toxcore/assoc.h"
|
8
|
+
#include "../toxcore/util.h"
|
9
|
+
|
10
|
+
#include <sys/types.h>
|
11
|
+
#include <stdint.h>
|
12
|
+
#include <string.h>
|
13
|
+
|
14
|
+
#include <check.h>
|
15
|
+
|
16
|
+
#include "helpers.h"
|
17
|
+
|
18
|
+
START_TEST(test_basics)
|
19
|
+
{
|
20
|
+
/* TODO: real test */
|
21
|
+
uint8_t id[CLIENT_ID_SIZE];
|
22
|
+
Assoc *assoc = new_Assoc_default(id);
|
23
|
+
ck_assert_msg(assoc != NULL, "failed to create default assoc");
|
24
|
+
|
25
|
+
kill_Assoc(assoc);
|
26
|
+
assoc = new_Assoc(17, 4, id); /* results in an assoc of 16/3 */
|
27
|
+
ck_assert_msg(assoc != NULL, "failed to create customized assoc");
|
28
|
+
|
29
|
+
IP_Port ipp;
|
30
|
+
ipp.ip.family = AF_INET;
|
31
|
+
ipp.ip.ip4.uint8[0] = 1;
|
32
|
+
ipp.port = htons(12345);
|
33
|
+
|
34
|
+
IPPTs ippts_send;
|
35
|
+
ippts_send.ip_port = ipp;
|
36
|
+
ippts_send.timestamp = unix_time();
|
37
|
+
IP_Port ipp_recv = ipp;
|
38
|
+
|
39
|
+
uint8_t res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0);
|
40
|
+
ck_assert_msg(res == 0, "stored self as entry: expected %u, got %u", 0, res);
|
41
|
+
|
42
|
+
id[0]++;
|
43
|
+
|
44
|
+
res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0);
|
45
|
+
ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u", 1, res);
|
46
|
+
|
47
|
+
Assoc_close_entries close_entries;
|
48
|
+
memset(&close_entries, 0, sizeof(close_entries));
|
49
|
+
close_entries.count = 4;
|
50
|
+
close_entries.count_good = 2;
|
51
|
+
close_entries.wanted_id = id;
|
52
|
+
|
53
|
+
Client_data *entries[close_entries.count];
|
54
|
+
close_entries.result = entries;
|
55
|
+
|
56
|
+
uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
|
57
|
+
ck_assert_msg(found == 1, "get_close_entries(): expected %u, got %u", 1, found);
|
58
|
+
}
|
59
|
+
END_TEST
|
60
|
+
|
61
|
+
START_TEST(test_fillup)
|
62
|
+
{
|
63
|
+
/* TODO: real test */
|
64
|
+
int i, j;
|
65
|
+
uint8_t id[CLIENT_ID_SIZE];
|
66
|
+
//uint32_t a = current_time();
|
67
|
+
uint32_t a = 2710106197;
|
68
|
+
srand(a);
|
69
|
+
|
70
|
+
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
|
71
|
+
id[i] = rand();
|
72
|
+
}
|
73
|
+
|
74
|
+
Assoc *assoc = new_Assoc(6, 15, id);
|
75
|
+
ck_assert_msg(assoc != NULL, "failed to create default assoc");
|
76
|
+
struct entry {
|
77
|
+
uint8_t id[CLIENT_ID_SIZE];
|
78
|
+
IPPTs ippts_send;
|
79
|
+
IP_Port ipp_recv;
|
80
|
+
};
|
81
|
+
unsigned int fail = 0;
|
82
|
+
struct entry entries[128];
|
83
|
+
struct entry closest[8];
|
84
|
+
|
85
|
+
for (j = 0; j < 128; ++j) {
|
86
|
+
|
87
|
+
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
|
88
|
+
entries[j].id[i] = rand();
|
89
|
+
}
|
90
|
+
|
91
|
+
IP_Port ipp;
|
92
|
+
ipp.ip.family = AF_INET;
|
93
|
+
ipp.ip.ip4.uint32 = rand();
|
94
|
+
ipp.port = rand();
|
95
|
+
entries[j].ippts_send.ip_port = ipp;
|
96
|
+
entries[j].ippts_send.timestamp = unix_time();
|
97
|
+
ipp.ip.ip4.uint32 = rand();
|
98
|
+
ipp.port = rand();
|
99
|
+
entries[j].ipp_recv = ipp;
|
100
|
+
|
101
|
+
if (j % 16 == 0) {
|
102
|
+
memcpy(entries[j].id, id, CLIENT_ID_SIZE - 30);
|
103
|
+
memcpy(&closest[j / 16], &entries[j], sizeof(struct entry));
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1);
|
108
|
+
ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u, j = %u", 1, res, j);
|
109
|
+
}
|
110
|
+
|
111
|
+
int good = 0;
|
112
|
+
Assoc_close_entries close_entries;
|
113
|
+
memset(&close_entries, 0, sizeof(close_entries));
|
114
|
+
close_entries.count = 8;
|
115
|
+
close_entries.count_good = 8;
|
116
|
+
close_entries.wanted_id = id;
|
117
|
+
|
118
|
+
Client_data *entri[close_entries.count];
|
119
|
+
close_entries.result = entri;
|
120
|
+
|
121
|
+
uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
|
122
|
+
ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found);
|
123
|
+
|
124
|
+
for (i = 0; i < 8; ++i) {
|
125
|
+
for (j = 0; j < 8; ++j) {
|
126
|
+
if (id_equal(entri[j]->client_id, closest[i].id))
|
127
|
+
++good;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good);
|
132
|
+
//printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a));
|
133
|
+
}
|
134
|
+
END_TEST
|
135
|
+
|
136
|
+
Suite *Assoc_suite(void)
|
137
|
+
{
|
138
|
+
Suite *s = suite_create("Assoc");
|
139
|
+
|
140
|
+
DEFTESTCASE(basics);
|
141
|
+
DEFTESTCASE(fillup);
|
142
|
+
return s;
|
143
|
+
}
|
144
|
+
|
145
|
+
int main(int argc, char *argv[])
|
146
|
+
{
|
147
|
+
unix_time_update();
|
148
|
+
Suite *Assoc = Assoc_suite();
|
149
|
+
SRunner *test_runner = srunner_create(Assoc);
|
150
|
+
|
151
|
+
srunner_set_fork_status(test_runner, CK_NOFORK);
|
152
|
+
|
153
|
+
srunner_run_all(test_runner, CK_NORMAL);
|
154
|
+
|
155
|
+
int number_failed = srunner_ntests_failed(test_runner);
|
156
|
+
|
157
|
+
srunner_free(test_runner);
|
158
|
+
|
159
|
+
return number_failed;
|
160
|
+
}
|
@@ -0,0 +1,302 @@
|
|
1
|
+
#ifdef HAVE_CONFIG_H
|
2
|
+
#include "config.h"
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#include "../toxcore/net_crypto.h"
|
6
|
+
#include <sys/types.h>
|
7
|
+
#include <stdint.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <check.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <time.h>
|
12
|
+
|
13
|
+
#include "helpers.h"
|
14
|
+
|
15
|
+
void rand_bytes(uint8_t *b, size_t blen)
|
16
|
+
{
|
17
|
+
size_t i;
|
18
|
+
|
19
|
+
for (i = 0; i < blen; i++) {
|
20
|
+
b[i] = rand();
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
// These test vectors are from libsodium's test suite
|
25
|
+
|
26
|
+
unsigned char alicesk[32] = {
|
27
|
+
0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d,
|
28
|
+
0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45,
|
29
|
+
0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a,
|
30
|
+
0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a
|
31
|
+
};
|
32
|
+
|
33
|
+
unsigned char bobpk[32] = {
|
34
|
+
0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4,
|
35
|
+
0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37,
|
36
|
+
0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d,
|
37
|
+
0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f
|
38
|
+
};
|
39
|
+
|
40
|
+
unsigned char nonce[24] = {
|
41
|
+
0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
|
42
|
+
0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
|
43
|
+
0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
|
44
|
+
};
|
45
|
+
|
46
|
+
unsigned char test_m[131] = {
|
47
|
+
0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5,
|
48
|
+
0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b,
|
49
|
+
0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4,
|
50
|
+
0x4b, 0x66, 0x84, 0x9b, 0x64, 0x24, 0x4f, 0xfc,
|
51
|
+
0xe5, 0xec, 0xba, 0xaf, 0x33, 0xbd, 0x75, 0x1a,
|
52
|
+
0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29,
|
53
|
+
0x6c, 0xdc, 0x3c, 0x01, 0x23, 0x35, 0x61, 0xf4,
|
54
|
+
0x1d, 0xb6, 0x6c, 0xce, 0x31, 0x4a, 0xdb, 0x31,
|
55
|
+
0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d,
|
56
|
+
0xce, 0xea, 0x3a, 0x7f, 0xa1, 0x34, 0x80, 0x57,
|
57
|
+
0xe2, 0xf6, 0x55, 0x6a, 0xd6, 0xb1, 0x31, 0x8a,
|
58
|
+
0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde,
|
59
|
+
0x04, 0x89, 0x77, 0xeb, 0x48, 0xf5, 0x9f, 0xfd,
|
60
|
+
0x49, 0x24, 0xca, 0x1c, 0x60, 0x90, 0x2e, 0x52,
|
61
|
+
0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40,
|
62
|
+
0xe0, 0x82, 0xf9, 0x37, 0x76, 0x38, 0x48, 0x64,
|
63
|
+
0x5e, 0x07, 0x05
|
64
|
+
};
|
65
|
+
|
66
|
+
unsigned char test_c[147] = {
|
67
|
+
0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
|
68
|
+
0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9,
|
69
|
+
0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73,
|
70
|
+
0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce,
|
71
|
+
0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4,
|
72
|
+
0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a,
|
73
|
+
0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b,
|
74
|
+
0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72,
|
75
|
+
0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2,
|
76
|
+
0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38,
|
77
|
+
0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a,
|
78
|
+
0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae,
|
79
|
+
0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea,
|
80
|
+
0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda,
|
81
|
+
0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde,
|
82
|
+
0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3,
|
83
|
+
0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6,
|
84
|
+
0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74,
|
85
|
+
0xe3, 0x55, 0xa5
|
86
|
+
};
|
87
|
+
|
88
|
+
START_TEST(test_known)
|
89
|
+
{
|
90
|
+
unsigned char c[147];
|
91
|
+
unsigned char m[131];
|
92
|
+
int clen, mlen;
|
93
|
+
|
94
|
+
ck_assert_msg(sizeof(c) == sizeof(m) + crypto_box_MACBYTES * sizeof(unsigned char),
|
95
|
+
"cyphertext should be crypto_box_MACBYTES bytes longer than plaintext");
|
96
|
+
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
|
97
|
+
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
|
98
|
+
|
99
|
+
clen = encrypt_data(bobpk, alicesk, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
|
100
|
+
|
101
|
+
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
|
102
|
+
ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
|
103
|
+
|
104
|
+
mlen = decrypt_data(bobpk, alicesk, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
|
105
|
+
|
106
|
+
ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
|
107
|
+
ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");
|
108
|
+
}
|
109
|
+
END_TEST
|
110
|
+
|
111
|
+
START_TEST(test_fast_known)
|
112
|
+
{
|
113
|
+
unsigned char k[crypto_box_BEFORENMBYTES];
|
114
|
+
unsigned char c[147];
|
115
|
+
unsigned char m[131];
|
116
|
+
int clen, mlen;
|
117
|
+
|
118
|
+
encrypt_precompute(bobpk, alicesk, k);
|
119
|
+
|
120
|
+
ck_assert_msg(sizeof(c) == sizeof(m) + crypto_box_MACBYTES * sizeof(unsigned char),
|
121
|
+
"cyphertext should be crypto_box_MACBYTES bytes longer than plaintext");
|
122
|
+
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
|
123
|
+
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
|
124
|
+
|
125
|
+
clen = encrypt_data_symmetric(k, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
|
126
|
+
|
127
|
+
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
|
128
|
+
ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
|
129
|
+
|
130
|
+
mlen = decrypt_data_symmetric(k, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
|
131
|
+
|
132
|
+
ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
|
133
|
+
ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");
|
134
|
+
|
135
|
+
}
|
136
|
+
END_TEST
|
137
|
+
|
138
|
+
START_TEST(test_endtoend)
|
139
|
+
{
|
140
|
+
unsigned char pk1[crypto_box_PUBLICKEYBYTES];
|
141
|
+
unsigned char sk1[crypto_box_SECRETKEYBYTES];
|
142
|
+
unsigned char pk2[crypto_box_PUBLICKEYBYTES];
|
143
|
+
unsigned char sk2[crypto_box_SECRETKEYBYTES];
|
144
|
+
unsigned char k1[crypto_box_BEFORENMBYTES];
|
145
|
+
unsigned char k2[crypto_box_BEFORENMBYTES];
|
146
|
+
|
147
|
+
unsigned char n[crypto_box_NONCEBYTES];
|
148
|
+
|
149
|
+
unsigned char m[500];
|
150
|
+
unsigned char c1[sizeof(m) + crypto_box_MACBYTES];
|
151
|
+
unsigned char c2[sizeof(m) + crypto_box_MACBYTES];
|
152
|
+
unsigned char c3[sizeof(m) + crypto_box_MACBYTES];
|
153
|
+
unsigned char c4[sizeof(m) + crypto_box_MACBYTES];
|
154
|
+
unsigned char m1[sizeof(m)];
|
155
|
+
unsigned char m2[sizeof(m)];
|
156
|
+
unsigned char m3[sizeof(m)];
|
157
|
+
unsigned char m4[sizeof(m)];
|
158
|
+
|
159
|
+
int mlen;
|
160
|
+
int c1len, c2len, c3len, c4len;
|
161
|
+
int m1len, m2len, m3len, m4len;
|
162
|
+
|
163
|
+
int testno;
|
164
|
+
|
165
|
+
// Test 100 random messages and keypairs
|
166
|
+
for (testno = 0; testno < 100; testno++) {
|
167
|
+
//Generate random message (random length from 100 to 500)
|
168
|
+
mlen = (rand() % 400) + 100;
|
169
|
+
rand_bytes(m, mlen);
|
170
|
+
rand_bytes(n, crypto_box_NONCEBYTES);
|
171
|
+
|
172
|
+
//Generate keypairs
|
173
|
+
crypto_box_keypair(pk1, sk1);
|
174
|
+
crypto_box_keypair(pk2, sk2);
|
175
|
+
|
176
|
+
//Precompute shared keys
|
177
|
+
encrypt_precompute(pk2, sk1, k1);
|
178
|
+
encrypt_precompute(pk1, sk2, k2);
|
179
|
+
|
180
|
+
ck_assert_msg(memcmp(k1, k2, crypto_box_BEFORENMBYTES) == 0, "encrypt_precompute: bad");
|
181
|
+
|
182
|
+
//Encrypt all four ways
|
183
|
+
c1len = encrypt_data(pk2, sk1, n, m, mlen, c1);
|
184
|
+
c2len = encrypt_data(pk1, sk2, n, m, mlen, c2);
|
185
|
+
c3len = encrypt_data_symmetric(k1, n, m, mlen, c3);
|
186
|
+
c4len = encrypt_data_symmetric(k2, n, m, mlen, c4);
|
187
|
+
|
188
|
+
ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ");
|
189
|
+
ck_assert_msg(c1len == mlen + (int)crypto_box_MACBYTES, "wrong cyphertext length");
|
190
|
+
ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0
|
191
|
+
&& memcmp(c1, c4, c1len) == 0, "crypertexts differ");
|
192
|
+
|
193
|
+
//Decrypt all four ways
|
194
|
+
m1len = decrypt_data(pk2, sk1, n, c1, c1len, m1);
|
195
|
+
m2len = decrypt_data(pk1, sk2, n, c1, c1len, m2);
|
196
|
+
m3len = decrypt_data_symmetric(k1, n, c1, c1len, m3);
|
197
|
+
m4len = decrypt_data_symmetric(k2, n, c1, c1len, m4);
|
198
|
+
|
199
|
+
ck_assert_msg(m1len == m2len && m1len == m3len && m1len == m4len, "decrypted text lengths differ");
|
200
|
+
ck_assert_msg(m1len == mlen, "wrong decrypted text length");
|
201
|
+
ck_assert_msg(memcmp(m1, m2, mlen) == 0 && memcmp(m1, m3, mlen) == 0
|
202
|
+
&& memcmp(m1, m4, mlen) == 0, "decrypted texts differ");
|
203
|
+
ck_assert_msg(memcmp(m1, m, mlen) == 0, "wrong decrypted text");
|
204
|
+
}
|
205
|
+
}
|
206
|
+
END_TEST
|
207
|
+
|
208
|
+
START_TEST(test_large_data)
|
209
|
+
{
|
210
|
+
unsigned char k[crypto_box_BEFORENMBYTES];
|
211
|
+
|
212
|
+
unsigned char n[crypto_box_NONCEBYTES];
|
213
|
+
|
214
|
+
unsigned char m1[MAX_CRYPTO_PACKET_SIZE - crypto_box_MACBYTES];
|
215
|
+
unsigned char c1[sizeof(m1) + crypto_box_MACBYTES];
|
216
|
+
unsigned char m1prime[sizeof(m1)];
|
217
|
+
|
218
|
+
unsigned char m2[MAX_CRYPTO_PACKET_SIZE];
|
219
|
+
unsigned char c2[sizeof(m2) + crypto_box_MACBYTES];
|
220
|
+
|
221
|
+
int c1len, c2len;
|
222
|
+
int m1plen;
|
223
|
+
|
224
|
+
//Generate random messages
|
225
|
+
rand_bytes(m1, sizeof(m1));
|
226
|
+
rand_bytes(m2, sizeof(m2));
|
227
|
+
rand_bytes(n, crypto_box_NONCEBYTES);
|
228
|
+
|
229
|
+
//Generate key
|
230
|
+
rand_bytes(k, crypto_box_BEFORENMBYTES);
|
231
|
+
|
232
|
+
c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1);
|
233
|
+
c2len = encrypt_data_symmetric(k, n, m2, sizeof(m2), c2);
|
234
|
+
|
235
|
+
ck_assert_msg(c1len == sizeof(m1) + crypto_box_MACBYTES, "could not encrypt");
|
236
|
+
ck_assert_msg(c2len == sizeof(m2) + crypto_box_MACBYTES, "could not encrypt");
|
237
|
+
|
238
|
+
m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime);
|
239
|
+
|
240
|
+
ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ");
|
241
|
+
ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ");
|
242
|
+
}
|
243
|
+
END_TEST
|
244
|
+
|
245
|
+
START_TEST(test_large_data_symmetric)
|
246
|
+
{
|
247
|
+
unsigned char k[crypto_box_KEYBYTES];
|
248
|
+
|
249
|
+
unsigned char n[crypto_box_NONCEBYTES];
|
250
|
+
|
251
|
+
unsigned char m1[16 * 16 * 16];
|
252
|
+
unsigned char c1[sizeof(m1) + crypto_box_MACBYTES];
|
253
|
+
unsigned char m1prime[sizeof(m1)];
|
254
|
+
|
255
|
+
int c1len;
|
256
|
+
int m1plen;
|
257
|
+
|
258
|
+
//Generate random messages
|
259
|
+
rand_bytes(m1, sizeof(m1));
|
260
|
+
rand_bytes(n, crypto_box_NONCEBYTES);
|
261
|
+
|
262
|
+
//Generate key
|
263
|
+
new_symmetric_key(k);
|
264
|
+
|
265
|
+
c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1);
|
266
|
+
ck_assert_msg(c1len == sizeof(m1) + crypto_box_MACBYTES, "could not encrypt data");
|
267
|
+
|
268
|
+
m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime);
|
269
|
+
|
270
|
+
ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ");
|
271
|
+
ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ");
|
272
|
+
}
|
273
|
+
END_TEST
|
274
|
+
|
275
|
+
Suite *crypto_suite(void)
|
276
|
+
{
|
277
|
+
Suite *s = suite_create("Crypto");
|
278
|
+
|
279
|
+
DEFTESTCASE(known);
|
280
|
+
DEFTESTCASE(fast_known);
|
281
|
+
DEFTESTCASE_SLOW(endtoend, 15); /* waiting up to 15 seconds */
|
282
|
+
DEFTESTCASE(large_data);
|
283
|
+
DEFTESTCASE(large_data_symmetric);
|
284
|
+
|
285
|
+
return s;
|
286
|
+
}
|
287
|
+
|
288
|
+
int main(int argc, char *argv[])
|
289
|
+
{
|
290
|
+
srand((unsigned int) time(NULL));
|
291
|
+
|
292
|
+
Suite *crypto = crypto_suite();
|
293
|
+
SRunner *test_runner = srunner_create(crypto);
|
294
|
+
int number_failed = 0;
|
295
|
+
|
296
|
+
srunner_run_all(test_runner, CK_NORMAL);
|
297
|
+
number_failed = srunner_ntests_failed(test_runner);
|
298
|
+
|
299
|
+
srunner_free(test_runner);
|
300
|
+
|
301
|
+
return number_failed;
|
302
|
+
}
|