Add MBEDTLS_PRIVATE wrapping to sample programs.

Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
This commit is contained in:
Mateusz Starzyk 2021-05-19 19:35:35 +02:00
parent 6c2e9b6048
commit 5dd4f6e9ce
22 changed files with 91 additions and 76 deletions

View file

@ -128,7 +128,7 @@ int main( int argc, char *argv[] )
while( *list ) while( *list )
{ {
cipher_info = mbedtls_cipher_info_from_type( *list ); cipher_info = mbedtls_cipher_info_from_type( *list );
mbedtls_printf( " %s\n", cipher_info->name ); mbedtls_printf( " %s\n", cipher_info->MBEDTLS_PRIVATE(name) );
list++; list++;
} }
@ -313,7 +313,7 @@ int main( int argc, char *argv[] )
} }
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_bitlen, if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->MBEDTLS_PRIVATE(key_bitlen),
MBEDTLS_ENCRYPT ) != 0 ) MBEDTLS_ENCRYPT ) != 0 )
{ {
mbedtls_fprintf( stderr, "mbedtls_cipher_setkey() returned error\n"); mbedtls_fprintf( stderr, "mbedtls_cipher_setkey() returned error\n");
@ -412,7 +412,7 @@ int main( int argc, char *argv[] )
/* /*
* Check the file size. * Check the file size.
*/ */
if( cipher_info->mode != MBEDTLS_MODE_GCM && if( cipher_info->MBEDTLS_PRIVATE(mode) != MBEDTLS_MODE_GCM &&
( ( filesize - mbedtls_md_get_size( md_info ) ) % ( ( filesize - mbedtls_md_get_size( md_info ) ) %
mbedtls_cipher_get_block_size( &cipher_ctx ) ) != 0 ) mbedtls_cipher_get_block_size( &cipher_ctx ) ) != 0 )
{ {
@ -452,7 +452,7 @@ int main( int argc, char *argv[] )
mbedtls_md_finish( &md_ctx, digest ); mbedtls_md_finish( &md_ctx, digest );
} }
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_bitlen, if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->MBEDTLS_PRIVATE(key_bitlen),
MBEDTLS_DECRYPT ) != 0 ) MBEDTLS_DECRYPT ) != 0 )
{ {
mbedtls_fprintf( stderr, "mbedtls_cipher_setkey() returned error\n" ); mbedtls_fprintf( stderr, "mbedtls_cipher_setkey() returned error\n" );

View file

@ -127,15 +127,15 @@ int main( void )
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 ); mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
if( ( ret = mbedtls_mpi_read_file( &rsa.N, 16, f ) ) != 0 || if( ( ret = mbedtls_mpi_read_file( &rsa.MBEDTLS_PRIVATE(N), 16, f ) ) != 0 ||
( ret = mbedtls_mpi_read_file( &rsa.E, 16, f ) ) != 0 ) ( ret = mbedtls_mpi_read_file( &rsa.MBEDTLS_PRIVATE(E), 16, f ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret );
fclose( f ); fclose( f );
goto exit; goto exit;
} }
rsa.len = ( mbedtls_mpi_bitlen( &rsa.N ) + 7 ) >> 3; rsa.MBEDTLS_PRIVATE(len) = ( mbedtls_mpi_bitlen( &rsa.MBEDTLS_PRIVATE(N) ) + 7 ) >> 3;
fclose( f ); fclose( f );
@ -193,7 +193,7 @@ int main( void )
goto exit; goto exit;
} }
if( dhm.len < 64 || dhm.len > 512 ) if( dhm.MBEDTLS_PRIVATE(len) < 64 || dhm.MBEDTLS_PRIVATE(len) > 512 )
{ {
mbedtls_printf( " failed\n ! Invalid DHM modulus size\n\n" ); mbedtls_printf( " failed\n ! Invalid DHM modulus size\n\n" );
goto exit; goto exit;
@ -208,7 +208,7 @@ int main( void )
p += 2; p += 2;
if( ( n = (size_t) ( end - p ) ) != rsa.len ) if( ( n = (size_t) ( end - p ) ) != rsa.MBEDTLS_PRIVATE(len) )
{ {
mbedtls_printf( " failed\n ! Invalid RSA signature size\n\n" ); mbedtls_printf( " failed\n ! Invalid RSA signature size\n\n" );
goto exit; goto exit;
@ -233,8 +233,8 @@ int main( void )
mbedtls_printf( "\n . Sending own public value to server" ); mbedtls_printf( "\n . Sending own public value to server" );
fflush( stdout ); fflush( stdout );
n = dhm.len; n = dhm.MBEDTLS_PRIVATE(len);
if( ( ret = mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, n, if( ( ret = mbedtls_dhm_make_public( &dhm, (int) dhm.MBEDTLS_PRIVATE(len), buf, n,
mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 ) mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_dhm_make_public returned %d\n\n", ret ); mbedtls_printf( " failed\n ! mbedtls_dhm_make_public returned %d\n\n", ret );

View file

@ -173,8 +173,8 @@ int main( void )
goto exit; goto exit;
} }
if( mbedtls_mpi_read_file( &dhm.P, 16, f ) != 0 || if( mbedtls_mpi_read_file( &dhm.MBEDTLS_PRIVATE(P), 16, f ) != 0 ||
mbedtls_mpi_read_file( &dhm.G, 16, f ) != 0 ) mbedtls_mpi_read_file( &dhm.MBEDTLS_PRIVATE(G), 16, f ) != 0 )
{ {
mbedtls_printf( " failed\n ! Invalid DH parameter file\n\n" ); mbedtls_printf( " failed\n ! Invalid DH parameter file\n\n" );
fclose( f ); fclose( f );
@ -210,7 +210,7 @@ int main( void )
memset( buf, 0, sizeof( buf ) ); memset( buf, 0, sizeof( buf ) );
if( ( ret = mbedtls_dhm_make_params( &dhm, (int) mbedtls_mpi_size( &dhm.P ), buf, &n, if( ( ret = mbedtls_dhm_make_params( &dhm, (int) mbedtls_mpi_size( &dhm.MBEDTLS_PRIVATE(P) ), buf, &n,
mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 ) mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_dhm_make_params returned %d\n\n", ret ); mbedtls_printf( " failed\n ! mbedtls_dhm_make_params returned %d\n\n", ret );
@ -226,8 +226,8 @@ int main( void )
goto exit; goto exit;
} }
buf[n ] = (unsigned char)( rsa.len >> 8 ); buf[n ] = (unsigned char)( rsa.MBEDTLS_PRIVATE(len) >> 8 );
buf[n + 1] = (unsigned char)( rsa.len ); buf[n + 1] = (unsigned char)( rsa.MBEDTLS_PRIVATE(len) );
if( ( ret = mbedtls_rsa_pkcs1_sign( &rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA256, if( ( ret = mbedtls_rsa_pkcs1_sign( &rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA256,
0, hash, buf + n + 2 ) ) != 0 ) 0, hash, buf + n + 2 ) ) != 0 )
@ -236,7 +236,7 @@ int main( void )
goto exit; goto exit;
} }
buflen = n + 2 + rsa.len; buflen = n + 2 + rsa.MBEDTLS_PRIVATE(len);
buf2[0] = (unsigned char)( buflen >> 8 ); buf2[0] = (unsigned char)( buflen >> 8 );
buf2[1] = (unsigned char)( buflen ); buf2[1] = (unsigned char)( buflen );
@ -255,14 +255,14 @@ int main( void )
memset( buf, 0, sizeof( buf ) ); memset( buf, 0, sizeof( buf ) );
n = dhm.len; n = dhm.MBEDTLS_PRIVATE(len);
if( ( ret = mbedtls_net_recv( &client_fd, buf, n ) ) != (int) n ) if( ( ret = mbedtls_net_recv( &client_fd, buf, n ) ) != (int) n )
{ {
mbedtls_printf( " failed\n ! mbedtls_net_recv returned %d\n\n", ret ); mbedtls_printf( " failed\n ! mbedtls_net_recv returned %d\n\n", ret );
goto exit; goto exit;
} }
if( ( ret = mbedtls_dhm_read_public( &dhm, buf, dhm.len ) ) != 0 ) if( ( ret = mbedtls_dhm_read_public( &dhm, buf, dhm.MBEDTLS_PRIVATE(len) ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_dhm_read_public returned %d\n\n", ret ); mbedtls_printf( " failed\n ! mbedtls_dhm_read_public returned %d\n\n", ret );
goto exit; goto exit;

View file

@ -91,14 +91,14 @@ int main( int argc, char *argv[] )
mbedtls_printf( " . Setting up client context..." ); mbedtls_printf( " . Setting up client context..." );
fflush( stdout ); fflush( stdout );
ret = mbedtls_ecp_group_load( &ctx_cli.grp, MBEDTLS_ECP_DP_CURVE25519 ); ret = mbedtls_ecp_group_load( &ctx_cli.MBEDTLS_PRIVATE(grp), MBEDTLS_ECP_DP_CURVE25519 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_ecp_group_load returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_ecp_group_load returned %d\n", ret );
goto exit; goto exit;
} }
ret = mbedtls_ecdh_gen_public( &ctx_cli.grp, &ctx_cli.d, &ctx_cli.Q, ret = mbedtls_ecdh_gen_public( &ctx_cli.MBEDTLS_PRIVATE(grp), &ctx_cli.MBEDTLS_PRIVATE(d), &ctx_cli.MBEDTLS_PRIVATE(Q),
mbedtls_ctr_drbg_random, &ctr_drbg ); mbedtls_ctr_drbg_random, &ctr_drbg );
if( ret != 0 ) if( ret != 0 )
{ {
@ -106,7 +106,7 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
ret = mbedtls_mpi_write_binary( &ctx_cli.Q.X, cli_to_srv, 32 ); ret = mbedtls_mpi_write_binary( &ctx_cli.MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), cli_to_srv, 32 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_write_binary returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_write_binary returned %d\n", ret );
@ -121,14 +121,14 @@ int main( int argc, char *argv[] )
mbedtls_printf( " . Setting up server context..." ); mbedtls_printf( " . Setting up server context..." );
fflush( stdout ); fflush( stdout );
ret = mbedtls_ecp_group_load( &ctx_srv.grp, MBEDTLS_ECP_DP_CURVE25519 ); ret = mbedtls_ecp_group_load( &ctx_srv.MBEDTLS_PRIVATE(grp), MBEDTLS_ECP_DP_CURVE25519 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_ecp_group_load returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_ecp_group_load returned %d\n", ret );
goto exit; goto exit;
} }
ret = mbedtls_ecdh_gen_public( &ctx_srv.grp, &ctx_srv.d, &ctx_srv.Q, ret = mbedtls_ecdh_gen_public( &ctx_srv.MBEDTLS_PRIVATE(grp), &ctx_srv.MBEDTLS_PRIVATE(d), &ctx_srv.MBEDTLS_PRIVATE(Q),
mbedtls_ctr_drbg_random, &ctr_drbg ); mbedtls_ctr_drbg_random, &ctr_drbg );
if( ret != 0 ) if( ret != 0 )
{ {
@ -136,7 +136,7 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
ret = mbedtls_mpi_write_binary( &ctx_srv.Q.X, srv_to_cli, 32 ); ret = mbedtls_mpi_write_binary( &ctx_srv.MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), srv_to_cli, 32 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_write_binary returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_write_binary returned %d\n", ret );
@ -151,22 +151,22 @@ int main( int argc, char *argv[] )
mbedtls_printf( " . Server reading client key and computing secret..." ); mbedtls_printf( " . Server reading client key and computing secret..." );
fflush( stdout ); fflush( stdout );
ret = mbedtls_mpi_lset( &ctx_srv.Qp.Z, 1 ); ret = mbedtls_mpi_lset( &ctx_srv.MBEDTLS_PRIVATE(Qp).MBEDTLS_PRIVATE(Z), 1 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_lset returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_lset returned %d\n", ret );
goto exit; goto exit;
} }
ret = mbedtls_mpi_read_binary( &ctx_srv.Qp.X, cli_to_srv, 32 ); ret = mbedtls_mpi_read_binary( &ctx_srv.MBEDTLS_PRIVATE(Qp).MBEDTLS_PRIVATE(X), cli_to_srv, 32 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_read_binary returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_read_binary returned %d\n", ret );
goto exit; goto exit;
} }
ret = mbedtls_ecdh_compute_shared( &ctx_srv.grp, &ctx_srv.z, ret = mbedtls_ecdh_compute_shared( &ctx_srv.MBEDTLS_PRIVATE(grp), &ctx_srv.MBEDTLS_PRIVATE(z),
&ctx_srv.Qp, &ctx_srv.d, &ctx_srv.MBEDTLS_PRIVATE(Qp), &ctx_srv.MBEDTLS_PRIVATE(d),
mbedtls_ctr_drbg_random, &ctr_drbg ); mbedtls_ctr_drbg_random, &ctr_drbg );
if( ret != 0 ) if( ret != 0 )
{ {
@ -182,22 +182,22 @@ int main( int argc, char *argv[] )
mbedtls_printf( " . Client reading server key and computing secret..." ); mbedtls_printf( " . Client reading server key and computing secret..." );
fflush( stdout ); fflush( stdout );
ret = mbedtls_mpi_lset( &ctx_cli.Qp.Z, 1 ); ret = mbedtls_mpi_lset( &ctx_cli.MBEDTLS_PRIVATE(Qp).MBEDTLS_PRIVATE(Z), 1 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_lset returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_lset returned %d\n", ret );
goto exit; goto exit;
} }
ret = mbedtls_mpi_read_binary( &ctx_cli.Qp.X, srv_to_cli, 32 ); ret = mbedtls_mpi_read_binary( &ctx_cli.MBEDTLS_PRIVATE(Qp).MBEDTLS_PRIVATE(X), srv_to_cli, 32 );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_read_binary returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_read_binary returned %d\n", ret );
goto exit; goto exit;
} }
ret = mbedtls_ecdh_compute_shared( &ctx_cli.grp, &ctx_cli.z, ret = mbedtls_ecdh_compute_shared( &ctx_cli.MBEDTLS_PRIVATE(grp), &ctx_cli.MBEDTLS_PRIVATE(z),
&ctx_cli.Qp, &ctx_cli.d, &ctx_cli.MBEDTLS_PRIVATE(Qp), &ctx_cli.MBEDTLS_PRIVATE(d),
mbedtls_ctr_drbg_random, &ctr_drbg ); mbedtls_ctr_drbg_random, &ctr_drbg );
if( ret != 0 ) if( ret != 0 )
{ {
@ -213,7 +213,7 @@ int main( int argc, char *argv[] )
mbedtls_printf( " . Checking if both computed secrets are equal..." ); mbedtls_printf( " . Checking if both computed secrets are equal..." );
fflush( stdout ); fflush( stdout );
ret = mbedtls_mpi_cmp_mpi( &ctx_cli.z, &ctx_srv.z ); ret = mbedtls_mpi_cmp_mpi( &ctx_cli.MBEDTLS_PRIVATE(z), &ctx_srv.MBEDTLS_PRIVATE(z) );
if( ret != 0 ) if( ret != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_ecdh_compute_shared returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_ecdh_compute_shared returned %d\n", ret );

View file

@ -55,7 +55,7 @@
#define ECPARAMS MBEDTLS_ECP_DP_SECP192R1 #define ECPARAMS MBEDTLS_ECP_DP_SECP192R1
#if !defined(ECPARAMS) #if !defined(ECPARAMS)
#define ECPARAMS mbedtls_ecp_curve_list()->grp_id #define ECPARAMS mbedtls_ecp_curve_list()->MBEDTLS_PRIVATE(grp_id)
#endif #endif
#if !defined(MBEDTLS_ECDSA_C) || !defined(MBEDTLS_SHA256_C) || \ #if !defined(MBEDTLS_ECDSA_C) || !defined(MBEDTLS_SHA256_C) || \
@ -84,7 +84,7 @@ static void dump_pubkey( const char *title, mbedtls_ecdsa_context *key )
unsigned char buf[300]; unsigned char buf[300];
size_t len; size_t len;
if( mbedtls_ecp_point_write_binary( &key->grp, &key->Q, if( mbedtls_ecp_point_write_binary( &key->MBEDTLS_PRIVATE(grp), &key->MBEDTLS_PRIVATE(Q),
MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof buf ) != 0 ) MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof buf ) != 0 )
{ {
mbedtls_printf("internal error\n"); mbedtls_printf("internal error\n");
@ -156,7 +156,7 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
mbedtls_printf( " ok (key size: %d bits)\n", (int) ctx_sign.grp.pbits ); mbedtls_printf( " ok (key size: %d bits)\n", (int) ctx_sign.MBEDTLS_PRIVATE(grp).MBEDTLS_PRIVATE(pbits) );
dump_pubkey( " + Public key: ", &ctx_sign ); dump_pubkey( " + Public key: ", &ctx_sign );
@ -204,13 +204,13 @@ int main( int argc, char *argv[] )
mbedtls_printf( " . Preparing verification context..." ); mbedtls_printf( " . Preparing verification context..." );
fflush( stdout ); fflush( stdout );
if( ( ret = mbedtls_ecp_group_copy( &ctx_verify.grp, &ctx_sign.grp ) ) != 0 ) if( ( ret = mbedtls_ecp_group_copy( &ctx_verify.MBEDTLS_PRIVATE(grp), &ctx_sign.MBEDTLS_PRIVATE(grp) ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_ecp_group_copy returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_ecp_group_copy returned %d\n", ret );
goto exit; goto exit;
} }
if( ( ret = mbedtls_ecp_copy( &ctx_verify.Q, &ctx_sign.Q ) ) != 0 ) if( ( ret = mbedtls_ecp_copy( &ctx_verify.MBEDTLS_PRIVATE(Q), &ctx_sign.MBEDTLS_PRIVATE(Q) ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_ecp_copy returned %d\n", ret ); mbedtls_printf( " failed\n ! mbedtls_ecp_copy returned %d\n", ret );
goto exit; goto exit;

View file

@ -90,7 +90,7 @@ int dev_random_entropy_poll( void *data, unsigned char *output,
#endif #endif
#if defined(MBEDTLS_ECP_C) #if defined(MBEDTLS_ECP_C)
#define DFL_EC_CURVE mbedtls_ecp_curve_list()->grp_id #define DFL_EC_CURVE mbedtls_ecp_curve_list()->MBEDTLS_PRIVATE(grp_id)
#else #else
#define DFL_EC_CURVE 0 #define DFL_EC_CURVE 0
#endif #endif
@ -223,9 +223,9 @@ int main( int argc, char *argv[] )
#if defined(MBEDTLS_ECP_C) #if defined(MBEDTLS_ECP_C)
mbedtls_printf( " available ec_curve values:\n" ); mbedtls_printf( " available ec_curve values:\n" );
curve_info = mbedtls_ecp_curve_list(); curve_info = mbedtls_ecp_curve_list();
mbedtls_printf( " %s (default)\n", curve_info->name ); mbedtls_printf( " %s (default)\n", curve_info->MBEDTLS_PRIVATE(name) );
while( ( ++curve_info )->name != NULL ) while( ( ++curve_info )->MBEDTLS_PRIVATE(name) != NULL )
mbedtls_printf( " %s\n", curve_info->name ); mbedtls_printf( " %s\n", curve_info->MBEDTLS_PRIVATE(name) );
#endif /* MBEDTLS_ECP_C */ #endif /* MBEDTLS_ECP_C */
goto exit; goto exit;
} }
@ -274,7 +274,7 @@ int main( int argc, char *argv[] )
{ {
if( ( curve_info = mbedtls_ecp_curve_info_from_name( q ) ) == NULL ) if( ( curve_info = mbedtls_ecp_curve_info_from_name( q ) ) == NULL )
goto usage; goto usage;
opt.ec_curve = curve_info->grp_id; opt.ec_curve = curve_info->MBEDTLS_PRIVATE(grp_id);
} }
#endif #endif
else if( strcmp( p, "filename" ) == 0 ) else if( strcmp( p, "filename" ) == 0 )
@ -395,10 +395,10 @@ int main( int argc, char *argv[] )
{ {
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( key ); mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( key );
mbedtls_printf( "curve: %s\n", mbedtls_printf( "curve: %s\n",
mbedtls_ecp_curve_info_from_grp_id( ecp->grp.id )->name ); mbedtls_ecp_curve_info_from_grp_id( ecp->MBEDTLS_PRIVATE(grp).MBEDTLS_PRIVATE(id) )->MBEDTLS_PRIVATE(name) );
mbedtls_mpi_write_file( "X_Q: ", &ecp->Q.X, 16, NULL ); mbedtls_mpi_write_file( "X_Q: ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL );
mbedtls_mpi_write_file( "Y_Q: ", &ecp->Q.Y, 16, NULL ); mbedtls_mpi_write_file( "Y_Q: ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL );
mbedtls_mpi_write_file( "D: ", &ecp->d , 16, NULL ); mbedtls_mpi_write_file( "D: ", &ecp->MBEDTLS_PRIVATE(d) , 16, NULL );
} }
else else
#endif #endif

View file

@ -222,10 +222,10 @@ int main( int argc, char *argv[] )
if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY ) if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY )
{ {
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pk ); mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pk );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(X): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Y): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Z): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16, NULL ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "D : ", &ecp->d , 16, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "D : ", &ecp->MBEDTLS_PRIVATE(d) , 16, NULL ) );
} }
else else
#endif #endif
@ -273,9 +273,9 @@ int main( int argc, char *argv[] )
if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY ) if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY )
{ {
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pk ); mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pk );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(X): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Y): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( "Q(Z): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16, NULL ) );
} }
else else
#endif #endif

View file

@ -335,10 +335,10 @@ int main( int argc, char *argv[] )
if( mbedtls_pk_get_type( &key ) == MBEDTLS_PK_ECKEY ) if( mbedtls_pk_get_type( &key ) == MBEDTLS_PK_ECKEY )
{ {
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( key ); mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( key );
mbedtls_mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL ); mbedtls_mpi_write_file( "Q(X): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL );
mbedtls_mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL ); mbedtls_mpi_write_file( "Q(Y): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL );
mbedtls_mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL ); mbedtls_mpi_write_file( "Q(Z): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16, NULL );
mbedtls_mpi_write_file( "D : ", &ecp->d , 16, NULL ); mbedtls_mpi_write_file( "D : ", &ecp->MBEDTLS_PRIVATE(d) , 16, NULL );
} }
else else
#endif #endif
@ -389,9 +389,9 @@ int main( int argc, char *argv[] )
if( mbedtls_pk_get_type( &key ) == MBEDTLS_PK_ECKEY ) if( mbedtls_pk_get_type( &key ) == MBEDTLS_PK_ECKEY )
{ {
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( key ); mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( key );
mbedtls_mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL ); mbedtls_mpi_write_file( "Q(X): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL );
mbedtls_mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL ); mbedtls_mpi_write_file( "Q(Y): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL );
mbedtls_mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL ); mbedtls_mpi_write_file( "Q(Z): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16, NULL );
} }
else else
#endif #endif

View file

@ -164,7 +164,7 @@ int main( int argc, char *argv[] )
fclose( f ); fclose( f );
if( i != rsa.len ) if( i != rsa.MBEDTLS_PRIVATE(len) )
{ {
mbedtls_printf( "\n ! Invalid RSA signature format\n\n" ); mbedtls_printf( "\n ! Invalid RSA signature format\n\n" );
goto exit; goto exit;

View file

@ -161,7 +161,7 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
for( i = 0; i < rsa.len; i++ ) for( i = 0; i < rsa.MBEDTLS_PRIVATE(len); i++ )
mbedtls_fprintf( f, "%02X%s", buf[i], mbedtls_fprintf( f, "%02X%s", buf[i],
( i + 1 ) % 16 == 0 ? "\r\n" : " " ); ( i + 1 ) % 16 == 0 ? "\r\n" : " " );

View file

@ -164,7 +164,7 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
for( i = 0; i < rsa.len; i++ ) for( i = 0; i < rsa.MBEDTLS_PRIVATE(len); i++ )
mbedtls_fprintf( f, "%02X%s", buf[i], mbedtls_fprintf( f, "%02X%s", buf[i],
( i + 1 ) % 16 == 0 ? "\r\n" : " " ); ( i + 1 ) % 16 == 0 ? "\r\n" : " " );

View file

@ -89,15 +89,15 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
if( ( ret = mbedtls_mpi_read_file( &rsa.N, 16, f ) ) != 0 || if( ( ret = mbedtls_mpi_read_file( &rsa.MBEDTLS_PRIVATE(N), 16, f ) ) != 0 ||
( ret = mbedtls_mpi_read_file( &rsa.E, 16, f ) ) != 0 ) ( ret = mbedtls_mpi_read_file( &rsa.MBEDTLS_PRIVATE(E), 16, f ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret ); mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret );
fclose( f ); fclose( f );
goto exit; goto exit;
} }
rsa.len = ( mbedtls_mpi_bitlen( &rsa.N ) + 7 ) >> 3; rsa.MBEDTLS_PRIVATE(len) = ( mbedtls_mpi_bitlen( &rsa.MBEDTLS_PRIVATE(N) ) + 7 ) >> 3;
fclose( f ); fclose( f );
@ -119,7 +119,7 @@ int main( int argc, char *argv[] )
fclose( f ); fclose( f );
if( i != rsa.len ) if( i != rsa.MBEDTLS_PRIVATE(len) )
{ {
mbedtls_printf( "\n ! Invalid RSA signature format\n\n" ); mbedtls_printf( "\n ! Invalid RSA signature format\n\n" );
goto exit; goto exit;

View file

@ -17,6 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#if !defined(MBEDTLS_CONFIG_FILE) #if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h" #include "mbedtls/config.h"
#else #else

View file

@ -17,6 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#if !defined(MBEDTLS_CONFIG_FILE) #if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h" #include "mbedtls/config.h"
#else #else

View file

@ -18,6 +18,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#if !defined(MBEDTLS_CONFIG_FILE) #if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h" #include "mbedtls/config.h"
#else #else

View file

@ -17,6 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#if !defined(MBEDTLS_CONFIG_FILE) #if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h" #include "mbedtls/config.h"
#else #else

View file

@ -17,6 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#if !defined(MBEDTLS_CONFIG_FILE) #if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h" #include "mbedtls/config.h"
#else #else

View file

@ -20,6 +20,9 @@
/* Enable definition of gethostname() even when compiling with -std=c99. Must /* Enable definition of gethostname() even when compiling with -std=c99. Must
* be set before config.h, which pulls in glibc's features.h indirectly. * be set before config.h, which pulls in glibc's features.h indirectly.
* Harmless on other platforms. */ * Harmless on other platforms. */
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 600 #define _XOPEN_SOURCE 600

View file

@ -17,6 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#if !defined(MBEDTLS_CONFIG_FILE) #if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h" #include "mbedtls/config.h"
#else #else

View file

@ -805,7 +805,7 @@ int sni_callback( void *p_info, mbedtls_ssl_context *ssl,
return( mbedtls_ssl_set_hs_own_cert( ssl, cur->cert, cur->key ) ); return( mbedtls_ssl_set_hs_own_cert( ssl, cur->cert, cur->key ) );
} }
cur = cur->next; cur = cur->MBEDTLS_PRIVATE(next);
} }
return( -1 ); return( -1 );
@ -921,7 +921,7 @@ int psk_callback( void *p_info, mbedtls_ssl_context *ssl,
return( mbedtls_ssl_set_hs_psk( ssl, cur->key, cur->key_len ) ); return( mbedtls_ssl_set_hs_psk( ssl, cur->key, cur->key_len ) );
} }
cur = cur->next; cur = cur->MBEDTLS_PRIVATE(next);
} }
return( -1 ); return( -1 );

View file

@ -335,7 +335,7 @@ int main( int argc, char *argv[] )
mbedtls_printf( "%s\n", buf ); mbedtls_printf( "%s\n", buf );
cur = cur->next; cur = cur->MBEDTLS_PRIVATE(next);
} }
/* /*

View file

@ -518,7 +518,7 @@ int main( int argc, char *argv[] )
} }
ret = mbedtls_x509_dn_gets( issuer_name, sizeof(issuer_name), ret = mbedtls_x509_dn_gets( issuer_name, sizeof(issuer_name),
&issuer_crt.subject ); &issuer_crt.MBEDTLS_PRIVATE(subject) );
if( ret < 0 ) if( ret < 0 )
{ {
mbedtls_strerror( ret, buf, 1024 ); mbedtls_strerror( ret, buf, 1024 );
@ -552,7 +552,7 @@ int main( int argc, char *argv[] )
} }
ret = mbedtls_x509_dn_gets( subject_name, sizeof(subject_name), ret = mbedtls_x509_dn_gets( subject_name, sizeof(subject_name),
&csr.subject ); &csr.MBEDTLS_PRIVATE(subject) );
if( ret < 0 ) if( ret < 0 )
{ {
mbedtls_strerror( ret, buf, 1024 ); mbedtls_strerror( ret, buf, 1024 );
@ -562,7 +562,7 @@ int main( int argc, char *argv[] )
} }
opt.subject_name = subject_name; opt.subject_name = subject_name;
subject_key = &csr.pk; subject_key = &csr.MBEDTLS_PRIVATE(pk);
mbedtls_printf( " ok\n" ); mbedtls_printf( " ok\n" );
} }
@ -606,7 +606,7 @@ int main( int argc, char *argv[] )
// //
if( strlen( opt.issuer_crt ) ) if( strlen( opt.issuer_crt ) )
{ {
if( mbedtls_pk_check_pair( &issuer_crt.pk, issuer_key ) != 0 ) if( mbedtls_pk_check_pair( &issuer_crt.MBEDTLS_PRIVATE(pk), issuer_key ) != 0 )
{ {
mbedtls_printf( " failed\n ! issuer_key does not match " mbedtls_printf( " failed\n ! issuer_key does not match "
"issuer certificate\n\n" ); "issuer certificate\n\n" );