Astyle fixes for the source

Used running: astyle -n --options=.astylerc
pull/8804/head
mohammad1603 2018-11-26 23:32:45 +02:00
parent 5c2cf07780
commit 88f4f48fac
6 changed files with 1485 additions and 1495 deletions

View File

@ -52,10 +52,11 @@ static void check_multi_crypto_init_deinit()
uint8_t output[TEST_RANDOM_SIZE] = {0};
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
/* inject some a seed for test*/
for(int i; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i)
for (int i; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
seed[i] = i;
}
/* don't really care if this succeed this is just to make crypto init pass*/
mbedtls_psa_inject_entropy( seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE );
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
psa_status_t status = psa_crypto_init();
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
status = psa_crypto_init();
@ -76,10 +77,11 @@ static void check_crypto_init_deinit()
uint8_t output[TEST_RANDOM_SIZE] = {0};
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
/* inject some a seed for test*/
for(int i; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i)
for (int i; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
seed[i] = i;
}
/* don't really care if this succeed this is just to make crypto init pass*/
mbedtls_psa_inject_entropy( seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE );
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
status = psa_generate_random(output, sizeof(output));
TEST_ASSERT_EQUAL(PSA_ERROR_BAD_STATE, status);
status = psa_crypto_init();

View File

@ -40,41 +40,41 @@
using namespace utest::v1;
uint8_t seed[MBEDTLS_ENTROPY_MAX_SEED_SIZE+2] = {0};
uint8_t seed[MBEDTLS_ENTROPY_MAX_SEED_SIZE + 2] = {0};
void validate_entropy_seed_injection( int seed_length_a,
int expected_status_a,
int seed_length_b,
int expected_status_b )
void validate_entropy_seed_injection(int seed_length_a,
int expected_status_a,
int seed_length_b,
int expected_status_b)
{
psa_status_t status;
uint8_t output[32] = { 0 };
uint8_t zeros[32] = { 0 };
status = mbedtls_psa_inject_entropy( seed, seed_length_a );
TEST_ASSERT( status == expected_status_a );
status = mbedtls_psa_inject_entropy( seed, seed_length_b );
TEST_ASSERT( status == expected_status_b );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_generate_random( output, sizeof( output ) ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( output , zeros, sizeof( output ) ) != 0 );
status = mbedtls_psa_inject_entropy(seed, seed_length_a);
TEST_ASSERT(status == expected_status_a);
status = mbedtls_psa_inject_entropy(seed, seed_length_b);
TEST_ASSERT(status == expected_status_b);
TEST_ASSERT(psa_crypto_init() == PSA_SUCCESS);
TEST_ASSERT(psa_generate_random(output, sizeof(output)) == PSA_SUCCESS);
TEST_ASSERT(memcmp(output, zeros, sizeof(output)) != 0);
}
void run_entropy_inject_with_crypto_init( )
void run_entropy_inject_with_crypto_init()
{
psa_its_status_t its_status;
psa_status_t status;
status = psa_crypto_init();
TEST_ASSERT( status == PSA_ERROR_INSUFFICIENT_ENTROPY );
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE );
TEST_ASSERT( status == PSA_SUCCESS );
TEST_ASSERT(status == PSA_ERROR_INSUFFICIENT_ENTROPY);
status = mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
TEST_ASSERT(status == PSA_SUCCESS);
status = psa_crypto_init();
TEST_ASSERT( status == PSA_SUCCESS );
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE );
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
mbedtls_psa_crypto_free( );
TEST_ASSERT(status == PSA_SUCCESS);
status = mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
TEST_ASSERT(status == PSA_ERROR_NOT_PERMITTED);
mbedtls_psa_crypto_free();
/* The seed is written by nv_seed callback functions therefore the injection will fail */
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE );
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
status = mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
TEST_ASSERT(status == PSA_ERROR_NOT_PERMITTED);
}
@ -88,7 +88,7 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
static void injection_small_good()
{
validate_entropy_seed_injection( MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_ERROR_NOT_PERMITTED);
validate_entropy_seed_injection(MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_ERROR_NOT_PERMITTED);
}
static void injection_big_good()
@ -113,14 +113,14 @@ static void injection_and_init_deinit()
/***************************************************************************************/
/***************************************************************************************/
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
{
psa_status_t status;
status = test_psa_its_reset();
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
mbedtls_psa_crypto_free( );
mbedtls_psa_crypto_free();
return greentea_case_teardown_handler(source, passed, failed, reason);
}
@ -130,8 +130,7 @@ utest::v1::status_t case_setup_handler(const Case *const source, const size_t in
status = test_psa_its_reset();
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
/* fill seed in some data */
for( size_t i = 0; i < MBEDTLS_ENTROPY_MAX_SEED_SIZE+2; ++i)
{
for (size_t i = 0; i < MBEDTLS_ENTROPY_MAX_SEED_SIZE + 2; ++i) {
seed[i] = i;
}
return greentea_case_setup_handler(source, index_of_case);

View File

@ -38,8 +38,7 @@
*/
/** \brief psa_s_function_t enum defines for all the available functions in PSA Crypto. */
typedef enum psa_sec_function_s
{
typedef enum psa_sec_function_s {
PSA_CRYPTO_INVALID,
PSA_CRYPTO_INIT,
PSA_IMPORT_KEY,
@ -87,7 +86,7 @@ typedef enum psa_sec_function_s
PSA_GENERATOR_ABORT,
PSA_KEY_DERIVATION,
PSA_KEY_AGREEMENT
}psa_sec_function_t;
} psa_sec_function_t;
/**@}*/
@ -101,8 +100,7 @@ typedef enum psa_sec_function_s
* pack them together.
*/
typedef struct psa_crypto_ipc_s
{
typedef struct psa_crypto_ipc_s {
psa_sec_function_t func;
psa_key_slot_t key;
psa_algorithm_t alg;
@ -113,8 +111,7 @@ typedef struct psa_crypto_ipc_s
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
* pack them together.
*/
typedef struct psa_crypto_derivation_ipc_s
{
typedef struct psa_crypto_derivation_ipc_s {
psa_sec_function_t func;
psa_key_slot_t key;
psa_algorithm_t alg;
@ -127,8 +124,7 @@ typedef struct psa_crypto_derivation_ipc_s
* pack them together.
*/
typedef struct psa_key_mng_ipc_s
{
typedef struct psa_key_mng_ipc_s {
psa_key_slot_t key;
psa_key_type_t type;
psa_sec_function_t func;
@ -142,8 +138,7 @@ typedef struct psa_key_mng_ipc_s
// Max length supported for nonce is 16 bytes.
#define PSA_AEAD_MAX_NONCE_SIZE 16
typedef struct psa_crypto_ipc_aead_s
{
typedef struct psa_crypto_ipc_aead_s {
psa_sec_function_t func;
psa_key_slot_t key;
psa_algorithm_t alg;
@ -158,8 +153,7 @@ typedef struct psa_crypto_ipc_aead_s
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
* pack them together.
*/
typedef struct psa_crypto_ipc_asymmetric_s
{
typedef struct psa_crypto_ipc_asymmetric_s {
psa_sec_function_t func;
psa_key_slot_t key;
psa_algorithm_t alg;

View File

@ -27,39 +27,33 @@
#ifndef PSA_CRYPTO_STRUCT_H
#define PSA_CRYPTO_STRUCT_H
struct psa_hash_operation_s
{
struct psa_hash_operation_s {
psa_handle_t handle;
};
struct psa_mac_operation_s
{
struct psa_mac_operation_s {
psa_handle_t handle;
};
struct psa_cipher_operation_s
{
struct psa_cipher_operation_s {
psa_handle_t handle;
};
struct psa_aead_operation_s
{
struct psa_aead_operation_s {
psa_handle_t handle;
};
struct psa_crypto_generator_s
{
struct psa_crypto_generator_s {
psa_handle_t handle;
};
static inline struct psa_crypto_generator_s psa_crypto_generator_init( void )
static inline struct psa_crypto_generator_s psa_crypto_generator_init(void)
{
const struct psa_crypto_generator_s v = { 0 };
return( v );
return (v);
}
struct psa_key_policy_s
{
struct psa_key_policy_s {
psa_key_usage_t usage;
psa_algorithm_t alg;
};