Botan  2.6.0
Crypto and TLS for C++11
p11_randomgenerator.h
Go to the documentation of this file.
1 /*
2 * PKCS#11 Random Generator
3 * (C) 2016 Daniel Neus, Sirrix AG
4 * (C) 2016 Philipp Weber, Sirrix AG
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #ifndef BOTAN_P11_RNG_H_
10 #define BOTAN_P11_RNG_H_
11 
12 #include <botan/rng.h>
13 #include <botan/p11_session.h>
14 #include <botan/entropy_src.h>
15 
16 #include <string>
17 #include <functional>
18 
19 namespace Botan {
20 namespace PKCS11 {
21 
22 class Module;
23 
24 /// A random generator that only fetches random from the PKCS#11 RNG
25 class BOTAN_PUBLIC_API(2,0) PKCS11_RNG final : public Hardware_RNG
26  {
27  public:
28  /// Initialize the RNG with the PKCS#11 session that provides access to the cryptoki functions
29  explicit PKCS11_RNG(Session& session);
30 
31  std::string name() const override
32  {
33  return "PKCS11_RNG";
34  }
35 
36  /// Always returns true
37  bool is_seeded() const override
38  {
39  return true;
40  }
41 
42  /// No operation - always returns 0
43  size_t reseed(Entropy_Sources&, size_t, std::chrono::milliseconds) override
44  {
45  return 0;
46  }
47 
48  /// @return the module used by this RNG
49  inline Module& module() const
50  {
51  return m_session.get().module();
52  }
53 
54  /// Calls `C_GenerateRandom` to generate random data
55  void randomize(uint8_t output[], std::size_t length) override;
56 
57  /// Calls `C_SeedRandom` to add entropy to the random generation function of the token/middleware
58  void add_entropy(const uint8_t in[], std::size_t length) override;
59 
60  private:
61  const std::reference_wrapper<Session> m_session;
62  };
63 }
64 
65 }
66 
67 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
size_t reseed(Entropy_Sources &, size_t, std::chrono::milliseconds) override
No operation - always returns 0.
Definition: alg_id.cpp:13
A random generator that only fetches random from the PKCS#11 RNG.
std::string name() const override
Represents a PKCS#11 session.
Definition: p11_session.h:21
bool is_seeded() const override
Always returns true.