mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Use platform layer in programs for consistency.
This commit is contained in:
@ -26,6 +26,15 @@
|
||||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_fprintf fprintf
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#if !defined(_WIN32_WCE)
|
||||
@ -58,7 +67,7 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
printf("POLARSSL_AES_C and/or POLARSSL_SHA256_C not defined.\n");
|
||||
polarssl_printf("POLARSSL_AES_C and/or POLARSSL_SHA256_C not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
@ -98,10 +107,10 @@ int main( int argc, char *argv[] )
|
||||
*/
|
||||
if( argc != 5 )
|
||||
{
|
||||
printf( USAGE );
|
||||
polarssl_printf( USAGE );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n Press Enter to exit this program.\n" );
|
||||
polarssl_printf( "\n Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
@ -112,25 +121,25 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( mode != MODE_ENCRYPT && mode != MODE_DECRYPT )
|
||||
{
|
||||
fprintf( stderr, "invalide operation mode\n" );
|
||||
polarssl_fprintf( stderr, "invalide operation mode\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( strcmp( argv[2], argv[3] ) == 0 )
|
||||
{
|
||||
fprintf( stderr, "input and output filenames must differ\n" );
|
||||
polarssl_fprintf( stderr, "input and output filenames must differ\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( fin = fopen( argv[2], "rb" ) ) == NULL )
|
||||
{
|
||||
fprintf( stderr, "fopen(%s,rb) failed\n", argv[2] );
|
||||
polarssl_fprintf( stderr, "fopen(%s,rb) failed\n", argv[2] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( fout = fopen( argv[3], "wb+" ) ) == NULL )
|
||||
{
|
||||
fprintf( stderr, "fopen(%s,wb+) failed\n", argv[3] );
|
||||
polarssl_fprintf( stderr, "fopen(%s,wb+) failed\n", argv[3] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -183,7 +192,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( li_size.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR )
|
||||
{
|
||||
fprintf( stderr, "SetFilePointer(0,FILE_END) failed\n" );
|
||||
polarssl_fprintf( stderr, "SetFilePointer(0,FILE_END) failed\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -199,7 +208,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( fseek( fin, 0, SEEK_SET ) < 0 )
|
||||
{
|
||||
fprintf( stderr, "fseek(0,SEEK_SET) failed\n" );
|
||||
polarssl_fprintf( stderr, "fseek(0,SEEK_SET) failed\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -235,7 +244,7 @@ int main( int argc, char *argv[] )
|
||||
*/
|
||||
if( fwrite( IV, 1, 16, fout ) != 16 )
|
||||
{
|
||||
fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
|
||||
polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -268,7 +277,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( fread( buffer, 1, n, fin ) != (size_t) n )
|
||||
{
|
||||
fprintf( stderr, "fread(%d bytes) failed\n", n );
|
||||
polarssl_fprintf( stderr, "fread(%d bytes) failed\n", n );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -280,7 +289,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( fwrite( buffer, 1, 16, fout ) != 16 )
|
||||
{
|
||||
fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
|
||||
polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -294,7 +303,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( fwrite( digest, 1, 32, fout ) != 32 )
|
||||
{
|
||||
fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
|
||||
polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@ -314,13 +323,13 @@ int main( int argc, char *argv[] )
|
||||
*/
|
||||
if( filesize < 48 )
|
||||
{
|
||||
fprintf( stderr, "File too short to be encrypted.\n" );
|
||||
polarssl_fprintf( stderr, "File too short to be encrypted.\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( filesize & 0x0F ) != 0 )
|
||||
{
|
||||
fprintf( stderr, "File size not a multiple of 16.\n" );
|
||||
polarssl_fprintf( stderr, "File size not a multiple of 16.\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -334,7 +343,7 @@ int main( int argc, char *argv[] )
|
||||
*/
|
||||
if( fread( buffer, 1, 16, fin ) != 16 )
|
||||
{
|
||||
fprintf( stderr, "fread(%d bytes) failed\n", 16 );
|
||||
polarssl_fprintf( stderr, "fread(%d bytes) failed\n", 16 );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -367,7 +376,7 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
if( fread( buffer, 1, 16, fin ) != 16 )
|
||||
{
|
||||
fprintf( stderr, "fread(%d bytes) failed\n", 16 );
|
||||
polarssl_fprintf( stderr, "fread(%d bytes) failed\n", 16 );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -386,7 +395,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( fwrite( buffer, 1, n, fout ) != (size_t) n )
|
||||
{
|
||||
fprintf( stderr, "fwrite(%d bytes) failed\n", n );
|
||||
polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", n );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@ -398,7 +407,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( fread( buffer, 1, 32, fin ) != 32 )
|
||||
{
|
||||
fprintf( stderr, "fread(%d bytes) failed\n", 32 );
|
||||
polarssl_fprintf( stderr, "fread(%d bytes) failed\n", 32 );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -409,7 +418,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
fprintf( stderr, "HMAC check failed: wrong key, "
|
||||
polarssl_fprintf( stderr, "HMAC check failed: wrong key, "
|
||||
"or file corrupted.\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
Reference in New Issue
Block a user