mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-27 06:35:22 +00:00
Merge pull request #3994 from stevew817/feature/cmac_self_test_skip_unsupported
Allow CMAC self test to skip tests for unsupported primitives
This commit is contained in:
commit
594d7afa00
@ -45,22 +45,10 @@
|
|||||||
#include "mbedtls/cmac.h"
|
#include "mbedtls/cmac.h"
|
||||||
#include "mbedtls/platform_util.h"
|
#include "mbedtls/platform_util.h"
|
||||||
#include "mbedtls/error.h"
|
#include "mbedtls/error.h"
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#include "mbedtls/platform.h"
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#define mbedtls_calloc calloc
|
|
||||||
#define mbedtls_free free
|
|
||||||
#if defined(MBEDTLS_SELF_TEST)
|
|
||||||
#include <stdio.h>
|
|
||||||
#define mbedtls_printf printf
|
|
||||||
#endif /* MBEDTLS_SELF_TEST */
|
|
||||||
#endif /* MBEDTLS_PLATFORM_C */
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST)
|
#if !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -793,6 +781,18 @@ static int cmac_test_subkeys( int verbose,
|
|||||||
if( ( ret = mbedtls_cipher_setkey( &ctx, key, keybits,
|
if( ( ret = mbedtls_cipher_setkey( &ctx, key, keybits,
|
||||||
MBEDTLS_ENCRYPT ) ) != 0 )
|
MBEDTLS_ENCRYPT ) ) != 0 )
|
||||||
{
|
{
|
||||||
|
/* When CMAC is implemented by an alternative implementation, or
|
||||||
|
* the underlying primitive itself is implemented alternatively,
|
||||||
|
* AES-192 may be unavailable. This should not cause the selftest
|
||||||
|
* function to fail. */
|
||||||
|
if( ( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ||
|
||||||
|
ret == MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ) &&
|
||||||
|
cipher_type == MBEDTLS_CIPHER_AES_192_ECB ) {
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "skipped\n" );
|
||||||
|
goto next_test;
|
||||||
|
}
|
||||||
|
|
||||||
if( verbose != 0 )
|
if( verbose != 0 )
|
||||||
mbedtls_printf( "test execution failed\n" );
|
mbedtls_printf( "test execution failed\n" );
|
||||||
|
|
||||||
@ -820,6 +820,7 @@ static int cmac_test_subkeys( int verbose,
|
|||||||
if( verbose != 0 )
|
if( verbose != 0 )
|
||||||
mbedtls_printf( "passed\n" );
|
mbedtls_printf( "passed\n" );
|
||||||
|
|
||||||
|
next_test:
|
||||||
mbedtls_cipher_free( &ctx );
|
mbedtls_cipher_free( &ctx );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -864,6 +865,18 @@ static int cmac_test_wth_cipher( int verbose,
|
|||||||
if( ( ret = mbedtls_cipher_cmac( cipher_info, key, keybits, messages,
|
if( ( ret = mbedtls_cipher_cmac( cipher_info, key, keybits, messages,
|
||||||
message_lengths[i], output ) ) != 0 )
|
message_lengths[i], output ) ) != 0 )
|
||||||
{
|
{
|
||||||
|
/* When CMAC is implemented by an alternative implementation, or
|
||||||
|
* the underlying primitive itself is implemented alternatively,
|
||||||
|
* AES-192 may be unavailable. This should not cause the selftest
|
||||||
|
* function to fail. */
|
||||||
|
if( ( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ||
|
||||||
|
ret == MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ) &&
|
||||||
|
cipher_type == MBEDTLS_CIPHER_AES_192_ECB ) {
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "skipped\n" );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if( verbose != 0 )
|
if( verbose != 0 )
|
||||||
mbedtls_printf( "failed\n" );
|
mbedtls_printf( "failed\n" );
|
||||||
goto exit;
|
goto exit;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user