aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/rng/hmac_drbg/hmac_drbg.h
blob: bd2d18d47391e426ec3a927c621ea9e9292340a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* HMAC_DRBG (SP800-90A)
* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_HMAC_DRBG_H__
#define BOTAN_HMAC_DRBG_H__

#include <botan/rng.h>
#include <botan/mac.h>

namespace Botan {

/**
* HMAC_DRBG (SP800-90A)
*/
class BOTAN_DLL HMAC_DRBG : public RandomNumberGenerator
   {
   public:
      void randomize(byte buf[], size_t buf_len) override;
      bool is_seeded() const override;
      void clear() override;
      std::string name() const override;

      size_t reseed_with_sources(Entropy_Sources& srcs,
                                 size_t poll_bits,
                                 std::chrono::milliseconds poll_timeout) override;

      void add_entropy(const byte input[], size_t input_len) override;

      /**
      * @param mac the underlying mac function (eg HMAC(SHA-512))
      * @param underlying_rng RNG used generating inputs (eg HMAC_RNG)
      */
      HMAC_DRBG(MessageAuthenticationCode* mac,
                RandomNumberGenerator* underlying_rng = nullptr);

      HMAC_DRBG(const std::string& mac,
                RandomNumberGenerator* underlying_rng = nullptr);

   private:
      void update(const byte input[], size_t input_len);

      std::unique_ptr<MessageAuthenticationCode> m_mac;
      std::unique_ptr<RandomNumberGenerator> m_prng;

      secure_vector<byte> m_V;
      size_t m_reseed_counter;
   };

}

#endif