View Source Tezex.Crypto.HMACDRBG (tezex v2.0.0)

Pure Elixir implementation of HMAC-DRBG

Usage:

entropy = "totally random0123456789"
nonce = "some secret nonce"
pers = "my drbg"
drbg = HMACDRBG.init(entropy, nonce, pers)

{_result, drbg} = HMACDRBG.generate(drbg, 32)
{_result, drbg} = HMACDRBG.generate(drbg, 32)
{result, drbg} = HMACDRBG.generate(drbg, 32)

Base16.encode(result, case: :lower) == "a00cb0982eec3917b4b48abccfd460366d98b887943ff402bb7147cda174a46f"

Implementation inspired by both:

https://github.com/indutny/hmac-drbg/blob/master/package.json

MIT / (c) Fedor Indutny fedor@indutny.com

https://github.com/sorpaas/rust-hmac-drbg/blob/master/src/lib.rs

Apache License, Version 2.0, January 2004 / Copyright {yyyy} {name of copyright owner}

Summary

Functions

Generate size bytes, returning the generated bytes and the updated DRBG

Types

@type hash_algo() ::
  :sha
  | :sha224
  | :sha256
  | :sha384
  | :sha512
  | :sha3_224
  | :sha3_256
  | :sha3_384
  | :sha3_512
@type t() :: %Tezex.Crypto.HMACDRBG{
  algo: hash_algo(),
  count: non_neg_integer(),
  k: binary(),
  v: binary()
}

Functions

Link to this function

generate(state, size, add \\ nil)

View Source
@spec generate(t(), pos_integer(), binary() | nil) :: {binary(), t()}

Generate size bytes, returning the generated bytes and the updated DRBG

Link to this function

init(entropy, nonce, pers \\ nil, algo \\ :sha256)

View Source
@spec init(binary(), binary(), binary() | nil, hash_algo()) :: t()

Initialize a DRBG

Link to this function

reseed(state, entropy, add \\ nil)

View Source
@spec reseed(t(), binary(), binary() | nil) :: t()

Reseed a DRBG