2
0

netInterface.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "sim/netConnection.h"
  24. #include "sim/netInterface.h"
  25. #include "core/stream/bitStream.h"
  26. #include "math/mRandom.h"
  27. #include "core/util/journal/journal.h"
  28. #include "console/engineAPI.h"
  29. #ifdef GGC_PLUGIN
  30. #include "GGCNatTunnel.h"
  31. extern void HandleGGCPacket(NetAddress* addr, unsigned char* data, U32 dataSize);
  32. #endif
  33. NetInterface *GNet = NULL;
  34. NetInterface::NetInterface()
  35. {
  36. AssertFatal(GNet == NULL, "ERROR: Multiple net interfaces declared.");
  37. GNet = this;
  38. mLastTimeoutCheckTime = 0;
  39. mAllowConnections = false;
  40. dMemset(mRandomHashData, 0, sizeof(mRandomHashData));
  41. mRandomDataInitialized = false;
  42. }
  43. void NetInterface::initRandomData()
  44. {
  45. mRandomDataInitialized = true;
  46. U32 seed = Platform::getRealMilliseconds();
  47. if(Journal::IsPlaying())
  48. Journal::Read(&seed);
  49. else if(Journal::IsRecording())
  50. Journal::Write(seed);
  51. MRandomR250 myRandom(seed);
  52. for(U32 i = 0; i < 12; i++)
  53. mRandomHashData[i] = myRandom.randI();
  54. }
  55. void NetInterface::addPendingConnection(NetConnection *connection)
  56. {
  57. Con::printf("Adding a pending connection");
  58. mPendingConnections.push_back(connection);
  59. }
  60. void NetInterface::removePendingConnection(NetConnection *connection)
  61. {
  62. for(U32 i = 0; i < mPendingConnections.size(); i++)
  63. if(mPendingConnections[i] == connection)
  64. mPendingConnections.erase(i);
  65. }
  66. NetConnection *NetInterface::findPendingConnection(const NetAddress *address, U32 connectSequence)
  67. {
  68. for(U32 i = 0; i < mPendingConnections.size(); i++)
  69. if(Net::compareAddresses(address, mPendingConnections[i]->getNetAddress()) &&
  70. connectSequence == mPendingConnections[i]->getSequence())
  71. return mPendingConnections[i];
  72. return NULL;
  73. }
  74. void NetInterface::processPacketReceiveEvent(NetAddress srcAddress, RawData packetData)
  75. {
  76. U32 dataSize = packetData.size;
  77. BitStream pStream(packetData.data, dataSize);
  78. // Determine what to do with this packet:
  79. if(packetData.data[0] & 0x01) // it's a protocol packet...
  80. {
  81. // if the LSB of the first byte is set, it's a game data packet
  82. // so pass it to the appropriate connection.
  83. // lookup the connection in the addressTable
  84. NetConnection *conn = NetConnection::lookup(&srcAddress);
  85. if(conn)
  86. conn->processRawPacket(&pStream);
  87. }
  88. else
  89. {
  90. // Otherwise, it's either a game info packet or a
  91. // connection handshake packet.
  92. U8 packetType;
  93. pStream.read(&packetType);
  94. NetAddress *addr = &srcAddress;
  95. if(packetType <= GameHeartbeat || packetType == MasterServerExtendedListResponse)
  96. handleInfoPacket(addr, packetType, &pStream);
  97. #ifdef GGC_PLUGIN
  98. else if (packetType == GGCPacket)
  99. {
  100. HandleGGCPacket(addr, (U8*)packetData.data, dataSize);
  101. }
  102. #endif
  103. else
  104. {
  105. // check if there's a connection already:
  106. switch(packetType)
  107. {
  108. case ConnectChallengeRequest:
  109. handleConnectChallengeRequest(addr, &pStream);
  110. break;
  111. case ConnectRequest:
  112. handleConnectRequest(addr, &pStream);
  113. break;
  114. case ConnectChallengeResponse:
  115. handleConnectChallengeResponse(addr, &pStream);
  116. break;
  117. case ConnectAccept:
  118. handleConnectAccept(addr, &pStream);
  119. break;
  120. case Disconnect:
  121. handleDisconnect(addr, &pStream);
  122. break;
  123. case ConnectReject:
  124. handleConnectReject(addr, &pStream);
  125. break;
  126. }
  127. }
  128. }
  129. }
  130. //-----------------------------------------------------------------------------
  131. //-----------------------------------------------------------------------------
  132. // Connection handshaking basic overview:
  133. // The torque engine does a two phase connect handshake to
  134. // prevent a spoofed source address Denial-of-Service (DOS) attack
  135. //
  136. // Basically, the initiator of a connection (client) sends a
  137. // Connect Challenge Request packet to the server to initiate the connection
  138. // The server then hashes the source address of the client request
  139. // with some random magic server data to come up with a 16-byte key that
  140. // the client can then use to gain entry to the server.
  141. // This way there are no partially active connection records on the
  142. // server at all.
  143. //
  144. // The client then sends a Connect Request packet to the server,
  145. // including any game specific data necessary to start a connection (a
  146. // server password, for instance), along with the key the server sent
  147. // on the Connect Challenge Response packet.
  148. //
  149. // The server, on receipt of the Connect Request, compares the
  150. // entry key with a computed key, makes sure it can create the requested
  151. // NetConnection subclass, and then passes all processing on to the connection
  152. // instance.
  153. //
  154. // If the subclass reads and accepts he connect request successfully, the
  155. // server sends a Connect Accept packet - otherwise the connection
  156. // is rejected with the sendConnectReject function
  157. //-----------------------------------------------------------------------------
  158. //-----------------------------------------------------------------------------
  159. void NetInterface::sendConnectChallengeRequest(NetConnection *conn)
  160. {
  161. Con::printf("Sending Connect challenge Request");
  162. BitStream *out = BitStream::getPacketStream();
  163. out->write(U8(ConnectChallengeRequest));
  164. out->write(conn->getSequence());
  165. conn->mConnectSendCount++;
  166. conn->mConnectLastSendTime = Platform::getVirtualMilliseconds();
  167. BitStream::sendPacketStream(conn->getNetAddress());
  168. }
  169. void NetInterface::handleConnectChallengeRequest(const NetAddress *addr, BitStream *stream)
  170. {
  171. char buf[256];
  172. Net::addressToString(addr, buf);
  173. Con::printf("Got Connect challenge Request from %s", buf);
  174. if(!mAllowConnections)
  175. return;
  176. U32 connectSequence;
  177. stream->read(&connectSequence);
  178. if(!mRandomDataInitialized)
  179. initRandomData();
  180. U32 addressDigest[4];
  181. computeNetMD5(addr, connectSequence, addressDigest);
  182. BitStream *out = BitStream::getPacketStream();
  183. out->write(U8(ConnectChallengeResponse));
  184. out->write(connectSequence);
  185. out->write(addressDigest[0]);
  186. out->write(addressDigest[1]);
  187. out->write(addressDigest[2]);
  188. out->write(addressDigest[3]);
  189. BitStream::sendPacketStream(addr);
  190. }
  191. //-----------------------------------------------------------------------------
  192. void NetInterface::handleConnectChallengeResponse(const NetAddress *address, BitStream *stream)
  193. {
  194. Con::printf("Got Connect challenge Response");
  195. U32 connectSequence;
  196. stream->read(&connectSequence);
  197. NetConnection *conn = findPendingConnection(address, connectSequence);
  198. if(!conn || conn->getConnectionState() != NetConnection::AwaitingChallengeResponse)
  199. return;
  200. U32 addressDigest[4];
  201. stream->read(&addressDigest[0]);
  202. stream->read(&addressDigest[1]);
  203. stream->read(&addressDigest[2]);
  204. stream->read(&addressDigest[3]);
  205. conn->setAddressDigest(addressDigest);
  206. conn->setConnectionState(NetConnection::AwaitingConnectResponse);
  207. conn->mConnectSendCount = 0;
  208. Con::printf("Sending Connect Request");
  209. sendConnectRequest(conn);
  210. }
  211. //-----------------------------------------------------------------------------
  212. void NetInterface::sendConnectRequest(NetConnection *conn)
  213. {
  214. BitStream *out = BitStream::getPacketStream();
  215. out->write(U8(ConnectRequest));
  216. out->write(conn->getSequence());
  217. U32 addressDigest[4];
  218. conn->getAddressDigest(addressDigest);
  219. out->write(addressDigest[0]);
  220. out->write(addressDigest[1]);
  221. out->write(addressDigest[2]);
  222. out->write(addressDigest[3]);
  223. out->writeString(conn->getClassName());
  224. conn->writeConnectRequest(out);
  225. conn->mConnectSendCount++;
  226. conn->mConnectLastSendTime = Platform::getVirtualMilliseconds();
  227. BitStream::sendPacketStream(conn->getNetAddress());
  228. }
  229. //-----------------------------------------------------------------------------
  230. void NetInterface::handleConnectRequest(const NetAddress *address, BitStream *stream)
  231. {
  232. if(!mAllowConnections)
  233. return;
  234. Con::printf("Got Connect Request");
  235. U32 connectSequence;
  236. stream->read(&connectSequence);
  237. // see if the connection is in the main connection table:
  238. NetConnection *connect = NetConnection::lookup(address);
  239. if(connect && connect->getSequence() == connectSequence)
  240. {
  241. sendConnectAccept(connect);
  242. return;
  243. }
  244. U32 addressDigest[4];
  245. U32 computedAddressDigest[4];
  246. stream->read(&addressDigest[0]);
  247. stream->read(&addressDigest[1]);
  248. stream->read(&addressDigest[2]);
  249. stream->read(&addressDigest[3]);
  250. computeNetMD5(address, connectSequence, computedAddressDigest);
  251. if(addressDigest[0] != computedAddressDigest[0] ||
  252. addressDigest[1] != computedAddressDigest[1] ||
  253. addressDigest[2] != computedAddressDigest[2] ||
  254. addressDigest[3] != computedAddressDigest[3])
  255. return; // bogus connection attempt
  256. if(connect)
  257. {
  258. if(connect->getSequence() > connectSequence)
  259. return; // the existing connection should be kept - the incoming request is stale.
  260. else
  261. connect->deleteObject(); // disconnect this one, and allow the new one to be created.
  262. }
  263. char connectionClass[255];
  264. stream->readString(connectionClass);
  265. ConsoleObject *co = ConsoleObject::create(connectionClass);
  266. NetConnection *conn = dynamic_cast<NetConnection *>(co);
  267. if(!conn || !conn->canRemoteCreate())
  268. {
  269. delete co;
  270. return;
  271. }
  272. conn->registerObject();
  273. conn->setNetAddress(address);
  274. conn->setNetworkConnection(true);
  275. conn->setSequence(connectSequence);
  276. const char *errorString = NULL;
  277. if(!conn->readConnectRequest(stream, &errorString))
  278. {
  279. sendConnectReject(conn, errorString);
  280. conn->deleteObject();
  281. return;
  282. }
  283. conn->setNetworkConnection(true);
  284. conn->onConnectionEstablished(false);
  285. conn->setEstablished();
  286. conn->setConnectSequence(connectSequence);
  287. sendConnectAccept(conn);
  288. }
  289. //-----------------------------------------------------------------------------
  290. void NetInterface::sendConnectAccept(NetConnection *conn)
  291. {
  292. BitStream *out = BitStream::getPacketStream();
  293. out->write(U8(ConnectAccept));
  294. out->write(conn->getSequence());
  295. conn->writeConnectAccept(out);
  296. BitStream::sendPacketStream(conn->getNetAddress());
  297. }
  298. void NetInterface::handleConnectAccept(const NetAddress *address, BitStream *stream)
  299. {
  300. U32 connectSequence;
  301. stream->read(&connectSequence);
  302. NetConnection *conn = findPendingConnection(address, connectSequence);
  303. if(!conn || conn->getConnectionState() != NetConnection::AwaitingConnectResponse)
  304. return;
  305. const char *errorString = NULL;
  306. if(!conn->readConnectAccept(stream, &errorString))
  307. {
  308. conn->handleStartupError(errorString);
  309. removePendingConnection(conn);
  310. conn->deleteObject();
  311. return;
  312. }
  313. removePendingConnection(conn); // remove from the pending connection list
  314. conn->setNetworkConnection(true);
  315. conn->onConnectionEstablished(true); // notify the connection that it has been established
  316. conn->setEstablished(); // installs the connection in the connection table, and causes pings/timeouts to happen
  317. conn->setConnectSequence(connectSequence);
  318. }
  319. void NetInterface::sendConnectReject(NetConnection *conn, const char *reason)
  320. {
  321. if(!reason)
  322. return; // if the stream is NULL, we reject silently
  323. BitStream *out = BitStream::getPacketStream();
  324. out->write(U8(ConnectReject));
  325. out->write(conn->getSequence());
  326. out->writeString(reason);
  327. BitStream::sendPacketStream(conn->getNetAddress());
  328. }
  329. void NetInterface::handleConnectReject(const NetAddress *address, BitStream *stream)
  330. {
  331. U32 connectSequence;
  332. stream->read(&connectSequence);
  333. NetConnection *conn = findPendingConnection(address, connectSequence);
  334. if(!conn || (conn->getConnectionState() != NetConnection::AwaitingChallengeResponse &&
  335. conn->getConnectionState() != NetConnection::AwaitingConnectResponse))
  336. return;
  337. removePendingConnection(conn);
  338. char reason[256];
  339. stream->readString(reason);
  340. conn->onConnectionRejected(reason);
  341. conn->deleteObject();
  342. }
  343. void NetInterface::handleDisconnect(const NetAddress *address, BitStream *stream)
  344. {
  345. NetConnection *conn = NetConnection::lookup(address);
  346. if(!conn)
  347. return;
  348. U32 connectSequence;
  349. char reason[256];
  350. stream->read(&connectSequence);
  351. stream->readString(reason);
  352. if(conn->getSequence() != connectSequence)
  353. return;
  354. conn->onDisconnect(reason);
  355. conn->deleteObject();
  356. }
  357. void NetInterface::handleInfoPacket(const NetAddress *address, U8 packetType, BitStream *stream)
  358. {
  359. }
  360. void NetInterface::processClient()
  361. {
  362. NetObject::collapseDirtyList(); // collapse all the mask bits...
  363. for(NetConnection *walk = NetConnection::getConnectionList();
  364. walk; walk = walk->getNext())
  365. {
  366. if(walk->isConnectionToServer() && (walk->isLocalConnection() || walk->isNetworkConnection()))
  367. walk->checkPacketSend(false);
  368. }
  369. }
  370. void NetInterface::processServer()
  371. {
  372. NetObject::collapseDirtyList(); // collapse all the mask bits...
  373. for(NetConnection *walk = NetConnection::getConnectionList();
  374. walk; walk = walk->getNext())
  375. {
  376. if(!walk->isConnectionToServer() && (walk->isLocalConnection() || walk->isNetworkConnection()))
  377. walk->checkPacketSend(false);
  378. }
  379. }
  380. void NetInterface::startConnection(NetConnection *conn)
  381. {
  382. addPendingConnection(conn);
  383. conn->mConnectionSendCount = 0;
  384. conn->setConnectSequence(Platform::getVirtualMilliseconds());
  385. conn->setConnectionState(NetConnection::AwaitingChallengeResponse);
  386. // This is a the client side of the connection, so set the connection to
  387. // server flag. We need to set this early so that if the connection times
  388. // out, its onRemove() will handle the cleanup properly.
  389. conn->setIsConnectionToServer();
  390. // Everything set, so send off the request.
  391. sendConnectChallengeRequest(conn);
  392. }
  393. void NetInterface::sendDisconnectPacket(NetConnection *conn, const char *reason)
  394. {
  395. Con::printf("Issuing Disconnect packet.");
  396. // send a disconnect packet...
  397. U32 connectSequence = conn->getSequence();
  398. BitStream *out = BitStream::getPacketStream();
  399. out->write(U8(Disconnect));
  400. out->write(connectSequence);
  401. out->writeString(reason);
  402. BitStream::sendPacketStream(conn->getNetAddress());
  403. }
  404. void NetInterface::checkTimeouts()
  405. {
  406. U32 time = Platform::getVirtualMilliseconds();
  407. if(time > mLastTimeoutCheckTime + TimeoutCheckInterval)
  408. {
  409. for(U32 i = 0; i < mPendingConnections.size();)
  410. {
  411. NetConnection *pending = mPendingConnections[i];
  412. if(pending->getConnectionState() == NetConnection::AwaitingChallengeResponse &&
  413. time > pending->mConnectLastSendTime + ChallengeRetryTime)
  414. {
  415. if(pending->mConnectSendCount > ChallengeRetryCount)
  416. {
  417. pending->onConnectTimedOut();
  418. removePendingConnection(pending);
  419. pending->deleteObject();
  420. continue;
  421. }
  422. else
  423. sendConnectChallengeRequest(pending);
  424. }
  425. else if(pending->getConnectionState() == NetConnection::AwaitingConnectResponse &&
  426. time > pending->mConnectLastSendTime + ConnectRetryTime)
  427. {
  428. if(pending->mConnectSendCount > ConnectRetryCount)
  429. {
  430. pending->onConnectTimedOut();
  431. removePendingConnection(pending);
  432. pending->deleteObject();
  433. continue;
  434. }
  435. else
  436. sendConnectRequest(pending);
  437. }
  438. i++;
  439. }
  440. mLastTimeoutCheckTime = time;
  441. NetConnection *walk = NetConnection::getConnectionList();
  442. while(walk)
  443. {
  444. NetConnection *next = walk->getNext();
  445. if(walk->checkTimeout(time))
  446. {
  447. // this baddie timed out
  448. walk->onTimedOut();
  449. walk->deleteObject();
  450. }
  451. walk = next;
  452. }
  453. }
  454. }
  455. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  456. #define F2(x, y, z) F1(z, x, y)
  457. #define F3(x, y, z) (x ^ y ^ z)
  458. #define F4(x, y, z) (y ^ (x | ~z))
  459. inline U32 rotlFixed(U32 x, U32 y)
  460. {
  461. return (x >> y) | (x << (32 - y));
  462. }
  463. #define MD5STEP(f, w, x, y, z, data, s) w = rotlFixed(w + f(x, y, z) + data, s) + x
  464. void NetInterface::computeNetMD5(const NetAddress *address, U32 connectSequence, U32 digest[4])
  465. {
  466. digest[0] = 0x67452301L;
  467. digest[1] = 0xefcdab89L;
  468. digest[2] = 0x98badcfeL;
  469. digest[3] = 0x10325476L;
  470. U32 a, b, c, d;
  471. a=digest[0];
  472. b=digest[1];
  473. c=digest[2];
  474. d=digest[3];
  475. U32 in[16];
  476. in[0] = address->type;
  477. in[1] = address->getHash();
  478. in[2] = address->port;
  479. in[3] = connectSequence;
  480. for(U32 i = 0; i < 12; i++)
  481. in[i + 4] = mRandomHashData[i];
  482. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  483. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  484. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  485. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  486. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  487. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  488. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  489. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  490. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  491. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  492. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  493. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  494. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  495. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  496. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  497. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  498. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  499. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  500. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  501. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  502. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  503. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  504. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  505. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  506. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  507. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  508. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  509. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  510. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  511. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  512. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  513. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  514. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  515. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  516. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  517. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  518. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  519. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  520. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  521. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  522. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  523. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  524. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  525. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  526. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  527. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  528. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  529. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  530. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  531. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  532. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  533. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  534. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  535. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  536. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  537. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  538. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  539. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  540. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  541. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  542. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  543. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  544. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  545. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  546. digest[0]+=a;
  547. digest[1]+=b;
  548. digest[2]+=c;
  549. digest[3]+=d;
  550. }
  551. ConsoleFunctionGroupBegin(NetInterface, "Global control functions for the netInterfaces.");
  552. DefineEngineFunction( allowConnections, void, ( bool allow ), , "allowConnections(bool allow)"
  553. "@brief Sets whether or not the global NetInterface allows connections from remote hosts.\n\n"
  554. "@param allow Set to true to allow remote connections.\n"
  555. "@ingroup Networking\n")
  556. {
  557. GNet->setAllowsConnections(allow);
  558. }
  559. ConsoleFunctionGroupEnd(NetInterface);