mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
Add cancelable key generation
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -79,14 +79,19 @@ const uint8_t *random_bytes_get(size_t len) {
|
|||||||
* Random byte iterator
|
* Random byte iterator
|
||||||
*/
|
*/
|
||||||
int random_fill_iterator(void *arg, unsigned char *out, size_t out_len) {
|
int random_fill_iterator(void *arg, unsigned char *out, size_t out_len) {
|
||||||
uint8_t *index_p = (uint8_t *) arg;
|
random_fill_iterator_ctx_t *ctx = (random_fill_iterator_ctx_t *) arg;
|
||||||
uint8_t index = index_p ? *index_p : 0;
|
uint32_t index = ctx ? ctx->index : 0;
|
||||||
uint8_t n;
|
uint8_t n;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (random_mutex_initialized) {
|
if (random_mutex_initialized) {
|
||||||
mutex_enter_blocking(&random_mutex);
|
mutex_enter_blocking(&random_mutex);
|
||||||
}
|
}
|
||||||
while (out_len) {
|
while (out_len) {
|
||||||
|
if (ctx && ctx->cancel) {
|
||||||
|
ret = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
hwrng_wait_full();
|
hwrng_wait_full();
|
||||||
|
|
||||||
n = RANDOM_BYTES_LENGTH - index;
|
n = RANDOM_BYTES_LENGTH - index;
|
||||||
@@ -105,14 +110,14 @@ int random_fill_iterator(void *arg, unsigned char *out, size_t out_len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index_p) {
|
if (ctx) {
|
||||||
*index_p = index;
|
ctx->index = index;
|
||||||
}
|
}
|
||||||
if (random_mutex_initialized) {
|
if (random_mutex_initialized) {
|
||||||
mutex_exit(&random_mutex);
|
mutex_exit(&random_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int random_fill_buffer(uint8_t *buf, size_t n) {
|
int random_fill_buffer(uint8_t *buf, size_t n) {
|
||||||
|
|||||||
@@ -22,7 +22,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
extern void random_init(void);
|
typedef struct {
|
||||||
|
uint32_t index;
|
||||||
|
volatile bool cancel;
|
||||||
|
} random_fill_iterator_ctx_t;
|
||||||
|
|
||||||
|
extern void
|
||||||
|
random_init(void);
|
||||||
|
|
||||||
extern const uint8_t *random_bytes_get(size_t);
|
extern const uint8_t *random_bytes_get(size_t);
|
||||||
extern int random_fill_iterator(void *arg, unsigned char *output, size_t output_len);
|
extern int random_fill_iterator(void *arg, unsigned char *output, size_t output_len);
|
||||||
|
|||||||
2
third-party/mbedtls
vendored
2
third-party/mbedtls
vendored
Submodule third-party/mbedtls updated: 0bebf8b8c7...30fbb3b712
Reference in New Issue
Block a user