rippled
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 #include <string>
25 #include <type_traits>
26 
27 namespace ripple {
28 
38 {
39 private:
41 
42 public:
44 
45  csprng_engine(csprng_engine const&) = delete;
47  operator=(csprng_engine const&) = delete;
48 
49  csprng_engine(csprng_engine&&) = delete;
51  operator=(csprng_engine&&) = delete;
52 
53  csprng_engine();
55 
57  void
58  mix_entropy(void* buffer = nullptr, std::size_t count = 0);
59 
62  operator()();
63 
65  void
66  operator()(void* ptr, std::size_t count);
67 
68  /* The smallest possible value that can be returned */
69  static constexpr result_type
70  min()
71  {
73  }
74 
75  /* The largest possible value that can be returned */
76  static constexpr result_type
77  max()
78  {
80  }
81 };
82 
91 csprng_engine&
92 crypto_prng();
93 
94 } // namespace ripple
95 
96 #endif
ripple::csprng_engine::~csprng_engine
~csprng_engine()
Definition: csprng.cpp:37
ripple::csprng_engine::mix_entropy
void mix_entropy(void *buffer=nullptr, std::size_t count=0)
Mix entropy into the pool.
Definition: csprng.cpp:46
ripple::csprng_engine::mutex_
std::mutex mutex_
Definition: csprng.h:40
ripple::csprng_engine::max
static constexpr result_type max()
Definition: csprng.h:77
ripple::csprng_engine::min
static constexpr result_type min()
Definition: csprng.h:70
ripple::crypto_prng
csprng_engine & crypto_prng()
The default cryptographically secure PRNG.
Definition: csprng.cpp:99
ripple::csprng_engine::operator=
csprng_engine & operator=(csprng_engine const &)=delete
ripple::csprng_engine::result_type
std::uint64_t result_type
Definition: csprng.h:43
ripple::csprng_engine::operator()
result_type operator()()
Generate a random integer.
Definition: csprng.cpp:91
ripple::csprng_engine::csprng_engine
csprng_engine()
Definition: csprng.cpp:30
ripple::csprng_engine
A cryptographically secure random number engine.
Definition: csprng.h:37
std::uint64_t
std::numeric_limits::min
T min(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
mutex
std::size_t
std::numeric_limits::max
T max(T... args)
type_traits
string