簡體   English   中英

計算HMAC-SHA1時HMAC_Init崩潰

[英]HMAC_Init crashes while calculating HMAC-SHA1

這是我的代碼:

int function(const char * buffer,size_t len,unsigned char * value)  
{   

char* user = "username";  
char*password = "password";  
size_t text_len = strlen(user) + strlen(password) + 2;  
  unsigned char* key = (unsigned char*)calloc(1,16);  
  unsigned char* text= (unsigned char *)calloc(1,text_len);  

  snprintf((char*)text, text_len, "%s:%s",user,password );  

MD5(text, text_len-1, key)

  HMAC_CTX *ctx = NULL;  
  unsigned int md_len = 20;  
  ctx = (HMAC_CTX*) calloc(1,sizeof(HMAC_CTX));  
  if(ctx == NULL){return -1;}

  HMAC_CTX_init(ctx);  
  `HMAC_Init(ctx, key, 16, EVP_sha1());`  //crashing everytime, saying heap corruption
  HMAC_Update(ctx, buffer, len);  
  HMAC_Final(ctx, value, &md_len);   

  HMAC_CTX_cleanup(ctx);  
return 0;  
}

我正在使用openssl0.9.8.c。 如果有人遇到此問題,請告訴我。

根據手冊頁 ,不建議使用HMAC_Init。 可能值得嘗試HMAC_Init_ex。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM