As indicated at
Key generation for AES-GCM-256 file encryption
I'm currently working on a file encryption software. In the above thread it was suggested that, for performance reasons, I use a combination of scrypt and HKDF.
But how should I go about using HKDF to derive a new key for each file? As suggested in the above thread, I intend to produce a single master key via scrypt and from that I want to derive file encryption keys via HKDF.
So far I have come up with two possible ways of doing this:
(1) Run HKDF (extract-then-expand) with the scrypt result as input key material (ikm) and a NEW random salt for each file to be encrypted
(2) Run HKDF (extract-then-expand) with the scrypt result as ikm, a FIXED random salt, and a random 'info' value for each file to be encrypted
Which - if any of these - is the better or correct way of doing what I want? As I understand it, NIST Special Publication 800-56C, explicitly dsicourages re-using the same ikm and just varying the salt. But I don't exactly understand why and their use case (shared secret Z as ikm) is different from mine.
salt1
andsalt2
be the same, although there's also no reason to do it (or, indeed, to use HKDF-extract after scrypt at all). – Ilmari Karonen Nov 19 '18 at 07:49As I pointed out, in NIST 800-56C it says on page 12 that the IKM is only to be used once - and zeroized immediately after use. Why? Also, https://crypto.stackexchange.com/a/59070/56772 seems to suggest that the IKM should not be re-used.
I'm a bit confused.
– FineJoe Nov 19 '18 at 09:04"In the extraction step, the following notations are used. [...]
Z – A shared secret established during an execution of an approved public key-based key establishment scheme. It is represented as a byte string and used as the “message” in a MAC execution in the randomness extraction step. Each call to the randomness extraction step requires a freshly-computed shared secret Z, and this shared secret shall be zeroized immediately following its use in the extraction process."
– FineJoe Nov 19 '18 at 10:48Info
parameter. That only applies to the extract phase after all. And yes, if you use any input key material correctly you should destroy (zeroize) the key as soon as you don't need it anymore. What it does not or should not indicate is that you cannot use the same input material as input to a KDF. In that case you could not separately derive two keys, e.g. one for encryption and one for authentication. – Maarten Bodewes Nov 19 '18 at 11:45IKM = scrypt(password, salt1)
PRK = HKDF-extract(IKM, salt2)
K = HKDF-expand(Z, Input, 256)
(with Input = Null)
– FineJoe Nov 19 '18 at 11:55