c - 打开 SSL 错误 : implicit declaration of MD5Init

标签 c authentication encryption openssl hmac

首先我要展示我的 c 文件的代码..

#include <stdlib.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <memory.h>
#include <string.h>
#include <ctype.h>
#include "sendip_module.h"
#include "ipv6ext.h"
#include "../ipv6.h"
#include "../ipv4.h"
#include "ah.h"
#include "esp.h"
#include "crypto_module.h"

#include <openssl/hmac.h>
#include <openssl/md5.h>

/*
code for hmac_md5 here....

void
hmac_md5(text, text_len, key, key_len, digest)
unsigned char*  text;                /* pointer to data stream */
int text_len;            /* length of data stream */
unsigned char* key;                 /* pointer to authentication key */
int key_len;             /* length of authentication key */
caddr_t digest;              /* caller digest to be filled in */

{
    MD5_CTX context;
    unsigned char k_ipad[65];    /* inner padding -
                                  * key XORd with ipad
                                  */
    unsigned char k_opad[65];    /* outer padding -
                                  * key XORd with opad
                                  */
    unsigned char tk[16];
    int i;
    /* if key is longer than 64 bytes reset it to key=MD5(key) */
    if (key_len > 64) {

            MD5_CTX      tctx;

            MD5Init(&tctx);
            MD5Update(&tctx, key, key_len);
            MD5Final(tk, &tctx);

            key = tk;
            key_len = 16;
    }

    /*
     * the HMAC_MD5 transform looks like:
     *
     * MD5(K XOR opad, MD5(K XOR ipad, text))
     *
     * where K is an n byte key
     * ipad is the byte 0x36 repeated 64 times
     * opad is the byte 0x5c repeated 64 times
     * and text is the data being protected
     */

    /* start out by storing key in pads */
    bzero( k_ipad, sizeof k_ipad);
    bzero( k_opad, sizeof k_opad);
    bcopy( key, k_ipad, key_len);
    bcopy( key, k_opad, key_len);

    /* XOR key with ipad and opad values */
    for (i=0; i<64; i++) {
            k_ipad[i] ^= 0x36;
            k_opad[i] ^= 0x5c;
    }
    /*
     * perform inner MD5
     */
    MD5Init(&context);                   /* init context for 1st
                                          * pass */
    MD5Update(&context, k_ipad, 64);      /* start with inner pad */
    MD5Update(&context, text, text_len); /* then text of datagram */
    MD5Final(digest, &context);          /* finish up 1st pass */
    /*
     * perform outer MD5
     */
    MD5Init(&context);                   /* init context for 2nd
                                          * pass */
    MD5Update(&context, k_opad, 64);     /* start with outer pad */
    MD5Update(&context, digest, 16);     /* then results of 1st
                                          * hash */
    MD5Final(digest, &context);          /* finish up 2nd pass */

*/

/*
rest of the program logic...
*/

我已经将 ...<.安装 openssl 的路径.....>../openssl/include 包含到 C_INCLUDE_PATH 并将其导出。

现在当我尝试编译它时出现错误:

 $ make

gcc -o xorauth.so -I.. -fPIC -fsigned-char -pipe -Wall -Wpointer-arith -Wwrite-strings
wstrict-prototypes -Wnested-externs -Winline -Werror -g -Wcast-align -  
DSENDIP_LIBS=\"/usr/local/lib/sendip\" -shared xorauth.c ../libsendipaux.a  
../libsendipaux.a

cc1: warnings being treated as errors

xorauth.c:34:1: error: function declaration isn’t a prototype
xorauth.c: In function ‘hmac_md5’:
xorauth.c:56:17: error: implicit declaration of function ‘MD5Init’
xorauth.c:56:17: error: nested extern declaration of ‘MD5Init’
xorauth.c:57:17: error: implicit declaration of function ‘MD5Update’
xorauth.c:57:17: error: nested extern declaration of ‘MD5Update’ 
xorauth.c:58:17: error: implicit declaration of function ‘MD5Final’
xorauth.c:58:17: error: nested extern declaration of ‘MD5Final’
make: *** [xorauth.so] Error 1

如果需要,我将编辑我跳过的其他实现细节,只是为了让帖子变小,因为我认为我需要做一些关于包含路径和头文件的事情,但我不知道。

请问有什么问题吗???

最佳答案

OpenSSL 中没有MD5Init 函数。 (在 BSD 实现中有。)

man MD5_Init(注意下划线),或参见 here .

编辑:

既然您已经向我们展示了有问题的代码,我还可以帮助处理“不是原型(prototype)”消息。

你有(编辑了一下):

void hmac_md5(text, text_len, key, key_len, digest)
unsigned char*  text;                
int text_len;            
unsigned char* key;                 
int key_len;             
caddr_t digest;              
{
    /* ... */
}

那是旧式或“K&R”函数定义。它仍然有效,但只是为了向后兼容,这意味着编译器将无法警告您有关参数数量或类型错误的调用。现代(自 1989 年起)版本是:

void hmac_md5(unsigned char *text, 
              int text_len, 
              unsigned char *key, 
              int key_len, 
              caddr_t digest)
{
    /* ... */
}

在将旧式函数声明和定义转换为使用原型(prototype)时,由于升级规则,您有时必须注意窄类型(float 和窄于 int 或 unsigned int 的整数类型)的参数。这不适用于这种特殊情况。

请注意,如果您愿意,您可以保留定义。由于您从互联网草稿中获得了代码,这甚至可能是个好主意(如果它没有损坏,请不要修复它)——但正如我所说,如果您调用它,您将无法从编译器那里获得任何帮助参数数量或类型错误。

关于c - 打开 SSL 错误 : implicit declaration of MD5Init,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7548223/

相关文章:

encryption - Solidity 合约中的 AES 解密

java - Android 不支持的 key 大小 : 3 bytes on decrypt text

c - 有效地找到二维空间中位置的两倍最优成本

c++ - 从 C 初始化 C++ 结构

功能代码

c - 分隔空字节分隔的 UNICODE C 字符串

authentication - 让用户输入特定页面的凭据

authentication - 具有委托(delegate)的 Laravel 5 - hasRole 不工作

session - 如何使用 Wicket 在 session 中存储用户数据?

java - 重用密码(防止初始化)