Security Scol plugin
darn.h
Go to the documentation of this file.
1// darn.h - written and placed in public domain by Jeffrey Walton
2// DARN requires POWER9/ISA 3.0.
3
4// At the moment only GCC 7.0 (and above) seems to support __builtin_darn()
5// and __builtin_darn_32(). However, GCC generates incorrect code. Clang 7.0
6// does not provide them, but it does support assembly instructions. XLC is
7// unknown, but there are no hits when searching IBM's site. To cover more
8// platforms we provide GCC inline assembly like we do with RDRAND and RDSEED.
9// Platforms that don't support GCC inline assembly or the builtin will fail
10// to compile. Also see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91481 and
11// https://gcc.gnu.org/onlinedocs/gcc/Basic-PowerPC-Built-in-Functions-Available-on-ISA-3_002e0.html
12
18
19#ifndef CRYPTOPP_DARN_H
20#define CRYPTOPP_DARN_H
21
22#include "cryptlib.h"
23
24NAMESPACE_BEGIN(CryptoPP)
25
26
29class DARN_Err : public Exception
30{
31public:
32 DARN_Err(const std::string &operation)
33 : Exception(OTHER_ERROR, "DARN: " + operation + " operation failed") {}
34};
35
53{
54public:
55 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "DARN"; }
56
57 virtual ~DARN() {}
58
61 DARN();
62
66 virtual void GenerateBlock(byte *output, size_t size);
67
73 virtual void DiscardBytes(size_t n);
74
79 virtual void IncorporateEntropy(const byte *input, size_t length)
80 {
81 // Override to avoid the base class' throw.
82 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
83 }
84
85 std::string AlgorithmProvider() const {
86 return "Power9";
87 }
88
89private:
91};
92
93NAMESPACE_END
94
95#endif // CRYPTOPP_DARN_H
Exception thrown when a DARN generator encounters a generator related error.
Definition darn.h:30
Hardware generated random numbers using DARN instruction.
Definition darn.h:53
DARN()
Construct a DARN generator.
Definition darn.cpp:217
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Definition darn.cpp:228
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition darn.h:85
virtual void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
Definition darn.h:79
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Definition darn.cpp:222
Base class for all exceptions thrown by the library.
Definition cryptlib.h:159
Interface for random number generators.
Definition cryptlib.h:1435
Secure memory block with allocator and cleanup.
Definition secblock.h:731
Abstract base classes that provide a uniform interface to this library.