Security Scol plugin
padlkrng.h
Go to the documentation of this file.
1// via-rng.h - written and placed in public domain by Jeffrey Walton
2
8
9#ifndef CRYPTOPP_PADLOCK_RNG_H
10#define CRYPTOPP_PADLOCK_RNG_H
11
12#include "cryptlib.h"
13#include "secblock.h"
14
15NAMESPACE_BEGIN(CryptoPP)
16
17
21{
22public:
23 PadlockRNG_Err(const std::string &operation)
24 : Exception(OTHER_ERROR, "PadlockRNG: " + operation + " operation failed") {}
25 PadlockRNG_Err(const std::string &component, const std::string &message)
26 : Exception(OTHER_ERROR, component + ": " + message) {}
27};
28
51{
52public:
53 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "PadlockRNG"; }
54
55 virtual ~PadlockRNG() {}
56
75 PadlockRNG(word32 divisor=1);
76
80 virtual void GenerateBlock(byte *output, size_t size);
81
87 virtual void DiscardBytes(size_t n);
88
93 virtual void IncorporateEntropy(const byte *input, size_t length)
94 {
95 // Override to avoid the base class' throw.
96 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
97 }
98
99 std::string AlgorithmProvider() const;
100
105 {
106 word32 old = m_divisor;
107 m_divisor = DivisorHelper(divisor);
108 return old;
109 }
110
114 {
115 return m_divisor;
116 }
117
121 {
122 return m_msr;
123 }
124
125protected:
126 inline word32 DivisorHelper(word32 divisor)
127 {
128 return divisor > 3 ? 3 : divisor;
129 }
130
131private:
133 word32 m_divisor, m_msr;
134};
135
136NAMESPACE_END
137
138#endif // CRYPTOPP_PADLOCK_RNG_H
Base class for all exceptions thrown by the library.
Definition cryptlib.h:159
Fixed size stack-based SecBlock with 16-byte alignment.
Definition secblock.h:1259
Exception thrown when a PadlockRNG generator encounters a generator related error.
Definition padlkrng.h:21
Hardware generated random numbers using VIA XSTORE.
Definition padlkrng.h:51
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Definition padlkrng.cpp:91
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Definition padlkrng.cpp:34
word32 GetMSR() const
Get the MSR for the last operation.
Definition padlkrng.h:120
word32 GetDivisor() const
Get the XSTORE divisor.
Definition padlkrng.h:113
virtual void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
Definition padlkrng.h:93
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition padlkrng.cpp:20
word32 SetDivisor(word32 divisor)
Set the XSTORE divisor.
Definition padlkrng.h:104
Interface for random number generators.
Definition cryptlib.h:1435
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:62
Abstract base classes that provide a uniform interface to this library.
Classes and functions for secure memory allocations.