blob: a44e8a35ae84125ba3def1d5691b6febf4824486 [file] [log] [blame]
Paul Bakkerfc36d162011-01-27 16:50:02 +00001/**
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"
27#include "polarssl/havege.h"
28#include <time.h>
29#include <stdio.h>
30
31int main( int argc, char *argv[] )
32{
33 FILE *f;
34 time_t t;
35 int i, j, k;
36 havege_state hs;
37 unsigned char buf[1024];
38
39 if( argc < 2 )
40 {
41 fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
42 return( 1 );
43 }
44
45 if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
46 {
47 printf( "failed to open '%s' for writing.\n", argv[0] );
48 return( 1 );
49 }
50
51 havege_init( &hs );
52
53 t = time( NULL );
54
55 for( i = 0, k = 768; i < k; i++ )
56 {
57 for( j = 0; j < (int) sizeof( buf ); j++ )
58 buf[j] = havege_rand( &hs );
59
60 fwrite( buf, sizeof( buf ), 1, f );
61
62 printf( "Generating 32Mb of data in file '%s'... %04.1f" \
63 "%% done\r", argv[1], (100 * (float) (i + 1)) / k );
64 fflush( stdout );
65 }
66
67 if( t == time( NULL ) )
68 t--;
69
70 fclose( f );
71 return( 0 );
72}