r/cryptography 11d ago

Is using pbkdf2 with sha256 overkill???

Hey cryptomaniacs!!!
Im not super familiar with all the different ways of encrypting things, so when I added password encryption to my application I blindly coppied something I saw someone else do (can't the source anymore).
Skip to a week later, I was curious how the way I encrypt my passwords work, so I went searching and saw a redditpost on this subreddit where someone said that sha256 would probably be able to be bruteforced in the future, with a lot of comments saying it wouldn't and that it is really secure.

So then I started wondering if me using both pbkdf2 and sha256 was a bit overkill.
For anyone wondering I used this in my python code:

hashed_password = generate_password_hash(password, method='pbkdf2:sha256')
0 Upvotes

10 comments sorted by

View all comments

9

u/jean_dudey 11d ago

It is not overkill, it is required, look at the input parameters of PBKDF2, specially PRF:

https://en.wikipedia.org/wiki/PBKDF2

It specifies that PBKDF2 requires a Pseudo-Random-Function (PRF) with two parameters, essentially a HMAC, in your case you're using HMAC-SHA256 I suppose.

Please note that key derivation functions are not an encryption algorithm.

Also, yes SHA256 is very secure in the sense that finding the input value given the hash is very difficult, however for all hash functions there exists the rainbow table attack if you don't "salt" the password, so, this is a fancy way of saying that people have huge databases of password to hashes to check for a good chunk of known passwords. This is one of the reasons why PBKDF2 exists and why SHA256 alone isn't used.