MD5() 函数在哪个库中? [英] In which library is the MD5() function?

查看:14
本文介绍了MD5() 函数在哪个库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编写代码以安装到目标机器上时,我想知道依赖项并注意到不需要 openssl 库.我想知道,因为我知道我使用的是 OpenSSL:

#include ...MD5(a, b, c);...

令我惊讶的是,我们似乎只与 libc 建立了链接.MD5 真的是在 libc 中实现的,而不是在某些 libssl 库中实现的吗?

<小时>

objdump 给了我关于链接库的信息:

动态部分:需要 libQtCore.so.4需要 libstdc++.so.6需要 libgcc_s.so.1需要 libc.so.6SONAME libcontent.so

<小时>

根据 noloader 的建议,我尝试使用 ldd,但仍然没有看到对 MD5 有意义的库.libcontent.so 是直接使用 MD5()...

ldd ../BUILD/snapwebsites/plugins/content/libcontent.solinux-vdso.so.1 =>(0x00007fff4f3ff000)libQtCore.so.4 =>/usr/lib/x86_64-linux-gnu/libQtCore.so.4 (0x00007ff37ad0f000)libstdc++.so.6 =>/usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff37aa0c000)libgcc_s.so.1 =>/lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff37a7f5000)libc.so.6 =>/lib/x86_64-linux-gnu/libc.so.6 (0x00007ff37a42c000)libpthread.so.0 =>/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff37a20f000)libz.so.1 =>/lib/x86_64-linux-gnu/libz.so.1 (0x00007ff379ff7000)libdl.so.2 =>/lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff379df3000)libglib-2.0.so.0 =>/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff379af7000)librt.so.1 =>/lib/x86_64-linux-gnu/librt.so.1 (0x00007ff3798ee000)libm.so.6 =>/lib/x86_64-linux-gnu/libm.so.6 (0x00007ff3795e9000)/lib64/ld-linux-x86-64.so.2 (0x00007ff37b5e5000)libpcre.so.3 =>/lib/x86_64-linux-gnu/libpcre.so.3 (0x00007ff3793a9000)

<小时>

另外,为了确保,我在该内容库上尝试了 nm,我可以看到 MD5 条目:

 w _ITM_registerTMCloneTable00000000003c9468 d __JCR_END__00000000003c9468 d __JCR_LIST__w _Jv_RegisterClassesU MD5 <---- 它在这里...你 memcmp@@GLIBC_2.2.5w pthread_cancelupthread_mutex_destroy@@GLIBC_2.2.5

解决方案

MD5() 函数在哪个库中?

OpenSSL 库.链接到 libcrypto.请参阅 md5(3).

<小时><块引用>

MD5 真的是在 libc 中实现的,而不是在某些 libssl 库中实现的吗?

好吧,它不在 Ubuntu 的 libc 中:

$ nm -D/lib/x86_64-linux-gnu/libc.so.6 |grep -i md5$

它在 OpenSSL 的 libcrypto 中:

$ nm -D/usr/lib/x86_64-linux-gnu/libcrypto.so |grep MD50000000000066840 T MD50000000000066640 T MD5_Final0000000000066790 T MD5_Init0000000000066630 T MD5_Transform0000000000066420 T MD5_Update

T 表示符号 (MD5) 在 TEXT 部分中定义并导出.t 表示符号在 TEXT 部分定义,它没有导出,所以你不能链接它(想想 GCC 的 visibility=private 或静态声明).

如果你得到一个 U,那么这意味着这个符号是必需的但未定义,并且一个库必须提供它.

<小时><块引用>

#include ...MD5(a, b, c, d);

MD5(a, b, c, d); 不是 OpenSSL 的 MD5.OpenSSL 的 MD5 有三个参数,而不是四个.

<小时><块引用>

objdump 给了我关于链接库的信息

ldd 可能会给你不同的结果.它是我用来检查依赖项的(我不使用 objdump):

$ cat t.c#include int main(int argc, char* argv[]){const char 密码[] = "密码";字符哈希[MD5_DIGEST_LENGTH];MD5(密码,大小(密码),哈希);返回0;}$ gcc t.c -o t.exe -lcrypto$ ldd t.exelinux-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)

t.exe的未解析符号:

$ nm t.exe |grep MD5U MD5@@OPENSSL_1.0.0

As I'm writing code to install on a target machine, I was wondering about the dependencies and noticed that there were no openssl library needed. I wondered because I know I am using OpenSSL:

#include <openssl/md5.h>

...
MD5(a, b, c);
...

To my surprise, it seems that we only get linked against libc. Is MD5 really implemented in libc and not in some libssl library?


objdump gives me the info about the linked library:

Dynamic Section:
  NEEDED               libQtCore.so.4
  NEEDED               libstdc++.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libc.so.6
  SONAME               libcontent.so


As suggested by noloader I tried with ldd and still fail to see a library that would make sense for MD5. libcontent.so is directly using MD5()...

ldd ../BUILD/snapwebsites/plugins/content/libcontent.so 
    linux-vdso.so.1 =>  (0x00007fff4f3ff000)
    libQtCore.so.4 => /usr/lib/x86_64-linux-gnu/libQtCore.so.4 (0x00007ff37ad0f000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff37aa0c000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff37a7f5000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff37a42c000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff37a20f000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff379ff7000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff379df3000)
    libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff379af7000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff3798ee000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff3795e9000)
    /lib64/ld-linux-x86-64.so.2 (0x00007ff37b5e5000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007ff3793a9000)


Also, just to make sure, I tried nm on that content library and I can see the MD5 entry:

                 w _ITM_registerTMCloneTable
00000000003c9468 d __JCR_END__
00000000003c9468 d __JCR_LIST__
                 w _Jv_RegisterClasses
                 U MD5                       <---- it's here...
                 U memcmp@@GLIBC_2.2.5
                 w pthread_cancel
                 U pthread_mutex_destroy@@GLIBC_2.2.5

解决方案

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

这篇关于MD5() 函数在哪个库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆