xorp

randomness.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/rtrmgr/randomness.hh,v 1.12 2008/10/02 21:58:24 bms Exp $
00021 
00022 #ifndef __RTRMGR_RANDOMNESS_HH__
00023 #define __RTRMGR_RANDOMNESS_HH__
00024 
00025 class RandomGen {
00026 public:
00027     RandomGen();
00028     ~RandomGen();
00029 
00030     void get_random_bytes(size_t len, uint8_t* buf);
00031 
00032 private:
00033     bool read_file(const string& filename);
00034     bool read_fd(FILE* file);
00035     void add_buf_to_randomness(uint8_t* buf, size_t len);
00036 
00037     static const size_t RAND_POOL_SIZE = 65536;
00038 
00039     bool    _random_exists;
00040     bool    _urandom_exists;
00041     uint8_t*    _random_data;
00042     uint32_t    _counter;
00043 };
00044 
00045 #endif // __RTRMGR_RANDOMNESS_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations