I'm attempting to use OpenSSL's PKCS5_PBKDF2_HMAC_SHA1 method. I gather that it returns 0 if it succeeds, and some other value otherwise. My question is, what does a non-zero return value mean? Memory error? Usage error? How should my program handle it (retry, quit?)?
Edit: A corollary question is, is there any way to figure this out besides reverse-engineering the method itself?
PKCS5_PBKDF2_HMAC_SHA1
looks like one of those undocumented functions because I can't find it in the OpenSSL docs. OpenSSL has a lot of them, so you should be prepared to study the sources if you are going to use the library.Actually, its reversed. Here's how I know...
So, you find the function's implementation in
crypto/evp/p5_crpt2.c
:Following
PKCS5_PBKDF2_HMAC
:And again, from
crypto/evp/p5_crpt2.c
:So it looks like
0
on failure, and1
on success. You should not see other values. And if you get a0
, then all theOUT
parameters are junk.Well, sometimes you can call
ERR_get_error
. If you call it and it makes sense, then the error code is good. If the error code makes no sense, then its probably not good.Sadly, that's the way I handle it because the library is not consistent with setting error codes. For example, here's the library code to load the
RDRAND
engine.Notice the code clears the error code on failure if its a 3rd generation Ivy Bridge (that's the capability being tested), and does not clear or set an error otherwise!!!
It looks like a hard failure.
Finally, that's exactly how I navigate the sources in this situation. If you don't like
grep
you can tryctags
or another source code browser.