fbpx
维基百科

HMAC

HMAC (有时扩展为 英語:keyed-hash message authentication code, 金鑰雜湊訊息鑑別碼, 或 英語:hash-based message authentication code雜湊訊息鑑別碼),是一種通過特別計算方式之後產生的訊息鑑別碼(MAC),使用密碼雜湊函數,同時結合一個加密金鑰。它可以用來保證資料的完整性,同時可以用來作某個訊息的身份驗證

SHA-1 HMAC產生過程

定義 编辑

根據RFC 2104,HMAC的數學公式為:  

其中:

H為密碼雜湊函數(如SHA家族
K密鑰(secret key)
m是要认证的消息
K'是从原始密钥K导出的另一个秘密密钥(如果K短于散列函数的输入块大小,则向右填充(Padding)零;如果比该块大小更长,则对K进行散列)
|| 代表串接
⊕ 代表異或(XOR)
opad 是外部填充(0x5c5c5c…5c5c,一段十六进制常量)
ipad 是内部填充(0x363636…3636,一段十六进制常量)

实现 编辑

下面的伪代码展示了如何实现HMAC。当使用以下散列函数之一时,块大小为64(字节):SHA-1、MD5、RIPEMD-128/160[1]

 function hmac (key, message) { if (length(key) > blocksize) { key = hash(key) // keys longer than blocksize are shortened } if (length(key) < blocksize) { // keys shorter than blocksize are zero-padded (where  is concatenation) key = key ∥ [0x00 * (blocksize - length(key))] // Where * is repetition. } o_key_pad = [0x5c * blocksize] ⊕ key // Where blocksize is that of the underlying hash function i_key_pad = [0x36 * blocksize] ⊕ key // Where ⊕ is exclusive or (XOR) return hash(o_key_pad ∥ hash(i_key_pad ∥ message)) // Where  is concatenation } 

相關條目 编辑

参考文献 编辑

  1. ^ RFC 2104, section 2, "Definition of HMAC", page 3.

hmac, 此條目可参照英語維基百科相應條目来扩充, 若您熟悉来源语言和主题, 请协助参考外语维基百科扩充条目, 请勿直接提交机械翻译, 也不要翻译不可靠, 低品质内容, 依版权协议, 译文需在编辑摘要注明来源, 或于讨论页顶部标记, href, template, translated, page, html, title, template, translated, page, translated, page, 标签, 有时扩展为, 英語, keyed, hash, message, authenticati. 此條目可参照英語維基百科相應條目来扩充 若您熟悉来源语言和主题 请协助参考外语维基百科扩充条目 请勿直接提交机械翻译 也不要翻译不可靠 低品质内容 依版权协议 译文需在编辑摘要注明来源 或于讨论页顶部标记 a href Template Translated page html title Template Translated page Translated page a 标签 HMAC 有时扩展为 英語 keyed hash message authentication code 金鑰雜湊訊息鑑別碼 或 英語 hash based message authentication code 雜湊訊息鑑別碼 是一種通過特別計算方式之後產生的訊息鑑別碼 MAC 使用密碼雜湊函數 同時結合一個加密金鑰 它可以用來保證資料的完整性 同時可以用來作某個訊息的身份驗證 SHA 1 HMAC產生過程 目录 1 定義 2 实现 3 相關條目 4 参考文献定義 编辑根據RFC 2104 HMAC的數學公式為 HMAC K m H K o p a d H K i p a d m displaystyle textit HMAC K m H Bigl K oplus opad H bigl K oplus ipad m bigr Bigr nbsp 其中 H為密碼雜湊函數 如SHA家族 K為密鑰 secret key m是要认证的消息 K 是从原始密钥K导出的另一个秘密密钥 如果K短于散列函数的输入块大小 则向右填充 Padding 零 如果比该块大小更长 则对K进行散列 代表串接 代表異或 XOR opad 是外部填充 0x5c5c5c 5c5c 一段十六进制常量 ipad 是内部填充 0x363636 3636 一段十六进制常量 实现 编辑下面的伪代码展示了如何实现HMAC 当使用以下散列函数之一时 块大小为64 字节 SHA 1 MD5 RIPEMD 128 160 1 function hmac key message if length key gt blocksize key hash key keys longer than blocksize are shortened if length key lt blocksize keys shorter than blocksize are zero padded where is concatenation key key 0x00 blocksize length key Where is repetition o key pad 0x5c blocksize key Where blocksize is that of the underlying hash function i key pad 0x36 blocksize key Where is exclusive or XOR return hash o key pad hash i key pad message Where is concatenation 相關條目 编辑SHA家族参考文献 编辑 RFC 2104 section 2 Definition of HMAC page 3 取自 https zh wikipedia org w index php title HMAC amp oldid 72929996, 维基百科,wiki,书籍,书籍,图书馆,

文章

,阅读,下载,免费,免费下载,mp3,视频,mp4,3gp, jpg,jpeg,gif,png,图片,音乐,歌曲,电影,书籍,游戏,游戏。