Browse Source

Merge pull request #239 from EinMByte/master

Split source code in directories
pull/247/head
Riccardo Spagni 9 years ago
parent
commit
d9dc406d18
  1. 9
      .gitignore
  2. 66
      AESNIMacros.h
  3. 8
      AddressBook.cpp
  4. 6
      AddressBook.h
  5. 2
      BOB.cpp
  6. 4
      ClientContext.cpp
  7. 11
      Daemon.cpp
  8. 4
      DaemonLinux.cpp
  9. 6
      DaemonWin32.cpp
  10. 4
      Datagram.cpp
  11. 8
      Destination.cpp
  12. 4
      Destination.h
  13. 8
      Garlic.cpp
  14. 4
      Garlic.h
  15. 4
      HTTPProxy.cpp
  16. 12
      HTTPServer.cpp
  17. 11
      I2NPProtocol.cpp
  18. 2
      I2NPProtocol.h
  19. 8
      I2PControl.cpp
  20. 3
      I2PTunnel.cpp
  21. 16
      Identity.cpp
  22. 14
      Identity.h
  23. 10
      LeaseSet.cpp
  24. 12
      Makefile
  25. 2
      Makefile.bsd
  26. 2
      Makefile.linux
  27. 2
      Makefile.osx
  28. 22
      NetDb.cpp
  29. 6
      NetDb.h
  30. 4
      NetDbRequests.cpp
  31. 6
      Profiling.cpp
  32. 8
      Reseed.cpp
  33. 2
      Reseed.h
  34. 6
      RouterContext.cpp
  35. 18
      RouterInfo.cpp
  36. 8
      SAM.cpp
  37. 2
      SOCKS.cpp
  38. 6
      Streaming.cpp
  39. 4
      Streaming.h
  40. 11
      TODO
  41. 4
      UPnP.cpp
  42. 2
      UPnP.h
  43. 357
      aes.cpp
  44. 8
      api.cpp
  45. 37
      build/CMakeLists.txt
  46. 0
      crypto/CryptoConst.cpp
  47. 0
      crypto/CryptoConst.h
  48. 2
      crypto/ElGamal.h
  49. 2
      crypto/Signature.cpp
  50. 0
      crypto/Signature.h
  51. 222
      crypto/aes.cpp
  52. 44
      crypto/aes.h
  53. 0
      crypto/hmac.h
  54. 27
      filelist.mk
  55. 6
      tests/Base64.cpp
  56. 2
      tests/Utility.cpp
  57. 10
      transport/NTCPSession.cpp
  58. 2
      transport/NTCPSession.h
  59. 4
      transport/SSU.cpp
  60. 4
      transport/SSU.h
  61. 4
      transport/SSUData.cpp
  62. 0
      transport/SSUData.h
  63. 6
      transport/SSUSession.cpp
  64. 4
      transport/SSUSession.h
  65. 0
      transport/TransportSession.h
  66. 4
      transport/Transports.cpp
  67. 0
      transport/Transports.h
  68. 6
      tunnel/TransitTunnel.cpp
  69. 2
      tunnel/TransitTunnel.h
  70. 8
      tunnel/Tunnel.cpp
  71. 2
      tunnel/Tunnel.h
  72. 2
      tunnel/TunnelBase.h
  73. 4
      tunnel/TunnelConfig.h
  74. 88
      tunnel/TunnelCrypto.cpp
  75. 49
      tunnel/TunnelCrypto.h
  76. 6
      tunnel/TunnelEndpoint.cpp
  77. 0
      tunnel/TunnelEndpoint.h
  78. 6
      tunnel/TunnelGateway.cpp
  79. 0
      tunnel/TunnelGateway.h
  80. 8
      tunnel/TunnelPool.cpp
  81. 0
      tunnel/TunnelPool.h
  82. 0
      util/I2PEndian.cpp
  83. 0
      util/I2PEndian.h
  84. 0
      util/LittleBigEndian.h
  85. 0
      util/Log.cpp
  86. 0
      util/Log.h
  87. 0
      util/Queue.h
  88. 0
      util/Timestamp.h
  89. 2
      util/base64.cpp
  90. 2
      util/base64.h
  91. 0
      util/util.cpp
  92. 0
      util/util.h

9
.gitignore vendored

@ -8,6 +8,15 @@ netDb
tunnels.cfg tunnels.cfg
tests/tests tests/tests
# Build files
build/CMakeCache.txt
build/CMakeFiles/*
build/cmake_install.cmake
build/i2pd
build/libcommon.a
build/libi2pd.a
# Autotools # Autotools
autom4te.cache autom4te.cache
.deps .deps

66
AESNIMacros.h

@ -0,0 +1,66 @@
#ifndef AESNIMACROS_H__
#define AESNIMACROS_H__
#define KeyExpansion256(round0,round1) \
"pshufd $0xff, %%xmm2, %%xmm2 \n" \
"movaps %%xmm1, %%xmm4 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pxor %%xmm2, %%xmm1 \n" \
"movaps %%xmm1, "#round0"(%[sched]) \n" \
"aeskeygenassist $0, %%xmm1, %%xmm4 \n" \
"pshufd $0xaa, %%xmm4, %%xmm2 \n" \
"movaps %%xmm3, %%xmm4 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pxor %%xmm2, %%xmm3 \n" \
"movaps %%xmm3, "#round1"(%[sched]) \n"
#define EncryptAES256(sched) \
"pxor (%["#sched"]), %%xmm0 \n" \
"aesenc 16(%["#sched"]), %%xmm0 \n" \
"aesenc 32(%["#sched"]), %%xmm0 \n" \
"aesenc 48(%["#sched"]), %%xmm0 \n" \
"aesenc 64(%["#sched"]), %%xmm0 \n" \
"aesenc 80(%["#sched"]), %%xmm0 \n" \
"aesenc 96(%["#sched"]), %%xmm0 \n" \
"aesenc 112(%["#sched"]), %%xmm0 \n" \
"aesenc 128(%["#sched"]), %%xmm0 \n" \
"aesenc 144(%["#sched"]), %%xmm0 \n" \
"aesenc 160(%["#sched"]), %%xmm0 \n" \
"aesenc 176(%["#sched"]), %%xmm0 \n" \
"aesenc 192(%["#sched"]), %%xmm0 \n" \
"aesenc 208(%["#sched"]), %%xmm0 \n" \
"aesenclast 224(%["#sched"]), %%xmm0 \n"
#define DecryptAES256(sched) \
"pxor 224(%["#sched"]), %%xmm0 \n" \
"aesdec 208(%["#sched"]), %%xmm0 \n" \
"aesdec 192(%["#sched"]), %%xmm0 \n" \
"aesdec 176(%["#sched"]), %%xmm0 \n" \
"aesdec 160(%["#sched"]), %%xmm0 \n" \
"aesdec 144(%["#sched"]), %%xmm0 \n" \
"aesdec 128(%["#sched"]), %%xmm0 \n" \
"aesdec 112(%["#sched"]), %%xmm0 \n" \
"aesdec 96(%["#sched"]), %%xmm0 \n" \
"aesdec 80(%["#sched"]), %%xmm0 \n" \
"aesdec 64(%["#sched"]), %%xmm0 \n" \
"aesdec 48(%["#sched"]), %%xmm0 \n" \
"aesdec 32(%["#sched"]), %%xmm0 \n" \
"aesdec 16(%["#sched"]), %%xmm0 \n" \
"aesdeclast (%["#sched"]), %%xmm0 \n"
#define CallAESIMC(offset) \
"movaps "#offset"(%[shed]), %%xmm0 \n" \
"aesimc %%xmm0, %%xmm0 \n" \
"movaps %%xmm0, "#offset"(%[shed]) \n"
#endif

8
AddressBook.cpp

@ -8,10 +8,10 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include "base64.h" #include "util/base64.h"
#include "util.h" #include "util/util.h"
#include "Identity.h" #include "Identity.h"
#include "Log.h" #include "util/Log.h"
#include "NetDb.h" #include "NetDb.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "AddressBook.h" #include "AddressBook.h"
@ -215,7 +215,7 @@ namespace client
auto pos = address.find(".b32.i2p"); auto pos = address.find(".b32.i2p");
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
Base32ToByteStream (address.c_str(), pos, ident, 32); i2p::util::Base32ToByteStream (address.c_str(), pos, ident, 32);
return true; return true;
} }
else else

6
AddressBook.h

@ -8,10 +8,10 @@
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "base64.h" #include "util/base64.h"
#include "util.h" #include "util/util.h"
#include "Identity.h" #include "Identity.h"
#include "Log.h" #include "util/Log.h"
namespace i2p namespace i2p
{ {

2
BOB.cpp

@ -1,6 +1,6 @@
#include <string.h> #include <string.h>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "Log.h" #include "util/Log.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "BOB.h" #include "BOB.h"

4
ClientContext.cpp

@ -2,8 +2,8 @@
#include <iostream> #include <iostream>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ini_parser.hpp>
#include "util.h" #include "util/util.h"
#include "Log.h" #include "util/Log.h"
#include "Identity.h" #include "Identity.h"
#include "ClientContext.h" #include "ClientContext.h"

11
Daemon.cpp

@ -2,17 +2,16 @@
#include "Daemon.h" #include "Daemon.h"
#include "Log.h" #include "util/Log.h"
#include "base64.h"
#include "version.h" #include "version.h"
#include "Transports.h" #include "transport/Transports.h"
#include "NTCPSession.h" #include "transport/NTCPSession.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "NetDb.h" #include "NetDb.h"
#include "Garlic.h" #include "Garlic.h"
#include "util.h" #include "util/util.h"
#include "Streaming.h" #include "Streaming.h"
#include "Destination.h" #include "Destination.h"
#include "HTTPServer.h" #include "HTTPServer.h"

4
DaemonLinux.cpp

@ -8,8 +8,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "Log.h" #include "util/Log.h"
#include "util.h" #include "util/util.h"
void handle_signal(int sig) void handle_signal(int sig)

6
DaemonWin32.cpp

@ -1,6 +1,6 @@
#include "Daemon.h" #include "Daemon.h"
#include "util.h" #include "util/util.h"
#include "Log.h" #include "util/Log.h"
#ifdef _WIN32 #ifdef _WIN32
@ -80,4 +80,4 @@ namespace i2p
} }
} }
#endif #endif

4
Datagram.cpp

@ -2,8 +2,8 @@
#include <vector> #include <vector>
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include <cryptopp/gzip.h> #include <cryptopp/gzip.h>
#include "Log.h" #include "util/Log.h"
#include "TunnelBase.h" #include "tunnel/TunnelBase.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Destination.h" #include "Destination.h"
#include "Datagram.h" #include "Datagram.h"

8
Destination.cpp

@ -1,10 +1,10 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "Log.h" #include "util/Log.h"
#include "util.h" #include "util/util.h"
#include "ElGamal.h" #include "crypto/ElGamal.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "NetDb.h" #include "NetDb.h"
#include "AddressBook.h" #include "AddressBook.h"
#include "Destination.h" #include "Destination.h"

4
Destination.h

@ -10,8 +10,8 @@
#include <functional> #include <functional>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "Identity.h" #include "Identity.h"
#include "TunnelPool.h" #include "tunnel/TunnelPool.h"
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "Garlic.h" #include "Garlic.h"
#include "NetDb.h" #include "NetDb.h"

8
Garlic.cpp

@ -1,12 +1,12 @@
#include <inttypes.h> #include <inttypes.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <map> #include <map>
#include <string> #include <string>
#include "RouterContext.h" #include "RouterContext.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "TunnelPool.h" #include "tunnel/TunnelPool.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "Destination.h" #include "Destination.h"
#include "Garlic.h" #include "Garlic.h"

4
Garlic.h

@ -9,10 +9,10 @@
#include <mutex> #include <mutex>
#include <memory> #include <memory>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include "aes.h" #include "crypto/aes.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "Queue.h" #include "util/Queue.h"
#include "Identity.h" #include "Identity.h"
namespace i2p namespace i2p

4
HTTPProxy.cpp

@ -5,12 +5,12 @@
#include <string> #include <string>
#include <atomic> #include <atomic>
#include "HTTPProxy.h" #include "HTTPProxy.h"
#include "util.h" #include "util/util.h"
#include "Identity.h" #include "Identity.h"
#include "Streaming.h" #include "Streaming.h"
#include "Destination.h" #include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "I2PTunnel.h" #include "I2PTunnel.h"
namespace i2p namespace i2p

12
HTTPServer.cpp

@ -1,13 +1,13 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "base64.h" #include "util/base64.h"
#include "Log.h" #include "util/Log.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "TransitTunnel.h" #include "tunnel/TransitTunnel.h"
#include "Transports.h" #include "transport/Transports.h"
#include "NetDb.h" #include "NetDb.h"
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "Streaming.h" #include "Streaming.h"
#include "Destination.h" #include "Destination.h"
#include "RouterContext.h" #include "RouterContext.h"

11
I2NPProtocol.cpp

@ -1,14 +1,13 @@
#include <string.h> #include <string.h>
#include <atomic> #include <atomic>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <cryptopp/gzip.h> #include <cryptopp/gzip.h>
#include "ElGamal.h" #include "crypto/ElGamal.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "NetDb.h" #include "NetDb.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "base64.h" #include "transport/Transports.h"
#include "Transports.h"
#include "Garlic.h" #include "Garlic.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"

2
I2NPProtocol.h

@ -6,7 +6,7 @@
#include <set> #include <set>
#include <memory> #include <memory>
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "Identity.h" #include "Identity.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "LeaseSet.h" #include "LeaseSet.h"

8
I2PControl.cpp

@ -9,13 +9,13 @@
#if !GCC47_BOOST149 #if !GCC47_BOOST149
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#endif #endif
#include "Log.h" #include "util/Log.h"
#include "NetDb.h" #include "NetDb.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Daemon.h" #include "Daemon.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "Transports.h" #include "transport/Transports.h"
#include "version.h" #include "version.h"
namespace i2p namespace i2p

3
I2PTunnel.cpp

@ -1,6 +1,5 @@
#include <cassert> #include <cassert>
#include "base64.h" #include "util/Log.h"
#include "Log.h"
#include "Destination.h" #include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "I2PTunnel.h" #include "I2PTunnel.h"

16
Identity.cpp

@ -3,12 +3,12 @@
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include "base64.h" #include "util/base64.h"
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "ElGamal.h" #include "crypto/ElGamal.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Identity.h" #include "Identity.h"
#include "I2PEndian.h" #include "util/I2PEndian.h"
namespace i2p namespace i2p
{ {
@ -237,7 +237,7 @@ namespace data
size_t IdentityEx::FromBase64(const std::string& s) size_t IdentityEx::FromBase64(const std::string& s)
{ {
uint8_t buf[1024]; uint8_t buf[1024];
auto len = Base64ToByteStream (s.c_str(), s.length(), buf, 1024); auto len = i2p::util::Base64ToByteStream (s.c_str(), s.length(), buf, 1024);
return FromBuffer (buf, len); return FromBuffer (buf, len);
} }
@ -246,7 +246,7 @@ namespace data
uint8_t buf[1024]; uint8_t buf[1024];
char str[1536]; char str[1536];
size_t l = ToBuffer (buf, 1024); size_t l = ToBuffer (buf, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, str, 1536); size_t l1 = i2p::util::ByteStreamToBase64 (buf, l, str, 1536);
str[l1] = 0; str[l1] = 0;
return std::string (str); return std::string (str);
} }
@ -420,7 +420,7 @@ namespace data
size_t PrivateKeys::FromBase64(const std::string& s) size_t PrivateKeys::FromBase64(const std::string& s)
{ {
uint8_t * buf = new uint8_t[s.length ()]; uint8_t * buf = new uint8_t[s.length ()];
size_t l = i2p::data::Base64ToByteStream (s.c_str (), s.length (), buf, s.length ()); size_t l = i2p::util::Base64ToByteStream (s.c_str (), s.length (), buf, s.length ());
size_t ret = FromBuffer (buf, l); size_t ret = FromBuffer (buf, l);
delete[] buf; delete[] buf;
return ret; return ret;
@ -431,7 +431,7 @@ namespace data
uint8_t * buf = new uint8_t[GetFullLen ()]; uint8_t * buf = new uint8_t[GetFullLen ()];
char * str = new char[GetFullLen ()*2]; char * str = new char[GetFullLen ()*2];
size_t l = ToBuffer (buf, GetFullLen ()); size_t l = ToBuffer (buf, GetFullLen ());
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, str, GetFullLen ()*2); size_t l1 = i2p::util::ByteStreamToBase64 (buf, l, str, GetFullLen ()*2);
str[l1] = 0; str[l1] = 0;
delete[] buf; delete[] buf;
std::string ret(str); std::string ret(str);

14
Identity.h

@ -5,9 +5,9 @@
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <memory> #include <memory>
#include "base64.h" #include "util/base64.h"
#include "ElGamal.h" #include "crypto/ElGamal.h"
#include "Signature.h" #include "crypto/Signature.h"
namespace i2p namespace i2p
{ {
@ -51,7 +51,7 @@ namespace data
std::string ToBase64 () const std::string ToBase64 () const
{ {
char str[sz*2]; char str[sz*2];
int l = i2p::data::ByteStreamToBase64 (m_Buf, sz, str, sz*2); int l = i2p::util::ByteStreamToBase64 (m_Buf, sz, str, sz*2);
str[l] = 0; str[l] = 0;
return std::string (str); return std::string (str);
} }
@ -59,19 +59,19 @@ namespace data
std::string ToBase32 () const std::string ToBase32 () const
{ {
char str[sz*2]; char str[sz*2];
int l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2); int l = i2p::util::ByteStreamToBase32 (m_Buf, sz, str, sz*2);
str[l] = 0; str[l] = 0;
return std::string (str); return std::string (str);
} }
void FromBase32 (const std::string& s) void FromBase32 (const std::string& s)
{ {
i2p::data::Base32ToByteStream (s.c_str (), s.length (), m_Buf, sz); i2p::util::Base32ToByteStream (s.c_str (), s.length (), m_Buf, sz);
} }
void FromBase64 (const std::string& s) void FromBase64 (const std::string& s)
{ {
i2p::data::Base64ToByteStream (s.c_str (), s.length (), m_Buf, sz); i2p::util::Base64ToByteStream (s.c_str (), s.length (), m_Buf, sz);
} }
private: private:

10
LeaseSet.cpp

@ -1,12 +1,12 @@
#include <string.h> #include <string.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "Log.h" #include "util/Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "NetDb.h" #include "NetDb.h"
#include "TunnelPool.h" #include "tunnel/TunnelPool.h"
#include "LeaseSet.h" #include "LeaseSet.h"
namespace i2p namespace i2p

12
Makefile

@ -28,6 +28,10 @@ tests: mk_build_test_dir $(TESTS)
mk_build_dir: mk_build_dir:
mkdir -p obj mkdir -p obj
mkdir -p obj/transport
mkdir -p obj/util
mkdir -p obj/crypto
mkdir -p obj/tunnel
mk_build_test_dir: mk_build_test_dir:
mkdir -p obj/tests mkdir -p obj/tests
@ -42,13 +46,21 @@ api: $(SHLIB)
deps: deps:
@mkdir -p obj @mkdir -p obj
@mkdir -p obj/transport
@mkdir -p obj/tests @mkdir -p obj/tests
@mkdir -p obj/util
@mkdir -p obj/crypto
@mkdir -p obj/tunnel
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS) $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS)
@sed -i -e '/\.o:/ s/^/obj\//' $(DEPS) @sed -i -e '/\.o:/ s/^/obj\//' $(DEPS)
obj/%.o : %.cpp obj/%.o : %.cpp
@mkdir -p obj @mkdir -p obj
@mkdir -p obj/transport
@mkdir -p obj/tests @mkdir -p obj/tests
@mkdir -p obj/util
@mkdir -p obj/crypto
@mkdir -p obj/tunnel
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $< $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $<
# '-' is 'ignore if missing' on first run # '-' is 'ignore if missing' on first run

2
Makefile.bsd

@ -7,7 +7,7 @@ CXXFLAGS = -O2
## -std=c++11. If you want to remove this variable please do so in a way that allows setting ## -std=c++11. If you want to remove this variable please do so in a way that allows setting
## custom FLAGS to work at build-time. ## custom FLAGS to work at build-time.
NEEDED_CXXFLAGS = -std=c++11 NEEDED_CXXFLAGS = -std=c++11
INCFLAGS = -I/usr/include/ -I/usr/local/include/ INCFLAGS = -I/usr/include/ -I/usr/local/include/ -I.
LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib
LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
LDTESTLIBS = -lboost_unit_test_framework LDTESTLIBS = -lboost_unit_test_framework

2
Makefile.linux

@ -1,5 +1,5 @@
CXXFLAGS = -g -Wall CXXFLAGS = -g -Wall
INCFLAGS = INCFLAGS = -I.
## NOTE: The NEEDED_CXXFLAGS are here so that custom CXXFLAGS can be specified at build time ## NOTE: The NEEDED_CXXFLAGS are here so that custom CXXFLAGS can be specified at build time
## **without** overwriting the CXXFLAGS which we need in order to build. ## **without** overwriting the CXXFLAGS which we need in order to build.

2
Makefile.osx vendored

@ -1,7 +1,7 @@
CXX = clang++ CXX = clang++
CXXFLAGS = -g -Wall -std=c++11 -DCRYPTOPP_DISABLE_ASM -DMAC_OSX CXXFLAGS = -g -Wall -std=c++11 -DCRYPTOPP_DISABLE_ASM -DMAC_OSX
#CXXFLAGS = -g -O2 -Wall -std=c++11 -DCRYPTOPP_DISABLE_ASM #CXXFLAGS = -g -O2 -Wall -std=c++11 -DCRYPTOPP_DISABLE_ASM
INCFLAGS = -I/usr/local/include INCFLAGS = -I/usr/local/include -I.
LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib
LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
LDTESTLIBS = -lboost_unit_test_framework LDTESTLIBS = -lboost_unit_test_framework

22
NetDb.cpp

@ -1,19 +1,19 @@
#include <string.h> #include <string.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <cryptopp/gzip.h> #include <cryptopp/gzip.h>
#include "base64.h" #include "util/base64.h"
#include "Log.h" #include "util/Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "Transports.h" #include "transport/Transports.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Garlic.h" #include "Garlic.h"
#include "NetDb.h" #include "NetDb.h"
#include "util.h" #include "util/util.h"
using namespace i2p::transport; using namespace i2p::transport;
@ -263,7 +263,7 @@ namespace data
} }
// list of chars might appear in base64 string // list of chars might appear in base64 string
const char * chars = GetBase64SubstitutionTable (); // 64 bytes const char * chars = i2p::util::GetBase64SubstitutionTable (); // 64 bytes
boost::filesystem::path suffix; boost::filesystem::path suffix;
for (int i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
{ {
@ -544,7 +544,7 @@ namespace data
{ {
const uint8_t * buf = msg->GetPayload (); const uint8_t * buf = msg->GetPayload ();
char key[48]; char key[48];
int l = i2p::data::ByteStreamToBase64 (buf, 32, key, 48); int l = i2p::util::ByteStreamToBase64 (buf, 32, key, 48);
key[l] = 0; key[l] = 0;
int num = buf[32]; // num int num = buf[32]; // num
LogPrint ("DatabaseSearchReply for ", key, " num=", num); LogPrint ("DatabaseSearchReply for ", key, " num=", num);
@ -613,7 +613,7 @@ namespace data
{ {
const uint8_t * router = buf + 33 + i*32; const uint8_t * router = buf + 33 + i*32;
char peerHash[48]; char peerHash[48];
int l1 = i2p::data::ByteStreamToBase64 (router, 32, peerHash, 48); int l1 = i2p::util::ByteStreamToBase64 (router, 32, peerHash, 48);
peerHash[l1] = 0; peerHash[l1] = 0;
LogPrint (i,": ", peerHash); LogPrint (i,": ", peerHash);
@ -639,7 +639,7 @@ namespace data
return; return;
} }
char key[48]; char key[48];
int l = i2p::data::ByteStreamToBase64 (buf, 32, key, 48); int l = i2p::util::ByteStreamToBase64 (buf, 32, key, 48);
key[l] = 0; key[l] = 0;
uint8_t flag = buf[64]; uint8_t flag = buf[64];
LogPrint ("DatabaseLookup for ", key, " recieved flags=", (int)flag); LogPrint ("DatabaseLookup for ", key, " recieved flags=", (int)flag);

6
NetDb.h

@ -9,12 +9,12 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "Queue.h" #include "util/Queue.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "TunnelPool.h" #include "tunnel/TunnelPool.h"
#include "Reseed.h" #include "Reseed.h"
#include "NetDbRequests.h" #include "NetDbRequests.h"

4
NetDbRequests.cpp

@ -1,6 +1,6 @@
#include "Log.h" #include "util/Log.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Transports.h" #include "transport/Transports.h"
#include "NetDb.h" #include "NetDb.h"
#include "NetDbRequests.h" #include "NetDbRequests.h"

6
Profiling.cpp

@ -1,8 +1,8 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ini_parser.hpp>
#include "base64.h" #include "util/base64.h"
#include "util.h" #include "util/util.h"
#include "Profiling.h" #include "Profiling.h"
namespace i2p namespace i2p
@ -52,7 +52,7 @@ namespace data
LogPrint (eLogError, "Failed to create directory ", path); LogPrint (eLogError, "Failed to create directory ", path);
return; return;
} }
const char * chars = GetBase64SubstitutionTable (); // 64 bytes const char * chars = i2p::util::GetBase64SubstitutionTable (); // 64 bytes
for (int i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
{ {
auto path1 = path / (std::string ("p") + chars[i]); auto path1 = path / (std::string ("p") + chars[i]);

8
Reseed.cpp

@ -11,13 +11,13 @@
#include <cryptopp/zinflate.h> #include <cryptopp/zinflate.h>
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <cryptopp/arc4.h> #include <cryptopp/arc4.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "Reseed.h" #include "Reseed.h"
#include "Log.h" #include "util/Log.h"
#include "Identity.h" #include "Identity.h"
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "NetDb.h" #include "NetDb.h"
#include "util.h" #include "util/util.h"
namespace i2p namespace i2p

2
Reseed.h

@ -9,7 +9,7 @@
#include <cryptopp/rsa.h> #include <cryptopp/rsa.h>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "Identity.h" #include "Identity.h"
#include "aes.h" #include "crypto/aes.h"
namespace i2p namespace i2p
{ {

6
RouterContext.cpp

@ -2,12 +2,12 @@
#include <cryptopp/dh.h> #include <cryptopp/dh.h>
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "NetDb.h" #include "NetDb.h"
#include "util.h" #include "util/util.h"
#include "version.h" #include "version.h"
namespace i2p namespace i2p

18
RouterInfo.cpp

@ -1,14 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <fstream> #include <fstream>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "base64.h" #include "util/base64.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "Log.h" #include "util/Log.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "RouterContext.h" #include "RouterContext.h"
@ -176,7 +176,7 @@ namespace data
else if (!strcmp (key, "mtu")) else if (!strcmp (key, "mtu"))
address.mtu = boost::lexical_cast<int>(value); address.mtu = boost::lexical_cast<int>(value);
else if (!strcmp (key, "key")) else if (!strcmp (key, "key"))
Base64ToByteStream (value, strlen (value), address.key, 32); i2p::util::Base64ToByteStream (value, strlen (value), address.key, 32);
else if (!strcmp (key, "caps")) else if (!strcmp (key, "caps"))
ExtractCaps (value); ExtractCaps (value);
else if (key[0] == 'i') else if (key[0] == 'i')
@ -199,7 +199,7 @@ namespace data
else if (!strcmp (key, "itag")) else if (!strcmp (key, "itag"))
introducer.iTag = boost::lexical_cast<uint32_t>(value); introducer.iTag = boost::lexical_cast<uint32_t>(value);
else if (!strcmp (key, "ikey")) else if (!strcmp (key, "ikey"))
Base64ToByteStream (value, strlen (value), introducer.iKey, 32); i2p::util::Base64ToByteStream (value, strlen (value), introducer.iKey, 32);
} }
} }
if (isValidAddress) if (isValidAddress)
@ -344,7 +344,7 @@ namespace data
WriteString ("ikey" + boost::lexical_cast<std::string>(i), properties); WriteString ("ikey" + boost::lexical_cast<std::string>(i), properties);
properties << '='; properties << '=';
char value[64]; char value[64];
size_t l = ByteStreamToBase64 (introducer.iKey, 32, value, 64); size_t l = i2p::util::ByteStreamToBase64 (introducer.iKey, 32, value, 64);
value[l] = 0; value[l] = 0;
WriteString (value, properties); WriteString (value, properties);
properties << ';'; properties << ';';
@ -373,7 +373,7 @@ namespace data
WriteString ("key", properties); WriteString ("key", properties);
properties << '='; properties << '=';
char value[64]; char value[64];
size_t l = ByteStreamToBase64 (address.key, 32, value, 64); size_t l = i2p::util::ByteStreamToBase64 (address.key, 32, value, 64);
value[l] = 0; value[l] = 0;
WriteString (value, properties); WriteString (value, properties);
properties << ';'; properties << ';';

8
SAM.cpp

@ -4,9 +4,9 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "base64.h" #include "util/base64.h"
#include "Identity.h" #include "Identity.h"
#include "Log.h" #include "util/Log.h"
#include "Destination.h" #include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "SAM.h" #include "SAM.h"
@ -319,7 +319,7 @@ namespace client
uint8_t buf[1024]; uint8_t buf[1024];
char priv[1024]; char priv[1024];
size_t l = m_Session->localDestination->GetPrivateKeys ().ToBuffer (buf, 1024); size_t l = m_Session->localDestination->GetPrivateKeys ().ToBuffer (buf, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, priv, 1024); size_t l1 = i2p::util::ByteStreamToBase64 (buf, l, priv, 1024);
priv[l1] = 0; priv[l1] = 0;
#ifdef _MSC_VER #ifdef _MSC_VER
size_t l2 = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_SESSION_CREATE_REPLY_OK, priv); size_t l2 = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_SESSION_CREATE_REPLY_OK, priv);
@ -632,7 +632,7 @@ namespace client
// send remote peer address // send remote peer address
uint8_t ident[1024]; uint8_t ident[1024];
size_t l = stream->GetRemoteIdentity ().ToBuffer (ident, 1024); size_t l = stream->GetRemoteIdentity ().ToBuffer (ident, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (ident, l, (char *)m_StreamBuffer, SAM_SOCKET_BUFFER_SIZE); size_t l1 = i2p::util::ByteStreamToBase64 (ident, l, (char *)m_StreamBuffer, SAM_SOCKET_BUFFER_SIZE);
m_StreamBuffer[l1] = '\n'; m_StreamBuffer[l1] = '\n';
HandleI2PReceive (boost::system::error_code (), l1 +1); // we send identity like it has been received from stream HandleI2PReceive (boost::system::error_code (), l1 +1); // we send identity like it has been received from stream
} }

2
SOCKS.cpp

@ -7,7 +7,7 @@
#include "Streaming.h" #include "Streaming.h"
#include "Destination.h" #include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "I2PTunnel.h" #include "I2PTunnel.h"
namespace i2p namespace i2p

6
Streaming.cpp

@ -1,9 +1,9 @@
#include <cryptopp/gzip.h> #include <cryptopp/gzip.h>
#include "Log.h" #include "util/Log.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "Destination.h" #include "Destination.h"
#include "Streaming.h" #include "Streaming.h"

4
Streaming.h

@ -11,12 +11,12 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "Identity.h" #include "Identity.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Garlic.h" #include "Garlic.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
namespace i2p namespace i2p
{ {

11
TODO

@ -1,13 +1,16 @@
Short-term refactoring: Refactoring:
- SSUSession:637, SSUSession:635 get rid of casting to SSUHeader - SSUSession:637, SSUSession:635 get rid of casting to SSUHeader
- Identity.cpp:156 check for self asignment - Identity.cpp:156 check for self asignment
Long-term refactoring:
- Rely on a library for TLS and SSL. - Rely on a library for TLS and SSL.
- Move parsing code out of networking code, to allow better testing. - Move parsing code out of networking code, to allow better testing.
- Move streaming code to a separate directory.
- Separate front-end code (SAM, BOB, ...) from the back-end. - Separate front-end code (SAM, BOB, ...) from the back-end.
Additions: Additions:
- Write tests. - Write tests.
- Add documentation. - Add documentation.
- Create a specialized IRC tunnel (instead of just a generic ClientTunnel instance).
- Ban peers with unexpected / bad behaviour.
- EdDSA support.
- Return correct error codes in HTTPProxy.
- Modify web interface layout and use AJAX to update information.

4
UPnP.cpp

@ -13,12 +13,12 @@
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
#include "Log.h" #include "util/Log.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "UPnP.h" #include "UPnP.h"
#include "NetDb.h" #include "NetDb.h"
#include "util.h" #include "util/util.h"
#include <miniupnpc/miniupnpc.h> #include <miniupnpc/miniupnpc.h>
#include <miniupnpc/upnpcommands.h> #include <miniupnpc/upnpcommands.h>

2
UPnP.h

@ -12,7 +12,7 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "util.h" #include "util/util.h"
#define I2P_UPNP_TCP 1 #define I2P_UPNP_TCP 1
#define I2P_UPNP_UDP 2 #define I2P_UPNP_UDP 2

357
aes.cpp

@ -1,357 +0,0 @@
#include <stdlib.h>
#include "TunnelBase.h"
#include "aes.h"
namespace i2p
{
namespace crypto
{
#ifdef AESNI
#define KeyExpansion256(round0,round1) \
"pshufd $0xff, %%xmm2, %%xmm2 \n" \
"movaps %%xmm1, %%xmm4 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pxor %%xmm2, %%xmm1 \n" \
"movaps %%xmm1, "#round0"(%[sched]) \n" \
"aeskeygenassist $0, %%xmm1, %%xmm4 \n" \
"pshufd $0xaa, %%xmm4, %%xmm2 \n" \
"movaps %%xmm3, %%xmm4 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pxor %%xmm2, %%xmm3 \n" \
"movaps %%xmm3, "#round1"(%[sched]) \n"
void ECBCryptoAESNI::ExpandKey (const AESKey& key)
{
__asm__
(
"movups (%[key]), %%xmm1 \n"
"movups 16(%[key]), %%xmm3 \n"
"movaps %%xmm1, (%[sched]) \n"
"movaps %%xmm3, 16(%[sched]) \n"
"aeskeygenassist $1, %%xmm3, %%xmm2 \n"
KeyExpansion256(32,48)
"aeskeygenassist $2, %%xmm3, %%xmm2 \n"
KeyExpansion256(64,80)
"aeskeygenassist $4, %%xmm3, %%xmm2 \n"
KeyExpansion256(96,112)
"aeskeygenassist $8, %%xmm3, %%xmm2 \n"
KeyExpansion256(128,144)
"aeskeygenassist $16, %%xmm3, %%xmm2 \n"
KeyExpansion256(160,176)
"aeskeygenassist $32, %%xmm3, %%xmm2 \n"
KeyExpansion256(192,208)
"aeskeygenassist $64, %%xmm3, %%xmm2 \n"
// key expansion final
"pshufd $0xff, %%xmm2, %%xmm2 \n"
"movaps %%xmm1, %%xmm4 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pxor %%xmm2, %%xmm1 \n"
"movups %%xmm1, 224(%[sched]) \n"
: // output
: [key]"r"((const uint8_t *)key), [sched]"r"(GetKeySchedule ()) // input
: "%xmm1", "%xmm2", "%xmm3", "%xmm4", "memory" // clogged
);
}
#define EncryptAES256(sched) \
"pxor (%["#sched"]), %%xmm0 \n" \
"aesenc 16(%["#sched"]), %%xmm0 \n" \
"aesenc 32(%["#sched"]), %%xmm0 \n" \
"aesenc 48(%["#sched"]), %%xmm0 \n" \
"aesenc 64(%["#sched"]), %%xmm0 \n" \
"aesenc 80(%["#sched"]), %%xmm0 \n" \
"aesenc 96(%["#sched"]), %%xmm0 \n" \
"aesenc 112(%["#sched"]), %%xmm0 \n" \
"aesenc 128(%["#sched"]), %%xmm0 \n" \
"aesenc 144(%["#sched"]), %%xmm0 \n" \
"aesenc 160(%["#sched"]), %%xmm0 \n" \
"aesenc 176(%["#sched"]), %%xmm0 \n" \
"aesenc 192(%["#sched"]), %%xmm0 \n" \
"aesenc 208(%["#sched"]), %%xmm0 \n" \
"aesenclast 224(%["#sched"]), %%xmm0 \n"
void ECBEncryptionAESNI::Encrypt (const ChipherBlock * in, ChipherBlock * out)
{
__asm__
(
"movups (%[in]), %%xmm0 \n"
EncryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
: : [sched]"r"(GetKeySchedule ()), [in]"r"(in), [out]"r"(out) : "%xmm0", "memory"
);
}
#define DecryptAES256(sched) \
"pxor 224(%["#sched"]), %%xmm0 \n" \
"aesdec 208(%["#sched"]), %%xmm0 \n" \
"aesdec 192(%["#sched"]), %%xmm0 \n" \
"aesdec 176(%["#sched"]), %%xmm0 \n" \
"aesdec 160(%["#sched"]), %%xmm0 \n" \
"aesdec 144(%["#sched"]), %%xmm0 \n" \
"aesdec 128(%["#sched"]), %%xmm0 \n" \
"aesdec 112(%["#sched"]), %%xmm0 \n" \
"aesdec 96(%["#sched"]), %%xmm0 \n" \
"aesdec 80(%["#sched"]), %%xmm0 \n" \
"aesdec 64(%["#sched"]), %%xmm0 \n" \
"aesdec 48(%["#sched"]), %%xmm0 \n" \
"aesdec 32(%["#sched"]), %%xmm0 \n" \
"aesdec 16(%["#sched"]), %%xmm0 \n" \
"aesdeclast (%["#sched"]), %%xmm0 \n"
void ECBDecryptionAESNI::Decrypt (const ChipherBlock * in, ChipherBlock * out)
{
__asm__
(
"movups (%[in]), %%xmm0 \n"
DecryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
: : [sched]"r"(GetKeySchedule ()), [in]"r"(in), [out]"r"(out) : "%xmm0", "memory"
);
}
#define CallAESIMC(offset) \
"movaps "#offset"(%[shed]), %%xmm0 \n" \
"aesimc %%xmm0, %%xmm0 \n" \
"movaps %%xmm0, "#offset"(%[shed]) \n"
void ECBDecryptionAESNI::SetKey (const AESKey& key)
{
ExpandKey (key); // expand encryption key first
// then invert it using aesimc
__asm__
(
CallAESIMC(16)
CallAESIMC(32)
CallAESIMC(48)
CallAESIMC(64)
CallAESIMC(80)
CallAESIMC(96)
CallAESIMC(112)
CallAESIMC(128)
CallAESIMC(144)
CallAESIMC(160)
CallAESIMC(176)
CallAESIMC(192)
CallAESIMC(208)
: : [shed]"r"(GetKeySchedule ()) : "%xmm0", "memory"
);
}
#endif
void CBCEncryption::Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"1: \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched)
"movaps %%xmm0, %%xmm1 \n"
"movups %%xmm0, (%[out]) \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"dec %[num] \n"
"jnz 1b \n"
"movups %%xmm1, (%[iv]) \n"
:
: [iv]"r"(&m_LastBlock), [sched]"r"(m_ECBEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(numBlocks)
: "%xmm0", "%xmm1", "cc", "memory"
);
#else
for (int i = 0; i < numBlocks; i++)
{
m_LastBlock ^= in[i];
m_ECBEncryption.Encrypt (&m_LastBlock, &m_LastBlock);
out[i] = m_LastBlock;
}
#endif
}
void CBCEncryption::Encrypt (const uint8_t * in, std::size_t len, uint8_t * out)
{
// len/16
int numBlocks = len >> 4;
if (numBlocks > 0)
Encrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
"movups %%xmm0, (%[iv]) \n"
:
: [iv]"r"(&m_LastBlock), [sched]"r"(m_ECBEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out)
: "%xmm0", "%xmm1", "memory"
);
#else
Encrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
#endif
}
void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"1: \n"
"movups (%[in]), %%xmm0 \n"
"movaps %%xmm0, %%xmm2 \n"
DecryptAES256(sched)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
"movaps %%xmm2, %%xmm1 \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"dec %[num] \n"
"jnz 1b \n"
"movups %%xmm1, (%[iv]) \n"
:
: [iv]"r"(&m_IV), [sched]"r"(m_ECBDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(numBlocks)
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
);
#else
for (int i = 0; i < numBlocks; i++)
{
ChipherBlock tmp = in[i];
m_ECBDecryption.Decrypt (in + i, out + i);
out[i] ^= m_IV;
m_IV = tmp;
}
#endif
}
void CBCDecryption::Decrypt (const uint8_t * in, std::size_t len, uint8_t * out)
{
int numBlocks = len >> 4;
if (numBlocks > 0)
Decrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"movups (%[in]), %%xmm0 \n"
"movups %%xmm0, (%[iv]) \n"
DecryptAES256(sched)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
:
: [iv]"r"(&m_IV), [sched]"r"(m_ECBDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out)
: "%xmm0", "%xmm1", "memory"
);
#else
Decrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
#endif
}
void TunnelEncryption::Encrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
// encrypt IV
"movups (%[in]), %%xmm0 \n"
EncryptAES256(sched_iv)
"movaps %%xmm0, %%xmm1 \n"
// double IV encryption
EncryptAES256(sched_iv)
"movups %%xmm0, (%[out]) \n"
// encrypt data, IV is xmm1
"1: \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched_l)
"movaps %%xmm0, %%xmm1 \n"
"movups %%xmm0, (%[out]) \n"
"dec %[num] \n"
"jnz 1b \n"
:
: [sched_iv]"r"(m_IVEncryption.GetKeySchedule ()), [sched_l]"r"(m_LayerEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
: "%xmm0", "%xmm1", "cc", "memory"
);
#else
m_IVEncryption.Encrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
m_LayerEncryption.SetIV (out);
m_LayerEncryption.Encrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
m_IVEncryption.Encrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
#endif
}
void TunnelDecryption::Decrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
// decrypt IV
"movups (%[in]), %%xmm0 \n"
DecryptAES256(sched_iv)
"movaps %%xmm0, %%xmm1 \n"
// double IV encryption
DecryptAES256(sched_iv)
"movups %%xmm0, (%[out]) \n"
// decrypt data, IV is xmm1
"1: \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"movups (%[in]), %%xmm0 \n"
"movaps %%xmm0, %%xmm2 \n"
DecryptAES256(sched_l)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
"movaps %%xmm2, %%xmm1 \n"
"dec %[num] \n"
"jnz 1b \n"
:
: [sched_iv]"r"(m_IVDecryption.GetKeySchedule ()), [sched_l]"r"(m_LayerDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
);
#else
m_IVDecryption.Decrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
m_LayerDecryption.SetIV (out);
m_LayerDecryption.Decrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
m_IVDecryption.Decrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
#endif
}
}
}

8
api.cpp

@ -1,13 +1,13 @@
#include <string> #include <string>
#include <map> #include <map>
#include "Log.h" #include "util/Log.h"
#include "NetDb.h" #include "NetDb.h"
#include "Transports.h" #include "transport/Transports.h"
#include "Tunnel.h" #include "tunnel/Tunnel.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Identity.h" #include "Identity.h"
#include "Destination.h" #include "Destination.h"
#include "util.h" #include "util/util.h"
#include "api.h" #include "api.h"
namespace i2p namespace i2p

37
build/CMakeLists.txt

@ -15,41 +15,42 @@ set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" )
set ( CMAKE_SOURCE_DIR ".." ) set ( CMAKE_SOURCE_DIR ".." )
set (COMMON_SRC set (COMMON_SRC
"${CMAKE_SOURCE_DIR}/transport/NTCPSession.cpp"
"${CMAKE_SOURCE_DIR}/transport/SSU.cpp"
"${CMAKE_SOURCE_DIR}/transport/SSUData.cpp"
"${CMAKE_SOURCE_DIR}/transport/SSUSession.cpp"
"${CMAKE_SOURCE_DIR}/transport/Transports.cpp"
"${CMAKE_SOURCE_DIR}/crypto/CryptoConst.cpp"
"${CMAKE_SOURCE_DIR}/crypto/aes.cpp"
"${CMAKE_SOURCE_DIR}/crypto/Signature.cpp"
"${CMAKE_SOURCE_DIR}/util/base64.cpp"
"${CMAKE_SOURCE_DIR}/util/util.cpp"
"${CMAKE_SOURCE_DIR}/util/Log.cpp"
"${CMAKE_SOURCE_DIR}/tunnel/TransitTunnel.cpp"
"${CMAKE_SOURCE_DIR}/tunnel/Tunnel.cpp"
"${CMAKE_SOURCE_DIR}/tunnel/TunnelGateway.cpp"
"${CMAKE_SOURCE_DIR}/tunnel/TunnelEndpoint.cpp"
"${CMAKE_SOURCE_DIR}/tunnel/TunnelPool.cpp"
"${CMAKE_SOURCE_DIR}/tunnel/TunnelCrypto.cpp"
"${CMAKE_SOURCE_DIR}/AddressBook.cpp" "${CMAKE_SOURCE_DIR}/AddressBook.cpp"
"${CMAKE_SOURCE_DIR}/CryptoConst.cpp"
"${CMAKE_SOURCE_DIR}/Garlic.cpp" "${CMAKE_SOURCE_DIR}/Garlic.cpp"
"${CMAKE_SOURCE_DIR}/I2NPProtocol.cpp" "${CMAKE_SOURCE_DIR}/I2NPProtocol.cpp"
"${CMAKE_SOURCE_DIR}/Identity.cpp" "${CMAKE_SOURCE_DIR}/Identity.cpp"
"${CMAKE_SOURCE_DIR}/LeaseSet.cpp" "${CMAKE_SOURCE_DIR}/LeaseSet.cpp"
"${CMAKE_SOURCE_DIR}/Log.cpp"
"${CMAKE_SOURCE_DIR}/NTCPSession.cpp"
"${CMAKE_SOURCE_DIR}/NetDbRequests.cpp" "${CMAKE_SOURCE_DIR}/NetDbRequests.cpp"
"${CMAKE_SOURCE_DIR}/NetDb.cpp" "${CMAKE_SOURCE_DIR}/NetDb.cpp"
"${CMAKE_SOURCE_DIR}/Profiling.cpp" "${CMAKE_SOURCE_DIR}/Profiling.cpp"
"${CMAKE_SOURCE_DIR}/Reseed.cpp" "${CMAKE_SOURCE_DIR}/Reseed.cpp"
"${CMAKE_SOURCE_DIR}/RouterContext.cpp" "${CMAKE_SOURCE_DIR}/RouterContext.cpp"
"${CMAKE_SOURCE_DIR}/RouterInfo.cpp" "${CMAKE_SOURCE_DIR}/RouterInfo.cpp"
"${CMAKE_SOURCE_DIR}/SSU.cpp"
"${CMAKE_SOURCE_DIR}/SSUData.cpp"
"${CMAKE_SOURCE_DIR}/SSUSession.cpp"
"${CMAKE_SOURCE_DIR}/Streaming.cpp" "${CMAKE_SOURCE_DIR}/Streaming.cpp"
"${CMAKE_SOURCE_DIR}/Destination.cpp" "${CMAKE_SOURCE_DIR}/Destination.cpp"
"${CMAKE_SOURCE_DIR}/TransitTunnel.cpp"
"${CMAKE_SOURCE_DIR}/Tunnel.cpp"
"${CMAKE_SOURCE_DIR}/TunnelGateway.cpp"
"${CMAKE_SOURCE_DIR}/Transports.cpp"
"${CMAKE_SOURCE_DIR}/TunnelEndpoint.cpp"
"${CMAKE_SOURCE_DIR}/TunnelPool.cpp"
"${CMAKE_SOURCE_DIR}/aes.cpp"
"${CMAKE_SOURCE_DIR}/base64.cpp"
"${CMAKE_SOURCE_DIR}/util.cpp"
"${CMAKE_SOURCE_DIR}/Datagram.cpp" "${CMAKE_SOURCE_DIR}/Datagram.cpp"
"${CMAKE_SOURCE_DIR}/Signature.cpp"
"${CMAKE_SOURCE_DIR}/UPnP.cpp" "${CMAKE_SOURCE_DIR}/UPnP.cpp"
) )
if (CMAKE_SYSTEM_NAME STREQUAL "Windows") if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
list (APPEND COMMON_SRC "${CMAKE_SOURCE_DIR}/I2PEndian.cpp") list (APPEND COMMON_SRC "${CMAKE_SOURCE_DIR}/util/I2PEndian.cpp")
endif () endif ()
add_library(common ${COMMON_SRC}) add_library(common ${COMMON_SRC})
@ -223,7 +224,7 @@ if (NOT ${MINIUPNPC_FOUND})
endif() endif()
# load includes # load includes
include_directories( ${Boost_INCLUDE_DIRS} ${CRYPTO++_INCLUDE_DIR} ) include_directories( ${CMAKE_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${CRYPTO++_INCLUDE_DIR} )
# show summary # show summary
message(STATUS "---------------------------------------") message(STATUS "---------------------------------------")

0
CryptoConst.cpp → crypto/CryptoConst.cpp

0
CryptoConst.h → crypto/CryptoConst.h

2
ElGamal.h → crypto/ElGamal.h

@ -7,7 +7,7 @@
#include <cryptopp/dh.h> #include <cryptopp/dh.h>
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include "CryptoConst.h" #include "CryptoConst.h"
#include "Log.h" #include "util/Log.h"
namespace i2p namespace i2p
{ {

2
Signature.cpp → crypto/Signature.cpp

@ -1,7 +1,7 @@
#include <memory> #include <memory>
#include <cryptopp/integer.h> #include <cryptopp/integer.h>
#include <cryptopp/eccrypto.h> #include <cryptopp/eccrypto.h>
#include "Log.h" #include "util/Log.h"
#include "Signature.h" #include "Signature.h"
namespace i2p namespace i2p

0
Signature.h → crypto/Signature.h

222
crypto/aes.cpp

@ -0,0 +1,222 @@
#include <stdlib.h>
#include "aes.h"
namespace i2p {
namespace crypto {
#ifdef AESNI
#include "AESNIMacros.h"
void ECBCryptoAESNI::ExpandKey (const AESKey& key)
{
__asm__
(
"movups (%[key]), %%xmm1 \n"
"movups 16(%[key]), %%xmm3 \n"
"movaps %%xmm1, (%[sched]) \n"
"movaps %%xmm3, 16(%[sched]) \n"
"aeskeygenassist $1, %%xmm3, %%xmm2 \n"
KeyExpansion256(32,48)
"aeskeygenassist $2, %%xmm3, %%xmm2 \n"
KeyExpansion256(64,80)
"aeskeygenassist $4, %%xmm3, %%xmm2 \n"
KeyExpansion256(96,112)
"aeskeygenassist $8, %%xmm3, %%xmm2 \n"
KeyExpansion256(128,144)
"aeskeygenassist $16, %%xmm3, %%xmm2 \n"
KeyExpansion256(160,176)
"aeskeygenassist $32, %%xmm3, %%xmm2 \n"
KeyExpansion256(192,208)
"aeskeygenassist $64, %%xmm3, %%xmm2 \n"
// key expansion final
"pshufd $0xff, %%xmm2, %%xmm2 \n"
"movaps %%xmm1, %%xmm4 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pxor %%xmm2, %%xmm1 \n"
"movups %%xmm1, 224(%[sched]) \n"
: // output
: [key]"r"((const uint8_t *)key), [sched]"r"(GetKeySchedule ()) // input
: "%xmm1", "%xmm2", "%xmm3", "%xmm4", "memory" // clogged
);
}
void ECBEncryptionAESNI::Encrypt (const ChipherBlock * in, ChipherBlock * out)
{
__asm__
(
"movups (%[in]), %%xmm0 \n"
EncryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
: : [sched]"r"(GetKeySchedule ()), [in]"r"(in), [out]"r"(out) : "%xmm0", "memory"
);
}
void ECBDecryptionAESNI::Decrypt (const ChipherBlock * in, ChipherBlock * out)
{
__asm__
(
"movups (%[in]), %%xmm0 \n"
DecryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
: : [sched]"r"(GetKeySchedule ()), [in]"r"(in), [out]"r"(out) : "%xmm0", "memory"
);
}
void ECBDecryptionAESNI::SetKey (const AESKey& key)
{
ExpandKey (key); // expand encryption key first
// then invert it using aesimc
__asm__
(
CallAESIMC(16)
CallAESIMC(32)
CallAESIMC(48)
CallAESIMC(64)
CallAESIMC(80)
CallAESIMC(96)
CallAESIMC(112)
CallAESIMC(128)
CallAESIMC(144)
CallAESIMC(160)
CallAESIMC(176)
CallAESIMC(192)
CallAESIMC(208)
: : [shed]"r"(GetKeySchedule ()) : "%xmm0", "memory"
);
}
#endif
void CBCEncryption::Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"1: \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched)
"movaps %%xmm0, %%xmm1 \n"
"movups %%xmm0, (%[out]) \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"dec %[num] \n"
"jnz 1b \n"
"movups %%xmm1, (%[iv]) \n"
:
: [iv]"r"(&m_LastBlock), [sched]"r"(m_ECBEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(numBlocks)
: "%xmm0", "%xmm1", "cc", "memory"
);
#else
for (int i = 0; i < numBlocks; i++)
{
m_LastBlock ^= in[i];
m_ECBEncryption.Encrypt (&m_LastBlock, &m_LastBlock);
out[i] = m_LastBlock;
}
#endif
}
void CBCEncryption::Encrypt (const uint8_t * in, std::size_t len, uint8_t * out)
{
// len/16
int numBlocks = len >> 4;
if (numBlocks > 0)
Encrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
"movups %%xmm0, (%[iv]) \n"
:
: [iv]"r"(&m_LastBlock), [sched]"r"(m_ECBEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out)
: "%xmm0", "%xmm1", "memory"
);
#else
Encrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
#endif
}
void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"1: \n"
"movups (%[in]), %%xmm0 \n"
"movaps %%xmm0, %%xmm2 \n"
DecryptAES256(sched)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
"movaps %%xmm2, %%xmm1 \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"dec %[num] \n"
"jnz 1b \n"
"movups %%xmm1, (%[iv]) \n"
:
: [iv]"r"(&m_IV), [sched]"r"(m_ECBDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(numBlocks)
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
);
#else
for (int i = 0; i < numBlocks; i++)
{
ChipherBlock tmp = in[i];
m_ECBDecryption.Decrypt (in + i, out + i);
out[i] ^= m_IV;
m_IV = tmp;
}
#endif
}
void CBCDecryption::Decrypt (const uint8_t * in, std::size_t len, uint8_t * out)
{
int numBlocks = len >> 4;
if (numBlocks > 0)
Decrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"movups (%[in]), %%xmm0 \n"
"movups %%xmm0, (%[iv]) \n"
DecryptAES256(sched)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
:
: [iv]"r"(&m_IV), [sched]"r"(m_ECBDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out)
: "%xmm0", "%xmm1", "memory"
);
#else
Decrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
#endif
}
} // crypto
} // i2p

44
aes.h → crypto/aes.h

@ -181,51 +181,7 @@ namespace crypto
ECBDecryption m_ECBDecryption; ECBDecryption m_ECBDecryption;
}; };
class TunnelEncryption // with double IV encryption
{
public:
void SetKeys (const AESKey& layerKey, const AESKey& ivKey)
{
m_LayerEncryption.SetKey (layerKey);
m_IVEncryption.SetKey (ivKey);
}
void Encrypt (const uint8_t * in, uint8_t * out); // 1024 bytes (16 IV + 1008 data)
private:
ECBEncryption m_IVEncryption;
#ifdef AESNI
ECBEncryption m_LayerEncryption;
#else
CBCEncryption m_LayerEncryption;
#endif
};
class TunnelDecryption // with double IV encryption
{
public:
void SetKeys (const AESKey& layerKey, const AESKey& ivKey)
{
m_LayerDecryption.SetKey (layerKey);
m_IVDecryption.SetKey (ivKey);
}
void Decrypt (const uint8_t * in, uint8_t * out); // 1024 bytes (16 IV + 1008 data)
private:
ECBDecryption m_IVDecryption;
#ifdef AESNI
ECBDecryption m_LayerDecryption;
#else
CBCDecryption m_LayerDecryption;
#endif
};
} }
} }
#endif #endif

0
hmac.h → crypto/hmac.h

27
filelist.mk

@ -1,28 +1,33 @@
COMMON_SRC = \ COMMON_SRC = \
CryptoConst.cpp Datagram.cpp Garlic.cpp I2NPProtocol.cpp LeaseSet.cpp \ transport/NTCPSession.cpp transport/SSU.cpp transport/SSUSession.cpp \
Log.cpp NTCPSession.cpp NetDb.cpp NetDbRequests.cpp Profiling.cpp \ transport/SSUData.cpp transport/Transports.cpp \
Reseed.cpp RouterContext.cpp RouterInfo.cpp Signature.cpp SSU.cpp \ util/util.cpp util/base64.cpp util/Log.cpp \
SSUSession.cpp SSUData.cpp Streaming.cpp Identity.cpp TransitTunnel.cpp \ crypto/CryptoConst.cpp crypto/aes.cpp crypto/Signature.cpp \
Transports.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelPool.cpp TunnelGateway.cpp \ tunnel/Tunnel.cpp tunnel/TransitTunnel.cpp tunnel/TunnelEndpoint.cpp \
Destination.cpp UPnP.cpp util.cpp aes.cpp base64.cpp tunnel/TunnelEndpoint.cpp tunnel/TunnelPool.cpp tunnel/TunnelGateway.cpp \
tunnel/TunnelCrypto.cpp Datagram.cpp Garlic.cpp I2NPProtocol.cpp LeaseSet.cpp \
NetDb.cpp NetDbRequests.cpp Profiling.cpp Reseed.cpp \
RouterContext.cpp RouterInfo.cpp Streaming.cpp Identity.cpp \
Destination.cpp UPnP.cpp
ifeq ($(UNAME),Darwin) ifeq ($(UNAME),Darwin)
# This is needed on OS X for some reason I don't understand (yet). # This is needed on OS X for some reason I don't understand (yet).
# Else will get linker error about unknown symbols. - torkel # Else will get linker error about unknown symbols. - torkel
COMMON_SRC += \ COMMON_SRC += \
AddressBook.cpp BOB.cpp ClientContext.cpp Daemon.cpp I2PTunnel.cpp I2PService.cpp SAM.cpp SOCKS.cpp \ AddressBook.cpp BOB.cpp ClientContext.cpp Daemon.cpp I2PTunnel.cpp I2PService.cpp \
UPnP.cpp HTTPServer.cpp HTTPProxy.cpp i2p.cpp DaemonLinux.cpp I2PControl.cpp SAM.cpp SOCKS.cpp UPnP.cpp HTTPProxy.cpp i2p.cpp DaemonLinux.cpp I2PControl.cpp \
HTTPServer.cpp
endif endif
# also: Daemon{Linux,Win32}.cpp will be added later # also: Daemon{Linux,Win32}.cpp will be added later
DAEMON_SRC = $(COMMON_SRC) \ DAEMON_SRC = $(COMMON_SRC) \
AddressBook.cpp BOB.cpp ClientContext.cpp Daemon.cpp I2PTunnel.cpp I2PService.cpp \ AddressBook.cpp BOB.cpp ClientContext.cpp Daemon.cpp I2PTunnel.cpp I2PService.cpp \
SAM.cpp SOCKS.cpp HTTPServer.cpp HTTPProxy.cpp I2PControl.cpp i2p.cpp SAM.cpp SOCKS.cpp HTTPServer.cpp HTTPProxy.cpp I2PControl.cpp i2p.cpp
LIB_SRC := $(COMMON_SRC) \ LIB_SRC := $(COMMON_SRC) \
api.cpp api.cpp
TESTS_SRC := $(COMMON_SRC) \ TESTS_SRC := $(COMMON_SRC) \
tests/Utility.cpp tests/Identity.cpp tests/Data.cpp tests/Utility.cpp tests/Identity.cpp tests/Base64.cpp

6
tests/Data.cpp → tests/Base64.cpp

@ -1,11 +1,11 @@
#define BOOST_TEST_DYN_LINK #define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../Identity.h" #include "util/base64.h"
BOOST_AUTO_TEST_SUITE(DataTests) BOOST_AUTO_TEST_SUITE(Base64and32Tests)
using namespace i2p::data; using namespace i2p::util;
BOOST_AUTO_TEST_CASE(Base64EncodeEmpty) BOOST_AUTO_TEST_CASE(Base64EncodeEmpty)
{ {

2
tests/Utility.cpp

@ -1,5 +1,5 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../util.h" #include "util/util.h"
BOOST_AUTO_TEST_SUITE(UtilityTests) BOOST_AUTO_TEST_SUITE(UtilityTests)

10
NTCPSession.cpp → transport/NTCPSession.cpp

@ -1,12 +1,12 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <cryptopp/dh.h> #include <cryptopp/dh.h>
#include <cryptopp/adler32.h> #include <cryptopp/adler32.h>
#include "base64.h" #include "util/base64.h"
#include "Log.h" #include "util/Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Transports.h" #include "Transports.h"

2
NTCPSession.h → transport/NTCPSession.h

@ -9,7 +9,7 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <cryptopp/modes.h> #include <cryptopp/modes.h>
#include <cryptopp/aes.h> #include <cryptopp/aes.h>
#include "aes.h" #include "crypto/aes.h"
#include "Identity.h" #include "Identity.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"

4
SSU.cpp → transport/SSU.cpp

@ -1,7 +1,7 @@
#include <string.h> #include <string.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include "Log.h" #include "util/Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "NetDb.h" #include "NetDb.h"
#include "SSU.h" #include "SSU.h"

4
SSU.h → transport/SSU.h

@ -9,8 +9,8 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "aes.h" #include "crypto/aes.h"
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "Identity.h" #include "Identity.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"

4
SSUData.cpp → transport/SSUData.cpp

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include "Log.h" #include "util/Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "NetDb.h" #include "NetDb.h"
#include "SSU.h" #include "SSU.h"
#include "SSUData.h" #include "SSUData.h"

0
SSUData.h → transport/SSUData.h

6
SSUSession.cpp → transport/SSUSession.cpp

@ -1,9 +1,9 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <cryptopp/dh.h> #include <cryptopp/dh.h>
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "Log.h" #include "util/Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Transports.h" #include "Transports.h"
#include "SSU.h" #include "SSU.h"

4
SSUSession.h → transport/SSUSession.h

@ -4,8 +4,8 @@
#include <inttypes.h> #include <inttypes.h>
#include <set> #include <set>
#include <memory> #include <memory>
#include "aes.h" #include "crypto/aes.h"
#include "hmac.h" #include "crypto/hmac.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "TransportSession.h" #include "TransportSession.h"
#include "SSUData.h" #include "SSUData.h"

0
TransportSession.h → transport/TransportSession.h

4
Transports.cpp → transport/Transports.cpp

@ -1,6 +1,6 @@
#include <cryptopp/dh.h> #include <cryptopp/dh.h>
#include "Log.h" #include "util/Log.h"
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "NetDb.h" #include "NetDb.h"

0
Transports.h → transport/Transports.h

6
TransitTunnel.cpp → tunnel/TransitTunnel.cpp

@ -1,10 +1,10 @@
#include <string.h> #include <string.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "Log.h" #include "util/Log.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "Transports.h" #include "transport/Transports.h"
#include "TransitTunnel.h" #include "TransitTunnel.h"
namespace i2p namespace i2p

2
TransitTunnel.h → tunnel/TransitTunnel.h

@ -5,7 +5,7 @@
#include <vector> #include <vector>
#include <mutex> #include <mutex>
#include <memory> #include <memory>
#include "aes.h" #include "TunnelCrypto.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "TunnelEndpoint.h" #include "TunnelEndpoint.h"
#include "TunnelGateway.h" #include "TunnelGateway.h"

8
Tunnel.cpp → tunnel/Tunnel.cpp

@ -1,14 +1,14 @@
#include <string.h> #include <string.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <thread> #include <thread>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include "RouterContext.h" #include "RouterContext.h"
#include "Log.h" #include "util/Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Transports.h" #include "transport/Transports.h"
#include "NetDb.h" #include "NetDb.h"
#include "Tunnel.h" #include "Tunnel.h"

2
Tunnel.h → tunnel/Tunnel.h

@ -9,7 +9,7 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <memory> #include <memory>
#include "Queue.h" #include "util/Queue.h"
#include "TunnelConfig.h" #include "TunnelConfig.h"
#include "TunnelPool.h" #include "TunnelPool.h"
#include "TransitTunnel.h" #include "TransitTunnel.h"

2
TunnelBase.h → tunnel/TunnelBase.h

@ -3,7 +3,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <memory> #include <memory>
#include "Timestamp.h" #include "util/Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Identity.h" #include "Identity.h"

4
TunnelConfig.h → tunnel/TunnelConfig.h

@ -5,10 +5,10 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include "aes.h" #include "TunnelCrypto.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Timestamp.h" #include "util/Timestamp.h"
namespace i2p namespace i2p
{ {

88
tunnel/TunnelCrypto.cpp

@ -0,0 +1,88 @@
#include "TunnelCrypto.h"
#include "TunnelBase.h"
#include "AESNIMacros.h"
namespace i2p {
namespace crypto {
void TunnelEncryption::SetKeys (const AESKey& layerKey, const AESKey& ivKey)
{
m_LayerEncryption.SetKey (layerKey);
m_IVEncryption.SetKey (ivKey);
}
void TunnelEncryption::Encrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
// encrypt IV
"movups (%[in]), %%xmm0 \n"
EncryptAES256(sched_iv)
"movaps %%xmm0, %%xmm1 \n"
// double IV encryption
EncryptAES256(sched_iv)
"movups %%xmm0, (%[out]) \n"
// encrypt data, IV is xmm1
"1: \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched_l)
"movaps %%xmm0, %%xmm1 \n"
"movups %%xmm0, (%[out]) \n"
"dec %[num] \n"
"jnz 1b \n"
:
: [sched_iv]"r"(m_IVEncryption.GetKeySchedule ()), [sched_l]"r"(m_LayerEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
: "%xmm0", "%xmm1", "cc", "memory"
);
#else
m_IVEncryption.Encrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
m_LayerEncryption.SetIV (out);
m_LayerEncryption.Encrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
m_IVEncryption.Encrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
#endif
}
void TunnelDecryption::Decrypt (const uint8_t * in, uint8_t * out)
{
#ifdef AESNI
__asm__
(
// decrypt IV
"movups (%[in]), %%xmm0 \n"
DecryptAES256(sched_iv)
"movaps %%xmm0, %%xmm1 \n"
// double IV encryption
DecryptAES256(sched_iv)
"movups %%xmm0, (%[out]) \n"
// decrypt data, IV is xmm1
"1: \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"movups (%[in]), %%xmm0 \n"
"movaps %%xmm0, %%xmm2 \n"
DecryptAES256(sched_l)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
"movaps %%xmm2, %%xmm1 \n"
"dec %[num] \n"
"jnz 1b \n"
:
: [sched_iv]"r"(m_IVDecryption.GetKeySchedule ()), [sched_l]"r"(m_LayerDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
);
#else
m_IVDecryption.Decrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
m_LayerDecryption.SetIV (out);
m_LayerDecryption.Decrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
m_IVDecryption.Decrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
#endif
}
} // crypto
} // i2p

49
tunnel/TunnelCrypto.h

@ -0,0 +1,49 @@
#ifndef TUNNEL_CRYPTO_H__
#define TUNNEL_CRYPTO_H__
#include "crypto/aes.h"
namespace i2p {
namespace crypto {
class TunnelEncryption { // with double IV encryption
public:
void SetKeys (const AESKey& layerKey, const AESKey& ivKey);
void Encrypt (const uint8_t * in, uint8_t * out); // 1024 bytes (16 IV + 1008 data)
private:
ECBEncryption m_IVEncryption;
#ifdef AESNI
ECBEncryption m_LayerEncryption;
#else
CBCEncryption m_LayerEncryption;
#endif
};
class TunnelDecryption { // with double IV encryption
public:
void SetKeys (const AESKey& layerKey, const AESKey& ivKey)
{
m_LayerDecryption.SetKey (layerKey);
m_IVDecryption.SetKey (ivKey);
}
void Decrypt (const uint8_t * in, uint8_t * out); // 1024 bytes (16 IV + 1008 data)
private:
ECBDecryption m_IVDecryption;
#ifdef AESNI
ECBDecryption m_LayerDecryption;
#else
CBCDecryption m_LayerDecryption;
#endif
};
} // crypto
} // i2p
#endif

6
TunnelEndpoint.cpp → tunnel/TunnelEndpoint.cpp

@ -1,9 +1,9 @@
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <string.h> #include <string.h>
#include "Log.h" #include "util/Log.h"
#include "NetDb.h" #include "NetDb.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Transports.h" #include "transport/Transports.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "TunnelEndpoint.h" #include "TunnelEndpoint.h"

0
TunnelEndpoint.h → tunnel/TunnelEndpoint.h

6
TunnelGateway.cpp → tunnel/TunnelGateway.cpp

@ -1,9 +1,9 @@
#include <string.h> #include <string.h>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include "Log.h" #include "util/Log.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Transports.h" #include "transport/Transports.h"
#include "TunnelGateway.h" #include "TunnelGateway.h"
namespace i2p namespace i2p

0
TunnelGateway.h → tunnel/TunnelGateway.h

8
TunnelPool.cpp → tunnel/TunnelPool.cpp

@ -1,11 +1,11 @@
#include <algorithm> #include <algorithm>
#include "I2PEndian.h" #include "util/I2PEndian.h"
#include "CryptoConst.h" #include "crypto/CryptoConst.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "NetDb.h" #include "NetDb.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "Garlic.h" #include "Garlic.h"
#include "Transports.h" #include "transport/Transports.h"
#include "TunnelPool.h" #include "TunnelPool.h"
namespace i2p namespace i2p

0
TunnelPool.h → tunnel/TunnelPool.h

0
I2PEndian.cpp → util/I2PEndian.cpp

0
I2PEndian.h → util/I2PEndian.h

0
LittleBigEndian.h → util/LittleBigEndian.h

0
Log.cpp → util/Log.cpp

0
Log.h → util/Log.h

0
Queue.h → util/Queue.h

0
Timestamp.h → util/Timestamp.h

2
base64.cpp → util/base64.cpp

@ -3,7 +3,7 @@
namespace i2p namespace i2p
{ {
namespace data namespace util
{ {
static void iT64Build(void); static void iT64Build(void);

2
base64.h → util/base64.h

@ -6,7 +6,7 @@
namespace i2p namespace i2p
{ {
namespace data namespace util
{ {

0
util.cpp → util/util.cpp

0
util.h → util/util.h

Loading…
Cancel
Save