Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/random/other_algorithm.c
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
#include <dev/random/uint128.h> | #include <dev/random/uint128.h> | ||||
#include <dev/random/other_algorithm.h> | #include <dev/random/other_algorithm.h> | ||||
#endif /* _KERNEL */ | #endif /* _KERNEL */ | ||||
static void random_other_pre_read(void); | static void random_other_pre_read(void); | ||||
static void random_other_read(uint8_t *, size_t); | static void random_other_read(uint8_t *, size_t); | ||||
static bool random_other_seeded(void); | static bool random_other_seeded(void); | ||||
static void random_other_process_event(struct harvest_event *); | static void random_other_process_event(struct harvest_event *); | ||||
static void random_other_init_alg(void *); | |||||
static void random_other_deinit_alg(void *); | |||||
/* | /* | ||||
* RANDOM_OTHER_NPOOLS is used when reading hardware random | * RANDOM_OTHER_NPOOLS is used when reading hardware random | ||||
* number sources to ensure that each pool gets one read sample | * number sources to ensure that each pool gets one read sample | ||||
* per loop iteration. Fortuna has 32 (0-31). | * per loop iteration. Fortuna has 32 (0-31). | ||||
*/ | */ | ||||
#define RANDOM_OTHER_NPOOLS 1 | #define RANDOM_OTHER_NPOOLS 1 | ||||
struct random_algorithm random_alg_context = { | #ifdef RANDOM_LOADABLE | ||||
static | |||||
#endif | |||||
const struct random_algorithm random_alg_context = { | |||||
.ra_ident = "other", | .ra_ident = "other", | ||||
.ra_init_alg = random_other_init_alg, | |||||
.ra_deinit_alg = random_other_deinit_alg, | |||||
.ra_pre_read = random_other_pre_read, | .ra_pre_read = random_other_pre_read, | ||||
.ra_read = random_other_read, | .ra_read = random_other_read, | ||||
.ra_seeded = random_other_seeded, | .ra_seeded = random_other_seeded, | ||||
.ra_event_processor = random_other_process_event, | .ra_event_processor = random_other_process_event, | ||||
.ra_poolcount = RANDOM_OTHER_NPOOLS, | .ra_poolcount = RANDOM_OTHER_NPOOLS, | ||||
}; | }; | ||||
/* Use a mutex to protect your reseed variables? */ | /* Use a mutex to protect your reseed variables? */ | ||||
static mtx_t other_mtx; | static mtx_t other_mtx; | ||||
/* | /* | ||||
* void random_other_init_alg(void *unused __unused) | * void random_other_init_alg(void *unused __unused) | ||||
gordon: Tiny nit. Update the comment to match the new function declaration. | |||||
cemAuthorUnsubmitted Done Inline Actionsstatic? Maybe just remove the comment entirely since it purely duplicates the code? cem: `static`? Maybe just remove the comment entirely since it purely duplicates the code? | |||||
* | * | ||||
* Do algorithm-specific initialisation here. | * Do algorithm-specific initialisation here. | ||||
*/ | */ | ||||
void | static void | ||||
random_other_init_alg(void *unused __unused) | random_other_init_alg(void *unused __unused) | ||||
{ | { | ||||
#ifdef RANDOM_LOADABLE | |||||
p_random_alg_context = &random_alg_context; | |||||
#endif | |||||
RANDOM_RESEED_INIT_LOCK(); | RANDOM_RESEED_INIT_LOCK(); | ||||
/* | /* | ||||
* Do set-up work here! | * Do set-up work here! | ||||
*/ | */ | ||||
} | } | ||||
SYSINIT(random_alg, SI_SUB_RANDOM, SI_ORDER_SECOND, random_other_init_alg, | |||||
/* | NULL); | ||||
* void random_other_deinit_alg(void *unused __unused) | |||||
* | |||||
* Do algorithm-specific deinitialisation here. | |||||
*/ | |||||
static void | |||||
random_other_deinit_alg(void *unused __unused) | |||||
{ | |||||
/* | |||||
* Do tear-down work here! | |||||
*/ | |||||
RANDOM_RESEED_DEINIT_LOCK(); | |||||
} | |||||
/* | /* | ||||
* void random_other_pre_read(void) | * void random_other_pre_read(void) | ||||
* | * | ||||
* Do any pre-read preparation you need to. This will be called | * Do any pre-read preparation you need to. This will be called | ||||
* before >=1 calls to random_other_read() corresponding to one | * before >=1 calls to random_other_read() corresponding to one | ||||
* read(2). | * read(2). | ||||
* | * | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
Tiny nit. Update the comment to match the new function declaration.