HMAC算法相当容易理解。
Function hmac
Inputs:
key: Bytes array of bytes
message: Bytes array of bytes to be hashed
hash: Function the hash function to use (e.g. SHA-1)
blockSize: Integer the block size of the underlying hash function (e.g. 64 bytes for SHA-1)
outputSize: Integer the output size of the underlying hash function (e.g. 20 bytes for SHA-1)
Keys longer than blockSize are shortened by hashing them
if (length(key) > blockSize) then
key ← hash(key) //Key becomes outputSize bytes long
Keys shorter than blockSize are padded to blockSize by padding with zeros on the right
if (length(key) < blockSize) then
key ← Pad(key, blockSize) //pad key with zeros to make it blockSize bytes long
o_key_pad = key xor [0x5c * blockSize] //Outer padded key
i_key_pad = key xor [0x36 * blockSize] //Inner padded key
retu