exth_crypto v0.1.6 ExthCrypto.MAC
Wrapper for erlang’s built-in HMAC (Hash-based Message Authentication Code) and CMAC (Cipher-based Message Authentication Code) routines, to be used for Exthereum.
Link to this section Summary
Functions
Finalizes a given mac stream to produce the current hash
Initializes a new mac of given type with given args
Calcluates the MAC of a given set of input
Updates a given mac stream with the given secret and data, returning a new mac stream
Link to this section Types
Link to this section Functions
Finalizes a given mac stream to produce the current hash.
Examples
iex> ExthCrypto.MAC.init(:kec)
...> |> ExthCrypto.MAC.update("data")
...> |> ExthCrypto.MAC.final()
...> |> ExthCrypto.Math.bin_to_hex
"8f54f1c2d0eb5771cd5bf67a6689fcd6eed9444d91a39e5ef32a9b4ae5ca14ff"
iex> ExthCrypto.MAC.init(:fake, ["jedi"])
...> |> ExthCrypto.MAC.update(" ")
...> |> ExthCrypto.MAC.update("knight")
...> |> ExthCrypto.MAC.final()
"jedi"
Link to this function
init(mac_type, args \\ [])
Initializes a new mac of given type with given args.
Link to this function
mac(data, key, hash_algorithm, length \\ nil)
mac(iodata(), iodata(), ExthCrypto.Hash.hash_algorithm(), integer()) :: mac()
Calcluates the MAC of a given set of input.
Examples
iex> ExthCrypto.MAC.mac("The quick brown fox jumps over the lazy dog", "key", :sha256) |> ExthCrypto.Math.bin_to_hex
"f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"
iex> ExthCrypto.MAC.mac("The quick brown fox jumps over the lazy dog", "key", :sha256, 8)
<<247, 188, 131, 244, 48, 83, 132, 36>>