Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 1 | // Copyright (C) 2010 David Sugar, Tycho Softworks. |
| 2 | // |
| 3 | // This file is part of GNU uCommon C++. |
| 4 | // |
| 5 | // GNU uCommon C++ is free software: you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU Lesser General Public License as published |
| 7 | // by the Free Software Foundation, either version 3 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // GNU uCommon C++ is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU Lesser General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU Lesser General Public License |
| 16 | // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | #include "local.h" |
| 19 | |
| 20 | void Random::seed(void) |
| 21 | { |
| 22 | secure::init(); |
| 23 | RAND_poll(); |
| 24 | } |
| 25 | |
| 26 | bool Random::seed(const unsigned char *buf, size_t size) |
| 27 | { |
| 28 | secure::init(); |
| 29 | |
| 30 | RAND_seed(buf, size); |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | size_t Random::key(unsigned char *buf, size_t size) |
| 35 | { |
| 36 | secure::init(); |
| 37 | |
| 38 | if(RAND_bytes(buf, size)) |
| 39 | return size; |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | size_t Random::fill(unsigned char *buf, size_t size) |
| 44 | { |
| 45 | secure::init(); |
| 46 | |
| 47 | if(RAND_pseudo_bytes(buf, size)) |
| 48 | return size; |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | bool Random::status(void) |
| 53 | { |
| 54 | if(RAND_status()) |
| 55 | return true; |
| 56 | |
| 57 | return false; |
| 58 | } |
| 59 | |