Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have heard that to combine two keys HKDF is better than using XOR function. But if you look at the HKDF RFC I could not figure out how to use it for concatenating two keys. What I can see is HKDF can be used to derive a key from another key. So I want to know how to use HKDF to concatenate two keys.

share|improve this question
up vote 2 down vote accepted

If you have two keys of constant length, using HKDF is rather pointless.

You can simply combine them using a hash function like SHA-2:

$$combined\_key = \text{SHA-2}(k_1 || k_2)$$

share|improve this answer
In CSE I have seen HKDF is recommended to use for key concatenation because it preserves the entropy unlike in a XOR function.…;. So why you are saying HKDF is pointless. Please enlighten me. I want the finale key to be as random as possible. Thats why I am using HKDF to concatenation without using HASH alto or a XOR function. – user10988 Dec 20 '13 at 7:16
@user10988 In your scenario HKDF basically comes down to a HMAC-SHA-256 call. HMAC has no advantage compared to SHA in this scenario, because the input is of constant length, so you might as well hash. – orlp Dec 20 '13 at 7:32
Thank you for explanation. One more question.Will using a hash function be better than use XOR the two keys(Considering the entropy)? – user10988 Dec 20 '13 at 7:52
@user10988 Hashing is better than xor-ing, for the same reason that HKDF is better than xor-ing. HKDF with a constant salt is a hash. – CodesInChaos Dec 20 '13 at 9:00

Forgive me for sounding condescending – that’s not the intent – but to “concatenate 2 keys” you use “concatenation” operation. Not XOR, HKDF, HASH/SHA-2, etc. The only proper way of concatenating an n-bit Key1 and m-bit Key2 - without entropy loss - is to concatenate them.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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