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'm designing a scheme for management of a small number of cryptographic keys (< 100 at any given time) and I had an idea: rather than storing all the keys, could I just store one master key and use a KDF to derive the particular key I need by varying the salt in a certain way?

For example, if I need the second encryption key for usage X, I'd give something like PBKDF a salt of

$$2||“encryption”||X||<random value>$$

which would uniquely derive the second version of that particular key.

share|improve this question
Hmm, good idea. Does this kind of scheme have a name, so I can do more research? – pg1989 Jul 2 '13 at 23:46
If your master key is already high-entropy (ie, 16+ bytes generated by a CSPRNG), I'd recommend HKDF. You can use the 'info' input to bind each key to an individual context (ie, a username, serial number, etc). – hunter Jul 3 '13 at 0:09
@hunter yes, in general a KBKDF should be preferred over a PBKDF. I've created an answer on this fact that also mentions the NIST 800-108 specification (which HKDF should improve upon according some claims I've read through very quickly). – Maarten Bodewes Jul 3 '13 at 0:13
BouncyCastle has an implementation of HKDF. Thanks much everybody, this is very helpful. – pg1989 Jul 3 '13 at 0:22
Apologies. I misread the question as having a master password to from which keys would be generated from. I've deleted my comment. – Stephen Touset Jul 3 '13 at 17:34
up vote 2 down vote accepted

You should not use a Password Based Key Derivation Function (PBKDF) for this. Instead you need a Key Based Key Derivation Function (KBKDF). You could use for instance NIST SP 800-108 (PDF) or HKDF. Both specify means for key derivation using some kind of context which is used as input for the KDF (e.g. a label or sequence number).

A salt is used in a similar fashion in PBKDF, but a salt has a different purpose than context data. Furthermore, it is not that likely that you need key strengthening which is delivered by the salt and iteration count commonly used in PBKDF's. If your master key is strong enough, then the derived keys should be safe without additional measures. PBKDF's are deliberately slow, KBKDF's aren't.

Note that KDF implementations may not be that widespread. They are however relatively easy to compose using the MAC or HMAC primitives that supply the necessary PRF functionality. If you go that way, don't forget to test against the available test vectors though.

If you go for the NIST defined KBKDF's I would advice for a counter mode KDF based on either HMAC using SHA-256 or AES-CMAC as they are easiest to implement and seem to be the most common implementations in the field.

[EDIT] When using HKDF it is advisable use use a Salt value even if your input key material (the master key) provides a lot of entropy. It is however not required for this use case. Neither do you have to use the extract function of HKDF, but normally you would want to perform it anyway for the sake of compatibility. Basically: only skip the Salt and extract function if you have strong resource constraints.

share|improve this answer
To use HKDF in this example, would you have a unique, randomly-generated salt for each context and perform the entire HKDF-Hash function? Or would you simply use the HKDF-Expand step with the context itself? – Stephen Touset Jul 3 '13 at 17:41
Sorry, I may have been unclear. HDKF consists of two steps: HDKF-Expand, and HKDF-Extract. HKDF-Expand expects a salt input. HKDF-Extract expects an info input. For this scenario, would you perform both steps, with a random salt and distinct info per context? Or would you simply perform the HKDF-Extract with the distinct info describing the context? – Stephen Touset Jul 3 '13 at 18:16
@StephenTouset If there is space for a derived key specific salt I would use it as the authors of HKDF are very clear that using a the Salt provides a lot of security. For an "input key material" with enough entropy the Salt or HKDF-Expand functions are not required, but I would personally always use HKDF-Expand for the sake of compatibility - again as the authors advice in the RFC and paper. Thanks for helping me improve the answer. – Maarten Bodewes Jul 4 '13 at 21:37
@StephenTouset Removed previous comment, it is better to be cautious regarding security, although adding a salt may be overdoing it for a KBKDF if the master key has enough entropy. – Maarten Bodewes Jul 4 '13 at 21:44

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.