iPXE
rbg.c File Reference

RBG mechanism. More...

#include <stdint.h>
#include <string.h>
#include <ipxe/init.h>
#include <ipxe/settings.h>
#include <ipxe/uuid.h>
#include <ipxe/crypto.h>
#include <ipxe/drbg.h>
#include <ipxe/rbg.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int rbg_startup (void)
 Start up RBG.
int rbg_generate (const void *additional, size_t additional_len, int prediction_resist, void *data, size_t len)
 Generate bits using RBG.
static void rbg_shutdown (void)
 Shut down RBG.
static void rbg_startup_fn (void)
 RBG startup function.
static void rbg_shutdown_fn (int booting __unused)
 RBG shutdown function.
struct startup_fn startup_rbg __startup_fn (STARTUP_NORMAL)
 RBG startup table entry.

Variables

struct random_bit_generator rbg
 The RBG.

Detailed Description

RBG mechanism.

This mechanism is designed to comply with ANS X9.82 Part 4 (April 2011 Draft) Section 10. This standard is unfortunately not freely available.

The chosen RBG design is that of a DRBG with a live entropy source with no conditioning function. Only a single security strength is supported. No seedfile is used since there may be no non-volatile storage available. The system UUID is used as the personalisation string.

Definition in file rbg.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ rbg_startup()

int rbg_startup ( void )
static

Start up RBG.

Return values
rcReturn status code

This is the RBG_Startup function defined in ANS X9.82 Part 4 (April 2011 Draft) Section 9.1.2.2.

Definition at line 74 of file rbg.c.

74 {
75 union uuid uuid;
76 int len;
77 int rc;
78
79 /* Record that startup has been attempted (even if unsuccessful) */
80 rbg.started = 1;
81
82 /* Try to obtain system UUID for use as personalisation
83 * string, in accordance with ANS X9.82 Part 3-2007 Section
84 * 8.5.2. If no UUID is available, proceed without a
85 * personalisation string.
86 */
87 if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) {
88 rc = len;
89 DBGC ( &rbg, "RBG could not fetch personalisation string: "
90 "%s\n", strerror ( rc ) );
91 len = 0;
92 }
93
94 /* Instantiate DRBG */
95 if ( ( rc = drbg_instantiate ( &rbg.state, &uuid, len ) ) != 0 ) {
96 DBGC ( &rbg, "RBG could not instantiate DRBG: %s\n",
97 strerror ( rc ) );
98 return rc;
99 }
100
101 return 0;
102}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
int drbg_instantiate(struct drbg_state *state, const void *personal, size_t personal_len)
Instantiate DRBG.
Definition drbg.c:79
ring len
Length.
Definition dwmac.h:226
#define DBGC(...)
Definition compiler.h:505
struct random_bit_generator rbg
The RBG.
Definition rbg.c:64
int fetch_uuid_setting(struct settings *settings, const struct setting *setting, union uuid *uuid)
Fetch value of UUID setting.
Definition settings.c:1085
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A universally unique ID.
Definition uuid.h:16

References DBGC, drbg_instantiate(), fetch_uuid_setting(), len, NULL, rbg, rc, and strerror().

Referenced by rbg_generate(), and rbg_startup_fn().

◆ rbg_generate()

int rbg_generate ( const void * additional,
size_t additional_len,
int prediction_resist,
void * data,
size_t len )

Generate bits using RBG.

Parameters
additionalAdditional input
additional_lenLength of additional input
prediction_resistPrediction resistance is required
dataOutput buffer
lenLength of output buffer
Return values
rcReturn status code

This is the RBG_Generate function defined in ANS X9.82 Part 4 (April 2011 Draft) Section 9.1.2.2.

Definition at line 117 of file rbg.c.

118 {
119
120 /* Attempt startup, if not already attempted */
121 if ( ! rbg.started )
122 rbg_startup();
123
124 /* Generate bits. The DRBG will itself return an error if it
125 * is not valid (e.g. due to an instantiation failure).
126 */
127 return drbg_generate ( &rbg.state, additional, additional_len,
128 prediction_resist, data, len );
129}
int drbg_generate(struct drbg_state *state, const void *additional, size_t additional_len, int prediction_resist, void *data, size_t len)
Generate pseudorandom bits using DRBG.
Definition drbg.c:284
uint8_t data[48]
Additional event data.
Definition ena.h:11
static int rbg_startup(void)
Start up RBG.
Definition rbg.c:74
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:13

References additional, data, drbg_generate(), len, rbg, and rbg_startup().

Referenced by get_random_nz(), tls_generate_random(), and wpa_handle_1_of_4().

◆ rbg_shutdown()

void rbg_shutdown ( void )
static

Shut down RBG.

Definition at line 135 of file rbg.c.

135 {
136
137 /* Uninstantiate DRBG */
138 drbg_uninstantiate ( &rbg.state );
139
140 /* Clear startup attempted flag */
141 rbg.started = 0;
142}
void drbg_uninstantiate(struct drbg_state *state)
Uninstantiate DRBG.
Definition drbg.c:424

References drbg_uninstantiate(), and rbg.

Referenced by rbg_shutdown_fn().

◆ rbg_startup_fn()

void rbg_startup_fn ( void )
static

RBG startup function.

Definition at line 145 of file rbg.c.

145 {
146
147 /* Start up RBG (if not already started on demand). There is
148 * no way to report an error at this stage, but a failed
149 * startup will result in an invalid DRBG that refuses to
150 * generate bits.
151 */
152 if ( ! rbg.started )
153 rbg_startup();
154}

References rbg, and rbg_startup().

Referenced by __startup_fn().

◆ rbg_shutdown_fn()

void rbg_shutdown_fn ( int booting __unused)
static

RBG shutdown function.

Definition at line 157 of file rbg.c.

157 {
158
159 /* Shut down RBG */
160 rbg_shutdown();
161}
static void rbg_shutdown(void)
Shut down RBG.
Definition rbg.c:135

References __unused, and rbg_shutdown().

Referenced by __startup_fn().

◆ __startup_fn()

struct startup_fn startup_rbg __startup_fn ( STARTUP_NORMAL )

RBG startup table entry.

References __startup_fn, rbg_shutdown_fn(), rbg_startup_fn(), and STARTUP_NORMAL.

Variable Documentation

◆ rbg

The RBG.

Definition at line 64 of file rbg.c.

Referenced by rbg_generate(), rbg_shutdown(), rbg_startup(), and rbg_startup_fn().