c语言 hmac sha1 调用,hmac-sha1加密

以下代码引用( C语言中的HMAC_SHA1加密方法-源码 )历程,并删掉测试函数,便于自己理解罢了.详细请参考原文.(本历程可在NodeMCU上运行 Arduino IDE版本:1.8.9)

删除的函数后的:

1. #define NUM_TEST_CASES 10//有多少条要加密的

2. int test_case_length[];//消息内容长度

3. unsigned char test_cases[];//消息内容

4. int key_lengths[] ;//key长度

5. unsigned char keys[];//key内容

6. int get_testcase(int test_case, unsigned char *plaintext, unsigned char *key, int *key_length_ptr);//用于在同一个数组包涵多个消息 \ key时选择用返回为消息内容长度 我只用单一个所以无用

7.

#ifdef HMAC_DEBUG

Debug out (unsigned char *label, unsigned char *data, int data_length);//用于调试输出

#endif

8. 所有

#ifdef HMAC_DEBUG

***************

#endif

删除后的hmac_sha1.c文件:

#include

#include

#define MAX_MESSAGE_LENGTH 4096//最大消息长度

/********************************************/

/* Test Cases */

/* An array of test cases taken from the */

/* 802.11i specification. */

/********************************************/

unsigned char digest[20]={0};//最终生成的缓存 算完之后是 20 字节的摘要信息

/*****************************/

/**** Function Prototypes ****/

/*****************************/

unsigned long int ft(

int t,

unsigned long int x,

unsigned long int y,

unsigned long int z

);

int get_testcase( int test_case,

unsigned char *plaintext,

unsigned char *key,

int *key_length_ptr);

void sha1 (

unsigned char *message,

int message_length,

unsigned char *digest

);

/****************************************/

/* sha1() */

/* Performs the NIST SHA-1 algorithm */

/****************************************/

unsigned long int ft(

int t,

unsigned long int x,

unsigned long int y,

unsigned long int z

)

{

unsigned long int a,b,c;

if (t < 20) {

a = x & y;

b = (~x) & z;

c = a ^ b;

}

else if (t < 40) {

c = x ^ y ^ z;

}

else if (t <

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值