2011-09-25 64 views
2

首先我表示我的C文件中的代码的隐式声明..OpenSSL的错误:MD5Init

#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... 
*/ 

我已经包括在内。 .. < .path其中安装了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 

如果需要的话,我会编辑的其他实施细节我已经skiped他们只是为了让后小,因为我觉得有一些东西,我需要要做有关包含路径和头文件,我不知道它。

什么问题请帮帮我???

+0

很可能'<其他头文件>正在做一些令人讨厌的事情(如忘记分号或括号)。 – cnicutar

+0

@cnicutar我检查了但他们没事,代码在删除hmac_md5函数和两个头文件后正常工作 –

+0

至少向我们展示了触发错误消息(第34行和第56行)的xorauth.c中的行。第34行的消息看起来并不致命,通过使用原型而不是旧式的函数声明。 –

回答

1

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

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

编辑

现在你已经证明我们有问题的代码,我还可以帮助与“不是一个原型”的消息。

你(编辑了一下):

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) 
{ 
    /* ... */ 
} 

当转换旧风格函数声明和定义为使用原型,你有时不得不小心窄类型(浮点和整数类型均比int窄或参数由于促销规则,无符号整数)。这不适用于这种特殊情况。

请注意,您可以可以离开定义,如果你喜欢。既然你从互联网草案中得到了代码,那么这可能是一个好主意(如果它没有被破坏,就不要修复它) - 但是正如我所说的,如果你称之为编译器,你将不会得到任何帮助错误的参数数量或类型。

+0

哦........ ya感谢这实际上是它的错误,它是互联网草案的一部分,但现在又有一个'hmac_md5'错误,它的功能声明不是原型''。替换它也??? –

+0

@UditGupta:查看我更新的答案。 –

+0

你是完美编译现在和'sudo make install'后xorauth.so也peftectly作出。但是当我运行我的项目使用这个xorauth.so然后它再次显示错误..'无法打开模块xorauth,尝试: \t xorauth:无法打开共享对象文件:没有这样的文件或目录 \t ./xorauth.so :未定义的符号:MD5_Init \t /usr/local/lib/sendip/xorauth.so:未定义符号:MD5_Init \t的/ usr /本地/ LIB/sendip/xorauth:无法打开共享对象文件:没有这样的文件或directory' –