Exmbus.Crypto (Exmbus v0.4.0)

View Source

Wraps the crypto functions used in the Exmbus library.

Summary

Functions

Wraps the crypto_one_time function from the crypto module, just like crypto_one_time/5, but without the IV.

Wraps the crypto_one_time function from the crypto module, catching errors and returning them as {:error, {:crypto_error, e}} tuples. We do this to prevent a bad key from crashing the parse.

Runs the KDF-A key derivation function as described in EN 13757-7:2018 (9.6.2)

Types

cipher_iv()

@type cipher_iv() :: atom()

cipher_no_iv()

@type cipher_no_iv() :: atom()

crypto_error()

crypto_error_c_fileinfo()

@type crypto_error_c_fileinfo() :: term()

crypto_error_description()

@type crypto_error_description() :: String.t()

crypto_error_tag()

@type crypto_error_tag() :: :badarg | :notsup | :error

crypto_opts()

@type crypto_opts() :: [any()]

Functions

cmac(key, data)

cmac!(key, data)

crypto_one_time(cipher, key, data, flag_or_options)

@spec crypto_one_time(
  cipher :: cipher_no_iv(),
  key :: iodata(),
  data :: iodata(),
  flag_or_options :: crypto_opts() | boolean()
) :: {:ok, binary()} | {:error, crypto_error()}

Wraps the crypto_one_time function from the crypto module, just like crypto_one_time/5, but without the IV.

crypto_one_time(cipher, key, iv, data, flag_or_options)

@spec crypto_one_time(
  cipher :: cipher_iv(),
  key :: iodata(),
  iv :: iodata(),
  data :: iodata(),
  flag_or_options :: crypto_opts() | boolean()
) :: {:ok, binary()} | {:error, crypto_error()}

Wraps the crypto_one_time function from the crypto module, catching errors and returning them as {:error, {:crypto_error, e}} tuples. We do this to prevent a bad key from crashing the parse.

kdf_a(direction, mode, counter, meter_id, message_key)

@spec kdf_a(
  direction :: :from_meter | :to_meter,
  mode :: :enc | :mac,
  counter :: integer(),
  meter_id :: binary(),
  message_key :: binary()
) :: {:ok, binary()} | {:error, reason :: any()}

Runs the KDF-A key derivation function as described in EN 13757-7:2018 (9.6.2)

kdf_a!(direction, mode, counter, meter_id, message_key)