Botan 3.7.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/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
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&, size_t, std::chrono::milliseconds) override { return 0; }
35
36 /// @return the module used by this RNG
37 inline Module& module() const { return m_session.get().module(); }
38
39 // C_SeedRandom may suceed
40 bool accepts_input() const override { return true; }
41
42 private:
43 /// Calls `C_GenerateRandom` to generate random data
44 /// Calls `C_SeedRandom` to add entropy to the random generation function of the token/middleware
45 void fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) override;
46
47 private:
48 const std::reference_wrapper<Session> m_session;
49};
50} // namespace Botan::PKCS11
51
52#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
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 *)