blob: 6a7aa3ae66b6b4dd83f410e1c3d1dccb3c1daf37 [file] [log] [blame]
Paul Bakkerfc36d162011-01-27 16:50:02 +00001/**
2 * \brief Generate random data into a file
3 *
Paul Bakkercce9d772011-11-18 14:26:47 +00004 * Copyright (C) 2006-2011, Brainspark B.V.
Paul Bakkerfc36d162011-01-27 16:50:02 +00005 *
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 Bakker5690efc2011-05-26 13:16:06 +000027
Paul Bakkerfc36d162011-01-27 16:50:02 +000028#include "polarssl/havege.h"
Paul Bakker5690efc2011-05-26 13:16:06 +000029
Paul Bakkerfc36d162011-01-27 16:50:02 +000030#include <time.h>
31#include <stdio.h>
32
Paul Bakker5690efc2011-05-26 13:16:06 +000033#if !defined(POLARSSL_HAVEGE_C)
Paul Bakkercce9d772011-11-18 14:26:47 +000034int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +000035{
Paul Bakkercce9d772011-11-18 14:26:47 +000036 ((void) argc);
37 ((void) argv);
38
Paul Bakker5690efc2011-05-26 13:16:06 +000039 printf("POLARSSL_HAVEGE_C not defined.\n");
40 return( 0 );
41}
42#else
Paul Bakkerfc36d162011-01-27 16:50:02 +000043int main( int argc, char *argv[] )
44{
45 FILE *f;
46 time_t t;
47 int i, j, k;
48 havege_state hs;
49 unsigned char buf[1024];
50
51 if( argc < 2 )
52 {
53 fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
54 return( 1 );
55 }
56
57 if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
58 {
59 printf( "failed to open '%s' for writing.\n", argv[0] );
60 return( 1 );
61 }
62
63 havege_init( &hs );
64
65 t = time( NULL );
66
67 for( i = 0, k = 768; i < k; i++ )
68 {
69 for( j = 0; j < (int) sizeof( buf ); j++ )
70 buf[j] = havege_rand( &hs );
71
72 fwrite( buf, sizeof( buf ), 1, f );
73
74 printf( "Generating 32Mb of data in file '%s'... %04.1f" \
75 "%% done\r", argv[1], (100 * (float) (i + 1)) / k );
76 fflush( stdout );
77 }
78
79 if( t == time( NULL ) )
80 t--;
81
82 fclose( f );
83 return( 0 );
84}
Paul Bakker5690efc2011-05-26 13:16:06 +000085#endif /* POLARSSL_HAVEGE_C */