Skip to content

Commit

Permalink
verify checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jun 28, 2014
1 parent 46ce01c commit 3a864cb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions TunnelEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ namespace tunnel
{
LogPrint ("TunnelMessage: zero found at ", (int)(zero-decrypted));
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)
{
uint8_t flag = fragment[0];
Expand Down

0 comments on commit 3a864cb

Please sign in to comment.