Skip to content

Unsupported feature support #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/mbedtls/pk.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx );
*
* \note The key is also checked for correctness.
*
* \return 0 if successful, or a specific PK or PEM error code
* \return 0 if successful, or a specific PK, PEM or generic platform error code
*/
int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
const unsigned char *key, size_t keylen,
Expand All @@ -696,7 +696,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
*
* \note The key is also checked for correctness.
*
* \return 0 if successful, or a specific PK or PEM error code
* \return 0 if successful, or a specific PK, PEM or generic platform error code
*/
int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
const unsigned char *key, size_t keylen );
Expand All @@ -721,7 +721,7 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
*
* \note The key is also checked for correctness.
*
* \return 0 if successful, or a specific PK or PEM error code
* \return 0 if successful, or a specific PK, PEM or generic platform error code
*/
int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
const char *path, const char *password );
Expand All @@ -741,7 +741,7 @@ int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
*
* \note The key is also checked for correctness.
*
* \return 0 if successful, or a specific PK or PEM error code
* \return 0 if successful, or a specific PK, PEM or generic platform error code
*/
int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path );
#endif /* MBEDTLS_FS_IO */
Expand Down Expand Up @@ -819,7 +819,7 @@ int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_
* \param pk The PK context to fill. It must have been initialized
* but not set up.
*
* \return 0 if successful, or a specific PK error code
* \return 0 if successful, or a specific PK or generic platform error code
*/
int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
mbedtls_pk_context *pk );
Expand Down
27 changes: 26 additions & 1 deletion include/mbedtls/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,38 @@
extern "C" {
#endif

#define MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_CONTINUE( RET ) \
if( RET == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ) \
{ \
if( verbose != 0 ) \
mbedtls_printf( "skipped\n" ); \
continue; \
} \
else if( RET != 0 ) \
{ \
goto exit; \
}

#define MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( RET, VERBOSE ) \
if( RET == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ) \
{ \
if( VERBOSE != 0 ) \
mbedtls_printf( "skipped\n" ); \
break; \
} \
else if( RET != 0 ) \
{ \
goto exit; \
}

#if defined(MBEDTLS_PLATFORM_C)
/**
* \name SECTION: Module settings
*
* The configuration options you can set for this module are in this section.
* Either change them in config.h or define them on the compiler command line.
* \{
*/

/* The older Microsoft Windows common runtime provides non-conforming
* implementations of some standard library functions, including snprintf
* and vsnprintf. This affects MSVC and MinGW builds.
Expand Down Expand Up @@ -412,6 +436,7 @@ int mbedtls_platform_setup( mbedtls_platform_context *ctx );
*/
void mbedtls_platform_teardown( mbedtls_platform_context *ctx );

#endif /* MBEDTLS_PLATFORM_C */
#ifdef __cplusplus
}
#endif
Expand Down
107 changes: 30 additions & 77 deletions library/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@
#include "mbedtls/aesni.h"
#endif

#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#if defined(MBEDTLS_SELF_TEST)
#if !defined(MBEDTLS_PLATFORM_C)
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
Expand Down Expand Up @@ -1839,27 +1838,14 @@ int mbedtls_aes_self_test( int verbose )
aes_tests = aes_test_ecb_enc[u];
}

/*
* AES-192 is an optional feature that may be unavailable when
* there is an alternative underlying implementation i.e. when
* MBEDTLS_AES_ALT is defined.
*/
if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 )
{
mbedtls_printf( "skipped\n" );
continue;
}
else if( ret != 0 )
{
goto exit;
}
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_CONTINUE( ret );

for( j = 0; j < 10000; j++ )
{
ret = mbedtls_aes_crypt_ecb( &ctx, mode, buf, buf );
if( ret != 0 )
goto exit;
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, 0 );
}
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, verbose );

if( memcmp( buf, aes_tests, 16 ) != 0 )
{
Expand Down Expand Up @@ -1903,20 +1889,7 @@ int mbedtls_aes_self_test( int verbose )
aes_tests = aes_test_cbc_enc[u];
}

/*
* AES-192 is an optional feature that may be unavailable when
* there is an alternative underlying implementation i.e. when
* MBEDTLS_AES_ALT is defined.
*/
if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 )
{
mbedtls_printf( "skipped\n" );
continue;
}
else if( ret != 0 )
{
goto exit;
}
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_CONTINUE( ret );

for( j = 0; j < 10000; j++ )
{
Expand All @@ -1930,10 +1903,10 @@ int mbedtls_aes_self_test( int verbose )
}

ret = mbedtls_aes_crypt_cbc( &ctx, mode, 16, iv, buf, buf );
if( ret != 0 )
goto exit;
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, 0 );

}
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, verbose );

if( memcmp( buf, aes_tests, 16 ) != 0 )
{
Expand Down Expand Up @@ -1968,20 +1941,8 @@ int mbedtls_aes_self_test( int verbose )

offset = 0;
ret = mbedtls_aes_setkey_enc( &ctx, key, keybits );
/*
* AES-192 is an optional feature that may be unavailable when
* there is an alternative underlying implementation i.e. when
* MBEDTLS_AES_ALT is defined.
*/
if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 )
{
mbedtls_printf( "skipped\n" );
continue;
}
else if( ret != 0 )
{
goto exit;
}

MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_CONTINUE( ret );

if( mode == MBEDTLS_AES_DECRYPT )
{
Expand All @@ -1995,8 +1956,7 @@ int mbedtls_aes_self_test( int verbose )
}

ret = mbedtls_aes_crypt_cfb128( &ctx, mode, 64, &offset, iv, buf, buf );
if( ret != 0 )
goto exit;
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, verbose );

if( memcmp( buf, aes_tests, 64 ) != 0 )
{
Expand Down Expand Up @@ -2031,20 +1991,8 @@ int mbedtls_aes_self_test( int verbose )

offset = 0;
ret = mbedtls_aes_setkey_enc( &ctx, key, keybits );
/*
* AES-192 is an optional feature that may be unavailable when
* there is an alternative underlying implementation i.e. when
* MBEDTLS_AES_ALT is defined.
*/
if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 )
{
mbedtls_printf( "skipped\n" );
continue;
}
else if( ret != 0 )
{
goto exit;
}

MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_CONTINUE( ret );

if( mode == MBEDTLS_AES_DECRYPT )
{
Expand All @@ -2058,8 +2006,7 @@ int mbedtls_aes_self_test( int verbose )
}

ret = mbedtls_aes_crypt_ofb( &ctx, 64, &offset, iv, buf, buf );
if( ret != 0 )
goto exit;
MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, verbose );

if( memcmp( buf, aes_tests, 64 ) != 0 )
{
Expand Down Expand Up @@ -2110,8 +2057,8 @@ int mbedtls_aes_self_test( int verbose )

ret = mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter,
stream_block, buf, buf );
if( ret != 0 )
goto exit;

MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, verbose );

if( memcmp( buf, aes_tests, len ) != 0 )
{
Expand Down Expand Up @@ -2157,25 +2104,27 @@ int mbedtls_aes_self_test( int verbose )
if( mode == MBEDTLS_AES_DECRYPT )
{
ret = mbedtls_aes_xts_setkey_dec( &ctx_xts, key, 256 );
if( ret != 0)
goto exit;

MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_CONTINUE( ret );

memcpy( buf, aes_test_xts_ct32[u], len );
aes_tests = aes_test_xts_pt32[u];
}
else
{
ret = mbedtls_aes_xts_setkey_enc( &ctx_xts, key, 256 );
if( ret != 0)
goto exit;

MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_CONTINUE( ret );

memcpy( buf, aes_test_xts_pt32[u], len );
aes_tests = aes_test_xts_ct32[u];
}


ret = mbedtls_aes_crypt_xts( &ctx_xts, mode, len, data_unit,
buf, buf );
if( ret != 0 )
goto exit;

MBEDTLS_PLATFORM_SELF_TEST_CHECK_AND_BREAK( ret, verbose );

if( memcmp( buf, aes_tests, len ) != 0 )
{
Expand All @@ -2197,8 +2146,12 @@ int mbedtls_aes_self_test( int verbose )
ret = 0;

exit:
if( ret != 0 && verbose != 0 )
mbedtls_printf( "failed\n" );
if( ret != 0 )
{
ret = 1;
if( verbose != 0 )
mbedtls_printf( "failed\n" );
}

mbedtls_aes_free( &ctx );

Expand Down
Loading