verify checksum

This commit is contained in:
orignal 2014-06-27 20:11:21 -04:00
parent 46ce01c89d
commit 3a864cb6c5

View File

@ -19,6 +19,17 @@ namespace tunnel
{ {
LogPrint ("TunnelMessage: zero found at ", (int)(zero-decrypted)); LogPrint ("TunnelMessage: zero found at ", (int)(zero-decrypted));
uint8_t * fragment = zero + 1; uint8_t * fragment = zero + 1;
// verify checksum
memcpy (msg->GetPayload () + TUNNEL_DATA_MSG_SIZE, msg->GetPayload () + 4, 16); // copy iv to the end
uint8_t hash[32];
CryptoPP::SHA256().CalculateDigest (hash, fragment, TUNNEL_DATA_MSG_SIZE -(fragment - msg->GetPayload ()) + 16); // payload + iv
if (memcmp (hash, decrypted, 4))
{
LogPrint ("TunnelMessage: checksum verification failed");
i2p::DeleteI2NPMessage (msg);
return;
}
// process fragments
while (fragment < decrypted + TUNNEL_DATA_ENCRYPTED_SIZE) while (fragment < decrypted + TUNNEL_DATA_ENCRYPTED_SIZE)
{ {
uint8_t flag = fragment[0]; uint8_t flag = fragment[0];