2 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
26 * This mechanism is designed to comply with ANS X9.82 Part 4 (April
27 * 2011 Draft) Section 10. This standard is unfortunately not freely
30 * The chosen RBG design is that of a DRBG with a live entropy source
31 * with no conditioning function. Only a single security strength is
32 * supported. No seedfile is used since there may be no non-volatile
33 * storage available. The system UUID is used as the personalisation
39 #include <ipxe/init.h>
40 #include <ipxe/settings.h>
41 #include <ipxe/uuid.h>
42 #include <ipxe/crypto.h>
43 #include <ipxe/drbg.h>
47 struct random_bit_generator rbg;
52 * @ret rc Return status code
54 * This is the RBG_Startup function defined in ANS X9.82 Part 4 (April
55 * 2011 Draft) Section 9.1.2.2.
57 static int rbg_startup ( void ) {
62 /* Try to obtain system UUID for use as personalisation
63 * string, in accordance with ANS X9.82 Part 3-2007 Section
64 * 8.5.2. If no UUID is available, proceed without a
65 * personalisation string.
67 if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) {
69 DBGC ( &rbg, "RBG could not fetch personalisation string: "
70 "%s\n", strerror ( rc ) );
74 /* Instantiate DRBG */
75 if ( ( rc = drbg_instantiate ( &rbg.state, &uuid, len ) ) != 0 ) {
76 DBGC ( &rbg, "RBG could not instantiate DRBG: %s\n",
88 static void rbg_shutdown ( void ) {
90 /* Uninstantiate DRBG */
91 drbg_uninstantiate ( &rbg.state );
94 /** RBG startup function */
95 static void rbg_startup_fn ( void ) {
97 /* Start up RBG. There is no way to report an error at this
98 * stage, but a failed startup will result in an invalid DRBG
99 * that refuses to generate bits.
104 /** RBG shutdown function */
105 static void rbg_shutdown_fn ( int booting __unused ) {
111 /** RBG startup table entry */
112 struct startup_fn startup_rbg __startup_fn ( STARTUP_NORMAL ) = {
113 .startup = rbg_startup_fn,
114 .shutdown = rbg_shutdown_fn,