Botan 3.6.1
Crypto and TLS for C&
entropy_src.h
Go to the documentation of this file.
1/*
2* EntropySource
3* (C) 2008,2009,2014,2015,2016 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_ENTROPY_H_
9#define BOTAN_ENTROPY_H_
10
11#include <botan/rng.h>
12#include <botan/secmem.h>
13#include <chrono>
14#include <memory>
15#include <string>
16#include <vector>
17
18namespace Botan {
19
20class RandomNumberGenerator;
21
22/**
23* Abstract interface to a source of entropy
24*/
26 public:
27 /**
28 * Return a new entropy source of a particular type, or null
29 * Each entropy source may require substantial resources (eg, a file handle
30 * or socket instance), so try to share them among multiple RNGs, or just
31 * use the preconfigured global list accessed by Entropy_Sources::global_sources()
32 */
33 static std::unique_ptr<Entropy_Source> create(std::string_view type);
34
35 /**
36 * @return name identifying this entropy source
37 */
38 virtual std::string name() const = 0;
39
40 /**
41 * Perform an entropy gathering poll
42 * @param rng will be provided with entropy via calls to add_entropy
43 * @return conservative estimate of actual entropy added to rng during poll
44 */
45 virtual size_t poll(RandomNumberGenerator& rng) = 0;
46
47 Entropy_Source() = default;
48 Entropy_Source(const Entropy_Source& other) = delete;
49 Entropy_Source(Entropy_Source&& other) = delete;
50 Entropy_Source& operator=(const Entropy_Source& other) = delete;
51
52 virtual ~Entropy_Source() = default;
53};
54
56 public:
57 static Entropy_Sources& global_sources();
58
59 void add_source(std::unique_ptr<Entropy_Source> src);
60
61 std::vector<std::string> enabled_sources() const;
62
63 size_t poll(RandomNumberGenerator& rng, size_t bits, std::chrono::milliseconds timeout);
64
65 /**
66 * Poll just a single named source. Ordinally only used for testing
67 */
68 size_t poll_just(RandomNumberGenerator& rng, std::string_view src);
69
70 Entropy_Sources() = default;
71 explicit Entropy_Sources(const std::vector<std::string>& sources);
72
73 Entropy_Sources(const Entropy_Sources& other) = delete;
75 Entropy_Sources& operator=(const Entropy_Sources& other) = delete;
76
77 private:
78 std::vector<std::unique_ptr<Entropy_Source>> m_srcs;
79};
80
81} // namespace Botan
82
83#endif
virtual std::string name() const =0
Entropy_Source(const Entropy_Source &other)=delete
virtual size_t poll(RandomNumberGenerator &rng)=0
Entropy_Source(Entropy_Source &&other)=delete
virtual ~Entropy_Source()=default
Entropy_Source & operator=(const Entropy_Source &other)=delete
Entropy_Sources(Entropy_Sources &&other)=delete
Entropy_Sources(const Entropy_Sources &other)=delete
Entropy_Sources & operator=(const Entropy_Sources &other)=delete
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31