0
$\begingroup$

Is it ok to create and store the hash (unkeyed hash function) of a plaintext before encryption or does it lead to vulnerabilities? If it is ok are there requirements for the used hash function and encryption algorithm?

Important to mention is that the hash should not be used for integrity checks or something like that.

$\endgroup$
6
  • 1
    $\begingroup$ What is it used for? What are your security requirements, i.e. why are you using encryption in the first place? Are you planning on storing the digest and the cipher text in the same location or in different locations? $\endgroup$ Feb 18, 2016 at 13:08
  • $\begingroup$ I want to encrypt files and the digest and the cipher text should be stored in the same location. The question is more theoretical but the hash could be used for example for searching or something like this. $\endgroup$
    – Bernhard
    Feb 18, 2016 at 13:20
  • $\begingroup$ Why not hash the encrypted file? $\endgroup$ Feb 18, 2016 at 13:49
  • $\begingroup$ I believe this goes against the use case as seen in OP's comment. $\endgroup$
    – Artjom B.
    Feb 18, 2016 at 13:55
  • $\begingroup$ @ArtjomB. you are right. $\endgroup$
    – Bernhard
    Feb 18, 2016 at 14:08

1 Answer 1

3
$\begingroup$

This will be less secure than storing only the encrypted data or storing also the hash of the encrypted data.

In your scenario, you give more options to an attacker, because it is possible to attack both the cryptosystem and the hash. For instance, think of an attacker that found a preimage attack to the hash...

Moreover, since the hash is deterministic, it allows some kinds of inference attacks, because if two stored hashs $h_1$ and $h_2$ are equal, then, they are probably hashs of the same message. This is the reason we use probabilistic encryption schemes.

$\endgroup$
3
  • 1
    $\begingroup$ If the hash function is a secure hash function then "they are probably hash values of the same message" should be replaced by a stronger statement. $\endgroup$
    – Maarten Bodewes
    Feb 18, 2016 at 15:57
  • $\begingroup$ Hello, @MaartenBodewes. Well, like which statement? I said "probably" because even if $m_1 \neq m_2$, it may happen that $h(m_1) = h(m_2)$... $\endgroup$ Feb 18, 2016 at 16:20
  • 1
    $\begingroup$ For an unbroken secure hash function that chance should be negligible. $\endgroup$
    – Maarten Bodewes
    Feb 18, 2016 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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