Browse Source

SSUHeader and authenticate added

pull/14/head
orignal 11 years ago
parent
commit
8d4b98c83a
  1. 10
      SSU.cpp
  2. 20
      SSU.h
  3. 3
      hmac.h

10
SSU.cpp

@ -14,6 +14,16 @@ namespace ssu
void SSUSession::ProcessNextMessage (uint8_t * buf, std::size_t len) void SSUSession::ProcessNextMessage (uint8_t * buf, std::size_t len)
{ {
switch (m_State)
{
default:
LogPrint ("SSU state not implemented yet");
}
}
void SSUSession::Authenticate (uint8_t * buf, size_t len, uint8_t * aesKey, uint8_t * iv, uint8_t * macKey)
{
m_Encryption.SetKeyWithIV (aesKey, 32, iv);
} }
SSUServer::SSUServer (boost::asio::io_service& service, int port): SSUServer::SSUServer (boost::asio::io_service& service, int port):

20
SSU.h

@ -4,11 +4,24 @@
#include <inttypes.h> #include <inttypes.h>
#include <map> #include <map>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <cryptopp/modes.h>
#include <cryptopp/aes.h>
#include "I2PEndian.h"
namespace i2p namespace i2p
{ {
namespace ssu namespace ssu
{ {
#pragma pack(1)
struct SSUHeader
{
uint8_t mac[16];
uint8_t iv[16];
uint8_t flag;
uint32_t time;
};
#pragma pack()
const int SSU_MTU = 1484; const int SSU_MTU = 1484;
// payload types (4 bits) // payload types (4 bits)
@ -38,11 +51,16 @@ namespace ssu
public: public:
SSUSession (); SSUSession ();
void ProcessNextMessage (uint8_t * buf, std::size_t len); void ProcessNextMessage (uint8_t * buf, size_t len);
private:
void Authenticate (uint8_t * buf, size_t len, uint8_t * aesKey, uint8_t * iv, uint8_t * macKey);
private: private:
SessionState m_State; SessionState m_State;
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption m_Encryption;
}; };
class SSUServer class SSUServer

3
hmac.h

@ -19,7 +19,7 @@ namespace crypto
// block size is 64 bytes // block size is 64 bytes
{ {
size_t totalLen = len + 64 + 32; size_t totalLen = len + 64 + 32;
uint8_t * buf = new uint8_t[totalLen]; // TODO: reuse buffers uint8_t buf[2048];
// ikeypad // ikeypad
((uint64_t *)buf)[0] = ((uint64_t *)key)[0] ^ IPAD; ((uint64_t *)buf)[0] = ((uint64_t *)key)[0] ^ IPAD;
((uint64_t *)buf)[1] = ((uint64_t *)key)[1] ^ IPAD; ((uint64_t *)buf)[1] = ((uint64_t *)key)[1] ^ IPAD;
@ -51,7 +51,6 @@ namespace crypto
// calculate digest // calculate digest
CryptoPP::Weak1::MD5().CalculateDigest (digest, buf, totalLen); CryptoPP::Weak1::MD5().CalculateDigest (digest, buf, totalLen);
delete[] buf;
} }
} }
} }

Loading…
Cancel
Save