mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 18:45:43 +01:00
Updated key_app.c and key_app_writer.c for EC key printing
This commit is contained in:
parent
cc34f95b43
commit
2e24ca74b0
@ -92,7 +92,7 @@ int main( int argc, char *argv[] )
|
|||||||
* Set to sane values
|
* Set to sane values
|
||||||
*/
|
*/
|
||||||
pk_init( &pk );
|
pk_init( &pk );
|
||||||
memset( buf, 0, 1024 );
|
memset( buf, 0, sizeof(buf) );
|
||||||
|
|
||||||
if( argc == 0 )
|
if( argc == 0 )
|
||||||
{
|
{
|
||||||
@ -150,7 +150,7 @@ int main( int argc, char *argv[] )
|
|||||||
printf( " failed\n ! fopen returned NULL\n" );
|
printf( " failed\n ! fopen returned NULL\n" );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
fgets( buf, 1024, f );
|
fgets( buf, sizeof(buf), f );
|
||||||
fclose( f );
|
fclose( f );
|
||||||
|
|
||||||
i = strlen( buf );
|
i = strlen( buf );
|
||||||
@ -169,8 +169,8 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
polarssl_strerror( ret, buf, 1024 );
|
polarssl_strerror( ret, buf, sizeof(buf) );
|
||||||
printf( " failed\n ! pk_parse_keyfile returned %d - %s\n\n", ret, buf );
|
printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,11 +179,11 @@ int main( int argc, char *argv[] )
|
|||||||
/*
|
/*
|
||||||
* 1.2 Print the key
|
* 1.2 Print the key
|
||||||
*/
|
*/
|
||||||
|
printf( " . Key information ...\n" );
|
||||||
#if defined(POLARSSL_RSA_C)
|
#if defined(POLARSSL_RSA_C)
|
||||||
if( pk_can_do( &pk, POLARSSL_PK_RSA ) )
|
if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
|
||||||
{
|
{
|
||||||
rsa_context *rsa = pk_rsa( pk );
|
rsa_context *rsa = pk_rsa( pk );
|
||||||
printf( " . Key information ...\n" );
|
|
||||||
mpi_write_file( "N: ", &rsa->N, 16, NULL );
|
mpi_write_file( "N: ", &rsa->N, 16, NULL );
|
||||||
mpi_write_file( "E: ", &rsa->E, 16, NULL );
|
mpi_write_file( "E: ", &rsa->E, 16, NULL );
|
||||||
mpi_write_file( "D: ", &rsa->D, 16, NULL );
|
mpi_write_file( "D: ", &rsa->D, 16, NULL );
|
||||||
@ -196,10 +196,9 @@ int main( int argc, char *argv[] )
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
#if defined(POLARSSL_ECP_C)
|
#if defined(POLARSSL_ECP_C)
|
||||||
if( pk_can_do( &pk, POLARSSL_PK_ECKEY ) )
|
if( pk_get_type( &pk ) == POLARSSL_PK_ECKEY )
|
||||||
{
|
{
|
||||||
ecp_keypair *ecp = pk_ec( pk );
|
ecp_keypair *ecp = pk_ec( pk );
|
||||||
printf( " . Key information ...\n" );
|
|
||||||
mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
|
mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
|
||||||
mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
|
mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
|
||||||
mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
|
mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
|
||||||
@ -224,28 +223,27 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
polarssl_strerror( ret, buf, 1024 );
|
polarssl_strerror( ret, buf, sizeof(buf) );
|
||||||
printf( " failed\n ! pk_parse_public_keyfile returned %d - %s\n\n", ret, buf );
|
printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x - %s\n\n", -ret, buf );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( " ok\n" );
|
printf( " ok\n" );
|
||||||
|
|
||||||
|
printf( " . Key information ...\n" );
|
||||||
#if defined(POLARSSL_RSA_C)
|
#if defined(POLARSSL_RSA_C)
|
||||||
if( pk_can_do( &pk, POLARSSL_PK_RSA ) )
|
if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
|
||||||
{
|
{
|
||||||
rsa_context *rsa = pk_rsa( pk );
|
rsa_context *rsa = pk_rsa( pk );
|
||||||
printf( " . Key information ...\n" );
|
|
||||||
mpi_write_file( "N: ", &rsa->N, 16, NULL );
|
mpi_write_file( "N: ", &rsa->N, 16, NULL );
|
||||||
mpi_write_file( "E: ", &rsa->E, 16, NULL );
|
mpi_write_file( "E: ", &rsa->E, 16, NULL );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
#if defined(POLARSSL_ECP_C)
|
#if defined(POLARSSL_ECP_C)
|
||||||
if( pk_can_do( &pk, POLARSSL_PK_ECKEY ) )
|
if( pk_get_type( &pk ) == POLARSSL_PK_ECKEY )
|
||||||
{
|
{
|
||||||
ecp_keypair *ecp = pk_ec( pk );
|
ecp_keypair *ecp = pk_ec( pk );
|
||||||
printf( " . Key information ...\n" );
|
|
||||||
mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
|
mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
|
||||||
mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
|
mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
|
||||||
mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
|
mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
|
#include "polarssl/error.h"
|
||||||
#include "polarssl/pk.h"
|
#include "polarssl/pk.h"
|
||||||
#include "polarssl/error.h"
|
#include "polarssl/error.h"
|
||||||
|
|
||||||
@ -254,7 +255,8 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! pk_parse_key returned %d", ret );
|
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||||
|
printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,6 +281,17 @@ int main( int argc, char *argv[] )
|
|||||||
mpi_write_file( "QP: ", &rsa->QP, 16, NULL );
|
mpi_write_file( "QP: ", &rsa->QP, 16, NULL );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
|
#if defined(POLARSSL_ECP_C)
|
||||||
|
if( pk_get_type( &key ) == POLARSSL_PK_ECKEY )
|
||||||
|
{
|
||||||
|
ecp_keypair *ecp = pk_ec( key );
|
||||||
|
mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
|
||||||
|
mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
|
||||||
|
mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
|
||||||
|
mpi_write_file( "D : ", &ecp->d , 16, NULL );
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
printf("key type not supported yet\n");
|
printf("key type not supported yet\n");
|
||||||
|
|
||||||
@ -295,7 +308,8 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! pk_parse_public_key returned %d", ret );
|
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||||
|
printf( " failed\n ! pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,6 +328,16 @@ int main( int argc, char *argv[] )
|
|||||||
mpi_write_file( "E: ", &rsa->E, 16, NULL );
|
mpi_write_file( "E: ", &rsa->E, 16, NULL );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
|
#if defined(POLARSSL_ECP_C)
|
||||||
|
if( pk_get_type( &key ) == POLARSSL_PK_ECKEY )
|
||||||
|
{
|
||||||
|
ecp_keypair *ecp = pk_ec( key );
|
||||||
|
mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
|
||||||
|
mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
|
||||||
|
mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
printf("key type not supported yet\n");
|
printf("key type not supported yet\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user