Safe API Framework
0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Toggle main menu visibility
Loading...
Searching...
No Matches
rte_random.c
Go to the documentation of this file.
1
7
#include "
rte/oal/random/rte_random.h
"
8
#include "
rte/utils/lifecycle/rte_lifecycle.h
"
9
#include "
rte_osadapter/random/rte_osadapter_random.h
"
10
13
static
const
rte_osadapter_random_t
*
s_osadapter
= NULL;
14
16
rte_status_t
rte_osadapter_random_register
(
const
rte_osadapter_random_t
*osadapter)
17
{
18
rte_status_t
lifecycle_status;
19
20
if
(osadapter == NULL)
21
{
22
return
RTE_STATUS_INVALID_PARAM
;
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
34
rte_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
{
38
return
RTE_STATUS_INVALID_PARAM
;
39
}
40
if
(
s_osadapter
== NULL)
41
{
42
return
RTE_STATUS_NOT_INITIALIZED
;
43
}
44
if
(
s_osadapter
->fill == NULL)
45
{
46
return
RTE_STATUS_NOT_SUPPORTED
;
47
}
48
return
s_osadapter
->fill(out, len);
49
}
rte_lifecycle_check_setup_allowed
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 ...
Definition
rte_lifecycle.c:41
rte_random_fill
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
RTE_RANDOM_MAX_REQUEST
#define RTE_RANDOM_MAX_REQUEST
Largest request rte_random_fill() accepts in one call (bytes).
Definition
rte_random.h:29
rte_status_t
rte_status_t
Common result/status codes.
Definition
rte_status.h:27
RTE_STATUS_OK
@ RTE_STATUS_OK
Definition
rte_status.h:28
RTE_STATUS_INVALID_PARAM
@ RTE_STATUS_INVALID_PARAM
Definition
rte_status.h:29
RTE_STATUS_NOT_SUPPORTED
@ RTE_STATUS_NOT_SUPPORTED
Definition
rte_status.h:34
RTE_STATUS_NOT_INITIALIZED
@ RTE_STATUS_NOT_INITIALIZED
Definition
rte_status.h:30
s_osadapter
static const rte_osadapter_clocksync_t * s_osadapter
Definition
rte_clocksync.c:18
rte_lifecycle.h
Process-wide application setup-phase lock (ADR-026).
rte_osadapter_random.h
OSAdapter interface for cryptographically secure random bytes.
rte_osadapter_random_register
rte_status_t rte_osadapter_random_register(const rte_osadapter_random_t *adapter)
Registers the OSAdapter random implementation.
Definition
rte_random.c:16
rte_random.h
OS Abstraction Layer - Cryptographically secure random bytes.
rte_osadapter_random_t
OSAdapter random operations vtable.
Definition
rte_osadapter_random.h:26
src
oal
random
rte_random.c
Generated by
1.18.0