Search code examples
securitycryptographypbkdf2

Highest number of bytes taken from Rfc2898DeriveBytes class


I know very little about PBKDF2 and its processing steps. To know more I started reading about it and looking at codes as well. I have seen codes like this in Google. For AES-128bit the value of N is 16. My question, for random use how far can I increase the value of N? can it be 50? or 100? is there any upper limit?

        string password = "123456789";
        string salt = "987654321";
        Rfc2898DeriveBytes keyGenerator = new Rfc2898DeriveBytes(password, Encoding .UTF8 .GetBytes (salt ),10000);
        byte[] key1 = keyGenerator.GetBytes(N);

Solution

  • According to RFC 2898 maximum length of derived key is (2^32 - 1) * hLen where hLen is the length in octets of pseudorandom function output.

    Rfc2898DeriveBytes class in .NET framework you are referring to in your code sample uses HMAC-SHA1 pseudorandom function which outputs 20 bytes so the maximum theoretical value of N in your case is 85899345900.