From d33b47eb282d6b46378e88df3693caa7ce4f1cce Mon Sep 17 00:00:00 2001 From: Vivien Kraus Date: Wed, 1 Jan 2020 00:00:00 +0100 Subject: Add a random number generator. --- src/random/webid-oidc/random.h | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/random/webid-oidc/random.h (limited to 'src/random/webid-oidc/random.h') diff --git a/src/random/webid-oidc/random.h b/src/random/webid-oidc/random.h new file mode 100644 index 0000000..ae1adfc --- /dev/null +++ b/src/random/webid-oidc/random.h @@ -0,0 +1,57 @@ +#ifndef H_RANDOM_INCLUDED +#define H_RANDOM_INCLUDED + +struct webid_oidc_random_context; +typedef struct webid_oidc_random_context webid_oidc_random_context; + +/* These functions allocate data, they are not reentrant. */ +struct webid_oidc_random_context *webid_oidc_random_context_alloc (void); +void webid_oidc_random_context_free (struct webid_oidc_random_context *ctx); + +enum webid_oidc_random_context_state +{ + WEBID_OIDC_RANDOM_CONTEXT_READY = 0, + WEBID_OIDC_RANDOM_CONTEXT_WAIT_LOCK_FILE, + WEBID_OIDC_RANDOM_CONTEXT_WAIT_FILE_READ, + WEBID_OIDC_RANDOM_CONTEXT_WAIT_FILE_WRITE, + WEBID_OIDC_RANDOM_CONTEXT_WAIT_UNLOCK_FILE +}; + +typedef enum webid_oidc_random_context_state webid_oidc_random_context_state; + +enum webid_oidc_random_context_state +webid_oidc_random_context_get_state (const struct webid_oidc_random_context + *ctx); +int webid_oidc_random_context_get_wait_bytes (const struct + webid_oidc_random_context *ctx, + size_t max, size_t start, + uint8_t * bytes, + size_t *n_bytes); +int webid_oidc_random_context_ok (struct webid_oidc_random_context *ctx); +int webid_oidc_random_context_bytes (struct webid_oidc_random_context *ctx, + size_t n_bytes, const uint8_t * bytes); + +enum webid_oidc_random_context_spawn_flags +{ + WEBID_OIDC_RANDOM_CONTEXT_THREAD_UNSAFE = 1 +}; +typedef enum webid_oidc_random_context_spawn_flags + webid_oidc_random_context_spawn_flags; + +int webid_oidc_random_context_spawn (struct webid_oidc_random_context *parent, + struct webid_oidc_random_context *child, + enum + webid_oidc_random_context_spawn_flags + flags); + +int webid_oidc_random_context_get (struct webid_oidc_random_context *ctx, + size_t request_size, uint8_t * data); + +/* These functions set up and use a global state. Neither are + reentrant. */ +void webid_oidc_random_init (void); + +/* This function is thread-safe. */ +void webid_oidc_random (size_t request_size, uint8_t * data); + +#endif /* not H_RANDOM_INCLUDED */ -- cgit v1.2.3