In which library is the MD5() function?
The OpenSSL library. Link to libcrypto
. See md5(3).
Is MD5 really implemented in libc and not in some libssl library?
Well, its not in Ubuntu's libc
:
$ nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep -i md5
$
And it is in OpenSSL's libcrypto
:
$ nm -D /usr/lib/x86_64-linux-gnu/libcrypto.so | grep MD5
0000000000066840 T MD5
0000000000066640 T MD5_Final
0000000000066790 T MD5_Init
0000000000066630 T MD5_Transform
0000000000066420 T MD5_Update
The T
means the symbol (MD5
) is defined in the TEXT section and its exported. A t
means the symbol is defined in the TEXT section, but its not exported so you cannot link against it (think GCC's visibility=private
or a static declaration).
If you get a U
, then that means the symbol is required but undefined and a library will have to provide it.
#include <openssl/md5.h>
...
MD5(a, b, c, d);
MD5(a, b, c, d);
is not OpenSSL's MD5. OpenSSL's MD5 has three parameters, not four.
objdump gives me the info about the linked library
ldd
might give you different results. Its what I use to check dependencies (and I don't use objdump
):
$ cat t.c
#include <openssl/md5.h>
int main(int argc, char* argv[])
{
const char password[] = "password";
char hash[MD5_DIGEST_LENGTH];
MD5(password, sizeof(password), hash);
return 0;
}
$ gcc t.c -o t.exe -lcrypto
$ ldd t.exe
linux-vdso.so.1 => (0x00007fff435ff000)
libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fbaff01b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbafec90000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbafea8b000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fbafe874000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbaff429000)
And t.exe
's unresolved symbol:
$ nm t.exe | grep MD5
U MD5@@OPENSSL_1.0.0