Packet.hpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2012-2013 ZeroTier Networks LLC
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef _ZT_N_PACKET_HPP
  28. #define _ZT_N_PACKET_HPP
  29. #include <stdint.h>
  30. #include <string.h>
  31. #include <stdio.h>
  32. #include <string>
  33. #include <iostream>
  34. #include "Address.hpp"
  35. #include "Poly1305.hpp"
  36. #include "Salsa20.hpp"
  37. #include "Utils.hpp"
  38. #include "Constants.hpp"
  39. #include "Buffer.hpp"
  40. #include "../ext/lz4/lz4.h"
  41. /**
  42. * Protocol version -- incremented only for MAJOR changes
  43. *
  44. * 1 - 0.2.0 ... 0.2.5
  45. * 2 - 0.3.0 ... 0.4.5
  46. * * Added signature and originating peer to multicast frame
  47. * * Double size of multicast frame bloom filter
  48. * 3 - 0.5.0 ...
  49. * * Yet another multicast redesign
  50. * * New crypto completely changes key agreement cipher
  51. */
  52. #define ZT_PROTO_VERSION 3
  53. /**
  54. * Maximum hop count allowed by packet structure (3 bits, 0-7)
  55. *
  56. * This is not necessarily the maximum hop counter after which
  57. * relaying is no longer performed.
  58. */
  59. #define ZT_PROTO_MAX_HOPS 7
  60. /**
  61. * Header flag indicating that a packet is encrypted with Salsa20
  62. *
  63. * If this is not set, then the packet's payload is in the clear and the
  64. * MAC is over this (since there is no ciphertext). Otherwise the MAC is
  65. * of the ciphertext after encryption.
  66. */
  67. #define ZT_PROTO_FLAG_ENCRYPTED 0x80
  68. /**
  69. * Header flag indicating that a packet is fragmented
  70. *
  71. * If this flag is set, the receiver knows to expect more than one fragment.
  72. * See Packet::Fragment for details.
  73. */
  74. #define ZT_PROTO_FLAG_FRAGMENTED 0x40
  75. /**
  76. * Verb flag indicating payload is compressed with LZ4
  77. */
  78. #define ZT_PROTO_VERB_FLAG_COMPRESSED 0x80
  79. // Indices of fields in normal packet header -- do not change as this
  80. // might require both code rework and will break compatibility.
  81. #define ZT_PACKET_IDX_IV 0
  82. #define ZT_PACKET_IDX_DEST 8
  83. #define ZT_PACKET_IDX_SOURCE 13
  84. #define ZT_PACKET_IDX_FLAGS 18
  85. #define ZT_PACKET_IDX_MAC 19
  86. #define ZT_PACKET_IDX_VERB 27
  87. #define ZT_PACKET_IDX_PAYLOAD 28
  88. /**
  89. * ZeroTier packet buffer size
  90. *
  91. * This can be changed. This provides enough room for MTU-size packet
  92. * payloads plus some overhead. The subtraction of sizeof(unsigned int)
  93. * makes it an even multiple of 1024 (see Buffer), which might reduce
  94. * memory use a little.
  95. */
  96. #define ZT_PROTO_MAX_PACKET_LENGTH (3072 - sizeof(unsigned int))
  97. /**
  98. * Minimum viable packet length (also length of header)
  99. */
  100. #define ZT_PROTO_MIN_PACKET_LENGTH ZT_PACKET_IDX_PAYLOAD
  101. // Indexes of fields in fragment header -- also can't be changed without
  102. // breaking compatibility.
  103. #define ZT_PACKET_FRAGMENT_IDX_PACKET_ID 0
  104. #define ZT_PACKET_FRAGMENT_IDX_DEST 8
  105. #define ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR 13
  106. #define ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO 14
  107. #define ZT_PACKET_FRAGMENT_IDX_HOPS 15
  108. #define ZT_PACKET_FRAGMENT_IDX_PAYLOAD 16
  109. /**
  110. * Value found at ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR in fragments
  111. */
  112. #define ZT_PACKET_FRAGMENT_INDICATOR ZT_ADDRESS_RESERVED_PREFIX
  113. /**
  114. * Minimum viable fragment length
  115. */
  116. #define ZT_PROTO_MIN_FRAGMENT_LENGTH ZT_PACKET_FRAGMENT_IDX_PAYLOAD
  117. // Size of bloom filter used in multicast propagation graph exploration
  118. #define ZT_PROTO_VERB_MULTICAST_FRAME_BLOOM_FILTER_SIZE_BITS 512
  119. #define ZT_PROTO_VERB_MULTICAST_FRAME_BLOOM_FILTER_SIZE_BYTES 64
  120. // Field incides for parsing verbs -------------------------------------------
  121. #define ZT_PROTO_VERB_HELLO_IDX_PROTOCOL_VERSION (ZT_PACKET_IDX_PAYLOAD)
  122. #define ZT_PROTO_VERB_HELLO_IDX_MAJOR_VERSION (ZT_PROTO_VERB_HELLO_IDX_PROTOCOL_VERSION + 1)
  123. #define ZT_PROTO_VERB_HELLO_IDX_MINOR_VERSION (ZT_PROTO_VERB_HELLO_IDX_MAJOR_VERSION + 1)
  124. #define ZT_PROTO_VERB_HELLO_IDX_REVISION (ZT_PROTO_VERB_HELLO_IDX_MINOR_VERSION + 1)
  125. #define ZT_PROTO_VERB_HELLO_IDX_TIMESTAMP (ZT_PROTO_VERB_HELLO_IDX_REVISION + 2)
  126. #define ZT_PROTO_VERB_HELLO_IDX_IDENTITY (ZT_PROTO_VERB_HELLO_IDX_TIMESTAMP + 8)
  127. #define ZT_PROTO_VERB_ERROR_IDX_IN_RE_VERB (ZT_PACKET_IDX_PAYLOAD)
  128. #define ZT_PROTO_VERB_ERROR_IDX_IN_RE_PACKET_ID (ZT_PROTO_VERB_ERROR_IDX_IN_RE_VERB + 1)
  129. #define ZT_PROTO_VERB_ERROR_IDX_ERROR_CODE (ZT_PROTO_VERB_ERROR_IDX_IN_RE_PACKET_ID + 8)
  130. #define ZT_PROTO_VERB_ERROR_IDX_PAYLOAD (ZT_PROTO_VERB_ERROR_IDX_ERROR_CODE + 1)
  131. #define ZT_PROTO_VERB_OK_IDX_IN_RE_VERB (ZT_PACKET_IDX_PAYLOAD)
  132. #define ZT_PROTO_VERB_OK_IDX_IN_RE_PACKET_ID (ZT_PROTO_VERB_OK_IDX_IN_RE_VERB + 1)
  133. #define ZT_PROTO_VERB_OK_IDX_PAYLOAD (ZT_PROTO_VERB_OK_IDX_IN_RE_PACKET_ID + 8)
  134. #define ZT_PROTO_VERB_WHOIS_IDX_ZTADDRESS (ZT_PACKET_IDX_PAYLOAD)
  135. #define ZT_PROTO_VERB_RENDEZVOUS_IDX_ZTADDRESS (ZT_PACKET_IDX_PAYLOAD)
  136. #define ZT_PROTO_VERB_RENDEZVOUS_IDX_PORT (ZT_PROTO_VERB_RENDEZVOUS_IDX_ZTADDRESS + 5)
  137. #define ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRLEN (ZT_PROTO_VERB_RENDEZVOUS_IDX_PORT + 2)
  138. #define ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRESS (ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRLEN + 1)
  139. #define ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID (ZT_PACKET_IDX_PAYLOAD)
  140. #define ZT_PROTO_VERB_FRAME_IDX_ETHERTYPE (ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID + 8)
  141. #define ZT_PROTO_VERB_FRAME_IDX_PAYLOAD (ZT_PROTO_VERB_FRAME_IDX_ETHERTYPE + 2)
  142. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_COUNTER (ZT_PACKET_IDX_PAYLOAD)
  143. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_QUEUE (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_COUNTER + 2)
  144. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_MAGNET (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_QUEUE + 320)
  145. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_SUBMITTER (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_MAGNET + 5)
  146. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_SUBMITTER_UNIQUE_ID (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_SUBMITTER + 5)
  147. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_NETWORK_ID (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_SUBMITTER_UNIQUE_ID + 3)
  148. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_SOURCE_MAC (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_NETWORK_ID + 8)
  149. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_DESTINATION_MAC (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_SOURCE_MAC + 6)
  150. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_DESTINATION_ADI (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_DESTINATION_MAC + 6)
  151. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_ETHERTYPE (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_DESTINATION_ADI + 4)
  152. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_PAYLOAD_LENGTH (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_ETHERTYPE + 2)
  153. #define ZT_PROTO_VERB_MULTICAST_FRAME_IDX_PAYLOAD (ZT_PROTO_VERB_MULTICAST_FRAME_IDX_PAYLOAD_LENGTH + 2)
  154. #define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID (ZT_PACKET_IDX_PAYLOAD)
  155. #define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID + 8)
  156. #define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN + 2)
  157. #define ZT_PROTO_VERB_NETWORK_CONFIG_REFRESH_IDX_NETWORK_ID (ZT_PACKET_IDX_PAYLOAD)
  158. #define ZT_PROTO_VERB_HELLO__OK__IDX_TIMESTAMP (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
  159. #define ZT_PROTO_VERB_HELLO__OK__IDX_PROTOCOL_VERSION (ZT_PROTO_VERB_HELLO__OK__IDX_TIMESTAMP + 8)
  160. #define ZT_PROTO_VERB_HELLO__OK__IDX_MAJOR_VERSION (ZT_PROTO_VERB_HELLO__OK__IDX_PROTOCOL_VERSION + 1)
  161. #define ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION (ZT_PROTO_VERB_HELLO__OK__IDX_MAJOR_VERSION + 1)
  162. #define ZT_PROTO_VERB_HELLO__OK__IDX_REVISION (ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION + 1)
  163. #define ZT_PROTO_VERB_WHOIS__OK__IDX_IDENTITY (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
  164. #define ZT_PROTO_VERB_WHOIS__ERROR__IDX_ZTADDRESS (ZT_PROTO_VERB_ERROR_IDX_PAYLOAD)
  165. #define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_NETWORK_ID (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
  166. #define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT_LEN (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_NETWORK_ID + 8)
  167. #define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT_LEN + 2)
  168. // ---------------------------------------------------------------------------
  169. namespace ZeroTier {
  170. /**
  171. * ZeroTier packet
  172. *
  173. * Packet format:
  174. * <[8] random initialization vector (doubles as 64-bit packet ID)>
  175. * <[5] destination ZT address>
  176. * <[5] source ZT address>
  177. * <[1] flags (LS 5 bits) and ZT hop count (MS 3 bits)>
  178. * <[8] 8-bit MAC (currently first 8 bytes of poly1305 tag)>
  179. * [... -- begin encryption envelope -- ...]
  180. * <[1] encrypted flags (MS 3 bits) and verb (LS 5 bits)>
  181. * [... verb-specific payload ...]
  182. *
  183. * Packets smaller than 28 bytes are invalid and silently discarded.
  184. *
  185. * MAC is computed on ciphertext *after* encryption. See also:
  186. *
  187. * http://tonyarcieri.com/all-the-crypto-code-youve-ever-written-is-probably-broken
  188. *
  189. * For unencrypted packets, MAC is computed on plaintext. Only HELLO is ever
  190. * sent in the clear, as it's the "here is my public key" message.
  191. */
  192. class Packet : public Buffer<ZT_PROTO_MAX_PACKET_LENGTH>
  193. {
  194. public:
  195. /**
  196. * A packet fragment
  197. *
  198. * Fragments are sent if a packet is larger than UDP MTU. The first fragment
  199. * is sent with its normal header with the fragmented flag set. Remaining
  200. * fragments are sent this way.
  201. *
  202. * The fragmented bit indicates that there is at least one fragment. Fragments
  203. * themselves contain the total, so the receiver must "learn" this from the
  204. * first fragment it receives.
  205. *
  206. * Fragments are sent with the following format:
  207. * <[8] packet ID of packet whose fragment this belongs to>
  208. * <[5] destination ZT address>
  209. * <[1] 0xff, a reserved address, signals that this isn't a normal packet>
  210. * <[1] total fragments (most significant 4 bits), fragment no (LS 4 bits)>
  211. * <[1] ZT hop count>
  212. * <[...] fragment data>
  213. *
  214. * The protocol supports a maximum of 16 fragments. If a fragment is received
  215. * before its main packet header, it should be cached for a brief period of
  216. * time to see if its parent arrives. Loss of any fragment constitutes packet
  217. * loss; there is no retransmission mechanism. The receiver must wait for full
  218. * receipt to authenticate and decrypt; there is no per-fragment MAC. (But if
  219. * fragments are corrupt, the MAC will fail for the whole assembled packet.)
  220. */
  221. class Fragment : public Buffer<ZT_PROTO_MAX_PACKET_LENGTH>
  222. {
  223. public:
  224. Fragment() :
  225. Buffer<ZT_PROTO_MAX_PACKET_LENGTH>()
  226. {
  227. }
  228. template<unsigned int C2>
  229. Fragment(const Buffer<C2> &b)
  230. throw(std::out_of_range) :
  231. Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(b)
  232. {
  233. }
  234. /**
  235. * Initialize from a packet
  236. *
  237. * @param p Original assembled packet
  238. * @param fragStart Start of fragment (raw index in packet data)
  239. * @param fragLen Length of fragment in bytes
  240. * @param fragNo Which fragment (>= 1, since 0 is Packet with end chopped off)
  241. * @param fragTotal Total number of fragments (including 0)
  242. * @throws std::out_of_range Packet size would exceed buffer
  243. */
  244. Fragment(const Packet &p,unsigned int fragStart,unsigned int fragLen,unsigned int fragNo,unsigned int fragTotal)
  245. throw(std::out_of_range)
  246. {
  247. init(p,fragStart,fragLen,fragNo,fragTotal);
  248. }
  249. /**
  250. * Initialize from a packet
  251. *
  252. * @param p Original assembled packet
  253. * @param fragStart Start of fragment (raw index in packet data)
  254. * @param fragLen Length of fragment in bytes
  255. * @param fragNo Which fragment (>= 1, since 0 is Packet with end chopped off)
  256. * @param fragTotal Total number of fragments (including 0)
  257. * @throws std::out_of_range Packet size would exceed buffer
  258. */
  259. inline void init(const Packet &p,unsigned int fragStart,unsigned int fragLen,unsigned int fragNo,unsigned int fragTotal)
  260. throw(std::out_of_range)
  261. {
  262. if ((fragStart + fragLen) > p.size())
  263. throw std::out_of_range("Packet::Fragment: tried to construct fragment of packet past its length");
  264. setSize(fragLen + ZT_PROTO_MIN_FRAGMENT_LENGTH);
  265. // NOTE: this copies both the IV/packet ID and the destination address.
  266. memcpy(field(ZT_PACKET_FRAGMENT_IDX_PACKET_ID,13),p.data() + ZT_PACKET_IDX_IV,13);
  267. (*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR] = ZT_PACKET_FRAGMENT_INDICATOR;
  268. (*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO] = (char)(((fragTotal & 0xf) << 4) | (fragNo & 0xf));
  269. (*this)[ZT_PACKET_FRAGMENT_IDX_HOPS] = 0;
  270. memcpy(field(ZT_PACKET_FRAGMENT_IDX_PAYLOAD,fragLen),p.data() + fragStart,fragLen);
  271. }
  272. /**
  273. * Get this fragment's destination
  274. *
  275. * @return Destination ZT address
  276. */
  277. inline Address destination() const { return Address(field(ZT_PACKET_FRAGMENT_IDX_DEST,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
  278. /**
  279. * @return True if fragment is of a valid length
  280. */
  281. inline bool lengthValid() const { return (size() >= ZT_PACKET_FRAGMENT_IDX_PAYLOAD); }
  282. /**
  283. * @return ID of packet this is a fragment of
  284. */
  285. inline uint64_t packetId() const { return at<uint64_t>(ZT_PACKET_FRAGMENT_IDX_PACKET_ID); }
  286. /**
  287. * @return Total number of fragments in packet
  288. */
  289. inline unsigned int totalFragments() const { return (((unsigned int)((*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO]) >> 4) & 0xf); }
  290. /**
  291. * @return Fragment number of this fragment
  292. */
  293. inline unsigned int fragmentNumber() const { return ((unsigned int)((*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO]) & 0xf); }
  294. /**
  295. * @return Fragment ZT hop count
  296. */
  297. inline unsigned int hops() const { return (unsigned int)((*this)[ZT_PACKET_FRAGMENT_IDX_HOPS]); }
  298. /**
  299. * Increment this packet's hop count
  300. */
  301. inline void incrementHops()
  302. {
  303. (*this)[ZT_PACKET_FRAGMENT_IDX_HOPS] = (((*this)[ZT_PACKET_FRAGMENT_IDX_HOPS]) + 1) & ZT_PROTO_MAX_HOPS;
  304. }
  305. /**
  306. * @return Length of payload in bytes
  307. */
  308. inline unsigned int payloadLength() const { return ((size() > ZT_PACKET_FRAGMENT_IDX_PAYLOAD) ? (size() - ZT_PACKET_FRAGMENT_IDX_PAYLOAD) : 0); }
  309. /**
  310. * @return Raw packet payload
  311. */
  312. inline const unsigned char *payload() const
  313. {
  314. return field(ZT_PACKET_FRAGMENT_IDX_PAYLOAD,size() - ZT_PACKET_FRAGMENT_IDX_PAYLOAD);
  315. }
  316. };
  317. /**
  318. * ZeroTier protocol verbs
  319. */
  320. enum Verb /* Max value: 32 (5 bits) */
  321. {
  322. /* No operation, payload ignored, no reply */
  323. VERB_NOP = 0,
  324. /* Announcement of a node's existence:
  325. * <[1] protocol version>
  326. * <[1] software major version>
  327. * <[1] software minor version>
  328. * <[2] software revision>
  329. * <[8] timestamp (ms since epoch)>
  330. * <[...] binary serialized identity (see Identity)>
  331. *
  332. * OK payload:
  333. * <[8] timestamp (echoed from original HELLO)>
  334. * <[1] protocol version (of responder)>
  335. * <[1] software major version (of responder)>
  336. * <[1] software minor version (of responder)>
  337. * <[2] software revision (of responder)>
  338. *
  339. * ERROR has no payload.
  340. */
  341. VERB_HELLO = 1,
  342. /* Error response:
  343. * <[1] in-re verb>
  344. * <[8] in-re packet ID>
  345. * <[1] error code>
  346. * <[...] error-dependent payload>
  347. */
  348. VERB_ERROR = 2,
  349. /* Success response:
  350. * <[1] in-re verb>
  351. * <[8] in-re packet ID>
  352. * <[...] request-specific payload>
  353. */
  354. VERB_OK = 3,
  355. /* Query an identity by address:
  356. * <[5] address to look up>
  357. *
  358. * OK response payload:
  359. * <[...] binary serialized identity>
  360. *
  361. * Error payload will be address queried.
  362. */
  363. VERB_WHOIS = 4,
  364. /* Meet another node at a given protocol address:
  365. * <[5] ZeroTier address of peer that might be found at this address>
  366. * <[2] 16-bit protocol address port>
  367. * <[1] protocol address length (4 for IPv4, 16 for IPv6)>
  368. * <[...] protocol address (network byte order)>
  369. *
  370. * This is sent by a relaying node to initiate NAT traversal between two
  371. * peers that are communicating by way of indirect relay. The relay will
  372. * send this to both peers at the same time on a periodic basis, telling
  373. * each where it might find the other on the network.
  374. *
  375. * Upon receipt, a peer sends a message such as NOP or HELLO to the other
  376. * peer. Peers only "learn" one anothers' direct addresses when they
  377. * successfully *receive* a message and authenticate it. Optionally, peers
  378. * will usually preface these messages with one or more firewall openers
  379. * to clear the path.
  380. *
  381. * Nodes should implement rate control, limiting the rate at which they
  382. * respond to these packets to prevent their use in DDOS attacks. Nodes
  383. * may also ignore these messages if a peer is not known or is not being
  384. * actively communicated with.
  385. *
  386. * No OK or ERROR is generated.
  387. */
  388. VERB_RENDEZVOUS = 5,
  389. /* A ZT-to-ZT unicast ethernet frame:
  390. * <[8] 64-bit network ID>
  391. * <[2] 16-bit ethertype>
  392. * <[...] ethernet payload>
  393. *
  394. * MAC addresses are derived from the packet's source and destination
  395. * ZeroTier addresses. ZeroTier does not support VLANs or other extensions
  396. * beyond core Ethernet.
  397. *
  398. * No OK or ERROR is generated.
  399. */
  400. VERB_FRAME = 6,
  401. /* Announce interest in multicast group(s):
  402. * <[8] 64-bit network ID>
  403. * <[6] multicast Ethernet address>
  404. * <[4] multicast additional distinguishing information (ADI)>
  405. * [... additional tuples of network/address/adi ...]
  406. *
  407. * OK is generated on successful receipt.
  408. */
  409. VERB_MULTICAST_LIKE = 7,
  410. /* Announce receipt of a multicast to propagation magnet node:
  411. * <[8] 64-bit multicast GUID>
  412. *
  413. * OK/ERROR are not generated.
  414. */
  415. VERB_MULTICAST_GOT = 8,
  416. /* A multicast frame:
  417. * <[2] 16-bit counter -- number of times multicast has been forwarded>
  418. * <[320] FIFO queue of up to 64 ZT addresses, zero address terminated>
  419. * [... start of signed portion, signed by original submitter below ...]
  420. * <[5] ZeroTier address of propagation magnet node>
  421. * <[5] ZeroTier address of original submitter/signer>
  422. * <[3] 24-bit multicast ID, combined with signer address to form GUID>
  423. * <[8] 64-bit network ID>
  424. * <[6] source MAC address>
  425. * <[6] destination multicast group MAC address>
  426. * <[4] destination multicast group 32-bit ADI field>
  427. * <[2] 16-bit frame ethertype>
  428. * <[2] 16-bit length of payload>
  429. * <[...] ethernet frame payload>
  430. * [... end of signed portion ...]
  431. * <[2] 16-bit length of signature>
  432. * <[...] signature (currently Ed25519/SHA-512, 96 bytes in length)>
  433. *
  434. * Multicast frames are propagated using a graph exploration algorithm in
  435. * which the FIFO queue is embedded in the multicast packet.
  436. *
  437. * Upon receipt:
  438. * (1) packet is possibly injected into the local TAP
  439. * (2) send a MULTICAST_GOT message to magnet node with 64-bit
  440. * multicast GUID
  441. * (3) counter is incremented, STOP if >= network's max multicast
  442. * recipient count
  443. * (4) topmost value is removed from FIFO and saved (next hop)
  444. * (5) FIFO is deduplicated (prevents amplification floods)
  445. * (6) FIFO is filled with as many known peers that have LIKED this
  446. * multicast group as possible, excluding peers to whom this
  447. * multicast has already been sent or (if magnet node) have GOT
  448. * this multicast
  449. * (7) packet is sent to next hop (if possible)
  450. *
  451. * If there was no next hop -- empty FIFO -- and no new hops are known,
  452. * the packet is sent to the magnet node. The magnet node must be aware
  453. * of all members of a given multicast group. It is the node responsible
  454. * for bridging sparse multicast groups. When other nodes receive the
  455. * multicast, they send GOT to the magnet node so that it will not
  456. * send it back to them.
  457. *
  458. * Right now the magnet is a supernode. In the future there may be
  459. * dedicated magnets and/or magnets elected via some kind of DHT or
  460. * something to act as such for given multicast groups. This latter
  461. * might happen if we evolve more toward a totally decentralized model
  462. * instead of today's partially decentralized model.
  463. *
  464. * The multicast GUID is formed by packing the original sender / signer
  465. * address into the most significant 5 bytes of a 64-bit big-endian
  466. * number, and then packing the 24-bit sender unique ID into the least
  467. * significant 3 bytes. This can be used to locally deduplicate, and
  468. * to identify the multicast in a GOT sent to the magnet. The 24-bit
  469. * ID must be unique for a given sender over recent (say, 10min) time
  470. * spans and across networks. Random or sequential values are fine.
  471. *
  472. * OK/ERROR are not generated, but GOT is sent to magnet.
  473. */
  474. VERB_MULTICAST_FRAME = 9,
  475. /* Network member certificate for sending peer:
  476. * <[8] 64-bit network ID>
  477. * <[2] 16-bit length of certificate>
  478. * <[2] 16-bit length of signature>
  479. * <[...] string-serialized certificate dictionary>
  480. * <[...] ECDSA signature of certificate>
  481. *
  482. * OK is generated on acceptance. ERROR is returned on failure. In both
  483. * cases the payload is the network ID.
  484. */
  485. VERB_NETWORK_MEMBERSHIP_CERTIFICATE = 10,
  486. /* Network configuration request:
  487. * <[8] 64-bit network ID>
  488. * <[2] 16-bit length of request meta-data dictionary>
  489. * <[...] string-serialized request meta-data>
  490. *
  491. * This message requests network configuration from a node capable of
  492. * providing it. Such nodes run the netconf service, which must be
  493. * installed into the ZeroTier home directory.
  494. *
  495. * OK response payload:
  496. * <[8] 64-bit network ID>
  497. * <[2] 16-bit length of network configuration dictionary>
  498. * <[...] network configuration dictionary>
  499. *
  500. * OK returns a Dictionary (string serialized) containing the network's
  501. * configuration and IP address assignment information for the querying
  502. * node. It also contains a membership certificate that the querying
  503. * node can push to other peers to demonstrate its right to speak on
  504. * a given network.
  505. *
  506. * ERROR may be NOT_FOUND if no such network is known, or
  507. * UNSUPPORTED_OPERATION if the netconf service isn't available. The
  508. * payload will be the network ID.
  509. */
  510. VERB_NETWORK_CONFIG_REQUEST = 11,
  511. /* Network configuration refresh request:
  512. * <[8] 64-bit network ID>
  513. *
  514. * This message can be sent by the network configuration master node
  515. * to request that nodes refresh their network configuration. It can
  516. * thus be used to "push" updates.
  517. *
  518. * It does not generate an OK or ERROR message, and is treated only as
  519. * a hint to refresh now.
  520. */
  521. VERB_NETWORK_CONFIG_REFRESH = 12
  522. };
  523. /**
  524. * Error codes for VERB_ERROR
  525. */
  526. enum ErrorCode
  527. {
  528. /* No error, not actually used in transit */
  529. ERROR_NONE = 0,
  530. /* Invalid request */
  531. ERROR_INVALID_REQUEST = 1,
  532. /* Bad/unsupported protocol version */
  533. ERROR_BAD_PROTOCOL_VERSION = 2,
  534. /* Unknown object queried (e.g. with WHOIS) */
  535. ERROR_OBJ_NOT_FOUND = 3,
  536. /* HELLO pushed an identity whose address is already claimed */
  537. ERROR_IDENTITY_COLLISION = 4,
  538. /* Identity was not valid */
  539. ERROR_IDENTITY_INVALID = 5,
  540. /* Verb or use case not supported/enabled by this node */
  541. ERROR_UNSUPPORTED_OPERATION = 6,
  542. /* Message to private network rejected -- no unexpired certificate on file */
  543. ERROR_NO_MEMBER_CERTIFICATE = 7
  544. };
  545. /**
  546. * @param v Verb
  547. * @return String representation (e.g. HELLO, OK)
  548. */
  549. static const char *verbString(Verb v)
  550. throw();
  551. /**
  552. * @param e Error code
  553. * @return String error name
  554. */
  555. static const char *errorString(ErrorCode e)
  556. throw();
  557. template<unsigned int C2>
  558. Packet(const Buffer<C2> &b)
  559. throw(std::out_of_range) :
  560. Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(b)
  561. {
  562. }
  563. /**
  564. * Construct a new empty packet with a unique random packet ID
  565. *
  566. * Flags and hops will be zero. Other fields and data region are undefined.
  567. * Use the header access methods (setDestination() and friends) to fill out
  568. * the header. Payload should be appended; initial size is header size.
  569. */
  570. Packet() :
  571. Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(ZT_PROTO_MIN_PACKET_LENGTH)
  572. {
  573. Utils::getSecureRandom(field(ZT_PACKET_IDX_IV,8),8);
  574. (*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags and hops
  575. }
  576. /**
  577. * Construct a new empty packet with a unique random packet ID
  578. *
  579. * @param dest Destination ZT address
  580. * @param source Source ZT address
  581. * @param v Verb
  582. */
  583. Packet(const Address &dest,const Address &source,const Verb v) :
  584. Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(ZT_PROTO_MIN_PACKET_LENGTH)
  585. {
  586. Utils::getSecureRandom(field(ZT_PACKET_IDX_IV,8),8);
  587. setDestination(dest);
  588. setSource(source);
  589. (*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags and hops
  590. setVerb(v);
  591. }
  592. /**
  593. * Reset this packet structure for reuse in place
  594. *
  595. * @param dest Destination ZT address
  596. * @param source Source ZT address
  597. * @param v Verb
  598. */
  599. inline void reset(const Address &dest,const Address &source,const Verb v)
  600. {
  601. setSize(ZT_PROTO_MIN_PACKET_LENGTH);
  602. Utils::getSecureRandom(field(ZT_PACKET_IDX_IV,8),8);
  603. setDestination(dest);
  604. setSource(source);
  605. (*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags and hops
  606. setVerb(v);
  607. }
  608. /**
  609. * Generate a new IV / packet ID in place
  610. *
  611. * This can be used to re-use a packet buffer multiple times to send
  612. * technically different but otherwise identical copies of the same
  613. * packet.
  614. */
  615. inline void newInitializationVector()
  616. {
  617. Utils::getSecureRandom(field(ZT_PACKET_IDX_IV,8),8);
  618. }
  619. /**
  620. * Set this packet's destination
  621. *
  622. * @param dest ZeroTier address of destination
  623. */
  624. inline void setDestination(const Address &dest)
  625. {
  626. unsigned char *d = field(ZT_PACKET_IDX_DEST,ZT_ADDRESS_LENGTH);
  627. for(unsigned int i=0;i<ZT_ADDRESS_LENGTH;++i)
  628. d[i] = dest[i];
  629. }
  630. /**
  631. * Set this packet's source
  632. *
  633. * @param source ZeroTier address of source
  634. */
  635. inline void setSource(const Address &source)
  636. {
  637. unsigned char *s = field(ZT_PACKET_IDX_SOURCE,ZT_ADDRESS_LENGTH);
  638. for(unsigned int i=0;i<ZT_ADDRESS_LENGTH;++i)
  639. s[i] = source[i];
  640. }
  641. /**
  642. * Get this packet's destination
  643. *
  644. * @return Destination ZT address
  645. */
  646. inline Address destination() const { return Address(field(ZT_PACKET_IDX_DEST,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
  647. /**
  648. * Get this packet's source
  649. *
  650. * @return Source ZT address
  651. */
  652. inline Address source() const { return Address(field(ZT_PACKET_IDX_SOURCE,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
  653. /**
  654. * @return True if packet is of valid length
  655. */
  656. inline bool lengthValid() const { return (size() >= ZT_PROTO_MIN_PACKET_LENGTH); }
  657. /**
  658. * @return True if packet is encrypted
  659. */
  660. inline bool encrypted() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_ENCRYPTED) != 0); }
  661. /**
  662. * @return True if packet is fragmented (expect fragments)
  663. */
  664. inline bool fragmented() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_FRAGMENTED) != 0); }
  665. /**
  666. * Set this packet's fragmented flag
  667. *
  668. * @param f Fragmented flag value
  669. */
  670. inline void setFragmented(bool f)
  671. {
  672. if (f)
  673. (*this)[ZT_PACKET_IDX_FLAGS] |= (char)ZT_PROTO_FLAG_FRAGMENTED;
  674. else (*this)[ZT_PACKET_IDX_FLAGS] &= (char)(~ZT_PROTO_FLAG_FRAGMENTED);
  675. }
  676. /**
  677. * @return True if compressed (result only valid if unencrypted)
  678. */
  679. inline bool compressed() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_VERB] & ZT_PROTO_VERB_FLAG_COMPRESSED) != 0); }
  680. /**
  681. * @return ZeroTier forwarding hops (0 to 7)
  682. */
  683. inline unsigned int hops() const { return ((unsigned int)(*this)[ZT_PACKET_IDX_FLAGS] & 0x07); }
  684. /**
  685. * Increment this packet's hop count
  686. */
  687. inline void incrementHops()
  688. {
  689. (*this)[ZT_PACKET_IDX_FLAGS] = (char)((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & 0xf8) | (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] + 1) & 0x07);
  690. }
  691. /**
  692. * Get this packet's unique ID (the IV field interpreted as uint64_t)
  693. *
  694. * @return Packet ID
  695. */
  696. inline uint64_t packetId() const { return at<uint64_t>(ZT_PACKET_IDX_IV); }
  697. /**
  698. * Set packet verb
  699. *
  700. * This also has the side-effect of clearing any verb flags, such as
  701. * compressed, and so must only be done during packet composition.
  702. *
  703. * @param v New packet verb
  704. */
  705. inline void setVerb(Verb v) { (*this)[ZT_PACKET_IDX_VERB] = (char)v; }
  706. /**
  707. * @return Packet verb (not including flag bits)
  708. */
  709. inline Verb verb() const { return (Verb)((*this)[ZT_PACKET_IDX_VERB] & 0x1f); }
  710. /**
  711. * @return Length of packet payload
  712. */
  713. inline unsigned int payloadLength() const { return ((size() < ZT_PROTO_MIN_PACKET_LENGTH) ? 0 : (size() - ZT_PROTO_MIN_PACKET_LENGTH)); }
  714. /**
  715. * @return Raw packet payload
  716. */
  717. inline const unsigned char *payload() const
  718. {
  719. return field(ZT_PACKET_IDX_PAYLOAD,size() - ZT_PACKET_IDX_PAYLOAD);
  720. }
  721. /**
  722. * Generate a message authenticationc code and set MAC field of packet
  723. *
  724. * For encrypted packets, this must be called after encryption.
  725. *
  726. * @param key 256-bit (32 byte) key
  727. */
  728. inline void macSet(const void *key)
  729. {
  730. unsigned char mac[16];
  731. unsigned char key2[32];
  732. _mangleKey((const unsigned char *)key,key2);
  733. unsigned int macLen = (size() >= ZT_PACKET_IDX_VERB) ? (size() - ZT_PACKET_IDX_VERB) : 0;
  734. Poly1305::compute(mac,field(ZT_PACKET_IDX_VERB,macLen),macLen,key2);
  735. memcpy(field(ZT_PACKET_IDX_MAC,8),mac,8);
  736. }
  737. /**
  738. * Check the MAC of this packet's payload
  739. *
  740. * For encrypted packets, this must be checked before decryption.
  741. *
  742. * @param key 256-bit (32 byte) key
  743. */
  744. inline bool macVerify(const void *key) const
  745. {
  746. unsigned char mac[16];
  747. unsigned char key2[32];
  748. if (size() < ZT_PACKET_IDX_VERB)
  749. return false; // incomplete packets fail
  750. _mangleKey((const unsigned char *)key,key2);
  751. unsigned int macLen = size() - ZT_PACKET_IDX_VERB;
  752. Poly1305::compute(mac,field(ZT_PACKET_IDX_VERB,macLen),macLen,key2);
  753. return Utils::secureEq(mac,field(ZT_PACKET_IDX_MAC,8),8);
  754. }
  755. /**
  756. * Encrypt this packet
  757. *
  758. * @param key 256-bit (32 byte) key
  759. */
  760. inline void encrypt(const void *key)
  761. {
  762. (*this)[ZT_PACKET_IDX_FLAGS] |= ZT_PROTO_FLAG_ENCRYPTED;
  763. unsigned char key2[32];
  764. if (size() >= ZT_PACKET_IDX_VERB) {
  765. _mangleKey((const unsigned char *)key,key2);
  766. Salsa20 s20(key2,256,field(ZT_PACKET_IDX_IV,8));
  767. unsigned int encLen = size() - ZT_PACKET_IDX_VERB;
  768. unsigned char *const encBuf = field(ZT_PACKET_IDX_VERB,encLen);
  769. s20.encrypt(encBuf,encBuf,encLen);
  770. }
  771. }
  772. /**
  773. * Decrypt this packet
  774. *
  775. * @param key 256-bit (32 byte) key
  776. */
  777. inline void decrypt(const void *key)
  778. {
  779. unsigned char key2[32];
  780. if (size() >= ZT_PACKET_IDX_VERB) {
  781. _mangleKey((const unsigned char *)key,key2);
  782. Salsa20 s20(key2,256,field(ZT_PACKET_IDX_IV,8));
  783. unsigned int decLen = size() - ZT_PACKET_IDX_VERB;
  784. unsigned char *const decBuf = field(ZT_PACKET_IDX_VERB,decLen);
  785. s20.decrypt(decBuf,decBuf,decLen);
  786. }
  787. (*this)[ZT_PACKET_IDX_FLAGS] &= (char)(~ZT_PROTO_FLAG_ENCRYPTED);
  788. }
  789. /**
  790. * Attempt to compress payload if not already (must be unencrypted)
  791. *
  792. * This requires that the payload at least contain the verb byte already
  793. * set. The compressed flag in the verb is set if compression successfully
  794. * results in a size reduction. If no size reduction occurs, compression
  795. * is not done and the flag is left cleared.
  796. *
  797. * @return True if compression occurred
  798. */
  799. inline bool compress()
  800. {
  801. unsigned char buf[ZT_PROTO_MAX_PACKET_LENGTH * 2];
  802. if ((!compressed())&&(size() > (ZT_PACKET_IDX_PAYLOAD + 32))) {
  803. int pl = (int)(size() - ZT_PACKET_IDX_PAYLOAD);
  804. int cl = LZ4_compress((const char *)field(ZT_PACKET_IDX_PAYLOAD,(unsigned int)pl),(char *)buf,pl);
  805. if ((cl > 0)&&(cl < pl)) {
  806. (*this)[ZT_PACKET_IDX_VERB] |= (char)ZT_PROTO_VERB_FLAG_COMPRESSED;
  807. setSize((unsigned int)cl + ZT_PACKET_IDX_PAYLOAD);
  808. memcpy(field(ZT_PACKET_IDX_PAYLOAD,(unsigned int)cl),buf,cl);
  809. return true;
  810. }
  811. }
  812. (*this)[ZT_PACKET_IDX_VERB] &= (char)(~ZT_PROTO_VERB_FLAG_COMPRESSED);
  813. return false;
  814. }
  815. /**
  816. * Attempt to decompress payload if it is compressed (must be unencrypted)
  817. *
  818. * If payload is compressed, it is decompressed and the compressed verb
  819. * flag is cleared. Otherwise nothing is done and true is returned.
  820. *
  821. * @return True if data is now decompressed and valid, false on error
  822. */
  823. inline bool uncompress()
  824. {
  825. unsigned char buf[ZT_PROTO_MAX_PACKET_LENGTH];
  826. if ((compressed())&&(size() >= ZT_PROTO_MIN_PACKET_LENGTH)) {
  827. if (size() > ZT_PACKET_IDX_PAYLOAD) {
  828. unsigned int compLen = size() - ZT_PACKET_IDX_PAYLOAD;
  829. int ucl = LZ4_uncompress_unknownOutputSize((const char *)field(ZT_PACKET_IDX_PAYLOAD,compLen),(char *)buf,compLen,sizeof(buf));
  830. if ((ucl > 0)&&(ucl <= (int)(capacity() - ZT_PACKET_IDX_PAYLOAD))) {
  831. setSize((unsigned int)ucl + ZT_PACKET_IDX_PAYLOAD);
  832. memcpy(field(ZT_PACKET_IDX_PAYLOAD,(unsigned int)ucl),buf,ucl);
  833. } else return false;
  834. }
  835. (*this)[ZT_PACKET_IDX_VERB] &= ~ZT_PROTO_VERB_FLAG_COMPRESSED;
  836. }
  837. return true;
  838. }
  839. private:
  840. /**
  841. * Deterministically mangle a 256-bit crypto key based on packet
  842. *
  843. * @param in Input key (32 bytes)
  844. * @param out Output buffer (32 bytes)
  845. */
  846. inline void _mangleKey(const unsigned char *in,unsigned char *out) const
  847. {
  848. // IV and source/destination addresses. Salsa uses the IV natively
  849. // so this is redundant there, but not harmful. But Poly1305 depends
  850. // on the key being mangled with the IV. Using the source and
  851. // destination addresses bifurcates the key space into a different
  852. // key space for each direction of the conversation.
  853. for(unsigned int i=0;i<18;++i) // 8 + (ZT_ADDRESS_LENGTH * 2) == 18
  854. out[i] = in[i] ^ (unsigned char)(*this)[i];
  855. // Flags, but with hop count masked off. Hop count is altered by forwarding
  856. // nodes. It's one of the only parts of a packet modifiable by people
  857. // without the key.
  858. out[18] = in[18] ^ ((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & 0xf8);
  859. // Raw packet size in bytes -- thus each packet size defines a new
  860. // key space.
  861. out[19] = in[19] ^ (unsigned char)(size() & 0xff);
  862. out[20] = in[20] ^ (unsigned char)((size() >> 8) & 0xff); // little endian
  863. // Rest of raw key is used unchanged
  864. for(unsigned int i=21;i<32;++i)
  865. out[i] = in[i];
  866. }
  867. };
  868. } // namespace ZeroTier
  869. #endif