mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -43,8 +43,8 @@
|
||||
*
|
||||
* \return \c 0 if the test failed, otherwise 1.
|
||||
*/
|
||||
int mbedtls_test_asn1_skip_integer( unsigned char **p, const unsigned char *end,
|
||||
size_t min_bits, size_t max_bits,
|
||||
int must_be_odd );
|
||||
int mbedtls_test_asn1_skip_integer(unsigned char **p, const unsigned char *end,
|
||||
size_t min_bits, size_t max_bits,
|
||||
int must_be_odd);
|
||||
|
||||
#endif /* ASN1_HELPERS_H */
|
||||
|
@@ -41,10 +41,10 @@ typedef struct {
|
||||
|
||||
#define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0 }
|
||||
static inline mbedtls_test_driver_aead_hooks_t
|
||||
mbedtls_test_driver_aead_hooks_init( void )
|
||||
mbedtls_test_driver_aead_hooks_init(void)
|
||||
{
|
||||
const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT;
|
||||
return( v );
|
||||
return v;
|
||||
}
|
||||
|
||||
extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks;
|
||||
@@ -56,7 +56,7 @@ psa_status_t mbedtls_test_transparent_aead_encrypt(
|
||||
const uint8_t *nonce, size_t nonce_length,
|
||||
const uint8_t *additional_data, size_t additional_data_length,
|
||||
const uint8_t *plaintext, size_t plaintext_length,
|
||||
uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length );
|
||||
uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_decrypt(
|
||||
const psa_key_attributes_t *attributes,
|
||||
@@ -65,7 +65,7 @@ psa_status_t mbedtls_test_transparent_aead_decrypt(
|
||||
const uint8_t *nonce, size_t nonce_length,
|
||||
const uint8_t *additional_data, size_t additional_data_length,
|
||||
const uint8_t *ciphertext, size_t ciphertext_length,
|
||||
uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length );
|
||||
uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length);
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */
|
||||
|
@@ -45,10 +45,10 @@ typedef struct {
|
||||
|
||||
#define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
|
||||
static inline mbedtls_test_driver_cipher_hooks_t
|
||||
mbedtls_test_driver_cipher_hooks_init( void )
|
||||
mbedtls_test_driver_cipher_hooks_init(void)
|
||||
{
|
||||
const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT;
|
||||
return( v );
|
||||
return v;
|
||||
}
|
||||
|
||||
extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks;
|
||||
@@ -81,7 +81,7 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
||||
psa_algorithm_t alg);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_abort(
|
||||
mbedtls_transparent_test_driver_cipher_operation_t *operation );
|
||||
mbedtls_transparent_test_driver_cipher_operation_t *operation);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_set_iv(
|
||||
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
||||
|
@@ -41,10 +41,10 @@ typedef struct {
|
||||
|
||||
#define MBEDTLS_TEST_DRIVER_HASH_INIT { 0, 0, 0 }
|
||||
static inline mbedtls_test_driver_hash_hooks_t
|
||||
mbedtls_test_driver_hash_hooks_init( void )
|
||||
mbedtls_test_driver_hash_hooks_init(void)
|
||||
{
|
||||
const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT;
|
||||
return( v );
|
||||
return v;
|
||||
}
|
||||
|
||||
extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks;
|
||||
@@ -52,29 +52,29 @@ extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks;
|
||||
psa_status_t mbedtls_test_transparent_hash_compute(
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *input, size_t input_length,
|
||||
uint8_t *hash, size_t hash_size, size_t *hash_length );
|
||||
uint8_t *hash, size_t hash_size, size_t *hash_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_setup(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
||||
psa_algorithm_t alg );
|
||||
psa_algorithm_t alg);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_clone(
|
||||
const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
|
||||
mbedtls_transparent_test_driver_hash_operation_t *target_operation );
|
||||
mbedtls_transparent_test_driver_hash_operation_t *target_operation);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_update(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length );
|
||||
size_t input_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_finish(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
||||
uint8_t *hash,
|
||||
size_t hash_size,
|
||||
size_t *hash_length );
|
||||
size_t *hash_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_abort(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation );
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation);
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */
|
||||
|
@@ -52,43 +52,43 @@ typedef struct {
|
||||
* used as a location of an opaque test drivers. */
|
||||
#define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0, 0x800000 }
|
||||
static inline mbedtls_test_driver_key_management_hooks_t
|
||||
mbedtls_test_driver_key_management_hooks_init( void )
|
||||
mbedtls_test_driver_key_management_hooks_init(void)
|
||||
{
|
||||
const mbedtls_test_driver_key_management_hooks_t
|
||||
v = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT;
|
||||
return( v );
|
||||
return v;
|
||||
}
|
||||
|
||||
extern mbedtls_test_driver_key_management_hooks_t
|
||||
mbedtls_test_driver_key_management_hooks;
|
||||
|
||||
psa_status_t mbedtls_test_transparent_init( void );
|
||||
void mbedtls_test_transparent_free( void );
|
||||
psa_status_t mbedtls_test_opaque_init( void );
|
||||
void mbedtls_test_opaque_free( void );
|
||||
psa_status_t mbedtls_test_transparent_init(void);
|
||||
void mbedtls_test_transparent_free(void);
|
||||
psa_status_t mbedtls_test_opaque_init(void);
|
||||
void mbedtls_test_opaque_free(void);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_generate_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *key, size_t key_size, size_t *key_length );
|
||||
uint8_t *key, size_t key_size, size_t *key_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_generate_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *key, size_t key_size, size_t *key_length );
|
||||
uint8_t *key, size_t key_size, size_t *key_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_export_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
uint8_t *data, size_t data_size, size_t *data_length );
|
||||
uint8_t *data, size_t data_size, size_t *data_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_export_public_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
uint8_t *data, size_t data_size, size_t *data_length );
|
||||
uint8_t *data, size_t data_size, size_t *data_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_export_public_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
uint8_t *data, size_t data_size, size_t *data_length );
|
||||
uint8_t *data, size_t data_size, size_t *data_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_import_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
@@ -102,7 +102,7 @@ psa_status_t mbedtls_test_transparent_import_key(
|
||||
psa_status_t mbedtls_test_opaque_get_builtin_key(
|
||||
psa_drv_slot_number_t slot_number,
|
||||
psa_key_attributes_t *attributes,
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length );
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length);
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H */
|
||||
|
@@ -41,10 +41,10 @@ typedef struct {
|
||||
|
||||
#define MBEDTLS_TEST_DRIVER_MAC_INIT { 0, 0, 0 }
|
||||
static inline mbedtls_test_driver_mac_hooks_t
|
||||
mbedtls_test_driver_mac_hooks_init( void )
|
||||
mbedtls_test_driver_mac_hooks_init(void)
|
||||
{
|
||||
const mbedtls_test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT;
|
||||
return( v );
|
||||
return v;
|
||||
}
|
||||
|
||||
extern mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks;
|
||||
@@ -58,40 +58,40 @@ psa_status_t mbedtls_test_transparent_mac_compute(
|
||||
size_t input_length,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length );
|
||||
size_t *mac_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_sign_setup(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg );
|
||||
psa_algorithm_t alg);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_verify_setup(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg );
|
||||
psa_algorithm_t alg);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_update(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length );
|
||||
size_t input_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_sign_finish(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length );
|
||||
size_t *mac_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_verify_finish(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *mac,
|
||||
size_t mac_length );
|
||||
size_t mac_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_abort(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation );
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_compute(
|
||||
const psa_key_attributes_t *attributes,
|
||||
@@ -102,40 +102,40 @@ psa_status_t mbedtls_test_opaque_mac_compute(
|
||||
size_t input_length,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length );
|
||||
size_t *mac_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_sign_setup(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg );
|
||||
psa_algorithm_t alg);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_verify_setup(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg );
|
||||
psa_algorithm_t alg);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_update(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length );
|
||||
size_t input_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_sign_finish(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length );
|
||||
size_t *mac_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_verify_finish(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *mac,
|
||||
size_t mac_length );
|
||||
size_t mac_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_abort(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation );
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation);
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_TEST_DRIVERS_MAC_H */
|
||||
|
@@ -42,11 +42,11 @@ typedef struct {
|
||||
|
||||
#define MBEDTLS_TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 }
|
||||
static inline mbedtls_test_driver_signature_hooks_t
|
||||
mbedtls_test_driver_signature_hooks_init( void )
|
||||
mbedtls_test_driver_signature_hooks_init(void)
|
||||
{
|
||||
const mbedtls_test_driver_signature_hooks_t
|
||||
v = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT;
|
||||
return( v );
|
||||
return v;
|
||||
}
|
||||
|
||||
extern mbedtls_test_driver_signature_hooks_t
|
||||
@@ -63,7 +63,7 @@ psa_status_t mbedtls_test_transparent_signature_sign_message(
|
||||
size_t input_length,
|
||||
uint8_t *signature,
|
||||
size_t signature_size,
|
||||
size_t *signature_length );
|
||||
size_t *signature_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_sign_message(
|
||||
const psa_key_attributes_t *attributes,
|
||||
@@ -74,7 +74,7 @@ psa_status_t mbedtls_test_opaque_signature_sign_message(
|
||||
size_t input_length,
|
||||
uint8_t *signature,
|
||||
size_t signature_size,
|
||||
size_t *signature_length );
|
||||
size_t *signature_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_signature_verify_message(
|
||||
const psa_key_attributes_t *attributes,
|
||||
@@ -84,7 +84,7 @@ psa_status_t mbedtls_test_transparent_signature_verify_message(
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length );
|
||||
size_t signature_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_verify_message(
|
||||
const psa_key_attributes_t *attributes,
|
||||
@@ -94,35 +94,35 @@ psa_status_t mbedtls_test_opaque_signature_verify_message(
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length );
|
||||
size_t signature_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_signature_sign_hash(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length );
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_sign_hash(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length );
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_signature_verify_hash(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
const uint8_t *signature, size_t signature_length );
|
||||
const uint8_t *signature, size_t signature_length);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_verify_hash(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
const uint8_t *signature, size_t signature_length );
|
||||
const uint8_t *signature, size_t signature_length);
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_TEST_DRIVERS_SIGNATURE_H */
|
||||
|
@@ -31,7 +31,7 @@
|
||||
|
||||
size_t mbedtls_test_size_function(
|
||||
const psa_key_type_t key_type,
|
||||
const size_t key_bits );
|
||||
const size_t key_bits);
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_TEST_DRIVERS_SIZE_H */
|
||||
|
@@ -44,13 +44,13 @@
|
||||
* of the PSA subsystem. You may disable it temporarily to simulate a
|
||||
* depleted entropy source.
|
||||
*/
|
||||
void mbedtls_test_enable_insecure_external_rng( void );
|
||||
void mbedtls_test_enable_insecure_external_rng(void);
|
||||
|
||||
/** Disable the insecure implementation of mbedtls_psa_external_get_random().
|
||||
*
|
||||
* See mbedtls_test_enable_insecure_external_rng().
|
||||
*/
|
||||
void mbedtls_test_disable_insecure_external_rng( void );
|
||||
void mbedtls_test_disable_insecure_external_rng(void);
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
|
||||
#endif /* FAKE_EXTERNAL_RNG_FOR_TEST_H */
|
||||
|
@@ -46,21 +46,18 @@
|
||||
#endif
|
||||
|
||||
/** The type of test case arguments that contain binary data. */
|
||||
typedef struct data_tag
|
||||
{
|
||||
uint8_t * x;
|
||||
typedef struct data_tag {
|
||||
uint8_t *x;
|
||||
uint32_t len;
|
||||
} data_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MBEDTLS_TEST_RESULT_SUCCESS = 0,
|
||||
MBEDTLS_TEST_RESULT_FAILED,
|
||||
MBEDTLS_TEST_RESULT_SKIPPED
|
||||
} mbedtls_test_result_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
mbedtls_test_result_t result;
|
||||
const char *test;
|
||||
const char *filename;
|
||||
@@ -75,8 +72,8 @@ typedef struct
|
||||
mbedtls_test_info_t;
|
||||
extern mbedtls_test_info_t mbedtls_test_info;
|
||||
|
||||
int mbedtls_test_platform_setup( void );
|
||||
void mbedtls_test_platform_teardown( void );
|
||||
int mbedtls_test_platform_setup(void);
|
||||
void mbedtls_test_platform_teardown(void);
|
||||
|
||||
/**
|
||||
* \brief Record the current test case as a failure.
|
||||
@@ -94,7 +91,7 @@ void mbedtls_test_platform_teardown( void );
|
||||
* \param line_no Line number where the failure originated.
|
||||
* \param filename Filename where the failure originated.
|
||||
*/
|
||||
void mbedtls_test_fail( const char *test, int line_no, const char* filename );
|
||||
void mbedtls_test_fail(const char *test, int line_no, const char *filename);
|
||||
|
||||
/**
|
||||
* \brief Record the current test case as skipped.
|
||||
@@ -107,7 +104,7 @@ void mbedtls_test_fail( const char *test, int line_no, const char* filename );
|
||||
* \param line_no Line number where the test case was skipped.
|
||||
* \param filename Filename where the test case was skipped.
|
||||
*/
|
||||
void mbedtls_test_skip( const char *test, int line_no, const char* filename );
|
||||
void mbedtls_test_skip(const char *test, int line_no, const char *filename);
|
||||
|
||||
/**
|
||||
* \brief Set the test step number for failure reports.
|
||||
@@ -119,12 +116,12 @@ void mbedtls_test_skip( const char *test, int line_no, const char* filename );
|
||||
*
|
||||
* \param step The step number to report.
|
||||
*/
|
||||
void mbedtls_test_set_step( unsigned long step );
|
||||
void mbedtls_test_set_step(unsigned long step);
|
||||
|
||||
/**
|
||||
* \brief Reset mbedtls_test_info to a ready/starting state.
|
||||
*/
|
||||
void mbedtls_test_info_reset( void );
|
||||
void mbedtls_test_info_reset(void);
|
||||
|
||||
/**
|
||||
* \brief Record the current test case as a failure if two integers
|
||||
@@ -144,8 +141,8 @@ void mbedtls_test_info_reset( void );
|
||||
*
|
||||
* \return \c 1 if the values are equal, otherwise \c 0.
|
||||
*/
|
||||
int mbedtls_test_equal( const char *test, int line_no, const char* filename,
|
||||
unsigned long long value1, unsigned long long value2 );
|
||||
int mbedtls_test_equal(const char *test, int line_no, const char *filename,
|
||||
unsigned long long value1, unsigned long long value2);
|
||||
|
||||
/**
|
||||
* \brief Record the current test case as a failure based
|
||||
@@ -165,8 +162,8 @@ int mbedtls_test_equal( const char *test, int line_no, const char* filename,
|
||||
*
|
||||
* \return \c 1 if \p value1 <= \p value2, otherwise \c 0.
|
||||
*/
|
||||
int mbedtls_test_le_u( const char *test, int line_no, const char* filename,
|
||||
unsigned long long value1, unsigned long long value2 );
|
||||
int mbedtls_test_le_u(const char *test, int line_no, const char *filename,
|
||||
unsigned long long value1, unsigned long long value2);
|
||||
|
||||
/**
|
||||
* \brief Record the current test case as a failure based
|
||||
@@ -186,8 +183,8 @@ int mbedtls_test_le_u( const char *test, int line_no, const char* filename,
|
||||
*
|
||||
* \return \c 1 if \p value1 <= \p value2, otherwise \c 0.
|
||||
*/
|
||||
int mbedtls_test_le_s( const char *test, int line_no, const char* filename,
|
||||
long long value1, long long value2 );
|
||||
int mbedtls_test_le_s(const char *test, int line_no, const char *filename,
|
||||
long long value1, long long value2);
|
||||
|
||||
/**
|
||||
* \brief This function decodes the hexadecimal representation of
|
||||
@@ -207,12 +204,12 @@ int mbedtls_test_le_s( const char *test, int line_no, const char* filename,
|
||||
* \return \c -1 if the output buffer is too small or the input string
|
||||
* is not a valid hexadecimal representation.
|
||||
*/
|
||||
int mbedtls_test_unhexify( unsigned char *obuf, size_t obufmax,
|
||||
const char *ibuf, size_t *len );
|
||||
int mbedtls_test_unhexify(unsigned char *obuf, size_t obufmax,
|
||||
const char *ibuf, size_t *len);
|
||||
|
||||
void mbedtls_test_hexify( unsigned char *obuf,
|
||||
const unsigned char *ibuf,
|
||||
int len );
|
||||
void mbedtls_test_hexify(unsigned char *obuf,
|
||||
const unsigned char *ibuf,
|
||||
int len);
|
||||
|
||||
/**
|
||||
* Allocate and zeroize a buffer.
|
||||
@@ -221,7 +218,7 @@ void mbedtls_test_hexify( unsigned char *obuf,
|
||||
*
|
||||
* For convenience, dies if allocation fails.
|
||||
*/
|
||||
unsigned char *mbedtls_test_zero_alloc( size_t len );
|
||||
unsigned char *mbedtls_test_zero_alloc(size_t len);
|
||||
|
||||
/**
|
||||
* Allocate and fill a buffer from hex data.
|
||||
@@ -233,15 +230,14 @@ unsigned char *mbedtls_test_zero_alloc( size_t len );
|
||||
*
|
||||
* For convenience, dies if allocation fails.
|
||||
*/
|
||||
unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen );
|
||||
unsigned char *mbedtls_test_unhexify_alloc(const char *ibuf, size_t *olen);
|
||||
|
||||
int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
|
||||
uint32_t a_len, uint32_t b_len );
|
||||
int mbedtls_test_hexcmp(uint8_t *a, uint8_t *b,
|
||||
uint32_t a_len, uint32_t b_len);
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
const char *failure_condition;
|
||||
const char *file;
|
||||
int line;
|
||||
@@ -257,7 +253,7 @@ mbedtls_test_param_failed_location_record_t;
|
||||
* mbedtls_param_failed() that cancels it.
|
||||
*/
|
||||
void mbedtls_test_param_failed_get_location_record(
|
||||
mbedtls_test_param_failed_location_record_t *location_record );
|
||||
mbedtls_test_param_failed_location_record_t *location_record);
|
||||
|
||||
/**
|
||||
* \brief State that a call to mbedtls_param_failed() is expected.
|
||||
@@ -266,7 +262,7 @@ void mbedtls_test_param_failed_get_location_record(
|
||||
* mbedtls_test_param_failed_check_expected_call() or
|
||||
* mbedtls_param_failed that cancel it.
|
||||
*/
|
||||
void mbedtls_test_param_failed_expect_call( void );
|
||||
void mbedtls_test_param_failed_expect_call(void);
|
||||
|
||||
/**
|
||||
* \brief Check whether mbedtls_param_failed() has been called as expected.
|
||||
@@ -279,7 +275,7 @@ void mbedtls_test_param_failed_expect_call( void );
|
||||
* mbedtls_param_failed() has been called.
|
||||
* \c -1 Otherwise.
|
||||
*/
|
||||
int mbedtls_test_param_failed_check_expected_call( void );
|
||||
int mbedtls_test_param_failed_check_expected_call(void);
|
||||
|
||||
/**
|
||||
* \brief Get the address of the object of type jmp_buf holding the execution
|
||||
@@ -308,7 +304,7 @@ int mbedtls_test_param_failed_check_expected_call( void );
|
||||
* \return Address of the object of type jmp_buf holding the execution state
|
||||
* information used by mbedtls_param_failed() to do a long jump.
|
||||
*/
|
||||
void* mbedtls_test_param_failed_get_state_buf( void );
|
||||
void *mbedtls_test_param_failed_get_state_buf(void);
|
||||
|
||||
/**
|
||||
* \brief Reset the execution state used by mbedtls_param_failed() to do a
|
||||
@@ -324,7 +320,7 @@ void* mbedtls_test_param_failed_get_state_buf( void );
|
||||
* mbedtls_param_failed() will not trigger a long jump with
|
||||
* undefined behavior but rather a long jump that will rather fault.
|
||||
*/
|
||||
void mbedtls_test_param_failed_reset_state( void );
|
||||
void mbedtls_test_param_failed_reset_state(void);
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
@@ -334,11 +330,11 @@ void mbedtls_test_param_failed_reset_state( void );
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
/** Permanently activate the mutex usage verification framework. See
|
||||
* threading_helpers.c for information. */
|
||||
void mbedtls_test_mutex_usage_init( void );
|
||||
void mbedtls_test_mutex_usage_init(void);
|
||||
|
||||
/** Call this function after executing a test case to check for mutex usage
|
||||
* errors. */
|
||||
void mbedtls_test_mutex_usage_check( void );
|
||||
void mbedtls_test_mutex_usage_check(void);
|
||||
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
@@ -353,8 +349,8 @@ void mbedtls_test_mutex_usage_check( void );
|
||||
*
|
||||
* \note If the check fails, fail the test currently being run.
|
||||
*/
|
||||
void mbedtls_test_err_add_check( int high, int low,
|
||||
const char *file, int line);
|
||||
void mbedtls_test_err_add_check(int high, int low,
|
||||
const char *file, int line);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
@@ -379,7 +375,7 @@ void mbedtls_test_err_add_check( int high, int low,
|
||||
*
|
||||
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
|
||||
*/
|
||||
int mbedtls_test_read_mpi( mbedtls_mpi *X, const char *s );
|
||||
int mbedtls_test_read_mpi(mbedtls_mpi *X, const char *s);
|
||||
|
||||
/** Nonzero if the current test case had an input parsed with
|
||||
* mbedtls_test_read_mpi() that is a negative 0 (`"-"`, `"-0"`, `"-00"`, etc.,
|
||||
|
@@ -62,14 +62,14 @@
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_ASSERT( TEST ) \
|
||||
#define TEST_ASSERT(TEST) \
|
||||
do { \
|
||||
if( ! (TEST) ) \
|
||||
{ \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
} while( 0 )
|
||||
if (!(TEST)) \
|
||||
{ \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
|
||||
goto exit; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/** Evaluate two integer expressions and fail the test case if they have
|
||||
* different values.
|
||||
@@ -80,12 +80,12 @@
|
||||
* \param expr1 An integral-typed expression to evaluate.
|
||||
* \param expr2 Another integral-typed expression to evaluate.
|
||||
*/
|
||||
#define TEST_EQUAL( expr1, expr2 ) \
|
||||
#define TEST_EQUAL(expr1, expr2) \
|
||||
do { \
|
||||
if( ! mbedtls_test_equal( #expr1 " == " #expr2, __LINE__, __FILE__, \
|
||||
expr1, expr2 ) ) \
|
||||
goto exit; \
|
||||
} while( 0 )
|
||||
if (!mbedtls_test_equal( #expr1 " == " #expr2, __LINE__, __FILE__, \
|
||||
expr1, expr2)) \
|
||||
goto exit; \
|
||||
} while (0)
|
||||
|
||||
/** Evaluate two unsigned integer expressions and fail the test case
|
||||
* if they are not in increasing order (left <= right).
|
||||
@@ -93,12 +93,12 @@
|
||||
* \param expr1 An integral-typed expression to evaluate.
|
||||
* \param expr2 Another integral-typed expression to evaluate.
|
||||
*/
|
||||
#define TEST_LE_U( expr1, expr2 ) \
|
||||
#define TEST_LE_U(expr1, expr2) \
|
||||
do { \
|
||||
if( ! mbedtls_test_le_u( #expr1 " <= " #expr2, __LINE__, __FILE__, \
|
||||
expr1, expr2 ) ) \
|
||||
goto exit; \
|
||||
} while( 0 )
|
||||
if (!mbedtls_test_le_u( #expr1 " <= " #expr2, __LINE__, __FILE__, \
|
||||
expr1, expr2)) \
|
||||
goto exit; \
|
||||
} while (0)
|
||||
|
||||
/** Evaluate two signed integer expressions and fail the test case
|
||||
* if they are not in increasing order (left <= right).
|
||||
@@ -106,12 +106,12 @@
|
||||
* \param expr1 An integral-typed expression to evaluate.
|
||||
* \param expr2 Another integral-typed expression to evaluate.
|
||||
*/
|
||||
#define TEST_LE_S( expr1, expr2 ) \
|
||||
#define TEST_LE_S(expr1, expr2) \
|
||||
do { \
|
||||
if( ! mbedtls_test_le_s( #expr1 " <= " #expr2, __LINE__, __FILE__, \
|
||||
expr1, expr2 ) ) \
|
||||
goto exit; \
|
||||
} while( 0 )
|
||||
if (!mbedtls_test_le_s( #expr1 " <= " #expr2, __LINE__, __FILE__, \
|
||||
expr1, expr2)) \
|
||||
goto exit; \
|
||||
} while (0)
|
||||
|
||||
/** Allocate memory dynamically and fail the test case if this fails.
|
||||
* The allocated memory will be filled with zeros.
|
||||
@@ -133,36 +133,36 @@
|
||||
* This expression may be evaluated multiple times.
|
||||
*
|
||||
*/
|
||||
#define ASSERT_ALLOC( pointer, length ) \
|
||||
#define ASSERT_ALLOC(pointer, length) \
|
||||
do \
|
||||
{ \
|
||||
TEST_ASSERT( ( pointer ) == NULL ); \
|
||||
if( ( length ) != 0 ) \
|
||||
TEST_ASSERT((pointer) == NULL); \
|
||||
if ((length) != 0) \
|
||||
{ \
|
||||
( pointer ) = mbedtls_calloc( sizeof( *( pointer ) ), \
|
||||
( length ) ); \
|
||||
TEST_ASSERT( ( pointer ) != NULL ); \
|
||||
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
|
||||
(length)); \
|
||||
TEST_ASSERT((pointer) != NULL); \
|
||||
} \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
/** Allocate memory dynamically. If the allocation fails, skip the test case.
|
||||
*
|
||||
* This macro behaves like #ASSERT_ALLOC, except that if the allocation
|
||||
* fails, it marks the test as skipped rather than failed.
|
||||
*/
|
||||
#define ASSERT_ALLOC_WEAK( pointer, length ) \
|
||||
#define ASSERT_ALLOC_WEAK(pointer, length) \
|
||||
do \
|
||||
{ \
|
||||
TEST_ASSERT( ( pointer ) == NULL ); \
|
||||
if( ( length ) != 0 ) \
|
||||
TEST_ASSERT((pointer) == NULL); \
|
||||
if ((length) != 0) \
|
||||
{ \
|
||||
( pointer ) = mbedtls_calloc( sizeof( *( pointer ) ), \
|
||||
( length ) ); \
|
||||
TEST_ASSUME( ( pointer ) != NULL ); \
|
||||
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
|
||||
(length)); \
|
||||
TEST_ASSUME((pointer) != NULL); \
|
||||
} \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
/** Compare two buffers and fail the test case if they differ.
|
||||
*
|
||||
@@ -176,14 +176,14 @@
|
||||
* \param size2 Size of the second buffer in bytes.
|
||||
* This expression may be evaluated multiple times.
|
||||
*/
|
||||
#define ASSERT_COMPARE( p1, size1, p2, size2 ) \
|
||||
#define ASSERT_COMPARE(p1, size1, p2, size2) \
|
||||
do \
|
||||
{ \
|
||||
TEST_ASSERT( ( size1 ) == ( size2 ) ); \
|
||||
if( ( size1 ) != 0 ) \
|
||||
TEST_ASSERT( memcmp( ( p1 ), ( p2 ), ( size1 ) ) == 0 ); \
|
||||
TEST_ASSERT((size1) == (size2)); \
|
||||
if ((size1) != 0) \
|
||||
TEST_ASSERT(memcmp((p1), (p2), (size1)) == 0); \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
/**
|
||||
* \brief This macro tests the expression passed to it and skips the
|
||||
@@ -191,14 +191,14 @@
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_ASSUME( TEST ) \
|
||||
#define TEST_ASSUME(TEST) \
|
||||
do { \
|
||||
if( ! (TEST) ) \
|
||||
if (!(TEST)) \
|
||||
{ \
|
||||
mbedtls_test_skip( #TEST, __LINE__, __FILE__ ); \
|
||||
mbedtls_test_skip( #TEST, __LINE__, __FILE__); \
|
||||
goto exit; \
|
||||
} \
|
||||
} while( 0 )
|
||||
} while (0)
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS) && !defined(MBEDTLS_PARAM_FAILED_ALT)
|
||||
/**
|
||||
@@ -221,17 +221,17 @@
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
|
||||
#define TEST_INVALID_PARAM_RET(PARAM_ERR_VALUE, TEST) \
|
||||
do { \
|
||||
mbedtls_test_param_failed_expect_call( ); \
|
||||
if( ( ( TEST ) != ( PARAM_ERR_VALUE ) ) || \
|
||||
( mbedtls_test_param_failed_check_expected_call( ) != 0 ) ) \
|
||||
mbedtls_test_param_failed_expect_call(); \
|
||||
if (((TEST) != (PARAM_ERR_VALUE)) || \
|
||||
(mbedtls_test_param_failed_check_expected_call() != 0)) \
|
||||
{ \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
|
||||
goto exit; \
|
||||
} \
|
||||
mbedtls_test_param_failed_check_expected_call( ); \
|
||||
} while( 0 )
|
||||
mbedtls_test_param_failed_check_expected_call(); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \brief This macro tests the statement passed to it as a test step or
|
||||
@@ -253,18 +253,18 @@
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_INVALID_PARAM( TEST ) \
|
||||
#define TEST_INVALID_PARAM(TEST) \
|
||||
do { \
|
||||
memcpy( jmp_tmp, mbedtls_test_param_failed_get_state_buf( ), \
|
||||
sizeof( jmp_tmp ) ); \
|
||||
if( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 ) \
|
||||
memcpy(jmp_tmp, mbedtls_test_param_failed_get_state_buf(), \
|
||||
sizeof(jmp_tmp)); \
|
||||
if (setjmp(mbedtls_test_param_failed_get_state_buf()) == 0) \
|
||||
{ \
|
||||
TEST; \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
|
||||
goto exit; \
|
||||
} \
|
||||
mbedtls_test_param_failed_reset_state( ); \
|
||||
} while( 0 )
|
||||
mbedtls_test_param_failed_reset_state(); \
|
||||
} while (0)
|
||||
#endif /* MBEDTLS_CHECK_PARAMS && !MBEDTLS_PARAM_FAILED_ALT */
|
||||
|
||||
/**
|
||||
@@ -298,15 +298,15 @@
|
||||
*
|
||||
* \param TEST The test expression to be tested.
|
||||
*/
|
||||
#define TEST_VALID_PARAM( TEST ) \
|
||||
TEST_ASSERT( ( TEST, 1 ) );
|
||||
#define TEST_VALID_PARAM(TEST) \
|
||||
TEST_ASSERT((TEST, 1));
|
||||
|
||||
#define TEST_HELPER_ASSERT(a) if( !( a ) ) \
|
||||
{ \
|
||||
mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
|
||||
__FILE__, __LINE__, #a ); \
|
||||
mbedtls_exit( 1 ); \
|
||||
}
|
||||
#define TEST_HELPER_ASSERT(a) if (!(a)) \
|
||||
{ \
|
||||
mbedtls_fprintf(stderr, "Assertion Failed at %s:%d - %s\n", \
|
||||
__FILE__, __LINE__, #a); \
|
||||
mbedtls_exit(1); \
|
||||
}
|
||||
|
||||
/** \def ARRAY_LENGTH
|
||||
* Return the number of elements of a static or stack array.
|
||||
@@ -317,34 +317,34 @@
|
||||
*/
|
||||
/* A correct implementation of ARRAY_LENGTH, but which silently gives
|
||||
* a nonsensical result if called with a pointer rather than an array. */
|
||||
#define ARRAY_LENGTH_UNSAFE( array ) \
|
||||
( sizeof( array ) / sizeof( *( array ) ) )
|
||||
#define ARRAY_LENGTH_UNSAFE(array) \
|
||||
(sizeof(array) / sizeof(*(array)))
|
||||
|
||||
#if defined(__GNUC__)
|
||||
/* Test if arg and &(arg)[0] have the same type. This is true if arg is
|
||||
* an array but not if it's a pointer. */
|
||||
#define IS_ARRAY_NOT_POINTER( arg ) \
|
||||
( ! __builtin_types_compatible_p( __typeof__( arg ), \
|
||||
__typeof__( &( arg )[0] ) ) )
|
||||
#define IS_ARRAY_NOT_POINTER(arg) \
|
||||
(!__builtin_types_compatible_p(__typeof__(arg), \
|
||||
__typeof__(&(arg)[0])))
|
||||
/* A compile-time constant with the value 0. If `const_expr` is not a
|
||||
* compile-time constant with a nonzero value, cause a compile-time error. */
|
||||
#define STATIC_ASSERT_EXPR( const_expr ) \
|
||||
( 0 && sizeof( struct { unsigned int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) )
|
||||
#define STATIC_ASSERT_EXPR(const_expr) \
|
||||
(0 && sizeof(struct { unsigned int STATIC_ASSERT : 1 - 2 * !(const_expr); }))
|
||||
|
||||
/* Return the scalar value `value` (possibly promoted). This is a compile-time
|
||||
* constant if `value` is. `condition` must be a compile-time constant.
|
||||
* If `condition` is false, arrange to cause a compile-time error. */
|
||||
#define STATIC_ASSERT_THEN_RETURN( condition, value ) \
|
||||
( STATIC_ASSERT_EXPR( condition ) ? 0 : ( value ) )
|
||||
#define STATIC_ASSERT_THEN_RETURN(condition, value) \
|
||||
(STATIC_ASSERT_EXPR(condition) ? 0 : (value))
|
||||
|
||||
#define ARRAY_LENGTH( array ) \
|
||||
( STATIC_ASSERT_THEN_RETURN( IS_ARRAY_NOT_POINTER( array ), \
|
||||
ARRAY_LENGTH_UNSAFE( array ) ) )
|
||||
#define ARRAY_LENGTH(array) \
|
||||
(STATIC_ASSERT_THEN_RETURN(IS_ARRAY_NOT_POINTER(array), \
|
||||
ARRAY_LENGTH_UNSAFE(array)))
|
||||
|
||||
#else
|
||||
/* If we aren't sure the compiler supports our non-standard tricks,
|
||||
* fall back to the unsafe implementation. */
|
||||
#define ARRAY_LENGTH( array ) ARRAY_LENGTH_UNSAFE( array )
|
||||
#define ARRAY_LENGTH(array) ARRAY_LENGTH_UNSAFE(array)
|
||||
#endif
|
||||
|
||||
/** Return the smaller of two values.
|
||||
@@ -354,7 +354,7 @@
|
||||
*
|
||||
* \return The smaller of \p x and \p y.
|
||||
*/
|
||||
#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
/** Return the larger of two values.
|
||||
*
|
||||
@@ -363,29 +363,29 @@
|
||||
*
|
||||
* \return The larger of \p x and \p y.
|
||||
*/
|
||||
#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
|
||||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_UINT32_BE
|
||||
#define GET_UINT32_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
||||
}
|
||||
#define GET_UINT32_BE(n, b, i) \
|
||||
{ \
|
||||
(n) = ((uint32_t) (b)[(i)] << 24) \
|
||||
| ((uint32_t) (b)[(i) + 1] << 16) \
|
||||
| ((uint32_t) (b)[(i) + 2] << 8) \
|
||||
| ((uint32_t) (b)[(i) + 3]); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_UINT32_BE
|
||||
#define PUT_UINT32_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#define PUT_UINT32_BE(n, b, i) \
|
||||
{ \
|
||||
(b)[(i)] = (unsigned char) ((n) >> 24); \
|
||||
(b)[(i) + 1] = (unsigned char) ((n) >> 16); \
|
||||
(b)[(i) + 2] = (unsigned char) ((n) >> 8); \
|
||||
(b)[(i) + 3] = (unsigned char) ((n)); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TEST_MACROS_H */
|
||||
|
@@ -36,11 +36,11 @@
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
|
||||
|
||||
/* Internal function for #TEST_USES_KEY_ID. Return 1 on success, 0 on failure. */
|
||||
int mbedtls_test_uses_key_id( mbedtls_svc_key_id_t key_id );
|
||||
int mbedtls_test_uses_key_id(mbedtls_svc_key_id_t key_id);
|
||||
|
||||
/** Destroy persistent keys recorded with #TEST_USES_KEY_ID.
|
||||
*/
|
||||
void mbedtls_test_psa_purge_key_storage( void );
|
||||
void mbedtls_test_psa_purge_key_storage(void);
|
||||
|
||||
/** Purge the in-memory cache of persistent keys recorded with
|
||||
* #TEST_USES_KEY_ID.
|
||||
@@ -48,7 +48,7 @@ void mbedtls_test_psa_purge_key_storage( void );
|
||||
* Call this function before calling PSA_DONE() if it's ok for
|
||||
* persistent keys to still exist at this point.
|
||||
*/
|
||||
void mbedtls_test_psa_purge_key_cache( void );
|
||||
void mbedtls_test_psa_purge_key_cache(void);
|
||||
|
||||
/** \def TEST_USES_KEY_ID
|
||||
*
|
||||
@@ -75,18 +75,18 @@ void mbedtls_test_psa_purge_key_cache( void );
|
||||
*
|
||||
* \param key_id The PSA key identifier to record.
|
||||
*/
|
||||
#define TEST_USES_KEY_ID( key_id ) \
|
||||
TEST_ASSERT( mbedtls_test_uses_key_id( key_id ) )
|
||||
#define TEST_USES_KEY_ID(key_id) \
|
||||
TEST_ASSERT(mbedtls_test_uses_key_id(key_id))
|
||||
|
||||
#else /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
|
||||
|
||||
#define TEST_USES_KEY_ID( key_id ) ( (void) ( key_id ) )
|
||||
#define mbedtls_test_psa_purge_key_storage( ) ( (void) 0 )
|
||||
#define mbedtls_test_psa_purge_key_cache( ) ( (void) 0 )
|
||||
#define TEST_USES_KEY_ID(key_id) ((void) (key_id))
|
||||
#define mbedtls_test_psa_purge_key_storage() ((void) 0)
|
||||
#define mbedtls_test_psa_purge_key_cache() ((void) 0)
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
|
||||
|
||||
#define PSA_INIT( ) PSA_ASSERT( psa_crypto_init( ) )
|
||||
#define PSA_INIT() PSA_ASSERT(psa_crypto_init())
|
||||
|
||||
/** Check for things that have not been cleaned up properly in the
|
||||
* PSA subsystem.
|
||||
@@ -95,7 +95,7 @@ void mbedtls_test_psa_purge_key_cache( void );
|
||||
* \return A string literal explaining what has not been cleaned up
|
||||
* if applicable.
|
||||
*/
|
||||
const char *mbedtls_test_helper_is_psa_leaking( void );
|
||||
const char *mbedtls_test_helper_is_psa_leaking(void);
|
||||
|
||||
/** Check that no PSA Crypto key slots are in use.
|
||||
*
|
||||
@@ -104,13 +104,13 @@ const char *mbedtls_test_helper_is_psa_leaking( void );
|
||||
* `TEST_ASSERT( ! mbedtls_test_helper_is_psa_leaking( ) )`
|
||||
* but with a more informative message.
|
||||
*/
|
||||
#define ASSERT_PSA_PRISTINE( ) \
|
||||
#define ASSERT_PSA_PRISTINE() \
|
||||
do \
|
||||
{ \
|
||||
if( test_fail_if_psa_leaking( __LINE__, __FILE__ ) ) \
|
||||
goto exit; \
|
||||
if (test_fail_if_psa_leaking(__LINE__, __FILE__)) \
|
||||
goto exit; \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
/** Shut down the PSA Crypto subsystem and destroy persistent keys.
|
||||
* Expect a clean shutdown, with no slots in use.
|
||||
@@ -122,14 +122,14 @@ const char *mbedtls_test_helper_is_psa_leaking( void );
|
||||
* \note Persistent keys must be recorded with #TEST_USES_KEY_ID before
|
||||
* creating them.
|
||||
*/
|
||||
#define PSA_DONE( ) \
|
||||
#define PSA_DONE() \
|
||||
do \
|
||||
{ \
|
||||
test_fail_if_psa_leaking( __LINE__, __FILE__ ); \
|
||||
mbedtls_test_psa_purge_key_storage( ); \
|
||||
mbedtls_psa_crypto_free( ); \
|
||||
test_fail_if_psa_leaking(__LINE__, __FILE__); \
|
||||
mbedtls_test_psa_purge_key_storage(); \
|
||||
mbedtls_psa_crypto_free(); \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
/** Shut down the PSA Crypto subsystem, allowing persistent keys to survive.
|
||||
* Expect a clean shutdown, with no slots in use.
|
||||
@@ -137,22 +137,22 @@ const char *mbedtls_test_helper_is_psa_leaking( void );
|
||||
* If some key slots are still in use, record the test case as failed and
|
||||
* jump to the `exit` label.
|
||||
*/
|
||||
#define PSA_SESSION_DONE( ) \
|
||||
#define PSA_SESSION_DONE() \
|
||||
do \
|
||||
{ \
|
||||
mbedtls_test_psa_purge_key_cache( ); \
|
||||
ASSERT_PSA_PRISTINE( ); \
|
||||
mbedtls_psa_crypto_free( ); \
|
||||
mbedtls_test_psa_purge_key_cache(); \
|
||||
ASSERT_PSA_PRISTINE(); \
|
||||
mbedtls_psa_crypto_free(); \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
|
||||
|
||||
#if defined(RECORD_PSA_STATUS_COVERAGE_LOG)
|
||||
psa_status_t mbedtls_test_record_status( psa_status_t status,
|
||||
const char *func,
|
||||
const char *file, int line,
|
||||
const char *expr );
|
||||
psa_status_t mbedtls_test_record_status(psa_status_t status,
|
||||
const char *func,
|
||||
const char *file, int line,
|
||||
const char *expr);
|
||||
|
||||
/** Return value logging wrapper macro.
|
||||
*
|
||||
@@ -178,8 +178,8 @@ psa_status_t mbedtls_test_record_status( psa_status_t status,
|
||||
* a value of type #psa_status_t.
|
||||
* \return The value of \p expr.
|
||||
*/
|
||||
#define RECORD_STATUS( string, expr ) \
|
||||
mbedtls_test_record_status( ( expr ), string, __FILE__, __LINE__, #expr )
|
||||
#define RECORD_STATUS(string, expr) \
|
||||
mbedtls_test_record_status((expr), string, __FILE__, __LINE__, #expr)
|
||||
|
||||
#include "instrument_record_status.h"
|
||||
|
||||
@@ -191,7 +191,7 @@ psa_status_t mbedtls_test_record_status( psa_status_t status,
|
||||
* permissions of other usage policies
|
||||
* (like PSA_KEY_USAGE_SIGN_HASH involves PSA_KEY_USAGE_SIGN_MESSAGE).
|
||||
*/
|
||||
psa_key_usage_t mbedtls_test_update_key_usage_flags( psa_key_usage_t usage_flags );
|
||||
psa_key_usage_t mbedtls_test_update_key_usage_flags(psa_key_usage_t usage_flags);
|
||||
|
||||
/** Skip a test case if the given key is a 192 bits AES key and the AES
|
||||
* implementation is at least partially provided by an accelerator or
|
||||
@@ -220,18 +220,18 @@ psa_key_usage_t mbedtls_test_update_key_usage_flags( psa_key_usage_t usage_flags
|
||||
#define MBEDTLS_TEST_HAVE_ALT_AES 0
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_bits ) \
|
||||
#define MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_bits) \
|
||||
do \
|
||||
{ \
|
||||
if( ( MBEDTLS_TEST_HAVE_ALT_AES ) && \
|
||||
( ( key_type ) == PSA_KEY_TYPE_AES ) && \
|
||||
( key_bits == 192 ) ) \
|
||||
if ((MBEDTLS_TEST_HAVE_ALT_AES) && \
|
||||
((key_type) == PSA_KEY_TYPE_AES) && \
|
||||
(key_bits == 192)) \
|
||||
{ \
|
||||
mbedtls_test_skip( "AES-192 not supported", __LINE__, __FILE__ ); \
|
||||
mbedtls_test_skip("AES-192 not supported", __LINE__, __FILE__); \
|
||||
goto exit; \
|
||||
} \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
/** Skip a test case if a GCM operation with a nonce length different from
|
||||
* 12 bytes fails and was performed by an accelerator or alternative
|
||||
@@ -262,20 +262,20 @@ psa_key_usage_t mbedtls_test_update_key_usage_flags( psa_key_usage_t usage_flags
|
||||
#define MBEDTLS_TEST_HAVE_ALT_GCM 0
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, \
|
||||
nonce_length ) \
|
||||
#define MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, \
|
||||
nonce_length) \
|
||||
do \
|
||||
{ \
|
||||
if( ( MBEDTLS_TEST_HAVE_ALT_GCM ) && \
|
||||
( PSA_ALG_AEAD_WITH_SHORTENED_TAG( ( alg ) , 0 ) == \
|
||||
PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, 0 ) ) && \
|
||||
( ( nonce_length ) != 12 ) ) \
|
||||
if ((MBEDTLS_TEST_HAVE_ALT_GCM) && \
|
||||
(PSA_ALG_AEAD_WITH_SHORTENED_TAG((alg), 0) == \
|
||||
PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, 0)) && \
|
||||
((nonce_length) != 12)) \
|
||||
{ \
|
||||
mbedtls_test_skip( "GCM with non-12-byte IV is not supported", __LINE__, __FILE__ ); \
|
||||
mbedtls_test_skip("GCM with non-12-byte IV is not supported", __LINE__, __FILE__); \
|
||||
goto exit; \
|
||||
} \
|
||||
} \
|
||||
while( 0 )
|
||||
while (0)
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||
|
||||
@@ -292,14 +292,14 @@ psa_key_usage_t mbedtls_test_update_key_usage_flags( psa_key_usage_t usage_flags
|
||||
* #MBEDTLS_USE_PSA_CRYPTO is disabled.
|
||||
*/
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#define USE_PSA_INIT( ) PSA_INIT( )
|
||||
#define USE_PSA_DONE( ) PSA_DONE( )
|
||||
#define USE_PSA_INIT() PSA_INIT()
|
||||
#define USE_PSA_DONE() PSA_DONE()
|
||||
#else /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
/* Define empty macros so that we can use them in the preamble and teardown
|
||||
* of every test function that uses PSA conditionally based on
|
||||
* MBEDTLS_USE_PSA_CRYPTO. */
|
||||
#define USE_PSA_INIT( ) ( (void) 0 )
|
||||
#define USE_PSA_DONE( ) ( (void) 0 )
|
||||
#define USE_PSA_INIT() ((void) 0)
|
||||
#define USE_PSA_DONE() ((void) 0)
|
||||
#endif /* !MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#endif /* PSA_CRYPTO_HELPERS_H */
|
||||
|
@@ -109,7 +109,7 @@
|
||||
* This is used in some smoke tests.
|
||||
*/
|
||||
#if defined(KNOWN_SUPPORTED_HASH_ALG) && defined(PSA_WANT_ALG_HMAC)
|
||||
#define KNOWN_SUPPORTED_MAC_ALG ( PSA_ALG_HMAC( KNOWN_SUPPORTED_HASH_ALG ) )
|
||||
#define KNOWN_SUPPORTED_MAC_ALG (PSA_ALG_HMAC(KNOWN_SUPPORTED_HASH_ALG))
|
||||
#define KNOWN_SUPPORTED_MAC_KEY_TYPE PSA_KEY_TYPE_HMAC
|
||||
#elif defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(MBEDTLS_CMAC_C)
|
||||
#define KNOWN_SUPPORTED_MAC_ALG PSA_ALG_CMAC
|
||||
@@ -168,12 +168,12 @@
|
||||
* \return \c 1 on success, \c 0 on failure.
|
||||
*/
|
||||
int mbedtls_test_psa_setup_key_derivation_wrap(
|
||||
psa_key_derivation_operation_t* operation,
|
||||
psa_key_derivation_operation_t *operation,
|
||||
mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
const unsigned char* input1, size_t input1_length,
|
||||
const unsigned char* input2, size_t input2_length,
|
||||
size_t capacity );
|
||||
const unsigned char *input1, size_t input1_length,
|
||||
const unsigned char *input2, size_t input2_length,
|
||||
size_t capacity);
|
||||
|
||||
/** Perform a key agreement using the given key pair against its public key
|
||||
* using psa_raw_key_agreement().
|
||||
@@ -189,7 +189,7 @@ int mbedtls_test_psa_setup_key_derivation_wrap(
|
||||
*/
|
||||
psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
|
||||
psa_algorithm_t alg,
|
||||
mbedtls_svc_key_id_t key );
|
||||
mbedtls_svc_key_id_t key);
|
||||
|
||||
/** Perform a key agreement using the given key pair against its public key
|
||||
* using psa_key_derivation_raw_key().
|
||||
@@ -208,7 +208,7 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
|
||||
*/
|
||||
psa_status_t mbedtls_test_psa_key_agreement_with_self(
|
||||
psa_key_derivation_operation_t *operation,
|
||||
mbedtls_svc_key_id_t key );
|
||||
mbedtls_svc_key_id_t key);
|
||||
|
||||
/** Perform sanity checks on the given key representation.
|
||||
*
|
||||
@@ -230,7 +230,7 @@ psa_status_t mbedtls_test_psa_key_agreement_with_self(
|
||||
*/
|
||||
int mbedtls_test_psa_exported_key_sanity_check(
|
||||
psa_key_type_t type, size_t bits,
|
||||
const uint8_t *exported, size_t exported_length );
|
||||
const uint8_t *exported, size_t exported_length);
|
||||
|
||||
/** Do smoke tests on a key.
|
||||
*
|
||||
@@ -259,11 +259,11 @@ int mbedtls_test_psa_exported_key_sanity_check(
|
||||
* \retval 0 The key failed the smoke tests.
|
||||
* \retval 1 The key passed the smoke tests.
|
||||
*/
|
||||
int mbedtls_test_psa_exercise_key( mbedtls_svc_key_id_t key,
|
||||
psa_key_usage_t usage,
|
||||
psa_algorithm_t alg );
|
||||
int mbedtls_test_psa_exercise_key(mbedtls_svc_key_id_t key,
|
||||
psa_key_usage_t usage,
|
||||
psa_algorithm_t alg);
|
||||
|
||||
psa_key_usage_t mbedtls_test_psa_usage_to_exercise( psa_key_type_t type,
|
||||
psa_algorithm_t alg );
|
||||
psa_key_usage_t mbedtls_test_psa_usage_to_exercise(psa_key_type_t type,
|
||||
psa_algorithm_t alg);
|
||||
|
||||
#endif /* PSA_EXERCISE_KEY_H */
|
||||
|
@@ -31,6 +31,6 @@
|
||||
* to a \c psa_xxx function that returns a value of type
|
||||
* #psa_status_t.
|
||||
*/
|
||||
#define PSA_ASSERT( expr ) TEST_EQUAL( ( expr ), PSA_SUCCESS )
|
||||
#define PSA_ASSERT(expr) TEST_EQUAL((expr), PSA_SUCCESS)
|
||||
|
||||
#endif /* PSA_HELPERS_H */
|
||||
|
@@ -34,12 +34,11 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
unsigned char *buf; /* Pointer to a buffer of length bytes. */
|
||||
size_t length;
|
||||
/* If fallback_f_rng is NULL, fail after delivering length bytes. */
|
||||
int ( *fallback_f_rng )( void*, unsigned char *, size_t );
|
||||
int (*fallback_f_rng)(void *, unsigned char *, size_t);
|
||||
void *fallback_p_rng;
|
||||
} mbedtls_test_rnd_buf_info;
|
||||
|
||||
@@ -50,8 +49,7 @@ typedef struct
|
||||
* Do not forget endianness!
|
||||
* State( v0, v1 ) should be set to zero.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
uint32_t key[16];
|
||||
uint32_t v0, v1;
|
||||
} mbedtls_test_rnd_pseudo_info;
|
||||
@@ -65,18 +63,18 @@ typedef struct
|
||||
*
|
||||
* rng_state shall be NULL.
|
||||
*/
|
||||
int mbedtls_test_rnd_std_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
int mbedtls_test_rnd_std_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* This function only returns zeros.
|
||||
*
|
||||
* \p rng_state shall be \c NULL.
|
||||
*/
|
||||
int mbedtls_test_rnd_zero_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
int mbedtls_test_rnd_zero_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* This function returns random data based on a buffer it receives.
|
||||
@@ -90,9 +88,9 @@ int mbedtls_test_rnd_zero_rand( void *rng_state,
|
||||
* #mbedtls_test_rnd_buf_info structure if there is one, and
|
||||
* will return #MBEDTLS_ERR_ENTROPY_SOURCE_FAILED otherwise.
|
||||
*/
|
||||
int mbedtls_test_rnd_buffer_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
int mbedtls_test_rnd_buffer_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* This function returns random based on a pseudo random function.
|
||||
@@ -102,8 +100,8 @@ int mbedtls_test_rnd_buffer_rand( void *rng_state,
|
||||
*
|
||||
* \p rng_state shall be a pointer to a #mbedtls_test_rnd_pseudo_info structure.
|
||||
*/
|
||||
int mbedtls_test_rnd_pseudo_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
int mbedtls_test_rnd_pseudo_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len);
|
||||
|
||||
#endif /* TEST_RANDOM_H */
|
||||
|
Reference in New Issue
Block a user