iPXE
Functions | Variables
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)
 
static int rbg_startup (void)
 Start up RBG. More...
 
int rbg_generate (const void *additional, size_t additional_len, int prediction_resist, void *data, size_t len)
 Generate bits using RBG. More...
 
static void rbg_shutdown (void)
 Shut down RBG. More...
 
static void rbg_startup_fn (void)
 RBG startup function. More...
 
static void rbg_shutdown_fn (int booting __unused)
 RBG shutdown function. More...
 
struct startup_fn startup_rbg __startup_fn (STARTUP_NORMAL)
 RBG startup table entry. More...
 

Variables

struct random_bit_generator rbg
 The RBG. More...
 

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  )

◆ rbg_startup()

static 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 73 of file rbg.c.

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

References DBGC, drbg_instantiate(), fetch_uuid_setting(), len, NULL, rbg, rc, random_bit_generator::started, random_bit_generator::state, 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 116 of file rbg.c.

117  {
118 
119  /* Attempt startup, if not already attempted */
120  if ( ! rbg.started )
121  rbg_startup();
122 
123  /* Generate bits. The DRBG will itself return an error if it
124  * is not valid (e.g. due to an instantiation failure).
125  */
126  return drbg_generate ( &rbg.state, additional, additional_len,
127  prediction_resist, data, len );
128 }
static int rbg_startup(void)
Start up RBG.
Definition: rbg.c:73
int started
Startup has been attempted.
Definition: rbg.h:20
uint16_t additional
Additional sense code and qualifier.
Definition: scsi.h:28
struct random_bit_generator rbg
The RBG.
Definition: rbg.c:63
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
struct drbg_state state
DRBG state.
Definition: rbg.h:18
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:283

References additional, data, drbg_generate(), len, rbg, rbg_startup(), random_bit_generator::started, and random_bit_generator::state.

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

◆ rbg_shutdown()

static void rbg_shutdown ( void  )
static

Shut down RBG.

Definition at line 134 of file rbg.c.

134  {
135 
136  /* Uninstantiate DRBG */
138 
139  /* Clear startup attempted flag */
140  rbg.started = 0;
141 }
int started
Startup has been attempted.
Definition: rbg.h:20
struct random_bit_generator rbg
The RBG.
Definition: rbg.c:63
void drbg_uninstantiate(struct drbg_state *state)
Uninstantiate DRBG.
Definition: drbg.c:423
struct drbg_state state
DRBG state.
Definition: rbg.h:18

References drbg_uninstantiate(), rbg, random_bit_generator::started, and random_bit_generator::state.

Referenced by rbg_shutdown_fn().

◆ rbg_startup_fn()

static void rbg_startup_fn ( void  )
static

RBG startup function.

Definition at line 144 of file rbg.c.

144  {
145 
146  /* Start up RBG (if not already started on demand). There is
147  * no way to report an error at this stage, but a failed
148  * startup will result in an invalid DRBG that refuses to
149  * generate bits.
150  */
151  if ( ! rbg.started )
152  rbg_startup();
153 }
static int rbg_startup(void)
Start up RBG.
Definition: rbg.c:73
int started
Startup has been attempted.
Definition: rbg.h:20
struct random_bit_generator rbg
The RBG.
Definition: rbg.c:63

References rbg, rbg_startup(), and random_bit_generator::started.

◆ rbg_shutdown_fn()

static void rbg_shutdown_fn ( int booting  __unused)
static

RBG shutdown function.

Definition at line 156 of file rbg.c.

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

References rbg_shutdown().

◆ __startup_fn()

struct startup_fn startup_rbg __startup_fn ( STARTUP_NORMAL  )

RBG startup table entry.

Variable Documentation

◆ rbg

The RBG.

Definition at line 63 of file rbg.c.

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