资源简介
阿里云设备登录一机一密和一型一密都需要用到HMAC-MD5算法
什么是 HMAC-MD5?
1、比如你和对方共享了一个密钥K,现在你要发消息给对方,既要保证消息没有被篡改,又要能证明信息确实是你本人发的,那么就把原信息和使用K计算的HMAC的值一起发过去。对方接到之后,使用自己手中的K把消息计算一下HMAC,如果和你发送的HMAC一致,那么可以认为这个消息既没有被篡改也没有冒充。
2、MD5就是通过散列对要输出的数据进行摘要,接收到数据时,再同样进行MD5散列,与给定的MD5散列值比较,一致不一致就很清楚了。通常来说,传输的数据和MD5是不同的渠道给出的,比如网页上显示MD5,下载链接是某个镜像网站的。如果要通过同一个渠道发送数据和散列值的话(比如消息认证码),就要考虑数据和MD5同时被篡改的问题,如果第三方修改了数据,然后进行MD5散列,并一块发给接收方,接收方并不能察觉到数据被篡改。HMAC-MD5就可以用一把发送方和接收方都有的key进行计算,而没有这把key的第三方是无法计算出正确的散列值的,这样就可以防止数据被篡改。

代码片段和文件信息
#include “md5.h“
/* The below was retrieved from
* http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.c?rev=1.1
* with the following changes:
* #includes commented out.
* Support context->count as unsigned int[2] instead of uint64_t
* u_int* to uint*
*/
/*
* This code implements the MD5 message-digest algorithm.
* The algorithm is due to Ron Rivest. This code was
* written by Colin Plumb in 1993 no copyright is claimed.
* This code is in the public domain; do with it what you wish.
*
* Equivalent code is available from RSA Data Security Inc.
* This code has been tested against that and is equivalent
* except that you don‘t need to include two pages of legalese
* with every copy.
*
* To compute the message digest of a chunk of bytes declare an
* MD5Context structure pass it to MD5Init call MD5Update as
* needed on buffers full of bytes and then call MD5Final which
* will fill a supplied 16-byte array with the digest.
*/
/*#include */
/*#include */
/*#include */
#define PUT_64BIT_LE(cp value) do { \
(cp)[7] = (value)[1] >> 24; \
(cp)[6] = (value)[1] >> 16; \
(cp)[5] = (value)[1] >> 8; \
(cp)[4] = (value)[1]; \
(cp)[3] = (value)[0] >> 24; \
(cp)[2] = (value)[0] >> 16; \
(cp)[1] = (value)[0] >> 8; \
(cp)[0] = (value)[0]; } while (0)
#define PUT_32BIT_LE(cp value) do { \
(cp)[3] = (value) >> 24; \
(cp)[2] = (value) >> 16; \
(cp)[1] = (value) >> 8; \
(cp)[0] = (value); } while (0)
static unsigned char PADDING[MD5_BLOCK_LENGTH] = {
0x80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
};
/*
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
void
MD5Init(MD5_CTX *ctx)
{
ctx->count[0] = 0;
ctx->count[1] = 0;
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xefcdab89;
ctx->state[2] = 0x98badcfe;
ctx->state[3] = 0x10325476;
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
MD5Update(MD5_CTX *ctx unsigned char const *input size_t len)
{
size_t have need;
/* Check how many bytes we already have and how many more we need. */
have = (size_t)((ctx->count[0] >> 3) & (MD5_BLOCK_LENGTH - 1));
need = MD5_BLOCK_LENGTH - have;
/* Update bitcount */
/* ctx->count += (uint64_t)len << 3;*/
if ((ctx->count[0] += ((unsigned int)len << 3)) < (unsigned int)len) {
/* Overflowed ctx->count[0] */
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3005 2019-04-09 20:13 md5.h
文件 12029 2019-04-09 20:10 md5.c
----------- --------- ---------- ----- ----
15034 2
- 上一篇:IC卡水表程序
- 下一篇:峰值检测系统课程设计
相关资源
- SVR算法程序可运行
- 计算机图形学 边填充算法实现代码
- 福建师范大学历年算法考卷
- 栈的实现及应用,六种基本算法
- Bresenham算法绘制线段并利用“橡皮筋
- 介绍几种压缩算法及《笨笨数据压缩
- 改进的BP神经网络算法
- A星算法_原理讲解_例子
- 云模型的相关算法cloud
- 旋转矩阵求欧拉角的简单算法
- 栅栏填充算法源码(VC)
- 38k单片机红外发送代码、keil
- RSA算法源码
- 关联分析Apriori算法实现
- [免费]relax算法成像
- 操作系统 LRU算法 实验报告 及 程序代
- 分治法快速排序算法QuickSort C
- 现代谱估计算法 music ESPRIT 谐波分解
- MUSIC算法c 实现
- 007出纳管理系统 v7[1].5.94 算法注册机
- 克鲁斯卡尔算法C和C 实现代码
- 2410的led测试程序keil可以用
- capon波束形成算法-VC实现
- QGA 量子遗传算法
- 利用OpenGL写毛笔字算法
- 带头结点的单链表的c算法实现
- 自适应隐写算法wow
- 协同过滤算法源码
- keil vcom windows 7 64bit 驱动
- RSA AES DES ECC加密算法源码
评论
共有 条评论