Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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_DLL 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 void clear() override
32 {}
33
34 std::string name() const override
35 {
36 return "PKCS11_RNG";
37 }
38
39 /// Always returns true
40 bool is_seeded() const override
41 {
42 return true;
43 }
44
45 /// No operation - always returns 0
46 size_t reseed(Entropy_Sources&, size_t, std::chrono::milliseconds) override
47 {
48 return 0;
49 }
50
51 /// @return the module used by this RNG
52 inline Module& module() const
53 {
54 return m_session.get().module();
55 }
56
57 /// Calls `C_GenerateRandom` to generate random data
58 void randomize(uint8_t output[], std::size_t length) override;
59
60 /// Calls `C_SeedRandom` to add entropy to the random generation function of the token/middleware
61 void add_entropy(const uint8_t in[], std::size_t length) override;
62
63 private:
64 const std::reference_wrapper<Session> m_session;
65 };
66 }
67
68 }
69
70 #endif
Botan::PKCS11::PKCS11_RNG::clear
void clear() override
Definition: p11_randomgenerator.h:31
Botan::PKCS11::PKCS11_RNG::reseed
size_t reseed(Entropy_Sources &, size_t, std::chrono::milliseconds) override
No operation - always returns 0.
Definition: p11_randomgenerator.h:46
Botan::PKCS11::PKCS11_RNG::module
Module & module() const
Definition: p11_randomgenerator.h:52
Botan::PKCS11::Module
Definition: p11_module.h:25
Botan
Definition: alg_id.cpp:13
Botan::PKCS11::PKCS11_RNG
A random generator that only fetches random from the PKCS#11 RNG.
Definition: p11_randomgenerator.h:25
Botan::Entropy_Sources
Definition: entropy_src.h:51
Botan::PKCS11::PKCS11_RNG::name
std::string name() const override
Definition: p11_randomgenerator.h:34
Botan::PKCS11::Session
Represents a PKCS#11 session.
Definition: p11_session.h:22
Botan::PKCS11::PKCS11_RNG::is_seeded
bool is_seeded() const override
Always returns true.
Definition: p11_randomgenerator.h:40
Botan::Hardware_RNG
Definition: rng.h:180