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