0 | module Data.Cryptography.HMAC
5 | import Data.Cryptography.Hash
8 | record HmacCtx (hash: HashAlgorithm) (keyLength: Nat) where
9 | constructor MkHmacCtx
10 | hashCtx: hash.ctxType
11 | key: Vect keyLength Bits8
24 | mkHmacCtx : {hash: HashAlgorithm}
26 | -> (key: Vect keyLength Bits8)
27 | -> HmacCtx hash keyLength
29 | let ikey = map (xor 0x36) key
31 | { hashCtx = hash.mkHashCtx |> hash.appendHash (toList ikey)
36 | appendHmac : {hash: HashAlgorithm} -> List Bits8 -> HmacCtx hash keyLength -> HmacCtx hash keyLength
38 | { hashCtx $= hash.appendHash text }
41 | finalizeHmac : {hash: HashAlgorithm} -> HmacCtx hash keyLength -> Vect hash.outputSize Bits8
43 | let okey = map (xor 0x5c) ctx.key
44 | innerHash : Vect hash.outputSize Bits8
45 | innerHash = hash.finalizeHash ctx.hashCtx
46 | outerHash : Vect hash.outputSize Bits8
49 | hash.appendHash (toList okey) |>
50 | hash.appendHash (toList innerHash) |>