2
$\begingroup$

Does there exist any hashing function that has a different output for all of the messages?

For example, let's say we have the function $H_{256}(x)$

Where $H$ is a 256 bit digest. Is it possible to construct $H$ so that it has a different output for every combination from $0$ to $(2^{256}-1)$?

EDIT: what I mean is, if you have a hash function which produces a fixed length 256 bit digest, is it possible to make such function so that every permutation of 1's and 0's of length 256 have a different output? I hope I'm clear now

$\endgroup$
8
  • 1
    $\begingroup$ That is a permutation. Use AES and you have it. If you want 256 use Rijndael. $\endgroup$
    – kelalaka
    Oct 25, 2019 at 16:30
  • $\begingroup$ @kelalaka, the other problem is that AES has a key. What do you use for a key? Hash functions themselves do not have secret values, so the key must be known to all, so for any message of just a single block, you could decrypt to get the original. $\endgroup$
    – mikeazo
    Oct 25, 2019 at 16:35
  • 2
    $\begingroup$ Here's one: $H(x) := x$. But maybe you want some security properties other than distinctness for all inputs? Why do you need it to be actually injective, rather than merely (say) preimage-resistant? $\endgroup$ Oct 25, 2019 at 16:40
  • $\begingroup$ @mikeazo you can fix the key. Anyway, the question title is also misleading. Maybe the op needs UUID if he has some aim. $\endgroup$
    – kelalaka
    Oct 25, 2019 at 17:03
  • $\begingroup$ Isn't the answer simply "Unknown." since we can't prove that a hash function like SHA-2 will / won't have any collisions? $\endgroup$ Oct 25, 2019 at 17:04

1 Answer 1

1
$\begingroup$

What you are looking for is a permutation, and not normally what we call a hash function. The identity function is a permutation and so is modular addition. And many more.

You probably want some other properties of cryptographicly secure hash functions such as preimage resistance.

A pseudo random permutation will suffice any secure block cipher such as AES will meet the bill.

Note this in itself isn't a usefull hash function, for hash functions we want a compression function where the output is smaller than the input. From pigeon hole principal it is obvious that if the output domain of a function is smaller than it's input domain it must have collisions and can not be a permutation.

With cryptographically secure hash functions like SHA-3 we fully expect there to be many collisions even when the input domain is restricted to match the output domain we simply don't know how to find any such collisions which is a basic requirement for cryptographically secure hash functions.

$\endgroup$

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