mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +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
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -42,7 +51,7 @@ int main( int argc, char *argv[] )
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
"POLARSSL_FS_IO and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
@@ -66,16 +75,16 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( argc != 2 )
|
||||
{
|
||||
printf( "usage: pk_decrypt <key_file>\n" );
|
||||
polarssl_printf( "usage: pk_decrypt <key_file>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
@@ -83,18 +92,18 @@ int main( int argc, char *argv[] )
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
polarssl_printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
pk_init( &pk );
|
||||
|
||||
if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -105,7 +114,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( ( f = fopen( "result-enc.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
printf( "\n ! Could not open %s\n\n", "result-enc.txt" );
|
||||
polarssl_printf( "\n ! Could not open %s\n\n", "result-enc.txt" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -120,19 +129,19 @@ int main( int argc, char *argv[] )
|
||||
/*
|
||||
* Decrypt the encrypted RSA data and print the result.
|
||||
*/
|
||||
printf( "\n . Decrypting the encrypted data" );
|
||||
polarssl_printf( "\n . Decrypting the encrypted data" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_decrypt( &pk, buf, i, result, &olen, sizeof(result),
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_decrypt returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_decrypt returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . OK\n\n" );
|
||||
polarssl_printf( "\n . OK\n\n" );
|
||||
|
||||
printf( "The decrypted result is: '%s'\n\n", result );
|
||||
polarssl_printf( "The decrypted result is: '%s'\n\n", result );
|
||||
|
||||
ret = 0;
|
||||
|
||||
@@ -142,11 +151,11 @@ exit:
|
||||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " ! Last error was: %s\n", buf );
|
||||
polarssl_printf( " ! Last error was: %s\n", buf );
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user