Andrew Lambert
Andrew Lambert

Reputation: 1909

Does libsodium have error codes?

Or any other mechanism to get the reason why a function is failing?

I'm calling crypto_pwhash and it's failing (returns -1) for no obvious reason, in fact the exact same code worked fine with an old version of libsodium. Having an error code would make debugging this a lot easier.

Upvotes: 0

Views: 743

Answers (1)

Frank Denis
Frank Denis

Reputation: 1501

Most functions do not return specific error codes when they fail.

History has shown that using different error codes for cryptographic operations can help attackers conduct devastating attacks.

crypto_pwhash allocates memory. So one reason it may fail is that you are running out of memory. In that case, errno will be set appropriately.

Also check that the parameters are within the allowed ranges. Functions such as crypto_pwhash_bytes_min(), crypto_pwhash_memlimit_min() and crypto_pwhash_memlimit_min() can come in handy. For example, given the purpose of that function, the output must be at least 128 bits.

Upvotes: 1

Related Questions