1

I am looking to hash user passwords to store in a database that will likely reside on a user's intranet, so I am expecting the database to be classed as open and insecure.

I am using libsodium 1.0.18 to perform the password hashing.

Is this an effective enough way to hash the passwords, or is there a more secure way to do so, bearing in mind reasonable memory and time limits?

auto password = static_cast<char*>(sodium_malloc(sizeof(char) * 128));

// get password...
std::cin >> password;

sodium_mprotect_noaccess(password);

// do stuff...

sodium_mprotect_readonly(password);

char result[crypto_pwhash_STRBYTES];

if (crypto_pwhash_str(result, password, strlen(password),
                      crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE) != 0)
{
    // ...
}

sodium_free(password);

std::cout << result << std::endl;
1
  • 3
    The documentation clearly says what the *_SENSITIVE options you use mean in terms of time and memory needed for the hashing. If this explanation there matches what you consider "reasonable" in your specific use case is unknown since no actual threat vectors are known about your use case. For example if users are allowed to use weak passwords then even using some slow hashing will still make brute forcing these weak passwords possible. – Steffen Ullrich Dec 16 '20 at 3:58

Your Answer

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

Browse other questions tagged or ask your own question.