Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
rte_random.c
Go to the documentation of this file.
1
10
14
17{
18 rte_status_t lifecycle_status;
19
20 if (osadapter == NULL)
21 {
23 }
24 /* REQ-LIFECYCLE-001 (ADR-026): registering an OSAdapter is a setup-only action. */
25 lifecycle_status = rte_lifecycle_check_setup_allowed();
26 if (lifecycle_status != RTE_STATUS_OK)
27 {
28 return lifecycle_status;
29 }
30 s_osadapter = osadapter;
31 return RTE_STATUS_OK;
32}
33
34rte_status_t rte_random_fill(uint8_t *out, size_t len)
35{
36 if ((out == NULL) || (len == 0U) || (len > (size_t)RTE_RANDOM_MAX_REQUEST))
37 {
39 }
40 if (s_osadapter == NULL)
41 {
43 }
44 if (s_osadapter->fill == NULL)
45 {
47 }
48 return s_osadapter->fill(out, len);
49}
rte_status_t rte_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
rte_status_t rte_random_fill(uint8_t *out, size_t len)
Fills out with len cryptographically secure random bytes from the registered OSAdapter.
Definition rte_random.c:34
#define RTE_RANDOM_MAX_REQUEST
Largest request rte_random_fill() accepts in one call (bytes).
Definition rte_random.h:29
rte_status_t
Common result/status codes.
Definition rte_status.h:27
@ RTE_STATUS_OK
Definition rte_status.h:28
@ RTE_STATUS_INVALID_PARAM
Definition rte_status.h:29
@ RTE_STATUS_NOT_SUPPORTED
Definition rte_status.h:34
@ RTE_STATUS_NOT_INITIALIZED
Definition rte_status.h:30
static const rte_osadapter_clocksync_t * s_osadapter
Process-wide application setup-phase lock (ADR-026).
OSAdapter interface for cryptographically secure random bytes.
rte_status_t rte_osadapter_random_register(const rte_osadapter_random_t *adapter)
Registers the OSAdapter random implementation.
Definition rte_random.c:16
OS Abstraction Layer - Cryptographically secure random bytes.
OSAdapter random operations vtable.