Commit 056a68ce authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Thomas Bogendoerfer

mips: allow firmware to pass RNG seed to kernel

Nearly all other firmware environments have some way of passing a RNG
seed to initialize the RNG: DTB's rng-seed, EFI's RNG protocol, m68k's
bootinfo block, x86's setup_data, and so forth. This adds something
similar for MIPS, which will allow various firmware environments,
bootloaders, and hypervisors to pass an RNG seed to initialize the
kernel's RNG.
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
parent 8e6ec6ce
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <asm/setup.h> #include <asm/setup.h>
#include <asm/smp-ops.h> #include <asm/smp-ops.h>
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/fw/fw.h>
#ifdef CONFIG_MIPS_ELF_APPENDED_DTB #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
char __section(".appended_dtb") __appended_dtb[0x100000]; char __section(".appended_dtb") __appended_dtb[0x100000];
...@@ -756,6 +757,24 @@ static void __init prefill_possible_map(void) ...@@ -756,6 +757,24 @@ static void __init prefill_possible_map(void)
static inline void prefill_possible_map(void) {} static inline void prefill_possible_map(void) {}
#endif #endif
static void __init setup_rng_seed(void)
{
char *rng_seed_hex = fw_getenv("rngseed");
u8 rng_seed[512];
size_t len;
if (!rng_seed_hex)
return;
len = min(sizeof(rng_seed), strlen(rng_seed_hex) / 2);
if (hex2bin(rng_seed, rng_seed_hex, len))
return;
add_bootloader_randomness(rng_seed, len);
memzero_explicit(rng_seed, len);
memzero_explicit(rng_seed_hex, len * 2);
}
void __init setup_arch(char **cmdline_p) void __init setup_arch(char **cmdline_p)
{ {
cpu_probe(); cpu_probe();
...@@ -786,6 +805,8 @@ void __init setup_arch(char **cmdline_p) ...@@ -786,6 +805,8 @@ void __init setup_arch(char **cmdline_p)
paging_init(); paging_init();
memblock_dump_all(); memblock_dump_all();
setup_rng_seed();
} }
unsigned long kernelsp[NR_CPUS]; unsigned long kernelsp[NR_CPUS];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment