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

Haven't found any clear cut answer in Google so its up to you guys:

DK = PBKDF2(PRF, Password, Salt, c, dkLen)

Here, what is the upper limit of password length? I tried up to 16 characters and it works. How far can I go? I read somewhere that salt has no upper limit! Is it really true?

share|improve this question
up vote 2 down vote accepted

There's no practical limit to password or salt length you can use with PBKDF2.

Theoretical limit, however, is determined by the hash function used by PBKDF2: under the hood, it uses $HMAC(Password, Salt || Counter)$, which in turn will translates to a series of hash function calls:

  • $K_0 = H(Password)$ (assuming password is longer than hash block)
  • $HMAC = H((K_0 \oplus opad) || H((K_0 \oplus ipad) || Salt))$

If we assume a very long password and/or salt, then two hash function calls can potentially "overflow": $H(Password)$ and $H((K_0 \oplus ipad) || Salt)$. To avoid such "overflow" $Password$ must be smaller than maximum input size supported by the hash function, and $Salt$ must be shorter than maximum input length minus block size of the function.

TO give some perspective and show why this doesn't really matters in real world, maximum input length for e.g. SHA-1 is $2^{64}-1$ bits or $2^{61}-1$ bytes. Block size of SHA-1 is 64 bytes, so maximum $Salt$ size will be $2^{61}-65$ bytes.

share|improve this answer
Could you clear this out "e.g. SHA-1 is 2<sup>64</sup>−1 bits <b>or</b> 2<sup>61</sup>−1 bytes" here one is in bit and another in byte! I just found a similar question like mine [here] ( It also says that maximum input length is 2<sup>64</sup>-1 ---And I have no more confusion about it. The only thing that is still not clear to me is "2<sup>61</sup>-1 bytes". – Giliweed Aug 22 '14 at 5:51
Sorry for the mess. I have no idea why is my comment is like this. Its true that this is my first time to add mathematical sigh and link in a comment. – Giliweed Aug 22 '14 at 5:55
One byte is 8=2^3 bits. Thus, 2^64 bits is 2^(64-3)=2^61 bytes. – Andrey Aug 22 '14 at 5:57

Andrey's answer has the correct hash function dependent upper bounds on the lengths. However, there is also a practical length limit above which you gain no security.

For the salt, it's just "long enough not to collide", which depends on the application. For deterministic salts it's just $\log_2(n)$ bits where $n$ is the number of salts used. For random ones it's $2\log(n)$ bits. In practice, 256 bits is a good choice for a random salt.

For the password, any entropy beyond the hash size is useless. The password itself may be however long is needed, but having more than 256 bits of entropy (for SHA-256) will not make it stronger. Additionally, a password longer than the blocksize is equivalent to the password $H(p)$, which some see as a theoretical weakness.

share|improve this answer
otus, I'm not clear in this -"For deterministic salts it's just $log_{2}(n)$ bits where n is the number of salts used. For random ones it's 2log(n) bits. " --- why do I need more then one salt? when do I need more then one salt? when I use only one salt the value of $log_{2}(1)$ is 0 and for a random salt the value of 2log(1) is also 0! So, can you explain a little on this? – Giliweed Aug 22 '14 at 9:44
@Giliweed, the purpose of the salt is to make each derived key different even if passwords match, so they have to be attacked independently. You need multiple, unique salts if you have multiple users/master passwords for which your derive keys. However, in principle an attacker could attack your password together with some completely unrelated password from some other application that happened to use the same salt, so a 256- bit random number is a safe choice. – otus Aug 22 '14 at 10:22

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.