Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is non destructive hash post processing a good idea?

Tags:

security

hash

Is it a good idea to do some kind of non destructive post processing (reordering) on hash strings before storing then? Ex:

$hash = strrev(hash($algo, $data . $salt));

Other example:

$hash = hash($algo, $data . $salt)
$hash = strrev(substr($hash, 0, (int) ($length / 2))) . strrev(substr($hash, (int) ($length / 2)));

Instead of simply:

$hash = hash($algo, $data . $salt);

In other words:

Considering the breaker will not know how the hashes were transformed, will first two examples result in less breakable hashes than third example?

I'm NOT saying I will strrev my hashes, this is just the most simple example I could think of to illustrate what "non destructive" means in this context: to post process the hash without reduce algorithm's key space.

Answers I'm NOT looking for:

  • Dude, use a salt to avoid raimbow table blah blah - Rainbow table is related though
  • Just rehash your hash like this hash(hash(hash($data))) - Question is not about rehashing
  • Please please please do not roll your own crypto - That's not what I'm talking about
  • DON'T RUN YOUR OWN CRYPTO. - This won't help either

Answer I'm actually looking for:

This is (is not) a good idea because of ...reasons... Here is some example about why you should (should not) do this: ...example... Also, read this ...paper, article, post, link to a research... that proves my point.

like image 655
marcio Avatar asked Feb 02 '26 04:02

marcio


1 Answers

Let's try analyzing the proposed algorithm as if the "non destructive post processing" were a secret function, taken from some space of possible functions.

In this view, the post processing is somewhat like a key, and the overall algorithm is a keyed hash (like HMAC). Here are some key points about this algorithm.

A keyed hash may be resistant to known-plaintext attacks: if an attacker knows the input values of many post processed hashes, it should still be hard to find the "key". However, if the post processing is simple, like strrev in your example, it could be very easy for an attacker to figure out the "key".

You'd have to design the space of these functions carefully.

edit: how 'bout just applying a block cipher to the hash result? At least that way, you can take advantage of the strength of a well scrutinized space of non destructive functions.

like image 113
guest Avatar answered Feb 05 '26 00:02

guest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!