You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use scrypt for key generation in config file encryption #618
Currently the key generation from the user's password is done with sha256 for the config file. It has pre and post strings so isn't vulnerable to rainbow table attack, but using sha isn't best practice any more as it isn't computationally expensive enough.
We should upgrade to using scrypt with salt we store in the encrypted config file (or maybe reuse the IV for the secret box encryption). This can be done transparently to the user. We'll need to continue to read the old format though.
SHA256 is not meant to encrypt the password - it is meant to distribute the password to 256 bits so it can be used for secretbox. What is the rejection time of a wrong password for secretbox?
I considered bcrypt, but didn't really see how it would fit in unless we fix the number of iterations, since we need a stable output from bcrypt which we can use as our 256 bit key.
I prefer bcrypt over scrypt for our cause, since bcrypt is only CPU intensive and not memory intensive. While it may be slow on some systems (NAS, etc), it will still be able to run, contrasted to scrypt which has a fixed memory cost per operation, which may be impossible to satisfy on some systems.
We could do password -> bcrypt(fixed iteration count) -> SHA256 -> secretbox. We can of course change the format if we change the iteration count, which again should be transparent to the user.
If we do this, we can remove the "we do not recommend storing your encrypted rclone configuration in public if it contains sensitive information, maybe except if you use a very strong password" from the documentation.
We are using sha256 as a key derivation function. scrypt was purposed designed as a key derivation function, to turn user input into a variable number of random looking bits in a hard to do way (see the keyLen parameter in the docs). So you would do scrypt(scrypt.Key(password, salt, 16384, 8, 1, 24) to directly generate the 24 byte key for secretbox.
From what I read scrypt is considered more secure than bcrypt - using more memory means it is more FPGA/ASIC resistant.
An alternative key derivation function would be pbkdf2 which I haven't investigated in depth - that might be a better choice than scrypt.
I believe that we can afford to run scrypt at the default parameters even on a puny NAS - it uses 16 MB of RAM according to its benchmark. I don't really want to have tune-able parameters on the key derivation function though - that would just complicate things.
bcrypt, pbkdf2 or scrypt would all make better key derivation functions than sha256 and we are lucky to have an implementation of each in the golang.org/x/ repository. In the interest of not bloating rclone with too much crypto it would be nice to use the same key derivation function here and in the upcoming file encryption. I've used scrypt there and it was very useful in generating the 80 bytes of key material needed, but it isn't released yet so I could change it to something else.
Ah - scrypt has arbitrary key length output - nice.
Most of the "scrypt is better than bcrypt" I have found is mostly FUD. bcrypt is perfectly safe, if it is strong enough (at least 12 iterations). Scrypt has a fixed memory requirement, and using "strong" parameters (N = 2^20, r = 8, p = 1) , it will require 1GB of RAM (128 x 2^20 x 8) to derive the password. That I could see as a weak point. We can of course weaken the requirements as you mention, but then we don't gain the advantage we want.
Either way with scrypt or bcrypt we are shooting flies with canon balls. There isn't any reason not to do so, we should just choose the right type of canon ball. 🎱
Argon2 when it becomes available. Argon2 is the winner of the password hashing competition and should be considered as your first choice when solid implementations are available.
PBKDF2 when FIPS certification or enterprise support on many platforms is required;
scrypt where resisting any/all hardware accelerated attacks is necessary but support isn’t.
bcrypt where PBKDF2 or scrypt support is not available.
There is a pure go argon2 implementatino but it has too many warnings on it for me to want to use it! I don't want to use cgo in rclone.
pbkdf2 also has that arbitrary key length output and has the advantage of being somewhat industry standard (PKCS #5 v2.0, RFC 2898, recommended by NIST). What do you think of that?
Activity
klauspost commentedon Aug 15, 2016
SHA256 is not meant to encrypt the password - it is meant to distribute the password to 256 bits so it can be used for secretbox. What is the rejection time of a wrong password for secretbox?
I considered bcrypt, but didn't really see how it would fit in unless we fix the number of iterations, since we need a stable output from bcrypt which we can use as our 256 bit key.
I prefer bcrypt over scrypt for our cause, since bcrypt is only CPU intensive and not memory intensive. While it may be slow on some systems (NAS, etc), it will still be able to run, contrasted to scrypt which has a fixed memory cost per operation, which may be impossible to satisfy on some systems.
We could do
password -> bcrypt(fixed iteration count) -> SHA256 -> secretbox. We can of course change the format if we change the iteration count, which again should be transparent to the user.If we do this, we can remove the "we do not recommend storing your encrypted rclone configuration in public if it contains sensitive information, maybe except if you use a very strong password" from the documentation.
ncw commentedon Aug 15, 2016
We are using sha256 as a key derivation function. scrypt was purposed designed as a key derivation function, to turn user input into a variable number of random looking bits in a hard to do way (see the
keyLenparameter in the docs). So you would doscrypt(scrypt.Key(password, salt, 16384, 8, 1, 24)to directly generate the 24 byte key for secretbox.From what I read scrypt is considered more secure than bcrypt - using more memory means it is more FPGA/ASIC resistant.
An alternative key derivation function would be pbkdf2 which I haven't investigated in depth - that might be a better choice than scrypt.
I believe that we can afford to run scrypt at the default parameters even on a puny NAS - it uses 16 MB of RAM according to its benchmark. I don't really want to have tune-able parameters on the key derivation function though - that would just complicate things.
bcrypt, pbkdf2 or scrypt would all make better key derivation functions than sha256 and we are lucky to have an implementation of each in the golang.org/x/ repository. In the interest of not bloating rclone with too much crypto it would be nice to use the same key derivation function here and in the upcoming file encryption. I've used scrypt there and it was very useful in generating the 80 bytes of key material needed, but it isn't released yet so I could change it to something else.
klauspost commentedon Aug 15, 2016
Ah - scrypt has arbitrary key length output - nice.
Most of the "scrypt is better than bcrypt" I have found is mostly FUD. bcrypt is perfectly safe, if it is strong enough (at least 12 iterations). Scrypt has a fixed memory requirement, and using "strong" parameters (N = 2^20, r = 8, p = 1) , it will require 1GB of RAM (128 x 2^20 x 8) to derive the password. That I could see as a weak point. We can of course weaken the requirements as you mention, but then we don't gain the advantage we want.
Either way with scrypt or bcrypt we are shooting flies with canon balls. There isn't any reason not to do so, we should just choose the right type of canon ball. 🎱
ncw commentedon Aug 15, 2016
;-)
I take your point about the memory usage and security.
OWASP's advice is interesting
It rates them like this
There is a pure go argon2 implementatino but it has too many warnings on it for me to want to use it! I don't want to use cgo in rclone.
pbkdf2 also has that arbitrary key length output and has the advantage of being somewhat industry standard (PKCS #5 v2.0, RFC 2898, recommended by NIST). What do you think of that?