Botan 2.19.1
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
19namespace Botan {
20namespace PKCS11 {
21
22class Module;
23
24/// A random generator that only fetches random from the PKCS#11 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
A random generator that only fetches random from the PKCS#11 RNG.
bool accepts_input() const override
std::string name() const override
size_t reseed(Entropy_Sources &, size_t, std::chrono::milliseconds) override
No operation - always returns 0.
bool is_seeded() const override
Always returns true.
Represents a PKCS#11 session.
Definition: p11_types.h:131
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:13