2
$\begingroup$

for bcrypt it's probably common knowledge that it isnt binary safe because it uses null termination, which means that when bcrypt is used you need to make sure that no one does these (e.g. by hashing the passwords in a different binary safe function like SHA256 before and encoding the output)

by now we have essentially 2 other ways which can be used for password hashing, scrypt and argon2, and after a quick round of using google I couldnt really find any info on whether these 2 are binary-safe (meaning I can just use them directly on passwords which certainly makes them easier to use) or not.

does anyone know?

$\endgroup$
2
  • $\begingroup$ Can you please give a (precise) definition of the term "binary-safe"? Also if I combine the wikipedia article with your question it comes down to "how does the PHP API handle null-characters with Argon2 and scrypt?" which is strictly an API-design / -documentation question. Cryptographically these functions don't care what you input them with. $\endgroup$
    – SEJPM
    Sep 14, 2017 at 10:21
  • $\begingroup$ well basically I mean binary safe as in that this thing doesnt do anything weird (like with bcrypt cut off the input too early because of a null byte) but can handle binary data of all kinds, because one good thing is normally that because of hashing you dont need to put any limits on the password (some sites for example forbid non-ascii chars, special characters limited programming and other stuff) or other special care because after the hash has been through with the password nothing is left. $\endgroup$
    – My1
    Sep 14, 2017 at 12:05

1 Answer 1

2
$\begingroup$

BCrypt, Argon2 and scrypt are all "binary-safe".

That is, there is nothing inherent in the algorithms (and their reference C implementations) that would require the "password" input to have any structure.

The only exception maybe being that bcrypt has a 72 bytes input limitation, but that can be worked-around using pre-hashing.

However, particular APIs may wrap things differently and "help" the programmer by cutting off at \0 bytes or similar things. If this is the sort of info you need, you need to consult the documentation / the source code of the relevant wrapper.

$\endgroup$
2
  • $\begingroup$ okay, thanks for the info. guess I need to get some more reads about PHP implementations of these. well the pre-hashing for the bcrypt length limitation is something I know and I am doing prehashing already, but not needing this makes easier and possibly even safer, because each link that doesnt exist in a chain, cannot become the weakest link of it. $\endgroup$
    – My1
    Sep 15, 2017 at 10:17
  • $\begingroup$ Sorry if this is a stupid question, but -- what is the "reference C implementation" of bcrypt? I thought that might mean OpenBSD's implementation, but I checked its source code (github.com/openbsd/src/blob/master/lib/libc/crypt/bcrypt.c), and I see that it does not support passwords containing null bytes. (It doesn't say that explicitly, but it's obvious from the code.) If you have a different C implementation in mind, could you provide a link to it? $\endgroup$
    – ruakh
    Feb 17 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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