summaryrefslogtreecommitdiff
path: root/Kernel/Random.h
AgeCommit message (Collapse)Author
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-21Kernel::CPU: Move headers into common directoryHendiadyoin1
Alot of code is shared between i386/i686/x86 and x86_64 and a lot probably will be used for compatability modes. So we start by moving the headers into one Directory. We will probalby be able to move some cpp files aswell.
2021-03-02Kernel: Make clang(?) happy about templates(?)Ben Wiederhake
This caused some issues with QtCreator, and since it's not wrong and improves readability very slightly, I adopt it.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-05Kernel: Don't left-shift 1 (signed) 31 timesAndreas Kling
Found by KUBSAN :^)
2021-01-28Kernel: Make KernelRng thread-safeTom
This adds an optional argument to get_good_random_bytes that can be used to only return randomness if it doesn't have to block. Also add a SpinLock around using FortunaPRNG. Fixes #5132
2021-01-24Kernel: Make use of interrupts as an entropy sourceJean-Baptiste Boric
Booting old computers without RDRAND/RDSEED and without a disk makes the system severely starved for entropy. Uses interrupts as a source to side-step that issue. Also warn whenever the system is starved of entropy, because that's a non-obvious failure mode.
2020-12-27Kernel: Tag more methods and types as [[nodiscard]]Brian Gianforcaro
Tag methods at where not obvserving the return value is an obvious error with [[nodiscard]] to catch potential future bugs.
2020-11-29LibCrypto: Require intent parameter in CTR constructorLuke
This was preventing clang from building.
2020-08-25Kernel: Switch singletons to use new Singleton classTom
MemoryManager cannot use the Singleton class because MemoryManager::initialize is called before the global constructors are run. That caused the Singleton to be re-initialized, causing it to create another MemoryManager instance. Fixes #3226
2020-08-22Revert "Kernel: Switch singletons to use new Singleton class"Andreas Kling
This reverts commit f48feae0b2a300992479abf0b2ded85e45ac6045.
2020-08-21Kernel: Switch singletons to use new Singleton classTom
Fixes #3226
2020-08-15AK: Rename span() to bytes() when appropriate.asynts
I originally defined the bytes() method for the String class, because it made it obvious that it's a span of bytes instead of span of characters. This commit makes this more consistent by defining a bytes() method when the type of the span is known to be u8. Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and such.
2020-08-13Kernel: Fix rng regression from bc7a149039Nico Weber
2020-08-11LibCrypto+LibTLS+Kernel: Switch the Cipher::Mode interface to use SpanAnotherTest
This shaves 2.5 more runtime seconds off 'disasm /bin/id', and makes the Mode<T> interface a lot more allocation-friendly.
2020-06-27Kernel: Make Random work on CPUs without rdrandPeter Elliott
- If rdseed is not available, fallback to rdrand. - If rdrand is not available, block for entropy, or use insecure prng depending on if user wants fast or good random.
2020-06-25Kernel: Harvest randomness from various driversPeter Elliott
Random now gets entropy from the following drivers: - KeyboardDevice - PATAChannel - PS2MouseDevice - E1000NetworkAdapter - RTL8139NetworkAdapter Of these devices, PS2MouseDevice and PATAChannel provide the vast majority of the entropy.
2020-06-25LibCrypto: Add CTR cipher modePeter Elliott
Kernel: Changed fortuna implementation to use CTR mode instead of manually implementing a counter.
2020-06-25Kernel: Replace existing random implementation with FortunaPeter Elliott
2020-06-25Kernel: Implement the Fortuna PRNG algorithmPeter Elliott
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-03Kernel: Add a more expressive API for getting random bytesAndreas Kling
We now have these API's in <Kernel/Random.h>: - get_fast_random_bytes(u8* buffer, size_t buffer_size) - get_good_random_bytes(u8* buffer, size_t buffer_size) - get_fast_random<T>() - get_good_random<T>() Internally they both use x86 RDRAND if available, otherwise they fall back to the same LCG we had in RandomDevice all along. The main purpose of this patch is to give kernel code a way to better express its needs for random data. Randomness is something that will require a lot more work, but this is hopefully a step in the right direction.