rippled
Loading...
Searching...
No Matches
csprng.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_CRYPTO_RANDOM_H_INCLUDED
21#define RIPPLE_CRYPTO_RANDOM_H_INCLUDED
22
23#include <mutex>
24
25namespace ripple {
26
36{
37private:
39
40public:
42
43 csprng_engine(csprng_engine const&) = delete;
45 operator=(csprng_engine const&) = delete;
46
50
53
55 void
56 mix_entropy(void* buffer = nullptr, std::size_t count = 0);
57
60 operator()();
61
63 void
64 operator()(void* ptr, std::size_t count);
65
66 /* The smallest possible value that can be returned */
67 static constexpr result_type
72
73 /* The largest possible value that can be returned */
74 static constexpr result_type
79};
80
89csprng_engine&
91
92} // namespace ripple
93
94#endif
A cryptographically secure random number engine.
Definition csprng.h:36
static constexpr result_type min()
Definition csprng.h:68
std::uint64_t result_type
Definition csprng.h:41
csprng_engine(csprng_engine const &)=delete
csprng_engine & operator=(csprng_engine const &)=delete
result_type operator()()
Generate a random integer.
csprng_engine(csprng_engine &&)=delete
std::mutex mutex_
Definition csprng.h:38
csprng_engine & operator=(csprng_engine &&)=delete
void mix_entropy(void *buffer=nullptr, std::size_t count=0)
Mix entropy into the pool.
static constexpr result_type max()
Definition csprng.h:75
T max(T... args)
T min(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
csprng_engine & crypto_prng()
The default cryptographically secure PRNG.