Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 1 | /** |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 2 | * \brief Use and generate multiple entropies calls into a file |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2011, Brainspark B.V. |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 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 | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 28 | #include "polarssl/entropy.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 <stdio.h> |
| 31 | |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 32 | #if !defined(POLARSSL_ENTROPY_C) |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 33 | int main( int argc, char *argv[] ) |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 34 | { |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 35 | ((void) argc); |
| 36 | ((void) argv); |
| 37 | |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 38 | printf("POLARSSL_ENTROPY_C not defined.\n"); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 39 | return( 0 ); |
| 40 | } |
| 41 | #else |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 42 | int main( int argc, char *argv[] ) |
| 43 | { |
| 44 | FILE *f; |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 45 | int i, k, ret; |
| 46 | entropy_context entropy; |
| 47 | unsigned char buf[ENTROPY_BLOCK_SIZE]; |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 48 | |
| 49 | if( argc < 2 ) |
| 50 | { |
| 51 | fprintf( stderr, "usage: %s <output filename>\n", argv[0] ); |
| 52 | return( 1 ); |
| 53 | } |
| 54 | |
| 55 | if( ( f = fopen( argv[1], "wb+" ) ) == NULL ) |
| 56 | { |
| 57 | printf( "failed to open '%s' for writing.\n", argv[0] ); |
| 58 | return( 1 ); |
| 59 | } |
| 60 | |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 61 | entropy_init( &entropy ); |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 62 | |
| 63 | for( i = 0, k = 768; i < k; i++ ) |
| 64 | { |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 65 | ret = entropy_func( &entropy, buf, sizeof( buf ) ); |
| 66 | if( ret != 0 ) |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 67 | { |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 68 | printf("failed!\n"); |
| 69 | goto cleanup; |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 70 | } |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 71 | |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 72 | fwrite( buf, 1, sizeof( buf ), f ); |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 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 | |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 79 | ret = 0; |
| 80 | |
| 81 | cleanup: |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 82 | |
| 83 | fclose( f ); |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 84 | |
| 85 | return( ret ); |
Paul Bakker | fc36d16 | 2011-01-27 16:50:02 +0000 | [diff] [blame] | 86 | } |
Paul Bakker | 6083fd2 | 2011-12-03 21:45:14 +0000 | [diff] [blame^] | 87 | #endif /* POLARSSL_ENTROPY_C */ |