diff options
author | Daniel Neus <[email protected]> | 2016-06-17 11:37:18 +0200 |
---|---|---|
committer | Daniel Neus <[email protected]> | 2016-06-17 16:19:40 +0200 |
commit | 2ea6f9b1963795dad74489b41bc7d37f897d7a21 (patch) | |
tree | c9120503521633ee4a25ac2021b392f33d82e8d7 /src/lib/prov/pkcs11/p11_randomgenerator.h | |
parent | 601f8f6d6075ff2f944c11d357f2309da0c4deb1 (diff) |
add PKCS#11 support
Diffstat (limited to 'src/lib/prov/pkcs11/p11_randomgenerator.h')
-rw-r--r-- | src/lib/prov/pkcs11/p11_randomgenerator.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/lib/prov/pkcs11/p11_randomgenerator.h b/src/lib/prov/pkcs11/p11_randomgenerator.h new file mode 100644 index 000000000..84673278d --- /dev/null +++ b/src/lib/prov/pkcs11/p11_randomgenerator.h @@ -0,0 +1,70 @@ +/* +* PKCS#11 Random Generator +* (C) 2016 Daniel Neus, Sirrix AG +* (C) 2016 Philipp Weber, Sirrix AG +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_P11_RNG_H__ +#define BOTAN_P11_RNG_H__ + +#include <botan/rng.h> +#include <botan/p11_session.h> +#include <botan/entropy_src.h> + +#include <string> +#include <functional> + +namespace Botan { +namespace PKCS11 { + +class Module; + +/// A random generator that only fetches random from the PKCS#11 RNG +class BOTAN_DLL PKCS11_RNG final : public RandomNumberGenerator + { + public: + /// Initialize the RNG with the PKCS#11 session that provides access to the cryptoki functions + explicit PKCS11_RNG(Session& session); + + void clear() override + {} + + std::string name() const override + { + return "PKCS11_RNG"; + } + + /// Always returns true + bool is_seeded() const override + { + return true; + } + + /// No operation - always returns 0 + size_t reseed_with_sources(Entropy_Sources&, size_t, std::chrono::milliseconds) override + { + return 0; + } + + /// @return the module used by this RNG + inline Module& module() const + { + return m_session.get().module(); + } + + /// Calls `C_GenerateRandom` to generate random data + void randomize(Botan::byte output[], std::size_t length) override; + + /// Calls `C_SeedRandom` to add entropy to the random generation function of the token/middleware + void add_entropy(const Botan::byte in[], std::size_t length) override; + + private: + const std::reference_wrapper<Session> m_session; + }; +} + +} + +#endif |