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 buf[512];
|
||||
const char *pers = "rsa_encrypt";
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
exit_val = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
@ -86,6 +87,7 @@ int main( int argc, char *argv[] )
|
||||
mbedtls_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||
mbedtls_entropy_init( &entropy );
|
||||
@ -112,8 +114,8 @@ int main( int argc, char *argv[] )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( return_val = mbedtls_mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
|
||||
( return_val = mbedtls_mpi_read_file( &rsa.E, 16, f ) ) != 0 )
|
||||
if( ( return_val = mbedtls_mpi_read_file( &N, 16, f ) ) != 0 ||
|
||||
( return_val = mbedtls_mpi_read_file( &E, 16, f ) ) != 0 )
|
||||
{
|
||||
exit_val = MBEDTLS_EXIT_FAILURE;
|
||||
mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n",
|
||||
@ -121,11 +123,17 @@ int main( int argc, char *argv[] )
|
||||
fclose( f );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rsa.len = ( mbedtls_mpi_bitlen( &rsa.N ) + 7 ) >> 3;
|
||||
|
||||
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 )
|
||||
{
|
||||
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" );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
|
||||
mbedtls_ctr_drbg_free( &ctr_drbg );
|
||||
mbedtls_entropy_free( &entropy );
|
||||
mbedtls_rsa_free( &rsa );
|
||||
|
Loading…
Reference in New Issue
Block a user