linux_entropy.c revision a734c64bff58bda2fa48c2795453e092167b0ff7
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file
*
* Linux entropy source
*
*/
#include <stdint.h>
#include <errno.h>
#include <linux_api.h>
/** Entropy source filename */
static const char entropy_filename[] = "/dev/random";
/** Entropy source file handle */
static int entropy_fd;
/**
* Enable entropy gathering
*
* @ret rc Return status code
*/
static int linux_entropy_enable ( void ) {
/* Open entropy source */
if ( entropy_fd < 0 ) {
return entropy_fd;
}
return 0;
}
/**
* Disable entropy gathering
*
*/
static void linux_entropy_disable ( void ) {
/* Close entropy source */
linux_close ( entropy_fd );
}
/**
* Get noise sample
*
* @ret noise Noise sample
* @ret rc Return status code
*/
/* Read a single byte from entropy source */
if ( len < 0 ) {
return len;
}
if ( len == 0 ) {
return -EPIPE;
}
return 0;
}