# Question about keyed hash functions

Maybe the answer to my question is obvious, but I have doubt...

I have noticed that hash functions are studied in two forms, keyed hash functions or unkeyed. In general, lecture notes present hash function without key.

Is there a key generation algorithm for a keyed hash function?

• Typically, one would expect a keyed hash function to take an arbitrary (possibly fixed length) binary string as the key; what that function does with the key is going to be awfully specific to the function. – poncho Jul 4 '15 at 16:34
• keyed hash functions...could it be that you're hinting at hmacs, or are you specifically asking about non-HMAC hash functions (which are rarely keyed, unless some individual implementation requires it while excluding/ignoring HMAC for whatever reason)? In the later (non-HMAC) case, the comment by Poncho pretty much wraps things up. – e-sushi Jul 4 '15 at 17:45
• @poncho Thank you for your comments. I'm referring to non hmac algorithms. In general, for a signature (or encryption) algorithm, there is a key generation function. That's why I wonder if there is such a generation function for hashing. So, is there such a key generation algorithm for a keyed hash function ? – Dingo13 Jul 5 '15 at 18:28
• Public key algorithms (such as signature and public key encryption, which you appear to be referring to) need to generate two keys, which are related (but not in an obvious way; at least, from the public key, you can't easily derive the private key); hence they need a procedure to generate those two keys. Symmetric algorithms (such as a keyed hash) only need one key, and are generally arranged so that an arbitrary bit string works (and hence there is no specific 'key generation' algorithm needed) – poncho Jul 5 '15 at 19:36
• @poncho Note that this is generally the case for symmetric schemes, and in fact, it can even be proven that without loss of generality it can be defined this way (at the cost of efficiency in encryption/decryption since the actual key has to be sampled from scratch each time). However, there are lattice-based symmetric encryption schemes with homomorphic properties. These do have keys that have a specific format... Again, this is the exception though and not the rule. – Yehuda Lindell Jul 6 '15 at 20:11

I think that you may be referring to hash functions with (not secret) keys as presented in any theoretically rigorous text on cryptography. In practice, hash functions do NOT have keys. However, if you try to define collision resistance without keyed hash functions, then it is impossible to achieve. This is because there always exists an adversary who finds a collision (this is an adversary who has a collision hardwired in its code). You may not be able to FIND such an adversary, but they certainly exist. We therefore define hash functions to have keys which are chosen after the adversary is fixed. (See textbooks for more discussion; it's an annoying technicality, but very not trivial.)

There a few ways to bridge this theory and practice. One is to say that the IV in practical hash functions is the key. I like this one, but most people don't (so I'm in the minority). Another is this paper by Rogaway http://web.cs.ucdavis.edu/~rogaway/papers/ignorance.pdf. Anyway, the introduction to that paper will also help explain the problem.

Hmac is an algo to make keyless hash into keyed hash. keyed hash example is AES-MAC and keyless example is Sha-1, MD5. HMAC- AES uses key to produce MAC. the MAC is derived by computation using the ipad and opad along with the key and the message .HMAC-AES: MAC(M)=c(t), the last block in cbc mode.