crandom.c File Reference

Cryptographically strong random number generator. More...

#include <gpxe/crypto.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
void get_random_bytes (void *buf, size_t len)
 Get cryptographically strong random bytes.


Detailed Description

Cryptographically strong random number generator.

Currently the cryptographic part is not implemented, and this just uses random().

Definition in file crandom.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

void get_random_bytes ( void *  buf,
size_t  len 
)

Get cryptographically strong random bytes.

Parameters:
buf Buffer in which to store random bytes
len Number of random bytes to generate
WARNING: This function is currently underimplemented, and does not give numbers any stronger than random()!

Definition at line 41 of file crandom.c.

References random(), and u8.

Referenced by forcedeth_probe(), and wpa_handle_1_of_4().

00042 {
00043         u8 *bufp = buf;
00044 
00045         /*
00046          * Somewhat arbitrarily, choose the 0x00FF0000-masked byte
00047          * returned by random() as having good entropy. PRNGs often
00048          * don't provide good entropy in lower bits, and the top byte
00049          * might show a pattern because of sign issues.
00050          */
00051 
00052         while ( len-- ) {
00053                 *bufp++ = ( random() >> 16 ) & 0xFF;
00054         }
00055 }


Generated on Tue Apr 6 20:01:15 2010 for gPXE by  doxygen 1.5.7.1