1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:47:45 +00:00

Kernel: Harvest randomness from various drivers

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.
This commit is contained in:
Peter Elliott 2020-06-24 14:07:28 -06:00 committed by Andreas Kling
parent 2e8cfe5435
commit af0b2d1d86
12 changed files with 71 additions and 7 deletions

View file

@ -287,6 +287,8 @@ void KeyboardDevice::handle_irq(const RegisterState&)
u8 ch = raw & 0x7f;
bool pressed = !(raw & 0x80);
m_entropy_source.add_random_event(raw);
if (raw == 0xe0) {
m_has_e0_prefix = true;
return;

View file

@ -32,6 +32,7 @@
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/KeyCode.h>
#include <Kernel/Random.h>
#include <LibKeyboard/CharacterMap.h>
namespace Kernel {
@ -82,6 +83,7 @@ private:
bool m_caps_lock_on { false };
bool m_num_lock_on { false };
bool m_has_e0_prefix { false };
EntropySource m_entropy_source;
Keyboard::CharacterMap m_character_map = Keyboard::CharacterMap("en");
};

View file

@ -29,9 +29,9 @@
#include <Kernel/Devices/PATAChannel.h>
#include <Kernel/Devices/PATADiskDevice.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/IO.h>
#include <Kernel/Process.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/IO.h>
namespace Kernel {
@ -186,6 +186,9 @@ void PATAChannel::handle_irq(const RegisterState&)
// FIXME: We might get random interrupts due to malfunctioning hardware, so we should check that we actually requested something to happen.
u8 status = m_io_base.offset(ATA_REG_STATUS).in<u8>();
m_entropy_source.add_random_event(status);
if (status & ATA_SR_ERR) {
print_ide_status(status);
m_device_error = m_io_base.offset(ATA_REG_ERROR).in<u8>();

View file

@ -44,6 +44,7 @@
#include <Kernel/PCI/Access.h>
#include <Kernel/PCI/Device.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/Random.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/WaitQueue.h>
@ -103,6 +104,7 @@ private:
RefPtr<PhysicalPage> m_dma_buffer_page;
IOAddress m_bus_master_base;
Lockable<bool> m_dma_enabled;
EntropySource m_entropy_source;
RefPtr<PATADiskDevice> m_master;
RefPtr<PATADiskDevice> m_slave;

View file

@ -81,6 +81,7 @@ void PS2MouseDevice::handle_irq(const RegisterState&)
if (backdoor->vmmouse_is_absolute()) {
IO::in8(I8042_BUFFER);
auto packet = backdoor->receive_mouse_packet();
m_entropy_source.add_random_event(packet);
if (packet.has_value())
m_queue.enqueue(packet.value());
return;
@ -99,6 +100,8 @@ void PS2MouseDevice::handle_irq(const RegisterState&)
#ifdef PS2MOUSE_DEBUG
dbg() << "PS2Mouse: " << m_data[1] << ", " << m_data[2] << " " << ((m_data[0] & 1) ? "Left" : "") << " " << ((m_data[0] & 2) ? "Right" : "") << " (buffered: " << m_queue.size() << ")";
#endif
m_entropy_source.add_random_event(*(u32*)m_data);
parse_data_packet();
};

View file

@ -30,6 +30,7 @@
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/MousePacket.h>
#include <Kernel/Random.h>
namespace Kernel {
@ -77,6 +78,7 @@ private:
u8 m_data[4];
bool m_has_wheel { false };
bool m_has_five_buttons { false };
EntropySource m_entropy_source;
};
}