Here https://security.stackexchange.com/a/52564 you can read that newer OpenSSH versions use bcrypt for protecting the keyfile. Security of bcrypt depends on the costfactor see https://security.stackexchange.com/questions/139721/estimate-the-time-to-crack-passwords-using-bcrypt/201965#201965
According to https://crypto.stackexchange.com/questions/58536/how-does-openssh-use-bcrypt-to-set-ivs/58543#58543 the default bcrypt round number would be 16. This would be a good security. But how to get the round count / cost factor?
What I've done so far: Key looks like (to make it shorter here only a weak 1024 bit key)
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABBLF8sO2Q
hcLXI43z96e1hiAAAAEAAAAAEAAACXAAAAB3NzaC1yc2EAAAADAQABAAAAgQC0gBWeZpej
9ILT/59bEb0/lSvXx0WfZqP2lXRDbuY+gluuWyT+REQcVTR2BxSx9F/P20mLTnupzY+XE3
xEu+SIJlwKIAH3fed62+QBzDrPsl9kyfoIGIvi/28ZftqVN/kg0GSOaAqu4Px+vNVX1VKn
PNV5VVCZWL4ZPlGQZ48UJwAAAhCwDkueKT9oq8E0qtD92/4DSAD2eTI7bd6jBGUxugEw85
6xWbRYnFQZdwO2ZCNV0aTHViD1FRKlC9cBHDoSORKcM/9dY9Msy6lZj7Tp5s8r7x2pOrJi
TVRbv5/cI732I+l/vYvssJEhZpeSw4JKh9tyPpifVmzBxqtqwkBrTuLCMqkwLmrcxReFUq
aA/RIZy3L616CJsAvx2ezEc49D6SbJ9i9OlKuv73a1baS4RpMvFzWGLE2NBvvtQpEnJFoL
Kyjz+two4doT6SZ7UtiVGyCtO5WQEoeAgjhkbZzOPtM2AvoV+hNLRIX2/52jOB5A1bNQ0v
qW64aj2YNe8vWfj5xtA/8BlyEG7gwhu+0HgbgMDxw7o/0qVkHM/Hv3YgBTRygsH+8h4wsR
kxA292NOKKaD18tv1j3atR80q0XQVcQH20uX8tSqXtKfDtkUc/EPbFCNp3xQJG/F81USKh
YAmjxEeDkZZ/LkEOEJKvFRCL3gFlH4rqF5/pRk6HmB99xceD4irbazm+BWfPAf5Q0zdB5L
/yei3sqA4G48yRXIkaELtYNEeTYHMp3PGz1b3CP3l+ZGZp6XNaM+sMfdICbI3Zae5bnxKg
VXEE2UMdi7DEXbqEzSlfcIf5QzXHMQJm0ZL+iLoaEmakamAxCKk6jJ+QzHzGADZEIRXrj3
5Nhhd0jsToEMsXmmawt2qxy0cIHET1M=
-----END OPENSSH PRIVATE KEY-----
PW is test
Then lets decode the base64. Therefore first and last line beginning with '-----' have to be removed
cat key | tail -n +2 | head -n -1 | base64 -d > text.txt
Now open text.txt e.g. in Notepad++ This shows
but now I have no idea how to read the roundcount from there. Can you assist?
Take your base64, decode it into hex:
The spec defines the format of this data. We can then pick data apart:
KDF Options string
The part you want is the string kdfOptions:
Which the spec explains:
In other words:
I doubt they mean "rounds". I assume they meant CostFactor.
But there it is.
Bcrypt isn't a KDF
BCrypt is not a key-derivation function; it is a password storage function. You cannot use bcrypt to generate a "key". For example if you wanted "derive" an AES-256 bit key: bcrypt cannot do it.
That's because bcrypt is not a key derivation function.
BCrypt is a password hashing function.
Mis-using bcrypt in this way is an abomination - and a crime against humanity.
More about bcrypt being a password hashing function and not a key derivation function can be found here https://crypto.stackexchange.com/a/70783
Some additional information. To recap the password protection of new ssh-keys is quite secure.
When creating the key or changing the password you can use
-a <number of rounds>
.This was done on an old i3-3220 and needs about half the time on Ryzen 7 5700U. So rounds is indeed rounds and not a cost factor.
To find out if your key is new format use
cat key | tail -n +2 | head -n -1 | base64 -d | head -n 2
If you seeaes256-ctrbcrypt
then your key is in the new format.To get an estimate of how secure it is against brute force password guessing I used John the ripper. Hashcat has currently (March 2022) no support for this format, see https://hashcat.net/forum/thread-10662.html Prebuilt binaries for John the ripper also might not include the neccessary module for cracking this new kind of ssh key format.
After you have compiled John the ripper go to
run
directory and create hash from your SSH keyfile viapython3 ssh2john.py <keyfile> > hash.txt
Now start John the ripper via
./john hash.txt
. Program will use a shipped password list. On AMD Ryzen 7 5700U it can try about 132 PW/s (c/s) which is a really low number. This is CPU only. When changing rounds to 32 via-a 32
number is halfed (65 PW/s) as expected.To get an estimate what would be possible with GPU I also used a MD5 crypt hash and with this John the Ripper was able to try about 712,000 passwords per second, so about 5400 times faster.
When you compare this to GTX1080 which is capable of about 10 million passwords per second with MD5Crypt https://gist.github.com/epixoip/a83d38f412b4737e99bbef804a270c40 So if this would be linear, GTX 1080 is about 14 times faster than Ryzen 7 5700U, so only about 1850 PW/s should be possible.
So current sshkey encryption is quite safe against offline attacks.
To the end a little python script that takes in
filename="test.key"
your ssh key and if it is bcrypt format it shows the salt and cost factor.