I know, that PBKDF2 uses HMAC with SHA2 function as PRF. But.. can I use many iterations of HMAC with SHA2 directly? Is this effective and securely? P.S I need the best function, but I can’t use bcrypt, argon, pbkdf2.
1 Answer
If you can't use an existing secure key derivation function but do have access to a SHA2 primitive, you can implement pbkdf2 yourself. It's not as good as using an existing trusted implementation and definetly inferior to modern memory hard functions but still better than a general lets iterate one way or another.
PBKDF2 is fairly simple to implemet but still has some key details, like using a salt and mixing in the input repeatedly.
-
1$\begingroup$ The thing is he does appear to have access to PBKDF2, so there's no need to implement anything. He's using the C# System.Security.Cryptography namespace, which offers PBKDF2. $\endgroup$ Feb 27 at 18:08
-
1$\begingroup$ I missed that, I only read the question which stated can't use PBKDF2, I took it at face value. I explictly stated using a well understood trusted implementation is superior. $\endgroup$ Feb 28 at 12:18
PasswordDeriveBytes
instead (also a horrid name), sanity, consistency, principle of least surprise and security be damned. It also relies on HMAC :P Anyway for both PBKDF1 (just joking, do not use) and PBKDF2, do not ask for more bits/bytes than the output size of the hash function used! $\endgroup$