1
$\begingroup$

I got confused about key derivation functions. For my project, I need to derive a 128 bits AES encryption key in CTR mode. To do so, I'm using a PBKDF2 to derive this encryption key using an initial information like a password.

PBKDF2 allows me to set its parameters before deriving a key, such as hashing function and iteration number. So, my question is if i set the PBKDF2's hashing function as SHA-256, and specificy the derived key's length as 128 bits, would that be okey? As SHA-256 will hash the input multiple times and produce a hash of 256 bits, how can I get a 128 bits encryption key while having 256 bits output of the SHA-256?

$\endgroup$
  • $\begingroup$ Welcome to Cryptography. The easiest way is trimming the 256-bit output of SHA-256. $\endgroup$ – kelalaka Jul 9 at 14:05
  • $\begingroup$ Hi, so does the PBKDF2 algorithm do it for me when I specify the parameters as such ? $\endgroup$ – Ahmet Eroğlu Jul 9 at 14:09
  • $\begingroup$ For that part is just reading the function prototype dLen that is desired length, see the answer from infortmation security $\endgroup$ – kelalaka Jul 9 at 14:16
  • $\begingroup$ so as far as I understand, it is suggested that if i use hashing function as SHA-256, the desired key should be also intended as 256 bits right? $\endgroup$ – Ahmet Eroğlu Jul 9 at 14:22
2
$\begingroup$

Truncate the output to 128 bits.

(Or, consider using AES-256 instead.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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