Botan 3.4.0
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/entropy_src.h>
13#include <botan/p11_types.h>
14#include <botan/rng.h>
15
16#include <functional>
17#include <string>
18
19namespace Botan::PKCS11 {
20
21class Module;
22
23/// A random generator that only fetches random from the PKCS#11 RNG
25 public:
26 /// Initialize the RNG with the PKCS#11 session that provides access to the cryptoki functions
27 explicit PKCS11_RNG(Session& session);
28
29 std::string name() const override { return "PKCS11_RNG"; }
30
31 /// Always returns true
32 bool is_seeded() const override { return true; }
33
34 /// No operation - always returns 0
35 size_t reseed(Entropy_Sources&, size_t, std::chrono::milliseconds) override { return 0; }
36
37 /// @return the module used by this RNG
38 inline Module& module() const { return m_session.get().module(); }
39
40 // C_SeedRandom may suceed
41 bool accepts_input() const override { return true; }
42
43 private:
44 /// Calls `C_GenerateRandom` to generate random data
45 /// Calls `C_SeedRandom` to add entropy to the random generation function of the token/middleware
46 void fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) override;
47
48 private:
49 const std::reference_wrapper<Session> m_session;
50};
51} // namespace Botan::PKCS11
52
53#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:121
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31