-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.py
70 lines (39 loc) · 1.07 KB
/
constants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
UDP_MTU = 65535
# UDP channel
IPV4_LEN = 4
PORT_LEN = 2
MIN_PORT = 50000
MAX_PORT = 60000
CHAN_ID_SIZE = 2
MIN_CHAN_ID = 1
MAX_CHAN_ID = 2**(8 * CHAN_ID_SIZE) - 1
REPLAY_WINDOW_SIZE = 10
CHANNEL_TIMEOUT_SEC = 30
# sym encryption
SYM_KEY_LEN = 16
CTR_PREFIX_LEN = 4
CTR_MODE_PADDING = CTR_PREFIX_LEN
CHANNEL_CTR_START = 0
# link encryption
LINK_CTR_START = 0
NONCE_LEN = 16
MSG_TYPE_FLAG_LEN = 1
DATA_MSG_FLAG = b"\x01"
CHAN_INIT_MSG_FLAG = b"\x02"
CHAN_CONFIRM_MSG_FLAG = b"\x03"
GCM_MAC_LEN = 16
LINK_HEADER_LEN = CHAN_ID_SIZE + CTR_PREFIX_LEN + MSG_TYPE_FLAG_LEN
RESERVED_LEN = 0
assert RESERVED_LEN >= 0
# mix messages
MIX_COUNT = 3
# init message
GROUP_ELEMENT_LEN = 29
INIT_PAYLOAD_LEN = IPV4_LEN + PORT_LEN
INIT_OVERHEAD = GROUP_ELEMENT_LEN + MIX_COUNT * 2 * SYM_KEY_LEN + INIT_PAYLOAD_LEN
# data message
DATA_OVERHEAD = 0
# biggest UDP packet seen in the wild was 1370, which gets divided equally by 274
DATA_FRAG_PAYLOAD_SIZE = 274
INIT_FRAG_PAYLOAD_SIZE = DATA_FRAG_PAYLOAD_SIZE - (INIT_OVERHEAD - DATA_OVERHEAD)
assert INIT_OVERHEAD >= DATA_OVERHEAD