Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pseudo Random number generation update #269

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/arch/riscv/32/i/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <lock/lock.h>
#include <visor/workers.h>
#include <interrupt.h>
#include <rand.h>

static void arch_vcall_handler()
{
Expand Down Expand Up @@ -160,3 +161,14 @@ _WEAK void arch_unhandled_irq()
while(1)
arch_wfi();
}

/**
* arch_rseed_capture
*
* @brief This function is intended to capture unique seed value
*/
void arch_rseed_capture()
{
extern uintptr_t *_bss_start;
srand(*_bss_start);
}
1 change: 1 addition & 0 deletions src/arch/riscv/32/i/terravisor/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ static inline void arch_dmb()
bool arch_suspended_state_was(cpu_sleep_t);
void arch_signal_suspend(cpu_sleep_t);
void arch_signal_resume(void);
void arch_rseed_capture();
5 changes: 4 additions & 1 deletion src/arch/riscv/32/i/terravisor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ void _NAKED init()
{
arch_di();
asm volatile("la tp, _tls_start");
#if USE_PRNG
/* Capture unique seed value before memory initialization */
arch_rseed_capture();
#endif
/* Boot framework */

#if CCSMP == 0
engine();
#else
Expand Down
10 changes: 8 additions & 2 deletions src/platform/sifive/common_fe310/platform/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdint.h>
#include <status.h>
#include <stdlib.h>
#include <rand.h>
#include <arch.h>
#include <driver.h>
#include <syslog.h>
Expand All @@ -20,15 +21,21 @@
#include <visor/workers.h>
#include <platform.h>


void platform_early_setup()
{
status_t ret = success;

#if USE_PRNG
unsigned int temp_randomnumber = rand();
#endif
ret |= platform_copy_data();
ret |= platform_copy_itim();
ret |= platform_bss_clear();
ret |= platform_init_heap();
ret |= platform_resources_setup();
#if USE_PRNG
srand(temp_randomnumber);
#endif
syslog_stdout_disable();
driver_setup("mslog");

Expand Down Expand Up @@ -110,4 +117,3 @@ void platform_cpu_setup()
arch_ei();
return;
}

8 changes: 8 additions & 0 deletions src/platform/sifive/fe310g002-bl/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ $(eval $(call add_define,BOOTLOADER))
USE_TIMER ?= 0
$(eval $(call add_define,USE_TIMER))
#======================================================================

#======================================================================
# Bootloader
# \ PRNG: Use upgraded PRNG
#======================================================================
USE_PRNG ?= 0
$(eval $(call add_define,USE_PRNG))
#======================================================================
#======================================================================
7 changes: 7 additions & 0 deletions src/platform/sifive/fe310g002/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ $(eval $(call add_define,PRCI_CLK))
USE_TIMER ?= 1
$(eval $(call add_define,USE_TIMER))
#======================================================================

#======================================================================
# PRNG: Use upgraded prng
#======================================================================
USE_PRNG ?= 1
$(eval $(call add_define,USE_PRNG))
#======================================================================
2 changes: 2 additions & 0 deletions src/platform/sifive/qemu-sifive-e-bl/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ $(eval $(call add_define,PRCI_CLK))
# Bootload Configuration
#======================================================================
USE_TIMER ?= 0
USE_PRNG := 0
$(eval $(call add_define,USE_TIMER))
$(eval $(call add_define,USE_PRNG))
$(eval $(call add_define,BOOTLOADER))
#======================================================================
7 changes: 7 additions & 0 deletions src/platform/sifive/qemu-sifive-e/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ $(eval $(call add_define,PRCI_CLK))
USE_TIMER ?= 1
$(eval $(call add_define,USE_TIMER))
#======================================================================

#======================================================================
# PRNG: Use upgraded prng
#======================================================================
USE_PRNG ?= 1
$(eval $(call add_define,USE_PRNG))
#======================================================================
Loading