Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 1 | /* (C) 2012 by Harald Welte <laforge@gnumonks.org> |
| 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program 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 Affero General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <stdint.h> |
| 25 | #include <unistd.h> |
| 26 | #include <sys/stat.h> |
| 27 | |
| 28 | static uint8_t ctr = 0; |
| 29 | |
| 30 | static void print_msg(void) |
| 31 | { |
| 32 | static int printed = 0; |
| 33 | if (!printed) { |
| 34 | fprintf(stderr, "Using fake random generator for deterministic " |
| 35 | "test results. NEVER USE THIS IN PRODUCTION\n"); |
| 36 | printed = 1; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | int rand_init(void) |
| 41 | { |
| 42 | print_msg(); |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | int rand_get(uint8_t *rand, unsigned int len) |
| 47 | { |
| 48 | print_msg(); |
| 49 | memset(rand, ctr, len); |
| 50 | ctr++; |
| 51 | return len; |
| 52 | } |