简体   繁体   English

计算HMAC-SHA1时HMAC_Init崩溃

[英]HMAC_Init crashes while calculating HMAC-SHA1

Here is my code: 这是我的代码:

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;  
}

I am using openssl 0.9.8.c. 我正在使用openssl0.9.8.c。 If anyone faced this problem please let me know. 如果有人遇到此问题,请告诉我。

According to the man page HMAC_Init is deprecated. 根据手册页 ,不建议使用HMAC_Init。 Might be worth trying HMAC_Init_ex. 可能值得尝试HMAC_Init_ex。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM