aboutsummaryrefslogtreecommitdiff
path: root/src/random.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* | Use hardware timestamps in RNG seedingPieter Wuille2017-05-051-7/+15
|/
* Merge #9792: FastRandomContext improvements and switch to ChaCha20Wladimir J. van der Laan2017-04-241-15/+18
|\ | | | | | | | | | | | | | | | | | | 4fd2d2f Add a FastRandomContext::randrange and use it (Pieter Wuille) 1632922 Switch FastRandomContext to ChaCha20 (Pieter Wuille) e04326f Add ChaCha20 (Pieter Wuille) 663fbae FastRandom benchmark (Pieter Wuille) c21cbe6 Introduce FastRandomContext::randbool() (Pieter Wuille) Tree-SHA512: 7fff61e3f6d6dc6ac846ca643d877b377db609646dd401a0e8f50b052c6b9bcd2f5fc34de6bbf28f04afd1724f6279ee163ead5f37d724fb782a00239f35db1d
| * Switch FastRandomContext to ChaCha20Pieter Wuille2017-03-291-15/+18
| |
* | Change LogAcceptCategory to use uint32_t rather than sets of strings.Gregory Maxwell2017-04-011-1/+1
|/ | | | | | | | | | | | | | | | | This changes the logging categories to boolean flags instead of strings. This simplifies the acceptance testing by avoiding accessing a scoped static thread local pointer to a thread local set of strings. It eliminates the only use of boost::thread_specific_ptr outside of lockorder debugging. This change allows log entries to be directed to multiple categories and makes it easy to change the logging flags at runtime (e.g. via an RPC, though that isn't done by this commit.) It also eliminates the fDebug global. Configuration of unknown logging categories now produces a warning.
* random: Add fallback if getrandom syscall not availableWladimir J. van der Laan2017-02-221-15/+34
| | | | | | If the code was compiled with newer (>=3.17) kernel headers but executed on a system without the system call, every use of random would crash the program. Add a fallback for that case.
* sanity: Move OS random to sanity check functionWladimir J. van der Laan2017-02-221-0/+30
| | | | | | | | Move the OS random test to a sanity check function that is called every time bitcoind is initialized. Keep `src/test/random_tests.cpp` for the case that later random tests are added, and keep a rudimentary test that just calls the sanity check.
* util: Specific GetOSRandom for Linux/FreeBSD/OpenBSDWladimir J. van der Laan2017-02-211-6/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are available in sandboxes without access to files or devices. Also [they are safer and more straightforward](https://en.wikipedia.org/wiki/Entropy-supplying_system_calls) to use than `/dev/urandom` as reading from a file has quite a few edge cases: - Linux: `getrandom(buf, buflen, 0)`. [getrandom(2)](http://man7.org/linux/man-pages/man2/getrandom.2.html) was introduced in version 3.17 of the Linux kernel. - OpenBSD: `getentropy(buf, buflen)`. The [getentropy(2)](http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2) function appeared in OpenBSD 5.6. - FreeBSD and NetBSD: `sysctl(KERN_ARND)`. Not sure when this was added but it has existed for quite a while. Alternatives: - Linux has sysctl `CTL_KERN` / `KERN_RANDOM` / `RANDOM_UUID` which gives 16 bytes of randomness. This may be available on older kernels, however [sysctl is deprecated on Linux](https://lwn.net/Articles/605392/) and even removed in some distros so we shouldn't use it. Add tests for `GetOSRand()`: - Test that no error happens (otherwise `RandFailure()` which aborts) - Test that all 32 bytes are overwritten (initialize with zeros, try multiple times) Discussion: - When to use these? Currently they are always used when available. Another option would be to use them only when `/dev/urandom` is not available. But this would mean these code paths receive less testing, and I'm not sure there is any reason to prefer `/dev/urandom`. Closes: #9676
* Increment MIT Licence copyright header year on files modified in 2016isle29832016-12-311-1/+1
| | | | | | Edited via: $ contrib/devtools/copyright_header.py update .
* Refactor: Removed begin/end_ptr functions.Karl-Johan Alm2016-12-091-4/+3
|
* Kill insecure_random and associated global stateWladimir J. van der Laan2016-10-171-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are only a few uses of `insecure_random` outside the tests. This PR replaces uses of insecure_random (and its accompanying global state) in the core code with an FastRandomContext that is automatically seeded on creation. This is meant to be used for inner loops. The FastRandomContext can be in the outer scope, or the class itself, then rand32() is used inside the loop. Useful e.g. for pushing addresses in CNode or the fee rounding, or randomization for coin selection. As a context is created per purpose, thus it gets rid of cross-thread unprotected shared usage of a single set of globals, this should also get rid of the potential race conditions. - I'd say TxMempool::check is not called enough to warrant using a special fast random context, this is switched to GetRand() (open for discussion...) - The use of `insecure_rand` in ConnectThroughProxy has been replaced by an atomic integer counter. The only goal here is to have a different credentials pair for each connection to go on a different Tor circuit, it does not need to be random nor unpredictable. - To avoid having a FastRandomContext on every CNode, the context is passed into PushAddress as appropriate. There remains an insecure_random for test usage in `test_random.h`.
* Don't use assert for catching randomness failuresPieter Wuille2016-05-291-6/+20
|
* Always require OS randomness when generating secret keysPieter Wuille2016-05-291-1/+47
|
* Bump copyright headers to 2015MarcoFalke2015-12-131-1/+1
|
* WIN32 Seed Cleanup: Move nLastPerfmon behind win32 ifdef.21E142015-02-251-3/+4
| | | | | Code to avoid calling Perfmon too often is only needed when perfmon is actually going to get called. This is not intended to make any functional difference in the addition of entropy to the random pool.
* openssl: abstract out OPENSSL_cleanseCory Fields2015-02-151-3/+3
| | | | | | This makes it easier for us to replace it if desired, since it's now only in one spot. Also, it avoids the openssl include from allocators.h, which essentially forced openssl to be included from every compilation unit.
* Added "Core" to copyright headerssandakersmann2014-12-191-1/+1
| | | | | Github-Pull: #5494 Rebased-From: 15de949bb9277e442302bdd8dee299a8d6deee60
* Remove references to X11 licenceMichael Ford2014-12-161-1/+1
|
* Make sure that GetRandomBytes never failsWladimir J. van der Laan2014-11-071-3/+2
| | | | | | | | | We're using GetRandomBytes in several contexts where it's either unwieldy to return an error, or an error would mean a fatal exception anyhow. @gmaxwell checked OpenSSL a while ago and discovered that it never actually fails, but it can't hurt to be a bit paranoid here.
* Apply clang-format on some infrequently-updated filesPieter Wuille2014-09-191-16/+12
|
* header include cleanupPhilip Kaufmann2014-09-141-1/+3
| | | | - ensures alphabetical ordering for includes etc. in source file headers
* Split up util.cpp/hWladimir J. van der Laan2014-08-261-1/+3
| | | | | | | | | | | | | | | | Split up util.cpp/h into: - string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach) - money utilities (parsesmoney, formatmoney) - time utilities (gettime*, sleep, format date): - and the rest (logging, argument parsing, config file parsing) The latter is basically the environment and OS handling, and is stripped of all utility functions, so we may want to rename it to something else than util.cpp/h for clarity (Matt suggested osinterface). Breaks dependency of sha256.cpp on all the things pulled in by util.
* make RandAddSeed() use OPENSSL_cleanse()Philip Kaufmann2014-07-091-2/+1
| | | | - removes the cstring include and is also used in RandAddSeedPerfmon()
* move rand functions from util to new random.h/.cppPhilip Kaufmann2014-07-091-0/+140