Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \brief Generate random data into a file |
| 3 | * |
| 4 | * Copyright (C) 2006-2010, Brainspark B.V. |
| 5 | * |
| 6 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | */ |
| 25 | |
| 26 | #include "polarssl/config.h" |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame^] | 27 | |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 28 | #include "polarssl/havege.h" |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame^] | 29 | |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 30 | #include <time.h> |
| 31 | #include <stdio.h> |
| 32 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame^] | 33 | #if !defined(POLARSSL_HAVEGE_C) |
| 34 | int main( void ) |
| 35 | { |
| 36 | printf("POLARSSL_HAVEGE_C not defined.\n"); |
| 37 | return( 0 ); |
| 38 | } |
| 39 | #else |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 40 | int main( int argc, char *argv[] ) |
| 41 | { |
| 42 | FILE *f; |
| 43 | time_t t; |
| 44 | int i, j, k; |
| 45 | havege_state hs; |
| 46 | unsigned char buf[1024]; |
| 47 | |
| 48 | if( argc < 2 ) |
| 49 | { |
| 50 | fprintf( stderr, "usage: %s <output filename>\n", argv[0] ); |
| 51 | return( 1 ); |
| 52 | } |
| 53 | |
| 54 | if( ( f = fopen( argv[1], "wb+" ) ) == NULL ) |
| 55 | { |
| 56 | printf( "failed to open '%s' for writing.\n", argv[0] ); |
| 57 | return( 1 ); |
| 58 | } |
| 59 | |
| 60 | havege_init( &hs ); |
| 61 | |
| 62 | t = time( NULL ); |
| 63 | |
| 64 | for( i = 0, k = 768; i < k; i++ ) |
| 65 | { |
| 66 | for( j = 0; j < (int) sizeof( buf ); j++ ) |
| 67 | buf[j] = havege_rand( &hs ); |
| 68 | |
| 69 | fwrite( buf, sizeof( buf ), 1, f ); |
| 70 | |
| 71 | printf( "Generating 32Mb of data in file '%s'... %04.1f" \ |
| 72 | "%% done\r", argv[1], (100 * (float) (i + 1)) / k ); |
| 73 | fflush( stdout ); |
| 74 | } |
| 75 | |
| 76 | if( t == time( NULL ) ) |
| 77 | t--; |
| 78 | |
| 79 | fclose( f ); |
| 80 | return( 0 ); |
| 81 | } |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame^] | 82 | #endif /* POLARSSL_HAVEGE_C */ |