2 * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 FILE_LICENCE ( GPL2_OR_LATER
);
23 * Cryptographically strong random number generator
25 * Currently the cryptographic part is not implemented, and this just
29 #include <gpxe/crypto.h>
33 * Get cryptographically strong random bytes
35 * @v buf Buffer in which to store random bytes
36 * @v len Number of random bytes to generate
38 * @b WARNING: This function is currently underimplemented, and does
39 * not give numbers any stronger than random()!
41 void get_random_bytes ( void *buf
, size_t len
)
46 * Somewhat arbitrarily, choose the 0x00FF0000-masked byte
47 * returned by random() as having good entropy. PRNGs often
48 * don't provide good entropy in lower bits, and the top byte
49 * might show a pattern because of sign issues.
53 *bufp
++ = ( random() >> 16 ) & 0xFF;