# scrypt and argon2: binary safe?

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?

• 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. – SEJPM Sep 14 '17 at 10:21
• 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. – My1 Sep 14 '17 at 12:05

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.

• 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. – My1 Sep 15 '17 at 10:17