Browse Source

use AES-NI for transit tunnel encryption

pull/72/head
orignal 11 years ago
parent
commit
61147def94
  1. 14
      TransitTunnel.cpp
  2. 9
      TransitTunnel.h

14
TransitTunnel.cpp

@ -17,22 +17,20 @@ namespace tunnel
m_TunnelID (receiveTunnelID), m_NextTunnelID (nextTunnelID), m_TunnelID (receiveTunnelID), m_NextTunnelID (nextTunnelID),
m_NextIdent (nextIdent), m_NumTransmittedBytes (0) m_NextIdent (nextIdent), m_NumTransmittedBytes (0)
{ {
memcpy (m_LayerKey, layerKey, 32); m_ECBEncryption.SetKey (ivKey);
memcpy (m_IVKey, ivKey, 32); m_CBCEncryption.SetKey (layerKey);
} }
void TransitTunnel::EncryptTunnelMsg (I2NPMessage * tunnelMsg) void TransitTunnel::EncryptTunnelMsg (I2NPMessage * tunnelMsg)
{ {
uint8_t * payload = tunnelMsg->GetPayload () + 4; uint8_t * payload = tunnelMsg->GetPayload () + 4;
m_ECBEncryption.SetKey (m_IVKey, 32);
m_ECBEncryption.ProcessData(payload, payload, 16); // iv
m_CBCEncryption.SetKeyWithIV (m_LayerKey, 32, payload); m_ECBEncryption.Encrypt ((i2p::crypto::ChipherBlock *)payload, (i2p::crypto::ChipherBlock *)payload); // iv
m_CBCEncryption.ProcessData(payload + 16, payload + 16, TUNNEL_DATA_ENCRYPTED_SIZE); // payload
m_ECBEncryption.SetKey (m_IVKey, 32); m_CBCEncryption.SetIV (payload);
m_ECBEncryption.ProcessData(payload, payload, 16); // double iv encryption m_CBCEncryption.Encrypt (payload + 16, TUNNEL_DATA_ENCRYPTED_SIZE, payload + 16); // payload
m_ECBEncryption.Encrypt((i2p::crypto::ChipherBlock *)payload, (i2p::crypto::ChipherBlock *)payload); // double iv encryption
} }
void TransitTunnel::HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg) void TransitTunnel::HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg)

9
TransitTunnel.h

@ -2,8 +2,7 @@
#define TRANSIT_TUNNEL_H__ #define TRANSIT_TUNNEL_H__
#include <inttypes.h> #include <inttypes.h>
#include <cryptopp/modes.h> #include "aes.h"
#include <cryptopp/aes.h>
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "TunnelEndpoint.h" #include "TunnelEndpoint.h"
#include "TunnelGateway.h" #include "TunnelGateway.h"
@ -36,12 +35,10 @@ namespace tunnel
uint32_t m_TunnelID, m_NextTunnelID; uint32_t m_TunnelID, m_NextTunnelID;
i2p::data::IdentHash m_NextIdent; i2p::data::IdentHash m_NextIdent;
uint8_t m_LayerKey[32];
uint8_t m_IVKey[32];
size_t m_NumTransmittedBytes; size_t m_NumTransmittedBytes;
CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption m_ECBEncryption; i2p::crypto::ECBEncryption m_ECBEncryption;
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption m_CBCEncryption; i2p::crypto::CBCEncryption m_CBCEncryption;
}; };
class TransitTunnelGateway: public TransitTunnel class TransitTunnelGateway: public TransitTunnel

Loading…
Cancel
Save