# `Tezex.Crypto.HMACDRBG`
[🔗](https://github.com/objkt-com/tezex/blob/v5.0.1/lib/crypto/hmacdrbg.ex#L1)

Pure Elixir implementation of [HMAC-DRBG](https://csrc.nist.gov/csrc/media/events/random-number-generation-workshop-2004/documents/hashblockcipherdrbg.pdf)

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}

# `hash_algo`

```elixir
@type hash_algo() ::
  :sha
  | :sha224
  | :sha256
  | :sha384
  | :sha512
  | :sha3_224
  | :sha3_256
  | :sha3_384
  | :sha3_512
```

# `t`

```elixir
@type t() :: %Tezex.Crypto.HMACDRBG{
  algo: hash_algo(),
  count: non_neg_integer(),
  k: binary(),
  v: binary()
}
```

# `generate`

```elixir
@spec generate(t(), pos_integer(), binary() | nil) :: {binary(), t()}
```

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

# `init`

```elixir
@spec init(binary(), binary(), binary() | nil, hash_algo()) :: t()
```

Initialize a DRBG

# `reseed`

```elixir
@spec reseed(t(), binary(), binary() | nil) :: t()
```

Reseed a DRBG

---

*Consult [api-reference.md](api-reference.md) for complete listing*
