I am trying to encrypt users private keys with the user password but if a user provides a weak password then the scrypt key generated from it will also be weak and suspectible to attack.

Let say the user generates a 32 bit key and the algorithm generates another 32 bit random salt. Then the key generated by XOR'ing these two keys will be used to enrypt the private keys. My question is: Is it safe to do so, will it be secure enough?

  • $\begingroup$ Where are you storing the salt? Or is the idea that you don't store it, but have to guess it by brute force when decrypting? (If so, I'd recommend just increasing the scrypt cost factor instead.) And are you XORing the salt with the password before feeding it to scrypt, or with the scrypt output aftwerwards? Oh, and by "32 bit key", do you mean a key with (approximately) 32 bits of entropy, or a key that's actually 32 bits long? $\endgroup$ – Ilmari Karonen Sep 17 '18 at 5:37
  • $\begingroup$ I am xoring the salt with the password before feeding it to scrypt function. $\endgroup$ – GraphicalDot Sep 17 '18 at 19:31

Scrypt is a psuedorandom function, the output will always be strong unless you purposely choose bad parameters. I would suggest just concatenating the password and the salt then feeding it into scrypt. That way the salt isn't limited in strength by the size of the password.

  • $\begingroup$ Scrypt already has a dedicated "salt" input, so it would make more sense to use that. $\endgroup$ – Ilmari Karonen Sep 17 '18 at 5:39
  • $\begingroup$ Can i put salt to public knowledge ?, keeping the user passwords sae with users? $\endgroup$ – GraphicalDot Sep 17 '18 at 8:53
  • 1
    $\begingroup$ A salt implies that you keep it in your database next to the account so yes. But as for storing password equivalent data, in this case no. $\endgroup$ – user245903 Sep 17 '18 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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