mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:42:43 +00:00 
			
		
		
		
	 9026598999
			
		
	
	
		9026598999
		
	
	
	
	
		
			
			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.
		
	
			
		
			
				
	
	
		
			18 lines
		
	
	
	
		
			588 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
	
		
			588 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include "CharacterDevice.h"
 | |
| 
 | |
| class RandomDevice final : public CharacterDevice {
 | |
|     AK_MAKE_ETERNAL
 | |
| public:
 | |
|     RandomDevice();
 | |
|     virtual ~RandomDevice() override;
 | |
| 
 | |
| private:
 | |
|     // ^CharacterDevice
 | |
|     virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
 | |
|     virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
 | |
|     virtual bool can_read(const FileDescription&) const override;
 | |
|     virtual bool can_write(const FileDescription&) const override { return true; }
 | |
|     virtual const char* class_name() const override { return "RandomDevice"; }
 | |
| };
 |