2
$\begingroup$

As we are all aware that HASHing is user to verify integrity in cryptography. I have a query about hashing.

Suppose a man in the middle attacker manipulates the data and creates new HASH (by running algorithm on manipulated data) using the same hashing algorithm (becausehashing algorithms are universal algorithms) and send it along with the manipulated data to the receiver.when receiver runs the algorithm on manipulated data, it gets the same HASH ( HASH created by the attacker) and though integrity will be verified. But actual data has been manipulated/modified and integrity is compromised.

Is it possible? and if it is possible how can we eliminate this problem (solution for the same)?

$\endgroup$
6
$\begingroup$

Indeed hashing is used to ensure integrity, but not this way.

What you have in mind it seems is sending (msg, Hash(msg)). Indeed this is not secure because of the attack you describe.

The first step starts with something you say by yourself:

hashing algorithms are universal algorithms

The name is not univesal but public, it means anyone knows it. Instead of a hashing algorithm we will use a MAC (Wikipedia:MAC), which a hashing algorithm with a key. A well-spread MAC construction is HMAC: HMAC(msg,key1,key2) = H( key1 || H(key2||msg) ) where H is a cryptographic hash and || is concatenation.

If we prevent the adversary from knowing the key we used, he cannot re-compute the MAC after he modified the message. So now we only need privacy on the MAC key, which is another challenge, you can solve it with a Key-Exchange protocol (typically: Diffie-Hellman), probably with authentication if you have a Man-In-The-Middle, and so on ...

$\endgroup$
  • 2
    $\begingroup$ Digital signatures also work. $\endgroup$ – cpast Apr 17 '15 at 17:46
  • 2
    $\begingroup$ That said, sending (msg, Hash(msg)) is common, but not as a security measure. It's just a way to ensure that a download completed successfully without corrupting any data due to an unreliable connection. For that purpose, it's perfectly fine, though a MAC will do the same AND provide authentication. $\endgroup$ – SAI Peregrinus Apr 18 '15 at 4:22
2
$\begingroup$

Usually Hashes are not used by themselves for integrity for exactly the reason you state. To make them stronger we take the hash and encrypt it using the private key of the sender. This way anybody who has the sender's public key can decrypt the hash and check it against a new hash of the message, but a man-in-the-middle can not fake it since they do not have the sender's private key.

This is called a digital signature.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.