1
$\begingroup$

I need to generate a hash for a small piece of data (~50 bytes). I'd normally use MD5 or SHA but that's not available in the platform I'm programming for.

Luckily, it provides Triple DES and I thought I could use it as cryptographic hash function (pseudo-code):

function MyHash(text)
    data = padded(text, 64)
    key = data[0:8] + data[8:16] + data[16:24]
    encrypted = TripleDES(data, key)
    return encrypted[0:16]

MyHash will produce 128-bit (16-bytes) long hashes for input text.

Is MyHash secure? How does it compare with MD5 and SHA-*?

$\endgroup$
  • 2
    $\begingroup$ The HAC can provide standard constructions. $\endgroup$ – SEJPM Oct 21 '15 at 12:31
  • 3
    $\begingroup$ We can't guess what TripleDES(data, key) does when data is larger than 8 bytes, which is apparently the case. Using any standard operating mode, either MyHash is not a function (it won't give the same result when called twice with the same input), or bytes starting from the 25th in the input (and the low-order bits of the 17th to 24th bytes) do not influence output. In either case, MyHash is a poor cryptographic hash function. $\endgroup$ – fgrieu Oct 21 '15 at 12:39
  • $\begingroup$ maybe using 3DES as in CBC-MAC with a fixed key? just guessing, still not analyzed the scheme. $\endgroup$ – ddddavidee Oct 21 '15 at 12:50
  • $\begingroup$ I can't use a fixed key. I really need to make irreversible. $\endgroup$ – Igor Gatis Oct 21 '15 at 12:52
2
$\begingroup$

It is not a secure hash. For example, it is easy to find collisions and second preimages for your hash function if the input is allowed to be longer than 24 bytes, because only the first three 64-bit blocks affect the output.

Additionally, it should not even work with a typical DES implementation. DES keys are 56 bits, encoded as 64-bit values where 8 bits are for parity. Arbitrary inputs will not produce a well formatted key.

$\endgroup$
  • $\begingroup$ What if they CBC encrypt pkcs#7 padded message using first 24 bytes as key (after fixing parity bits in key) or first 21 bytes as key, whichever is easier, and use the ciphertext of the last block? $\endgroup$ – Z.T. Oct 21 '15 at 17:05
  • $\begingroup$ @Z.T. with CBC you can change a block of ciphertext in the middle (not in the first three or the last blocks) and decrypt to find another message that ends with the same values. (Also, using only one final block would be 64 bits for which collisions can easily be brute forced.) $\endgroup$ – otus Oct 22 '15 at 7:08

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.