News for hackers. Stuff that matters.
Re:Blake3 is 10 times faster than SHA-2 by nneonneo on Saturday January 11, 2020 @05:16PM (#22022742)
A lot of people in the comments are wondering about using SHA-2 vs Blake3 for password hashing. The answer is, neither of these is suitable by itself for password hashing. Sadly there’s still a lot of advice on the internet (and, sadly, real systems) which do things like store md5(password) in a database and call it a day.

Blake2/3, SHA-2/3, and other cryptographic hash functions are meant to be fast, while also effectively guaranteeing no collisions or any way of reversing the hash (pre-image attack). This makes them ideal for stuff like checking file integrity, message authentication, inputs for cryptographic signatures and the like. But since they’re meant to be fast, they’re very poor choices for hashing low-entropy data such as passwords - attackers can test vast numbers of passwords (even if you salt!!) on GPU hardware.

For low-entropy data, you want a hash function that is slow and hard to parallelize. Use a specialized password hashing algorithm like bcrypt, scrypt or Argon2, and tune it so it’s slow enough without impacting overall usability (e.g. takes 50ms on your server). These algorithms are resistant to parallelization, so attackers will only be able to test a small number of passwords per second. This slows attackers down and can prevent them from recovering passwords that might be recoverable if stored using SHA-2, etc.

Re:Blake3 is 10 times faster than SHA-2 by nolok on Saturday January 11, 2020 @05:27PM (#22022815)
> tune it so it’s slow enough without impacting overall usability (e.g. takes 50ms on your server)

I want to insist that this is a very important part. If you are 99.9% of applications or websites out there, the only time you need to run that hash is at registration, login and password change. All of these case will be fine if it's a bit slow. Don't lowball it.

Also informationally I would like to add that as part of their "meant to be slow" job, algorithm like bcrypt are built in a way that makes it extremely hard if not impossible to run on cheap massively parallelized hardware (eg: CUDA on GPU).

Re:Blake3 is 10 times faster than SHA-2 by kragen on Saturday January 11, 2020 @05:36PM (#22022865)
Also you can do the stretching in the browser client (“server relief”) without losing security. Historically this would have meant a big performance penalty (and thus an advantage for attackers, who don't need to use your code) but JS and wasm are fast enough now that the price is fairly low.
Re:Blake3 is 10 times faster than SHA-2 by nneonneo on Saturday January 11, 2020 @07:12PM (#22023409)
If you’re going to do this, make sure you still hash the client’s hash output on the server (you can use SHA-2 in this case since the client’s hash output will effectively be high-entropy if salted). Otherwise you will be vulnerable to a “pass the hash” attack where an attacker in possession of your stored password hashes simply passes the hash to login.
Re:Blake3 is 10 times faster than SHA-2 by jaytaylor on Saturday January 11, 2020 @07:48PM (#22023567)
I didn't think hashing the hash would be helpful here, and couldn't think of a way to mitigate against this attack.

After reading more it seems the only mitigation is Layers of Security.

https://en.m.wikipedia.org/wiki/Pass_the_hash#Mitigations

Re:Blake3 is 10 times faster than SHA-2 by kragen on Saturday January 11, 2020 @08:17PM (#22023735)
No, hashing the hash solves the problem.
Re:Blake3 is 10 times faster than SHA-2 by lisper on Saturday January 11, 2020 @09:50PM (#22024136)
It's important to understand why this is so: it's because the hash is big, so while it might be possible to mount a brute force preimage attack against a password, it is not practical to do so against a hash. So hashing a hash (once) is secure even though hashing a password (once) isn't.
Re:Blake3 is 10 times faster than SHA-2 by throwaway838475 on Saturday January 11, 2020 @11:38PM (#22024510)
Almost. That construction is still vulnerable to chosen input attacks without inner and outer padding, which is basically rediscovering HMAC, which also isn’t suitable for storing passwords. Don’t roll your own crypto if you don’t know what you’re doing. Use a PBKDF like argon2, scrypt, bcrypt or PBKDF2 as they are intended because they are far, far stronger than hashing a couple of times.
Re:Blake3 is 10 times faster than SHA-2 by nneonneo on Sunday January 12, 2020 @12:05AM (#22024596)
I believe what we’re discussing is having a client compute a PBKDF of the password, and then having the server hash the PBKDF output one more time to obtain the thing that’s actually inserted into the database. The idea is that if the database leaks, the attacker gets H(PBKDF(password)) which is hard to bruteforce due to the PBKDF, and can’t be used directly as a login token because of the extra H(). I don’t see where this would be subject to a chosen input attack.
Re:Blake3 is 10 times faster than SHA-2 by jaytaylor on Saturday January 11, 2020 @08:33PM (#22023806)
I see, clever. Thanks!
Re:Blake3 is 10 times faster than SHA-2 by zahllos on Sunday January 12, 2020 @03:30AM (#22025191)
It's not server relief, but there's also a technique called delegated hashing, i.e. allowing the client to do part of the work of computing the actual hash. This was one of the main selling points of the Makwa candidate for the password hashing competition.

It did not win, and I believe it is only CPU hard and not also memory hard unlike argon2. Nevertheless techniques to do this have been explored academically and might make it into future designs.

In case it isn't obvious, please continue to use argon2 (I'm just mentioning this as a point of interest).

Re:Blake3 is 10 times faster than SHA-2 by zxcmx on Sunday January 12, 2020 @05:21AM (#22025538)
Lots of advice in these threads and no one has mentioned anchoring yet so I'll staple it here; if you're a big company who can afford an HSM and the overhead of the key ceremony stuff to manage it (managed stuff like AWS cloud HSM simplifies this a fair bit) a great option is using an HSM as an anchored one-way function.

For whatever reason this seems to be seldom discussed but the general idea is as follows in hand-wavey fashion:

Set up HSM with a non-exportable symmetric key, set key usages to "encrypt only" and as one step of the hashing scheme you use, encrypt your hash through the HSM. Protected HMAC key would work too.

The result is that an attacker who compromises your password db cannot perform offline attacks on your passwords anymore - they now need to do key extraction on your HSM or remain in your infrastructure and keep running guesses through the HSM where it is relatively easy to monitor what is going on and they can't do a bajillion operations per second anymore.

Wish everyone running large user dbs like yahoo or linkedin etc applied anchoring to their password hashing - it's a relatively simple measure for an org "at scale" to make hash dumps alone useless.

Re:Blake3 is 10 times faster than SHA-2 by zahllos on Wednesday January 15, 2020 @06:20PM (#22059941)
Fair warning, mine isn't advice, just a comment about a technique that requires experienced cryptographers to use. I wouldn't attempt to use it myself :)
Re:Blake3 is 10 times faster than SHA-2 by tgb on Saturday January 11, 2020 @05:56PM (#22022973)
Can you elaborate? This doesn't sound right to me but I don't know much about this.
Re:Blake3 is 10 times faster than SHA-2 by kragen on Saturday January 11, 2020 @06:19PM (#22023129)
It is indeed surprising; it took me a long time to be sure it was safe. Google “server relief”.
Re:Blake3 is 10 times faster than SHA-2 by jaytaylor on Saturday January 11, 2020 @08:07PM (#22023667)
Re:Blake3 is 10 times faster than SHA-2 by pitaj on Saturday January 11, 2020 @09:01PM (#22023931)
That is pretty interesting, but doesn't actually offer up a solution that provides server relief, unless I missed something. In every case they still require that HSrv be a slow hash function.
Re:Blake3 is 10 times faster than SHA-2 by jaytaylor on Saturday January 11, 2020 @09:07PM (#22023954)
My take away was that the server relief comes from reducing the ability of clients to trigger disproportionate amounts of server resource consumption.
Re:Blake3 is 10 times faster than SHA-2 by nneonneo on Saturday January 11, 2020 @10:59PM (#22024371)
I don’t see how that follows. If HSrv is expensive or slow, a malicious client could just submit nonsense hashes that only look like they might have come from HCli - the server shouldn’t be able to tell the difference.

Requiring client-side JavaScript for your login system seems fraught. I would much rather have an approach that does server side hashing exclusively, but gates it behind some kind of DDoS protection or rate-limiting.

Re:Blake3 is 10 times faster than SHA-2 by pnako on Saturday January 11, 2020 @11:39PM (#22024514)
You do the slow (bcrypt, argon2 or whatever) hash in the browser, and then the server can do the hyper-fast hash (SHA256).

You can still flood the server, but you're flooding it with things that take microseconds to compute, instead of 50ms.

Re:Blake3 is 10 times faster than SHA-2 by tgb on Sunday January 12, 2020 @02:45PM (#22028704)
That's not what the article states, though it's not very explicit about why you shouldn't do what you suggest.
Re:Blake3 is 10 times faster than SHA-2 by CalmStorm on Sunday January 12, 2020 @01:29AM (#22024834)
But you also need to be careful. The slow password hashing can be exploited for Denial of Service attack. You may want to rate-limit the APIs that use the hash algorithm.
Re:Blake3 is 10 times faster than SHA-2 by masklinn on Sunday January 12, 2020 @06:38AM (#22025807)
The official Blake3 site / repo actually covers this itself:

> NOTE: BLAKE3 is not a password hashing algorithm, because it's designed to be fast, whereas password hashing should not be fast. If you hash passwords to store the hashes or if you derive keys from passwords, we recommend Argon2.

Re:Blake3 is 10 times faster than SHA-2 by mekster on Sunday January 12, 2020 @06:52PM (#22030632)
Argon2 is a recent entry which won the password hashing competition in 2015 and is slowly getting included in recent versions of languages like PHP 7.2 as an alternative to bcrypt.

https://password-hashing.net/

As stated in the parent, integrity check hashing (should be fast) and password hashing (should be slow) are very different things and should not be mixed to use wrong implementations.

As bcrypt and argon2 both have specific prefixes, you can still keep bcrypt hashes and verifier can work on both (assuming it supports argon2) while using argon2 for newer entries stored in a database. (Preferably update the old bcrypt into argon2 on next login or something.)

Re:Blake3 is 10 times faster than SHA-2 by stevefan1999 on Saturday January 11, 2020 @09:10PM (#22023965)
And we should all use bcrpyt to hash password. We all should have had it long long time ago, and people are still rolling out their own password hashing with salting mechanism. Biggest facepalm in the industry in my eyes.
Re:Blake3 is 10 times faster than SHA-2 by blattimwind on Saturday January 11, 2020 @09:12PM (#22023973)
not processing plaintext passwords on your server >> argon > scrypt > bcrypt > pbkdf2 >>> any hash
Re:Blake3 is 10 times faster than SHA-2 by CaptainMarvel on Sunday January 12, 2020 @05:30AM (#22025571)
There is an algorithm to authenticate without sharing the plaintext password from client to server, nor server to client - SRP. I know Apple uses it.
Re:Blake3 is 10 times faster than SHA-2 by ris on Sunday January 12, 2020 @06:07AM (#22025689)
Unless any of your users ever try and use a >72 character password.
Re:Blake3 is 10 times faster than SHA-2 by masklinn on Sunday January 12, 2020 @06:46AM (#22025834)
TBF that's super easy to work around: just prehash the key.

In fact, an other risk of bcrypt is that any nul byte will truncate the key, so you probably want to hash the password with something else (SHA384 or SHA512/256 for instance) then base64/base85-encode it before passing it to bcrypt.

Re:Blake3 is 10 times faster than SHA-2 by SkyMarshal on Saturday January 11, 2020 @11:50PM (#22024561)
>For low-entropy data, you want a hash function that is slow and hard to parallelize. Use a specialized password hashing algorithm like bcrypt, scrypt or Argon2, and tune it so it’s slow enough without impacting overall usability (e.g. takes 50ms on your server).

For most of the 2010s I've been under the impression that password hashing was a solved problem and that this is the solution.

And yet I still see comments online saying to hash passwords with a salt + 10,000 rounds of PBKDF2. Why bother when you can just b/scrypt it? Is there still some benefit of the former over the latter?

Re:Blake3 is 10 times faster than SHA-2 by aaronmdjones on Saturday January 11, 2020 @11:57PM (#22024581)
There are two principal benefits of sticking with PBKDF2:

1) It's a NIST standard. This may be necessary in some environments, typically just to check a box. (Yeah, I know...)

2) It's necessary for SCRAM (RFCs 5802, 7677), which is a much better login method based on passwords. This is applicable if your system uses GSS-API or SASL (e.g. dovecot IMAP logins).

If neither applies, my advice is to migrate to Argon2.

Re:Blake3 is 10 times faster than SHA-2 by masklinn on Sunday January 12, 2020 @06:39AM (#22025812)
Also PBKDF2 is really easy to implement if you have a cryptographic hash (even more so with a ready-made HMAC), which is useful if you can't or don't want to pull in dependencies.
Re:Blake3 is 10 times faster than SHA-2 by littlestymaar on Saturday January 11, 2020 @05:44PM (#22022905)
This is a good time to ask for a question I have always wondered about these slow hash functions: are they slow because they are computationally intensive or is it that they have other tricks that makes them slow without costing too much load on your server (like needing RAM access, syscalls or anything that add latency but not much CPU load). If it's the former, isn't it a good DOS target, making your server busy hashing random crap and unable to process other requests?
Re:Blake3 is 10 times faster than SHA-2 by eyegor on Saturday January 11, 2020 @09:05PM (#22023944)
> are they slow because they are computationally intensive...

In general, no. Most "slow" hashing schemes are designed to be memory-hard and highly serial (more threads = more contention, not throughput). Some of the earlier approaches just try to maximize computational requirements, but modern research acknowledges the march of computing power makes that an inherently poor choice for long term sensitive data. Argon2 is just one of the more advanced versions of a memory-hard scheme, building on prior research. I could try to give a poor explanation, but instead I'll link you the spec which is very readable: https://github.com/P-H-C/phc-winner-argon2/blob/master/argon...

Re:Blake3 is 10 times faster than SHA-2 by littlestymaar on Sunday January 12, 2020 @02:46AM (#22025078)
Thanks!
Re:Blake3 is 10 times faster than SHA-2 by dpc_pw on Saturday January 11, 2020 @05:53PM (#22022955)
They are computationally slow, no tricks. The purpose is to prevent attackers from calculating the plain passwords if they actually got access to the content of your DB. They are not that slow (let's say less than a second to calculate) - fast enough for your user to not notice , slow enough so that attacker can't do gazillion tries per second with their GPU or something.

As per DOS: rate limit per ip and account, and it's not an issue.

Re:Blake3 is 10 times faster than SHA-2 by phiresky on Saturday January 11, 2020 @06:38PM (#22023243)
> They are computationally slow, no tricks

They have to and do use tricks, they aren't just slow. You could trivially make sha256 slow by just applying it a million times (that's not even parallelizable as well), but scrypt et al improve on that by making the algorithm also require a lot of RAM, use complex instructions (hard to recreate on a GPU or FPGA) and so on.

It's really hard to do very well, look at cryptocurrencies trying to be ASIC resistant: They want every normal person to be able to mine it, and don't want companies to be able to build a machine that can eclipse the mining power of everyone which means centralization.

Re:Blake3 is 10 times faster than SHA-2 by wongarsu on Saturday January 11, 2020 @05:57PM (#22022978)
They are computationally expensive. scrypt and Argon2 also depend on RAM access for their slowness, since that's much harder to parallelize (compute is easier to scale than RAM bandwidth). When your CPU can do hyperthreading that property might help recover some of that execution time.

It is a good DOS target, you should definitely rate limit logins to mitigate that. Other strategies are requiring captchas for login or letting the client execute the hash function and just doing a simple (fixed time) comparison on the server side.

Re:Blake3 is 10 times faster than SHA-2 by throwaway838475 on Saturday January 11, 2020 @11:25PM (#22024472)
The correct term is PBKDF.

And more succinctly:

crypto hash fn != authenticated hash fn (like HMAC constructions) != PBKDF

Re:Blake3 is 10 times faster than SHA-2 by masklinn on Sunday January 12, 2020 @06:47AM (#22025842)
The correct term is KDF, PBKDF is a specific KDF algorithm.
Re:Blake3 is 10 times faster than SHA-2 by bigcohoneypot on Saturday January 11, 2020 @07:12PM (#22023412)
I get md5 is pretty weak now, but what's wrong with sha-256 and a salt?
Re:Blake3 is 10 times faster than SHA-2 by nneonneo on Saturday January 11, 2020 @07:45PM (#22023559)
The Bitcoin network can perform some 10^20 SHA-256 hashes per second. That’s one 11-character upper/lowercase alphanumeric password PER SECOND.

A practical password cracking rig can probably do upwards of 10^11 hashes per second. The same rig can only do 10^5 bcrypt hashes per second.

Re:Blake3 is 10 times faster than SHA-2 by bawolff on Saturday January 11, 2020 @07:45PM (#22023557)
The md5 weakness (that everyone talks about) is about collision resistance, which isn't relavent to password hashing.

Generally you want slow, high cpu & memory hash functions for password hashing. This is the opposite of what md5/sha/blake aim for, as they want to be fast as possible. A fast hash allows the attacker to make many guesses very quickly (i think you can get something like 2 billion sha256 hashes a second with high end gpus). A slow hash makes it harder for the attacker to take lots of guesses (adding high mem usage helps protect against using alternate architectures like fpgas to speed things up).

Anyways, for passwords use something like argon2.

Re:Blake3 is 10 times faster than SHA-2 by basilgohar on Saturday January 11, 2020 @07:23PM (#22023459)
Salting only protects against rainbow tables, but does next to nothing against brute force attacks because the salt is usually stored adjacent or even as part of the stored password hash.