Do not break backward compatibility during wallet encryption
[bitcoinplatinum.git] / src / random.h
blob0464bdce147f1274e6335f9e492dd00ec646b109
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_RANDOM_H
7 #define BITCOIN_RANDOM_H
9 #include "uint256.h"
11 #include <stdint.h>
13 /* Seed OpenSSL PRNG with additional entropy data */
14 void RandAddSeed();
16 /**
17 * Functions to gather random data via the OpenSSL PRNG
19 void GetRandBytes(unsigned char* buf, int num);
20 uint64_t GetRand(uint64_t nMax);
21 int GetRandInt(int nMax);
22 uint256 GetRandHash();
24 /**
25 * Function to gather random data from multiple sources, failing whenever any
26 * of those source fail to provide a result.
28 void GetStrongRandBytes(unsigned char* buf, int num);
30 /**
31 * Fast randomness source. This is seeded once with secure random data, but
32 * is completely deterministic and insecure after that.
33 * This class is not thread-safe.
35 class FastRandomContext {
36 public:
37 explicit FastRandomContext(bool fDeterministic=false);
39 uint32_t rand32() {
40 Rz = 36969 * (Rz & 65535) + (Rz >> 16);
41 Rw = 18000 * (Rw & 65535) + (Rw >> 16);
42 return (Rw << 16) + Rz;
45 uint32_t Rz;
46 uint32_t Rw;
49 /* Number of random bytes returned by GetOSRand.
50 * When changing this constant make sure to change all call sites, and make
51 * sure that the underlying OS APIs for all platforms support the number.
52 * (many cap out at 256 bytes).
54 static const ssize_t NUM_OS_RANDOM_BYTES = 32;
56 /** Get 32 bytes of system entropy. Do not use this in application code: use
57 * GetStrongRandBytes instead.
59 void GetOSRand(unsigned char *ent32);
61 /** Check that OS randomness is available and returning the requested number
62 * of bytes.
64 bool Random_SanityCheck();
66 #endif // BITCOIN_RANDOM_H