Botan 3.7.1
Crypto and TLS for C&
esdm_rng.h
Go to the documentation of this file.
1/*
2* ESDM RNG
3* (C) 2024, Markus Theil <theil.markus@gmail.com>
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_ESDM_RNG_H_
9#define BOTAN_ESDM_RNG_H_
10
11#include <botan/rng.h>
12#include <memory>
13
14namespace Botan {
15
16/**
17* Return a shared reference to a global PRNG instance provided by ESDM
18*/
19BOTAN_PUBLIC_API(3, 7) RandomNumberGenerator& esdm_rng();
20
21/**
22* Entropy Source and DRNG Manager (ESDM) is a Linux/Unix based
23* PRNG manager, which can be seeded from NTG.1/SP800-90B sources.
24*
25* See:
26* - Repository: https://github.com/smuellerDD/esdm
27* - Further Docs: https://www.chronox.de/esdm/index.html
28*
29* Different entropy sources can be configured in respect of being
30* active and how much entropy is accounted for each of them.
31*
32* ESDM tracks its seed and reseed status and blocks, when not fully seeded.
33* For this functionality, the esdm_rpcc_get_random_bytes_pr (prediction resistant) or
34* esdm_rpcc_get_random_bytes_full (fully seeded) calls have to be used.
35*
36* Configurable modes:
37* - fully seeded (-> fast): provide entropy from a DRBG/PRNG after beeing fully seeded,
38* block until this point is reached, reseed from after a time
39* and/or invocation limit, block again if reseeding is not possible
40* - prediction resistance (-> slow): reseed ESDM with fresh entropy after each invocation
41*
42* You typically want to use the fast fully seeded mode, which is the default.
43*
44* Instances of this class communicate over RPC with ESDM. The esdm_rpc_client
45* library, provided by ESDM, is leveraged for this.
46*
47* Thread safety:
48* It is fine to construct, destruct and use objects of this class concurrently.
49* The communication with ESDM is thread-safe, as handled by esdm_rpc_client.
50* The initialization of esdm_rpc_client is not thread safe, therefore this class
51* takes care of it, with its embedded ESDM_Context.
52*/
54 public:
55 /**
56 * Default constructor for ESDM, fully seeded mode
57 */
58 ESDM_RNG() : ESDM_RNG(false) {}
59
60 /**
61 * Construct ESDM instance with configurable mode
62 */
63 explicit ESDM_RNG(bool prediction_resistance);
64
65 std::string name() const override {
66 if(m_prediction_resistance) {
67 return "esdm-pr";
68 } else {
69 return "esdm-full";
70 }
71 }
72
73 /**
74 * ESDM blocks, if it is not seeded,
75 *
76 * @return true
77 */
78 bool is_seeded() const override { return true; }
79
80 /**
81 * ESDM can inject additional inputs
82 * but we do not account entropy for it
83 *
84 * @return true
85 */
86 bool accepts_input() const override { return true; }
87
88 /**
89 * the ESDM RNG does not hold any state outside ESDM, that should be cleared
90 * here
91 */
92 void clear() override {}
93
94 protected:
95 void fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) override;
96
97 private:
98 /**
99 * tracks if predicition resistant or fully seeded interface should be queried
100 */
101 bool m_prediction_resistance;
102
103 /**
104 * takes care of thread-safe esdm_rpc_client initialization
105 */
106 std::shared_ptr<void> m_ctx;
107};
108
109} // namespace Botan
110
111#endif /* BOTAN_ESDM_RNG_H_ */
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
bool is_seeded() const override
Definition esdm_rng.h:78
bool accepts_input() const override
Definition esdm_rng.h:86
std::string name() const override
Definition esdm_rng.h:65
void clear() override
Definition esdm_rng.h:92
int(* final)(unsigned char *, CTX *)
RandomNumberGenerator & esdm_rng()
Definition esdm_rng.cpp:99