|
|
@ -57,10 +57,8 @@ namespace tunnel |
|
|
|
while (hop) |
|
|
|
while (hop) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (size_t i = ind; i < numRecords; i++) |
|
|
|
for (size_t i = ind; i < numRecords; i++) |
|
|
|
{ |
|
|
|
hop->decryption.Decrypt((uint8_t *)&records[i], |
|
|
|
m_CBCDecryption.SetKeyWithIV (hop->replyKey, 32, hop->replyIV); |
|
|
|
sizeof (I2NPBuildRequestRecordElGamalEncrypted), (uint8_t *)&records[i]); |
|
|
|
m_CBCDecryption.ProcessData((uint8_t *)&records[i], (uint8_t *)&records[i], sizeof (I2NPBuildRequestRecordElGamalEncrypted)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
hop = hop->prev; |
|
|
|
hop = hop->prev; |
|
|
|
ind--; |
|
|
|
ind--; |
|
|
|
} |
|
|
|
} |
|
|
@ -83,8 +81,7 @@ namespace tunnel |
|
|
|
for (int i = 0; i < num; i++) |
|
|
|
for (int i = 0; i < num; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t * record = msg + 1 + i*sizeof (I2NPBuildResponseRecord); |
|
|
|
uint8_t * record = msg + 1 + i*sizeof (I2NPBuildResponseRecord); |
|
|
|
m_CBCDecryption.SetKeyWithIV(hop->replyKey, 32, hop->replyIV); |
|
|
|
hop->decryption.Decrypt(record, sizeof (I2NPBuildResponseRecord), record); |
|
|
|
m_CBCDecryption.ProcessData(record, record, sizeof (I2NPBuildResponseRecord)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
hop = hop->prev; |
|
|
|
hop = hop->prev; |
|
|
|
num--; |
|
|
|
num--; |
|
|
@ -99,20 +96,18 @@ namespace tunnel |
|
|
|
// if any of participants declined the tunnel is not established
|
|
|
|
// if any of participants declined the tunnel is not established
|
|
|
|
m_IsEstablished = false; |
|
|
|
m_IsEstablished = false; |
|
|
|
} |
|
|
|
} |
|
|
|
return m_IsEstablished; |
|
|
|
if (m_IsEstablished) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tunnel::LayerDecrypt (const uint8_t * in, size_t len, const uint8_t * layerKey, |
|
|
|
|
|
|
|
const uint8_t * iv, uint8_t * out) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
m_CBCDecryption.SetKeyWithIV (layerKey, 32, iv); |
|
|
|
// change reply keys to layer keys
|
|
|
|
m_CBCDecryption.ProcessData(out, in, len); |
|
|
|
TunnelHopConfig * hop = m_Config->GetFirstHop (); |
|
|
|
} |
|
|
|
while (hop) |
|
|
|
|
|
|
|
|
|
|
|
void Tunnel::IVDecrypt (const uint8_t * in, const uint8_t * ivKey, uint8_t * out) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
m_ECBDecryption.SetKey (ivKey, 32); |
|
|
|
hop->decryption.SetKey (hop->layerKey); |
|
|
|
m_ECBDecryption.ProcessData(out, in, 16); |
|
|
|
hop->ivDecryption.SetKey (hop->ivKey); |
|
|
|
|
|
|
|
hop = hop->next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return m_IsEstablished; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Tunnel::EncryptTunnelMsg (I2NPMessage * tunnelMsg) |
|
|
|
void Tunnel::EncryptTunnelMsg (I2NPMessage * tunnelMsg) |
|
|
@ -121,10 +116,14 @@ namespace tunnel |
|
|
|
TunnelHopConfig * hop = m_Config->GetLastHop (); |
|
|
|
TunnelHopConfig * hop = m_Config->GetLastHop (); |
|
|
|
while (hop) |
|
|
|
while (hop) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// iv + data
|
|
|
|
// iv
|
|
|
|
IVDecrypt (payload, hop->ivKey, payload); |
|
|
|
hop->ivDecryption.Decrypt ((i2p::crypto::ChipherBlock *)payload, (i2p::crypto::ChipherBlock *)payload); |
|
|
|
LayerDecrypt (payload + 16, TUNNEL_DATA_ENCRYPTED_SIZE, hop->layerKey, payload, payload+16); |
|
|
|
// data
|
|
|
|
IVDecrypt (payload, hop->ivKey, payload); |
|
|
|
hop->decryption.SetIV (payload); |
|
|
|
|
|
|
|
hop->decryption.Decrypt (payload + 16, TUNNEL_DATA_ENCRYPTED_SIZE, payload+16); |
|
|
|
|
|
|
|
// double iv ecncryption
|
|
|
|
|
|
|
|
hop->ivDecryption.Decrypt ((i2p::crypto::ChipherBlock *)payload, (i2p::crypto::ChipherBlock *)payload); |
|
|
|
|
|
|
|
|
|
|
|
hop = hop->prev; |
|
|
|
hop = hop->prev; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|