2011-01-27 17:50:02 +01:00
|
|
|
/**
|
2011-12-03 22:45:14 +01:00
|
|
|
* \brief Use and generate multiple entropies calls into a file
|
2011-01-27 17:50:02 +01:00
|
|
|
*
|
2011-11-18 15:26:47 +01:00
|
|
|
* Copyright (C) 2006-2011, Brainspark B.V.
|
2011-01-27 17:50:02 +01:00
|
|
|
*
|
|
|
|
* This file is part of PolarSSL (http://www.polarssl.org)
|
|
|
|
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "polarssl/config.h"
|
2011-05-26 15:16:06 +02:00
|
|
|
|
2011-12-03 22:45:14 +01:00
|
|
|
#include "polarssl/entropy.h"
|
2011-05-26 15:16:06 +02:00
|
|
|
|
2011-01-27 17:50:02 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-12-03 22:45:14 +01:00
|
|
|
#if !defined(POLARSSL_ENTROPY_C)
|
2011-11-18 15:26:47 +01:00
|
|
|
int main( int argc, char *argv[] )
|
2011-05-26 15:16:06 +02:00
|
|
|
{
|
2011-11-18 15:26:47 +01:00
|
|
|
((void) argc);
|
|
|
|
((void) argv);
|
|
|
|
|
2011-12-03 22:45:14 +01:00
|
|
|
printf("POLARSSL_ENTROPY_C not defined.\n");
|
2011-05-26 15:16:06 +02:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#else
|
2011-01-27 17:50:02 +01:00
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
FILE *f;
|
2011-12-03 22:45:14 +01:00
|
|
|
int i, k, ret;
|
|
|
|
entropy_context entropy;
|
|
|
|
unsigned char buf[ENTROPY_BLOCK_SIZE];
|
2011-01-27 17:50:02 +01:00
|
|
|
|
|
|
|
if( argc < 2 )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
|
|
|
|
{
|
|
|
|
printf( "failed to open '%s' for writing.\n", argv[0] );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
2011-12-03 22:45:14 +01:00
|
|
|
entropy_init( &entropy );
|
2011-01-27 17:50:02 +01:00
|
|
|
|
|
|
|
for( i = 0, k = 768; i < k; i++ )
|
|
|
|
{
|
2011-12-03 22:45:14 +01:00
|
|
|
ret = entropy_func( &entropy, buf, sizeof( buf ) );
|
|
|
|
if( ret != 0 )
|
2011-11-27 22:07:34 +01:00
|
|
|
{
|
2011-12-03 22:45:14 +01:00
|
|
|
printf("failed!\n");
|
|
|
|
goto cleanup;
|
2011-11-27 22:07:34 +01:00
|
|
|
}
|
2011-01-27 17:50:02 +01:00
|
|
|
|
2011-12-03 22:45:14 +01:00
|
|
|
fwrite( buf, 1, sizeof( buf ), f );
|
2011-01-27 17:50:02 +01:00
|
|
|
|
|
|
|
printf( "Generating 32Mb of data in file '%s'... %04.1f" \
|
|
|
|
"%% done\r", argv[1], (100 * (float) (i + 1)) / k );
|
|
|
|
fflush( stdout );
|
|
|
|
}
|
|
|
|
|
2011-12-03 22:45:14 +01:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2011-01-27 17:50:02 +01:00
|
|
|
|
|
|
|
fclose( f );
|
2011-12-03 22:45:14 +01:00
|
|
|
|
|
|
|
return( ret );
|
2011-01-27 17:50:02 +01:00
|
|
|
}
|
2011-12-03 22:45:14 +01:00
|
|
|
#endif /* POLARSSL_ENTROPY_C */
|