Botan 2.19.5 Crypto and TLS for C&

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_types.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 // C_SeedRandom may suceed
61 bool accepts_input() const override { return true; }
62
63 private:
64 const std::reference_wrapper<Session> m_session;
65 };
66}
67
68}
69
70#endif
Botan::Entropy_Sources
Definition: entropy_src.h:57
Botan::Hardware_RNG
Definition: rng.h:197
Botan::PKCS11::Module
Definition: p11_types.h:29
Botan::PKCS11::PKCS11_RNG
A random generator that only fetches random from the PKCS#11 RNG.
Definition: p11_randomgenerator.h:26
Botan::PKCS11::PKCS11_RNG::accepts_input
bool accepts_input() const override
Definition: p11_randomgenerator.h:61
Botan::PKCS11::PKCS11_RNG::name
std::string name() const 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:43
Botan::PKCS11::PKCS11_RNG::module
Module & module() const
Definition: p11_randomgenerator.h:49
Botan::PKCS11::PKCS11_RNG::is_seeded
bool is_seeded() const override
Always returns true.
Definition: p11_randomgenerator.h:37
Botan::PKCS11::Session
Represents a PKCS#11 session.
Definition: p11_types.h:131
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan
Definition: alg_id.cpp:13