7.1 Overview of Hashes and MACs
首先,摘要值不应包含可用于确定原始输入的信息。 为了实现这一点,输入数据中的一位变化应该改变摘要值中的许多位(平均一半)。 其次,构造第二个消息产生相同的哈希值应该是非常困难的。 第三,也很难找到任何两个产生相同散列值的消息。
Table 7-1. Message digests and the EVP interface | |||
Hash algorithm | EVP call for getting EVP_MD | String for lookup | Digest length (in bits) |
MD2 | EVP_md2 | md2 | 128 |
MD4 | EVP_md4 | md4 | 128 |
MD5 | EVP_md5 | md5 | 128 |
MDC2 | EVP_mdc2 | mdc2 | 128 |
SHA1 | EVP_sha1 EVP_dssl | sha1 dssl | 160 |
RIPEMD-160 | EVP_ripemd160 | ripemd | 160 |
函数 | void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); |
功能 | 初始化ctx句柄 |
参数 | |
ctx | |
type | listed Table 7-1 |
函数 | void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *buf, unsigned int len); |
功能 | 用于在散列计算中包含数据 |
参数 | |
ctx | |
buf | 计算hash数据 |
len | buf长度 |
函数 | void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *hash, unsigned int *len); |
功能 | 一旦散列考虑的所有数据已经传递给EVP_DigestUpdate, 结果散列值可以使用EVP_DigestFinal检索。 |
参数 | |
ctx | |
hash | 哈希值将放置在其中的缓冲区。 这个缓冲区应该至少是EVP_MAX_MD_SIZE字节的大小。 |
len | buf长度 |
7.3 Using MACs
函数 | unsigned char *HMAC(const EVP_MD *type, const void *key, int keylen, const unsigned char *data, int datalen, unsigned char *hash, unsigned int *hashlen); |
功能 | 产生MAC值 |
参数 | |
type | 要使用的消息摘要。 |
key | 包含将使用的密钥的缓冲区。 |
keylen | 密钥长度 |
data | 包含将要计算HMAC的数据的缓冲区。 |
datalen | 数据长度 |
hash | 计算的消息摘要将被放置的缓冲区 |
hashlen | 指向一个整数的指针,该整数将接收填充的散列缓冲区的字节数。 |
函数 | void HMAC_Init(HMAC_CTX *ctx, const void *key, int keylen, const EVP_MD *type); |
功能 | 初始化HMAC对象 |
参数 | |
ctx | ctx对象 |
key | 包含将要使用的密钥的缓冲区。 |
keylen | 密钥缓冲区中的字节数将被视为有效的密钥数据。 |
type | 将使用的消息摘要对象。 |
函数 | void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len); |
功能 | 正在用于计算MAC的HMAC上下文对象。 |
参数 | |
ctx | ctx对象 |
data | 计算的数据 |
len | 计算数据的长度 |
函数 | void HMAC_Final(HMAC_CTX *ctx, unsigned char *hash, unsigned int *len); |
功能 | 获取HMAC值 |
参数 | |
ctx | ctx对象 |
hash | 将接收计算出的散列值的缓冲区。 |
len | hash长度 |
7.3.1 Other MACs
转载于:https://www.cnblogs.com/aixiaoxiaoyu/p/8214529.html