2011-09-25 305 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' –