11
$\begingroup$

When using Encrypt-then-MAC with AES and HMAC by password, and given 128 bits of payload with the ciphertext to store a random salt, which would be more secure:

  • Using PBKDF2 with then entire 128 bit random salt and generating 512 bits of derived data to split into a 256 bit AES Key and a 256 bit HMAC key.

or

  • Using PBKDF2 separately for each key using two 64 bits salts to generate a 256 bit AES Key and a 256 bit HMAC key.

or

  • Better option?
$\endgroup$
0

1 Answer 1

14
$\begingroup$

I'd use HKDF's "expand" step to generate multiple keys from one masterkey.

Use PBKDF2 to derive that masterkey from the password and salt. i.e. replace the "extract" step of HKDF with PBKDF2.

//Extract
MasterKey = PBKDF2(salt, password, iterations)

//Expand
AES-Key = HMAC(MasterKey, "AES-Key" | 0x01)
MAC-Key = HMAC(MasterKey, "MAC-Key" | 0x01)

(where | denotes concatenation)

Having PBKDF2 output more than its native size is a bad idea IMO. It increases the cost for the defender considerably (multiple key derivations with thousands of iterations) but doesn't increase the cost for the attacker(he can verify correctness of his password guess after one key was derived, he doesn't need both).


If you use a 512 bit hash, such as SHA-512 in PBKDF2 (PBKDF2-HMAC-SHA-512) you can also get away with simply splitting those 512 bits into two parts, using one for encryption and the other for MAC. But IMO the HKDF approach is cleaner.

$\endgroup$
7
  • $\begingroup$ What does the concatenation of 0x01 provide us? $\endgroup$
    – d1str0
    Mar 7, 2016 at 7:58
  • 1
    $\begingroup$ @d1str0 If you never need more than one block of output, it's pointless. But HKDF supports larger outputs, where the last byte of the message acts as counter (it also includes the previous output in the message, similar to OFB mode). $\endgroup$ Mar 7, 2016 at 8:01
  • $\begingroup$ So would this be similar to HMAC(MasterKey, 0x01) and HMAC(MasterKey, 0x02)? $\endgroup$
    – d1str0
    Mar 7, 2016 at 8:08
  • 1
    $\begingroup$ h1 = HMAC(MasterKey, info | 0x01), h2 = HMAC(MasterKey, h1 | info | 0x02), ... Just look at the HKDF spec I linked above for the details. $\endgroup$ Mar 7, 2016 at 8:13
  • 1
    $\begingroup$ @d1str0 It's not strictly needed for security, but it ensures that each iteration of the hash has a unique input. $\endgroup$ Mar 7, 2016 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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