Adding functions for calling random in core0.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-09-16 00:49:10 +02:00
parent 4c49e59edc
commit 68f43f3cb2
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
4 changed files with 26 additions and 2 deletions

View file

@ -176,6 +176,17 @@ void neug_wait_full(void) { //should be called only on core1
}
}
void neug_wait_full_ext(bool blocking) {
struct rng_rb *rb = &the_ring_buffer;
while (!rb->full) {
if (blocking == true)
sleep_ms(1);
else
neug_task();
}
}
void neug_fini(void) {
neug_get();
}

View file

@ -20,10 +20,14 @@
#define NEUG_PRE_LOOP 32
#include <stdlib.h>
#include "pico/stdlib.h"
void neug_init(uint32_t *buf, uint8_t size);
uint32_t neug_get();
void neug_flush(void);
void neug_wait_full(void);
void neug_wait_full_ext(bool);
void neug_fini(void);
#endif

View file

@ -79,13 +79,13 @@ void random_get_salt(uint8_t *p) {
/*
* Random byte iterator
*/
int random_gen(void *arg, unsigned char *out, size_t out_len) {
int random_gen_ext(void *arg, unsigned char *out, size_t out_len, bool blocking) {
uint8_t *index_p = (uint8_t *)arg;
uint8_t index = index_p ? *index_p : 0;
size_t n;
while (out_len) {
neug_wait_full();
neug_wait_full_ext(blocking);
n = RANDOM_BYTES_LENGTH - index;
if (n > out_len)
@ -107,3 +107,11 @@ int random_gen(void *arg, unsigned char *out, size_t out_len) {
return 0;
}
int random_gen(void *arg, unsigned char *out, size_t out_len) {
return random_gen_ext(arg, out, out_len, true);
}
int random_gen_core0(void *arg, unsigned char *out, size_t out_len) {
return random_gen_ext(arg, out, out_len, false);
}

View file

@ -34,5 +34,6 @@ void random_get_salt (uint8_t *p);
/* iterator returning a byta at a time */
extern int random_gen (void *arg, unsigned char *output, size_t output_len);
extern int random_gen_core0(void *arg, unsigned char *out, size_t out_len);
#endif