mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-29 22:20:30 +00:00
Adapt rsa_encrypt example program to new RSA interface
This commit is contained in:
parent
d6ba5e3d8b
commit
0c2639386e
@ -69,6 +69,7 @@ int main( int argc, char *argv[] )
|
|||||||
unsigned char input[1024];
|
unsigned char input[1024];
|
||||||
unsigned char buf[512];
|
unsigned char buf[512];
|
||||||
const char *pers = "rsa_encrypt";
|
const char *pers = "rsa_encrypt";
|
||||||
|
mbedtls_mpi N, E;
|
||||||
|
|
||||||
exit_val = MBEDTLS_EXIT_SUCCESS;
|
exit_val = MBEDTLS_EXIT_SUCCESS;
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ int main( int argc, char *argv[] )
|
|||||||
mbedtls_printf( "\n . Seeding the random number generator..." );
|
mbedtls_printf( "\n . Seeding the random number generator..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
|
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||||
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
|
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||||
mbedtls_entropy_init( &entropy );
|
mbedtls_entropy_init( &entropy );
|
||||||
@ -112,8 +114,8 @@ int main( int argc, char *argv[] )
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( return_val = mbedtls_mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
|
if( ( return_val = mbedtls_mpi_read_file( &N, 16, f ) ) != 0 ||
|
||||||
( return_val = mbedtls_mpi_read_file( &rsa.E, 16, f ) ) != 0 )
|
( return_val = mbedtls_mpi_read_file( &E, 16, f ) ) != 0 )
|
||||||
{
|
{
|
||||||
exit_val = MBEDTLS_EXIT_FAILURE;
|
exit_val = MBEDTLS_EXIT_FAILURE;
|
||||||
mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n",
|
mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n",
|
||||||
@ -121,11 +123,17 @@ int main( int argc, char *argv[] )
|
|||||||
fclose( f );
|
fclose( f );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsa.len = ( mbedtls_mpi_bitlen( &rsa.N ) + 7 ) >> 3;
|
|
||||||
|
|
||||||
fclose( f );
|
fclose( f );
|
||||||
|
|
||||||
|
if( ( return_val = mbedtls_rsa_import( &rsa, &N, NULL,
|
||||||
|
NULL, NULL, &E ) ) != 0 )
|
||||||
|
{
|
||||||
|
exit_val = MBEDTLS_EXIT_FAILURE;
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_rsa_import returned %d\n\n",
|
||||||
|
return_val );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( strlen( argv[1] ) > 100 )
|
if( strlen( argv[1] ) > 100 )
|
||||||
{
|
{
|
||||||
exit_val = MBEDTLS_EXIT_FAILURE;
|
exit_val = MBEDTLS_EXIT_FAILURE;
|
||||||
@ -171,6 +179,7 @@ int main( int argc, char *argv[] )
|
|||||||
mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
|
||||||
mbedtls_ctr_drbg_free( &ctr_drbg );
|
mbedtls_ctr_drbg_free( &ctr_drbg );
|
||||||
mbedtls_entropy_free( &entropy );
|
mbedtls_entropy_free( &entropy );
|
||||||
mbedtls_rsa_free( &rsa );
|
mbedtls_rsa_free( &rsa );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user