Created
May 16, 2012 16:57
-
-
Save etrepum/2712195 to your computer and use it in GitHub Desktop.
hmac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(erlhmac). | |
-export([hmac/4]). | |
hmac(Key, Message, Hash, BlockSize) when byte_size(Key) > BlockSize -> | |
hmac(Hash(Key), Message, Hash, BlockSize); | |
hmac(Key, Message, Hash, BlockSize) when byte_size(Key) < BlockSize -> | |
hmac(<<Key/binary, | |
(binary:copy(<<0>>, BlockSize - byte_size(Key)))/binary>>, | |
Message, Hash, BlockSize); | |
hmac(Key, Message, Hash, _BlockSize) -> | |
OKeyPad = <<<<(X bxor 16#5c)>> || <<X>> <= Key>>, | |
IKeyPad = <<<<(X bxor 16#36)>> || <<X>> <= Key>>, | |
Hash([OKeyPad, Hash([IKeyPad, Message])]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment