2020-01-03 14:36:30 +03:00
|
|
|
#include <Kernel/Devices/RandomDevice.h>
|
|
|
|
#include <Kernel/Random.h>
|
2018-10-15 01:44:54 +03:00
|
|
|
|
|
|
|
RandomDevice::RandomDevice()
|
2018-10-30 15:59:29 +03:00
|
|
|
: CharacterDevice(1, 8)
|
2018-10-15 01:44:54 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RandomDevice::~RandomDevice()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-11-04 16:03:14 +03:00
|
|
|
bool RandomDevice::can_read(const FileDescription&) const
|
2018-10-25 14:07:59 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
ssize_t RandomDevice::read(FileDescription&, u8* buffer, ssize_t size)
|
2018-10-15 01:44:54 +03:00
|
|
|
{
|
2020-01-03 14:36:30 +03:00
|
|
|
get_good_random_bytes(buffer, size);
|
|
|
|
return size;
|
2018-10-15 01:44:54 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
ssize_t RandomDevice::write(FileDescription&, const u8*, ssize_t size)
|
2018-10-15 01:44:54 +03:00
|
|
|
{
|
|
|
|
// FIXME: Use input for entropy? I guess that could be a neat feature?
|
2019-04-03 14:18:42 +03:00
|
|
|
return min(PAGE_SIZE, size);
|
2018-10-15 01:44:54 +03:00
|
|
|
}
|