diff options
author | Vivien Kraus <vivien@planete-kraus.eu> | 2020-01-01 00:00:00 +0100 |
---|---|---|
committer | Vivien Kraus <vivien@planete-kraus.eu> | 2021-05-11 00:14:27 +0200 |
commit | d33b47eb282d6b46378e88df3693caa7ce4f1cce (patch) | |
tree | bb36ca3a8975ca2985b063a2971e59cc4cbf0a5c /src/random/webid-oidc/random.h | |
parent | b021d3c7188a5705a858144c0bdd8e6a962fc677 (diff) |
Add a random number generator.
Diffstat (limited to 'src/random/webid-oidc/random.h')
-rw-r--r-- | src/random/webid-oidc/random.h | 57 |
1 files changed, 57 insertions, 0 deletions
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 */ |