Countersign.Crypto (Countersign v0.1.0)

Copy Markdown View Source

Encryption and digests under keys derived from the host's secret_key_base (Countersign.Config).

  • Addresses and tokens are encrypted with Plug.Crypto.MessageEncryptor (AES-256-GCM), each purpose under its own derived key pair, so a token ciphertext can never be decrypted as an address or the other way round.
  • An address digest is HMAC-SHA256 of the normalised address under its own derived key: equal addresses give equal digests, and the digest reveals nothing without the secret.

Summary

Functions

Decrypts what encrypt/3 produced for the same purpose.

HMAC-SHA256 (32 bytes) of the normalised address on channel.

Encrypts plaintext for purpose.

The normalised form of address that digest/3 hashes.

Types

purpose()

@type purpose() :: :address | :token | :code

Functions

decrypt(config, purpose, ciphertext)

@spec decrypt(Countersign.Config.t(), purpose(), binary() | nil) ::
  {:ok, String.t()} | :error

Decrypts what encrypt/3 produced for the same purpose.

digest(config, channel, address)

@spec digest(Countersign.Config.t(), String.t(), String.t()) :: binary()

HMAC-SHA256 (32 bytes) of the normalised address on channel.

An email is trimmed and lowercased; a phone number keeps its digits only, with a leading US country code 1 dropped from an 11-digit number.

encrypt(config, purpose, plaintext)

@spec encrypt(Countersign.Config.t(), purpose(), String.t()) :: binary()

Encrypts plaintext for purpose.

normalize(binary, address)

@spec normalize(String.t(), String.t()) :: String.t()

The normalised form of address that digest/3 hashes.