I'm working on a project where I need to derive several child keys from a parent key. I'm not a cryptography expert, so I'd really appreciate a simple explanation to help me understand the best practices and potential risks involved.
Here's the method I'm currently considering; I derive each child key using the SHA-256 hash function as follows:
child_key = SHA256( SHA256( 256_bit_parent_key || label ) || version )
Where:
- parent_key is the original key from which I'm deriving child keys.
- label is a unique UTF-8 string identifier for each child.
- version is the number of times the key has been previously rotated.
My questions are:
Compromise Concerns: Are there any concerns that if one or more child keys are compromised, it could lead to the compromise of other child keys or even the parent key using this method?
NIST Recommendation: I read in NIST Special Publication 800-108 that in a key derivation hierarchy, child keys should be used either for deriving other child keys or for other purposes (but not both). Is this recommendation due to specific security concerns?
SHA-256 vs. HKDF (HMAC-SHA256): I understand that the "proper" solution is probably to use an HKDF (HMAC-based Key Derivation Function). Is this primarily because it's a standard, or are there specific security issues with using SHA-256 directly for key derivation? As far as I know, SHA-256 doesn't leak additional information from related hashes. Are there any known risks in using SHA-256 in this way?
Differences Between HMAC-SHA256 and SHA-256: In my specific context, what properties distinguish HMAC-SHA256 from plain SHA-256 that are relevant to key derivation? I understand that HMAC includes an XOR of the key material, and the algorithm is:
HMAC(K, m) = H( (K' ⊕ opad) || H( (K' ⊕ ipad) || m ) )Mixing Key and Non-Critical Data: I've read that it's bad practice to mix "key data that is to be protected and other non-critical data (which is often known by the attacker)." (How is HKDF-Expand better than a simple hash?) What are the details of this "badness"? How would it impact the security of the derived keys?
Tldr; I would love to know the specific advantages of using HMAC-SHA256/HKDF over SHA-256 for key derivation as I have outlined, and any risks associated with the way I'm currently doing it.
Thank you!
Note: I apologize if any of my terminology or understanding is incorrect; I'm still learning about cryptography concepts.