Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
HMAC
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Implementation== The following [[pseudocode]] demonstrates how HMAC may be implemented. The block size is 512 bits (64 bytes) when using one of the following hash functions: SHA-1, MD5, RIPEMD-128.{{Ref RFC|2104|rsection=2}} '''{{blue|function}}''' hmac '''{{blue|is}}''' '''{{blue|input:}}''' key: Bytes {{green|// Array of bytes}} message: Bytes {{green|// Array of bytes to be hashed}} hash: Function {{green|// The hash function to use (e.g. SHA-1)}} blockSize: Integer {{green|// The block size of the hash function (e.g. 64 bytes for SHA-1)}} {{green|// Compute the block sized key}} block_sized_key = computeBlockSizedKey(key, hash, blockSize) o_key_pad β block_sized_key xor [0x5c blockSize] {{green|// Outer padded key}} i_key_pad β block_sized_key xor [0x36 blockSize] {{green|// Inner padded key}} '''{{blue|return}}''' hash(o_key_pad β₯ hash(i_key_pad β₯ message)) '''{{blue|function}}''' computeBlockSizedKey '''{{blue|is}}''' '''{{blue|input:}}''' key: Bytes {{green|// Array of bytes}} hash: Function {{green|// The hash function to use (e.g. SHA-1)}} blockSize: Integer {{green|// The block size of the hash function (e.g. 64 bytes for SHA-1)}} {{green|// Keys longer than ''blockSize'' are shortened by hashing them}} '''{{blue|if}}''' (length(key) > blockSize) '''{{Font color|blue|then}}''' key = hash(key) {{green|// Keys shorter than ''blockSize'' are padded to ''blockSize'' by padding with zeros on the right}} '''{{blue|if}}''' (length(key) < blockSize) '''{{Font color|blue|then}}''' '''{{blue|return}}''' Pad(key, blockSize) {{green|// Pad key with zeros to make it ''blockSize'' bytes long}} '''{{blue|return}}''' key
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)