mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-08 23:49:24 +01:00
Fixed bunch of X509_PARSE related defines / dependencies
This commit is contained in:
parent
30520d1776
commit
36713e8ed9
17 changed files with 107 additions and 98 deletions
|
|
@ -40,20 +40,20 @@
|
|||
|
||||
#include "polarssl/config.h"
|
||||
|
||||
#include "polarssl/pk.h"
|
||||
#include "polarssl/x509.h"
|
||||
#include "polarssl/rsa.h"
|
||||
#include "polarssl/entropy.h"
|
||||
#include "polarssl/ctr_drbg.h"
|
||||
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO)
|
||||
!defined(POLARSSL_PK_PARSE_C) || !defined(POLARSSL_FS_IO)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
"POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
|
@ -62,7 +62,8 @@ int main( int argc, char *argv[] )
|
|||
int ret;
|
||||
FILE *key_file;
|
||||
size_t olen;
|
||||
rsa_context p_rsa;
|
||||
pk_context p_pk;
|
||||
rsa_context *p_rsa;
|
||||
RSA *o_rsa;
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
|
|
@ -103,14 +104,23 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Reading private key from %s into PolarSSL ...", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
rsa_init( &p_rsa, RSA_PKCS_V15, 0 );
|
||||
if( x509parse_keyfile_rsa( &p_rsa, argv[1], NULL ) != 0 )
|
||||
pk_init( &p_pk );
|
||||
if( pk_parse_keyfile( &p_pk, argv[1], NULL ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not load key.\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( !pk_can_do( &p_pk, POLARSSL_PK_RSA ) )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Key is not an RSA key\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
p_rsa = pk_rsa( p_pk );
|
||||
|
||||
printf( " passed\n");
|
||||
|
||||
printf( " . Reading private key from %s into OpenSSL ...", argv[1] );
|
||||
|
|
@ -143,7 +153,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA encrypted value with PolarSSL (RSA_PUBLIC) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = rsa_pkcs1_encrypt( &p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PUBLIC, strlen( argv[1] ), input, p_pub_encrypted ) ) != 0 )
|
||||
if( ( ret = rsa_pkcs1_encrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PUBLIC, strlen( argv[2] ), input, p_pub_encrypted ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret );
|
||||
goto exit;
|
||||
|
|
@ -154,7 +164,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA encrypted value with OpenSSL (PUBLIC) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = RSA_public_encrypt( strlen( argv[1] ), input, o_pub_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
if( ( ret = RSA_public_encrypt( strlen( argv[2] ), input, o_pub_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
{
|
||||
unsigned long code = ERR_get_error();
|
||||
printf( " failed\n ! RSA_public_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
|
||||
|
|
@ -169,7 +179,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA encrypted value with PolarSSL (RSA_PRIVATE) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = rsa_pkcs1_encrypt( &p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, strlen( argv[1] ), input, p_priv_encrypted ) ) != 0 )
|
||||
if( ( ret = rsa_pkcs1_encrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, strlen( argv[2] ), input, p_priv_encrypted ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret );
|
||||
goto exit;
|
||||
|
|
@ -180,7 +190,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA encrypted value with OpenSSL (PRIVATE) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = RSA_private_encrypt( strlen( argv[1] ), input, o_priv_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
if( ( ret = RSA_private_encrypt( strlen( argv[2] ), input, o_priv_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
{
|
||||
unsigned long code = ERR_get_error();
|
||||
printf( " failed\n ! RSA_private_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
|
||||
|
|
@ -197,7 +207,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA decrypted value for OpenSSL (PUBLIC) with PolarSSL (PRIVATE) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = rsa_pkcs1_decrypt( &p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, &olen, o_pub_encrypted, p_pub_decrypted, 1024 ) ) != 0 )
|
||||
if( ( ret = rsa_pkcs1_decrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, &olen, o_pub_encrypted, p_pub_decrypted, 1024 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_decrypt returned %d\n\n", ret );
|
||||
}
|
||||
|
|
@ -207,7 +217,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA decrypted value for PolarSSL (PUBLIC) with OpenSSL (PRIVATE) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = RSA_private_decrypt( p_rsa.len, p_pub_encrypted, o_pub_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
if( ( ret = RSA_private_decrypt( p_rsa->len, p_pub_encrypted, o_pub_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
{
|
||||
unsigned long code = ERR_get_error();
|
||||
printf( " failed\n ! RSA_private_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
|
||||
|
|
@ -221,7 +231,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA decrypted value for OpenSSL (PRIVATE) with PolarSSL (PUBLIC) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = rsa_pkcs1_decrypt( &p_rsa, NULL, NULL, RSA_PUBLIC, &olen, o_priv_encrypted, p_priv_decrypted, 1024 ) ) != 0 )
|
||||
if( ( ret = rsa_pkcs1_decrypt( p_rsa, NULL, NULL, RSA_PUBLIC, &olen, o_priv_encrypted, p_priv_decrypted, 1024 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_decrypt returned %d\n\n", ret );
|
||||
}
|
||||
|
|
@ -231,7 +241,7 @@ int main( int argc, char *argv[] )
|
|||
printf( " . Generating the RSA decrypted value for PolarSSL (PRIVATE) with OpenSSL (PUBLIC) ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = RSA_public_decrypt( p_rsa.len, p_priv_encrypted, o_priv_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
if( ( ret = RSA_public_decrypt( p_rsa->len, p_priv_encrypted, o_priv_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
|
||||
{
|
||||
unsigned long code = ERR_get_error();
|
||||
printf( " failed\n ! RSA_public_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
|
||||
|
|
@ -255,4 +265,4 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C &&
|
||||
POLARSSL_X509_PARSE_C && POLARSSL_FS_IO */
|
||||
POLARSSL_PK_PARSE_C && POLARSSL_FS_IO */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue