Switch to the new code style
Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/tests/configs/config-wrapper-malloc-0-null.h b/tests/configs/config-wrapper-malloc-0-null.h
index b065c2d..fc649bf 100644
--- a/tests/configs/config-wrapper-malloc-0-null.h
+++ b/tests/configs/config-wrapper-malloc-0-null.h
@@ -23,11 +23,12 @@
#include <stdlib.h>
#ifndef MBEDTLS_PLATFORM_STD_CALLOC
-static inline void *custom_calloc( size_t nmemb, size_t size )
+static inline void *custom_calloc(size_t nmemb, size_t size)
{
- if( nmemb == 0 || size == 0 )
- return( NULL );
- return( calloc( nmemb, size ) );
+ if (nmemb == 0 || size == 0) {
+ return NULL;
+ }
+ return calloc(nmemb, size);
}
#define MBEDTLS_PLATFORM_MEMORY
diff --git a/tests/include/alt-dummy/aes_alt.h b/tests/include/alt-dummy/aes_alt.h
index f226188..21d85f1 100644
--- a/tests/include/alt-dummy/aes_alt.h
+++ b/tests/include/alt-dummy/aes_alt.h
@@ -19,16 +19,14 @@
#ifndef AES_ALT_H
#define AES_ALT_H
-typedef struct mbedtls_aes_context
-{
+typedef struct mbedtls_aes_context {
int dummy;
}
mbedtls_aes_context;
#if defined(MBEDTLS_CIPHER_MODE_XTS)
-typedef struct mbedtls_aes_xts_context
-{
+typedef struct mbedtls_aes_xts_context {
int dummy;
} mbedtls_aes_xts_context;
#endif
diff --git a/tests/include/alt-dummy/aria_alt.h b/tests/include/alt-dummy/aria_alt.h
index 5f2335b..aabec9c 100644
--- a/tests/include/alt-dummy/aria_alt.h
+++ b/tests/include/alt-dummy/aria_alt.h
@@ -19,8 +19,7 @@
#ifndef ARIA_ALT_H
#define ARIA_ALT_H
-typedef struct mbedtls_aria_context
-{
+typedef struct mbedtls_aria_context {
int dummy;
}
mbedtls_aria_context;
diff --git a/tests/include/alt-dummy/camellia_alt.h b/tests/include/alt-dummy/camellia_alt.h
index c23d1b4..b42613b 100644
--- a/tests/include/alt-dummy/camellia_alt.h
+++ b/tests/include/alt-dummy/camellia_alt.h
@@ -19,8 +19,7 @@
#ifndef CAMELLIA_ALT_H
#define CAMELLIA_ALT_H
-typedef struct mbedtls_camellia_context
-{
+typedef struct mbedtls_camellia_context {
int dummy;
}
mbedtls_camellia_context;
diff --git a/tests/include/alt-dummy/ccm_alt.h b/tests/include/alt-dummy/ccm_alt.h
index dcb834e..5ec7d4e 100644
--- a/tests/include/alt-dummy/ccm_alt.h
+++ b/tests/include/alt-dummy/ccm_alt.h
@@ -19,8 +19,7 @@
#ifndef CCM_ALT_H
#define CCM_ALT_H
-typedef struct mbedtls_ccm_context
-{
+typedef struct mbedtls_ccm_context {
int dummy;
}
mbedtls_ccm_context;
diff --git a/tests/include/alt-dummy/chacha20_alt.h b/tests/include/alt-dummy/chacha20_alt.h
index 7a5a25c..a53a330 100644
--- a/tests/include/alt-dummy/chacha20_alt.h
+++ b/tests/include/alt-dummy/chacha20_alt.h
@@ -19,8 +19,7 @@
#ifndef CHACHA20_ALT_H
#define CHACHA20_ALT_H
-typedef struct mbedtls_chacha20_context
-{
+typedef struct mbedtls_chacha20_context {
int dummy;
}
mbedtls_chacha20_context;
diff --git a/tests/include/alt-dummy/chachapoly_alt.h b/tests/include/alt-dummy/chachapoly_alt.h
index 448517d..584a421 100644
--- a/tests/include/alt-dummy/chachapoly_alt.h
+++ b/tests/include/alt-dummy/chachapoly_alt.h
@@ -21,8 +21,7 @@
#include "mbedtls/chacha20.h"
-typedef struct mbedtls_chachapoly_context
-{
+typedef struct mbedtls_chachapoly_context {
int dummy;
}
mbedtls_chachapoly_context;
diff --git a/tests/include/alt-dummy/cmac_alt.h b/tests/include/alt-dummy/cmac_alt.h
index 4c9feee..13c998d 100644
--- a/tests/include/alt-dummy/cmac_alt.h
+++ b/tests/include/alt-dummy/cmac_alt.h
@@ -19,8 +19,7 @@
#ifndef CMAC_ALT_H
#define CMAC_ALT_H
-struct mbedtls_cmac_context_t
-{
+struct mbedtls_cmac_context_t {
int dummy;
};
diff --git a/tests/include/alt-dummy/des_alt.h b/tests/include/alt-dummy/des_alt.h
index e5a0bd3..3b8abe4 100644
--- a/tests/include/alt-dummy/des_alt.h
+++ b/tests/include/alt-dummy/des_alt.h
@@ -20,14 +20,12 @@
#ifndef DES_ALT_H
#define DES_ALT_H
-typedef struct mbedtls_des_context
-{
+typedef struct mbedtls_des_context {
int dummy;
}
mbedtls_des_context;
-typedef struct mbedtls_des3_context
-{
+typedef struct mbedtls_des3_context {
int dummy;
}
mbedtls_des3_context;
diff --git a/tests/include/alt-dummy/dhm_alt.h b/tests/include/alt-dummy/dhm_alt.h
index 6289a41..ccb3bd3 100644
--- a/tests/include/alt-dummy/dhm_alt.h
+++ b/tests/include/alt-dummy/dhm_alt.h
@@ -19,8 +19,7 @@
#ifndef DHM_ALT_H
#define DHM_ALT_H
-typedef struct mbedtls_dhm_context
-{
+typedef struct mbedtls_dhm_context {
int dummy;
}
mbedtls_dhm_context;
diff --git a/tests/include/alt-dummy/ecjpake_alt.h b/tests/include/alt-dummy/ecjpake_alt.h
index 8de0fcf..90c21da 100644
--- a/tests/include/alt-dummy/ecjpake_alt.h
+++ b/tests/include/alt-dummy/ecjpake_alt.h
@@ -19,8 +19,7 @@
#ifndef ECJPAKE_ALT_H
#define ECJPAKE_ALT_H
-typedef struct mbedtls_ecjpake_context
-{
+typedef struct mbedtls_ecjpake_context {
int dummy;
} mbedtls_ecjpake_context;
diff --git a/tests/include/alt-dummy/ecp_alt.h b/tests/include/alt-dummy/ecp_alt.h
index d263871..56c9810 100644
--- a/tests/include/alt-dummy/ecp_alt.h
+++ b/tests/include/alt-dummy/ecp_alt.h
@@ -19,8 +19,7 @@
#ifndef ECP_ALT_H
#define ECP_ALT_H
-typedef struct mbedtls_ecp_group
-{
+typedef struct mbedtls_ecp_group {
const mbedtls_ecp_group_id id;
const mbedtls_mpi P;
const mbedtls_mpi A;
diff --git a/tests/include/alt-dummy/gcm_alt.h b/tests/include/alt-dummy/gcm_alt.h
index 94986ff..7be5b62 100644
--- a/tests/include/alt-dummy/gcm_alt.h
+++ b/tests/include/alt-dummy/gcm_alt.h
@@ -19,8 +19,7 @@
#ifndef GCM_ALT_H
#define GCM_ALT_H
-typedef struct mbedtls_gcm_context
-{
+typedef struct mbedtls_gcm_context {
int dummy;
}
mbedtls_gcm_context;
diff --git a/tests/include/alt-dummy/md5_alt.h b/tests/include/alt-dummy/md5_alt.h
index c119147..1f3e5ed 100644
--- a/tests/include/alt-dummy/md5_alt.h
+++ b/tests/include/alt-dummy/md5_alt.h
@@ -19,8 +19,7 @@
#ifndef MD5_ALT_H
#define MD5_ALT_H
-typedef struct mbedtls_md5_context
-{
+typedef struct mbedtls_md5_context {
int dummy;
}
mbedtls_md5_context;
diff --git a/tests/include/alt-dummy/platform_alt.h b/tests/include/alt-dummy/platform_alt.h
index 2bf712d..836f299 100644
--- a/tests/include/alt-dummy/platform_alt.h
+++ b/tests/include/alt-dummy/platform_alt.h
@@ -19,8 +19,7 @@
#ifndef PLATFORM_ALT_H
#define PLATFORM_ALT_H
-typedef struct mbedtls_platform_context
-{
+typedef struct mbedtls_platform_context {
int dummy;
}
mbedtls_platform_context;
diff --git a/tests/include/alt-dummy/poly1305_alt.h b/tests/include/alt-dummy/poly1305_alt.h
index b8c1210..5a8295f 100644
--- a/tests/include/alt-dummy/poly1305_alt.h
+++ b/tests/include/alt-dummy/poly1305_alt.h
@@ -19,8 +19,7 @@
#ifndef POLY1305_ALT_H
#define POLY1305_ALT_H
-typedef struct mbedtls_poly1305_context
-{
+typedef struct mbedtls_poly1305_context {
int dummy;
}
mbedtls_poly1305_context;
diff --git a/tests/include/alt-dummy/ripemd160_alt.h b/tests/include/alt-dummy/ripemd160_alt.h
index 722aeeb..ca3b338 100644
--- a/tests/include/alt-dummy/ripemd160_alt.h
+++ b/tests/include/alt-dummy/ripemd160_alt.h
@@ -19,8 +19,7 @@
#ifndef RIPEMD160_ALT_H
#define RIPEMD160_ALT_H
-typedef struct mbedtls_ripemd160_context
-{
+typedef struct mbedtls_ripemd160_context {
int dummy;
}
mbedtls_ripemd160_context;
diff --git a/tests/include/alt-dummy/rsa_alt.h b/tests/include/alt-dummy/rsa_alt.h
index ae80dba..24f672b 100644
--- a/tests/include/alt-dummy/rsa_alt.h
+++ b/tests/include/alt-dummy/rsa_alt.h
@@ -19,8 +19,7 @@
#ifndef RSA_ALT_H
#define RSA_ALT_H
-typedef struct mbedtls_rsa_context
-{
+typedef struct mbedtls_rsa_context {
int dummy;
}
mbedtls_rsa_context;
diff --git a/tests/include/alt-dummy/sha1_alt.h b/tests/include/alt-dummy/sha1_alt.h
index df2990b..36bf71d 100644
--- a/tests/include/alt-dummy/sha1_alt.h
+++ b/tests/include/alt-dummy/sha1_alt.h
@@ -19,8 +19,7 @@
#ifndef SHA1_ALT_H
#define SHA1_ALT_H
-typedef struct mbedtls_sha1_context
-{
+typedef struct mbedtls_sha1_context {
int dummy;
}
mbedtls_sha1_context;
diff --git a/tests/include/alt-dummy/sha256_alt.h b/tests/include/alt-dummy/sha256_alt.h
index 7e501ed..304734b 100644
--- a/tests/include/alt-dummy/sha256_alt.h
+++ b/tests/include/alt-dummy/sha256_alt.h
@@ -19,8 +19,7 @@
#ifndef SHA256_ALT_H
#define SHA256_ALT_H
-typedef struct mbedtls_sha256_context
-{
+typedef struct mbedtls_sha256_context {
int dummy;
}
mbedtls_sha256_context;
diff --git a/tests/include/alt-dummy/sha512_alt.h b/tests/include/alt-dummy/sha512_alt.h
index 45c9599..13e5810 100644
--- a/tests/include/alt-dummy/sha512_alt.h
+++ b/tests/include/alt-dummy/sha512_alt.h
@@ -19,8 +19,7 @@
#ifndef SHA512_ALT_H
#define SHA512_ALT_H
-typedef struct mbedtls_sha512_context
-{
+typedef struct mbedtls_sha512_context {
int dummy;
}
mbedtls_sha512_context;
diff --git a/tests/include/alt-dummy/threading_alt.h b/tests/include/alt-dummy/threading_alt.h
index ff2fed5..4003506 100644
--- a/tests/include/alt-dummy/threading_alt.h
+++ b/tests/include/alt-dummy/threading_alt.h
@@ -19,8 +19,7 @@
#ifndef THREADING_ALT_H
#define THREADING_ALT_H
-typedef struct mbedtls_threading_mutex_t
-{
+typedef struct mbedtls_threading_mutex_t {
int dummy;
} mbedtls_threading_mutex_t;
diff --git a/tests/include/alt-dummy/timing_alt.h b/tests/include/alt-dummy/timing_alt.h
index f2da154..9d4e100 100644
--- a/tests/include/alt-dummy/timing_alt.h
+++ b/tests/include/alt-dummy/timing_alt.h
@@ -19,13 +19,11 @@
#ifndef TIMING_ALT_H
#define TIMING_ALT_H
-struct mbedtls_timing_hr_time
-{
+struct mbedtls_timing_hr_time {
int dummy;
};
-typedef struct mbedtls_timing_delay_context
-{
+typedef struct mbedtls_timing_delay_context {
int dummy;
} mbedtls_timing_delay_context;
diff --git a/tests/include/spe/crypto_spe.h b/tests/include/spe/crypto_spe.h
index 1aee8a5..a79ce17 100644
--- a/tests/include/spe/crypto_spe.h
+++ b/tests/include/spe/crypto_spe.h
@@ -34,110 +34,110 @@
#define PSA_FUNCTION_NAME(x) mbedcrypto__ ## x
#define psa_crypto_init \
- PSA_FUNCTION_NAME(psa_crypto_init)
+ PSA_FUNCTION_NAME(psa_crypto_init)
#define psa_key_derivation_get_capacity \
- PSA_FUNCTION_NAME(psa_key_derivation_get_capacity)
+ PSA_FUNCTION_NAME(psa_key_derivation_get_capacity)
#define psa_key_derivation_set_capacity \
- PSA_FUNCTION_NAME(psa_key_derivation_set_capacity)
+ PSA_FUNCTION_NAME(psa_key_derivation_set_capacity)
#define psa_key_derivation_input_bytes \
- PSA_FUNCTION_NAME(psa_key_derivation_input_bytes)
+ PSA_FUNCTION_NAME(psa_key_derivation_input_bytes)
#define psa_key_derivation_output_bytes \
- PSA_FUNCTION_NAME(psa_key_derivation_output_bytes)
+ PSA_FUNCTION_NAME(psa_key_derivation_output_bytes)
#define psa_key_derivation_input_key \
- PSA_FUNCTION_NAME(psa_key_derivation_input_key)
+ PSA_FUNCTION_NAME(psa_key_derivation_input_key)
#define psa_key_derivation_output_key \
- PSA_FUNCTION_NAME(psa_key_derivation_output_key)
+ PSA_FUNCTION_NAME(psa_key_derivation_output_key)
#define psa_key_derivation_setup \
- PSA_FUNCTION_NAME(psa_key_derivation_setup)
+ PSA_FUNCTION_NAME(psa_key_derivation_setup)
#define psa_key_derivation_abort \
- PSA_FUNCTION_NAME(psa_key_derivation_abort)
+ PSA_FUNCTION_NAME(psa_key_derivation_abort)
#define psa_key_derivation_key_agreement \
- PSA_FUNCTION_NAME(psa_key_derivation_key_agreement)
+ PSA_FUNCTION_NAME(psa_key_derivation_key_agreement)
#define psa_raw_key_agreement \
- PSA_FUNCTION_NAME(psa_raw_key_agreement)
+ PSA_FUNCTION_NAME(psa_raw_key_agreement)
#define psa_generate_random \
- PSA_FUNCTION_NAME(psa_generate_random)
+ PSA_FUNCTION_NAME(psa_generate_random)
#define psa_aead_encrypt \
- PSA_FUNCTION_NAME(psa_aead_encrypt)
+ PSA_FUNCTION_NAME(psa_aead_encrypt)
#define psa_aead_decrypt \
- PSA_FUNCTION_NAME(psa_aead_decrypt)
+ PSA_FUNCTION_NAME(psa_aead_decrypt)
#define psa_open_key \
- PSA_FUNCTION_NAME(psa_open_key)
+ PSA_FUNCTION_NAME(psa_open_key)
#define psa_close_key \
- PSA_FUNCTION_NAME(psa_close_key)
+ PSA_FUNCTION_NAME(psa_close_key)
#define psa_import_key \
- PSA_FUNCTION_NAME(psa_import_key)
+ PSA_FUNCTION_NAME(psa_import_key)
#define psa_destroy_key \
- PSA_FUNCTION_NAME(psa_destroy_key)
+ PSA_FUNCTION_NAME(psa_destroy_key)
#define psa_get_key_attributes \
- PSA_FUNCTION_NAME(psa_get_key_attributes)
+ PSA_FUNCTION_NAME(psa_get_key_attributes)
#define psa_reset_key_attributes \
- PSA_FUNCTION_NAME(psa_reset_key_attributes)
+ PSA_FUNCTION_NAME(psa_reset_key_attributes)
#define psa_export_key \
- PSA_FUNCTION_NAME(psa_export_key)
+ PSA_FUNCTION_NAME(psa_export_key)
#define psa_export_public_key \
- PSA_FUNCTION_NAME(psa_export_public_key)
+ PSA_FUNCTION_NAME(psa_export_public_key)
#define psa_purge_key \
- PSA_FUNCTION_NAME(psa_purge_key)
+ PSA_FUNCTION_NAME(psa_purge_key)
#define psa_copy_key \
- PSA_FUNCTION_NAME(psa_copy_key)
+ PSA_FUNCTION_NAME(psa_copy_key)
#define psa_cipher_operation_init \
- PSA_FUNCTION_NAME(psa_cipher_operation_init)
+ PSA_FUNCTION_NAME(psa_cipher_operation_init)
#define psa_cipher_generate_iv \
- PSA_FUNCTION_NAME(psa_cipher_generate_iv)
+ PSA_FUNCTION_NAME(psa_cipher_generate_iv)
#define psa_cipher_set_iv \
- PSA_FUNCTION_NAME(psa_cipher_set_iv)
+ PSA_FUNCTION_NAME(psa_cipher_set_iv)
#define psa_cipher_encrypt_setup \
- PSA_FUNCTION_NAME(psa_cipher_encrypt_setup)
+ PSA_FUNCTION_NAME(psa_cipher_encrypt_setup)
#define psa_cipher_decrypt_setup \
- PSA_FUNCTION_NAME(psa_cipher_decrypt_setup)
+ PSA_FUNCTION_NAME(psa_cipher_decrypt_setup)
#define psa_cipher_update \
- PSA_FUNCTION_NAME(psa_cipher_update)
+ PSA_FUNCTION_NAME(psa_cipher_update)
#define psa_cipher_finish \
- PSA_FUNCTION_NAME(psa_cipher_finish)
+ PSA_FUNCTION_NAME(psa_cipher_finish)
#define psa_cipher_abort \
- PSA_FUNCTION_NAME(psa_cipher_abort)
+ PSA_FUNCTION_NAME(psa_cipher_abort)
#define psa_hash_operation_init \
- PSA_FUNCTION_NAME(psa_hash_operation_init)
+ PSA_FUNCTION_NAME(psa_hash_operation_init)
#define psa_hash_setup \
- PSA_FUNCTION_NAME(psa_hash_setup)
+ PSA_FUNCTION_NAME(psa_hash_setup)
#define psa_hash_update \
- PSA_FUNCTION_NAME(psa_hash_update)
+ PSA_FUNCTION_NAME(psa_hash_update)
#define psa_hash_finish \
- PSA_FUNCTION_NAME(psa_hash_finish)
+ PSA_FUNCTION_NAME(psa_hash_finish)
#define psa_hash_verify \
- PSA_FUNCTION_NAME(psa_hash_verify)
+ PSA_FUNCTION_NAME(psa_hash_verify)
#define psa_hash_abort \
- PSA_FUNCTION_NAME(psa_hash_abort)
+ PSA_FUNCTION_NAME(psa_hash_abort)
#define psa_hash_clone \
- PSA_FUNCTION_NAME(psa_hash_clone)
+ PSA_FUNCTION_NAME(psa_hash_clone)
#define psa_hash_compute \
- PSA_FUNCTION_NAME(psa_hash_compute)
+ PSA_FUNCTION_NAME(psa_hash_compute)
#define psa_hash_compare \
- PSA_FUNCTION_NAME(psa_hash_compare)
+ PSA_FUNCTION_NAME(psa_hash_compare)
#define psa_mac_operation_init \
- PSA_FUNCTION_NAME(psa_mac_operation_init)
+ PSA_FUNCTION_NAME(psa_mac_operation_init)
#define psa_mac_sign_setup \
- PSA_FUNCTION_NAME(psa_mac_sign_setup)
+ PSA_FUNCTION_NAME(psa_mac_sign_setup)
#define psa_mac_verify_setup \
- PSA_FUNCTION_NAME(psa_mac_verify_setup)
+ PSA_FUNCTION_NAME(psa_mac_verify_setup)
#define psa_mac_update \
- PSA_FUNCTION_NAME(psa_mac_update)
+ PSA_FUNCTION_NAME(psa_mac_update)
#define psa_mac_sign_finish \
- PSA_FUNCTION_NAME(psa_mac_sign_finish)
+ PSA_FUNCTION_NAME(psa_mac_sign_finish)
#define psa_mac_verify_finish \
- PSA_FUNCTION_NAME(psa_mac_verify_finish)
+ PSA_FUNCTION_NAME(psa_mac_verify_finish)
#define psa_mac_abort \
- PSA_FUNCTION_NAME(psa_mac_abort)
+ PSA_FUNCTION_NAME(psa_mac_abort)
#define psa_sign_hash \
- PSA_FUNCTION_NAME(psa_sign_hash)
+ PSA_FUNCTION_NAME(psa_sign_hash)
#define psa_verify_hash \
- PSA_FUNCTION_NAME(psa_verify_hash)
+ PSA_FUNCTION_NAME(psa_verify_hash)
#define psa_asymmetric_encrypt \
- PSA_FUNCTION_NAME(psa_asymmetric_encrypt)
+ PSA_FUNCTION_NAME(psa_asymmetric_encrypt)
#define psa_asymmetric_decrypt \
- PSA_FUNCTION_NAME(psa_asymmetric_decrypt)
+ PSA_FUNCTION_NAME(psa_asymmetric_decrypt)
#define psa_generate_key \
- PSA_FUNCTION_NAME(psa_generate_key)
+ PSA_FUNCTION_NAME(psa_generate_key)
#endif /* CRYPTO_SPE_H */
diff --git a/tests/include/test/asn1_helpers.h b/tests/include/test/asn1_helpers.h
index 91ae260..dee3cbd 100644
--- a/tests/include/test/asn1_helpers.h
+++ b/tests/include/test/asn1_helpers.h
@@ -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 */
diff --git a/tests/include/test/bignum_helpers.h b/tests/include/test/bignum_helpers.h
index 164017e..fc97d23 100644
--- a/tests/include/test/bignum_helpers.h
+++ b/tests/include/test/bignum_helpers.h
@@ -52,8 +52,8 @@
*
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
*/
-int mbedtls_test_read_mpi_core( mbedtls_mpi_uint **pX, size_t *plimbs,
- const char *input );
+int mbedtls_test_read_mpi_core(mbedtls_mpi_uint **pX, size_t *plimbs,
+ const char *input);
/** Read a modulus from a hexadecimal string.
*
@@ -71,16 +71,16 @@
*
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
*/
-int mbedtls_test_read_mpi_modulus( mbedtls_mpi_mod_modulus *N,
- const char *s,
- mbedtls_mpi_mod_rep_selector int_rep );
+int mbedtls_test_read_mpi_modulus(mbedtls_mpi_mod_modulus *N,
+ const char *s,
+ mbedtls_mpi_mod_rep_selector int_rep);
/** Free a modulus and its limbs.
*
* \param[in] N A modulus structure such that there is no other
* reference to `N->p`.
*/
-void mbedtls_test_mpi_mod_modulus_free_with_limbs( mbedtls_mpi_mod_modulus *N );
+void mbedtls_test_mpi_mod_modulus_free_with_limbs(mbedtls_mpi_mod_modulus *N);
/** Read an MPI from a hexadecimal string.
*
@@ -103,7 +103,7 @@
*
* \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.,
diff --git a/tests/include/test/certs.h b/tests/include/test/certs.h
index 03f0d03..65c5582 100644
--- a/tests/include/test/certs.h
+++ b/tests/include/test/certs.h
@@ -33,11 +33,11 @@
/* List of all PEM-encoded CA certificates, terminated by NULL;
* PEM encoded if MBEDTLS_PEM_PARSE_C is enabled, DER encoded
* otherwise. */
-extern const char * mbedtls_test_cas[];
+extern const char *mbedtls_test_cas[];
extern const size_t mbedtls_test_cas_len[];
/* List of all DER-encoded CA certificates, terminated by NULL */
-extern const unsigned char * mbedtls_test_cas_der[];
+extern const unsigned char *mbedtls_test_cas_der[];
extern const size_t mbedtls_test_cas_der_len[];
#if defined(MBEDTLS_PEM_PARSE_C)
@@ -108,9 +108,9 @@
/* Config-dependent dispatch between EC and RSA
* (RSA if enabled, otherwise EC) */
-extern const char * mbedtls_test_ca_crt;
-extern const char * mbedtls_test_ca_key;
-extern const char * mbedtls_test_ca_pwd;
+extern const char *mbedtls_test_ca_crt;
+extern const char *mbedtls_test_ca_key;
+extern const char *mbedtls_test_ca_pwd;
extern const size_t mbedtls_test_ca_crt_len;
extern const size_t mbedtls_test_ca_key_len;
extern const size_t mbedtls_test_ca_pwd_len;
@@ -177,9 +177,9 @@
/* Config-dependent dispatch between EC and RSA
* (RSA if enabled, otherwise EC) */
-extern const char * mbedtls_test_srv_crt;
-extern const char * mbedtls_test_srv_key;
-extern const char * mbedtls_test_srv_pwd;
+extern const char *mbedtls_test_srv_crt;
+extern const char *mbedtls_test_srv_key;
+extern const char *mbedtls_test_srv_pwd;
extern const size_t mbedtls_test_srv_crt_len;
extern const size_t mbedtls_test_srv_key_len;
extern const size_t mbedtls_test_srv_pwd_len;
@@ -232,9 +232,9 @@
/* Config-dependent dispatch between EC and RSA
* (RSA if enabled, otherwise EC) */
-extern const char * mbedtls_test_cli_crt;
-extern const char * mbedtls_test_cli_key;
-extern const char * mbedtls_test_cli_pwd;
+extern const char *mbedtls_test_cli_crt;
+extern const char *mbedtls_test_cli_key;
+extern const char *mbedtls_test_cli_pwd;
extern const size_t mbedtls_test_cli_crt_len;
extern const size_t mbedtls_test_cli_key_len;
extern const size_t mbedtls_test_cli_pwd_len;
diff --git a/tests/include/test/drivers/aead.h b/tests/include/test/drivers/aead.h
index 33e1f50..037a255 100644
--- a/tests/include/test/drivers/aead.h
+++ b/tests/include/test/drivers/aead.h
@@ -48,10 +48,10 @@
#define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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;
@@ -63,7 +63,7 @@
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,
@@ -72,62 +72,62 @@
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);
psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
mbedtls_transparent_test_driver_aead_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_aead_decrypt_setup(
mbedtls_transparent_test_driver_aead_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_aead_set_nonce(
mbedtls_transparent_test_driver_aead_operation_t *operation,
const uint8_t *nonce,
- size_t nonce_length );
+ size_t nonce_length);
psa_status_t mbedtls_test_transparent_aead_set_lengths(
mbedtls_transparent_test_driver_aead_operation_t *operation,
size_t ad_length,
- size_t plaintext_length );
+ size_t plaintext_length);
psa_status_t mbedtls_test_transparent_aead_update_ad(
mbedtls_transparent_test_driver_aead_operation_t *operation,
const uint8_t *input,
- size_t input_length );
+ size_t input_length);
psa_status_t mbedtls_test_transparent_aead_update(
- mbedtls_transparent_test_driver_aead_operation_t *operation,
- const uint8_t *input,
- size_t input_length,
- uint8_t *output,
- size_t output_size,
- size_t *output_length );
+ mbedtls_transparent_test_driver_aead_operation_t *operation,
+ const uint8_t *input,
+ size_t input_length,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length);
psa_status_t mbedtls_test_transparent_aead_finish(
- mbedtls_transparent_test_driver_aead_operation_t *operation,
- uint8_t *ciphertext,
- size_t ciphertext_size,
- size_t *ciphertext_length,
- uint8_t *tag,
- size_t tag_size,
- size_t *tag_length );
+ mbedtls_transparent_test_driver_aead_operation_t *operation,
+ uint8_t *ciphertext,
+ size_t ciphertext_size,
+ size_t *ciphertext_length,
+ uint8_t *tag,
+ size_t tag_size,
+ size_t *tag_length);
psa_status_t mbedtls_test_transparent_aead_verify(
- mbedtls_transparent_test_driver_aead_operation_t *operation,
- uint8_t *plaintext,
- size_t plaintext_size,
- size_t *plaintext_length,
- const uint8_t *tag,
- size_t tag_length );
+ mbedtls_transparent_test_driver_aead_operation_t *operation,
+ uint8_t *plaintext,
+ size_t plaintext_size,
+ size_t *plaintext_length,
+ const uint8_t *tag,
+ size_t tag_length);
psa_status_t mbedtls_test_transparent_aead_abort(
- mbedtls_transparent_test_driver_aead_operation_t *operation );
+ mbedtls_transparent_test_driver_aead_operation_t *operation);
#endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */
diff --git a/tests/include/test/drivers/asymmetric_encryption.h b/tests/include/test/drivers/asymmetric_encryption.h
index 595e18d..c602d2f 100644
--- a/tests/include/test/drivers/asymmetric_encryption.h
+++ b/tests/include/test/drivers/asymmetric_encryption.h
@@ -41,11 +41,11 @@
#define MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT { NULL, 0, PSA_SUCCESS, 0 }
static inline mbedtls_test_driver_asymmetric_encryption_hooks_t
- mbedtls_test_driver_asymmetric_encryption_hooks_init( void )
+mbedtls_test_driver_asymmetric_encryption_hooks_init(void)
{
const mbedtls_test_driver_asymmetric_encryption_hooks_t v =
MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT;
- return( v );
+ return v;
}
extern mbedtls_test_driver_asymmetric_encryption_hooks_t
@@ -55,25 +55,25 @@
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length );
+ uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
const psa_key_attributes_t *attributes, const uint8_t *key,
size_t key_length, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length );
+ uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length );
+ uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
const psa_key_attributes_t *attributes, const uint8_t *key,
size_t key_length, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length );
+ uint8_t *output, size_t output_size, size_t *output_length);
#endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H */
diff --git a/tests/include/test/drivers/cipher.h b/tests/include/test/drivers/cipher.h
index 33a5e66..54c37f7 100644
--- a/tests/include/test/drivers/cipher.h
+++ b/tests/include/test/drivers/cipher.h
@@ -41,10 +41,10 @@
#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;
@@ -77,7 +77,7 @@
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,
diff --git a/tests/include/test/drivers/hash.h b/tests/include/test/drivers/hash.h
index b05fcd7..f1da8d3 100644
--- a/tests/include/test/drivers/hash.h
+++ b/tests/include/test/drivers/hash.h
@@ -37,10 +37,10 @@
#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;
@@ -48,29 +48,29 @@
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 */
diff --git a/tests/include/test/drivers/key_agreement.h b/tests/include/test/drivers/key_agreement.h
index 8f28cef..aaf74a8 100644
--- a/tests/include/test/drivers/key_agreement.h
+++ b/tests/include/test/drivers/key_agreement.h
@@ -38,11 +38,11 @@
#define MBEDTLS_TEST_DRIVER_KEY_AGREEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 }
static inline mbedtls_test_driver_key_agreement_hooks_t
- mbedtls_test_driver_key_agreement_hooks_init( void )
+mbedtls_test_driver_key_agreement_hooks_init(void)
{
const mbedtls_test_driver_key_agreement_hooks_t
v = MBEDTLS_TEST_DRIVER_KEY_AGREEMENT_INIT;
- return( v );
+ return v;
}
extern mbedtls_test_driver_key_agreement_hooks_t
@@ -57,7 +57,7 @@
size_t peer_key_length,
uint8_t *shared_secret,
size_t shared_secret_size,
- size_t *shared_secret_length );
+ size_t *shared_secret_length);
psa_status_t mbedtls_test_opaque_key_agreement(
const psa_key_attributes_t *attributes,
@@ -68,7 +68,7 @@
size_t peer_key_length,
uint8_t *shared_secret,
size_t shared_secret_size,
- size_t *shared_secret_length );
+ size_t *shared_secret_length);
#endif /*PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_TEST_DRIVERS_KEY_AGREEMENT_H */
diff --git a/tests/include/test/drivers/key_management.h b/tests/include/test/drivers/key_management.h
index 1f33da1..43df0d6 100644
--- a/tests/include/test/drivers/key_management.h
+++ b/tests/include/test/drivers/key_management.h
@@ -48,11 +48,11 @@
* 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;
}
/*
@@ -63,42 +63,42 @@
*/
#define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX 0xBEEFED00U
#define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE sizeof( \
- PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX )
+ PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX)
size_t mbedtls_test_opaque_size_function(
const psa_key_type_t key_type,
- const size_t key_bits );
+ const size_t key_bits);
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,
@@ -121,7 +121,7 @@
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);
psa_status_t mbedtls_test_opaque_copy_key(
psa_key_attributes_t *attributes,
diff --git a/tests/include/test/drivers/mac.h b/tests/include/test/drivers/mac.h
index 5f6cd38..bdc2b70 100644
--- a/tests/include/test/drivers/mac.h
+++ b/tests/include/test/drivers/mac.h
@@ -37,10 +37,10 @@
#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;
@@ -54,40 +54,40 @@
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,
@@ -98,40 +98,40 @@
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 */
diff --git a/tests/include/test/drivers/signature.h b/tests/include/test/drivers/signature.h
index 67f2b29..4c56a12 100644
--- a/tests/include/test/drivers/signature.h
+++ b/tests/include/test/drivers/signature.h
@@ -38,11 +38,11 @@
#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
@@ -59,7 +59,7 @@
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,
@@ -70,7 +70,7 @@
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,
@@ -80,7 +80,7 @@
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,
@@ -90,35 +90,35 @@
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 */
diff --git a/tests/include/test/fake_external_rng_for_test.h b/tests/include/test/fake_external_rng_for_test.h
index 9d56dab..01bfb91 100644
--- a/tests/include/test/fake_external_rng_for_test.h
+++ b/tests/include/test/fake_external_rng_for_test.h
@@ -40,13 +40,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 */
diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h
index b64bfcb..dd4a6a2 100644
--- a/tests/include/test/helpers.h
+++ b/tests/include/test/helpers.h
@@ -47,21 +47,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;
@@ -76,8 +73,8 @@
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.
@@ -95,7 +92,7 @@
* \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.
@@ -108,7 +105,7 @@
* \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.
@@ -120,12 +117,12 @@
*
* \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
@@ -145,8 +142,8 @@
*
* \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
@@ -166,8 +163,8 @@
*
* \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
@@ -187,8 +184,8 @@
*
* \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
@@ -208,12 +205,12 @@
* \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);
/**
* \brief Convert hexadecimal digit to an integer.
@@ -233,7 +230,7 @@
*
* 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.
@@ -245,10 +242,10 @@
*
* 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_PSA_CRYPTO_C) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
#include "test/fake_external_rng_for_test.h"
@@ -257,11 +254,11 @@
#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)
@@ -276,8 +273,8 @@
*
* \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
#endif /* TEST_HELPERS_H */
diff --git a/tests/include/test/macros.h b/tests/include/test/macros.h
index 695a243..83a48cd 100644
--- a/tests/include/test/macros.h
+++ b/tests/include/test/macros.h
@@ -51,14 +51,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.
@@ -69,12 +69,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).
@@ -82,12 +82,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).
@@ -95,12 +95,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.
@@ -122,36 +122,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.
*
@@ -165,14 +165,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
@@ -180,21 +180,21 @@
*
* \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)
-#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.
@@ -205,34 +205,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.
@@ -242,7 +242,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.
*
@@ -251,29 +251,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 */
diff --git a/tests/include/test/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h
index 3542950..19a0483 100644
--- a/tests/include/test/psa_crypto_helpers.h
+++ b/tests/include/test/psa_crypto_helpers.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 @@
* 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 @@
*
* \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 @@
* \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 @@
* `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 @@
* \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 @@
* 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 @@
* 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 @@
* 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 @@
#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,30 +262,30 @@
#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)
#if !defined(MBEDTLS_MD_C)
-#define PSA_INIT_IF_NO_MD( ) PSA_INIT( )
-#define PSA_DONE_IF_NO_MD( ) PSA_DONE( )
+#define PSA_INIT_IF_NO_MD() PSA_INIT()
+#define PSA_DONE_IF_NO_MD() PSA_DONE()
#endif
#endif /* MBEDTLS_PSA_CRYPTO_C */
#if defined(MBEDTLS_MD_C)
-#define PSA_INIT_IF_NO_MD( ) ( (void) 0 )
-#define PSA_DONE_IF_NO_MD( ) ( (void) 0 )
+#define PSA_INIT_IF_NO_MD() ((void) 0)
+#define PSA_DONE_IF_NO_MD() ((void) 0)
#endif
/** \def USE_PSA_INIT
*
@@ -303,14 +303,14 @@
* #MBEDTLS_USE_PSA_CRYPTO is disabled.
*/
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
-#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 || MBEDTLS_SSL_PROTO_TLS1_3 */
/* 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 && !MBEDTLS_SSL_PROTO_TLS1_3 */
#endif /* PSA_CRYPTO_HELPERS_H */
diff --git a/tests/include/test/psa_exercise_key.h b/tests/include/test/psa_exercise_key.h
index aa0aeb5..eb69fc6 100644
--- a/tests/include/test/psa_exercise_key.h
+++ b/tests/include/test/psa_exercise_key.h
@@ -77,7 +77,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
@@ -133,12 +133,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().
@@ -154,7 +154,7 @@
*/
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().
@@ -173,7 +173,7 @@
*/
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.
*
@@ -195,7 +195,7 @@
*/
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.
*
@@ -224,11 +224,11 @@
* \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 */
diff --git a/tests/include/test/psa_helpers.h b/tests/include/test/psa_helpers.h
index f438a71..2665fac 100644
--- a/tests/include/test/psa_helpers.h
+++ b/tests/include/test/psa_helpers.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 */
diff --git a/tests/include/test/random.h b/tests/include/test/random.h
index 58548a2..c557208 100644
--- a/tests/include/test/random.h
+++ b/tests/include/test/random.h
@@ -30,12 +30,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;
@@ -46,8 +45,7 @@
* 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;
@@ -61,18 +59,18 @@
*
* 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.
@@ -86,9 +84,9 @@
* #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.
@@ -98,8 +96,8 @@
*
* \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 */
diff --git a/tests/src/asn1_helpers.c b/tests/src/asn1_helpers.c
index 79aa166..aaf7587 100644
--- a/tests/src/asn1_helpers.c
+++ b/tests/src/asn1_helpers.c
@@ -27,48 +27,48 @@
#include <mbedtls/asn1.h>
-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)
{
size_t len;
size_t actual_bits;
unsigned char msb;
- TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len,
- MBEDTLS_ASN1_INTEGER ),
- 0 );
+ TEST_EQUAL(mbedtls_asn1_get_tag(p, end, &len,
+ MBEDTLS_ASN1_INTEGER),
+ 0);
/* Check if the retrieved length doesn't extend the actual buffer's size.
* It is assumed here, that end >= p, which validates casting to size_t. */
- TEST_ASSERT( len <= (size_t)( end - *p) );
+ TEST_ASSERT(len <= (size_t) (end - *p));
/* Tolerate a slight departure from DER encoding:
* - 0 may be represented by an empty string or a 1-byte string.
* - The sign bit may be used as a value bit. */
- if( ( len == 1 && ( *p )[0] == 0 ) ||
- ( len > 1 && ( *p )[0] == 0 && ( ( *p )[1] & 0x80 ) != 0 ) )
- {
- ++( *p );
+ if ((len == 1 && (*p)[0] == 0) ||
+ (len > 1 && (*p)[0] == 0 && ((*p)[1] & 0x80) != 0)) {
+ ++(*p);
--len;
}
- if( min_bits == 0 && len == 0 )
- return( 1 );
- msb = ( *p )[0];
- TEST_ASSERT( msb != 0 );
- actual_bits = 8 * ( len - 1 );
- while( msb != 0 )
- {
+ if (min_bits == 0 && len == 0) {
+ return 1;
+ }
+ msb = (*p)[0];
+ TEST_ASSERT(msb != 0);
+ actual_bits = 8 * (len - 1);
+ while (msb != 0) {
msb >>= 1;
++actual_bits;
}
- TEST_ASSERT( actual_bits >= min_bits );
- TEST_ASSERT( actual_bits <= max_bits );
- if( must_be_odd )
- TEST_ASSERT( ( ( *p )[len-1] & 1 ) != 0 );
+ TEST_ASSERT(actual_bits >= min_bits);
+ TEST_ASSERT(actual_bits <= max_bits);
+ if (must_be_odd) {
+ TEST_ASSERT(((*p)[len-1] & 1) != 0);
+ }
*p += len;
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
#endif /* MBEDTLS_ASN1_PARSE_C */
diff --git a/tests/src/bignum_helpers.c b/tests/src/bignum_helpers.c
index d6ec9bd..4dd3791 100644
--- a/tests/src/bignum_helpers.c
+++ b/tests/src/bignum_helpers.c
@@ -38,105 +38,107 @@
#include <test/helpers.h>
#include <test/macros.h>
-int mbedtls_test_read_mpi_core( mbedtls_mpi_uint **pX, size_t *plimbs,
- const char *input )
+int mbedtls_test_read_mpi_core(mbedtls_mpi_uint **pX, size_t *plimbs,
+ const char *input)
{
/* Sanity check */
- if( *pX != NULL )
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ if (*pX != NULL) {
+ return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+ }
- size_t hex_len = strlen( input );
- size_t byte_len = ( hex_len + 1 ) / 2;
- *plimbs = CHARS_TO_LIMBS( byte_len );
+ size_t hex_len = strlen(input);
+ size_t byte_len = (hex_len + 1) / 2;
+ *plimbs = CHARS_TO_LIMBS(byte_len);
/* A core bignum is not allowed to be empty. Forbid it as test data,
* this way static analyzers have a chance of knowing we don't expect
* the bignum functions to support empty inputs. */
- if( *plimbs == 0 )
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
-
- *pX = mbedtls_calloc( *plimbs, sizeof( **pX ) );
- if( *pX == NULL )
- return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
-
- unsigned char *byte_start = ( unsigned char * ) *pX;
- if( byte_len % sizeof( mbedtls_mpi_uint ) != 0 )
- {
- byte_start += sizeof( mbedtls_mpi_uint ) - byte_len % sizeof( mbedtls_mpi_uint );
+ if (*plimbs == 0) {
+ return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
}
- if( ( hex_len & 1 ) != 0 )
- {
+
+ *pX = mbedtls_calloc(*plimbs, sizeof(**pX));
+ if (*pX == NULL) {
+ return MBEDTLS_ERR_MPI_ALLOC_FAILED;
+ }
+
+ unsigned char *byte_start = (unsigned char *) *pX;
+ if (byte_len % sizeof(mbedtls_mpi_uint) != 0) {
+ byte_start += sizeof(mbedtls_mpi_uint) - byte_len % sizeof(mbedtls_mpi_uint);
+ }
+ if ((hex_len & 1) != 0) {
/* mbedtls_test_unhexify wants an even number of hex digits */
- TEST_ASSERT( mbedtls_test_ascii2uc( *input, byte_start ) == 0 );
+ TEST_ASSERT(mbedtls_test_ascii2uc(*input, byte_start) == 0);
++byte_start;
++input;
--byte_len;
}
- TEST_ASSERT( mbedtls_test_unhexify( byte_start,
- byte_len,
- input,
- &byte_len ) == 0 );
+ TEST_ASSERT(mbedtls_test_unhexify(byte_start,
+ byte_len,
+ input,
+ &byte_len) == 0);
- mbedtls_mpi_core_bigendian_to_host( *pX, *plimbs );
- return( 0 );
+ mbedtls_mpi_core_bigendian_to_host(*pX, *plimbs);
+ return 0;
exit:
- mbedtls_free( *pX );
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ mbedtls_free(*pX);
+ return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
}
-int mbedtls_test_read_mpi_modulus( mbedtls_mpi_mod_modulus *N,
- const char *s,
- mbedtls_mpi_mod_rep_selector int_rep )
+int mbedtls_test_read_mpi_modulus(mbedtls_mpi_mod_modulus *N,
+ const char *s,
+ mbedtls_mpi_mod_rep_selector int_rep)
{
mbedtls_mpi_uint *p = NULL;
size_t limbs = 0;
- if( N->limbs != 0 )
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
- int ret = mbedtls_test_read_mpi_core( &p, &limbs, s );
- if( ret != 0 )
- return( ret );
- ret = mbedtls_mpi_mod_modulus_setup( N, p, limbs, int_rep );
- if( ret != 0 )
- mbedtls_free( p );
- return( ret );
+ if (N->limbs != 0) {
+ return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+ }
+ int ret = mbedtls_test_read_mpi_core(&p, &limbs, s);
+ if (ret != 0) {
+ return ret;
+ }
+ ret = mbedtls_mpi_mod_modulus_setup(N, p, limbs, int_rep);
+ if (ret != 0) {
+ mbedtls_free(p);
+ }
+ return ret;
}
-void mbedtls_test_mpi_mod_modulus_free_with_limbs( mbedtls_mpi_mod_modulus *N )
+void mbedtls_test_mpi_mod_modulus_free_with_limbs(mbedtls_mpi_mod_modulus *N)
{
- mbedtls_free( (mbedtls_mpi_uint*) N->p );
- mbedtls_mpi_mod_modulus_free( N );
+ mbedtls_free((mbedtls_mpi_uint *) N->p);
+ mbedtls_mpi_mod_modulus_free(N);
}
-int mbedtls_test_read_mpi( mbedtls_mpi *X, const char *s )
+int mbedtls_test_read_mpi(mbedtls_mpi *X, const char *s)
{
int negative = 0;
/* Always set the sign bit to -1 if the input has a minus sign, even for 0.
* This creates an invalid representation, which mbedtls_mpi_read_string()
* avoids but we want to be able to create that in test data. */
- if( s[0] == '-' )
- {
+ if (s[0] == '-') {
++s;
negative = 1;
}
/* mbedtls_mpi_read_string() currently retains leading zeros.
* It always allocates at least one limb for the value 0. */
- if( s[0] == 0 )
- {
- mbedtls_mpi_free( X );
- return( 0 );
+ if (s[0] == 0) {
+ mbedtls_mpi_free(X);
+ return 0;
}
- int ret = mbedtls_mpi_read_string( X, 16, s );
- if( ret != 0 )
- return( ret );
- if( negative )
- {
- if( mbedtls_mpi_cmp_int( X, 0 ) == 0 )
+ int ret = mbedtls_mpi_read_string(X, 16, s);
+ if (ret != 0) {
+ return ret;
+ }
+ if (negative) {
+ if (mbedtls_mpi_cmp_int(X, 0) == 0) {
++mbedtls_test_case_uses_negative_0;
+ }
X->s = -1;
}
- return( 0 );
+ return 0;
}
#endif /* MBEDTLS_BIGNUM_C */
-
diff --git a/tests/src/certs.c b/tests/src/certs.c
index ca03b29..1fcdc42 100644
--- a/tests/src/certs.c
+++ b/tests/src/certs.c
@@ -59,50 +59,50 @@
/* This is generated from tests/data_files/test-ca2.crt.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_CA_CRT_EC_DER tests/data_files/test-ca2.crt.der */
#define TEST_CA_CRT_EC_DER { \
- 0x30, 0x82, 0x02, 0x04, 0x30, 0x82, 0x01, 0x88, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x09, 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, \
- 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, \
- 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, \
- 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, \
- 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
- 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, \
- 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, \
- 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, \
- 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, \
- 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, \
- 0x30, 0x5a, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, \
- 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, \
- 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
- 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, \
- 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, \
- 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x76, 0x30, 0x10, 0x06, 0x07, \
- 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, \
- 0x00, 0x22, 0x03, 0x62, 0x00, 0x04, 0xc3, 0xda, 0x2b, 0x34, 0x41, 0x37, \
- 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, 0xba, 0x29, 0x43, 0x4b, 0x4e, \
- 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, 0x39, 0x58, 0xd4, 0x52, 0xb4, \
- 0x91, 0x95, 0x39, 0x0b, 0x23, 0xdf, 0x5f, 0x17, 0x24, 0x62, 0x48, 0xfc, \
- 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, 0xc2, 0x88, 0x52, 0x80, 0xaf, \
- 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, 0x1c, 0x6e, 0x58, 0xb8, 0xca, \
- 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, 0x29, 0xc3, 0xb4, 0x5f, 0x75, \
- 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, 0x55, 0x69, 0x9a, 0x53, 0x3b, 0x20, \
- 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, \
- 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, \
- 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x9d, \
- 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, \
- 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x1f, 0x06, 0x03, 0x55, \
- 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, \
- 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, \
- 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
- 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, \
- 0x30, 0x51, 0xca, 0xae, 0x30, 0x0f, 0xa4, 0x70, 0x74, 0x04, 0xdd, 0x5a, \
- 0x2c, 0x7f, 0x13, 0xc1, 0xc2, 0x77, 0xbe, 0x1d, 0x00, 0xc5, 0xe2, 0x99, \
- 0x8f, 0x7d, 0x26, 0x45, 0xd3, 0x8a, 0x06, 0x68, 0x3f, 0x8c, 0xb4, 0xb7, \
- 0xad, 0x4d, 0xe0, 0xf1, 0x54, 0x01, 0x1e, 0x99, 0xfc, 0xb0, 0xe4, 0xd3, \
- 0x07, 0x02, 0x31, 0x00, 0xdc, 0x4f, 0x3b, 0x90, 0x1e, 0xae, 0x29, 0x99, \
- 0x84, 0x28, 0xcc, 0x7b, 0x47, 0x78, 0x09, 0x31, 0xdf, 0xd6, 0x01, 0x59, \
- 0x30, 0x5e, 0xf4, 0xf8, 0x8a, 0x84, 0x3f, 0xea, 0x39, 0x54, 0x7b, 0x08, \
- 0xa7, 0x60, 0xaa, 0xbd, 0xf9, 0x5b, 0xd1, 0x51, 0x96, 0x14, 0x2e, 0x65, \
- 0xf5, 0xae, 0x1c, 0x42 \
+ 0x30, 0x82, 0x02, 0x04, 0x30, 0x82, 0x01, 0x88, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x09, 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, \
+ 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, \
+ 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, \
+ 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, \
+ 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, \
+ 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, \
+ 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, \
+ 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, \
+ 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, \
+ 0x30, 0x5a, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, \
+ 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, \
+ 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, \
+ 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, \
+ 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x76, 0x30, 0x10, 0x06, 0x07, \
+ 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, \
+ 0x00, 0x22, 0x03, 0x62, 0x00, 0x04, 0xc3, 0xda, 0x2b, 0x34, 0x41, 0x37, \
+ 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, 0xba, 0x29, 0x43, 0x4b, 0x4e, \
+ 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, 0x39, 0x58, 0xd4, 0x52, 0xb4, \
+ 0x91, 0x95, 0x39, 0x0b, 0x23, 0xdf, 0x5f, 0x17, 0x24, 0x62, 0x48, 0xfc, \
+ 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, 0xc2, 0x88, 0x52, 0x80, 0xaf, \
+ 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, 0x1c, 0x6e, 0x58, 0xb8, 0xca, \
+ 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, 0x29, 0xc3, 0xb4, 0x5f, 0x75, \
+ 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, 0x55, 0x69, 0x9a, 0x53, 0x3b, 0x20, \
+ 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, \
+ 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, \
+ 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x9d, \
+ 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, \
+ 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x1f, 0x06, 0x03, 0x55, \
+ 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, \
+ 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, \
+ 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
+ 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, \
+ 0x30, 0x51, 0xca, 0xae, 0x30, 0x0f, 0xa4, 0x70, 0x74, 0x04, 0xdd, 0x5a, \
+ 0x2c, 0x7f, 0x13, 0xc1, 0xc2, 0x77, 0xbe, 0x1d, 0x00, 0xc5, 0xe2, 0x99, \
+ 0x8f, 0x7d, 0x26, 0x45, 0xd3, 0x8a, 0x06, 0x68, 0x3f, 0x8c, 0xb4, 0xb7, \
+ 0xad, 0x4d, 0xe0, 0xf1, 0x54, 0x01, 0x1e, 0x99, 0xfc, 0xb0, 0xe4, 0xd3, \
+ 0x07, 0x02, 0x31, 0x00, 0xdc, 0x4f, 0x3b, 0x90, 0x1e, 0xae, 0x29, 0x99, \
+ 0x84, 0x28, 0xcc, 0x7b, 0x47, 0x78, 0x09, 0x31, 0xdf, 0xd6, 0x01, 0x59, \
+ 0x30, 0x5e, 0xf4, 0xf8, 0x8a, 0x84, 0x3f, 0xea, 0x39, 0x54, 0x7b, 0x08, \
+ 0xa7, 0x60, 0xaa, 0xbd, 0xf9, 0x5b, 0xd1, 0x51, 0x96, 0x14, 0x2e, 0x65, \
+ 0xf5, 0xae, 0x1c, 0x42 \
}
/* END FILE */
@@ -125,20 +125,20 @@
/* This is generated from tests/data_files/test-ca2.key.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_CA_KEY_EC_DER tests/data_files/test-ca2.key.der */
#define TEST_CA_KEY_EC_DER { \
- 0x30, 0x81, 0xa4, 0x02, 0x01, 0x01, 0x04, 0x30, 0x83, 0xd9, 0x15, 0x0e, \
- 0xa0, 0x71, 0xf0, 0x57, 0x10, 0x33, 0xa3, 0x38, 0xb8, 0x86, 0xc1, 0xa6, \
- 0x11, 0x5d, 0x6d, 0xb4, 0x03, 0xe1, 0x29, 0x76, 0x45, 0xd7, 0x87, 0x6f, \
- 0x23, 0xab, 0x44, 0x20, 0xea, 0x64, 0x7b, 0x85, 0xb1, 0x76, 0xe7, 0x85, \
- 0x95, 0xaa, 0x74, 0xd6, 0xd1, 0xa4, 0x5e, 0xea, 0xa0, 0x07, 0x06, 0x05, \
- 0x2b, 0x81, 0x04, 0x00, 0x22, 0xa1, 0x64, 0x03, 0x62, 0x00, 0x04, 0xc3, \
- 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, \
- 0xba, 0x29, 0x43, 0x4b, 0x4e, 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, \
- 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, 0x39, 0x0b, 0x23, 0xdf, 0x5f, \
- 0x17, 0x24, 0x62, 0x48, 0xfc, 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, \
- 0xc2, 0x88, 0x52, 0x80, 0xaf, 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, \
- 0x1c, 0x6e, 0x58, 0xb8, 0xca, 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, \
- 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, 0x55, \
- 0x69, 0x9a, 0x53, 0x3b, 0x20, 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e \
+ 0x30, 0x81, 0xa4, 0x02, 0x01, 0x01, 0x04, 0x30, 0x83, 0xd9, 0x15, 0x0e, \
+ 0xa0, 0x71, 0xf0, 0x57, 0x10, 0x33, 0xa3, 0x38, 0xb8, 0x86, 0xc1, 0xa6, \
+ 0x11, 0x5d, 0x6d, 0xb4, 0x03, 0xe1, 0x29, 0x76, 0x45, 0xd7, 0x87, 0x6f, \
+ 0x23, 0xab, 0x44, 0x20, 0xea, 0x64, 0x7b, 0x85, 0xb1, 0x76, 0xe7, 0x85, \
+ 0x95, 0xaa, 0x74, 0xd6, 0xd1, 0xa4, 0x5e, 0xea, 0xa0, 0x07, 0x06, 0x05, \
+ 0x2b, 0x81, 0x04, 0x00, 0x22, 0xa1, 0x64, 0x03, 0x62, 0x00, 0x04, 0xc3, \
+ 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, \
+ 0xba, 0x29, 0x43, 0x4b, 0x4e, 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, \
+ 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, 0x39, 0x0b, 0x23, 0xdf, 0x5f, \
+ 0x17, 0x24, 0x62, 0x48, 0xfc, 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, \
+ 0xc2, 0x88, 0x52, 0x80, 0xaf, 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, \
+ 0x1c, 0x6e, 0x58, 0xb8, 0xca, 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, \
+ 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, 0x55, \
+ 0x69, 0x9a, 0x53, 0x3b, 0x20, 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e \
}
/* END FILE */
@@ -171,76 +171,76 @@
* using `xxd -i`. */
/* BEGIN FILE binary macro TEST_CA_CRT_RSA_SHA256_DER tests/data_files/test-ca-sha256.crt.der */
#define TEST_CA_CRT_RSA_SHA256_DER { \
- 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
- 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
- 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
- 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
- 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
- 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
- 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
- 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, \
- 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \
- 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
- 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
- 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
- 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \
- 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, \
- 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, \
- 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, \
- 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, \
- 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, \
- 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, \
- 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, \
- 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, \
- 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, \
- 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, \
- 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, \
- 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \
- 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, \
- 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, \
- 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, \
- 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, \
- 0xee, 0xe2, 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, \
- 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, \
- 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, \
- 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, \
- 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, \
- 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, \
- 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, \
- 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, \
- 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, \
- 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, \
- 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \
- 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, \
- 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \
- 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, \
- 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, \
- 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, \
- 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, \
- 0x03, 0x82, 0x01, 0x01, 0x00, 0x38, 0xa8, 0x54, 0x82, 0xb6, 0x1d, 0xaa, \
- 0xdb, 0x6b, 0x89, 0x21, 0xd1, 0x38, 0x28, 0x61, 0xc9, 0xb0, 0x98, 0xd5, \
- 0x11, 0xfc, 0x36, 0xff, 0x19, 0xfe, 0x32, 0x44, 0xef, 0x08, 0xc7, 0xf1, \
- 0x56, 0xbb, 0xe6, 0x46, 0xfa, 0x82, 0xb6, 0x31, 0x38, 0xb4, 0xa0, 0xe5, \
- 0xa0, 0xae, 0x0c, 0xc4, 0x53, 0x9e, 0x93, 0x4e, 0xe8, 0x0d, 0x9c, 0x2f, \
- 0xb4, 0x04, 0xfd, 0x8a, 0x39, 0xf5, 0x84, 0x77, 0xed, 0x4c, 0xd4, 0xbb, \
- 0x44, 0x7f, 0x73, 0x77, 0xf7, 0xf1, 0x36, 0x97, 0xdc, 0x1e, 0x73, 0x19, \
- 0x5d, 0x50, 0xb8, 0xc3, 0x80, 0xcd, 0x03, 0x57, 0xd2, 0x00, 0xdb, 0x56, \
- 0xe6, 0xc6, 0x35, 0x24, 0x1e, 0x49, 0x7b, 0xd8, 0xd2, 0x72, 0xbb, 0x0b, \
- 0x49, 0x2f, 0xa6, 0x02, 0x3c, 0xaf, 0xd0, 0xec, 0x37, 0x1d, 0xbd, 0x81, \
- 0x8b, 0x1f, 0x30, 0xbb, 0xbc, 0x4d, 0x36, 0xb5, 0x79, 0x7c, 0x87, 0xfb, \
- 0x51, 0xb9, 0xbe, 0xc2, 0xde, 0x92, 0xa8, 0x40, 0x71, 0xbb, 0x72, 0x9b, \
- 0xf8, 0x47, 0xce, 0x6c, 0x04, 0xf8, 0x86, 0xe7, 0xf7, 0x73, 0x3c, 0xe7, \
- 0x84, 0x7d, 0xc2, 0xd7, 0xb7, 0x9d, 0xe8, 0xd4, 0x9b, 0x5f, 0x0a, 0x17, \
- 0x7d, 0xbc, 0xbb, 0xb2, 0xd5, 0x94, 0x0d, 0xe4, 0x49, 0xbf, 0x4f, 0x11, \
- 0x68, 0x53, 0xb2, 0x91, 0xff, 0xc0, 0x69, 0xee, 0xdb, 0x63, 0x93, 0xcb, \
- 0xc9, 0x35, 0x6b, 0x90, 0x09, 0xe2, 0x90, 0xc9, 0xed, 0x27, 0xd6, 0x08, \
- 0xfa, 0x13, 0x4d, 0x62, 0xdd, 0xe2, 0x9e, 0xaa, 0xb5, 0xd4, 0x0e, 0x5c, \
- 0x37, 0x4f, 0xab, 0x55, 0x3b, 0x2d, 0xf1, 0x42, 0x82, 0xc7, 0x34, 0x38, \
- 0x1a, 0x9b, 0xeb, 0xa1, 0x2c, 0x0f, 0x29, 0x31, 0x64, 0x6c, 0xcc, 0x38, \
- 0xfd, 0xa9, 0xd3, 0xd5, 0xd5, 0x71, 0xaf, 0xf0, 0x6d, 0xc0, 0x97, 0xe2, \
- 0x11, 0x2a, 0x0a, 0xdf, 0xfe, 0x02, 0x79, 0x74, 0x75 \
+ 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, \
+ 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, \
+ 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, \
+ 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, \
+ 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, \
+ 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, \
+ 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, \
+ 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, \
+ 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, \
+ 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \
+ 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, \
+ 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, \
+ 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, \
+ 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, \
+ 0xee, 0xe2, 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, \
+ 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, \
+ 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, \
+ 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, \
+ 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, \
+ 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, \
+ 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, \
+ 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, \
+ 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, \
+ 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, \
+ 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \
+ 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, \
+ 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \
+ 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, \
+ 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, \
+ 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x01, 0x00, 0x38, 0xa8, 0x54, 0x82, 0xb6, 0x1d, 0xaa, \
+ 0xdb, 0x6b, 0x89, 0x21, 0xd1, 0x38, 0x28, 0x61, 0xc9, 0xb0, 0x98, 0xd5, \
+ 0x11, 0xfc, 0x36, 0xff, 0x19, 0xfe, 0x32, 0x44, 0xef, 0x08, 0xc7, 0xf1, \
+ 0x56, 0xbb, 0xe6, 0x46, 0xfa, 0x82, 0xb6, 0x31, 0x38, 0xb4, 0xa0, 0xe5, \
+ 0xa0, 0xae, 0x0c, 0xc4, 0x53, 0x9e, 0x93, 0x4e, 0xe8, 0x0d, 0x9c, 0x2f, \
+ 0xb4, 0x04, 0xfd, 0x8a, 0x39, 0xf5, 0x84, 0x77, 0xed, 0x4c, 0xd4, 0xbb, \
+ 0x44, 0x7f, 0x73, 0x77, 0xf7, 0xf1, 0x36, 0x97, 0xdc, 0x1e, 0x73, 0x19, \
+ 0x5d, 0x50, 0xb8, 0xc3, 0x80, 0xcd, 0x03, 0x57, 0xd2, 0x00, 0xdb, 0x56, \
+ 0xe6, 0xc6, 0x35, 0x24, 0x1e, 0x49, 0x7b, 0xd8, 0xd2, 0x72, 0xbb, 0x0b, \
+ 0x49, 0x2f, 0xa6, 0x02, 0x3c, 0xaf, 0xd0, 0xec, 0x37, 0x1d, 0xbd, 0x81, \
+ 0x8b, 0x1f, 0x30, 0xbb, 0xbc, 0x4d, 0x36, 0xb5, 0x79, 0x7c, 0x87, 0xfb, \
+ 0x51, 0xb9, 0xbe, 0xc2, 0xde, 0x92, 0xa8, 0x40, 0x71, 0xbb, 0x72, 0x9b, \
+ 0xf8, 0x47, 0xce, 0x6c, 0x04, 0xf8, 0x86, 0xe7, 0xf7, 0x73, 0x3c, 0xe7, \
+ 0x84, 0x7d, 0xc2, 0xd7, 0xb7, 0x9d, 0xe8, 0xd4, 0x9b, 0x5f, 0x0a, 0x17, \
+ 0x7d, 0xbc, 0xbb, 0xb2, 0xd5, 0x94, 0x0d, 0xe4, 0x49, 0xbf, 0x4f, 0x11, \
+ 0x68, 0x53, 0xb2, 0x91, 0xff, 0xc0, 0x69, 0xee, 0xdb, 0x63, 0x93, 0xcb, \
+ 0xc9, 0x35, 0x6b, 0x90, 0x09, 0xe2, 0x90, 0xc9, 0xed, 0x27, 0xd6, 0x08, \
+ 0xfa, 0x13, 0x4d, 0x62, 0xdd, 0xe2, 0x9e, 0xaa, 0xb5, 0xd4, 0x0e, 0x5c, \
+ 0x37, 0x4f, 0xab, 0x55, 0x3b, 0x2d, 0xf1, 0x42, 0x82, 0xc7, 0x34, 0x38, \
+ 0x1a, 0x9b, 0xeb, 0xa1, 0x2c, 0x0f, 0x29, 0x31, 0x64, 0x6c, 0xcc, 0x38, \
+ 0xfd, 0xa9, 0xd3, 0xd5, 0xd5, 0x71, 0xaf, 0xf0, 0x6d, 0xc0, 0x97, 0xe2, \
+ 0x11, 0x2a, 0x0a, 0xdf, 0xfe, 0x02, 0x79, 0x74, 0x75 \
}
/* END FILE */
@@ -272,76 +272,76 @@
/* This is taken from tests/data_files/test-ca-sha1.crt.der. */
/* BEGIN FILE binary macro TEST_CA_CRT_RSA_SHA1_DER tests/data_files/test-ca-sha1.crt.der */
#define TEST_CA_CRT_RSA_SHA1_DER { \
- 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
- 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
- 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
- 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
- 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
- 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
- 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
- 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, \
- 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
- 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
- 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
- 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
- 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \
- 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, \
- 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, \
- 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, \
- 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, \
- 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, \
- 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, \
- 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, \
- 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, \
- 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, \
- 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, \
- 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, \
- 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \
- 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, \
- 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, \
- 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, \
- 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, \
- 0xee, 0xe2, 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, \
- 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, \
- 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, \
- 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, \
- 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, \
- 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, \
- 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, \
- 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, \
- 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, \
- 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, \
- 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \
- 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, \
- 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \
- 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, \
- 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, \
- 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, \
- 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, \
- 0x03, 0x82, 0x01, 0x01, 0x00, 0x01, 0x13, 0x73, 0x84, 0x3d, 0xf1, 0x1d, \
- 0xfd, 0xb7, 0x09, 0x5b, 0x96, 0x5d, 0x53, 0x7f, 0xd5, 0x80, 0xf3, 0x52, \
- 0xe2, 0xd3, 0x33, 0x87, 0xc8, 0x27, 0x24, 0xff, 0xd5, 0xd8, 0x57, 0x2f, \
- 0x16, 0xd1, 0xb2, 0x94, 0xca, 0x50, 0xab, 0xa6, 0x27, 0x10, 0x16, 0x08, \
- 0xc8, 0x11, 0xc0, 0x2f, 0x80, 0xd1, 0xbe, 0x53, 0x18, 0xe6, 0xb9, 0xd7, \
- 0x18, 0x1a, 0x77, 0x38, 0x34, 0x7c, 0x32, 0x9a, 0x87, 0x0b, 0xa0, 0x2a, \
- 0xb9, 0x14, 0xc2, 0x2f, 0x38, 0xd2, 0xe7, 0xb8, 0x98, 0x7d, 0xff, 0xff, \
- 0xe1, 0x01, 0x50, 0xa9, 0x6f, 0x67, 0xf7, 0x6c, 0xdc, 0xb6, 0xca, 0x6f, \
- 0x73, 0x39, 0x1a, 0x3c, 0xa8, 0x23, 0xaa, 0x8d, 0x4d, 0xa3, 0x75, 0x2a, \
- 0xd1, 0x76, 0xb3, 0xd7, 0x4a, 0xdc, 0xc7, 0x24, 0xd4, 0x3e, 0xb7, 0xf9, \
- 0xc0, 0xd5, 0x51, 0x67, 0x65, 0x74, 0x2a, 0xf9, 0x65, 0xbc, 0x00, 0x15, \
- 0x4b, 0x36, 0xc8, 0xe2, 0x6a, 0x5d, 0x51, 0x7c, 0xed, 0x8e, 0x14, 0x93, \
- 0x4b, 0x90, 0x36, 0x05, 0xe5, 0x90, 0x00, 0x03, 0xab, 0xd3, 0x3a, 0xb5, \
- 0x17, 0xb4, 0xd2, 0x45, 0x52, 0x69, 0x26, 0xce, 0xe3, 0x98, 0x1d, 0x9a, \
- 0x8b, 0xf8, 0xa0, 0x92, 0x1d, 0x48, 0x02, 0x37, 0x2e, 0xc1, 0x5e, 0x95, \
- 0xc2, 0x53, 0xfe, 0xb1, 0xbc, 0x34, 0x82, 0x34, 0x34, 0x36, 0x91, 0x8c, \
- 0x88, 0x7a, 0x67, 0x97, 0x34, 0x40, 0x8b, 0xfb, 0x48, 0x6e, 0xd3, 0xaf, \
- 0x30, 0x81, 0x8e, 0x05, 0x4d, 0x93, 0x21, 0xf6, 0xb1, 0xff, 0x98, 0xea, \
- 0xd5, 0xa8, 0x14, 0xc7, 0x96, 0x8f, 0x99, 0x3e, 0x53, 0x58, 0x08, 0x89, \
- 0x3c, 0xe3, 0x8f, 0xea, 0x5e, 0x71, 0x5e, 0x70, 0xf0, 0xc5, 0xe6, 0x12, \
- 0x35, 0x6a, 0xa2, 0x5f, 0xd1, 0xb2, 0xba, 0xc0, 0x59, 0x8d, 0xec, 0xda, \
- 0x09, 0xa1, 0xda, 0x6e, 0x30, 0xcb, 0x53, 0x4a, 0x90 \
+ 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, \
+ 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, \
+ 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, \
+ 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, \
+ 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, \
+ 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, \
+ 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, \
+ 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, \
+ 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, \
+ 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \
+ 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, \
+ 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, \
+ 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, \
+ 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, \
+ 0xee, 0xe2, 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, \
+ 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, \
+ 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, \
+ 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, \
+ 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, \
+ 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, \
+ 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, \
+ 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, \
+ 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, \
+ 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, \
+ 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \
+ 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, \
+ 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \
+ 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, \
+ 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, \
+ 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, \
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, \
+ 0x03, 0x82, 0x01, 0x01, 0x00, 0x01, 0x13, 0x73, 0x84, 0x3d, 0xf1, 0x1d, \
+ 0xfd, 0xb7, 0x09, 0x5b, 0x96, 0x5d, 0x53, 0x7f, 0xd5, 0x80, 0xf3, 0x52, \
+ 0xe2, 0xd3, 0x33, 0x87, 0xc8, 0x27, 0x24, 0xff, 0xd5, 0xd8, 0x57, 0x2f, \
+ 0x16, 0xd1, 0xb2, 0x94, 0xca, 0x50, 0xab, 0xa6, 0x27, 0x10, 0x16, 0x08, \
+ 0xc8, 0x11, 0xc0, 0x2f, 0x80, 0xd1, 0xbe, 0x53, 0x18, 0xe6, 0xb9, 0xd7, \
+ 0x18, 0x1a, 0x77, 0x38, 0x34, 0x7c, 0x32, 0x9a, 0x87, 0x0b, 0xa0, 0x2a, \
+ 0xb9, 0x14, 0xc2, 0x2f, 0x38, 0xd2, 0xe7, 0xb8, 0x98, 0x7d, 0xff, 0xff, \
+ 0xe1, 0x01, 0x50, 0xa9, 0x6f, 0x67, 0xf7, 0x6c, 0xdc, 0xb6, 0xca, 0x6f, \
+ 0x73, 0x39, 0x1a, 0x3c, 0xa8, 0x23, 0xaa, 0x8d, 0x4d, 0xa3, 0x75, 0x2a, \
+ 0xd1, 0x76, 0xb3, 0xd7, 0x4a, 0xdc, 0xc7, 0x24, 0xd4, 0x3e, 0xb7, 0xf9, \
+ 0xc0, 0xd5, 0x51, 0x67, 0x65, 0x74, 0x2a, 0xf9, 0x65, 0xbc, 0x00, 0x15, \
+ 0x4b, 0x36, 0xc8, 0xe2, 0x6a, 0x5d, 0x51, 0x7c, 0xed, 0x8e, 0x14, 0x93, \
+ 0x4b, 0x90, 0x36, 0x05, 0xe5, 0x90, 0x00, 0x03, 0xab, 0xd3, 0x3a, 0xb5, \
+ 0x17, 0xb4, 0xd2, 0x45, 0x52, 0x69, 0x26, 0xce, 0xe3, 0x98, 0x1d, 0x9a, \
+ 0x8b, 0xf8, 0xa0, 0x92, 0x1d, 0x48, 0x02, 0x37, 0x2e, 0xc1, 0x5e, 0x95, \
+ 0xc2, 0x53, 0xfe, 0xb1, 0xbc, 0x34, 0x82, 0x34, 0x34, 0x36, 0x91, 0x8c, \
+ 0x88, 0x7a, 0x67, 0x97, 0x34, 0x40, 0x8b, 0xfb, 0x48, 0x6e, 0xd3, 0xaf, \
+ 0x30, 0x81, 0x8e, 0x05, 0x4d, 0x93, 0x21, 0xf6, 0xb1, 0xff, 0x98, 0xea, \
+ 0xd5, 0xa8, 0x14, 0xc7, 0x96, 0x8f, 0x99, 0x3e, 0x53, 0x58, 0x08, 0x89, \
+ 0x3c, 0xe3, 0x8f, 0xea, 0x5e, 0x71, 0x5e, 0x70, 0xf0, 0xc5, 0xe6, 0x12, \
+ 0x35, 0x6a, 0xa2, 0x5f, 0xd1, 0xb2, 0xba, 0xc0, 0x59, 0x8d, 0xec, 0xda, \
+ 0x09, 0xa1, 0xda, 0x6e, 0x30, 0xcb, 0x53, 0x4a, 0x90 \
}
/* END FILE */
@@ -385,106 +385,106 @@
/* This was generated from test-ca.key.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_CA_KEY_RSA_DER tests/data_files/test-ca.key.der */
#define TEST_CA_KEY_RSA_DER { \
- 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
- 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, \
- 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, 0x99, 0xd4, \
- 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, \
- 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, 0x8d, \
- 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, 0x93, 0xe8, \
- 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, 0xe7, 0x40, \
- 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, \
- 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, 0x29, 0x00, \
- 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, 0xbd, 0x83, \
- 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, \
- 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, \
- 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, 0xfb, 0xf5, \
- 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, \
- 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, \
- 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, 0xf1, 0x79, \
- 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, 0x27, \
- 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, 0xa1, 0x30, \
- 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, \
- 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, 0x09, 0xea, \
- 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, \
- 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, \
- 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
- 0x00, 0x3f, 0xf7, 0x07, 0xd3, 0x34, 0x6f, 0xdb, 0xc9, 0x37, 0xb7, 0x84, \
- 0xdc, 0x37, 0x45, 0xe1, 0x63, 0xad, 0xb8, 0xb6, 0x75, 0xb1, 0xc7, 0x35, \
- 0xb4, 0x77, 0x2a, 0x5b, 0x77, 0xf9, 0x7e, 0xe0, 0xc1, 0xa3, 0xd1, 0xb7, \
- 0xcb, 0xa9, 0x5a, 0xc1, 0x87, 0xda, 0x5a, 0xfa, 0x17, 0xe4, 0xd5, 0x38, \
- 0x03, 0xde, 0x68, 0x98, 0x81, 0xec, 0xb5, 0xf2, 0x2a, 0x8d, 0xe9, 0x2c, \
- 0xf3, 0xa6, 0xe5, 0x32, 0x17, 0x7f, 0x33, 0x81, 0xe8, 0x38, 0x72, 0xd5, \
- 0x9c, 0xfa, 0x4e, 0xfb, 0x26, 0xf5, 0x15, 0x0b, 0xaf, 0x84, 0x66, 0xab, \
- 0x02, 0xe0, 0x18, 0xd5, 0x91, 0x7c, 0xd6, 0x8f, 0xc9, 0x4b, 0x76, 0x08, \
- 0x2b, 0x1d, 0x81, 0x68, 0x30, 0xe1, 0xfa, 0x70, 0x6c, 0x13, 0x4e, 0x10, \
- 0x03, 0x35, 0x3e, 0xc5, 0xca, 0x58, 0x20, 0x8a, 0x21, 0x18, 0x38, 0xa0, \
- 0x0f, 0xed, 0xc4, 0xbb, 0x45, 0x6f, 0xf5, 0x84, 0x5b, 0xb0, 0xcf, 0x4e, \
- 0x9d, 0x58, 0x13, 0x6b, 0x35, 0x35, 0x69, 0xa1, 0xd2, 0xc4, 0xf2, 0xc1, \
- 0x48, 0x04, 0x20, 0x51, 0xb9, 0x6b, 0xa4, 0x5d, 0xa5, 0x4b, 0x84, 0x88, \
- 0x43, 0x48, 0x99, 0x2c, 0xbb, 0xa4, 0x97, 0xd6, 0xd6, 0x18, 0xf6, 0xec, \
- 0x5c, 0xd1, 0x31, 0x49, 0xc9, 0xf2, 0x8f, 0x0b, 0x4d, 0xef, 0x09, 0x02, \
- 0xfe, 0x7d, 0xfd, 0xbb, 0xaf, 0x2b, 0x83, 0x94, 0x22, 0xc4, 0xa7, 0x3e, \
- 0x66, 0xf5, 0xe0, 0x57, 0xdc, 0xf2, 0xed, 0x2c, 0x3e, 0x81, 0x74, 0x76, \
- 0x1e, 0x96, 0x6f, 0x74, 0x1e, 0x32, 0x0e, 0x14, 0x31, 0xd0, 0x74, 0xf0, \
- 0xf4, 0x07, 0xbd, 0xc3, 0xd1, 0x22, 0xc2, 0xa8, 0x95, 0x92, 0x06, 0x7f, \
- 0x43, 0x02, 0x91, 0xbc, 0xdd, 0x23, 0x01, 0x89, 0x94, 0x20, 0x44, 0x64, \
- 0xf5, 0x1d, 0x67, 0xd2, 0x8f, 0xe8, 0x69, 0xa5, 0x29, 0x25, 0xe6, 0x50, \
- 0x9c, 0xe3, 0xe9, 0xcb, 0x75, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x29, 0x3e, \
- 0xaa, 0x6b, 0xd5, 0x59, 0x1e, 0x9c, 0xe6, 0x47, 0xd5, 0xb6, 0xd7, 0xe3, \
- 0xf1, 0x8e, 0x9e, 0xe9, 0x83, 0x5f, 0x10, 0x9f, 0x63, 0xec, 0x04, 0x44, \
- 0xcc, 0x3f, 0xf8, 0xd9, 0x3a, 0x17, 0xe0, 0x4f, 0xfe, 0xd8, 0x4d, 0xcd, \
- 0x46, 0x54, 0x74, 0xbf, 0x0a, 0xc4, 0x67, 0x9c, 0xa7, 0xd8, 0x89, 0x65, \
- 0x4c, 0xfd, 0x58, 0x2a, 0x47, 0x0f, 0xf4, 0x37, 0xb6, 0x55, 0xb0, 0x1d, \
- 0xed, 0xa7, 0x39, 0xfc, 0x4f, 0xa3, 0xc4, 0x75, 0x3a, 0xa3, 0x98, 0xa7, \
- 0x45, 0xf5, 0x66, 0xcb, 0x7c, 0x65, 0xfb, 0x80, 0x23, 0xe6, 0xff, 0xfd, \
- 0x99, 0x1f, 0x8e, 0x6b, 0xff, 0x5e, 0x93, 0x66, 0xdf, 0x6c, 0x6f, 0xc3, \
- 0xf6, 0x38, 0x2e, 0xff, 0x69, 0xb5, 0xac, 0xae, 0xbb, 0xc6, 0x71, 0x16, \
- 0x6b, 0xd0, 0xf8, 0x22, 0xd9, 0xf8, 0xa2, 0x72, 0x20, 0xd2, 0xe2, 0x3a, \
- 0x70, 0x4b, 0xde, 0xab, 0x2f, 0x02, 0x81, 0x81, 0x00, 0xda, 0x51, 0x9b, \
- 0xb8, 0xb2, 0x2a, 0x14, 0x75, 0x58, 0x40, 0x8d, 0x27, 0x70, 0xfa, 0x31, \
- 0x48, 0xb0, 0x20, 0x21, 0x34, 0xfa, 0x4c, 0x57, 0xa8, 0x11, 0x88, 0xf3, \
- 0xa7, 0xae, 0x21, 0xe9, 0xb6, 0x2b, 0xd1, 0xcd, 0xa7, 0xf8, 0xd8, 0x0c, \
- 0x8a, 0x76, 0x22, 0x35, 0x44, 0xce, 0x3f, 0x25, 0x29, 0x83, 0x7d, 0x79, \
- 0xa7, 0x31, 0xd6, 0xec, 0xb2, 0xbf, 0xda, 0x34, 0xb6, 0xf6, 0xb2, 0x3b, \
- 0xf3, 0x78, 0x5a, 0x04, 0x83, 0x33, 0x3e, 0xa2, 0xe2, 0x81, 0x82, 0x13, \
- 0xd4, 0x35, 0x17, 0x63, 0x9b, 0x9e, 0xc4, 0x8d, 0x91, 0x4c, 0x03, 0x77, \
- 0xc7, 0x71, 0x5b, 0xee, 0x83, 0x6d, 0xd5, 0x78, 0x88, 0xf6, 0x2c, 0x79, \
- 0xc2, 0x4a, 0xb4, 0x79, 0x90, 0x70, 0xbf, 0xdf, 0x34, 0x56, 0x96, 0x71, \
- 0xe3, 0x0e, 0x68, 0x91, 0xbc, 0xea, 0xcb, 0x33, 0xc0, 0xbe, 0x45, 0xd7, \
- 0xfc, 0x30, 0xfd, 0x01, 0x3b, 0x02, 0x81, 0x81, 0x00, 0xd2, 0x9f, 0x2a, \
- 0xb7, 0x38, 0x19, 0xc7, 0x17, 0x95, 0x73, 0x78, 0xae, 0xf5, 0xcb, 0x75, \
- 0x83, 0x7f, 0x19, 0x4b, 0xcb, 0x86, 0xfb, 0x4a, 0x15, 0x9a, 0xb6, 0x17, \
- 0x04, 0x49, 0x07, 0x8d, 0xf6, 0x66, 0x4a, 0x06, 0xf6, 0x05, 0xa7, 0xdf, \
- 0x66, 0x82, 0x3c, 0xff, 0xb6, 0x1d, 0x57, 0x89, 0x33, 0x5f, 0x9c, 0x05, \
- 0x75, 0x7f, 0xf3, 0x5d, 0xdc, 0x34, 0x65, 0x72, 0x85, 0x22, 0xa4, 0x14, \
- 0x1b, 0x41, 0xc3, 0xe4, 0xd0, 0x9e, 0x69, 0xd5, 0xeb, 0x38, 0x74, 0x70, \
- 0x43, 0xdc, 0xd9, 0x50, 0xe4, 0x97, 0x6d, 0x73, 0xd6, 0xfb, 0xc8, 0xa7, \
- 0xfa, 0xb4, 0xc2, 0xc4, 0x9d, 0x5d, 0x0c, 0xd5, 0x9f, 0x79, 0xb3, 0x54, \
- 0xc2, 0xb7, 0x6c, 0x3d, 0x7d, 0xcb, 0x2d, 0xf8, 0xc4, 0xf3, 0x78, 0x5a, \
- 0x33, 0x2a, 0xb8, 0x0c, 0x6d, 0x06, 0xfa, 0xf2, 0x62, 0xd3, 0x42, 0xd0, \
- 0xbd, 0xc8, 0x4a, 0xa5, 0x0d, 0x02, 0x81, 0x81, 0x00, 0xd4, 0xa9, 0x90, \
- 0x15, 0xde, 0xbf, 0x2c, 0xc4, 0x8d, 0x9d, 0xfb, 0xa1, 0xc2, 0xe4, 0x83, \
- 0xe3, 0x79, 0x65, 0x22, 0xd3, 0xb7, 0x49, 0x6c, 0x4d, 0x94, 0x1f, 0x22, \
- 0xb1, 0x60, 0xe7, 0x3a, 0x00, 0xb1, 0x38, 0xa2, 0xab, 0x0f, 0xb4, 0x6c, \
- 0xaa, 0xe7, 0x9e, 0x34, 0xe3, 0x7c, 0x40, 0x78, 0x53, 0xb2, 0xf9, 0x23, \
- 0xea, 0xa0, 0x9a, 0xea, 0x60, 0xc8, 0x8f, 0xa6, 0xaf, 0xdf, 0x29, 0x09, \
- 0x4b, 0x06, 0x1e, 0x31, 0xad, 0x17, 0xda, 0xd8, 0xd1, 0xe9, 0x33, 0xab, \
- 0x5b, 0x18, 0x08, 0x5b, 0x87, 0xf8, 0xa5, 0x1f, 0xfd, 0xbb, 0xdc, 0xd8, \
- 0xed, 0x97, 0x57, 0xe4, 0xc3, 0x73, 0xd6, 0xf0, 0x9e, 0x01, 0xa6, 0x9b, \
- 0x48, 0x8e, 0x7a, 0xb4, 0xbb, 0xe5, 0x88, 0x91, 0xc5, 0x2a, 0xdf, 0x4b, \
- 0xba, 0xd0, 0x8b, 0x3e, 0x03, 0x97, 0x77, 0x2f, 0x47, 0x7e, 0x51, 0x0c, \
- 0xae, 0x65, 0x8d, 0xde, 0x87, 0x02, 0x81, 0x80, 0x20, 0x24, 0x0f, 0xd2, \
- 0xaf, 0xc2, 0x28, 0x3b, 0x97, 0x20, 0xb2, 0x92, 0x49, 0xeb, 0x09, 0x68, \
- 0x40, 0xb2, 0xbe, 0xd1, 0xc3, 0x83, 0x94, 0x34, 0x38, 0xd6, 0xc9, 0xec, \
- 0x34, 0x09, 0xf9, 0x41, 0x6d, 0x5c, 0x42, 0x94, 0xf7, 0x04, 0xfc, 0x32, \
- 0x39, 0x69, 0xbc, 0x1c, 0xfb, 0x3e, 0x61, 0x98, 0xc0, 0x80, 0xd8, 0x36, \
- 0x47, 0xc3, 0x6d, 0xc2, 0x2e, 0xe7, 0x81, 0x2a, 0x17, 0x34, 0x64, 0x30, \
- 0x4e, 0x96, 0xbb, 0x26, 0x16, 0xb9, 0x41, 0x36, 0xfe, 0x8a, 0xd6, 0x53, \
- 0x7c, 0xaa, 0xec, 0x39, 0x42, 0x50, 0xef, 0xe3, 0xb3, 0x01, 0x28, 0x32, \
- 0xca, 0x6d, 0xf5, 0x9a, 0x1e, 0x9f, 0x37, 0xbe, 0xfe, 0x38, 0x20, 0x22, \
- 0x91, 0x8c, 0xcd, 0x95, 0x02, 0xf2, 0x4d, 0x6f, 0x1a, 0xb4, 0x43, 0xf0, \
- 0x19, 0xdf, 0x65, 0xc0, 0x92, 0xe7, 0x9d, 0x2f, 0x09, 0xe7, 0xec, 0x69, \
- 0xa8, 0xc2, 0x8f, 0x0d \
+ 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
+ 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, \
+ 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, 0x99, 0xd4, \
+ 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, \
+ 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, 0x8d, \
+ 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, 0x93, 0xe8, \
+ 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, 0xe7, 0x40, \
+ 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, \
+ 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, 0x29, 0x00, \
+ 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, 0xbd, 0x83, \
+ 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, \
+ 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, \
+ 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, 0xfb, 0xf5, \
+ 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, \
+ 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, \
+ 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, 0xf1, 0x79, \
+ 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, 0x27, \
+ 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, 0xa1, 0x30, \
+ 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, \
+ 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, 0x09, 0xea, \
+ 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, \
+ 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, \
+ 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
+ 0x00, 0x3f, 0xf7, 0x07, 0xd3, 0x34, 0x6f, 0xdb, 0xc9, 0x37, 0xb7, 0x84, \
+ 0xdc, 0x37, 0x45, 0xe1, 0x63, 0xad, 0xb8, 0xb6, 0x75, 0xb1, 0xc7, 0x35, \
+ 0xb4, 0x77, 0x2a, 0x5b, 0x77, 0xf9, 0x7e, 0xe0, 0xc1, 0xa3, 0xd1, 0xb7, \
+ 0xcb, 0xa9, 0x5a, 0xc1, 0x87, 0xda, 0x5a, 0xfa, 0x17, 0xe4, 0xd5, 0x38, \
+ 0x03, 0xde, 0x68, 0x98, 0x81, 0xec, 0xb5, 0xf2, 0x2a, 0x8d, 0xe9, 0x2c, \
+ 0xf3, 0xa6, 0xe5, 0x32, 0x17, 0x7f, 0x33, 0x81, 0xe8, 0x38, 0x72, 0xd5, \
+ 0x9c, 0xfa, 0x4e, 0xfb, 0x26, 0xf5, 0x15, 0x0b, 0xaf, 0x84, 0x66, 0xab, \
+ 0x02, 0xe0, 0x18, 0xd5, 0x91, 0x7c, 0xd6, 0x8f, 0xc9, 0x4b, 0x76, 0x08, \
+ 0x2b, 0x1d, 0x81, 0x68, 0x30, 0xe1, 0xfa, 0x70, 0x6c, 0x13, 0x4e, 0x10, \
+ 0x03, 0x35, 0x3e, 0xc5, 0xca, 0x58, 0x20, 0x8a, 0x21, 0x18, 0x38, 0xa0, \
+ 0x0f, 0xed, 0xc4, 0xbb, 0x45, 0x6f, 0xf5, 0x84, 0x5b, 0xb0, 0xcf, 0x4e, \
+ 0x9d, 0x58, 0x13, 0x6b, 0x35, 0x35, 0x69, 0xa1, 0xd2, 0xc4, 0xf2, 0xc1, \
+ 0x48, 0x04, 0x20, 0x51, 0xb9, 0x6b, 0xa4, 0x5d, 0xa5, 0x4b, 0x84, 0x88, \
+ 0x43, 0x48, 0x99, 0x2c, 0xbb, 0xa4, 0x97, 0xd6, 0xd6, 0x18, 0xf6, 0xec, \
+ 0x5c, 0xd1, 0x31, 0x49, 0xc9, 0xf2, 0x8f, 0x0b, 0x4d, 0xef, 0x09, 0x02, \
+ 0xfe, 0x7d, 0xfd, 0xbb, 0xaf, 0x2b, 0x83, 0x94, 0x22, 0xc4, 0xa7, 0x3e, \
+ 0x66, 0xf5, 0xe0, 0x57, 0xdc, 0xf2, 0xed, 0x2c, 0x3e, 0x81, 0x74, 0x76, \
+ 0x1e, 0x96, 0x6f, 0x74, 0x1e, 0x32, 0x0e, 0x14, 0x31, 0xd0, 0x74, 0xf0, \
+ 0xf4, 0x07, 0xbd, 0xc3, 0xd1, 0x22, 0xc2, 0xa8, 0x95, 0x92, 0x06, 0x7f, \
+ 0x43, 0x02, 0x91, 0xbc, 0xdd, 0x23, 0x01, 0x89, 0x94, 0x20, 0x44, 0x64, \
+ 0xf5, 0x1d, 0x67, 0xd2, 0x8f, 0xe8, 0x69, 0xa5, 0x29, 0x25, 0xe6, 0x50, \
+ 0x9c, 0xe3, 0xe9, 0xcb, 0x75, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x29, 0x3e, \
+ 0xaa, 0x6b, 0xd5, 0x59, 0x1e, 0x9c, 0xe6, 0x47, 0xd5, 0xb6, 0xd7, 0xe3, \
+ 0xf1, 0x8e, 0x9e, 0xe9, 0x83, 0x5f, 0x10, 0x9f, 0x63, 0xec, 0x04, 0x44, \
+ 0xcc, 0x3f, 0xf8, 0xd9, 0x3a, 0x17, 0xe0, 0x4f, 0xfe, 0xd8, 0x4d, 0xcd, \
+ 0x46, 0x54, 0x74, 0xbf, 0x0a, 0xc4, 0x67, 0x9c, 0xa7, 0xd8, 0x89, 0x65, \
+ 0x4c, 0xfd, 0x58, 0x2a, 0x47, 0x0f, 0xf4, 0x37, 0xb6, 0x55, 0xb0, 0x1d, \
+ 0xed, 0xa7, 0x39, 0xfc, 0x4f, 0xa3, 0xc4, 0x75, 0x3a, 0xa3, 0x98, 0xa7, \
+ 0x45, 0xf5, 0x66, 0xcb, 0x7c, 0x65, 0xfb, 0x80, 0x23, 0xe6, 0xff, 0xfd, \
+ 0x99, 0x1f, 0x8e, 0x6b, 0xff, 0x5e, 0x93, 0x66, 0xdf, 0x6c, 0x6f, 0xc3, \
+ 0xf6, 0x38, 0x2e, 0xff, 0x69, 0xb5, 0xac, 0xae, 0xbb, 0xc6, 0x71, 0x16, \
+ 0x6b, 0xd0, 0xf8, 0x22, 0xd9, 0xf8, 0xa2, 0x72, 0x20, 0xd2, 0xe2, 0x3a, \
+ 0x70, 0x4b, 0xde, 0xab, 0x2f, 0x02, 0x81, 0x81, 0x00, 0xda, 0x51, 0x9b, \
+ 0xb8, 0xb2, 0x2a, 0x14, 0x75, 0x58, 0x40, 0x8d, 0x27, 0x70, 0xfa, 0x31, \
+ 0x48, 0xb0, 0x20, 0x21, 0x34, 0xfa, 0x4c, 0x57, 0xa8, 0x11, 0x88, 0xf3, \
+ 0xa7, 0xae, 0x21, 0xe9, 0xb6, 0x2b, 0xd1, 0xcd, 0xa7, 0xf8, 0xd8, 0x0c, \
+ 0x8a, 0x76, 0x22, 0x35, 0x44, 0xce, 0x3f, 0x25, 0x29, 0x83, 0x7d, 0x79, \
+ 0xa7, 0x31, 0xd6, 0xec, 0xb2, 0xbf, 0xda, 0x34, 0xb6, 0xf6, 0xb2, 0x3b, \
+ 0xf3, 0x78, 0x5a, 0x04, 0x83, 0x33, 0x3e, 0xa2, 0xe2, 0x81, 0x82, 0x13, \
+ 0xd4, 0x35, 0x17, 0x63, 0x9b, 0x9e, 0xc4, 0x8d, 0x91, 0x4c, 0x03, 0x77, \
+ 0xc7, 0x71, 0x5b, 0xee, 0x83, 0x6d, 0xd5, 0x78, 0x88, 0xf6, 0x2c, 0x79, \
+ 0xc2, 0x4a, 0xb4, 0x79, 0x90, 0x70, 0xbf, 0xdf, 0x34, 0x56, 0x96, 0x71, \
+ 0xe3, 0x0e, 0x68, 0x91, 0xbc, 0xea, 0xcb, 0x33, 0xc0, 0xbe, 0x45, 0xd7, \
+ 0xfc, 0x30, 0xfd, 0x01, 0x3b, 0x02, 0x81, 0x81, 0x00, 0xd2, 0x9f, 0x2a, \
+ 0xb7, 0x38, 0x19, 0xc7, 0x17, 0x95, 0x73, 0x78, 0xae, 0xf5, 0xcb, 0x75, \
+ 0x83, 0x7f, 0x19, 0x4b, 0xcb, 0x86, 0xfb, 0x4a, 0x15, 0x9a, 0xb6, 0x17, \
+ 0x04, 0x49, 0x07, 0x8d, 0xf6, 0x66, 0x4a, 0x06, 0xf6, 0x05, 0xa7, 0xdf, \
+ 0x66, 0x82, 0x3c, 0xff, 0xb6, 0x1d, 0x57, 0x89, 0x33, 0x5f, 0x9c, 0x05, \
+ 0x75, 0x7f, 0xf3, 0x5d, 0xdc, 0x34, 0x65, 0x72, 0x85, 0x22, 0xa4, 0x14, \
+ 0x1b, 0x41, 0xc3, 0xe4, 0xd0, 0x9e, 0x69, 0xd5, 0xeb, 0x38, 0x74, 0x70, \
+ 0x43, 0xdc, 0xd9, 0x50, 0xe4, 0x97, 0x6d, 0x73, 0xd6, 0xfb, 0xc8, 0xa7, \
+ 0xfa, 0xb4, 0xc2, 0xc4, 0x9d, 0x5d, 0x0c, 0xd5, 0x9f, 0x79, 0xb3, 0x54, \
+ 0xc2, 0xb7, 0x6c, 0x3d, 0x7d, 0xcb, 0x2d, 0xf8, 0xc4, 0xf3, 0x78, 0x5a, \
+ 0x33, 0x2a, 0xb8, 0x0c, 0x6d, 0x06, 0xfa, 0xf2, 0x62, 0xd3, 0x42, 0xd0, \
+ 0xbd, 0xc8, 0x4a, 0xa5, 0x0d, 0x02, 0x81, 0x81, 0x00, 0xd4, 0xa9, 0x90, \
+ 0x15, 0xde, 0xbf, 0x2c, 0xc4, 0x8d, 0x9d, 0xfb, 0xa1, 0xc2, 0xe4, 0x83, \
+ 0xe3, 0x79, 0x65, 0x22, 0xd3, 0xb7, 0x49, 0x6c, 0x4d, 0x94, 0x1f, 0x22, \
+ 0xb1, 0x60, 0xe7, 0x3a, 0x00, 0xb1, 0x38, 0xa2, 0xab, 0x0f, 0xb4, 0x6c, \
+ 0xaa, 0xe7, 0x9e, 0x34, 0xe3, 0x7c, 0x40, 0x78, 0x53, 0xb2, 0xf9, 0x23, \
+ 0xea, 0xa0, 0x9a, 0xea, 0x60, 0xc8, 0x8f, 0xa6, 0xaf, 0xdf, 0x29, 0x09, \
+ 0x4b, 0x06, 0x1e, 0x31, 0xad, 0x17, 0xda, 0xd8, 0xd1, 0xe9, 0x33, 0xab, \
+ 0x5b, 0x18, 0x08, 0x5b, 0x87, 0xf8, 0xa5, 0x1f, 0xfd, 0xbb, 0xdc, 0xd8, \
+ 0xed, 0x97, 0x57, 0xe4, 0xc3, 0x73, 0xd6, 0xf0, 0x9e, 0x01, 0xa6, 0x9b, \
+ 0x48, 0x8e, 0x7a, 0xb4, 0xbb, 0xe5, 0x88, 0x91, 0xc5, 0x2a, 0xdf, 0x4b, \
+ 0xba, 0xd0, 0x8b, 0x3e, 0x03, 0x97, 0x77, 0x2f, 0x47, 0x7e, 0x51, 0x0c, \
+ 0xae, 0x65, 0x8d, 0xde, 0x87, 0x02, 0x81, 0x80, 0x20, 0x24, 0x0f, 0xd2, \
+ 0xaf, 0xc2, 0x28, 0x3b, 0x97, 0x20, 0xb2, 0x92, 0x49, 0xeb, 0x09, 0x68, \
+ 0x40, 0xb2, 0xbe, 0xd1, 0xc3, 0x83, 0x94, 0x34, 0x38, 0xd6, 0xc9, 0xec, \
+ 0x34, 0x09, 0xf9, 0x41, 0x6d, 0x5c, 0x42, 0x94, 0xf7, 0x04, 0xfc, 0x32, \
+ 0x39, 0x69, 0xbc, 0x1c, 0xfb, 0x3e, 0x61, 0x98, 0xc0, 0x80, 0xd8, 0x36, \
+ 0x47, 0xc3, 0x6d, 0xc2, 0x2e, 0xe7, 0x81, 0x2a, 0x17, 0x34, 0x64, 0x30, \
+ 0x4e, 0x96, 0xbb, 0x26, 0x16, 0xb9, 0x41, 0x36, 0xfe, 0x8a, 0xd6, 0x53, \
+ 0x7c, 0xaa, 0xec, 0x39, 0x42, 0x50, 0xef, 0xe3, 0xb3, 0x01, 0x28, 0x32, \
+ 0xca, 0x6d, 0xf5, 0x9a, 0x1e, 0x9f, 0x37, 0xbe, 0xfe, 0x38, 0x20, 0x22, \
+ 0x91, 0x8c, 0xcd, 0x95, 0x02, 0xf2, 0x4d, 0x6f, 0x1a, 0xb4, 0x43, 0xf0, \
+ 0x19, 0xdf, 0x65, 0xc0, 0x92, 0xe7, 0x9d, 0x2f, 0x09, 0xe7, 0xec, 0x69, \
+ 0xa8, 0xc2, 0x8f, 0x0d \
}
/* END FILE */
@@ -523,52 +523,52 @@
/* This is generated from tests/data_files/server5.crt.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_SRV_CRT_EC_DER tests/data_files/server5.crt.der */
#define TEST_SRV_CRT_EC_DER { \
- 0x30, 0x82, 0x02, 0x1f, 0x30, 0x82, 0x01, 0xa5, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x01, 0x09, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
- 0x3d, 0x04, 0x03, 0x02, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
- 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
- 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
- 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, \
- 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
- 0x31, 0x33, 0x30, 0x39, 0x32, 0x34, 0x31, 0x35, 0x35, 0x32, 0x30, 0x34, \
- 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x35, \
- 0x32, 0x30, 0x34, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
- 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
- 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
- 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x59, \
- 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, \
- 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, \
- 0x04, 0x37, 0xcc, 0x56, 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, \
- 0x59, 0x2d, 0xff, 0x20, 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, \
- 0xad, 0x14, 0xb5, 0xf7, 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, \
- 0xd8, 0x23, 0x11, 0xff, 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, \
- 0x8a, 0x88, 0xc2, 0x6b, 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, \
- 0x01, 0xc8, 0xb4, 0xed, 0xff, 0xa3, 0x81, 0x9d, 0x30, 0x81, 0x9a, 0x30, \
- 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, \
- 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x50, 0x61, 0xa5, \
- 0x8f, 0xd4, 0x07, 0xd9, 0xd7, 0x82, 0x01, 0x0c, 0xe5, 0x65, 0x7f, 0x8c, \
- 0x63, 0x46, 0xa7, 0x13, 0xbe, 0x30, 0x6e, 0x06, 0x03, 0x55, 0x1d, 0x23, \
- 0x04, 0x67, 0x30, 0x65, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, \
- 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, \
- 0x36, 0x7c, 0xa1, 0x42, 0xa4, 0x40, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, \
- 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
- 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
- 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, \
- 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, \
- 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, 0x09, \
- 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0a, 0x06, \
- 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x68, 0x00, \
- 0x30, 0x65, 0x02, 0x31, 0x00, 0x9a, 0x2c, 0x5c, 0xd7, 0xa6, 0xdb, 0xa2, \
- 0xe5, 0x64, 0x0d, 0xf0, 0xb9, 0x4e, 0xdd, 0xd7, 0x61, 0xd6, 0x13, 0x31, \
- 0xc7, 0xab, 0x73, 0x80, 0xbb, 0xd3, 0xd3, 0x73, 0x13, 0x54, 0xad, 0x92, \
- 0x0b, 0x5d, 0xab, 0xd0, 0xbc, 0xf7, 0xae, 0x2f, 0xe6, 0xa1, 0x21, 0x29, \
- 0x35, 0x95, 0xaa, 0x3e, 0x39, 0x02, 0x30, 0x21, 0x36, 0x7f, 0x9d, 0xc6, \
- 0x5d, 0xc6, 0x0b, 0xab, 0x27, 0xf2, 0x25, 0x1d, 0x3b, 0xf1, 0xcf, 0xf1, \
- 0x35, 0x25, 0x14, 0xe7, 0xe5, 0xf1, 0x97, 0xb5, 0x59, 0xe3, 0x5e, 0x15, \
- 0x7c, 0x66, 0xb9, 0x90, 0x7b, 0xc7, 0x01, 0x10, 0x4f, 0x73, 0xc6, 0x00, \
- 0x21, 0x52, 0x2a, 0x0e, 0xf1, 0xc7, 0xd5 \
+ 0x30, 0x82, 0x02, 0x1f, 0x30, 0x82, 0x01, 0xa5, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x09, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
+ 0x3d, 0x04, 0x03, 0x02, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
+ 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, \
+ 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x33, 0x30, 0x39, 0x32, 0x34, 0x31, 0x35, 0x35, 0x32, 0x30, 0x34, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x35, \
+ 0x32, 0x30, 0x34, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
+ 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x59, \
+ 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, \
+ 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, \
+ 0x04, 0x37, 0xcc, 0x56, 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, \
+ 0x59, 0x2d, 0xff, 0x20, 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, \
+ 0xad, 0x14, 0xb5, 0xf7, 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, \
+ 0xd8, 0x23, 0x11, 0xff, 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, \
+ 0x8a, 0x88, 0xc2, 0x6b, 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, \
+ 0x01, 0xc8, 0xb4, 0xed, 0xff, 0xa3, 0x81, 0x9d, 0x30, 0x81, 0x9a, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, \
+ 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x50, 0x61, 0xa5, \
+ 0x8f, 0xd4, 0x07, 0xd9, 0xd7, 0x82, 0x01, 0x0c, 0xe5, 0x65, 0x7f, 0x8c, \
+ 0x63, 0x46, 0xa7, 0x13, 0xbe, 0x30, 0x6e, 0x06, 0x03, 0x55, 0x1d, 0x23, \
+ 0x04, 0x67, 0x30, 0x65, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, \
+ 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, \
+ 0x36, 0x7c, 0xa1, 0x42, 0xa4, 0x40, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, \
+ 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
+ 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
+ 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, \
+ 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, \
+ 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, 0x09, \
+ 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0a, 0x06, \
+ 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x68, 0x00, \
+ 0x30, 0x65, 0x02, 0x31, 0x00, 0x9a, 0x2c, 0x5c, 0xd7, 0xa6, 0xdb, 0xa2, \
+ 0xe5, 0x64, 0x0d, 0xf0, 0xb9, 0x4e, 0xdd, 0xd7, 0x61, 0xd6, 0x13, 0x31, \
+ 0xc7, 0xab, 0x73, 0x80, 0xbb, 0xd3, 0xd3, 0x73, 0x13, 0x54, 0xad, 0x92, \
+ 0x0b, 0x5d, 0xab, 0xd0, 0xbc, 0xf7, 0xae, 0x2f, 0xe6, 0xa1, 0x21, 0x29, \
+ 0x35, 0x95, 0xaa, 0x3e, 0x39, 0x02, 0x30, 0x21, 0x36, 0x7f, 0x9d, 0xc6, \
+ 0x5d, 0xc6, 0x0b, 0xab, 0x27, 0xf2, 0x25, 0x1d, 0x3b, 0xf1, 0xcf, 0xf1, \
+ 0x35, 0x25, 0x14, 0xe7, 0xe5, 0xf1, 0x97, 0xb5, 0x59, 0xe3, 0x5e, 0x15, \
+ 0x7c, 0x66, 0xb9, 0x90, 0x7b, 0xc7, 0x01, 0x10, 0x4f, 0x73, 0xc6, 0x00, \
+ 0x21, 0x52, 0x2a, 0x0e, 0xf1, 0xc7, 0xd5 \
}
/* END FILE */
@@ -585,17 +585,17 @@
/* This is generated from tests/data_files/server5.key.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_SRV_KEY_EC_DER tests/data_files/server5.key.der */
#define TEST_SRV_KEY_EC_DER { \
- 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf1, 0x2a, 0x13, 0x20, 0x76, \
- 0x02, 0x70, 0xa8, 0x3c, 0xbf, 0xfd, 0x53, 0xf6, 0x03, 0x1e, 0xf7, 0x6a, \
- 0x5d, 0x86, 0xc8, 0xa2, 0x04, 0xf2, 0xc3, 0x0c, 0xa9, 0xeb, 0xf5, 0x1f, \
- 0x0f, 0x0e, 0xa7, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
- 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x37, 0xcc, 0x56, \
- 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, 0x59, 0x2d, 0xff, 0x20, \
- 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, 0xad, 0x14, 0xb5, 0xf7, \
- 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, 0xd8, 0x23, 0x11, 0xff, \
- 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, 0x8a, 0x88, 0xc2, 0x6b, \
- 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, 0x01, 0xc8, 0xb4, 0xed, \
- 0xff \
+ 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf1, 0x2a, 0x13, 0x20, 0x76, \
+ 0x02, 0x70, 0xa8, 0x3c, 0xbf, 0xfd, 0x53, 0xf6, 0x03, 0x1e, 0xf7, 0x6a, \
+ 0x5d, 0x86, 0xc8, 0xa2, 0x04, 0xf2, 0xc3, 0x0c, 0xa9, 0xeb, 0xf5, 0x1f, \
+ 0x0f, 0x0e, 0xa7, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
+ 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x37, 0xcc, 0x56, \
+ 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, 0x59, 0x2d, 0xff, 0x20, \
+ 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, 0xad, 0x14, 0xb5, 0xf7, \
+ 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, 0xd8, 0x23, 0x11, 0xff, \
+ 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, 0x8a, 0x88, 0xc2, 0x6b, \
+ 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, 0x01, 0xc8, 0xb4, 0xed, \
+ 0xff \
}
/* END FILE */
@@ -627,175 +627,175 @@
/* This is taken from tests/data_files/server2-sha256.crt.der. */
/* BEGIN FILE binary macro TEST_SRV_CRT_RSA_SHA256_DER tests/data_files/server2-sha256.crt.der */
#define TEST_SRV_CRT_RSA_SHA256_DER { \
- 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
- 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
- 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
- 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
- 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
- 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
- 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
- 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
- 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \
- 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
- 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
- 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
- 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, \
- 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \
- 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, \
- 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, \
- 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, \
- 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, \
- 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, \
- 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, \
- 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, \
- 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, \
- 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, \
- 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, 0x07, 0x7d, \
- 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \
- 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, \
- 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, \
- 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, \
- 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, \
- 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, \
- 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, \
- 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, \
- 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, \
- 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, \
- 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, 0x96, \
- 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, \
- 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, \
- 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, \
- 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, \
- 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, \
- 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \
- 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, \
- 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \
- 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, \
- 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x2e, 0x3a, 0xe4, 0x52, 0x61, \
- 0x3e, 0xa7, 0xa5, 0xef, 0x32, 0x67, 0x80, 0x72, 0x07, 0x26, 0xba, 0xa3, \
- 0xff, 0x05, 0x40, 0xc4, 0x60, 0x05, 0x39, 0x31, 0x77, 0xf7, 0xa5, 0xca, \
- 0x01, 0x31, 0x80, 0xa7, 0xe1, 0xd1, 0x0a, 0xa2, 0x7c, 0xd5, 0x1c, 0xba, \
- 0xd0, 0x23, 0x4a, 0xd6, 0x30, 0xf3, 0x93, 0xc7, 0x6f, 0xe8, 0xce, 0x94, \
- 0x1e, 0x84, 0xbb, 0x44, 0x81, 0x62, 0x33, 0xff, 0x6b, 0x5d, 0x00, 0x9b, \
- 0x25, 0xf8, 0x8f, 0x0f, 0x9c, 0x4c, 0x4d, 0xe8, 0xd9, 0xa7, 0x99, 0xf9, \
- 0x51, 0x81, 0xc0, 0x9b, 0x1b, 0x31, 0x0d, 0xa6, 0xb3, 0x7c, 0x0e, 0x45, \
- 0xb8, 0x18, 0x64, 0x7e, 0x89, 0x0a, 0x2b, 0xa8, 0xc3, 0xe0, 0x4a, 0xbd, \
- 0xd4, 0x2f, 0x78, 0xc4, 0x62, 0x9b, 0xe9, 0x7e, 0x3f, 0x56, 0x46, 0x8f, \
- 0x17, 0xb7, 0x2a, 0xa0, 0x10, 0x70, 0xfd, 0xb1, 0xf1, 0x6b, 0x05, 0xdc, \
- 0xd1, 0x41, 0x0f, 0x8e, 0xa6, 0xb2, 0x88, 0x1a, 0x42, 0x61, 0x4f, 0xeb, \
- 0x26, 0x85, 0x59, 0x80, 0xba, 0x85, 0x54, 0xfe, 0xcf, 0xc7, 0x7b, 0x2f, \
- 0x6b, 0x59, 0xce, 0xac, 0xdc, 0x7c, 0xac, 0xf3, 0xc8, 0xd6, 0x12, 0x7e, \
- 0x64, 0xe8, 0x3c, 0x99, 0xa8, 0x8f, 0x4f, 0x11, 0xd9, 0x9c, 0x15, 0x4b, \
- 0x6a, 0x44, 0x92, 0x2d, 0x0c, 0xbf, 0xb1, 0x67, 0x96, 0xc9, 0xac, 0xce, \
- 0xd5, 0x19, 0xeb, 0x6f, 0x18, 0xeb, 0x6e, 0x04, 0x2d, 0x60, 0xac, 0xf4, \
- 0x7b, 0x79, 0xf0, 0x1a, 0x9b, 0xb5, 0xc3, 0x5d, 0xef, 0x7d, 0xc9, 0x05, \
- 0x99, 0x44, 0x81, 0x84, 0x75, 0xc7, 0xec, 0x00, 0x12, 0xfc, 0x7a, 0x4a, \
- 0x0b, 0x82, 0x07, 0xec, 0x6d, 0x86, 0x02, 0x4d, 0xfe, 0x9f, 0xc8, 0x92, \
- 0x48, 0xde, 0xf5, 0xb1, 0x9c, 0xe9, 0xc6, 0x89, 0xd0, 0xc1, 0x56, 0xe8, \
- 0xa4, 0xc6, 0x6a, 0x2e, 0x66, 0xc1, 0x9b, 0xfe, 0xd6, 0x3c, 0xb7 \
+ 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, \
+ 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \
+ 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, \
+ 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, \
+ 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, \
+ 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, \
+ 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, \
+ 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, \
+ 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, \
+ 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, \
+ 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, \
+ 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, 0x07, 0x7d, \
+ 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \
+ 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, \
+ 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, \
+ 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, \
+ 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, \
+ 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, \
+ 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, \
+ 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, \
+ 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, \
+ 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, \
+ 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, 0x96, \
+ 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, \
+ 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, \
+ 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, \
+ 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, \
+ 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, \
+ 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \
+ 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, \
+ 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \
+ 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, \
+ 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x2e, 0x3a, 0xe4, 0x52, 0x61, \
+ 0x3e, 0xa7, 0xa5, 0xef, 0x32, 0x67, 0x80, 0x72, 0x07, 0x26, 0xba, 0xa3, \
+ 0xff, 0x05, 0x40, 0xc4, 0x60, 0x05, 0x39, 0x31, 0x77, 0xf7, 0xa5, 0xca, \
+ 0x01, 0x31, 0x80, 0xa7, 0xe1, 0xd1, 0x0a, 0xa2, 0x7c, 0xd5, 0x1c, 0xba, \
+ 0xd0, 0x23, 0x4a, 0xd6, 0x30, 0xf3, 0x93, 0xc7, 0x6f, 0xe8, 0xce, 0x94, \
+ 0x1e, 0x84, 0xbb, 0x44, 0x81, 0x62, 0x33, 0xff, 0x6b, 0x5d, 0x00, 0x9b, \
+ 0x25, 0xf8, 0x8f, 0x0f, 0x9c, 0x4c, 0x4d, 0xe8, 0xd9, 0xa7, 0x99, 0xf9, \
+ 0x51, 0x81, 0xc0, 0x9b, 0x1b, 0x31, 0x0d, 0xa6, 0xb3, 0x7c, 0x0e, 0x45, \
+ 0xb8, 0x18, 0x64, 0x7e, 0x89, 0x0a, 0x2b, 0xa8, 0xc3, 0xe0, 0x4a, 0xbd, \
+ 0xd4, 0x2f, 0x78, 0xc4, 0x62, 0x9b, 0xe9, 0x7e, 0x3f, 0x56, 0x46, 0x8f, \
+ 0x17, 0xb7, 0x2a, 0xa0, 0x10, 0x70, 0xfd, 0xb1, 0xf1, 0x6b, 0x05, 0xdc, \
+ 0xd1, 0x41, 0x0f, 0x8e, 0xa6, 0xb2, 0x88, 0x1a, 0x42, 0x61, 0x4f, 0xeb, \
+ 0x26, 0x85, 0x59, 0x80, 0xba, 0x85, 0x54, 0xfe, 0xcf, 0xc7, 0x7b, 0x2f, \
+ 0x6b, 0x59, 0xce, 0xac, 0xdc, 0x7c, 0xac, 0xf3, 0xc8, 0xd6, 0x12, 0x7e, \
+ 0x64, 0xe8, 0x3c, 0x99, 0xa8, 0x8f, 0x4f, 0x11, 0xd9, 0x9c, 0x15, 0x4b, \
+ 0x6a, 0x44, 0x92, 0x2d, 0x0c, 0xbf, 0xb1, 0x67, 0x96, 0xc9, 0xac, 0xce, \
+ 0xd5, 0x19, 0xeb, 0x6f, 0x18, 0xeb, 0x6e, 0x04, 0x2d, 0x60, 0xac, 0xf4, \
+ 0x7b, 0x79, 0xf0, 0x1a, 0x9b, 0xb5, 0xc3, 0x5d, 0xef, 0x7d, 0xc9, 0x05, \
+ 0x99, 0x44, 0x81, 0x84, 0x75, 0xc7, 0xec, 0x00, 0x12, 0xfc, 0x7a, 0x4a, \
+ 0x0b, 0x82, 0x07, 0xec, 0x6d, 0x86, 0x02, 0x4d, 0xfe, 0x9f, 0xc8, 0x92, \
+ 0x48, 0xde, 0xf5, 0xb1, 0x9c, 0xe9, 0xc6, 0x89, 0xd0, 0xc1, 0x56, 0xe8, \
+ 0xa4, 0xc6, 0x6a, 0x2e, 0x66, 0xc1, 0x9b, 0xfe, 0xd6, 0x3c, 0xb7 \
}
/* END FILE */
/* This is taken from tests/data_files/server2.crt. */
/* BEGIN FILE string macro TEST_SRV_CRT_RSA_SHA1_PEM tests/data_files/server2.crt */
#define TEST_SRV_CRT_RSA_SHA1_PEM \
-"-----BEGIN CERTIFICATE-----\r\n" \
-"MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" \
-"MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
-"MTkwMjEwMTQ0NDA2WhcNMjkwMjEwMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \
-"A1UECgwIUG9sYXJTU0wxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n" \
-"AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n" \
-"owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n" \
-"NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n" \
-"tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n" \
-"hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n" \
-"HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n" \
-"VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n" \
-"FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQEFBQADggEBAJklg3Q4\r\n" \
-"cB7v7BzsxM/vLyKccO6op0/gZzM4ghuLq2Y32kl0sM6kSNUUmduuq3u/+GmUZN2A\r\n" \
-"O/7c+Hw7hDFEIvZk98aBGjCLqn3DmgHIv8ToQ67nellQxx2Uj309PdgjNi/r9HOc\r\n" \
-"KNAYPbBcg6MJGWWj2TI6vNaceios/DhOYx5V0j5nfqSJ/pnU0g9Ign2LAhgYpGJE\r\n" \
-"iEM9wW7hEMkwmk0h/sqZsrJsGH5YsF/VThSq/JVO1e2mZH2vruyZKJVBq+8tDNYp\r\n" \
-"HkK6tSyVYQhzIt3StMJWKMl/o5k2AYz6tSC164+1oG+ML3LWg8XrGKa91H4UOKap\r\n" \
-"Awgk0+4m0T25cNs=\r\n" \
-"-----END CERTIFICATE-----\r\n"
+ "-----BEGIN CERTIFICATE-----\r\n" \
+ "MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" \
+ "MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
+ "MTkwMjEwMTQ0NDA2WhcNMjkwMjEwMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \
+ "A1UECgwIUG9sYXJTU0wxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n" \
+ "AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n" \
+ "owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n" \
+ "NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n" \
+ "tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n" \
+ "hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n" \
+ "HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n" \
+ "VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n" \
+ "FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQEFBQADggEBAJklg3Q4\r\n" \
+ "cB7v7BzsxM/vLyKccO6op0/gZzM4ghuLq2Y32kl0sM6kSNUUmduuq3u/+GmUZN2A\r\n" \
+ "O/7c+Hw7hDFEIvZk98aBGjCLqn3DmgHIv8ToQ67nellQxx2Uj309PdgjNi/r9HOc\r\n" \
+ "KNAYPbBcg6MJGWWj2TI6vNaceios/DhOYx5V0j5nfqSJ/pnU0g9Ign2LAhgYpGJE\r\n" \
+ "iEM9wW7hEMkwmk0h/sqZsrJsGH5YsF/VThSq/JVO1e2mZH2vruyZKJVBq+8tDNYp\r\n" \
+ "HkK6tSyVYQhzIt3StMJWKMl/o5k2AYz6tSC164+1oG+ML3LWg8XrGKa91H4UOKap\r\n" \
+ "Awgk0+4m0T25cNs=\r\n" \
+ "-----END CERTIFICATE-----\r\n"
/* END FILE */
/* This is taken from tests/data_files/server2.crt.der. */
/* BEGIN FILE binary macro TEST_SRV_CRT_RSA_SHA1_DER tests/data_files/server2.crt.der */
#define TEST_SRV_CRT_RSA_SHA1_DER { \
- 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
- 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
- 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
- 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
- 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
- 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
- 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
- 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
- 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
- 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
- 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
- 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
- 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, \
- 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \
- 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, \
- 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, \
- 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, \
- 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, \
- 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, \
- 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, \
- 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, \
- 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, \
- 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, \
- 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, 0x07, 0x7d, \
- 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \
- 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, \
- 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, \
- 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, \
- 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, \
- 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, \
- 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, \
- 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, \
- 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, \
- 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, \
- 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, 0x96, \
- 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, \
- 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, \
- 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, \
- 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, \
- 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, \
- 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \
- 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, \
- 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \
- 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, \
- 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x01, 0x73, 0x0b, 0x4a, 0xc5, \
- 0xcb, 0xa0, 0xde, 0xf1, 0x63, 0x1c, 0x76, 0x04, 0x2b, 0x13, 0x0d, 0xc0, \
- 0x84, 0x11, 0xc5, 0x8f, 0x3a, 0xa7, 0xc5, 0x9c, 0x35, 0x7a, 0x77, 0xb8, \
- 0x20, 0x14, 0x82, 0xee, 0x54, 0xf0, 0xf2, 0xb0, 0x52, 0xcb, 0x78, 0xce, \
- 0x59, 0x07, 0x4f, 0x51, 0x69, 0xfe, 0xd3, 0x2f, 0xe9, 0x09, 0xe7, 0x85, \
- 0x92, 0xd8, 0xba, 0xb1, 0xeb, 0xc5, 0x76, 0x5d, 0x61, 0x2d, 0xe9, 0x86, \
- 0xb5, 0xde, 0x2a, 0xf9, 0x3f, 0x53, 0x28, 0x42, 0x86, 0x83, 0x73, 0x43, \
- 0xe0, 0x04, 0x5f, 0x07, 0x90, 0x14, 0x65, 0x9f, 0x6e, 0x10, 0x7a, 0xbc, \
- 0x58, 0x19, 0x22, 0xc2, 0xeb, 0x39, 0x72, 0x51, 0x92, 0xd7, 0xb4, 0x1d, \
- 0x75, 0x2f, 0xd3, 0x3a, 0x2b, 0x01, 0xe7, 0xdb, 0x50, 0xae, 0xe2, 0xf1, \
- 0xd4, 0x4d, 0x5b, 0x3c, 0xbb, 0x41, 0x2b, 0x2a, 0xa4, 0xe2, 0x4a, 0x02, \
- 0xe5, 0x60, 0x14, 0x2c, 0x9c, 0x1f, 0xa6, 0xcc, 0x06, 0x4b, 0x25, 0x89, \
- 0x4e, 0x96, 0x30, 0x22, 0x9c, 0x5c, 0x58, 0x4d, 0xc3, 0xda, 0xd0, 0x6e, \
- 0x50, 0x1e, 0x8c, 0x65, 0xf5, 0xd9, 0x17, 0x35, 0xa6, 0x58, 0x43, 0xb2, \
- 0x29, 0xb7, 0xa8, 0x5e, 0x35, 0xde, 0xf0, 0x60, 0x42, 0x1a, 0x01, 0xcb, \
- 0xcb, 0x0b, 0xd8, 0x0e, 0xc1, 0x90, 0xdf, 0xa1, 0xd2, 0x1a, 0xd1, 0x2c, \
- 0x02, 0xf4, 0x76, 0x41, 0xa4, 0xcb, 0x4b, 0x15, 0x98, 0x71, 0xf9, 0x35, \
- 0x7d, 0xb0, 0xe7, 0xe2, 0x34, 0x96, 0x91, 0xbe, 0x32, 0x67, 0x2d, 0x6b, \
- 0xd3, 0x55, 0x04, 0x8a, 0x01, 0x50, 0xb4, 0xe3, 0x62, 0x78, 0x6c, 0x11, \
- 0x15, 0xa5, 0x2a, 0x11, 0xc1, 0x49, 0x1c, 0x9b, 0xc4, 0x10, 0x65, 0x60, \
- 0x87, 0xd9, 0x1e, 0x69, 0x59, 0x4e, 0x8f, 0x6b, 0xeb, 0xc1, 0xfe, 0x6b, \
- 0xe2, 0x63, 0x78, 0x95, 0x6e, 0xe0, 0x2d, 0xd7, 0xa7, 0x37, 0xa8 \
+ 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x31, 0x32, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, \
+ 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \
+ 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, \
+ 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, \
+ 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, \
+ 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, \
+ 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, \
+ 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, \
+ 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, \
+ 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, \
+ 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, \
+ 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, 0x07, 0x7d, \
+ 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \
+ 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, \
+ 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, \
+ 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, \
+ 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, \
+ 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, \
+ 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, \
+ 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, \
+ 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, \
+ 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, \
+ 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, 0x96, \
+ 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, \
+ 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, \
+ 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, \
+ 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, \
+ 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, \
+ 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \
+ 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, \
+ 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \
+ 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, \
+ 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x01, 0x73, 0x0b, 0x4a, 0xc5, \
+ 0xcb, 0xa0, 0xde, 0xf1, 0x63, 0x1c, 0x76, 0x04, 0x2b, 0x13, 0x0d, 0xc0, \
+ 0x84, 0x11, 0xc5, 0x8f, 0x3a, 0xa7, 0xc5, 0x9c, 0x35, 0x7a, 0x77, 0xb8, \
+ 0x20, 0x14, 0x82, 0xee, 0x54, 0xf0, 0xf2, 0xb0, 0x52, 0xcb, 0x78, 0xce, \
+ 0x59, 0x07, 0x4f, 0x51, 0x69, 0xfe, 0xd3, 0x2f, 0xe9, 0x09, 0xe7, 0x85, \
+ 0x92, 0xd8, 0xba, 0xb1, 0xeb, 0xc5, 0x76, 0x5d, 0x61, 0x2d, 0xe9, 0x86, \
+ 0xb5, 0xde, 0x2a, 0xf9, 0x3f, 0x53, 0x28, 0x42, 0x86, 0x83, 0x73, 0x43, \
+ 0xe0, 0x04, 0x5f, 0x07, 0x90, 0x14, 0x65, 0x9f, 0x6e, 0x10, 0x7a, 0xbc, \
+ 0x58, 0x19, 0x22, 0xc2, 0xeb, 0x39, 0x72, 0x51, 0x92, 0xd7, 0xb4, 0x1d, \
+ 0x75, 0x2f, 0xd3, 0x3a, 0x2b, 0x01, 0xe7, 0xdb, 0x50, 0xae, 0xe2, 0xf1, \
+ 0xd4, 0x4d, 0x5b, 0x3c, 0xbb, 0x41, 0x2b, 0x2a, 0xa4, 0xe2, 0x4a, 0x02, \
+ 0xe5, 0x60, 0x14, 0x2c, 0x9c, 0x1f, 0xa6, 0xcc, 0x06, 0x4b, 0x25, 0x89, \
+ 0x4e, 0x96, 0x30, 0x22, 0x9c, 0x5c, 0x58, 0x4d, 0xc3, 0xda, 0xd0, 0x6e, \
+ 0x50, 0x1e, 0x8c, 0x65, 0xf5, 0xd9, 0x17, 0x35, 0xa6, 0x58, 0x43, 0xb2, \
+ 0x29, 0xb7, 0xa8, 0x5e, 0x35, 0xde, 0xf0, 0x60, 0x42, 0x1a, 0x01, 0xcb, \
+ 0xcb, 0x0b, 0xd8, 0x0e, 0xc1, 0x90, 0xdf, 0xa1, 0xd2, 0x1a, 0xd1, 0x2c, \
+ 0x02, 0xf4, 0x76, 0x41, 0xa4, 0xcb, 0x4b, 0x15, 0x98, 0x71, 0xf9, 0x35, \
+ 0x7d, 0xb0, 0xe7, 0xe2, 0x34, 0x96, 0x91, 0xbe, 0x32, 0x67, 0x2d, 0x6b, \
+ 0xd3, 0x55, 0x04, 0x8a, 0x01, 0x50, 0xb4, 0xe3, 0x62, 0x78, 0x6c, 0x11, \
+ 0x15, 0xa5, 0x2a, 0x11, 0xc1, 0x49, 0x1c, 0x9b, 0xc4, 0x10, 0x65, 0x60, \
+ 0x87, 0xd9, 0x1e, 0x69, 0x59, 0x4e, 0x8f, 0x6b, 0xeb, 0xc1, 0xfe, 0x6b, \
+ 0xe2, 0x63, 0x78, 0x95, 0x6e, 0xe0, 0x2d, 0xd7, 0xa7, 0x37, 0xa8 \
}
/* END FILE */
@@ -834,106 +834,106 @@
/* This was generated from tests/data_files/server2.key.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_SRV_KEY_RSA_DER tests/data_files/server2.key.der */
#define TEST_SRV_KEY_RSA_DER { \
- 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
- 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, \
- 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, \
- 0x16, 0xd0, 0x5a, 0xe4, 0xcd, 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, \
- 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, \
- 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, \
- 0xb0, 0x28, 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, \
- 0xfe, 0xc1, 0x04, 0x52, 0xb3, 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, \
- 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, \
- 0xab, 0x74, 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, \
- 0xd9, 0x0d, 0x1c, 0x2d, 0x49, 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, \
- 0x0b, 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, \
- 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, \
- 0xc3, 0xcd, 0x40, 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, \
- 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, \
- 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, \
- 0x18, 0xc6, 0x62, 0x2f, 0xc7, 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, \
- 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, \
- 0x4a, 0x0e, 0xef, 0xd6, 0xde, 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, \
- 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, \
- 0xcb, 0x73, 0x4b, 0x52, 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, \
- 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, \
- 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
- 0x01, 0x00, 0x97, 0x47, 0x44, 0xbc, 0x10, 0x81, 0xc5, 0x18, 0xe4, 0x59, \
- 0xfb, 0xe0, 0x2d, 0x3a, 0x0e, 0x9e, 0x10, 0xdc, 0x43, 0xfb, 0x15, 0x6c, \
- 0xd1, 0xfd, 0x48, 0x78, 0x6c, 0xf9, 0xed, 0x38, 0xe8, 0xdd, 0x09, 0xd7, \
- 0x5f, 0xb5, 0x41, 0x64, 0xd7, 0x63, 0xfa, 0x9d, 0x44, 0x0a, 0xf8, 0x42, \
- 0x13, 0xf1, 0xbb, 0x5e, 0x79, 0x20, 0x53, 0x98, 0x4b, 0x65, 0x7f, 0x86, \
- 0x67, 0x48, 0xe4, 0xcf, 0xfb, 0x6a, 0x24, 0xe2, 0x34, 0xbd, 0x14, 0x9d, \
- 0x2c, 0x16, 0xe2, 0xa4, 0x79, 0xd6, 0xa2, 0xec, 0x81, 0x43, 0x87, 0xbf, \
- 0x03, 0x5c, 0x88, 0x25, 0xd9, 0x41, 0xb6, 0xa5, 0xf1, 0x27, 0x52, 0x84, \
- 0xfe, 0x2b, 0x6e, 0x1d, 0x16, 0xcd, 0x73, 0x88, 0xf8, 0x90, 0xbf, 0x19, \
- 0xfe, 0xbe, 0xa9, 0xbf, 0x09, 0xd3, 0x23, 0x43, 0xd2, 0xc7, 0x61, 0x2a, \
- 0xb3, 0x4e, 0x3c, 0x61, 0xd4, 0xbd, 0xd8, 0xb4, 0xfa, 0xa8, 0x0b, 0xf8, \
- 0x7e, 0x56, 0xcd, 0x0f, 0x13, 0x27, 0xda, 0xe6, 0x3b, 0xb3, 0x8c, 0x9c, \
- 0x4b, 0x84, 0x3c, 0xc3, 0x52, 0x57, 0x9c, 0x27, 0x9a, 0x02, 0x76, 0x26, \
- 0x59, 0x82, 0x39, 0xc3, 0x13, 0xbe, 0x6e, 0xf4, 0x44, 0x2d, 0x1d, 0x8c, \
- 0x73, 0x3e, 0x43, 0x99, 0x59, 0xcb, 0xf2, 0x34, 0x72, 0x9a, 0x5e, 0xa5, \
- 0xeb, 0x9f, 0x36, 0x6d, 0x2b, 0xf9, 0xa2, 0xe7, 0xd1, 0x78, 0x52, 0x1b, \
- 0xc8, 0xf6, 0x5b, 0x41, 0x69, 0x57, 0x81, 0x89, 0xe9, 0xbb, 0xa1, 0xde, \
- 0x19, 0x37, 0x3b, 0x13, 0x5c, 0xca, 0x61, 0x01, 0x86, 0xff, 0xdf, 0x83, \
- 0x41, 0x49, 0x7f, 0xd6, 0xf4, 0x2e, 0x08, 0xfa, 0x90, 0xc2, 0x7c, 0xb4, \
- 0xb5, 0x0a, 0x17, 0xdb, 0x0e, 0x6d, 0x75, 0x8a, 0x5d, 0x31, 0xd5, 0x66, \
- 0xfb, 0x39, 0x0b, 0xb5, 0xb6, 0xa3, 0xcd, 0xd4, 0xef, 0x88, 0x92, 0x5a, \
- 0x4d, 0x6c, 0xcb, 0xea, 0x5b, 0x79, 0x02, 0x81, 0x81, 0x00, 0xdf, 0x3a, \
- 0xf9, 0x25, 0x5e, 0x24, 0x37, 0x26, 0x40, 0x97, 0x2f, 0xe0, 0x4a, 0xba, \
- 0x52, 0x1b, 0x51, 0xaf, 0x84, 0x06, 0x32, 0x24, 0x0c, 0xcf, 0x44, 0xa8, \
- 0x77, 0xa7, 0xad, 0xb5, 0x8c, 0x58, 0xcc, 0xc8, 0x31, 0xb7, 0x0d, 0xbc, \
- 0x08, 0x8a, 0xe0, 0xa6, 0x8c, 0xc2, 0x73, 0xe5, 0x1a, 0x64, 0x92, 0xe8, \
- 0xed, 0x4c, 0x6f, 0x0b, 0xa6, 0xa7, 0xf3, 0x9a, 0xf5, 0x6f, 0x69, 0xca, \
- 0x3c, 0x22, 0xd0, 0x15, 0xa8, 0x20, 0x27, 0x41, 0xf8, 0x43, 0x42, 0x7f, \
- 0xb1, 0x93, 0xa1, 0x04, 0x85, 0xda, 0xa0, 0x1c, 0xd6, 0xc6, 0xf7, 0x8a, \
- 0x9e, 0xea, 0x5c, 0x78, 0xa7, 0x55, 0xc4, 0x6b, 0x05, 0x8b, 0xc0, 0x83, \
- 0xcb, 0xce, 0x83, 0x05, 0xf8, 0xb2, 0x16, 0x2b, 0xdf, 0x06, 0x3f, 0xb8, \
- 0xec, 0x16, 0xda, 0x43, 0x33, 0xc1, 0x8f, 0xb0, 0xb8, 0xac, 0xae, 0xd4, \
- 0x94, 0xb8, 0xda, 0x6f, 0x6a, 0xc3, 0x02, 0x81, 0x81, 0x00, 0xdd, 0xae, \
- 0x00, 0xcd, 0xa0, 0x72, 0x1a, 0x05, 0x8a, 0xee, 0x2f, 0xd4, 0x71, 0x4b, \
- 0xf0, 0x3e, 0xe5, 0xc1, 0xe1, 0x29, 0x8b, 0xa6, 0x67, 0x30, 0x98, 0xe7, \
- 0x12, 0xef, 0xdd, 0x12, 0x01, 0x90, 0x24, 0x58, 0xf0, 0x76, 0x92, 0xe7, \
- 0x3d, 0xbb, 0x23, 0xe1, 0xce, 0xf9, 0xa1, 0xd4, 0x38, 0x1b, 0x3f, 0x20, \
- 0xb3, 0x0f, 0x65, 0x6a, 0x8f, 0x55, 0x57, 0x36, 0xee, 0xb2, 0x84, 0x44, \
- 0xfc, 0x91, 0x88, 0xe1, 0xa4, 0xdd, 0x3b, 0x4a, 0x40, 0x4d, 0x7c, 0x86, \
- 0xed, 0xe1, 0xb5, 0x42, 0xef, 0xb9, 0x61, 0xcd, 0x58, 0x19, 0x77, 0x02, \
- 0xae, 0x58, 0x80, 0xdb, 0x13, 0x3d, 0xc7, 0x1f, 0x9d, 0xed, 0xff, 0xac, \
- 0x98, 0xfc, 0xcd, 0xf9, 0x62, 0x04, 0x83, 0x91, 0x89, 0x0d, 0x86, 0x43, \
- 0x8c, 0x0c, 0xc7, 0x1b, 0x90, 0x4d, 0xbe, 0x2f, 0xc5, 0x7c, 0xcd, 0x42, \
- 0xf5, 0xd3, 0xad, 0x8e, 0xfd, 0x9d, 0x02, 0x81, 0x80, 0x17, 0x4b, 0x79, \
- 0x2a, 0x6c, 0x1b, 0x8d, 0x61, 0xc1, 0x85, 0xc5, 0x6a, 0x3b, 0x82, 0x1c, \
- 0x05, 0x5b, 0xcd, 0xdc, 0x12, 0x25, 0x73, 0x5b, 0x9e, 0xd9, 0x84, 0x57, \
- 0x10, 0x39, 0x71, 0x63, 0x96, 0xf4, 0xaf, 0xc3, 0x78, 0x5d, 0xc7, 0x8c, \
- 0x80, 0xa9, 0x96, 0xd7, 0xc3, 0x87, 0x02, 0x96, 0x71, 0x7e, 0x5f, 0x2e, \
- 0x3c, 0x36, 0xae, 0x59, 0x92, 0xd7, 0x3a, 0x09, 0x78, 0xb9, 0xea, 0x6f, \
- 0xc2, 0x16, 0x42, 0xdc, 0x4b, 0x96, 0xad, 0x2c, 0xb2, 0x20, 0x23, 0x61, \
- 0x2d, 0x8d, 0xb5, 0x02, 0x1e, 0xe1, 0x6c, 0x81, 0x01, 0x3c, 0x5d, 0xcb, \
- 0xdd, 0x9b, 0x0e, 0xc0, 0x2f, 0x94, 0x12, 0xb2, 0xfe, 0x75, 0x75, 0x8b, \
- 0x74, 0x1e, 0x7a, 0x26, 0x0c, 0xb7, 0x81, 0x96, 0x81, 0x79, 0x6e, 0xdb, \
- 0xbc, 0x3a, 0xc4, 0x9e, 0x87, 0x09, 0x6e, 0xa0, 0xa6, 0xec, 0x8b, 0xa4, \
- 0x85, 0x71, 0xce, 0x04, 0xaf, 0x02, 0x81, 0x81, 0x00, 0xc2, 0xa7, 0x47, \
- 0x07, 0x48, 0x6a, 0xc8, 0xd4, 0xb3, 0x20, 0xe1, 0x98, 0xee, 0xff, 0x5a, \
- 0x6f, 0x30, 0x7a, 0xa5, 0x47, 0x40, 0xdc, 0x16, 0x62, 0x42, 0xf1, 0x2c, \
- 0xdc, 0xb8, 0xc7, 0x55, 0xde, 0x07, 0x3c, 0x9d, 0xb1, 0xd0, 0xdf, 0x02, \
- 0x82, 0xb0, 0x48, 0x58, 0xe1, 0x34, 0xab, 0xcf, 0xb4, 0x85, 0x23, 0x26, \
- 0x78, 0x4f, 0x7a, 0x59, 0x6f, 0xfb, 0x8c, 0x3d, 0xdf, 0x3d, 0x6c, 0x02, \
- 0x47, 0x9c, 0xe5, 0x5e, 0x49, 0xf1, 0x05, 0x0b, 0x1f, 0xbf, 0x48, 0x0f, \
- 0xdc, 0x10, 0xb9, 0x3d, 0x1d, 0x10, 0x77, 0x2a, 0x73, 0xf9, 0xdf, 0xbd, \
- 0xcd, 0xf3, 0x1f, 0xeb, 0x6e, 0x64, 0xca, 0x2b, 0x78, 0x4f, 0xf8, 0x73, \
- 0xc2, 0x10, 0xef, 0x79, 0x95, 0x33, 0x1e, 0x79, 0x35, 0x09, 0xff, 0x88, \
- 0x1b, 0xb4, 0x3e, 0x4c, 0xe1, 0x27, 0x2e, 0x75, 0x80, 0x58, 0x11, 0x03, \
- 0x21, 0x23, 0x96, 0x9a, 0xb5, 0x02, 0x81, 0x80, 0x05, 0x12, 0x64, 0x71, \
- 0x83, 0x00, 0x1c, 0xfe, 0xef, 0x83, 0xea, 0xdd, 0x2c, 0xc8, 0x2c, 0x00, \
- 0x62, 0x1e, 0x8f, 0x3a, 0xdb, 0x1c, 0xab, 0xd6, 0x34, 0x8b, 0xd1, 0xb2, \
- 0x5a, 0x4f, 0x3d, 0x37, 0x38, 0x02, 0xe0, 0xd7, 0x70, 0xc1, 0xb0, 0x47, \
- 0xe0, 0x08, 0x1a, 0x84, 0xec, 0x48, 0xc5, 0x7c, 0x76, 0x83, 0x12, 0x67, \
- 0xab, 0x7c, 0x9f, 0x90, 0x97, 0xc8, 0x8f, 0x07, 0xf4, 0xb3, 0x60, 0xf2, \
- 0x3f, 0x49, 0x18, 0xdb, 0x2e, 0x94, 0x6b, 0x53, 0x9e, 0xa2, 0x63, 0xde, \
- 0x63, 0xd9, 0xab, 0x21, 0x2e, 0x2d, 0x0a, 0xe0, 0xd0, 0xe8, 0xba, 0xc4, \
- 0x4c, 0x1e, 0xa5, 0xf5, 0x51, 0xa8, 0xc4, 0x92, 0xf8, 0x7f, 0x21, 0xe7, \
- 0x65, 0xbf, 0x0b, 0xe6, 0x01, 0xaf, 0x9c, 0x1d, 0x5b, 0x6c, 0x3f, 0x1c, \
- 0x2f, 0xa6, 0x0f, 0x68, 0x38, 0x8e, 0x85, 0xc4, 0x6c, 0x78, 0x2f, 0x6f, \
- 0x06, 0x21, 0x2e, 0x56 \
+ 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
+ 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, \
+ 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, \
+ 0x16, 0xd0, 0x5a, 0xe4, 0xcd, 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, \
+ 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, \
+ 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, \
+ 0xb0, 0x28, 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, \
+ 0xfe, 0xc1, 0x04, 0x52, 0xb3, 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, \
+ 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, \
+ 0xab, 0x74, 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, \
+ 0xd9, 0x0d, 0x1c, 0x2d, 0x49, 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, \
+ 0x0b, 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, \
+ 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, \
+ 0xc3, 0xcd, 0x40, 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, \
+ 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, \
+ 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, \
+ 0x18, 0xc6, 0x62, 0x2f, 0xc7, 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, \
+ 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, \
+ 0x4a, 0x0e, 0xef, 0xd6, 0xde, 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, \
+ 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, \
+ 0xcb, 0x73, 0x4b, 0x52, 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, \
+ 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, \
+ 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
+ 0x01, 0x00, 0x97, 0x47, 0x44, 0xbc, 0x10, 0x81, 0xc5, 0x18, 0xe4, 0x59, \
+ 0xfb, 0xe0, 0x2d, 0x3a, 0x0e, 0x9e, 0x10, 0xdc, 0x43, 0xfb, 0x15, 0x6c, \
+ 0xd1, 0xfd, 0x48, 0x78, 0x6c, 0xf9, 0xed, 0x38, 0xe8, 0xdd, 0x09, 0xd7, \
+ 0x5f, 0xb5, 0x41, 0x64, 0xd7, 0x63, 0xfa, 0x9d, 0x44, 0x0a, 0xf8, 0x42, \
+ 0x13, 0xf1, 0xbb, 0x5e, 0x79, 0x20, 0x53, 0x98, 0x4b, 0x65, 0x7f, 0x86, \
+ 0x67, 0x48, 0xe4, 0xcf, 0xfb, 0x6a, 0x24, 0xe2, 0x34, 0xbd, 0x14, 0x9d, \
+ 0x2c, 0x16, 0xe2, 0xa4, 0x79, 0xd6, 0xa2, 0xec, 0x81, 0x43, 0x87, 0xbf, \
+ 0x03, 0x5c, 0x88, 0x25, 0xd9, 0x41, 0xb6, 0xa5, 0xf1, 0x27, 0x52, 0x84, \
+ 0xfe, 0x2b, 0x6e, 0x1d, 0x16, 0xcd, 0x73, 0x88, 0xf8, 0x90, 0xbf, 0x19, \
+ 0xfe, 0xbe, 0xa9, 0xbf, 0x09, 0xd3, 0x23, 0x43, 0xd2, 0xc7, 0x61, 0x2a, \
+ 0xb3, 0x4e, 0x3c, 0x61, 0xd4, 0xbd, 0xd8, 0xb4, 0xfa, 0xa8, 0x0b, 0xf8, \
+ 0x7e, 0x56, 0xcd, 0x0f, 0x13, 0x27, 0xda, 0xe6, 0x3b, 0xb3, 0x8c, 0x9c, \
+ 0x4b, 0x84, 0x3c, 0xc3, 0x52, 0x57, 0x9c, 0x27, 0x9a, 0x02, 0x76, 0x26, \
+ 0x59, 0x82, 0x39, 0xc3, 0x13, 0xbe, 0x6e, 0xf4, 0x44, 0x2d, 0x1d, 0x8c, \
+ 0x73, 0x3e, 0x43, 0x99, 0x59, 0xcb, 0xf2, 0x34, 0x72, 0x9a, 0x5e, 0xa5, \
+ 0xeb, 0x9f, 0x36, 0x6d, 0x2b, 0xf9, 0xa2, 0xe7, 0xd1, 0x78, 0x52, 0x1b, \
+ 0xc8, 0xf6, 0x5b, 0x41, 0x69, 0x57, 0x81, 0x89, 0xe9, 0xbb, 0xa1, 0xde, \
+ 0x19, 0x37, 0x3b, 0x13, 0x5c, 0xca, 0x61, 0x01, 0x86, 0xff, 0xdf, 0x83, \
+ 0x41, 0x49, 0x7f, 0xd6, 0xf4, 0x2e, 0x08, 0xfa, 0x90, 0xc2, 0x7c, 0xb4, \
+ 0xb5, 0x0a, 0x17, 0xdb, 0x0e, 0x6d, 0x75, 0x8a, 0x5d, 0x31, 0xd5, 0x66, \
+ 0xfb, 0x39, 0x0b, 0xb5, 0xb6, 0xa3, 0xcd, 0xd4, 0xef, 0x88, 0x92, 0x5a, \
+ 0x4d, 0x6c, 0xcb, 0xea, 0x5b, 0x79, 0x02, 0x81, 0x81, 0x00, 0xdf, 0x3a, \
+ 0xf9, 0x25, 0x5e, 0x24, 0x37, 0x26, 0x40, 0x97, 0x2f, 0xe0, 0x4a, 0xba, \
+ 0x52, 0x1b, 0x51, 0xaf, 0x84, 0x06, 0x32, 0x24, 0x0c, 0xcf, 0x44, 0xa8, \
+ 0x77, 0xa7, 0xad, 0xb5, 0x8c, 0x58, 0xcc, 0xc8, 0x31, 0xb7, 0x0d, 0xbc, \
+ 0x08, 0x8a, 0xe0, 0xa6, 0x8c, 0xc2, 0x73, 0xe5, 0x1a, 0x64, 0x92, 0xe8, \
+ 0xed, 0x4c, 0x6f, 0x0b, 0xa6, 0xa7, 0xf3, 0x9a, 0xf5, 0x6f, 0x69, 0xca, \
+ 0x3c, 0x22, 0xd0, 0x15, 0xa8, 0x20, 0x27, 0x41, 0xf8, 0x43, 0x42, 0x7f, \
+ 0xb1, 0x93, 0xa1, 0x04, 0x85, 0xda, 0xa0, 0x1c, 0xd6, 0xc6, 0xf7, 0x8a, \
+ 0x9e, 0xea, 0x5c, 0x78, 0xa7, 0x55, 0xc4, 0x6b, 0x05, 0x8b, 0xc0, 0x83, \
+ 0xcb, 0xce, 0x83, 0x05, 0xf8, 0xb2, 0x16, 0x2b, 0xdf, 0x06, 0x3f, 0xb8, \
+ 0xec, 0x16, 0xda, 0x43, 0x33, 0xc1, 0x8f, 0xb0, 0xb8, 0xac, 0xae, 0xd4, \
+ 0x94, 0xb8, 0xda, 0x6f, 0x6a, 0xc3, 0x02, 0x81, 0x81, 0x00, 0xdd, 0xae, \
+ 0x00, 0xcd, 0xa0, 0x72, 0x1a, 0x05, 0x8a, 0xee, 0x2f, 0xd4, 0x71, 0x4b, \
+ 0xf0, 0x3e, 0xe5, 0xc1, 0xe1, 0x29, 0x8b, 0xa6, 0x67, 0x30, 0x98, 0xe7, \
+ 0x12, 0xef, 0xdd, 0x12, 0x01, 0x90, 0x24, 0x58, 0xf0, 0x76, 0x92, 0xe7, \
+ 0x3d, 0xbb, 0x23, 0xe1, 0xce, 0xf9, 0xa1, 0xd4, 0x38, 0x1b, 0x3f, 0x20, \
+ 0xb3, 0x0f, 0x65, 0x6a, 0x8f, 0x55, 0x57, 0x36, 0xee, 0xb2, 0x84, 0x44, \
+ 0xfc, 0x91, 0x88, 0xe1, 0xa4, 0xdd, 0x3b, 0x4a, 0x40, 0x4d, 0x7c, 0x86, \
+ 0xed, 0xe1, 0xb5, 0x42, 0xef, 0xb9, 0x61, 0xcd, 0x58, 0x19, 0x77, 0x02, \
+ 0xae, 0x58, 0x80, 0xdb, 0x13, 0x3d, 0xc7, 0x1f, 0x9d, 0xed, 0xff, 0xac, \
+ 0x98, 0xfc, 0xcd, 0xf9, 0x62, 0x04, 0x83, 0x91, 0x89, 0x0d, 0x86, 0x43, \
+ 0x8c, 0x0c, 0xc7, 0x1b, 0x90, 0x4d, 0xbe, 0x2f, 0xc5, 0x7c, 0xcd, 0x42, \
+ 0xf5, 0xd3, 0xad, 0x8e, 0xfd, 0x9d, 0x02, 0x81, 0x80, 0x17, 0x4b, 0x79, \
+ 0x2a, 0x6c, 0x1b, 0x8d, 0x61, 0xc1, 0x85, 0xc5, 0x6a, 0x3b, 0x82, 0x1c, \
+ 0x05, 0x5b, 0xcd, 0xdc, 0x12, 0x25, 0x73, 0x5b, 0x9e, 0xd9, 0x84, 0x57, \
+ 0x10, 0x39, 0x71, 0x63, 0x96, 0xf4, 0xaf, 0xc3, 0x78, 0x5d, 0xc7, 0x8c, \
+ 0x80, 0xa9, 0x96, 0xd7, 0xc3, 0x87, 0x02, 0x96, 0x71, 0x7e, 0x5f, 0x2e, \
+ 0x3c, 0x36, 0xae, 0x59, 0x92, 0xd7, 0x3a, 0x09, 0x78, 0xb9, 0xea, 0x6f, \
+ 0xc2, 0x16, 0x42, 0xdc, 0x4b, 0x96, 0xad, 0x2c, 0xb2, 0x20, 0x23, 0x61, \
+ 0x2d, 0x8d, 0xb5, 0x02, 0x1e, 0xe1, 0x6c, 0x81, 0x01, 0x3c, 0x5d, 0xcb, \
+ 0xdd, 0x9b, 0x0e, 0xc0, 0x2f, 0x94, 0x12, 0xb2, 0xfe, 0x75, 0x75, 0x8b, \
+ 0x74, 0x1e, 0x7a, 0x26, 0x0c, 0xb7, 0x81, 0x96, 0x81, 0x79, 0x6e, 0xdb, \
+ 0xbc, 0x3a, 0xc4, 0x9e, 0x87, 0x09, 0x6e, 0xa0, 0xa6, 0xec, 0x8b, 0xa4, \
+ 0x85, 0x71, 0xce, 0x04, 0xaf, 0x02, 0x81, 0x81, 0x00, 0xc2, 0xa7, 0x47, \
+ 0x07, 0x48, 0x6a, 0xc8, 0xd4, 0xb3, 0x20, 0xe1, 0x98, 0xee, 0xff, 0x5a, \
+ 0x6f, 0x30, 0x7a, 0xa5, 0x47, 0x40, 0xdc, 0x16, 0x62, 0x42, 0xf1, 0x2c, \
+ 0xdc, 0xb8, 0xc7, 0x55, 0xde, 0x07, 0x3c, 0x9d, 0xb1, 0xd0, 0xdf, 0x02, \
+ 0x82, 0xb0, 0x48, 0x58, 0xe1, 0x34, 0xab, 0xcf, 0xb4, 0x85, 0x23, 0x26, \
+ 0x78, 0x4f, 0x7a, 0x59, 0x6f, 0xfb, 0x8c, 0x3d, 0xdf, 0x3d, 0x6c, 0x02, \
+ 0x47, 0x9c, 0xe5, 0x5e, 0x49, 0xf1, 0x05, 0x0b, 0x1f, 0xbf, 0x48, 0x0f, \
+ 0xdc, 0x10, 0xb9, 0x3d, 0x1d, 0x10, 0x77, 0x2a, 0x73, 0xf9, 0xdf, 0xbd, \
+ 0xcd, 0xf3, 0x1f, 0xeb, 0x6e, 0x64, 0xca, 0x2b, 0x78, 0x4f, 0xf8, 0x73, \
+ 0xc2, 0x10, 0xef, 0x79, 0x95, 0x33, 0x1e, 0x79, 0x35, 0x09, 0xff, 0x88, \
+ 0x1b, 0xb4, 0x3e, 0x4c, 0xe1, 0x27, 0x2e, 0x75, 0x80, 0x58, 0x11, 0x03, \
+ 0x21, 0x23, 0x96, 0x9a, 0xb5, 0x02, 0x81, 0x80, 0x05, 0x12, 0x64, 0x71, \
+ 0x83, 0x00, 0x1c, 0xfe, 0xef, 0x83, 0xea, 0xdd, 0x2c, 0xc8, 0x2c, 0x00, \
+ 0x62, 0x1e, 0x8f, 0x3a, 0xdb, 0x1c, 0xab, 0xd6, 0x34, 0x8b, 0xd1, 0xb2, \
+ 0x5a, 0x4f, 0x3d, 0x37, 0x38, 0x02, 0xe0, 0xd7, 0x70, 0xc1, 0xb0, 0x47, \
+ 0xe0, 0x08, 0x1a, 0x84, 0xec, 0x48, 0xc5, 0x7c, 0x76, 0x83, 0x12, 0x67, \
+ 0xab, 0x7c, 0x9f, 0x90, 0x97, 0xc8, 0x8f, 0x07, 0xf4, 0xb3, 0x60, 0xf2, \
+ 0x3f, 0x49, 0x18, 0xdb, 0x2e, 0x94, 0x6b, 0x53, 0x9e, 0xa2, 0x63, 0xde, \
+ 0x63, 0xd9, 0xab, 0x21, 0x2e, 0x2d, 0x0a, 0xe0, 0xd0, 0xe8, 0xba, 0xc4, \
+ 0x4c, 0x1e, 0xa5, 0xf5, 0x51, 0xa8, 0xc4, 0x92, 0xf8, 0x7f, 0x21, 0xe7, \
+ 0x65, 0xbf, 0x0b, 0xe6, 0x01, 0xaf, 0x9c, 0x1d, 0x5b, 0x6c, 0x3f, 0x1c, \
+ 0x2f, 0xa6, 0x0f, 0x68, 0x38, 0x8e, 0x85, 0xc4, 0x6c, 0x78, 0x2f, 0x6f, \
+ 0x06, 0x21, 0x2e, 0x56 \
}
/* END FILE */
@@ -971,47 +971,47 @@
/* This is generated from tests/data_files/cli2.crt.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_CLI_CRT_EC_DER tests/data_files/cli2.crt.der */
#define TEST_CLI_CRT_EC_DER { \
- 0x30, 0x82, 0x01, 0xdf, 0x30, 0x82, 0x01, 0x63, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x01, 0x0d, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
- 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, \
- 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
- 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
- 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, \
- 0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, \
- 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, \
- 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, \
- 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \
- 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x30, 0x41, 0x31, 0x0b, 0x30, 0x09, \
- 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
- 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
- 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, \
- 0x03, 0x0c, 0x16, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, \
- 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, \
- 0x32, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
- 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, \
- 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, 0xae, 0xb1, 0x73, 0xdf, 0xd3, 0xac, \
- 0xbb, 0x93, 0xb8, 0x81, 0xff, 0x12, 0xae, 0xee, 0xe6, 0x53, 0xac, 0xce, \
- 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, 0xe3, 0x63, 0x25, 0x0b, 0xdf, \
- 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, 0xc0, 0xd5, 0x18, 0x14, 0x70, \
- 0xe5, 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, \
- 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, 0xc7, 0xa3, 0x4d, 0x30, 0x4b, \
- 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, \
- 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x7a, 0x00, \
- 0x5f, 0x86, 0x64, 0xfc, 0xe0, 0x5d, 0xe5, 0x11, 0x10, 0x3b, 0xb2, 0xe6, \
- 0x3b, 0xc4, 0x26, 0x3f, 0xcf, 0xe2, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, \
- 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, \
- 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, \
- 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
- 0x04, 0x03, 0x02, 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, \
- 0x00, 0xca, 0xa6, 0x7b, 0x80, 0xca, 0x32, 0x57, 0x54, 0x96, 0x99, 0x43, \
- 0x11, 0x3f, 0x50, 0xe8, 0x4a, 0x6d, 0xad, 0xee, 0xee, 0x51, 0x62, 0xa1, \
- 0xb0, 0xb3, 0x85, 0xfb, 0x33, 0xe4, 0x28, 0x39, 0x5f, 0xce, 0x92, 0x24, \
- 0x25, 0x81, 0x05, 0x81, 0xc9, 0x68, 0x0c, 0x71, 0x98, 0xc3, 0xcd, 0x2e, \
- 0x22, 0x02, 0x30, 0x35, 0xfb, 0x72, 0x3d, 0x7b, 0x1a, 0x6d, 0x3a, 0x8c, \
- 0x33, 0xb8, 0x84, 0x1e, 0x05, 0x69, 0x5f, 0xf1, 0x91, 0xa3, 0x32, 0xa4, \
- 0x95, 0x8f, 0x72, 0x40, 0x8f, 0xf9, 0x7a, 0x80, 0x3a, 0x80, 0x65, 0xbb, \
- 0x63, 0xe8, 0xa6, 0xb8, 0x64, 0x7f, 0xa1, 0xaa, 0x39, 0xc9, 0x23, 0x9b, \
- 0x6b, 0xd5, 0x64 \
+ 0x30, 0x82, 0x01, 0xdf, 0x30, 0x82, 0x01, 0x63, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x0d, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
+ 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, \
+ 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
+ 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
+ 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, \
+ 0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, \
+ 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, \
+ 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, \
+ 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \
+ 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x30, 0x41, 0x31, 0x0b, 0x30, 0x09, \
+ 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
+ 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
+ 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, \
+ 0x03, 0x0c, 0x16, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, \
+ 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, \
+ 0x32, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
+ 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, \
+ 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, 0xae, 0xb1, 0x73, 0xdf, 0xd3, 0xac, \
+ 0xbb, 0x93, 0xb8, 0x81, 0xff, 0x12, 0xae, 0xee, 0xe6, 0x53, 0xac, 0xce, \
+ 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, 0xe3, 0x63, 0x25, 0x0b, 0xdf, \
+ 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, 0xc0, 0xd5, 0x18, 0x14, 0x70, \
+ 0xe5, 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, \
+ 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, 0xc7, 0xa3, 0x4d, 0x30, 0x4b, \
+ 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, \
+ 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x7a, 0x00, \
+ 0x5f, 0x86, 0x64, 0xfc, 0xe0, 0x5d, 0xe5, 0x11, 0x10, 0x3b, 0xb2, 0xe6, \
+ 0x3b, 0xc4, 0x26, 0x3f, 0xcf, 0xe2, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, \
+ 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, \
+ 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, \
+ 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
+ 0x04, 0x03, 0x02, 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, \
+ 0x00, 0xca, 0xa6, 0x7b, 0x80, 0xca, 0x32, 0x57, 0x54, 0x96, 0x99, 0x43, \
+ 0x11, 0x3f, 0x50, 0xe8, 0x4a, 0x6d, 0xad, 0xee, 0xee, 0x51, 0x62, 0xa1, \
+ 0xb0, 0xb3, 0x85, 0xfb, 0x33, 0xe4, 0x28, 0x39, 0x5f, 0xce, 0x92, 0x24, \
+ 0x25, 0x81, 0x05, 0x81, 0xc9, 0x68, 0x0c, 0x71, 0x98, 0xc3, 0xcd, 0x2e, \
+ 0x22, 0x02, 0x30, 0x35, 0xfb, 0x72, 0x3d, 0x7b, 0x1a, 0x6d, 0x3a, 0x8c, \
+ 0x33, 0xb8, 0x84, 0x1e, 0x05, 0x69, 0x5f, 0xf1, 0x91, 0xa3, 0x32, 0xa4, \
+ 0x95, 0x8f, 0x72, 0x40, 0x8f, 0xf9, 0x7a, 0x80, 0x3a, 0x80, 0x65, 0xbb, \
+ 0x63, 0xe8, 0xa6, 0xb8, 0x64, 0x7f, 0xa1, 0xaa, 0x39, 0xc9, 0x23, 0x9b, \
+ 0x6b, 0xd5, 0x64 \
}
/* END FILE */
@@ -1028,17 +1028,17 @@
/* This is generated from tests/data_files/cli2.key.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_CLI_KEY_EC_DER tests/data_files/cli2.key.der */
#define TEST_CLI_KEY_EC_DER { \
- 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf6, 0xf7, 0x86, 0x64, 0xf1, \
- 0x67, 0x7f, 0xe6, 0x64, 0x8d, 0xef, 0xca, 0x4e, 0xe9, 0xdd, 0x4d, 0xf0, \
- 0x05, 0xff, 0x96, 0x22, 0x8a, 0x7a, 0x84, 0x38, 0x64, 0x17, 0x32, 0x61, \
- 0x98, 0xb7, 0x2a, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
- 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, 0xae, \
- 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, 0xb8, 0x81, 0xff, 0x12, 0xae, \
- 0xee, 0xe6, 0x53, 0xac, 0xce, 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, \
- 0xe3, 0x63, 0x25, 0x0b, 0xdf, 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, \
- 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, \
- 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, \
- 0xc7 \
+ 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf6, 0xf7, 0x86, 0x64, 0xf1, \
+ 0x67, 0x7f, 0xe6, 0x64, 0x8d, 0xef, 0xca, 0x4e, 0xe9, 0xdd, 0x4d, 0xf0, \
+ 0x05, 0xff, 0x96, 0x22, 0x8a, 0x7a, 0x84, 0x38, 0x64, 0x17, 0x32, 0x61, \
+ 0x98, 0xb7, 0x2a, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \
+ 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, 0xae, \
+ 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, 0xb8, 0x81, 0xff, 0x12, 0xae, \
+ 0xee, 0xe6, 0x53, 0xac, 0xce, 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, \
+ 0xe3, 0x63, 0x25, 0x0b, 0xdf, 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, \
+ 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, \
+ 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, \
+ 0xc7 \
}
/* END FILE */
@@ -1071,76 +1071,76 @@
using `xxd -i.` */
/* BEGIN FILE binary macro TEST_CLI_CRT_RSA_DER tests/data_files/cli-rsa-sha256.crt.der */
#define TEST_CLI_CRT_RSA_DER { \
- 0x30, 0x82, 0x03, 0x3f, 0x30, 0x82, 0x02, 0x27, 0xa0, 0x03, 0x02, 0x01, \
- 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
- 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
- 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
- 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
- 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
- 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
- 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
- 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
- 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \
- 0x34, 0x30, 0x36, 0x5a, 0x30, 0x3c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
- 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
- 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
- 0x53, 0x4c, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
- 0x11, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x43, 0x6c, \
- 0x69, 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, \
- 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, \
- 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, \
- 0x01, 0x01, 0x00, 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, \
- 0x45, 0xd9, 0x14, 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, \
- 0x33, 0xad, 0x0d, 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, \
- 0xcc, 0x66, 0x85, 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, \
- 0x9e, 0x0a, 0x6e, 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, \
- 0x93, 0x86, 0x49, 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, \
- 0xd4, 0x2f, 0x77, 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, \
- 0x48, 0x70, 0xf5, 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, 0x1a, 0xed, \
- 0xe6, 0x43, 0xea, 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, \
- 0x57, 0x4e, 0xa9, 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, \
- 0x32, 0x30, 0xd5, 0xd3, 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, \
- 0x5f, 0xf9, 0x3d, 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, \
- 0xfb, 0xe5, 0x0c, 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, \
- 0x7f, 0xca, 0xad, 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, \
- 0xe0, 0x9b, 0xf8, 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, \
- 0x04, 0x66, 0xc7, 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, \
- 0x06, 0x67, 0xf4, 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, \
- 0x3c, 0x8b, 0x35, 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, \
- 0xfc, 0x36, 0x6b, 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, \
- 0x00, 0xcf, 0xaf, 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, \
- 0xe7, 0x50, 0x71, 0xe6, 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, \
- 0xe4, 0xc4, 0xfd, 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, \
- 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, \
- 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, \
- 0x04, 0x14, 0x71, 0xa1, 0x00, 0x73, 0x72, 0x40, 0x2f, 0x54, 0x76, 0x5e, \
- 0x33, 0xfc, 0x52, 0x8f, 0xbc, 0xf1, 0xdd, 0x6b, 0x46, 0x21, 0x30, 0x1f, \
- 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, \
- 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, \
- 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, \
- 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, \
- 0x01, 0x01, 0x00, 0x5e, 0x27, 0x6f, 0xd5, 0xde, 0x29, 0x2e, 0x50, 0x62, \
- 0x29, 0x61, 0x03, 0xf7, 0x9a, 0xcc, 0xc9, 0xc0, 0x5d, 0x80, 0x37, 0x20, \
- 0xc8, 0xda, 0x89, 0xc5, 0xa9, 0x05, 0x91, 0x17, 0xd1, 0xc8, 0x0d, 0xb2, \
- 0xd6, 0x69, 0x72, 0x4e, 0x7e, 0xee, 0x05, 0x74, 0x64, 0x34, 0xb6, 0x39, \
- 0x64, 0x5c, 0xca, 0xf3, 0x61, 0x82, 0x8e, 0x4d, 0x90, 0xd8, 0xe0, 0xf8, \
- 0x45, 0x94, 0x82, 0x3c, 0x02, 0x49, 0xa8, 0xba, 0x47, 0x1d, 0x4d, 0xf8, \
- 0xb7, 0xbd, 0x5c, 0x89, 0xf7, 0xef, 0xcb, 0x62, 0x8a, 0xf3, 0x56, 0x2f, \
- 0xaf, 0x17, 0x33, 0x46, 0x13, 0x00, 0x13, 0xae, 0x22, 0xfa, 0xa9, 0xda, \
- 0xc8, 0xfd, 0xd3, 0x77, 0x65, 0xee, 0x58, 0x94, 0x74, 0xe4, 0xf5, 0x4f, \
- 0xa1, 0x27, 0xa6, 0xb0, 0xd1, 0x0b, 0xb3, 0xd8, 0x16, 0xb6, 0xd7, 0x67, \
- 0x63, 0x2d, 0xdc, 0x7b, 0xe1, 0x18, 0xd9, 0x8d, 0x27, 0xed, 0x1b, 0x22, \
- 0xef, 0xdf, 0x36, 0x11, 0xe2, 0xc8, 0x00, 0x0e, 0xc7, 0xe9, 0xc6, 0xb8, \
- 0xd8, 0x4b, 0x3f, 0x35, 0x41, 0xff, 0xfc, 0x96, 0x49, 0x4f, 0x7d, 0x8e, \
- 0x3f, 0x47, 0x68, 0x33, 0x17, 0x83, 0x44, 0x0f, 0xaf, 0xa6, 0x59, 0x0a, \
- 0xa9, 0x32, 0xcb, 0x59, 0xfe, 0xdd, 0x5f, 0x6e, 0x8b, 0x22, 0xb8, 0x81, \
- 0x90, 0x16, 0x91, 0x0a, 0x04, 0x79, 0x62, 0xff, 0x4b, 0x04, 0xf1, 0x5c, \
- 0x34, 0xeb, 0x69, 0xce, 0xef, 0xcb, 0x6e, 0xb6, 0x3b, 0x40, 0x55, 0xca, \
- 0x24, 0xc2, 0x3e, 0x25, 0x70, 0xee, 0x74, 0x2b, 0x0e, 0x9f, 0xc2, 0x82, \
- 0x9a, 0x20, 0x38, 0x77, 0xa1, 0x26, 0x8a, 0xca, 0x9f, 0x87, 0x75, 0x77, \
- 0xe3, 0xce, 0x65, 0xec, 0x71, 0x10, 0x35, 0xcb, 0xcb, 0x4f, 0x19, 0x43, \
- 0xeb, 0x30, 0xd0, 0xca, 0x2d, 0x3f, 0xca, 0x46, 0x14, 0x61, 0x99, 0x30, \
- 0x41, 0x32, 0xb5, 0x37, 0x63, 0x6f, 0x97 \
+ 0x30, 0x82, 0x03, 0x3f, 0x30, 0x82, 0x02, 0x27, 0xa0, 0x03, 0x02, 0x01, \
+ 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, \
+ 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, \
+ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \
+ 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \
+ 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, \
+ 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \
+ 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
+ 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, \
+ 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \
+ 0x34, 0x30, 0x36, 0x5a, 0x30, 0x3c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
+ 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
+ 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
+ 0x53, 0x4c, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
+ 0x11, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x43, 0x6c, \
+ 0x69, 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, \
+ 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, \
+ 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, \
+ 0x01, 0x01, 0x00, 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, \
+ 0x45, 0xd9, 0x14, 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, \
+ 0x33, 0xad, 0x0d, 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, \
+ 0xcc, 0x66, 0x85, 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, \
+ 0x9e, 0x0a, 0x6e, 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, \
+ 0x93, 0x86, 0x49, 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, \
+ 0xd4, 0x2f, 0x77, 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, \
+ 0x48, 0x70, 0xf5, 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, 0x1a, 0xed, \
+ 0xe6, 0x43, 0xea, 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, \
+ 0x57, 0x4e, 0xa9, 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, \
+ 0x32, 0x30, 0xd5, 0xd3, 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, \
+ 0x5f, 0xf9, 0x3d, 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, \
+ 0xfb, 0xe5, 0x0c, 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, \
+ 0x7f, 0xca, 0xad, 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, \
+ 0xe0, 0x9b, 0xf8, 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, \
+ 0x04, 0x66, 0xc7, 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, \
+ 0x06, 0x67, 0xf4, 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, \
+ 0x3c, 0x8b, 0x35, 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, \
+ 0xfc, 0x36, 0x6b, 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, \
+ 0x00, 0xcf, 0xaf, 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, \
+ 0xe7, 0x50, 0x71, 0xe6, 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, \
+ 0xe4, 0xc4, 0xfd, 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, \
+ 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, \
+ 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, \
+ 0x04, 0x14, 0x71, 0xa1, 0x00, 0x73, 0x72, 0x40, 0x2f, 0x54, 0x76, 0x5e, \
+ 0x33, 0xfc, 0x52, 0x8f, 0xbc, 0xf1, 0xdd, 0x6b, 0x46, 0x21, 0x30, 0x1f, \
+ 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, \
+ 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, \
+ 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, \
+ 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, \
+ 0x01, 0x01, 0x00, 0x5e, 0x27, 0x6f, 0xd5, 0xde, 0x29, 0x2e, 0x50, 0x62, \
+ 0x29, 0x61, 0x03, 0xf7, 0x9a, 0xcc, 0xc9, 0xc0, 0x5d, 0x80, 0x37, 0x20, \
+ 0xc8, 0xda, 0x89, 0xc5, 0xa9, 0x05, 0x91, 0x17, 0xd1, 0xc8, 0x0d, 0xb2, \
+ 0xd6, 0x69, 0x72, 0x4e, 0x7e, 0xee, 0x05, 0x74, 0x64, 0x34, 0xb6, 0x39, \
+ 0x64, 0x5c, 0xca, 0xf3, 0x61, 0x82, 0x8e, 0x4d, 0x90, 0xd8, 0xe0, 0xf8, \
+ 0x45, 0x94, 0x82, 0x3c, 0x02, 0x49, 0xa8, 0xba, 0x47, 0x1d, 0x4d, 0xf8, \
+ 0xb7, 0xbd, 0x5c, 0x89, 0xf7, 0xef, 0xcb, 0x62, 0x8a, 0xf3, 0x56, 0x2f, \
+ 0xaf, 0x17, 0x33, 0x46, 0x13, 0x00, 0x13, 0xae, 0x22, 0xfa, 0xa9, 0xda, \
+ 0xc8, 0xfd, 0xd3, 0x77, 0x65, 0xee, 0x58, 0x94, 0x74, 0xe4, 0xf5, 0x4f, \
+ 0xa1, 0x27, 0xa6, 0xb0, 0xd1, 0x0b, 0xb3, 0xd8, 0x16, 0xb6, 0xd7, 0x67, \
+ 0x63, 0x2d, 0xdc, 0x7b, 0xe1, 0x18, 0xd9, 0x8d, 0x27, 0xed, 0x1b, 0x22, \
+ 0xef, 0xdf, 0x36, 0x11, 0xe2, 0xc8, 0x00, 0x0e, 0xc7, 0xe9, 0xc6, 0xb8, \
+ 0xd8, 0x4b, 0x3f, 0x35, 0x41, 0xff, 0xfc, 0x96, 0x49, 0x4f, 0x7d, 0x8e, \
+ 0x3f, 0x47, 0x68, 0x33, 0x17, 0x83, 0x44, 0x0f, 0xaf, 0xa6, 0x59, 0x0a, \
+ 0xa9, 0x32, 0xcb, 0x59, 0xfe, 0xdd, 0x5f, 0x6e, 0x8b, 0x22, 0xb8, 0x81, \
+ 0x90, 0x16, 0x91, 0x0a, 0x04, 0x79, 0x62, 0xff, 0x4b, 0x04, 0xf1, 0x5c, \
+ 0x34, 0xeb, 0x69, 0xce, 0xef, 0xcb, 0x6e, 0xb6, 0x3b, 0x40, 0x55, 0xca, \
+ 0x24, 0xc2, 0x3e, 0x25, 0x70, 0xee, 0x74, 0x2b, 0x0e, 0x9f, 0xc2, 0x82, \
+ 0x9a, 0x20, 0x38, 0x77, 0xa1, 0x26, 0x8a, 0xca, 0x9f, 0x87, 0x75, 0x77, \
+ 0xe3, 0xce, 0x65, 0xec, 0x71, 0x10, 0x35, 0xcb, 0xcb, 0x4f, 0x19, 0x43, \
+ 0xeb, 0x30, 0xd0, 0xca, 0x2d, 0x3f, 0xca, 0x46, 0x14, 0x61, 0x99, 0x30, \
+ 0x41, 0x32, 0xb5, 0x37, 0x63, 0x6f, 0x97 \
}
/* END FILE */
@@ -1178,106 +1178,106 @@
/* This was generated from tests/data_files/cli-rsa.key.der using `xxd -i`. */
/* BEGIN FILE binary macro TEST_CLI_KEY_RSA_DER tests/data_files/cli-rsa.key.der */
#define TEST_CLI_KEY_RSA_DER { \
- 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
- 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, 0x45, 0xd9, 0x14, \
- 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, 0x33, 0xad, 0x0d, \
- 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, 0xcc, 0x66, 0x85, \
- 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, 0x9e, 0x0a, 0x6e, \
- 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, 0x93, 0x86, 0x49, \
- 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, 0xd4, 0x2f, 0x77, \
- 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, 0x48, 0x70, 0xf5, \
- 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, 0x1a, 0xed, 0xe6, 0x43, 0xea, \
- 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, 0x57, 0x4e, 0xa9, \
- 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, 0x32, 0x30, 0xd5, \
- 0xd3, 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, 0x5f, 0xf9, 0x3d, \
- 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, 0xfb, 0xe5, 0x0c, \
- 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, 0x7f, 0xca, 0xad, \
- 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, 0xe0, 0x9b, 0xf8, \
- 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, 0x04, 0x66, 0xc7, \
- 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, 0x06, 0x67, 0xf4, \
- 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, 0x3c, 0x8b, 0x35, \
- 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, 0xfc, 0x36, 0x6b, \
- 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, 0x00, 0xcf, 0xaf, \
- 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, 0xe7, 0x50, 0x71, \
- 0xe6, 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, 0xe4, 0xc4, 0xfd, \
- 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
- 0x00, 0x67, 0x4d, 0xb5, 0xf6, 0x03, 0x89, 0xaa, 0x7a, 0x6f, 0x3b, 0x2d, \
- 0xca, 0x10, 0xa2, 0x23, 0xc9, 0xbd, 0x4e, 0xda, 0xe1, 0x67, 0x0e, 0x0c, \
- 0x8a, 0xc6, 0x84, 0x68, 0xdf, 0xe5, 0x97, 0x75, 0xd2, 0x8d, 0xa3, 0x86, \
- 0xd9, 0xdb, 0xd5, 0xeb, 0x13, 0x19, 0x08, 0xc5, 0x7e, 0xe5, 0x37, 0x97, \
- 0x0c, 0x73, 0x80, 0x66, 0x76, 0x35, 0xf1, 0x88, 0xb5, 0xf2, 0xfc, 0xf3, \
- 0xe1, 0x4b, 0x76, 0x4e, 0x73, 0x45, 0xce, 0x2c, 0xc2, 0x10, 0x26, 0x0d, \
- 0x68, 0x0d, 0x9f, 0x49, 0x3d, 0xd6, 0x80, 0x89, 0xe7, 0xc5, 0x49, 0x15, \
- 0xdd, 0x85, 0xc0, 0xc8, 0xfe, 0x82, 0x37, 0x12, 0x5a, 0x0a, 0x6b, 0xf6, \
- 0x68, 0x0d, 0x32, 0x16, 0xbd, 0xa4, 0x15, 0x54, 0x9e, 0x68, 0xa1, 0xad, \
- 0xca, 0x6b, 0xe5, 0x8c, 0xda, 0x76, 0x35, 0x59, 0x2f, 0x9b, 0xb4, 0xe1, \
- 0xf1, 0xf0, 0x50, 0x04, 0xee, 0xc8, 0xec, 0x05, 0xe1, 0xcf, 0x8d, 0xe4, \
- 0xd2, 0x64, 0x7b, 0x5e, 0x63, 0xe0, 0x7b, 0x07, 0xbc, 0x02, 0x96, 0x4e, \
- 0x1b, 0x78, 0x6c, 0xb6, 0x43, 0x9a, 0x32, 0xf6, 0xd6, 0x02, 0xf5, 0x80, \
- 0xcc, 0x26, 0x6e, 0xa5, 0xd0, 0xe3, 0x65, 0x88, 0xce, 0x26, 0xa9, 0x40, \
- 0xe1, 0xe1, 0x00, 0xe0, 0x7f, 0x3f, 0xc3, 0xb1, 0x7c, 0xde, 0xbe, 0x42, \
- 0xba, 0x07, 0x81, 0x13, 0xc2, 0xe0, 0x11, 0x11, 0x23, 0x2c, 0xf8, 0xb2, \
- 0x7a, 0x3a, 0xd4, 0xe4, 0x7d, 0x5f, 0xb9, 0xb1, 0x18, 0xfa, 0x1d, 0x1d, \
- 0x97, 0x91, 0xd9, 0x04, 0x9e, 0xbc, 0xc9, 0xb4, 0xd7, 0x7d, 0x0e, 0x54, \
- 0xf6, 0x8f, 0xd0, 0x28, 0x0d, 0xdd, 0x77, 0x4b, 0x68, 0x04, 0x48, 0x61, \
- 0x75, 0x15, 0x03, 0x1b, 0x35, 0xad, 0x8e, 0xfc, 0x24, 0x11, 0x07, 0xea, \
- 0x17, 0x5a, 0xde, 0x19, 0x68, 0xff, 0xb6, 0x87, 0x7f, 0x80, 0x2a, 0x5f, \
- 0x0c, 0x58, 0xba, 0x5f, 0x41, 0x02, 0x81, 0x81, 0x00, 0xe3, 0x03, 0xaf, \
- 0xfe, 0x98, 0xd2, 0x0b, 0x7b, 0x72, 0xe9, 0x3b, 0x8e, 0xbc, 0xa5, 0xf6, \
- 0xac, 0xe5, 0x22, 0x06, 0xb2, 0xd7, 0x5e, 0xfd, 0x89, 0x4b, 0x16, 0x67, \
- 0x32, 0x83, 0x22, 0x58, 0x8e, 0x62, 0xa4, 0xb4, 0x2d, 0xf9, 0x16, 0x13, \
- 0x54, 0xf6, 0x9f, 0x2f, 0xf9, 0xbb, 0x0e, 0x7e, 0x8c, 0x6f, 0x08, 0xda, \
- 0xc8, 0xe9, 0x1c, 0x66, 0x10, 0x70, 0x93, 0x90, 0x8d, 0xcf, 0x90, 0x3a, \
- 0x43, 0x89, 0x49, 0xeb, 0x83, 0x2a, 0xfe, 0x5a, 0x87, 0xce, 0x74, 0x42, \
- 0x41, 0x0d, 0x8c, 0x73, 0x51, 0xbc, 0x7b, 0x20, 0xc5, 0xfd, 0xf6, 0x0b, \
- 0x65, 0xed, 0xa9, 0x2e, 0xfc, 0x0f, 0xf5, 0x50, 0xf9, 0x8d, 0x37, 0x36, \
- 0x9a, 0x20, 0xdf, 0xc3, 0xe3, 0x27, 0xbc, 0x98, 0x72, 0xc1, 0x14, 0x4b, \
- 0x71, 0xe9, 0x83, 0x14, 0xff, 0x24, 0xe2, 0x14, 0x15, 0xb6, 0x6f, 0x0f, \
- 0x32, 0x9d, 0xd9, 0x98, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x0c, 0xfb, \
- 0xc3, 0x33, 0x9b, 0x47, 0x88, 0x27, 0xf2, 0x26, 0xde, 0xeb, 0x5e, 0xee, \
- 0x40, 0xf6, 0x63, 0x5b, 0x35, 0x23, 0xf5, 0xd5, 0x07, 0x61, 0xdf, 0xa2, \
- 0x9f, 0x58, 0x30, 0x04, 0x22, 0x2b, 0xb4, 0xd9, 0xda, 0x46, 0x7f, 0x48, \
- 0xf5, 0x4f, 0xd0, 0xea, 0xd7, 0xa0, 0x45, 0x8a, 0x62, 0x8b, 0x8c, 0xac, \
- 0x73, 0x5e, 0xfa, 0x36, 0x65, 0x3e, 0xba, 0x6c, 0xba, 0x5e, 0x6b, 0x92, \
- 0x29, 0x5e, 0x6a, 0x0f, 0xd6, 0xd2, 0xa5, 0x95, 0x86, 0xda, 0x72, 0xc5, \
- 0x9e, 0xc9, 0x6b, 0x37, 0x5e, 0x4b, 0x9b, 0x77, 0xe1, 0x67, 0x1a, 0x1e, \
- 0x30, 0xd8, 0x41, 0x68, 0x40, 0xd3, 0x9c, 0xb4, 0xf6, 0xeb, 0x2a, 0x22, \
- 0xdf, 0x78, 0x29, 0xd2, 0x64, 0x92, 0x5b, 0x2f, 0x78, 0x64, 0x4a, 0xa2, \
- 0xa6, 0x6b, 0x3e, 0x50, 0xb1, 0x7a, 0xb1, 0x8d, 0x59, 0xb4, 0x55, 0xba, \
- 0xb6, 0x91, 0x85, 0xa3, 0x2f, 0x02, 0x81, 0x80, 0x10, 0x1e, 0x19, 0xe7, \
- 0xbc, 0x97, 0xe5, 0x22, 0xcd, 0xa4, 0xcb, 0x8a, 0xb5, 0xd0, 0x1e, 0xb4, \
- 0x65, 0xcc, 0x45, 0xa7, 0x7a, 0xed, 0x0e, 0x99, 0x29, 0xd0, 0x9c, 0x61, \
- 0x14, 0xb8, 0x62, 0x8b, 0x31, 0x6b, 0xba, 0x33, 0x2d, 0x65, 0x28, 0xd8, \
- 0x36, 0x6e, 0x54, 0xec, 0xa9, 0x20, 0x3d, 0x51, 0xe1, 0x2c, 0x42, 0xc4, \
- 0x52, 0xf0, 0xa6, 0x3a, 0x72, 0x93, 0xb7, 0x86, 0xa9, 0xfe, 0xf6, 0x74, \
- 0x07, 0x12, 0x4d, 0x7b, 0x51, 0x99, 0x1f, 0x7a, 0x56, 0xe9, 0x20, 0x2f, \
- 0x18, 0x34, 0x29, 0x97, 0xdb, 0x06, 0xee, 0xeb, 0xbf, 0xbd, 0x31, 0x4f, \
- 0xfa, 0x50, 0xb1, 0xba, 0x49, 0xb3, 0xc4, 0x1d, 0x03, 0xae, 0xb0, 0xdc, \
- 0xbe, 0x8a, 0xc4, 0x90, 0xa3, 0x28, 0x9b, 0xb6, 0x42, 0x09, 0x1b, 0xd6, \
- 0x29, 0x9b, 0x19, 0xe9, 0x87, 0x87, 0xd9, 0x9f, 0x35, 0x05, 0xab, 0x91, \
- 0x8f, 0x6d, 0x7c, 0x91, 0x02, 0x81, 0x81, 0x00, 0x94, 0x57, 0xf0, 0xe0, \
- 0x28, 0xfd, 0xbd, 0xf3, 0x9c, 0x43, 0x4d, 0x3e, 0xfd, 0x37, 0x4f, 0x23, \
- 0x52, 0x8d, 0xe1, 0x4c, 0xfe, 0x4c, 0x55, 0x80, 0x82, 0xba, 0x3f, 0xfe, \
- 0x51, 0xe1, 0x30, 0xd5, 0x3b, 0xd9, 0x73, 0x1d, 0xcb, 0x25, 0xbc, 0xbb, \
- 0x3f, 0xa5, 0xda, 0x77, 0xa6, 0xb5, 0xfc, 0x1a, 0xaf, 0x79, 0xa1, 0xb2, \
- 0x14, 0xa2, 0x1f, 0x10, 0x52, 0x1a, 0x05, 0x40, 0x48, 0xb6, 0x4f, 0x34, \
- 0xd6, 0xc0, 0xc3, 0xa4, 0x36, 0x98, 0x73, 0x88, 0x0b, 0xd3, 0x45, 0xdc, \
- 0xee, 0x51, 0x6e, 0x04, 0x73, 0x99, 0x93, 0x12, 0x58, 0x96, 0xcb, 0x39, \
- 0x42, 0xb1, 0xa9, 0xb8, 0xe1, 0x25, 0xf5, 0x9c, 0x14, 0xb7, 0x92, 0x2b, \
- 0x14, 0xb0, 0x5d, 0x61, 0xa2, 0xaa, 0x34, 0x7c, 0xcd, 0x54, 0x2d, 0x69, \
- 0x08, 0xf7, 0xdb, 0xfc, 0x9c, 0x87, 0xe8, 0x3a, 0xf6, 0x1d, 0x4c, 0x6a, \
- 0x83, 0x15, 0x30, 0x01, 0x02, 0x81, 0x81, 0x00, 0x9c, 0x53, 0xa1, 0xb6, \
- 0x2f, 0xc0, 0x06, 0xf5, 0xdf, 0x5c, 0xd1, 0x4a, 0x4e, 0xc8, 0xbd, 0x6d, \
- 0x32, 0xf1, 0x5e, 0xe5, 0x3b, 0x70, 0xd0, 0xa8, 0xe5, 0x41, 0x57, 0x6c, \
- 0x87, 0x53, 0x0f, 0xeb, 0x28, 0xa0, 0x62, 0x8f, 0x43, 0x62, 0xec, 0x2e, \
- 0x6c, 0x71, 0x55, 0x5b, 0x6a, 0xf4, 0x74, 0x14, 0xea, 0x7a, 0x03, 0xf6, \
- 0xfc, 0xa4, 0xce, 0xc4, 0xac, 0xda, 0x1d, 0xf0, 0xb5, 0xa9, 0xfd, 0x11, \
- 0x18, 0x3b, 0x14, 0xa0, 0x90, 0x8d, 0x26, 0xb7, 0x75, 0x73, 0x0a, 0x02, \
- 0x2c, 0x6f, 0x0f, 0xd8, 0x41, 0x78, 0xc3, 0x73, 0x81, 0xac, 0xaa, 0xaf, \
- 0xf2, 0xee, 0x32, 0xb5, 0x8d, 0x05, 0xf9, 0x59, 0x5a, 0x9e, 0x3e, 0x65, \
- 0x9b, 0x74, 0xda, 0xa0, 0x74, 0x95, 0x17, 0x5f, 0x8d, 0x58, 0xfc, 0x8e, \
- 0x4e, 0x2c, 0x1e, 0xbc, 0x81, 0x02, 0x18, 0xac, 0x12, 0xc6, 0xf9, 0x64, \
- 0x8b, 0x87, 0xc3, 0x00 \
+ 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, \
+ 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, 0x45, 0xd9, 0x14, \
+ 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, 0x33, 0xad, 0x0d, \
+ 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, 0xcc, 0x66, 0x85, \
+ 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, 0x9e, 0x0a, 0x6e, \
+ 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, 0x93, 0x86, 0x49, \
+ 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, 0xd4, 0x2f, 0x77, \
+ 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, 0x48, 0x70, 0xf5, \
+ 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, 0x1a, 0xed, 0xe6, 0x43, 0xea, \
+ 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, 0x57, 0x4e, 0xa9, \
+ 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, 0x32, 0x30, 0xd5, \
+ 0xd3, 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, 0x5f, 0xf9, 0x3d, \
+ 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, 0xfb, 0xe5, 0x0c, \
+ 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, 0x7f, 0xca, 0xad, \
+ 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, 0xe0, 0x9b, 0xf8, \
+ 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, 0x04, 0x66, 0xc7, \
+ 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, 0x06, 0x67, 0xf4, \
+ 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, 0x3c, 0x8b, 0x35, \
+ 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, 0xfc, 0x36, 0x6b, \
+ 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, 0x00, 0xcf, 0xaf, \
+ 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, 0xe7, 0x50, 0x71, \
+ 0xe6, 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, 0xe4, 0xc4, 0xfd, \
+ 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, \
+ 0x00, 0x67, 0x4d, 0xb5, 0xf6, 0x03, 0x89, 0xaa, 0x7a, 0x6f, 0x3b, 0x2d, \
+ 0xca, 0x10, 0xa2, 0x23, 0xc9, 0xbd, 0x4e, 0xda, 0xe1, 0x67, 0x0e, 0x0c, \
+ 0x8a, 0xc6, 0x84, 0x68, 0xdf, 0xe5, 0x97, 0x75, 0xd2, 0x8d, 0xa3, 0x86, \
+ 0xd9, 0xdb, 0xd5, 0xeb, 0x13, 0x19, 0x08, 0xc5, 0x7e, 0xe5, 0x37, 0x97, \
+ 0x0c, 0x73, 0x80, 0x66, 0x76, 0x35, 0xf1, 0x88, 0xb5, 0xf2, 0xfc, 0xf3, \
+ 0xe1, 0x4b, 0x76, 0x4e, 0x73, 0x45, 0xce, 0x2c, 0xc2, 0x10, 0x26, 0x0d, \
+ 0x68, 0x0d, 0x9f, 0x49, 0x3d, 0xd6, 0x80, 0x89, 0xe7, 0xc5, 0x49, 0x15, \
+ 0xdd, 0x85, 0xc0, 0xc8, 0xfe, 0x82, 0x37, 0x12, 0x5a, 0x0a, 0x6b, 0xf6, \
+ 0x68, 0x0d, 0x32, 0x16, 0xbd, 0xa4, 0x15, 0x54, 0x9e, 0x68, 0xa1, 0xad, \
+ 0xca, 0x6b, 0xe5, 0x8c, 0xda, 0x76, 0x35, 0x59, 0x2f, 0x9b, 0xb4, 0xe1, \
+ 0xf1, 0xf0, 0x50, 0x04, 0xee, 0xc8, 0xec, 0x05, 0xe1, 0xcf, 0x8d, 0xe4, \
+ 0xd2, 0x64, 0x7b, 0x5e, 0x63, 0xe0, 0x7b, 0x07, 0xbc, 0x02, 0x96, 0x4e, \
+ 0x1b, 0x78, 0x6c, 0xb6, 0x43, 0x9a, 0x32, 0xf6, 0xd6, 0x02, 0xf5, 0x80, \
+ 0xcc, 0x26, 0x6e, 0xa5, 0xd0, 0xe3, 0x65, 0x88, 0xce, 0x26, 0xa9, 0x40, \
+ 0xe1, 0xe1, 0x00, 0xe0, 0x7f, 0x3f, 0xc3, 0xb1, 0x7c, 0xde, 0xbe, 0x42, \
+ 0xba, 0x07, 0x81, 0x13, 0xc2, 0xe0, 0x11, 0x11, 0x23, 0x2c, 0xf8, 0xb2, \
+ 0x7a, 0x3a, 0xd4, 0xe4, 0x7d, 0x5f, 0xb9, 0xb1, 0x18, 0xfa, 0x1d, 0x1d, \
+ 0x97, 0x91, 0xd9, 0x04, 0x9e, 0xbc, 0xc9, 0xb4, 0xd7, 0x7d, 0x0e, 0x54, \
+ 0xf6, 0x8f, 0xd0, 0x28, 0x0d, 0xdd, 0x77, 0x4b, 0x68, 0x04, 0x48, 0x61, \
+ 0x75, 0x15, 0x03, 0x1b, 0x35, 0xad, 0x8e, 0xfc, 0x24, 0x11, 0x07, 0xea, \
+ 0x17, 0x5a, 0xde, 0x19, 0x68, 0xff, 0xb6, 0x87, 0x7f, 0x80, 0x2a, 0x5f, \
+ 0x0c, 0x58, 0xba, 0x5f, 0x41, 0x02, 0x81, 0x81, 0x00, 0xe3, 0x03, 0xaf, \
+ 0xfe, 0x98, 0xd2, 0x0b, 0x7b, 0x72, 0xe9, 0x3b, 0x8e, 0xbc, 0xa5, 0xf6, \
+ 0xac, 0xe5, 0x22, 0x06, 0xb2, 0xd7, 0x5e, 0xfd, 0x89, 0x4b, 0x16, 0x67, \
+ 0x32, 0x83, 0x22, 0x58, 0x8e, 0x62, 0xa4, 0xb4, 0x2d, 0xf9, 0x16, 0x13, \
+ 0x54, 0xf6, 0x9f, 0x2f, 0xf9, 0xbb, 0x0e, 0x7e, 0x8c, 0x6f, 0x08, 0xda, \
+ 0xc8, 0xe9, 0x1c, 0x66, 0x10, 0x70, 0x93, 0x90, 0x8d, 0xcf, 0x90, 0x3a, \
+ 0x43, 0x89, 0x49, 0xeb, 0x83, 0x2a, 0xfe, 0x5a, 0x87, 0xce, 0x74, 0x42, \
+ 0x41, 0x0d, 0x8c, 0x73, 0x51, 0xbc, 0x7b, 0x20, 0xc5, 0xfd, 0xf6, 0x0b, \
+ 0x65, 0xed, 0xa9, 0x2e, 0xfc, 0x0f, 0xf5, 0x50, 0xf9, 0x8d, 0x37, 0x36, \
+ 0x9a, 0x20, 0xdf, 0xc3, 0xe3, 0x27, 0xbc, 0x98, 0x72, 0xc1, 0x14, 0x4b, \
+ 0x71, 0xe9, 0x83, 0x14, 0xff, 0x24, 0xe2, 0x14, 0x15, 0xb6, 0x6f, 0x0f, \
+ 0x32, 0x9d, 0xd9, 0x98, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x0c, 0xfb, \
+ 0xc3, 0x33, 0x9b, 0x47, 0x88, 0x27, 0xf2, 0x26, 0xde, 0xeb, 0x5e, 0xee, \
+ 0x40, 0xf6, 0x63, 0x5b, 0x35, 0x23, 0xf5, 0xd5, 0x07, 0x61, 0xdf, 0xa2, \
+ 0x9f, 0x58, 0x30, 0x04, 0x22, 0x2b, 0xb4, 0xd9, 0xda, 0x46, 0x7f, 0x48, \
+ 0xf5, 0x4f, 0xd0, 0xea, 0xd7, 0xa0, 0x45, 0x8a, 0x62, 0x8b, 0x8c, 0xac, \
+ 0x73, 0x5e, 0xfa, 0x36, 0x65, 0x3e, 0xba, 0x6c, 0xba, 0x5e, 0x6b, 0x92, \
+ 0x29, 0x5e, 0x6a, 0x0f, 0xd6, 0xd2, 0xa5, 0x95, 0x86, 0xda, 0x72, 0xc5, \
+ 0x9e, 0xc9, 0x6b, 0x37, 0x5e, 0x4b, 0x9b, 0x77, 0xe1, 0x67, 0x1a, 0x1e, \
+ 0x30, 0xd8, 0x41, 0x68, 0x40, 0xd3, 0x9c, 0xb4, 0xf6, 0xeb, 0x2a, 0x22, \
+ 0xdf, 0x78, 0x29, 0xd2, 0x64, 0x92, 0x5b, 0x2f, 0x78, 0x64, 0x4a, 0xa2, \
+ 0xa6, 0x6b, 0x3e, 0x50, 0xb1, 0x7a, 0xb1, 0x8d, 0x59, 0xb4, 0x55, 0xba, \
+ 0xb6, 0x91, 0x85, 0xa3, 0x2f, 0x02, 0x81, 0x80, 0x10, 0x1e, 0x19, 0xe7, \
+ 0xbc, 0x97, 0xe5, 0x22, 0xcd, 0xa4, 0xcb, 0x8a, 0xb5, 0xd0, 0x1e, 0xb4, \
+ 0x65, 0xcc, 0x45, 0xa7, 0x7a, 0xed, 0x0e, 0x99, 0x29, 0xd0, 0x9c, 0x61, \
+ 0x14, 0xb8, 0x62, 0x8b, 0x31, 0x6b, 0xba, 0x33, 0x2d, 0x65, 0x28, 0xd8, \
+ 0x36, 0x6e, 0x54, 0xec, 0xa9, 0x20, 0x3d, 0x51, 0xe1, 0x2c, 0x42, 0xc4, \
+ 0x52, 0xf0, 0xa6, 0x3a, 0x72, 0x93, 0xb7, 0x86, 0xa9, 0xfe, 0xf6, 0x74, \
+ 0x07, 0x12, 0x4d, 0x7b, 0x51, 0x99, 0x1f, 0x7a, 0x56, 0xe9, 0x20, 0x2f, \
+ 0x18, 0x34, 0x29, 0x97, 0xdb, 0x06, 0xee, 0xeb, 0xbf, 0xbd, 0x31, 0x4f, \
+ 0xfa, 0x50, 0xb1, 0xba, 0x49, 0xb3, 0xc4, 0x1d, 0x03, 0xae, 0xb0, 0xdc, \
+ 0xbe, 0x8a, 0xc4, 0x90, 0xa3, 0x28, 0x9b, 0xb6, 0x42, 0x09, 0x1b, 0xd6, \
+ 0x29, 0x9b, 0x19, 0xe9, 0x87, 0x87, 0xd9, 0x9f, 0x35, 0x05, 0xab, 0x91, \
+ 0x8f, 0x6d, 0x7c, 0x91, 0x02, 0x81, 0x81, 0x00, 0x94, 0x57, 0xf0, 0xe0, \
+ 0x28, 0xfd, 0xbd, 0xf3, 0x9c, 0x43, 0x4d, 0x3e, 0xfd, 0x37, 0x4f, 0x23, \
+ 0x52, 0x8d, 0xe1, 0x4c, 0xfe, 0x4c, 0x55, 0x80, 0x82, 0xba, 0x3f, 0xfe, \
+ 0x51, 0xe1, 0x30, 0xd5, 0x3b, 0xd9, 0x73, 0x1d, 0xcb, 0x25, 0xbc, 0xbb, \
+ 0x3f, 0xa5, 0xda, 0x77, 0xa6, 0xb5, 0xfc, 0x1a, 0xaf, 0x79, 0xa1, 0xb2, \
+ 0x14, 0xa2, 0x1f, 0x10, 0x52, 0x1a, 0x05, 0x40, 0x48, 0xb6, 0x4f, 0x34, \
+ 0xd6, 0xc0, 0xc3, 0xa4, 0x36, 0x98, 0x73, 0x88, 0x0b, 0xd3, 0x45, 0xdc, \
+ 0xee, 0x51, 0x6e, 0x04, 0x73, 0x99, 0x93, 0x12, 0x58, 0x96, 0xcb, 0x39, \
+ 0x42, 0xb1, 0xa9, 0xb8, 0xe1, 0x25, 0xf5, 0x9c, 0x14, 0xb7, 0x92, 0x2b, \
+ 0x14, 0xb0, 0x5d, 0x61, 0xa2, 0xaa, 0x34, 0x7c, 0xcd, 0x54, 0x2d, 0x69, \
+ 0x08, 0xf7, 0xdb, 0xfc, 0x9c, 0x87, 0xe8, 0x3a, 0xf6, 0x1d, 0x4c, 0x6a, \
+ 0x83, 0x15, 0x30, 0x01, 0x02, 0x81, 0x81, 0x00, 0x9c, 0x53, 0xa1, 0xb6, \
+ 0x2f, 0xc0, 0x06, 0xf5, 0xdf, 0x5c, 0xd1, 0x4a, 0x4e, 0xc8, 0xbd, 0x6d, \
+ 0x32, 0xf1, 0x5e, 0xe5, 0x3b, 0x70, 0xd0, 0xa8, 0xe5, 0x41, 0x57, 0x6c, \
+ 0x87, 0x53, 0x0f, 0xeb, 0x28, 0xa0, 0x62, 0x8f, 0x43, 0x62, 0xec, 0x2e, \
+ 0x6c, 0x71, 0x55, 0x5b, 0x6a, 0xf4, 0x74, 0x14, 0xea, 0x7a, 0x03, 0xf6, \
+ 0xfc, 0xa4, 0xce, 0xc4, 0xac, 0xda, 0x1d, 0xf0, 0xb5, 0xa9, 0xfd, 0x11, \
+ 0x18, 0x3b, 0x14, 0xa0, 0x90, 0x8d, 0x26, 0xb7, 0x75, 0x73, 0x0a, 0x02, \
+ 0x2c, 0x6f, 0x0f, 0xd8, 0x41, 0x78, 0xc3, 0x73, 0x81, 0xac, 0xaa, 0xaf, \
+ 0xf2, 0xee, 0x32, 0xb5, 0x8d, 0x05, 0xf9, 0x59, 0x5a, 0x9e, 0x3e, 0x65, \
+ 0x9b, 0x74, 0xda, 0xa0, 0x74, 0x95, 0x17, 0x5f, 0x8d, 0x58, 0xfc, 0x8e, \
+ 0x4e, 0x2c, 0x1e, 0xbc, 0x81, 0x02, 0x18, 0xac, 0x12, 0xc6, 0xf9, 0x64, \
+ 0x8b, 0x87, 0xc3, 0x00 \
}
/* END FILE */
@@ -1308,32 +1308,32 @@
TEST_CA_CRT_RSA_SHA256_DER;
const size_t mbedtls_test_ca_crt_ec_pem_len =
- sizeof( mbedtls_test_ca_crt_ec_pem );
+ sizeof(mbedtls_test_ca_crt_ec_pem);
const size_t mbedtls_test_ca_key_ec_pem_len =
- sizeof( mbedtls_test_ca_key_ec_pem );
+ sizeof(mbedtls_test_ca_key_ec_pem);
const size_t mbedtls_test_ca_pwd_ec_pem_len =
- sizeof( mbedtls_test_ca_pwd_ec_pem ) - 1;
+ sizeof(mbedtls_test_ca_pwd_ec_pem) - 1;
const size_t mbedtls_test_ca_key_rsa_pem_len =
- sizeof( mbedtls_test_ca_key_rsa_pem );
+ sizeof(mbedtls_test_ca_key_rsa_pem);
const size_t mbedtls_test_ca_pwd_rsa_pem_len =
- sizeof( mbedtls_test_ca_pwd_rsa_pem ) - 1;
+ sizeof(mbedtls_test_ca_pwd_rsa_pem) - 1;
const size_t mbedtls_test_ca_crt_rsa_sha1_pem_len =
- sizeof( mbedtls_test_ca_crt_rsa_sha1_pem );
+ sizeof(mbedtls_test_ca_crt_rsa_sha1_pem);
const size_t mbedtls_test_ca_crt_rsa_sha256_pem_len =
- sizeof( mbedtls_test_ca_crt_rsa_sha256_pem );
+ sizeof(mbedtls_test_ca_crt_rsa_sha256_pem);
const size_t mbedtls_test_ca_crt_ec_der_len =
- sizeof( mbedtls_test_ca_crt_ec_der );
+ sizeof(mbedtls_test_ca_crt_ec_der);
const size_t mbedtls_test_ca_key_ec_der_len =
- sizeof( mbedtls_test_ca_key_ec_der );
+ sizeof(mbedtls_test_ca_key_ec_der);
const size_t mbedtls_test_ca_pwd_ec_der_len = 0;
const size_t mbedtls_test_ca_key_rsa_der_len =
- sizeof( mbedtls_test_ca_key_rsa_der );
+ sizeof(mbedtls_test_ca_key_rsa_der);
const size_t mbedtls_test_ca_pwd_rsa_der_len = 0;
const size_t mbedtls_test_ca_crt_rsa_sha1_der_len =
- sizeof( mbedtls_test_ca_crt_rsa_sha1_der );
+ sizeof(mbedtls_test_ca_crt_rsa_sha1_der);
const size_t mbedtls_test_ca_crt_rsa_sha256_der_len =
- sizeof( mbedtls_test_ca_crt_rsa_sha256_der );
+ sizeof(mbedtls_test_ca_crt_rsa_sha256_der);
/*
* Server
@@ -1356,32 +1356,32 @@
TEST_SRV_CRT_RSA_SHA256_DER;
const size_t mbedtls_test_srv_crt_ec_pem_len =
- sizeof( mbedtls_test_srv_crt_ec_pem );
+ sizeof(mbedtls_test_srv_crt_ec_pem);
const size_t mbedtls_test_srv_key_ec_pem_len =
- sizeof( mbedtls_test_srv_key_ec_pem );
+ sizeof(mbedtls_test_srv_key_ec_pem);
const size_t mbedtls_test_srv_pwd_ec_pem_len =
- sizeof( mbedtls_test_srv_pwd_ec_pem ) - 1;
+ sizeof(mbedtls_test_srv_pwd_ec_pem) - 1;
const size_t mbedtls_test_srv_key_rsa_pem_len =
- sizeof( mbedtls_test_srv_key_rsa_pem );
+ sizeof(mbedtls_test_srv_key_rsa_pem);
const size_t mbedtls_test_srv_pwd_rsa_pem_len =
- sizeof( mbedtls_test_srv_pwd_rsa_pem ) - 1;
+ sizeof(mbedtls_test_srv_pwd_rsa_pem) - 1;
const size_t mbedtls_test_srv_crt_rsa_sha1_pem_len =
- sizeof( mbedtls_test_srv_crt_rsa_sha1_pem );
+ sizeof(mbedtls_test_srv_crt_rsa_sha1_pem);
const size_t mbedtls_test_srv_crt_rsa_sha256_pem_len =
- sizeof( mbedtls_test_srv_crt_rsa_sha256_pem );
+ sizeof(mbedtls_test_srv_crt_rsa_sha256_pem);
const size_t mbedtls_test_srv_crt_ec_der_len =
- sizeof( mbedtls_test_srv_crt_ec_der );
+ sizeof(mbedtls_test_srv_crt_ec_der);
const size_t mbedtls_test_srv_key_ec_der_len =
- sizeof( mbedtls_test_srv_key_ec_der );
+ sizeof(mbedtls_test_srv_key_ec_der);
const size_t mbedtls_test_srv_pwd_ec_der_len = 0;
const size_t mbedtls_test_srv_key_rsa_der_len =
- sizeof( mbedtls_test_srv_key_rsa_der );
+ sizeof(mbedtls_test_srv_key_rsa_der);
const size_t mbedtls_test_srv_pwd_rsa_der_len = 0;
const size_t mbedtls_test_srv_crt_rsa_sha1_der_len =
- sizeof( mbedtls_test_srv_crt_rsa_sha1_der );
+ sizeof(mbedtls_test_srv_crt_rsa_sha1_der);
const size_t mbedtls_test_srv_crt_rsa_sha256_der_len =
- sizeof( mbedtls_test_srv_crt_rsa_sha256_der );
+ sizeof(mbedtls_test_srv_crt_rsa_sha256_der);
/*
* Client
@@ -1400,26 +1400,26 @@
const unsigned char mbedtls_test_cli_crt_rsa_der[] = TEST_CLI_CRT_RSA_DER;
const size_t mbedtls_test_cli_crt_ec_pem_len =
- sizeof( mbedtls_test_cli_crt_ec_pem );
+ sizeof(mbedtls_test_cli_crt_ec_pem);
const size_t mbedtls_test_cli_key_ec_pem_len =
- sizeof( mbedtls_test_cli_key_ec_pem );
+ sizeof(mbedtls_test_cli_key_ec_pem);
const size_t mbedtls_test_cli_pwd_ec_pem_len =
- sizeof( mbedtls_test_cli_pwd_ec_pem ) - 1;
+ sizeof(mbedtls_test_cli_pwd_ec_pem) - 1;
const size_t mbedtls_test_cli_key_rsa_pem_len =
- sizeof( mbedtls_test_cli_key_rsa_pem );
+ sizeof(mbedtls_test_cli_key_rsa_pem);
const size_t mbedtls_test_cli_pwd_rsa_pem_len =
- sizeof( mbedtls_test_cli_pwd_rsa_pem ) - 1;
+ sizeof(mbedtls_test_cli_pwd_rsa_pem) - 1;
const size_t mbedtls_test_cli_crt_rsa_pem_len =
- sizeof( mbedtls_test_cli_crt_rsa_pem );
+ sizeof(mbedtls_test_cli_crt_rsa_pem);
const size_t mbedtls_test_cli_crt_ec_der_len =
- sizeof( mbedtls_test_cli_crt_ec_der );
+ sizeof(mbedtls_test_cli_crt_ec_der);
const size_t mbedtls_test_cli_key_ec_der_len =
- sizeof( mbedtls_test_cli_key_ec_der );
+ sizeof(mbedtls_test_cli_key_ec_der);
const size_t mbedtls_test_cli_key_rsa_der_len =
- sizeof( mbedtls_test_cli_key_rsa_der );
+ sizeof(mbedtls_test_cli_key_rsa_der);
const size_t mbedtls_test_cli_crt_rsa_der_len =
- sizeof( mbedtls_test_cli_crt_rsa_der );
+ sizeof(mbedtls_test_cli_crt_rsa_der);
/*
*
@@ -1521,47 +1521,47 @@
const char mbedtls_test_cli_crt_ec[] = TEST_CLI_CRT_EC;
const size_t mbedtls_test_ca_key_rsa_len =
- sizeof( mbedtls_test_ca_key_rsa );
+ sizeof(mbedtls_test_ca_key_rsa);
const size_t mbedtls_test_ca_pwd_rsa_len =
- sizeof( mbedtls_test_ca_pwd_rsa ) - 1;
+ sizeof(mbedtls_test_ca_pwd_rsa) - 1;
const size_t mbedtls_test_ca_crt_rsa_sha256_len =
- sizeof( mbedtls_test_ca_crt_rsa_sha256 );
+ sizeof(mbedtls_test_ca_crt_rsa_sha256);
const size_t mbedtls_test_ca_crt_rsa_sha1_len =
- sizeof( mbedtls_test_ca_crt_rsa_sha1 );
+ sizeof(mbedtls_test_ca_crt_rsa_sha1);
const size_t mbedtls_test_ca_key_ec_len =
- sizeof( mbedtls_test_ca_key_ec );
+ sizeof(mbedtls_test_ca_key_ec);
const size_t mbedtls_test_ca_pwd_ec_len =
- sizeof( mbedtls_test_ca_pwd_ec ) - 1;
+ sizeof(mbedtls_test_ca_pwd_ec) - 1;
const size_t mbedtls_test_ca_crt_ec_len =
- sizeof( mbedtls_test_ca_crt_ec );
+ sizeof(mbedtls_test_ca_crt_ec);
const size_t mbedtls_test_srv_key_rsa_len =
- sizeof( mbedtls_test_srv_key_rsa );
+ sizeof(mbedtls_test_srv_key_rsa);
const size_t mbedtls_test_srv_pwd_rsa_len =
- sizeof( mbedtls_test_srv_pwd_rsa ) -1;
+ sizeof(mbedtls_test_srv_pwd_rsa) -1;
const size_t mbedtls_test_srv_crt_rsa_sha256_len =
- sizeof( mbedtls_test_srv_crt_rsa_sha256 );
+ sizeof(mbedtls_test_srv_crt_rsa_sha256);
const size_t mbedtls_test_srv_crt_rsa_sha1_len =
- sizeof( mbedtls_test_srv_crt_rsa_sha1 );
+ sizeof(mbedtls_test_srv_crt_rsa_sha1);
const size_t mbedtls_test_srv_key_ec_len =
- sizeof( mbedtls_test_srv_key_ec );
+ sizeof(mbedtls_test_srv_key_ec);
const size_t mbedtls_test_srv_pwd_ec_len =
- sizeof( mbedtls_test_srv_pwd_ec ) - 1;
+ sizeof(mbedtls_test_srv_pwd_ec) - 1;
const size_t mbedtls_test_srv_crt_ec_len =
- sizeof( mbedtls_test_srv_crt_ec );
+ sizeof(mbedtls_test_srv_crt_ec);
const size_t mbedtls_test_cli_key_rsa_len =
- sizeof( mbedtls_test_cli_key_rsa );
+ sizeof(mbedtls_test_cli_key_rsa);
const size_t mbedtls_test_cli_pwd_rsa_len =
- sizeof( mbedtls_test_cli_pwd_rsa ) - 1;
+ sizeof(mbedtls_test_cli_pwd_rsa) - 1;
const size_t mbedtls_test_cli_crt_rsa_len =
- sizeof( mbedtls_test_cli_crt_rsa );
+ sizeof(mbedtls_test_cli_crt_rsa);
const size_t mbedtls_test_cli_key_ec_len =
- sizeof( mbedtls_test_cli_key_ec );
+ sizeof(mbedtls_test_cli_key_ec);
const size_t mbedtls_test_cli_pwd_ec_len =
- sizeof( mbedtls_test_cli_pwd_ec ) - 1;
+ sizeof(mbedtls_test_cli_pwd_ec) - 1;
const size_t mbedtls_test_cli_crt_ec_len =
- sizeof( mbedtls_test_cli_crt_ec );
+ sizeof(mbedtls_test_cli_crt_ec);
/*
* Dispatch between SHA-1 and SHA-256
@@ -1579,9 +1579,9 @@
const char mbedtls_test_srv_crt_rsa[] = TEST_SRV_CRT_RSA;
const size_t mbedtls_test_ca_crt_rsa_len =
- sizeof( mbedtls_test_ca_crt_rsa );
+ sizeof(mbedtls_test_ca_crt_rsa);
const size_t mbedtls_test_srv_crt_rsa_len =
- sizeof( mbedtls_test_srv_crt_rsa );
+ sizeof(mbedtls_test_srv_crt_rsa);
/*
* Dispatch between RSA and EC
@@ -1644,25 +1644,25 @@
const char *mbedtls_test_cli_crt = test_cli_crt;
const size_t mbedtls_test_ca_key_len =
- sizeof( test_ca_key );
+ sizeof(test_ca_key);
const size_t mbedtls_test_ca_pwd_len =
- sizeof( test_ca_pwd ) - 1;
+ sizeof(test_ca_pwd) - 1;
const size_t mbedtls_test_ca_crt_len =
- sizeof( test_ca_crt );
+ sizeof(test_ca_crt);
const size_t mbedtls_test_srv_key_len =
- sizeof( test_srv_key );
+ sizeof(test_srv_key);
const size_t mbedtls_test_srv_pwd_len =
- sizeof( test_srv_pwd ) - 1;
+ sizeof(test_srv_pwd) - 1;
const size_t mbedtls_test_srv_crt_len =
- sizeof( test_srv_crt );
+ sizeof(test_srv_crt);
const size_t mbedtls_test_cli_key_len =
- sizeof( test_cli_key );
+ sizeof(test_cli_key);
const size_t mbedtls_test_cli_pwd_len =
- sizeof( test_cli_pwd ) - 1;
+ sizeof(test_cli_pwd) - 1;
const size_t mbedtls_test_cli_crt_len =
- sizeof( test_cli_crt );
+ sizeof(test_cli_crt);
/*
*
@@ -1671,7 +1671,7 @@
*/
/* List of CAs in PEM or DER, depending on config */
-const char * mbedtls_test_cas[] = {
+const char *mbedtls_test_cas[] = {
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA)
mbedtls_test_ca_crt_rsa_sha1,
#endif
@@ -1685,19 +1685,19 @@
};
const size_t mbedtls_test_cas_len[] = {
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA)
- sizeof( mbedtls_test_ca_crt_rsa_sha1 ),
+ sizeof(mbedtls_test_ca_crt_rsa_sha1),
#endif
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA)
- sizeof( mbedtls_test_ca_crt_rsa_sha256 ),
+ sizeof(mbedtls_test_ca_crt_rsa_sha256),
#endif
#if defined(MBEDTLS_ECDSA_C)
- sizeof( mbedtls_test_ca_crt_ec ),
+ sizeof(mbedtls_test_ca_crt_ec),
#endif
0
};
/* List of all available CA certificates in DER format */
-const unsigned char * mbedtls_test_cas_der[] = {
+const unsigned char *mbedtls_test_cas_der[] = {
#if defined(MBEDTLS_RSA_C)
#if defined(MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA)
mbedtls_test_ca_crt_rsa_sha256_der,
@@ -1715,14 +1715,14 @@
const size_t mbedtls_test_cas_der_len[] = {
#if defined(MBEDTLS_RSA_C)
#if defined(MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA)
- sizeof( mbedtls_test_ca_crt_rsa_sha256_der ),
+ sizeof(mbedtls_test_ca_crt_rsa_sha256_der),
#endif /* MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
#if defined(MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA)
- sizeof( mbedtls_test_ca_crt_rsa_sha1_der ),
+ sizeof(mbedtls_test_ca_crt_rsa_sha1_der),
#endif /* MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
#endif /* MBEDTLS_RSA_C */
#if defined(MBEDTLS_ECDSA_C)
- sizeof( mbedtls_test_ca_crt_ec_der ),
+ sizeof(mbedtls_test_ca_crt_ec_der),
#endif /* MBEDTLS_ECDSA_C */
0
};
@@ -1742,5 +1742,5 @@
TEST_CA_CRT_EC_PEM
#endif /* MBEDTLS_ECDSA_C */
"";
-const size_t mbedtls_test_cas_pem_len = sizeof( mbedtls_test_cas_pem );
+const size_t mbedtls_test_cas_pem_len = sizeof(mbedtls_test_cas_pem);
#endif /* MBEDTLS_PEM_PARSE_C */
diff --git a/tests/src/drivers/hash.c b/tests/src/drivers/hash.c
index 44e0e80..7487e84 100644
--- a/tests/src/drivers/hash.c
+++ b/tests/src/drivers/hash.c
@@ -34,28 +34,25 @@
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)
{
mbedtls_test_driver_hash_hooks.hits++;
- if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_test_driver_hash_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_hash_hooks.driver_status =
+ mbedtls_test_driver_hash_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
libtestdriver1_mbedtls_psa_hash_compute(
alg, input, input_length,
- hash, hash_size, hash_length );
+ hash, hash_size, hash_length);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
mbedtls_psa_hash_compute(
alg, input, input_length,
- hash, hash_size, hash_length );
+ hash, hash_size, hash_length);
#else
(void) alg;
(void) input;
@@ -67,29 +64,26 @@
#endif
}
- return( mbedtls_test_driver_hash_hooks.driver_status );
+ return mbedtls_test_driver_hash_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_hash_setup(
mbedtls_transparent_test_driver_hash_operation_t *operation,
- psa_algorithm_t alg )
+ psa_algorithm_t alg)
{
mbedtls_test_driver_hash_hooks.hits++;
- if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_test_driver_hash_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_hash_hooks.driver_status =
- libtestdriver1_mbedtls_psa_hash_setup( operation, alg );
+ mbedtls_test_driver_hash_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ mbedtls_test_driver_hash_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_hash_setup(operation, alg);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_psa_hash_setup( operation, alg );
+ mbedtls_psa_hash_setup(operation, alg);
#else
(void) operation;
(void) alg;
@@ -97,30 +91,27 @@
#endif
}
- return( mbedtls_test_driver_hash_hooks.driver_status );
+ return mbedtls_test_driver_hash_hooks.driver_status;
}
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)
{
mbedtls_test_driver_hash_hooks.hits++;
- if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_test_driver_hash_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_hash_hooks.driver_status =
- libtestdriver1_mbedtls_psa_hash_clone( source_operation,
- target_operation );
+ mbedtls_test_driver_hash_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ mbedtls_test_driver_hash_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_hash_clone(source_operation,
+ target_operation);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_psa_hash_clone( source_operation, target_operation );
+ mbedtls_psa_hash_clone(source_operation, target_operation);
#else
(void) source_operation;
(void) target_operation;
@@ -128,31 +119,28 @@
#endif
}
- return( mbedtls_test_driver_hash_hooks.driver_status );
+ return mbedtls_test_driver_hash_hooks.driver_status;
}
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)
{
mbedtls_test_driver_hash_hooks.hits++;
- if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_test_driver_hash_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_hash_hooks.driver_status =
+ mbedtls_test_driver_hash_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
libtestdriver1_mbedtls_psa_hash_update(
- operation, input, input_length );
+ operation, input, input_length);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_psa_hash_update( operation, input, input_length );
+ mbedtls_psa_hash_update(operation, input, input_length);
#else
(void) operation;
(void) input;
@@ -161,32 +149,29 @@
#endif
}
- return( mbedtls_test_driver_hash_hooks.driver_status );
+ return mbedtls_test_driver_hash_hooks.driver_status;
}
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)
{
mbedtls_test_driver_hash_hooks.hits++;
- if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_test_driver_hash_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_hash_hooks.driver_status =
+ mbedtls_test_driver_hash_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
libtestdriver1_mbedtls_psa_hash_finish(
- operation, hash, hash_size, hash_length );
+ operation, hash, hash_size, hash_length);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_psa_hash_finish( operation, hash, hash_size, hash_length );
+ mbedtls_psa_hash_finish(operation, hash, hash_size, hash_length);
#else
(void) operation;
(void) hash;
@@ -196,34 +181,31 @@
#endif
}
- return( mbedtls_test_driver_hash_hooks.driver_status );
+ return mbedtls_test_driver_hash_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_hash_abort(
- mbedtls_transparent_test_driver_hash_operation_t *operation )
+ mbedtls_transparent_test_driver_hash_operation_t *operation)
{
mbedtls_test_driver_hash_hooks.hits++;
- if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_test_driver_hash_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_hash_hooks.driver_status =
- libtestdriver1_mbedtls_psa_hash_abort( operation );
+ mbedtls_test_driver_hash_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
+ mbedtls_test_driver_hash_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_hash_abort(operation);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
mbedtls_test_driver_hash_hooks.driver_status =
- mbedtls_psa_hash_abort( operation );
+ mbedtls_psa_hash_abort(operation);
#else
(void) operation;
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
#endif
}
- return( mbedtls_test_driver_hash_hooks.driver_status );
+ return mbedtls_test_driver_hash_hooks.driver_status;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/drivers/platform_builtin_keys.c b/tests/src/drivers/platform_builtin_keys.c
index da5865d..6334a43 100644
--- a/tests/src/drivers/platform_builtin_keys.c
+++ b/tests/src/drivers/platform_builtin_keys.c
@@ -29,8 +29,7 @@
#include <test/drivers/test_driver.h>
#endif
-typedef struct
-{
+typedef struct {
psa_key_id_t builtin_key_id;
psa_key_lifetime_t lifetime;
psa_drv_slot_number_t slot_number;
@@ -42,52 +41,50 @@
* ECDSA can be exercised on key ID MBEDTLS_PSA_KEY_ID_BUILTIN_MIN + 1. */
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MIN - 1,
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
- PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
+ PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MIN,
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
- PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
+ PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MIN + 1,
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
- PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
- PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT},
+ PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
+ PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT },
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MAX - 1,
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
- PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
- PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT},
+ PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
+ PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MAX,
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
- PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
- PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT},
+ PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
+ PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MAX + 1,
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
- PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
- PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT},
+ PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
+ PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
#else
- {0, 0, 0}
+ { 0, 0, 0 }
#endif
};
psa_status_t mbedtls_psa_platform_get_builtin_key(
mbedtls_svc_key_id_t key_id,
psa_key_lifetime_t *lifetime,
- psa_drv_slot_number_t *slot_number )
+ psa_drv_slot_number_t *slot_number)
{
- psa_key_id_t app_key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key_id );
+ psa_key_id_t app_key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID(key_id);
const mbedtls_psa_builtin_key_description_t *builtin_key;
- for( size_t i = 0;
- i < ( sizeof( builtin_keys ) / sizeof( builtin_keys[0] ) ); i++ )
- {
+ for (size_t i = 0;
+ i < (sizeof(builtin_keys) / sizeof(builtin_keys[0])); i++) {
builtin_key = &builtin_keys[i];
- if( builtin_key->builtin_key_id == app_key_id )
- {
+ if (builtin_key->builtin_key_id == app_key_id) {
*lifetime = builtin_key->lifetime;
*slot_number = builtin_key->slot_number;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
}
- return( PSA_ERROR_DOES_NOT_EXIST );
+ return PSA_ERROR_DOES_NOT_EXIST;
}
diff --git a/tests/src/drivers/test_driver_aead.c b/tests/src/drivers/test_driver_aead.c
index 93a75f6..4bf2a86 100644
--- a/tests/src/drivers/test_driver_aead.c
+++ b/tests/src/drivers/test_driver_aead.c
@@ -39,28 +39,25 @@
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)
{
mbedtls_test_driver_aead_hooks.hits_encrypt++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_aead_hooks.driver_status =
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
libtestdriver1_mbedtls_psa_aead_encrypt(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
key_buffer, key_buffer_size,
alg,
nonce, nonce_length,
additional_data, additional_data_length,
plaintext, plaintext_length,
- ciphertext, ciphertext_size, ciphertext_length );
+ ciphertext, ciphertext_size, ciphertext_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
mbedtls_psa_aead_encrypt(
@@ -69,7 +66,7 @@
nonce, nonce_length,
additional_data, additional_data_length,
plaintext, plaintext_length,
- ciphertext, ciphertext_size, ciphertext_length );
+ ciphertext, ciphertext_size, ciphertext_length);
#else
(void) attributes;
(void) key_buffer;
@@ -88,7 +85,7 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_decrypt(
@@ -98,28 +95,25 @@
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)
{
mbedtls_test_driver_aead_hooks.hits_decrypt++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_aead_hooks.driver_status =
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
libtestdriver1_mbedtls_psa_aead_decrypt(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
key_buffer, key_buffer_size,
alg,
nonce, nonce_length,
additional_data, additional_data_length,
ciphertext, ciphertext_length,
- plaintext, plaintext_size, plaintext_length );
+ plaintext, plaintext_size, plaintext_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
mbedtls_psa_aead_decrypt(
@@ -128,7 +122,7 @@
nonce, nonce_length,
additional_data, additional_data_length,
ciphertext, ciphertext_length,
- plaintext, plaintext_size, plaintext_length );
+ plaintext, plaintext_size, plaintext_length);
#else
(void) attributes;
(void) key_buffer;
@@ -147,35 +141,33 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
mbedtls_transparent_test_driver_aead_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)
{
mbedtls_test_driver_aead_hooks.hits_encrypt_setup++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_encrypt_setup( operation,
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer,
- key_buffer_size, alg );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_encrypt_setup(operation,
+ (const libtestdriver1_psa_key_attributes_t
+ *) attributes,
+ key_buffer,
+ key_buffer_size, alg);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_encrypt_setup( operation, attributes, key_buffer,
- key_buffer_size, alg );
+ mbedtls_psa_aead_encrypt_setup(operation, attributes, key_buffer,
+ key_buffer_size, alg);
#else
(void) operation;
(void) attributes;
@@ -186,34 +178,32 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
mbedtls_transparent_test_driver_aead_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)
{
mbedtls_test_driver_aead_hooks.hits_decrypt_setup++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_decrypt_setup( operation,
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size, alg );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_decrypt_setup(operation,
+ (const libtestdriver1_psa_key_attributes_t
+ *) attributes,
+ key_buffer, key_buffer_size, alg);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_decrypt_setup( operation, attributes, key_buffer,
- key_buffer_size, alg );
+ mbedtls_psa_aead_decrypt_setup(operation, attributes, key_buffer,
+ key_buffer_size, alg);
#else
(void) operation;
(void) attributes;
@@ -224,30 +214,27 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_set_nonce(
mbedtls_transparent_test_driver_aead_operation_t *operation,
const uint8_t *nonce,
- size_t nonce_length )
+ size_t nonce_length)
{
mbedtls_test_driver_aead_hooks.hits_set_nonce++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_set_nonce(operation, nonce, nonce_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length );
+ mbedtls_psa_aead_set_nonce(operation, nonce, nonce_length);
#else
(void) operation;
(void) nonce;
@@ -256,32 +243,29 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_set_lengths(
mbedtls_transparent_test_driver_aead_operation_t *operation,
size_t ad_length,
- size_t plaintext_length )
+ size_t plaintext_length)
{
mbedtls_test_driver_aead_hooks.hits_set_lengths++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_set_lengths( operation, ad_length,
- plaintext_length );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_set_lengths(operation, ad_length,
+ plaintext_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_set_lengths( operation, ad_length,
- plaintext_length );
+ mbedtls_psa_aead_set_lengths(operation, ad_length,
+ plaintext_length);
#else
(void) operation;
(void) ad_length;
@@ -290,30 +274,27 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_update_ad(
mbedtls_transparent_test_driver_aead_operation_t *operation,
const uint8_t *input,
- size_t input_length )
+ size_t input_length)
{
mbedtls_test_driver_aead_hooks.hits_update_ad++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_update_ad( operation, input, input_length );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_update_ad(operation, input, input_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_update_ad( operation, input, input_length );
+ mbedtls_psa_aead_update_ad(operation, input, input_length);
#else
(void) operation;
(void) input;
@@ -322,36 +303,33 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_update(
- mbedtls_transparent_test_driver_aead_operation_t *operation,
- const uint8_t *input,
- size_t input_length,
- uint8_t *output,
- size_t output_size,
- size_t *output_length )
+ mbedtls_transparent_test_driver_aead_operation_t *operation,
+ const uint8_t *input,
+ size_t input_length,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length)
{
mbedtls_test_driver_aead_hooks.hits_update++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_update( operation, input,
- input_length, output,
- output_size, output_length );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_update(operation, input,
+ input_length, output,
+ output_size, output_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_update( operation, input, input_length, output,
- output_size, output_length );
+ mbedtls_psa_aead_update(operation, input, input_length, output,
+ output_size, output_length);
#else
(void) operation;
(void) input;
@@ -363,38 +341,35 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_finish(
- mbedtls_transparent_test_driver_aead_operation_t *operation,
- uint8_t *ciphertext,
- size_t ciphertext_size,
- size_t *ciphertext_length,
- uint8_t *tag,
- size_t tag_size,
- size_t *tag_length )
+ mbedtls_transparent_test_driver_aead_operation_t *operation,
+ uint8_t *ciphertext,
+ size_t ciphertext_size,
+ size_t *ciphertext_length,
+ uint8_t *tag,
+ size_t tag_size,
+ size_t *tag_length)
{
- mbedtls_test_driver_aead_hooks.hits_finish++;
+ mbedtls_test_driver_aead_hooks.hits_finish++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_finish( operation, ciphertext,
- ciphertext_size, ciphertext_length,
- tag, tag_size, tag_length );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_finish(operation, ciphertext,
+ ciphertext_size, ciphertext_length,
+ tag, tag_size, tag_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_finish( operation, ciphertext, ciphertext_size,
- ciphertext_length, tag, tag_size,
- tag_length );
+ mbedtls_psa_aead_finish(operation, ciphertext, ciphertext_size,
+ ciphertext_length, tag, tag_size,
+ tag_length);
#else
(void) operation;
(void) ciphertext;
@@ -407,48 +382,45 @@
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_verify(
- mbedtls_transparent_test_driver_aead_operation_t *operation,
- uint8_t *plaintext,
- size_t plaintext_size,
- size_t *plaintext_length,
- const uint8_t *tag,
- size_t tag_length )
+ mbedtls_transparent_test_driver_aead_operation_t *operation,
+ uint8_t *plaintext,
+ size_t plaintext_size,
+ size_t *plaintext_length,
+ const uint8_t *tag,
+ size_t tag_length)
{
- mbedtls_test_driver_aead_hooks.hits_verify++;
+ mbedtls_test_driver_aead_hooks.hits_verify++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
- uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE];
- size_t check_tag_length = 0;
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_aead_hooks.driver_status =
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+ uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE];
+ size_t check_tag_length = 0;
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_finish( operation,
- plaintext,
- plaintext_size,
- plaintext_length,
- check_tag,
- sizeof( check_tag ),
- &check_tag_length );
+ libtestdriver1_mbedtls_psa_aead_finish(operation,
+ plaintext,
+ plaintext_size,
+ plaintext_length,
+ check_tag,
+ sizeof(check_tag),
+ &check_tag_length);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_finish( operation,
- plaintext,
- plaintext_size,
- plaintext_length,
- check_tag,
- sizeof( check_tag ),
- &check_tag_length );
+ mbedtls_test_driver_aead_hooks.driver_status =
+ mbedtls_psa_aead_finish(operation,
+ plaintext,
+ plaintext_size,
+ plaintext_length,
+ check_tag,
+ sizeof(check_tag),
+ &check_tag_length);
#else
(void) operation;
(void) plaintext;
@@ -457,47 +429,44 @@
mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
#endif
- if( mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS )
- {
- if( tag_length != check_tag_length ||
- mbedtls_psa_safer_memcmp( tag, check_tag, tag_length )
- != 0 )
- mbedtls_test_driver_aead_hooks.driver_status =
- PSA_ERROR_INVALID_SIGNATURE;
- }
+ if (mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS) {
+ if (tag_length != check_tag_length ||
+ mbedtls_psa_safer_memcmp(tag, check_tag, tag_length)
+ != 0) {
+ mbedtls_test_driver_aead_hooks.driver_status =
+ PSA_ERROR_INVALID_SIGNATURE;
+ }
+ }
- mbedtls_platform_zeroize( check_tag, sizeof( check_tag ) );
+ mbedtls_platform_zeroize(check_tag, sizeof(check_tag));
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_aead_abort(
- mbedtls_transparent_test_driver_aead_operation_t *operation )
+ mbedtls_transparent_test_driver_aead_operation_t *operation)
{
- mbedtls_test_driver_aead_hooks.hits_abort++;
+ mbedtls_test_driver_aead_hooks.hits_abort++;
- if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_test_driver_aead_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_aead_hooks.driver_status =
- libtestdriver1_mbedtls_psa_aead_abort( operation );
+ mbedtls_test_driver_aead_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
+ mbedtls_test_driver_aead_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_aead_abort(operation);
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
mbedtls_test_driver_aead_hooks.driver_status =
- mbedtls_psa_aead_abort( operation );
+ mbedtls_psa_aead_abort(operation);
#else
(void) operation;
mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
#endif
}
- return( mbedtls_test_driver_aead_hooks.driver_status );
+ return mbedtls_test_driver_aead_hooks.driver_status;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/drivers/test_driver_asymmetric_encryption.c b/tests/src/drivers/test_driver_asymmetric_encryption.c
index 506c29b..8c5e207 100644
--- a/tests/src/drivers/test_driver_asymmetric_encryption.c
+++ b/tests/src/drivers/test_driver_asymmetric_encryption.c
@@ -37,82 +37,84 @@
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length )
+ uint8_t *output, size_t output_size, size_t *output_length)
{
mbedtls_test_driver_asymmetric_encryption_hooks.hits++;
- if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL )
- {
- if( output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL) {
+ if (output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( output,
- mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
- mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length );
+ memcpy(output,
+ mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
+ mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length);
*output_length = mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length;
- return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
+ return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
}
- if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
+ if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_asymmetric_encrypt(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size,
- alg, input, input_length, salt, salt_length,
- output, output_size, output_length ) );
+ return libtestdriver1_mbedtls_psa_asymmetric_encrypt(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, input, input_length, salt, salt_length,
+ output, output_size, output_length);
#else
- return( mbedtls_psa_asymmetric_encrypt(
- attributes, key_buffer, key_buffer_size,
- alg, input, input_length, salt, salt_length,
- output, output_size, output_length ) );
+ return mbedtls_psa_asymmetric_encrypt(
+ attributes, key_buffer, key_buffer_size,
+ alg, input, input_length, salt, salt_length,
+ output, output_size, output_length);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length )
+ uint8_t *output, size_t output_size, size_t *output_length)
{
mbedtls_test_driver_asymmetric_encryption_hooks.hits++;
- if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL )
- {
- if( output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL) {
+ if (output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( output,
- mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
- mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length );
+ memcpy(output,
+ mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
+ mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length);
*output_length = mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length;
- return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
+ return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
}
- if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
+ if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_asymmetric_decrypt(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size,
- alg, input, input_length, salt, salt_length,
- output, output_size, output_length ) );
+ return libtestdriver1_mbedtls_psa_asymmetric_decrypt(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, input, input_length, salt, salt_length,
+ output, output_size, output_length);
#else
- return( mbedtls_psa_asymmetric_decrypt(
- attributes, key_buffer, key_buffer_size,
- alg, input, input_length, salt, salt_length,
- output, output_size, output_length ) );
+ return mbedtls_psa_asymmetric_decrypt(
+ attributes, key_buffer, key_buffer_size,
+ alg, input, input_length, salt, salt_length,
+ output, output_size, output_length);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
/*
@@ -122,7 +124,7 @@
const psa_key_attributes_t *attributes, const uint8_t *key,
size_t key_length, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length )
+ uint8_t *output, size_t output_size, size_t *output_length)
{
(void) attributes;
(void) key;
@@ -135,14 +137,14 @@
(void) output;
(void) output_size;
(void) output_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
const psa_key_attributes_t *attributes, const uint8_t *key,
size_t key_length, psa_algorithm_t alg, const uint8_t *input,
size_t input_length, const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length )
+ uint8_t *output, size_t output_size, size_t *output_length)
{
(void) attributes;
(void) key;
@@ -155,7 +157,7 @@
(void) output;
(void) output_size;
(void) output_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/drivers/test_driver_cipher.c b/tests/src/drivers/test_driver_cipher.c
index 3536408..f0cb6b2 100644
--- a/tests/src/drivers/test_driver_cipher.c
+++ b/tests/src/drivers/test_driver_cipher.c
@@ -50,41 +50,42 @@
size_t input_length,
uint8_t *output,
size_t output_size,
- size_t *output_length )
+ size_t *output_length)
{
mbedtls_test_driver_cipher_hooks.hits++;
- if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
- {
- if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
+ if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( output,
- mbedtls_test_driver_cipher_hooks.forced_output,
- mbedtls_test_driver_cipher_hooks.forced_output_length );
+ memcpy(output,
+ mbedtls_test_driver_cipher_hooks.forced_output,
+ mbedtls_test_driver_cipher_hooks.forced_output_length);
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ return mbedtls_test_driver_cipher_hooks.forced_status;
}
- if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_cipher_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_cipher_encrypt(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size,
- alg, iv, iv_length, input, input_length,
- output, output_size, output_length ) );
+ return libtestdriver1_mbedtls_psa_cipher_encrypt(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, iv, iv_length, input, input_length,
+ output, output_size, output_length);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- return( mbedtls_psa_cipher_encrypt(
- attributes, key_buffer, key_buffer_size,
- alg, iv, iv_length, input, input_length,
- output, output_size, output_length ) );
+ return mbedtls_psa_cipher_encrypt(
+ attributes, key_buffer, key_buffer_size,
+ alg, iv, iv_length, input, input_length,
+ output, output_size, output_length);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_cipher_decrypt(
@@ -96,41 +97,42 @@
size_t input_length,
uint8_t *output,
size_t output_size,
- size_t *output_length )
+ size_t *output_length)
{
- mbedtls_test_driver_cipher_hooks.hits++;
+ mbedtls_test_driver_cipher_hooks.hits++;
- if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
- {
- if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
+ if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( output,
- mbedtls_test_driver_cipher_hooks.forced_output,
- mbedtls_test_driver_cipher_hooks.forced_output_length );
+ memcpy(output,
+ mbedtls_test_driver_cipher_hooks.forced_output,
+ mbedtls_test_driver_cipher_hooks.forced_output_length);
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ return mbedtls_test_driver_cipher_hooks.forced_status;
}
- if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_cipher_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_cipher_decrypt(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size,
- alg, input, input_length,
- output, output_size, output_length ) );
+ return libtestdriver1_mbedtls_psa_cipher_decrypt(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, input, input_length,
+ output, output_size, output_length);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- return( mbedtls_psa_cipher_decrypt(
- attributes, key_buffer, key_buffer_size,
- alg, input, input_length,
- output, output_size, output_length ) );
+ return mbedtls_psa_cipher_decrypt(
+ attributes, key_buffer, key_buffer_size,
+ alg, input, input_length,
+ output, output_size, output_length);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
@@ -145,23 +147,24 @@
* useful for the test suite, since it gives a chance of catching memory
* corruption errors should the core not have allocated (enough) memory for
* our context struct. */
- memset( operation, 0, sizeof( *operation ) );
+ memset(operation, 0, sizeof(*operation));
- if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_cipher_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
- operation,
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key, key_length, alg ) );
+ return libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
+ operation,
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key, key_length, alg);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- return( mbedtls_psa_cipher_encrypt_setup(
- operation, attributes, key, key_length, alg ) );
+ return mbedtls_psa_cipher_encrypt_setup(
+ operation, attributes, key, key_length, alg);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
@@ -172,21 +175,22 @@
{
mbedtls_test_driver_cipher_hooks.hits++;
- if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_cipher_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
- operation,
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key, key_length, alg ) );
+ return libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
+ operation,
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key, key_length, alg);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- return( mbedtls_psa_cipher_decrypt_setup(
- operation, attributes, key, key_length, alg ) );
+ return mbedtls_psa_cipher_decrypt_setup(
+ operation, attributes, key, key_length, alg);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_cipher_abort(
@@ -196,18 +200,18 @@
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- libtestdriver1_mbedtls_psa_cipher_abort( operation );
+ libtestdriver1_mbedtls_psa_cipher_abort(operation);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- mbedtls_psa_cipher_abort( operation );
+ mbedtls_psa_cipher_abort(operation);
#endif
/* Wiping the entire struct here, instead of member-by-member. This is
* useful for the test suite, since it gives a chance of catching memory
* corruption errors should the core not have allocated (enough) memory for
* our context struct. */
- memset( operation, 0, sizeof( *operation ) );
+ memset(operation, 0, sizeof(*operation));
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ return mbedtls_test_driver_cipher_hooks.forced_status;
}
psa_status_t mbedtls_test_transparent_cipher_set_iv(
@@ -217,18 +221,19 @@
{
mbedtls_test_driver_cipher_hooks.hits++;
- if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_cipher_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_cipher_set_iv(
- operation, iv, iv_length ) );
+ return libtestdriver1_mbedtls_psa_cipher_set_iv(
+ operation, iv, iv_length);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- return( mbedtls_psa_cipher_set_iv( operation, iv, iv_length ) );
+ return mbedtls_psa_cipher_set_iv(operation, iv, iv_length);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_cipher_update(
@@ -241,34 +246,35 @@
{
mbedtls_test_driver_cipher_hooks.hits++;
- if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
- {
- if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
+ if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
+ if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( output,
- mbedtls_test_driver_cipher_hooks.forced_output,
- mbedtls_test_driver_cipher_hooks.forced_output_length );
+ memcpy(output,
+ mbedtls_test_driver_cipher_hooks.forced_output,
+ mbedtls_test_driver_cipher_hooks.forced_output_length);
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ return mbedtls_test_driver_cipher_hooks.forced_status;
}
- if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_cipher_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_cipher_update(
- operation, input, input_length,
- output, output_size, output_length ) );
+ return libtestdriver1_mbedtls_psa_cipher_update(
+ operation, input, input_length,
+ output, output_size, output_length);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- return( mbedtls_psa_cipher_update(
- operation, input, input_length,
- output, output_size, output_length ) );
+ return mbedtls_psa_cipher_update(
+ operation, input, input_length,
+ output, output_size, output_length);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_cipher_finish(
@@ -279,32 +285,33 @@
{
mbedtls_test_driver_cipher_hooks.hits++;
- if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
- {
- if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
+ if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
+ if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( output,
- mbedtls_test_driver_cipher_hooks.forced_output,
- mbedtls_test_driver_cipher_hooks.forced_output_length );
+ memcpy(output,
+ mbedtls_test_driver_cipher_hooks.forced_output,
+ mbedtls_test_driver_cipher_hooks.forced_output_length);
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ return mbedtls_test_driver_cipher_hooks.forced_status;
}
- if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_cipher_hooks.forced_status );
+ if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_cipher_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
- return( libtestdriver1_mbedtls_psa_cipher_finish(
- operation, output, output_size, output_length ) );
+ return libtestdriver1_mbedtls_psa_cipher_finish(
+ operation, output, output_size, output_length);
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
- return( mbedtls_psa_cipher_finish(
- operation, output, output_size, output_length ) );
+ return mbedtls_psa_cipher_finish(
+ operation, output, output_size, output_length);
#endif
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
/*
@@ -329,7 +336,7 @@
(void) output;
(void) output_size;
(void) output_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_cipher_decrypt(
@@ -348,7 +355,7 @@
(void) output;
(void) output_size;
(void) output_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
@@ -362,7 +369,7 @@
(void) key;
(void) key_length;
(void) alg;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
@@ -376,14 +383,14 @@
(void) key;
(void) key_length;
(void) alg;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_cipher_abort(
- mbedtls_opaque_test_driver_cipher_operation_t *operation )
+ mbedtls_opaque_test_driver_cipher_operation_t *operation)
{
(void) operation;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_cipher_set_iv(
@@ -394,7 +401,7 @@
(void) operation;
(void) iv;
(void) iv_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_cipher_update(
@@ -411,7 +418,7 @@
(void) output;
(void) output_size;
(void) output_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_opaque_cipher_finish(
@@ -424,6 +431,6 @@
(void) output;
(void) output_size;
(void) output_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/drivers/test_driver_key_agreement.c b/tests/src/drivers/test_driver_key_agreement.c
index 7c37b03..d1fd891 100644
--- a/tests/src/drivers/test_driver_key_agreement.c
+++ b/tests/src/drivers/test_driver_key_agreement.c
@@ -47,42 +47,42 @@
size_t peer_key_length,
uint8_t *shared_secret,
size_t shared_secret_size,
- size_t *shared_secret_length )
+ size_t *shared_secret_length)
{
mbedtls_test_driver_key_agreement_hooks.hits++;
- if( mbedtls_test_driver_key_agreement_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_key_agreement_hooks.forced_status );
-
- if( mbedtls_test_driver_key_agreement_hooks.forced_output != NULL )
- {
- if( mbedtls_test_driver_key_agreement_hooks.forced_output_length > shared_secret_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
-
- memcpy( shared_secret, mbedtls_test_driver_key_agreement_hooks.forced_output,
- mbedtls_test_driver_key_agreement_hooks.forced_output_length );
- *shared_secret_length = mbedtls_test_driver_key_agreement_hooks.forced_output_length;
-
- return( PSA_SUCCESS );
+ if (mbedtls_test_driver_key_agreement_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_key_agreement_hooks.forced_status;
}
- if( PSA_ALG_IS_ECDH(alg) )
- {
+ if (mbedtls_test_driver_key_agreement_hooks.forced_output != NULL) {
+ if (mbedtls_test_driver_key_agreement_hooks.forced_output_length > shared_secret_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+
+ memcpy(shared_secret, mbedtls_test_driver_key_agreement_hooks.forced_output,
+ mbedtls_test_driver_key_agreement_hooks.forced_output_length);
+ *shared_secret_length = mbedtls_test_driver_key_agreement_hooks.forced_output_length;
+
+ return PSA_SUCCESS;
+ }
+
+ if (PSA_ALG_IS_ECDH(alg)) {
#if (defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDH))
- return( libtestdriver1_mbedtls_psa_key_agreement_ecdh(
- (const libtestdriver1_psa_key_attributes_t *) attributes,
- key_buffer, key_buffer_size,
- alg, peer_key, peer_key_length,
- shared_secret, shared_secret_size,
- shared_secret_length ) );
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDH))
+ return libtestdriver1_mbedtls_psa_key_agreement_ecdh(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, peer_key, peer_key_length,
+ shared_secret, shared_secret_size,
+ shared_secret_length);
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH)
- return( mbedtls_psa_key_agreement_ecdh(
- attributes,
- key_buffer, key_buffer_size,
- alg, peer_key, peer_key_length,
- shared_secret, shared_secret_size,
- shared_secret_length ) );
+ return mbedtls_psa_key_agreement_ecdh(
+ attributes,
+ key_buffer, key_buffer_size,
+ alg, peer_key, peer_key_length,
+ shared_secret, shared_secret_size,
+ shared_secret_length);
#else
(void) attributes;
(void) key_buffer;
@@ -92,12 +92,10 @@
(void) shared_secret;
(void) shared_secret_size;
(void) shared_secret_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
#endif
- }
- else
- {
- return( PSA_ERROR_INVALID_ARGUMENT );
+ } else {
+ return PSA_ERROR_INVALID_ARGUMENT;
}
}
@@ -111,7 +109,7 @@
size_t peer_key_length,
uint8_t *shared_secret,
size_t shared_secret_size,
- size_t *shared_secret_length )
+ size_t *shared_secret_length)
{
(void) attributes;
(void) key_buffer;
@@ -122,7 +120,7 @@
(void) shared_secret;
(void) shared_secret_size;
(void) shared_secret_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/drivers/test_driver_key_management.c b/tests/src/drivers/test_driver_key_management.c
index 974d498..4e340aa 100644
--- a/tests/src/drivers/test_driver_key_management.c
+++ b/tests/src/drivers/test_driver_key_management.c
@@ -44,53 +44,54 @@
mbedtls_test_driver_key_management_hooks = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT;
const uint8_t mbedtls_test_driver_aes_key[16] =
- { 0x36, 0x77, 0x39, 0x7A, 0x24, 0x43, 0x26, 0x46,
- 0x29, 0x4A, 0x40, 0x4E, 0x63, 0x52, 0x66, 0x55 };
+{ 0x36, 0x77, 0x39, 0x7A, 0x24, 0x43, 0x26, 0x46,
+ 0x29, 0x4A, 0x40, 0x4E, 0x63, 0x52, 0x66, 0x55 };
const uint8_t mbedtls_test_driver_ecdsa_key[32] =
- { 0xdc, 0x7d, 0x9d, 0x26, 0xd6, 0x7a, 0x4f, 0x63,
- 0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18,
- 0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7,
- 0xd6, 0x9a, 0xab, 0xe2, 0x8b, 0xe4, 0xf8, 0x1a };
+{ 0xdc, 0x7d, 0x9d, 0x26, 0xd6, 0x7a, 0x4f, 0x63,
+ 0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18,
+ 0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7,
+ 0xd6, 0x9a, 0xab, 0xe2, 0x8b, 0xe4, 0xf8, 0x1a };
const uint8_t mbedtls_test_driver_ecdsa_pubkey[65] =
- { 0x04,
- 0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c,
- 0x88, 0xdd, 0x93, 0x7e, 0xfd, 0x6d, 0x7c, 0x44,
- 0x56, 0x48, 0xdc, 0xb7, 0x01, 0x15, 0x0b, 0x8a,
- 0x95, 0x09, 0x29, 0x58, 0x50, 0xf4, 0x1c, 0x19,
- 0x31, 0xe5, 0x71, 0xfb, 0x8f, 0x8c, 0x78, 0x31,
- 0x7a, 0x20, 0xb3, 0x80, 0xe8, 0x66, 0x58, 0x4b,
- 0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79,
- 0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c };
+{ 0x04,
+ 0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c,
+ 0x88, 0xdd, 0x93, 0x7e, 0xfd, 0x6d, 0x7c, 0x44,
+ 0x56, 0x48, 0xdc, 0xb7, 0x01, 0x15, 0x0b, 0x8a,
+ 0x95, 0x09, 0x29, 0x58, 0x50, 0xf4, 0x1c, 0x19,
+ 0x31, 0xe5, 0x71, 0xfb, 0x8f, 0x8c, 0x78, 0x31,
+ 0x7a, 0x20, 0xb3, 0x80, 0xe8, 0x66, 0x58, 0x4b,
+ 0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79,
+ 0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c };
-psa_status_t mbedtls_test_transparent_init( void )
+psa_status_t mbedtls_test_transparent_init(void)
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
- status = libtestdriver1_psa_crypto_init( );
- if( status != PSA_SUCCESS )
- return( status );
+ status = libtestdriver1_psa_crypto_init();
+ if (status != PSA_SUCCESS) {
+ return status;
+ }
#endif
- (void)status;
- return( PSA_SUCCESS );
+ (void) status;
+ return PSA_SUCCESS;
}
-void mbedtls_test_transparent_free( void )
+void mbedtls_test_transparent_free(void)
{
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
- libtestdriver1_mbedtls_psa_crypto_free( );
+ libtestdriver1_mbedtls_psa_crypto_free();
#endif
return;
}
-psa_status_t mbedtls_test_opaque_init( void )
+psa_status_t mbedtls_test_opaque_init(void)
{
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
-void mbedtls_test_opaque_free( void )
+void mbedtls_test_opaque_free(void)
{
return;
}
@@ -102,22 +103,23 @@
* prefixing to the key.
*/
#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE \
- PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE
+ PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE
size_t mbedtls_test_opaque_size_function(
const psa_key_type_t key_type,
- const size_t key_bits )
+ const size_t key_bits)
{
size_t key_buffer_size = 0;
- key_buffer_size = PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits );
- if( key_buffer_size == 0 )
- return( 0 );
+ key_buffer_size = PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits);
+ if (key_buffer_size == 0) {
+ return 0;
+ }
/* Include spacing for base size overhead over the key size
* */
key_buffer_size += TEST_DRIVER_KEY_CONTEXT_BASE_SIZE;
- return( key_buffer_size );
+ return key_buffer_size;
}
static size_t mbedtls_test_opaque_get_base_size()
@@ -138,22 +140,24 @@
size_t key_length,
uint8_t *wrapped_key_buffer,
size_t wrapped_key_buffer_size,
- size_t *wrapped_key_buffer_length )
+ size_t *wrapped_key_buffer_length)
{
size_t opaque_key_base_size = mbedtls_test_opaque_get_base_size();
uint64_t prefix = PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX;
- if( key_length + opaque_key_base_size > wrapped_key_buffer_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (key_length + opaque_key_base_size > wrapped_key_buffer_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
/* Write in the opaque pad prefix */
- memcpy( wrapped_key_buffer, &prefix, opaque_key_base_size );
+ memcpy(wrapped_key_buffer, &prefix, opaque_key_base_size);
wrapped_key_buffer += opaque_key_base_size;
*wrapped_key_buffer_length = key_length + opaque_key_base_size;
- while( key_length-- )
+ while (key_length--) {
wrapped_key_buffer[key_length] = key[key_length] ^ 0xFF;
- return( PSA_SUCCESS );
+ }
+ return PSA_SUCCESS;
}
/*
@@ -177,79 +181,80 @@
size_t clear_key_size;
/* Check for underflow */
- if( wrapped_key_length < opaque_key_base_size )
- return( PSA_ERROR_DATA_CORRUPT );
+ if (wrapped_key_length < opaque_key_base_size) {
+ return PSA_ERROR_DATA_CORRUPT;
+ }
clear_key_size = wrapped_key_length - opaque_key_base_size;
wrapped_key += opaque_key_base_size;
- if( clear_key_size > key_buffer_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (clear_key_size > key_buffer_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
*key_buffer_length = clear_key_size;
- while( clear_key_size-- )
+ while (clear_key_size--) {
key_buffer[clear_key_size] = wrapped_key[clear_key_size] ^ 0xFF;
- return( PSA_SUCCESS );
+ }
+ return PSA_SUCCESS;
}
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)
{
++mbedtls_test_driver_key_management_hooks.hits;
- if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_key_management_hooks.forced_status );
+ if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_key_management_hooks.forced_status;
+ }
- if( mbedtls_test_driver_key_management_hooks.forced_output != NULL )
- {
- if( mbedtls_test_driver_key_management_hooks.forced_output_length >
- key_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
- memcpy( key, mbedtls_test_driver_key_management_hooks.forced_output,
- mbedtls_test_driver_key_management_hooks.forced_output_length );
+ if (mbedtls_test_driver_key_management_hooks.forced_output != NULL) {
+ if (mbedtls_test_driver_key_management_hooks.forced_output_length >
+ key_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ memcpy(key, mbedtls_test_driver_key_management_hooks.forced_output,
+ mbedtls_test_driver_key_management_hooks.forced_output_length);
*key_length = mbedtls_test_driver_key_management_hooks.forced_output_length;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
- if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type( attributes ) )
- && PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
- {
+ if (PSA_KEY_TYPE_IS_ECC(psa_get_key_type(attributes))
+ && PSA_KEY_TYPE_IS_KEY_PAIR(psa_get_key_type(attributes))) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
- return( libtestdriver1_mbedtls_psa_ecp_generate_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key, key_size, key_length ) );
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
+ return libtestdriver1_mbedtls_psa_ecp_generate_key(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key, key_size, key_length);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
- return( mbedtls_psa_ecp_generate_key(
- attributes, key, key_size, key_length ) );
+ return mbedtls_psa_ecp_generate_key(
+ attributes, key, key_size, key_length);
#endif
- }
- else if( psa_get_key_type( attributes ) == PSA_KEY_TYPE_RSA_KEY_PAIR )
- {
+ } else if (psa_get_key_type(attributes) == PSA_KEY_TYPE_RSA_KEY_PAIR) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
- return( libtestdriver1_mbedtls_psa_rsa_generate_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key, key_size, key_length ) );
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
+ return libtestdriver1_mbedtls_psa_rsa_generate_key(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key, key_size, key_length);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
- return( mbedtls_psa_rsa_generate_key(
- attributes, key, key_size, key_length ) );
+ return mbedtls_psa_rsa_generate_key(
+ attributes, key, key_size, key_length);
#endif
}
- (void)attributes;
- return( PSA_ERROR_NOT_SUPPORTED );
+ (void) attributes;
+ return PSA_ERROR_NOT_SUPPORTED;
}
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)
{
(void) attributes;
(void) key;
(void) key_size;
(void) key_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_import_key(
@@ -261,62 +266,60 @@
size_t *key_buffer_length,
size_t *bits)
{
- psa_key_type_t type = psa_get_key_type( attributes );
+ psa_key_type_t type = psa_get_key_type(attributes);
++mbedtls_test_driver_key_management_hooks.hits;
mbedtls_test_driver_key_management_hooks.location = PSA_KEY_LOCATION_LOCAL_STORAGE;
- if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_key_management_hooks.forced_status );
+ if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_key_management_hooks.forced_status;
+ }
- if( PSA_KEY_TYPE_IS_ECC( type ) )
- {
+ if (PSA_KEY_TYPE_IS_ECC(type)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) )
- return( libtestdriver1_mbedtls_psa_ecp_import_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- data, data_length,
- key_buffer, key_buffer_size,
- key_buffer_length, bits ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY))
+ return libtestdriver1_mbedtls_psa_ecp_import_key(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ data, data_length,
+ key_buffer, key_buffer_size,
+ key_buffer_length, bits);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
- return( mbedtls_psa_ecp_import_key(
- attributes,
- data, data_length,
- key_buffer, key_buffer_size,
- key_buffer_length, bits ) );
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
+ return mbedtls_psa_ecp_import_key(
+ attributes,
+ data, data_length,
+ key_buffer, key_buffer_size,
+ key_buffer_length, bits);
#endif
- }
- else if( PSA_KEY_TYPE_IS_RSA( type ) )
- {
+ } else if (PSA_KEY_TYPE_IS_RSA(type)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) )
- return( libtestdriver1_mbedtls_psa_rsa_import_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- data, data_length,
- key_buffer, key_buffer_size,
- key_buffer_length, bits ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY))
+ return libtestdriver1_mbedtls_psa_rsa_import_key(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ data, data_length,
+ key_buffer, key_buffer_size,
+ key_buffer_length, bits);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
- return( mbedtls_psa_rsa_import_key(
- attributes,
- data, data_length,
- key_buffer, key_buffer_size,
- key_buffer_length, bits ) );
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
+ return mbedtls_psa_rsa_import_key(
+ attributes,
+ data, data_length,
+ key_buffer, key_buffer_size,
+ key_buffer_length, bits);
#endif
}
- (void)data;
- (void)data_length;
- (void)key_buffer;
- (void)key_buffer_size;
- (void)key_buffer_length;
- (void)bits;
- (void)type;
+ (void) data;
+ (void) data_length;
+ (void) key_buffer;
+ (void) key_buffer_size;
+ (void) key_buffer_length;
+ (void) bits;
+ (void) type;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
@@ -330,7 +333,7 @@
size_t *bits)
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- psa_key_type_t type = psa_get_key_type( attributes );
+ psa_key_type_t type = psa_get_key_type(attributes);
/* This buffer will be used as an intermediate placeholder for
* the clear key till we wrap it */
uint8_t *key_buffer_temp;
@@ -338,331 +341,329 @@
++mbedtls_test_driver_key_management_hooks.hits;
mbedtls_test_driver_key_management_hooks.location = PSA_CRYPTO_TEST_DRIVER_LOCATION;
- if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_key_management_hooks.forced_status );
+ if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_key_management_hooks.forced_status;
+ }
- key_buffer_temp = mbedtls_calloc( 1, key_buffer_size );
- if( key_buffer_temp == NULL )
- return( PSA_ERROR_INSUFFICIENT_MEMORY );
+ key_buffer_temp = mbedtls_calloc(1, key_buffer_size);
+ if (key_buffer_temp == NULL) {
+ return PSA_ERROR_INSUFFICIENT_MEMORY;
+ }
- if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
- {
- *bits = PSA_BYTES_TO_BITS( data_length );
+ if (PSA_KEY_TYPE_IS_UNSTRUCTURED(type)) {
+ *bits = PSA_BYTES_TO_BITS(data_length);
- status = psa_validate_unstructured_key_bit_size( type,
- *bits );
- if( status != PSA_SUCCESS )
+ status = psa_validate_unstructured_key_bit_size(type,
+ *bits);
+ if (status != PSA_SUCCESS) {
goto exit;
+ }
- if( data_length > key_buffer_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (data_length > key_buffer_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
/* Copy the key material accounting for opaque key padding. */
- memcpy( key_buffer_temp, data, data_length );
+ memcpy(key_buffer_temp, data, data_length);
*key_buffer_length = data_length;
- }
- else if( PSA_KEY_TYPE_IS_ECC( type ) )
- {
+ } else if (PSA_KEY_TYPE_IS_ECC(type)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) )
+ (defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
+ defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY))
status = libtestdriver1_mbedtls_psa_ecp_import_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- data, data_length,
- key_buffer_temp, key_buffer_size,
- key_buffer_length, bits );
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ data, data_length,
+ key_buffer_temp, key_buffer_size,
+ key_buffer_length, bits);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
status = mbedtls_psa_ecp_import_key(
- attributes,
- data, data_length,
- key_buffer_temp, key_buffer_size,
- key_buffer_length, bits );
+ attributes,
+ data, data_length,
+ key_buffer_temp, key_buffer_size,
+ key_buffer_length, bits);
#else
status = PSA_ERROR_NOT_SUPPORTED;
#endif
- if( status != PSA_SUCCESS )
- goto exit;
- }
- else if( PSA_KEY_TYPE_IS_RSA( type ) )
- {
+ if (status != PSA_SUCCESS) {
+ goto exit;
+ }
+ } else if (PSA_KEY_TYPE_IS_RSA(type)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) )
+ (defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
+ defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY))
status = libtestdriver1_mbedtls_psa_rsa_import_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- data, data_length,
- key_buffer_temp, key_buffer_size,
- key_buffer_length, bits );
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ data, data_length,
+ key_buffer_temp, key_buffer_size,
+ key_buffer_length, bits);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
status = mbedtls_psa_rsa_import_key(
- attributes,
- data, data_length,
- key_buffer_temp, key_buffer_size,
- key_buffer_length, bits );
+ attributes,
+ data, data_length,
+ key_buffer_temp, key_buffer_size,
+ key_buffer_length, bits);
#else
status = PSA_ERROR_NOT_SUPPORTED;
#endif
- if( status != PSA_SUCCESS )
- goto exit;
- }
- else
- {
+ if (status != PSA_SUCCESS) {
+ goto exit;
+ }
+ } else {
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit;
}
- status = mbedtls_test_opaque_wrap_key( key_buffer_temp, *key_buffer_length,
- key_buffer, key_buffer_size, key_buffer_length );
+ status = mbedtls_test_opaque_wrap_key(key_buffer_temp, *key_buffer_length,
+ key_buffer, key_buffer_size, key_buffer_length);
exit:
- mbedtls_free( key_buffer_temp );
- return( status );
+ mbedtls_free(key_buffer_temp);
+ return status;
}
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)
{
- if( key_length == sizeof( psa_drv_slot_number_t ) )
- {
+ if (key_length == sizeof(psa_drv_slot_number_t)) {
/* Assume this is a builtin key based on the key material length. */
- psa_drv_slot_number_t slot_number = *( ( psa_drv_slot_number_t* ) key );
+ psa_drv_slot_number_t slot_number = *((psa_drv_slot_number_t *) key);
- switch( slot_number )
- {
+ switch (slot_number) {
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT:
/* This is the ECDSA slot. Verify the key's attributes before
* returning the private key. */
- if( psa_get_key_type( attributes ) !=
- PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( psa_get_key_bits( attributes ) != 256 )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( psa_get_key_algorithm( attributes ) !=
- PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( ( psa_get_key_usage_flags( attributes ) &
- PSA_KEY_USAGE_EXPORT ) == 0 )
- return( PSA_ERROR_CORRUPTION_DETECTED );
+ if (psa_get_key_type(attributes) !=
+ PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if (psa_get_key_bits(attributes) != 256) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if (psa_get_key_algorithm(attributes) !=
+ PSA_ALG_ECDSA(PSA_ALG_ANY_HASH)) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if ((psa_get_key_usage_flags(attributes) &
+ PSA_KEY_USAGE_EXPORT) == 0) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
- if( data_size < sizeof( mbedtls_test_driver_ecdsa_key ) )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (data_size < sizeof(mbedtls_test_driver_ecdsa_key)) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( data, mbedtls_test_driver_ecdsa_key,
- sizeof( mbedtls_test_driver_ecdsa_key ) );
- *data_length = sizeof( mbedtls_test_driver_ecdsa_key );
- return( PSA_SUCCESS );
+ memcpy(data, mbedtls_test_driver_ecdsa_key,
+ sizeof(mbedtls_test_driver_ecdsa_key));
+ *data_length = sizeof(mbedtls_test_driver_ecdsa_key);
+ return PSA_SUCCESS;
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT:
/* This is the AES slot. Verify the key's attributes before
* returning the key. */
- if( psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( psa_get_key_bits( attributes ) != 128 )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( psa_get_key_algorithm( attributes ) != PSA_ALG_CTR )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( ( psa_get_key_usage_flags( attributes ) &
- PSA_KEY_USAGE_EXPORT ) == 0 )
- return( PSA_ERROR_CORRUPTION_DETECTED );
+ if (psa_get_key_type(attributes) != PSA_KEY_TYPE_AES) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if (psa_get_key_bits(attributes) != 128) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if (psa_get_key_algorithm(attributes) != PSA_ALG_CTR) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if ((psa_get_key_usage_flags(attributes) &
+ PSA_KEY_USAGE_EXPORT) == 0) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
- if( data_size < sizeof( mbedtls_test_driver_aes_key ) )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (data_size < sizeof(mbedtls_test_driver_aes_key)) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( data, mbedtls_test_driver_aes_key,
- sizeof( mbedtls_test_driver_aes_key ) );
- *data_length = sizeof( mbedtls_test_driver_aes_key );
- return( PSA_SUCCESS );
+ memcpy(data, mbedtls_test_driver_aes_key,
+ sizeof(mbedtls_test_driver_aes_key));
+ *data_length = sizeof(mbedtls_test_driver_aes_key);
+ return PSA_SUCCESS;
default:
- return( PSA_ERROR_DOES_NOT_EXIST );
+ return PSA_ERROR_DOES_NOT_EXIST;
}
- }
- else
- {
+ } else {
/* This buffer will be used as an intermediate placeholder for
* the opaque key till we unwrap the key into key_buffer */
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- psa_key_type_t type = psa_get_key_type( attributes );
+ psa_key_type_t type = psa_get_key_type(attributes);
- if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ||
- PSA_KEY_TYPE_IS_RSA( type ) ||
- PSA_KEY_TYPE_IS_ECC( type ) )
- {
- status = mbedtls_test_opaque_unwrap_key( key, key_length,
- data, data_size, data_length );
- return( status );
+ if (PSA_KEY_TYPE_IS_UNSTRUCTURED(type) ||
+ PSA_KEY_TYPE_IS_RSA(type) ||
+ PSA_KEY_TYPE_IS_ECC(type)) {
+ status = mbedtls_test_opaque_unwrap_key(key, key_length,
+ data, data_size, data_length);
+ return status;
}
}
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_export_public_key(
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size,
- uint8_t *data, size_t data_size, size_t *data_length )
+ uint8_t *data, size_t data_size, size_t *data_length)
{
++mbedtls_test_driver_key_management_hooks.hits;
- if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_key_management_hooks.forced_status );
+ if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_key_management_hooks.forced_status;
+ }
- if( mbedtls_test_driver_key_management_hooks.forced_output != NULL )
- {
- if( mbedtls_test_driver_key_management_hooks.forced_output_length >
- data_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
- memcpy( data, mbedtls_test_driver_key_management_hooks.forced_output,
- mbedtls_test_driver_key_management_hooks.forced_output_length );
+ if (mbedtls_test_driver_key_management_hooks.forced_output != NULL) {
+ if (mbedtls_test_driver_key_management_hooks.forced_output_length >
+ data_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ memcpy(data, mbedtls_test_driver_key_management_hooks.forced_output,
+ mbedtls_test_driver_key_management_hooks.forced_output_length);
*data_length = mbedtls_test_driver_key_management_hooks.forced_output_length;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
- psa_key_type_t key_type = psa_get_key_type( attributes );
+ psa_key_type_t key_type = psa_get_key_type(attributes);
- if( PSA_KEY_TYPE_IS_ECC( key_type ) )
- {
+ if (PSA_KEY_TYPE_IS_ECC(key_type)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) )
- return( libtestdriver1_mbedtls_psa_ecp_export_public_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size,
- data, data_size, data_length ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY))
+ return libtestdriver1_mbedtls_psa_ecp_export_public_key(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ data, data_size, data_length);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
- return( mbedtls_psa_ecp_export_public_key(
- attributes,
- key_buffer, key_buffer_size,
- data, data_size, data_length ) );
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
+ return mbedtls_psa_ecp_export_public_key(
+ attributes,
+ key_buffer, key_buffer_size,
+ data, data_size, data_length);
#endif
- }
- else if( PSA_KEY_TYPE_IS_RSA( key_type ) )
- {
+ } else if (PSA_KEY_TYPE_IS_RSA(key_type)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) )
- return( libtestdriver1_mbedtls_psa_rsa_export_public_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size,
- data, data_size, data_length ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY))
+ return libtestdriver1_mbedtls_psa_rsa_export_public_key(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ data, data_size, data_length);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
- return( mbedtls_psa_rsa_export_public_key(
- attributes,
- key_buffer, key_buffer_size,
- data, data_size, data_length ) );
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
+ return mbedtls_psa_rsa_export_public_key(
+ attributes,
+ key_buffer, key_buffer_size,
+ data, data_size, data_length);
#endif
}
- (void)key_buffer;
- (void)key_buffer_size;
- (void)key_type;
+ (void) key_buffer;
+ (void) key_buffer_size;
+ (void) key_type;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
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)
{
- if( key_length != sizeof( psa_drv_slot_number_t ) )
- {
+ if (key_length != sizeof(psa_drv_slot_number_t)) {
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- psa_key_type_t key_type = psa_get_key_type( attributes );
+ psa_key_type_t key_type = psa_get_key_type(attributes);
uint8_t *key_buffer_temp;
- key_buffer_temp = mbedtls_calloc( 1, key_length );
- if( key_buffer_temp == NULL )
- return( PSA_ERROR_INSUFFICIENT_MEMORY );
+ key_buffer_temp = mbedtls_calloc(1, key_length);
+ if (key_buffer_temp == NULL) {
+ return PSA_ERROR_INSUFFICIENT_MEMORY;
+ }
- if( PSA_KEY_TYPE_IS_ECC( key_type ) )
- {
- status = mbedtls_test_opaque_unwrap_key( key, key_length,
- key_buffer_temp, key_length, data_length );
- if( status == PSA_SUCCESS )
- {
+ if (PSA_KEY_TYPE_IS_ECC(key_type)) {
+ status = mbedtls_test_opaque_unwrap_key(key, key_length,
+ key_buffer_temp, key_length, data_length);
+ if (status == PSA_SUCCESS) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) )
+ (defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
+ defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY))
status = libtestdriver1_mbedtls_psa_ecp_export_public_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer_temp, *data_length,
- data, data_size, data_length );
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer_temp, *data_length,
+ data, data_size, data_length);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
status = mbedtls_psa_ecp_export_public_key(
- attributes,
- key_buffer_temp, *data_length,
- data, data_size, data_length );
+ attributes,
+ key_buffer_temp, *data_length,
+ data, data_size, data_length);
#else
status = PSA_ERROR_NOT_SUPPORTED;
#endif
}
- }
- else if( PSA_KEY_TYPE_IS_RSA( key_type ) )
- {
- status = mbedtls_test_opaque_unwrap_key( key, key_length,
- key_buffer_temp, key_length, data_length );
- if( status == PSA_SUCCESS )
- {
+ } else if (PSA_KEY_TYPE_IS_RSA(key_type)) {
+ status = mbedtls_test_opaque_unwrap_key(key, key_length,
+ key_buffer_temp, key_length, data_length);
+ if (status == PSA_SUCCESS) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) )
+ (defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
+ defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY))
status = libtestdriver1_mbedtls_psa_rsa_export_public_key(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer_temp, *data_length,
- data, data_size, data_length );
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer_temp, *data_length,
+ data, data_size, data_length);
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
- defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
+ defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
status = mbedtls_psa_rsa_export_public_key(
- attributes,
- key_buffer_temp, *data_length,
- data, data_size, data_length );
+ attributes,
+ key_buffer_temp, *data_length,
+ data, data_size, data_length);
#else
status = PSA_ERROR_NOT_SUPPORTED;
#endif
}
- }
- else
- {
+ } else {
status = PSA_ERROR_NOT_SUPPORTED;
- (void)key;
- (void)key_type;
+ (void) key;
+ (void) key_type;
}
- mbedtls_free( key_buffer_temp );
- return( status );
+ mbedtls_free(key_buffer_temp);
+ return status;
}
/* Assume this is a builtin key based on the key material length. */
- psa_drv_slot_number_t slot_number = *( ( psa_drv_slot_number_t* ) key );
- switch( slot_number )
- {
+ psa_drv_slot_number_t slot_number = *((psa_drv_slot_number_t *) key);
+ switch (slot_number) {
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT:
/* This is the ECDSA slot. Verify the key's attributes before
* returning the public key. */
- if( psa_get_key_type( attributes ) !=
- PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( psa_get_key_bits( attributes ) != 256 )
- return( PSA_ERROR_CORRUPTION_DETECTED );
- if( psa_get_key_algorithm( attributes ) !=
- PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) )
- return( PSA_ERROR_CORRUPTION_DETECTED );
+ if (psa_get_key_type(attributes) !=
+ PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if (psa_get_key_bits(attributes) != 256) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
+ if (psa_get_key_algorithm(attributes) !=
+ PSA_ALG_ECDSA(PSA_ALG_ANY_HASH)) {
+ return PSA_ERROR_CORRUPTION_DETECTED;
+ }
- if( data_size < sizeof( mbedtls_test_driver_ecdsa_pubkey ) )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (data_size < sizeof(mbedtls_test_driver_ecdsa_pubkey)) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( data, mbedtls_test_driver_ecdsa_pubkey,
- sizeof( mbedtls_test_driver_ecdsa_pubkey ) );
- *data_length = sizeof( mbedtls_test_driver_ecdsa_pubkey );
- return( PSA_SUCCESS );
+ memcpy(data, mbedtls_test_driver_ecdsa_pubkey,
+ sizeof(mbedtls_test_driver_ecdsa_pubkey));
+ *data_length = sizeof(mbedtls_test_driver_ecdsa_pubkey);
+ return PSA_SUCCESS;
default:
- return( PSA_ERROR_DOES_NOT_EXIST );
+ return PSA_ERROR_DOES_NOT_EXIST;
}
}
@@ -679,49 +680,50 @@
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)
{
- switch( slot_number )
- {
+ switch (slot_number) {
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT:
- psa_set_key_type( attributes, PSA_KEY_TYPE_AES );
- psa_set_key_bits( attributes, 128 );
+ psa_set_key_type(attributes, PSA_KEY_TYPE_AES);
+ psa_set_key_bits(attributes, 128);
psa_set_key_usage_flags(
attributes,
PSA_KEY_USAGE_ENCRYPT |
PSA_KEY_USAGE_DECRYPT |
- PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( attributes, PSA_ALG_CTR );
+ PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(attributes, PSA_ALG_CTR);
- if( key_buffer_size < sizeof( psa_drv_slot_number_t ) )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (key_buffer_size < sizeof(psa_drv_slot_number_t)) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- *( (psa_drv_slot_number_t*) key_buffer ) =
+ *((psa_drv_slot_number_t *) key_buffer) =
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT;
- *key_buffer_length = sizeof( psa_drv_slot_number_t );
- return( PSA_SUCCESS );
+ *key_buffer_length = sizeof(psa_drv_slot_number_t);
+ return PSA_SUCCESS;
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT:
psa_set_key_type(
attributes,
- PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) );
- psa_set_key_bits( attributes, 256 );
+ PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
+ psa_set_key_bits(attributes, 256);
psa_set_key_usage_flags(
attributes,
PSA_KEY_USAGE_SIGN_HASH |
PSA_KEY_USAGE_VERIFY_HASH |
- PSA_KEY_USAGE_EXPORT );
+ PSA_KEY_USAGE_EXPORT);
psa_set_key_algorithm(
- attributes, PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) );
+ attributes, PSA_ALG_ECDSA(PSA_ALG_ANY_HASH));
- if( key_buffer_size < sizeof( psa_drv_slot_number_t ) )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (key_buffer_size < sizeof(psa_drv_slot_number_t)) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- *( (psa_drv_slot_number_t*) key_buffer ) =
+ *((psa_drv_slot_number_t *) key_buffer) =
PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT;
- *key_buffer_length = sizeof( psa_drv_slot_number_t );
- return( PSA_SUCCESS );
+ *key_buffer_length = sizeof(psa_drv_slot_number_t);
+ return PSA_SUCCESS;
default:
- return( PSA_ERROR_DOES_NOT_EXIST );
+ return PSA_ERROR_DOES_NOT_EXIST;
}
}
@@ -736,13 +738,14 @@
* copied keys. This could change when the opaque test driver is extended
* to support SE with storage, or to emulate an SE without storage but
* still holding some slot references */
- if( source_key_length > key_buffer_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (source_key_length > key_buffer_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( key_buffer, source_key, source_key_length );
+ memcpy(key_buffer, source_key, source_key_length);
*key_buffer_length = source_key_length;
- (void)attributes;
- return( PSA_SUCCESS );
+ (void) attributes;
+ return PSA_SUCCESS;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/drivers/test_driver_mac.c b/tests/src/drivers/test_driver_mac.c
index f909785..ea09cf4 100644
--- a/tests/src/drivers/test_driver_mac.c
+++ b/tests/src/drivers/test_driver_mac.c
@@ -40,31 +40,28 @@
size_t input_length,
uint8_t *mac,
size_t mac_size,
- size_t *mac_length )
+ size_t *mac_length)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
libtestdriver1_mbedtls_psa_mac_compute(
- (const libtestdriver1_psa_key_attributes_t *)attributes,
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
key_buffer, key_buffer_size, alg,
input, input_length,
- mac, mac_size, mac_length );
+ mac, mac_size, mac_length);
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_psa_mac_compute(
attributes, key_buffer, key_buffer_size, alg,
input, input_length,
- mac, mac_size, mac_length );
+ mac, mac_size, mac_length);
#else
(void) attributes;
(void) key_buffer;
@@ -79,7 +76,7 @@
#endif
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_mac_sign_setup(
@@ -87,28 +84,25 @@
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
- psa_algorithm_t alg )
+ psa_algorithm_t alg)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
libtestdriver1_mbedtls_psa_mac_sign_setup(
operation,
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size, alg );
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size, alg);
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_psa_mac_sign_setup(
- operation, attributes, key_buffer, key_buffer_size, alg );
+ operation, attributes, key_buffer, key_buffer_size, alg);
#else
(void) operation;
(void) attributes;
@@ -119,7 +113,7 @@
#endif
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_mac_verify_setup(
@@ -127,28 +121,25 @@
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
- psa_algorithm_t alg )
+ psa_algorithm_t alg)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
libtestdriver1_mbedtls_psa_mac_verify_setup(
operation,
- (const libtestdriver1_psa_key_attributes_t *)attributes,
- key_buffer, key_buffer_size, alg );
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size, alg);
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_psa_mac_verify_setup(
- operation, attributes, key_buffer, key_buffer_size, alg );
+ operation, attributes, key_buffer, key_buffer_size, alg);
#else
(void) operation;
(void) attributes;
@@ -159,32 +150,29 @@
#endif
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
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)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
libtestdriver1_mbedtls_psa_mac_update(
- operation, input, input_length );
+ operation, input, input_length);
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_psa_mac_update(
- operation, input, input_length );
+ operation, input, input_length);
#else
(void) operation;
(void) input;
@@ -193,33 +181,30 @@
#endif
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
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)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
libtestdriver1_mbedtls_psa_mac_sign_finish(
- operation, mac, mac_size, mac_length );
+ operation, mac, mac_size, mac_length);
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_psa_mac_sign_finish(
- operation, mac, mac_size, mac_length );
+ operation, mac, mac_size, mac_length);
#else
(void) operation;
(void) mac;
@@ -229,32 +214,29 @@
#endif
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
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)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
libtestdriver1_mbedtls_psa_mac_verify_finish(
- operation, mac, mac_length );
+ operation, mac, mac_length);
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_psa_mac_verify_finish(
- operation, mac, mac_length );
+ operation, mac, mac_length);
#else
(void) operation;
(void) mac;
@@ -263,35 +245,32 @@
#endif
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
psa_status_t mbedtls_test_transparent_mac_abort(
- mbedtls_transparent_test_driver_mac_operation_t *operation )
+ mbedtls_transparent_test_driver_mac_operation_t *operation)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
-#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
mbedtls_test_driver_mac_hooks.driver_status =
- libtestdriver1_mbedtls_psa_mac_abort( operation );
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
+#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
+ mbedtls_test_driver_mac_hooks.driver_status =
+ libtestdriver1_mbedtls_psa_mac_abort(operation);
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_psa_mac_abort( operation );
+ mbedtls_psa_mac_abort(operation);
#else
(void) operation;
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
#endif
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
psa_status_t mbedtls_test_opaque_mac_compute(
@@ -303,17 +282,14 @@
size_t input_length,
uint8_t *mac,
size_t mac_size,
- size_t *mac_length )
+ size_t *mac_length)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
(void) attributes;
(void) key_buffer;
(void) key_buffer_size;
@@ -326,7 +302,7 @@
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
psa_status_t mbedtls_test_opaque_mac_sign_setup(
@@ -334,17 +310,14 @@
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
- psa_algorithm_t alg )
+ psa_algorithm_t alg)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
(void) operation;
(void) attributes;
(void) key_buffer;
@@ -353,7 +326,7 @@
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
psa_status_t mbedtls_test_opaque_mac_verify_setup(
@@ -361,17 +334,14 @@
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
- psa_algorithm_t alg )
+ psa_algorithm_t alg)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
(void) operation;
(void) attributes;
(void) key_buffer;
@@ -380,47 +350,41 @@
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
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)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
(void) operation;
(void) input;
(void) input_length;
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
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)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
(void) operation;
(void) mac;
(void) mac_size;
@@ -428,49 +392,43 @@
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
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)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
(void) operation;
(void) mac;
(void) mac_length;
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
psa_status_t mbedtls_test_opaque_mac_abort(
- mbedtls_opaque_test_driver_mac_operation_t *operation )
+ mbedtls_opaque_test_driver_mac_operation_t *operation)
{
mbedtls_test_driver_mac_hooks.hits++;
- if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
- {
- mbedtls_test_driver_mac_hooks.driver_status =
- mbedtls_test_driver_mac_hooks.forced_status;
- }
- else
- {
+ if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
+ mbedtls_test_driver_mac_hooks.driver_status =
+ mbedtls_test_driver_mac_hooks.forced_status;
+ } else {
(void) operation;
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
}
- return( mbedtls_test_driver_mac_hooks.driver_status );
+ return mbedtls_test_driver_mac_hooks.driver_status;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/drivers/test_driver_signature.c b/tests/src/drivers/test_driver_signature.c
index ef6d135..11815b0 100644
--- a/tests/src/drivers/test_driver_signature.c
+++ b/tests/src/drivers/test_driver_signature.c
@@ -60,72 +60,63 @@
size_t hash_length,
uint8_t *signature,
size_t signature_size,
- size_t *signature_length )
+ size_t *signature_length)
{
- if( attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR )
- {
- if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ||
- PSA_ALG_IS_RSA_PSS( alg) )
- {
+ if (attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR) {
+ if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) ||
+ PSA_ALG_IS_RSA_PSS(alg)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) )
- return( libtestdriver1_mbedtls_psa_rsa_sign_hash(
- (const libtestdriver1_psa_key_attributes_t *) attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_size, signature_length ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS))
+ return libtestdriver1_mbedtls_psa_rsa_sign_hash(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_size, signature_length);
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
- defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
- return( mbedtls_psa_rsa_sign_hash(
- attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_size, signature_length ) );
+ defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
+ return mbedtls_psa_rsa_sign_hash(
+ attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_size, signature_length);
#endif
+ } else {
+ return PSA_ERROR_INVALID_ARGUMENT;
}
- else
- {
- return( PSA_ERROR_INVALID_ARGUMENT );
- }
- }
- else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
- {
- if( PSA_ALG_IS_ECDSA( alg ) )
- {
+ } else if (PSA_KEY_TYPE_IS_ECC(attributes->core.type)) {
+ if (PSA_ALG_IS_ECDSA(alg)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) )
- return( libtestdriver1_mbedtls_psa_ecdsa_sign_hash(
- (const libtestdriver1_psa_key_attributes_t *) attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_size, signature_length ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA))
+ return libtestdriver1_mbedtls_psa_ecdsa_sign_hash(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_size, signature_length);
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
- defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
- return( mbedtls_psa_ecdsa_sign_hash(
- attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_size, signature_length ) );
+ defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
+ return mbedtls_psa_ecdsa_sign_hash(
+ attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_size, signature_length);
#endif
- }
- else
- {
- return( PSA_ERROR_INVALID_ARGUMENT );
+ } else {
+ return PSA_ERROR_INVALID_ARGUMENT;
}
}
- (void)attributes;
- (void)key_buffer;
- (void)key_buffer_size;
- (void)alg;
- (void)hash;
- (void)hash_length;
- (void)signature;
- (void)signature_size;
- (void)signature_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ (void) attributes;
+ (void) key_buffer;
+ (void) key_buffer_size;
+ (void) alg;
+ (void) hash;
+ (void) hash_length;
+ (void) signature;
+ (void) signature_size;
+ (void) signature_length;
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t verify_hash(
@@ -136,71 +127,62 @@
const uint8_t *hash,
size_t hash_length,
const uint8_t *signature,
- size_t signature_length )
+ size_t signature_length)
{
- if( PSA_KEY_TYPE_IS_RSA( attributes->core.type ) )
- {
- if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ||
- PSA_ALG_IS_RSA_PSS( alg) )
- {
+ if (PSA_KEY_TYPE_IS_RSA(attributes->core.type)) {
+ if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) ||
+ PSA_ALG_IS_RSA_PSS(alg)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) )
- return( libtestdriver1_mbedtls_psa_rsa_verify_hash(
- (const libtestdriver1_psa_key_attributes_t *) attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_length ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS))
+ return libtestdriver1_mbedtls_psa_rsa_verify_hash(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_length);
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
- defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
- return( mbedtls_psa_rsa_verify_hash(
- attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_length ) );
+ defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
+ return mbedtls_psa_rsa_verify_hash(
+ attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_length);
#endif
+ } else {
+ return PSA_ERROR_INVALID_ARGUMENT;
}
- else
- {
- return( PSA_ERROR_INVALID_ARGUMENT );
- }
- }
- else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
- {
- if( PSA_ALG_IS_ECDSA( alg ) )
- {
+ } else if (PSA_KEY_TYPE_IS_ECC(attributes->core.type)) {
+ if (PSA_ALG_IS_ECDSA(alg)) {
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
- ( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
- defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) )
- return( libtestdriver1_mbedtls_psa_ecdsa_verify_hash(
- (const libtestdriver1_psa_key_attributes_t *) attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_length ) );
+ (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
+ defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA))
+ return libtestdriver1_mbedtls_psa_ecdsa_verify_hash(
+ (const libtestdriver1_psa_key_attributes_t *) attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_length);
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
- defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
- return( mbedtls_psa_ecdsa_verify_hash(
- attributes,
- key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_length ) );
+ defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
+ return mbedtls_psa_ecdsa_verify_hash(
+ attributes,
+ key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_length);
#endif
- }
- else
- {
- return( PSA_ERROR_INVALID_ARGUMENT );
+ } else {
+ return PSA_ERROR_INVALID_ARGUMENT;
}
}
- (void)attributes;
- (void)key_buffer;
- (void)key_buffer_size;
- (void)alg;
- (void)hash;
- (void)hash_length;
- (void)signature;
- (void)signature_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ (void) attributes;
+ (void) key_buffer;
+ (void) key_buffer_size;
+ (void) alg;
+ (void) hash;
+ (void) hash_length;
+ (void) signature;
+ (void) signature_length;
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_signature_sign_message(
@@ -212,7 +194,7 @@
size_t input_length,
uint8_t *signature,
size_t signature_size,
- size_t *signature_length )
+ size_t *signature_length)
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
size_t hash_length;
@@ -220,41 +202,43 @@
++mbedtls_test_driver_signature_sign_hooks.hits;
- if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_signature_sign_hooks.forced_status );
+ if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_signature_sign_hooks.forced_status;
+ }
- if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL )
- {
- if( mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) {
+ if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
- memcpy( signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
- mbedtls_test_driver_signature_sign_hooks.forced_output_length );
+ memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
+ mbedtls_test_driver_signature_sign_hooks.forced_output_length);
*signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
status = libtestdriver1_mbedtls_psa_hash_compute(
- PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
- hash, sizeof( hash ), &hash_length );
+ PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
+ hash, sizeof(hash), &hash_length);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
status = mbedtls_psa_hash_compute(
- PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
- hash, sizeof( hash ), &hash_length );
+ PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
+ hash, sizeof(hash), &hash_length);
#else
(void) input;
(void) input_length;
status = PSA_ERROR_NOT_SUPPORTED;
#endif
- if( status != PSA_SUCCESS )
+ if (status != PSA_SUCCESS) {
return status;
+ }
- return( sign_hash( attributes, key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_size, signature_length ) );
+ return sign_hash(attributes, key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_size, signature_length);
}
psa_status_t mbedtls_test_opaque_signature_sign_message(
@@ -266,7 +250,7 @@
size_t input_length,
uint8_t *signature,
size_t signature_size,
- size_t *signature_length )
+ size_t *signature_length)
{
(void) attributes;
(void) key;
@@ -278,7 +262,7 @@
(void) signature_size;
(void) signature_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_signature_verify_message(
@@ -289,7 +273,7 @@
const uint8_t *input,
size_t input_length,
const uint8_t *signature,
- size_t signature_length )
+ size_t signature_length)
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
size_t hash_length;
@@ -297,29 +281,31 @@
++mbedtls_test_driver_signature_verify_hooks.hits;
- if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_signature_verify_hooks.forced_status );
+ if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_signature_verify_hooks.forced_status;
+ }
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
status = libtestdriver1_mbedtls_psa_hash_compute(
- PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
- hash, sizeof( hash ), &hash_length );
+ PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
+ hash, sizeof(hash), &hash_length);
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
status = mbedtls_psa_hash_compute(
- PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
- hash, sizeof( hash ), &hash_length );
+ PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
+ hash, sizeof(hash), &hash_length);
#else
(void) input;
(void) input_length;
status = PSA_ERROR_NOT_SUPPORTED;
#endif
- if( status != PSA_SUCCESS )
+ if (status != PSA_SUCCESS) {
return status;
+ }
- return( verify_hash( attributes, key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_length ) );
+ return verify_hash(attributes, key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_length);
}
psa_status_t mbedtls_test_opaque_signature_verify_message(
@@ -330,7 +316,7 @@
const uint8_t *input,
size_t input_length,
const uint8_t *signature,
- size_t signature_length )
+ size_t signature_length)
{
(void) attributes;
(void) key;
@@ -341,7 +327,7 @@
(void) signature;
(void) signature_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_signature_sign_hash(
@@ -349,26 +335,27 @@
const uint8_t *key_buffer, size_t key_buffer_size,
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)
{
++mbedtls_test_driver_signature_sign_hooks.hits;
- if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_signature_sign_hooks.forced_status );
-
- if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL )
- {
- if( mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
- memcpy( signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
- mbedtls_test_driver_signature_sign_hooks.forced_output_length );
- *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
- return( PSA_SUCCESS );
+ if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_signature_sign_hooks.forced_status;
}
- return( sign_hash( attributes, key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_size, signature_length ) );
+ if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) {
+ if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
+ mbedtls_test_driver_signature_sign_hooks.forced_output_length);
+ *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
+ return PSA_SUCCESS;
+ }
+
+ return sign_hash(attributes, key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_size, signature_length);
}
psa_status_t mbedtls_test_opaque_signature_sign_hash(
@@ -376,7 +363,7 @@
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)
{
(void) attributes;
(void) key;
@@ -388,7 +375,7 @@
(void) signature_size;
(void) signature_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
psa_status_t mbedtls_test_transparent_signature_verify_hash(
@@ -396,16 +383,17 @@
const uint8_t *key_buffer, size_t key_buffer_size,
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)
{
++mbedtls_test_driver_signature_verify_hooks.hits;
- if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS )
- return( mbedtls_test_driver_signature_verify_hooks.forced_status );
+ if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) {
+ return mbedtls_test_driver_signature_verify_hooks.forced_status;
+ }
- return verify_hash( attributes, key_buffer, key_buffer_size,
- alg, hash, hash_length,
- signature, signature_length );
+ return verify_hash(attributes, key_buffer, key_buffer_size,
+ alg, hash, hash_length,
+ signature, signature_length);
}
psa_status_t mbedtls_test_opaque_signature_verify_hash(
@@ -413,7 +401,7 @@
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)
{
(void) attributes;
(void) key;
@@ -423,7 +411,7 @@
(void) hash_length;
(void) signature;
(void) signature_length;
- return( PSA_ERROR_NOT_SUPPORTED );
+ return PSA_ERROR_NOT_SUPPORTED;
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
diff --git a/tests/src/fake_external_rng_for_test.c b/tests/src/fake_external_rng_for_test.c
index 9c2195b..89af7d3 100644
--- a/tests/src/fake_external_rng_for_test.c
+++ b/tests/src/fake_external_rng_for_test.c
@@ -28,29 +28,30 @@
static int test_insecure_external_rng_enabled = 0;
-void mbedtls_test_enable_insecure_external_rng( void )
+void mbedtls_test_enable_insecure_external_rng(void)
{
test_insecure_external_rng_enabled = 1;
}
-void mbedtls_test_disable_insecure_external_rng( void )
+void mbedtls_test_disable_insecure_external_rng(void)
{
test_insecure_external_rng_enabled = 0;
}
psa_status_t mbedtls_psa_external_get_random(
mbedtls_psa_external_random_context_t *context,
- uint8_t *output, size_t output_size, size_t *output_length )
+ uint8_t *output, size_t output_size, size_t *output_length)
{
(void) context;
- if( !test_insecure_external_rng_enabled )
- return( PSA_ERROR_INSUFFICIENT_ENTROPY );
+ if (!test_insecure_external_rng_enabled) {
+ return PSA_ERROR_INSUFFICIENT_ENTROPY;
+ }
/* This implementation is for test purposes only!
* Use the libc non-cryptographic random generator. */
- mbedtls_test_rnd_std_rand( NULL, output, output_size );
+ mbedtls_test_rnd_std_rand(NULL, output, output_size);
*output_length = output_size;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
diff --git a/tests/src/helpers.c b/tests/src/helpers.c
index be5c465..30fd362 100644
--- a/tests/src/helpers.c
+++ b/tests/src/helpers.c
@@ -32,40 +32,40 @@
/*----------------------------------------------------------------------------*/
/* Helper Functions */
-int mbedtls_test_platform_setup( void )
+int mbedtls_test_platform_setup(void)
{
int ret = 0;
#if defined(MBEDTLS_PLATFORM_C)
- ret = mbedtls_platform_setup( &platform_ctx );
+ ret = mbedtls_platform_setup(&platform_ctx);
#endif /* MBEDTLS_PLATFORM_C */
- return( ret );
+ return ret;
}
-void mbedtls_test_platform_teardown( void )
+void mbedtls_test_platform_teardown(void)
{
#if defined(MBEDTLS_PLATFORM_C)
- mbedtls_platform_teardown( &platform_ctx );
+ mbedtls_platform_teardown(&platform_ctx);
#endif /* MBEDTLS_PLATFORM_C */
}
int mbedtls_test_ascii2uc(const char c, unsigned char *uc)
{
- if( ( c >= '0' ) && ( c <= '9' ) )
+ if ((c >= '0') && (c <= '9')) {
*uc = c - '0';
- else if( ( c >= 'a' ) && ( c <= 'f' ) )
+ } else if ((c >= 'a') && (c <= 'f')) {
*uc = c - 'a' + 10;
- else if( ( c >= 'A' ) && ( c <= 'F' ) )
+ } else if ((c >= 'A') && (c <= 'F')) {
*uc = c - 'A' + 10;
- else
- return( -1 );
+ } else {
+ return -1;
+ }
- return( 0 );
+ return 0;
}
-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)
{
- if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
- {
+ if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
/* We've already recorded the test as having failed. Don't
* overwrite any previous information about the failure. */
return;
@@ -76,7 +76,7 @@
mbedtls_test_info.filename = filename;
}
-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)
{
mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SKIPPED;
mbedtls_test_info.test = test;
@@ -84,7 +84,7 @@
mbedtls_test_info.filename = filename;
}
-void mbedtls_test_set_step( unsigned long step )
+void mbedtls_test_set_step(unsigned long step)
{
mbedtls_test_info.step = step;
}
@@ -93,201 +93,205 @@
unsigned mbedtls_test_case_uses_negative_0 = 0;
#endif
-void mbedtls_test_info_reset( void )
+void mbedtls_test_info_reset(void)
{
mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SUCCESS;
- mbedtls_test_info.step = (unsigned long)( -1 );
+ mbedtls_test_info.step = (unsigned long) (-1);
mbedtls_test_info.test = 0;
mbedtls_test_info.line_no = 0;
mbedtls_test_info.filename = 0;
- memset( mbedtls_test_info.line1, 0, sizeof( mbedtls_test_info.line1 ) );
- memset( mbedtls_test_info.line2, 0, sizeof( mbedtls_test_info.line2 ) );
+ memset(mbedtls_test_info.line1, 0, sizeof(mbedtls_test_info.line1));
+ memset(mbedtls_test_info.line2, 0, sizeof(mbedtls_test_info.line2));
#if defined(MBEDTLS_BIGNUM_C)
mbedtls_test_case_uses_negative_0 = 0;
#endif
}
-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)
{
- TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
- TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
+ TEST_CF_PUBLIC(&value1, sizeof(value1));
+ TEST_CF_PUBLIC(&value2, sizeof(value2));
- if( value1 == value2 )
- return( 1 );
+ if (value1 == value2) {
+ return 1;
+ }
- if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
- {
+ if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
/* We've already recorded the test as having failed. Don't
* overwrite any previous information about the failure. */
- return( 0 );
+ return 0;
}
- mbedtls_test_fail( test, line_no, filename );
- (void) mbedtls_snprintf( mbedtls_test_info.line1,
- sizeof( mbedtls_test_info.line1 ),
- "lhs = 0x%016llx = %lld",
- value1, (long long) value1 );
- (void) mbedtls_snprintf( mbedtls_test_info.line2,
- sizeof( mbedtls_test_info.line2 ),
- "rhs = 0x%016llx = %lld",
- value2, (long long) value2 );
- return( 0 );
+ mbedtls_test_fail(test, line_no, filename);
+ (void) mbedtls_snprintf(mbedtls_test_info.line1,
+ sizeof(mbedtls_test_info.line1),
+ "lhs = 0x%016llx = %lld",
+ value1, (long long) value1);
+ (void) mbedtls_snprintf(mbedtls_test_info.line2,
+ sizeof(mbedtls_test_info.line2),
+ "rhs = 0x%016llx = %lld",
+ value2, (long long) value2);
+ return 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)
{
- TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
- TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
+ TEST_CF_PUBLIC(&value1, sizeof(value1));
+ TEST_CF_PUBLIC(&value2, sizeof(value2));
- if( value1 <= value2 )
- return( 1 );
+ if (value1 <= value2) {
+ return 1;
+ }
- if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
- {
+ if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
/* We've already recorded the test as having failed. Don't
* overwrite any previous information about the failure. */
- return( 0 );
+ return 0;
}
- mbedtls_test_fail( test, line_no, filename );
- (void) mbedtls_snprintf( mbedtls_test_info.line1,
- sizeof( mbedtls_test_info.line1 ),
- "lhs = 0x%016llx = %llu",
- value1, value1 );
- (void) mbedtls_snprintf( mbedtls_test_info.line2,
- sizeof( mbedtls_test_info.line2 ),
- "rhs = 0x%016llx = %llu",
- value2, value2 );
- return( 0 );
+ mbedtls_test_fail(test, line_no, filename);
+ (void) mbedtls_snprintf(mbedtls_test_info.line1,
+ sizeof(mbedtls_test_info.line1),
+ "lhs = 0x%016llx = %llu",
+ value1, value1);
+ (void) mbedtls_snprintf(mbedtls_test_info.line2,
+ sizeof(mbedtls_test_info.line2),
+ "rhs = 0x%016llx = %llu",
+ value2, value2);
+ return 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)
{
- TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
- TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
+ TEST_CF_PUBLIC(&value1, sizeof(value1));
+ TEST_CF_PUBLIC(&value2, sizeof(value2));
- if( value1 <= value2 )
- return( 1 );
+ if (value1 <= value2) {
+ return 1;
+ }
- if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
- {
+ if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
/* We've already recorded the test as having failed. Don't
* overwrite any previous information about the failure. */
- return( 0 );
+ return 0;
}
- mbedtls_test_fail( test, line_no, filename );
- (void) mbedtls_snprintf( mbedtls_test_info.line1,
- sizeof( mbedtls_test_info.line1 ),
- "lhs = 0x%016llx = %lld",
- (unsigned long long) value1, value1 );
- (void) mbedtls_snprintf( mbedtls_test_info.line2,
- sizeof( mbedtls_test_info.line2 ),
- "rhs = 0x%016llx = %lld",
- (unsigned long long) value2, value2 );
- return( 0 );
+ mbedtls_test_fail(test, line_no, filename);
+ (void) mbedtls_snprintf(mbedtls_test_info.line1,
+ sizeof(mbedtls_test_info.line1),
+ "lhs = 0x%016llx = %lld",
+ (unsigned long long) value1, value1);
+ (void) mbedtls_snprintf(mbedtls_test_info.line2,
+ sizeof(mbedtls_test_info.line2),
+ "rhs = 0x%016llx = %lld",
+ (unsigned long long) value2, value2);
+ return 0;
}
-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)
{
unsigned char uc, uc2;
- *len = strlen( ibuf );
+ *len = strlen(ibuf);
/* Must be even number of bytes. */
- if ( ( *len ) & 1 )
- return( -1 );
+ if ((*len) & 1) {
+ return -1;
+ }
*len /= 2;
- if ( (*len) > obufmax )
- return( -1 );
-
- while( *ibuf != 0 )
- {
- if ( mbedtls_test_ascii2uc( *(ibuf++), &uc ) != 0 )
- return( -1 );
-
- if ( mbedtls_test_ascii2uc( *(ibuf++), &uc2 ) != 0 )
- return( -1 );
-
- *(obuf++) = ( uc << 4 ) | uc2;
+ if ((*len) > obufmax) {
+ return -1;
}
- return( 0 );
+ while (*ibuf != 0) {
+ if (mbedtls_test_ascii2uc(*(ibuf++), &uc) != 0) {
+ return -1;
+ }
+
+ if (mbedtls_test_ascii2uc(*(ibuf++), &uc2) != 0) {
+ return -1;
+ }
+
+ *(obuf++) = (uc << 4) | uc2;
+ }
+
+ return 0;
}
-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)
{
unsigned char l, h;
- while( len != 0 )
- {
+ while (len != 0) {
h = *ibuf / 16;
l = *ibuf % 16;
- if( h < 10 )
+ if (h < 10) {
*obuf++ = '0' + h;
- else
+ } else {
*obuf++ = 'a' + h - 10;
+ }
- if( l < 10 )
+ if (l < 10) {
*obuf++ = '0' + l;
- else
+ } else {
*obuf++ = 'a' + l - 10;
+ }
++ibuf;
len--;
}
}
-unsigned char *mbedtls_test_zero_alloc( size_t len )
+unsigned char *mbedtls_test_zero_alloc(size_t len)
{
void *p;
- size_t actual_len = ( len != 0 ) ? len : 1;
+ size_t actual_len = (len != 0) ? len : 1;
- p = mbedtls_calloc( 1, actual_len );
- TEST_HELPER_ASSERT( p != NULL );
+ p = mbedtls_calloc(1, actual_len);
+ TEST_HELPER_ASSERT(p != NULL);
- memset( p, 0x00, actual_len );
+ memset(p, 0x00, actual_len);
- return( p );
+ return p;
}
-unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen )
+unsigned char *mbedtls_test_unhexify_alloc(const char *ibuf, size_t *olen)
{
unsigned char *obuf;
size_t len;
- *olen = strlen( ibuf ) / 2;
+ *olen = strlen(ibuf) / 2;
- if( *olen == 0 )
- return( mbedtls_test_zero_alloc( *olen ) );
+ if (*olen == 0) {
+ return mbedtls_test_zero_alloc(*olen);
+ }
- obuf = mbedtls_calloc( 1, *olen );
- TEST_HELPER_ASSERT( obuf != NULL );
- TEST_HELPER_ASSERT( mbedtls_test_unhexify( obuf, *olen, ibuf, &len ) == 0 );
+ obuf = mbedtls_calloc(1, *olen);
+ TEST_HELPER_ASSERT(obuf != NULL);
+ TEST_HELPER_ASSERT(mbedtls_test_unhexify(obuf, *olen, ibuf, &len) == 0);
- return( obuf );
+ return obuf;
}
-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)
{
int ret = 0;
uint32_t i = 0;
- if( a_len != b_len )
- return( -1 );
+ if (a_len != b_len) {
+ return -1;
+ }
- for( i = 0; i < a_len; i++ )
- {
- if( a[i] != b[i] )
- {
+ for (i = 0; i < a_len; i++) {
+ if (a[i] != b[i]) {
ret = -1;
break;
}
@@ -296,8 +300,8 @@
}
#if defined(MBEDTLS_TEST_HOOKS)
-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)
{
/* Error codes are always negative (a value of zero is a success) however
* their positive opposites can be easier to understand. The following
@@ -311,42 +315,33 @@
* and module-dependent error code (bits 7..11)).
* l = low level error code.
*/
- if ( high > -0x1000 && high != 0 )
- /* high < 0001000000000000
- * No high level module ID bits are set.
- */
- {
- mbedtls_test_fail( "'high' is not a high-level error code",
- line, file );
- }
- else if ( high < -0x7F80 )
- /* high > 0111111110000000
- * Error code is greater than the largest allowed high level module ID.
- */
- {
- mbedtls_test_fail( "'high' error code is greater than 15 bits",
- line, file );
- }
- else if ( ( high & 0x7F ) != 0 )
- /* high & 0000000001111111
- * Error code contains low level error code bits.
- */
- {
- mbedtls_test_fail( "'high' contains a low-level error code",
- line, file );
- }
- else if ( low < -0x007F )
- /* low > 0000000001111111
- * Error code contains high or module level error code bits.
- */
- {
- mbedtls_test_fail( "'low' error code is greater than 7 bits",
- line, file );
- }
- else if ( low > 0 )
- {
- mbedtls_test_fail( "'low' error code is greater than zero",
- line, file );
+ if (high > -0x1000 && high != 0) {
+ /* high < 0001000000000000
+ * No high level module ID bits are set.
+ */
+ mbedtls_test_fail("'high' is not a high-level error code",
+ line, file);
+ } else if (high < -0x7F80) {
+ /* high > 0111111110000000
+ * Error code is greater than the largest allowed high level module ID.
+ */
+ mbedtls_test_fail("'high' error code is greater than 15 bits",
+ line, file);
+ } else if ((high & 0x7F) != 0) {
+ /* high & 0000000001111111
+ * Error code contains low level error code bits.
+ */
+ mbedtls_test_fail("'high' contains a low-level error code",
+ line, file);
+ } else if (low < -0x007F) {
+ /* low > 0000000001111111
+ * Error code contains high or module level error code bits.
+ */
+ mbedtls_test_fail("'low' error code is greater than 7 bits",
+ line, file);
+ } else if (low > 0) {
+ mbedtls_test_fail("'low' error code is greater than zero",
+ line, file);
}
}
#endif /* MBEDTLS_TEST_HOOKS */
diff --git a/tests/src/psa_crypto_helpers.c b/tests/src/psa_crypto_helpers.c
index 299b6d1..06274d3 100644
--- a/tests/src/psa_crypto_helpers.c
+++ b/tests/src/psa_crypto_helpers.c
@@ -36,96 +36,106 @@
static mbedtls_svc_key_id_t key_ids_used_in_test[9];
static size_t num_key_ids_used;
-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)
{
size_t i;
- if( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key_id ) >
- PSA_MAX_PERSISTENT_KEY_IDENTIFIER )
- {
+ if (MBEDTLS_SVC_KEY_ID_GET_KEY_ID(key_id) >
+ PSA_MAX_PERSISTENT_KEY_IDENTIFIER) {
/* Don't touch key id values that designate non-key files. */
- return( 1 );
+ return 1;
}
- for( i = 0; i < num_key_ids_used ; i++ )
- {
- if( mbedtls_svc_key_id_equal( key_id, key_ids_used_in_test[i] ) )
- return( 1 );
+ for (i = 0; i < num_key_ids_used; i++) {
+ if (mbedtls_svc_key_id_equal(key_id, key_ids_used_in_test[i])) {
+ return 1;
+ }
}
- if( num_key_ids_used == ARRAY_LENGTH( key_ids_used_in_test ) )
- return( 0 );
+ if (num_key_ids_used == ARRAY_LENGTH(key_ids_used_in_test)) {
+ return 0;
+ }
key_ids_used_in_test[num_key_ids_used] = key_id;
++num_key_ids_used;
- return( 1 );
+ return 1;
}
-void mbedtls_test_psa_purge_key_storage( void )
+void mbedtls_test_psa_purge_key_storage(void)
{
size_t i;
- for( i = 0; i < num_key_ids_used; i++ )
- psa_destroy_persistent_key( key_ids_used_in_test[i] );
+ for (i = 0; i < num_key_ids_used; i++) {
+ psa_destroy_persistent_key(key_ids_used_in_test[i]);
+ }
num_key_ids_used = 0;
}
-void mbedtls_test_psa_purge_key_cache( void )
+void mbedtls_test_psa_purge_key_cache(void)
{
size_t i;
- for( i = 0; i < num_key_ids_used; i++ )
- psa_purge_key( key_ids_used_in_test[i] );
+ for (i = 0; i < num_key_ids_used; i++) {
+ psa_purge_key(key_ids_used_in_test[i]);
+ }
}
#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
-const char *mbedtls_test_helper_is_psa_leaking( void )
+const char *mbedtls_test_helper_is_psa_leaking(void)
{
mbedtls_psa_stats_t stats;
- mbedtls_psa_get_stats( &stats );
+ mbedtls_psa_get_stats(&stats);
- if( stats.volatile_slots != 0 )
- return( "A volatile slot has not been closed properly." );
- if( stats.persistent_slots != 0 )
- return( "A persistent slot has not been closed properly." );
- if( stats.external_slots != 0 )
- return( "An external slot has not been closed properly." );
- if( stats.half_filled_slots != 0 )
- return( "A half-filled slot has not been cleared properly." );
- if( stats.locked_slots != 0 )
- return( "Some slots are still marked as locked." );
+ if (stats.volatile_slots != 0) {
+ return "A volatile slot has not been closed properly.";
+ }
+ if (stats.persistent_slots != 0) {
+ return "A persistent slot has not been closed properly.";
+ }
+ if (stats.external_slots != 0) {
+ return "An external slot has not been closed properly.";
+ }
+ if (stats.half_filled_slots != 0) {
+ return "A half-filled slot has not been cleared properly.";
+ }
+ if (stats.locked_slots != 0) {
+ return "Some slots are still marked as locked.";
+ }
- return( NULL );
+ return NULL;
}
#if defined(RECORD_PSA_STATUS_COVERAGE_LOG)
/** Name of the file where return statuses are logged by #RECORD_STATUS. */
#define STATUS_LOG_FILE_NAME "statuses.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)
{
/* We open the log file on first use.
* We never close the log file, so the record_status feature is not
* compatible with resource leak detectors such as Asan.
*/
static FILE *log;
- if( log == NULL )
- log = fopen( STATUS_LOG_FILE_NAME, "a" );
- fprintf( log, "%d:%s:%s:%d:%s\n", (int) status, func, file, line, expr );
- return( status );
+ if (log == NULL) {
+ log = fopen(STATUS_LOG_FILE_NAME, "a");
+ }
+ fprintf(log, "%d:%s:%s:%d:%s\n", (int) status, func, file, line, expr);
+ return status;
}
#endif /* defined(RECORD_PSA_STATUS_COVERAGE_LOG) */
-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)
{
psa_key_usage_t updated_usage = usage_flags;
- if( usage_flags & PSA_KEY_USAGE_SIGN_HASH )
+ if (usage_flags & PSA_KEY_USAGE_SIGN_HASH) {
updated_usage |= PSA_KEY_USAGE_SIGN_MESSAGE;
+ }
- if( usage_flags & PSA_KEY_USAGE_VERIFY_HASH )
+ if (usage_flags & PSA_KEY_USAGE_VERIFY_HASH) {
updated_usage |= PSA_KEY_USAGE_VERIFY_MESSAGE;
+ }
- return( updated_usage );
+ return updated_usage;
}
#endif /* MBEDTLS_PSA_CRYPTO_C */
diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c
index 08c3b46..ecd1ec4 100644
--- a/tests/src/psa_exercise_key.c
+++ b/tests/src/psa_exercise_key.c
@@ -33,14 +33,14 @@
#include <test/psa_crypto_helpers.h>
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
-static int lifetime_is_dynamic_secure_element( psa_key_lifetime_t lifetime )
+static int lifetime_is_dynamic_secure_element(psa_key_lifetime_t lifetime)
{
- return( PSA_KEY_LIFETIME_GET_LOCATION( lifetime ) !=
- PSA_KEY_LOCATION_LOCAL_STORAGE );
+ return PSA_KEY_LIFETIME_GET_LOCATION(lifetime) !=
+ PSA_KEY_LOCATION_LOCAL_STORAGE;
}
#endif
-static int check_key_attributes_sanity( mbedtls_svc_key_id_t key )
+static int check_key_attributes_sanity(mbedtls_svc_key_id_t key)
{
int ok = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -49,58 +49,54 @@
psa_key_type_t type;
size_t bits;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- lifetime = psa_get_key_lifetime( &attributes );
- id = psa_get_key_id( &attributes );
- type = psa_get_key_type( &attributes );
- bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ lifetime = psa_get_key_lifetime(&attributes);
+ id = psa_get_key_id(&attributes);
+ type = psa_get_key_type(&attributes);
+ bits = psa_get_key_bits(&attributes);
/* Persistence */
- if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) )
- {
+ if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) {
TEST_ASSERT(
- ( PSA_KEY_ID_VOLATILE_MIN <=
- MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ) &&
- ( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) <=
- PSA_KEY_ID_VOLATILE_MAX ) );
- }
- else
- {
+ (PSA_KEY_ID_VOLATILE_MIN <=
+ MBEDTLS_SVC_KEY_ID_GET_KEY_ID(id)) &&
+ (MBEDTLS_SVC_KEY_ID_GET_KEY_ID(id) <=
+ PSA_KEY_ID_VOLATILE_MAX));
+ } else {
TEST_ASSERT(
- ( PSA_KEY_ID_USER_MIN <= MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ) &&
- ( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) <= PSA_KEY_ID_USER_MAX ) );
+ (PSA_KEY_ID_USER_MIN <= MBEDTLS_SVC_KEY_ID_GET_KEY_ID(id)) &&
+ (MBEDTLS_SVC_KEY_ID_GET_KEY_ID(id) <= PSA_KEY_ID_USER_MAX));
}
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
/* randomly-generated 64-bit constant, should never appear in test data */
psa_key_slot_number_t slot_number = 0xec94d4a5058a1a21;
- psa_status_t status = psa_get_key_slot_number( &attributes, &slot_number );
- if( lifetime_is_dynamic_secure_element( lifetime ) )
- {
+ psa_status_t status = psa_get_key_slot_number(&attributes, &slot_number);
+ if (lifetime_is_dynamic_secure_element(lifetime)) {
/* Mbed Crypto currently always exposes the slot number to
* applications. This is not mandated by the PSA specification
* and may change in future versions. */
- TEST_EQUAL( status, 0 );
- TEST_ASSERT( slot_number != 0xec94d4a5058a1a21 );
- }
- else
- {
- TEST_EQUAL( status, PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(status, 0);
+ TEST_ASSERT(slot_number != 0xec94d4a5058a1a21);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_ARGUMENT);
}
#endif
/* Type and size */
- TEST_ASSERT( type != 0 );
- TEST_ASSERT( bits != 0 );
- TEST_ASSERT( bits <= PSA_MAX_KEY_BITS );
- if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
- TEST_ASSERT( bits % 8 == 0 );
+ TEST_ASSERT(type != 0);
+ TEST_ASSERT(bits != 0);
+ TEST_ASSERT(bits <= PSA_MAX_KEY_BITS);
+ if (PSA_KEY_TYPE_IS_UNSTRUCTURED(type)) {
+ TEST_ASSERT(bits % 8 == 0);
+ }
/* MAX macros concerning specific key types */
- if( PSA_KEY_TYPE_IS_ECC( type ) )
- TEST_ASSERT( bits <= PSA_VENDOR_ECC_MAX_CURVE_BITS );
- else if( PSA_KEY_TYPE_IS_RSA( type ) )
- TEST_ASSERT( bits <= PSA_VENDOR_RSA_MAX_KEY_BITS );
- TEST_ASSERT( PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ) <= PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE );
+ if (PSA_KEY_TYPE_IS_ECC(type)) {
+ TEST_ASSERT(bits <= PSA_VENDOR_ECC_MAX_CURVE_BITS);
+ } else if (PSA_KEY_TYPE_IS_RSA(type)) {
+ TEST_ASSERT(bits <= PSA_VENDOR_RSA_MAX_KEY_BITS);
+ }
+ TEST_ASSERT(PSA_BLOCK_CIPHER_BLOCK_LENGTH(type) <= PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE);
ok = 1;
@@ -109,410 +105,389 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- return( ok );
+ return ok;
}
-static int exercise_mac_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_mac_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
const unsigned char input[] = "foo";
- unsigned char mac[PSA_MAC_MAX_SIZE] = {0};
- size_t mac_length = sizeof( mac );
+ unsigned char mac[PSA_MAC_MAX_SIZE] = { 0 };
+ size_t mac_length = sizeof(mac);
/* Convert wildcard algorithm to exercisable algorithm */
- if( alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG )
- {
- alg = PSA_ALG_TRUNCATED_MAC( alg, PSA_MAC_TRUNCATED_LENGTH( alg ) );
+ if (alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG) {
+ alg = PSA_ALG_TRUNCATED_MAC(alg, PSA_MAC_TRUNCATED_LENGTH(alg));
}
- if( usage & PSA_KEY_USAGE_SIGN_HASH )
- {
- PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation,
- input, sizeof( input ) ) );
- PSA_ASSERT( psa_mac_sign_finish( &operation,
- mac, sizeof( mac ),
- &mac_length ) );
+ if (usage & PSA_KEY_USAGE_SIGN_HASH) {
+ PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation,
+ input, sizeof(input)));
+ PSA_ASSERT(psa_mac_sign_finish(&operation,
+ mac, sizeof(mac),
+ &mac_length));
}
- if( usage & PSA_KEY_USAGE_VERIFY_HASH )
- {
+ if (usage & PSA_KEY_USAGE_VERIFY_HASH) {
psa_status_t verify_status =
- ( usage & PSA_KEY_USAGE_SIGN_HASH ?
- PSA_SUCCESS :
- PSA_ERROR_INVALID_SIGNATURE );
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation,
- input, sizeof( input ) ) );
- TEST_EQUAL( psa_mac_verify_finish( &operation, mac, mac_length ),
- verify_status );
+ (usage & PSA_KEY_USAGE_SIGN_HASH ?
+ PSA_SUCCESS :
+ PSA_ERROR_INVALID_SIGNATURE);
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation,
+ input, sizeof(input)));
+ TEST_EQUAL(psa_mac_verify_finish(&operation, mac, mac_length),
+ verify_status);
}
- return( 1 );
+ return 1;
exit:
- psa_mac_abort( &operation );
- return( 0 );
+ psa_mac_abort(&operation);
+ return 0;
}
-static int exercise_cipher_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_cipher_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
- unsigned char iv[PSA_CIPHER_IV_MAX_SIZE] = {0};
+ unsigned char iv[PSA_CIPHER_IV_MAX_SIZE] = { 0 };
size_t iv_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t key_type;
const unsigned char plaintext[16] = "Hello, world...";
unsigned char ciphertext[32] = "(wabblewebblewibblewobblewubble)";
- size_t ciphertext_length = sizeof( ciphertext );
- unsigned char decrypted[sizeof( ciphertext )];
+ size_t ciphertext_length = sizeof(ciphertext);
+ unsigned char decrypted[sizeof(ciphertext)];
size_t part_length;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_type = psa_get_key_type( &attributes );
- iv_length = PSA_CIPHER_IV_LENGTH( key_type, alg );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_type = psa_get_key_type(&attributes);
+ iv_length = PSA_CIPHER_IV_LENGTH(key_type, alg);
- if( usage & PSA_KEY_USAGE_ENCRYPT )
- {
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- if( iv_length != 0 )
- {
- PSA_ASSERT( psa_cipher_generate_iv( &operation,
- iv, sizeof( iv ),
- &iv_length ) );
+ if (usage & PSA_KEY_USAGE_ENCRYPT) {
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ if (iv_length != 0) {
+ PSA_ASSERT(psa_cipher_generate_iv(&operation,
+ iv, sizeof(iv),
+ &iv_length));
}
- PSA_ASSERT( psa_cipher_update( &operation,
- plaintext, sizeof( plaintext ),
- ciphertext, sizeof( ciphertext ),
- &ciphertext_length ) );
- PSA_ASSERT( psa_cipher_finish( &operation,
- ciphertext + ciphertext_length,
- sizeof( ciphertext ) - ciphertext_length,
- &part_length ) );
+ PSA_ASSERT(psa_cipher_update(&operation,
+ plaintext, sizeof(plaintext),
+ ciphertext, sizeof(ciphertext),
+ &ciphertext_length));
+ PSA_ASSERT(psa_cipher_finish(&operation,
+ ciphertext + ciphertext_length,
+ sizeof(ciphertext) - ciphertext_length,
+ &part_length));
ciphertext_length += part_length;
}
- if( usage & PSA_KEY_USAGE_DECRYPT )
- {
+ if (usage & PSA_KEY_USAGE_DECRYPT) {
psa_status_t status;
int maybe_invalid_padding = 0;
- if( ! ( usage & PSA_KEY_USAGE_ENCRYPT ) )
- {
- maybe_invalid_padding = ! PSA_ALG_IS_STREAM_CIPHER( alg );
+ if (!(usage & PSA_KEY_USAGE_ENCRYPT)) {
+ maybe_invalid_padding = !PSA_ALG_IS_STREAM_CIPHER(alg);
}
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
- if( iv_length != 0 )
- {
- PSA_ASSERT( psa_cipher_set_iv( &operation,
- iv, iv_length ) );
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
+ if (iv_length != 0) {
+ PSA_ASSERT(psa_cipher_set_iv(&operation,
+ iv, iv_length));
}
- PSA_ASSERT( psa_cipher_update( &operation,
- ciphertext, ciphertext_length,
- decrypted, sizeof( decrypted ),
- &part_length ) );
- status = psa_cipher_finish( &operation,
- decrypted + part_length,
- sizeof( decrypted ) - part_length,
- &part_length );
+ PSA_ASSERT(psa_cipher_update(&operation,
+ ciphertext, ciphertext_length,
+ decrypted, sizeof(decrypted),
+ &part_length));
+ status = psa_cipher_finish(&operation,
+ decrypted + part_length,
+ sizeof(decrypted) - part_length,
+ &part_length);
/* For a stream cipher, all inputs are valid. For a block cipher,
* if the input is some arbitrary data rather than an actual
- ciphertext, a padding error is likely. */
- if( maybe_invalid_padding )
- TEST_ASSERT( status == PSA_SUCCESS ||
- status == PSA_ERROR_INVALID_PADDING );
- else
- PSA_ASSERT( status );
+ ciphertext, a padding error is likely. */
+ if (maybe_invalid_padding) {
+ TEST_ASSERT(status == PSA_SUCCESS ||
+ status == PSA_ERROR_INVALID_PADDING);
+ } else {
+ PSA_ASSERT(status);
+ }
}
- return( 1 );
+ return 1;
exit:
- psa_cipher_abort( &operation );
- psa_reset_key_attributes( &attributes );
- return( 0 );
+ psa_cipher_abort(&operation);
+ psa_reset_key_attributes(&attributes);
+ return 0;
}
-static int exercise_aead_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_aead_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
- unsigned char nonce[PSA_AEAD_NONCE_MAX_SIZE] = {0};
+ unsigned char nonce[PSA_AEAD_NONCE_MAX_SIZE] = { 0 };
size_t nonce_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t key_type;
unsigned char plaintext[16] = "Hello, world...";
unsigned char ciphertext[48] = "(wabblewebblewibblewobblewubble)";
- size_t ciphertext_length = sizeof( ciphertext );
- size_t plaintext_length = sizeof( ciphertext );
+ size_t ciphertext_length = sizeof(ciphertext);
+ size_t plaintext_length = sizeof(ciphertext);
/* Convert wildcard algorithm to exercisable algorithm */
- if( alg & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG )
- {
- alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) );
+ if (alg & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG) {
+ alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, PSA_ALG_AEAD_GET_TAG_LENGTH(alg));
}
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_type = psa_get_key_type( &attributes );
- nonce_length = PSA_AEAD_NONCE_LENGTH( key_type, alg );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_type = psa_get_key_type(&attributes);
+ nonce_length = PSA_AEAD_NONCE_LENGTH(key_type, alg);
- if( usage & PSA_KEY_USAGE_ENCRYPT )
- {
- PSA_ASSERT( psa_aead_encrypt( key, alg,
- nonce, nonce_length,
- NULL, 0,
- plaintext, sizeof( plaintext ),
- ciphertext, sizeof( ciphertext ),
- &ciphertext_length ) );
+ if (usage & PSA_KEY_USAGE_ENCRYPT) {
+ PSA_ASSERT(psa_aead_encrypt(key, alg,
+ nonce, nonce_length,
+ NULL, 0,
+ plaintext, sizeof(plaintext),
+ ciphertext, sizeof(ciphertext),
+ &ciphertext_length));
}
- if( usage & PSA_KEY_USAGE_DECRYPT )
- {
+ if (usage & PSA_KEY_USAGE_DECRYPT) {
psa_status_t verify_status =
- ( usage & PSA_KEY_USAGE_ENCRYPT ?
- PSA_SUCCESS :
- PSA_ERROR_INVALID_SIGNATURE );
- TEST_EQUAL( psa_aead_decrypt( key, alg,
- nonce, nonce_length,
- NULL, 0,
- ciphertext, ciphertext_length,
- plaintext, sizeof( plaintext ),
- &plaintext_length ),
- verify_status );
+ (usage & PSA_KEY_USAGE_ENCRYPT ?
+ PSA_SUCCESS :
+ PSA_ERROR_INVALID_SIGNATURE);
+ TEST_EQUAL(psa_aead_decrypt(key, alg,
+ nonce, nonce_length,
+ NULL, 0,
+ ciphertext, ciphertext_length,
+ plaintext, sizeof(plaintext),
+ &plaintext_length),
+ verify_status);
}
- return( 1 );
+ return 1;
exit:
- psa_reset_key_attributes( &attributes );
- return( 0 );
+ psa_reset_key_attributes(&attributes);
+ return 0;
}
-static int can_sign_or_verify_message( psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int can_sign_or_verify_message(psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
/* Sign-the-unspecified-hash algorithms can only be used with
* {sign,verify}_hash, not with {sign,verify}_message. */
- if( alg == PSA_ALG_ECDSA_ANY || alg == PSA_ALG_RSA_PKCS1V15_SIGN_RAW )
- return( 0 );
- return( usage & ( PSA_KEY_USAGE_SIGN_MESSAGE |
- PSA_KEY_USAGE_VERIFY_MESSAGE ) );
+ if (alg == PSA_ALG_ECDSA_ANY || alg == PSA_ALG_RSA_PKCS1V15_SIGN_RAW) {
+ return 0;
+ }
+ return usage & (PSA_KEY_USAGE_SIGN_MESSAGE |
+ PSA_KEY_USAGE_VERIFY_MESSAGE);
}
-static int exercise_signature_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_signature_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
- if( usage & ( PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH ) )
- {
- unsigned char payload[PSA_HASH_MAX_SIZE] = {1};
+ if (usage & (PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH)) {
+ unsigned char payload[PSA_HASH_MAX_SIZE] = { 1 };
size_t payload_length = 16;
- unsigned char signature[PSA_SIGNATURE_MAX_SIZE] = {0};
- size_t signature_length = sizeof( signature );
- psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH( alg );
+ unsigned char signature[PSA_SIGNATURE_MAX_SIZE] = { 0 };
+ size_t signature_length = sizeof(signature);
+ psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH(alg);
/* If the policy allows signing with any hash, just pick one. */
- if( PSA_ALG_IS_SIGN_HASH( alg ) && hash_alg == PSA_ALG_ANY_HASH )
- {
+ if (PSA_ALG_IS_SIGN_HASH(alg) && hash_alg == PSA_ALG_ANY_HASH) {
#if defined(KNOWN_SUPPORTED_HASH_ALG)
hash_alg = KNOWN_SUPPORTED_HASH_ALG;
alg ^= PSA_ALG_ANY_HASH ^ hash_alg;
#else
- TEST_ASSERT( ! "No hash algorithm for hash-and-sign testing" );
+ TEST_ASSERT(!"No hash algorithm for hash-and-sign testing");
#endif
}
/* Some algorithms require the payload to have the size of
* the hash encoded in the algorithm. Use this input size
* even for algorithms that allow other input sizes. */
- if( hash_alg != 0 )
- payload_length = PSA_HASH_LENGTH( hash_alg );
+ if (hash_alg != 0) {
+ payload_length = PSA_HASH_LENGTH(hash_alg);
+ }
- if( usage & PSA_KEY_USAGE_SIGN_HASH )
- {
- PSA_ASSERT( psa_sign_hash( key, alg,
+ if (usage & PSA_KEY_USAGE_SIGN_HASH) {
+ PSA_ASSERT(psa_sign_hash(key, alg,
+ payload, payload_length,
+ signature, sizeof(signature),
+ &signature_length));
+ }
+
+ if (usage & PSA_KEY_USAGE_VERIFY_HASH) {
+ psa_status_t verify_status =
+ (usage & PSA_KEY_USAGE_SIGN_HASH ?
+ PSA_SUCCESS :
+ PSA_ERROR_INVALID_SIGNATURE);
+ TEST_EQUAL(psa_verify_hash(key, alg,
payload, payload_length,
- signature, sizeof( signature ),
- &signature_length ) );
- }
-
- if( usage & PSA_KEY_USAGE_VERIFY_HASH )
- {
- psa_status_t verify_status =
- ( usage & PSA_KEY_USAGE_SIGN_HASH ?
- PSA_SUCCESS :
- PSA_ERROR_INVALID_SIGNATURE );
- TEST_EQUAL( psa_verify_hash( key, alg,
- payload, payload_length,
- signature, signature_length ),
- verify_status );
+ signature, signature_length),
+ verify_status);
}
}
- if( can_sign_or_verify_message( usage, alg ) )
- {
+ if (can_sign_or_verify_message(usage, alg)) {
unsigned char message[256] = "Hello, world...";
- unsigned char signature[PSA_SIGNATURE_MAX_SIZE] = {0};
+ unsigned char signature[PSA_SIGNATURE_MAX_SIZE] = { 0 };
size_t message_length = 16;
- size_t signature_length = sizeof( signature );
+ size_t signature_length = sizeof(signature);
- if( usage & PSA_KEY_USAGE_SIGN_MESSAGE )
- {
- PSA_ASSERT( psa_sign_message( key, alg,
- message, message_length,
- signature, sizeof( signature ),
- &signature_length ) );
+ if (usage & PSA_KEY_USAGE_SIGN_MESSAGE) {
+ PSA_ASSERT(psa_sign_message(key, alg,
+ message, message_length,
+ signature, sizeof(signature),
+ &signature_length));
}
- if( usage & PSA_KEY_USAGE_VERIFY_MESSAGE )
- {
+ if (usage & PSA_KEY_USAGE_VERIFY_MESSAGE) {
psa_status_t verify_status =
- ( usage & PSA_KEY_USAGE_SIGN_MESSAGE ?
- PSA_SUCCESS :
- PSA_ERROR_INVALID_SIGNATURE );
- TEST_EQUAL( psa_verify_message( key, alg,
- message, message_length,
- signature, signature_length ),
- verify_status );
+ (usage & PSA_KEY_USAGE_SIGN_MESSAGE ?
+ PSA_SUCCESS :
+ PSA_ERROR_INVALID_SIGNATURE);
+ TEST_EQUAL(psa_verify_message(key, alg,
+ message, message_length,
+ signature, signature_length),
+ verify_status);
}
}
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
-static int exercise_asymmetric_encryption_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_asymmetric_encryption_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
unsigned char plaintext[256] = "Hello, world...";
unsigned char ciphertext[256] = "(wabblewebblewibblewobblewubble)";
- size_t ciphertext_length = sizeof( ciphertext );
+ size_t ciphertext_length = sizeof(ciphertext);
size_t plaintext_length = 16;
- if( usage & PSA_KEY_USAGE_ENCRYPT )
- {
- PSA_ASSERT( psa_asymmetric_encrypt( key, alg,
- plaintext, plaintext_length,
- NULL, 0,
- ciphertext, sizeof( ciphertext ),
- &ciphertext_length ) );
+ if (usage & PSA_KEY_USAGE_ENCRYPT) {
+ PSA_ASSERT(psa_asymmetric_encrypt(key, alg,
+ plaintext, plaintext_length,
+ NULL, 0,
+ ciphertext, sizeof(ciphertext),
+ &ciphertext_length));
}
- if( usage & PSA_KEY_USAGE_DECRYPT )
- {
+ if (usage & PSA_KEY_USAGE_DECRYPT) {
psa_status_t status =
- psa_asymmetric_decrypt( key, alg,
- ciphertext, ciphertext_length,
- NULL, 0,
- plaintext, sizeof( plaintext ),
- &plaintext_length );
- TEST_ASSERT( status == PSA_SUCCESS ||
- ( ( usage & PSA_KEY_USAGE_ENCRYPT ) == 0 &&
- ( status == PSA_ERROR_INVALID_ARGUMENT ||
- status == PSA_ERROR_INVALID_PADDING ) ) );
+ psa_asymmetric_decrypt(key, alg,
+ ciphertext, ciphertext_length,
+ NULL, 0,
+ plaintext, sizeof(plaintext),
+ &plaintext_length);
+ TEST_ASSERT(status == PSA_SUCCESS ||
+ ((usage & PSA_KEY_USAGE_ENCRYPT) == 0 &&
+ (status == PSA_ERROR_INVALID_ARGUMENT ||
+ status == PSA_ERROR_INVALID_PADDING)));
}
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
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)
{
- PSA_ASSERT( psa_key_derivation_setup( operation, alg ) );
- if( PSA_ALG_IS_HKDF( alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes( operation,
- PSA_KEY_DERIVATION_INPUT_SALT,
- input1, input1_length ) );
- PSA_ASSERT( psa_key_derivation_input_key( operation,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- key ) );
- PSA_ASSERT( psa_key_derivation_input_bytes( operation,
- PSA_KEY_DERIVATION_INPUT_INFO,
- input2,
- input2_length ) );
- }
- else if( PSA_ALG_IS_TLS12_PRF( alg ) ||
- PSA_ALG_IS_TLS12_PSK_TO_MS( alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes( operation,
- PSA_KEY_DERIVATION_INPUT_SEED,
- input1, input1_length ) );
- PSA_ASSERT( psa_key_derivation_input_key( operation,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- key ) );
- PSA_ASSERT( psa_key_derivation_input_bytes( operation,
- PSA_KEY_DERIVATION_INPUT_LABEL,
- input2, input2_length ) );
- }
- else
- {
- TEST_ASSERT( ! "Key derivation algorithm not supported" );
+ PSA_ASSERT(psa_key_derivation_setup(operation, alg));
+ if (PSA_ALG_IS_HKDF(alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(operation,
+ PSA_KEY_DERIVATION_INPUT_SALT,
+ input1, input1_length));
+ PSA_ASSERT(psa_key_derivation_input_key(operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET,
+ key));
+ PSA_ASSERT(psa_key_derivation_input_bytes(operation,
+ PSA_KEY_DERIVATION_INPUT_INFO,
+ input2,
+ input2_length));
+ } else if (PSA_ALG_IS_TLS12_PRF(alg) ||
+ PSA_ALG_IS_TLS12_PSK_TO_MS(alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(operation,
+ PSA_KEY_DERIVATION_INPUT_SEED,
+ input1, input1_length));
+ PSA_ASSERT(psa_key_derivation_input_key(operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET,
+ key));
+ PSA_ASSERT(psa_key_derivation_input_bytes(operation,
+ PSA_KEY_DERIVATION_INPUT_LABEL,
+ input2, input2_length));
+ } else {
+ TEST_ASSERT(!"Key derivation algorithm not supported");
}
- if( capacity != SIZE_MAX )
- PSA_ASSERT( psa_key_derivation_set_capacity( operation, capacity ) );
+ if (capacity != SIZE_MAX) {
+ PSA_ASSERT(psa_key_derivation_set_capacity(operation, capacity));
+ }
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
-static int exercise_key_derivation_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_key_derivation_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
unsigned char input1[] = "Input 1";
- size_t input1_length = sizeof( input1 );
+ size_t input1_length = sizeof(input1);
unsigned char input2[] = "Input 2";
- size_t input2_length = sizeof( input2 );
+ size_t input2_length = sizeof(input2);
unsigned char output[1];
- size_t capacity = sizeof( output );
+ size_t capacity = sizeof(output);
- if( usage & PSA_KEY_USAGE_DERIVE )
- {
- if( !mbedtls_test_psa_setup_key_derivation_wrap( &operation, key, alg,
- input1, input1_length,
- input2, input2_length,
- capacity ) )
+ if (usage & PSA_KEY_USAGE_DERIVE) {
+ if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, key, alg,
+ input1, input1_length,
+ input2, input2_length,
+ capacity)) {
goto exit;
+ }
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- output,
- capacity ) );
- PSA_ASSERT( psa_key_derivation_abort( &operation ) );
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output,
+ capacity));
+ PSA_ASSERT(psa_key_derivation_abort(&operation));
}
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
/* We need two keys to exercise key agreement. Exercise the
* private key against its own public key. */
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)
{
psa_key_type_t private_key_type;
psa_key_type_t public_key_type;
@@ -525,34 +500,34 @@
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- private_key_type = psa_get_key_type( &attributes );
- key_bits = psa_get_key_bits( &attributes );
- public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( private_key_type );
- public_key_length = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( public_key_type, key_bits );
- ASSERT_ALLOC( public_key, public_key_length );
- PSA_ASSERT( psa_export_public_key( key, public_key, public_key_length,
- &public_key_length ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ private_key_type = psa_get_key_type(&attributes);
+ key_bits = psa_get_key_bits(&attributes);
+ public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(private_key_type);
+ public_key_length = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_key_type, key_bits);
+ ASSERT_ALLOC(public_key, public_key_length);
+ PSA_ASSERT(psa_export_public_key(key, public_key, public_key_length,
+ &public_key_length));
status = psa_key_derivation_key_agreement(
operation, PSA_KEY_DERIVATION_INPUT_SECRET, key,
- public_key, public_key_length );
+ public_key, public_key_length);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_free( public_key );
- return( status );
+ mbedtls_free(public_key);
+ return status;
}
/* We need two keys to exercise key agreement. Exercise the
* private key against its own public key. */
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)
{
psa_key_type_t private_key_type;
psa_key_type_t public_key_type;
@@ -567,26 +542,25 @@
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- private_key_type = psa_get_key_type( &attributes );
- key_bits = psa_get_key_bits( &attributes );
- public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( private_key_type );
- public_key_length = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( public_key_type, key_bits );
- ASSERT_ALLOC( public_key, public_key_length );
- PSA_ASSERT( psa_export_public_key( key,
- public_key, public_key_length,
- &public_key_length ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ private_key_type = psa_get_key_type(&attributes);
+ key_bits = psa_get_key_bits(&attributes);
+ public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(private_key_type);
+ public_key_length = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_key_type, key_bits);
+ ASSERT_ALLOC(public_key, public_key_length);
+ PSA_ASSERT(psa_export_public_key(key,
+ public_key, public_key_length,
+ &public_key_length));
- status = psa_raw_key_agreement( alg, key,
- public_key, public_key_length,
- output, sizeof( output ), &output_length );
- if ( status == PSA_SUCCESS )
- {
- TEST_ASSERT( output_length <=
- PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( private_key_type,
- key_bits ) );
- TEST_ASSERT( output_length <=
- PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE );
+ status = psa_raw_key_agreement(alg, key,
+ public_key, public_key_length,
+ output, sizeof(output), &output_length);
+ if (status == PSA_SUCCESS) {
+ TEST_ASSERT(output_length <=
+ PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(private_key_type,
+ key_bits));
+ TEST_ASSERT(output_length <=
+ PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE);
}
exit:
@@ -594,119 +568,112 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_free( public_key );
- return( status );
+ mbedtls_free(public_key);
+ return status;
}
-static int exercise_raw_key_agreement_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_raw_key_agreement_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
int ok = 0;
- if( usage & PSA_KEY_USAGE_DERIVE )
- {
+ if (usage & PSA_KEY_USAGE_DERIVE) {
/* We need two keys to exercise key agreement. Exercise the
* private key against its own public key. */
- PSA_ASSERT( mbedtls_test_psa_raw_key_agreement_with_self( alg, key ) );
+ PSA_ASSERT(mbedtls_test_psa_raw_key_agreement_with_self(alg, key));
}
ok = 1;
exit:
- return( ok );
+ return ok;
}
-static int exercise_key_agreement_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage,
- psa_algorithm_t alg )
+static int exercise_key_agreement_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage,
+ psa_algorithm_t alg)
{
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
unsigned char input[1] = { 0 };
unsigned char output[1];
int ok = 0;
- psa_algorithm_t kdf_alg = PSA_ALG_KEY_AGREEMENT_GET_KDF( alg );
+ psa_algorithm_t kdf_alg = PSA_ALG_KEY_AGREEMENT_GET_KDF(alg);
psa_status_t expected_key_agreement_status = PSA_SUCCESS;
- if( usage & PSA_KEY_USAGE_DERIVE )
- {
+ if (usage & PSA_KEY_USAGE_DERIVE) {
/* We need two keys to exercise key agreement. Exercise the
* private key against its own public key. */
- PSA_ASSERT( psa_key_derivation_setup( &operation, alg ) );
- if( PSA_ALG_IS_TLS12_PRF( kdf_alg ) ||
- PSA_ALG_IS_TLS12_PSK_TO_MS( kdf_alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes(
- &operation, PSA_KEY_DERIVATION_INPUT_SEED,
- input, sizeof( input ) ) );
+ PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
+ if (PSA_ALG_IS_TLS12_PRF(kdf_alg) ||
+ PSA_ALG_IS_TLS12_PSK_TO_MS(kdf_alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(
+ &operation, PSA_KEY_DERIVATION_INPUT_SEED,
+ input, sizeof(input)));
}
- if( PSA_ALG_IS_HKDF_EXTRACT( kdf_alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes(
- &operation, PSA_KEY_DERIVATION_INPUT_SALT,
- input, sizeof( input ) ) );
+ if (PSA_ALG_IS_HKDF_EXTRACT(kdf_alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(
+ &operation, PSA_KEY_DERIVATION_INPUT_SALT,
+ input, sizeof(input)));
}
/* For HKDF_EXPAND input secret may fail as secret size may not match
to expected PRK size. In practice it means that key bits must match
hash length. Otherwise test should fail with INVALID_ARGUMENT. */
- if( PSA_ALG_IS_HKDF_EXPAND( kdf_alg ) )
- {
+ if (PSA_ALG_IS_HKDF_EXPAND(kdf_alg)) {
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- size_t key_bits = psa_get_key_bits( &attributes );
- psa_algorithm_t hash_alg = PSA_ALG_HKDF_GET_HASH( kdf_alg );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ size_t key_bits = psa_get_key_bits(&attributes);
+ psa_algorithm_t hash_alg = PSA_ALG_HKDF_GET_HASH(kdf_alg);
- if( PSA_BITS_TO_BYTES( key_bits ) != PSA_HASH_LENGTH( hash_alg ) )
+ if (PSA_BITS_TO_BYTES(key_bits) != PSA_HASH_LENGTH(hash_alg)) {
expected_key_agreement_status = PSA_ERROR_INVALID_ARGUMENT;
+ }
}
- TEST_EQUAL( mbedtls_test_psa_key_agreement_with_self( &operation, key ),
- expected_key_agreement_status );
+ TEST_EQUAL(mbedtls_test_psa_key_agreement_with_self(&operation, key),
+ expected_key_agreement_status);
- if( expected_key_agreement_status != PSA_SUCCESS )
- return( 1 );
+ if (expected_key_agreement_status != PSA_SUCCESS) {
+ return 1;
+ }
- if( PSA_ALG_IS_TLS12_PRF( kdf_alg ) ||
- PSA_ALG_IS_TLS12_PSK_TO_MS( kdf_alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes(
- &operation, PSA_KEY_DERIVATION_INPUT_LABEL,
- input, sizeof( input ) ) );
+ if (PSA_ALG_IS_TLS12_PRF(kdf_alg) ||
+ PSA_ALG_IS_TLS12_PSK_TO_MS(kdf_alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(
+ &operation, PSA_KEY_DERIVATION_INPUT_LABEL,
+ input, sizeof(input)));
+ } else if (PSA_ALG_IS_HKDF(kdf_alg) || PSA_ALG_IS_HKDF_EXPAND(kdf_alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(
+ &operation, PSA_KEY_DERIVATION_INPUT_INFO,
+ input, sizeof(input)));
}
- else if( PSA_ALG_IS_HKDF( kdf_alg ) || PSA_ALG_IS_HKDF_EXPAND( kdf_alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes(
- &operation, PSA_KEY_DERIVATION_INPUT_INFO,
- input, sizeof( input ) ) );
- }
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- output,
- sizeof( output ) ) );
- PSA_ASSERT( psa_key_derivation_abort( &operation ) );
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output,
+ sizeof(output)));
+ PSA_ASSERT(psa_key_derivation_abort(&operation));
}
ok = 1;
exit:
- return( ok );
+ return ok;
}
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)
{
- TEST_ASSERT( exported_length <= PSA_EXPORT_KEY_OUTPUT_SIZE( type, bits ) );
+ TEST_ASSERT(exported_length <= PSA_EXPORT_KEY_OUTPUT_SIZE(type, bits));
- if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
- TEST_EQUAL( exported_length, PSA_BITS_TO_BYTES( bits ) );
- else
+ if (PSA_KEY_TYPE_IS_UNSTRUCTURED(type)) {
+ TEST_EQUAL(exported_length, PSA_BITS_TO_BYTES(bits));
+ } else
#if defined(MBEDTLS_ASN1_PARSE_C)
- if( type == PSA_KEY_TYPE_RSA_KEY_PAIR )
- {
- uint8_t *p = (uint8_t*) exported;
+ if (type == PSA_KEY_TYPE_RSA_KEY_PAIR) {
+ uint8_t *p = (uint8_t *) exported;
const uint8_t *end = exported + exported_length;
size_t len;
/* RSAPrivateKey ::= SEQUENCE {
@@ -721,140 +688,139 @@
* coefficient INTEGER, -- (inverse of q) mod p
* }
*/
- TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len,
- MBEDTLS_ASN1_SEQUENCE |
- MBEDTLS_ASN1_CONSTRUCTED ), 0 );
- TEST_EQUAL( len, end - p );
- if( ! mbedtls_test_asn1_skip_integer( &p, end, 0, 0, 0 ) )
+ TEST_EQUAL(mbedtls_asn1_get_tag(&p, end, &len,
+ MBEDTLS_ASN1_SEQUENCE |
+ MBEDTLS_ASN1_CONSTRUCTED), 0);
+ TEST_EQUAL(len, end - p);
+ if (!mbedtls_test_asn1_skip_integer(&p, end, 0, 0, 0)) {
goto exit;
- if( ! mbedtls_test_asn1_skip_integer( &p, end, bits, bits, 1 ) )
+ }
+ if (!mbedtls_test_asn1_skip_integer(&p, end, bits, bits, 1)) {
goto exit;
- if( ! mbedtls_test_asn1_skip_integer( &p, end, 2, bits, 1 ) )
+ }
+ if (!mbedtls_test_asn1_skip_integer(&p, end, 2, bits, 1)) {
goto exit;
+ }
/* Require d to be at least half the size of n. */
- if( ! mbedtls_test_asn1_skip_integer( &p, end, bits / 2, bits, 1 ) )
+ if (!mbedtls_test_asn1_skip_integer(&p, end, bits / 2, bits, 1)) {
goto exit;
+ }
/* Require p and q to be at most half the size of n, rounded up. */
- if( ! mbedtls_test_asn1_skip_integer( &p, end, bits / 2, bits / 2 + 1, 1 ) )
+ if (!mbedtls_test_asn1_skip_integer(&p, end, bits / 2, bits / 2 + 1, 1)) {
goto exit;
- if( ! mbedtls_test_asn1_skip_integer( &p, end, bits / 2, bits / 2 + 1, 1 ) )
+ }
+ if (!mbedtls_test_asn1_skip_integer(&p, end, bits / 2, bits / 2 + 1, 1)) {
goto exit;
- if( ! mbedtls_test_asn1_skip_integer( &p, end, 1, bits / 2 + 1, 0 ) )
+ }
+ if (!mbedtls_test_asn1_skip_integer(&p, end, 1, bits / 2 + 1, 0)) {
goto exit;
- if( ! mbedtls_test_asn1_skip_integer( &p, end, 1, bits / 2 + 1, 0 ) )
+ }
+ if (!mbedtls_test_asn1_skip_integer(&p, end, 1, bits / 2 + 1, 0)) {
goto exit;
- if( ! mbedtls_test_asn1_skip_integer( &p, end, 1, bits / 2 + 1, 0 ) )
+ }
+ if (!mbedtls_test_asn1_skip_integer(&p, end, 1, bits / 2 + 1, 0)) {
goto exit;
- TEST_EQUAL( p - end, 0 );
+ }
+ TEST_EQUAL(p - end, 0);
- TEST_ASSERT( exported_length <= PSA_EXPORT_KEY_PAIR_MAX_SIZE );
- }
- else
+ TEST_ASSERT(exported_length <= PSA_EXPORT_KEY_PAIR_MAX_SIZE);
+ } else
#endif /* MBEDTLS_ASN1_PARSE_C */
#if defined(MBEDTLS_ECP_C)
- if( PSA_KEY_TYPE_IS_ECC_KEY_PAIR( type ) )
- {
+ if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) {
/* Just the secret value */
- TEST_EQUAL( exported_length, PSA_BITS_TO_BYTES( bits ) );
+ TEST_EQUAL(exported_length, PSA_BITS_TO_BYTES(bits));
- TEST_ASSERT( exported_length <= PSA_EXPORT_KEY_PAIR_MAX_SIZE );
- }
- else
+ TEST_ASSERT(exported_length <= PSA_EXPORT_KEY_PAIR_MAX_SIZE);
+ } else
#endif /* MBEDTLS_ECP_C */
#if defined(MBEDTLS_ASN1_PARSE_C)
- if( type == PSA_KEY_TYPE_RSA_PUBLIC_KEY )
- {
- uint8_t *p = (uint8_t*) exported;
+ if (type == PSA_KEY_TYPE_RSA_PUBLIC_KEY) {
+ uint8_t *p = (uint8_t *) exported;
const uint8_t *end = exported + exported_length;
size_t len;
/* RSAPublicKey ::= SEQUENCE {
* modulus INTEGER, -- n
* publicExponent INTEGER } -- e
*/
- TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len,
- MBEDTLS_ASN1_SEQUENCE |
- MBEDTLS_ASN1_CONSTRUCTED ),
- 0 );
- TEST_EQUAL( len, end - p );
- if( ! mbedtls_test_asn1_skip_integer( &p, end, bits, bits, 1 ) )
+ TEST_EQUAL(mbedtls_asn1_get_tag(&p, end, &len,
+ MBEDTLS_ASN1_SEQUENCE |
+ MBEDTLS_ASN1_CONSTRUCTED),
+ 0);
+ TEST_EQUAL(len, end - p);
+ if (!mbedtls_test_asn1_skip_integer(&p, end, bits, bits, 1)) {
goto exit;
- if( ! mbedtls_test_asn1_skip_integer( &p, end, 2, bits, 1 ) )
+ }
+ if (!mbedtls_test_asn1_skip_integer(&p, end, 2, bits, 1)) {
goto exit;
- TEST_EQUAL( p - end, 0 );
+ }
+ TEST_EQUAL(p - end, 0);
- TEST_ASSERT( exported_length <=
- PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( type, bits ) );
- TEST_ASSERT( exported_length <=
- PSA_EXPORT_PUBLIC_KEY_MAX_SIZE );
- }
- else
+ TEST_ASSERT(exported_length <=
+ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(type, bits));
+ TEST_ASSERT(exported_length <=
+ PSA_EXPORT_PUBLIC_KEY_MAX_SIZE);
+ } else
#endif /* MBEDTLS_ASN1_PARSE_C */
#if defined(MBEDTLS_ECP_C)
- if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( type ) )
- {
+ if (PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type)) {
- TEST_ASSERT( exported_length <=
- PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( type, bits ) );
- TEST_ASSERT( exported_length <=
- PSA_EXPORT_PUBLIC_KEY_MAX_SIZE );
+ TEST_ASSERT(exported_length <=
+ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(type, bits));
+ TEST_ASSERT(exported_length <=
+ PSA_EXPORT_PUBLIC_KEY_MAX_SIZE);
- if( PSA_KEY_TYPE_ECC_GET_FAMILY( type ) == PSA_ECC_FAMILY_MONTGOMERY )
- {
+ if (PSA_KEY_TYPE_ECC_GET_FAMILY(type) == PSA_ECC_FAMILY_MONTGOMERY) {
/* The representation of an ECC Montgomery public key is
* the raw compressed point */
- TEST_EQUAL( PSA_BITS_TO_BYTES( bits ), exported_length );
- }
- else
- {
+ TEST_EQUAL(PSA_BITS_TO_BYTES(bits), exported_length);
+ } else {
/* The representation of an ECC Weierstrass public key is:
* - The byte 0x04;
* - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
* - `y_P` as a `ceiling(m/8)`-byte string, big-endian;
* - where m is the bit size associated with the curve.
*/
- TEST_EQUAL( 1 + 2 * PSA_BITS_TO_BYTES( bits ), exported_length );
- TEST_EQUAL( exported[0], 4 );
+ TEST_EQUAL(1 + 2 * PSA_BITS_TO_BYTES(bits), exported_length);
+ TEST_EQUAL(exported[0], 4);
}
- }
- else
+ } else
#endif /* MBEDTLS_ECP_C */
{
(void) exported;
- TEST_ASSERT( ! "Sanity check not implemented for this key type" );
+ TEST_ASSERT(!"Sanity check not implemented for this key type");
}
#if defined(MBEDTLS_DES_C)
- if( type == PSA_KEY_TYPE_DES )
- {
+ if (type == PSA_KEY_TYPE_DES) {
/* Check the parity bits. */
unsigned i;
- for( i = 0; i < bits / 8; i++ )
- {
+ for (i = 0; i < bits / 8; i++) {
unsigned bit_count = 0;
unsigned m;
- for( m = 1; m <= 0x100; m <<= 1 )
- {
- if( exported[i] & m )
+ for (m = 1; m <= 0x100; m <<= 1) {
+ if (exported[i] & m) {
++bit_count;
+ }
}
- TEST_ASSERT( bit_count % 2 != 0 );
+ TEST_ASSERT(bit_count % 2 != 0);
}
}
#endif
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
-static int exercise_export_key( mbedtls_svc_key_id_t key,
- psa_key_usage_t usage )
+static int exercise_export_key(mbedtls_svc_key_id_t key,
+ psa_key_usage_t usage)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *exported = NULL;
@@ -862,42 +828,41 @@
size_t exported_length = 0;
int ok = 0;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
exported_size = PSA_EXPORT_KEY_OUTPUT_SIZE(
- psa_get_key_type( &attributes ),
- psa_get_key_bits( &attributes ) );
- ASSERT_ALLOC( exported, exported_size );
+ psa_get_key_type(&attributes),
+ psa_get_key_bits(&attributes));
+ ASSERT_ALLOC(exported, exported_size);
- if( ( usage & PSA_KEY_USAGE_EXPORT ) == 0 &&
- ! PSA_KEY_TYPE_IS_PUBLIC_KEY( psa_get_key_type( &attributes ) ) )
- {
- TEST_EQUAL( psa_export_key( key, exported,
- exported_size, &exported_length ),
- PSA_ERROR_NOT_PERMITTED );
+ if ((usage & PSA_KEY_USAGE_EXPORT) == 0 &&
+ !PSA_KEY_TYPE_IS_PUBLIC_KEY(psa_get_key_type(&attributes))) {
+ TEST_EQUAL(psa_export_key(key, exported,
+ exported_size, &exported_length),
+ PSA_ERROR_NOT_PERMITTED);
ok = 1;
goto exit;
}
- PSA_ASSERT( psa_export_key( key,
- exported, exported_size,
- &exported_length ) );
+ PSA_ASSERT(psa_export_key(key,
+ exported, exported_size,
+ &exported_length));
ok = mbedtls_test_psa_exported_key_sanity_check(
- psa_get_key_type( &attributes ), psa_get_key_bits( &attributes ),
- exported, exported_length );
+ psa_get_key_type(&attributes), psa_get_key_bits(&attributes),
+ exported, exported_length);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_free( exported );
- return( ok );
+ mbedtls_free(exported);
+ return ok;
}
-static int exercise_export_public_key( mbedtls_svc_key_id_t key )
+static int exercise_export_public_key(mbedtls_svc_key_id_t key)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t public_type;
@@ -906,119 +871,113 @@
size_t exported_length = 0;
int ok = 0;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( psa_get_key_type( &attributes ) ) )
- {
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ if (!PSA_KEY_TYPE_IS_ASYMMETRIC(psa_get_key_type(&attributes))) {
exported_size = PSA_EXPORT_KEY_OUTPUT_SIZE(
- psa_get_key_type( &attributes ),
- psa_get_key_bits( &attributes ) );
- ASSERT_ALLOC( exported, exported_size );
+ psa_get_key_type(&attributes),
+ psa_get_key_bits(&attributes));
+ ASSERT_ALLOC(exported, exported_size);
- TEST_EQUAL( psa_export_public_key( key, exported,
- exported_size, &exported_length ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_export_public_key(key, exported,
+ exported_size, &exported_length),
+ PSA_ERROR_INVALID_ARGUMENT);
ok = 1;
goto exit;
}
public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(
- psa_get_key_type( &attributes ) );
- exported_size = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( public_type,
- psa_get_key_bits( &attributes ) );
- ASSERT_ALLOC( exported, exported_size );
+ psa_get_key_type(&attributes));
+ exported_size = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_type,
+ psa_get_key_bits(&attributes));
+ ASSERT_ALLOC(exported, exported_size);
- PSA_ASSERT( psa_export_public_key( key,
- exported, exported_size,
- &exported_length ) );
+ PSA_ASSERT(psa_export_public_key(key,
+ exported, exported_size,
+ &exported_length));
ok = mbedtls_test_psa_exported_key_sanity_check(
- public_type, psa_get_key_bits( &attributes ),
- exported, exported_length );
+ public_type, psa_get_key_bits(&attributes),
+ exported, exported_length);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_free( exported );
- return( ok );
+ mbedtls_free(exported);
+ return ok;
}
-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)
{
int ok = 0;
- if( ! check_key_attributes_sanity( key ) )
- return( 0 );
+ if (!check_key_attributes_sanity(key)) {
+ return 0;
+ }
- if( alg == 0 )
+ if (alg == 0) {
ok = 1; /* If no algorithm, do nothing (used for raw data "keys"). */
- else if( PSA_ALG_IS_MAC( alg ) )
- ok = exercise_mac_key( key, usage, alg );
- else if( PSA_ALG_IS_CIPHER( alg ) )
- ok = exercise_cipher_key( key, usage, alg );
- else if( PSA_ALG_IS_AEAD( alg ) )
- ok = exercise_aead_key( key, usage, alg );
- else if( PSA_ALG_IS_SIGN( alg ) )
- ok = exercise_signature_key( key, usage, alg );
- else if( PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) )
- ok = exercise_asymmetric_encryption_key( key, usage, alg );
- else if( PSA_ALG_IS_KEY_DERIVATION( alg ) )
- ok = exercise_key_derivation_key( key, usage, alg );
- else if( PSA_ALG_IS_RAW_KEY_AGREEMENT( alg ) )
- ok = exercise_raw_key_agreement_key( key, usage, alg );
- else if( PSA_ALG_IS_KEY_AGREEMENT( alg ) )
- ok = exercise_key_agreement_key( key, usage, alg );
- else
- TEST_ASSERT( ! "No code to exercise this category of algorithm" );
+ } else if (PSA_ALG_IS_MAC(alg)) {
+ ok = exercise_mac_key(key, usage, alg);
+ } else if (PSA_ALG_IS_CIPHER(alg)) {
+ ok = exercise_cipher_key(key, usage, alg);
+ } else if (PSA_ALG_IS_AEAD(alg)) {
+ ok = exercise_aead_key(key, usage, alg);
+ } else if (PSA_ALG_IS_SIGN(alg)) {
+ ok = exercise_signature_key(key, usage, alg);
+ } else if (PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg)) {
+ ok = exercise_asymmetric_encryption_key(key, usage, alg);
+ } else if (PSA_ALG_IS_KEY_DERIVATION(alg)) {
+ ok = exercise_key_derivation_key(key, usage, alg);
+ } else if (PSA_ALG_IS_RAW_KEY_AGREEMENT(alg)) {
+ ok = exercise_raw_key_agreement_key(key, usage, alg);
+ } else if (PSA_ALG_IS_KEY_AGREEMENT(alg)) {
+ ok = exercise_key_agreement_key(key, usage, alg);
+ } else {
+ TEST_ASSERT(!"No code to exercise this category of algorithm");
+ }
- ok = ok && exercise_export_key( key, usage );
- ok = ok && exercise_export_public_key( key );
+ ok = ok && exercise_export_key(key, usage);
+ ok = ok && exercise_export_public_key(key);
exit:
- return( ok );
+ return ok;
}
-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)
{
- if( PSA_ALG_IS_MAC( alg ) || PSA_ALG_IS_SIGN( alg ) )
- {
- if( PSA_ALG_IS_SIGN_HASH( alg ) )
- {
- if( PSA_ALG_SIGN_GET_HASH( alg ) )
- return( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ?
- PSA_KEY_USAGE_VERIFY_HASH | PSA_KEY_USAGE_VERIFY_MESSAGE:
- PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH |
- PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE );
+ if (PSA_ALG_IS_MAC(alg) || PSA_ALG_IS_SIGN(alg)) {
+ if (PSA_ALG_IS_SIGN_HASH(alg)) {
+ if (PSA_ALG_SIGN_GET_HASH(alg)) {
+ return PSA_KEY_TYPE_IS_PUBLIC_KEY(type) ?
+ PSA_KEY_USAGE_VERIFY_HASH | PSA_KEY_USAGE_VERIFY_MESSAGE :
+ PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH |
+ PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE;
+ }
+ } else if (PSA_ALG_IS_SIGN_MESSAGE(alg)) {
+ return PSA_KEY_TYPE_IS_PUBLIC_KEY(type) ?
+ PSA_KEY_USAGE_VERIFY_MESSAGE :
+ PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE;
}
- else if( PSA_ALG_IS_SIGN_MESSAGE( alg) )
- return( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ?
- PSA_KEY_USAGE_VERIFY_MESSAGE :
- PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE );
- return( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ?
- PSA_KEY_USAGE_VERIFY_HASH :
- PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH );
- }
- else if( PSA_ALG_IS_CIPHER( alg ) || PSA_ALG_IS_AEAD( alg ) ||
- PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) )
- {
- return( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ?
- PSA_KEY_USAGE_ENCRYPT :
- PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- }
- else if( PSA_ALG_IS_KEY_DERIVATION( alg ) ||
- PSA_ALG_IS_KEY_AGREEMENT( alg ) )
- {
- return( PSA_KEY_USAGE_DERIVE );
- }
- else
- {
- return( 0 );
+ return PSA_KEY_TYPE_IS_PUBLIC_KEY(type) ?
+ PSA_KEY_USAGE_VERIFY_HASH :
+ PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH;
+ } else if (PSA_ALG_IS_CIPHER(alg) || PSA_ALG_IS_AEAD(alg) ||
+ PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg)) {
+ return PSA_KEY_TYPE_IS_PUBLIC_KEY(type) ?
+ PSA_KEY_USAGE_ENCRYPT :
+ PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
+ } else if (PSA_ALG_IS_KEY_DERIVATION(alg) ||
+ PSA_ALG_IS_KEY_AGREEMENT(alg)) {
+ return PSA_KEY_USAGE_DERIVE;
+ } else {
+ return 0;
}
}
diff --git a/tests/src/random.c b/tests/src/random.c
index 7f3f401..e74e689 100644
--- a/tests/src/random.c
+++ b/tests/src/random.c
@@ -37,109 +37,111 @@
#include <mbedtls/entropy.h>
-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)
{
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
size_t i;
- if( rng_state != NULL )
+ if (rng_state != NULL) {
rng_state = NULL;
+ }
- for( i = 0; i < len; ++i )
+ for (i = 0; i < len; ++i) {
output[i] = rand();
+ }
#else
- if( rng_state != NULL )
+ if (rng_state != NULL) {
rng_state = NULL;
+ }
- arc4random_buf( output, len );
+ arc4random_buf(output, len);
#endif /* !OpenBSD && !NetBSD */
- return( 0 );
+ return 0;
}
-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)
{
- if( rng_state != NULL )
+ if (rng_state != NULL) {
rng_state = NULL;
+ }
- memset( output, 0, len );
+ memset(output, 0, len);
- return( 0 );
+ return 0;
}
-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)
{
mbedtls_test_rnd_buf_info *info = (mbedtls_test_rnd_buf_info *) rng_state;
size_t use_len;
- if( rng_state == NULL )
- return( mbedtls_test_rnd_std_rand( NULL, output, len ) );
+ if (rng_state == NULL) {
+ return mbedtls_test_rnd_std_rand(NULL, output, len);
+ }
use_len = len;
- if( len > info->length )
+ if (len > info->length) {
use_len = info->length;
+ }
- if( use_len )
- {
- memcpy( output, info->buf, use_len );
+ if (use_len) {
+ memcpy(output, info->buf, use_len);
info->buf += use_len;
info->length -= use_len;
}
- if( len - use_len > 0 )
- {
- if( info->fallback_f_rng != NULL )
- {
- return( info->fallback_f_rng( info->fallback_p_rng,
- output + use_len,
- len - use_len ) );
+ if (len - use_len > 0) {
+ if (info->fallback_f_rng != NULL) {
+ return info->fallback_f_rng(info->fallback_p_rng,
+ output + use_len,
+ len - use_len);
+ } else {
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
- else
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
}
- return( 0 );
+ return 0;
}
-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)
{
mbedtls_test_rnd_pseudo_info *info =
(mbedtls_test_rnd_pseudo_info *) rng_state;
- uint32_t i, *k, sum, delta=0x9E3779B9;
+ uint32_t i, *k, sum, delta = 0x9E3779B9;
unsigned char result[4], *out = output;
- if( rng_state == NULL )
- return( mbedtls_test_rnd_std_rand( NULL, output, len ) );
+ if (rng_state == NULL) {
+ return mbedtls_test_rnd_std_rand(NULL, output, len);
+ }
k = info->key;
- while( len > 0 )
- {
- size_t use_len = ( len > 4 ) ? 4 : len;
+ while (len > 0) {
+ size_t use_len = (len > 4) ? 4 : len;
sum = 0;
- for( i = 0; i < 32; i++ )
- {
- info->v0 += ( ( ( info->v1 << 4 ) ^ ( info->v1 >> 5 ) )
- + info->v1 ) ^ ( sum + k[sum & 3] );
+ for (i = 0; i < 32; i++) {
+ info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5))
+ + info->v1) ^ (sum + k[sum & 3]);
sum += delta;
- info->v1 += ( ( ( info->v0 << 4 ) ^ ( info->v0 >> 5 ) )
- + info->v0 ) ^ ( sum + k[( sum>>11 ) & 3] );
+ info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5))
+ + info->v0) ^ (sum + k[(sum>>11) & 3]);
}
- PUT_UINT32_BE( info->v0, result, 0 );
- memcpy( out, result, use_len );
+ PUT_UINT32_BE(info->v0, result, 0);
+ memcpy(out, result, use_len);
len -= use_len;
out += 4;
}
- return( 0 );
+ return 0;
}
diff --git a/tests/src/threading_helpers.c b/tests/src/threading_helpers.c
index ca91b79..ae6e590 100644
--- a/tests/src/threading_helpers.c
+++ b/tests/src/threading_helpers.c
@@ -70,8 +70,7 @@
* indicate the exact location of the problematic call. To locate the error,
* use a debugger and set a breakpoint on mbedtls_test_mutex_usage_error().
*/
-enum value_of_mutex_is_valid_field
-{
+enum value_of_mutex_is_valid_field {
/* Potential values for the is_valid field of mbedtls_threading_mutex_t.
* Note that MUTEX_FREED must be 0 and MUTEX_IDLE must be 1 for
* compatibility with threading_mutex_init_pthread() and
@@ -82,12 +81,11 @@
MUTEX_LOCKED = 2, //!< Set by our lock
};
-typedef struct
-{
- void (*init)( mbedtls_threading_mutex_t * );
- void (*free)( mbedtls_threading_mutex_t * );
- int (*lock)( mbedtls_threading_mutex_t * );
- int (*unlock)( mbedtls_threading_mutex_t * );
+typedef struct {
+ void (*init)(mbedtls_threading_mutex_t *);
+ void (*free)(mbedtls_threading_mutex_t *);
+ int (*lock)(mbedtls_threading_mutex_t *);
+ int (*unlock)(mbedtls_threading_mutex_t *);
} mutex_functions_t;
static mutex_functions_t mutex_functions;
@@ -98,94 +96,96 @@
*/
static int live_mutexes;
-static void mbedtls_test_mutex_usage_error( mbedtls_threading_mutex_t *mutex,
- const char *msg )
+static void mbedtls_test_mutex_usage_error(mbedtls_threading_mutex_t *mutex,
+ const char *msg)
{
(void) mutex;
- if( mbedtls_test_info.mutex_usage_error == NULL )
+ if (mbedtls_test_info.mutex_usage_error == NULL) {
mbedtls_test_info.mutex_usage_error = msg;
- mbedtls_fprintf( stdout, "[mutex: %s] ", msg );
+ }
+ mbedtls_fprintf(stdout, "[mutex: %s] ", msg);
/* Don't mark the test as failed yet. This way, if the test fails later
* for a functional reason, the test framework will report the message
* and location for this functional reason. If the test passes,
* mbedtls_test_mutex_usage_check() will mark it as failed. */
}
-static void mbedtls_test_wrap_mutex_init( mbedtls_threading_mutex_t *mutex )
+static void mbedtls_test_wrap_mutex_init(mbedtls_threading_mutex_t *mutex)
{
- mutex_functions.init( mutex );
- if( mutex->is_valid )
+ mutex_functions.init(mutex);
+ if (mutex->is_valid) {
++live_mutexes;
+ }
}
-static void mbedtls_test_wrap_mutex_free( mbedtls_threading_mutex_t *mutex )
+static void mbedtls_test_wrap_mutex_free(mbedtls_threading_mutex_t *mutex)
{
- switch( mutex->is_valid )
- {
+ switch (mutex->is_valid) {
case MUTEX_FREED:
- mbedtls_test_mutex_usage_error( mutex, "free without init or double free" );
+ mbedtls_test_mutex_usage_error(mutex, "free without init or double free");
break;
case MUTEX_IDLE:
/* Do nothing. The underlying free function will reset is_valid
* to 0. */
break;
case MUTEX_LOCKED:
- mbedtls_test_mutex_usage_error( mutex, "free without unlock" );
+ mbedtls_test_mutex_usage_error(mutex, "free without unlock");
break;
default:
- mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
+ mbedtls_test_mutex_usage_error(mutex, "corrupted state");
break;
}
- if( mutex->is_valid )
+ if (mutex->is_valid) {
--live_mutexes;
- mutex_functions.free( mutex );
+ }
+ mutex_functions.free(mutex);
}
-static int mbedtls_test_wrap_mutex_lock( mbedtls_threading_mutex_t *mutex )
+static int mbedtls_test_wrap_mutex_lock(mbedtls_threading_mutex_t *mutex)
{
- int ret = mutex_functions.lock( mutex );
- switch( mutex->is_valid )
- {
+ int ret = mutex_functions.lock(mutex);
+ switch (mutex->is_valid) {
case MUTEX_FREED:
- mbedtls_test_mutex_usage_error( mutex, "lock without init" );
+ mbedtls_test_mutex_usage_error(mutex, "lock without init");
break;
case MUTEX_IDLE:
- if( ret == 0 )
+ if (ret == 0) {
mutex->is_valid = 2;
+ }
break;
case MUTEX_LOCKED:
- mbedtls_test_mutex_usage_error( mutex, "double lock" );
+ mbedtls_test_mutex_usage_error(mutex, "double lock");
break;
default:
- mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
+ mbedtls_test_mutex_usage_error(mutex, "corrupted state");
break;
}
- return( ret );
+ return ret;
}
-static int mbedtls_test_wrap_mutex_unlock( mbedtls_threading_mutex_t *mutex )
+static int mbedtls_test_wrap_mutex_unlock(mbedtls_threading_mutex_t *mutex)
{
- int ret = mutex_functions.unlock( mutex );
- switch( mutex->is_valid )
- {
+ int ret = mutex_functions.unlock(mutex);
+ switch (mutex->is_valid) {
case MUTEX_FREED:
- mbedtls_test_mutex_usage_error( mutex, "unlock without init" );
+ mbedtls_test_mutex_usage_error(mutex, "unlock without init");
break;
case MUTEX_IDLE:
- mbedtls_test_mutex_usage_error( mutex, "unlock without lock" );
+ mbedtls_test_mutex_usage_error(mutex, "unlock without lock");
break;
case MUTEX_LOCKED:
- if( ret == 0 )
+ if (ret == 0) {
mutex->is_valid = MUTEX_IDLE;
+ }
break;
default:
- mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
+ mbedtls_test_mutex_usage_error(mutex, "corrupted state");
break;
}
- return( ret );
+ return ret;
}
-void mbedtls_test_mutex_usage_init( void )
+void mbedtls_test_mutex_usage_init(void)
{
mutex_functions.init = mbedtls_mutex_init;
mutex_functions.free = mbedtls_mutex_free;
@@ -197,25 +197,24 @@
mbedtls_mutex_unlock = &mbedtls_test_wrap_mutex_unlock;
}
-void mbedtls_test_mutex_usage_check( void )
+void mbedtls_test_mutex_usage_check(void)
{
- if( live_mutexes != 0 )
- {
+ if (live_mutexes != 0) {
/* A positive number (more init than free) means that a mutex resource
* is leaking (on platforms where a mutex consumes more than the
* mbedtls_threading_mutex_t object itself). The rare case of a
* negative number means a missing init somewhere. */
- mbedtls_fprintf( stdout, "[mutex: %d leaked] ", live_mutexes );
+ mbedtls_fprintf(stdout, "[mutex: %d leaked] ", live_mutexes);
live_mutexes = 0;
- if( mbedtls_test_info.mutex_usage_error == NULL )
+ if (mbedtls_test_info.mutex_usage_error == NULL) {
mbedtls_test_info.mutex_usage_error = "missing free";
+ }
}
- if( mbedtls_test_info.mutex_usage_error != NULL &&
- mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED )
- {
+ if (mbedtls_test_info.mutex_usage_error != NULL &&
+ mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED) {
/* Functionally, the test passed. But there was a mutex usage error,
* so mark the test as failed after all. */
- mbedtls_test_fail( "Mutex usage error", __LINE__, __FILE__ );
+ mbedtls_test_fail("Mutex usage error", __LINE__, __FILE__);
}
mbedtls_test_info.mutex_usage_error = NULL;
}
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index 8249564..313459e 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -10,7 +10,7 @@
#include <stdlib.h>
-#if defined (MBEDTLS_ERROR_C)
+#if defined(MBEDTLS_ERROR_C)
#include "mbedtls/error.h"
#endif
#include "mbedtls/platform.h"
@@ -66,9 +66,9 @@
/* Indicates whether we expect mbedtls_entropy_init
* to initialize some strong entropy source. */
#if !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) && \
- ( !defined(MBEDTLS_NO_PLATFORM_ENTROPY) || \
- defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
- defined(ENTROPY_NV_SEED) )
+ (!defined(MBEDTLS_NO_PLATFORM_ENTROPY) || \
+ defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
+ defined(ENTROPY_NV_SEED))
#define ENTROPY_HAVE_STRONG
#endif
@@ -83,65 +83,60 @@
*
* \return 0 if the key store is empty, 1 otherwise.
*/
-int test_fail_if_psa_leaking( int line_no, const char *filename )
+int test_fail_if_psa_leaking(int line_no, const char *filename)
{
- const char *msg = mbedtls_test_helper_is_psa_leaking( );
- if( msg == NULL )
+ const char *msg = mbedtls_test_helper_is_psa_leaking();
+ if (msg == NULL) {
return 0;
- else
- {
- mbedtls_test_fail( msg, line_no, filename );
+ } else {
+ mbedtls_test_fail(msg, line_no, filename);
return 1;
}
}
#endif /* defined(MBEDTLS_PSA_CRYPTO_C) */
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-static int redirect_output( FILE* out_stream, const char* path )
+static int redirect_output(FILE *out_stream, const char *path)
{
int out_fd, dup_fd;
- FILE* path_stream;
+ FILE *path_stream;
- out_fd = fileno( out_stream );
- dup_fd = dup( out_fd );
+ out_fd = fileno(out_stream);
+ dup_fd = dup(out_fd);
- if( dup_fd == -1 )
- {
- return( -1 );
+ if (dup_fd == -1) {
+ return -1;
}
- path_stream = fopen( path, "w" );
- if( path_stream == NULL )
- {
- close( dup_fd );
- return( -1 );
+ path_stream = fopen(path, "w");
+ if (path_stream == NULL) {
+ close(dup_fd);
+ return -1;
}
- fflush( out_stream );
- if( dup2( fileno( path_stream ), out_fd ) == -1 )
- {
- close( dup_fd );
- fclose( path_stream );
- return( -1 );
+ fflush(out_stream);
+ if (dup2(fileno(path_stream), out_fd) == -1) {
+ close(dup_fd);
+ fclose(path_stream);
+ return -1;
}
- fclose( path_stream );
- return( dup_fd );
+ fclose(path_stream);
+ return dup_fd;
}
-static int restore_output( FILE* out_stream, int dup_fd )
+static int restore_output(FILE *out_stream, int dup_fd)
{
- int out_fd = fileno( out_stream );
+ int out_fd = fileno(out_stream);
- fflush( out_stream );
- if( dup2( dup_fd, out_fd ) == -1 )
- {
- close( out_fd );
- close( dup_fd );
- return( -1 );
+ fflush(out_stream);
+ if (dup2(dup_fd, out_fd) == -1) {
+ close(out_fd);
+ close(dup_fd);
+ return -1;
}
- close( dup_fd );
- return( 0 );
+ close(dup_fd);
+ return 0;
}
#endif /* __unix__ || __APPLE__ __MACH__ */
diff --git a/tests/suites/host_test.function b/tests/suites/host_test.function
index bb06822..475a9c8 100644
--- a/tests/suites/host_test.function
+++ b/tests/suites/host_test.function
@@ -8,20 +8,19 @@
*
* \return 0 if success else 1
*/
-int verify_string( char **str )
+int verify_string(char **str)
{
- if( ( *str )[0] != '"' ||
- ( *str )[strlen( *str ) - 1] != '"' )
- {
- mbedtls_fprintf( stderr,
- "Expected string (with \"\") for parameter and got: %s\n", *str );
- return( -1 );
+ if ((*str)[0] != '"' ||
+ (*str)[strlen(*str) - 1] != '"') {
+ mbedtls_fprintf(stderr,
+ "Expected string (with \"\") for parameter and got: %s\n", *str);
+ return -1;
}
- ( *str )++;
- ( *str )[strlen( *str ) - 1] = '\0';
+ (*str)++;
+ (*str)[strlen(*str) - 1] = '\0';
- return( 0 );
+ return 0;
}
/**
@@ -33,50 +32,46 @@
*
* \return 0 if success else 1
*/
-int verify_int( char *str, int32_t *value )
+int verify_int(char *str, int32_t *value)
{
size_t i;
int minus = 0;
int digits = 1;
int hex = 0;
- for( i = 0; i < strlen( str ); i++ )
- {
- if( i == 0 && str[i] == '-' )
- {
+ for (i = 0; i < strlen(str); i++) {
+ if (i == 0 && str[i] == '-') {
minus = 1;
continue;
}
- if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
- str[i - 1] == '0' && ( str[i] == 'x' || str[i] == 'X' ) )
- {
+ if (((minus && i == 2) || (!minus && i == 1)) &&
+ str[i - 1] == '0' && (str[i] == 'x' || str[i] == 'X')) {
hex = 1;
continue;
}
- if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
- ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
- ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
- {
+ if (!((str[i] >= '0' && str[i] <= '9') ||
+ (hex && ((str[i] >= 'a' && str[i] <= 'f') ||
+ (str[i] >= 'A' && str[i] <= 'F'))))) {
digits = 0;
break;
}
}
- if( digits )
- {
- if( hex )
- *value = strtol( str, NULL, 16 );
- else
- *value = strtol( str, NULL, 10 );
+ if (digits) {
+ if (hex) {
+ *value = strtol(str, NULL, 16);
+ } else {
+ *value = strtol(str, NULL, 10);
+ }
- return( 0 );
+ return 0;
}
- mbedtls_fprintf( stderr,
- "Expected integer for parameter and got: %s\n", str );
- return( KEY_VALUE_MAPPING_NOT_FOUND );
+ mbedtls_fprintf(stderr,
+ "Expected integer for parameter and got: %s\n", str);
+ return KEY_VALUE_MAPPING_NOT_FOUND;
}
@@ -107,44 +102,45 @@
*
* \return 0 if success else -1
*/
-int get_line( FILE *f, char *buf, size_t len )
+int get_line(FILE *f, char *buf, size_t len)
{
char *ret;
int i = 0, str_len = 0, has_string = 0;
/* Read until we get a valid line */
- do
- {
- ret = fgets( buf, len, f );
- if( ret == NULL )
- return( -1 );
+ do {
+ ret = fgets(buf, len, f);
+ if (ret == NULL) {
+ return -1;
+ }
- str_len = strlen( buf );
+ str_len = strlen(buf);
/* Skip empty line and comment */
- if ( str_len == 0 || buf[0] == '#' )
+ if (str_len == 0 || buf[0] == '#') {
continue;
+ }
has_string = 0;
- for ( i = 0; i < str_len; i++ )
- {
+ for (i = 0; i < str_len; i++) {
char c = buf[i];
- if ( c != ' ' && c != '\t' && c != '\n' &&
- c != '\v' && c != '\f' && c != '\r' )
- {
+ if (c != ' ' && c != '\t' && c != '\n' &&
+ c != '\v' && c != '\f' && c != '\r') {
has_string = 1;
break;
}
}
- } while( !has_string );
+ } while (!has_string);
/* Strip new line and carriage return */
- ret = buf + strlen( buf );
- if( ret-- > buf && *ret == '\n' )
+ ret = buf + strlen(buf);
+ if (ret-- > buf && *ret == '\n') {
*ret = '\0';
- if( ret-- > buf && *ret == '\r' )
+ }
+ if (ret-- > buf && *ret == '\r') {
*ret = '\0';
+ }
- return( 0 );
+ return 0;
}
/**
@@ -157,8 +153,8 @@
*
* \return Count of strings found.
*/
-static int parse_arguments( char *buf, size_t len, char **params,
- size_t params_len )
+static int parse_arguments(char *buf, size_t len, char **params,
+ size_t params_len)
{
size_t cnt = 0, i;
char *cur = buf;
@@ -166,20 +162,16 @@
params[cnt++] = cur;
- while( *p != '\0' && p < ( buf + len ) )
- {
- if( *p == '\\' )
- {
+ while (*p != '\0' && p < (buf + len)) {
+ if (*p == '\\') {
p++;
p++;
continue;
}
- if( *p == ':' )
- {
- if( p + 1 < buf + len )
- {
+ if (*p == ':') {
+ if (p + 1 < buf + len) {
cur = p + 1;
- TEST_HELPER_ASSERT( cnt < params_len );
+ TEST_HELPER_ASSERT(cnt < params_len);
params[cnt++] = cur;
}
*p = '\0';
@@ -189,35 +181,28 @@
}
/* Replace newlines, question marks and colons in strings */
- for( i = 0; i < cnt; i++ )
- {
+ for (i = 0; i < cnt; i++) {
p = params[i];
q = params[i];
- while( *p != '\0' )
- {
- if( *p == '\\' && *( p + 1 ) == 'n' )
- {
+ while (*p != '\0') {
+ if (*p == '\\' && *(p + 1) == 'n') {
p += 2;
- *( q++ ) = '\n';
- }
- else if( *p == '\\' && *( p + 1 ) == ':' )
- {
+ *(q++) = '\n';
+ } else if (*p == '\\' && *(p + 1) == ':') {
p += 2;
- *( q++ ) = ':';
- }
- else if( *p == '\\' && *( p + 1 ) == '?' )
- {
+ *(q++) = ':';
+ } else if (*p == '\\' && *(p + 1) == '?') {
p += 2;
- *( q++ ) = '?';
+ *(q++) = '?';
+ } else {
+ *(q++) = *(p++);
}
- else
- *( q++ ) = *( p++ );
}
*q = '\0';
}
- return( cnt );
+ return cnt;
}
/**
@@ -238,81 +223,59 @@
*
* \return 0 for success else 1
*/
-static int convert_params( size_t cnt , char ** params , int32_t * int_params_store )
+static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
{
- char ** cur = params;
- char ** out = params;
+ char **cur = params;
+ char **out = params;
int ret = DISPATCH_TEST_SUCCESS;
- while ( cur < params + cnt )
- {
- char * type = *cur++;
- char * val = *cur++;
+ while (cur < params + cnt) {
+ char *type = *cur++;
+ char *val = *cur++;
- if ( strcmp( type, "char*" ) == 0 )
- {
- if ( verify_string( &val ) == 0 )
- {
- *out++ = val;
- }
- else
- {
- ret = ( DISPATCH_INVALID_TEST_DATA );
+ if (strcmp(type, "char*") == 0) {
+ if (verify_string(&val) == 0) {
+ *out++ = val;
+ } else {
+ ret = (DISPATCH_INVALID_TEST_DATA);
break;
}
- }
- else if ( strcmp( type, "int" ) == 0 )
- {
- if ( verify_int( val, int_params_store ) == 0 )
- {
- *out++ = (char *) int_params_store++;
- }
- else
- {
- ret = ( DISPATCH_INVALID_TEST_DATA );
+ } else if (strcmp(type, "int") == 0) {
+ if (verify_int(val, int_params_store) == 0) {
+ *out++ = (char *) int_params_store++;
+ } else {
+ ret = (DISPATCH_INVALID_TEST_DATA);
break;
}
- }
- else if ( strcmp( type, "hex" ) == 0 )
- {
- if ( verify_string( &val ) == 0 )
- {
+ } else if (strcmp(type, "hex") == 0) {
+ if (verify_string(&val) == 0) {
size_t len;
TEST_HELPER_ASSERT(
- mbedtls_test_unhexify( (unsigned char *) val, strlen( val ),
- val, &len ) == 0 );
+ mbedtls_test_unhexify((unsigned char *) val, strlen(val),
+ val, &len) == 0);
*int_params_store = len;
*out++ = val;
- *out++ = (char *)(int_params_store++);
- }
- else
- {
- ret = ( DISPATCH_INVALID_TEST_DATA );
+ *out++ = (char *) (int_params_store++);
+ } else {
+ ret = (DISPATCH_INVALID_TEST_DATA);
break;
}
- }
- else if ( strcmp( type, "exp" ) == 0 )
- {
- int exp_id = strtol( val, NULL, 10 );
- if ( get_expression ( exp_id, int_params_store ) == 0 )
- {
- *out++ = (char *)int_params_store++;
+ } else if (strcmp(type, "exp") == 0) {
+ int exp_id = strtol(val, NULL, 10);
+ if (get_expression(exp_id, int_params_store) == 0) {
+ *out++ = (char *) int_params_store++;
+ } else {
+ ret = (DISPATCH_INVALID_TEST_DATA);
+ break;
}
- else
- {
- ret = ( DISPATCH_INVALID_TEST_DATA );
- break;
- }
- }
- else
- {
- ret = ( DISPATCH_INVALID_TEST_DATA );
- break;
+ } else {
+ ret = (DISPATCH_INVALID_TEST_DATA);
+ break;
}
}
- return( ret );
+ return ret;
}
/**
@@ -335,26 +298,27 @@
#if defined(__GNUC__)
__attribute__((__noinline__))
#endif
-static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
+static int test_snprintf(size_t n, const char *ref_buf, int ref_ret)
{
int ret;
char buf[10] = "xxxxxxxxx";
const char ref[10] = "xxxxxxxxx";
- if( n >= sizeof( buf ) )
- return( -1 );
- ret = mbedtls_snprintf( buf, n, "%s", "123" );
- if( ret < 0 || (size_t) ret >= n )
+ if (n >= sizeof(buf)) {
+ return -1;
+ }
+ ret = mbedtls_snprintf(buf, n, "%s", "123");
+ if (ret < 0 || (size_t) ret >= n) {
ret = -1;
-
- if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
- ref_ret != ret ||
- memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
- {
- return( 1 );
}
- return( 0 );
+ if (strncmp(ref_buf, buf, sizeof(buf)) != 0 ||
+ ref_ret != ret ||
+ memcmp(buf + n, ref + n, sizeof(buf) - n) != 0) {
+ return 1;
+ }
+
+ return 0;
}
/**
@@ -362,14 +326,14 @@
*
* \return 0 for success else 1
*/
-static int run_test_snprintf( void )
+static int run_test_snprintf(void)
{
- return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
- test_snprintf( 1, "", -1 ) != 0 ||
- test_snprintf( 2, "1", -1 ) != 0 ||
- test_snprintf( 3, "12", -1 ) != 0 ||
- test_snprintf( 4, "123", 3 ) != 0 ||
- test_snprintf( 5, "123", 3 ) != 0 );
+ return test_snprintf(0, "xxxxxxxxx", -1) != 0 ||
+ test_snprintf(1, "", -1) != 0 ||
+ test_snprintf(2, "1", -1) != 0 ||
+ test_snprintf(3, "12", -1) != 0 ||
+ test_snprintf(4, "123", 3) != 0 ||
+ test_snprintf(5, "123", 3) != 0;
}
/** \brief Write the description of the test case to the outcome CSV file.
@@ -379,43 +343,44 @@
* \param argv0 The test suite name.
* \param test_case The test case description.
*/
-static void write_outcome_entry( FILE *outcome_file,
- const char *argv0,
- const char *test_case )
+static void write_outcome_entry(FILE *outcome_file,
+ const char *argv0,
+ const char *test_case)
{
/* The non-varying fields are initialized on first use. */
static const char *platform = NULL;
static const char *configuration = NULL;
static const char *test_suite = NULL;
- if( outcome_file == NULL )
+ if (outcome_file == NULL) {
return;
+ }
- if( platform == NULL )
- {
- platform = getenv( "MBEDTLS_TEST_PLATFORM" );
- if( platform == NULL )
+ if (platform == NULL) {
+ platform = getenv("MBEDTLS_TEST_PLATFORM");
+ if (platform == NULL) {
platform = "unknown";
+ }
}
- if( configuration == NULL )
- {
- configuration = getenv( "MBEDTLS_TEST_CONFIGURATION" );
- if( configuration == NULL )
+ if (configuration == NULL) {
+ configuration = getenv("MBEDTLS_TEST_CONFIGURATION");
+ if (configuration == NULL) {
configuration = "unknown";
+ }
}
- if( test_suite == NULL )
- {
- test_suite = strrchr( argv0, '/' );
- if( test_suite != NULL )
+ if (test_suite == NULL) {
+ test_suite = strrchr(argv0, '/');
+ if (test_suite != NULL) {
test_suite += 1; // skip the '/'
- else
+ } else {
test_suite = argv0;
+ }
}
/* Write the beginning of the outcome line.
* Ignore errors: writing the outcome file is on a best-effort basis. */
- mbedtls_fprintf( outcome_file, "%s;%s;%s;%s;",
- platform, configuration, test_suite, test_case );
+ mbedtls_fprintf(outcome_file, "%s;%s;%s;%s;",
+ platform, configuration, test_suite, test_case);
}
/** \brief Write the result of the test case to the outcome CSV file.
@@ -429,65 +394,63 @@
* \param ret The test dispatch status (DISPATCH_xxx).
* \param info A pointer to the test info structure.
*/
-static void write_outcome_result( FILE *outcome_file,
- size_t unmet_dep_count,
- int unmet_dependencies[],
- int missing_unmet_dependencies,
- int ret,
- const mbedtls_test_info_t *info )
+static void write_outcome_result(FILE *outcome_file,
+ size_t unmet_dep_count,
+ int unmet_dependencies[],
+ int missing_unmet_dependencies,
+ int ret,
+ const mbedtls_test_info_t *info)
{
- if( outcome_file == NULL )
+ if (outcome_file == NULL) {
return;
+ }
/* Write the end of the outcome line.
* Ignore errors: writing the outcome file is on a best-effort basis. */
- switch( ret )
- {
+ switch (ret) {
case DISPATCH_TEST_SUCCESS:
- if( unmet_dep_count > 0 )
- {
+ if (unmet_dep_count > 0) {
size_t i;
- mbedtls_fprintf( outcome_file, "SKIP" );
- for( i = 0; i < unmet_dep_count; i++ )
- {
- mbedtls_fprintf( outcome_file, "%c%d",
- i == 0 ? ';' : ':',
- unmet_dependencies[i] );
+ mbedtls_fprintf(outcome_file, "SKIP");
+ for (i = 0; i < unmet_dep_count; i++) {
+ mbedtls_fprintf(outcome_file, "%c%d",
+ i == 0 ? ';' : ':',
+ unmet_dependencies[i]);
}
- if( missing_unmet_dependencies )
- mbedtls_fprintf( outcome_file, ":..." );
+ if (missing_unmet_dependencies) {
+ mbedtls_fprintf(outcome_file, ":...");
+ }
break;
}
- switch( info->result )
- {
+ switch (info->result) {
case MBEDTLS_TEST_RESULT_SUCCESS:
- mbedtls_fprintf( outcome_file, "PASS;" );
+ mbedtls_fprintf(outcome_file, "PASS;");
break;
case MBEDTLS_TEST_RESULT_SKIPPED:
- mbedtls_fprintf( outcome_file, "SKIP;Runtime skip" );
+ mbedtls_fprintf(outcome_file, "SKIP;Runtime skip");
break;
default:
- mbedtls_fprintf( outcome_file, "FAIL;%s:%d:%s",
- info->filename, info->line_no,
- info->test );
+ mbedtls_fprintf(outcome_file, "FAIL;%s:%d:%s",
+ info->filename, info->line_no,
+ info->test);
break;
}
break;
case DISPATCH_TEST_FN_NOT_FOUND:
- mbedtls_fprintf( outcome_file, "FAIL;Test function not found" );
+ mbedtls_fprintf(outcome_file, "FAIL;Test function not found");
break;
case DISPATCH_INVALID_TEST_DATA:
- mbedtls_fprintf( outcome_file, "FAIL;Invalid test data" );
+ mbedtls_fprintf(outcome_file, "FAIL;Invalid test data");
break;
case DISPATCH_UNSUPPORTED_SUITE:
- mbedtls_fprintf( outcome_file, "SKIP;Unsupported suite" );
+ mbedtls_fprintf(outcome_file, "SKIP;Unsupported suite");
break;
default:
- mbedtls_fprintf( outcome_file, "FAIL;Unknown cause" );
+ mbedtls_fprintf(outcome_file, "FAIL;Unknown cause");
break;
}
- mbedtls_fprintf( outcome_file, "\n" );
- fflush( outcome_file );
+ mbedtls_fprintf(outcome_file, "\n");
+ fflush(outcome_file);
}
/**
@@ -500,7 +463,7 @@
*
* \return Program exit status.
*/
-int execute_tests( int argc , const char ** argv )
+int execute_tests(int argc, const char **argv)
{
/* Local Configurations and options */
const char *default_filename = "DATA_FILE";
@@ -525,17 +488,17 @@
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
int stdout_fd = -1;
#endif /* __unix__ || __APPLE__ __MACH__ */
- const char *outcome_file_name = getenv( "MBEDTLS_TEST_OUTCOME_FILE" );
+ const char *outcome_file_name = getenv("MBEDTLS_TEST_OUTCOME_FILE");
FILE *outcome_file = NULL;
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
unsigned char alloc_buf[1000000];
- mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof( alloc_buf ) );
+ mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
#endif
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
- mbedtls_test_mutex_usage_init( );
+ mbedtls_test_mutex_usage_init();
#endif
/*
@@ -543,52 +506,42 @@
* of a NULL pointer. We do however use that in our code for initializing
* structures, which should work on every modern platform. Let's be sure.
*/
- memset( &pointer, 0, sizeof( void * ) );
- if( pointer != NULL )
- {
- mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
- return( 1 );
+ memset(&pointer, 0, sizeof(void *));
+ if (pointer != NULL) {
+ mbedtls_fprintf(stderr, "all-bits-zero is not a NULL pointer\n");
+ return 1;
}
/*
* Make sure we have a snprintf that correctly zero-terminates
*/
- if( run_test_snprintf() != 0 )
- {
- mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
- return( 1 );
+ if (run_test_snprintf() != 0) {
+ mbedtls_fprintf(stderr, "the snprintf implementation is broken\n");
+ return 1;
}
- if( outcome_file_name != NULL && *outcome_file_name != '\0' )
- {
- outcome_file = fopen( outcome_file_name, "a" );
- if( outcome_file == NULL )
- {
- mbedtls_fprintf( stderr, "Unable to open outcome file. Continuing anyway.\n" );
+ if (outcome_file_name != NULL && *outcome_file_name != '\0') {
+ outcome_file = fopen(outcome_file_name, "a");
+ if (outcome_file == NULL) {
+ mbedtls_fprintf(stderr, "Unable to open outcome file. Continuing anyway.\n");
}
}
- while( arg_index < argc )
- {
+ while (arg_index < argc) {
next_arg = argv[arg_index];
- if( strcmp( next_arg, "--verbose" ) == 0 ||
- strcmp( next_arg, "-v" ) == 0 )
- {
+ if (strcmp(next_arg, "--verbose") == 0 ||
+ strcmp(next_arg, "-v") == 0) {
option_verbose = 1;
- }
- else if( strcmp(next_arg, "--help" ) == 0 ||
- strcmp(next_arg, "-h" ) == 0 )
- {
- mbedtls_fprintf( stdout, USAGE );
- mbedtls_exit( EXIT_SUCCESS );
- }
- else
- {
+ } else if (strcmp(next_arg, "--help") == 0 ||
+ strcmp(next_arg, "-h") == 0) {
+ mbedtls_fprintf(stdout, USAGE);
+ mbedtls_exit(EXIT_SUCCESS);
+ } else {
/* Not an option, therefore treat all further arguments as the file
* list.
*/
- test_files = &argv[ arg_index ];
+ test_files = &argv[arg_index];
testfile_count = argc - arg_index;
break;
}
@@ -597,226 +550,204 @@
}
/* If no files were specified, assume a default */
- if ( test_files == NULL || testfile_count == 0 )
- {
+ if (test_files == NULL || testfile_count == 0) {
test_files = &default_filename;
testfile_count = 1;
}
/* Initialize the struct that holds information about the last test */
- mbedtls_test_info_reset( );
+ mbedtls_test_info_reset();
/* Now begin to execute the tests in the testfiles */
- for ( testfile_index = 0;
- testfile_index < testfile_count;
- testfile_index++ )
- {
+ for (testfile_index = 0;
+ testfile_index < testfile_count;
+ testfile_index++) {
size_t unmet_dep_count = 0;
int unmet_dependencies[20];
int missing_unmet_dependencies = 0;
- test_filename = test_files[ testfile_index ];
+ test_filename = test_files[testfile_index];
- file = fopen( test_filename, "r" );
- if( file == NULL )
- {
- mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
- test_filename );
- if( outcome_file != NULL )
- fclose( outcome_file );
- return( 1 );
+ file = fopen(test_filename, "r");
+ if (file == NULL) {
+ mbedtls_fprintf(stderr, "Failed to open test file: %s\n",
+ test_filename);
+ if (outcome_file != NULL) {
+ fclose(outcome_file);
+ }
+ return 1;
}
- while( !feof( file ) )
- {
- if( unmet_dep_count > 0 )
- {
- mbedtls_fprintf( stderr,
- "FATAL: Dep count larger than zero at start of loop\n" );
- mbedtls_exit( MBEDTLS_EXIT_FAILURE );
+ while (!feof(file)) {
+ if (unmet_dep_count > 0) {
+ mbedtls_fprintf(stderr,
+ "FATAL: Dep count larger than zero at start of loop\n");
+ mbedtls_exit(MBEDTLS_EXIT_FAILURE);
}
unmet_dep_count = 0;
missing_unmet_dependencies = 0;
- if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
+ if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
break;
- mbedtls_fprintf( stdout, "%s%.66s",
- mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ?
- "\n" : "", buf );
- mbedtls_fprintf( stdout, " " );
- for( i = strlen( buf ) + 1; i < 67; i++ )
- mbedtls_fprintf( stdout, "." );
- mbedtls_fprintf( stdout, " " );
- fflush( stdout );
- write_outcome_entry( outcome_file, argv[0], buf );
+ }
+ mbedtls_fprintf(stdout, "%s%.66s",
+ mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ?
+ "\n" : "", buf);
+ mbedtls_fprintf(stdout, " ");
+ for (i = strlen(buf) + 1; i < 67; i++) {
+ mbedtls_fprintf(stdout, ".");
+ }
+ mbedtls_fprintf(stdout, " ");
+ fflush(stdout);
+ write_outcome_entry(outcome_file, argv[0], buf);
total_tests++;
- if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
+ if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
break;
- cnt = parse_arguments( buf, strlen( buf ), params,
- sizeof( params ) / sizeof( params[0] ) );
+ }
+ cnt = parse_arguments(buf, strlen(buf), params,
+ sizeof(params) / sizeof(params[0]));
- if( strcmp( params[0], "depends_on" ) == 0 )
- {
- for( i = 1; i < cnt; i++ )
- {
- int dep_id = strtol( params[i], NULL, 10 );
- if( dep_check( dep_id ) != DEPENDENCY_SUPPORTED )
- {
- if( unmet_dep_count <
- ARRAY_LENGTH( unmet_dependencies ) )
- {
+ if (strcmp(params[0], "depends_on") == 0) {
+ for (i = 1; i < cnt; i++) {
+ int dep_id = strtol(params[i], NULL, 10);
+ if (dep_check(dep_id) != DEPENDENCY_SUPPORTED) {
+ if (unmet_dep_count <
+ ARRAY_LENGTH(unmet_dependencies)) {
unmet_dependencies[unmet_dep_count] = dep_id;
unmet_dep_count++;
- }
- else
- {
+ } else {
missing_unmet_dependencies = 1;
}
}
}
- if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
+ if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
break;
- cnt = parse_arguments( buf, strlen( buf ), params,
- sizeof( params ) / sizeof( params[0] ) );
+ }
+ cnt = parse_arguments(buf, strlen(buf), params,
+ sizeof(params) / sizeof(params[0]));
}
// If there are no unmet dependencies execute the test
- if( unmet_dep_count == 0 )
- {
- mbedtls_test_info_reset( );
+ if (unmet_dep_count == 0) {
+ mbedtls_test_info_reset();
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
/* Suppress all output from the library unless we're verbose
* mode
*/
- if( !option_verbose )
- {
- stdout_fd = redirect_output( stdout, "/dev/null" );
- if( stdout_fd == -1 )
- {
+ if (!option_verbose) {
+ stdout_fd = redirect_output(stdout, "/dev/null");
+ if (stdout_fd == -1) {
/* Redirection has failed with no stdout so exit */
- exit( 1 );
+ exit(1);
}
}
#endif /* __unix__ || __APPLE__ __MACH__ */
- function_id = strtoul( params[0], NULL, 10 );
- if ( (ret = check_test( function_id )) == DISPATCH_TEST_SUCCESS )
- {
- ret = convert_params( cnt - 1, params + 1, int_params );
- if ( DISPATCH_TEST_SUCCESS == ret )
- {
- ret = dispatch_test( function_id, (void **)( params + 1 ) );
+ function_id = strtoul(params[0], NULL, 10);
+ if ((ret = check_test(function_id)) == DISPATCH_TEST_SUCCESS) {
+ ret = convert_params(cnt - 1, params + 1, int_params);
+ if (DISPATCH_TEST_SUCCESS == ret) {
+ ret = dispatch_test(function_id, (void **) (params + 1));
}
}
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
- if( !option_verbose && restore_output( stdout, stdout_fd ) )
- {
- /* Redirection has failed with no stdout so exit */
- exit( 1 );
+ if (!option_verbose && restore_output(stdout, stdout_fd)) {
+ /* Redirection has failed with no stdout so exit */
+ exit(1);
}
#endif /* __unix__ || __APPLE__ __MACH__ */
}
- write_outcome_result( outcome_file,
- unmet_dep_count, unmet_dependencies,
- missing_unmet_dependencies,
- ret, &mbedtls_test_info );
- if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
- {
+ write_outcome_result(outcome_file,
+ unmet_dep_count, unmet_dependencies,
+ missing_unmet_dependencies,
+ ret, &mbedtls_test_info);
+ if (unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE) {
total_skipped++;
- mbedtls_fprintf( stdout, "----" );
+ mbedtls_fprintf(stdout, "----");
- if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
- {
- mbedtls_fprintf( stdout, "\n Test Suite not enabled" );
+ if (1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE) {
+ mbedtls_fprintf(stdout, "\n Test Suite not enabled");
}
- if( 1 == option_verbose && unmet_dep_count > 0 )
- {
- mbedtls_fprintf( stdout, "\n Unmet dependencies: " );
- for( i = 0; i < unmet_dep_count; i++ )
- {
- mbedtls_fprintf( stdout, "%d ",
- unmet_dependencies[i] );
+ if (1 == option_verbose && unmet_dep_count > 0) {
+ mbedtls_fprintf(stdout, "\n Unmet dependencies: ");
+ for (i = 0; i < unmet_dep_count; i++) {
+ mbedtls_fprintf(stdout, "%d ",
+ unmet_dependencies[i]);
}
- if( missing_unmet_dependencies )
- mbedtls_fprintf( stdout, "..." );
+ if (missing_unmet_dependencies) {
+ mbedtls_fprintf(stdout, "...");
+ }
}
- mbedtls_fprintf( stdout, "\n" );
- fflush( stdout );
+ mbedtls_fprintf(stdout, "\n");
+ fflush(stdout);
unmet_dep_count = 0;
missing_unmet_dependencies = 0;
- }
- else if( ret == DISPATCH_TEST_SUCCESS )
- {
- if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SUCCESS )
- {
- mbedtls_fprintf( stdout, "PASS\n" );
- }
- else if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SKIPPED )
- {
- mbedtls_fprintf( stdout, "----\n" );
+ } else if (ret == DISPATCH_TEST_SUCCESS) {
+ if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SUCCESS) {
+ mbedtls_fprintf(stdout, "PASS\n");
+ } else if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SKIPPED) {
+ mbedtls_fprintf(stdout, "----\n");
total_skipped++;
- }
- else
- {
+ } else {
total_errors++;
- mbedtls_fprintf( stdout, "FAILED\n" );
- mbedtls_fprintf( stdout, " %s\n at ",
- mbedtls_test_info.test );
- if( mbedtls_test_info.step != (unsigned long)( -1 ) )
- {
- mbedtls_fprintf( stdout, "step %lu, ",
- mbedtls_test_info.step );
+ mbedtls_fprintf(stdout, "FAILED\n");
+ mbedtls_fprintf(stdout, " %s\n at ",
+ mbedtls_test_info.test);
+ if (mbedtls_test_info.step != (unsigned long) (-1)) {
+ mbedtls_fprintf(stdout, "step %lu, ",
+ mbedtls_test_info.step);
}
- mbedtls_fprintf( stdout, "line %d, %s",
- mbedtls_test_info.line_no,
- mbedtls_test_info.filename );
- if( mbedtls_test_info.line1[0] != 0 )
- mbedtls_fprintf( stdout, "\n %s",
- mbedtls_test_info.line1 );
- if( mbedtls_test_info.line2[0] != 0 )
- mbedtls_fprintf( stdout, "\n %s",
- mbedtls_test_info.line2 );
+ mbedtls_fprintf(stdout, "line %d, %s",
+ mbedtls_test_info.line_no,
+ mbedtls_test_info.filename);
+ if (mbedtls_test_info.line1[0] != 0) {
+ mbedtls_fprintf(stdout, "\n %s",
+ mbedtls_test_info.line1);
+ }
+ if (mbedtls_test_info.line2[0] != 0) {
+ mbedtls_fprintf(stdout, "\n %s",
+ mbedtls_test_info.line2);
+ }
}
- fflush( stdout );
- }
- else if( ret == DISPATCH_INVALID_TEST_DATA )
- {
- mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
- fclose( file );
- mbedtls_exit( 2 );
- }
- else if( ret == DISPATCH_TEST_FN_NOT_FOUND )
- {
- mbedtls_fprintf( stderr, "FAILED: FATAL TEST FUNCTION NOT FOUND\n" );
- fclose( file );
- mbedtls_exit( 2 );
- }
- else
+ fflush(stdout);
+ } else if (ret == DISPATCH_INVALID_TEST_DATA) {
+ mbedtls_fprintf(stderr, "FAILED: FATAL PARSE ERROR\n");
+ fclose(file);
+ mbedtls_exit(2);
+ } else if (ret == DISPATCH_TEST_FN_NOT_FOUND) {
+ mbedtls_fprintf(stderr, "FAILED: FATAL TEST FUNCTION NOT FOUND\n");
+ fclose(file);
+ mbedtls_exit(2);
+ } else {
total_errors++;
+ }
}
- fclose( file );
+ fclose(file);
}
- if( outcome_file != NULL )
- fclose( outcome_file );
+ if (outcome_file != NULL) {
+ fclose(outcome_file);
+ }
- mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
- if( total_errors == 0 )
- mbedtls_fprintf( stdout, "PASSED" );
- else
- mbedtls_fprintf( stdout, "FAILED" );
+ mbedtls_fprintf(stdout,
+ "\n----------------------------------------------------------------------------\n\n");
+ if (total_errors == 0) {
+ mbedtls_fprintf(stdout, "PASSED");
+ } else {
+ mbedtls_fprintf(stdout, "FAILED");
+ }
- mbedtls_fprintf( stdout, " (%u / %u tests (%u skipped))\n",
- total_tests - total_errors, total_tests, total_skipped );
+ mbedtls_fprintf(stdout, " (%u / %u tests (%u skipped))\n",
+ total_tests - total_errors, total_tests, total_skipped);
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
@@ -826,5 +757,5 @@
mbedtls_memory_buffer_alloc_free();
#endif
- return( total_errors != 0 );
+ return total_errors != 0;
}
diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function
index 48003d4..11a009a 100644
--- a/tests/suites/main_test.function
+++ b/tests/suites/main_test.function
@@ -69,24 +69,23 @@
*
* \return 0 if exp_id is found. 1 otherwise.
*/
-int get_expression( int32_t exp_id, int32_t * out_value )
+int get_expression(int32_t exp_id, int32_t *out_value)
{
int ret = KEY_VALUE_MAPPING_FOUND;
(void) exp_id;
(void) out_value;
- switch( exp_id )
- {
-__MBEDTLS_TEST_TEMPLATE__EXPRESSION_CODE
+ switch (exp_id) {
+ __MBEDTLS_TEST_TEMPLATE__EXPRESSION_CODE
#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
default:
- {
- ret = KEY_VALUE_MAPPING_NOT_FOUND;
- }
- break;
+ {
+ ret = KEY_VALUE_MAPPING_NOT_FOUND;
+ }
+ break;
}
- return( ret );
+ return ret;
}
@@ -101,20 +100,19 @@
*
* \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
*/
-int dep_check( int dep_id )
+int dep_check(int dep_id)
{
int ret = DEPENDENCY_NOT_SUPPORTED;
(void) dep_id;
- switch( dep_id )
- {
-__MBEDTLS_TEST_TEMPLATE__DEP_CHECK_CODE
+ switch (dep_id) {
+ __MBEDTLS_TEST_TEMPLATE__DEP_CHECK_CODE
#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
default:
break;
}
- return( ret );
+ return ret;
}
@@ -131,7 +129,7 @@
* dereferences. Each wrapper function hard-codes the
* number and types of the parameters.
*/
-typedef void (*TestWrapper_t)( void **param_array );
+typedef void (*TestWrapper_t)(void **param_array);
/**
@@ -142,7 +140,7 @@
*/
TestWrapper_t test_funcs[] =
{
-__MBEDTLS_TEST_TEMPLATE__DISPATCH_CODE
+ __MBEDTLS_TEST_TEMPLATE__DISPATCH_CODE
#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
};
@@ -157,35 +155,31 @@
* DISPATCH_TEST_FN_NOT_FOUND if not found
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
*/
-int dispatch_test( size_t func_idx, void ** params )
+int dispatch_test(size_t func_idx, void **params)
{
int ret = DISPATCH_TEST_SUCCESS;
TestWrapper_t fp = NULL;
- if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
- {
+ if (func_idx < (int) (sizeof(test_funcs) / sizeof(TestWrapper_t))) {
fp = test_funcs[func_idx];
- if ( fp )
- {
+ if (fp) {
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
- mbedtls_test_enable_insecure_external_rng( );
+ mbedtls_test_enable_insecure_external_rng();
#endif
- fp( params );
+ fp(params);
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
- mbedtls_test_mutex_usage_check( );
+ mbedtls_test_mutex_usage_check();
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
- }
- else
+ } else {
ret = DISPATCH_UNSUPPORTED_SUITE;
- }
- else
- {
+ }
+ } else {
ret = DISPATCH_TEST_FN_NOT_FOUND;
}
- return( ret );
+ return ret;
}
@@ -199,23 +193,21 @@
* DISPATCH_TEST_FN_NOT_FOUND if not found
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
*/
-int check_test( size_t func_idx )
+int check_test(size_t func_idx)
{
int ret = DISPATCH_TEST_SUCCESS;
TestWrapper_t fp = NULL;
- if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
- {
+ if (func_idx < (int) (sizeof(test_funcs)/sizeof(TestWrapper_t))) {
fp = test_funcs[func_idx];
- if ( fp == NULL )
+ if (fp == NULL) {
ret = DISPATCH_UNSUPPORTED_SUITE;
- }
- else
- {
+ }
+ } else {
ret = DISPATCH_TEST_FN_NOT_FOUND;
}
- return( ret );
+ return ret;
}
@@ -235,10 +227,10 @@
*
* \return Exit code.
*/
-int main( int argc, const char *argv[] )
+int main(int argc, const char *argv[])
{
#if defined(MBEDTLS_TEST_HOOKS)
- extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file );
+ extern void (*mbedtls_test_hook_test_fail)(const char *test, int line, const char *file);
mbedtls_test_hook_test_fail = &mbedtls_test_fail;
#if defined(MBEDTLS_ERROR_C)
mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;
@@ -246,15 +238,14 @@
#endif
int ret = mbedtls_test_platform_setup();
- if( ret != 0 )
- {
- mbedtls_fprintf( stderr,
- "FATAL: Failed to initialize platform - error %d\n",
- ret );
- return( -1 );
+ if (ret != 0) {
+ mbedtls_fprintf(stderr,
+ "FATAL: Failed to initialize platform - error %d\n",
+ ret);
+ return -1;
}
- ret = execute_tests( argc, argv );
+ ret = execute_tests(argc, argv);
mbedtls_test_platform_teardown();
- return( ret );
+ return ret;
}
diff --git a/tests/suites/test_suite_aes.function b/tests/suites/test_suite_aes.function
index 6a87d42..d95503a 100644
--- a/tests/suites/test_suite_aes.function
+++ b/tests/suites/test_suite_aes.function
@@ -8,107 +8,105 @@
*/
/* BEGIN_CASE */
-void aes_encrypt_ecb( data_t * key_str, data_t * src_str,
- data_t * dst, int setkey_result )
+void aes_encrypt_ecb(data_t *key_str, data_t *src_str,
+ data_t *dst, int setkey_result)
{
unsigned char output[100];
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
- if( setkey_result == 0 )
- {
- TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == setkey_result);
+ if (setkey_result == 0) {
+ TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
}
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void aes_decrypt_ecb( data_t * key_str, data_t * src_str,
- data_t * dst, int setkey_result )
+void aes_decrypt_ecb(data_t *key_str, data_t *src_str,
+ data_t *dst, int setkey_result)
{
unsigned char output[100];
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
- if( setkey_result == 0 )
- {
- TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_DECRYPT, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_dec(&ctx, key_str->x, key_str->len * 8) == setkey_result);
+ if (setkey_result == 0) {
+ TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_DECRYPT, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
}
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void aes_encrypt_cbc( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst,
- int cbc_result )
+void aes_encrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst,
+ int cbc_result)
{
unsigned char output[100];
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
- if( cbc_result == 0 )
- {
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
- src_str->len, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
+ src_str->len, dst->len) == 0);
}
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void aes_decrypt_cbc( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst,
- int cbc_result )
+void aes_decrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst,
+ int cbc_result)
{
unsigned char output[100];
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
- if( cbc_result == 0)
- {
+ TEST_ASSERT(mbedtls_aes_setkey_dec(&ctx, key_str->x, key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
- src_str->len, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
+ src_str->len, dst->len) == 0);
}
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
-void aes_encrypt_xts( char *hex_key_string, char *hex_data_unit_string,
- char *hex_src_string, char *hex_dst_string )
+void aes_encrypt_xts(char *hex_key_string, char *hex_data_unit_string,
+ char *hex_src_string, char *hex_dst_string)
{
enum { AES_BLOCK_SIZE = 16 };
unsigned char *data_unit = NULL;
@@ -119,40 +117,40 @@
mbedtls_aes_xts_context ctx;
size_t key_len, src_len, dst_len, data_unit_len;
- mbedtls_aes_xts_init( &ctx );
+ mbedtls_aes_xts_init(&ctx);
- data_unit = mbedtls_test_unhexify_alloc( hex_data_unit_string,
- &data_unit_len );
- TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE );
+ data_unit = mbedtls_test_unhexify_alloc(hex_data_unit_string,
+ &data_unit_len);
+ TEST_ASSERT(data_unit_len == AES_BLOCK_SIZE);
- key = mbedtls_test_unhexify_alloc( hex_key_string, &key_len );
- TEST_ASSERT( key_len % 2 == 0 );
+ key = mbedtls_test_unhexify_alloc(hex_key_string, &key_len);
+ TEST_ASSERT(key_len % 2 == 0);
- src = mbedtls_test_unhexify_alloc( hex_src_string, &src_len );
- dst = mbedtls_test_unhexify_alloc( hex_dst_string, &dst_len );
- TEST_ASSERT( src_len == dst_len );
+ src = mbedtls_test_unhexify_alloc(hex_src_string, &src_len);
+ dst = mbedtls_test_unhexify_alloc(hex_dst_string, &dst_len);
+ TEST_ASSERT(src_len == dst_len);
- output = mbedtls_test_zero_alloc( dst_len );
+ output = mbedtls_test_zero_alloc(dst_len);
- TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, src_len,
- data_unit, src, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_xts_setkey_enc(&ctx, key, key_len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_ENCRYPT, src_len,
+ data_unit, src, output) == 0);
- TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 );
+ TEST_ASSERT(memcmp(output, dst, dst_len) == 0);
exit:
- mbedtls_aes_xts_free( &ctx );
- mbedtls_free( data_unit );
- mbedtls_free( key );
- mbedtls_free( src );
- mbedtls_free( dst );
- mbedtls_free( output );
+ mbedtls_aes_xts_free(&ctx);
+ mbedtls_free(data_unit);
+ mbedtls_free(key);
+ mbedtls_free(src);
+ mbedtls_free(dst);
+ mbedtls_free(output);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
-void aes_decrypt_xts( char *hex_key_string, char *hex_data_unit_string,
- char *hex_dst_string, char *hex_src_string )
+void aes_decrypt_xts(char *hex_key_string, char *hex_data_unit_string,
+ char *hex_dst_string, char *hex_src_string)
{
enum { AES_BLOCK_SIZE = 16 };
unsigned char *data_unit = NULL;
@@ -163,39 +161,39 @@
mbedtls_aes_xts_context ctx;
size_t key_len, src_len, dst_len, data_unit_len;
- mbedtls_aes_xts_init( &ctx );
+ mbedtls_aes_xts_init(&ctx);
- data_unit = mbedtls_test_unhexify_alloc( hex_data_unit_string,
- &data_unit_len );
- TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE );
+ data_unit = mbedtls_test_unhexify_alloc(hex_data_unit_string,
+ &data_unit_len);
+ TEST_ASSERT(data_unit_len == AES_BLOCK_SIZE);
- key = mbedtls_test_unhexify_alloc( hex_key_string, &key_len );
- TEST_ASSERT( key_len % 2 == 0 );
+ key = mbedtls_test_unhexify_alloc(hex_key_string, &key_len);
+ TEST_ASSERT(key_len % 2 == 0);
- src = mbedtls_test_unhexify_alloc( hex_src_string, &src_len );
- dst = mbedtls_test_unhexify_alloc( hex_dst_string, &dst_len );
- TEST_ASSERT( src_len == dst_len );
+ src = mbedtls_test_unhexify_alloc(hex_src_string, &src_len);
+ dst = mbedtls_test_unhexify_alloc(hex_dst_string, &dst_len);
+ TEST_ASSERT(src_len == dst_len);
- output = mbedtls_test_zero_alloc( dst_len );
+ output = mbedtls_test_zero_alloc(dst_len);
- TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_DECRYPT, src_len,
- data_unit, src, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_xts_setkey_dec(&ctx, key, key_len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_DECRYPT, src_len,
+ data_unit, src, output) == 0);
- TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 );
+ TEST_ASSERT(memcmp(output, dst, dst_len) == 0);
exit:
- mbedtls_aes_xts_free( &ctx );
- mbedtls_free( data_unit );
- mbedtls_free( key );
- mbedtls_free( src );
- mbedtls_free( dst );
- mbedtls_free( output );
+ mbedtls_aes_xts_free(&ctx);
+ mbedtls_free(data_unit);
+ mbedtls_free(key);
+ mbedtls_free(src);
+ mbedtls_free(dst);
+ mbedtls_free(output);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
-void aes_crypt_xts_size( int size, int retval )
+void aes_crypt_xts_size(int size, int retval)
{
mbedtls_aes_xts_context ctx;
const unsigned char src[16] = { 0 };
@@ -203,201 +201,206 @@
unsigned char data_unit[16];
size_t length = size;
- mbedtls_aes_xts_init( &ctx );
- memset( data_unit, 0x00, sizeof( data_unit ) );
+ mbedtls_aes_xts_init(&ctx);
+ memset(data_unit, 0x00, sizeof(data_unit));
- TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, length, data_unit, src, output ) == retval );
+ TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_ENCRYPT, length, data_unit, src,
+ output) == retval);
exit:
- mbedtls_aes_xts_free( &ctx );
+ mbedtls_aes_xts_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
-void aes_crypt_xts_keysize( int size, int retval )
+void aes_crypt_xts_keysize(int size, int retval)
{
mbedtls_aes_xts_context ctx;
const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
size_t key_len = size;
- mbedtls_aes_xts_init( &ctx );
+ mbedtls_aes_xts_init(&ctx);
- TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == retval );
- TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == retval );
+ TEST_ASSERT(mbedtls_aes_xts_setkey_enc(&ctx, key, key_len * 8) == retval);
+ TEST_ASSERT(mbedtls_aes_xts_setkey_dec(&ctx, key, key_len * 8) == retval);
exit:
- mbedtls_aes_xts_free( &ctx );
+ mbedtls_aes_xts_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void aes_encrypt_cfb128( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst )
+void aes_encrypt_cfb128(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_aes_context ctx;
size_t iv_offset = 0;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x,
+ src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void aes_decrypt_cfb128( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst )
+void aes_decrypt_cfb128(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_aes_context ctx;
size_t iv_offset = 0;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x,
+ src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void aes_encrypt_cfb8( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst )
+void aes_encrypt_cfb8(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
- src_str->len, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
+ src_str->len, dst->len) == 0);
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void aes_decrypt_cfb8( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst )
+void aes_decrypt_cfb8(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
- src_str->len, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
+ src_str->len, dst->len) == 0);
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_OFB */
-void aes_encrypt_ofb( int fragment_size, data_t *key_str,
- data_t *iv_str, data_t *src_str,
- data_t *expected_output )
+void aes_encrypt_ofb(int fragment_size, data_t *key_str,
+ data_t *iv_str, data_t *src_str,
+ data_t *expected_output)
{
unsigned char output[32];
mbedtls_aes_context ctx;
size_t iv_offset = 0;
int in_buffer_len;
- unsigned char* src_str_next;
+ unsigned char *src_str_next;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aes_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aes_init(&ctx);
- TEST_ASSERT( (size_t)fragment_size < sizeof( output ) );
+ TEST_ASSERT((size_t) fragment_size < sizeof(output));
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x,
- key_str->len * 8 ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x,
+ key_str->len * 8) == 0);
in_buffer_len = src_str->len;
src_str_next = src_str->x;
- while( in_buffer_len > 0 )
- {
- TEST_ASSERT( mbedtls_aes_crypt_ofb( &ctx, fragment_size, &iv_offset,
- iv_str->x, src_str_next, output ) == 0 );
+ while (in_buffer_len > 0) {
+ TEST_ASSERT(mbedtls_aes_crypt_ofb(&ctx, fragment_size, &iv_offset,
+ iv_str->x, src_str_next, output) == 0);
- TEST_ASSERT( memcmp( output, expected_output->x, fragment_size ) == 0 );
+ TEST_ASSERT(memcmp(output, expected_output->x, fragment_size) == 0);
in_buffer_len -= fragment_size;
expected_output->x += fragment_size;
src_str_next += fragment_size;
- if( in_buffer_len < fragment_size )
+ if (in_buffer_len < fragment_size) {
fragment_size = in_buffer_len;
+ }
}
exit:
- mbedtls_aes_free( &ctx );
+ mbedtls_aes_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void aes_invalid_mode( )
+void aes_invalid_mode()
{
mbedtls_aes_context aes_ctx;
const unsigned char in[16] = { 0 };
unsigned char out[16];
const int invalid_mode = 42;
- TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ecb( &aes_ctx, invalid_mode, in, out ) );
+ TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_ecb(&aes_ctx, invalid_mode, in, out));
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cbc( &aes_ctx, invalid_mode, 16,
- out, in, out ) );
+ TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_cbc(&aes_ctx, invalid_mode, 16,
+ out, in, out));
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_XTS)
mbedtls_aes_xts_context xts_ctx;
- TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_xts( &xts_ctx, invalid_mode, 16,
- in, in, out ) );
+ TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_xts(&xts_ctx, invalid_mode, 16,
+ in, in, out));
#endif /* MBEDTLS_CIPHER_MODE_XTS */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
size_t size;
- TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb128( &aes_ctx, invalid_mode, 16,
- &size, out, in, out ) );
- TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb8( &aes_ctx, invalid_mode, 16,
- out, in, out ) );
+ TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_cfb128(&aes_ctx, invalid_mode, 16,
+ &size, out, in, out));
+ TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_cfb8(&aes_ctx, invalid_mode, 16,
+ out, in, out));
#endif /* MBEDTLS_CIPHER_MODE_CFB */
}
/* END_CASE */
/* BEGIN_CASE */
-void aes_misc_params( )
+void aes_misc_params()
{
#if defined(MBEDTLS_CIPHER_MODE_CBC) || \
defined(MBEDTLS_CIPHER_MODE_XTS) || \
@@ -409,7 +412,7 @@
#if defined(MBEDTLS_CIPHER_MODE_CBC) || \
defined(MBEDTLS_CIPHER_MODE_CFB) || \
defined(MBEDTLS_CIPHER_MODE_OFB)
-mbedtls_aes_context aes_ctx;
+ mbedtls_aes_context aes_ctx;
#endif
#if defined(MBEDTLS_CIPHER_MODE_XTS)
mbedtls_aes_xts_context xts_ctx;
@@ -420,38 +423,38 @@
#endif
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_ASSERT( mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_ENCRYPT,
- 15,
- out, in, out )
- == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
- TEST_ASSERT( mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_ENCRYPT,
- 17,
- out, in, out )
- == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
+ TEST_ASSERT(mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_ENCRYPT,
+ 15,
+ out, in, out)
+ == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
+ TEST_ASSERT(mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_ENCRYPT,
+ 17,
+ out, in, out)
+ == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
#endif
#if defined(MBEDTLS_CIPHER_MODE_XTS)
- TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT,
- 15,
- in, in, out )
- == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
- TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT,
- (1 << 24) + 1,
- in, in, out )
- == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
+ TEST_ASSERT(mbedtls_aes_crypt_xts(&xts_ctx, MBEDTLS_AES_ENCRYPT,
+ 15,
+ in, in, out)
+ == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
+ TEST_ASSERT(mbedtls_aes_crypt_xts(&xts_ctx, MBEDTLS_AES_ENCRYPT,
+ (1 << 24) + 1,
+ in, in, out)
+ == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
#endif
#if defined(MBEDTLS_CIPHER_MODE_CFB)
size = 16;
- TEST_ASSERT( mbedtls_aes_crypt_cfb128( &aes_ctx, MBEDTLS_AES_ENCRYPT, 16,
- &size, out, in, out )
- == MBEDTLS_ERR_AES_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_aes_crypt_cfb128(&aes_ctx, MBEDTLS_AES_ENCRYPT, 16,
+ &size, out, in, out)
+ == MBEDTLS_ERR_AES_BAD_INPUT_DATA);
#endif
#if defined(MBEDTLS_CIPHER_MODE_OFB)
size = 16;
- TEST_ASSERT( mbedtls_aes_crypt_ofb( &aes_ctx, 16, &size, out, in, out )
- == MBEDTLS_ERR_AES_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_aes_crypt_ofb(&aes_ctx, 16, &size, out, in, out)
+ == MBEDTLS_ERR_AES_BAD_INPUT_DATA);
#endif
/*
@@ -459,44 +462,44 @@
* when all the conditions above will be not define in a specific
* choice of features.
*/
- TEST_ASSERT( 1 );
+ TEST_ASSERT(1);
/* TODO: It will be removed when the whole test will be reworked */
}
/* END_CASE */
/* BEGIN_CASE */
-void aes_ecb_copy_context( data_t * key_str, data_t * src_str )
+void aes_ecb_copy_context(data_t *key_str, data_t *src_str)
{
unsigned char output1[16], output2[16], plain[16];
mbedtls_aes_context ctx1, ctx2, ctx3;
// Set key and encrypt with original context
- mbedtls_aes_init( &ctx1 );
- TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx1, key_str->x,
- key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx1, MBEDTLS_AES_ENCRYPT,
- src_str->x, output1 ) == 0 );
+ mbedtls_aes_init(&ctx1);
+ TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx1, key_str->x,
+ key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx1, MBEDTLS_AES_ENCRYPT,
+ src_str->x, output1) == 0);
ctx2 = ctx1;
- TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx1, key_str->x,
- key_str->len * 8 ) == 0 );
+ TEST_ASSERT(mbedtls_aes_setkey_dec(&ctx1, key_str->x,
+ key_str->len * 8) == 0);
ctx3 = ctx1;
- memset( &ctx1, 0, sizeof( ctx1 ) );
+ memset(&ctx1, 0, sizeof(ctx1));
// Encrypt and decrypt with copied context
- TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx2, MBEDTLS_AES_ENCRYPT,
- src_str->x, output2 ) == 0 );
- TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx3, MBEDTLS_AES_DECRYPT,
- output1, plain ) == 0 );
+ TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx2, MBEDTLS_AES_ENCRYPT,
+ src_str->x, output2) == 0);
+ TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx3, MBEDTLS_AES_DECRYPT,
+ output1, plain) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output1, output2, 16, 16 ) == 0 );
- TEST_ASSERT( mbedtls_test_hexcmp( src_str->x, plain, src_str->len, 16 ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output1, output2, 16, 16) == 0);
+ TEST_ASSERT(mbedtls_test_hexcmp(src_str->x, plain, src_str->len, 16) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void aes_selftest( )
+void aes_selftest()
{
- TEST_ASSERT( mbedtls_aes_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_aes_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_alignment.function b/tests/suites/test_suite_alignment.function
index 06c5668..6c98f23 100644
--- a/tests/suites/test_suite_alignment.function
+++ b/tests/suites/test_suite_alignment.function
@@ -11,20 +11,19 @@
/*
* Convert a string of the form "abcd" (case-insensitive) to a uint64_t.
*/
-int parse_hex_string( char* hex_string, uint64_t *result )
+int parse_hex_string(char *hex_string, uint64_t *result)
{
uint8_t raw[8];
size_t olen;
- if ( mbedtls_test_unhexify(raw, sizeof(raw), hex_string, &olen) != 0 ) return 0;
+ if (mbedtls_test_unhexify(raw, sizeof(raw), hex_string, &olen) != 0) {
+ return 0;
+ }
*result = 0;
- for ( size_t i = 0; i < olen; i++ )
- {
- if ( MBEDTLS_IS_BIG_ENDIAN ) {
- *result |= ((uint64_t)raw[i]) << ( i * 8 );
- }
- else
- {
- *result |= ((uint64_t)raw[i]) << ( (olen - i - 1) * 8 );
+ for (size_t i = 0; i < olen; i++) {
+ if (MBEDTLS_IS_BIG_ENDIAN) {
+ *result |= ((uint64_t) raw[i]) << (i * 8);
+ } else {
+ *result |= ((uint64_t) raw[i]) << ((olen - i - 1) * 8);
}
}
return 1;
@@ -33,53 +32,51 @@
/* END_HEADER */
/* BEGIN_CASE */
-void mbedtls_unaligned_access( int size, int offset )
+void mbedtls_unaligned_access(int size, int offset)
{
/* Define 64-bit aligned raw byte array */
uint64_t raw[2];
/* Populate with known data */
uint8_t *x = (uint8_t *) raw;
- for ( size_t i = 0; i < sizeof(raw); i++ )
- x[i] = (uint8_t)i;
+ for (size_t i = 0; i < sizeof(raw); i++) {
+ x[i] = (uint8_t) i;
+ }
- TEST_ASSERT( size == 16 || size == 32 || size == 64 );
+ TEST_ASSERT(size == 16 || size == 32 || size == 64);
uint64_t r = 0;
- switch ( size )
- {
+ switch (size) {
case 16:
- r = mbedtls_get_unaligned_uint16( x + offset );
+ r = mbedtls_get_unaligned_uint16(x + offset);
break;
case 32:
- r = mbedtls_get_unaligned_uint32( x + offset );
+ r = mbedtls_get_unaligned_uint32(x + offset);
break;
case 64:
- r = mbedtls_get_unaligned_uint64( x + offset );
+ r = mbedtls_get_unaligned_uint64(x + offset);
break;
}
/* Generate expected result */
uint64_t expected = 0;
- for ( uint8_t i = 0; i < 8; i++ )
- {
+ for (uint8_t i = 0; i < 8; i++) {
uint8_t shift;
- if ( MBEDTLS_IS_BIG_ENDIAN )
- {
+ if (MBEDTLS_IS_BIG_ENDIAN) {
/*
- * Similar to little-endian case described below, but the shift needs
- * to be inverted
- */
- shift = 7 - ( i * 8 );
+ * Similar to little-endian case described below, but the shift needs
+ * to be inverted
+ */
+ shift = 7 - (i * 8);
} else {
/* example for offset == 1:
- * expected = (( 1 + 0 ) << (0 * 8)) | (( 1 + 1 ) << (1 * 8)) | (( 1 + 2 ) << (2 * 8)))
- * = (1 << 0) | (2 << 8) | (3 << 16) ...
- * = 0x0807060504030201
- * x = { 0, 1, 2, 3, ... }
- * ie expected is the value that would be read from x on a LE system, when
- * byte swapping is not performed
- */
+ * expected = (( 1 + 0 ) << (0 * 8)) | (( 1 + 1 ) << (1 * 8)) | (( 1 + 2 ) << (2 * 8)))
+ * = (1 << 0) | (2 << 8) | (3 << 16) ...
+ * = 0x0807060504030201
+ * x = { 0, 1, 2, 3, ... }
+ * ie expected is the value that would be read from x on a LE system, when
+ * byte swapping is not performed
+ */
shift = i * 8;
}
uint64_t b = offset + i;
@@ -87,8 +84,7 @@
}
/* Mask out excess bits from expected result */
- switch ( size )
- {
+ switch (size) {
case 16:
expected &= 0xffff;
break;
@@ -97,88 +93,82 @@
break;
}
- TEST_EQUAL( r, expected );
+ TEST_EQUAL(r, expected);
/* Write sentinel to the part of the array we will testing writing to */
- for ( size_t i = 0; i < (size_t) ( size / 8 ); i++ )
- {
+ for (size_t i = 0; i < (size_t) (size / 8); i++) {
x[i + offset] = 0xff;
}
/*
- * Write back to the array with mbedtls_put_unaligned_uint16 and validate
- * that the array is unchanged as a result.
- */
- switch ( size )
- {
+ * Write back to the array with mbedtls_put_unaligned_uint16 and validate
+ * that the array is unchanged as a result.
+ */
+ switch (size) {
case 16:
- mbedtls_put_unaligned_uint16( x + offset, r );
+ mbedtls_put_unaligned_uint16(x + offset, r);
break;
case 32:
- mbedtls_put_unaligned_uint32( x + offset, r );
+ mbedtls_put_unaligned_uint32(x + offset, r);
break;
case 64:
- mbedtls_put_unaligned_uint64( x + offset, r );
+ mbedtls_put_unaligned_uint64(x + offset, r);
break;
}
- for ( size_t i = 0; i < sizeof(x); i++ )
- {
- TEST_EQUAL( x[i], (uint8_t)i );
+ for (size_t i = 0; i < sizeof(x); i++) {
+ TEST_EQUAL(x[i], (uint8_t) i);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_byteswap( char* input_str, int size, char *expected_str )
+void mbedtls_byteswap(char *input_str, int size, char *expected_str)
{
uint64_t input, expected;
- TEST_ASSERT( parse_hex_string( input_str, &input ) );
- TEST_ASSERT( parse_hex_string( expected_str, &expected ) );
+ TEST_ASSERT(parse_hex_string(input_str, &input));
+ TEST_ASSERT(parse_hex_string(expected_str, &expected));
/* Check against expected result */
uint64_t r = 0;
- switch ( size )
- {
+ switch (size) {
case 16:
- r = MBEDTLS_BSWAP16( input );
+ r = MBEDTLS_BSWAP16(input);
break;
case 32:
- r = MBEDTLS_BSWAP32( input );
+ r = MBEDTLS_BSWAP32(input);
break;
case 64:
- r = MBEDTLS_BSWAP64( input );
+ r = MBEDTLS_BSWAP64(input);
break;
default:
- TEST_ASSERT( ! "size must be 16, 32 or 64" );
+ TEST_ASSERT(!"size must be 16, 32 or 64");
}
- TEST_EQUAL( r, expected );
+ TEST_EQUAL(r, expected);
/*
* Check byte by byte by extracting bytes from opposite ends of
* input and r.
*/
- for ( size_t i = 0; i < (size_t)( size / 8 ); i++ )
- {
+ for (size_t i = 0; i < (size_t) (size / 8); i++) {
size_t s1 = i * 8;
- size_t s2 = ( ( size / 8 - 1 ) - i ) * 8;
- uint64_t a = ( input & ( (uint64_t)0xff << s1 ) ) >> s1;
- uint64_t b = ( r & ( (uint64_t)0xff << s2 ) ) >> s2;
- TEST_EQUAL( a, b );
+ size_t s2 = ((size / 8 - 1) - i) * 8;
+ uint64_t a = (input & ((uint64_t) 0xff << s1)) >> s1;
+ uint64_t b = (r & ((uint64_t) 0xff << s2)) >> s2;
+ TEST_EQUAL(a, b);
}
/* Check BSWAP(BSWAP(x)) == x */
- switch ( size )
- {
+ switch (size) {
case 16:
- r = MBEDTLS_BSWAP16( r );
- TEST_EQUAL( r, input & 0xffff );
+ r = MBEDTLS_BSWAP16(r);
+ TEST_EQUAL(r, input & 0xffff);
break;
case 32:
- r = MBEDTLS_BSWAP32( r );
- TEST_EQUAL( r, input & 0xffffffff );
+ r = MBEDTLS_BSWAP32(r);
+ TEST_EQUAL(r, input & 0xffffffff);
break;
case 64:
- r = MBEDTLS_BSWAP64( r );
- TEST_EQUAL( r, input );
+ r = MBEDTLS_BSWAP64(r);
+ TEST_EQUAL(r, input);
break;
}
}
@@ -189,199 +179,184 @@
{
uint8_t data[16];
- for ( size_t i = 0; i < sizeof(data); i++ )
+ for (size_t i = 0; i < sizeof(data); i++) {
data[i] = (uint8_t) i;
+ }
uint64_t u64 = 0x0706050403020100;
- for ( size_t b = 0; b < 8 ; b++ )
- {
+ for (size_t b = 0; b < 8; b++) {
uint8_t expected = b;
uint8_t actual = b + 1;
- switch ( b )
- {
+ switch (b) {
case 0:
- actual = MBEDTLS_BYTE_0( u64 );
+ actual = MBEDTLS_BYTE_0(u64);
break;
case 1:
- actual = MBEDTLS_BYTE_1( u64 );
+ actual = MBEDTLS_BYTE_1(u64);
break;
case 2:
- actual = MBEDTLS_BYTE_2( u64 );
+ actual = MBEDTLS_BYTE_2(u64);
break;
case 3:
- actual = MBEDTLS_BYTE_3( u64 );
+ actual = MBEDTLS_BYTE_3(u64);
break;
case 4:
- actual = MBEDTLS_BYTE_4( u64 );
+ actual = MBEDTLS_BYTE_4(u64);
break;
case 5:
- actual = MBEDTLS_BYTE_5( u64 );
+ actual = MBEDTLS_BYTE_5(u64);
break;
case 6:
- actual = MBEDTLS_BYTE_6( u64 );
+ actual = MBEDTLS_BYTE_6(u64);
break;
case 7:
- actual = MBEDTLS_BYTE_7( u64 );
+ actual = MBEDTLS_BYTE_7(u64);
break;
}
- TEST_EQUAL( actual, expected );
+ TEST_EQUAL(actual, expected);
}
uint32_t u32 = 0x03020100;
- for ( size_t b = 0; b < 4 ; b++ )
- {
+ for (size_t b = 0; b < 4; b++) {
uint8_t expected = b;
uint8_t actual = b + 1;
- switch ( b )
- {
+ switch (b) {
case 0:
- actual = MBEDTLS_BYTE_0( u32 );
+ actual = MBEDTLS_BYTE_0(u32);
break;
case 1:
- actual = MBEDTLS_BYTE_1( u32 );
+ actual = MBEDTLS_BYTE_1(u32);
break;
case 2:
- actual = MBEDTLS_BYTE_2( u32 );
+ actual = MBEDTLS_BYTE_2(u32);
break;
case 3:
- actual = MBEDTLS_BYTE_3( u32 );
+ actual = MBEDTLS_BYTE_3(u32);
break;
}
- TEST_EQUAL( actual, expected );
+ TEST_EQUAL(actual, expected);
}
uint16_t u16 = 0x0100;
- for ( size_t b = 0; b < 2 ; b++ )
- {
+ for (size_t b = 0; b < 2; b++) {
uint8_t expected = b;
uint8_t actual = b + 1;
- switch ( b )
- {
+ switch (b) {
case 0:
- actual = MBEDTLS_BYTE_0( u16 );
+ actual = MBEDTLS_BYTE_0(u16);
break;
case 1:
- actual = MBEDTLS_BYTE_1( u16 );
+ actual = MBEDTLS_BYTE_1(u16);
break;
}
- TEST_EQUAL( actual, expected );
+ TEST_EQUAL(actual, expected);
}
uint8_t u8 = 0x01;
- uint8_t actual = MBEDTLS_BYTE_0( u8 );
- TEST_EQUAL( actual, u8 );
+ uint8_t actual = MBEDTLS_BYTE_0(u8);
+ TEST_EQUAL(actual, u8);
}
/* END_CASE */
/* BEGIN_CASE */
-void unaligned_access_endian_aware(int size, int offset, int big_endian )
+void unaligned_access_endian_aware(int size, int offset, int big_endian)
{
- TEST_ASSERT( size == 16 || size == 24 || size == 32 || size == 64 );
- TEST_ASSERT( offset >= 0 && offset < 8 );
+ TEST_ASSERT(size == 16 || size == 24 || size == 32 || size == 64);
+ TEST_ASSERT(offset >= 0 && offset < 8);
/* Define 64-bit aligned raw byte array */
uint64_t raw[2];
/* Populate with known data: x == { 0, 1, 2, ... } */
uint8_t *x = (uint8_t *) raw;
- for ( size_t i = 0; i < sizeof(raw); i++ )
+ for (size_t i = 0; i < sizeof(raw); i++) {
x[i] = (uint8_t) i;
+ }
uint64_t read = 0;
- if ( big_endian )
- {
- switch ( size )
- {
+ if (big_endian) {
+ switch (size) {
case 16:
- read = MBEDTLS_GET_UINT16_BE( x, offset );
+ read = MBEDTLS_GET_UINT16_BE(x, offset);
break;
case 24:
- read = MBEDTLS_GET_UINT24_BE( x, offset );
+ read = MBEDTLS_GET_UINT24_BE(x, offset);
break;
case 32:
- read = MBEDTLS_GET_UINT32_BE( x, offset );
+ read = MBEDTLS_GET_UINT32_BE(x, offset);
break;
case 64:
- read = MBEDTLS_GET_UINT64_BE( x, offset );
+ read = MBEDTLS_GET_UINT64_BE(x, offset);
break;
}
- }
- else
- {
- switch ( size )
- {
+ } else {
+ switch (size) {
case 16:
- read = MBEDTLS_GET_UINT16_LE( x, offset );
+ read = MBEDTLS_GET_UINT16_LE(x, offset);
break;
case 24:
- read = MBEDTLS_GET_UINT24_LE( x, offset );
+ read = MBEDTLS_GET_UINT24_LE(x, offset);
break;
case 32:
- read = MBEDTLS_GET_UINT32_LE( x, offset );
+ read = MBEDTLS_GET_UINT32_LE(x, offset);
break;
case 64:
- read = MBEDTLS_GET_UINT64_LE( x, offset );
+ read = MBEDTLS_GET_UINT64_LE(x, offset);
break;
}
}
/* Build up expected value byte by byte, in either big or little endian format */
uint64_t expected = 0;
- for ( size_t i = 0; i < (size_t)(size / 8); i++ )
- {
+ for (size_t i = 0; i < (size_t) (size / 8); i++) {
uint64_t b = x[i + offset];
uint8_t shift = (big_endian) ? (8 * ((size / 8 - 1) - i)) : (8 * i);
expected |= b << shift;
}
/* Verify read */
- TEST_EQUAL( read, expected );
+ TEST_EQUAL(read, expected);
/* Test writing back to memory. First write sentiel */
- for ( size_t i = 0; i < (size_t)(size / 8); i++ )
- {
+ for (size_t i = 0; i < (size_t) (size / 8); i++) {
x[i + offset] = 0xff;
}
/* Overwrite sentinel with endian-aware write macro */
- if ( big_endian )
- {
- switch ( size )
- {
+ if (big_endian) {
+ switch (size) {
case 16:
- MBEDTLS_PUT_UINT16_BE( read, x, offset );
+ MBEDTLS_PUT_UINT16_BE(read, x, offset);
break;
case 24:
- MBEDTLS_PUT_UINT24_BE( read, x, offset );
+ MBEDTLS_PUT_UINT24_BE(read, x, offset);
break;
case 32:
- MBEDTLS_PUT_UINT32_BE( read, x, offset );
+ MBEDTLS_PUT_UINT32_BE(read, x, offset);
break;
case 64:
- MBEDTLS_PUT_UINT64_BE( read, x, offset );
+ MBEDTLS_PUT_UINT64_BE(read, x, offset);
break;
}
- }
- else
- {
- switch ( size )
- {
+ } else {
+ switch (size) {
case 16:
- MBEDTLS_PUT_UINT16_LE( read, x, offset );
+ MBEDTLS_PUT_UINT16_LE(read, x, offset);
break;
- case 24:
- MBEDTLS_PUT_UINT24_LE( read, x, offset );
+ case 24:
+ MBEDTLS_PUT_UINT24_LE(read, x, offset);
break;
case 32:
- MBEDTLS_PUT_UINT32_LE( read, x, offset );
+ MBEDTLS_PUT_UINT32_LE(read, x, offset);
break;
case 64:
- MBEDTLS_PUT_UINT64_LE( read, x, offset );
+ MBEDTLS_PUT_UINT64_LE(read, x, offset);
break;
}
}
/* Verify write - check memory is correct */
- for ( size_t i = 0; i < sizeof(raw); i++ )
- TEST_EQUAL( x[i], (uint8_t) i );
+ for (size_t i = 0; i < sizeof(raw); i++) {
+ TEST_EQUAL(x[i], (uint8_t) i);
+ }
}
/* END_CASE */
@@ -389,19 +364,16 @@
void mbedtls_is_big_endian()
{
uint16_t check = 0x1234;
- uint8_t* p = (uint8_t*) ✓
+ uint8_t *p = (uint8_t *) ✓
- if ( MBEDTLS_IS_BIG_ENDIAN )
- {
+ if (MBEDTLS_IS_BIG_ENDIAN) {
/* Big-endian: data stored MSB first, i.e. p == { 0x12, 0x34 } */
- TEST_EQUAL( p[0], 0x12 );
- TEST_EQUAL( p[1], 0x34 );
- }
- else
- {
+ TEST_EQUAL(p[0], 0x12);
+ TEST_EQUAL(p[1], 0x34);
+ } else {
/* Little-endian: data stored LSB first, i.e. p == { 0x34, 0x12 } */
- TEST_EQUAL( p[0], 0x34 );
- TEST_EQUAL( p[1], 0x12 );
+ TEST_EQUAL(p[0], 0x34);
+ TEST_EQUAL(p[1], 0x12);
}
}
/* END_CASE */
diff --git a/tests/suites/test_suite_aria.function b/tests/suites/test_suite_aria.function
index ad7c773..9e4db2c 100644
--- a/tests/suites/test_suite_aria.function
+++ b/tests/suites/test_suite_aria.function
@@ -6,9 +6,9 @@
#define ARIA_MAX_DATASIZE 160
/* Maximum sizes of hexified things */
-#define ARIA_MAX_KEY_STR ( 2 * MBEDTLS_ARIA_MAX_KEYSIZE + 1 )
-#define ARIA_BLOCK_STR ( 2 * MBEDTLS_ARIA_BLOCKSIZE + 1 )
-#define ARIA_MAX_DATA_STR ( 2 * ARIA_MAX_DATASIZE + 1 )
+#define ARIA_MAX_KEY_STR (2 * MBEDTLS_ARIA_MAX_KEYSIZE + 1)
+#define ARIA_BLOCK_STR (2 * MBEDTLS_ARIA_BLOCKSIZE + 1)
+#define ARIA_MAX_DATA_STR (2 * ARIA_MAX_DATASIZE + 1)
/* END_HEADER */
/* BEGIN_DEPENDENCIES
@@ -17,7 +17,7 @@
*/
/* BEGIN_CASE depends_on:NOT_DEFINED */
-void aria_invalid_param( )
+void aria_invalid_param()
{
mbedtls_aria_context ctx;
unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
@@ -32,24 +32,24 @@
((void) output);
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_EQUAL( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cbc( &ctx,
- 42 /* invalid mode */,
- sizeof( input ),
- iv,
- input,
- output ) );
+ TEST_EQUAL(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
+ mbedtls_aria_crypt_cbc(&ctx,
+ 42 /* invalid mode */,
+ sizeof(input),
+ iv,
+ input,
+ output));
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
- TEST_EQUAL( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cfb128( &ctx,
- 42, /* invalid mode */
- sizeof( input ),
- &iv_off,
- iv,
- input,
- output ) );
+ TEST_EQUAL(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
+ mbedtls_aria_crypt_cfb128(&ctx,
+ 42, /* invalid mode */
+ sizeof(input),
+ &iv_off,
+ iv,
+ input,
+ output));
#endif /* MBEDTLS_CIPHER_MODE_CFB */
exit:
@@ -59,224 +59,218 @@
/* END_CASE */
/* BEGIN_CASE */
-void aria_encrypt_ecb( data_t *key_str, data_t *src_str,
- data_t *expected_output, int setkey_result )
+void aria_encrypt_ecb(data_t *key_str, data_t *src_str,
+ data_t *expected_output, int setkey_result)
{
unsigned char output[ARIA_MAX_DATASIZE];
mbedtls_aria_context ctx;
size_t i;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 )
- == setkey_result );
- if( setkey_result == 0 )
- {
- for( i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE )
- {
- TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i,
- output + i ) == 0 );
+ TEST_ASSERT(mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8)
+ == setkey_result);
+ if (setkey_result == 0) {
+ for (i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE) {
+ TEST_ASSERT(mbedtls_aria_crypt_ecb(&ctx, src_str->x + i,
+ output + i) == 0);
}
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
}
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void aria_decrypt_ecb( data_t *key_str, data_t *src_str,
- data_t *expected_output, int setkey_result )
+void aria_decrypt_ecb(data_t *key_str, data_t *src_str,
+ data_t *expected_output, int setkey_result)
{
unsigned char output[ARIA_MAX_DATASIZE];
mbedtls_aria_context ctx;
size_t i;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str->x, key_str->len * 8 )
- == setkey_result );
- if( setkey_result == 0 )
- {
- for( i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE )
- {
- TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i,
- output + i ) == 0 );
+ TEST_ASSERT(mbedtls_aria_setkey_dec(&ctx, key_str->x, key_str->len * 8)
+ == setkey_result);
+ if (setkey_result == 0) {
+ for (i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE) {
+ TEST_ASSERT(mbedtls_aria_crypt_ecb(&ctx, src_str->x + i,
+ output + i) == 0);
}
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
}
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void aria_encrypt_cbc( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int cbc_result )
+void aria_encrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *expected_output,
+ int cbc_result)
{
unsigned char output[ARIA_MAX_DATASIZE];
mbedtls_aria_context ctx;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT,
- src_str->len, iv_str->x, src_str->x,
- output ) == cbc_result );
- if( cbc_result == 0 )
- {
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_ENCRYPT,
+ src_str->len, iv_str->x, src_str->x,
+ output) == cbc_result);
+ if (cbc_result == 0) {
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
}
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void aria_decrypt_cbc( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int cbc_result )
+void aria_decrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *expected_output,
+ int cbc_result)
{
unsigned char output[ARIA_MAX_DATASIZE];
mbedtls_aria_context ctx;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- mbedtls_aria_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT,
- src_str->len, iv_str->x, src_str->x,
- output ) == cbc_result );
- if( cbc_result == 0 )
- {
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ mbedtls_aria_setkey_dec(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_DECRYPT,
+ src_str->len, iv_str->x, src_str->x,
+ output) == cbc_result);
+ if (cbc_result == 0) {
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
}
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
+void aria_encrypt_cfb128(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *expected_output,
+ int result)
{
unsigned char output[ARIA_MAX_DATASIZE];
mbedtls_aria_context ctx;
size_t iv_offset = 0;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT,
- src_str->len, &iv_offset,
- iv_str->x, src_str->x, output )
- == result );
+ mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_ENCRYPT,
+ src_str->len, &iv_offset,
+ iv_str->x, src_str->x, output)
+ == result);
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
+void aria_decrypt_cfb128(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *expected_output,
+ int result)
{
unsigned char output[ARIA_MAX_DATASIZE];
mbedtls_aria_context ctx;
size_t iv_offset = 0;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT,
- src_str->len, &iv_offset,
- iv_str->x, src_str->x, output )
- == result );
+ mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_DECRYPT,
+ src_str->len, &iv_offset,
+ iv_str->x, src_str->x, output)
+ == result);
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
-void aria_encrypt_ctr( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
+void aria_encrypt_ctr(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *expected_output,
+ int result)
{
unsigned char output[ARIA_MAX_DATASIZE];
unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
mbedtls_aria_context ctx;
size_t iv_offset = 0;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset,
- iv_str->x, blk, src_str->x, output )
- == result );
+ mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_aria_crypt_ctr(&ctx, src_str->len, &iv_offset,
+ iv_str->x, blk, src_str->x, output)
+ == result);
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
-void aria_decrypt_ctr( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
+void aria_decrypt_ctr(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *expected_output,
+ int result)
{
unsigned char output[ARIA_MAX_DATASIZE];
unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
mbedtls_aria_context ctx;
size_t iv_offset = 0;
- memset( output, 0x00, sizeof( output ) );
- mbedtls_aria_init( &ctx );
+ memset(output, 0x00, sizeof(output));
+ mbedtls_aria_init(&ctx);
- mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset,
- iv_str->x, blk, src_str->x, output )
- == result );
+ mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_aria_crypt_ctr(&ctx, src_str->len, &iv_offset,
+ iv_str->x, blk, src_str->x, output)
+ == result);
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
+ ASSERT_COMPARE(output, expected_output->len,
+ expected_output->x, expected_output->len);
exit:
- mbedtls_aria_free( &ctx );
+ mbedtls_aria_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void aria_selftest()
{
- TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_aria_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_asn1parse.function b/tests/suites/test_suite_asn1parse.function
index 62669b3..e1a26b7 100644
--- a/tests/suites/test_suite_asn1parse.function
+++ b/tests/suites/test_suite_asn1parse.function
@@ -16,8 +16,8 @@
* should not be checked. */
#define UNPREDICTABLE_RESULT 0x5552
-static int nested_parse( unsigned char **const p,
- const unsigned char *const end )
+static int nested_parse(unsigned char **const p,
+ const unsigned char *const end)
{
int ret;
size_t len = 0;
@@ -28,31 +28,32 @@
/* First get the length, skipping over the tag. */
content_start = start + 1;
- ret = mbedtls_asn1_get_len( &content_start, end, &len );
- TEST_ASSERT( content_start <= end );
- if( ret != 0 )
- return( ret );
+ ret = mbedtls_asn1_get_len(&content_start, end, &len);
+ TEST_ASSERT(content_start <= end);
+ if (ret != 0) {
+ return ret;
+ }
/* Since we have a valid element start (tag and length), retrieve and
* check the tag. */
tag = start[0];
- TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len2, tag ^ 1 ),
- MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
+ TEST_EQUAL(mbedtls_asn1_get_tag(p, end, &len2, tag ^ 1),
+ MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
*p = start;
- TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len2, tag ), 0 );
- TEST_EQUAL( len, len2 );
- TEST_ASSERT( *p == content_start );
+ TEST_EQUAL(mbedtls_asn1_get_tag(p, end, &len2, tag), 0);
+ TEST_EQUAL(len, len2);
+ TEST_ASSERT(*p == content_start);
*p = content_start;
- switch( tag & 0x1f )
- {
+ switch (tag & 0x1f) {
case MBEDTLS_ASN1_BOOLEAN:
{
int val = -257;
*p = start;
- ret = mbedtls_asn1_get_bool( p, end, &val );
- if( ret == 0 )
- TEST_ASSERT( val == 0 || val == 1 );
+ ret = mbedtls_asn1_get_bool(p, end, &val);
+ if (ret == 0) {
+ TEST_ASSERT(val == 0 || val == 1);
+ }
break;
}
@@ -60,23 +61,22 @@
{
#if defined(MBEDTLS_BIGNUM_C)
mbedtls_mpi mpi;
- mbedtls_mpi_init( &mpi );
+ mbedtls_mpi_init(&mpi);
*p = start;
- ret = mbedtls_asn1_get_mpi( p, end, &mpi );
- mbedtls_mpi_free( &mpi );
+ ret = mbedtls_asn1_get_mpi(p, end, &mpi);
+ mbedtls_mpi_free(&mpi);
#else
*p = start + 1;
- ret = mbedtls_asn1_get_len( p, end, &len );
+ ret = mbedtls_asn1_get_len(p, end, &len);
*p += len;
#endif
/* If we're sure that the number fits in an int, also
* call mbedtls_asn1_get_int(). */
- if( ret == 0 && len < sizeof( int ) )
- {
+ if (ret == 0 && len < sizeof(int)) {
int val = -257;
unsigned char *q = start;
- ret = mbedtls_asn1_get_int( &q, end, &val );
- TEST_ASSERT( *p == q );
+ ret = mbedtls_asn1_get_int(&q, end, &val);
+ TEST_ASSERT(*p == q);
}
break;
}
@@ -85,14 +85,15 @@
{
mbedtls_asn1_bitstring bs;
*p = start;
- ret = mbedtls_asn1_get_bitstring( p, end, &bs );
+ ret = mbedtls_asn1_get_bitstring(p, end, &bs);
break;
}
case MBEDTLS_ASN1_SEQUENCE:
{
- while( *p <= end && *p < content_start + len && ret == 0 )
- ret = nested_parse( p, content_start + len );
+ while (*p <= end && *p < content_start + len && ret == 0) {
+ ret = nested_parse(p, content_start + len);
+ }
break;
}
@@ -111,18 +112,18 @@
default:
/* No further testing implemented for this tag. */
*p += len;
- return( 0 );
+ return 0;
}
- TEST_ASSERT( *p <= end );
- return( ret );
+ TEST_ASSERT(*p <= end);
+ return ret;
exit:
- return( ERR_PARSE_INCONSISTENCY );
+ return ERR_PARSE_INCONSISTENCY;
}
-int get_len_step( const data_t *input, size_t buffer_size,
- size_t actual_length )
+int get_len_step(const data_t *input, size_t buffer_size,
+ size_t actual_length)
{
unsigned char *buf = NULL;
unsigned char *p = NULL;
@@ -130,53 +131,43 @@
size_t parsed_length;
int ret;
- mbedtls_test_set_step( buffer_size );
+ mbedtls_test_set_step(buffer_size);
/* Allocate a new buffer of exactly the length to parse each time.
* This gives memory sanitizers a chance to catch buffer overreads. */
- if( buffer_size == 0 )
- {
- ASSERT_ALLOC( buf, 1 );
+ if (buffer_size == 0) {
+ ASSERT_ALLOC(buf, 1);
end = buf + 1;
p = end;
- }
- else
- {
- ASSERT_ALLOC_WEAK( buf, buffer_size );
- if( buffer_size > input->len )
- {
- memcpy( buf, input->x, input->len );
- memset( buf + input->len, 'A', buffer_size - input->len );
- }
- else
- {
- memcpy( buf, input->x, buffer_size );
+ } else {
+ ASSERT_ALLOC_WEAK(buf, buffer_size);
+ if (buffer_size > input->len) {
+ memcpy(buf, input->x, input->len);
+ memset(buf + input->len, 'A', buffer_size - input->len);
+ } else {
+ memcpy(buf, input->x, buffer_size);
}
p = buf;
end = buf + buffer_size;
}
- ret = mbedtls_asn1_get_len( &p, end, &parsed_length );
+ ret = mbedtls_asn1_get_len(&p, end, &parsed_length);
- if( buffer_size >= input->len + actual_length )
- {
- TEST_EQUAL( ret, 0 );
- TEST_ASSERT( p == buf + input->len );
- TEST_EQUAL( parsed_length, actual_length );
+ if (buffer_size >= input->len + actual_length) {
+ TEST_EQUAL(ret, 0);
+ TEST_ASSERT(p == buf + input->len);
+ TEST_EQUAL(parsed_length, actual_length);
+ } else {
+ TEST_EQUAL(ret, MBEDTLS_ERR_ASN1_OUT_OF_DATA);
}
- else
- {
- TEST_EQUAL( ret, MBEDTLS_ERR_ASN1_OUT_OF_DATA );
- }
- mbedtls_free( buf );
- return( 1 );
+ mbedtls_free(buf);
+ return 1;
exit:
- mbedtls_free( buf );
- return( 0 );
+ mbedtls_free(buf);
+ return 0;
}
-typedef struct
-{
+typedef struct {
const unsigned char *input_start;
const char *description;
} traverse_state_t;
@@ -188,38 +179,40 @@
#define RET_TRAVERSE_ERROR 2
-static int traverse_callback( void *ctx, int tag,
- unsigned char *content, size_t len )
+static int traverse_callback(void *ctx, int tag,
+ unsigned char *content, size_t len)
{
traverse_state_t *state = ctx;
size_t offset;
const char *rest = state->description;
unsigned long n;
- TEST_ASSERT( content > state->input_start );
+ TEST_ASSERT(content > state->input_start);
offset = content - state->input_start;
- mbedtls_test_set_step( offset );
+ mbedtls_test_set_step(offset);
- if( *rest == 0 )
- return( RET_TRAVERSE_STOP );
- n = strtoul( rest, (char **) &rest, 0 );
- TEST_EQUAL( n, offset );
- TEST_EQUAL( *rest, ',' );
+ if (*rest == 0) {
+ return RET_TRAVERSE_STOP;
+ }
+ n = strtoul(rest, (char **) &rest, 0);
+ TEST_EQUAL(n, offset);
+ TEST_EQUAL(*rest, ',');
++rest;
- n = strtoul( rest, (char **) &rest, 0 );
- TEST_EQUAL( n, (unsigned) tag );
- TEST_EQUAL( *rest, ',' );
+ n = strtoul(rest, (char **) &rest, 0);
+ TEST_EQUAL(n, (unsigned) tag);
+ TEST_EQUAL(*rest, ',');
++rest;
- n = strtoul( rest, (char **) &rest, 0 );
- TEST_EQUAL( n, len );
- if( *rest == ',' )
+ n = strtoul(rest, (char **) &rest, 0);
+ TEST_EQUAL(n, len);
+ if (*rest == ',') {
++rest;
+ }
state->description = rest;
- return( 0 );
+ return 0;
exit:
- return( RET_TRAVERSE_ERROR );
+ return RET_TRAVERSE_ERROR;
}
/* END_HEADER */
@@ -230,9 +223,9 @@
*/
/* BEGIN_CASE */
-void parse_prefixes( const data_t *input,
- int full_result,
- int overfull_result )
+void parse_prefixes(const data_t *input,
+ int full_result,
+ int overfull_result)
{
/* full_result: expected result from parsing the given string. */
/* overfull_result: expected_result from parsing the given string plus
@@ -250,45 +243,42 @@
* we wouldn't know what to parse the input as.
* Also test the input followed by an extra byte.
*/
- for( buffer_size = 1; buffer_size <= input->len + 1; buffer_size++ )
- {
- mbedtls_test_set_step( buffer_size );
+ for (buffer_size = 1; buffer_size <= input->len + 1; buffer_size++) {
+ mbedtls_test_set_step(buffer_size);
/* Allocate a new buffer of exactly the length to parse each time.
* This gives memory sanitizers a chance to catch buffer overreads. */
- ASSERT_ALLOC( buf, buffer_size );
- memcpy( buf, input->x, buffer_size );
+ ASSERT_ALLOC(buf, buffer_size);
+ memcpy(buf, input->x, buffer_size);
p = buf;
- ret = nested_parse( &p, buf + buffer_size );
+ ret = nested_parse(&p, buf + buffer_size);
- if( ret == ERR_PARSE_INCONSISTENCY )
+ if (ret == ERR_PARSE_INCONSISTENCY) {
goto exit;
- if( buffer_size < input->len )
- {
- TEST_EQUAL( ret, MBEDTLS_ERR_ASN1_OUT_OF_DATA );
}
- else if( buffer_size == input->len )
- {
- TEST_EQUAL( ret, full_result );
+ if (buffer_size < input->len) {
+ TEST_EQUAL(ret, MBEDTLS_ERR_ASN1_OUT_OF_DATA);
+ } else if (buffer_size == input->len) {
+ TEST_EQUAL(ret, full_result);
+ } else { /* ( buffer_size > input->len ) */
+ if (overfull_result != UNPREDICTABLE_RESULT) {
+ TEST_EQUAL(ret, overfull_result);
+ }
}
- else /* ( buffer_size > input->len ) */
- {
- if( overfull_result != UNPREDICTABLE_RESULT )
- TEST_EQUAL( ret, overfull_result );
+ if (ret == 0) {
+ TEST_ASSERT(p == buf + input->len);
}
- if( ret == 0 )
- TEST_ASSERT( p == buf + input->len );
- mbedtls_free( buf );
+ mbedtls_free(buf);
buf = NULL;
}
exit:
- mbedtls_free( buf );
+ mbedtls_free(buf);
}
/* END_CASE */
/* BEGIN_CASE */
-void get_len( const data_t *input, int actual_length_arg )
+void get_len(const data_t *input, int actual_length_arg)
{
size_t actual_length = actual_length_arg;
size_t buffer_size;
@@ -299,37 +289,38 @@
* the payload is truncated more than one byte away from either end,
* and we only test the empty string on a 1-byte input.
*/
- for( buffer_size = 1; buffer_size <= input->len + 1; buffer_size++ )
- {
- if( ! get_len_step( input, buffer_size, actual_length ) )
+ for (buffer_size = 1; buffer_size <= input->len + 1; buffer_size++) {
+ if (!get_len_step(input, buffer_size, actual_length)) {
goto exit;
+ }
}
- if( ! get_len_step( input, input->len + actual_length - 1, actual_length ) )
+ if (!get_len_step(input, input->len + actual_length - 1, actual_length)) {
goto exit;
- if( ! get_len_step( input, input->len + actual_length, actual_length ) )
+ }
+ if (!get_len_step(input, input->len + actual_length, actual_length)) {
goto exit;
+ }
}
/* END_CASE */
/* BEGIN_CASE */
-void get_boolean( const data_t *input,
- int expected_value, int expected_result )
+void get_boolean(const data_t *input,
+ int expected_value, int expected_result)
{
unsigned char *p = input->x;
int val;
int ret;
- ret = mbedtls_asn1_get_bool( &p, input->x + input->len, &val );
- TEST_EQUAL( ret, expected_result );
- if( expected_result == 0 )
- {
- TEST_EQUAL( val, expected_value );
- TEST_ASSERT( p == input->x + input->len );
+ ret = mbedtls_asn1_get_bool(&p, input->x + input->len, &val);
+ TEST_EQUAL(ret, expected_result);
+ if (expected_result == 0) {
+ TEST_EQUAL(val, expected_value);
+ TEST_ASSERT(p == input->x + input->len);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void empty_integer( const data_t *input )
+void empty_integer(const data_t *input)
{
unsigned char *p;
#if defined(MBEDTLS_BIGNUM_C)
@@ -338,34 +329,34 @@
int val;
#if defined(MBEDTLS_BIGNUM_C)
- mbedtls_mpi_init( & actual_mpi );
+ mbedtls_mpi_init(&actual_mpi);
#endif
/* An INTEGER with no content is not valid. */
p = input->x;
- TEST_EQUAL( mbedtls_asn1_get_int( &p, input->x + input->len, &val ),
- MBEDTLS_ERR_ASN1_INVALID_LENGTH );
+ TEST_EQUAL(mbedtls_asn1_get_int(&p, input->x + input->len, &val),
+ MBEDTLS_ERR_ASN1_INVALID_LENGTH);
#if defined(MBEDTLS_BIGNUM_C)
/* INTEGERs are sometimes abused as bitstrings, so the library accepts
* an INTEGER with empty content and gives it the value 0. */
p = input->x;
- TEST_EQUAL( mbedtls_asn1_get_mpi( &p, input->x + input->len, &actual_mpi ),
- 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &actual_mpi, 0 ), 0 );
+ TEST_EQUAL(mbedtls_asn1_get_mpi(&p, input->x + input->len, &actual_mpi),
+ 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&actual_mpi, 0), 0);
#endif
exit:
#if defined(MBEDTLS_BIGNUM_C)
- mbedtls_mpi_free( &actual_mpi );
+ mbedtls_mpi_free(&actual_mpi);
#endif
- /*empty cleanup in some configurations*/ ;
+ /*empty cleanup in some configurations*/;
}
/* END_CASE */
/* BEGIN_CASE */
-void get_integer( const data_t *input,
- const char *expected_hex, int expected_result )
+void get_integer(const data_t *input,
+ const char *expected_hex, int expected_result)
{
unsigned char *p;
#if defined(MBEDTLS_BIGNUM_C)
@@ -380,26 +371,24 @@
int ret;
#if defined(MBEDTLS_BIGNUM_C)
- mbedtls_mpi_init( &expected_mpi );
- mbedtls_mpi_init( &actual_mpi );
- mbedtls_mpi_init( &complement );
+ mbedtls_mpi_init(&expected_mpi);
+ mbedtls_mpi_init(&actual_mpi);
+ mbedtls_mpi_init(&complement);
#endif
errno = 0;
- expected_value = strtol( expected_hex, NULL, 16 );
- if( expected_result == 0 &&
- ( errno == ERANGE
+ expected_value = strtol(expected_hex, NULL, 16);
+ if (expected_result == 0 &&
+ (errno == ERANGE
#if LONG_MAX > INT_MAX
- || expected_value > INT_MAX || expected_value < INT_MIN
+ || expected_value > INT_MAX || expected_value < INT_MIN
#endif
- ) )
- {
+ )) {
/* The library returns the dubious error code INVALID_LENGTH
* for integers that are out of range. */
expected_result_for_int = MBEDTLS_ERR_ASN1_INVALID_LENGTH;
}
- if( expected_result == 0 && expected_value < 0 )
- {
+ if (expected_result == 0 && expected_value < 0) {
/* The library does not support negative INTEGERs and
* returns the dubious error code INVALID_LENGTH.
* Test that we preserve the historical behavior. If we
@@ -408,34 +397,28 @@
}
p = input->x;
- ret = mbedtls_asn1_get_int( &p, input->x + input->len, &val );
- TEST_EQUAL( ret, expected_result_for_int );
- if( ret == 0 )
- {
- TEST_EQUAL( val, expected_value );
- TEST_ASSERT( p == input->x + input->len );
+ ret = mbedtls_asn1_get_int(&p, input->x + input->len, &val);
+ TEST_EQUAL(ret, expected_result_for_int);
+ if (ret == 0) {
+ TEST_EQUAL(val, expected_value);
+ TEST_ASSERT(p == input->x + input->len);
}
#if defined(MBEDTLS_BIGNUM_C)
- ret = mbedtls_test_read_mpi( &expected_mpi, expected_hex );
- TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
- if( ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA )
- {
+ ret = mbedtls_test_read_mpi(&expected_mpi, expected_hex);
+ TEST_ASSERT(ret == 0 || ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA);
+ if (ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA) {
/* The data overflows the maximum MPI size. */
expected_result_for_mpi = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
}
p = input->x;
- ret = mbedtls_asn1_get_mpi( &p, input->x + input->len, &actual_mpi );
- TEST_EQUAL( ret, expected_result_for_mpi );
- if( ret == 0 )
- {
- if( expected_value >= 0 )
- {
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &actual_mpi,
- &expected_mpi ) == 0 );
- }
- else
- {
+ ret = mbedtls_asn1_get_mpi(&p, input->x + input->len, &actual_mpi);
+ TEST_EQUAL(ret, expected_result_for_mpi);
+ if (ret == 0) {
+ if (expected_value >= 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&actual_mpi,
+ &expected_mpi) == 0);
+ } else {
/* The library ignores the sign bit in ASN.1 INTEGERs
* (which makes sense insofar as INTEGERs are sometimes
* abused as bit strings), so the result of parsing them
@@ -448,32 +431,32 @@
* negative INTEGERs, we'll fix this test code. */
unsigned char *q = input->x + 1;
size_t len;
- TEST_ASSERT( mbedtls_asn1_get_len( &q, input->x + input->len,
- &len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_lset( &complement, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_shift_l( &complement, len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_add_mpi( &complement, &complement,
- &expected_mpi ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &complement,
- &actual_mpi ) == 0 );
+ TEST_ASSERT(mbedtls_asn1_get_len(&q, input->x + input->len,
+ &len) == 0);
+ TEST_ASSERT(mbedtls_mpi_lset(&complement, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_shift_l(&complement, len * 8) == 0);
+ TEST_ASSERT(mbedtls_mpi_add_mpi(&complement, &complement,
+ &expected_mpi) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&complement,
+ &actual_mpi) == 0);
}
- TEST_ASSERT( p == input->x + input->len );
+ TEST_ASSERT(p == input->x + input->len);
}
#endif
exit:
#if defined(MBEDTLS_BIGNUM_C)
- mbedtls_mpi_free( &expected_mpi );
- mbedtls_mpi_free( &actual_mpi );
- mbedtls_mpi_free( &complement );
+ mbedtls_mpi_free(&expected_mpi);
+ mbedtls_mpi_free(&actual_mpi);
+ mbedtls_mpi_free(&complement);
#endif
- /*empty cleanup in some configurations*/ ;
+ /*empty cleanup in some configurations*/;
}
/* END_CASE */
/* BEGIN_CASE */
-void get_enum( const data_t *input,
- const char *expected_hex, int expected_result )
+void get_enum(const data_t *input,
+ const char *expected_hex, int expected_result)
{
unsigned char *p;
long expected_value;
@@ -482,20 +465,18 @@
int ret;
errno = 0;
- expected_value = strtol( expected_hex, NULL, 16 );
- if( expected_result == 0 &&
- ( errno == ERANGE
+ expected_value = strtol(expected_hex, NULL, 16);
+ if (expected_result == 0 &&
+ (errno == ERANGE
#if LONG_MAX > INT_MAX
- || expected_value > INT_MAX || expected_value < INT_MIN
+ || expected_value > INT_MAX || expected_value < INT_MIN
#endif
- ) )
- {
+ )) {
/* The library returns the dubious error code INVALID_LENGTH
* for integers that are out of range. */
expected_result_for_enum = MBEDTLS_ERR_ASN1_INVALID_LENGTH;
}
- if( expected_result == 0 && expected_value < 0 )
- {
+ if (expected_result == 0 && expected_value < 0) {
/* The library does not support negative INTEGERs and
* returns the dubious error code INVALID_LENGTH.
* Test that we preserve the historical behavior. If we
@@ -504,18 +485,17 @@
}
p = input->x;
- ret = mbedtls_asn1_get_enum( &p, input->x + input->len, &val );
- TEST_EQUAL( ret, expected_result_for_enum );
- if( ret == 0 )
- {
- TEST_EQUAL( val, expected_value );
- TEST_ASSERT( p == input->x + input->len );
+ ret = mbedtls_asn1_get_enum(&p, input->x + input->len, &val);
+ TEST_EQUAL(ret, expected_result_for_enum);
+ if (ret == 0) {
+ TEST_EQUAL(val, expected_value);
+ TEST_ASSERT(p == input->x + input->len);
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */
-void get_mpi_too_large( )
+void get_mpi_too_large()
{
unsigned char *buf = NULL;
unsigned char *p;
@@ -524,63 +504,62 @@
MBEDTLS_MPI_MAX_LIMBS * sizeof(mbedtls_mpi_uint) + 1;
size_t size = too_many_octets + 6;
- mbedtls_mpi_init( &actual_mpi );
+ mbedtls_mpi_init(&actual_mpi);
- ASSERT_ALLOC( buf, size );
+ ASSERT_ALLOC(buf, size);
buf[0] = 0x02; /* tag: INTEGER */
buf[1] = 0x84; /* 4-octet length */
- buf[2] = ( too_many_octets >> 24 ) & 0xff;
- buf[3] = ( too_many_octets >> 16 ) & 0xff;
- buf[4] = ( too_many_octets >> 8 ) & 0xff;
+ buf[2] = (too_many_octets >> 24) & 0xff;
+ buf[3] = (too_many_octets >> 16) & 0xff;
+ buf[4] = (too_many_octets >> 8) & 0xff;
buf[5] = too_many_octets & 0xff;
buf[6] = 0x01; /* most significant octet */
p = buf;
- TEST_EQUAL( mbedtls_asn1_get_mpi( &p, buf + size, &actual_mpi ),
- MBEDTLS_ERR_MPI_ALLOC_FAILED );
+ TEST_EQUAL(mbedtls_asn1_get_mpi(&p, buf + size, &actual_mpi),
+ MBEDTLS_ERR_MPI_ALLOC_FAILED);
exit:
- mbedtls_mpi_free( &actual_mpi );
- mbedtls_free( buf );
+ mbedtls_mpi_free(&actual_mpi);
+ mbedtls_free(buf);
}
/* END_CASE */
/* BEGIN_CASE */
-void get_bitstring( const data_t *input,
- int expected_length, int expected_unused_bits,
- int expected_result, int expected_result_null )
+void get_bitstring(const data_t *input,
+ int expected_length, int expected_unused_bits,
+ int expected_result, int expected_result_null)
{
mbedtls_asn1_bitstring bs = { 0xdead, 0x21, NULL };
unsigned char *p = input->x;
- TEST_EQUAL( mbedtls_asn1_get_bitstring( &p, input->x + input->len, &bs ),
- expected_result );
- if( expected_result == 0 )
- {
- TEST_EQUAL( bs.len, (size_t) expected_length );
- TEST_EQUAL( bs.unused_bits, expected_unused_bits );
- TEST_ASSERT( bs.p != NULL );
- TEST_EQUAL( bs.p - input->x + bs.len, input->len );
- TEST_ASSERT( p == input->x + input->len );
+ TEST_EQUAL(mbedtls_asn1_get_bitstring(&p, input->x + input->len, &bs),
+ expected_result);
+ if (expected_result == 0) {
+ TEST_EQUAL(bs.len, (size_t) expected_length);
+ TEST_EQUAL(bs.unused_bits, expected_unused_bits);
+ TEST_ASSERT(bs.p != NULL);
+ TEST_EQUAL(bs.p - input->x + bs.len, input->len);
+ TEST_ASSERT(p == input->x + input->len);
}
p = input->x;
- TEST_EQUAL( mbedtls_asn1_get_bitstring_null( &p, input->x + input->len,
- &bs.len ),
- expected_result_null );
- if( expected_result_null == 0 )
- {
- TEST_EQUAL( bs.len, (size_t) expected_length );
- if( expected_result == 0 )
- TEST_ASSERT( p == input->x + input->len - bs.len );
+ TEST_EQUAL(mbedtls_asn1_get_bitstring_null(&p, input->x + input->len,
+ &bs.len),
+ expected_result_null);
+ if (expected_result_null == 0) {
+ TEST_EQUAL(bs.len, (size_t) expected_length);
+ if (expected_result == 0) {
+ TEST_ASSERT(p == input->x + input->len - bs.len);
+ }
}
}
/* END_CASE */
/* BEGIN_CASE */
-void get_sequence_of( const data_t *input, int tag,
- const char *description,
- int expected_result )
+void get_sequence_of(const data_t *input, int tag,
+ const char *description,
+ int expected_result)
{
/* The description string is a comma-separated list of integers.
* For each element in the SEQUENCE in input, description contains
@@ -596,53 +575,49 @@
unsigned long n;
unsigned int step = 0;
- TEST_EQUAL( mbedtls_asn1_get_sequence_of( &p, input->x + input->len,
- &head, tag ),
- expected_result );
- if( expected_result == 0 )
- {
- TEST_ASSERT( p == input->x + input->len );
+ TEST_EQUAL(mbedtls_asn1_get_sequence_of(&p, input->x + input->len,
+ &head, tag),
+ expected_result);
+ if (expected_result == 0) {
+ TEST_ASSERT(p == input->x + input->len);
- if( ! *rest )
- {
- TEST_EQUAL( head.buf.tag, 0 );
- TEST_ASSERT( head.buf.p == NULL );
- TEST_EQUAL( head.buf.len, 0 );
- TEST_ASSERT( head.next == NULL );
- }
- else
- {
+ if (!*rest) {
+ TEST_EQUAL(head.buf.tag, 0);
+ TEST_ASSERT(head.buf.p == NULL);
+ TEST_EQUAL(head.buf.len, 0);
+ TEST_ASSERT(head.next == NULL);
+ } else {
cur = &head;
- while( *rest )
- {
- mbedtls_test_set_step( step );
- TEST_ASSERT( cur != NULL );
- TEST_EQUAL( cur->buf.tag, tag );
- n = strtoul( rest, (char **) &rest, 0 );
- TEST_EQUAL( n, (size_t)( cur->buf.p - input->x ) );
+ while (*rest) {
+ mbedtls_test_set_step(step);
+ TEST_ASSERT(cur != NULL);
+ TEST_EQUAL(cur->buf.tag, tag);
+ n = strtoul(rest, (char **) &rest, 0);
+ TEST_EQUAL(n, (size_t) (cur->buf.p - input->x));
++rest;
- n = strtoul( rest, (char **) &rest, 0 );
- TEST_EQUAL( n, cur->buf.len );
- if( *rest )
+ n = strtoul(rest, (char **) &rest, 0);
+ TEST_EQUAL(n, cur->buf.len);
+ if (*rest) {
++rest;
+ }
cur = cur->next;
++step;
}
- TEST_ASSERT( cur == NULL );
+ TEST_ASSERT(cur == NULL);
}
}
exit:
- mbedtls_asn1_sequence_free( head.next );
+ mbedtls_asn1_sequence_free(head.next);
}
/* END_CASE */
/* BEGIN_CASE */
-void traverse_sequence_of( const data_t *input,
- int tag_must_mask, int tag_must_val,
- int tag_may_mask, int tag_may_val,
- const char *description,
- int expected_result )
+void traverse_sequence_of(const data_t *input,
+ int tag_must_mask, int tag_must_val,
+ int tag_may_mask, int tag_may_val,
+ const char *description,
+ int expected_result)
{
/* The description string is a comma-separated list of integers.
* For each element in the SEQUENCE in input, description contains
@@ -652,144 +627,148 @@
* "offset1,tag1,length1,..." */
unsigned char *p = input->x;
- traverse_state_t traverse_state = {input->x, description};
+ traverse_state_t traverse_state = { input->x, description };
int ret;
- ret = mbedtls_asn1_traverse_sequence_of( &p, input->x + input->len,
- (uint8_t) tag_must_mask, (uint8_t) tag_must_val,
- (uint8_t) tag_may_mask, (uint8_t) tag_may_val,
- traverse_callback, &traverse_state );
- if( ret == RET_TRAVERSE_ERROR )
+ ret = mbedtls_asn1_traverse_sequence_of(&p, input->x + input->len,
+ (uint8_t) tag_must_mask, (uint8_t) tag_must_val,
+ (uint8_t) tag_may_mask, (uint8_t) tag_may_val,
+ traverse_callback, &traverse_state);
+ if (ret == RET_TRAVERSE_ERROR) {
goto exit;
- TEST_EQUAL( ret, expected_result );
- TEST_EQUAL( *traverse_state.description, 0 );
+ }
+ TEST_EQUAL(ret, expected_result);
+ TEST_EQUAL(*traverse_state.description, 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void get_alg( const data_t *input,
- int oid_offset, int oid_length,
- int params_tag, int params_offset, int params_length,
- int total_length,
- int expected_result )
+void get_alg(const data_t *input,
+ int oid_offset, int oid_length,
+ int params_tag, int params_offset, int params_length,
+ int total_length,
+ int expected_result)
{
mbedtls_asn1_buf oid = { -1, 0, NULL };
mbedtls_asn1_buf params = { -1, 0, NULL };
unsigned char *p = input->x;
int ret;
- TEST_EQUAL( mbedtls_asn1_get_alg( &p, input->x + input->len,
- &oid, ¶ms ),
- expected_result );
- if( expected_result == 0 )
- {
- TEST_EQUAL( oid.tag, MBEDTLS_ASN1_OID );
- TEST_EQUAL( oid.p - input->x, oid_offset );
- TEST_EQUAL( oid.len, (size_t) oid_length );
- TEST_EQUAL( params.tag, params_tag );
- if( params_offset != 0 )
- TEST_EQUAL( params.p - input->x, params_offset );
- else
- TEST_ASSERT( params.p == NULL );
- TEST_EQUAL( params.len, (size_t) params_length );
- TEST_EQUAL( p - input->x, total_length );
+ TEST_EQUAL(mbedtls_asn1_get_alg(&p, input->x + input->len,
+ &oid, ¶ms),
+ expected_result);
+ if (expected_result == 0) {
+ TEST_EQUAL(oid.tag, MBEDTLS_ASN1_OID);
+ TEST_EQUAL(oid.p - input->x, oid_offset);
+ TEST_EQUAL(oid.len, (size_t) oid_length);
+ TEST_EQUAL(params.tag, params_tag);
+ if (params_offset != 0) {
+ TEST_EQUAL(params.p - input->x, params_offset);
+ } else {
+ TEST_ASSERT(params.p == NULL);
+ }
+ TEST_EQUAL(params.len, (size_t) params_length);
+ TEST_EQUAL(p - input->x, total_length);
}
- ret = mbedtls_asn1_get_alg_null( &p, input->x + input->len, &oid );
- if( expected_result == 0 && params_offset == 0 )
- {
- TEST_EQUAL( oid.tag, MBEDTLS_ASN1_OID );
- TEST_EQUAL( oid.p - input->x, oid_offset );
- TEST_EQUAL( oid.len, (size_t) oid_length );
- TEST_EQUAL( p - input->x, total_length );
+ ret = mbedtls_asn1_get_alg_null(&p, input->x + input->len, &oid);
+ if (expected_result == 0 && params_offset == 0) {
+ TEST_EQUAL(oid.tag, MBEDTLS_ASN1_OID);
+ TEST_EQUAL(oid.p - input->x, oid_offset);
+ TEST_EQUAL(oid.len, (size_t) oid_length);
+ TEST_EQUAL(p - input->x, total_length);
+ } else {
+ TEST_ASSERT(ret != 0);
}
- else
- TEST_ASSERT( ret != 0 );
}
/* END_CASE */
/* BEGIN_CASE */
-void find_named_data( data_t *oid0, data_t *oid1, data_t *oid2, data_t *oid3,
- data_t *needle, int from, int position )
+void find_named_data(data_t *oid0, data_t *oid1, data_t *oid2, data_t *oid3,
+ data_t *needle, int from, int position)
{
- mbedtls_asn1_named_data nd[] ={
- { {0x06, oid0->len, oid0->x}, {0, 0, NULL}, NULL, 0 },
- { {0x06, oid1->len, oid1->x}, {0, 0, NULL}, NULL, 0 },
- { {0x06, oid2->len, oid2->x}, {0, 0, NULL}, NULL, 0 },
- { {0x06, oid3->len, oid3->x}, {0, 0, NULL}, NULL, 0 },
+ mbedtls_asn1_named_data nd[] = {
+ { { 0x06, oid0->len, oid0->x }, { 0, 0, NULL }, NULL, 0 },
+ { { 0x06, oid1->len, oid1->x }, { 0, 0, NULL }, NULL, 0 },
+ { { 0x06, oid2->len, oid2->x }, { 0, 0, NULL }, NULL, 0 },
+ { { 0x06, oid3->len, oid3->x }, { 0, 0, NULL }, NULL, 0 },
};
- mbedtls_asn1_named_data *pointers[ARRAY_LENGTH( nd ) + 1];
+ mbedtls_asn1_named_data *pointers[ARRAY_LENGTH(nd) + 1];
size_t i;
const mbedtls_asn1_named_data *found;
- for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
+ for (i = 0; i < ARRAY_LENGTH(nd); i++) {
pointers[i] = &nd[i];
- pointers[ARRAY_LENGTH( nd )] = NULL;
- for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
+ }
+ pointers[ARRAY_LENGTH(nd)] = NULL;
+ for (i = 0; i < ARRAY_LENGTH(nd); i++) {
nd[i].next = pointers[i+1];
+ }
- found = mbedtls_asn1_find_named_data( (const mbedtls_asn1_named_data*) pointers[from],
- (const char *) needle->x,
- needle->len );
- TEST_ASSERT( found == pointers[position] );
+ found = mbedtls_asn1_find_named_data((const mbedtls_asn1_named_data *) pointers[from],
+ (const char *) needle->x,
+ needle->len);
+ TEST_ASSERT(found == pointers[position]);
}
/* END_CASE */
/* BEGIN_CASE depends_on:!MBEDTLS_DEPRECATED_REMOVED:!MBEDTLS_DEPRECATED_WARNING */
-void free_named_data_null( )
+void free_named_data_null()
{
- mbedtls_asn1_free_named_data( NULL );
+ mbedtls_asn1_free_named_data(NULL);
goto exit; /* Silence unused label warning */
}
/* END_CASE */
/* BEGIN_CASE depends_on:!MBEDTLS_DEPRECATED_REMOVED:!MBEDTLS_DEPRECATED_WARNING */
-void free_named_data( int with_oid, int with_val, int with_next )
+void free_named_data(int with_oid, int with_val, int with_next)
{
mbedtls_asn1_named_data next =
- { {0x06, 0, NULL}, {0, 0xcafe, NULL}, NULL, 0 };
+ { { 0x06, 0, NULL }, { 0, 0xcafe, NULL }, NULL, 0 };
mbedtls_asn1_named_data head =
- { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 };
+ { { 0x06, 0, NULL }, { 0, 0, NULL }, NULL, 0 };
- if( with_oid )
- ASSERT_ALLOC( head.oid.p, 1 );
- if( with_val )
- ASSERT_ALLOC( head.val.p, 1 );
- if( with_next )
+ if (with_oid) {
+ ASSERT_ALLOC(head.oid.p, 1);
+ }
+ if (with_val) {
+ ASSERT_ALLOC(head.val.p, 1);
+ }
+ if (with_next) {
head.next = &next;
+ }
- mbedtls_asn1_free_named_data( &head );
- TEST_ASSERT( head.oid.p == NULL );
- TEST_ASSERT( head.val.p == NULL );
- TEST_ASSERT( head.next == NULL );
- TEST_ASSERT( next.val.len == 0xcafe );
+ mbedtls_asn1_free_named_data(&head);
+ TEST_ASSERT(head.oid.p == NULL);
+ TEST_ASSERT(head.val.p == NULL);
+ TEST_ASSERT(head.next == NULL);
+ TEST_ASSERT(next.val.len == 0xcafe);
exit:
- mbedtls_free( head.oid.p );
- mbedtls_free( head.val.p );
+ mbedtls_free(head.oid.p);
+ mbedtls_free(head.val.p);
}
/* END_CASE */
/* BEGIN_CASE */
-void free_named_data_list( int length )
+void free_named_data_list(int length)
{
mbedtls_asn1_named_data *head = NULL;
int i;
- for( i = 0; i < length; i++ )
- {
+ for (i = 0; i < length; i++) {
mbedtls_asn1_named_data *new = NULL;
- ASSERT_ALLOC( new, 1 );
+ ASSERT_ALLOC(new, 1);
new->next = head;
head = new;
}
- mbedtls_asn1_free_named_data_list( &head );
- TEST_ASSERT( head == NULL );
+ mbedtls_asn1_free_named_data_list(&head);
+ TEST_ASSERT(head == NULL);
/* Most of the point of the test is that it doesn't leak memory.
* So this test is only really useful under a memory leak detection
* framework. */
exit:
- mbedtls_asn1_free_named_data_list( &head );
+ mbedtls_asn1_free_named_data_list(&head);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_asn1write.function b/tests/suites/test_suite_asn1write.function
index 4ed8644..ce0d0f3 100644
--- a/tests/suites/test_suite_asn1write.function
+++ b/tests/suites/test_suite_asn1write.function
@@ -4,8 +4,7 @@
#define GUARD_LEN 4
#define GUARD_VAL 0x2a
-typedef struct
-{
+typedef struct {
unsigned char *output;
unsigned char *start;
unsigned char *end;
@@ -13,41 +12,38 @@
size_t size;
} generic_write_data_t;
-int generic_write_start_step( generic_write_data_t *data )
+int generic_write_start_step(generic_write_data_t *data)
{
- mbedtls_test_set_step( data->size );
- mbedtls_free( data->output );
+ mbedtls_test_set_step(data->size);
+ mbedtls_free(data->output);
data->output = NULL;
- ASSERT_ALLOC( data->output, data->size == 0 ? 1 : data->size );
+ ASSERT_ALLOC(data->output, data->size == 0 ? 1 : data->size);
data->end = data->output + data->size;
data->p = data->end;
data->start = data->end - data->size;
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
-int generic_write_finish_step( generic_write_data_t *data,
- const data_t *expected, int ret )
+int generic_write_finish_step(generic_write_data_t *data,
+ const data_t *expected, int ret)
{
int ok = 0;
- if( data->size < expected->len )
- {
- TEST_EQUAL( ret, MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
- }
- else
- {
- TEST_EQUAL( ret, data->end - data->p );
- TEST_ASSERT( data->p >= data->start );
- TEST_ASSERT( data->p <= data->end );
- ASSERT_COMPARE( data->p, (size_t)( data->end - data->p ),
- expected->x, expected->len );
+ if (data->size < expected->len) {
+ TEST_EQUAL(ret, MBEDTLS_ERR_ASN1_BUF_TOO_SMALL);
+ } else {
+ TEST_EQUAL(ret, data->end - data->p);
+ TEST_ASSERT(data->p >= data->start);
+ TEST_ASSERT(data->p <= data->end);
+ ASSERT_COMPARE(data->p, (size_t) (data->end - data->p),
+ expected->x, expected->len);
}
ok = 1;
exit:
- return( ok );
+ return ok;
}
/* END_HEADER */
@@ -58,206 +54,209 @@
*/
/* BEGIN_CASE */
-void mbedtls_asn1_write_null( data_t *expected )
+void mbedtls_asn1_write_null(data_t *expected)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
int ret;
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
- ret = mbedtls_asn1_write_null( &data.p, data.start );
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ }
+ ret = mbedtls_asn1_write_null(&data.p, data.start);
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
/* There's no parsing function for NULL. */
}
exit:
- mbedtls_free( data.output );
+ mbedtls_free(data.output);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_asn1_write_bool( int val, data_t *expected )
+void mbedtls_asn1_write_bool(int val, data_t *expected)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
int ret;
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
- ret = mbedtls_asn1_write_bool( &data.p, data.start, val );
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ }
+ ret = mbedtls_asn1_write_bool(&data.p, data.start, val);
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
#if defined(MBEDTLS_ASN1_PARSE_C)
- if( ret >= 0 )
- {
+ if (ret >= 0) {
int read = 0xdeadbeef;
- TEST_EQUAL( mbedtls_asn1_get_bool( &data.p, data.end, &read ), 0 );
- TEST_EQUAL( val, read );
+ TEST_EQUAL(mbedtls_asn1_get_bool(&data.p, data.end, &read), 0);
+ TEST_EQUAL(val, read);
}
#endif /* MBEDTLS_ASN1_PARSE_C */
}
exit:
- mbedtls_free( data.output );
+ mbedtls_free(data.output);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_asn1_write_int( int val, data_t *expected )
+void mbedtls_asn1_write_int(int val, data_t *expected)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
int ret;
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
- ret = mbedtls_asn1_write_int( &data.p, data.start, val );
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ }
+ ret = mbedtls_asn1_write_int(&data.p, data.start, val);
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
#if defined(MBEDTLS_ASN1_PARSE_C)
- if( ret >= 0 )
- {
+ if (ret >= 0) {
int read = 0xdeadbeef;
- TEST_EQUAL( mbedtls_asn1_get_int( &data.p, data.end, &read ), 0 );
- TEST_EQUAL( val, read );
+ TEST_EQUAL(mbedtls_asn1_get_int(&data.p, data.end, &read), 0);
+ TEST_EQUAL(val, read);
}
#endif /* MBEDTLS_ASN1_PARSE_C */
}
exit:
- mbedtls_free( data.output );
+ mbedtls_free(data.output);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_asn1_write_enum( int val, data_t *expected )
+void mbedtls_asn1_write_enum(int val, data_t *expected)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
int ret;
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
- ret = mbedtls_asn1_write_enum( &data.p, data.start, val );
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ }
+ ret = mbedtls_asn1_write_enum(&data.p, data.start, val);
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
#if defined(MBEDTLS_ASN1_PARSE_C)
- if( ret >= 0 )
- {
+ if (ret >= 0) {
int read = 0xdeadbeef;
- TEST_EQUAL( mbedtls_asn1_get_enum( &data.p, data.end, &read ), 0 );
- TEST_EQUAL( val, read );
+ TEST_EQUAL(mbedtls_asn1_get_enum(&data.p, data.end, &read), 0);
+ TEST_EQUAL(val, read);
}
#endif /* MBEDTLS_ASN1_PARSE_C */
}
exit:
- mbedtls_free( data.output );
+ mbedtls_free(data.output);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */
-void mbedtls_asn1_write_mpi( data_t *val, data_t *expected )
+void mbedtls_asn1_write_mpi(data_t *val, data_t *expected)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
mbedtls_mpi mpi, read;
int ret;
- mbedtls_mpi_init( &mpi );
- mbedtls_mpi_init( &read );
- TEST_ASSERT( mbedtls_mpi_read_binary( &mpi, val->x, val->len ) == 0 );
+ mbedtls_mpi_init(&mpi);
+ mbedtls_mpi_init(&read);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&mpi, val->x, val->len) == 0);
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
- ret = mbedtls_asn1_write_mpi( &data.p, data.start, &mpi );
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ }
+ ret = mbedtls_asn1_write_mpi(&data.p, data.start, &mpi);
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
#if defined(MBEDTLS_ASN1_PARSE_C)
- if( ret >= 0 )
- {
- TEST_EQUAL( mbedtls_asn1_get_mpi( &data.p, data.end, &read ), 0 );
- TEST_EQUAL( 0, mbedtls_mpi_cmp_mpi( &mpi, &read ) );
+ if (ret >= 0) {
+ TEST_EQUAL(mbedtls_asn1_get_mpi(&data.p, data.end, &read), 0);
+ TEST_EQUAL(0, mbedtls_mpi_cmp_mpi(&mpi, &read));
}
#endif /* MBEDTLS_ASN1_PARSE_C */
/* Skip some intermediate lengths, they're boring. */
- if( expected->len > 10 && data.size == 8 )
+ if (expected->len > 10 && data.size == 8) {
data.size = expected->len - 2;
+ }
}
exit:
- mbedtls_mpi_free( &mpi );
- mbedtls_mpi_free( &read );
- mbedtls_free( data.output );
+ mbedtls_mpi_free(&mpi);
+ mbedtls_mpi_free(&read);
+ mbedtls_free(data.output);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_asn1_write_string( int tag, data_t *content, data_t *expected )
+void mbedtls_asn1_write_string(int tag, data_t *content, data_t *expected)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
int ret;
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
- switch( tag )
- {
+ }
+ switch (tag) {
case MBEDTLS_ASN1_OCTET_STRING:
ret = mbedtls_asn1_write_octet_string(
- &data.p, data.start, content->x, content->len );
+ &data.p, data.start, content->x, content->len);
break;
case MBEDTLS_ASN1_OID:
ret = mbedtls_asn1_write_oid(
&data.p, data.start,
- (const char *) content->x, content->len );
+ (const char *) content->x, content->len);
break;
case MBEDTLS_ASN1_UTF8_STRING:
ret = mbedtls_asn1_write_utf8_string(
&data.p, data.start,
- (const char *) content->x, content->len );
+ (const char *) content->x, content->len);
break;
case MBEDTLS_ASN1_PRINTABLE_STRING:
ret = mbedtls_asn1_write_printable_string(
&data.p, data.start,
- (const char *) content->x, content->len );
+ (const char *) content->x, content->len);
break;
case MBEDTLS_ASN1_IA5_STRING:
ret = mbedtls_asn1_write_ia5_string(
&data.p, data.start,
- (const char *) content->x, content->len );
+ (const char *) content->x, content->len);
break;
default:
ret = mbedtls_asn1_write_tagged_string(
&data.p, data.start, tag,
- (const char *) content->x, content->len );
+ (const char *) content->x, content->len);
}
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
/* There's no parsing function for octet or character strings. */
/* Skip some intermediate lengths, they're boring. */
- if( expected->len > 10 && data.size == 8 )
+ if (expected->len > 10 && data.size == 8) {
data.size = expected->len - 2;
+ }
}
exit:
- mbedtls_free( data.output );
+ mbedtls_free(data.output);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_asn1_write_algorithm_identifier( data_t *oid,
- int par_len,
- data_t *expected )
+void mbedtls_asn1_write_algorithm_identifier(data_t *oid,
+ int par_len,
+ data_t *expected)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
int ret;
@@ -265,29 +264,30 @@
unsigned char *buf_complete = NULL;
#endif /* MBEDTLS_ASN1_PARSE_C */
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
+ }
ret = mbedtls_asn1_write_algorithm_identifier(
&data.p, data.start,
- (const char *) oid->x, oid->len, par_len );
+ (const char *) oid->x, oid->len, par_len);
/* If params_len != 0, mbedtls_asn1_write_algorithm_identifier()
* assumes that the parameters are already present in the buffer
* and returns a length that accounts for this, but our test
* data omits the parameters. */
- if( ret >= 0 )
+ if (ret >= 0) {
ret -= par_len;
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ }
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
#if defined(MBEDTLS_ASN1_PARSE_C)
/* Only do a parse-back test if the parameters aren't too large for
* a small-heap environment. The boundary is somewhat arbitrary. */
- if( ret >= 0 && par_len <= 1234 )
- {
- mbedtls_asn1_buf alg = {0, 0, NULL};
- mbedtls_asn1_buf params = {0, 0, NULL};
+ if (ret >= 0 && par_len <= 1234) {
+ mbedtls_asn1_buf alg = { 0, 0, NULL };
+ mbedtls_asn1_buf params = { 0, 0, NULL };
/* The writing function doesn't write the parameters unless
* they're null: it only takes their length as input. But the
* parsing function requires the parameters to be present.
@@ -296,59 +296,52 @@
size_t len_complete = data_len + par_len;
unsigned char expected_params_tag;
size_t expected_params_len;
- ASSERT_ALLOC( buf_complete, len_complete );
+ ASSERT_ALLOC(buf_complete, len_complete);
unsigned char *end_complete = buf_complete + len_complete;
- memcpy( buf_complete, data.p, data_len );
- if( par_len == 0 )
- {
+ memcpy(buf_complete, data.p, data_len);
+ if (par_len == 0) {
/* mbedtls_asn1_write_algorithm_identifier() wrote a NULL */
expected_params_tag = 0x05;
expected_params_len = 0;
- }
- else if( par_len >= 2 && par_len < 2 + 128 )
- {
+ } else if (par_len >= 2 && par_len < 2 + 128) {
/* Write an OCTET STRING with a short length encoding */
expected_params_tag = buf_complete[data_len] = 0x04;
expected_params_len = par_len - 2;
buf_complete[data_len + 1] = (unsigned char) expected_params_len;
- }
- else if( par_len >= 4 + 128 && par_len < 3 + 256 * 256 )
- {
+ } else if (par_len >= 4 + 128 && par_len < 3 + 256 * 256) {
/* Write an OCTET STRING with a two-byte length encoding */
expected_params_tag = buf_complete[data_len] = 0x04;
expected_params_len = par_len - 4;
buf_complete[data_len + 1] = 0x82;
- buf_complete[data_len + 2] = (unsigned char) ( expected_params_len >> 8 );
- buf_complete[data_len + 3] = (unsigned char) ( expected_params_len );
- }
- else
- {
- TEST_ASSERT( ! "Bad test data: invalid length of ASN.1 element" );
+ buf_complete[data_len + 2] = (unsigned char) (expected_params_len >> 8);
+ buf_complete[data_len + 3] = (unsigned char) (expected_params_len);
+ } else {
+ TEST_ASSERT(!"Bad test data: invalid length of ASN.1 element");
}
unsigned char *p = buf_complete;
- TEST_EQUAL( mbedtls_asn1_get_alg( &p, end_complete,
- &alg, ¶ms ), 0 );
- TEST_EQUAL( alg.tag, MBEDTLS_ASN1_OID );
- ASSERT_COMPARE( alg.p, alg.len, oid->x, oid->len );
- TEST_EQUAL( params.tag, expected_params_tag );
- TEST_EQUAL( params.len, expected_params_len );
- mbedtls_free( buf_complete );
+ TEST_EQUAL(mbedtls_asn1_get_alg(&p, end_complete,
+ &alg, ¶ms), 0);
+ TEST_EQUAL(alg.tag, MBEDTLS_ASN1_OID);
+ ASSERT_COMPARE(alg.p, alg.len, oid->x, oid->len);
+ TEST_EQUAL(params.tag, expected_params_tag);
+ TEST_EQUAL(params.len, expected_params_len);
+ mbedtls_free(buf_complete);
buf_complete = NULL;
}
#endif /* MBEDTLS_ASN1_PARSE_C */
}
exit:
- mbedtls_free( data.output );
+ mbedtls_free(data.output);
#if defined(MBEDTLS_ASN1_PARSE_C)
- mbedtls_free( buf_complete );
+ mbedtls_free(buf_complete);
#endif /* MBEDTLS_ASN1_PARSE_C */
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */
-void mbedtls_asn1_write_len( int len, data_t * asn1, int buf_len,
- int result )
+void mbedtls_asn1_write_len(int len, data_t *asn1, int buf_len,
+ int result)
{
int ret;
unsigned char buf[150];
@@ -356,260 +349,253 @@
size_t i;
size_t read_len;
- memset( buf, GUARD_VAL, sizeof( buf ) );
+ memset(buf, GUARD_VAL, sizeof(buf));
p = buf + GUARD_LEN + buf_len;
- ret = mbedtls_asn1_write_len( &p, buf + GUARD_LEN, (size_t) len );
+ ret = mbedtls_asn1_write_len(&p, buf + GUARD_LEN, (size_t) len);
- TEST_ASSERT( ret == result );
+ TEST_ASSERT(ret == result);
/* Check for buffer overwrite on both sides */
- for( i = 0; i < GUARD_LEN; i++ )
- {
- TEST_ASSERT( buf[i] == GUARD_VAL );
- TEST_ASSERT( buf[GUARD_LEN + buf_len + i] == GUARD_VAL );
+ for (i = 0; i < GUARD_LEN; i++) {
+ TEST_ASSERT(buf[i] == GUARD_VAL);
+ TEST_ASSERT(buf[GUARD_LEN + buf_len + i] == GUARD_VAL);
}
- if( result >= 0 )
- {
- TEST_ASSERT( p + asn1->len == buf + GUARD_LEN + buf_len );
+ if (result >= 0) {
+ TEST_ASSERT(p + asn1->len == buf + GUARD_LEN + buf_len);
- TEST_ASSERT( memcmp( p, asn1->x, asn1->len ) == 0 );
+ TEST_ASSERT(memcmp(p, asn1->x, asn1->len) == 0);
/* Read back with mbedtls_asn1_get_len() to check */
- ret = mbedtls_asn1_get_len( &p, buf + GUARD_LEN + buf_len, &read_len );
+ ret = mbedtls_asn1_get_len(&p, buf + GUARD_LEN + buf_len, &read_len);
- if( len == 0 )
- {
- TEST_ASSERT( ret == 0 );
- }
- else
- {
+ if (len == 0) {
+ TEST_ASSERT(ret == 0);
+ } else {
/* Return will be MBEDTLS_ERR_ASN1_OUT_OF_DATA because the rest of
* the buffer is missing
*/
- TEST_ASSERT( ret == MBEDTLS_ERR_ASN1_OUT_OF_DATA );
+ TEST_ASSERT(ret == MBEDTLS_ERR_ASN1_OUT_OF_DATA);
}
- TEST_ASSERT( read_len == (size_t) len );
- TEST_ASSERT( p == buf + GUARD_LEN + buf_len );
+ TEST_ASSERT(read_len == (size_t) len);
+ TEST_ASSERT(p == buf + GUARD_LEN + buf_len);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void test_asn1_write_bitstrings( data_t *bitstring, int bits,
- data_t *expected, int is_named )
+void test_asn1_write_bitstrings(data_t *bitstring, int bits,
+ data_t *expected, int is_named)
{
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
int ret;
- int ( *func )( unsigned char **p, const unsigned char *start,
- const unsigned char *buf, size_t bits ) =
- ( is_named ? mbedtls_asn1_write_named_bitstring :
- mbedtls_asn1_write_bitstring );
+ int (*func)(unsigned char **p, const unsigned char *start,
+ const unsigned char *buf, size_t bits) =
+ (is_named ? mbedtls_asn1_write_named_bitstring :
+ mbedtls_asn1_write_bitstring);
#if defined(MBEDTLS_ASN1_PARSE_C)
unsigned char *masked_bitstring = NULL;
#endif /* MBEDTLS_ASN1_PARSE_C */
/* The API expects `bitstring->x` to contain `bits` bits. */
- size_t byte_length = ( bits + 7 ) / 8;
- TEST_ASSERT( bitstring->len >= byte_length );
+ size_t byte_length = (bits + 7) / 8;
+ TEST_ASSERT(bitstring->len >= byte_length);
#if defined(MBEDTLS_ASN1_PARSE_C)
- ASSERT_ALLOC( masked_bitstring, byte_length );
- if( byte_length != 0 )
- {
- memcpy( masked_bitstring, bitstring->x, byte_length );
- if( bits % 8 != 0 )
- masked_bitstring[byte_length - 1] &= ~( 0xff >> ( bits % 8 ) );
+ ASSERT_ALLOC(masked_bitstring, byte_length);
+ if (byte_length != 0) {
+ memcpy(masked_bitstring, bitstring->x, byte_length);
+ if (bits % 8 != 0) {
+ masked_bitstring[byte_length - 1] &= ~(0xff >> (bits % 8));
+ }
}
size_t value_bits = bits;
- if( is_named )
- {
+ if (is_named) {
/* In a named bit string, all trailing 0 bits are removed. */
- while( byte_length > 0 && masked_bitstring[byte_length - 1] == 0 )
+ while (byte_length > 0 && masked_bitstring[byte_length - 1] == 0) {
--byte_length;
+ }
value_bits = 8 * byte_length;
- if( byte_length > 0 )
- {
+ if (byte_length > 0) {
unsigned char last_byte = masked_bitstring[byte_length - 1];
- for( unsigned b = 1; b < 0xff && ( last_byte & b ) == 0; b <<= 1 )
+ for (unsigned b = 1; b < 0xff && (last_byte & b) == 0; b <<= 1) {
--value_bits;
+ }
}
}
#endif /* MBEDTLS_ASN1_PARSE_C */
- for( data.size = 0; data.size <= expected->len + 1; data.size++ )
- {
- if( ! generic_write_start_step( &data ) )
+ for (data.size = 0; data.size <= expected->len + 1; data.size++) {
+ if (!generic_write_start_step(&data)) {
goto exit;
- ret = ( *func )( &data.p, data.start, bitstring->x, bits );
- if( ! generic_write_finish_step( &data, expected, ret ) )
+ }
+ ret = (*func)(&data.p, data.start, bitstring->x, bits);
+ if (!generic_write_finish_step(&data, expected, ret)) {
goto exit;
+ }
#if defined(MBEDTLS_ASN1_PARSE_C)
- if( ret >= 0 )
- {
- mbedtls_asn1_bitstring read = {0, 0, NULL};
- TEST_EQUAL( mbedtls_asn1_get_bitstring( &data.p, data.end,
- &read ), 0 );
- ASSERT_COMPARE( read.p, read.len,
- masked_bitstring, byte_length );
- TEST_EQUAL( read.unused_bits, 8 * byte_length - value_bits );
+ if (ret >= 0) {
+ mbedtls_asn1_bitstring read = { 0, 0, NULL };
+ TEST_EQUAL(mbedtls_asn1_get_bitstring(&data.p, data.end,
+ &read), 0);
+ ASSERT_COMPARE(read.p, read.len,
+ masked_bitstring, byte_length);
+ TEST_EQUAL(read.unused_bits, 8 * byte_length - value_bits);
}
#endif /* MBEDTLS_ASN1_PARSE_C */
}
exit:
- mbedtls_free( data.output );
+ mbedtls_free(data.output);
#if defined(MBEDTLS_ASN1_PARSE_C)
- mbedtls_free( masked_bitstring );
+ mbedtls_free(masked_bitstring);
#endif /* MBEDTLS_ASN1_PARSE_C */
}
/* END_CASE */
/* BEGIN_CASE */
-void store_named_data_find( data_t *oid0, data_t *oid1,
- data_t *oid2, data_t *oid3,
- data_t *needle, int from, int position )
+void store_named_data_find(data_t *oid0, data_t *oid1,
+ data_t *oid2, data_t *oid3,
+ data_t *needle, int from, int position)
{
- data_t *oid[4] = {oid0, oid1, oid2, oid3};
- mbedtls_asn1_named_data nd[] ={
- { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
- { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
- { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
- { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
+ data_t *oid[4] = { oid0, oid1, oid2, oid3 };
+ mbedtls_asn1_named_data nd[] = {
+ { { 0x06, 0, NULL }, { 0, 0, NULL }, NULL, 0 },
+ { { 0x06, 0, NULL }, { 0, 0, NULL }, NULL, 0 },
+ { { 0x06, 0, NULL }, { 0, 0, NULL }, NULL, 0 },
+ { { 0x06, 0, NULL }, { 0, 0, NULL }, NULL, 0 },
};
- mbedtls_asn1_named_data *pointers[ARRAY_LENGTH( nd ) + 1];
+ mbedtls_asn1_named_data *pointers[ARRAY_LENGTH(nd) + 1];
size_t i;
mbedtls_asn1_named_data *head = NULL;
mbedtls_asn1_named_data *found = NULL;
- for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
+ for (i = 0; i < ARRAY_LENGTH(nd); i++) {
pointers[i] = &nd[i];
- pointers[ARRAY_LENGTH( nd )] = NULL;
- for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
- {
- ASSERT_ALLOC( nd[i].oid.p, oid[i]->len );
- memcpy( nd[i].oid.p, oid[i]->x, oid[i]->len );
+ }
+ pointers[ARRAY_LENGTH(nd)] = NULL;
+ for (i = 0; i < ARRAY_LENGTH(nd); i++) {
+ ASSERT_ALLOC(nd[i].oid.p, oid[i]->len);
+ memcpy(nd[i].oid.p, oid[i]->x, oid[i]->len);
nd[i].oid.len = oid[i]->len;
nd[i].next = pointers[i+1];
}
head = pointers[from];
- found = mbedtls_asn1_store_named_data( &head,
- (const char *) needle->x,
- needle->len,
- NULL, 0 );
+ found = mbedtls_asn1_store_named_data(&head,
+ (const char *) needle->x,
+ needle->len,
+ NULL, 0);
/* In any case, the existing list structure must be unchanged. */
- for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
- TEST_ASSERT( nd[i].next == pointers[i+1] );
-
- if( position >= 0 )
- {
- /* position should have been found and modified. */
- TEST_ASSERT( head == pointers[from] );
- TEST_ASSERT( found == pointers[position] );
+ for (i = 0; i < ARRAY_LENGTH(nd); i++) {
+ TEST_ASSERT(nd[i].next == pointers[i+1]);
}
- else
- {
+
+ if (position >= 0) {
+ /* position should have been found and modified. */
+ TEST_ASSERT(head == pointers[from]);
+ TEST_ASSERT(found == pointers[position]);
+ } else {
/* A new entry should have been created. */
- TEST_ASSERT( found == head );
- TEST_ASSERT( head->next == pointers[from] );
- for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
- TEST_ASSERT( found != &nd[i] );
+ TEST_ASSERT(found == head);
+ TEST_ASSERT(head->next == pointers[from]);
+ for (i = 0; i < ARRAY_LENGTH(nd); i++) {
+ TEST_ASSERT(found != &nd[i]);
+ }
}
exit:
- if( found != NULL && found == head && found != pointers[from] )
- {
- mbedtls_free( found->oid.p );
- mbedtls_free( found );
+ if (found != NULL && found == head && found != pointers[from]) {
+ mbedtls_free(found->oid.p);
+ mbedtls_free(found);
}
- for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
- mbedtls_free( nd[i].oid.p );
+ for (i = 0; i < ARRAY_LENGTH(nd); i++) {
+ mbedtls_free(nd[i].oid.p);
+ }
}
/* END_CASE */
/* BEGIN_CASE */
-void store_named_data_val_found( int old_len, int new_len )
+void store_named_data_val_found(int old_len, int new_len)
{
mbedtls_asn1_named_data nd =
- { {0x06, 3, (unsigned char *) "OID"}, {0, 0, NULL}, NULL, 0 };
+ { { 0x06, 3, (unsigned char *) "OID" }, { 0, 0, NULL }, NULL, 0 };
mbedtls_asn1_named_data *head = &nd;
mbedtls_asn1_named_data *found = NULL;
unsigned char *old_val = NULL;
unsigned char *new_val = (unsigned char *) "new value";
- if( old_len != 0 )
- {
- ASSERT_ALLOC( nd.val.p, (size_t) old_len );
+ if (old_len != 0) {
+ ASSERT_ALLOC(nd.val.p, (size_t) old_len);
old_val = nd.val.p;
nd.val.len = old_len;
- memset( old_val, 'x', old_len );
+ memset(old_val, 'x', old_len);
}
- if( new_len <= 0 )
- {
- new_len = - new_len;
+ if (new_len <= 0) {
+ new_len = -new_len;
new_val = NULL;
}
- found = mbedtls_asn1_store_named_data( &head, "OID", 3,
- new_val, new_len );
- TEST_ASSERT( head == &nd );
- TEST_ASSERT( found == head );
+ found = mbedtls_asn1_store_named_data(&head, "OID", 3,
+ new_val, new_len);
+ TEST_ASSERT(head == &nd);
+ TEST_ASSERT(found == head);
- if( new_val != NULL)
- ASSERT_COMPARE( found->val.p, found->val.len,
- new_val, (size_t) new_len );
- if( new_len == 0)
- TEST_ASSERT( found->val.p == NULL );
- else if( new_len == old_len )
- TEST_ASSERT( found->val.p == old_val );
- else
- TEST_ASSERT( found->val.p != old_val );
+ if (new_val != NULL) {
+ ASSERT_COMPARE(found->val.p, found->val.len,
+ new_val, (size_t) new_len);
+ }
+ if (new_len == 0) {
+ TEST_ASSERT(found->val.p == NULL);
+ } else if (new_len == old_len) {
+ TEST_ASSERT(found->val.p == old_val);
+ } else {
+ TEST_ASSERT(found->val.p != old_val);
+ }
exit:
- mbedtls_free( nd.val.p );
+ mbedtls_free(nd.val.p);
}
/* END_CASE */
/* BEGIN_CASE */
-void store_named_data_val_new( int new_len, int set_new_val )
+void store_named_data_val_new(int new_len, int set_new_val)
{
mbedtls_asn1_named_data *head = NULL;
mbedtls_asn1_named_data *found = NULL;
const unsigned char *oid = (unsigned char *) "OID";
- size_t oid_len = strlen( (const char *) oid );
+ size_t oid_len = strlen((const char *) oid);
const unsigned char *new_val = (unsigned char *) "new value";
- if( set_new_val == 0 )
+ if (set_new_val == 0) {
new_val = NULL;
+ }
- found = mbedtls_asn1_store_named_data( &head,
- (const char *) oid, oid_len,
- new_val, (size_t) new_len );
- TEST_ASSERT( found != NULL );
- TEST_ASSERT( found == head );
- TEST_ASSERT( found->oid.p != oid );
- ASSERT_COMPARE( found->oid.p, found->oid.len, oid, oid_len );
- if( new_len == 0 )
- TEST_ASSERT( found->val.p == NULL );
- else if( new_val == NULL )
- TEST_ASSERT( found->val.p != NULL );
- else
- {
- TEST_ASSERT( found->val.p != new_val );
- ASSERT_COMPARE( found->val.p, found->val.len,
- new_val, (size_t) new_len );
+ found = mbedtls_asn1_store_named_data(&head,
+ (const char *) oid, oid_len,
+ new_val, (size_t) new_len);
+ TEST_ASSERT(found != NULL);
+ TEST_ASSERT(found == head);
+ TEST_ASSERT(found->oid.p != oid);
+ ASSERT_COMPARE(found->oid.p, found->oid.len, oid, oid_len);
+ if (new_len == 0) {
+ TEST_ASSERT(found->val.p == NULL);
+ } else if (new_val == NULL) {
+ TEST_ASSERT(found->val.p != NULL);
+ } else {
+ TEST_ASSERT(found->val.p != new_val);
+ ASSERT_COMPARE(found->val.p, found->val.len,
+ new_val, (size_t) new_len);
}
exit:
- if( found != NULL )
- {
- mbedtls_free( found->oid.p );
- mbedtls_free( found->val.p );
+ if (found != NULL) {
+ mbedtls_free(found->oid.p);
+ mbedtls_free(found->val.p);
}
- mbedtls_free( found );
+ mbedtls_free(found);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_base64.function b/tests/suites/test_suite_base64.function
index 7baa3d5..ce6bd42 100644
--- a/tests/suites/test_suite_base64.function
+++ b/tests/suites/test_suite_base64.function
@@ -17,67 +17,66 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
-void mask_of_range( int low_arg, int high_arg )
+void mask_of_range(int low_arg, int high_arg)
{
unsigned char low = low_arg, high = high_arg;
unsigned c;
- for( c = 0; c <= 0xff; c++ )
- {
- mbedtls_test_set_step( c );
- TEST_CF_SECRET( &c, sizeof( c ) );
- unsigned char m = mbedtls_ct_uchar_mask_of_range( low, high, c );
- TEST_CF_PUBLIC( &c, sizeof( c ) );
- TEST_CF_PUBLIC( &m, sizeof( m ) );
- if( low <= c && c <= high )
- TEST_EQUAL( m, 0xff );
- else
- TEST_EQUAL( m, 0 );
+ for (c = 0; c <= 0xff; c++) {
+ mbedtls_test_set_step(c);
+ TEST_CF_SECRET(&c, sizeof(c));
+ unsigned char m = mbedtls_ct_uchar_mask_of_range(low, high, c);
+ TEST_CF_PUBLIC(&c, sizeof(c));
+ TEST_CF_PUBLIC(&m, sizeof(m));
+ if (low <= c && c <= high) {
+ TEST_EQUAL(m, 0xff);
+ } else {
+ TEST_EQUAL(m, 0);
+ }
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
-void enc_chars( )
+void enc_chars()
{
- for( unsigned value = 0; value < 64; value++ )
- {
- mbedtls_test_set_step( value );
- TEST_CF_SECRET( &value, sizeof( value ) );
- unsigned char digit = mbedtls_ct_base64_enc_char( value );
- TEST_CF_PUBLIC( &value, sizeof( value ) );
- TEST_CF_PUBLIC( &digit, sizeof( digit ) );
- TEST_EQUAL( digit, base64_digits[value] );
+ for (unsigned value = 0; value < 64; value++) {
+ mbedtls_test_set_step(value);
+ TEST_CF_SECRET(&value, sizeof(value));
+ unsigned char digit = mbedtls_ct_base64_enc_char(value);
+ TEST_CF_PUBLIC(&value, sizeof(value));
+ TEST_CF_PUBLIC(&digit, sizeof(digit));
+ TEST_EQUAL(digit, base64_digits[value]);
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
-void dec_chars( )
+void dec_chars()
{
char *p;
signed char expected;
- for( unsigned c = 0; c <= 0xff; c++ )
- {
- mbedtls_test_set_step( c );
+ for (unsigned c = 0; c <= 0xff; c++) {
+ mbedtls_test_set_step(c);
/* base64_digits is 0-terminated. sizeof()-1 excludes the trailing 0. */
- p = memchr( base64_digits, c, sizeof( base64_digits ) - 1 );
- if( p == NULL )
+ p = memchr(base64_digits, c, sizeof(base64_digits) - 1);
+ if (p == NULL) {
expected = -1;
- else
+ } else {
expected = p - base64_digits;
- TEST_CF_SECRET( &c, sizeof( c ) );
- signed char actual = mbedtls_ct_base64_dec_value( c );
- TEST_CF_PUBLIC( &c, sizeof( c ) );
- TEST_CF_PUBLIC( &actual, sizeof( actual ) );
- TEST_EQUAL( actual, expected );
+ }
+ TEST_CF_SECRET(&c, sizeof(c));
+ signed char actual = mbedtls_ct_base64_dec_value(c);
+ TEST_CF_PUBLIC(&c, sizeof(c));
+ TEST_CF_PUBLIC(&actual, sizeof(actual));
+ TEST_EQUAL(actual, expected);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_base64_encode( char * src_string, char * dst_string,
- int dst_buf_size, int result )
+void mbedtls_base64_encode(char *src_string, char *dst_string,
+ int dst_buf_size, int result)
{
unsigned char src_str[1000];
unsigned char dst_str[1000];
@@ -86,26 +85,25 @@
memset(src_str, 0x00, 1000);
memset(dst_str, 0x00, 1000);
- strncpy( (char *) src_str, src_string, sizeof(src_str) - 1 );
- src_len = strlen( (char *) src_str );
+ strncpy((char *) src_str, src_string, sizeof(src_str) - 1);
+ src_len = strlen((char *) src_str);
- TEST_CF_SECRET( src_str, sizeof( src_str ) );
- TEST_ASSERT( mbedtls_base64_encode( dst_str, dst_buf_size, &len, src_str, src_len) == result );
- TEST_CF_PUBLIC( src_str, sizeof( src_str ) );
+ TEST_CF_SECRET(src_str, sizeof(src_str));
+ TEST_ASSERT(mbedtls_base64_encode(dst_str, dst_buf_size, &len, src_str, src_len) == result);
+ TEST_CF_PUBLIC(src_str, sizeof(src_str));
/* dest_str will have had tainted data copied to it, prevent the TEST_ASSERT below from triggering
CF failures by unmarking it. */
- TEST_CF_PUBLIC( dst_str, len );
+ TEST_CF_PUBLIC(dst_str, len);
- if( result == 0 )
- {
- TEST_ASSERT( strcmp( (char *) dst_str, dst_string ) == 0 );
+ if (result == 0) {
+ TEST_ASSERT(strcmp((char *) dst_str, dst_string) == 0);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_base64_decode( char * src_string, char * dst_string, int result )
+void mbedtls_base64_decode(char *src_string, char *dst_string, int result)
{
unsigned char src_str[1000];
unsigned char dst_str[1000];
@@ -115,77 +113,73 @@
memset(src_str, 0x00, 1000);
memset(dst_str, 0x00, 1000);
- strncpy( (char *) src_str, src_string, sizeof(src_str) - 1 );
- res = mbedtls_base64_decode( dst_str, sizeof( dst_str ), &len, src_str, strlen( (char *) src_str ) );
- TEST_ASSERT( res == result );
- if( result == 0 )
- {
- TEST_ASSERT( strcmp( (char *) dst_str, dst_string ) == 0 );
+ strncpy((char *) src_str, src_string, sizeof(src_str) - 1);
+ res = mbedtls_base64_decode(dst_str, sizeof(dst_str), &len, src_str, strlen((char *) src_str));
+ TEST_ASSERT(res == result);
+ if (result == 0) {
+ TEST_ASSERT(strcmp((char *) dst_str, dst_string) == 0);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void base64_encode_hex( data_t * src, char * dst, int dst_buf_size,
- int result )
+void base64_encode_hex(data_t *src, char *dst, int dst_buf_size,
+ int result)
{
unsigned char *res = NULL;
size_t len;
- res = mbedtls_test_zero_alloc( dst_buf_size );
+ res = mbedtls_test_zero_alloc(dst_buf_size);
- TEST_CF_SECRET( src->x, src->len );
- TEST_ASSERT( mbedtls_base64_encode( res, dst_buf_size, &len, src->x, src->len ) == result );
- TEST_CF_PUBLIC( src->x, src->len );
+ TEST_CF_SECRET(src->x, src->len);
+ TEST_ASSERT(mbedtls_base64_encode(res, dst_buf_size, &len, src->x, src->len) == result);
+ TEST_CF_PUBLIC(src->x, src->len);
/* res will have had tainted data copied to it, prevent the TEST_ASSERT below from triggering
CF failures by unmarking it. */
- TEST_CF_PUBLIC( res, len );
+ TEST_CF_PUBLIC(res, len);
- if( result == 0 )
- {
- TEST_ASSERT( len == strlen( dst ) );
- TEST_ASSERT( memcmp( dst, res, len ) == 0 );
+ if (result == 0) {
+ TEST_ASSERT(len == strlen(dst));
+ TEST_ASSERT(memcmp(dst, res, len) == 0);
}
exit:
- mbedtls_free( res );
+ mbedtls_free(res);
}
/* END_CASE */
/* BEGIN_CASE */
-void base64_decode_hex( char * src, data_t * dst, int dst_buf_size,
- int result )
+void base64_decode_hex(char *src, data_t *dst, int dst_buf_size,
+ int result)
{
unsigned char *res = NULL;
size_t len;
- res = mbedtls_test_zero_alloc( dst_buf_size );
+ res = mbedtls_test_zero_alloc(dst_buf_size);
- TEST_ASSERT( mbedtls_base64_decode( res, dst_buf_size, &len, (unsigned char *) src,
- strlen( src ) ) == result );
- if( result == 0 )
- {
- TEST_ASSERT( len == dst->len );
- TEST_ASSERT( memcmp( dst->x, res, len ) == 0 );
+ TEST_ASSERT(mbedtls_base64_decode(res, dst_buf_size, &len, (unsigned char *) src,
+ strlen(src)) == result);
+ if (result == 0) {
+ TEST_ASSERT(len == dst->len);
+ TEST_ASSERT(memcmp(dst->x, res, len) == 0);
}
exit:
- mbedtls_free( res );
+ mbedtls_free(res);
}
/* END_CASE */
/* BEGIN_CASE */
-void base64_decode_hex_src( data_t * src, char * dst_ref, int result )
+void base64_decode_hex_src(data_t *src, char *dst_ref, int result)
{
unsigned char dst[1000] = { 0 };
size_t len;
- TEST_ASSERT( mbedtls_base64_decode( dst, sizeof( dst ), &len, src->x, src->len ) == result );
- if( result == 0 )
- {
- TEST_ASSERT( len == strlen( dst_ref ) );
- TEST_ASSERT( memcmp( dst, dst_ref, len ) == 0 );
+ TEST_ASSERT(mbedtls_base64_decode(dst, sizeof(dst), &len, src->x, src->len) == result);
+ if (result == 0) {
+ TEST_ASSERT(len == strlen(dst_ref));
+ TEST_ASSERT(memcmp(dst, dst_ref, len) == 0);
}
exit:
@@ -194,8 +188,8 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void base64_selftest( )
+void base64_selftest()
{
- TEST_ASSERT( mbedtls_base64_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_base64_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_bignum.function b/tests/suites/test_suite_bignum.function
index 01af2ff..cefbfc3 100644
--- a/tests/suites/test_suite_bignum.function
+++ b/tests/suites/test_suite_bignum.function
@@ -12,28 +12,27 @@
/* Check the validity of the sign bit in an MPI object. Reject representations
* that are not supported by the rest of the library and indicate a bug when
* constructing the value. */
-static int sign_is_valid( const mbedtls_mpi *X )
+static int sign_is_valid(const mbedtls_mpi *X)
{
/* Only +1 and -1 are valid sign bits, not e.g. 0 */
- if( X->s != 1 && X->s != -1 )
- return( 0 );
+ if (X->s != 1 && X->s != -1) {
+ return 0;
+ }
/* The value 0 must be represented with the sign +1. A "negative zero"
* with s=-1 is an invalid representation. Forbid that. As an exception,
* we sometimes test the robustness of library functions when given
* a negative zero input. If a test case has a negative zero as input,
* we don't mind if the function has a negative zero output. */
- if( ! mbedtls_test_case_uses_negative_0 &&
- mbedtls_mpi_bitlen( X ) == 0 && X->s != 1 )
- {
- return( 0 );
+ if (!mbedtls_test_case_uses_negative_0 &&
+ mbedtls_mpi_bitlen(X) == 0 && X->s != 1) {
+ return 0;
}
- return( 1 );
+ return 1;
}
-typedef struct mbedtls_test_mpi_random
-{
+typedef struct mbedtls_test_mpi_random {
data_t *data;
size_t pos;
size_t chunk_len;
@@ -45,49 +44,49 @@
* test) are stored in the data member of the state structure. Each number is in
* the format that mbedtls_mpi_read_string understands and is chunk_len long.
*/
-int mbedtls_test_mpi_miller_rabin_determinizer( void* state,
- unsigned char* buf,
- size_t len )
+int mbedtls_test_mpi_miller_rabin_determinizer(void *state,
+ unsigned char *buf,
+ size_t len)
{
- mbedtls_test_mpi_random *random = (mbedtls_test_mpi_random*) state;
+ mbedtls_test_mpi_random *random = (mbedtls_test_mpi_random *) state;
- if( random == NULL || random->data->x == NULL || buf == NULL )
- return( -1 );
-
- if( random->pos + random->chunk_len > random->data->len
- || random->chunk_len > len )
- {
- return( -1 );
+ if (random == NULL || random->data->x == NULL || buf == NULL) {
+ return -1;
}
- memset( buf, 0, len );
+ if (random->pos + random->chunk_len > random->data->len
+ || random->chunk_len > len) {
+ return -1;
+ }
+
+ memset(buf, 0, len);
/* The witness is written to the end of the buffer, since the buffer is
* used as big endian, unsigned binary data in mbedtls_mpi_read_binary.
* Writing the witness to the start of the buffer would result in the
* buffer being 'witness 000...000', which would be treated as
* witness * 2^n for some n. */
- memcpy( buf + len - random->chunk_len, &random->data->x[random->pos],
- random->chunk_len );
+ memcpy(buf + len - random->chunk_len, &random->data->x[random->pos],
+ random->chunk_len);
random->pos += random->chunk_len;
- return( 0 );
+ return 0;
}
/* Random generator that is told how many bytes to return. */
-static int f_rng_bytes_left( void *state, unsigned char *buf, size_t len )
+static int f_rng_bytes_left(void *state, unsigned char *buf, size_t len)
{
size_t *bytes_left = state;
size_t i;
- for( i = 0; i < len; i++ )
- {
- if( *bytes_left == 0 )
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ for (i = 0; i < len; i++) {
+ if (*bytes_left == 0) {
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
+ }
buf[i] = *bytes_left & 0xff;
- --( *bytes_left );
+ --(*bytes_left);
}
- return( 0 );
+ return 0;
}
/* END_HEADER */
@@ -98,158 +97,156 @@
*/
/* BEGIN_CASE */
-void mpi_null( )
+void mpi_null()
{
mbedtls_mpi X, Y, Z;
- mbedtls_mpi_init( &X );
- mbedtls_mpi_init( &Y );
- mbedtls_mpi_init( &Z );
+ mbedtls_mpi_init(&X);
+ mbedtls_mpi_init(&Y);
+ mbedtls_mpi_init(&Z);
- TEST_ASSERT( mbedtls_mpi_get_bit( &X, 42 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_lsb( &X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_bitlen( &X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_size( &X ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_get_bit(&X, 42) == 0);
+ TEST_ASSERT(mbedtls_mpi_lsb(&X) == 0);
+ TEST_ASSERT(mbedtls_mpi_bitlen(&X) == 0);
+ TEST_ASSERT(mbedtls_mpi_size(&X) == 0);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_read_write_string( int radix_X, char * input_X, int radix_A,
- char * input_A, int output_size, int result_read,
- int result_write )
+void mpi_read_write_string(int radix_X, char *input_X, int radix_A,
+ char *input_A, int output_size, int result_read,
+ int result_write)
{
mbedtls_mpi X;
char str[1000];
size_t len;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- memset( str, '!', sizeof( str ) );
+ memset(str, '!', sizeof(str));
- TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == result_read );
- if( result_read == 0 )
- {
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_write_string( &X, radix_A, str, output_size, &len ) == result_write );
- if( result_write == 0 )
- {
- TEST_ASSERT( strcasecmp( str, input_A ) == 0 );
- TEST_ASSERT( str[len] == '!' );
+ TEST_ASSERT(mbedtls_mpi_read_string(&X, radix_X, input_X) == result_read);
+ if (result_read == 0) {
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_write_string(&X, radix_A, str, output_size, &len) == result_write);
+ if (result_write == 0) {
+ TEST_ASSERT(strcasecmp(str, input_A) == 0);
+ TEST_ASSERT(str[len] == '!');
}
}
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_read_binary( data_t * buf, char * input_A )
+void mpi_read_binary(data_t *buf, char *input_A)
{
mbedtls_mpi X;
char str[1000];
size_t len;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_mpi_read_binary( &X, buf->x, buf->len ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_write_string( &X, 16, str, sizeof( str ), &len ) == 0 );
- TEST_ASSERT( strcmp( (char *) str, input_A ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&X, buf->x, buf->len) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_write_string(&X, 16, str, sizeof(str), &len) == 0);
+ TEST_ASSERT(strcmp((char *) str, input_A) == 0);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_read_binary_le( data_t * buf, char * input_A )
+void mpi_read_binary_le(data_t *buf, char *input_A)
{
mbedtls_mpi X;
char str[1000];
size_t len;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_mpi_read_binary_le( &X, buf->x, buf->len ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_write_string( &X, 16, str, sizeof( str ), &len ) == 0 );
- TEST_ASSERT( strcmp( (char *) str, input_A ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary_le(&X, buf->x, buf->len) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_write_string(&X, 16, str, sizeof(str), &len) == 0);
+ TEST_ASSERT(strcmp((char *) str, input_A) == 0);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_write_binary( char * input_X, data_t * input_A,
- int output_size, int result )
+void mpi_write_binary(char *input_X, data_t *input_A,
+ int output_size, int result)
{
mbedtls_mpi X;
unsigned char buf[1000];
size_t buflen;
- memset( buf, 0x00, 1000 );
+ memset(buf, 0x00, 1000);
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
- buflen = mbedtls_mpi_size( &X );
- if( buflen > (size_t) output_size )
+ buflen = mbedtls_mpi_size(&X);
+ if (buflen > (size_t) output_size) {
buflen = (size_t) output_size;
+ }
- TEST_ASSERT( mbedtls_mpi_write_binary( &X, buf, buflen ) == result );
- if( result == 0)
- {
+ TEST_ASSERT(mbedtls_mpi_write_binary(&X, buf, buflen) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( buf, input_A->x,
- buflen, input_A->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(buf, input_A->x,
+ buflen, input_A->len) == 0);
}
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_write_binary_le( char * input_X, data_t * input_A,
- int output_size, int result )
+void mpi_write_binary_le(char *input_X, data_t *input_A,
+ int output_size, int result)
{
mbedtls_mpi X;
unsigned char buf[1000];
size_t buflen;
- memset( buf, 0x00, 1000 );
+ memset(buf, 0x00, 1000);
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
- buflen = mbedtls_mpi_size( &X );
- if( buflen > (size_t) output_size )
+ buflen = mbedtls_mpi_size(&X);
+ if (buflen > (size_t) output_size) {
buflen = (size_t) output_size;
+ }
- TEST_ASSERT( mbedtls_mpi_write_binary_le( &X, buf, buflen ) == result );
- if( result == 0)
- {
+ TEST_ASSERT(mbedtls_mpi_write_binary_le(&X, buf, buflen) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( buf, input_A->x,
- buflen, input_A->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(buf, input_A->x,
+ buflen, input_A->len) == 0);
}
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
-void mpi_read_file( char * input_file, data_t * input_A, int result )
+void mpi_read_file(char *input_file, data_t *input_A, int result)
{
mbedtls_mpi X;
unsigned char buf[1000];
@@ -257,678 +254,677 @@
FILE *file;
int ret;
- memset( buf, 0x00, 1000 );
+ memset(buf, 0x00, 1000);
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- file = fopen( input_file, "r" );
- TEST_ASSERT( file != NULL );
- ret = mbedtls_mpi_read_file( &X, 16, file );
+ file = fopen(input_file, "r");
+ TEST_ASSERT(file != NULL);
+ ret = mbedtls_mpi_read_file(&X, 16, file);
fclose(file);
- TEST_ASSERT( ret == result );
+ TEST_ASSERT(ret == result);
- if( result == 0 )
- {
- TEST_ASSERT( sign_is_valid( &X ) );
- buflen = mbedtls_mpi_size( &X );
- TEST_ASSERT( mbedtls_mpi_write_binary( &X, buf, buflen ) == 0 );
+ if (result == 0) {
+ TEST_ASSERT(sign_is_valid(&X));
+ buflen = mbedtls_mpi_size(&X);
+ TEST_ASSERT(mbedtls_mpi_write_binary(&X, buf, buflen) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( buf, input_A->x,
- buflen, input_A->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(buf, input_A->x,
+ buflen, input_A->len) == 0);
}
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
-void mpi_write_file( char * input_X, char * output_file )
+void mpi_write_file(char *input_X, char *output_file)
{
mbedtls_mpi X, Y;
FILE *file_out, *file_in;
int ret;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
- file_out = fopen( output_file, "w" );
- TEST_ASSERT( file_out != NULL );
- ret = mbedtls_mpi_write_file( NULL, &X, 16, file_out );
+ file_out = fopen(output_file, "w");
+ TEST_ASSERT(file_out != NULL);
+ ret = mbedtls_mpi_write_file(NULL, &X, 16, file_out);
fclose(file_out);
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(ret == 0);
- file_in = fopen( output_file, "r" );
- TEST_ASSERT( file_in != NULL );
- ret = mbedtls_mpi_read_file( &Y, 16, file_in );
+ file_in = fopen(output_file, "r");
+ TEST_ASSERT(file_in != NULL);
+ ret = mbedtls_mpi_read_file(&Y, 16, file_in);
fclose(file_in);
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(ret == 0);
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &Y) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_get_bit( char * input_X, int pos, int val )
+void mpi_get_bit(char *input_X, int pos, int val)
{
mbedtls_mpi X;
- mbedtls_mpi_init( &X );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_get_bit( &X, pos ) == val );
+ mbedtls_mpi_init(&X);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_get_bit(&X, pos) == val);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_set_bit( char * input_X, int pos, int val,
- char * output_Y, int result )
+void mpi_set_bit(char *input_X, int pos, int val,
+ char *output_Y, int result)
{
mbedtls_mpi X, Y;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, output_Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_set_bit( &X, pos, val ) == result );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, output_Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_set_bit(&X, pos, val) == result);
- if( result == 0 )
- {
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == 0 );
+ if (result == 0) {
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &Y) == 0);
}
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_lsb( char * input_X, int nr_bits )
+void mpi_lsb(char *input_X, int nr_bits)
{
mbedtls_mpi X;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_lsb( &X ) == (size_t) nr_bits );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_lsb(&X) == (size_t) nr_bits);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_bitlen( char * input_X, int nr_bits )
+void mpi_bitlen(char *input_X, int nr_bits)
{
mbedtls_mpi X;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_bitlen( &X ) == (size_t) nr_bits );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_bitlen(&X) == (size_t) nr_bits);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_gcd( char * input_X, char * input_Y,
- char * input_A )
+void mpi_gcd(char *input_X, char *input_Y,
+ char *input_A)
{
mbedtls_mpi A, X, Y, Z;
- mbedtls_mpi_init( &A ); mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
+ mbedtls_mpi_init(&A); mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_gcd( &Z, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_gcd(&Z, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
exit:
- mbedtls_mpi_free( &A ); mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z );
+ mbedtls_mpi_free(&A); mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_cmp_int( int input_X, int input_A, int result_CMP )
+void mpi_cmp_int(int input_X, int input_A, int result_CMP)
{
mbedtls_mpi X;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_mpi_lset( &X, input_X ) == 0);
- TEST_ASSERT( mbedtls_mpi_cmp_int( &X, input_A ) == result_CMP);
+ TEST_ASSERT(mbedtls_mpi_lset(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&X, input_A) == result_CMP);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_cmp_mpi( char * input_X, char * input_Y,
- int input_A )
+void mpi_cmp_mpi(char *input_X, char *input_Y,
+ int input_A)
{
mbedtls_mpi X, Y;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == input_A );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &Y) == input_A);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_lt_mpi_ct( int size_X, char * input_X,
- int size_Y, char * input_Y,
- int input_ret, int input_err )
+void mpi_lt_mpi_ct(int size_X, char *input_X,
+ int size_Y, char *input_Y,
+ int input_ret, int input_err)
{
unsigned ret = -1;
unsigned input_uret = input_ret;
mbedtls_mpi X, Y;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
- TEST_ASSERT( mbedtls_mpi_grow( &X, size_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_grow( &Y, size_Y ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_grow(&X, size_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_grow(&Y, size_Y) == 0);
- TEST_ASSERT( mbedtls_mpi_lt_mpi_ct( &X, &Y, &ret ) == input_err );
- if( input_err == 0 )
- TEST_ASSERT( ret == input_uret );
+ TEST_ASSERT(mbedtls_mpi_lt_mpi_ct(&X, &Y, &ret) == input_err);
+ if (input_err == 0) {
+ TEST_ASSERT(ret == input_uret);
+ }
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_cmp_abs( char * input_X, char * input_Y,
- int input_A )
+void mpi_cmp_abs(char *input_X, char *input_Y,
+ int input_A)
{
mbedtls_mpi X, Y;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_abs( &X, &Y ) == input_A );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_abs(&X, &Y) == input_A);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_copy( char *src_hex, char *dst_hex )
+void mpi_copy(char *src_hex, char *dst_hex)
{
mbedtls_mpi src, dst, ref;
- mbedtls_mpi_init( &src );
- mbedtls_mpi_init( &dst );
- mbedtls_mpi_init( &ref );
+ mbedtls_mpi_init(&src);
+ mbedtls_mpi_init(&dst);
+ mbedtls_mpi_init(&ref);
- TEST_ASSERT( mbedtls_test_read_mpi( &src, src_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &ref, dst_hex ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&src, src_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&ref, dst_hex) == 0);
/* mbedtls_mpi_copy() */
- TEST_ASSERT( mbedtls_test_read_mpi( &dst, dst_hex ) == 0 );
- TEST_ASSERT( mbedtls_mpi_copy( &dst, &src ) == 0 );
- TEST_ASSERT( sign_is_valid( &dst ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &dst, &src ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&dst, dst_hex) == 0);
+ TEST_ASSERT(mbedtls_mpi_copy(&dst, &src) == 0);
+ TEST_ASSERT(sign_is_valid(&dst));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&dst, &src) == 0);
/* mbedtls_mpi_safe_cond_assign(), assignment done */
- mbedtls_mpi_free( &dst );
- TEST_ASSERT( mbedtls_test_read_mpi( &dst, dst_hex ) == 0 );
- TEST_ASSERT( mbedtls_mpi_safe_cond_assign( &dst, &src, 1 ) == 0 );
- TEST_ASSERT( sign_is_valid( &dst ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &dst, &src ) == 0 );
+ mbedtls_mpi_free(&dst);
+ TEST_ASSERT(mbedtls_test_read_mpi(&dst, dst_hex) == 0);
+ TEST_ASSERT(mbedtls_mpi_safe_cond_assign(&dst, &src, 1) == 0);
+ TEST_ASSERT(sign_is_valid(&dst));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&dst, &src) == 0);
/* mbedtls_mpi_safe_cond_assign(), assignment not done */
- mbedtls_mpi_free( &dst );
- TEST_ASSERT( mbedtls_test_read_mpi( &dst, dst_hex ) == 0 );
- TEST_ASSERT( mbedtls_mpi_safe_cond_assign( &dst, &src, 0 ) == 0 );
- TEST_ASSERT( sign_is_valid( &dst ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &dst, &ref ) == 0 );
+ mbedtls_mpi_free(&dst);
+ TEST_ASSERT(mbedtls_test_read_mpi(&dst, dst_hex) == 0);
+ TEST_ASSERT(mbedtls_mpi_safe_cond_assign(&dst, &src, 0) == 0);
+ TEST_ASSERT(sign_is_valid(&dst));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&dst, &ref) == 0);
exit:
- mbedtls_mpi_free( &src );
- mbedtls_mpi_free( &dst );
- mbedtls_mpi_free( &ref );
+ mbedtls_mpi_free(&src);
+ mbedtls_mpi_free(&dst);
+ mbedtls_mpi_free(&ref);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_copy_self( char *input_X )
+void mpi_copy_self(char *input_X)
{
mbedtls_mpi X, A;
- mbedtls_mpi_init( &A );
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&A);
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_copy( &X, &X ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_copy(&X, &X) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_X ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_X) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
exit:
- mbedtls_mpi_free( &A );
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&A);
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_swap( char *X_hex, char *Y_hex )
+void mpi_swap(char *X_hex, char *Y_hex)
{
mbedtls_mpi X, Y, X0, Y0;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
- mbedtls_mpi_init( &X0 ); mbedtls_mpi_init( &Y0 );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
+ mbedtls_mpi_init(&X0); mbedtls_mpi_init(&Y0);
- TEST_ASSERT( mbedtls_test_read_mpi( &X0, X_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y0, Y_hex ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X0, X_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y0, Y_hex) == 0);
/* mbedtls_mpi_swap() */
- TEST_ASSERT( mbedtls_test_read_mpi( &X, X_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, Y_hex ) == 0 );
- mbedtls_mpi_swap( &X, &Y );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( sign_is_valid( &Y ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y0 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &X0 ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, X_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, Y_hex) == 0);
+ mbedtls_mpi_swap(&X, &Y);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(sign_is_valid(&Y));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &Y0) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Y, &X0) == 0);
/* mbedtls_mpi_safe_cond_swap(), swap done */
- mbedtls_mpi_free( &X );
- mbedtls_mpi_free( &Y );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, X_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, Y_hex ) == 0 );
- TEST_ASSERT( mbedtls_mpi_safe_cond_swap( &X, &Y, 1 ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( sign_is_valid( &Y ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y0 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &X0 ) == 0 );
+ mbedtls_mpi_free(&X);
+ mbedtls_mpi_free(&Y);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, X_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, Y_hex) == 0);
+ TEST_ASSERT(mbedtls_mpi_safe_cond_swap(&X, &Y, 1) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(sign_is_valid(&Y));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &Y0) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Y, &X0) == 0);
/* mbedtls_mpi_safe_cond_swap(), swap not done */
- mbedtls_mpi_free( &X );
- mbedtls_mpi_free( &Y );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, X_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, Y_hex ) == 0 );
- TEST_ASSERT( mbedtls_mpi_safe_cond_swap( &X, &Y, 0 ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( sign_is_valid( &Y ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &X0 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &Y0 ) == 0 );
+ mbedtls_mpi_free(&X);
+ mbedtls_mpi_free(&Y);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, X_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, Y_hex) == 0);
+ TEST_ASSERT(mbedtls_mpi_safe_cond_swap(&X, &Y, 0) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(sign_is_valid(&Y));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &X0) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Y, &Y0) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
- mbedtls_mpi_free( &X0 ); mbedtls_mpi_free( &Y0 );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
+ mbedtls_mpi_free(&X0); mbedtls_mpi_free(&Y0);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_swap_self( char *X_hex )
+void mpi_swap_self(char *X_hex)
{
mbedtls_mpi X, X0;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &X0 );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&X0);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, X_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &X0, X_hex ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, X_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X0, X_hex) == 0);
- mbedtls_mpi_swap( &X, &X );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &X0 ) == 0 );
+ mbedtls_mpi_swap(&X, &X);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &X0) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &X0 );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&X0);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_shrink( int before, int used, int min, int after )
+void mpi_shrink(int before, int used, int min, int after)
{
mbedtls_mpi X;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_mpi_grow( &X, before ) == 0 );
- if( used > 0 )
- {
- size_t used_bit_count = used * 8 * sizeof( mbedtls_mpi_uint );
- TEST_ASSERT( mbedtls_mpi_set_bit( &X, used_bit_count - 1, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_grow(&X, before) == 0);
+ if (used > 0) {
+ size_t used_bit_count = used * 8 * sizeof(mbedtls_mpi_uint);
+ TEST_ASSERT(mbedtls_mpi_set_bit(&X, used_bit_count - 1, 1) == 0);
}
- TEST_EQUAL( X.n, (size_t) before );
- TEST_ASSERT( mbedtls_mpi_shrink( &X, min ) == 0 );
- TEST_EQUAL( X.n, (size_t) after );
+ TEST_EQUAL(X.n, (size_t) before);
+ TEST_ASSERT(mbedtls_mpi_shrink(&X, min) == 0);
+ TEST_EQUAL(X.n, (size_t) after);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_add_mpi( char * input_X, char * input_Y,
- char * input_A )
+void mpi_add_mpi(char *input_X, char *input_Y,
+ char *input_A)
{
mbedtls_mpi X, Y, Z, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_add_mpi( &Z, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_add_mpi(&Z, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
/* result == first operand */
- TEST_ASSERT( mbedtls_mpi_add_mpi( &X, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_add_mpi(&X, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
/* result == second operand */
- TEST_ASSERT( mbedtls_mpi_add_mpi( &Y, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Y ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_add_mpi(&Y, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Y));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Y, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_add_mpi_inplace( char * input_X, char * input_A )
+void mpi_add_mpi_inplace(char *input_X, char *input_A)
{
mbedtls_mpi X, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_sub_abs( &X, &X, &X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_int( &X, 0 ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_sub_abs(&X, &X, &X) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&X, 0) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_add_abs( &X, &X, &X ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_add_abs(&X, &X, &X) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_add_mpi( &X, &X, &X ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_mpi_add_mpi(&X, &X, &X) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_add_abs( char * input_X, char * input_Y,
- char * input_A )
+void mpi_add_abs(char *input_X, char *input_Y,
+ char *input_A)
{
mbedtls_mpi X, Y, Z, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_add_abs( &Z, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_add_abs(&Z, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
/* result == first operand */
- TEST_ASSERT( mbedtls_mpi_add_abs( &X, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_add_abs(&X, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
/* result == second operand */
- TEST_ASSERT( mbedtls_mpi_add_abs( &Y, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Y ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_add_abs(&Y, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Y));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Y, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_add_int( char * input_X, int input_Y,
- char * input_A )
+void mpi_add_int(char *input_X, int input_Y,
+ char *input_A)
{
mbedtls_mpi X, Z, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_add_int( &Z, &X, input_Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_add_int(&Z, &X, input_Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_sub_mpi( char * input_X, char * input_Y,
- char * input_A )
+void mpi_sub_mpi(char *input_X, char *input_Y,
+ char *input_A)
{
mbedtls_mpi X, Y, Z, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_sub_mpi( &Z, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_sub_mpi(&Z, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
/* result == first operand */
- TEST_ASSERT( mbedtls_mpi_sub_mpi( &X, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_sub_mpi(&X, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
/* result == second operand */
- TEST_ASSERT( mbedtls_mpi_sub_mpi( &Y, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Y ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_sub_mpi(&Y, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Y));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Y, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_sub_abs( char * input_X, char * input_Y,
- char * input_A, int sub_result )
+void mpi_sub_abs(char *input_X, char *input_Y,
+ char *input_A, int sub_result)
{
mbedtls_mpi X, Y, Z, A;
int res;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
- res = mbedtls_mpi_sub_abs( &Z, &X, &Y );
- TEST_ASSERT( res == sub_result );
- TEST_ASSERT( sign_is_valid( &Z ) );
- if( res == 0 )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ res = mbedtls_mpi_sub_abs(&Z, &X, &Y);
+ TEST_ASSERT(res == sub_result);
+ TEST_ASSERT(sign_is_valid(&Z));
+ if (res == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
+ }
/* result == first operand */
- TEST_ASSERT( mbedtls_mpi_sub_abs( &X, &X, &Y ) == sub_result );
- TEST_ASSERT( sign_is_valid( &X ) );
- if( sub_result == 0 )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_sub_abs(&X, &X, &Y) == sub_result);
+ TEST_ASSERT(sign_is_valid(&X));
+ if (sub_result == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
+ }
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
/* result == second operand */
- TEST_ASSERT( mbedtls_mpi_sub_abs( &Y, &X, &Y ) == sub_result );
- TEST_ASSERT( sign_is_valid( &Y ) );
- if( sub_result == 0 )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Y, &A ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_sub_abs(&Y, &X, &Y) == sub_result);
+ TEST_ASSERT(sign_is_valid(&Y));
+ if (sub_result == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Y, &A) == 0);
+ }
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_sub_int( char * input_X, int input_Y,
- char * input_A )
+void mpi_sub_int(char *input_X, int input_Y,
+ char *input_A)
{
mbedtls_mpi X, Z, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_sub_int( &Z, &X, input_Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_sub_int(&Z, &X, input_Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mul_mpi( char * input_X, char * input_Y,
- char * input_A )
+void mpi_mul_mpi(char *input_X, char *input_Y,
+ char *input_A)
{
mbedtls_mpi X, Y, Z, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_mul_mpi( &Z, &X, &Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_mul_mpi(&Z, &X, &Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mul_int( char * input_X, int input_Y,
- char * input_A, char * result_comparison )
+void mpi_mul_int(char *input_X, int input_Y,
+ char *input_A, char *result_comparison)
{
mbedtls_mpi X, Z, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_mul_int( &Z, &X, input_Y ) == 0 );
- TEST_ASSERT( sign_is_valid( &Z ) );
- if( strcmp( result_comparison, "==" ) == 0 )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
- else if( strcmp( result_comparison, "!=" ) == 0 )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) != 0 );
- else
- TEST_ASSERT( "unknown operator" == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_mul_int(&Z, &X, input_Y) == 0);
+ TEST_ASSERT(sign_is_valid(&Z));
+ if (strcmp(result_comparison, "==") == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
+ } else if (strcmp(result_comparison, "!=") == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) != 0);
+ } else {
+ TEST_ASSERT("unknown operator" == 0);
+ }
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_div_mpi( char * input_X, char * input_Y,
- char * input_A, char * input_B,
- int div_result )
+void mpi_div_mpi(char *input_X, char *input_Y,
+ char *input_A, char *input_B,
+ int div_result)
{
mbedtls_mpi X, Y, Q, R, A, B;
int res;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &R );
- mbedtls_mpi_init( &A ); mbedtls_mpi_init( &B );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Q); mbedtls_mpi_init(&R);
+ mbedtls_mpi_init(&A); mbedtls_mpi_init(&B);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &B, input_B ) == 0 );
- res = mbedtls_mpi_div_mpi( &Q, &R, &X, &Y );
- TEST_ASSERT( res == div_result );
- if( res == 0 )
- {
- TEST_ASSERT( sign_is_valid( &Q ) );
- TEST_ASSERT( sign_is_valid( &R ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Q, &A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R, &B ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&B, input_B) == 0);
+ res = mbedtls_mpi_div_mpi(&Q, &R, &X, &Y);
+ TEST_ASSERT(res == div_result);
+ if (res == 0) {
+ TEST_ASSERT(sign_is_valid(&Q));
+ TEST_ASSERT(sign_is_valid(&R));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Q, &A) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R, &B) == 0);
}
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &R );
- mbedtls_mpi_free( &A ); mbedtls_mpi_free( &B );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Q); mbedtls_mpi_free(&R);
+ mbedtls_mpi_free(&A); mbedtls_mpi_free(&B);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_div_int( char * input_X, int input_Y,
- char * input_A, char * input_B,
- int div_result )
+void mpi_div_int(char *input_X, int input_Y,
+ char *input_A, char *input_B,
+ int div_result)
{
mbedtls_mpi X, Q, R, A, B;
int res;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &R ); mbedtls_mpi_init( &A );
- mbedtls_mpi_init( &B );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Q); mbedtls_mpi_init(&R); mbedtls_mpi_init(&A);
+ mbedtls_mpi_init(&B);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &B, input_B ) == 0 );
- res = mbedtls_mpi_div_int( &Q, &R, &X, input_Y );
- TEST_ASSERT( res == div_result );
- if( res == 0 )
- {
- TEST_ASSERT( sign_is_valid( &Q ) );
- TEST_ASSERT( sign_is_valid( &R ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Q, &A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R, &B ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&B, input_B) == 0);
+ res = mbedtls_mpi_div_int(&Q, &R, &X, input_Y);
+ TEST_ASSERT(res == div_result);
+ if (res == 0) {
+ TEST_ASSERT(sign_is_valid(&Q));
+ TEST_ASSERT(sign_is_valid(&R));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Q, &A) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R, &B) == 0);
}
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &R ); mbedtls_mpi_free( &A );
- mbedtls_mpi_free( &B );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Q); mbedtls_mpi_free(&R); mbedtls_mpi_free(&A);
+ mbedtls_mpi_free(&B);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_mpi( char * input_X, char * input_Y,
- char * input_A, int div_result )
+void mpi_mod_mpi(char *input_X, char *input_Y,
+ char *input_A, int div_result)
{
mbedtls_mpi X, Y, A;
int res;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- res = mbedtls_mpi_mod_mpi( &X, &X, &Y );
- TEST_ASSERT( res == div_result );
- if( res == 0 )
- {
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ res = mbedtls_mpi_mod_mpi(&X, &X, &Y);
+ TEST_ASSERT(res == div_result);
+ if (res == 0) {
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
}
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_int( char * input_X, char * input_Y,
- char * input_A, int mod_result )
+void mpi_mod_int(char *input_X, char *input_Y,
+ char *input_A, int mod_result)
{
mbedtls_mpi X;
mbedtls_mpi Y;
@@ -936,18 +932,18 @@
int res;
mbedtls_mpi_uint r;
- mbedtls_mpi_init( &X );
- mbedtls_mpi_init( &Y );
- mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X);
+ mbedtls_mpi_init(&Y);
+ mbedtls_mpi_init(&A);
/* We use MPIs to read Y and A since the test framework limits us to
* ints, so we can't have 64-bit values */
- TEST_EQUAL( mbedtls_test_read_mpi( &X, input_X ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &Y, input_Y ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &A, input_A ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi(&X, input_X), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&Y, input_Y), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&A, input_A), 0);
- TEST_EQUAL( Y.n, 1 );
- TEST_EQUAL( A.n, 1 );
+ TEST_EQUAL(Y.n, 1);
+ TEST_EQUAL(A.n, 1);
/* Convert the MPIs for Y and A to (signed) mbedtls_mpi_sints */
@@ -958,301 +954,297 @@
* easy to test for, and this helps guard against human error. */
mbedtls_mpi_sint y = (mbedtls_mpi_sint) Y.p[0];
- TEST_ASSERT( y >= 0 ); /* If y < 0 here, we can't make negative y */
- if( Y.s == -1 )
+ TEST_ASSERT(y >= 0); /* If y < 0 here, we can't make negative y */
+ if (Y.s == -1) {
y = -y;
+ }
mbedtls_mpi_sint a = (mbedtls_mpi_sint) A.p[0];
- TEST_ASSERT( a >= 0 ); /* Same goes for a */
- if( A.s == -1 )
+ TEST_ASSERT(a >= 0); /* Same goes for a */
+ if (A.s == -1) {
a = -a;
+ }
- res = mbedtls_mpi_mod_int( &r, &X, y );
- TEST_EQUAL( res, mod_result );
- if( res == 0 )
- {
- TEST_EQUAL( r, a );
+ res = mbedtls_mpi_mod_int(&r, &X, y);
+ TEST_EQUAL(res, mod_result);
+ if (res == 0) {
+ TEST_EQUAL(r, a);
}
exit:
- mbedtls_mpi_free( &X );
- mbedtls_mpi_free( &Y );
- mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X);
+ mbedtls_mpi_free(&Y);
+ mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_exp_mod( char * input_A, char * input_E,
- char * input_N, char * input_X,
- int exp_result )
+void mpi_exp_mod(char *input_A, char *input_E,
+ char *input_N, char *input_X,
+ int exp_result)
{
mbedtls_mpi A, E, N, RR, Z, X;
int res;
- mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &RR ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&A); mbedtls_mpi_init(&E); mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&RR); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
- res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, NULL );
- TEST_ASSERT( res == exp_result );
- if( res == 0 )
- {
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
+ res = mbedtls_mpi_exp_mod(&Z, &A, &E, &N, NULL);
+ TEST_ASSERT(res == exp_result);
+ if (res == 0) {
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &X) == 0);
}
/* Now test again with the speed-up parameter supplied as an output. */
- res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
- TEST_ASSERT( res == exp_result );
- if( res == 0 )
- {
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
+ res = mbedtls_mpi_exp_mod(&Z, &A, &E, &N, &RR);
+ TEST_ASSERT(res == exp_result);
+ if (res == 0) {
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &X) == 0);
}
/* Now test again with the speed-up parameter supplied in calculated form. */
- res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
- TEST_ASSERT( res == exp_result );
- if( res == 0 )
- {
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
+ res = mbedtls_mpi_exp_mod(&Z, &A, &E, &N, &RR);
+ TEST_ASSERT(res == exp_result);
+ if (res == 0) {
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &X) == 0);
}
exit:
- mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &RR ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&A); mbedtls_mpi_free(&E); mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&RR); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_exp_mod_size( int A_bytes, int E_bytes, int N_bytes,
- char * input_RR, int exp_result )
+void mpi_exp_mod_size(int A_bytes, int E_bytes, int N_bytes,
+ char *input_RR, int exp_result)
{
mbedtls_mpi A, E, N, RR, Z;
- mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &RR ); mbedtls_mpi_init( &Z );
+ mbedtls_mpi_init(&A); mbedtls_mpi_init(&E); mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&RR); mbedtls_mpi_init(&Z);
/* Set A to 2^(A_bytes - 1) + 1 */
- TEST_ASSERT( mbedtls_mpi_lset( &A, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_shift_l( &A, ( A_bytes * 8 ) - 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_set_bit( &A, 0, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_lset(&A, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_shift_l(&A, (A_bytes * 8) - 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_set_bit(&A, 0, 1) == 0);
/* Set E to 2^(E_bytes - 1) + 1 */
- TEST_ASSERT( mbedtls_mpi_lset( &E, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_shift_l( &E, ( E_bytes * 8 ) - 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_set_bit( &E, 0, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_lset(&E, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_shift_l(&E, (E_bytes * 8) - 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_set_bit(&E, 0, 1) == 0);
/* Set N to 2^(N_bytes - 1) + 1 */
- TEST_ASSERT( mbedtls_mpi_lset( &N, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_shift_l( &N, ( N_bytes * 8 ) - 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_set_bit( &N, 0, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_lset(&N, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_shift_l(&N, (N_bytes * 8) - 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_set_bit(&N, 0, 1) == 0);
- if( strlen( input_RR ) )
- TEST_ASSERT( mbedtls_test_read_mpi( &RR, input_RR ) == 0 );
+ if (strlen(input_RR)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&RR, input_RR) == 0);
+ }
- TEST_ASSERT( mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR ) == exp_result );
+ TEST_ASSERT(mbedtls_mpi_exp_mod(&Z, &A, &E, &N, &RR) == exp_result);
exit:
- mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &RR ); mbedtls_mpi_free( &Z );
+ mbedtls_mpi_free(&A); mbedtls_mpi_free(&E); mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&RR); mbedtls_mpi_free(&Z);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_inv_mod( char * input_X, char * input_Y,
- char * input_A, int div_result )
+void mpi_inv_mod(char *input_X, char *input_Y,
+ char *input_A, int div_result)
{
mbedtls_mpi X, Y, Z, A;
int res;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, input_Y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- res = mbedtls_mpi_inv_mod( &Z, &X, &Y );
- TEST_ASSERT( res == div_result );
- if( res == 0 )
- {
- TEST_ASSERT( sign_is_valid( &Z ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, input_Y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ res = mbedtls_mpi_inv_mod(&Z, &X, &Y);
+ TEST_ASSERT(res == div_result);
+ if (res == 0) {
+ TEST_ASSERT(sign_is_valid(&Z));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Z, &A) == 0);
}
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
-void mpi_is_prime( char * input_X, int div_result )
+void mpi_is_prime(char *input_X, int div_result)
{
mbedtls_mpi X;
int res;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- res = mbedtls_mpi_is_prime_ext( &X, 40, mbedtls_test_rnd_std_rand, NULL );
- TEST_ASSERT( res == div_result );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ res = mbedtls_mpi_is_prime_ext(&X, 40, mbedtls_test_rnd_std_rand, NULL);
+ TEST_ASSERT(res == div_result);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
-void mpi_is_prime_det( data_t * input_X, data_t * witnesses,
- int chunk_len, int rounds )
+void mpi_is_prime_det(data_t *input_X, data_t *witnesses,
+ int chunk_len, int rounds)
{
mbedtls_mpi X;
int res;
mbedtls_test_mpi_random rand;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
rand.data = witnesses;
rand.pos = 0;
rand.chunk_len = chunk_len;
- TEST_ASSERT( mbedtls_mpi_read_binary( &X, input_X->x, input_X->len ) == 0 );
- res = mbedtls_mpi_is_prime_ext( &X, rounds - 1,
- mbedtls_test_mpi_miller_rabin_determinizer,
- &rand );
- TEST_ASSERT( res == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&X, input_X->x, input_X->len) == 0);
+ res = mbedtls_mpi_is_prime_ext(&X, rounds - 1,
+ mbedtls_test_mpi_miller_rabin_determinizer,
+ &rand);
+ TEST_ASSERT(res == 0);
rand.data = witnesses;
rand.pos = 0;
rand.chunk_len = chunk_len;
- res = mbedtls_mpi_is_prime_ext( &X, rounds,
- mbedtls_test_mpi_miller_rabin_determinizer,
- &rand );
- TEST_ASSERT( res == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE );
+ res = mbedtls_mpi_is_prime_ext(&X, rounds,
+ mbedtls_test_mpi_miller_rabin_determinizer,
+ &rand);
+ TEST_ASSERT(res == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE);
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
-void mpi_gen_prime( int bits, int flags, int ref_ret )
+void mpi_gen_prime(int bits, int flags, int ref_ret)
{
mbedtls_mpi X;
int my_ret;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- my_ret = mbedtls_mpi_gen_prime( &X, bits, flags,
- mbedtls_test_rnd_std_rand, NULL );
- TEST_ASSERT( my_ret == ref_ret );
+ my_ret = mbedtls_mpi_gen_prime(&X, bits, flags,
+ mbedtls_test_rnd_std_rand, NULL);
+ TEST_ASSERT(my_ret == ref_ret);
- if( ref_ret == 0 )
- {
- size_t actual_bits = mbedtls_mpi_bitlen( &X );
+ if (ref_ret == 0) {
+ size_t actual_bits = mbedtls_mpi_bitlen(&X);
- TEST_ASSERT( actual_bits >= (size_t) bits );
- TEST_ASSERT( actual_bits <= (size_t) bits + 1 );
- TEST_ASSERT( sign_is_valid( &X ) );
+ TEST_ASSERT(actual_bits >= (size_t) bits);
+ TEST_ASSERT(actual_bits <= (size_t) bits + 1);
+ TEST_ASSERT(sign_is_valid(&X));
- TEST_ASSERT( mbedtls_mpi_is_prime_ext( &X, 40,
- mbedtls_test_rnd_std_rand,
- NULL ) == 0 );
- if( flags & MBEDTLS_MPI_GEN_PRIME_FLAG_DH )
- {
+ TEST_ASSERT(mbedtls_mpi_is_prime_ext(&X, 40,
+ mbedtls_test_rnd_std_rand,
+ NULL) == 0);
+ if (flags & MBEDTLS_MPI_GEN_PRIME_FLAG_DH) {
/* X = ( X - 1 ) / 2 */
- TEST_ASSERT( mbedtls_mpi_shift_r( &X, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_is_prime_ext( &X, 40,
- mbedtls_test_rnd_std_rand,
- NULL ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_shift_r(&X, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_is_prime_ext(&X, 40,
+ mbedtls_test_rnd_std_rand,
+ NULL) == 0);
}
}
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_shift_l( char * input_X, int shift_X,
- char * input_A )
+void mpi_shift_l(char *input_X, int shift_X,
+ char *input_A)
{
mbedtls_mpi X, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_shift_l( &X, shift_X ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_shift_l(&X, shift_X) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_shift_r( char * input_X, int shift_X,
- char * input_A )
+void mpi_shift_r(char *input_X, int shift_X,
+ char *input_A)
{
mbedtls_mpi X, A;
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &A, input_A ) == 0 );
- TEST_ASSERT( mbedtls_mpi_shift_r( &X, shift_X ) == 0 );
- TEST_ASSERT( sign_is_valid( &X ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, input_X) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&A, input_A) == 0);
+ TEST_ASSERT(mbedtls_mpi_shift_r(&X, shift_X) == 0);
+ TEST_ASSERT(sign_is_valid(&X));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&X, &A) == 0);
exit:
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &A );
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_fill_random( int wanted_bytes, int rng_bytes,
- int before, int expected_ret )
+void mpi_fill_random(int wanted_bytes, int rng_bytes,
+ int before, int expected_ret)
{
mbedtls_mpi X;
int ret;
size_t bytes_left = rng_bytes;
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&X);
- if( before != 0 )
- {
+ if (before != 0) {
/* Set X to sign(before) * 2^(|before|-1) */
- TEST_ASSERT( mbedtls_mpi_lset( &X, before > 0 ? 1 : -1 ) == 0 );
- if( before < 0 )
- before = - before;
- TEST_ASSERT( mbedtls_mpi_shift_l( &X, before - 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_lset(&X, before > 0 ? 1 : -1) == 0);
+ if (before < 0) {
+ before = -before;
+ }
+ TEST_ASSERT(mbedtls_mpi_shift_l(&X, before - 1) == 0);
}
- ret = mbedtls_mpi_fill_random( &X, wanted_bytes,
- f_rng_bytes_left, &bytes_left );
- TEST_ASSERT( ret == expected_ret );
+ ret = mbedtls_mpi_fill_random(&X, wanted_bytes,
+ f_rng_bytes_left, &bytes_left);
+ TEST_ASSERT(ret == expected_ret);
- if( expected_ret == 0 )
- {
+ if (expected_ret == 0) {
/* mbedtls_mpi_fill_random is documented to use bytes from the RNG
* as a big-endian representation of the number. We know when
* our RNG function returns null bytes, so we know how many
* leading zero bytes the number has. */
size_t leading_zeros = 0;
- if( wanted_bytes > 0 && rng_bytes % 256 == 0 )
+ if (wanted_bytes > 0 && rng_bytes % 256 == 0) {
leading_zeros = 1;
- TEST_ASSERT( mbedtls_mpi_size( &X ) + leading_zeros ==
- (size_t) wanted_bytes );
- TEST_ASSERT( (int) bytes_left == rng_bytes - wanted_bytes );
- TEST_ASSERT( sign_is_valid( &X ) );
+ }
+ TEST_ASSERT(mbedtls_mpi_size(&X) + leading_zeros ==
+ (size_t) wanted_bytes);
+ TEST_ASSERT((int) bytes_left == rng_bytes - wanted_bytes);
+ TEST_ASSERT(sign_is_valid(&X));
}
exit:
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void most_negative_mpi_sint( )
+void most_negative_mpi_sint()
{
/* Ad hoc tests for n = -p = -2^(biL-1) as a mbedtls_mpi_sint. We
* guarantee that mbedtls_mpi_sint is a two's complement type, so this
@@ -1270,133 +1262,133 @@
*/
mbedtls_mpi A, R, X;
- mbedtls_mpi_init( &A );
- mbedtls_mpi_init( &R );
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&A);
+ mbedtls_mpi_init(&R);
+ mbedtls_mpi_init(&X);
- mbedtls_mpi_uint most_positive_plus_1 = (mbedtls_mpi_uint) 1 << ( biL - 1 );
+ mbedtls_mpi_uint most_positive_plus_1 = (mbedtls_mpi_uint) 1 << (biL - 1);
const mbedtls_mpi_sint most_positive = most_positive_plus_1 - 1;
- const mbedtls_mpi_sint most_negative = - most_positive - 1;
- TEST_EQUAL( (mbedtls_mpi_uint) most_negative,
- (mbedtls_mpi_uint) 1 << ( biL - 1 ) );
- TEST_EQUAL( (mbedtls_mpi_uint) most_negative << 1, 0 );
+ const mbedtls_mpi_sint most_negative = -most_positive - 1;
+ TEST_EQUAL((mbedtls_mpi_uint) most_negative,
+ (mbedtls_mpi_uint) 1 << (biL - 1));
+ TEST_EQUAL((mbedtls_mpi_uint) most_negative << 1, 0);
/* Test mbedtls_mpi_lset() */
- TEST_EQUAL( mbedtls_mpi_lset( &A, most_negative ), 0 );
- TEST_EQUAL( A.s, -1 );
- TEST_EQUAL( A.n, 1 );
- TEST_EQUAL( A.p[0], most_positive_plus_1 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, most_negative), 0);
+ TEST_EQUAL(A.s, -1);
+ TEST_EQUAL(A.n, 1);
+ TEST_EQUAL(A.p[0], most_positive_plus_1);
/* Test mbedtls_mpi_cmp_int(): -p == -p */
- TEST_EQUAL( mbedtls_mpi_cmp_int( &A, most_negative ), 0 );
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&A, most_negative), 0);
/* Test mbedtls_mpi_cmp_int(): -(p+1) < -p */
A.p[0] = most_positive_plus_1 + 1;
- TEST_EQUAL( mbedtls_mpi_cmp_int( &A, most_negative ), -1 );
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&A, most_negative), -1);
/* Test mbedtls_mpi_cmp_int(): -(p-1) > -p */
A.p[0] = most_positive_plus_1 - 1;
- TEST_EQUAL( mbedtls_mpi_cmp_int( &A, most_negative ), 1 );
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&A, most_negative), 1);
/* Test mbedtls_mpi_add_int(): (p-1) + (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, most_positive ), 0 );
- TEST_EQUAL( mbedtls_mpi_add_int( &X, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, -1 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, most_positive), 0);
+ TEST_EQUAL(mbedtls_mpi_add_int(&X, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, -1), 0);
/* Test mbedtls_mpi_add_int(): (0) + (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, 0 ), 0 );
- TEST_EQUAL( mbedtls_mpi_add_int( &X, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, most_negative ), 0 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, 0), 0);
+ TEST_EQUAL(mbedtls_mpi_add_int(&X, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, most_negative), 0);
/* Test mbedtls_mpi_add_int(): (-p) + (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_add_int( &X, &A, most_negative ), 0 );
- TEST_EQUAL( X.s, -1 );
- TEST_EQUAL( X.n, 2 );
- TEST_EQUAL( X.p[0], 0 );
- TEST_EQUAL( X.p[1], 1 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_add_int(&X, &A, most_negative), 0);
+ TEST_EQUAL(X.s, -1);
+ TEST_EQUAL(X.n, 2);
+ TEST_EQUAL(X.p[0], 0);
+ TEST_EQUAL(X.p[1], 1);
/* Test mbedtls_mpi_sub_int(): (p) - (-p) */
- mbedtls_mpi_free( &X );
- TEST_EQUAL( mbedtls_mpi_lset( &A, most_positive ), 0 );
- TEST_EQUAL( mbedtls_mpi_sub_int( &X, &A, most_negative ), 0 );
- TEST_EQUAL( X.s, 1 );
- TEST_EQUAL( X.n, 1 );
- TEST_EQUAL( X.p[0], ~(mbedtls_mpi_uint)0 );
+ mbedtls_mpi_free(&X);
+ TEST_EQUAL(mbedtls_mpi_lset(&A, most_positive), 0);
+ TEST_EQUAL(mbedtls_mpi_sub_int(&X, &A, most_negative), 0);
+ TEST_EQUAL(X.s, 1);
+ TEST_EQUAL(X.n, 1);
+ TEST_EQUAL(X.p[0], ~(mbedtls_mpi_uint) 0);
/* Test mbedtls_mpi_sub_int(): (0) - (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, 0 ), 0 );
- TEST_EQUAL( mbedtls_mpi_sub_int( &X, &A, most_negative ), 0 );
- TEST_EQUAL( X.s, 1 );
- TEST_EQUAL( X.n, 1 );
- TEST_EQUAL( X.p[0], most_positive_plus_1 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, 0), 0);
+ TEST_EQUAL(mbedtls_mpi_sub_int(&X, &A, most_negative), 0);
+ TEST_EQUAL(X.s, 1);
+ TEST_EQUAL(X.n, 1);
+ TEST_EQUAL(X.p[0], most_positive_plus_1);
/* Test mbedtls_mpi_sub_int(): (-p) - (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_sub_int( &X, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, 0 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_sub_int(&X, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, 0), 0);
/* Test mbedtls_mpi_div_int(): (-p+1) / (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, -most_positive ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &X, &R, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, 0 ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &R, -most_positive ), 0 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, -most_positive), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&X, &R, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, 0), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&R, -most_positive), 0);
/* Test mbedtls_mpi_div_int(): (-p) / (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &X, &R, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, 1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &R, 0 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&X, &R, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, 1), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&R, 0), 0);
/* Test mbedtls_mpi_div_int(): (-2*p) / (-p) */
- TEST_EQUAL( mbedtls_mpi_shift_l( &A, 1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &X, &R, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, 2 ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &R, 0 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_shift_l(&A, 1), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&X, &R, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, 2), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&R, 0), 0);
/* Test mbedtls_mpi_div_int(): (-2*p+1) / (-p) */
- TEST_EQUAL( mbedtls_mpi_add_int( &A, &A, 1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &X, &R, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, 1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &R, -most_positive ), 0 );
+ TEST_EQUAL(mbedtls_mpi_add_int(&A, &A, 1), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&X, &R, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, 1), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&R, -most_positive), 0);
/* Test mbedtls_mpi_div_int(): (p-1) / (-p) */
- TEST_EQUAL( mbedtls_mpi_lset( &A, most_positive ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &X, &R, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, 0 ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &R, most_positive ), 0 );
+ TEST_EQUAL(mbedtls_mpi_lset(&A, most_positive), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&X, &R, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, 0), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&R, most_positive), 0);
/* Test mbedtls_mpi_div_int(): (p) / (-p) */
- TEST_EQUAL( mbedtls_mpi_add_int( &A, &A, 1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &X, &R, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, -1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &R, 0 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_add_int(&A, &A, 1), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&X, &R, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, -1), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&R, 0), 0);
/* Test mbedtls_mpi_div_int(): (2*p) / (-p) */
- TEST_EQUAL( mbedtls_mpi_shift_l( &A, 1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &X, &R, &A, most_negative ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &X, -2 ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_int( &R, 0 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_shift_l(&A, 1), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&X, &R, &A, most_negative), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&X, -2), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_int(&R, 0), 0);
/* Test mbedtls_mpi_mod_int(): never valid */
- TEST_EQUAL( mbedtls_mpi_mod_int( X.p, &A, most_negative ),
- MBEDTLS_ERR_MPI_NEGATIVE_VALUE );
+ TEST_EQUAL(mbedtls_mpi_mod_int(X.p, &A, most_negative),
+ MBEDTLS_ERR_MPI_NEGATIVE_VALUE);
/* Test mbedtls_mpi_random(): never valid */
- TEST_EQUAL( mbedtls_mpi_random( &X, most_negative, &A,
- mbedtls_test_rnd_std_rand, NULL ),
- MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_mpi_random(&X, most_negative, &A,
+ mbedtls_test_rnd_std_rand, NULL),
+ MBEDTLS_ERR_MPI_BAD_INPUT_DATA);
exit:
- mbedtls_mpi_free( &A );
- mbedtls_mpi_free( &R );
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&A);
+ mbedtls_mpi_free(&R);
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void mpi_selftest( )
+void mpi_selftest()
{
- TEST_ASSERT( mbedtls_mpi_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_bignum_core.function b/tests/suites/test_suite_bignum_core.function
index 47f9013..408eb0b 100644
--- a/tests/suites/test_suite_bignum_core.function
+++ b/tests/suites/test_suite_bignum_core.function
@@ -16,16 +16,16 @@
*
* \return 1 if mbedtls_mpi_core_add() passes this test, otherwise 0.
*/
-static int mpi_core_verify_add( mbedtls_mpi_uint *A,
- mbedtls_mpi_uint *B,
- size_t limbs,
- mbedtls_mpi_uint *S,
- int carry,
- mbedtls_mpi_uint *X )
+static int mpi_core_verify_add(mbedtls_mpi_uint *A,
+ mbedtls_mpi_uint *B,
+ size_t limbs,
+ mbedtls_mpi_uint *S,
+ int carry,
+ mbedtls_mpi_uint *X)
{
int ret = 0;
- size_t bytes = limbs * sizeof( *A );
+ size_t bytes = limbs * sizeof(*A);
/* The test cases have A <= B to avoid repetition, so we test A + B then,
* if A != B, B + A. If A == B, we can test when A and B are aliased */
@@ -33,49 +33,46 @@
/* A + B */
/* A + B => correct result and carry */
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, A, B, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, A, B, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* A + B; alias output and first operand => correct result and carry */
- memcpy( X, A, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, X, B, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, A, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, X, B, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* A + B; alias output and second operand => correct result and carry */
- memcpy( X, B, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, A, X, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, B, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, A, X, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
- if ( memcmp( A, B, bytes ) == 0 )
- {
+ if (memcmp(A, B, bytes) == 0) {
/* A == B, so test where A and B are aliased */
/* A + A => correct result and carry */
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, A, A, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, A, A, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* A + A, output aliased to both operands => correct result and carry */
- memcpy( X, A, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, X, X, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
- }
- else
- {
+ memcpy(X, A, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, X, X, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
+ } else {
/* A != B, so test B + A */
/* B + A => correct result and carry */
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, B, A, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, B, A, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* B + A; alias output and first operand => correct result and carry */
- memcpy( X, B, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, X, A, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, B, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, X, A, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* B + A; alias output and second operand => correct result and carry */
- memcpy( X, A, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_add( X, B, X, limbs ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, A, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_add(X, B, X, limbs));
+ ASSERT_COMPARE(X, bytes, S, bytes);
}
ret = 1;
@@ -95,16 +92,16 @@
*
* \return 1 if mbedtls_mpi_core_add_if() passes this test, otherwise 0.
*/
-static int mpi_core_verify_add_if( mbedtls_mpi_uint *A,
- mbedtls_mpi_uint *B,
- size_t limbs,
- mbedtls_mpi_uint *S,
- int carry,
- mbedtls_mpi_uint *X )
+static int mpi_core_verify_add_if(mbedtls_mpi_uint *A,
+ mbedtls_mpi_uint *B,
+ size_t limbs,
+ mbedtls_mpi_uint *S,
+ int carry,
+ mbedtls_mpi_uint *X)
{
int ret = 0;
- size_t bytes = limbs * sizeof( *A );
+ size_t bytes = limbs * sizeof(*A);
/* The test cases have A <= B to avoid repetition, so we test A + B then,
* if A != B, B + A. If A == B, we can test when A and B are aliased */
@@ -112,39 +109,36 @@
/* A + B */
/* cond = 0 => X unchanged, no carry */
- memcpy( X, A, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_core_add_if( X, B, limbs, 0 ) );
- ASSERT_COMPARE( X, bytes, A, bytes );
+ memcpy(X, A, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_core_add_if(X, B, limbs, 0));
+ ASSERT_COMPARE(X, bytes, A, bytes);
/* cond = 1 => correct result and carry */
- TEST_EQUAL( carry, mbedtls_mpi_core_add_if( X, B, limbs, 1 ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ TEST_EQUAL(carry, mbedtls_mpi_core_add_if(X, B, limbs, 1));
+ ASSERT_COMPARE(X, bytes, S, bytes);
- if ( memcmp( A, B, bytes ) == 0 )
- {
+ if (memcmp(A, B, bytes) == 0) {
/* A == B, so test where A and B are aliased */
/* cond = 0 => X unchanged, no carry */
- memcpy( X, B, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_core_add_if( X, X, limbs, 0 ) );
- ASSERT_COMPARE( X, bytes, B, bytes );
+ memcpy(X, B, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_core_add_if(X, X, limbs, 0));
+ ASSERT_COMPARE(X, bytes, B, bytes);
/* cond = 1 => correct result and carry */
- TEST_EQUAL( carry, mbedtls_mpi_core_add_if( X, X, limbs, 1 ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
- }
- else
- {
+ TEST_EQUAL(carry, mbedtls_mpi_core_add_if(X, X, limbs, 1));
+ ASSERT_COMPARE(X, bytes, S, bytes);
+ } else {
/* A != B, so test B + A */
/* cond = 0 => d unchanged, no carry */
- memcpy( X, B, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_core_add_if( X, A, limbs, 0 ) );
- ASSERT_COMPARE( X, bytes, B, bytes );
+ memcpy(X, B, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_core_add_if(X, A, limbs, 0));
+ ASSERT_COMPARE(X, bytes, B, bytes);
/* cond = 1 => correct result and carry */
- TEST_EQUAL( carry, mbedtls_mpi_core_add_if( X, A, limbs, 1 ) );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ TEST_EQUAL(carry, mbedtls_mpi_core_add_if(X, A, limbs, 1));
+ ASSERT_COMPARE(X, bytes, S, bytes);
}
ret = 1;
@@ -166,25 +160,25 @@
mbedtls_mpi_uint X = 0;
int ret;
- ret = mbedtls_mpi_core_read_be( &X, 1, NULL, 0 );
- TEST_EQUAL( ret, 0 );
- ret = mbedtls_mpi_core_write_be( &X, 1, NULL, 0 );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_mpi_core_read_be(&X, 1, NULL, 0);
+ TEST_EQUAL(ret, 0);
+ ret = mbedtls_mpi_core_write_be(&X, 1, NULL, 0);
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_mpi_core_read_be( NULL, 0, NULL, 0 );
- TEST_EQUAL( ret, 0 );
- ret = mbedtls_mpi_core_write_be( NULL, 0, NULL, 0 );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_mpi_core_read_be(NULL, 0, NULL, 0);
+ TEST_EQUAL(ret, 0);
+ ret = mbedtls_mpi_core_write_be(NULL, 0, NULL, 0);
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_mpi_core_read_le( &X, 1, NULL, 0 );
- TEST_EQUAL( ret, 0 );
- ret = mbedtls_mpi_core_write_le( &X, 1, NULL, 0 );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_mpi_core_read_le(&X, 1, NULL, 0);
+ TEST_EQUAL(ret, 0);
+ ret = mbedtls_mpi_core_write_le(&X, 1, NULL, 0);
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_mpi_core_read_le( NULL, 0, NULL, 0 );
- TEST_EQUAL( ret, 0 );
- ret = mbedtls_mpi_core_write_le( NULL, 0, NULL, 0 );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_mpi_core_read_le(NULL, 0, NULL, 0);
+ TEST_EQUAL(ret, 0);
+ ret = mbedtls_mpi_core_write_le(NULL, 0, NULL, 0);
+ TEST_EQUAL(ret, 0);
exit:
;
@@ -192,54 +186,53 @@
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_io_be( data_t *input, int nb_int, int nx_32_int, int iret,
- int oret )
+void mpi_core_io_be(data_t *input, int nb_int, int nx_32_int, int iret,
+ int oret)
{
- if( iret != 0 )
- TEST_ASSERT( oret == 0 );
+ if (iret != 0) {
+ TEST_ASSERT(oret == 0);
+ }
- TEST_LE_S( 0, nb_int );
+ TEST_LE_S(0, nb_int);
size_t nb = nb_int;
unsigned char buf[1024];
- TEST_LE_U( nb, sizeof( buf ) );
+ TEST_LE_U(nb, sizeof(buf));
/* nx_32_int is the number of 32 bit limbs, if we have 64 bit limbs we need
* to halve the number of limbs to have the same size. */
size_t nx;
- TEST_LE_S( 0, nx_32_int );
- if( sizeof( mbedtls_mpi_uint ) == 8 )
+ TEST_LE_S(0, nx_32_int);
+ if (sizeof(mbedtls_mpi_uint) == 8) {
nx = nx_32_int / 2 + nx_32_int % 2;
- else
+ } else {
nx = nx_32_int;
-
- mbedtls_mpi_uint X[sizeof( buf ) / sizeof( mbedtls_mpi_uint )];
- TEST_LE_U( nx, sizeof( X ) / sizeof( X[0] ) );
-
- int ret = mbedtls_mpi_core_read_be( X, nx, input->x, input->len );
- TEST_EQUAL( ret, iret );
-
- if( iret == 0 )
- {
- ret = mbedtls_mpi_core_write_be( X, nx, buf, nb );
- TEST_EQUAL( ret, oret );
}
- if( ( iret == 0 ) && ( oret == 0 ) )
- {
- if( nb > input->len )
- {
+ mbedtls_mpi_uint X[sizeof(buf) / sizeof(mbedtls_mpi_uint)];
+ TEST_LE_U(nx, sizeof(X) / sizeof(X[0]));
+
+ int ret = mbedtls_mpi_core_read_be(X, nx, input->x, input->len);
+ TEST_EQUAL(ret, iret);
+
+ if (iret == 0) {
+ ret = mbedtls_mpi_core_write_be(X, nx, buf, nb);
+ TEST_EQUAL(ret, oret);
+ }
+
+ if ((iret == 0) && (oret == 0)) {
+ if (nb > input->len) {
size_t leading_zeroes = nb - input->len;
- TEST_ASSERT( memcmp( buf + nb - input->len, input->x, input->len ) == 0 );
- for( size_t i = 0; i < leading_zeroes; i++ )
- TEST_EQUAL( buf[i], 0 );
- }
- else
- {
+ TEST_ASSERT(memcmp(buf + nb - input->len, input->x, input->len) == 0);
+ for (size_t i = 0; i < leading_zeroes; i++) {
+ TEST_EQUAL(buf[i], 0);
+ }
+ } else {
size_t leading_zeroes = input->len - nb;
- TEST_ASSERT( memcmp( input->x + input->len - nb, buf, nb ) == 0 );
- for( size_t i = 0; i < leading_zeroes; i++ )
- TEST_EQUAL( input->x[i], 0 );
+ TEST_ASSERT(memcmp(input->x + input->len - nb, buf, nb) == 0);
+ for (size_t i = 0; i < leading_zeroes; i++) {
+ TEST_EQUAL(input->x[i], 0);
+ }
}
}
@@ -249,52 +242,51 @@
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_io_le( data_t *input, int nb_int, int nx_32_int, int iret,
- int oret )
+void mpi_core_io_le(data_t *input, int nb_int, int nx_32_int, int iret,
+ int oret)
{
- if( iret != 0 )
- TEST_ASSERT( oret == 0 );
+ if (iret != 0) {
+ TEST_ASSERT(oret == 0);
+ }
- TEST_LE_S( 0, nb_int );
+ TEST_LE_S(0, nb_int);
size_t nb = nb_int;
unsigned char buf[1024];
- TEST_LE_U( nb, sizeof( buf ) );
+ TEST_LE_U(nb, sizeof(buf));
/* nx_32_int is the number of 32 bit limbs, if we have 64 bit limbs we need
* to halve the number of limbs to have the same size. */
size_t nx;
- TEST_LE_S( 0, nx_32_int );
- if( sizeof( mbedtls_mpi_uint ) == 8 )
+ TEST_LE_S(0, nx_32_int);
+ if (sizeof(mbedtls_mpi_uint) == 8) {
nx = nx_32_int / 2 + nx_32_int % 2;
- else
+ } else {
nx = nx_32_int;
-
- mbedtls_mpi_uint X[sizeof( buf ) / sizeof( mbedtls_mpi_uint )];
- TEST_LE_U( nx, sizeof( X ) / sizeof( X[0] ) );
-
- int ret = mbedtls_mpi_core_read_le( X, nx, input->x, input->len );
- TEST_EQUAL( ret, iret );
-
- if( iret == 0 )
- {
- ret = mbedtls_mpi_core_write_le( X, nx, buf, nb );
- TEST_EQUAL( ret, oret );
}
- if( ( iret == 0 ) && ( oret == 0 ) )
- {
- if( nb > input->len )
- {
- TEST_ASSERT( memcmp( buf, input->x, input->len ) == 0 );
- for( size_t i = input->len; i < nb; i++ )
- TEST_EQUAL( buf[i], 0 );
- }
- else
- {
- TEST_ASSERT( memcmp( input->x, buf, nb ) == 0 );
- for( size_t i = nb; i < input->len; i++ )
- TEST_EQUAL( input->x[i], 0 );
+ mbedtls_mpi_uint X[sizeof(buf) / sizeof(mbedtls_mpi_uint)];
+ TEST_LE_U(nx, sizeof(X) / sizeof(X[0]));
+
+ int ret = mbedtls_mpi_core_read_le(X, nx, input->x, input->len);
+ TEST_EQUAL(ret, iret);
+
+ if (iret == 0) {
+ ret = mbedtls_mpi_core_write_le(X, nx, buf, nb);
+ TEST_EQUAL(ret, oret);
+ }
+
+ if ((iret == 0) && (oret == 0)) {
+ if (nb > input->len) {
+ TEST_ASSERT(memcmp(buf, input->x, input->len) == 0);
+ for (size_t i = input->len; i < nb; i++) {
+ TEST_EQUAL(buf[i], 0);
+ }
+ } else {
+ TEST_ASSERT(memcmp(input->x, buf, nb) == 0);
+ for (size_t i = nb; i < input->len; i++) {
+ TEST_EQUAL(input->x[i], 0);
+ }
}
}
@@ -304,21 +296,21 @@
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_bitlen( char *input_X, int nr_bits )
+void mpi_core_bitlen(char *input_X, int nr_bits)
{
mbedtls_mpi_uint *X = NULL;
size_t limbs;
- TEST_EQUAL( mbedtls_test_read_mpi_core( &X, &limbs, input_X ), 0 );
- TEST_EQUAL( mbedtls_mpi_core_bitlen( X, limbs ), nr_bits );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&X, &limbs, input_X), 0);
+ TEST_EQUAL(mbedtls_mpi_core_bitlen(X, limbs), nr_bits);
exit:
- mbedtls_free( X );
+ mbedtls_free(X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_lt_ct( char *input_X, char *input_Y, int exp_ret )
+void mpi_core_lt_ct(char *input_X, char *input_Y, int exp_ret)
{
mbedtls_mpi_uint *X = NULL;
size_t X_limbs;
@@ -326,138 +318,132 @@
size_t Y_limbs;
int ret;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &Y, &Y_limbs, input_Y ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&Y, &Y_limbs, input_Y));
/* We need two same-length limb arrays */
- TEST_EQUAL( X_limbs, Y_limbs );
+ TEST_EQUAL(X_limbs, Y_limbs);
- TEST_CF_SECRET( X, X_limbs * sizeof( mbedtls_mpi_uint ) );
- TEST_CF_SECRET( Y, X_limbs * sizeof( mbedtls_mpi_uint ) );
+ TEST_CF_SECRET(X, X_limbs * sizeof(mbedtls_mpi_uint));
+ TEST_CF_SECRET(Y, X_limbs * sizeof(mbedtls_mpi_uint));
- ret = mbedtls_mpi_core_lt_ct( X, Y, X_limbs );
- TEST_EQUAL( ret, exp_ret );
+ ret = mbedtls_mpi_core_lt_ct(X, Y, X_limbs);
+ TEST_EQUAL(ret, exp_ret);
exit:
- mbedtls_free( X );
- mbedtls_free( Y );
+ mbedtls_free(X);
+ mbedtls_free(Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_uint_le_mpi( char *input_A )
+void mpi_core_uint_le_mpi(char *input_A)
{
mbedtls_mpi_uint *A = NULL;
size_t A_limbs = 0;
- TEST_EQUAL( mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&A, &A_limbs, input_A), 0);
int is_large = 0; /* nonzero limbs beyond the lowest-order one? */
- for( size_t i = 1; i < A_limbs; i++ )
- {
- if( A[i] != 0 )
- {
+ for (size_t i = 1; i < A_limbs; i++) {
+ if (A[i] != 0) {
is_large = 1;
break;
}
}
- TEST_CF_SECRET( A, A_limbs * sizeof( *A ) );
+ TEST_CF_SECRET(A, A_limbs * sizeof(*A));
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( 0, A, A_limbs ), 1 );
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( A[0], A, A_limbs ), 1 );
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(0, A, A_limbs), 1);
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(A[0], A, A_limbs), 1);
- if( is_large )
- {
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( A[0] + 1,
- A, A_limbs ), 1 );
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( (mbedtls_mpi_uint)( -1 ) >> 1,
- A, A_limbs ), 1 );
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( (mbedtls_mpi_uint)( -1 ),
- A, A_limbs ), 1 );
- }
- else
- {
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( A[0] + 1,
- A, A_limbs ),
- A[0] + 1 <= A[0] );
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( (mbedtls_mpi_uint)( -1 ) >> 1,
- A, A_limbs ),
- (mbedtls_mpi_uint)( -1 ) >> 1 <= A[0] );
- TEST_EQUAL( mbedtls_mpi_core_uint_le_mpi( (mbedtls_mpi_uint)( -1 ),
- A, A_limbs ),
- (mbedtls_mpi_uint)( -1 ) <= A[0] );
+ if (is_large) {
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(A[0] + 1,
+ A, A_limbs), 1);
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1) >> 1,
+ A, A_limbs), 1);
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1),
+ A, A_limbs), 1);
+ } else {
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(A[0] + 1,
+ A, A_limbs),
+ A[0] + 1 <= A[0]);
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1) >> 1,
+ A, A_limbs),
+ (mbedtls_mpi_uint) (-1) >> 1 <= A[0]);
+ TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1),
+ A, A_limbs),
+ (mbedtls_mpi_uint) (-1) <= A[0]);
}
exit:
- mbedtls_free( A );
+ mbedtls_free(A);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_cond_assign( char * input_X,
- char * input_Y,
- int input_bytes )
+void mpi_core_cond_assign(char *input_X,
+ char *input_Y,
+ int input_bytes)
{
mbedtls_mpi_uint *X = NULL;
mbedtls_mpi_uint *Y = NULL;
size_t limbs_X;
size_t limbs_Y;
- TEST_EQUAL( mbedtls_test_read_mpi_core( &X, &limbs_X, input_X ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &Y, &limbs_Y, input_Y ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&X, &limbs_X, input_X), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&Y, &limbs_Y, input_Y), 0);
size_t limbs = limbs_X;
- size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
- size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
- size_t copy_bytes = copy_limbs * sizeof( mbedtls_mpi_uint );
+ size_t copy_limbs = CHARS_TO_LIMBS(input_bytes);
+ size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
+ size_t copy_bytes = copy_limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( limbs_X, limbs_Y );
- TEST_ASSERT( copy_limbs <= limbs );
+ TEST_EQUAL(limbs_X, limbs_Y);
+ TEST_ASSERT(copy_limbs <= limbs);
/* condition is false */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_core_cond_assign( X, Y, copy_limbs, 0 );
+ mbedtls_mpi_core_cond_assign(X, Y, copy_limbs, 0);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
- TEST_ASSERT( memcmp( X, Y, bytes ) != 0 );
+ TEST_ASSERT(memcmp(X, Y, bytes) != 0);
/* condition is true */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_core_cond_assign( X, Y, copy_limbs, 1 );
+ mbedtls_mpi_core_cond_assign(X, Y, copy_limbs, 1);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
/* Check if the given length is copied even it is smaller
than the length of the given MPIs. */
- if( copy_limbs < limbs )
- {
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ if (copy_limbs < limbs) {
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
- ASSERT_COMPARE( X, copy_bytes, Y, copy_bytes );
- TEST_ASSERT( memcmp( X, Y, bytes ) != 0 );
+ ASSERT_COMPARE(X, copy_bytes, Y, copy_bytes);
+ TEST_ASSERT(memcmp(X, Y, bytes) != 0);
+ } else {
+ ASSERT_COMPARE(X, bytes, Y, bytes);
}
- else
- ASSERT_COMPARE( X, bytes, Y, bytes );
exit:
- mbedtls_free( X );
- mbedtls_free( Y );
+ mbedtls_free(X);
+ mbedtls_free(Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_cond_swap( char * input_X,
- char * input_Y,
- int input_bytes )
+void mpi_core_cond_swap(char *input_X,
+ char *input_Y,
+ int input_bytes)
{
mbedtls_mpi_uint *tmp_X = NULL;
mbedtls_mpi_uint *tmp_Y = NULL;
@@ -466,92 +452,89 @@
size_t limbs_X;
size_t limbs_Y;
- TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_X, &limbs_X, input_X ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_Y, &limbs_Y, input_Y ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&tmp_X, &limbs_X, input_X), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&tmp_Y, &limbs_Y, input_Y), 0);
size_t limbs = limbs_X;
- size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
- size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
- size_t copy_bytes = copy_limbs * sizeof( mbedtls_mpi_uint );
+ size_t copy_limbs = CHARS_TO_LIMBS(input_bytes);
+ size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
+ size_t copy_bytes = copy_limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( limbs_X, limbs_Y );
- TEST_ASSERT( copy_limbs <= limbs );
+ TEST_EQUAL(limbs_X, limbs_Y);
+ TEST_ASSERT(copy_limbs <= limbs);
- ASSERT_ALLOC( X, limbs );
- memcpy( X, tmp_X, bytes );
+ ASSERT_ALLOC(X, limbs);
+ memcpy(X, tmp_X, bytes);
- ASSERT_ALLOC( Y, limbs );
- memcpy( Y, tmp_Y, bytes );
+ ASSERT_ALLOC(Y, limbs);
+ memcpy(Y, tmp_Y, bytes);
/* condition is false */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_core_cond_swap( X, Y, copy_limbs, 0 );
+ mbedtls_mpi_core_cond_swap(X, Y, copy_limbs, 0);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
- ASSERT_COMPARE( X, bytes, tmp_X, bytes );
- ASSERT_COMPARE( Y, bytes, tmp_Y, bytes );
+ ASSERT_COMPARE(X, bytes, tmp_X, bytes);
+ ASSERT_COMPARE(Y, bytes, tmp_Y, bytes);
/* condition is true */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_core_cond_swap( X, Y, copy_limbs, 1 );
+ mbedtls_mpi_core_cond_swap(X, Y, copy_limbs, 1);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
/* Check if the given length is copied even it is smaller
than the length of the given MPIs. */
- if( copy_limbs < limbs )
- {
- ASSERT_COMPARE( X, copy_bytes, tmp_Y, copy_bytes );
- ASSERT_COMPARE( Y, copy_bytes, tmp_X, copy_bytes );
- TEST_ASSERT( memcmp( X, tmp_X, bytes ) != 0 );
- TEST_ASSERT( memcmp( X, tmp_Y, bytes ) != 0 );
- TEST_ASSERT( memcmp( Y, tmp_X, bytes ) != 0 );
- TEST_ASSERT( memcmp( Y, tmp_Y, bytes ) != 0 );
- }
- else
- {
- ASSERT_COMPARE( X, bytes, tmp_Y, bytes );
- ASSERT_COMPARE( Y, bytes, tmp_X, bytes );
+ if (copy_limbs < limbs) {
+ ASSERT_COMPARE(X, copy_bytes, tmp_Y, copy_bytes);
+ ASSERT_COMPARE(Y, copy_bytes, tmp_X, copy_bytes);
+ TEST_ASSERT(memcmp(X, tmp_X, bytes) != 0);
+ TEST_ASSERT(memcmp(X, tmp_Y, bytes) != 0);
+ TEST_ASSERT(memcmp(Y, tmp_X, bytes) != 0);
+ TEST_ASSERT(memcmp(Y, tmp_Y, bytes) != 0);
+ } else {
+ ASSERT_COMPARE(X, bytes, tmp_Y, bytes);
+ ASSERT_COMPARE(Y, bytes, tmp_X, bytes);
}
exit:
- mbedtls_free( tmp_X );
- mbedtls_free( tmp_Y );
- mbedtls_free( X );
- mbedtls_free( Y );
+ mbedtls_free(tmp_X);
+ mbedtls_free(tmp_Y);
+ mbedtls_free(X);
+ mbedtls_free(Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_shift_r( char *input, int count, char *result )
+void mpi_core_shift_r(char *input, int count, char *result)
{
mbedtls_mpi_uint *X = NULL;
mbedtls_mpi_uint *Y = NULL;
size_t limbs, n;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &limbs, input ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &Y, &n, result ) );
- TEST_EQUAL( limbs, n );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &limbs, input));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&Y, &n, result));
+ TEST_EQUAL(limbs, n);
- mbedtls_mpi_core_shift_r( X, limbs, count );
- ASSERT_COMPARE( X, limbs * ciL, Y, limbs * ciL );
+ mbedtls_mpi_core_shift_r(X, limbs, count);
+ ASSERT_COMPARE(X, limbs * ciL, Y, limbs * ciL);
exit:
- mbedtls_free( X );
- mbedtls_free( Y );
+ mbedtls_free(X);
+ mbedtls_free(Y);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_add_and_add_if( char * input_A, char * input_B,
- char * input_S, int carry )
+void mpi_core_add_and_add_if(char *input_A, char *input_B,
+ char *input_S, int carry)
{
mbedtls_mpi_uint *A = NULL; /* first value to add */
mbedtls_mpi_uint *B = NULL; /* second value to add */
@@ -559,31 +542,31 @@
mbedtls_mpi_uint *X = NULL; /* destination - the in/out first operand */
size_t A_limbs, B_limbs, S_limbs;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &B, &B_limbs, input_B ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &S, &S_limbs, input_S ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&B, &B_limbs, input_B));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&S, &S_limbs, input_S));
/* add and add_if expect all operands to be the same length */
- TEST_EQUAL( A_limbs, B_limbs );
- TEST_EQUAL( A_limbs, S_limbs );
+ TEST_EQUAL(A_limbs, B_limbs);
+ TEST_EQUAL(A_limbs, S_limbs);
size_t limbs = A_limbs;
- ASSERT_ALLOC( X, limbs );
+ ASSERT_ALLOC(X, limbs);
- TEST_ASSERT( mpi_core_verify_add( A, B, limbs, S, carry, X ) );
- TEST_ASSERT( mpi_core_verify_add_if( A, B, limbs, S, carry, X ) );
+ TEST_ASSERT(mpi_core_verify_add(A, B, limbs, S, carry, X));
+ TEST_ASSERT(mpi_core_verify_add_if(A, B, limbs, S, carry, X));
exit:
- mbedtls_free( A );
- mbedtls_free( B );
- mbedtls_free( S );
- mbedtls_free( X );
+ mbedtls_free(A);
+ mbedtls_free(B);
+ mbedtls_free(S);
+ mbedtls_free(X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_sub( char * input_A, char * input_B,
- char * input_X, int carry )
+void mpi_core_sub(char *input_A, char *input_B,
+ char *input_X, int carry)
{
mbedtls_mpi A, B, X;
mbedtls_mpi_uint *a = NULL;
@@ -591,87 +574,86 @@
mbedtls_mpi_uint *x = NULL; /* expected */
mbedtls_mpi_uint *r = NULL; /* result */
- mbedtls_mpi_init( &A );
- mbedtls_mpi_init( &B );
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&A);
+ mbedtls_mpi_init(&B);
+ mbedtls_mpi_init(&X);
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &A, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &B, input_B ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &X, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&A, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&B, input_B));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&X, input_X));
/* All of the inputs are +ve (or zero) */
- TEST_EQUAL( 1, A.s );
- TEST_EQUAL( 1, B.s );
- TEST_EQUAL( 1, X.s );
+ TEST_EQUAL(1, A.s);
+ TEST_EQUAL(1, B.s);
+ TEST_EQUAL(1, X.s);
/* Get the number of limbs we will need */
- size_t limbs = MAX( A.n, B.n );
+ size_t limbs = MAX(A.n, B.n);
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
/* The result shouldn't have more limbs than the longest input */
- TEST_LE_U( X.n, limbs );
+ TEST_LE_U(X.n, limbs);
/* Now let's get arrays of mbedtls_mpi_uints, rather than MPI structures */
/* ASSERT_ALLOC() uses calloc() under the hood, so these do get zeroed */
- ASSERT_ALLOC( a, bytes );
- ASSERT_ALLOC( b, bytes );
- ASSERT_ALLOC( x, bytes );
- ASSERT_ALLOC( r, bytes );
+ ASSERT_ALLOC(a, bytes);
+ ASSERT_ALLOC(b, bytes);
+ ASSERT_ALLOC(x, bytes);
+ ASSERT_ALLOC(r, bytes);
/* Populate the arrays. As the mbedtls_mpi_uint[]s in mbedtls_mpis (and as
* processed by mbedtls_mpi_core_sub()) are little endian, we can just
* copy what we have as long as MSBs are 0 (which they are from ASSERT_ALLOC())
*/
- memcpy( a, A.p, A.n * sizeof(mbedtls_mpi_uint) );
- memcpy( b, B.p, B.n * sizeof(mbedtls_mpi_uint) );
- memcpy( x, X.p, X.n * sizeof(mbedtls_mpi_uint) );
+ memcpy(a, A.p, A.n * sizeof(mbedtls_mpi_uint));
+ memcpy(b, B.p, B.n * sizeof(mbedtls_mpi_uint));
+ memcpy(x, X.p, X.n * sizeof(mbedtls_mpi_uint));
/* 1a) r = a - b => we should get the correct carry */
- TEST_EQUAL( carry, mbedtls_mpi_core_sub( r, a, b, limbs ) );
+ TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, a, b, limbs));
/* 1b) r = a - b => we should get the correct result */
- ASSERT_COMPARE( r, bytes, x, bytes );
+ ASSERT_COMPARE(r, bytes, x, bytes);
/* 2 and 3 test "r may be aliased to a or b" */
/* 2a) r = a; r -= b => we should get the correct carry (use r to avoid clobbering a) */
- memcpy( r, a, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_sub( r, r, b, limbs ) );
+ memcpy(r, a, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, r, b, limbs));
/* 2b) r -= b => we should get the correct result */
- ASSERT_COMPARE( r, bytes, x, bytes );
+ ASSERT_COMPARE(r, bytes, x, bytes);
/* 3a) r = b; r = a - r => we should get the correct carry (use r to avoid clobbering b) */
- memcpy( r, b, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_sub( r, a, r, limbs ) );
+ memcpy(r, b, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, a, r, limbs));
/* 3b) r = a - b => we should get the correct result */
- ASSERT_COMPARE( r, bytes, x, bytes );
+ ASSERT_COMPARE(r, bytes, x, bytes);
/* 4 tests "r may be aliased to [...] both" */
- if ( A.n == B.n && memcmp( A.p, B.p, bytes ) == 0 )
- {
- memcpy( r, b, bytes );
- TEST_EQUAL( carry, mbedtls_mpi_core_sub( r, r, r, limbs ) );
- ASSERT_COMPARE( r, bytes, x, bytes );
+ if (A.n == B.n && memcmp(A.p, B.p, bytes) == 0) {
+ memcpy(r, b, bytes);
+ TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, r, r, limbs));
+ ASSERT_COMPARE(r, bytes, x, bytes);
}
exit:
- mbedtls_free( a );
- mbedtls_free( b );
- mbedtls_free( x );
- mbedtls_free( r );
+ mbedtls_free(a);
+ mbedtls_free(b);
+ mbedtls_free(x);
+ mbedtls_free(r);
- mbedtls_mpi_free( &A );
- mbedtls_mpi_free( &B );
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&A);
+ mbedtls_mpi_free(&B);
+ mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_mla( char * input_A, char * input_B, char * input_S,
- char * input_X4, char * input_cy4,
- char * input_X8, char * input_cy8 )
+void mpi_core_mla(char *input_A, char *input_B, char *input_S,
+ char *input_X4, char *input_cy4,
+ char *input_X8, char *input_cy8)
{
/* We are testing A += B * s; A, B are MPIs, s is a scalar.
*
@@ -685,98 +667,97 @@
mbedtls_mpi_uint *a = NULL;
mbedtls_mpi_uint *x = NULL;
- mbedtls_mpi_init( &A );
- mbedtls_mpi_init( &B );
- mbedtls_mpi_init( &S );
- mbedtls_mpi_init( &X4 );
- mbedtls_mpi_init( &X8 );
- mbedtls_mpi_init( &cy4 );
- mbedtls_mpi_init( &cy8 );
+ mbedtls_mpi_init(&A);
+ mbedtls_mpi_init(&B);
+ mbedtls_mpi_init(&S);
+ mbedtls_mpi_init(&X4);
+ mbedtls_mpi_init(&X8);
+ mbedtls_mpi_init(&cy4);
+ mbedtls_mpi_init(&cy8);
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &A, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &B, input_B ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &S, input_S ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &X4, input_X4 ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &cy4, input_cy4 ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &X8, input_X8 ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &cy8, input_cy8 ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&A, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&B, input_B));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&S, input_S));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&X4, input_X4));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&cy4, input_cy4));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&X8, input_X8));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&cy8, input_cy8));
/* The MPI encoding of scalar s must be only 1 limb */
- TEST_EQUAL( 1, S.n );
+ TEST_EQUAL(1, S.n);
/* We only need to work with X4 or X8, and cy4 or cy8, depending on sizeof(mbedtls_mpi_uint) */
- mbedtls_mpi *X = ( sizeof(mbedtls_mpi_uint) == 4 ) ? &X4 : &X8;
- mbedtls_mpi *cy = ( sizeof(mbedtls_mpi_uint) == 4 ) ? &cy4 : &cy8;
+ mbedtls_mpi *X = (sizeof(mbedtls_mpi_uint) == 4) ? &X4 : &X8;
+ mbedtls_mpi *cy = (sizeof(mbedtls_mpi_uint) == 4) ? &cy4 : &cy8;
/* The carry should only have one limb */
- TEST_EQUAL( 1, cy->n );
+ TEST_EQUAL(1, cy->n);
/* All of the inputs are +ve (or zero) */
- TEST_EQUAL( 1, A.s );
- TEST_EQUAL( 1, B.s );
- TEST_EQUAL( 1, S.s );
- TEST_EQUAL( 1, X->s );
- TEST_EQUAL( 1, cy->s );
+ TEST_EQUAL(1, A.s);
+ TEST_EQUAL(1, B.s);
+ TEST_EQUAL(1, S.s);
+ TEST_EQUAL(1, X->s);
+ TEST_EQUAL(1, cy->s);
/* Get the (max) number of limbs we will need */
- size_t limbs = MAX( A.n, B.n );
+ size_t limbs = MAX(A.n, B.n);
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
/* The result shouldn't have more limbs than the longest input */
- TEST_LE_U( X->n, limbs );
+ TEST_LE_U(X->n, limbs);
/* Now let's get arrays of mbedtls_mpi_uints, rather than MPI structures */
/* ASSERT_ALLOC() uses calloc() under the hood, so these do get zeroed */
- ASSERT_ALLOC( a, bytes );
- ASSERT_ALLOC( x, bytes );
+ ASSERT_ALLOC(a, bytes);
+ ASSERT_ALLOC(x, bytes);
/* Populate the arrays. As the mbedtls_mpi_uint[]s in mbedtls_mpis (and as
* processed by mbedtls_mpi_core_mla()) are little endian, we can just
* copy what we have as long as MSBs are 0 (which they are from ASSERT_ALLOC()).
*/
- memcpy( a, A.p, A.n * sizeof(mbedtls_mpi_uint) );
- memcpy( x, X->p, X->n * sizeof(mbedtls_mpi_uint) );
+ memcpy(a, A.p, A.n * sizeof(mbedtls_mpi_uint));
+ memcpy(x, X->p, X->n * sizeof(mbedtls_mpi_uint));
/* 1a) A += B * s => we should get the correct carry */
- TEST_EQUAL( mbedtls_mpi_core_mla( a, limbs, B.p, B.n, *S.p ), *cy->p );
+ TEST_EQUAL(mbedtls_mpi_core_mla(a, limbs, B.p, B.n, *S.p), *cy->p);
/* 1b) A += B * s => we should get the correct result */
- ASSERT_COMPARE( a, bytes, x, bytes );
+ ASSERT_COMPARE(a, bytes, x, bytes);
- if ( A.n == B.n && memcmp( A.p, B.p, bytes ) == 0 )
- {
+ if (A.n == B.n && memcmp(A.p, B.p, bytes) == 0) {
/* Check when A and B are aliased */
- memcpy( a, A.p, A.n * sizeof(mbedtls_mpi_uint) );
- TEST_EQUAL( mbedtls_mpi_core_mla( a, limbs, a, limbs, *S.p ), *cy->p );
- ASSERT_COMPARE( a, bytes, x, bytes );
+ memcpy(a, A.p, A.n * sizeof(mbedtls_mpi_uint));
+ TEST_EQUAL(mbedtls_mpi_core_mla(a, limbs, a, limbs, *S.p), *cy->p);
+ ASSERT_COMPARE(a, bytes, x, bytes);
}
exit:
- mbedtls_free( a );
- mbedtls_free( x );
+ mbedtls_free(a);
+ mbedtls_free(x);
- mbedtls_mpi_free( &A );
- mbedtls_mpi_free( &B );
- mbedtls_mpi_free( &S );
- mbedtls_mpi_free( &X4 );
- mbedtls_mpi_free( &X8 );
- mbedtls_mpi_free( &cy4 );
- mbedtls_mpi_free( &cy8 );
+ mbedtls_mpi_free(&A);
+ mbedtls_mpi_free(&B);
+ mbedtls_mpi_free(&S);
+ mbedtls_mpi_free(&X4);
+ mbedtls_mpi_free(&X8);
+ mbedtls_mpi_free(&cy4);
+ mbedtls_mpi_free(&cy8);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_montg_init( char * input_N, char * input_mm )
+void mpi_montg_init(char *input_N, char *input_mm)
{
mbedtls_mpi N, mm;
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &mm );
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&mm);
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &N, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &mm, input_mm ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&N, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&mm, input_mm));
/* The MPI encoding of mm should be 1 limb (sizeof(mbedtls_mpi_uint) == 8) or
* 2 limbs (sizeof(mbedtls_mpi_uint) == 4).
@@ -784,244 +765,240 @@
* The data file contains the expected result for sizeof(mbedtls_mpi_uint) == 8;
* for sizeof(mbedtls_mpi_uint) == 4 it's just the LSW of this.
*/
- TEST_ASSERT( mm.n == 1 || mm.n == 2 );
+ TEST_ASSERT(mm.n == 1 || mm.n == 2);
/* All of the inputs are +ve (or zero) */
- TEST_EQUAL( 1, N.s );
- TEST_EQUAL( 1, mm.s );
+ TEST_EQUAL(1, N.s);
+ TEST_EQUAL(1, mm.s);
/* mbedtls_mpi_core_montmul_init() only returns a result, no error possible */
- mbedtls_mpi_uint result = mbedtls_mpi_core_montmul_init( N.p );
+ mbedtls_mpi_uint result = mbedtls_mpi_core_montmul_init(N.p);
/* Check we got the correct result */
- TEST_EQUAL( result, mm.p[0] );
+ TEST_EQUAL(result, mm.p[0]);
exit:
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &mm );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&mm);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_montmul( int limbs_AN4, int limbs_B4,
- int limbs_AN8, int limbs_B8,
- char * input_A,
- char * input_B,
- char * input_N,
- char * input_X4,
- char * input_X8 )
+void mpi_core_montmul(int limbs_AN4, int limbs_B4,
+ int limbs_AN8, int limbs_B8,
+ char *input_A,
+ char *input_B,
+ char *input_N,
+ char *input_X4,
+ char *input_X8)
{
mbedtls_mpi A, B, N, X4, X8, T, R;
- mbedtls_mpi_init( &A );
- mbedtls_mpi_init( &B );
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &X4 ); /* expected result, sizeof(mbedtls_mpi_uint) == 4 */
- mbedtls_mpi_init( &X8 ); /* expected result, sizeof(mbedtls_mpi_uint) == 8 */
- mbedtls_mpi_init( &T );
- mbedtls_mpi_init( &R ); /* for the result */
+ mbedtls_mpi_init(&A);
+ mbedtls_mpi_init(&B);
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&X4); /* expected result, sizeof(mbedtls_mpi_uint) == 4 */
+ mbedtls_mpi_init(&X8); /* expected result, sizeof(mbedtls_mpi_uint) == 8 */
+ mbedtls_mpi_init(&T);
+ mbedtls_mpi_init(&R); /* for the result */
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &A, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &B, input_B ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &N, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &X4, input_X4 ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &X8, input_X8 ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&A, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&B, input_B));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&N, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&X4, input_X4));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&X8, input_X8));
- mbedtls_mpi *X = ( sizeof(mbedtls_mpi_uint) == 4 ) ? &X4 : &X8;
+ mbedtls_mpi *X = (sizeof(mbedtls_mpi_uint) == 4) ? &X4 : &X8;
- int limbs_AN = ( sizeof(mbedtls_mpi_uint) == 4 ) ? limbs_AN4 : limbs_AN8;
- int limbs_B = ( sizeof(mbedtls_mpi_uint) == 4 ) ? limbs_B4 : limbs_B8;
+ int limbs_AN = (sizeof(mbedtls_mpi_uint) == 4) ? limbs_AN4 : limbs_AN8;
+ int limbs_B = (sizeof(mbedtls_mpi_uint) == 4) ? limbs_B4 : limbs_B8;
- TEST_LE_U( A.n, (size_t)limbs_AN );
- TEST_LE_U( X->n, (size_t)limbs_AN );
- TEST_LE_U( B.n, (size_t)limbs_B );
- TEST_LE_U( limbs_B, limbs_AN );
+ TEST_LE_U(A.n, (size_t) limbs_AN);
+ TEST_LE_U(X->n, (size_t) limbs_AN);
+ TEST_LE_U(B.n, (size_t) limbs_B);
+ TEST_LE_U(limbs_B, limbs_AN);
/* All of the inputs are +ve (or zero) */
- TEST_EQUAL( 1, A.s );
- TEST_EQUAL( 1, B.s );
- TEST_EQUAL( 1, N.s );
- TEST_EQUAL( 1, X->s );
+ TEST_EQUAL(1, A.s);
+ TEST_EQUAL(1, B.s);
+ TEST_EQUAL(1, N.s);
+ TEST_EQUAL(1, X->s);
- TEST_EQUAL( 0, mbedtls_mpi_grow( &A, limbs_AN ) );
- TEST_EQUAL( 0, mbedtls_mpi_grow( &N, limbs_AN ) );
- TEST_EQUAL( 0, mbedtls_mpi_grow( X, limbs_AN ) );
- TEST_EQUAL( 0, mbedtls_mpi_grow( &B, limbs_B ) );
+ TEST_EQUAL(0, mbedtls_mpi_grow(&A, limbs_AN));
+ TEST_EQUAL(0, mbedtls_mpi_grow(&N, limbs_AN));
+ TEST_EQUAL(0, mbedtls_mpi_grow(X, limbs_AN));
+ TEST_EQUAL(0, mbedtls_mpi_grow(&B, limbs_B));
- size_t working_limbs = mbedtls_mpi_core_montmul_working_limbs( limbs_AN );
- TEST_EQUAL( working_limbs, limbs_AN * 2 + 1 );
- TEST_EQUAL( 0, mbedtls_mpi_grow( &T, working_limbs ) );
+ size_t working_limbs = mbedtls_mpi_core_montmul_working_limbs(limbs_AN);
+ TEST_EQUAL(working_limbs, limbs_AN * 2 + 1);
+ TEST_EQUAL(0, mbedtls_mpi_grow(&T, working_limbs));
/* Calculate the Montgomery constant (this is unit tested separately) */
- mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init( N.p );
+ mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N.p);
- TEST_EQUAL( 0, mbedtls_mpi_grow( &R, limbs_AN ) ); /* ensure it's got the right number of limbs */
+ TEST_EQUAL(0, mbedtls_mpi_grow(&R, limbs_AN)); /* ensure it's got the right number of limbs */
- mbedtls_mpi_core_montmul( R.p, A.p, B.p, B.n, N.p, N.n, mm, T.p );
+ mbedtls_mpi_core_montmul(R.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
size_t bytes = N.n * sizeof(mbedtls_mpi_uint);
- ASSERT_COMPARE( R.p, bytes, X->p, bytes );
+ ASSERT_COMPARE(R.p, bytes, X->p, bytes);
/* The output (R, above) may be aliased to A - use R to save the value of A */
- memcpy( R.p, A.p, bytes );
+ memcpy(R.p, A.p, bytes);
- mbedtls_mpi_core_montmul( A.p, A.p, B.p, B.n, N.p, N.n, mm, T.p );
- ASSERT_COMPARE( A.p, bytes, X->p, bytes );
+ mbedtls_mpi_core_montmul(A.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
+ ASSERT_COMPARE(A.p, bytes, X->p, bytes);
- memcpy( A.p, R.p, bytes ); /* restore A */
+ memcpy(A.p, R.p, bytes); /* restore A */
/* The output may be aliased to N - use R to save the value of N */
- memcpy( R.p, N.p, bytes );
+ memcpy(R.p, N.p, bytes);
- mbedtls_mpi_core_montmul( N.p, A.p, B.p, B.n, N.p, N.n, mm, T.p );
- ASSERT_COMPARE( N.p, bytes, X->p, bytes );
+ mbedtls_mpi_core_montmul(N.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
+ ASSERT_COMPARE(N.p, bytes, X->p, bytes);
- memcpy( N.p, R.p, bytes );
+ memcpy(N.p, R.p, bytes);
- if (limbs_AN == limbs_B)
- {
+ if (limbs_AN == limbs_B) {
/* Test when A aliased to B (requires A == B on input values) */
- if ( memcmp( A.p, B.p, bytes ) == 0 )
- {
+ if (memcmp(A.p, B.p, bytes) == 0) {
/* Test with A aliased to B and output, since this is permitted -
* don't bother with yet another test with only A and B aliased */
- mbedtls_mpi_core_montmul( B.p, B.p, B.p, B.n, N.p, N.n, mm, T.p );
- ASSERT_COMPARE( B.p, bytes, X->p, bytes );
+ mbedtls_mpi_core_montmul(B.p, B.p, B.p, B.n, N.p, N.n, mm, T.p);
+ ASSERT_COMPARE(B.p, bytes, X->p, bytes);
- memcpy( B.p, A.p, bytes ); /* restore B from equal value A */
+ memcpy(B.p, A.p, bytes); /* restore B from equal value A */
}
/* The output may be aliased to B - last test, so we don't save B */
- mbedtls_mpi_core_montmul( B.p, A.p, B.p, B.n, N.p, N.n, mm, T.p );
- ASSERT_COMPARE( B.p, bytes, X->p, bytes );
+ mbedtls_mpi_core_montmul(B.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
+ ASSERT_COMPARE(B.p, bytes, X->p, bytes);
}
exit:
- mbedtls_mpi_free( &A );
- mbedtls_mpi_free( &B );
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &X4 );
- mbedtls_mpi_free( &X8 );
- mbedtls_mpi_free( &T );
- mbedtls_mpi_free( &R );
+ mbedtls_mpi_free(&A);
+ mbedtls_mpi_free(&B);
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&X4);
+ mbedtls_mpi_free(&X8);
+ mbedtls_mpi_free(&T);
+ mbedtls_mpi_free(&R);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_get_mont_r2_unsafe_neg( )
+void mpi_core_get_mont_r2_unsafe_neg()
{
mbedtls_mpi N, RR;
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &RR );
- const char * n = "7ffffffffffffff1";
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&RR);
+ const char *n = "7ffffffffffffff1";
/* Test for zero divisor */
- TEST_EQUAL( MBEDTLS_ERR_MPI_DIVISION_BY_ZERO,
- mbedtls_mpi_core_get_mont_r2_unsafe( &RR, &N ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO,
+ mbedtls_mpi_core_get_mont_r2_unsafe(&RR, &N));
/* Test for negative input */
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &N, n ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&N, n));
N.s = -1;
- TEST_EQUAL( MBEDTLS_ERR_MPI_NEGATIVE_VALUE,
- mbedtls_mpi_core_get_mont_r2_unsafe( &RR, &N ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_NEGATIVE_VALUE,
+ mbedtls_mpi_core_get_mont_r2_unsafe(&RR, &N));
N.s = 1;
exit:
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &RR );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&RR);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_get_mont_r2_unsafe( char * input_N,
- char * input_RR_X4,
- char * input_RR_X8 )
+void mpi_core_get_mont_r2_unsafe(char *input_N,
+ char *input_RR_X4,
+ char *input_RR_X8)
{
mbedtls_mpi N, RR, RR_REF;
/* Select the appropriate output */
- char * input_rr = ( sizeof(mbedtls_mpi_uint) == 4 ) ? input_RR_X4: input_RR_X8;
+ char *input_rr = (sizeof(mbedtls_mpi_uint) == 4) ? input_RR_X4 : input_RR_X8;
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &RR );
- mbedtls_mpi_init( &RR_REF );
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&RR);
+ mbedtls_mpi_init(&RR_REF);
/* Read inputs */
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &N, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &RR_REF, input_rr ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&N, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&RR_REF, input_rr));
/* All of the inputs are +ve (or zero) */
- TEST_EQUAL( 1, N.s );
- TEST_EQUAL( 1, RR_REF.s );
+ TEST_EQUAL(1, N.s);
+ TEST_EQUAL(1, RR_REF.s);
/* Test valid input */
- TEST_EQUAL( 0, mbedtls_mpi_core_get_mont_r2_unsafe( &RR, &N ) );
+ TEST_EQUAL(0, mbedtls_mpi_core_get_mont_r2_unsafe(&RR, &N));
/* Test that the moduli is odd */
- TEST_EQUAL( N.p[0] ^ 1, N.p[0] - 1 );
+ TEST_EQUAL(N.p[0] ^ 1, N.p[0] - 1);
- /* Output is +ve (or zero) */
- TEST_EQUAL( 1, RR_REF.s );
+ /* Output is +ve (or zero) */
+ TEST_EQUAL(1, RR_REF.s);
/* rr is updated to a valid pointer */
- TEST_ASSERT( RR.p != NULL );
+ TEST_ASSERT(RR.p != NULL);
/* Calculated rr matches expected value */
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &RR, &RR_REF ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&RR, &RR_REF) == 0);
exit:
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &RR );
- mbedtls_mpi_free( &RR_REF );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&RR);
+ mbedtls_mpi_free(&RR_REF);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
-void mpi_core_ct_uint_table_lookup( int bitlen, int window_size )
+void mpi_core_ct_uint_table_lookup(int bitlen, int window_size)
{
- size_t limbs = BITS_TO_LIMBS( bitlen );
- size_t count = ( (size_t) 1 ) << window_size;
+ size_t limbs = BITS_TO_LIMBS(bitlen);
+ size_t count = ((size_t) 1) << window_size;
mbedtls_mpi_uint *table = NULL;
mbedtls_mpi_uint *dest = NULL;
- ASSERT_ALLOC( table, limbs * count );
- ASSERT_ALLOC( dest, limbs );
+ ASSERT_ALLOC(table, limbs * count);
+ ASSERT_ALLOC(dest, limbs);
/*
* Fill the table with a unique counter so that differences are easily
* detected. (And have their relationship to the index relatively non-trivial just
* to be sure.)
*/
- for( size_t i = 0; i < count * limbs; i++ )
- {
+ for (size_t i = 0; i < count * limbs; i++) {
table[i] = ~i - 1;
}
- for( size_t i = 0; i < count; i++ )
- {
+ for (size_t i = 0; i < count; i++) {
mbedtls_mpi_uint *current = table + i * limbs;
- memset( dest, 0x00, limbs * sizeof( *dest ) );
+ memset(dest, 0x00, limbs * sizeof(*dest));
/*
* We shouldn't leak anything through timing.
* We need to set these in every loop as we need to make the loop
* variable public for the loop head and the buffers for comparison.
*/
- TEST_CF_SECRET( &i, sizeof( i ) );
- TEST_CF_SECRET( dest, limbs * sizeof( *dest ) );
- TEST_CF_SECRET( table, count * limbs * sizeof( *table ) );
+ TEST_CF_SECRET(&i, sizeof(i));
+ TEST_CF_SECRET(dest, limbs * sizeof(*dest));
+ TEST_CF_SECRET(table, count * limbs * sizeof(*table));
- mbedtls_mpi_core_ct_uint_table_lookup( dest, table, limbs, count, i );
+ mbedtls_mpi_core_ct_uint_table_lookup(dest, table, limbs, count, i);
- TEST_CF_PUBLIC( dest, limbs * sizeof( *dest ) );
- TEST_CF_PUBLIC( table, count * limbs * sizeof( *table ) );
- ASSERT_COMPARE( dest, limbs * sizeof( *dest ),
- current, limbs * sizeof( *current ) );
- TEST_CF_PUBLIC( &i, sizeof( i ) );
+ TEST_CF_PUBLIC(dest, limbs * sizeof(*dest));
+ TEST_CF_PUBLIC(table, count * limbs * sizeof(*table));
+ ASSERT_COMPARE(dest, limbs * sizeof(*dest),
+ current, limbs * sizeof(*current));
+ TEST_CF_PUBLIC(&i, sizeof(i));
}
exit:
@@ -1031,63 +1008,60 @@
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_fill_random( int wanted_bytes_arg, int extra_rng_bytes,
- int extra_limbs, int before, int expected_ret )
+void mpi_core_fill_random(int wanted_bytes_arg, int extra_rng_bytes,
+ int extra_limbs, int before, int expected_ret)
{
size_t wanted_bytes = wanted_bytes_arg;
mbedtls_mpi_uint *X = NULL;
- size_t X_limbs = CHARS_TO_LIMBS( wanted_bytes ) + extra_limbs;
+ size_t X_limbs = CHARS_TO_LIMBS(wanted_bytes) + extra_limbs;
size_t rng_bytes = wanted_bytes + extra_rng_bytes;
unsigned char *rnd_data = NULL;
- mbedtls_test_rnd_buf_info rnd_info = {NULL, rng_bytes, NULL, NULL};
+ mbedtls_test_rnd_buf_info rnd_info = { NULL, rng_bytes, NULL, NULL };
int ret;
/* Prepare an RNG with known output, limited to rng_bytes. */
- ASSERT_ALLOC( rnd_data, rng_bytes );
- TEST_EQUAL( 0, mbedtls_test_rnd_std_rand( NULL, rnd_data, rng_bytes ) );
+ ASSERT_ALLOC(rnd_data, rng_bytes);
+ TEST_EQUAL(0, mbedtls_test_rnd_std_rand(NULL, rnd_data, rng_bytes));
rnd_info.buf = rnd_data;
/* Allocate an MPI with room for wanted_bytes plus extra_limbs.
* extra_limbs may be negative but the total limb count must be positive.
* Fill the MPI with the byte value in before. */
- TEST_LE_U( 1, X_limbs );
- ASSERT_ALLOC( X, X_limbs );
- memset( X, before, X_limbs * sizeof( *X ) );
+ TEST_LE_U(1, X_limbs);
+ ASSERT_ALLOC(X, X_limbs);
+ memset(X, before, X_limbs * sizeof(*X));
- ret = mbedtls_mpi_core_fill_random( X, X_limbs, wanted_bytes,
- mbedtls_test_rnd_buffer_rand,
- &rnd_info );
- TEST_EQUAL( expected_ret, ret );
+ ret = mbedtls_mpi_core_fill_random(X, X_limbs, wanted_bytes,
+ mbedtls_test_rnd_buffer_rand,
+ &rnd_info);
+ TEST_EQUAL(expected_ret, ret);
- if( expected_ret == 0 )
- {
+ if (expected_ret == 0) {
/* mbedtls_mpi_core_fill_random is documented to use bytes from the
* RNG as a big-endian representation of the number. We used an RNG
* with known output, so check that the output contains the
* expected value. Bytes above wanted_bytes must be zero. */
- for( size_t i = 0; i < wanted_bytes; i++ )
- {
- mbedtls_test_set_step( i );
- TEST_EQUAL( GET_BYTE( X, i ), rnd_data[wanted_bytes - 1 - i] );
+ for (size_t i = 0; i < wanted_bytes; i++) {
+ mbedtls_test_set_step(i);
+ TEST_EQUAL(GET_BYTE(X, i), rnd_data[wanted_bytes - 1 - i]);
}
- for( size_t i = wanted_bytes; i < X_limbs * ciL; i++ )
- {
- mbedtls_test_set_step( i );
- TEST_EQUAL( GET_BYTE( X, i ), 0 );
+ for (size_t i = wanted_bytes; i < X_limbs * ciL; i++) {
+ mbedtls_test_set_step(i);
+ TEST_EQUAL(GET_BYTE(X, i), 0);
}
}
exit:
- mbedtls_free( rnd_data );
- mbedtls_free( X );
+ mbedtls_free(rnd_data);
+ mbedtls_free(X);
}
/* END_CASE */
/* BEGIN MERGE SLOT 1 */
/* BEGIN_CASE */
-void mpi_core_exp_mod( char * input_N, char * input_A,
- char * input_E, char * input_X )
+void mpi_core_exp_mod(char *input_N, char *input_A,
+ char *input_E, char *input_X)
{
mbedtls_mpi_uint *A = NULL;
mbedtls_mpi_uint *E = NULL;
@@ -1099,29 +1073,29 @@
mbedtls_mpi_uint *T = NULL;
/* Legacy MPIs for computing R2 */
mbedtls_mpi N_mpi;
- mbedtls_mpi_init( &N_mpi );
+ mbedtls_mpi_init(&N_mpi);
mbedtls_mpi R2_mpi;
- mbedtls_mpi_init( &R2_mpi );
+ mbedtls_mpi_init(&R2_mpi);
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &E, &E_limbs, input_E ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &N_limbs, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
- ASSERT_ALLOC( Y, N_limbs );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&E, &E_limbs, input_E));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &N_limbs, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
+ ASSERT_ALLOC(Y, N_limbs);
- TEST_EQUAL( A_limbs, N_limbs );
- TEST_EQUAL( X_limbs, N_limbs );
+ TEST_EQUAL(A_limbs, N_limbs);
+ TEST_EQUAL(X_limbs, N_limbs);
- TEST_EQUAL( 0, mbedtls_mpi_grow( &N_mpi, N_limbs ) );
- memcpy( N_mpi.p, N, N_limbs * sizeof( *N ) );
+ TEST_EQUAL(0, mbedtls_mpi_grow(&N_mpi, N_limbs));
+ memcpy(N_mpi.p, N, N_limbs * sizeof(*N));
N_mpi.n = N_limbs;
- TEST_EQUAL( 0,
- mbedtls_mpi_core_get_mont_r2_unsafe( &R2_mpi, &N_mpi ) );
- TEST_EQUAL( 0, mbedtls_mpi_grow( &R2_mpi, N_limbs ) );
+ TEST_EQUAL(0,
+ mbedtls_mpi_core_get_mont_r2_unsafe(&R2_mpi, &N_mpi));
+ TEST_EQUAL(0, mbedtls_mpi_grow(&R2_mpi, N_limbs));
R2 = R2_mpi.p;
- size_t working_limbs = mbedtls_mpi_core_exp_mod_working_limbs( N_limbs,
- E_limbs );
+ size_t working_limbs = mbedtls_mpi_core_exp_mod_working_limbs(N_limbs,
+ E_limbs);
/* No point exactly duplicating the code in mbedtls_mpi_core_exp_mod_working_limbs()
* to see if the output is correct, but we can check that it's in a
@@ -1132,34 +1106,34 @@
size_t min_expected_working_limbs = 1 + N_limbs * 4;
size_t max_expected_working_limbs = 1 + N_limbs * 67;
- TEST_LE_U( min_expected_working_limbs, working_limbs );
- TEST_LE_U( working_limbs, max_expected_working_limbs );
+ TEST_LE_U(min_expected_working_limbs, working_limbs);
+ TEST_LE_U(working_limbs, max_expected_working_limbs);
/* Should also be at least mbedtls_mpi_core_montmul_working_limbs() */
- TEST_LE_U( mbedtls_mpi_core_montmul_working_limbs( N_limbs ),
- working_limbs );
+ TEST_LE_U(mbedtls_mpi_core_montmul_working_limbs(N_limbs),
+ working_limbs);
- ASSERT_ALLOC( T, working_limbs );
+ ASSERT_ALLOC(T, working_limbs);
- mbedtls_mpi_core_exp_mod( Y, A, N, N_limbs, E, E_limbs, R2, T );
+ mbedtls_mpi_core_exp_mod(Y, A, N, N_limbs, E, E_limbs, R2, T);
- TEST_EQUAL( 0, memcmp( X, Y, N_limbs * sizeof( mbedtls_mpi_uint ) ) );
+ TEST_EQUAL(0, memcmp(X, Y, N_limbs * sizeof(mbedtls_mpi_uint)));
/* Check when output aliased to input */
- mbedtls_mpi_core_exp_mod( A, A, N, N_limbs, E, E_limbs, R2, T );
+ mbedtls_mpi_core_exp_mod(A, A, N, N_limbs, E, E_limbs, R2, T);
- TEST_EQUAL( 0, memcmp( X, A, N_limbs * sizeof( mbedtls_mpi_uint ) ) );
+ TEST_EQUAL(0, memcmp(X, A, N_limbs * sizeof(mbedtls_mpi_uint)));
exit:
- mbedtls_free( T );
- mbedtls_free( A );
- mbedtls_free( E );
- mbedtls_free( N );
- mbedtls_free( X );
- mbedtls_free( Y );
- mbedtls_mpi_free( &N_mpi );
- mbedtls_mpi_free( &R2_mpi );
+ mbedtls_free(T);
+ mbedtls_free(A);
+ mbedtls_free(E);
+ mbedtls_free(N);
+ mbedtls_free(X);
+ mbedtls_free(Y);
+ mbedtls_mpi_free(&N_mpi);
+ mbedtls_mpi_free(&R2_mpi);
// R2 doesn't need to be freed as it is only aliasing R2_mpi
}
/* END_CASE */
@@ -1173,8 +1147,8 @@
/* BEGIN MERGE SLOT 3 */
/* BEGIN_CASE */
-void mpi_core_sub_int( char * input_A, char * input_B,
- char * input_X, int borrow )
+void mpi_core_sub_int(char *input_A, char *input_B,
+ char *input_X, int borrow)
{
/* We are testing A - b, where A is an MPI and b is a scalar, expecting
* result X with borrow borrow. However, for ease of handling we encode b
@@ -1186,54 +1160,54 @@
mbedtls_mpi_uint *R = NULL;
size_t A_limbs, B_limbs, X_limbs;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &B, &B_limbs, input_B ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&B, &B_limbs, input_B));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
/* The MPI encoding of scalar b must be only 1 limb */
- TEST_EQUAL( B_limbs, 1 );
+ TEST_EQUAL(B_limbs, 1);
/* The subtraction is fixed-width, so A and X must have the same number of limbs */
- TEST_EQUAL( A_limbs, X_limbs );
+ TEST_EQUAL(A_limbs, X_limbs);
size_t limbs = A_limbs;
- ASSERT_ALLOC( R, limbs );
+ ASSERT_ALLOC(R, limbs);
-#define TEST_COMPARE_CORE_MPIS( A, B, limbs ) \
- ASSERT_COMPARE( A, (limbs) * sizeof(mbedtls_mpi_uint), B, (limbs) * sizeof(mbedtls_mpi_uint) )
+#define TEST_COMPARE_CORE_MPIS(A, B, limbs) \
+ ASSERT_COMPARE(A, (limbs) * sizeof(mbedtls_mpi_uint), B, (limbs) * sizeof(mbedtls_mpi_uint))
/* 1. R = A - b. Result and borrow should be correct */
- TEST_EQUAL( mbedtls_mpi_core_sub_int( R, A, B[0], limbs ), borrow );
- TEST_COMPARE_CORE_MPIS( R, X, limbs );
+ TEST_EQUAL(mbedtls_mpi_core_sub_int(R, A, B[0], limbs), borrow);
+ TEST_COMPARE_CORE_MPIS(R, X, limbs);
/* 2. A = A - b. Result and borrow should be correct */
- TEST_EQUAL( mbedtls_mpi_core_sub_int( A, A, B[0], limbs ), borrow );
- TEST_COMPARE_CORE_MPIS( A, X, limbs );
+ TEST_EQUAL(mbedtls_mpi_core_sub_int(A, A, B[0], limbs), borrow);
+ TEST_COMPARE_CORE_MPIS(A, X, limbs);
exit:
- mbedtls_free( A );
- mbedtls_free( B );
- mbedtls_free( X );
- mbedtls_free( R );
+ mbedtls_free(A);
+ mbedtls_free(B);
+ mbedtls_free(X);
+ mbedtls_free(R);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_core_check_zero_ct( char *input_X, int expected_is_zero )
+void mpi_core_check_zero_ct(char *input_X, int expected_is_zero)
{
mbedtls_mpi_uint *X = NULL;
size_t X_limbs;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
- TEST_CF_SECRET( X, X_limbs * sizeof( mbedtls_mpi_uint ) );
+ TEST_CF_SECRET(X, X_limbs * sizeof(mbedtls_mpi_uint));
- mbedtls_mpi_uint check = mbedtls_mpi_core_check_zero_ct( X, X_limbs );
+ mbedtls_mpi_uint check = mbedtls_mpi_core_check_zero_ct(X, X_limbs);
int is_zero = (check == 0);
- TEST_EQUAL( is_zero, expected_is_zero );
+ TEST_EQUAL(is_zero, expected_is_zero);
exit:
- mbedtls_free( X );
+ mbedtls_free(X);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_bignum_mod.function b/tests/suites/test_suite_bignum_mod.function
index 8ab8ccf..ded4c0c 100644
--- a/tests/suites/test_suite_bignum_mod.function
+++ b/tests/suites/test_suite_bignum_mod.function
@@ -6,45 +6,46 @@
#include "constant_time_internal.h"
#include "test/constant_flow.h"
-#define TEST_COMPARE_MPI_RESIDUES( a, b ) \
- ASSERT_COMPARE( (a).p, (a).limbs * sizeof(mbedtls_mpi_uint), \
- (b).p, (b).limbs * sizeof(mbedtls_mpi_uint) )
+#define TEST_COMPARE_MPI_RESIDUES(a, b) \
+ ASSERT_COMPARE((a).p, (a).limbs * sizeof(mbedtls_mpi_uint), \
+ (b).p, (b).limbs * sizeof(mbedtls_mpi_uint))
-static int test_read_modulus( mbedtls_mpi_mod_modulus *m,
- mbedtls_mpi_mod_rep_selector int_rep,
- char *input )
+static int test_read_modulus(mbedtls_mpi_mod_modulus *m,
+ mbedtls_mpi_mod_rep_selector int_rep,
+ char *input)
{
mbedtls_mpi_uint *p = NULL;
size_t limbs;
- int ret = mbedtls_test_read_mpi_core( &p, &limbs, input );
- if( ret != 0 )
- return( ret );
+ int ret = mbedtls_test_read_mpi_core(&p, &limbs, input);
+ if (ret != 0) {
+ return ret;
+ }
- return( mbedtls_mpi_mod_modulus_setup( m, p, limbs, int_rep ) );
+ return mbedtls_mpi_mod_modulus_setup(m, p, limbs, int_rep);
}
-static int test_read_residue( mbedtls_mpi_mod_residue *r,
- const mbedtls_mpi_mod_modulus *m,
- char *input,
- int skip_limbs_and_value_checks )
+static int test_read_residue(mbedtls_mpi_mod_residue *r,
+ const mbedtls_mpi_mod_modulus *m,
+ char *input,
+ int skip_limbs_and_value_checks)
{
mbedtls_mpi_uint *p = NULL;
size_t limbs;
- int ret = mbedtls_test_read_mpi_core( &p, &limbs, input );
- if( ret != 0 )
- return( ret );
+ int ret = mbedtls_test_read_mpi_core(&p, &limbs, input);
+ if (ret != 0) {
+ return ret;
+ }
- if( skip_limbs_and_value_checks )
- {
+ if (skip_limbs_and_value_checks) {
r->p = p;
r->limbs = limbs;
- return( 0 );
+ return 0;
}
/* mbedtls_mpi_mod_residue_setup() checks limbs, and that value < m */
- return( mbedtls_mpi_mod_residue_setup( r, m, p, limbs ) );
+ return mbedtls_mpi_mod_residue_setup(r, m, p, limbs);
}
/* END_HEADER */
@@ -54,44 +55,42 @@
*/
/* BEGIN_CASE */
-void mpi_mod_setup( int int_rep, int iret )
+void mpi_mod_setup(int int_rep, int iret)
{
#define MLIMBS 8
mbedtls_mpi_uint mp[MLIMBS];
mbedtls_mpi_mod_modulus m;
int ret;
- memset( mp, 0xFF, sizeof(mp) );
+ memset(mp, 0xFF, sizeof(mp));
- mbedtls_mpi_mod_modulus_init( &m );
- ret = mbedtls_mpi_mod_modulus_setup( &m, mp, MLIMBS, int_rep );
- TEST_EQUAL( ret, iret );
+ mbedtls_mpi_mod_modulus_init(&m);
+ ret = mbedtls_mpi_mod_modulus_setup(&m, mp, MLIMBS, int_rep);
+ TEST_EQUAL(ret, iret);
/* Only test if the constants have been set-up */
- if ( ret == 0 && int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY )
- {
+ if (ret == 0 && int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
/* Test that the consts have been calculated */
- TEST_ASSERT( m.rep.mont.rr != NULL );
- TEST_ASSERT( m.rep.mont.mm != 0 );
+ TEST_ASSERT(m.rep.mont.rr != NULL);
+ TEST_ASSERT(m.rep.mont.mm != 0);
}
/* Address sanitiser should catch if we try to free mp */
- mbedtls_mpi_mod_modulus_free( &m );
+ mbedtls_mpi_mod_modulus_free(&m);
/* Make sure that the modulus doesn't have reference to mp anymore */
- TEST_ASSERT( m.p != mp );
+ TEST_ASSERT(m.p != mp);
/* Only test if the constants have been set-up */
- if ( ret == 0 && int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY )
- {
+ if (ret == 0 && int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
/* Verify the data and pointers allocated have been properly wiped */
- TEST_ASSERT( m.rep.mont.rr == NULL );
- TEST_ASSERT( m.rep.mont.mm == 0 );
+ TEST_ASSERT(m.rep.mont.rr == NULL);
+ TEST_ASSERT(m.rep.mont.mm == 0);
}
exit:
/* It should be safe to call an mbedtls free several times */
- mbedtls_mpi_mod_modulus_free( &m );
+ mbedtls_mpi_mod_modulus_free(&m);
#undef MLIMBS
}
@@ -104,10 +103,10 @@
/* BEGIN MERGE SLOT 2 */
/* BEGIN_CASE */
-void mpi_mod_mul( char * input_A,
- char * input_B,
- char * input_N,
- char * result )
+void mpi_mod_mul(char *input_A,
+ char *input_B,
+ char *input_N,
+ char *result)
{
mbedtls_mpi_uint *X = NULL;
@@ -117,85 +116,82 @@
mbedtls_mpi_mod_residue rX = { NULL, 0 };
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( test_read_modulus( &m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N ),
- 0 );
+ TEST_EQUAL(test_read_modulus(&m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N),
+ 0);
- TEST_EQUAL( test_read_residue( &rA, &m, input_A, 0 ), 0 );
- TEST_EQUAL( test_read_residue( &rB, &m, input_B, 0 ), 0 );
- TEST_EQUAL( test_read_residue( &rR, &m, result, 0 ), 0 );
+ TEST_EQUAL(test_read_residue(&rA, &m, input_A, 0), 0);
+ TEST_EQUAL(test_read_residue(&rB, &m, input_B, 0), 0);
+ TEST_EQUAL(test_read_residue(&rR, &m, result, 0), 0);
const size_t limbs = m.limbs;
- const size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
+ const size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( rA.limbs, limbs );
- TEST_EQUAL( rB.limbs, limbs );
- TEST_EQUAL( rR.limbs, limbs );
+ TEST_EQUAL(rA.limbs, limbs);
+ TEST_EQUAL(rB.limbs, limbs);
+ TEST_EQUAL(rR.limbs, limbs);
- ASSERT_ALLOC( X, limbs );
+ ASSERT_ALLOC(X, limbs);
- TEST_EQUAL( mbedtls_mpi_mod_residue_setup( &rX, &m, X, limbs ), 0 );
+ TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&rX, &m, X, limbs), 0);
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rB, &m ), 0 );
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rB, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
/* alias X to A */
- memcpy( rX.p, rA.p, bytes );
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rX, &rB, &m ), 0 );
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ memcpy(rX.p, rA.p, bytes);
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rX, &rB, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
/* alias X to B */
- memcpy( rX.p, rB.p, bytes );
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rX, &m ), 0);
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ memcpy(rX.p, rB.p, bytes);
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rX, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
/* A == B: alias A and B */
- if( memcmp( rA.p, rB.p, bytes ) == 0 )
- {
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rA, &m ), 0 );
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ if (memcmp(rA.p, rB.p, bytes) == 0) {
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rA, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
/* X, A, B all aliased together */
- memcpy( rX.p, rA.p, bytes );
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rX, &rX, &m ), 0 );
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ memcpy(rX.p, rA.p, bytes);
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rX, &rX, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
}
-
/* A != B: test B * A */
- else
- {
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rB, &rA, &m ), 0 );
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ else {
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rB, &rA, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
/* B * A: alias X to A */
- memcpy( rX.p, rA.p, bytes );
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rB, &rX, &m ), 0 );
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ memcpy(rX.p, rA.p, bytes);
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rB, &rX, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
/* B + A: alias X to B */
- memcpy( rX.p, rB.p, bytes );
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rX, &rA, &m ), 0 );
- ASSERT_COMPARE( rX.p, bytes, rR.p, bytes );
+ memcpy(rX.p, rB.p, bytes);
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rX, &rA, &m), 0);
+ ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
}
exit:
- mbedtls_free( rA.p );
- mbedtls_free( rB.p );
- mbedtls_free( rR.p );
- mbedtls_free( X );
- mbedtls_free( (mbedtls_mpi_uint *) m.p );
+ mbedtls_free(rA.p);
+ mbedtls_free(rB.p);
+ mbedtls_free(rR.p);
+ mbedtls_free(X);
+ mbedtls_free((mbedtls_mpi_uint *) m.p);
- mbedtls_mpi_mod_modulus_free( &m );
+ mbedtls_mpi_mod_modulus_free(&m);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_mul_neg( char * input_A,
- char * input_B,
- char * input_N,
- char * result,
- int exp_ret )
+void mpi_mod_mul_neg(char *input_A,
+ char *input_B,
+ char *input_N,
+ char *result,
+ int exp_ret)
{
mbedtls_mpi_uint *X = NULL;
@@ -205,40 +201,40 @@
mbedtls_mpi_mod_residue rX = { NULL, 0 };
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
mbedtls_mpi_mod_modulus fake_m;
- mbedtls_mpi_mod_modulus_init( &fake_m );
+ mbedtls_mpi_mod_modulus_init(&fake_m);
- TEST_EQUAL( test_read_modulus( &m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N ),
- 0 );
+ TEST_EQUAL(test_read_modulus(&m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N),
+ 0);
- TEST_EQUAL( test_read_residue( &rA, &m, input_A, 1 ), 0 );
- TEST_EQUAL( test_read_residue( &rB, &m, input_B, 1 ), 0 );
- TEST_EQUAL( test_read_residue( &rR, &m, result, 1 ), 0 );
+ TEST_EQUAL(test_read_residue(&rA, &m, input_A, 1), 0);
+ TEST_EQUAL(test_read_residue(&rB, &m, input_B, 1), 0);
+ TEST_EQUAL(test_read_residue(&rR, &m, result, 1), 0);
const size_t limbs = m.limbs;
- ASSERT_ALLOC( X, limbs );
+ ASSERT_ALLOC(X, limbs);
- TEST_EQUAL( mbedtls_mpi_mod_residue_setup( &rX, &m, X, limbs ), 0 );
+ TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&rX, &m, X, limbs), 0);
rX.limbs = rR.limbs;
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rB, &m ), exp_ret );
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rB, &m), exp_ret);
/* Check when m is not initialized */
- TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rB, &fake_m ),
- MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rB, &fake_m),
+ MBEDTLS_ERR_MPI_BAD_INPUT_DATA);
exit:
- mbedtls_free( rA.p );
- mbedtls_free( rB.p );
- mbedtls_free( rR.p );
- mbedtls_free( X );
- mbedtls_free( (mbedtls_mpi_uint *) m.p );
+ mbedtls_free(rA.p);
+ mbedtls_free(rB.p);
+ mbedtls_free(rR.p);
+ mbedtls_free(X);
+ mbedtls_free((mbedtls_mpi_uint *) m.p);
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_mpi_mod_modulus_free( &fake_m );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_mpi_mod_modulus_free(&fake_m);
}
/* END_CASE */
@@ -246,9 +242,9 @@
/* BEGIN MERGE SLOT 3 */
/* BEGIN_CASE */
-void mpi_mod_sub( char * input_N,
- char * input_A, char * input_B,
- char * input_D, int expected_ret )
+void mpi_mod_sub(char *input_N,
+ char *input_A, char *input_B,
+ char *input_D, int expected_ret)
{
mbedtls_mpi_mod_residue a = { NULL, 0 };
mbedtls_mpi_mod_residue b = { NULL, 0 };
@@ -257,45 +253,43 @@
mbedtls_mpi_uint *X_raw = NULL;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( 0,
- test_read_modulus( &m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N ) );
+ TEST_EQUAL(0,
+ test_read_modulus(&m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N));
/* test_read_residue() normally checks that inputs have the same number of
* limbs as the modulus. For negative testing we can ask it to skip this
* with a non-zero final parameter. */
- TEST_EQUAL( 0, test_read_residue( &a, &m, input_A, expected_ret != 0 ) );
- TEST_EQUAL( 0, test_read_residue( &b, &m, input_B, expected_ret != 0 ) );
- TEST_EQUAL( 0, test_read_residue( &d, &m, input_D, expected_ret != 0 ) );
+ TEST_EQUAL(0, test_read_residue(&a, &m, input_A, expected_ret != 0));
+ TEST_EQUAL(0, test_read_residue(&b, &m, input_B, expected_ret != 0));
+ TEST_EQUAL(0, test_read_residue(&d, &m, input_D, expected_ret != 0));
size_t limbs = m.limbs;
- size_t bytes = limbs * sizeof( *X_raw );
+ size_t bytes = limbs * sizeof(*X_raw);
- if( expected_ret == 0 )
- {
+ if (expected_ret == 0) {
/* Negative test with too many limbs in output */
- ASSERT_ALLOC( X_raw, limbs + 1 );
+ ASSERT_ALLOC(X_raw, limbs + 1);
x.p = X_raw;
x.limbs = limbs + 1;
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_sub( &x, &a, &b, &m ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_sub(&x, &a, &b, &m));
- mbedtls_free( X_raw );
+ mbedtls_free(X_raw);
X_raw = NULL;
/* Negative test with too few limbs in output */
- if( limbs > 1 )
- {
- ASSERT_ALLOC( X_raw, limbs - 1 );
+ if (limbs > 1) {
+ ASSERT_ALLOC(X_raw, limbs - 1);
x.p = X_raw;
x.limbs = limbs - 1;
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_sub( &x, &a, &b, &m ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_sub(&x, &a, &b, &m));
- mbedtls_free( X_raw );
+ mbedtls_free(X_raw);
X_raw = NULL;
}
@@ -303,56 +297,56 @@
* manually-written test cases with expected_ret != 0. */
}
- ASSERT_ALLOC( X_raw, limbs );
+ ASSERT_ALLOC(X_raw, limbs);
- TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &x, &m, X_raw, limbs ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &m, X_raw, limbs));
/* a - b => Correct result, or expected error */
- TEST_EQUAL( expected_ret, mbedtls_mpi_mod_sub( &x, &a, &b, &m ) );
- if( expected_ret != 0 )
+ TEST_EQUAL(expected_ret, mbedtls_mpi_mod_sub(&x, &a, &b, &m));
+ if (expected_ret != 0) {
goto exit;
+ }
- TEST_COMPARE_MPI_RESIDUES( x, d );
+ TEST_COMPARE_MPI_RESIDUES(x, d);
/* a - b: alias x to a => Correct result */
- memcpy( x.p, a.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_sub( &x, &x, &b, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, d );
+ memcpy(x.p, a.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_sub(&x, &x, &b, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, d);
/* a - b: alias x to b => Correct result */
- memcpy( x.p, b.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_sub( &x, &a, &x, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, d );
+ memcpy(x.p, b.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_sub(&x, &a, &x, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, d);
- if ( memcmp( a.p, b.p, bytes ) == 0 )
- {
+ if (memcmp(a.p, b.p, bytes) == 0) {
/* a == b: alias a and b */
/* a - a => Correct result */
- TEST_EQUAL( 0, mbedtls_mpi_mod_sub( &x, &a, &a, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, d );
+ TEST_EQUAL(0, mbedtls_mpi_mod_sub(&x, &a, &a, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, d);
/* a - a: x, a, b all aliased together => Correct result */
- memcpy( x.p, a.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_sub( &x, &x, &x, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, d );
+ memcpy(x.p, a.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_sub(&x, &x, &x, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, d);
}
exit:
- mbedtls_free( (void *)m.p ); /* mbedtls_mpi_mod_modulus_free() sets m.p = NULL */
- mbedtls_mpi_mod_modulus_free( &m );
+ mbedtls_free((void *) m.p); /* mbedtls_mpi_mod_modulus_free() sets m.p = NULL */
+ mbedtls_mpi_mod_modulus_free(&m);
- mbedtls_free( a.p );
- mbedtls_free( b.p );
- mbedtls_free( d.p );
- mbedtls_free( X_raw );
+ mbedtls_free(a.p);
+ mbedtls_free(b.p);
+ mbedtls_free(d.p);
+ mbedtls_free(X_raw);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_inv_mont( char * input_N,
- char * input_A, char * input_I,
- int expected_ret )
+void mpi_mod_inv_mont(char *input_N,
+ char *input_A, char *input_I,
+ int expected_ret)
{
mbedtls_mpi_mod_residue a = { NULL, 0 }; /* argument */
mbedtls_mpi_mod_residue i = { NULL, 0 }; /* expected inverse wrt N */
@@ -360,49 +354,48 @@
mbedtls_mpi_uint *X_raw = NULL;
mbedtls_mpi_mod_modulus N;
- mbedtls_mpi_mod_modulus_init( &N );
+ mbedtls_mpi_mod_modulus_init(&N);
- TEST_EQUAL( 0,
- test_read_modulus( &N, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N ) );
+ TEST_EQUAL(0,
+ test_read_modulus(&N, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N));
/* test_read_residue() normally checks that inputs have the same number of
* limbs as the modulus. For negative testing we can ask it to skip this
* with a non-zero final parameter. */
- TEST_EQUAL( 0, test_read_residue( &a, &N, input_A, expected_ret != 0 ) );
- TEST_EQUAL( 0, test_read_residue( &i, &N, input_I, expected_ret != 0 ) );
+ TEST_EQUAL(0, test_read_residue(&a, &N, input_A, expected_ret != 0));
+ TEST_EQUAL(0, test_read_residue(&i, &N, input_I, expected_ret != 0));
size_t limbs = N.limbs;
- size_t bytes = limbs * sizeof( *X_raw );
+ size_t bytes = limbs * sizeof(*X_raw);
- ASSERT_ALLOC( X_raw, limbs );
+ ASSERT_ALLOC(X_raw, limbs);
- TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &x, &N, X_raw, limbs ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &N, X_raw, limbs));
- TEST_EQUAL( expected_ret, mbedtls_mpi_mod_inv( &x, &a, &N ) );
- if( expected_ret == 0 )
- {
- TEST_COMPARE_MPI_RESIDUES( x, i );
+ TEST_EQUAL(expected_ret, mbedtls_mpi_mod_inv(&x, &a, &N));
+ if (expected_ret == 0) {
+ TEST_COMPARE_MPI_RESIDUES(x, i);
/* a^-1: alias x to a => Correct result */
- memcpy( x.p, a.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_inv( &x, &x, &N ) );
- TEST_COMPARE_MPI_RESIDUES( x, i );
+ memcpy(x.p, a.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_inv(&x, &x, &N));
+ TEST_COMPARE_MPI_RESIDUES(x, i);
}
exit:
- mbedtls_free( (void *)N.p ); /* mbedtls_mpi_mod_modulus_free() sets N.p = NULL */
- mbedtls_mpi_mod_modulus_free( &N );
+ mbedtls_free((void *) N.p); /* mbedtls_mpi_mod_modulus_free() sets N.p = NULL */
+ mbedtls_mpi_mod_modulus_free(&N);
- mbedtls_free( a.p );
- mbedtls_free( i.p );
- mbedtls_free( X_raw );
+ mbedtls_free(a.p);
+ mbedtls_free(i.p);
+ mbedtls_free(X_raw);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_inv_non_mont( char * input_N,
- char * input_A, char * input_I,
- int expected_ret )
+void mpi_mod_inv_non_mont(char *input_N,
+ char *input_A, char *input_I,
+ int expected_ret)
{
mbedtls_mpi_mod_residue a = { NULL, 0 }; /* argument */
mbedtls_mpi_mod_residue i = { NULL, 0 }; /* expected inverse wrt N */
@@ -410,42 +403,41 @@
mbedtls_mpi_uint *X_raw = NULL;
mbedtls_mpi_mod_modulus N;
- mbedtls_mpi_mod_modulus_init( &N );
+ mbedtls_mpi_mod_modulus_init(&N);
- TEST_EQUAL( 0,
- test_read_modulus( &N, MBEDTLS_MPI_MOD_REP_OPT_RED, input_N ) );
+ TEST_EQUAL(0,
+ test_read_modulus(&N, MBEDTLS_MPI_MOD_REP_OPT_RED, input_N));
/* test_read_residue() normally checks that inputs have the same number of
* limbs as the modulus. For negative testing we can ask it to skip this
* with a non-zero final parameter. */
- TEST_EQUAL( 0, test_read_residue( &a, &N, input_A, expected_ret != 0 ) );
- TEST_EQUAL( 0, test_read_residue( &i, &N, input_I, expected_ret != 0 ) );
+ TEST_EQUAL(0, test_read_residue(&a, &N, input_A, expected_ret != 0));
+ TEST_EQUAL(0, test_read_residue(&i, &N, input_I, expected_ret != 0));
size_t limbs = N.limbs;
- size_t bytes = limbs * sizeof( *X_raw );
+ size_t bytes = limbs * sizeof(*X_raw);
- ASSERT_ALLOC( X_raw, limbs );
+ ASSERT_ALLOC(X_raw, limbs);
- TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &x, &N, X_raw, limbs ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &N, X_raw, limbs));
- TEST_EQUAL( expected_ret, mbedtls_mpi_mod_inv( &x, &a, &N ) );
- if( expected_ret == 0 )
- {
- TEST_COMPARE_MPI_RESIDUES( x, i );
+ TEST_EQUAL(expected_ret, mbedtls_mpi_mod_inv(&x, &a, &N));
+ if (expected_ret == 0) {
+ TEST_COMPARE_MPI_RESIDUES(x, i);
/* a^-1: alias x to a => Correct result */
- memcpy( x.p, a.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_inv( &x, &x, &N ) );
- TEST_COMPARE_MPI_RESIDUES( x, i );
+ memcpy(x.p, a.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_inv(&x, &x, &N));
+ TEST_COMPARE_MPI_RESIDUES(x, i);
}
exit:
- mbedtls_free( (void *)N.p ); /* mbedtls_mpi_mod_modulus_free() sets N.p = NULL */
- mbedtls_mpi_mod_modulus_free( &N );
+ mbedtls_free((void *) N.p); /* mbedtls_mpi_mod_modulus_free() sets N.p = NULL */
+ mbedtls_mpi_mod_modulus_free(&N);
- mbedtls_free( a.p );
- mbedtls_free( i.p );
- mbedtls_free( X_raw );
+ mbedtls_free(a.p);
+ mbedtls_free(i.p);
+ mbedtls_free(X_raw);
}
/* END_CASE */
/* END MERGE SLOT 3 */
@@ -456,9 +448,9 @@
/* BEGIN MERGE SLOT 5 */
/* BEGIN_CASE */
-void mpi_mod_add( char * input_N,
- char * input_A, char * input_B,
- char * input_S, int expected_ret )
+void mpi_mod_add(char *input_N,
+ char *input_A, char *input_B,
+ char *input_S, int expected_ret)
{
mbedtls_mpi_mod_residue a = { NULL, 0 };
mbedtls_mpi_mod_residue b = { NULL, 0 };
@@ -467,45 +459,43 @@
mbedtls_mpi_uint *X_raw = NULL;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( 0,
- test_read_modulus( &m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N ) );
+ TEST_EQUAL(0,
+ test_read_modulus(&m, MBEDTLS_MPI_MOD_REP_MONTGOMERY, input_N));
/* test_read_residue() normally checks that inputs have the same number of
* limbs as the modulus. For negative testing we can ask it to skip this
* with a non-zero final parameter. */
- TEST_EQUAL( 0, test_read_residue( &a, &m, input_A, expected_ret != 0 ) );
- TEST_EQUAL( 0, test_read_residue( &b, &m, input_B, expected_ret != 0 ) );
- TEST_EQUAL( 0, test_read_residue( &s, &m, input_S, expected_ret != 0 ) );
+ TEST_EQUAL(0, test_read_residue(&a, &m, input_A, expected_ret != 0));
+ TEST_EQUAL(0, test_read_residue(&b, &m, input_B, expected_ret != 0));
+ TEST_EQUAL(0, test_read_residue(&s, &m, input_S, expected_ret != 0));
size_t limbs = m.limbs;
- size_t bytes = limbs * sizeof( *X_raw );
+ size_t bytes = limbs * sizeof(*X_raw);
- if( expected_ret == 0 )
- {
+ if (expected_ret == 0) {
/* Negative test with too many limbs in output */
- ASSERT_ALLOC( X_raw, limbs + 1 );
+ ASSERT_ALLOC(X_raw, limbs + 1);
x.p = X_raw;
x.limbs = limbs + 1;
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_add( &x, &a, &b, &m ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_add(&x, &a, &b, &m));
- mbedtls_free( X_raw );
+ mbedtls_free(X_raw);
X_raw = NULL;
/* Negative test with too few limbs in output */
- if( limbs > 1 )
- {
- ASSERT_ALLOC( X_raw, limbs - 1 );
+ if (limbs > 1) {
+ ASSERT_ALLOC(X_raw, limbs - 1);
x.p = X_raw;
x.limbs = limbs - 1;
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_add( &x, &a, &b, &m ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_add(&x, &a, &b, &m));
- mbedtls_free( X_raw );
+ mbedtls_free(X_raw);
X_raw = NULL;
}
@@ -514,49 +504,49 @@
}
/* Allocate correct number of limbs for X_raw */
- ASSERT_ALLOC( X_raw, limbs );
+ ASSERT_ALLOC(X_raw, limbs);
- TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &x, &m, X_raw, limbs ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &m, X_raw, limbs));
/* A + B => Correct result or expected error */
- TEST_EQUAL( expected_ret, mbedtls_mpi_mod_add( &x, &a, &b, &m ) );
- if( expected_ret != 0 )
+ TEST_EQUAL(expected_ret, mbedtls_mpi_mod_add(&x, &a, &b, &m));
+ if (expected_ret != 0) {
goto exit;
+ }
- TEST_COMPARE_MPI_RESIDUES( x, s );
+ TEST_COMPARE_MPI_RESIDUES(x, s);
/* a + b: alias x to a => Correct result */
- memcpy( x.p, a.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_add( &x, &x, &b, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, s );
+ memcpy(x.p, a.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_add(&x, &x, &b, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, s);
/* a + b: alias x to b => Correct result */
- memcpy( x.p, b.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_add( &x, &a, &x, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, s );
+ memcpy(x.p, b.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_add(&x, &a, &x, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, s);
- if ( memcmp( a.p, b.p, bytes ) == 0 )
- {
+ if (memcmp(a.p, b.p, bytes) == 0) {
/* a == b: alias a and b */
/* a + a => Correct result */
- TEST_EQUAL( 0, mbedtls_mpi_mod_add( &x, &a, &a, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, s );
+ TEST_EQUAL(0, mbedtls_mpi_mod_add(&x, &a, &a, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, s);
/* a + a: x, a, b all aliased together => Correct result */
- memcpy( x.p, a.p, bytes );
- TEST_EQUAL( 0, mbedtls_mpi_mod_add( &x, &x, &x, &m ) );
- TEST_COMPARE_MPI_RESIDUES( x, s );
+ memcpy(x.p, a.p, bytes);
+ TEST_EQUAL(0, mbedtls_mpi_mod_add(&x, &x, &x, &m));
+ TEST_COMPARE_MPI_RESIDUES(x, s);
}
exit:
- mbedtls_free( (void *)m.p ); /* mbedtls_mpi_mod_modulus_free() sets m.p = NULL */
- mbedtls_mpi_mod_modulus_free( &m );
+ mbedtls_free((void *) m.p); /* mbedtls_mpi_mod_modulus_free() sets m.p = NULL */
+ mbedtls_mpi_mod_modulus_free(&m);
- mbedtls_free( a.p );
- mbedtls_free( b.p );
- mbedtls_free( s.p );
- mbedtls_free( X_raw );
+ mbedtls_free(a.p);
+ mbedtls_free(b.p);
+ mbedtls_free(s.p);
+ mbedtls_free(X_raw);
}
/* END_CASE */
/* END MERGE SLOT 5 */
@@ -567,7 +557,7 @@
/* BEGIN MERGE SLOT 7 */
/* BEGIN_CASE */
-void mpi_residue_setup( char * input_N, char * input_R, int ret )
+void mpi_residue_setup(char *input_N, char *input_R, int ret)
{
mbedtls_mpi_uint *N = NULL;
mbedtls_mpi_uint *R = NULL;
@@ -575,32 +565,31 @@
mbedtls_mpi_mod_modulus m;
mbedtls_mpi_mod_residue r;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
/* Allocate the memory for intermediate data structures */
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &R, &r_limbs, input_R ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &n_limbs, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&R, &r_limbs, input_R));
- TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_modulus_setup(&m, N, n_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY));
- TEST_EQUAL( ret, mbedtls_mpi_mod_residue_setup( &r, &m, R , r_limbs ) );
+ TEST_EQUAL(ret, mbedtls_mpi_mod_residue_setup(&r, &m, R, r_limbs));
- if ( ret == 0 )
- {
- TEST_EQUAL( r.limbs, r_limbs );
- TEST_ASSERT( r.p == R );
+ if (ret == 0) {
+ TEST_EQUAL(r.limbs, r_limbs);
+ TEST_ASSERT(r.p == R);
}
exit:
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( N );
- mbedtls_free( R );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(N);
+ mbedtls_free(R);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_io_neg( char * input_N, data_t * buf, int ret )
+void mpi_mod_io_neg(char *input_N, data_t *buf, int ret)
{
mbedtls_mpi_uint *N = NULL;
mbedtls_mpi_uint *R = NULL;
@@ -609,68 +598,69 @@
mbedtls_mpi_mod_residue r = { NULL, 0 };
mbedtls_mpi_mod_ext_rep endian = MBEDTLS_MPI_MOD_EXT_REP_LE;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
size_t n_limbs;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &n_limbs, input_N));
size_t r_limbs = n_limbs;
- ASSERT_ALLOC( R, r_limbs );
+ ASSERT_ALLOC(R, r_limbs);
/* modulus->p == NULL || residue->p == NULL ( m has not been set-up ) */
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_read(&r, &m, buf->x, buf->len, endian));
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_write( &r, &m, buf->x, buf->len, endian ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_write(&r, &m, buf->x, buf->len, endian));
/* Set up modulus and test with residue->p == NULL */
- TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_modulus_setup(&m, N, n_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY));
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_write( &r, &m, buf->x, buf->len, endian ) );
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_read(&r, &m, buf->x, buf->len, endian));
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_write(&r, &m, buf->x, buf->len, endian));
/* Do the rest of the tests with a residue set up with the input data */
- TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &r, &m, R , r_limbs ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&r, &m, R, r_limbs));
/* Fail for r_limbs < m->limbs */
r.limbs--;
- TEST_ASSERT( r.limbs < m.limbs );
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_write( &r, &m, buf->x, buf->len, endian ) );
+ TEST_ASSERT(r.limbs < m.limbs);
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_read(&r, &m, buf->x, buf->len, endian));
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_write(&r, &m, buf->x, buf->len, endian));
r.limbs++;
/* Fail for r_limbs > m->limbs */
m.limbs--;
- TEST_ASSERT( r.limbs > m.limbs );
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
- TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_write( &r, &m, buf->x, buf->len, endian ) );
+ TEST_ASSERT(r.limbs > m.limbs);
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_read(&r, &m, buf->x, buf->len, endian));
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
+ mbedtls_mpi_mod_write(&r, &m, buf->x, buf->len, endian));
m.limbs++;
/* Test the read */
- TEST_EQUAL( ret, mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
+ TEST_EQUAL(ret, mbedtls_mpi_mod_read(&r, &m, buf->x, buf->len, endian));
/* Test write overflow only when the representation is large and read is successful */
- if ( r.limbs > 1 && ret == 0 )
- TEST_EQUAL( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL,
- mbedtls_mpi_mod_write( &r, &m, buf->x, 1, endian ) );
+ if (r.limbs > 1 && ret == 0) {
+ TEST_EQUAL(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL,
+ mbedtls_mpi_mod_write(&r, &m, buf->x, 1, endian));
+ }
exit:
- mbedtls_mpi_mod_residue_release( &r );
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( N );
- mbedtls_free( R );
+ mbedtls_mpi_mod_residue_release(&r);
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(N);
+ mbedtls_free(R);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_io( char * input_N, data_t * input_A, int endian )
+void mpi_mod_io(char *input_N, data_t *input_A, int endian)
{
mbedtls_mpi_uint *N = NULL;
mbedtls_mpi_uint *R = NULL;
@@ -682,96 +672,94 @@
mbedtls_mpi_mod_residue r_copy;
size_t n_limbs, n_bytes, a_bytes;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
/* Read inputs */
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) );
- n_bytes = n_limbs * sizeof( mbedtls_mpi_uint );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &n_limbs, input_N));
+ n_bytes = n_limbs * sizeof(mbedtls_mpi_uint);
a_bytes = input_A->len;
/* Allocate the memory for intermediate data structures */
- ASSERT_ALLOC( R, n_bytes );
- ASSERT_ALLOC( R_COPY, n_bytes );
+ ASSERT_ALLOC(R, n_bytes);
+ ASSERT_ALLOC(R_COPY, n_bytes);
/* Test that input's size is not greater to modulo's */
- TEST_LE_U( a_bytes, n_bytes );
+ TEST_LE_U(a_bytes, n_bytes);
/* Init Structures */
- TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_modulus_setup(&m, N, n_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY));
/* Enforcing p_limbs >= m->limbs */
- TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &r, &m, R, n_limbs ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&r, &m, R, n_limbs));
- TEST_EQUAL( 0, mbedtls_mpi_mod_read( &r, &m, input_A->x, input_A->len,
- endian ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_read(&r, &m, input_A->x, input_A->len,
+ endian));
/* Read a copy for checking that writing didn't change the value of r */
- TEST_EQUAL( 0, mbedtls_mpi_mod_residue_setup( &r_copy, &m,
- R_COPY, n_limbs ) );
- TEST_EQUAL( 0, mbedtls_mpi_mod_read( &r_copy, &m, input_A->x, input_A->len,
- endian ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&r_copy, &m,
+ R_COPY, n_limbs));
+ TEST_EQUAL(0, mbedtls_mpi_mod_read(&r_copy, &m, input_A->x, input_A->len,
+ endian));
/* Get number of bytes without leading zeroes */
size_t a_bytes_trimmed = a_bytes;
- while( a_bytes_trimmed > 0 )
- {
- unsigned char* r_byte_array = (unsigned char*) r.p;
- if( r_byte_array[--a_bytes_trimmed] != 0 )
+ while (a_bytes_trimmed > 0) {
+ unsigned char *r_byte_array = (unsigned char *) r.p;
+ if (r_byte_array[--a_bytes_trimmed] != 0) {
break;
+ }
}
a_bytes_trimmed++;
/* Test write with three output buffer sizes: tight, same as input and
* longer than the input */
size_t obuf_sizes[3];
- const size_t obuf_sizes_len = sizeof( obuf_sizes ) / sizeof( obuf_sizes[0] );
+ const size_t obuf_sizes_len = sizeof(obuf_sizes) / sizeof(obuf_sizes[0]);
obuf_sizes[0] = a_bytes_trimmed;
obuf_sizes[1] = a_bytes;
obuf_sizes[2] = a_bytes + 8;
- for( size_t i = 0; i < obuf_sizes_len; i++ )
- {
- ASSERT_ALLOC( obuf, obuf_sizes[i] );
- TEST_EQUAL( 0, mbedtls_mpi_mod_write( &r, &m, obuf, obuf_sizes[i], endian ) );
+ for (size_t i = 0; i < obuf_sizes_len; i++) {
+ ASSERT_ALLOC(obuf, obuf_sizes[i]);
+ TEST_EQUAL(0, mbedtls_mpi_mod_write(&r, &m, obuf, obuf_sizes[i], endian));
/* Make sure that writing didn't corrupt the value of r */
- ASSERT_COMPARE( r.p, r.limbs, r_copy.p, r_copy.limbs );
+ ASSERT_COMPARE(r.p, r.limbs, r_copy.p, r_copy.limbs);
/* Set up reference output for checking the result */
- ASSERT_ALLOC( ref_buf, obuf_sizes[i] );
- switch( endian )
- {
+ ASSERT_ALLOC(ref_buf, obuf_sizes[i]);
+ switch (endian) {
case MBEDTLS_MPI_MOD_EXT_REP_LE:
- memcpy( ref_buf, input_A->x, a_bytes_trimmed );
+ memcpy(ref_buf, input_A->x, a_bytes_trimmed);
break;
case MBEDTLS_MPI_MOD_EXT_REP_BE:
- {
- size_t a_offset = input_A->len - a_bytes_trimmed;
- size_t ref_offset = obuf_sizes[i] - a_bytes_trimmed;
- memcpy( ref_buf + ref_offset, input_A->x + a_offset,
- a_bytes_trimmed );
- }
- break;
+ {
+ size_t a_offset = input_A->len - a_bytes_trimmed;
+ size_t ref_offset = obuf_sizes[i] - a_bytes_trimmed;
+ memcpy(ref_buf + ref_offset, input_A->x + a_offset,
+ a_bytes_trimmed);
+ }
+ break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
}
/* Check the result */
- ASSERT_COMPARE( obuf, obuf_sizes[i], ref_buf, obuf_sizes[i] );
+ ASSERT_COMPARE(obuf, obuf_sizes[i], ref_buf, obuf_sizes[i]);
- mbedtls_free( ref_buf );
+ mbedtls_free(ref_buf);
ref_buf = NULL;
- mbedtls_free( obuf );
+ mbedtls_free(obuf);
obuf = NULL;
}
exit:
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( N );
- mbedtls_free( R );
- mbedtls_free( R_COPY );
- mbedtls_free( obuf );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(N);
+ mbedtls_free(R);
+ mbedtls_free(R_COPY);
+ mbedtls_free(obuf);
}
/* END_CASE */
/* END MERGE SLOT 7 */
diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function
index 4a658e1..9310b0e 100644
--- a/tests/suites/test_suite_bignum_mod_raw.function
+++ b/tests/suites/test_suite_bignum_mod_raw.function
@@ -14,105 +14,103 @@
*/
/* BEGIN_CASE */
-void mpi_mod_raw_io( data_t *input, int nb_int, int nx_32_int,
- int iendian, int iret, int oret )
+void mpi_mod_raw_io(data_t *input, int nb_int, int nx_32_int,
+ int iendian, int iret, int oret)
{
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- if( iret != 0 )
- TEST_ASSERT( oret == 0 );
+ if (iret != 0) {
+ TEST_ASSERT(oret == 0);
+ }
- TEST_LE_S( 0, nb_int );
+ TEST_LE_S(0, nb_int);
size_t nb = nb_int;
unsigned char buf[1024];
- TEST_LE_U( nb, sizeof( buf ) );
+ TEST_LE_U(nb, sizeof(buf));
/* nx_32_int is the number of 32 bit limbs, if we have 64 bit limbs we need
* to halve the number of limbs to have the same size. */
size_t nx;
- TEST_LE_S( 0, nx_32_int );
- if( sizeof( mbedtls_mpi_uint ) == 8 )
+ TEST_LE_S(0, nx_32_int);
+ if (sizeof(mbedtls_mpi_uint) == 8) {
nx = nx_32_int / 2 + nx_32_int % 2;
- else
+ } else {
nx = nx_32_int;
-
- mbedtls_mpi_uint X[sizeof( buf ) / sizeof( mbedtls_mpi_uint )];
- TEST_LE_U( nx, sizeof( X ) / sizeof( X[0] ) );
-
- int endian;
- if( iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID )
- endian = MBEDTLS_MPI_MOD_EXT_REP_LE;
- else
- endian = iendian;
-
- mbedtls_mpi_uint init[sizeof( X ) / sizeof( X[0] )];
- memset( init, 0xFF, sizeof( init ) );
- int ret = mbedtls_mpi_mod_modulus_setup( &m, init, nx,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY );
- TEST_EQUAL( ret, 0 );
-
- if( iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID && iret != 0 )
- endian = MBEDTLS_MPI_MOD_EXT_REP_INVALID;
-
- ret = mbedtls_mpi_mod_raw_read( X, &m, input->x, input->len, endian );
- TEST_EQUAL( ret, iret );
-
- if( iret == 0 )
- {
- if( iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID && oret != 0 )
- endian = MBEDTLS_MPI_MOD_EXT_REP_INVALID;
-
- ret = mbedtls_mpi_mod_raw_write( X, &m, buf, nb, endian );
- TEST_EQUAL( ret, oret );
}
- if( ( iret == 0 ) && ( oret == 0 ) )
- {
- if( nb > input->len )
- {
- if( endian == MBEDTLS_MPI_MOD_EXT_REP_BE )
- {
- size_t leading_zeroes = nb - input->len;
- TEST_ASSERT( memcmp( buf + nb - input->len, input->x, input->len ) == 0 );
- for( size_t i = 0; i < leading_zeroes; i++ )
- TEST_EQUAL( buf[i], 0 );
- }
- else
- {
- TEST_ASSERT( memcmp( buf, input->x, input->len ) == 0 );
- for( size_t i = input->len; i < nb; i++ )
- TEST_EQUAL( buf[i], 0 );
- }
+ mbedtls_mpi_uint X[sizeof(buf) / sizeof(mbedtls_mpi_uint)];
+ TEST_LE_U(nx, sizeof(X) / sizeof(X[0]));
+
+ int endian;
+ if (iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID) {
+ endian = MBEDTLS_MPI_MOD_EXT_REP_LE;
+ } else {
+ endian = iendian;
+ }
+
+ mbedtls_mpi_uint init[sizeof(X) / sizeof(X[0])];
+ memset(init, 0xFF, sizeof(init));
+ int ret = mbedtls_mpi_mod_modulus_setup(&m, init, nx,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY);
+ TEST_EQUAL(ret, 0);
+
+ if (iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID && iret != 0) {
+ endian = MBEDTLS_MPI_MOD_EXT_REP_INVALID;
+ }
+
+ ret = mbedtls_mpi_mod_raw_read(X, &m, input->x, input->len, endian);
+ TEST_EQUAL(ret, iret);
+
+ if (iret == 0) {
+ if (iendian == MBEDTLS_MPI_MOD_EXT_REP_INVALID && oret != 0) {
+ endian = MBEDTLS_MPI_MOD_EXT_REP_INVALID;
}
- else
- {
- if( endian == MBEDTLS_MPI_MOD_EXT_REP_BE )
- {
- size_t leading_zeroes = input->len - nb;
- TEST_ASSERT( memcmp( input->x + input->len - nb, buf, nb ) == 0 );
- for( size_t i = 0; i < leading_zeroes; i++ )
- TEST_EQUAL( input->x[i], 0 );
+
+ ret = mbedtls_mpi_mod_raw_write(X, &m, buf, nb, endian);
+ TEST_EQUAL(ret, oret);
+ }
+
+ if ((iret == 0) && (oret == 0)) {
+ if (nb > input->len) {
+ if (endian == MBEDTLS_MPI_MOD_EXT_REP_BE) {
+ size_t leading_zeroes = nb - input->len;
+ TEST_ASSERT(memcmp(buf + nb - input->len, input->x, input->len) == 0);
+ for (size_t i = 0; i < leading_zeroes; i++) {
+ TEST_EQUAL(buf[i], 0);
+ }
+ } else {
+ TEST_ASSERT(memcmp(buf, input->x, input->len) == 0);
+ for (size_t i = input->len; i < nb; i++) {
+ TEST_EQUAL(buf[i], 0);
+ }
}
- else
- {
- TEST_ASSERT( memcmp( input->x, buf, nb ) == 0 );
- for( size_t i = nb; i < input->len; i++ )
- TEST_EQUAL( input->x[i], 0 );
+ } else {
+ if (endian == MBEDTLS_MPI_MOD_EXT_REP_BE) {
+ size_t leading_zeroes = input->len - nb;
+ TEST_ASSERT(memcmp(input->x + input->len - nb, buf, nb) == 0);
+ for (size_t i = 0; i < leading_zeroes; i++) {
+ TEST_EQUAL(input->x[i], 0);
+ }
+ } else {
+ TEST_ASSERT(memcmp(input->x, buf, nb) == 0);
+ for (size_t i = nb; i < input->len; i++) {
+ TEST_EQUAL(input->x[i], 0);
+ }
}
}
}
exit:
- mbedtls_mpi_mod_modulus_free( &m );
+ mbedtls_mpi_mod_modulus_free(&m);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_raw_cond_assign( char * input_X,
- char * input_Y,
- int input_bytes )
+void mpi_mod_raw_cond_assign(char *input_X,
+ char *input_Y,
+ int input_bytes)
{
mbedtls_mpi_uint *X = NULL;
mbedtls_mpi_uint *Y = NULL;
@@ -121,68 +119,67 @@
size_t limbs_Y;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( mbedtls_test_read_mpi_core( &X, &limbs_X, input_X ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &Y, &limbs_Y, input_Y ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&X, &limbs_X, input_X), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&Y, &limbs_Y, input_Y), 0);
size_t limbs = limbs_X;
- size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
- size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
- size_t copy_bytes = copy_limbs * sizeof( mbedtls_mpi_uint );
+ size_t copy_limbs = CHARS_TO_LIMBS(input_bytes);
+ size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
+ size_t copy_bytes = copy_limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( limbs_X, limbs_Y );
- TEST_ASSERT( copy_limbs <= limbs );
+ TEST_EQUAL(limbs_X, limbs_Y);
+ TEST_ASSERT(copy_limbs <= limbs);
- ASSERT_ALLOC( buff_m, copy_limbs );
- memset( buff_m, 0xFF, copy_limbs );
- TEST_EQUAL( mbedtls_mpi_mod_modulus_setup(
- &m, buff_m, copy_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ), 0 );
+ ASSERT_ALLOC(buff_m, copy_limbs);
+ memset(buff_m, 0xFF, copy_limbs);
+ TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
+ &m, buff_m, copy_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
/* condition is false */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_mod_raw_cond_assign( X, Y, &m, 0 );
+ mbedtls_mpi_mod_raw_cond_assign(X, Y, &m, 0);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
- TEST_ASSERT( memcmp( X, Y, bytes ) != 0 );
+ TEST_ASSERT(memcmp(X, Y, bytes) != 0);
/* condition is true */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_mod_raw_cond_assign( X, Y, &m, 1 );
+ mbedtls_mpi_mod_raw_cond_assign(X, Y, &m, 1);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
/* Check if the given length is copied even it is smaller
than the length of the given MPIs. */
- if( copy_limbs <limbs )
- {
- ASSERT_COMPARE( X, copy_bytes, Y, copy_bytes );
- TEST_ASSERT( memcmp( X, Y, bytes ) != 0 );
+ if (copy_limbs < limbs) {
+ ASSERT_COMPARE(X, copy_bytes, Y, copy_bytes);
+ TEST_ASSERT(memcmp(X, Y, bytes) != 0);
+ } else {
+ ASSERT_COMPARE(X, bytes, Y, bytes);
}
- else
- ASSERT_COMPARE( X, bytes, Y, bytes );
exit:
- mbedtls_free( X );
- mbedtls_free( Y );
+ mbedtls_free(X);
+ mbedtls_free(Y);
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( buff_m );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(buff_m);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_raw_cond_swap( char * input_X,
- char * input_Y,
- int input_bytes )
+void mpi_mod_raw_cond_swap(char *input_X,
+ char *input_Y,
+ int input_bytes)
{
mbedtls_mpi_uint *tmp_X = NULL;
mbedtls_mpi_uint *tmp_Y = NULL;
@@ -193,77 +190,74 @@
size_t limbs_Y;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_X, &limbs_X, input_X ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_Y, &limbs_Y, input_Y ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&tmp_X, &limbs_X, input_X), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&tmp_Y, &limbs_Y, input_Y), 0);
size_t limbs = limbs_X;
- size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
- size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
- size_t copy_bytes = copy_limbs * sizeof( mbedtls_mpi_uint );
+ size_t copy_limbs = CHARS_TO_LIMBS(input_bytes);
+ size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
+ size_t copy_bytes = copy_limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( limbs_X, limbs_Y );
- TEST_ASSERT( copy_limbs <= limbs );
+ TEST_EQUAL(limbs_X, limbs_Y);
+ TEST_ASSERT(copy_limbs <= limbs);
- ASSERT_ALLOC( buff_m, copy_limbs );
- memset( buff_m, 0xFF, copy_limbs );
- TEST_EQUAL( mbedtls_mpi_mod_modulus_setup(
- &m, buff_m, copy_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ), 0 );
+ ASSERT_ALLOC(buff_m, copy_limbs);
+ memset(buff_m, 0xFF, copy_limbs);
+ TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
+ &m, buff_m, copy_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
- ASSERT_ALLOC( X, limbs );
- memcpy( X, tmp_X, bytes );
+ ASSERT_ALLOC(X, limbs);
+ memcpy(X, tmp_X, bytes);
- ASSERT_ALLOC( Y, bytes );
- memcpy( Y, tmp_Y, bytes );
+ ASSERT_ALLOC(Y, bytes);
+ memcpy(Y, tmp_Y, bytes);
/* condition is false */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_mod_raw_cond_swap( X, Y, &m, 0 );
+ mbedtls_mpi_mod_raw_cond_swap(X, Y, &m, 0);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
- ASSERT_COMPARE( X, bytes, tmp_X, bytes );
- ASSERT_COMPARE( Y, bytes, tmp_Y, bytes );
+ ASSERT_COMPARE(X, bytes, tmp_X, bytes);
+ ASSERT_COMPARE(Y, bytes, tmp_Y, bytes);
/* condition is true */
- TEST_CF_SECRET( X, bytes );
- TEST_CF_SECRET( Y, bytes );
+ TEST_CF_SECRET(X, bytes);
+ TEST_CF_SECRET(Y, bytes);
- mbedtls_mpi_mod_raw_cond_swap( X, Y, &m, 1 );
+ mbedtls_mpi_mod_raw_cond_swap(X, Y, &m, 1);
- TEST_CF_PUBLIC( X, bytes );
- TEST_CF_PUBLIC( Y, bytes );
+ TEST_CF_PUBLIC(X, bytes);
+ TEST_CF_PUBLIC(Y, bytes);
/* Check if the given length is copied even it is smaller
than the length of the given MPIs. */
- if( copy_limbs < limbs )
- {
- ASSERT_COMPARE( X, copy_bytes, tmp_Y, copy_bytes );
- ASSERT_COMPARE( Y, copy_bytes, tmp_X, copy_bytes );
- TEST_ASSERT( memcmp( X, tmp_X, bytes ) != 0 );
- TEST_ASSERT( memcmp( X, tmp_Y, bytes ) != 0 );
- TEST_ASSERT( memcmp( Y, tmp_X, bytes ) != 0 );
- TEST_ASSERT( memcmp( Y, tmp_Y, bytes ) != 0 );
- }
- else
- {
- ASSERT_COMPARE( X, bytes, tmp_Y, bytes );
- ASSERT_COMPARE( Y, bytes, tmp_X, bytes );
+ if (copy_limbs < limbs) {
+ ASSERT_COMPARE(X, copy_bytes, tmp_Y, copy_bytes);
+ ASSERT_COMPARE(Y, copy_bytes, tmp_X, copy_bytes);
+ TEST_ASSERT(memcmp(X, tmp_X, bytes) != 0);
+ TEST_ASSERT(memcmp(X, tmp_Y, bytes) != 0);
+ TEST_ASSERT(memcmp(Y, tmp_X, bytes) != 0);
+ TEST_ASSERT(memcmp(Y, tmp_Y, bytes) != 0);
+ } else {
+ ASSERT_COMPARE(X, bytes, tmp_Y, bytes);
+ ASSERT_COMPARE(Y, bytes, tmp_X, bytes);
}
exit:
- mbedtls_free( tmp_X );
- mbedtls_free( tmp_Y );
- mbedtls_free( X );
- mbedtls_free( Y );
+ mbedtls_free(tmp_X);
+ mbedtls_free(tmp_Y);
+ mbedtls_free(X);
+ mbedtls_free(Y);
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( buff_m );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(buff_m);
}
/* END_CASE */
@@ -274,10 +268,10 @@
/* BEGIN MERGE SLOT 2 */
/* BEGIN_CASE */
-void mpi_mod_raw_sub( char * input_A,
- char * input_B,
- char * input_N,
- char * result )
+void mpi_mod_raw_sub(char *input_A,
+ char *input_B,
+ char *input_N,
+ char *result)
{
mbedtls_mpi_uint *A = NULL;
mbedtls_mpi_uint *B = NULL;
@@ -290,66 +284,65 @@
size_t limbs_res;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( mbedtls_test_read_mpi_core( &A, &limbs_A, input_A ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &B, &limbs_B, input_B ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &N, &limbs_N, input_N ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &res, &limbs_res, result ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&A, &limbs_A, input_A), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&B, &limbs_B, input_B), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&N, &limbs_N, input_N), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&res, &limbs_res, result), 0);
size_t limbs = limbs_N;
- size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
+ size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( limbs_A, limbs );
- TEST_EQUAL( limbs_B, limbs );
- TEST_EQUAL( limbs_res, limbs );
+ TEST_EQUAL(limbs_A, limbs);
+ TEST_EQUAL(limbs_B, limbs);
+ TEST_EQUAL(limbs_res, limbs);
- ASSERT_ALLOC( X, limbs );
+ ASSERT_ALLOC(X, limbs);
- TEST_EQUAL( mbedtls_mpi_mod_modulus_setup(
- &m, N, limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ), 0 );
+ TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
+ &m, N, limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
- mbedtls_mpi_mod_raw_sub( X, A, B, &m );
- ASSERT_COMPARE( X, bytes, res, bytes );
+ mbedtls_mpi_mod_raw_sub(X, A, B, &m);
+ ASSERT_COMPARE(X, bytes, res, bytes);
/* alias X to A */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_sub( X, X, B, &m );
- ASSERT_COMPARE( X, bytes, res, bytes );
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_sub(X, X, B, &m);
+ ASSERT_COMPARE(X, bytes, res, bytes);
/* alias X to B */
- memcpy( X, B, bytes );
- mbedtls_mpi_mod_raw_sub( X, A, X, &m );
- ASSERT_COMPARE( X, bytes, res, bytes );
+ memcpy(X, B, bytes);
+ mbedtls_mpi_mod_raw_sub(X, A, X, &m);
+ ASSERT_COMPARE(X, bytes, res, bytes);
/* A == B: alias A and B */
- if( memcmp( A, B, bytes ) == 0 )
- {
- mbedtls_mpi_mod_raw_sub( X, A, A, &m );
- ASSERT_COMPARE( X, bytes, res, bytes );
+ if (memcmp(A, B, bytes) == 0) {
+ mbedtls_mpi_mod_raw_sub(X, A, A, &m);
+ ASSERT_COMPARE(X, bytes, res, bytes);
/* X, A, B all aliased together */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_sub( X, X, X, &m );
- ASSERT_COMPARE( X, bytes, res, bytes );
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_sub(X, X, X, &m);
+ ASSERT_COMPARE(X, bytes, res, bytes);
}
exit:
- mbedtls_free( A );
- mbedtls_free( B );
- mbedtls_free( X );
- mbedtls_free( res );
+ mbedtls_free(A);
+ mbedtls_free(B);
+ mbedtls_free(X);
+ mbedtls_free(res);
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( N );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(N);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_raw_mul( char * input_A,
- char * input_B,
- char * input_N,
- char * result )
+void mpi_mod_raw_mul(char *input_A,
+ char *input_B,
+ char *input_N,
+ char *result)
{
mbedtls_mpi_uint *A = NULL;
mbedtls_mpi_uint *B = NULL;
@@ -363,80 +356,77 @@
size_t limbs_R;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( mbedtls_test_read_mpi_core( &A, &limbs_A, input_A ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &B, &limbs_B, input_B ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &N, &limbs_N, input_N ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi_core( &R, &limbs_R, result ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&A, &limbs_A, input_A), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&B, &limbs_B, input_B), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&N, &limbs_N, input_N), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi_core(&R, &limbs_R, result), 0);
const size_t limbs = limbs_N;
- const size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
+ const size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( limbs_A, limbs );
- TEST_EQUAL( limbs_B, limbs );
- TEST_EQUAL( limbs_R, limbs );
+ TEST_EQUAL(limbs_A, limbs);
+ TEST_EQUAL(limbs_B, limbs);
+ TEST_EQUAL(limbs_R, limbs);
- ASSERT_ALLOC( X, limbs );
+ ASSERT_ALLOC(X, limbs);
- TEST_EQUAL( mbedtls_mpi_mod_modulus_setup(
- &m, N, limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ), 0 );
+ TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
+ &m, N, limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
const size_t limbs_T = limbs * 2 + 1;
- ASSERT_ALLOC( T, limbs_T );
+ ASSERT_ALLOC(T, limbs_T);
- mbedtls_mpi_mod_raw_mul( X, A, B, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ mbedtls_mpi_mod_raw_mul(X, A, B, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
/* alias X to A */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_mul( X, X, B, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_mul(X, X, B, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
/* alias X to B */
- memcpy( X, B, bytes );
- mbedtls_mpi_mod_raw_mul( X, A, X, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ memcpy(X, B, bytes);
+ mbedtls_mpi_mod_raw_mul(X, A, X, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
/* A == B: alias A and B */
- if( memcmp( A, B, bytes ) == 0 )
- {
- mbedtls_mpi_mod_raw_mul( X, A, A, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ if (memcmp(A, B, bytes) == 0) {
+ mbedtls_mpi_mod_raw_mul(X, A, A, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
/* X, A, B all aliased together */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_mul( X, X, X, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_mul(X, X, X, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
}
-
/* A != B: test B * A */
- else
- {
- mbedtls_mpi_mod_raw_mul( X, B, A, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ else {
+ mbedtls_mpi_mod_raw_mul(X, B, A, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
/* B * A: alias X to A */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_mul( X, B, X, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_mul(X, B, X, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
/* B + A: alias X to B */
- memcpy( X, B, bytes );
- mbedtls_mpi_mod_raw_mul( X, X, A, &m, T );
- ASSERT_COMPARE( X, bytes, R, bytes );
+ memcpy(X, B, bytes);
+ mbedtls_mpi_mod_raw_mul(X, X, A, &m, T);
+ ASSERT_COMPARE(X, bytes, R, bytes);
}
exit:
- mbedtls_free( A );
- mbedtls_free( B );
- mbedtls_free( X );
- mbedtls_free( R );
- mbedtls_free( T );
+ mbedtls_free(A);
+ mbedtls_free(B);
+ mbedtls_free(X);
+ mbedtls_free(R);
+ mbedtls_free(T);
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( N );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(N);
}
/* END_CASE */
@@ -445,7 +435,7 @@
/* BEGIN MERGE SLOT 3 */
/* BEGIN_CASE */
-void mpi_mod_raw_inv_prime( char * input_N, char * input_A, char * input_X )
+void mpi_mod_raw_inv_prime(char *input_N, char *input_A, char *input_X)
{
mbedtls_mpi_uint *A = NULL;
mbedtls_mpi_uint *N = NULL;
@@ -458,24 +448,24 @@
/* Legacy MPIs for computing R2 */
mbedtls_mpi N_mpi; /* gets set up manually, aliasing N, so no need to free */
mbedtls_mpi R2_mpi;
- mbedtls_mpi_init( &R2_mpi );
+ mbedtls_mpi_init(&R2_mpi);
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &N_limbs, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
- ASSERT_ALLOC( Y, N_limbs );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &N_limbs, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
+ ASSERT_ALLOC(Y, N_limbs);
- TEST_EQUAL( A_limbs, N_limbs );
- TEST_EQUAL( X_limbs, N_limbs );
+ TEST_EQUAL(A_limbs, N_limbs);
+ TEST_EQUAL(X_limbs, N_limbs);
N_mpi.s = 1;
N_mpi.p = N;
N_mpi.n = N_limbs;
- TEST_EQUAL( 0, mbedtls_mpi_core_get_mont_r2_unsafe( &R2_mpi, &N_mpi ) );
- TEST_EQUAL( 0, mbedtls_mpi_grow( &R2_mpi, N_limbs ) );
+ TEST_EQUAL(0, mbedtls_mpi_core_get_mont_r2_unsafe(&R2_mpi, &N_mpi));
+ TEST_EQUAL(0, mbedtls_mpi_grow(&R2_mpi, N_limbs));
R2 = R2_mpi.p;
- size_t working_limbs = mbedtls_mpi_mod_raw_inv_prime_working_limbs( N_limbs );
+ size_t working_limbs = mbedtls_mpi_mod_raw_inv_prime_working_limbs(N_limbs);
/* No point exactly duplicating the code in mbedtls_mpi_mod_raw_inv_prime_working_limbs()
* to see if the output is correct, but we can check that it's in a
@@ -486,32 +476,32 @@
size_t min_expected_working_limbs = 1 + N_limbs * 5;
size_t max_expected_working_limbs = 1 + N_limbs * 68;
- TEST_LE_U( min_expected_working_limbs, working_limbs );
- TEST_LE_U( working_limbs, max_expected_working_limbs );
+ TEST_LE_U(min_expected_working_limbs, working_limbs);
+ TEST_LE_U(working_limbs, max_expected_working_limbs);
/* Should also be at least mbedtls_mpi_core_montmul_working_limbs() */
- TEST_LE_U( mbedtls_mpi_core_montmul_working_limbs( N_limbs ),
- working_limbs );
+ TEST_LE_U(mbedtls_mpi_core_montmul_working_limbs(N_limbs),
+ working_limbs);
- ASSERT_ALLOC( T, working_limbs );
+ ASSERT_ALLOC(T, working_limbs);
- mbedtls_mpi_mod_raw_inv_prime( Y, A, N, N_limbs, R2, T );
+ mbedtls_mpi_mod_raw_inv_prime(Y, A, N, N_limbs, R2, T);
- TEST_EQUAL( 0, memcmp( X, Y, N_limbs * sizeof( mbedtls_mpi_uint ) ) );
+ TEST_EQUAL(0, memcmp(X, Y, N_limbs * sizeof(mbedtls_mpi_uint)));
/* Check when output aliased to input */
- mbedtls_mpi_mod_raw_inv_prime( A, A, N, N_limbs, R2, T );
+ mbedtls_mpi_mod_raw_inv_prime(A, A, N, N_limbs, R2, T);
- TEST_EQUAL( 0, memcmp( X, A, N_limbs * sizeof( mbedtls_mpi_uint ) ) );
+ TEST_EQUAL(0, memcmp(X, A, N_limbs * sizeof(mbedtls_mpi_uint)));
exit:
- mbedtls_free( T );
- mbedtls_free( A );
- mbedtls_free( N );
- mbedtls_free( X );
- mbedtls_free( Y );
- mbedtls_mpi_free( &R2_mpi );
+ mbedtls_free(T);
+ mbedtls_free(A);
+ mbedtls_free(N);
+ mbedtls_free(X);
+ mbedtls_free(Y);
+ mbedtls_mpi_free(&R2_mpi);
// R2 doesn't need to be freed as it is only aliasing R2_mpi
// N_mpi doesn't need to be freed as it is only aliasing N
}
@@ -526,9 +516,9 @@
/* BEGIN MERGE SLOT 5 */
/* BEGIN_CASE */
-void mpi_mod_raw_add( char * input_N,
- char * input_A, char * input_B,
- char * input_S )
+void mpi_mod_raw_add(char *input_N,
+ char *input_A, char *input_B,
+ char *input_S)
{
mbedtls_mpi_uint *A = NULL;
mbedtls_mpi_uint *B = NULL;
@@ -538,145 +528,142 @@
size_t A_limbs, B_limbs, N_limbs, S_limbs;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &B, &B_limbs, input_B ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &N_limbs, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &S, &S_limbs, input_S ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&B, &B_limbs, input_B));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &N_limbs, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&S, &S_limbs, input_S));
/* Modulus gives the number of limbs; all inputs must have the same. */
size_t limbs = N_limbs;
- size_t bytes = limbs * sizeof( *A );
+ size_t bytes = limbs * sizeof(*A);
- TEST_EQUAL( A_limbs, limbs );
- TEST_EQUAL( B_limbs, limbs );
- TEST_EQUAL( S_limbs, limbs );
+ TEST_EQUAL(A_limbs, limbs);
+ TEST_EQUAL(B_limbs, limbs);
+ TEST_EQUAL(S_limbs, limbs);
- ASSERT_ALLOC( X, limbs );
+ ASSERT_ALLOC(X, limbs);
- TEST_EQUAL( mbedtls_mpi_mod_modulus_setup(
- &m, N, limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY
- ), 0 );
+ TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
+ &m, N, limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY
+ ), 0);
/* A + B => Correct result */
- mbedtls_mpi_mod_raw_add( X, A, B, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ mbedtls_mpi_mod_raw_add(X, A, B, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* A + B: alias X to A => Correct result */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_add( X, X, B, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_add(X, X, B, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* A + B: alias X to B => Correct result */
- memcpy( X, B, bytes );
- mbedtls_mpi_mod_raw_add( X, A, X, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, B, bytes);
+ mbedtls_mpi_mod_raw_add(X, A, X, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
- if ( memcmp(A, B, bytes ) == 0 )
- {
+ if (memcmp(A, B, bytes) == 0) {
/* A == B: alias A and B */
/* A + A => Correct result */
- mbedtls_mpi_mod_raw_add( X, A, A, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ mbedtls_mpi_mod_raw_add(X, A, A, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* A + A: X, A, B all aliased together => Correct result */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_add( X, X, X, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
- }
- else
- {
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_add(X, X, X, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
+ } else {
/* A != B: test B + A */
/* B + A => Correct result */
- mbedtls_mpi_mod_raw_add( X, B, A, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ mbedtls_mpi_mod_raw_add(X, B, A, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* B + A: alias X to A => Correct result */
- memcpy( X, A, bytes );
- mbedtls_mpi_mod_raw_add( X, B, X, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, A, bytes);
+ mbedtls_mpi_mod_raw_add(X, B, X, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
/* B + A: alias X to B => Correct result */
- memcpy( X, B, bytes );
- mbedtls_mpi_mod_raw_add( X, X, A, &m );
- ASSERT_COMPARE( X, bytes, S, bytes );
+ memcpy(X, B, bytes);
+ mbedtls_mpi_mod_raw_add(X, X, A, &m);
+ ASSERT_COMPARE(X, bytes, S, bytes);
}
exit:
- mbedtls_mpi_mod_modulus_free( &m );
+ mbedtls_mpi_mod_modulus_free(&m);
- mbedtls_free( A );
- mbedtls_free( B );
- mbedtls_free( S );
- mbedtls_free( N );
- mbedtls_free( X );
+ mbedtls_free(A);
+ mbedtls_free(B);
+ mbedtls_free(S);
+ mbedtls_free(N);
+ mbedtls_free(X);
}
/* END_CASE */
/* END MERGE SLOT 5 */
/* BEGIN MERGE SLOT 6 */
/* BEGIN_CASE */
-void mpi_mod_raw_canonical_to_modulus_rep( const char *input_N, int rep,
- const char *input_A,
- const char *input_X )
+void mpi_mod_raw_canonical_to_modulus_rep(const char *input_N, int rep,
+ const char *input_A,
+ const char *input_X)
{
mbedtls_mpi_mod_modulus N;
- mbedtls_mpi_mod_modulus_init( &N );
+ mbedtls_mpi_mod_modulus_init(&N);
mbedtls_mpi_uint *A = NULL;
size_t A_limbs = 0;;
mbedtls_mpi_uint *X = NULL;
size_t X_limbs = 0;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_modulus( &N, input_N, rep ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_modulus(&N, input_N, rep));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
- TEST_EQUAL( 0, mbedtls_mpi_mod_raw_canonical_to_modulus_rep( A, &N ) );
- ASSERT_COMPARE( A, A_limbs * sizeof( mbedtls_mpi_uint ),
- X, X_limbs * sizeof( mbedtls_mpi_uint ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_raw_canonical_to_modulus_rep(A, &N));
+ ASSERT_COMPARE(A, A_limbs * sizeof(mbedtls_mpi_uint),
+ X, X_limbs * sizeof(mbedtls_mpi_uint));
exit:
- mbedtls_test_mpi_mod_modulus_free_with_limbs( &N );
- mbedtls_free( A );
- mbedtls_free( X );
+ mbedtls_test_mpi_mod_modulus_free_with_limbs(&N);
+ mbedtls_free(A);
+ mbedtls_free(X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_raw_modulus_to_canonical_rep( const char *input_N, int rep,
- const char *input_A,
- const char *input_X )
+void mpi_mod_raw_modulus_to_canonical_rep(const char *input_N, int rep,
+ const char *input_A,
+ const char *input_X)
{
mbedtls_mpi_mod_modulus N;
- mbedtls_mpi_mod_modulus_init( &N );
+ mbedtls_mpi_mod_modulus_init(&N);
mbedtls_mpi_uint *A = NULL;
size_t A_limbs = 0;
mbedtls_mpi_uint *X = NULL;
size_t X_limbs = 0;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_modulus( &N, input_N, rep ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &A_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_modulus(&N, input_N, rep));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
- TEST_EQUAL( 0, mbedtls_mpi_mod_raw_modulus_to_canonical_rep( A, &N ) );
- ASSERT_COMPARE( A, A_limbs * sizeof( mbedtls_mpi_uint ),
- X, X_limbs * sizeof( mbedtls_mpi_uint ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_raw_modulus_to_canonical_rep(A, &N));
+ ASSERT_COMPARE(A, A_limbs * sizeof(mbedtls_mpi_uint),
+ X, X_limbs * sizeof(mbedtls_mpi_uint));
exit:
- mbedtls_test_mpi_mod_modulus_free_with_limbs( &N );
- mbedtls_free( A );
- mbedtls_free( X );
+ mbedtls_test_mpi_mod_modulus_free_with_limbs(&N);
+ mbedtls_free(A);
+ mbedtls_free(X);
}
/* END_CASE */
/* END MERGE SLOT 6 */
/* BEGIN MERGE SLOT 7 */
/* BEGIN_CASE */
-void mpi_mod_raw_to_mont_rep( char * input_N, char * input_A, char * input_X )
+void mpi_mod_raw_to_mont_rep(char *input_N, char *input_A, char *input_X)
{
mbedtls_mpi_uint *N = NULL;
mbedtls_mpi_uint *A = NULL;
@@ -686,12 +673,12 @@
size_t n_limbs, a_limbs, x_limbs;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
/* Read inputs */
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &a_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &x_limbs, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &n_limbs, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &a_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &x_limbs, input_X));
/* Number to convert must have same number of limbs as modulus */
TEST_EQUAL(a_limbs, n_limbs);
@@ -703,45 +690,45 @@
size_t limbs = n_limbs;
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_modulus_setup(&m, N, n_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY));
/* 1. Test low-level function first */
/* It has separate output, and requires temporary working storage */
- size_t temp_limbs = mbedtls_mpi_core_montmul_working_limbs( limbs );
- ASSERT_ALLOC( T, temp_limbs );
- ASSERT_ALLOC( R, limbs );
- mbedtls_mpi_core_to_mont_rep( R, A, N, n_limbs,
- m.rep.mont.mm, m.rep.mont.rr, T );
+ size_t temp_limbs = mbedtls_mpi_core_montmul_working_limbs(limbs);
+ ASSERT_ALLOC(T, temp_limbs);
+ ASSERT_ALLOC(R, limbs);
+ mbedtls_mpi_core_to_mont_rep(R, A, N, n_limbs,
+ m.rep.mont.mm, m.rep.mont.rr, T);
/* Test that the low-level function gives the required value */
- ASSERT_COMPARE( R, bytes, X, bytes );
+ ASSERT_COMPARE(R, bytes, X, bytes);
/* Test when output is aliased to input */
- memcpy( R, A, bytes );
- mbedtls_mpi_core_to_mont_rep( R, R, N, n_limbs,
- m.rep.mont.mm, m.rep.mont.rr, T );
- ASSERT_COMPARE( R, bytes, X, bytes );
+ memcpy(R, A, bytes);
+ mbedtls_mpi_core_to_mont_rep(R, R, N, n_limbs,
+ m.rep.mont.mm, m.rep.mont.rr, T);
+ ASSERT_COMPARE(R, bytes, X, bytes);
/* 2. Test higher-level cannonical to Montgomery conversion */
- TEST_EQUAL(0, mbedtls_mpi_mod_raw_to_mont_rep( A, &m ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_raw_to_mont_rep(A, &m));
/* The result matches expected value */
- ASSERT_COMPARE( A, bytes, X, bytes );
+ ASSERT_COMPARE(A, bytes, X, bytes);
exit:
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( T );
- mbedtls_free( N );
- mbedtls_free( A );
- mbedtls_free( R );
- mbedtls_free( X );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(T);
+ mbedtls_free(N);
+ mbedtls_free(A);
+ mbedtls_free(R);
+ mbedtls_free(X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_raw_from_mont_rep( char * input_N, char * input_A, char * input_X )
+void mpi_mod_raw_from_mont_rep(char *input_N, char *input_A, char *input_X)
{
mbedtls_mpi_uint *N = NULL;
mbedtls_mpi_uint *A = NULL;
@@ -751,12 +738,12 @@
size_t n_limbs, a_limbs, x_limbs;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
/* Read inputs */
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &a_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &x_limbs, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &n_limbs, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &a_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &x_limbs, input_X));
/* Number to convert must have same number of limbs as modulus */
TEST_EQUAL(a_limbs, n_limbs);
@@ -768,45 +755,45 @@
size_t limbs = n_limbs;
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
- TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_modulus_setup(&m, N, n_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY));
/* 1. Test low-level function first */
/* It has separate output, and requires temporary working storage */
- size_t temp_limbs = mbedtls_mpi_core_montmul_working_limbs( limbs );
- ASSERT_ALLOC( T, temp_limbs );
- ASSERT_ALLOC( R, limbs );
- mbedtls_mpi_core_from_mont_rep( R, A, N, n_limbs,
- m.rep.mont.mm, T );
+ size_t temp_limbs = mbedtls_mpi_core_montmul_working_limbs(limbs);
+ ASSERT_ALLOC(T, temp_limbs);
+ ASSERT_ALLOC(R, limbs);
+ mbedtls_mpi_core_from_mont_rep(R, A, N, n_limbs,
+ m.rep.mont.mm, T);
/* Test that the low-level function gives the required value */
- ASSERT_COMPARE( R, bytes, X, bytes );
+ ASSERT_COMPARE(R, bytes, X, bytes);
/* Test when output is aliased to input */
- memcpy( R, A, bytes );
- mbedtls_mpi_core_from_mont_rep( R, R, N, n_limbs,
- m.rep.mont.mm, T );
- ASSERT_COMPARE( R, bytes, X, bytes );
+ memcpy(R, A, bytes);
+ mbedtls_mpi_core_from_mont_rep(R, R, N, n_limbs,
+ m.rep.mont.mm, T);
+ ASSERT_COMPARE(R, bytes, X, bytes);
/* 2. Test higher-level Montgomery to cannonical conversion */
- TEST_EQUAL(0, mbedtls_mpi_mod_raw_from_mont_rep( A, &m ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_raw_from_mont_rep(A, &m));
/* The result matches expected value */
- ASSERT_COMPARE( A, bytes, X, bytes );
+ ASSERT_COMPARE(A, bytes, X, bytes);
exit:
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( T );
- mbedtls_free( N );
- mbedtls_free( A );
- mbedtls_free( R );
- mbedtls_free( X );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(T);
+ mbedtls_free(N);
+ mbedtls_free(A);
+ mbedtls_free(R);
+ mbedtls_free(X);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_raw_neg( char * input_N, char * input_A, char * input_X )
+void mpi_mod_raw_neg(char *input_N, char *input_A, char *input_X)
{
mbedtls_mpi_uint *N = NULL;
mbedtls_mpi_uint *A = NULL;
@@ -816,45 +803,45 @@
size_t n_limbs, a_limbs, x_limbs, bytes;
mbedtls_mpi_mod_modulus m;
- mbedtls_mpi_mod_modulus_init( &m );
+ mbedtls_mpi_mod_modulus_init(&m);
/* Read inputs */
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &A, &a_limbs, input_A ) );
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &x_limbs, input_X ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &n_limbs, input_N));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &a_limbs, input_A));
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &x_limbs, input_X));
- TEST_EQUAL( a_limbs, n_limbs );
- TEST_EQUAL( x_limbs, n_limbs );
- bytes = n_limbs * sizeof( mbedtls_mpi_uint );
+ TEST_EQUAL(a_limbs, n_limbs);
+ TEST_EQUAL(x_limbs, n_limbs);
+ bytes = n_limbs * sizeof(mbedtls_mpi_uint);
- ASSERT_ALLOC( R, n_limbs );
- ASSERT_ALLOC( Z, n_limbs );
+ ASSERT_ALLOC(R, n_limbs);
+ ASSERT_ALLOC(Z, n_limbs);
- TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs,
- MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );
+ TEST_EQUAL(0, mbedtls_mpi_mod_modulus_setup(&m, N, n_limbs,
+ MBEDTLS_MPI_MOD_REP_MONTGOMERY));
/* Neg( A == 0 ) => Zero result */
- mbedtls_mpi_mod_raw_neg( R, Z, &m );
- ASSERT_COMPARE( R, bytes, Z, bytes );
+ mbedtls_mpi_mod_raw_neg(R, Z, &m);
+ ASSERT_COMPARE(R, bytes, Z, bytes);
/* Neg( A == N ) => Zero result */
- mbedtls_mpi_mod_raw_neg( R, N, &m );
- ASSERT_COMPARE( R, bytes, Z, bytes );
+ mbedtls_mpi_mod_raw_neg(R, N, &m);
+ ASSERT_COMPARE(R, bytes, Z, bytes);
/* Neg( A ) => Correct result */
- mbedtls_mpi_mod_raw_neg( R, A, &m );
- ASSERT_COMPARE( R, bytes, X, bytes );
+ mbedtls_mpi_mod_raw_neg(R, A, &m);
+ ASSERT_COMPARE(R, bytes, X, bytes);
/* Neg( A ): alias A to R => Correct result */
- mbedtls_mpi_mod_raw_neg( A, A, &m );
- ASSERT_COMPARE( A, bytes, X, bytes );
+ mbedtls_mpi_mod_raw_neg(A, A, &m);
+ ASSERT_COMPARE(A, bytes, X, bytes);
exit:
- mbedtls_mpi_mod_modulus_free( &m );
- mbedtls_free( N );
- mbedtls_free( A );
- mbedtls_free( X );
- mbedtls_free( R );
- mbedtls_free( Z );
+ mbedtls_mpi_mod_modulus_free(&m);
+ mbedtls_free(N);
+ mbedtls_free(A);
+ mbedtls_free(X);
+ mbedtls_free(R);
+ mbedtls_free(Z);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_bignum_random.function b/tests/suites/test_suite_bignum_random.function
index 4709148..e4db3d7 100644
--- a/tests/suites/test_suite_bignum_random.function
+++ b/tests/suites/test_suite_bignum_random.function
@@ -44,19 +44,20 @@
#include "constant_time_internal.h"
/* This test suite only manipulates non-negative bignums. */
-static int sign_is_valid( const mbedtls_mpi *X )
+static int sign_is_valid(const mbedtls_mpi *X)
{
- return( X->s == 1 );
+ return X->s == 1;
}
/* A common initializer for test functions that should generate the same
* sequences for reproducibility and good coverage. */
const mbedtls_test_rnd_pseudo_info rnd_pseudo_seed = {
/* 16-word key */
- {'T', 'h', 'i', 's', ' ', 'i', 's', ' ',
- 'a', ' ', 's', 'e', 'e', 'd', '!', 0},
+ { 'T', 'h', 'i', 's', ' ', 'i', 's', ' ',
+ 'a', ' ', 's', 'e', 'e', 'd', '!', 0 },
/* 2-word initial state, should be zero */
- 0, 0};
+ 0, 0
+};
/* Test whether bytes represents (in big-endian base 256) a number b that
* is significantly above a power of 2. That is, b must not have a long run
@@ -69,37 +70,39 @@
* number is above some threshold A. The threshold value is heuristic and
* based on the needs of mpi_random_many().
*/
-static int is_significantly_above_a_power_of_2( data_t *bytes )
+static int is_significantly_above_a_power_of_2(data_t *bytes)
{
const uint8_t *p = bytes->x;
size_t len = bytes->len;
unsigned x;
/* Skip leading null bytes */
- while( len > 0 && p[0] == 0 )
- {
+ while (len > 0 && p[0] == 0) {
++p;
--len;
}
/* 0 is not significantly above a power of 2 */
- if( len == 0 )
- return( 0 );
+ if (len == 0) {
+ return 0;
+ }
/* Extract the (up to) 2 most significant bytes */
- if( len == 1 )
+ if (len == 1) {
x = p[0];
- else
- x = ( p[0] << 8 ) | p[1];
+ } else {
+ x = (p[0] << 8) | p[1];
+ }
/* Shift the most significant bit of x to position 8 and mask it out */
- while( ( x & 0xfe00 ) != 0 )
+ while ((x & 0xfe00) != 0) {
x >>= 1;
+ }
x &= 0x00ff;
/* At this point, x = floor((b - 2^n) / 2^(n-8)). b is significantly above
* a power of 2 iff x is significantly above 0 compared to 2^8.
* Testing x >= 2^4 amounts to picking A = 1/16 in the function
* description above. */
- return( x >= 0x10 );
+ return x >= 0x10;
}
/* END_HEADER */
@@ -110,7 +113,7 @@
*/
/* BEGIN_CASE */
-void mpi_core_random_basic( int min, char *bound_bytes, int expected_ret )
+void mpi_core_random_basic(int min, char *bound_bytes, int expected_ret)
{
/* Same RNG as in mpi_random_values */
mbedtls_test_rnd_pseudo_info rnd = rnd_pseudo_seed;
@@ -119,151 +122,148 @@
mbedtls_mpi_uint *upper_bound = NULL;
mbedtls_mpi_uint *result = NULL;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &upper_bound, &limbs,
- bound_bytes ) );
- ASSERT_ALLOC( lower_bound, limbs );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&upper_bound, &limbs,
+ bound_bytes));
+ ASSERT_ALLOC(lower_bound, limbs);
lower_bound[0] = min;
- ASSERT_ALLOC( result, limbs );
+ ASSERT_ALLOC(result, limbs);
- TEST_EQUAL( expected_ret,
- mbedtls_mpi_core_random( result, min, upper_bound, limbs,
- mbedtls_test_rnd_pseudo_rand, &rnd ) );
+ TEST_EQUAL(expected_ret,
+ mbedtls_mpi_core_random(result, min, upper_bound, limbs,
+ mbedtls_test_rnd_pseudo_rand, &rnd));
- if( expected_ret == 0 )
- {
- TEST_EQUAL( 0, mbedtls_mpi_core_lt_ct( result, lower_bound, limbs ) );
- TEST_EQUAL( 1, mbedtls_mpi_core_lt_ct( result, upper_bound, limbs ) );
+ if (expected_ret == 0) {
+ TEST_EQUAL(0, mbedtls_mpi_core_lt_ct(result, lower_bound, limbs));
+ TEST_EQUAL(1, mbedtls_mpi_core_lt_ct(result, upper_bound, limbs));
}
exit:
- mbedtls_free( lower_bound );
- mbedtls_free( upper_bound );
- mbedtls_free( result );
+ mbedtls_free(lower_bound);
+ mbedtls_free(upper_bound);
+ mbedtls_free(result);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_legacy_random_values( int min, char *max_hex )
+void mpi_legacy_random_values(int min, char *max_hex)
{
/* Same RNG as in mpi_core_random_basic */
mbedtls_test_rnd_pseudo_info rnd_core = rnd_pseudo_seed;
mbedtls_test_rnd_pseudo_info rnd_legacy;
- memcpy( &rnd_legacy, &rnd_core, sizeof( rnd_core ) );
+ memcpy(&rnd_legacy, &rnd_core, sizeof(rnd_core));
mbedtls_mpi max_legacy;
- mbedtls_mpi_init( &max_legacy );
+ mbedtls_mpi_init(&max_legacy);
mbedtls_mpi_uint *R_core = NULL;
mbedtls_mpi R_legacy;
- mbedtls_mpi_init( &R_legacy );
+ mbedtls_mpi_init(&R_legacy);
- TEST_EQUAL( 0, mbedtls_test_read_mpi( &max_legacy, max_hex ) );
+ TEST_EQUAL(0, mbedtls_test_read_mpi(&max_legacy, max_hex));
size_t limbs = max_legacy.n;
- ASSERT_ALLOC( R_core, limbs );
+ ASSERT_ALLOC(R_core, limbs);
/* Call the legacy function and the core function with the same random
* stream. */
- int core_ret = mbedtls_mpi_core_random( R_core, min, max_legacy.p, limbs,
- mbedtls_test_rnd_pseudo_rand,
- &rnd_core );
- int legacy_ret = mbedtls_mpi_random( &R_legacy, min, &max_legacy,
- mbedtls_test_rnd_pseudo_rand,
- &rnd_legacy );
+ int core_ret = mbedtls_mpi_core_random(R_core, min, max_legacy.p, limbs,
+ mbedtls_test_rnd_pseudo_rand,
+ &rnd_core);
+ int legacy_ret = mbedtls_mpi_random(&R_legacy, min, &max_legacy,
+ mbedtls_test_rnd_pseudo_rand,
+ &rnd_legacy);
/* They must return the same status, and, on success, output the
* same number, with the same limb count. */
- TEST_EQUAL( core_ret, legacy_ret );
- if( core_ret == 0 )
- {
- ASSERT_COMPARE( R_core, limbs * ciL,
- R_legacy.p, R_legacy.n * ciL );
+ TEST_EQUAL(core_ret, legacy_ret);
+ if (core_ret == 0) {
+ ASSERT_COMPARE(R_core, limbs * ciL,
+ R_legacy.p, R_legacy.n * ciL);
}
/* Also check that they have consumed the RNG in the same way. */
/* This may theoretically fail on rare platforms with padding in
* the structure! If this is a problem in practice, change to a
* field-by-field comparison. */
- ASSERT_COMPARE( &rnd_core, sizeof( rnd_core ),
- &rnd_legacy, sizeof( rnd_legacy ) );
+ ASSERT_COMPARE(&rnd_core, sizeof(rnd_core),
+ &rnd_legacy, sizeof(rnd_legacy));
exit:
- mbedtls_mpi_free( &max_legacy );
- mbedtls_free( R_core );
- mbedtls_mpi_free( &R_legacy );
+ mbedtls_mpi_free(&max_legacy);
+ mbedtls_free(R_core);
+ mbedtls_mpi_free(&R_legacy);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_random_values( int min, char *max_hex, int rep )
+void mpi_mod_random_values(int min, char *max_hex, int rep)
{
/* Same RNG as in mpi_core_random_basic */
mbedtls_test_rnd_pseudo_info rnd_core = rnd_pseudo_seed;
mbedtls_test_rnd_pseudo_info rnd_mod_raw;
- memcpy( &rnd_mod_raw, &rnd_core, sizeof( rnd_core ) );
+ memcpy(&rnd_mod_raw, &rnd_core, sizeof(rnd_core));
mbedtls_test_rnd_pseudo_info rnd_mod;
- memcpy( &rnd_mod, &rnd_core, sizeof( rnd_core ) );
+ memcpy(&rnd_mod, &rnd_core, sizeof(rnd_core));
mbedtls_mpi_uint *R_core = NULL;
mbedtls_mpi_uint *R_mod_raw = NULL;
mbedtls_mpi_uint *R_mod_digits = NULL;
mbedtls_mpi_mod_residue R_mod;
mbedtls_mpi_mod_modulus N;
- mbedtls_mpi_mod_modulus_init( &N );
+ mbedtls_mpi_mod_modulus_init(&N);
- TEST_EQUAL( mbedtls_test_read_mpi_modulus( &N, max_hex, rep ), 0 );
- ASSERT_ALLOC( R_core, N.limbs );
- ASSERT_ALLOC( R_mod_raw, N.limbs );
- ASSERT_ALLOC( R_mod_digits, N.limbs );
- TEST_EQUAL( mbedtls_mpi_mod_residue_setup( &R_mod, &N,
- R_mod_digits, N.limbs ),
- 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_modulus(&N, max_hex, rep), 0);
+ ASSERT_ALLOC(R_core, N.limbs);
+ ASSERT_ALLOC(R_mod_raw, N.limbs);
+ ASSERT_ALLOC(R_mod_digits, N.limbs);
+ TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&R_mod, &N,
+ R_mod_digits, N.limbs),
+ 0);
/* Call the core and mod random() functions with the same random stream. */
- int core_ret = mbedtls_mpi_core_random( R_core,
- min, N.p, N.limbs,
- mbedtls_test_rnd_pseudo_rand,
- &rnd_core );
- int mod_raw_ret = mbedtls_mpi_mod_raw_random( R_mod_raw,
- min, &N,
- mbedtls_test_rnd_pseudo_rand,
- &rnd_mod_raw );
- int mod_ret = mbedtls_mpi_mod_random( &R_mod,
- min, &N,
- mbedtls_test_rnd_pseudo_rand,
- &rnd_mod );
+ int core_ret = mbedtls_mpi_core_random(R_core,
+ min, N.p, N.limbs,
+ mbedtls_test_rnd_pseudo_rand,
+ &rnd_core);
+ int mod_raw_ret = mbedtls_mpi_mod_raw_random(R_mod_raw,
+ min, &N,
+ mbedtls_test_rnd_pseudo_rand,
+ &rnd_mod_raw);
+ int mod_ret = mbedtls_mpi_mod_random(&R_mod,
+ min, &N,
+ mbedtls_test_rnd_pseudo_rand,
+ &rnd_mod);
/* They must return the same status, and, on success, output the
* same number, with the same limb count. */
- TEST_EQUAL( core_ret, mod_raw_ret );
- TEST_EQUAL( core_ret, mod_ret );
- if( core_ret == 0 )
- {
- TEST_EQUAL( mbedtls_mpi_mod_raw_modulus_to_canonical_rep( R_mod_raw, &N ),
- 0 );
- ASSERT_COMPARE( R_core, N.limbs * ciL,
- R_mod_raw, N.limbs * ciL );
- TEST_EQUAL( mbedtls_mpi_mod_raw_modulus_to_canonical_rep( R_mod_digits, &N ),
- 0 );
- ASSERT_COMPARE( R_core, N.limbs * ciL,
- R_mod_digits, N.limbs * ciL );
+ TEST_EQUAL(core_ret, mod_raw_ret);
+ TEST_EQUAL(core_ret, mod_ret);
+ if (core_ret == 0) {
+ TEST_EQUAL(mbedtls_mpi_mod_raw_modulus_to_canonical_rep(R_mod_raw, &N),
+ 0);
+ ASSERT_COMPARE(R_core, N.limbs * ciL,
+ R_mod_raw, N.limbs * ciL);
+ TEST_EQUAL(mbedtls_mpi_mod_raw_modulus_to_canonical_rep(R_mod_digits, &N),
+ 0);
+ ASSERT_COMPARE(R_core, N.limbs * ciL,
+ R_mod_digits, N.limbs * ciL);
}
/* Also check that they have consumed the RNG in the same way. */
/* This may theoretically fail on rare platforms with padding in
* the structure! If this is a problem in practice, change to a
* field-by-field comparison. */
- ASSERT_COMPARE( &rnd_core, sizeof( rnd_core ),
- &rnd_mod_raw, sizeof( rnd_mod_raw ) );
- ASSERT_COMPARE( &rnd_core, sizeof( rnd_core ),
- &rnd_mod, sizeof( rnd_mod ) );
+ ASSERT_COMPARE(&rnd_core, sizeof(rnd_core),
+ &rnd_mod_raw, sizeof(rnd_mod_raw));
+ ASSERT_COMPARE(&rnd_core, sizeof(rnd_core),
+ &rnd_mod, sizeof(rnd_mod));
exit:
- mbedtls_test_mpi_mod_modulus_free_with_limbs( &N );
- mbedtls_free( R_core );
- mbedtls_free( R_mod_raw );
- mbedtls_free( R_mod_digits );
+ mbedtls_test_mpi_mod_modulus_free_with_limbs(&N);
+ mbedtls_free(R_core);
+ mbedtls_free(R_mod_raw);
+ mbedtls_free(R_mod_digits);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_random_many( int min, char *bound_hex, int iterations )
+void mpi_random_many(int min, char *bound_hex, int iterations)
{
/* Generate numbers in the range 1..bound-1. Do it iterations times.
* This function assumes that the value of bound is at least 2 and
@@ -271,7 +271,7 @@
* effectively never occurs.
*/
- data_t bound_bytes = {NULL, 0};
+ data_t bound_bytes = { NULL, 0 };
mbedtls_mpi_uint *upper_bound = NULL;
size_t limbs;
size_t n_bits;
@@ -285,79 +285,68 @@
int full_stats;
size_t i;
- TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &upper_bound, &limbs,
- bound_hex ) );
- ASSERT_ALLOC( result, limbs );
+ TEST_EQUAL(0, mbedtls_test_read_mpi_core(&upper_bound, &limbs,
+ bound_hex));
+ ASSERT_ALLOC(result, limbs);
- n_bits = mbedtls_mpi_core_bitlen( upper_bound, limbs );
+ n_bits = mbedtls_mpi_core_bitlen(upper_bound, limbs);
/* Consider a bound "small" if it's less than 2^5. This value is chosen
* to be small enough that the probability of missing one value is
* negligible given the number of iterations. It must be less than
* 256 because some of the code below assumes that "small" values
* fit in a byte. */
- if( n_bits <= 5 )
- {
+ if (n_bits <= 5) {
full_stats = 1;
stats_len = (uint8_t) upper_bound[0];
- }
- else
- {
+ } else {
full_stats = 0;
stats_len = n_bits;
}
- ASSERT_ALLOC( stats, stats_len );
+ ASSERT_ALLOC(stats, stats_len);
- for( i = 0; i < (size_t) iterations; i++ )
- {
- mbedtls_test_set_step( i );
- TEST_EQUAL( 0, mbedtls_mpi_core_random( result,
- min, upper_bound, limbs,
- mbedtls_test_rnd_std_rand, NULL ) );
+ for (i = 0; i < (size_t) iterations; i++) {
+ mbedtls_test_set_step(i);
+ TEST_EQUAL(0, mbedtls_mpi_core_random(result,
+ min, upper_bound, limbs,
+ mbedtls_test_rnd_std_rand, NULL));
/* Temporarily use a legacy MPI for analysis, because the
* necessary auxiliary functions don't exist yet in core. */
- mbedtls_mpi B = {1, limbs, upper_bound};
- mbedtls_mpi R = {1, limbs, result};
+ mbedtls_mpi B = { 1, limbs, upper_bound };
+ mbedtls_mpi R = { 1, limbs, result };
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R, &B ) < 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_int( &R, min ) >= 0 );
- if( full_stats )
- {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R, &B) < 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&R, min) >= 0);
+ if (full_stats) {
uint8_t value;
- TEST_EQUAL( 0, mbedtls_mpi_write_binary( &R, &value, 1 ) );
- TEST_ASSERT( value < stats_len );
+ TEST_EQUAL(0, mbedtls_mpi_write_binary(&R, &value, 1));
+ TEST_ASSERT(value < stats_len);
++stats[value];
- }
- else
- {
- for( b = 0; b < n_bits; b++ )
- stats[b] += mbedtls_mpi_get_bit( &R, b );
+ } else {
+ for (b = 0; b < n_bits; b++) {
+ stats[b] += mbedtls_mpi_get_bit(&R, b);
+ }
}
}
- if( full_stats )
- {
- for( b = min; b < stats_len; b++ )
- {
- mbedtls_test_set_step( 1000000 + b );
+ if (full_stats) {
+ for (b = min; b < stats_len; b++) {
+ mbedtls_test_set_step(1000000 + b);
/* Assert that each value has been reached at least once.
* This is almost guaranteed if the iteration count is large
* enough. This is a very crude way of checking the distribution.
*/
- TEST_ASSERT( stats[b] > 0 );
+ TEST_ASSERT(stats[b] > 0);
}
- }
- else
- {
- bound_bytes.len = limbs * sizeof( mbedtls_mpi_uint );
- ASSERT_ALLOC( bound_bytes.x, bound_bytes.len );
- mbedtls_mpi_core_write_be( upper_bound, limbs,
- bound_bytes.x, bound_bytes.len );
+ } else {
+ bound_bytes.len = limbs * sizeof(mbedtls_mpi_uint);
+ ASSERT_ALLOC(bound_bytes.x, bound_bytes.len);
+ mbedtls_mpi_core_write_be(upper_bound, limbs,
+ bound_bytes.x, bound_bytes.len);
int statistically_safe_all_the_way =
- is_significantly_above_a_power_of_2( &bound_bytes );
- for( b = 0; b < n_bits; b++ )
- {
- mbedtls_test_set_step( 1000000 + b );
+ is_significantly_above_a_power_of_2(&bound_bytes);
+ for (b = 0; b < n_bits; b++) {
+ mbedtls_test_set_step(1000000 + b);
/* Assert that each bit has been set in at least one result and
* clear in at least one result. Provided that iterations is not
* too small, it would be extremely unlikely for this not to be
@@ -366,131 +355,127 @@
* As an exception, the top bit may legitimately never be set
* if bound is a power of 2 or only slightly above.
*/
- if( statistically_safe_all_the_way || b != n_bits - 1 )
- {
- TEST_ASSERT( stats[b] > 0 );
+ if (statistically_safe_all_the_way || b != n_bits - 1) {
+ TEST_ASSERT(stats[b] > 0);
}
- TEST_ASSERT( stats[b] < (size_t) iterations );
+ TEST_ASSERT(stats[b] < (size_t) iterations);
}
}
exit:
- mbedtls_free( bound_bytes.x );
- mbedtls_free( upper_bound );
- mbedtls_free( result );
- mbedtls_free( stats );
+ mbedtls_free(bound_bytes.x);
+ mbedtls_free(upper_bound);
+ mbedtls_free(result);
+ mbedtls_free(stats);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_random_sizes( int min, data_t *bound_bytes, int nlimbs, int before )
+void mpi_random_sizes(int min, data_t *bound_bytes, int nlimbs, int before)
{
mbedtls_mpi upper_bound;
mbedtls_mpi result;
- mbedtls_mpi_init( &upper_bound );
- mbedtls_mpi_init( &result );
+ mbedtls_mpi_init(&upper_bound);
+ mbedtls_mpi_init(&result);
- if( before != 0 )
- {
+ if (before != 0) {
/* Set result to sign(before) * 2^(|before|-1) */
- TEST_ASSERT( mbedtls_mpi_lset( &result, before > 0 ? 1 : -1 ) == 0 );
- if( before < 0 )
- before = - before;
- TEST_ASSERT( mbedtls_mpi_shift_l( &result, before - 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_lset(&result, before > 0 ? 1 : -1) == 0);
+ if (before < 0) {
+ before = -before;
+ }
+ TEST_ASSERT(mbedtls_mpi_shift_l(&result, before - 1) == 0);
}
- TEST_EQUAL( 0, mbedtls_mpi_grow( &result, nlimbs ) );
- TEST_EQUAL( 0, mbedtls_mpi_read_binary( &upper_bound,
- bound_bytes->x, bound_bytes->len ) );
- TEST_EQUAL( 0, mbedtls_mpi_random( &result, min, &upper_bound,
- mbedtls_test_rnd_std_rand, NULL ) );
- TEST_ASSERT( sign_is_valid( &result ) );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &result, &upper_bound ) < 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_int( &result, min ) >= 0 );
+ TEST_EQUAL(0, mbedtls_mpi_grow(&result, nlimbs));
+ TEST_EQUAL(0, mbedtls_mpi_read_binary(&upper_bound,
+ bound_bytes->x, bound_bytes->len));
+ TEST_EQUAL(0, mbedtls_mpi_random(&result, min, &upper_bound,
+ mbedtls_test_rnd_std_rand, NULL));
+ TEST_ASSERT(sign_is_valid(&result));
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&result, &upper_bound) < 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&result, min) >= 0);
exit:
- mbedtls_mpi_free( &upper_bound );
- mbedtls_mpi_free( &result );
+ mbedtls_mpi_free(&upper_bound);
+ mbedtls_mpi_free(&result);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_mod_random_validation( int min, char *bound_hex,
- int result_limbs_delta,
- int expected_ret )
+void mpi_mod_random_validation(int min, char *bound_hex,
+ int result_limbs_delta,
+ int expected_ret)
{
mbedtls_mpi_uint *result_digits = NULL;
mbedtls_mpi_mod_modulus N;
- mbedtls_mpi_mod_modulus_init( &N );
+ mbedtls_mpi_mod_modulus_init(&N);
- TEST_EQUAL( mbedtls_test_read_mpi_modulus( &N, bound_hex,
- MBEDTLS_MPI_MOD_REP_OPT_RED ),
- 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi_modulus(&N, bound_hex,
+ MBEDTLS_MPI_MOD_REP_OPT_RED),
+ 0);
size_t result_limbs = N.limbs + result_limbs_delta;
- ASSERT_ALLOC( result_digits, result_limbs );
+ ASSERT_ALLOC(result_digits, result_limbs);
/* Build a reside that might not match the modulus, to test that
* the library function rejects that as expected. */
- mbedtls_mpi_mod_residue result = {result_digits, result_limbs};
+ mbedtls_mpi_mod_residue result = { result_digits, result_limbs };
- TEST_EQUAL( mbedtls_mpi_mod_random( &result, min, &N,
- mbedtls_test_rnd_std_rand, NULL ),
- expected_ret );
- if( expected_ret == 0 )
- {
+ TEST_EQUAL(mbedtls_mpi_mod_random(&result, min, &N,
+ mbedtls_test_rnd_std_rand, NULL),
+ expected_ret);
+ if (expected_ret == 0) {
/* Success should only be expected when the result has the same
* size as the modulus, otherwise it's a mistake in the test data. */
- TEST_EQUAL( result_limbs, N.limbs );
+ TEST_EQUAL(result_limbs, N.limbs);
/* Sanity check: check that the result is in range */
- TEST_EQUAL( mbedtls_mpi_core_lt_ct( result_digits, N.p, N.limbs ),
- 1 );
+ TEST_EQUAL(mbedtls_mpi_core_lt_ct(result_digits, N.p, N.limbs),
+ 1);
/* Check result >= min (changes result) */
- TEST_EQUAL( mbedtls_mpi_core_sub_int( result_digits, result_digits, min,
- result_limbs ),
- 0 );
+ TEST_EQUAL(mbedtls_mpi_core_sub_int(result_digits, result_digits, min,
+ result_limbs),
+ 0);
}
/* When the result has the right number of limbs, also test mod_raw
* (for which this is an unchecked precondition). */
- if( result_limbs_delta == 0 )
- {
- TEST_EQUAL( mbedtls_mpi_mod_raw_random( result_digits, min, &N,
- mbedtls_test_rnd_std_rand, NULL ),
- expected_ret );
- if( expected_ret == 0 )
- {
- TEST_EQUAL( mbedtls_mpi_core_lt_ct( result_digits, N.p, N.limbs ),
- 1 );
- TEST_EQUAL( mbedtls_mpi_core_sub_int( result_digits, result.p, min,
- result_limbs ),
- 0 );
+ if (result_limbs_delta == 0) {
+ TEST_EQUAL(mbedtls_mpi_mod_raw_random(result_digits, min, &N,
+ mbedtls_test_rnd_std_rand, NULL),
+ expected_ret);
+ if (expected_ret == 0) {
+ TEST_EQUAL(mbedtls_mpi_core_lt_ct(result_digits, N.p, N.limbs),
+ 1);
+ TEST_EQUAL(mbedtls_mpi_core_sub_int(result_digits, result.p, min,
+ result_limbs),
+ 0);
}
}
exit:
- mbedtls_test_mpi_mod_modulus_free_with_limbs( &N );
- mbedtls_free( result_digits );
+ mbedtls_test_mpi_mod_modulus_free_with_limbs(&N);
+ mbedtls_free(result_digits);
}
/* END_CASE */
/* BEGIN_CASE */
-void mpi_random_fail( int min, data_t *bound_bytes, int expected_ret )
+void mpi_random_fail(int min, data_t *bound_bytes, int expected_ret)
{
mbedtls_mpi upper_bound;
mbedtls_mpi result;
int actual_ret;
- mbedtls_mpi_init( &upper_bound );
- mbedtls_mpi_init( &result );
+ mbedtls_mpi_init(&upper_bound);
+ mbedtls_mpi_init(&result);
- TEST_EQUAL( 0, mbedtls_mpi_read_binary( &upper_bound,
- bound_bytes->x, bound_bytes->len ) );
- actual_ret = mbedtls_mpi_random( &result, min, &upper_bound,
- mbedtls_test_rnd_std_rand, NULL );
- TEST_EQUAL( expected_ret, actual_ret );
+ TEST_EQUAL(0, mbedtls_mpi_read_binary(&upper_bound,
+ bound_bytes->x, bound_bytes->len));
+ actual_ret = mbedtls_mpi_random(&result, min, &upper_bound,
+ mbedtls_test_rnd_std_rand, NULL);
+ TEST_EQUAL(expected_ret, actual_ret);
exit:
- mbedtls_mpi_free( &upper_bound );
- mbedtls_mpi_free( &result );
+ mbedtls_mpi_free(&upper_bound);
+ mbedtls_mpi_free(&result);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_camellia.function b/tests/suites/test_suite_camellia.function
index 3d318c8..1cef97a 100644
--- a/tests/suites/test_suite_camellia.function
+++ b/tests/suites/test_suite_camellia.function
@@ -8,7 +8,7 @@
*/
/* BEGIN_CASE */
-void camellia_invalid_param( )
+void camellia_invalid_param()
{
mbedtls_camellia_context ctx;
unsigned char buf[16] = { 0 };
@@ -16,26 +16,26 @@
size_t off;
((void) off);
- TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ecb( &ctx,
- invalid_mode,
- buf, buf ) );
+ TEST_EQUAL(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
+ mbedtls_camellia_crypt_ecb(&ctx,
+ invalid_mode,
+ buf, buf));
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cbc( &ctx,
- invalid_mode,
- sizeof( buf ),
- buf, buf, buf ) );
+ TEST_EQUAL(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
+ mbedtls_camellia_crypt_cbc(&ctx,
+ invalid_mode,
+ sizeof(buf),
+ buf, buf, buf));
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
- TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cfb128( &ctx,
- invalid_mode,
- sizeof( buf ),
- &off, buf,
- buf, buf ) );
+ TEST_EQUAL(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
+ mbedtls_camellia_crypt_cfb128(&ctx,
+ invalid_mode,
+ sizeof(buf),
+ &off, buf,
+ buf, buf));
#endif /* MBEDTLS_CIPHER_MODE_CFB */
exit:
@@ -44,152 +44,154 @@
/* END_CASE */
/* BEGIN_CASE */
-void camellia_encrypt_ecb( data_t * key_str, data_t * src_str,
- data_t * dst, int setkey_result )
+void camellia_encrypt_ecb(data_t *key_str, data_t *src_str,
+ data_t *dst, int setkey_result)
{
unsigned char output[100];
mbedtls_camellia_context ctx;
memset(output, 0x00, 100);
- mbedtls_camellia_init( &ctx );
+ mbedtls_camellia_init(&ctx);
- TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
- if( setkey_result == 0 )
- {
- TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_camellia_setkey_enc(&ctx, key_str->x, key_str->len * 8) == setkey_result);
+ if (setkey_result == 0) {
+ TEST_ASSERT(mbedtls_camellia_crypt_ecb(&ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x,
+ output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
}
exit:
- mbedtls_camellia_free( &ctx );
+ mbedtls_camellia_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void camellia_decrypt_ecb( data_t * key_str, data_t * src_str,
- data_t * dst, int setkey_result )
+void camellia_decrypt_ecb(data_t *key_str, data_t *src_str,
+ data_t *dst, int setkey_result)
{
unsigned char output[100];
mbedtls_camellia_context ctx;
memset(output, 0x00, 100);
- mbedtls_camellia_init( &ctx );
+ mbedtls_camellia_init(&ctx);
- TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
- if( setkey_result == 0 )
- {
- TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_camellia_setkey_dec(&ctx, key_str->x, key_str->len * 8) == setkey_result);
+ if (setkey_result == 0) {
+ TEST_ASSERT(mbedtls_camellia_crypt_ecb(&ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x,
+ output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
}
exit:
- mbedtls_camellia_free( &ctx );
+ mbedtls_camellia_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void camellia_encrypt_cbc( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst, int cbc_result )
+void camellia_encrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst, int cbc_result)
{
unsigned char output[100];
mbedtls_camellia_context ctx;
memset(output, 0x00, 100);
- mbedtls_camellia_init( &ctx );
+ mbedtls_camellia_init(&ctx);
- mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->len, iv_str->x, src_str->x, output) == cbc_result );
- if( cbc_result == 0 )
- {
+ mbedtls_camellia_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_camellia_crypt_cbc(&ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
- dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, src_str->len,
+ dst->len) == 0);
}
exit:
- mbedtls_camellia_free( &ctx );
+ mbedtls_camellia_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void camellia_decrypt_cbc( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst,
- int cbc_result )
+void camellia_decrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst,
+ int cbc_result)
{
unsigned char output[100];
mbedtls_camellia_context ctx;
memset(output, 0x00, 100);
- mbedtls_camellia_init( &ctx );
+ mbedtls_camellia_init(&ctx);
- mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
- if( cbc_result == 0 )
- {
+ mbedtls_camellia_setkey_dec(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_camellia_crypt_cbc(&ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
- dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, src_str->len,
+ dst->len) == 0);
}
exit:
- mbedtls_camellia_free( &ctx );
+ mbedtls_camellia_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void camellia_encrypt_cfb128( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst )
+void camellia_encrypt_cfb128(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_camellia_context ctx;
size_t iv_offset = 0;
memset(output, 0x00, 100);
- mbedtls_camellia_init( &ctx );
+ mbedtls_camellia_init(&ctx);
- mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
+ mbedtls_camellia_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_camellia_crypt_cfb128(&ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset,
+ iv_str->x, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
exit:
- mbedtls_camellia_free( &ctx );
+ mbedtls_camellia_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
-void camellia_decrypt_cfb128( data_t * key_str, data_t * iv_str,
- data_t * src_str,
- data_t * dst )
+void camellia_decrypt_cfb128(data_t *key_str, data_t *iv_str,
+ data_t *src_str,
+ data_t *dst)
{
unsigned char output[100];
mbedtls_camellia_context ctx;
size_t iv_offset = 0;
memset(output, 0x00, 100);
- mbedtls_camellia_init( &ctx );
+ mbedtls_camellia_init(&ctx);
- mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
- TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
+ mbedtls_camellia_setkey_enc(&ctx, key_str->x, key_str->len * 8);
+ TEST_ASSERT(mbedtls_camellia_crypt_cfb128(&ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset,
+ iv_str->x, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
exit:
- mbedtls_camellia_free( &ctx );
+ mbedtls_camellia_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void camellia_selftest( )
+void camellia_selftest()
{
- TEST_ASSERT( mbedtls_camellia_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_camellia_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_ccm.function b/tests/suites/test_suite_ccm.function
index a7ba0de..8c5e6ab 100644
--- a/tests/suites/test_suite_ccm.function
+++ b/tests/suites/test_suite_ccm.function
@@ -4,15 +4,15 @@
/* Use the multipart interface to process the encrypted data in two parts
* and check that the output matches the expected output.
* The context must have been set up with the key. */
-static int check_multipart( mbedtls_ccm_context *ctx,
- int mode,
- const data_t *iv,
- const data_t *add,
- const data_t *input,
- const data_t *expected_output,
- const data_t *tag,
- size_t n1,
- size_t n1_add)
+static int check_multipart(mbedtls_ccm_context *ctx,
+ int mode,
+ const data_t *iv,
+ const data_t *add,
+ const data_t *input,
+ const data_t *expected_output,
+ const data_t *tag,
+ size_t n1,
+ size_t n1_add)
{
int ok = 0;
uint8_t *output = NULL;
@@ -21,43 +21,43 @@
size_t olen;
/* Sanity checks on the test data */
- TEST_ASSERT( n1 <= input->len );
- TEST_ASSERT( n1_add <= add->len );
- TEST_EQUAL( input->len, expected_output->len );
- TEST_EQUAL( 0, mbedtls_ccm_starts( ctx, mode, iv->x, iv->len ) );
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( ctx, add->len, input->len, tag->len ) );
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( ctx, add->x, n1_add) );
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( ctx, add->x + n1_add, n2_add ) );
+ TEST_ASSERT(n1 <= input->len);
+ TEST_ASSERT(n1_add <= add->len);
+ TEST_EQUAL(input->len, expected_output->len);
+ TEST_EQUAL(0, mbedtls_ccm_starts(ctx, mode, iv->x, iv->len));
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(ctx, add->len, input->len, tag->len));
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(ctx, add->x, n1_add));
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(ctx, add->x + n1_add, n2_add));
/* Allocate a tight buffer for each update call. This way, if the function
* tries to write beyond the advertised required buffer size, this will
* count as an overflow for memory sanitizers and static checkers. */
- ASSERT_ALLOC( output, n1 );
+ ASSERT_ALLOC(output, n1);
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_ccm_update( ctx, input->x, n1, output, n1, &olen ) );
- TEST_EQUAL( n1, olen );
- ASSERT_COMPARE( output, olen, expected_output->x, n1 );
- mbedtls_free( output );
+ TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x, n1, output, n1, &olen));
+ TEST_EQUAL(n1, olen);
+ ASSERT_COMPARE(output, olen, expected_output->x, n1);
+ mbedtls_free(output);
output = NULL;
- ASSERT_ALLOC( output, n2 );
+ ASSERT_ALLOC(output, n2);
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_ccm_update( ctx, input->x + n1, n2, output, n2, &olen ) );
- TEST_EQUAL( n2, olen );
- ASSERT_COMPARE( output, olen, expected_output->x + n1, n2 );
- mbedtls_free( output );
+ TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x + n1, n2, output, n2, &olen));
+ TEST_EQUAL(n2, olen);
+ ASSERT_COMPARE(output, olen, expected_output->x + n1, n2);
+ mbedtls_free(output);
output = NULL;
- ASSERT_ALLOC( output, tag->len );
- TEST_EQUAL( 0, mbedtls_ccm_finish( ctx, output, tag->len ) );
- ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
- mbedtls_free( output );
+ ASSERT_ALLOC(output, tag->len);
+ TEST_EQUAL(0, mbedtls_ccm_finish(ctx, output, tag->len));
+ ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
+ mbedtls_free(output);
output = NULL;
ok = 1;
exit:
- mbedtls_free( output );
- return( ok );
+ mbedtls_free(output);
+ return ok;
}
/* END_HEADER */
@@ -67,34 +67,34 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
-void mbedtls_ccm_self_test( )
+void mbedtls_ccm_self_test()
{
- TEST_ASSERT( mbedtls_ccm_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_ccm_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ccm_setkey( int cipher_id, int key_size, int result )
+void mbedtls_ccm_setkey(int cipher_id, int key_size, int result)
{
mbedtls_ccm_context ctx;
unsigned char key[32];
int ret;
- mbedtls_ccm_init( &ctx );
+ mbedtls_ccm_init(&ctx);
- memset( key, 0x2A, sizeof( key ) );
- TEST_ASSERT( (unsigned) key_size <= 8 * sizeof( key ) );
+ memset(key, 0x2A, sizeof(key));
+ TEST_ASSERT((unsigned) key_size <= 8 * sizeof(key));
- ret = mbedtls_ccm_setkey( &ctx, cipher_id, key, key_size );
- TEST_ASSERT( ret == result );
+ ret = mbedtls_ccm_setkey(&ctx, cipher_id, key, key_size);
+ TEST_ASSERT(ret == result);
exit:
- mbedtls_ccm_free( &ctx );
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
-void ccm_lengths( int msg_len, int iv_len, int add_len, int tag_len, int res )
+void ccm_lengths(int msg_len, int iv_len, int add_len, int tag_len, int res)
{
mbedtls_ccm_context ctx;
unsigned char key[16];
@@ -105,38 +105,39 @@
unsigned char tag[18];
int decrypt_ret;
- mbedtls_ccm_init( &ctx );
+ mbedtls_ccm_init(&ctx);
- ASSERT_ALLOC_WEAK( add, add_len );
- memset( key, 0, sizeof( key ) );
- memset( msg, 0, sizeof( msg ) );
- memset( iv, 0, sizeof( iv ) );
- memset( out, 0, sizeof( out ) );
- memset( tag, 0, sizeof( tag ) );
+ ASSERT_ALLOC_WEAK(add, add_len);
+ memset(key, 0, sizeof(key));
+ memset(msg, 0, sizeof(msg));
+ memset(iv, 0, sizeof(iv));
+ memset(out, 0, sizeof(out));
+ memset(tag, 0, sizeof(tag));
- TEST_ASSERT( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES,
- key, 8 * sizeof( key ) ) == 0 );
+ TEST_ASSERT(mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES,
+ key, 8 * sizeof(key)) == 0);
- TEST_ASSERT( mbedtls_ccm_encrypt_and_tag( &ctx, msg_len, iv, iv_len, add, add_len,
- msg, out, tag, tag_len ) == res );
+ TEST_ASSERT(mbedtls_ccm_encrypt_and_tag(&ctx, msg_len, iv, iv_len, add, add_len,
+ msg, out, tag, tag_len) == res);
- decrypt_ret = mbedtls_ccm_auth_decrypt( &ctx, msg_len, iv, iv_len, add, add_len,
- msg, out, tag, tag_len );
+ decrypt_ret = mbedtls_ccm_auth_decrypt(&ctx, msg_len, iv, iv_len, add, add_len,
+ msg, out, tag, tag_len);
- if( res == 0 )
- TEST_ASSERT( decrypt_ret == MBEDTLS_ERR_CCM_AUTH_FAILED );
- else
- TEST_ASSERT( decrypt_ret == res );
+ if (res == 0) {
+ TEST_ASSERT(decrypt_ret == MBEDTLS_ERR_CCM_AUTH_FAILED);
+ } else {
+ TEST_ASSERT(decrypt_ret == res);
+ }
exit:
- mbedtls_free( add );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(add);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
-void ccm_star_lengths( int msg_len, int iv_len, int add_len, int tag_len,
- int res )
+void ccm_star_lengths(int msg_len, int iv_len, int add_len, int tag_len,
+ int res)
{
mbedtls_ccm_context ctx;
unsigned char key[16];
@@ -147,268 +148,269 @@
unsigned char tag[18];
int decrypt_ret;
- mbedtls_ccm_init( &ctx );
+ mbedtls_ccm_init(&ctx);
- memset( key, 0, sizeof( key ) );
- memset( msg, 0, sizeof( msg ) );
- memset( iv, 0, sizeof( iv ) );
- memset( add, 0, sizeof( add ) );
- memset( out, 0, sizeof( out ) );
- memset( tag, 0, sizeof( tag ) );
+ memset(key, 0, sizeof(key));
+ memset(msg, 0, sizeof(msg));
+ memset(iv, 0, sizeof(iv));
+ memset(add, 0, sizeof(add));
+ memset(out, 0, sizeof(out));
+ memset(tag, 0, sizeof(tag));
- TEST_ASSERT( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES,
- key, 8 * sizeof( key ) ) == 0 );
+ TEST_ASSERT(mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES,
+ key, 8 * sizeof(key)) == 0);
- TEST_ASSERT( mbedtls_ccm_star_encrypt_and_tag( &ctx, msg_len, iv, iv_len,
- add, add_len, msg, out, tag, tag_len ) == res );
+ TEST_ASSERT(mbedtls_ccm_star_encrypt_and_tag(&ctx, msg_len, iv, iv_len,
+ add, add_len, msg, out, tag, tag_len) == res);
- decrypt_ret = mbedtls_ccm_star_auth_decrypt( &ctx, msg_len, iv, iv_len, add,
- add_len, msg, out, tag, tag_len );
+ decrypt_ret = mbedtls_ccm_star_auth_decrypt(&ctx, msg_len, iv, iv_len, add,
+ add_len, msg, out, tag, tag_len);
- if( res == 0 && tag_len != 0 )
- TEST_ASSERT( decrypt_ret == MBEDTLS_ERR_CCM_AUTH_FAILED );
- else
- TEST_ASSERT( decrypt_ret == res );
+ if (res == 0 && tag_len != 0) {
+ TEST_ASSERT(decrypt_ret == MBEDTLS_ERR_CCM_AUTH_FAILED);
+ } else {
+ TEST_ASSERT(decrypt_ret == res);
+ }
exit:
- mbedtls_ccm_free( &ctx );
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ccm_encrypt_and_tag( int cipher_id, data_t * key,
- data_t * msg, data_t * iv,
- data_t * add, data_t * result )
+void mbedtls_ccm_encrypt_and_tag(int cipher_id, data_t *key,
+ data_t *msg, data_t *iv,
+ data_t *add, data_t *result)
{
mbedtls_ccm_context ctx;
size_t n1, n1_add;
- uint8_t* io_msg_buf = NULL;
- uint8_t* tag_buf = NULL;
+ uint8_t *io_msg_buf = NULL;
+ uint8_t *tag_buf = NULL;
const size_t expected_tag_len = result->len - msg->len;
- const uint8_t* expected_tag = result->x + msg->len;
+ const uint8_t *expected_tag = result->x + msg->len;
/* Prepare input/output message buffer */
- ASSERT_ALLOC( io_msg_buf, msg->len );
- if( msg->len != 0 )
- memcpy( io_msg_buf, msg->x, msg->len );
+ ASSERT_ALLOC(io_msg_buf, msg->len);
+ if (msg->len != 0) {
+ memcpy(io_msg_buf, msg->x, msg->len);
+ }
/* Prepare tag buffer */
- ASSERT_ALLOC( tag_buf, expected_tag_len );
+ ASSERT_ALLOC(tag_buf, expected_tag_len);
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
/* Test with input == output */
- TEST_EQUAL( mbedtls_ccm_encrypt_and_tag( &ctx, msg->len, iv->x, iv->len, add->x, add->len,
- io_msg_buf, io_msg_buf, tag_buf, expected_tag_len ), 0);
+ TEST_EQUAL(mbedtls_ccm_encrypt_and_tag(&ctx, msg->len, iv->x, iv->len, add->x, add->len,
+ io_msg_buf, io_msg_buf, tag_buf, expected_tag_len), 0);
- ASSERT_COMPARE( io_msg_buf, msg->len, result->x, msg->len );
- ASSERT_COMPARE( tag_buf, expected_tag_len, expected_tag, expected_tag_len );
+ ASSERT_COMPARE(io_msg_buf, msg->len, result->x, msg->len);
+ ASSERT_COMPARE(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
/* Prepare data_t structures for multipart testing */
const data_t encrypted_expected = { .x = result->x,
.len = msg->len };
- const data_t tag_expected = { .x = (uint8_t*) expected_tag, /* cast to conform with data_t x type */
+ const data_t tag_expected = { .x = (uint8_t *) expected_tag, /* cast to conform with data_t x type */
.len = expected_tag_len };
- for( n1 = 0; n1 <= msg->len; n1 += 1 )
- {
- for( n1_add = 0; n1_add <= add->len; n1_add += 1 )
- {
- mbedtls_test_set_step( n1 * 10000 + n1_add );
- if( !check_multipart( &ctx, MBEDTLS_CCM_ENCRYPT,
- iv, add, msg,
- &encrypted_expected,
- &tag_expected,
- n1, n1_add ) )
+ for (n1 = 0; n1 <= msg->len; n1 += 1) {
+ for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
+ mbedtls_test_set_step(n1 * 10000 + n1_add);
+ if (!check_multipart(&ctx, MBEDTLS_CCM_ENCRYPT,
+ iv, add, msg,
+ &encrypted_expected,
+ &tag_expected,
+ n1, n1_add)) {
goto exit;
- }
- }
-
-exit:
- mbedtls_ccm_free( &ctx );
- mbedtls_free( io_msg_buf );
- mbedtls_free( tag_buf );
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void mbedtls_ccm_star_no_tag( int cipher_id, int mode, data_t * key,
- data_t * msg, data_t * iv, data_t * result )
-{
- mbedtls_ccm_context ctx;
- uint8_t *output = NULL;
- size_t olen;
-
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, 0, msg->len, 0 ) );
-
- ASSERT_ALLOC( output, msg->len );
- TEST_EQUAL( 0, mbedtls_ccm_update( &ctx, msg->x, msg->len, output, msg->len, &olen ) );
- TEST_EQUAL( result->len, olen );
- ASSERT_COMPARE( output, olen, result->x, result->len );
-
- TEST_EQUAL( 0, mbedtls_ccm_finish( &ctx, NULL, 0 ) );
-exit:
- mbedtls_free(output);
- mbedtls_ccm_free( &ctx );
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void mbedtls_ccm_auth_decrypt( int cipher_id, data_t * key,
- data_t * msg, data_t * iv,
- data_t * add, int expected_tag_len, int result,
- data_t * expected_msg )
-{
- mbedtls_ccm_context ctx;
- size_t n1, n1_add;
-
- const size_t expected_msg_len = msg->len - expected_tag_len;
- const uint8_t* expected_tag = msg->x + expected_msg_len;
-
- /* Prepare input/output message buffer */
- uint8_t* io_msg_buf = NULL;
- ASSERT_ALLOC( io_msg_buf, expected_msg_len );
- if( expected_msg_len )
- memcpy( io_msg_buf, msg->x, expected_msg_len );
-
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- /* Test with input == output */
- TEST_EQUAL( mbedtls_ccm_auth_decrypt( &ctx, expected_msg_len, iv->x, iv->len, add->x, add->len,
- io_msg_buf, io_msg_buf, expected_tag, expected_tag_len ), result );
-
- if( result == 0 )
- {
- ASSERT_COMPARE( io_msg_buf, expected_msg_len, expected_msg->x, expected_msg_len );
-
- /* Prepare data_t structures for multipart testing */
- const data_t encrypted = { .x = msg->x,
- .len = expected_msg_len };
-
- const data_t tag_expected = { .x = (uint8_t*) expected_tag,
- .len = expected_tag_len };
-
- for( n1 = 0; n1 <= expected_msg_len; n1 += 1 )
- {
- for( n1_add = 0; n1_add <= add->len; n1_add += 1 )
- {
- mbedtls_test_set_step( n1 * 10000 + n1_add );
- if( !check_multipart( &ctx, MBEDTLS_CCM_DECRYPT,
- iv, add, &encrypted,
- expected_msg,
- &tag_expected,
- n1, n1_add ) )
- goto exit;
- }
- }
- }
- else
- {
- size_t i;
-
- for( i = 0; i < expected_msg_len; i++ )
- TEST_EQUAL( io_msg_buf[i], 0 );
- }
-
-exit:
- mbedtls_free(io_msg_buf);
- mbedtls_ccm_free( &ctx );
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void mbedtls_ccm_star_encrypt_and_tag( int cipher_id,
- data_t *key, data_t *msg,
- data_t *source_address, data_t *frame_counter,
- int sec_level, data_t *add,
- data_t *expected_result, int output_ret )
-{
- unsigned char iv[13];
- mbedtls_ccm_context ctx;
- size_t iv_len, expected_tag_len;
- size_t n1, n1_add;
- uint8_t* io_msg_buf = NULL;
- uint8_t* tag_buf = NULL;
-
- const uint8_t* expected_tag = expected_result->x + msg->len;
-
- /* Calculate tag length */
- if( sec_level % 4 == 0)
- expected_tag_len = 0;
- else
- expected_tag_len = 1 << ( sec_level % 4 + 1);
-
- /* Prepare input/output message buffer */
- ASSERT_ALLOC( io_msg_buf, msg->len );
- if( msg->len )
- memcpy( io_msg_buf, msg->x, msg->len );
-
- /* Prepare tag buffer */
- if( expected_tag_len == 0 )
- ASSERT_ALLOC( tag_buf, 16 );
- else
- ASSERT_ALLOC( tag_buf, expected_tag_len );
-
- /* Calculate iv */
- TEST_ASSERT( source_address->len == 8 );
- TEST_ASSERT( frame_counter->len == 4 );
- memcpy( iv, source_address->x, source_address->len );
- memcpy( iv + source_address->len, frame_counter->x, frame_counter->len );
- iv[source_address->len + frame_counter->len] = sec_level;
- iv_len = sizeof( iv );
-
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id,
- key->x, key->len * 8 ), 0 );
- /* Test with input == output */
- TEST_EQUAL( mbedtls_ccm_star_encrypt_and_tag( &ctx, msg->len, iv, iv_len,
- add->x, add->len, io_msg_buf,
- io_msg_buf, tag_buf, expected_tag_len), output_ret );
-
- ASSERT_COMPARE( io_msg_buf, msg->len, expected_result->x, msg->len );
- ASSERT_COMPARE( tag_buf, expected_tag_len, expected_tag, expected_tag_len );
-
- if( output_ret == 0 )
- {
- const data_t iv_data = { .x = iv,
- .len = iv_len };
-
- const data_t encrypted_expected = { .x = expected_result->x,
- .len = msg->len };
- const data_t tag_expected = { .x = (uint8_t*)expected_tag,
- .len = expected_tag_len };
-
- for( n1 = 0; n1 <= msg->len; n1 += 1 )
- {
- for( n1_add = 0; n1_add <= add->len; n1_add += 1 )
- {
- mbedtls_test_set_step( n1 * 10000 + n1_add );
- if( !check_multipart( &ctx, MBEDTLS_CCM_STAR_ENCRYPT,
- &iv_data, add, msg,
- &encrypted_expected,
- &tag_expected,
- n1, n1_add ) )
- goto exit;
}
}
}
exit:
- mbedtls_ccm_free( &ctx );
- mbedtls_free( io_msg_buf );
- mbedtls_free( tag_buf );
+ mbedtls_ccm_free(&ctx);
+ mbedtls_free(io_msg_buf);
+ mbedtls_free(tag_buf);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ccm_star_auth_decrypt( int cipher_id,
- data_t *key, data_t *msg,
- data_t *source_address, data_t *frame_counter,
- int sec_level, data_t *add,
- data_t *expected_result, int output_ret )
+void mbedtls_ccm_star_no_tag(int cipher_id, int mode, data_t *key,
+ data_t *msg, data_t *iv, data_t *result)
+{
+ mbedtls_ccm_context ctx;
+ uint8_t *output = NULL;
+ size_t olen;
+
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 0, msg->len, 0));
+
+ ASSERT_ALLOC(output, msg->len);
+ TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
+ TEST_EQUAL(result->len, olen);
+ ASSERT_COMPARE(output, olen, result->x, result->len);
+
+ TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, NULL, 0));
+exit:
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void mbedtls_ccm_auth_decrypt(int cipher_id, data_t *key,
+ data_t *msg, data_t *iv,
+ data_t *add, int expected_tag_len, int result,
+ data_t *expected_msg)
+{
+ mbedtls_ccm_context ctx;
+ size_t n1, n1_add;
+
+ const size_t expected_msg_len = msg->len - expected_tag_len;
+ const uint8_t *expected_tag = msg->x + expected_msg_len;
+
+ /* Prepare input/output message buffer */
+ uint8_t *io_msg_buf = NULL;
+ ASSERT_ALLOC(io_msg_buf, expected_msg_len);
+ if (expected_msg_len) {
+ memcpy(io_msg_buf, msg->x, expected_msg_len);
+ }
+
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ /* Test with input == output */
+ TEST_EQUAL(mbedtls_ccm_auth_decrypt(&ctx, expected_msg_len, iv->x, iv->len, add->x, add->len,
+ io_msg_buf, io_msg_buf, expected_tag, expected_tag_len),
+ result);
+
+ if (result == 0) {
+ ASSERT_COMPARE(io_msg_buf, expected_msg_len, expected_msg->x, expected_msg_len);
+
+ /* Prepare data_t structures for multipart testing */
+ const data_t encrypted = { .x = msg->x,
+ .len = expected_msg_len };
+
+ const data_t tag_expected = { .x = (uint8_t *) expected_tag,
+ .len = expected_tag_len };
+
+ for (n1 = 0; n1 <= expected_msg_len; n1 += 1) {
+ for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
+ mbedtls_test_set_step(n1 * 10000 + n1_add);
+ if (!check_multipart(&ctx, MBEDTLS_CCM_DECRYPT,
+ iv, add, &encrypted,
+ expected_msg,
+ &tag_expected,
+ n1, n1_add)) {
+ goto exit;
+ }
+ }
+ }
+ } else {
+ size_t i;
+
+ for (i = 0; i < expected_msg_len; i++) {
+ TEST_EQUAL(io_msg_buf[i], 0);
+ }
+ }
+
+exit:
+ mbedtls_free(io_msg_buf);
+ mbedtls_ccm_free(&ctx);
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void mbedtls_ccm_star_encrypt_and_tag(int cipher_id,
+ data_t *key, data_t *msg,
+ data_t *source_address, data_t *frame_counter,
+ int sec_level, data_t *add,
+ data_t *expected_result, int output_ret)
+{
+ unsigned char iv[13];
+ mbedtls_ccm_context ctx;
+ size_t iv_len, expected_tag_len;
+ size_t n1, n1_add;
+ uint8_t *io_msg_buf = NULL;
+ uint8_t *tag_buf = NULL;
+
+ const uint8_t *expected_tag = expected_result->x + msg->len;
+
+ /* Calculate tag length */
+ if (sec_level % 4 == 0) {
+ expected_tag_len = 0;
+ } else {
+ expected_tag_len = 1 << (sec_level % 4 + 1);
+ }
+
+ /* Prepare input/output message buffer */
+ ASSERT_ALLOC(io_msg_buf, msg->len);
+ if (msg->len) {
+ memcpy(io_msg_buf, msg->x, msg->len);
+ }
+
+ /* Prepare tag buffer */
+ if (expected_tag_len == 0) {
+ ASSERT_ALLOC(tag_buf, 16);
+ } else {
+ ASSERT_ALLOC(tag_buf, expected_tag_len);
+ }
+
+ /* Calculate iv */
+ TEST_ASSERT(source_address->len == 8);
+ TEST_ASSERT(frame_counter->len == 4);
+ memcpy(iv, source_address->x, source_address->len);
+ memcpy(iv + source_address->len, frame_counter->x, frame_counter->len);
+ iv[source_address->len + frame_counter->len] = sec_level;
+ iv_len = sizeof(iv);
+
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id,
+ key->x, key->len * 8), 0);
+ /* Test with input == output */
+ TEST_EQUAL(mbedtls_ccm_star_encrypt_and_tag(&ctx, msg->len, iv, iv_len,
+ add->x, add->len, io_msg_buf,
+ io_msg_buf, tag_buf, expected_tag_len), output_ret);
+
+ ASSERT_COMPARE(io_msg_buf, msg->len, expected_result->x, msg->len);
+ ASSERT_COMPARE(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
+
+ if (output_ret == 0) {
+ const data_t iv_data = { .x = iv,
+ .len = iv_len };
+
+ const data_t encrypted_expected = { .x = expected_result->x,
+ .len = msg->len };
+ const data_t tag_expected = { .x = (uint8_t *) expected_tag,
+ .len = expected_tag_len };
+
+ for (n1 = 0; n1 <= msg->len; n1 += 1) {
+ for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
+ mbedtls_test_set_step(n1 * 10000 + n1_add);
+ if (!check_multipart(&ctx, MBEDTLS_CCM_STAR_ENCRYPT,
+ &iv_data, add, msg,
+ &encrypted_expected,
+ &tag_expected,
+ n1, n1_add)) {
+ goto exit;
+ }
+ }
+ }
+ }
+
+exit:
+ mbedtls_ccm_free(&ctx);
+ mbedtls_free(io_msg_buf);
+ mbedtls_free(tag_buf);
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void mbedtls_ccm_star_auth_decrypt(int cipher_id,
+ data_t *key, data_t *msg,
+ data_t *source_address, data_t *frame_counter,
+ int sec_level, data_t *add,
+ data_t *expected_result, int output_ret)
{
unsigned char iv[13];
mbedtls_ccm_context ctx;
@@ -416,428 +418,429 @@
size_t n1, n1_add;
/* Calculate tag length */
- if( sec_level % 4 == 0)
+ if (sec_level % 4 == 0) {
expected_tag_len = 0;
- else
- expected_tag_len = 1 << ( sec_level % 4 + 1);
+ } else {
+ expected_tag_len = 1 << (sec_level % 4 + 1);
+ }
const size_t expected_msg_len = msg->len - expected_tag_len;
- const uint8_t* expected_tag = msg->x + expected_msg_len;
+ const uint8_t *expected_tag = msg->x + expected_msg_len;
/* Prepare input/output message buffer */
- uint8_t* io_msg_buf = NULL;
- ASSERT_ALLOC( io_msg_buf, expected_msg_len );
- if( expected_msg_len )
- memcpy( io_msg_buf, msg->x, expected_msg_len );
+ uint8_t *io_msg_buf = NULL;
+ ASSERT_ALLOC(io_msg_buf, expected_msg_len);
+ if (expected_msg_len) {
+ memcpy(io_msg_buf, msg->x, expected_msg_len);
+ }
/* Calculate iv */
- memset( iv, 0x00, sizeof( iv ) );
- TEST_ASSERT( source_address->len == 8 );
- TEST_ASSERT( frame_counter->len == 4 );
- memcpy( iv, source_address->x, source_address->len );
- memcpy( iv + source_address->len, frame_counter->x, frame_counter->len );
+ memset(iv, 0x00, sizeof(iv));
+ TEST_ASSERT(source_address->len == 8);
+ TEST_ASSERT(frame_counter->len == 4);
+ memcpy(iv, source_address->x, source_address->len);
+ memcpy(iv + source_address->len, frame_counter->x, frame_counter->len);
iv[source_address->len + frame_counter->len] = sec_level;
- iv_len = sizeof( iv );
+ iv_len = sizeof(iv);
- mbedtls_ccm_init( &ctx );
- TEST_ASSERT( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ) == 0 );
+ mbedtls_ccm_init(&ctx);
+ TEST_ASSERT(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8) == 0);
/* Test with input == output */
- TEST_EQUAL( mbedtls_ccm_star_auth_decrypt( &ctx, expected_msg_len, iv, iv_len,
- add->x, add->len, io_msg_buf, io_msg_buf,
- expected_tag, expected_tag_len ), output_ret );
+ TEST_EQUAL(mbedtls_ccm_star_auth_decrypt(&ctx, expected_msg_len, iv, iv_len,
+ add->x, add->len, io_msg_buf, io_msg_buf,
+ expected_tag, expected_tag_len), output_ret);
- ASSERT_COMPARE( io_msg_buf, expected_msg_len, expected_result->x, expected_msg_len );
+ ASSERT_COMPARE(io_msg_buf, expected_msg_len, expected_result->x, expected_msg_len);
- if( output_ret == 0 )
- {
+ if (output_ret == 0) {
const data_t iv_data = { .x = iv,
.len = iv_len };
const data_t encrypted = { .x = msg->x,
- .len = expected_msg_len} ;
+ .len = expected_msg_len };
- const data_t tag_expected = { .x = (uint8_t*) expected_tag,
+ const data_t tag_expected = { .x = (uint8_t *) expected_tag,
.len = expected_tag_len };
- for( n1 = 0; n1 <= expected_msg_len; n1 += 1 )
- {
- for( n1_add = 0; n1_add <= add->len; n1_add += 1 )
- {
- mbedtls_test_set_step( n1 * 10000 + n1_add );
- if( !check_multipart( &ctx, MBEDTLS_CCM_STAR_DECRYPT,
- &iv_data, add, &encrypted,
- expected_result,
- &tag_expected,
- n1, n1_add ) )
+ for (n1 = 0; n1 <= expected_msg_len; n1 += 1) {
+ for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
+ mbedtls_test_set_step(n1 * 10000 + n1_add);
+ if (!check_multipart(&ctx, MBEDTLS_CCM_STAR_DECRYPT,
+ &iv_data, add, &encrypted,
+ expected_result,
+ &tag_expected,
+ n1, n1_add)) {
goto exit;
- }
+ }
+ }
}
}
exit:
- mbedtls_ccm_free( &ctx );
- mbedtls_free( io_msg_buf );
+ mbedtls_ccm_free(&ctx);
+ mbedtls_free(io_msg_buf);
}
/* END_CASE */
/* Skip auth data, provide full text */
/* BEGIN_CASE */
-void mbedtls_ccm_skip_ad( int cipher_id, int mode,
- data_t * key, data_t * msg, data_t * iv,
- data_t * result, data_t * tag )
+void mbedtls_ccm_skip_ad(int cipher_id, int mode,
+ data_t *key, data_t *msg, data_t *iv,
+ data_t *result, data_t *tag)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
size_t olen;
/* Sanity checks on the test data */
- TEST_EQUAL( msg->len, result->len );
+ TEST_EQUAL(msg->len, result->len);
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, 0, msg->len, tag->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 0, msg->len, tag->len));
- ASSERT_ALLOC( output, result->len );
+ ASSERT_ALLOC(output, result->len);
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_ccm_update( &ctx, msg->x, msg->len, output, result->len, &olen ) );
- TEST_EQUAL( result->len, olen );
- ASSERT_COMPARE( output, olen, result->x, result->len );
- mbedtls_free( output );
+ TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, result->len, &olen));
+ TEST_EQUAL(result->len, olen);
+ ASSERT_COMPARE(output, olen, result->x, result->len);
+ mbedtls_free(output);
output = NULL;
- ASSERT_ALLOC( output, tag->len );
- TEST_EQUAL( 0, mbedtls_ccm_finish( &ctx, output, tag->len ) );
- ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
- mbedtls_free( output );
+ ASSERT_ALLOC(output, tag->len);
+ TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
+ ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
+ mbedtls_free(output);
output = NULL;
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide auth data, skip full text */
/* BEGIN_CASE */
-void mbedtls_ccm_skip_update( int cipher_id, int mode,
- data_t * key, data_t * iv, data_t* add,
- data_t * tag )
+void mbedtls_ccm_skip_update(int cipher_id, int mode,
+ data_t *key, data_t *iv, data_t *add,
+ data_t *tag)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, 0, tag->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 0, tag->len));
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
- ASSERT_ALLOC( output, tag->len );
- TEST_EQUAL( 0, mbedtls_ccm_finish( &ctx, output, tag->len ) );
- ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
- mbedtls_free( output );
+ ASSERT_ALLOC(output, tag->len);
+ TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
+ ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
+ mbedtls_free(output);
output = NULL;
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide too much auth data */
/* BEGIN_CASE */
-void mbedtls_ccm_overflow_ad( int cipher_id, int mode,
- data_t * key, data_t * iv,
- data_t * add )
+void mbedtls_ccm_overflow_ad(int cipher_id, int mode,
+ data_t *key, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded values for msg length and tag length. They are not a part of this test
// subtract 1 from configured auth data length to provoke an overflow
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len - 1, 16, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len - 1, 16, 16));
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
exit:
- mbedtls_ccm_free( &ctx );
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide unexpected auth data */
/* BEGIN_CASE */
-void mbedtls_ccm_unexpected_ad( int cipher_id, int mode,
- data_t * key, data_t * iv,
- data_t * add )
+void mbedtls_ccm_unexpected_ad(int cipher_id, int mode,
+ data_t *key, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded values for msg length and tag length. They are not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, 0, 16, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 0, 16, 16));
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
exit:
- mbedtls_ccm_free( &ctx );
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide unexpected plaintext/ciphertext data */
/* BEGIN_CASE */
-void mbedtls_ccm_unexpected_text( int cipher_id, int mode,
- data_t * key, data_t * msg, data_t * iv,
- data_t * add )
+void mbedtls_ccm_unexpected_text(int cipher_id, int mode,
+ data_t *key, data_t *msg, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
size_t olen;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded value for tag length. It is not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, 0, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 0, 16));
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
- ASSERT_ALLOC( output, msg->len );
+ ASSERT_ALLOC(output, msg->len);
olen = 0xdeadbeef;
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update( &ctx, msg->x, msg->len, output, msg->len, &olen ) );
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT,
+ mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide incomplete auth data and finish */
/* BEGIN_CASE */
-void mbedtls_ccm_incomplete_ad( int cipher_id, int mode,
- data_t * key, data_t * iv, data_t* add )
+void mbedtls_ccm_incomplete_ad(int cipher_id, int mode,
+ data_t *key, data_t *iv, data_t *add)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded values for msg length and tag length. They are not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, 0, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 0, 16));
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len - 1) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len - 1));
- ASSERT_ALLOC( output, 16 );
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish( &ctx, output, 16 ) );
+ ASSERT_ALLOC(output, 16);
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide complete auth data on first update_ad.
* Provide unexpected auth data on second update_ad */
/* BEGIN_CASE */
-void mbedtls_ccm_full_ad_and_overflow( int cipher_id, int mode,
- data_t * key, data_t * iv,
- data_t * add )
+void mbedtls_ccm_full_ad_and_overflow(int cipher_id, int mode,
+ data_t *key, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded values for msg length and tag length. They are not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, 16, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 16, 16));
// pass full auth data
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
// pass 1 extra byte
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad( &ctx, add->x, 1) );
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, 1));
exit:
- mbedtls_ccm_free( &ctx );
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide incomplete auth data on first update_ad.
* Provide too much auth data on second update_ad */
/* BEGIN_CASE */
-void mbedtls_ccm_incomplete_ad_and_overflow( int cipher_id, int mode,
- data_t * key, data_t * iv,
- data_t * add )
+void mbedtls_ccm_incomplete_ad_and_overflow(int cipher_id, int mode,
+ data_t *key, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
uint8_t add_second_buffer[2];
- add_second_buffer[0] = add->x[ add->len - 1 ];
+ add_second_buffer[0] = add->x[add->len - 1];
add_second_buffer[1] = 0xAB; // some magic value
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded values for msg length and tag length. They are not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, 16, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 16, 16));
// pass incomplete auth data
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len - 1) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len - 1));
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad( &ctx, add_second_buffer, 2) );
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add_second_buffer, 2));
exit:
- mbedtls_ccm_free( &ctx );
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide too much plaintext/ciphertext */
/* BEGIN_CASE */
-void mbedtls_ccm_overflow_update( int cipher_id, int mode,
- data_t * key, data_t * msg, data_t * iv,
- data_t * add )
+void mbedtls_ccm_overflow_update(int cipher_id, int mode,
+ data_t *key, data_t *msg, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
size_t olen;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded value for tag length. It is a not a part of this test
// subtract 1 from configured msg length to provoke an overflow
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, msg->len - 1, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len - 1, 16));
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
- ASSERT_ALLOC( output, msg->len );
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, \
- mbedtls_ccm_update( &ctx, msg->x, msg->len, output, msg->len, &olen ) );
+ ASSERT_ALLOC(output, msg->len);
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, \
+ mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide incomplete plaintext/ciphertext and finish */
/* BEGIN_CASE */
-void mbedtls_ccm_incomplete_update( int cipher_id, int mode,
- data_t * key, data_t * msg, data_t * iv,
- data_t * add )
+void mbedtls_ccm_incomplete_update(int cipher_id, int mode,
+ data_t *key, data_t *msg, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
size_t olen;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded value for tag length. It is not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, msg->len, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len, 16));
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
- ASSERT_ALLOC( output, msg->len );
+ ASSERT_ALLOC(output, msg->len);
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_ccm_update( &ctx, msg->x, msg->len - 1, output, msg->len, &olen ) );
- mbedtls_free( output );
+ TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len - 1, output, msg->len, &olen));
+ mbedtls_free(output);
output = NULL;
- ASSERT_ALLOC( output, 16 );
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish( &ctx, output, 16 ) );
+ ASSERT_ALLOC(output, 16);
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide full plaintext/ciphertext of first update
* Provide unexpected plaintext/ciphertext on second update */
/* BEGIN_CASE */
-void mbedtls_ccm_full_update_and_overflow( int cipher_id, int mode,
- data_t * key, data_t * msg, data_t * iv,
- data_t * add )
+void mbedtls_ccm_full_update_and_overflow(int cipher_id, int mode,
+ data_t *key, data_t *msg, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
size_t olen;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded value for tag length. It is a not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, msg->len, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len, 16));
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
- ASSERT_ALLOC( output, msg->len );
+ ASSERT_ALLOC(output, msg->len);
// pass full text
- TEST_EQUAL( 0, mbedtls_ccm_update( &ctx, msg->x, msg->len, output, msg->len, &olen ) );
+ TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
// pass 1 extra byte
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, \
- mbedtls_ccm_update( &ctx, msg->x, 1, output, 1, &olen ) );
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, \
+ mbedtls_ccm_update(&ctx, msg->x, 1, output, 1, &olen));
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Provide incomplete plaintext/ciphertext of first update
* Provide too much plaintext/ciphertext on second update */
/* BEGIN_CASE */
-void mbedtls_ccm_incomplete_update_overflow( int cipher_id, int mode,
- data_t * key, data_t * msg, data_t * iv,
- data_t * add )
+void mbedtls_ccm_incomplete_update_overflow(int cipher_id, int mode,
+ data_t *key, data_t *msg, data_t *iv,
+ data_t *add)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
size_t olen;
uint8_t msg_second_buffer[2];
- msg_second_buffer[0] = msg->x[ msg->len - 1 ];
+ msg_second_buffer[0] = msg->x[msg->len - 1];
msg_second_buffer[1] = 0xAB; // some magic value
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded value for tag length. It is a not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, msg->len, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len, 16));
- TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len) );
+ TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
- ASSERT_ALLOC( output, msg->len + 1 );
+ ASSERT_ALLOC(output, msg->len + 1);
// pass incomplete text
- TEST_EQUAL( 0, mbedtls_ccm_update( &ctx, msg->x, msg->len - 1, output, msg->len + 1, &olen ) );
+ TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len - 1, output, msg->len + 1, &olen));
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, \
- mbedtls_ccm_update( &ctx, msg_second_buffer, 2, output + msg->len - 1, 2, &olen ) );
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, \
+ mbedtls_ccm_update(&ctx, msg_second_buffer, 2, output + msg->len - 1, 2, &olen));
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
/* Finish without passing any auth data or plaintext/ciphertext input */
/* BEGIN_CASE */
-void mbedtls_ccm_instant_finish( int cipher_id, int mode,
- data_t * key, data_t * iv )
+void mbedtls_ccm_instant_finish(int cipher_id, int mode,
+ data_t *key, data_t *iv)
{
mbedtls_ccm_context ctx;
uint8_t *output = NULL;
- mbedtls_ccm_init( &ctx );
- TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_ccm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_ccm_init(&ctx);
+ TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
// use hardcoded values for add length, msg length and tag length.
// They are not a part of this test
- TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, 16, 16, 16 ) );
+ TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 16, 16, 16));
- ASSERT_ALLOC( output, 16 );
- TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish( &ctx, output, 16 ) );
+ ASSERT_ALLOC(output, 16);
+ TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
exit:
- mbedtls_free( output );
- mbedtls_ccm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_ccm_free(&ctx);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_chacha20.function b/tests/suites/test_suite_chacha20.function
index 9afadb7..1a7e676 100644
--- a/tests/suites/test_suite_chacha20.function
+++ b/tests/suites/test_suite_chacha20.function
@@ -8,43 +8,44 @@
*/
/* BEGIN_CASE */
-void chacha20_crypt( data_t *key_str,
- data_t *nonce_str,
- int counter,
- data_t *src_str,
- data_t *expected_output_str )
+void chacha20_crypt(data_t *key_str,
+ data_t *nonce_str,
+ int counter,
+ data_t *src_str,
+ data_t *expected_output_str)
{
unsigned char output[375];
mbedtls_chacha20_context ctx;
- memset( output, 0x00, sizeof( output ) );
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( src_str->len == expected_output_str->len );
- TEST_ASSERT( key_str->len == 32U );
- TEST_ASSERT( nonce_str->len == 12U );
+ TEST_ASSERT(src_str->len == expected_output_str->len);
+ TEST_ASSERT(key_str->len == 32U);
+ TEST_ASSERT(nonce_str->len == 12U);
/*
* Test the integrated API
*/
- TEST_ASSERT( mbedtls_chacha20_crypt( key_str->x, nonce_str->x, counter, src_str->len, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_chacha20_crypt(key_str->x, nonce_str->x, counter, src_str->len, src_str->x,
+ output) == 0);
- ASSERT_COMPARE( output, expected_output_str->len,
- expected_output_str->x, expected_output_str->len );
+ ASSERT_COMPARE(output, expected_output_str->len,
+ expected_output_str->x, expected_output_str->len);
/*
* Test the streaming API
*/
- mbedtls_chacha20_init( &ctx );
+ mbedtls_chacha20_init(&ctx);
- TEST_ASSERT( mbedtls_chacha20_setkey( &ctx, key_str->x ) == 0 );
+ TEST_ASSERT(mbedtls_chacha20_setkey(&ctx, key_str->x) == 0);
- TEST_ASSERT( mbedtls_chacha20_starts( &ctx, nonce_str->x, counter ) == 0 );
+ TEST_ASSERT(mbedtls_chacha20_starts(&ctx, nonce_str->x, counter) == 0);
- memset( output, 0x00, sizeof( output ) );
- TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len, src_str->x, output ) == 0 );
+ memset(output, 0x00, sizeof(output));
+ TEST_ASSERT(mbedtls_chacha20_update(&ctx, src_str->len, src_str->x, output) == 0);
- ASSERT_COMPARE( output, expected_output_str->len,
- expected_output_str->x, expected_output_str->len );
+ ASSERT_COMPARE(output, expected_output_str->len,
+ expected_output_str->x, expected_output_str->len);
/*
* Test the streaming API again, piecewise
@@ -52,23 +53,23 @@
/* Don't free/init the context nor set the key again,
* in order to test that starts() does the right thing. */
- TEST_ASSERT( mbedtls_chacha20_starts( &ctx, nonce_str->x, counter ) == 0 );
+ TEST_ASSERT(mbedtls_chacha20_starts(&ctx, nonce_str->x, counter) == 0);
- memset( output, 0x00, sizeof( output ) );
- TEST_ASSERT( mbedtls_chacha20_update( &ctx, 1, src_str->x, output ) == 0 );
- TEST_ASSERT( mbedtls_chacha20_update( &ctx, src_str->len - 1,
- src_str->x + 1, output + 1 ) == 0 );
+ memset(output, 0x00, sizeof(output));
+ TEST_ASSERT(mbedtls_chacha20_update(&ctx, 1, src_str->x, output) == 0);
+ TEST_ASSERT(mbedtls_chacha20_update(&ctx, src_str->len - 1,
+ src_str->x + 1, output + 1) == 0);
- ASSERT_COMPARE( output, expected_output_str->len,
- expected_output_str->x, expected_output_str->len );
+ ASSERT_COMPARE(output, expected_output_str->len,
+ expected_output_str->x, expected_output_str->len);
- mbedtls_chacha20_free( &ctx );
+ mbedtls_chacha20_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void chacha20_self_test()
{
- TEST_ASSERT( mbedtls_chacha20_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_chacha20_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_chachapoly.function b/tests/suites/test_suite_chachapoly.function
index 2e1e7b2..4f1a34e 100644
--- a/tests/suites/test_suite_chachapoly.function
+++ b/tests/suites/test_suite_chachapoly.function
@@ -8,61 +8,71 @@
*/
/* BEGIN_CASE */
-void mbedtls_chachapoly_enc( data_t *key_str, data_t *nonce_str, data_t *aad_str, data_t *input_str, data_t *output_str, data_t *mac_str )
+void mbedtls_chachapoly_enc(data_t *key_str,
+ data_t *nonce_str,
+ data_t *aad_str,
+ data_t *input_str,
+ data_t *output_str,
+ data_t *mac_str)
{
unsigned char output[265];
unsigned char mac[16]; /* size set by the standard */
mbedtls_chachapoly_context ctx;
- TEST_ASSERT( key_str->len == 32 );
- TEST_ASSERT( nonce_str->len == 12 );
- TEST_ASSERT( mac_str->len == 16 );
+ TEST_ASSERT(key_str->len == 32);
+ TEST_ASSERT(nonce_str->len == 12);
+ TEST_ASSERT(mac_str->len == 16);
- mbedtls_chachapoly_init( &ctx );
+ mbedtls_chachapoly_init(&ctx);
- TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str->x ) == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_setkey(&ctx, key_str->x) == 0);
- TEST_ASSERT( mbedtls_chachapoly_encrypt_and_tag( &ctx,
- input_str->len, nonce_str->x,
- aad_str->x, aad_str->len,
- input_str->x, output, mac ) == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_encrypt_and_tag(&ctx,
+ input_str->len, nonce_str->x,
+ aad_str->x, aad_str->len,
+ input_str->x, output, mac) == 0);
- TEST_ASSERT( memcmp( output_str->x, output, output_str->len ) == 0 );
- TEST_ASSERT( memcmp( mac_str->x, mac, 16U ) == 0 );
+ TEST_ASSERT(memcmp(output_str->x, output, output_str->len) == 0);
+ TEST_ASSERT(memcmp(mac_str->x, mac, 16U) == 0);
exit:
- mbedtls_chachapoly_free( &ctx );
+ mbedtls_chachapoly_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_chachapoly_dec( data_t *key_str, data_t *nonce_str, data_t *aad_str, data_t *input_str, data_t *output_str, data_t *mac_str, int ret_exp )
+void mbedtls_chachapoly_dec(data_t *key_str,
+ data_t *nonce_str,
+ data_t *aad_str,
+ data_t *input_str,
+ data_t *output_str,
+ data_t *mac_str,
+ int ret_exp)
{
unsigned char output[265];
int ret;
mbedtls_chachapoly_context ctx;
- TEST_ASSERT( key_str->len == 32 );
- TEST_ASSERT( nonce_str->len == 12 );
- TEST_ASSERT( mac_str->len == 16 );
+ TEST_ASSERT(key_str->len == 32);
+ TEST_ASSERT(nonce_str->len == 12);
+ TEST_ASSERT(mac_str->len == 16);
- mbedtls_chachapoly_init( &ctx );
+ mbedtls_chachapoly_init(&ctx);
- TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str->x ) == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_setkey(&ctx, key_str->x) == 0);
- ret = mbedtls_chachapoly_auth_decrypt( &ctx,
- input_str->len, nonce_str->x,
- aad_str->x, aad_str->len,
- mac_str->x, input_str->x, output );
+ ret = mbedtls_chachapoly_auth_decrypt(&ctx,
+ input_str->len, nonce_str->x,
+ aad_str->x, aad_str->len,
+ mac_str->x, input_str->x, output);
- TEST_ASSERT( ret == ret_exp );
- if( ret_exp == 0 )
- {
- TEST_ASSERT( memcmp( output_str->x, output, output_str->len ) == 0 );
+ TEST_ASSERT(ret == ret_exp);
+ if (ret_exp == 0) {
+ TEST_ASSERT(memcmp(output_str->x, output, output_str->len) == 0);
}
exit:
- mbedtls_chachapoly_free( &ctx );
+ mbedtls_chachapoly_free(&ctx);
}
/* END_CASE */
@@ -75,80 +85,80 @@
unsigned char input[1];
unsigned char output[1];
unsigned char mac[16];
- size_t input_len = sizeof( input );
- size_t aad_len = sizeof( aad );
+ size_t input_len = sizeof(input);
+ size_t aad_len = sizeof(aad);
mbedtls_chachapoly_context ctx;
- memset( key, 0x00, sizeof( key ) );
- memset( nonce, 0x00, sizeof( nonce ) );
- memset( aad, 0x00, sizeof( aad ) );
- memset( input, 0x00, sizeof( input ) );
- memset( output, 0x00, sizeof( output ) );
- memset( mac, 0x00, sizeof( mac ) );
+ memset(key, 0x00, sizeof(key));
+ memset(nonce, 0x00, sizeof(nonce));
+ memset(aad, 0x00, sizeof(aad));
+ memset(input, 0x00, sizeof(input));
+ memset(output, 0x00, sizeof(output));
+ memset(mac, 0x00, sizeof(mac));
/* Initial state: finish, update, update_aad forbidden */
- mbedtls_chachapoly_init( &ctx );
+ mbedtls_chachapoly_init(&ctx);
- TEST_ASSERT( mbedtls_chachapoly_finish( &ctx, mac )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
- TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, input, output )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
- TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, aad, aad_len )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
+ TEST_ASSERT(mbedtls_chachapoly_finish(&ctx, mac)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
+ TEST_ASSERT(mbedtls_chachapoly_update(&ctx, input_len, input, output)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
+ TEST_ASSERT(mbedtls_chachapoly_update_aad(&ctx, aad, aad_len)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
/* Still initial state: finish, update, update_aad forbidden */
- TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key )
- == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_setkey(&ctx, key)
+ == 0);
- TEST_ASSERT( mbedtls_chachapoly_finish( &ctx, mac )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
- TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, input, output )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
- TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, aad, aad_len )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
+ TEST_ASSERT(mbedtls_chachapoly_finish(&ctx, mac)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
+ TEST_ASSERT(mbedtls_chachapoly_update(&ctx, input_len, input, output)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
+ TEST_ASSERT(mbedtls_chachapoly_update_aad(&ctx, aad, aad_len)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
/* Starts -> finish OK */
- TEST_ASSERT( mbedtls_chachapoly_starts( &ctx, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT )
- == 0 );
- TEST_ASSERT( mbedtls_chachapoly_finish( &ctx, mac )
- == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_starts(&ctx, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT)
+ == 0);
+ TEST_ASSERT(mbedtls_chachapoly_finish(&ctx, mac)
+ == 0);
/* After finish: update, update_aad forbidden */
- TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, input, output )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
- TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, aad, aad_len )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
+ TEST_ASSERT(mbedtls_chachapoly_update(&ctx, input_len, input, output)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
+ TEST_ASSERT(mbedtls_chachapoly_update_aad(&ctx, aad, aad_len)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
/* Starts -> update* OK */
- TEST_ASSERT( mbedtls_chachapoly_starts( &ctx, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT )
- == 0 );
- TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, input, output )
- == 0 );
- TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, input, output )
- == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_starts(&ctx, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT)
+ == 0);
+ TEST_ASSERT(mbedtls_chachapoly_update(&ctx, input_len, input, output)
+ == 0);
+ TEST_ASSERT(mbedtls_chachapoly_update(&ctx, input_len, input, output)
+ == 0);
/* After update: update_aad forbidden */
- TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, aad, aad_len )
- == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
+ TEST_ASSERT(mbedtls_chachapoly_update_aad(&ctx, aad, aad_len)
+ == MBEDTLS_ERR_CHACHAPOLY_BAD_STATE);
/* Starts -> update_aad* -> finish OK */
- TEST_ASSERT( mbedtls_chachapoly_starts( &ctx, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT )
- == 0 );
- TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, aad, aad_len )
- == 0 );
- TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, aad, aad_len )
- == 0 );
- TEST_ASSERT( mbedtls_chachapoly_finish( &ctx, mac )
- == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_starts(&ctx, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT)
+ == 0);
+ TEST_ASSERT(mbedtls_chachapoly_update_aad(&ctx, aad, aad_len)
+ == 0);
+ TEST_ASSERT(mbedtls_chachapoly_update_aad(&ctx, aad, aad_len)
+ == 0);
+ TEST_ASSERT(mbedtls_chachapoly_finish(&ctx, mac)
+ == 0);
exit:
- mbedtls_chachapoly_free( &ctx );
+ mbedtls_chachapoly_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void chachapoly_selftest()
{
- TEST_ASSERT( mbedtls_chachapoly_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_chachapoly_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function
index ff936df..f842045 100644
--- a/tests/suites/test_suite_cipher.function
+++ b/tests/suites/test_suite_cipher.function
@@ -12,92 +12,74 @@
/* Check the internal consistency of a cipher info structure, and
* check it against mbedtls_cipher_info_from_xxx(). */
-static int check_cipher_info( mbedtls_cipher_type_t type,
- const mbedtls_cipher_info_t *info )
+static int check_cipher_info(mbedtls_cipher_type_t type,
+ const mbedtls_cipher_info_t *info)
{
size_t key_bitlen, block_size, iv_size;
- TEST_ASSERT( info != NULL );
- TEST_EQUAL( type, mbedtls_cipher_info_get_type( info ) );
- TEST_EQUAL( type, info->type );
- TEST_ASSERT( mbedtls_cipher_info_from_type( type ) == info );
+ TEST_ASSERT(info != NULL);
+ TEST_EQUAL(type, mbedtls_cipher_info_get_type(info));
+ TEST_EQUAL(type, info->type);
+ TEST_ASSERT(mbedtls_cipher_info_from_type(type) == info);
- TEST_EQUAL( info->mode, mbedtls_cipher_info_get_mode( info ) );
+ TEST_EQUAL(info->mode, mbedtls_cipher_info_get_mode(info));
/* Insist that get_name() return the string from the structure and
* not a copy. A copy would have an unknown storage duration. */
- TEST_ASSERT( mbedtls_cipher_info_get_name( info ) == info->name );
- TEST_ASSERT( mbedtls_cipher_info_from_string( info->name ) == info );
+ TEST_ASSERT(mbedtls_cipher_info_get_name(info) == info->name);
+ TEST_ASSERT(mbedtls_cipher_info_from_string(info->name) == info);
- key_bitlen = mbedtls_cipher_info_get_key_bitlen( info );
- block_size = mbedtls_cipher_info_get_block_size( info );
- iv_size = mbedtls_cipher_info_get_iv_size( info );
- if( info->type == MBEDTLS_CIPHER_NULL )
- {
- TEST_ASSERT( key_bitlen == 0 );
- TEST_ASSERT( block_size == 1 );
- TEST_ASSERT( iv_size == 0 );
- }
- else if( info->mode == MBEDTLS_MODE_XTS )
- {
- TEST_ASSERT( key_bitlen == 256 ||
- key_bitlen == 384 ||
- key_bitlen == 512 );
- }
- else if( ! strncmp( info->name, "DES-EDE3-", 9 ) )
- {
- TEST_ASSERT( key_bitlen == 192 );
- TEST_ASSERT( ! mbedtls_cipher_info_has_variable_key_bitlen( info ) );
- TEST_ASSERT( block_size == 8 );
- }
- else if( ! strncmp( info->name, "DES-EDE-", 8 ) )
- {
- TEST_ASSERT( key_bitlen == 128 );
- TEST_ASSERT( ! mbedtls_cipher_info_has_variable_key_bitlen( info ) );
- TEST_ASSERT( block_size == 8 );
- }
- else if( ! strncmp( info->name, "DES-", 4 ) )
- {
- TEST_ASSERT( key_bitlen == 64 );
- TEST_ASSERT( ! mbedtls_cipher_info_has_variable_key_bitlen( info ) );
- TEST_ASSERT( block_size == 8 );
- }
- else if( ! strncmp( info->name, "AES", 3 ) )
- {
- TEST_ASSERT( key_bitlen == 128 ||
- key_bitlen == 192 ||
- key_bitlen == 256 );
- TEST_ASSERT( ! mbedtls_cipher_info_has_variable_key_bitlen( info ) );
- TEST_ASSERT( block_size == 16 );
- }
- else
- {
- TEST_ASSERT( key_bitlen == 128 ||
- key_bitlen == 192 ||
- key_bitlen == 256 );
+ key_bitlen = mbedtls_cipher_info_get_key_bitlen(info);
+ block_size = mbedtls_cipher_info_get_block_size(info);
+ iv_size = mbedtls_cipher_info_get_iv_size(info);
+ if (info->type == MBEDTLS_CIPHER_NULL) {
+ TEST_ASSERT(key_bitlen == 0);
+ TEST_ASSERT(block_size == 1);
+ TEST_ASSERT(iv_size == 0);
+ } else if (info->mode == MBEDTLS_MODE_XTS) {
+ TEST_ASSERT(key_bitlen == 256 ||
+ key_bitlen == 384 ||
+ key_bitlen == 512);
+ } else if (!strncmp(info->name, "DES-EDE3-", 9)) {
+ TEST_ASSERT(key_bitlen == 192);
+ TEST_ASSERT(!mbedtls_cipher_info_has_variable_key_bitlen(info));
+ TEST_ASSERT(block_size == 8);
+ } else if (!strncmp(info->name, "DES-EDE-", 8)) {
+ TEST_ASSERT(key_bitlen == 128);
+ TEST_ASSERT(!mbedtls_cipher_info_has_variable_key_bitlen(info));
+ TEST_ASSERT(block_size == 8);
+ } else if (!strncmp(info->name, "DES-", 4)) {
+ TEST_ASSERT(key_bitlen == 64);
+ TEST_ASSERT(!mbedtls_cipher_info_has_variable_key_bitlen(info));
+ TEST_ASSERT(block_size == 8);
+ } else if (!strncmp(info->name, "AES", 3)) {
+ TEST_ASSERT(key_bitlen == 128 ||
+ key_bitlen == 192 ||
+ key_bitlen == 256);
+ TEST_ASSERT(!mbedtls_cipher_info_has_variable_key_bitlen(info));
+ TEST_ASSERT(block_size == 16);
+ } else {
+ TEST_ASSERT(key_bitlen == 128 ||
+ key_bitlen == 192 ||
+ key_bitlen == 256);
}
- if( strstr( info->name, "-ECB" ) != NULL )
- {
- TEST_ASSERT( iv_size == 0 );
- TEST_ASSERT( ! mbedtls_cipher_info_has_variable_iv_size( info ) );
- }
- else if( strstr( info->name, "-CBC" ) != NULL ||
- strstr( info->name, "-CTR" ) != NULL )
- {
- TEST_ASSERT( iv_size == block_size );
- TEST_ASSERT( ! mbedtls_cipher_info_has_variable_iv_size( info ) );
- }
- else if( strstr( info->name, "-GCM" ) != NULL )
- {
- TEST_ASSERT( iv_size == block_size - 4 );
- TEST_ASSERT( mbedtls_cipher_info_has_variable_iv_size( info ) );
+ if (strstr(info->name, "-ECB") != NULL) {
+ TEST_ASSERT(iv_size == 0);
+ TEST_ASSERT(!mbedtls_cipher_info_has_variable_iv_size(info));
+ } else if (strstr(info->name, "-CBC") != NULL ||
+ strstr(info->name, "-CTR") != NULL) {
+ TEST_ASSERT(iv_size == block_size);
+ TEST_ASSERT(!mbedtls_cipher_info_has_variable_iv_size(info));
+ } else if (strstr(info->name, "-GCM") != NULL) {
+ TEST_ASSERT(iv_size == block_size - 4);
+ TEST_ASSERT(mbedtls_cipher_info_has_variable_iv_size(info));
}
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
#if defined(MBEDTLS_CIPHER_AUTH_CRYPT)
@@ -110,35 +92,33 @@
* individual ciphers, and it doesn't work with the PSA wrappers. So don't do
* it, and instead start with a fresh context.
*/
-static int cipher_reset_key( mbedtls_cipher_context_t *ctx, int cipher_id,
- int use_psa, size_t tag_len, const data_t *key, int direction )
+static int cipher_reset_key(mbedtls_cipher_context_t *ctx, int cipher_id,
+ int use_psa, size_t tag_len, const data_t *key, int direction)
{
- mbedtls_cipher_free( ctx );
- mbedtls_cipher_init( ctx );
+ mbedtls_cipher_free(ctx);
+ mbedtls_cipher_init(ctx);
#if !defined(MBEDTLS_USE_PSA_CRYPTO) || !defined(MBEDTLS_TEST_DEPRECATED)
(void) use_psa;
(void) tag_len;
#else
- if( use_psa == 1 )
- {
- TEST_ASSERT( 0 == mbedtls_cipher_setup_psa( ctx,
- mbedtls_cipher_info_from_type( cipher_id ),
- tag_len ) );
- }
- else
+ if (use_psa == 1) {
+ TEST_ASSERT(0 == mbedtls_cipher_setup_psa(ctx,
+ mbedtls_cipher_info_from_type(cipher_id),
+ tag_len));
+ } else
#endif /* !MBEDTLS_USE_PSA_CRYPTO || !MBEDTLS_TEST_DEPRECATED */
{
- TEST_ASSERT( 0 == mbedtls_cipher_setup( ctx,
- mbedtls_cipher_info_from_type( cipher_id ) ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(ctx,
+ mbedtls_cipher_info_from_type(cipher_id)));
}
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( ctx, key->x, 8 * key->len,
- direction ) );
- return( 1 );
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(ctx, key->x, 8 * key->len,
+ direction));
+ return 1;
exit:
- return( 0 );
+ return 0;
}
/*
@@ -146,11 +126,13 @@
* return 1 if it is,
* 0 if it isn't.
*/
-int buffer_is_all_zero( const uint8_t *buf, size_t size )
+int buffer_is_all_zero(const uint8_t *buf, size_t size)
{
- for( size_t i = 0; i < size; i++ )
- if( buf[i] != 0 )
+ for (size_t i = 0; i < size; i++) {
+ if (buf[i] != 0) {
return 0;
+ }
+ }
return 1;
}
#endif /* MBEDTLS_CIPHER_AUTH_CRYPT */
@@ -163,23 +145,23 @@
*/
/* BEGIN_CASE */
-void mbedtls_cipher_list( )
+void mbedtls_cipher_list()
{
const int *cipher_type;
- for( cipher_type = mbedtls_cipher_list(); *cipher_type != 0; cipher_type++ )
- {
+ for (cipher_type = mbedtls_cipher_list(); *cipher_type != 0; cipher_type++) {
const mbedtls_cipher_info_t *info =
- mbedtls_cipher_info_from_type( *cipher_type );
- mbedtls_test_set_step( *cipher_type );
- if( ! check_cipher_info( *cipher_type, info ) )
+ mbedtls_cipher_info_from_type(*cipher_type);
+ mbedtls_test_set_step(*cipher_type);
+ if (!check_cipher_info(*cipher_type, info)) {
goto exit;
+ }
}
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_invalid_param_unconditional( )
+void cipher_invalid_param_unconditional()
{
mbedtls_cipher_context_t valid_ctx;
mbedtls_cipher_context_t invalid_ctx;
@@ -189,120 +171,120 @@
int valid_size = sizeof(valid_buffer);
int valid_bitlen = valid_size * 8;
const mbedtls_cipher_info_t *valid_info = mbedtls_cipher_info_from_type(
- *( mbedtls_cipher_list() ) );
+ *(mbedtls_cipher_list()));
size_t size_t_var;
- (void)valid_mode; /* In some configurations this is unused */
+ (void) valid_mode; /* In some configurations this is unused */
- mbedtls_cipher_init( &valid_ctx );
- mbedtls_cipher_init( &invalid_ctx );
+ mbedtls_cipher_init(&valid_ctx);
+ mbedtls_cipher_init(&invalid_ctx);
- TEST_ASSERT( mbedtls_cipher_setup( &valid_ctx, valid_info ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_setup(&valid_ctx, valid_info) == 0);
/* mbedtls_cipher_setup() */
- TEST_ASSERT( mbedtls_cipher_setup( &valid_ctx, NULL ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_setup(&valid_ctx, NULL) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
/* mbedtls_cipher_get_block_size() */
- TEST_ASSERT( mbedtls_cipher_get_block_size( &invalid_ctx ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_get_block_size(&invalid_ctx) == 0);
/* mbedtls_cipher_get_cipher_mode() */
- TEST_ASSERT( mbedtls_cipher_get_cipher_mode( &invalid_ctx ) ==
- MBEDTLS_MODE_NONE );
+ TEST_ASSERT(mbedtls_cipher_get_cipher_mode(&invalid_ctx) ==
+ MBEDTLS_MODE_NONE);
/* mbedtls_cipher_get_iv_size() */
- TEST_ASSERT( mbedtls_cipher_get_iv_size( &invalid_ctx ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_get_iv_size(&invalid_ctx) == 0);
/* mbedtls_cipher_get_type() */
TEST_ASSERT(
- mbedtls_cipher_get_type( &invalid_ctx ) ==
+ mbedtls_cipher_get_type(&invalid_ctx) ==
MBEDTLS_CIPHER_NONE);
/* mbedtls_cipher_get_name() */
- TEST_ASSERT( mbedtls_cipher_get_name( &invalid_ctx ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_get_name(&invalid_ctx) == 0);
/* mbedtls_cipher_get_key_bitlen() */
- TEST_ASSERT( mbedtls_cipher_get_key_bitlen( &invalid_ctx ) ==
- MBEDTLS_KEY_LENGTH_NONE );
+ TEST_ASSERT(mbedtls_cipher_get_key_bitlen(&invalid_ctx) ==
+ MBEDTLS_KEY_LENGTH_NONE);
/* mbedtls_cipher_get_operation() */
- TEST_ASSERT( mbedtls_cipher_get_operation( &invalid_ctx ) ==
- MBEDTLS_OPERATION_NONE );
+ TEST_ASSERT(mbedtls_cipher_get_operation(&invalid_ctx) ==
+ MBEDTLS_OPERATION_NONE);
/* mbedtls_cipher_setkey() */
TEST_ASSERT(
- mbedtls_cipher_setkey( &invalid_ctx,
- valid_buffer,
- valid_bitlen,
- valid_operation ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ mbedtls_cipher_setkey(&invalid_ctx,
+ valid_buffer,
+ valid_bitlen,
+ valid_operation) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
/* mbedtls_cipher_set_iv() */
TEST_ASSERT(
- mbedtls_cipher_set_iv( &invalid_ctx,
- valid_buffer,
- valid_size ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ mbedtls_cipher_set_iv(&invalid_ctx,
+ valid_buffer,
+ valid_size) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
/* mbedtls_cipher_reset() */
- TEST_ASSERT( mbedtls_cipher_reset( &invalid_ctx ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_reset(&invalid_ctx) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
/* mbedtls_cipher_update_ad() */
TEST_ASSERT(
- mbedtls_cipher_update_ad( &invalid_ctx,
- valid_buffer,
- valid_size ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ mbedtls_cipher_update_ad(&invalid_ctx,
+ valid_buffer,
+ valid_size) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
#endif /* defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) */
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
/* mbedtls_cipher_set_padding_mode() */
- TEST_ASSERT( mbedtls_cipher_set_padding_mode( &invalid_ctx, valid_mode ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_set_padding_mode(&invalid_ctx, valid_mode) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
#endif
/* mbedtls_cipher_update() */
TEST_ASSERT(
- mbedtls_cipher_update( &invalid_ctx,
- valid_buffer,
- valid_size,
- valid_buffer,
- &size_t_var ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ mbedtls_cipher_update(&invalid_ctx,
+ valid_buffer,
+ valid_size,
+ valid_buffer,
+ &size_t_var) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
/* mbedtls_cipher_finish() */
TEST_ASSERT(
- mbedtls_cipher_finish( &invalid_ctx,
- valid_buffer,
- &size_t_var ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ mbedtls_cipher_finish(&invalid_ctx,
+ valid_buffer,
+ &size_t_var) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
/* mbedtls_cipher_write_tag() */
TEST_ASSERT(
- mbedtls_cipher_write_tag( &invalid_ctx,
- valid_buffer,
- valid_size ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ mbedtls_cipher_write_tag(&invalid_ctx,
+ valid_buffer,
+ valid_size) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
/* mbedtls_cipher_check_tag() */
TEST_ASSERT(
- mbedtls_cipher_check_tag( &invalid_ctx,
- valid_buffer,
- valid_size ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ mbedtls_cipher_check_tag(&invalid_ctx,
+ valid_buffer,
+ valid_size) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
#endif /* defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) */
exit:
- mbedtls_cipher_free( &invalid_ctx );
- mbedtls_cipher_free( &valid_ctx );
+ mbedtls_cipher_free(&invalid_ctx);
+ mbedtls_cipher_free(&valid_ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_invalid_param_conditional( )
+void cipher_invalid_param_conditional()
{
mbedtls_cipher_context_t valid_ctx;
@@ -313,10 +295,10 @@
TEST_EQUAL(
MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_setkey( &valid_ctx,
- valid_buffer,
- valid_bitlen,
- invalid_operation ) );
+ mbedtls_cipher_setkey(&valid_ctx,
+ valid_buffer,
+ valid_bitlen,
+ invalid_operation));
exit:
;
@@ -324,57 +306,57 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
-void cipher_special_behaviours( )
+void cipher_special_behaviours()
{
const mbedtls_cipher_info_t *cipher_info;
mbedtls_cipher_context_t ctx;
unsigned char input[32];
unsigned char output[32];
-#if defined (MBEDTLS_CIPHER_MODE_CBC)
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
unsigned char iv[32];
#endif
size_t olen = 0;
- mbedtls_cipher_init( &ctx );
- memset( input, 0, sizeof( input ) );
- memset( output, 0, sizeof( output ) );
+ mbedtls_cipher_init(&ctx);
+ memset(input, 0, sizeof(input));
+ memset(output, 0, sizeof(output));
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- memset( iv, 0, sizeof( iv ) );
+ memset(iv, 0, sizeof(iv));
/* Check and get info structures */
- cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_CBC );
- TEST_ASSERT( NULL != cipher_info );
+ cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_CBC);
+ TEST_ASSERT(NULL != cipher_info);
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, cipher_info ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx, cipher_info));
/* IV too big */
- TEST_ASSERT( mbedtls_cipher_set_iv( &ctx, iv, MBEDTLS_MAX_IV_LENGTH + 1 )
- == MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
+ TEST_ASSERT(mbedtls_cipher_set_iv(&ctx, iv, MBEDTLS_MAX_IV_LENGTH + 1)
+ == MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE);
/* IV too small */
- TEST_ASSERT( mbedtls_cipher_set_iv( &ctx, iv, 0 )
- == MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_set_iv(&ctx, iv, 0)
+ == MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- mbedtls_cipher_free( &ctx );
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_free(&ctx);
+ mbedtls_cipher_init(&ctx);
#endif /* MBEDTLS_CIPHER_MODE_CBC */
- cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB );
- TEST_ASSERT( NULL != cipher_info );
+ cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB);
+ TEST_ASSERT(NULL != cipher_info);
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, cipher_info ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx, cipher_info));
/* Update ECB with partial block */
- TEST_ASSERT( mbedtls_cipher_update( &ctx, input, 1, output, &olen )
- == MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED );
+ TEST_ASSERT(mbedtls_cipher_update(&ctx, input, 1, output, &olen)
+ == MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED);
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void enc_dec_buf( int cipher_id, char * cipher_string, int key_len,
- int length_val, int pad_mode )
+void enc_dec_buf(int cipher_id, char *cipher_string, int key_len,
+ int length_val, int pad_mode)
{
size_t length = length_val, outlen, total_len, i, block_size, iv_len;
unsigned char key[64];
@@ -392,30 +374,29 @@
/*
* Prepare contexts
*/
- mbedtls_cipher_init( &ctx_dec );
- mbedtls_cipher_init( &ctx_enc );
+ mbedtls_cipher_init(&ctx_dec);
+ mbedtls_cipher_init(&ctx_enc);
- memset( key, 0x2a, sizeof( key ) );
+ memset(key, 0x2a, sizeof(key));
/* Check and get info structures */
- cipher_info = mbedtls_cipher_info_from_type( cipher_id );
- TEST_ASSERT( NULL != cipher_info );
- TEST_ASSERT( mbedtls_cipher_info_from_string( cipher_string ) == cipher_info );
- TEST_ASSERT( strcmp( mbedtls_cipher_info_get_name( cipher_info ),
- cipher_string ) == 0 );
+ cipher_info = mbedtls_cipher_info_from_type(cipher_id);
+ TEST_ASSERT(NULL != cipher_info);
+ TEST_ASSERT(mbedtls_cipher_info_from_string(cipher_string) == cipher_info);
+ TEST_ASSERT(strcmp(mbedtls_cipher_info_get_name(cipher_info),
+ cipher_string) == 0);
/* Initialise enc and dec contexts */
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_enc, cipher_info ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx_dec, cipher_info));
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx_enc, cipher_info));
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_dec, key, key_len, MBEDTLS_DECRYPT ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_enc, key, key_len, MBEDTLS_ENCRYPT ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx_dec, key, key_len, MBEDTLS_DECRYPT));
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx_enc, key, key_len, MBEDTLS_ENCRYPT));
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
- if( -1 != pad_mode )
- {
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx_dec, pad_mode ) );
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx_enc, pad_mode ) );
+ if (-1 != pad_mode) {
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx_dec, pad_mode));
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx_enc, pad_mode));
}
#else
(void) pad_mode;
@@ -424,97 +405,97 @@
/*
* Do a few encode/decode cycles
*/
- for( i = 0; i < 3; i++ )
- {
- memset( iv , 0x00 + i, sizeof( iv ) );
- memset( ad, 0x10 + i, sizeof( ad ) );
- memset( inbuf, 0x20 + i, sizeof( inbuf ) );
+ for (i = 0; i < 3; i++) {
+ memset(iv, 0x00 + i, sizeof(iv));
+ memset(ad, 0x10 + i, sizeof(ad));
+ memset(inbuf, 0x20 + i, sizeof(inbuf));
- memset( encbuf, 0, sizeof( encbuf ) );
- memset( decbuf, 0, sizeof( decbuf ) );
- memset( tag, 0, sizeof( tag ) );
+ memset(encbuf, 0, sizeof(encbuf));
+ memset(decbuf, 0, sizeof(decbuf));
+ memset(tag, 0, sizeof(tag));
- if( NULL != strstr( cipher_info->name, "CCM*-NO-TAG") )
- iv_len = 13; /* For CCM, IV length is expected to be between 7 and 13 bytes.
- * For CCM*-NO-TAG, IV length must be exactly 13 bytes long. */
- else if( cipher_info->type == MBEDTLS_CIPHER_CHACHA20 ||
- cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 )
- iv_len = 12;
- else
- iv_len = sizeof(iv);
+ if (NULL != strstr(cipher_info->name, "CCM*-NO-TAG")) {
+ iv_len = 13; /* For CCM, IV length is expected to be between 7 and 13 bytes.
+ * For CCM*-NO-TAG, IV length must be exactly 13 bytes long. */
+ } else if (cipher_info->type == MBEDTLS_CIPHER_CHACHA20 ||
+ cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) {
+ iv_len = 12;
+ } else {
+ iv_len = sizeof(iv);
+ }
- TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx_dec, iv, iv_len ) );
- TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx_enc, iv, iv_len ) );
+ TEST_ASSERT(0 == mbedtls_cipher_set_iv(&ctx_dec, iv, iv_len));
+ TEST_ASSERT(0 == mbedtls_cipher_set_iv(&ctx_enc, iv, iv_len));
- TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx_dec ) );
- TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx_enc ) );
+ TEST_ASSERT(0 == mbedtls_cipher_reset(&ctx_dec));
+ TEST_ASSERT(0 == mbedtls_cipher_reset(&ctx_enc));
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- int expected = ( cipher_info->mode == MBEDTLS_MODE_GCM ||
- cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) ?
- 0 : MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
+ int expected = (cipher_info->mode == MBEDTLS_MODE_GCM ||
+ cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) ?
+ 0 : MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- TEST_EQUAL( expected, mbedtls_cipher_update_ad( &ctx_dec, ad, sizeof(ad) - i ) );
- TEST_EQUAL( expected, mbedtls_cipher_update_ad( &ctx_enc, ad, sizeof(ad) - i ) );
+ TEST_EQUAL(expected, mbedtls_cipher_update_ad(&ctx_dec, ad, sizeof(ad) - i));
+ TEST_EQUAL(expected, mbedtls_cipher_update_ad(&ctx_enc, ad, sizeof(ad) - i));
#endif
- block_size = mbedtls_cipher_get_block_size( &ctx_enc );
- TEST_ASSERT( block_size != 0 );
+ block_size = mbedtls_cipher_get_block_size(&ctx_enc);
+ TEST_ASSERT(block_size != 0);
- /* encode length number of bytes from inbuf */
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
- total_len = outlen;
+ /* encode length number of bytes from inbuf */
+ TEST_ASSERT(0 == mbedtls_cipher_update(&ctx_enc, inbuf, length, encbuf, &outlen));
+ total_len = outlen;
- TEST_ASSERT( total_len == length ||
- ( total_len % block_size == 0 &&
- total_len < length &&
- total_len + block_size > length ) );
+ TEST_ASSERT(total_len == length ||
+ (total_len % block_size == 0 &&
+ total_len < length &&
+ total_len + block_size > length));
- TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
- total_len += outlen;
+ TEST_ASSERT(0 == mbedtls_cipher_finish(&ctx_enc, encbuf + outlen, &outlen));
+ total_len += outlen;
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- TEST_EQUAL( expected, mbedtls_cipher_write_tag( &ctx_enc, tag, sizeof(tag) ) );
+ TEST_EQUAL(expected, mbedtls_cipher_write_tag(&ctx_enc, tag, sizeof(tag)));
#endif
- TEST_ASSERT( total_len == length ||
- ( total_len % block_size == 0 &&
- total_len > length &&
- total_len <= length + block_size ) );
+ TEST_ASSERT(total_len == length ||
+ (total_len % block_size == 0 &&
+ total_len > length &&
+ total_len <= length + block_size));
- /* decode the previously encoded string */
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_dec, encbuf, total_len, decbuf, &outlen ) );
- total_len = outlen;
+ /* decode the previously encoded string */
+ TEST_ASSERT(0 == mbedtls_cipher_update(&ctx_dec, encbuf, total_len, decbuf, &outlen));
+ total_len = outlen;
- TEST_ASSERT( total_len == length ||
- ( total_len % block_size == 0 &&
- total_len < length &&
- total_len + block_size >= length ) );
+ TEST_ASSERT(total_len == length ||
+ (total_len % block_size == 0 &&
+ total_len < length &&
+ total_len + block_size >= length));
- TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
- total_len += outlen;
+ TEST_ASSERT(0 == mbedtls_cipher_finish(&ctx_dec, decbuf + outlen, &outlen));
+ total_len += outlen;
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- TEST_EQUAL( expected, mbedtls_cipher_check_tag( &ctx_dec, tag, sizeof(tag) ) );
+ TEST_EQUAL(expected, mbedtls_cipher_check_tag(&ctx_dec, tag, sizeof(tag)));
#endif
- /* check result */
- TEST_ASSERT( total_len == length );
- TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
+ /* check result */
+ TEST_ASSERT(total_len == length);
+ TEST_ASSERT(0 == memcmp(inbuf, decbuf, length));
}
/*
* Done
*/
exit:
- mbedtls_cipher_free( &ctx_dec );
- mbedtls_cipher_free( &ctx_enc );
+ mbedtls_cipher_free(&ctx_dec);
+ mbedtls_cipher_free(&ctx_enc);
}
/* END_CASE */
/* BEGIN_CASE */
-void enc_fail( int cipher_id, int pad_mode, int key_len, int length_val,
- int ret )
+void enc_fail(int cipher_id, int pad_mode, int key_len, int length_val,
+ int ret)
{
size_t length = length_val;
unsigned char key[32];
@@ -528,50 +509,50 @@
size_t outlen = 0;
- memset( key, 0, 32 );
- memset( iv , 0, 16 );
+ memset(key, 0, 32);
+ memset(iv, 0, 16);
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
- memset( inbuf, 5, 64 );
- memset( encbuf, 0, 64 );
+ memset(inbuf, 5, 64);
+ memset(encbuf, 0, 64);
/* Check and get info structures */
- cipher_info = mbedtls_cipher_info_from_type( cipher_id );
- TEST_ASSERT( NULL != cipher_info );
+ cipher_info = mbedtls_cipher_info_from_type(cipher_id);
+ TEST_ASSERT(NULL != cipher_info);
/* Initialise context */
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, cipher_info ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, key_len, MBEDTLS_ENCRYPT ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx, cipher_info));
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx, key, key_len, MBEDTLS_ENCRYPT));
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) );
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx, pad_mode));
#else
(void) pad_mode;
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
- TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx, iv, 16 ) );
- TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx ) );
+ TEST_ASSERT(0 == mbedtls_cipher_set_iv(&ctx, iv, 16));
+ TEST_ASSERT(0 == mbedtls_cipher_reset(&ctx));
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- int expected = ( cipher_info->mode == MBEDTLS_MODE_GCM ||
- cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) ?
+ int expected = (cipher_info->mode == MBEDTLS_MODE_GCM ||
+ cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) ?
0 : MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- TEST_EQUAL( expected, mbedtls_cipher_update_ad( &ctx, NULL, 0 ) );
+ TEST_EQUAL(expected, mbedtls_cipher_update_ad(&ctx, NULL, 0));
#endif
/* encode length number of bytes from inbuf */
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx, inbuf, length, encbuf, &outlen ) );
- TEST_ASSERT( ret == mbedtls_cipher_finish( &ctx, encbuf + outlen, &outlen ) );
+ TEST_ASSERT(0 == mbedtls_cipher_update(&ctx, inbuf, length, encbuf, &outlen));
+ TEST_ASSERT(ret == mbedtls_cipher_finish(&ctx, encbuf + outlen, &outlen));
/* done */
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void dec_empty_buf( int cipher,
- int expected_update_ret,
- int expected_finish_ret )
+void dec_empty_buf(int cipher,
+ int expected_update_ret,
+ int expected_finish_ret)
{
unsigned char key[32];
@@ -586,53 +567,53 @@
size_t outlen = 0;
- memset( key, 0, 32 );
+ memset(key, 0, 32);
- mbedtls_cipher_init( &ctx_dec );
+ mbedtls_cipher_init(&ctx_dec);
- memset( encbuf, 0, 64 );
- memset( decbuf, 0, 64 );
+ memset(encbuf, 0, 64);
+ memset(decbuf, 0, 64);
/* Initialise context */
- cipher_info = mbedtls_cipher_info_from_type( cipher );
- TEST_ASSERT( NULL != cipher_info);
+ cipher_info = mbedtls_cipher_info_from_type(cipher);
+ TEST_ASSERT(NULL != cipher_info);
- if( cipher_info->type == MBEDTLS_CIPHER_CHACHA20 ||
- cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 )
+ if (cipher_info->type == MBEDTLS_CIPHER_CHACHA20 ||
+ cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) {
iv_len = 12;
+ }
- ASSERT_ALLOC( iv, iv_len );
- memset( iv , 0, iv_len );
+ ASSERT_ALLOC(iv, iv_len);
+ memset(iv, 0, iv_len);
- TEST_ASSERT( sizeof(key) * 8 >= cipher_info->key_bitlen );
+ TEST_ASSERT(sizeof(key) * 8 >= cipher_info->key_bitlen);
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx_dec, cipher_info));
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_dec,
- key, cipher_info->key_bitlen,
- MBEDTLS_DECRYPT ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx_dec,
+ key, cipher_info->key_bitlen,
+ MBEDTLS_DECRYPT));
- TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx_dec, iv, iv_len ) );
+ TEST_ASSERT(0 == mbedtls_cipher_set_iv(&ctx_dec, iv, iv_len));
- TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx_dec ) );
+ TEST_ASSERT(0 == mbedtls_cipher_reset(&ctx_dec));
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- int expected = ( cipher_info->mode == MBEDTLS_MODE_GCM ||
- cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) ?
+ int expected = (cipher_info->mode == MBEDTLS_MODE_GCM ||
+ cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) ?
0 : MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- TEST_EQUAL( expected, mbedtls_cipher_update_ad( &ctx_dec, NULL, 0 ) );
+ TEST_EQUAL(expected, mbedtls_cipher_update_ad(&ctx_dec, NULL, 0));
#endif
/* decode 0-byte string */
- TEST_ASSERT( expected_update_ret ==
- mbedtls_cipher_update( &ctx_dec, encbuf, 0, decbuf, &outlen ) );
- TEST_ASSERT( 0 == outlen );
+ TEST_ASSERT(expected_update_ret ==
+ mbedtls_cipher_update(&ctx_dec, encbuf, 0, decbuf, &outlen));
+ TEST_ASSERT(0 == outlen);
- if ( expected_finish_ret == 0 &&
- ( cipher_info->mode == MBEDTLS_MODE_CBC ||
- cipher_info->mode == MBEDTLS_MODE_ECB ) )
- {
+ if (expected_finish_ret == 0 &&
+ (cipher_info->mode == MBEDTLS_MODE_CBC ||
+ cipher_info->mode == MBEDTLS_MODE_ECB)) {
/* Non-CBC and non-ECB ciphers are OK with decrypting empty buffers and
* return success, not MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED, when
* decrypting an empty buffer.
@@ -641,21 +622,21 @@
expected_finish_ret = MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED;
}
- TEST_ASSERT( expected_finish_ret == mbedtls_cipher_finish(
- &ctx_dec, decbuf + outlen, &outlen ) );
- TEST_ASSERT( 0 == outlen );
+ TEST_ASSERT(expected_finish_ret == mbedtls_cipher_finish(
+ &ctx_dec, decbuf + outlen, &outlen));
+ TEST_ASSERT(0 == outlen);
exit:
- mbedtls_free( iv );
- mbedtls_cipher_free( &ctx_dec );
+ mbedtls_free(iv);
+ mbedtls_cipher_free(&ctx_dec);
}
/* END_CASE */
/* BEGIN_CASE */
-void enc_dec_buf_multipart( int cipher_id, int key_len, int first_length_val,
- int second_length_val, int pad_mode,
- int first_encrypt_output_len, int second_encrypt_output_len,
- int first_decrypt_output_len, int second_decrypt_output_len )
+void enc_dec_buf_multipart(int cipher_id, int key_len, int first_length_val,
+ int second_length_val, int pad_mode,
+ int first_encrypt_output_len, int second_encrypt_output_len,
+ int first_decrypt_output_len, int second_decrypt_output_len)
{
size_t first_length = first_length_val;
size_t second_length = second_length_val;
@@ -676,122 +657,128 @@
size_t outlen = 0;
size_t totaloutlen = 0;
- memset( key, 0, 32 );
- memset( iv , 0, 16 );
+ memset(key, 0, 32);
+ memset(iv, 0, 16);
- mbedtls_cipher_init( &ctx_dec );
- mbedtls_cipher_init( &ctx_enc );
+ mbedtls_cipher_init(&ctx_dec);
+ mbedtls_cipher_init(&ctx_enc);
- memset( inbuf, 5, 64 );
- memset( encbuf, 0, 64 );
- memset( decbuf, 0, 64 );
+ memset(inbuf, 5, 64);
+ memset(encbuf, 0, 64);
+ memset(decbuf, 0, 64);
/* Initialise enc and dec contexts */
- cipher_info = mbedtls_cipher_info_from_type( cipher_id );
- TEST_ASSERT( NULL != cipher_info);
+ cipher_info = mbedtls_cipher_info_from_type(cipher_id);
+ TEST_ASSERT(NULL != cipher_info);
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_enc, cipher_info ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx_dec, cipher_info));
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx_enc, cipher_info));
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_dec, key, key_len, MBEDTLS_DECRYPT ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_enc, key, key_len, MBEDTLS_ENCRYPT ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx_dec, key, key_len, MBEDTLS_DECRYPT));
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx_enc, key, key_len, MBEDTLS_ENCRYPT));
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
- if( -1 != pad_mode )
- {
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx_dec, pad_mode ) );
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx_enc, pad_mode ) );
+ if (-1 != pad_mode) {
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx_dec, pad_mode));
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx_enc, pad_mode));
}
#else
(void) pad_mode;
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
- if( NULL != strstr( cipher_info->name, "CCM*-NO-TAG") )
+ if (NULL != strstr(cipher_info->name, "CCM*-NO-TAG")) {
iv_len = 13; /* For CCM, IV length is expected to be between 7 and 13 bytes.
* For CCM*-NO-TAG, IV length must be exactly 13 bytes long. */
- else if( cipher_info->type == MBEDTLS_CIPHER_CHACHA20 ||
- cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 )
+ } else if (cipher_info->type == MBEDTLS_CIPHER_CHACHA20 ||
+ cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) {
iv_len = 12;
- else
+ } else {
iv_len = sizeof(iv);
+ }
- TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx_dec, iv, iv_len ) );
- TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx_enc, iv, iv_len ) );
+ TEST_ASSERT(0 == mbedtls_cipher_set_iv(&ctx_dec, iv, iv_len));
+ TEST_ASSERT(0 == mbedtls_cipher_set_iv(&ctx_enc, iv, iv_len));
- TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx_dec ) );
- TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx_enc ) );
+ TEST_ASSERT(0 == mbedtls_cipher_reset(&ctx_dec));
+ TEST_ASSERT(0 == mbedtls_cipher_reset(&ctx_enc));
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- int expected = ( cipher_info->mode == MBEDTLS_MODE_GCM ||
- cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) ?
+ int expected = (cipher_info->mode == MBEDTLS_MODE_GCM ||
+ cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) ?
0 : MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- TEST_EQUAL( expected, mbedtls_cipher_update_ad( &ctx_dec, NULL, 0 ) );
- TEST_EQUAL( expected, mbedtls_cipher_update_ad( &ctx_enc, NULL, 0 ) );
+ TEST_EQUAL(expected, mbedtls_cipher_update_ad(&ctx_dec, NULL, 0));
+ TEST_EQUAL(expected, mbedtls_cipher_update_ad(&ctx_enc, NULL, 0));
#endif
- block_size = mbedtls_cipher_get_block_size( &ctx_enc );
- TEST_ASSERT( block_size != 0 );
+ block_size = mbedtls_cipher_get_block_size(&ctx_enc);
+ TEST_ASSERT(block_size != 0);
/* encode length number of bytes from inbuf */
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
- TEST_ASSERT( (size_t)first_encrypt_output_len == outlen );
+ TEST_ASSERT(0 == mbedtls_cipher_update(&ctx_enc, inbuf, first_length, encbuf, &outlen));
+ TEST_ASSERT((size_t) first_encrypt_output_len == outlen);
totaloutlen = outlen;
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
- TEST_ASSERT( (size_t)second_encrypt_output_len == outlen );
+ TEST_ASSERT(0 ==
+ mbedtls_cipher_update(&ctx_enc, inbuf + first_length, second_length,
+ encbuf + totaloutlen,
+ &outlen));
+ TEST_ASSERT((size_t) second_encrypt_output_len == outlen);
totaloutlen += outlen;
- TEST_ASSERT( totaloutlen == length ||
- ( totaloutlen % block_size == 0 &&
- totaloutlen < length &&
- totaloutlen + block_size > length ) );
+ TEST_ASSERT(totaloutlen == length ||
+ (totaloutlen % block_size == 0 &&
+ totaloutlen < length &&
+ totaloutlen + block_size > length));
- TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
+ TEST_ASSERT(0 == mbedtls_cipher_finish(&ctx_enc, encbuf + totaloutlen, &outlen));
totaloutlen += outlen;
- TEST_ASSERT( totaloutlen == length ||
- ( totaloutlen % block_size == 0 &&
- totaloutlen > length &&
- totaloutlen <= length + block_size ) );
+ TEST_ASSERT(totaloutlen == length ||
+ (totaloutlen % block_size == 0 &&
+ totaloutlen > length &&
+ totaloutlen <= length + block_size));
/* decode the previously encoded string */
second_length = totaloutlen - first_length;
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_dec, encbuf, first_length, decbuf, &outlen ) );
- TEST_ASSERT( (size_t)first_decrypt_output_len == outlen );
+ TEST_ASSERT(0 == mbedtls_cipher_update(&ctx_dec, encbuf, first_length, decbuf, &outlen));
+ TEST_ASSERT((size_t) first_decrypt_output_len == outlen);
totaloutlen = outlen;
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_dec, encbuf + first_length, second_length, decbuf + totaloutlen, &outlen ) );
- TEST_ASSERT( (size_t)second_decrypt_output_len == outlen );
+ TEST_ASSERT(0 ==
+ mbedtls_cipher_update(&ctx_dec, encbuf + first_length, second_length,
+ decbuf + totaloutlen,
+ &outlen));
+ TEST_ASSERT((size_t) second_decrypt_output_len == outlen);
totaloutlen += outlen;
- TEST_ASSERT( totaloutlen == length ||
- ( totaloutlen % block_size == 0 &&
- totaloutlen < length &&
- totaloutlen + block_size >= length ) );
+ TEST_ASSERT(totaloutlen == length ||
+ (totaloutlen % block_size == 0 &&
+ totaloutlen < length &&
+ totaloutlen + block_size >= length));
- TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_dec, decbuf + totaloutlen, &outlen ) );
+ TEST_ASSERT(0 == mbedtls_cipher_finish(&ctx_dec, decbuf + totaloutlen, &outlen));
totaloutlen += outlen;
- TEST_ASSERT( totaloutlen == length );
+ TEST_ASSERT(totaloutlen == length);
- TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
+ TEST_ASSERT(0 == memcmp(inbuf, decbuf, length));
exit:
- mbedtls_cipher_free( &ctx_dec );
- mbedtls_cipher_free( &ctx_enc );
+ mbedtls_cipher_free(&ctx_dec);
+ mbedtls_cipher_free(&ctx_enc);
}
/* END_CASE */
/* BEGIN_CASE */
-void decrypt_test_vec( int cipher_id, int pad_mode, data_t * key,
- data_t * iv, data_t * cipher,
- data_t * clear, data_t * ad, data_t * tag,
- int finish_result, int tag_result )
+void decrypt_test_vec(int cipher_id, int pad_mode, data_t *key,
+ data_t *iv, data_t *cipher,
+ data_t *clear, data_t *ad, data_t *tag,
+ int finish_result, int tag_result)
{
unsigned char output[265];
mbedtls_cipher_context_t ctx;
size_t outlen, total_len;
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
- memset( output, 0x00, sizeof( output ) );
+ memset(output, 0x00, sizeof(output));
#if !defined(MBEDTLS_GCM_C) && !defined(MBEDTLS_CHACHAPOLY_C)
((void) ad);
@@ -799,56 +786,56 @@
#endif
/* Prepare context */
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx,
- mbedtls_cipher_info_from_type( cipher_id ) ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key->x, 8 * key->len, MBEDTLS_DECRYPT ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx,
+ mbedtls_cipher_info_from_type(cipher_id)));
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx, key->x, 8 * key->len, MBEDTLS_DECRYPT));
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
- if( pad_mode != -1 )
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) );
+ if (pad_mode != -1) {
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx, pad_mode));
+ }
#else
(void) pad_mode;
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
- TEST_ASSERT( 0 == mbedtls_cipher_set_iv( &ctx, iv->x, iv->len ) );
- TEST_ASSERT( 0 == mbedtls_cipher_reset( &ctx ) );
+ TEST_ASSERT(0 == mbedtls_cipher_set_iv(&ctx, iv->x, iv->len));
+ TEST_ASSERT(0 == mbedtls_cipher_reset(&ctx));
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- int expected = ( ctx.cipher_info->mode == MBEDTLS_MODE_GCM ||
- ctx.cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) ?
+ int expected = (ctx.cipher_info->mode == MBEDTLS_MODE_GCM ||
+ ctx.cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) ?
0 : MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- TEST_EQUAL( expected, mbedtls_cipher_update_ad( &ctx, ad->x, ad->len ) );
+ TEST_EQUAL(expected, mbedtls_cipher_update_ad(&ctx, ad->x, ad->len));
#endif
/* decode buffer and check tag->x */
total_len = 0;
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx, cipher->x, cipher->len, output, &outlen ) );
+ TEST_ASSERT(0 == mbedtls_cipher_update(&ctx, cipher->x, cipher->len, output, &outlen));
total_len += outlen;
- TEST_ASSERT( finish_result == mbedtls_cipher_finish( &ctx, output + outlen,
- &outlen ) );
+ TEST_ASSERT(finish_result == mbedtls_cipher_finish(&ctx, output + outlen,
+ &outlen));
total_len += outlen;
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- int tag_expected = ( ctx.cipher_info->mode == MBEDTLS_MODE_GCM ||
- ctx.cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) ?
+ int tag_expected = (ctx.cipher_info->mode == MBEDTLS_MODE_GCM ||
+ ctx.cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305) ?
tag_result : MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- TEST_EQUAL( tag_expected, mbedtls_cipher_check_tag( &ctx, tag->x, tag->len ) );
+ TEST_EQUAL(tag_expected, mbedtls_cipher_check_tag(&ctx, tag->x, tag->len));
#endif
/* check plaintext only if everything went fine */
- if( 0 == finish_result && 0 == tag_result )
- {
- TEST_ASSERT( total_len == clear->len );
- TEST_ASSERT( 0 == memcmp( output, clear->x, clear->len ) );
+ if (0 == finish_result && 0 == tag_result) {
+ TEST_ASSERT(total_len == clear->len);
+ TEST_ASSERT(0 == memcmp(output, clear->x, clear->len));
}
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_AUTH_CRYPT */
-void auth_crypt_tv( int cipher_id, data_t * key, data_t * iv,
- data_t * ad, data_t * cipher, data_t * tag,
- char * result, data_t * clear, int use_psa )
+void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
+ data_t *ad, data_t *cipher, data_t *tag,
+ char *result, data_t *clear, int use_psa)
{
/*
* Take an AEAD ciphertext + tag and perform a pair
@@ -873,19 +860,23 @@
/* Null pointers are documented as valid for inputs of length 0.
* The test framework passes non-null pointers, so set them to NULL.
* key, cipher and tag can't be empty. */
- if( iv->len == 0 )
+ if (iv->len == 0) {
iv->x = NULL;
- if( ad->len == 0 )
+ }
+ if (ad->len == 0) {
ad->x = NULL;
- if( clear->len == 0 )
+ }
+ if (clear->len == 0) {
clear->x = NULL;
+ }
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
/* Initialize PSA Crypto */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- if( use_psa == 1 )
- PSA_ASSERT( psa_crypto_init( ) );
+ if (use_psa == 1) {
+ PSA_ASSERT(psa_crypto_init());
+ }
#else
(void) use_psa;
#endif
@@ -904,277 +895,276 @@
/*
* Prepare context for decryption
*/
- if( ! cipher_reset_key( &ctx, cipher_id, use_psa, tag->len, key,
- MBEDTLS_DECRYPT ) )
+ if (!cipher_reset_key(&ctx, cipher_id, use_psa, tag->len, key,
+ MBEDTLS_DECRYPT)) {
goto exit;
+ }
/*
* prepare buffer for decryption
* (we need the tag appended to the ciphertext)
*/
cipher_plus_tag_len = cipher->len + tag->len;
- ASSERT_ALLOC( cipher_plus_tag, cipher_plus_tag_len );
- memcpy( cipher_plus_tag, cipher->x, cipher->len );
- memcpy( cipher_plus_tag + cipher->len, tag->x, tag->len );
+ ASSERT_ALLOC(cipher_plus_tag, cipher_plus_tag_len);
+ memcpy(cipher_plus_tag, cipher->x, cipher->len);
+ memcpy(cipher_plus_tag + cipher->len, tag->x, tag->len);
/*
* Compute length of output buffer according to the documentation
*/
- if( using_nist_kw )
+ if (using_nist_kw) {
decrypt_buf_len = cipher_plus_tag_len - 8;
- else
+ } else {
decrypt_buf_len = cipher_plus_tag_len - tag->len;
+ }
/*
* Try decrypting to a buffer that's 1B too small
*/
- if( decrypt_buf_len != 0 )
- {
- ASSERT_ALLOC( decrypt_buf, decrypt_buf_len - 1 );
+ if (decrypt_buf_len != 0) {
+ ASSERT_ALLOC(decrypt_buf, decrypt_buf_len - 1);
outlen = 0;
- ret = mbedtls_cipher_auth_decrypt_ext( &ctx, iv->x, iv->len,
- ad->x, ad->len, cipher_plus_tag, cipher_plus_tag_len,
- decrypt_buf, decrypt_buf_len - 1, &outlen, tag->len );
- TEST_ASSERT( ret == MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ ret = mbedtls_cipher_auth_decrypt_ext(&ctx, iv->x, iv->len,
+ ad->x, ad->len, cipher_plus_tag, cipher_plus_tag_len,
+ decrypt_buf, decrypt_buf_len - 1, &outlen, tag->len);
+ TEST_ASSERT(ret == MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- mbedtls_free( decrypt_buf );
+ mbedtls_free(decrypt_buf);
decrypt_buf = NULL;
}
/*
* Authenticate and decrypt, and check result
*/
- ASSERT_ALLOC( decrypt_buf, decrypt_buf_len );
+ ASSERT_ALLOC(decrypt_buf, decrypt_buf_len);
outlen = 0;
- ret = mbedtls_cipher_auth_decrypt_ext( &ctx, iv->x, iv->len,
- ad->x, ad->len, cipher_plus_tag, cipher_plus_tag_len,
- decrypt_buf, decrypt_buf_len, &outlen, tag->len );
+ ret = mbedtls_cipher_auth_decrypt_ext(&ctx, iv->x, iv->len,
+ ad->x, ad->len, cipher_plus_tag, cipher_plus_tag_len,
+ decrypt_buf, decrypt_buf_len, &outlen, tag->len);
- if( strcmp( result, "FAIL" ) == 0 )
- {
- TEST_ASSERT( ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED );
- TEST_ASSERT( buffer_is_all_zero( decrypt_buf, decrypt_buf_len ) );
- }
- else
- {
- TEST_ASSERT( ret == 0 );
- ASSERT_COMPARE( decrypt_buf, outlen, clear->x, clear->len );
+ if (strcmp(result, "FAIL") == 0) {
+ TEST_ASSERT(ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED);
+ TEST_ASSERT(buffer_is_all_zero(decrypt_buf, decrypt_buf_len));
+ } else {
+ TEST_ASSERT(ret == 0);
+ ASSERT_COMPARE(decrypt_buf, outlen, clear->x, clear->len);
}
- mbedtls_free( decrypt_buf );
+ mbedtls_free(decrypt_buf);
decrypt_buf = NULL;
/*
* Encrypt back if test data was authentic
*/
- if( strcmp( result, "FAIL" ) != 0 )
- {
+ if (strcmp(result, "FAIL") != 0) {
/* prepare context for encryption */
- if( ! cipher_reset_key( &ctx, cipher_id, use_psa, tag->len, key,
- MBEDTLS_ENCRYPT ) )
+ if (!cipher_reset_key(&ctx, cipher_id, use_psa, tag->len, key,
+ MBEDTLS_ENCRYPT)) {
goto exit;
+ }
/*
* Compute size of output buffer according to documentation
*/
- if( using_nist_kw )
- {
+ if (using_nist_kw) {
encrypt_buf_len = clear->len + 8;
- if( using_nist_kw_padding && encrypt_buf_len % 8 != 0 )
+ if (using_nist_kw_padding && encrypt_buf_len % 8 != 0) {
encrypt_buf_len += 8 - encrypt_buf_len % 8;
- }
- else
- {
+ }
+ } else {
encrypt_buf_len = clear->len + tag->len;
}
/*
* Try encrypting with an output buffer that's 1B too small
*/
- ASSERT_ALLOC( encrypt_buf, encrypt_buf_len - 1 );
+ ASSERT_ALLOC(encrypt_buf, encrypt_buf_len - 1);
outlen = 0;
- ret = mbedtls_cipher_auth_encrypt_ext( &ctx, iv->x, iv->len,
- ad->x, ad->len, clear->x, clear->len,
- encrypt_buf, encrypt_buf_len - 1, &outlen, tag->len );
- TEST_ASSERT( ret != 0 );
+ ret = mbedtls_cipher_auth_encrypt_ext(&ctx, iv->x, iv->len,
+ ad->x, ad->len, clear->x, clear->len,
+ encrypt_buf, encrypt_buf_len - 1, &outlen, tag->len);
+ TEST_ASSERT(ret != 0);
- mbedtls_free( encrypt_buf );
+ mbedtls_free(encrypt_buf);
encrypt_buf = NULL;
/*
* Encrypt and check the result
*/
- ASSERT_ALLOC( encrypt_buf, encrypt_buf_len );
+ ASSERT_ALLOC(encrypt_buf, encrypt_buf_len);
outlen = 0;
- ret = mbedtls_cipher_auth_encrypt_ext( &ctx, iv->x, iv->len,
- ad->x, ad->len, clear->x, clear->len,
- encrypt_buf, encrypt_buf_len, &outlen, tag->len );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_cipher_auth_encrypt_ext(&ctx, iv->x, iv->len,
+ ad->x, ad->len, clear->x, clear->len,
+ encrypt_buf, encrypt_buf_len, &outlen, tag->len);
+ TEST_ASSERT(ret == 0);
- TEST_ASSERT( outlen == cipher->len + tag->len );
- TEST_ASSERT( memcmp( encrypt_buf, cipher->x, cipher->len ) == 0 );
- TEST_ASSERT( memcmp( encrypt_buf + cipher->len,
- tag->x, tag->len ) == 0 );
+ TEST_ASSERT(outlen == cipher->len + tag->len);
+ TEST_ASSERT(memcmp(encrypt_buf, cipher->x, cipher->len) == 0);
+ TEST_ASSERT(memcmp(encrypt_buf + cipher->len,
+ tag->x, tag->len) == 0);
- mbedtls_free( encrypt_buf );
+ mbedtls_free(encrypt_buf);
encrypt_buf = NULL;
}
exit:
- mbedtls_cipher_free( &ctx );
- mbedtls_free( decrypt_buf );
- mbedtls_free( encrypt_buf );
- mbedtls_free( cipher_plus_tag );
+ mbedtls_cipher_free(&ctx);
+ mbedtls_free(decrypt_buf);
+ mbedtls_free(encrypt_buf);
+ mbedtls_free(cipher_plus_tag);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- if( use_psa == 1 )
- PSA_DONE( );
+ if (use_psa == 1) {
+ PSA_DONE();
+ }
#endif /* MBEDTLS_USE_PSA_CRYPTO */
}
/* END_CASE */
/* BEGIN_CASE */
-void test_vec_ecb( int cipher_id, int operation, data_t * key,
- data_t * input, data_t * result, int finish_result
- )
+void test_vec_ecb(int cipher_id, int operation, data_t *key,
+ data_t *input, data_t *result, int finish_result
+ )
{
mbedtls_cipher_context_t ctx;
unsigned char output[32];
size_t outlen;
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
- memset( output, 0x00, sizeof( output ) );
+ memset(output, 0x00, sizeof(output));
/* Prepare context */
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx,
- mbedtls_cipher_info_from_type( cipher_id ) ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx,
+ mbedtls_cipher_info_from_type(cipher_id)));
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key->x, 8 * key->len, operation ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx, key->x, 8 * key->len, operation));
- TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx, input->x,
- mbedtls_cipher_get_block_size( &ctx ),
- output, &outlen ) );
- TEST_ASSERT( outlen == mbedtls_cipher_get_block_size( &ctx ) );
- TEST_ASSERT( finish_result == mbedtls_cipher_finish( &ctx, output + outlen,
- &outlen ) );
- TEST_ASSERT( 0 == outlen );
+ TEST_ASSERT(0 == mbedtls_cipher_update(&ctx, input->x,
+ mbedtls_cipher_get_block_size(&ctx),
+ output, &outlen));
+ TEST_ASSERT(outlen == mbedtls_cipher_get_block_size(&ctx));
+ TEST_ASSERT(finish_result == mbedtls_cipher_finish(&ctx, output + outlen,
+ &outlen));
+ TEST_ASSERT(0 == outlen);
/* check plaintext only if everything went fine */
- if( 0 == finish_result )
- TEST_ASSERT( 0 == memcmp( output, result->x,
- mbedtls_cipher_get_block_size( &ctx ) ) );
+ if (0 == finish_result) {
+ TEST_ASSERT(0 == memcmp(output, result->x,
+ mbedtls_cipher_get_block_size(&ctx)));
+ }
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_WITH_PADDING */
-void test_vec_crypt( int cipher_id, int operation, data_t *key,
- data_t *iv, data_t *input, data_t *result,
- int finish_result, int use_psa )
+void test_vec_crypt(int cipher_id, int operation, data_t *key,
+ data_t *iv, data_t *input, data_t *result,
+ int finish_result, int use_psa)
{
mbedtls_cipher_context_t ctx;
unsigned char output[32];
size_t outlen;
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
- memset( output, 0x00, sizeof( output ) );
+ memset(output, 0x00, sizeof(output));
/* Prepare context */
#if !defined(MBEDTLS_USE_PSA_CRYPTO) || !defined(MBEDTLS_TEST_DEPRECATED)
(void) use_psa;
#else
- if( use_psa == 1 )
- {
- PSA_ASSERT( psa_crypto_init( ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setup_psa( &ctx,
- mbedtls_cipher_info_from_type( cipher_id ), 0 ) );
- }
- else
+ if (use_psa == 1) {
+ PSA_ASSERT(psa_crypto_init());
+ TEST_ASSERT(0 == mbedtls_cipher_setup_psa(&ctx,
+ mbedtls_cipher_info_from_type(cipher_id), 0));
+ } else
#endif /* !MBEDTLS_USE_PSA_CRYPTO || !MBEDTLS_TEST_DEPRECATED*/
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx,
- mbedtls_cipher_info_from_type( cipher_id ) ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx,
+ mbedtls_cipher_info_from_type(cipher_id)));
- TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key->x, 8 * key->len, operation ) );
- if( MBEDTLS_MODE_CBC == ctx.cipher_info->mode )
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, MBEDTLS_PADDING_NONE ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setkey(&ctx, key->x, 8 * key->len, operation));
+ if (MBEDTLS_MODE_CBC == ctx.cipher_info->mode) {
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_NONE));
+ }
- TEST_ASSERT( finish_result == mbedtls_cipher_crypt( &ctx, iv->len ? iv->x : NULL,
- iv->len, input->x, input->len,
- output, &outlen ) );
- TEST_ASSERT( result->len == outlen );
+ TEST_ASSERT(finish_result == mbedtls_cipher_crypt(&ctx, iv->len ? iv->x : NULL,
+ iv->len, input->x, input->len,
+ output, &outlen));
+ TEST_ASSERT(result->len == outlen);
/* check plaintext only if everything went fine */
- if( 0 == finish_result )
- TEST_ASSERT( 0 == memcmp( output, result->x, outlen ) );
+ if (0 == finish_result) {
+ TEST_ASSERT(0 == memcmp(output, result->x, outlen));
+ }
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_TEST_DEPRECATED)
- PSA_DONE( );
+ PSA_DONE();
#endif /* MBEDTLS_USE_PSA_CRYPTO && MBEDTLS_TEST_DEPRECATED */
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_WITH_PADDING */
-void set_padding( int cipher_id, int pad_mode, int ret )
+void set_padding(int cipher_id, int pad_mode, int ret)
{
const mbedtls_cipher_info_t *cipher_info;
mbedtls_cipher_context_t ctx;
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
- cipher_info = mbedtls_cipher_info_from_type( cipher_id );
- TEST_ASSERT( NULL != cipher_info );
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, cipher_info ) );
+ cipher_info = mbedtls_cipher_info_from_type(cipher_id);
+ TEST_ASSERT(NULL != cipher_info);
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx, cipher_info));
- TEST_ASSERT( ret == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) );
+ TEST_ASSERT(ret == mbedtls_cipher_set_padding_mode(&ctx, pad_mode));
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void check_padding( int pad_mode, data_t * input, int ret, int dlen_check
- )
+void check_padding(int pad_mode, data_t *input, int ret, int dlen_check
+ )
{
mbedtls_cipher_info_t cipher_info;
mbedtls_cipher_context_t ctx;
size_t dlen;
/* build a fake context just for getting access to get_padding */
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
cipher_info.mode = MBEDTLS_MODE_CBC;
ctx.cipher_info = &cipher_info;
- TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) );
+ TEST_ASSERT(0 == mbedtls_cipher_set_padding_mode(&ctx, pad_mode));
- TEST_ASSERT( ret == ctx.get_padding( input->x, input->len, &dlen ) );
- if( 0 == ret )
- TEST_ASSERT( dlen == (size_t) dlen_check );
+ TEST_ASSERT(ret == ctx.get_padding(input->x, input->len, &dlen));
+ if (0 == ret) {
+ TEST_ASSERT(dlen == (size_t) dlen_check);
+ }
}
/* END_CASE */
/* BEGIN_CASE */
-void iv_len_validity( int cipher_id, char * cipher_string,
- int iv_len_val, int ret )
+void iv_len_validity(int cipher_id, char *cipher_string,
+ int iv_len_val, int ret)
{
size_t iv_len = iv_len_val;
unsigned char iv[16];
/* Initialise iv buffer */
- memset( iv, 0, sizeof( iv ) );
+ memset(iv, 0, sizeof(iv));
const mbedtls_cipher_info_t *cipher_info;
mbedtls_cipher_context_t ctx_dec;
@@ -1183,25 +1173,25 @@
/*
* Prepare contexts
*/
- mbedtls_cipher_init( &ctx_dec );
- mbedtls_cipher_init( &ctx_enc );
+ mbedtls_cipher_init(&ctx_dec);
+ mbedtls_cipher_init(&ctx_enc);
/* Check and get info structures */
- cipher_info = mbedtls_cipher_info_from_type( cipher_id );
- TEST_ASSERT( NULL != cipher_info );
- TEST_ASSERT( mbedtls_cipher_info_from_string( cipher_string ) == cipher_info );
- TEST_ASSERT( strcmp( mbedtls_cipher_info_get_name( cipher_info ),
- cipher_string ) == 0 );
+ cipher_info = mbedtls_cipher_info_from_type(cipher_id);
+ TEST_ASSERT(NULL != cipher_info);
+ TEST_ASSERT(mbedtls_cipher_info_from_string(cipher_string) == cipher_info);
+ TEST_ASSERT(strcmp(mbedtls_cipher_info_get_name(cipher_info),
+ cipher_string) == 0);
/* Initialise enc and dec contexts */
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) );
- TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_enc, cipher_info ) );
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx_dec, cipher_info));
+ TEST_ASSERT(0 == mbedtls_cipher_setup(&ctx_enc, cipher_info));
- TEST_ASSERT( ret == mbedtls_cipher_set_iv( &ctx_dec, iv, iv_len ) );
- TEST_ASSERT( ret == mbedtls_cipher_set_iv( &ctx_enc, iv, iv_len ) );
+ TEST_ASSERT(ret == mbedtls_cipher_set_iv(&ctx_dec, iv, iv_len));
+ TEST_ASSERT(ret == mbedtls_cipher_set_iv(&ctx_enc, iv, iv_len));
exit:
- mbedtls_cipher_free( &ctx_dec );
- mbedtls_cipher_free( &ctx_enc );
+ mbedtls_cipher_free(&ctx_dec);
+ mbedtls_cipher_free(&ctx_enc);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_cmac.function b/tests/suites/test_suite_cmac.function
index c3d7da4..9624e8f 100644
--- a/tests/suites/test_suite_cmac.function
+++ b/tests/suites/test_suite_cmac.function
@@ -9,14 +9,14 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void mbedtls_cmac_self_test( )
+void mbedtls_cmac_self_test()
{
- TEST_ASSERT( mbedtls_cmac_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_cmac_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_cmac_null_args( )
+void mbedtls_cmac_null_args()
{
mbedtls_cipher_context_t ctx;
const mbedtls_cipher_info_t *cipher_info;
@@ -24,108 +24,108 @@
unsigned char test_data[MBEDTLS_CIPHER_BLKSIZE_MAX];
unsigned char test_output[MBEDTLS_CIPHER_BLKSIZE_MAX];
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
/* Test NULL cipher info */
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, test_data, 16 ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, test_data, 16) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB );
- TEST_ASSERT( mbedtls_cipher_setup( &ctx, cipher_info ) == 0 );
+ cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB);
+ TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0);
- TEST_ASSERT( mbedtls_cipher_cmac_starts( NULL, test_key, 128 ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_starts(NULL, test_key, 128) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac_starts( &ctx, NULL, 128 ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_starts(&ctx, NULL, 128) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac_update( NULL, test_data, 16 ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_update(NULL, test_data, 16) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx, NULL, 16 ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, NULL, 16) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac_finish( NULL, test_output ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_finish(NULL, test_output) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac_finish( &ctx, NULL ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, NULL) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac_reset( NULL ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac_reset(NULL) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac( NULL,
- test_key, 128,
- test_data, 16,
- test_output ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac(NULL,
+ test_key, 128,
+ test_data, 16,
+ test_output) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac( cipher_info,
- NULL, 128,
- test_data, 16,
- test_output ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac(cipher_info,
+ NULL, 128,
+ test_data, 16,
+ test_output) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac( cipher_info,
- test_key, 128,
- NULL, 16,
- test_output ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac(cipher_info,
+ test_key, 128,
+ NULL, 16,
+ test_output) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_cipher_cmac( cipher_info,
- test_key, 128,
- test_data, 16,
- NULL ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_cipher_cmac(cipher_info,
+ test_key, 128,
+ test_data, 16,
+ NULL) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
#if defined(MBEDTLS_AES_C)
- TEST_ASSERT( mbedtls_aes_cmac_prf_128( NULL, 16,
- test_data, 16,
- test_output ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_aes_cmac_prf_128(NULL, 16,
+ test_data, 16,
+ test_output) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_aes_cmac_prf_128( test_key, 16,
- NULL, 16,
- test_output ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_aes_cmac_prf_128(test_key, 16,
+ NULL, 16,
+ test_output) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_aes_cmac_prf_128( test_key, 16,
- test_data, 16,
- NULL ) ==
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_aes_cmac_prf_128(test_key, 16,
+ test_data, 16,
+ NULL) ==
+ MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA);
#endif
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_cmac_setkey( int cipher_type, int key_size, int result )
+void mbedtls_cmac_setkey(int cipher_type, int key_size, int result)
{
const mbedtls_cipher_info_t *cipher_info;
unsigned char key[32];
unsigned char buf[16];
unsigned char tmp[16];
- memset( key, 0x2A, sizeof( key ) );
- TEST_ASSERT( (unsigned) key_size <= 8 * sizeof( key ) );
+ memset(key, 0x2A, sizeof(key));
+ TEST_ASSERT((unsigned) key_size <= 8 * sizeof(key));
- TEST_ASSERT( ( cipher_info = mbedtls_cipher_info_from_type( cipher_type ) )
- != NULL );
+ TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type))
+ != NULL);
- memset( buf, 0x2A, sizeof( buf ) );
- TEST_ASSERT( ( result == mbedtls_cipher_cmac( cipher_info, key, key_size,
- buf, 16, tmp ) ) != 0 );
+ memset(buf, 0x2A, sizeof(buf));
+ TEST_ASSERT((result == mbedtls_cipher_cmac(cipher_info, key, key_size,
+ buf, 16, tmp)) != 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_cmac_multiple_blocks( int cipher_type, data_t * key,
- int keybits, int block_size,
- data_t * block1, int block1_len,
- data_t * block2, int block2_len,
- data_t * block3, int block3_len,
- data_t * block4, int block4_len,
- data_t * expected_result )
+void mbedtls_cmac_multiple_blocks(int cipher_type, data_t *key,
+ int keybits, int block_size,
+ data_t *block1, int block1_len,
+ data_t *block2, int block2_len,
+ data_t *block3, int block3_len,
+ data_t *block4, int block4_len,
+ data_t *expected_result)
{
const mbedtls_cipher_info_t *cipher_info;
mbedtls_cipher_context_t ctx;
@@ -133,74 +133,78 @@
/* Convert the test parameters to binary data */
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
/* Validate the test inputs */
- TEST_ASSERT( block1_len <= 100 );
- TEST_ASSERT( block2_len <= 100 );
- TEST_ASSERT( block3_len <= 100 );
- TEST_ASSERT( block4_len <= 100 );
+ TEST_ASSERT(block1_len <= 100);
+ TEST_ASSERT(block2_len <= 100);
+ TEST_ASSERT(block3_len <= 100);
+ TEST_ASSERT(block4_len <= 100);
/* Set up */
- TEST_ASSERT( ( cipher_info = mbedtls_cipher_info_from_type( cipher_type ) )
- != NULL );
+ TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type))
+ != NULL);
- TEST_ASSERT( mbedtls_cipher_setup( &ctx, cipher_info ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0);
- TEST_ASSERT( mbedtls_cipher_cmac_starts( &ctx,
- (const unsigned char*)key->x,
- keybits ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_cmac_starts(&ctx,
+ (const unsigned char *) key->x,
+ keybits) == 0);
/* Multiple partial and complete blocks. A negative length means skip the
* update operation */
- if( block1_len >= 0)
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block1->x,
- block1_len ) == 0);
+ if (block1_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block1->x,
+ block1_len) == 0);
+ }
- if( block2_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block2->x,
- block2_len ) == 0);
+ if (block2_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block2->x,
+ block2_len) == 0);
+ }
- if( block3_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block3->x,
- block3_len ) == 0);
+ if (block3_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block3->x,
+ block3_len) == 0);
+ }
- if( block4_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block4->x,
- block4_len ) == 0);
+ if (block4_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block4->x,
+ block4_len) == 0);
+ }
- TEST_ASSERT( mbedtls_cipher_cmac_finish( &ctx, output ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0);
- TEST_ASSERT( memcmp( output, expected_result->x, block_size ) == 0 );
+ TEST_ASSERT(memcmp(output, expected_result->x, block_size) == 0);
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_cmac_multiple_operations_same_key( int cipher_type,
- data_t * key, int keybits,
- int block_size,
- data_t * block_a1,
- int block_a1_len,
- data_t * block_a2,
- int block_a2_len,
- data_t * block_a3,
- int block_a3_len,
- data_t * expected_result_a,
- data_t * block_b1,
- int block_b1_len,
- data_t * block_b2,
- int block_b2_len,
- data_t * block_b3,
- int block_b3_len,
- data_t * expected_result_b
- )
+void mbedtls_cmac_multiple_operations_same_key(int cipher_type,
+ data_t *key, int keybits,
+ int block_size,
+ data_t *block_a1,
+ int block_a1_len,
+ data_t *block_a2,
+ int block_a2_len,
+ data_t *block_a3,
+ int block_a3_len,
+ data_t *expected_result_a,
+ data_t *block_b1,
+ int block_b1_len,
+ data_t *block_b2,
+ int block_b2_len,
+ data_t *block_b3,
+ int block_b3_len,
+ data_t *expected_result_b
+ )
{
const mbedtls_cipher_info_t *cipher_info;
mbedtls_cipher_context_t ctx;
@@ -210,77 +214,82 @@
- mbedtls_cipher_init( &ctx );
+ mbedtls_cipher_init(&ctx);
/* Validate the test inputs */
- TEST_ASSERT( block_a1_len <= 100 );
- TEST_ASSERT( block_a2_len <= 100 );
- TEST_ASSERT( block_a3_len <= 100 );
+ TEST_ASSERT(block_a1_len <= 100);
+ TEST_ASSERT(block_a2_len <= 100);
+ TEST_ASSERT(block_a3_len <= 100);
- TEST_ASSERT( block_b1_len <= 100 );
- TEST_ASSERT( block_b2_len <= 100 );
- TEST_ASSERT( block_b3_len <= 100 );
+ TEST_ASSERT(block_b1_len <= 100);
+ TEST_ASSERT(block_b2_len <= 100);
+ TEST_ASSERT(block_b3_len <= 100);
/* Set up */
- TEST_ASSERT( ( cipher_info = mbedtls_cipher_info_from_type( cipher_type ) )
- != NULL );
+ TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type))
+ != NULL);
- TEST_ASSERT( mbedtls_cipher_setup( &ctx, cipher_info ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0);
- TEST_ASSERT( mbedtls_cipher_cmac_starts( &ctx,
- (const unsigned char*)key->x,
- keybits ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_cmac_starts(&ctx,
+ (const unsigned char *) key->x,
+ keybits) == 0);
/* Sequence A */
/* Multiple partial and complete blocks. A negative length means skip the
* update operation */
- if( block_a1_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block_a1->x,
- block_a1_len ) == 0);
+ if (block_a1_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block_a1->x,
+ block_a1_len) == 0);
+ }
- if( block_a2_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block_a2->x,
- block_a2_len ) == 0);
+ if (block_a2_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block_a2->x,
+ block_a2_len) == 0);
+ }
- if( block_a3_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block_a3->x,
- block_a3_len ) == 0);
+ if (block_a3_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block_a3->x,
+ block_a3_len) == 0);
+ }
- TEST_ASSERT( mbedtls_cipher_cmac_finish( &ctx, output ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0);
- TEST_ASSERT( memcmp( output, expected_result_a->x, block_size ) == 0 );
+ TEST_ASSERT(memcmp(output, expected_result_a->x, block_size) == 0);
- TEST_ASSERT( mbedtls_cipher_cmac_reset( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_cmac_reset(&ctx) == 0);
/* Sequence B */
/* Multiple partial and complete blocks. A negative length means skip the
* update operation */
- if( block_b1_len >= 0)
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block_b1->x,
- block_b1_len ) == 0);
+ if (block_b1_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block_b1->x,
+ block_b1_len) == 0);
+ }
- if( block_b2_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block_b2->x,
- block_b2_len ) == 0);
+ if (block_b2_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block_b2->x,
+ block_b2_len) == 0);
+ }
- if( block_b3_len >= 0 )
- TEST_ASSERT( mbedtls_cipher_cmac_update( &ctx,
- (unsigned char*)block_b3->x,
- block_b3_len ) == 0);
+ if (block_b3_len >= 0) {
+ TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx,
+ (unsigned char *) block_b3->x,
+ block_b3_len) == 0);
+ }
- TEST_ASSERT( mbedtls_cipher_cmac_finish( &ctx, output ) == 0 );
+ TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0);
- TEST_ASSERT( memcmp( output, expected_result_b->x, block_size ) == 0 );
+ TEST_ASSERT(memcmp(output, expected_result_b->x, block_size) == 0);
exit:
- mbedtls_cipher_free( &ctx );
+ mbedtls_cipher_free(&ctx);
}
/* END_CASE */
-
diff --git a/tests/suites/test_suite_common.function b/tests/suites/test_suite_common.function
index 4444a52..dd0b2d5 100644
--- a/tests/suites/test_suite_common.function
+++ b/tests/suites/test_suite_common.function
@@ -1,10 +1,9 @@
/* BEGIN_HEADER */
#include "../library/common.h"
-void fill_arrays( unsigned char *a, unsigned char *b, unsigned char *r1, unsigned char *r2, size_t n )
+void fill_arrays(unsigned char *a, unsigned char *b, unsigned char *r1, unsigned char *r2, size_t n)
{
- for ( size_t i = 0; i < n; i++ )
- {
+ for (size_t i = 0; i < n; i++) {
a[i] = (unsigned char) i * 3;
b[i] = (unsigned char) i * 3 + 1;
r1[i] = (unsigned char) i * 3 + 2;
@@ -14,77 +13,70 @@
/* END_HEADER */
/* BEGIN_CASE */
-void mbedtls_xor( int len )
+void mbedtls_xor(int len)
{
size_t n = (size_t) len;
unsigned char *a = NULL, *b = NULL, *r1 = NULL, *r2 = NULL;
- ASSERT_ALLOC( a, n + 1 );
- ASSERT_ALLOC( b, n + 1 );
- ASSERT_ALLOC( r1, n + 1 );
- ASSERT_ALLOC( r2, n + 1 );
+ ASSERT_ALLOC(a, n + 1);
+ ASSERT_ALLOC(b, n + 1);
+ ASSERT_ALLOC(r1, n + 1);
+ ASSERT_ALLOC(r2, n + 1);
/* Test non-overlapping */
- fill_arrays( a, b, r1, r2, n );
- for ( size_t i = 0; i < n; i++ )
- {
+ fill_arrays(a, b, r1, r2, n);
+ for (size_t i = 0; i < n; i++) {
r1[i] = a[i] ^ b[i];
}
- mbedtls_xor( r2, a, b, n );
- ASSERT_COMPARE( r1, n, r2, n );
+ mbedtls_xor(r2, a, b, n);
+ ASSERT_COMPARE(r1, n, r2, n);
/* Test r == a */
- fill_arrays( a, b, r1, r2, n );
- for ( size_t i = 0; i < n; i++ )
- {
+ fill_arrays(a, b, r1, r2, n);
+ for (size_t i = 0; i < n; i++) {
r1[i] = r1[i] ^ b[i];
}
- mbedtls_xor( r2, r2, b, n );
- ASSERT_COMPARE( r1, n, r2, n );
+ mbedtls_xor(r2, r2, b, n);
+ ASSERT_COMPARE(r1, n, r2, n);
/* Test r == b */
- fill_arrays( a, b, r1, r2, n );
- for ( size_t i = 0; i < n; i++ )
- {
+ fill_arrays(a, b, r1, r2, n);
+ for (size_t i = 0; i < n; i++) {
r1[i] = a[i] ^ r1[i];
}
- mbedtls_xor( r2, a, r2, n );
- ASSERT_COMPARE( r1, n, r2, n );
+ mbedtls_xor(r2, a, r2, n);
+ ASSERT_COMPARE(r1, n, r2, n);
/* Test a == b */
- fill_arrays( a, b, r1, r2, n );
- for ( size_t i = 0; i < n; i++ )
- {
+ fill_arrays(a, b, r1, r2, n);
+ for (size_t i = 0; i < n; i++) {
r1[i] = a[i] ^ a[i];
}
- mbedtls_xor( r2, a, a, n );
- ASSERT_COMPARE( r1, n, r2, n );
+ mbedtls_xor(r2, a, a, n);
+ ASSERT_COMPARE(r1, n, r2, n);
/* Test a == b == r */
- fill_arrays( a, b, r1, r2, n );
- for ( size_t i = 0; i < n; i++ )
- {
+ fill_arrays(a, b, r1, r2, n);
+ for (size_t i = 0; i < n; i++) {
r1[i] = r1[i] ^ r1[i];
}
- mbedtls_xor( r2, r2, r2, n );
- ASSERT_COMPARE( r1, n, r2, n );
+ mbedtls_xor(r2, r2, r2, n);
+ ASSERT_COMPARE(r1, n, r2, n);
/* Test non-word-aligned buffers, for all combinations of alignedness */
- for ( int i = 0; i < 7; i++ )
- {
+ for (int i = 0; i < 7; i++) {
int r_off = i & 1, a_off = (i & 2) >> 1, b_off = (i & 4) >> 2;
- fill_arrays( a, b, r1, r2, n + 1 );
+ fill_arrays(a, b, r1, r2, n + 1);
- for ( size_t j = 0; j < n; j++ )
- {
+ for (size_t j = 0; j < n; j++) {
r1[j + r_off] = a[j + a_off] ^ b[j + b_off];
}
- mbedtls_xor( r2 + r_off, a + a_off, b + b_off, n );
- ASSERT_COMPARE( r1 + r_off, n, r2 + r_off, n );
+ mbedtls_xor(r2 + r_off, a + a_off, b + b_off, n);
+ ASSERT_COMPARE(r1 + r_off, n, r2 + r_off, n);
}
exit:
- mbedtls_free( a );
- mbedtls_free( b );
- mbedtls_free( r1 );
- mbedtls_free( r2 );
+ mbedtls_free(a);
+ mbedtls_free(b);
+ mbedtls_free(r1);
+ mbedtls_free(r2);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_constant_time.function b/tests/suites/test_suite_constant_time.function
index a3673b7..a40149a 100644
--- a/tests/suites/test_suite_constant_time.function
+++ b/tests/suites/test_suite_constant_time.function
@@ -16,34 +16,33 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC:MBEDTLS_TEST_HOOKS */
-void ssl_cf_memcpy_offset( int offset_min, int offset_max, int len )
+void ssl_cf_memcpy_offset(int offset_min, int offset_max, int len)
{
unsigned char *dst = NULL;
unsigned char *src = NULL;
size_t src_len = offset_max + len;
size_t secret;
- ASSERT_ALLOC( dst, len );
- ASSERT_ALLOC( src, src_len );
+ ASSERT_ALLOC(dst, len);
+ ASSERT_ALLOC(src, src_len);
/* Fill src in a way that we can detect if we copied the right bytes */
- mbedtls_test_rnd_std_rand( NULL, src, src_len );
+ mbedtls_test_rnd_std_rand(NULL, src, src_len);
- for( secret = offset_min; secret <= (size_t) offset_max; secret++ )
- {
- mbedtls_test_set_step( (int) secret );
+ for (secret = offset_min; secret <= (size_t) offset_max; secret++) {
+ mbedtls_test_set_step((int) secret);
- TEST_CF_SECRET( &secret, sizeof( secret ) );
- mbedtls_ct_memcpy_offset( dst, src, secret,
- offset_min, offset_max, len );
- TEST_CF_PUBLIC( &secret, sizeof( secret ) );
- TEST_CF_PUBLIC( dst, len );
+ TEST_CF_SECRET(&secret, sizeof(secret));
+ mbedtls_ct_memcpy_offset(dst, src, secret,
+ offset_min, offset_max, len);
+ TEST_CF_PUBLIC(&secret, sizeof(secret));
+ TEST_CF_PUBLIC(dst, len);
- ASSERT_COMPARE( dst, len, src + secret, len );
+ ASSERT_COMPARE(dst, len, src + secret, len);
}
exit:
- mbedtls_free( dst );
- mbedtls_free( src );
+ mbedtls_free(dst);
+ mbedtls_free(src);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_constant_time_hmac.function b/tests/suites/test_suite_constant_time_hmac.function
index f8c1bfc..8ba6ff4 100644
--- a/tests/suites/test_suite_constant_time_hmac.function
+++ b/tests/suites/test_suite_constant_time_hmac.function
@@ -10,7 +10,7 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC:MBEDTLS_TEST_HOOKS */
-void ssl_cf_hmac( int hash )
+void ssl_cf_hmac(int hash)
{
/*
* Test the function mbedtls_ct_hmac() against a reference
@@ -34,47 +34,47 @@
unsigned char *out = NULL;
unsigned char rec_num = 0;
- USE_PSA_INIT( );
+ USE_PSA_INIT();
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- alg = PSA_ALG_HMAC( mbedtls_hash_info_psa_from_md( hash ) );
+ alg = PSA_ALG_HMAC(mbedtls_hash_info_psa_from_md(hash));
- out_len = PSA_HASH_LENGTH( alg );
- block_size = PSA_HASH_BLOCK_LENGTH( alg );
+ out_len = PSA_HASH_LENGTH(alg);
+ block_size = PSA_HASH_BLOCK_LENGTH(alg);
/* mbedtls_ct_hmac() requires the key to be exportable */
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT |
- PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, PSA_ALG_HMAC( alg ) );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_HMAC );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT |
+ PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, PSA_ALG_HMAC(alg));
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_HMAC);
#else
- mbedtls_md_init( &ctx );
- mbedtls_md_init( &ref_ctx );
+ mbedtls_md_init(&ctx);
+ mbedtls_md_init(&ref_ctx);
- md_info = mbedtls_md_info_from_type( hash );
- TEST_ASSERT( md_info != NULL );
- out_len = mbedtls_md_get_size( md_info );
- TEST_ASSERT( out_len != 0 );
+ md_info = mbedtls_md_info_from_type(hash);
+ TEST_ASSERT(md_info != NULL);
+ out_len = mbedtls_md_get_size(md_info);
+ TEST_ASSERT(out_len != 0);
block_size = hash == MBEDTLS_MD_SHA384 ? 128 : 64;
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* Use allocated out buffer to catch overwrites */
- ASSERT_ALLOC( out, out_len );
+ ASSERT_ALLOC(out, out_len);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
/* Set up dummy key */
- memset( ref_out, 42, sizeof( ref_out ) );
- TEST_EQUAL( PSA_SUCCESS, psa_import_key( &attributes,
- ref_out, out_len,
- &key ) );
+ memset(ref_out, 42, sizeof(ref_out));
+ TEST_EQUAL(PSA_SUCCESS, psa_import_key(&attributes,
+ ref_out, out_len,
+ &key));
#else
/* Set up contexts with the given hash and a dummy key */
- TEST_EQUAL( 0, mbedtls_md_setup( &ctx, md_info, 1 ) );
- TEST_EQUAL( 0, mbedtls_md_setup( &ref_ctx, md_info, 1 ) );
- memset( ref_out, 42, sizeof( ref_out ) );
- TEST_EQUAL( 0, mbedtls_md_hmac_starts( &ctx, ref_out, out_len ) );
- TEST_EQUAL( 0, mbedtls_md_hmac_starts( &ref_ctx, ref_out, out_len ) );
- memset( ref_out, 0, sizeof( ref_out ) );
+ TEST_EQUAL(0, mbedtls_md_setup(&ctx, md_info, 1));
+ TEST_EQUAL(0, mbedtls_md_setup(&ref_ctx, md_info, 1));
+ memset(ref_out, 42, sizeof(ref_out));
+ TEST_EQUAL(0, mbedtls_md_hmac_starts(&ctx, ref_out, out_len));
+ TEST_EQUAL(0, mbedtls_md_hmac_starts(&ref_ctx, ref_out, out_len));
+ memset(ref_out, 0, sizeof(ref_out));
#endif
/*
@@ -82,79 +82,78 @@
* max_in_len and min_in_len is at most 255, and make sure they both vary
* by at least one block size.
*/
- for( max_in_len = 0; max_in_len <= 255 + block_size; max_in_len++ )
- {
- mbedtls_test_set_step( max_in_len * 10000 );
+ for (max_in_len = 0; max_in_len <= 255 + block_size; max_in_len++) {
+ mbedtls_test_set_step(max_in_len * 10000);
/* Use allocated in buffer to catch overreads */
- ASSERT_ALLOC( data, max_in_len );
+ ASSERT_ALLOC(data, max_in_len);
min_in_len = max_in_len > 255 ? max_in_len - 255 : 0;
- for( in_len = min_in_len; in_len <= max_in_len; in_len++ )
- {
- mbedtls_test_set_step( max_in_len * 10000 + in_len );
+ for (in_len = min_in_len; in_len <= max_in_len; in_len++) {
+ mbedtls_test_set_step(max_in_len * 10000 + in_len);
/* Set up dummy data and add_data */
rec_num++;
- memset( add_data, rec_num, sizeof( add_data ) );
- for( i = 0; i < in_len; i++ )
- data[i] = ( i & 0xff ) ^ rec_num;
+ memset(add_data, rec_num, sizeof(add_data));
+ for (i = 0; i < in_len; i++) {
+ data[i] = (i & 0xff) ^ rec_num;
+ }
/* Get the function's result */
- TEST_CF_SECRET( &in_len, sizeof( in_len ) );
+ TEST_CF_SECRET(&in_len, sizeof(in_len));
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- TEST_EQUAL( 0, mbedtls_ct_hmac( key, PSA_ALG_HMAC( alg ),
- add_data, sizeof( add_data ),
- data, in_len,
- min_in_len, max_in_len,
- out ) );
+ TEST_EQUAL(0, mbedtls_ct_hmac(key, PSA_ALG_HMAC(alg),
+ add_data, sizeof(add_data),
+ data, in_len,
+ min_in_len, max_in_len,
+ out));
#else
- TEST_EQUAL( 0, mbedtls_ct_hmac( &ctx, add_data, sizeof( add_data ),
- data, in_len,
- min_in_len, max_in_len,
- out ) );
+ TEST_EQUAL(0, mbedtls_ct_hmac(&ctx, add_data, sizeof(add_data),
+ data, in_len,
+ min_in_len, max_in_len,
+ out));
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- TEST_CF_PUBLIC( &in_len, sizeof( in_len ) );
- TEST_CF_PUBLIC( out, out_len );
+ TEST_CF_PUBLIC(&in_len, sizeof(in_len));
+ TEST_CF_PUBLIC(out, out_len);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- TEST_EQUAL( PSA_SUCCESS, psa_mac_verify_setup( &operation,
- key, alg ) );
- TEST_EQUAL( PSA_SUCCESS, psa_mac_update( &operation, add_data,
- sizeof( add_data ) ) );
- TEST_EQUAL( PSA_SUCCESS, psa_mac_update( &operation,
- data, in_len ) );
- TEST_EQUAL( PSA_SUCCESS, psa_mac_verify_finish( &operation,
- out, out_len ) );
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_verify_setup(&operation,
+ key, alg));
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_update(&operation, add_data,
+ sizeof(add_data)));
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_update(&operation,
+ data, in_len));
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_verify_finish(&operation,
+ out, out_len));
#else
/* Compute the reference result */
- TEST_EQUAL( 0, mbedtls_md_hmac_update( &ref_ctx, add_data,
- sizeof( add_data ) ) );
- TEST_EQUAL( 0, mbedtls_md_hmac_update( &ref_ctx, data, in_len ) );
- TEST_EQUAL( 0, mbedtls_md_hmac_finish( &ref_ctx, ref_out ) );
- TEST_EQUAL( 0, mbedtls_md_hmac_reset( &ref_ctx ) );
+ TEST_EQUAL(0, mbedtls_md_hmac_update(&ref_ctx, add_data,
+ sizeof(add_data)));
+ TEST_EQUAL(0, mbedtls_md_hmac_update(&ref_ctx, data, in_len));
+ TEST_EQUAL(0, mbedtls_md_hmac_finish(&ref_ctx, ref_out));
+ TEST_EQUAL(0, mbedtls_md_hmac_reset(&ref_ctx));
/* Compare */
- ASSERT_COMPARE( out, out_len, ref_out, out_len );
+ ASSERT_COMPARE(out, out_len, ref_out, out_len);
#endif /* MBEDTLS_USE_PSA_CRYPTO */
}
- mbedtls_free( data );
+ mbedtls_free(data);
data = NULL;
}
exit:
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_mac_abort( &operation );
- psa_destroy_key( key );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
#else
- mbedtls_md_free( &ref_ctx );
- mbedtls_md_free( &ctx );
+ mbedtls_md_free(&ref_ctx);
+ mbedtls_md_free(&ctx);
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- mbedtls_free( data );
- mbedtls_free( out );
+ mbedtls_free(data);
+ mbedtls_free(out);
- USE_PSA_DONE( );
+ USE_PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_ctr_drbg.function b/tests/suites/test_suite_ctr_drbg.function
index a46f21c..85c00eb 100644
--- a/tests/suites/test_suite_ctr_drbg.function
+++ b/tests/suites/test_suite_ctr_drbg.function
@@ -4,8 +4,7 @@
#include "string.h"
/* Modes for ctr_drbg_validate */
-enum reseed_mode
-{
+enum reseed_mode {
RESEED_NEVER, /* never reseed */
RESEED_FIRST, /* instantiate, reseed, generate, generate */
RESEED_SECOND, /* instantiate, generate, reseed, generate */
@@ -14,83 +13,83 @@
static size_t test_offset_idx = 0;
static size_t test_max_idx = 0;
-static int mbedtls_test_entropy_func( void *data, unsigned char *buf, size_t len )
+static int mbedtls_test_entropy_func(void *data, unsigned char *buf, size_t len)
{
const unsigned char *p = (unsigned char *) data;
- if( test_offset_idx + len > test_max_idx )
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
- memcpy( buf, p + test_offset_idx, len );
+ if (test_offset_idx + len > test_max_idx) {
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
+ }
+ memcpy(buf, p + test_offset_idx, len);
test_offset_idx += len;
- return( 0 );
+ return 0;
}
-static void ctr_drbg_validate_internal( int reseed_mode, data_t * nonce,
- int entropy_len_arg, data_t * entropy,
- data_t * reseed,
- data_t * add1, data_t * add2,
- data_t * result )
+static void ctr_drbg_validate_internal(int reseed_mode, data_t *nonce,
+ int entropy_len_arg, data_t *entropy,
+ data_t *reseed,
+ data_t *add1, data_t *add2,
+ data_t *result)
{
mbedtls_ctr_drbg_context ctx;
unsigned char buf[64];
size_t entropy_chunk_len = (size_t) entropy_len_arg;
- TEST_ASSERT( entropy_chunk_len <= sizeof( buf ) );
+ TEST_ASSERT(entropy_chunk_len <= sizeof(buf));
test_offset_idx = 0;
- mbedtls_ctr_drbg_init( &ctx );
+ mbedtls_ctr_drbg_init(&ctx);
test_max_idx = entropy->len;
/* CTR_DRBG_Instantiate(entropy[:entropy->len], nonce, perso, <ignored>)
* where nonce||perso = nonce[nonce->len] */
- mbedtls_ctr_drbg_set_entropy_len( &ctx, entropy_chunk_len );
- mbedtls_ctr_drbg_set_nonce_len( &ctx, 0 );
- TEST_ASSERT( mbedtls_ctr_drbg_seed(
- &ctx,
- mbedtls_test_entropy_func, entropy->x,
- nonce->x, nonce->len ) == 0 );
- if( reseed_mode == RESEED_ALWAYS )
+ mbedtls_ctr_drbg_set_entropy_len(&ctx, entropy_chunk_len);
+ mbedtls_ctr_drbg_set_nonce_len(&ctx, 0);
+ TEST_ASSERT(mbedtls_ctr_drbg_seed(
+ &ctx,
+ mbedtls_test_entropy_func, entropy->x,
+ nonce->x, nonce->len) == 0);
+ if (reseed_mode == RESEED_ALWAYS) {
mbedtls_ctr_drbg_set_prediction_resistance(
&ctx,
- MBEDTLS_CTR_DRBG_PR_ON );
+ MBEDTLS_CTR_DRBG_PR_ON);
+ }
- if( reseed_mode == RESEED_FIRST )
- {
+ if (reseed_mode == RESEED_FIRST) {
/* CTR_DRBG_Reseed(entropy[idx:idx+entropy->len],
* reseed[:reseed->len]) */
- TEST_ASSERT( mbedtls_ctr_drbg_reseed(
- &ctx,
- reseed->x, reseed->len ) == 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_reseed(
+ &ctx,
+ reseed->x, reseed->len) == 0);
}
/* CTR_DRBG_Generate(result->len * 8 bits, add1[:add1->len]) -> buf */
/* Then reseed if prediction resistance is enabled. */
- TEST_ASSERT( mbedtls_ctr_drbg_random_with_add(
- &ctx,
- buf, result->len,
- add1->x, add1->len ) == 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_random_with_add(
+ &ctx,
+ buf, result->len,
+ add1->x, add1->len) == 0);
- if( reseed_mode == RESEED_SECOND )
- {
+ if (reseed_mode == RESEED_SECOND) {
/* CTR_DRBG_Reseed(entropy[idx:idx+entropy->len],
* reseed[:reseed->len]) */
- TEST_ASSERT( mbedtls_ctr_drbg_reseed(
- &ctx,
- reseed->x, reseed->len ) == 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_reseed(
+ &ctx,
+ reseed->x, reseed->len) == 0);
}
/* CTR_DRBG_Generate(result->len * 8 bits, add2->x[:add2->len]) -> buf */
/* Then reseed if prediction resistance is enabled. */
- TEST_ASSERT( mbedtls_ctr_drbg_random_with_add(
- &ctx,
- buf, result->len,
- add2->x, add2->len ) == 0 );
- TEST_ASSERT( memcmp( buf, result->x, result->len ) == 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_random_with_add(
+ &ctx,
+ buf, result->len,
+ add2->x, add2->len) == 0);
+ TEST_ASSERT(memcmp(buf, result->x, result->len) == 0);
exit:
- mbedtls_ctr_drbg_free( &ctx );
+ mbedtls_ctr_drbg_free(&ctx);
}
/* END_HEADER */
@@ -101,127 +100,127 @@
*/
/* BEGIN_CASE */
-void ctr_drbg_special_behaviours( )
+void ctr_drbg_special_behaviours()
{
mbedtls_ctr_drbg_context ctx;
unsigned char output[512];
unsigned char additional[512];
- mbedtls_ctr_drbg_init( &ctx );
- memset( output, 0, sizeof( output ) );
- memset( additional, 0, sizeof( additional ) );
+ mbedtls_ctr_drbg_init(&ctx);
+ memset(output, 0, sizeof(output));
+ memset(additional, 0, sizeof(additional));
- TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx,
- output, MBEDTLS_CTR_DRBG_MAX_REQUEST + 1,
- additional, 16 ) ==
- MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG );
- TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx,
- output, 16,
- additional, MBEDTLS_CTR_DRBG_MAX_INPUT + 1 ) ==
- MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
+ TEST_ASSERT(mbedtls_ctr_drbg_random_with_add(&ctx,
+ output, MBEDTLS_CTR_DRBG_MAX_REQUEST + 1,
+ additional, 16) ==
+ MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG);
+ TEST_ASSERT(mbedtls_ctr_drbg_random_with_add(&ctx,
+ output, 16,
+ additional, MBEDTLS_CTR_DRBG_MAX_INPUT + 1) ==
+ MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG);
- TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, additional,
- MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + 1 ) ==
- MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
+ TEST_ASSERT(mbedtls_ctr_drbg_reseed(&ctx, additional,
+ MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + 1) ==
+ MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG);
- mbedtls_ctr_drbg_set_entropy_len( &ctx, ~0 );
- TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, additional,
- MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) ==
- MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
+ mbedtls_ctr_drbg_set_entropy_len(&ctx, ~0);
+ TEST_ASSERT(mbedtls_ctr_drbg_reseed(&ctx, additional,
+ MBEDTLS_CTR_DRBG_MAX_SEED_INPUT) ==
+ MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG);
exit:
- mbedtls_ctr_drbg_free( &ctx );
+ mbedtls_ctr_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void ctr_drbg_validate_no_reseed( data_t * add_init, data_t * entropy,
- data_t * add1, data_t * add2,
- data_t * result_string )
+void ctr_drbg_validate_no_reseed(data_t *add_init, data_t *entropy,
+ data_t *add1, data_t *add2,
+ data_t *result_string)
{
data_t empty = { 0, 0 };
- ctr_drbg_validate_internal( RESEED_NEVER, add_init,
- entropy->len, entropy,
- &empty, add1, add2,
- result_string );
+ ctr_drbg_validate_internal(RESEED_NEVER, add_init,
+ entropy->len, entropy,
+ &empty, add1, add2,
+ result_string);
goto exit; // goto is needed to avoid warning ( no test assertions in func)
}
/* END_CASE */
/* BEGIN_CASE */
-void ctr_drbg_validate_pr( data_t * add_init, data_t * entropy,
- data_t * add1, data_t * add2,
- data_t * result_string )
+void ctr_drbg_validate_pr(data_t *add_init, data_t *entropy,
+ data_t *add1, data_t *add2,
+ data_t *result_string)
{
data_t empty = { 0, 0 };
- ctr_drbg_validate_internal( RESEED_ALWAYS, add_init,
- entropy->len / 3, entropy,
- &empty, add1, add2,
- result_string );
+ ctr_drbg_validate_internal(RESEED_ALWAYS, add_init,
+ entropy->len / 3, entropy,
+ &empty, add1, add2,
+ result_string);
goto exit; // goto is needed to avoid warning ( no test assertions in func)
}
/* END_CASE */
/* BEGIN_CASE */
-void ctr_drbg_validate_reseed_between( data_t * add_init, data_t * entropy,
- data_t * add1, data_t * add_reseed,
- data_t * add2, data_t * result_string )
+void ctr_drbg_validate_reseed_between(data_t *add_init, data_t *entropy,
+ data_t *add1, data_t *add_reseed,
+ data_t *add2, data_t *result_string)
{
- ctr_drbg_validate_internal( RESEED_SECOND, add_init,
- entropy->len / 2, entropy,
- add_reseed, add1, add2,
- result_string );
+ ctr_drbg_validate_internal(RESEED_SECOND, add_init,
+ entropy->len / 2, entropy,
+ add_reseed, add1, add2,
+ result_string);
goto exit; // goto is needed to avoid warning ( no test assertions in func)
}
/* END_CASE */
/* BEGIN_CASE */
-void ctr_drbg_validate_reseed_first( data_t * add_init, data_t * entropy,
- data_t * add1, data_t * add_reseed,
- data_t * add2, data_t * result_string )
+void ctr_drbg_validate_reseed_first(data_t *add_init, data_t *entropy,
+ data_t *add1, data_t *add_reseed,
+ data_t *add2, data_t *result_string)
{
- ctr_drbg_validate_internal( RESEED_FIRST, add_init,
- entropy->len / 2, entropy,
- add_reseed, add1, add2,
- result_string );
+ ctr_drbg_validate_internal(RESEED_FIRST, add_init,
+ entropy->len / 2, entropy,
+ add_reseed, add1, add2,
+ result_string);
goto exit; // goto is needed to avoid warning ( no test assertions in func)
}
/* END_CASE */
/* BEGIN_CASE */
-void ctr_drbg_entropy_strength( int expected_bit_strength )
+void ctr_drbg_entropy_strength(int expected_bit_strength)
{
unsigned char entropy[/*initial entropy*/ MBEDTLS_CTR_DRBG_ENTROPY_LEN +
- /*nonce*/ MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN +
- /*reseed*/ MBEDTLS_CTR_DRBG_ENTROPY_LEN];
+ /*nonce*/ MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN +
+ /*reseed*/ MBEDTLS_CTR_DRBG_ENTROPY_LEN];
mbedtls_ctr_drbg_context ctx;
size_t last_idx;
size_t byte_strength = expected_bit_strength / 8;
- mbedtls_ctr_drbg_init( &ctx );
+ mbedtls_ctr_drbg_init(&ctx);
test_offset_idx = 0;
- test_max_idx = sizeof( entropy );
- memset( entropy, 0, sizeof( entropy ) );
+ test_max_idx = sizeof(entropy);
+ memset(entropy, 0, sizeof(entropy));
/* The initial seeding must grab at least byte_strength bytes of entropy
* for the entropy input and byte_strength/2 bytes for a nonce. */
- TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx,
- mbedtls_test_entropy_func, entropy,
- NULL, 0 ) == 0 );
- TEST_ASSERT( test_offset_idx >= ( byte_strength * 3 + 1 ) / 2 );
+ TEST_ASSERT(mbedtls_ctr_drbg_seed(&ctx,
+ mbedtls_test_entropy_func, entropy,
+ NULL, 0) == 0);
+ TEST_ASSERT(test_offset_idx >= (byte_strength * 3 + 1) / 2);
last_idx = test_offset_idx;
/* A reseed must grab at least byte_strength bytes of entropy. */
- TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) == 0 );
- TEST_ASSERT( test_offset_idx - last_idx >= byte_strength );
+ TEST_ASSERT(mbedtls_ctr_drbg_reseed(&ctx, NULL, 0) == 0);
+ TEST_ASSERT(test_offset_idx - last_idx >= byte_strength);
exit:
- mbedtls_ctr_drbg_free( &ctx );
+ mbedtls_ctr_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void ctr_drbg_entropy_usage( int entropy_nonce_len )
+void ctr_drbg_entropy_usage(int entropy_nonce_len)
{
unsigned char out[16];
unsigned char add[16];
@@ -230,109 +229,109 @@
size_t i, reps = 10;
size_t expected_idx = 0;
- mbedtls_ctr_drbg_init( &ctx );
+ mbedtls_ctr_drbg_init(&ctx);
test_offset_idx = 0;
- test_max_idx = sizeof( entropy );
- memset( entropy, 0, sizeof( entropy ) );
- memset( out, 0, sizeof( out ) );
- memset( add, 0, sizeof( add ) );
+ test_max_idx = sizeof(entropy);
+ memset(entropy, 0, sizeof(entropy));
+ memset(out, 0, sizeof(out));
+ memset(add, 0, sizeof(add));
- if( entropy_nonce_len >= 0 )
- TEST_ASSERT( mbedtls_ctr_drbg_set_nonce_len( &ctx, entropy_nonce_len ) == 0 );
+ if (entropy_nonce_len >= 0) {
+ TEST_ASSERT(mbedtls_ctr_drbg_set_nonce_len(&ctx, entropy_nonce_len) == 0);
+ }
/* Set reseed interval before seed */
- mbedtls_ctr_drbg_set_reseed_interval( &ctx, 2 * reps );
+ mbedtls_ctr_drbg_set_reseed_interval(&ctx, 2 * reps);
/* Init must use entropy */
- TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx, mbedtls_test_entropy_func, entropy, NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_seed(&ctx, mbedtls_test_entropy_func, entropy, NULL, 0) == 0);
expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_LEN;
- if( entropy_nonce_len >= 0 )
+ if (entropy_nonce_len >= 0) {
expected_idx += entropy_nonce_len;
- else
+ } else {
expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN;
- TEST_EQUAL( test_offset_idx, expected_idx );
+ }
+ TEST_EQUAL(test_offset_idx, expected_idx);
/* By default, PR is off, and reseed interval was set to
* 2 * reps so the next few calls should not use entropy */
- for( i = 0; i < reps; i++ )
- {
- TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) - 4 ) == 0 );
- TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, out, sizeof( out ) - 4,
- add, sizeof( add ) ) == 0 );
+ for (i = 0; i < reps; i++) {
+ TEST_ASSERT(mbedtls_ctr_drbg_random(&ctx, out, sizeof(out) - 4) == 0);
+ TEST_ASSERT(mbedtls_ctr_drbg_random_with_add(&ctx, out, sizeof(out) - 4,
+ add, sizeof(add)) == 0);
}
- TEST_EQUAL( test_offset_idx, expected_idx );
+ TEST_EQUAL(test_offset_idx, expected_idx);
/* While at it, make sure we didn't write past the requested length */
- TEST_ASSERT( out[sizeof( out ) - 4] == 0 );
- TEST_ASSERT( out[sizeof( out ) - 3] == 0 );
- TEST_ASSERT( out[sizeof( out ) - 2] == 0 );
- TEST_ASSERT( out[sizeof( out ) - 1] == 0 );
+ TEST_ASSERT(out[sizeof(out) - 4] == 0);
+ TEST_ASSERT(out[sizeof(out) - 3] == 0);
+ TEST_ASSERT(out[sizeof(out) - 2] == 0);
+ TEST_ASSERT(out[sizeof(out) - 1] == 0);
/* There have been 2 * reps calls to random. The next call should reseed */
- TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_LEN;
- TEST_EQUAL( test_offset_idx, expected_idx );
+ TEST_EQUAL(test_offset_idx, expected_idx);
/* Set reseed interval after seed */
- mbedtls_ctr_drbg_set_reseed_interval( &ctx, 4 * reps + 1 );
+ mbedtls_ctr_drbg_set_reseed_interval(&ctx, 4 * reps + 1);
/* The next few calls should not reseed */
- for( i = 0; i < (2 * reps); i++ )
- {
- TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
- TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, out, sizeof( out ) ,
- add, sizeof( add ) ) == 0 );
+ for (i = 0; i < (2 * reps); i++) {
+ TEST_ASSERT(mbedtls_ctr_drbg_random(&ctx, out, sizeof(out)) == 0);
+ TEST_ASSERT(mbedtls_ctr_drbg_random_with_add(&ctx, out, sizeof(out),
+ add, sizeof(add)) == 0);
}
- TEST_EQUAL( test_offset_idx, expected_idx );
+ TEST_EQUAL(test_offset_idx, expected_idx);
/* Call update with too much data (sizeof entropy > MAX(_SEED)_INPUT).
* Make sure it's detected as an error and doesn't cause memory
* corruption. */
- TEST_ASSERT( mbedtls_ctr_drbg_update(
- &ctx, entropy, sizeof( entropy ) ) != 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_update(
+ &ctx, entropy, sizeof(entropy)) != 0);
/* Now enable PR, so the next few calls should all reseed */
- mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON );
- TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ mbedtls_ctr_drbg_set_prediction_resistance(&ctx, MBEDTLS_CTR_DRBG_PR_ON);
+ TEST_ASSERT(mbedtls_ctr_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_LEN;
- TEST_EQUAL( test_offset_idx, expected_idx );
+ TEST_EQUAL(test_offset_idx, expected_idx);
/* Finally, check setting entropy_len */
- mbedtls_ctr_drbg_set_entropy_len( &ctx, 42 );
- TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ mbedtls_ctr_drbg_set_entropy_len(&ctx, 42);
+ TEST_ASSERT(mbedtls_ctr_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_idx += 42;
- TEST_EQUAL( test_offset_idx, expected_idx );
+ TEST_EQUAL(test_offset_idx, expected_idx);
- mbedtls_ctr_drbg_set_entropy_len( &ctx, 13 );
- TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ mbedtls_ctr_drbg_set_entropy_len(&ctx, 13);
+ TEST_ASSERT(mbedtls_ctr_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_idx += 13;
- TEST_EQUAL( test_offset_idx, expected_idx );
+ TEST_EQUAL(test_offset_idx, expected_idx);
exit:
- mbedtls_ctr_drbg_free( &ctx );
+ mbedtls_ctr_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
-void ctr_drbg_seed_file( char * path, int ret )
+void ctr_drbg_seed_file(char *path, int ret)
{
mbedtls_ctr_drbg_context ctx;
- mbedtls_ctr_drbg_init( &ctx );
+ mbedtls_ctr_drbg_init(&ctx);
- TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx, mbedtls_test_rnd_std_rand,
- NULL, NULL, 0 ) == 0 );
- TEST_ASSERT( mbedtls_ctr_drbg_write_seed_file( &ctx, path ) == ret );
- TEST_ASSERT( mbedtls_ctr_drbg_update_seed_file( &ctx, path ) == ret );
+ TEST_ASSERT(mbedtls_ctr_drbg_seed(&ctx, mbedtls_test_rnd_std_rand,
+ NULL, NULL, 0) == 0);
+ TEST_ASSERT(mbedtls_ctr_drbg_write_seed_file(&ctx, path) == ret);
+ TEST_ASSERT(mbedtls_ctr_drbg_update_seed_file(&ctx, path) == ret);
exit:
- mbedtls_ctr_drbg_free( &ctx );
+ mbedtls_ctr_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void ctr_drbg_selftest( )
+void ctr_drbg_selftest()
{
- TEST_ASSERT( mbedtls_ctr_drbg_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_ctr_drbg_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_debug.function b/tests/suites/test_suite_debug.function
index 85544b5..6a3ca33 100644
--- a/tests/suites/test_suite_debug.function
+++ b/tests/suites/test_suite_debug.function
@@ -3,8 +3,7 @@
#include "string.h"
#include "mbedtls/legacy_or_psa.h"
-struct buffer_data
-{
+struct buffer_data {
char buf[2000];
char *ptr;
};
@@ -15,29 +14,32 @@
char *p = buffer->ptr;
((void) level);
- memcpy( p, file, strlen( file ) );
- p += strlen( file );
+ memcpy(p, file, strlen(file));
+ p += strlen(file);
*p++ = '(';
- *p++ = '0' + ( line / 1000 ) % 10;
- *p++ = '0' + ( line / 100 ) % 10;
- *p++ = '0' + ( line / 10 ) % 10;
- *p++ = '0' + ( line / 1 ) % 10;
+ *p++ = '0' + (line / 1000) % 10;
+ *p++ = '0' + (line / 100) % 10;
+ *p++ = '0' + (line / 10) % 10;
+ *p++ = '0' + (line / 1) % 10;
*p++ = ')';
*p++ = ':';
*p++ = ' ';
#if defined(MBEDTLS_THREADING_C)
/* Skip "thread ID" (up to the first space) as it is not predictable */
- while( *str++ != ' ' );
+ while (*str++ != ' ') {
+ ;
+ }
#endif
- memcpy( p, str, strlen( str ) );
- p += strlen( str );
+ memcpy(p, str, strlen(str));
+ p += strlen(str);
/* Detect if debug messages output partial lines and mark them */
- if( p[-1] != '\n' )
+ if (p[-1] != '\n') {
*p++ = '*';
+ }
buffer->ptr = p;
}
@@ -49,173 +51,173 @@
*/
/* BEGIN_CASE */
-void debug_print_msg_threshold( int threshold, int level, char * file,
- int line, char * result_str )
+void debug_print_msg_threshold(int threshold, int level, char *file,
+ int line, char *result_str)
{
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
struct buffer_data buffer;
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
- memset( buffer.buf, 0, 2000 );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
+ memset(buffer.buf, 0, 2000);
buffer.ptr = buffer.buf;
- mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT );
+ mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT);
- mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
+ mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
- mbedtls_debug_set_threshold( threshold );
+ mbedtls_debug_set_threshold(threshold);
- mbedtls_debug_print_msg( &ssl, level, file, line,
- "Text message, 2 == %d", 2 );
+ mbedtls_debug_print_msg(&ssl, level, file, line,
+ "Text message, 2 == %d", 2);
- TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
exit:
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_debug_print_ret( char * file, int line, char * text, int value,
- char * result_str )
+void mbedtls_debug_print_ret(char *file, int line, char *text, int value,
+ char *result_str)
{
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
struct buffer_data buffer;
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
- memset( buffer.buf, 0, 2000 );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
+ memset(buffer.buf, 0, 2000);
buffer.ptr = buffer.buf;
- mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT );
+ mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT);
- mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
+ mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
- mbedtls_debug_print_ret( &ssl, 0, file, line, text, value);
+ mbedtls_debug_print_ret(&ssl, 0, file, line, text, value);
- TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
exit:
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_debug_print_buf( char * file, int line, char * text,
- data_t * data, char * result_str )
+void mbedtls_debug_print_buf(char *file, int line, char *text,
+ data_t *data, char *result_str)
{
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
struct buffer_data buffer;
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
- memset( buffer.buf, 0, 2000 );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
+ memset(buffer.buf, 0, 2000);
buffer.ptr = buffer.buf;
- mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT );
+ mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT);
- mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
+ mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
- mbedtls_debug_print_buf( &ssl, 0, file, line, text, data->x, data->len );
+ mbedtls_debug_print_buf(&ssl, 0, file, line, text, data->x, data->len);
- TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
exit:
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void mbedtls_debug_print_crt( char * crt_file, char * file, int line,
- char * prefix, char * result_str )
+void mbedtls_debug_print_crt(char *crt_file, char *file, int line,
+ char *prefix, char *result_str)
{
mbedtls_x509_crt crt;
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
struct buffer_data buffer;
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
- mbedtls_x509_crt_init( &crt );
- memset( buffer.buf, 0, 2000 );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
+ mbedtls_x509_crt_init(&crt);
+ memset(buffer.buf, 0, 2000);
buffer.ptr = buffer.buf;
- mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT );
+ mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT);
- mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
+ mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
- mbedtls_debug_print_crt( &ssl, 0, file, line, prefix, &crt);
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
+ mbedtls_debug_print_crt(&ssl, 0, file, line, prefix, &crt);
- TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
exit:
- mbedtls_x509_crt_free( &crt );
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */
-void mbedtls_debug_print_mpi( char * value, char * file, int line,
- char * prefix, char * result_str )
+void mbedtls_debug_print_mpi(char *value, char *file, int line,
+ char *prefix, char *result_str)
{
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
struct buffer_data buffer;
mbedtls_mpi val;
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
- mbedtls_mpi_init( &val );
- memset( buffer.buf, 0, 2000 );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
+ mbedtls_mpi_init(&val);
+ memset(buffer.buf, 0, 2000);
buffer.ptr = buffer.buf;
- mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT );
+ mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT);
- mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
+ mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &val, value ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&val, value) == 0);
- mbedtls_debug_print_mpi( &ssl, 0, file, line, prefix, &val);
+ mbedtls_debug_print_mpi(&ssl, 0, file, line, prefix, &val);
- TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
exit:
- mbedtls_mpi_free( &val );
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_mpi_free(&val);
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_des.function b/tests/suites/test_suite_des.function
index 7256fb5..b846d77 100644
--- a/tests/suites/test_suite_des.function
+++ b/tests/suites/test_suite_des.function
@@ -8,269 +8,273 @@
*/
/* BEGIN_CASE */
-void des_check_weak( data_t * key, int ret )
+void des_check_weak(data_t *key, int ret)
{
- TEST_ASSERT( mbedtls_des_key_check_weak( key->x ) == ret );
+ TEST_ASSERT(mbedtls_des_key_check_weak(key->x) == ret);
}
/* END_CASE */
/* BEGIN_CASE */
-void des_encrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
+void des_encrypt_ecb(data_t *key_str, data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_des_context ctx;
memset(output, 0x00, 100);
- mbedtls_des_init( &ctx );
+ mbedtls_des_init(&ctx);
- TEST_ASSERT( mbedtls_des_setkey_enc( &ctx, key_str->x ) == 0 );
- TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_des_setkey_enc(&ctx, key_str->x) == 0);
+ TEST_ASSERT(mbedtls_des_crypt_ecb(&ctx, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 8, dst->len) == 0);
exit:
- mbedtls_des_free( &ctx );
+ mbedtls_des_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void des_decrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
+void des_decrypt_ecb(data_t *key_str, data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_des_context ctx;
memset(output, 0x00, 100);
- mbedtls_des_init( &ctx );
+ mbedtls_des_init(&ctx);
- TEST_ASSERT( mbedtls_des_setkey_dec( &ctx, key_str->x ) == 0 );
- TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_des_setkey_dec(&ctx, key_str->x) == 0);
+ TEST_ASSERT(mbedtls_des_crypt_ecb(&ctx, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 8, dst->len) == 0);
exit:
- mbedtls_des_free( &ctx );
+ mbedtls_des_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void des_encrypt_cbc( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst, int cbc_result )
+void des_encrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst, int cbc_result)
{
unsigned char output[100];
mbedtls_des_context ctx;
memset(output, 0x00, 100);
- mbedtls_des_init( &ctx );
+ mbedtls_des_init(&ctx);
- TEST_ASSERT( mbedtls_des_setkey_enc( &ctx, key_str->x ) == 0 );
- TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
- if( cbc_result == 0 )
- {
+ TEST_ASSERT(mbedtls_des_setkey_enc(&ctx, key_str->x) == 0);
+ TEST_ASSERT(mbedtls_des_crypt_cbc(&ctx, MBEDTLS_DES_ENCRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
- dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, src_str->len,
+ dst->len) == 0);
}
exit:
- mbedtls_des_free( &ctx );
+ mbedtls_des_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void des_decrypt_cbc( data_t * key_str, data_t * iv_str,
- data_t * src_str, data_t * dst,
- int cbc_result )
+void des_decrypt_cbc(data_t *key_str, data_t *iv_str,
+ data_t *src_str, data_t *dst,
+ int cbc_result)
{
unsigned char output[100];
mbedtls_des_context ctx;
memset(output, 0x00, 100);
- mbedtls_des_init( &ctx );
+ mbedtls_des_init(&ctx);
- TEST_ASSERT( mbedtls_des_setkey_dec( &ctx, key_str->x ) == 0 );
- TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
- if( cbc_result == 0 )
- {
+ TEST_ASSERT(mbedtls_des_setkey_dec(&ctx, key_str->x) == 0);
+ TEST_ASSERT(mbedtls_des_crypt_cbc(&ctx, MBEDTLS_DES_DECRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
- dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, src_str->len,
+ dst->len) == 0);
}
exit:
- mbedtls_des_free( &ctx );
+ mbedtls_des_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void des3_encrypt_ecb( int key_count, data_t * key_str,
- data_t * src_str, data_t * dst )
+void des3_encrypt_ecb(int key_count, data_t *key_str,
+ data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_des3_context ctx;
memset(output, 0x00, 100);
- mbedtls_des3_init( &ctx );
+ mbedtls_des3_init(&ctx);
- if( key_count == 2 )
- TEST_ASSERT( mbedtls_des3_set2key_enc( &ctx, key_str->x ) == 0 );
- else if( key_count == 3 )
- TEST_ASSERT( mbedtls_des3_set3key_enc( &ctx, key_str->x ) == 0 );
- else
- TEST_ASSERT( 0 );
+ if (key_count == 2) {
+ TEST_ASSERT(mbedtls_des3_set2key_enc(&ctx, key_str->x) == 0);
+ } else if (key_count == 3) {
+ TEST_ASSERT(mbedtls_des3_set3key_enc(&ctx, key_str->x) == 0);
+ } else {
+ TEST_ASSERT(0);
+ }
- TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_des3_crypt_ecb(&ctx, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 8, dst->len) == 0);
exit:
- mbedtls_des3_free( &ctx );
+ mbedtls_des3_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void des3_decrypt_ecb( int key_count, data_t * key_str,
- data_t * src_str, data_t * dst )
+void des3_decrypt_ecb(int key_count, data_t *key_str,
+ data_t *src_str, data_t *dst)
{
unsigned char output[100];
mbedtls_des3_context ctx;
memset(output, 0x00, 100);
- mbedtls_des3_init( &ctx );
+ mbedtls_des3_init(&ctx);
- if( key_count == 2 )
- TEST_ASSERT( mbedtls_des3_set2key_dec( &ctx, key_str->x ) == 0 );
- else if( key_count == 3 )
- TEST_ASSERT( mbedtls_des3_set3key_dec( &ctx, key_str->x ) == 0 );
- else
- TEST_ASSERT( 0 );
+ if (key_count == 2) {
+ TEST_ASSERT(mbedtls_des3_set2key_dec(&ctx, key_str->x) == 0);
+ } else if (key_count == 3) {
+ TEST_ASSERT(mbedtls_des3_set3key_dec(&ctx, key_str->x) == 0);
+ } else {
+ TEST_ASSERT(0);
+ }
- TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_des3_crypt_ecb(&ctx, src_str->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 8, dst->len) == 0);
exit:
- mbedtls_des3_free( &ctx );
+ mbedtls_des3_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void des3_encrypt_cbc( int key_count, data_t * key_str,
- data_t * iv_str, data_t * src_str,
- data_t * dst, int cbc_result )
+void des3_encrypt_cbc(int key_count, data_t *key_str,
+ data_t *iv_str, data_t *src_str,
+ data_t *dst, int cbc_result)
{
unsigned char output[100];
mbedtls_des3_context ctx;
memset(output, 0x00, 100);
- mbedtls_des3_init( &ctx );
+ mbedtls_des3_init(&ctx);
- if( key_count == 2 )
- TEST_ASSERT( mbedtls_des3_set2key_enc( &ctx, key_str->x ) == 0 );
- else if( key_count == 3 )
- TEST_ASSERT( mbedtls_des3_set3key_enc( &ctx, key_str->x ) == 0 );
- else
- TEST_ASSERT( 0 );
+ if (key_count == 2) {
+ TEST_ASSERT(mbedtls_des3_set2key_enc(&ctx, key_str->x) == 0);
+ } else if (key_count == 3) {
+ TEST_ASSERT(mbedtls_des3_set3key_enc(&ctx, key_str->x) == 0);
+ } else {
+ TEST_ASSERT(0);
+ }
- TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
+ TEST_ASSERT(mbedtls_des3_crypt_cbc(&ctx, MBEDTLS_DES_ENCRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
- if( cbc_result == 0 )
- {
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
- src_str->len, dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
+ src_str->len, dst->len) == 0);
}
exit:
- mbedtls_des3_free( &ctx );
+ mbedtls_des3_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
-void des3_decrypt_cbc( int key_count, data_t * key_str,
- data_t * iv_str, data_t * src_str,
- data_t * dst, int cbc_result )
+void des3_decrypt_cbc(int key_count, data_t *key_str,
+ data_t *iv_str, data_t *src_str,
+ data_t *dst, int cbc_result)
{
unsigned char output[100];
mbedtls_des3_context ctx;
memset(output, 0x00, 100);
- mbedtls_des3_init( &ctx );
+ mbedtls_des3_init(&ctx);
- if( key_count == 2 )
- TEST_ASSERT( mbedtls_des3_set2key_dec( &ctx, key_str->x ) == 0 );
- else if( key_count == 3 )
- TEST_ASSERT( mbedtls_des3_set3key_dec( &ctx, key_str->x ) == 0 );
- else
- TEST_ASSERT( 0 );
+ if (key_count == 2) {
+ TEST_ASSERT(mbedtls_des3_set2key_dec(&ctx, key_str->x) == 0);
+ } else if (key_count == 3) {
+ TEST_ASSERT(mbedtls_des3_set3key_dec(&ctx, key_str->x) == 0);
+ } else {
+ TEST_ASSERT(0);
+ }
- TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
+ TEST_ASSERT(mbedtls_des3_crypt_cbc(&ctx, MBEDTLS_DES_DECRYPT, src_str->len, iv_str->x,
+ src_str->x, output) == cbc_result);
- if( cbc_result == 0 )
- {
+ if (cbc_result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, src_str->len,
- dst->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, src_str->len,
+ dst->len) == 0);
}
exit:
- mbedtls_des3_free( &ctx );
+ mbedtls_des3_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void des_key_parity_run( )
+void des_key_parity_run()
{
int i, j, cnt;
unsigned char key[MBEDTLS_DES_KEY_SIZE];
unsigned int parity;
- memset( key, 0, MBEDTLS_DES_KEY_SIZE );
+ memset(key, 0, MBEDTLS_DES_KEY_SIZE);
cnt = 0;
// Iterate through all possible byte values
//
- for( i = 0; i < 32; i++ )
- {
- for( j = 0; j < 8; j++ )
+ for (i = 0; i < 32; i++) {
+ for (j = 0; j < 8; j++) {
key[j] = cnt++;
+ }
// Set the key parity according to the table
//
- mbedtls_des_key_set_parity( key );
+ mbedtls_des_key_set_parity(key);
// Check the parity with a function
//
- for( j = 0; j < 8; j++ )
- {
- parity = key[j] ^ ( key[j] >> 4 );
+ for (j = 0; j < 8; j++) {
+ parity = key[j] ^ (key[j] >> 4);
parity = parity ^
- ( parity >> 1 ) ^
- ( parity >> 2 ) ^
- ( parity >> 3 );
+ (parity >> 1) ^
+ (parity >> 2) ^
+ (parity >> 3);
parity &= 1;
- if( parity != 1 )
- TEST_ASSERT( 0 );
+ if (parity != 1) {
+ TEST_ASSERT(0);
+ }
}
// Check the parity with the table
//
- TEST_ASSERT( mbedtls_des_key_check_key_parity( key ) == 0 );
+ TEST_ASSERT(mbedtls_des_key_check_key_parity(key) == 0);
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void des_selftest( )
+void des_selftest()
{
- TEST_ASSERT( mbedtls_des_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_des_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_dhm.function b/tests/suites/test_suite_dhm.function
index d74c24d..e6f75de 100644
--- a/tests/suites/test_suite_dhm.function
+++ b/tests/suites/test_suite_dhm.function
@@ -1,83 +1,86 @@
/* BEGIN_HEADER */
#include "mbedtls/dhm.h"
-int check_get_value( const mbedtls_dhm_context *ctx,
- mbedtls_dhm_parameter param,
- const mbedtls_mpi *expected )
+int check_get_value(const mbedtls_dhm_context *ctx,
+ mbedtls_dhm_parameter param,
+ const mbedtls_mpi *expected)
{
mbedtls_mpi actual;
int ok = 0;
- mbedtls_mpi_init( &actual );
+ mbedtls_mpi_init(&actual);
- TEST_ASSERT( mbedtls_dhm_get_value( ctx, param, &actual ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &actual, expected ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_get_value(ctx, param, &actual) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&actual, expected) == 0);
ok = 1;
exit:
- mbedtls_mpi_free( &actual );
- return( ok );
+ mbedtls_mpi_free(&actual);
+ return ok;
}
/* Sanity checks on a Diffie-Hellman parameter: check the length-value
* syntax and check that the value is the expected one (taken from the
* DHM context by the caller). */
-static int check_dhm_param_output( const mbedtls_mpi *expected,
- const unsigned char *buffer,
- size_t size,
- size_t *offset )
+static int check_dhm_param_output(const mbedtls_mpi *expected,
+ const unsigned char *buffer,
+ size_t size,
+ size_t *offset)
{
size_t n;
mbedtls_mpi actual;
int ok = 0;
- mbedtls_mpi_init( &actual );
+ mbedtls_mpi_init(&actual);
++mbedtls_test_info.step;
- TEST_ASSERT( size >= *offset + 2 );
- n = ( buffer[*offset] << 8 ) | buffer[*offset + 1];
+ TEST_ASSERT(size >= *offset + 2);
+ n = (buffer[*offset] << 8) | buffer[*offset + 1];
*offset += 2;
/* The DHM param output from Mbed TLS has leading zeros stripped, as
* permitted but not required by RFC 5246 \S4.4. */
- TEST_EQUAL( n, mbedtls_mpi_size( expected ) );
- TEST_ASSERT( size >= *offset + n );
- TEST_EQUAL( 0, mbedtls_mpi_read_binary( &actual, buffer + *offset, n ) );
- TEST_EQUAL( 0, mbedtls_mpi_cmp_mpi( expected, &actual ) );
+ TEST_EQUAL(n, mbedtls_mpi_size(expected));
+ TEST_ASSERT(size >= *offset + n);
+ TEST_EQUAL(0, mbedtls_mpi_read_binary(&actual, buffer + *offset, n));
+ TEST_EQUAL(0, mbedtls_mpi_cmp_mpi(expected, &actual));
*offset += n;
ok = 1;
exit:
- mbedtls_mpi_free( &actual );
- return( ok );
+ mbedtls_mpi_free(&actual);
+ return ok;
}
/* Sanity checks on Diffie-Hellman parameters: syntax, range, and comparison
* against the context. */
-static int check_dhm_params( const mbedtls_dhm_context *ctx,
- size_t x_size,
- const unsigned char *ske, size_t ske_len )
+static int check_dhm_params(const mbedtls_dhm_context *ctx,
+ size_t x_size,
+ const unsigned char *ske, size_t ske_len)
{
size_t offset = 0;
/* Check that ctx->X and ctx->GX are within range. */
- TEST_ASSERT( mbedtls_mpi_cmp_int( &ctx->X, 1 ) > 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &ctx->X, &ctx->P ) < 0 );
- TEST_ASSERT( mbedtls_mpi_size( &ctx->X ) <= x_size );
- TEST_ASSERT( mbedtls_mpi_cmp_int( &ctx->GX, 1 ) > 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &ctx->GX, &ctx->P ) < 0 );
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&ctx->X, 1) > 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&ctx->X, &ctx->P) < 0);
+ TEST_ASSERT(mbedtls_mpi_size(&ctx->X) <= x_size);
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&ctx->GX, 1) > 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&ctx->GX, &ctx->P) < 0);
/* Check ske: it must contain P, G and G^X, each prefixed with a
* 2-byte size. */
- if( !check_dhm_param_output( &ctx->P, ske, ske_len, &offset ) )
+ if (!check_dhm_param_output(&ctx->P, ske, ske_len, &offset)) {
goto exit;
- if( !check_dhm_param_output( &ctx->G, ske, ske_len, &offset ) )
+ }
+ if (!check_dhm_param_output(&ctx->G, ske, ske_len, &offset)) {
goto exit;
- if( !check_dhm_param_output( &ctx->GX, ske, ske_len, &offset ) )
+ }
+ if (!check_dhm_param_output(&ctx->GX, ske, ske_len, &offset)) {
goto exit;
- TEST_EQUAL( offset, ske_len );
+ }
+ TEST_EQUAL(offset, ske_len);
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
/* END_HEADER */
@@ -88,8 +91,8 @@
*/
/* BEGIN_CASE */
-void dhm_do_dhm( char *input_P, int x_size,
- char *input_G, int result )
+void dhm_do_dhm(char *input_P, int x_size,
+ char *input_G, int result)
{
mbedtls_dhm_context ctx_srv;
mbedtls_dhm_context ctx_cli;
@@ -105,84 +108,85 @@
int i;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_dhm_init( &ctx_srv );
- mbedtls_dhm_init( &ctx_cli );
- memset( ske, 0x00, 1000 );
- memset( pub_cli, 0x00, 1000 );
- memset( sec_srv, 0x00, 1000 );
- memset( sec_cli, 0x00, 1000 );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_dhm_init(&ctx_srv);
+ mbedtls_dhm_init(&ctx_cli);
+ memset(ske, 0x00, 1000);
+ memset(pub_cli, 0x00, 1000);
+ memset(sec_srv, 0x00, 1000);
+ memset(sec_cli, 0x00, 1000);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
/*
* Set params
*/
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx_srv.P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx_srv.G, input_G ) == 0 );
- pub_cli_len = mbedtls_mpi_size( &ctx_srv.P );
- TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_P, &ctx_srv.P ) );
- TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_G, &ctx_srv.G ) );
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx_srv.P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx_srv.G, input_G) == 0);
+ pub_cli_len = mbedtls_mpi_size(&ctx_srv.P);
+ TEST_ASSERT(check_get_value(&ctx_srv, MBEDTLS_DHM_PARAM_P, &ctx_srv.P));
+ TEST_ASSERT(check_get_value(&ctx_srv, MBEDTLS_DHM_PARAM_G, &ctx_srv.G));
/*
* First key exchange
*/
- mbedtls_test_set_step( 10 );
- TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == result );
- if ( result != 0 )
+ mbedtls_test_set_step(10);
+ TEST_ASSERT(mbedtls_dhm_make_params(&ctx_srv, x_size, ske, &ske_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == result);
+ if (result != 0) {
goto exit;
- if( !check_dhm_params( &ctx_srv, x_size, ske, ske_len ) )
+ }
+ if (!check_dhm_params(&ctx_srv, x_size, ske, ske_len)) {
goto exit;
+ }
ske[ske_len++] = 0;
ske[ske_len++] = 0;
- TEST_ASSERT( mbedtls_dhm_read_params( &ctx_cli, &p, ske + ske_len ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_read_params(&ctx_cli, &p, ske + ske_len) == 0);
/* The domain parameters must be the same on both side. */
- TEST_ASSERT( check_get_value( &ctx_cli, MBEDTLS_DHM_PARAM_P, &ctx_srv.P ) );
- TEST_ASSERT( check_get_value( &ctx_cli, MBEDTLS_DHM_PARAM_G, &ctx_srv.G ) );
+ TEST_ASSERT(check_get_value(&ctx_cli, MBEDTLS_DHM_PARAM_P, &ctx_srv.P));
+ TEST_ASSERT(check_get_value(&ctx_cli, MBEDTLS_DHM_PARAM_G, &ctx_srv.G));
- TEST_ASSERT( mbedtls_dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_dhm_read_public( &ctx_srv, pub_cli, pub_cli_len ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_make_public(&ctx_cli, x_size, pub_cli, pub_cli_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_dhm_read_public(&ctx_srv, pub_cli, pub_cli_len) == 0);
- TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ),
- &sec_srv_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ),
- &sec_cli_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_calc_secret(&ctx_srv, sec_srv, sizeof(sec_srv),
+ &sec_srv_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_dhm_calc_secret(&ctx_cli, sec_cli, sizeof(sec_cli),
+ &sec_cli_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( sec_srv_len == sec_cli_len );
- TEST_ASSERT( sec_srv_len != 0 );
- TEST_ASSERT( memcmp( sec_srv, sec_cli, sec_srv_len ) == 0 );
+ TEST_ASSERT(sec_srv_len == sec_cli_len);
+ TEST_ASSERT(sec_srv_len != 0);
+ TEST_ASSERT(memcmp(sec_srv, sec_cli, sec_srv_len) == 0);
/* Internal value checks */
- TEST_ASSERT( check_get_value( &ctx_cli, MBEDTLS_DHM_PARAM_X, &ctx_cli.X ) );
- TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_X, &ctx_srv.X ) );
+ TEST_ASSERT(check_get_value(&ctx_cli, MBEDTLS_DHM_PARAM_X, &ctx_cli.X));
+ TEST_ASSERT(check_get_value(&ctx_srv, MBEDTLS_DHM_PARAM_X, &ctx_srv.X));
/* Cross-checks */
- TEST_ASSERT( check_get_value( &ctx_cli, MBEDTLS_DHM_PARAM_GX, &ctx_srv.GY ) );
- TEST_ASSERT( check_get_value( &ctx_cli, MBEDTLS_DHM_PARAM_GY, &ctx_srv.GX ) );
- TEST_ASSERT( check_get_value( &ctx_cli, MBEDTLS_DHM_PARAM_K, &ctx_srv.K ) );
- TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_GX, &ctx_cli.GY ) );
- TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_GY, &ctx_cli.GX ) );
- TEST_ASSERT( check_get_value( &ctx_srv, MBEDTLS_DHM_PARAM_K, &ctx_cli.K ) );
+ TEST_ASSERT(check_get_value(&ctx_cli, MBEDTLS_DHM_PARAM_GX, &ctx_srv.GY));
+ TEST_ASSERT(check_get_value(&ctx_cli, MBEDTLS_DHM_PARAM_GY, &ctx_srv.GX));
+ TEST_ASSERT(check_get_value(&ctx_cli, MBEDTLS_DHM_PARAM_K, &ctx_srv.K));
+ TEST_ASSERT(check_get_value(&ctx_srv, MBEDTLS_DHM_PARAM_GX, &ctx_cli.GY));
+ TEST_ASSERT(check_get_value(&ctx_srv, MBEDTLS_DHM_PARAM_GY, &ctx_cli.GX));
+ TEST_ASSERT(check_get_value(&ctx_srv, MBEDTLS_DHM_PARAM_K, &ctx_cli.K));
/* Re-do calc_secret on server a few times to test update of blinding values */
- for( i = 0; i < 3; i++ )
- {
- mbedtls_test_set_step( 20 + i );
+ for (i = 0; i < 3; i++) {
+ mbedtls_test_set_step(20 + i);
sec_srv_len = 1000;
- TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv,
- sizeof( sec_srv ), &sec_srv_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_calc_secret(&ctx_srv, sec_srv,
+ sizeof(sec_srv), &sec_srv_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( sec_srv_len == sec_cli_len );
- TEST_ASSERT( sec_srv_len != 0 );
- TEST_ASSERT( memcmp( sec_srv, sec_cli, sec_srv_len ) == 0 );
+ TEST_ASSERT(sec_srv_len == sec_cli_len);
+ TEST_ASSERT(sec_srv_len != 0);
+ TEST_ASSERT(memcmp(sec_srv, sec_cli, sec_srv_len) == 0);
}
/*
@@ -190,98 +194,99 @@
*/
p = ske;
- mbedtls_test_set_step( 30 );
- TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- if( !check_dhm_params( &ctx_srv, x_size, ske, ske_len ) )
+ mbedtls_test_set_step(30);
+ TEST_ASSERT(mbedtls_dhm_make_params(&ctx_srv, x_size, ske, &ske_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ if (!check_dhm_params(&ctx_srv, x_size, ske, ske_len)) {
goto exit;
+ }
ske[ske_len++] = 0;
ske[ske_len++] = 0;
- TEST_ASSERT( mbedtls_dhm_read_params( &ctx_cli, &p, ske + ske_len ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_read_params(&ctx_cli, &p, ske + ske_len) == 0);
- TEST_ASSERT( mbedtls_dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_dhm_read_public( &ctx_srv, pub_cli, pub_cli_len ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_make_public(&ctx_cli, x_size, pub_cli, pub_cli_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_dhm_read_public(&ctx_srv, pub_cli, pub_cli_len) == 0);
- TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ),
- &sec_srv_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ),
- &sec_cli_len,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_calc_secret(&ctx_srv, sec_srv, sizeof(sec_srv),
+ &sec_srv_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_dhm_calc_secret(&ctx_cli, sec_cli, sizeof(sec_cli),
+ &sec_cli_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( sec_srv_len == sec_cli_len );
- TEST_ASSERT( sec_srv_len != 0 );
- TEST_ASSERT( memcmp( sec_srv, sec_cli, sec_srv_len ) == 0 );
+ TEST_ASSERT(sec_srv_len == sec_cli_len);
+ TEST_ASSERT(sec_srv_len != 0);
+ TEST_ASSERT(memcmp(sec_srv, sec_cli, sec_srv_len) == 0);
exit:
- mbedtls_dhm_free( &ctx_srv );
- mbedtls_dhm_free( &ctx_cli );
+ mbedtls_dhm_free(&ctx_srv);
+ mbedtls_dhm_free(&ctx_cli);
}
/* END_CASE */
/* BEGIN_CASE */
-void dhm_make_public( int P_bytes, char *input_G, int result )
+void dhm_make_public(int P_bytes, char *input_G, int result)
{
mbedtls_mpi P, G;
mbedtls_dhm_context ctx;
unsigned char output[MBEDTLS_MPI_MAX_SIZE];
- mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &G );
- mbedtls_dhm_init( &ctx );
+ mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&G);
+ mbedtls_dhm_init(&ctx);
- TEST_ASSERT( mbedtls_mpi_lset( &P, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_shift_l( &P, ( P_bytes * 8 ) - 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_set_bit( &P, 0, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_lset(&P, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_shift_l(&P, (P_bytes * 8) - 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_set_bit(&P, 0, 1) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &G, input_G ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&G, input_G) == 0);
- TEST_ASSERT( mbedtls_dhm_set_group( &ctx, &P, &G ) == 0 );
- TEST_ASSERT( mbedtls_dhm_make_public( &ctx, (int) mbedtls_mpi_size( &P ),
- output, sizeof(output),
- &mbedtls_test_rnd_pseudo_rand,
- NULL ) == result );
+ TEST_ASSERT(mbedtls_dhm_set_group(&ctx, &P, &G) == 0);
+ TEST_ASSERT(mbedtls_dhm_make_public(&ctx, (int) mbedtls_mpi_size(&P),
+ output, sizeof(output),
+ &mbedtls_test_rnd_pseudo_rand,
+ NULL) == result);
exit:
- mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &G );
- mbedtls_dhm_free( &ctx );
+ mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&G);
+ mbedtls_dhm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
-void dhm_file( char * filename, char * p, char * g, int len )
+void dhm_file(char *filename, char *p, char *g, int len)
{
mbedtls_dhm_context ctx;
mbedtls_mpi P, G;
- mbedtls_dhm_init( &ctx );
- mbedtls_mpi_init( &P ); mbedtls_mpi_init( &G );
+ mbedtls_dhm_init(&ctx);
+ mbedtls_mpi_init(&P); mbedtls_mpi_init(&G);
- TEST_ASSERT( mbedtls_test_read_mpi( &P, p ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &G, g ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, p) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&G, g) == 0);
- TEST_ASSERT( mbedtls_dhm_parse_dhmfile( &ctx, filename ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_parse_dhmfile(&ctx, filename) == 0);
- TEST_EQUAL( mbedtls_dhm_get_len( &ctx ), (size_t) len );
- TEST_EQUAL( mbedtls_dhm_get_bitlen( &ctx ), mbedtls_mpi_bitlen( &P ) );
- TEST_ASSERT( check_get_value( &ctx, MBEDTLS_DHM_PARAM_P, &P ) );
- TEST_ASSERT( check_get_value( &ctx, MBEDTLS_DHM_PARAM_G, &G ) );
+ TEST_EQUAL(mbedtls_dhm_get_len(&ctx), (size_t) len);
+ TEST_EQUAL(mbedtls_dhm_get_bitlen(&ctx), mbedtls_mpi_bitlen(&P));
+ TEST_ASSERT(check_get_value(&ctx, MBEDTLS_DHM_PARAM_P, &P));
+ TEST_ASSERT(check_get_value(&ctx, MBEDTLS_DHM_PARAM_G, &G));
exit:
- mbedtls_mpi_free( &P ); mbedtls_mpi_free( &G );
- mbedtls_dhm_free( &ctx );
+ mbedtls_mpi_free(&P); mbedtls_mpi_free(&G);
+ mbedtls_dhm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void dhm_selftest( )
+void dhm_selftest()
{
- TEST_ASSERT( mbedtls_dhm_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_dhm_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_ecdh.function b/tests/suites/test_suite_ecdh.function
index 515a974..cc193da 100644
--- a/tests/suites/test_suite_ecdh.function
+++ b/tests/suites/test_suite_ecdh.function
@@ -1,39 +1,39 @@
/* BEGIN_HEADER */
#include "mbedtls/ecdh.h"
-static int load_public_key( int grp_id, data_t *point,
- mbedtls_ecp_keypair *ecp )
+static int load_public_key(int grp_id, data_t *point,
+ mbedtls_ecp_keypair *ecp)
{
int ok = 0;
- TEST_ASSERT( mbedtls_ecp_group_load( &ecp->grp, grp_id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_binary( &ecp->grp,
- &ecp->Q,
- point->x,
- point->len ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &ecp->grp,
- &ecp->Q ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&ecp->grp, grp_id) == 0);
+ TEST_ASSERT(mbedtls_ecp_point_read_binary(&ecp->grp,
+ &ecp->Q,
+ point->x,
+ point->len) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&ecp->grp,
+ &ecp->Q) == 0);
ok = 1;
exit:
- return( ok );
+ return ok;
}
-static int load_private_key( int grp_id, data_t *private_key,
- mbedtls_ecp_keypair *ecp,
- mbedtls_test_rnd_pseudo_info *rnd_info )
+static int load_private_key(int grp_id, data_t *private_key,
+ mbedtls_ecp_keypair *ecp,
+ mbedtls_test_rnd_pseudo_info *rnd_info)
{
int ok = 0;
- TEST_ASSERT( mbedtls_ecp_read_key( grp_id, ecp,
- private_key->x,
- private_key->len ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_privkey( &ecp->grp, &ecp->d ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_read_key(grp_id, ecp,
+ private_key->x,
+ private_key->len) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_privkey(&ecp->grp, &ecp->d) == 0);
/* Calculate the public key from the private key. */
- TEST_ASSERT( mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d,
- &ecp->grp.G,
- &mbedtls_test_rnd_pseudo_rand,
- rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_mul(&ecp->grp, &ecp->Q, &ecp->d,
+ &ecp->grp.G,
+ &mbedtls_test_rnd_pseudo_rand,
+ rnd_info) == 0);
ok = 1;
exit:
- return( ok );
+ return ok;
}
/* END_HEADER */
@@ -44,18 +44,18 @@
*/
/* BEGIN_CASE */
-void ecdh_invalid_param( )
+void ecdh_invalid_param()
{
mbedtls_ecdh_context ctx;
mbedtls_ecp_keypair kp;
int invalid_side = 42;
- mbedtls_ecdh_init( &ctx );
- mbedtls_ecp_keypair_init( &kp );
+ mbedtls_ecdh_init(&ctx);
+ mbedtls_ecp_keypair_init(&kp);
- TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_get_params( &ctx, &kp,
- invalid_side ) );
+ TEST_EQUAL(MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ mbedtls_ecdh_get_params(&ctx, &kp,
+ invalid_side));
exit:
return;
@@ -63,48 +63,48 @@
/* END_CASE */
/* BEGIN_CASE */
-void ecdh_primitive_random( int id )
+void ecdh_primitive_random(int id)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point qA, qB;
mbedtls_mpi dA, dB, zA, zB;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &qA ); mbedtls_ecp_point_init( &qB );
- mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &dB );
- mbedtls_mpi_init( &zA ); mbedtls_mpi_init( &zB );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&qA); mbedtls_ecp_point_init(&qB);
+ mbedtls_mpi_init(&dA); mbedtls_mpi_init(&dB);
+ mbedtls_mpi_init(&zA); mbedtls_mpi_init(&zB);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_gen_public(&grp, &dA, &qA,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdh_gen_public(&grp, &dB, &qB,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdh_compute_shared(&grp, &zA, &qB, &dA,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdh_compute_shared(&grp, &zB, &qA, &dB,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zA, &zB ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&zA, &zB) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &qA ); mbedtls_ecp_point_free( &qB );
- mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &dB );
- mbedtls_mpi_free( &zA ); mbedtls_mpi_free( &zB );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&qA); mbedtls_ecp_point_free(&qB);
+ mbedtls_mpi_free(&dA); mbedtls_mpi_free(&dB);
+ mbedtls_mpi_free(&zA); mbedtls_mpi_free(&zB);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
- char * yA_str, data_t * rnd_buf_B,
- char * xB_str, char * yB_str, char * z_str )
+void ecdh_primitive_testvec(int id, data_t *rnd_buf_A, char *xA_str,
+ char *yA_str, data_t *rnd_buf_B,
+ char *xB_str, char *yB_str, char *z_str)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point qA, qB;
@@ -112,13 +112,13 @@
mbedtls_test_rnd_buf_info rnd_info_A, rnd_info_B;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &qA ); mbedtls_ecp_point_init( &qB );
- mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &dB );
- mbedtls_mpi_init( &zA ); mbedtls_mpi_init( &zB ); mbedtls_mpi_init( &check );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&qA); mbedtls_ecp_point_init(&qB);
+ mbedtls_mpi_init(&dA); mbedtls_mpi_init(&dB);
+ mbedtls_mpi_init(&zA); mbedtls_mpi_init(&zB); mbedtls_mpi_init(&check);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
rnd_info_A.buf = rnd_buf_A->x;
rnd_info_A.length = rnd_buf_A->len;
@@ -126,14 +126,14 @@
rnd_info_A.fallback_p_rng = NULL;
/* Fix rnd_buf_A->x by shifting it left if necessary */
- if( grp.nbits % 8 != 0 )
- {
- unsigned char shift = 8 - ( grp.nbits % 8 );
+ if (grp.nbits % 8 != 0) {
+ unsigned char shift = 8 - (grp.nbits % 8);
size_t i;
- for( i = 0; i < rnd_info_A.length - 1; i++ )
+ for (i = 0; i < rnd_info_A.length - 1; i++) {
rnd_buf_A->x[i] = rnd_buf_A->x[i] << shift
- | rnd_buf_A->x[i+1] >> ( 8 - shift );
+ | rnd_buf_A->x[i+1] >> (8 - shift);
+ }
rnd_buf_A->x[rnd_info_A.length-1] <<= shift;
}
@@ -144,56 +144,56 @@
rnd_info_B.fallback_p_rng = NULL;
/* Fix rnd_buf_B->x by shifting it left if necessary */
- if( grp.nbits % 8 != 0 )
- {
- unsigned char shift = 8 - ( grp.nbits % 8 );
+ if (grp.nbits % 8 != 0) {
+ unsigned char shift = 8 - (grp.nbits % 8);
size_t i;
- for( i = 0; i < rnd_info_B.length - 1; i++ )
+ for (i = 0; i < rnd_info_B.length - 1; i++) {
rnd_buf_B->x[i] = rnd_buf_B->x[i] << shift
- | rnd_buf_B->x[i+1] >> ( 8 - shift );
+ | rnd_buf_B->x[i+1] >> (8 - shift);
+ }
rnd_buf_B->x[rnd_info_B.length-1] <<= shift;
}
- TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA,
- mbedtls_test_rnd_buffer_rand,
- &rnd_info_A ) == 0 );
- TEST_ASSERT( ! mbedtls_ecp_is_zero( &qA ) );
- TEST_ASSERT( mbedtls_test_read_mpi( &check, xA_str ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.X, &check ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &check, yA_str ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.Y, &check ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_gen_public(&grp, &dA, &qA,
+ mbedtls_test_rnd_buffer_rand,
+ &rnd_info_A) == 0);
+ TEST_ASSERT(!mbedtls_ecp_is_zero(&qA));
+ TEST_ASSERT(mbedtls_test_read_mpi(&check, xA_str) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&qA.X, &check) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&check, yA_str) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&qA.Y, &check) == 0);
- TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB,
- mbedtls_test_rnd_buffer_rand,
- &rnd_info_B ) == 0 );
- TEST_ASSERT( ! mbedtls_ecp_is_zero( &qB ) );
- TEST_ASSERT( mbedtls_test_read_mpi( &check, xB_str ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.X, &check ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &check, yB_str ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.Y, &check ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_gen_public(&grp, &dB, &qB,
+ mbedtls_test_rnd_buffer_rand,
+ &rnd_info_B) == 0);
+ TEST_ASSERT(!mbedtls_ecp_is_zero(&qB));
+ TEST_ASSERT(mbedtls_test_read_mpi(&check, xB_str) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&qB.X, &check) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&check, yB_str) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&qB.Y, &check) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &check, z_str ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zA, &check ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zB, &check ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&check, z_str) == 0);
+ TEST_ASSERT(mbedtls_ecdh_compute_shared(&grp, &zA, &qB, &dA,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&zA, &check) == 0);
+ TEST_ASSERT(mbedtls_ecdh_compute_shared(&grp, &zB, &qA, &dB,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&zB, &check) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &qA ); mbedtls_ecp_point_free( &qB );
- mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &dB );
- mbedtls_mpi_free( &zA ); mbedtls_mpi_free( &zB ); mbedtls_mpi_free( &check );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&qA); mbedtls_ecp_point_free(&qB);
+ mbedtls_mpi_free(&dA); mbedtls_mpi_free(&dB);
+ mbedtls_mpi_free(&zA); mbedtls_mpi_free(&zB); mbedtls_mpi_free(&check);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecdh_exchange( int id )
+void ecdh_exchange(int id)
{
mbedtls_ecdh_context srv, cli;
unsigned char buf[1000];
@@ -203,42 +203,42 @@
unsigned char res_buf[1000];
size_t res_len;
- mbedtls_ecdh_init( &srv );
- mbedtls_ecdh_init( &cli );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecdh_init(&srv);
+ mbedtls_ecdh_init(&cli);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecdh_setup( &srv, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_setup(&srv, id) == 0);
- memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
- TEST_ASSERT( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
+ memset(buf, 0x00, sizeof(buf)); vbuf = buf;
+ TEST_ASSERT(mbedtls_ecdh_make_params(&srv, &len, buf, 1000,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdh_read_params(&cli, &vbuf, buf + len) == 0);
- memset( buf, 0x00, sizeof( buf ) );
- TEST_ASSERT( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
+ memset(buf, 0x00, sizeof(buf));
+ TEST_ASSERT(mbedtls_ecdh_make_public(&cli, &len, buf, 1000,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdh_read_public(&srv, buf, len) == 0);
- TEST_ASSERT( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &res_len, res_buf, 1000,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( len == res_len );
- TEST_ASSERT( memcmp( buf, res_buf, len ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_calc_secret(&srv, &len, buf, 1000,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdh_calc_secret(&cli, &res_len, res_buf, 1000,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(len == res_len);
+ TEST_ASSERT(memcmp(buf, res_buf, len) == 0);
exit:
- mbedtls_ecdh_free( &srv );
- mbedtls_ecdh_free( &cli );
+ mbedtls_ecdh_free(&srv);
+ mbedtls_ecdh_free(&cli);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE */
-void ecdh_restart( int id, data_t *dA, data_t *dB, data_t *z,
- int enable, int max_ops, int min_restart, int max_restart )
+void ecdh_restart(int id, data_t *dA, data_t *dB, data_t *z,
+ int enable, int max_ops, int min_restart, int max_restart)
{
int ret;
mbedtls_ecdh_context srv, cli;
@@ -250,10 +250,10 @@
int cnt_restart;
mbedtls_ecp_group grp;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecdh_init( &srv );
- mbedtls_ecdh_init( &cli );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecdh_init(&srv);
+ mbedtls_ecdh_init(&cli);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
rnd_info_A.fallback_f_rng = mbedtls_test_rnd_std_rand;
rnd_info_A.fallback_p_rng = NULL;
@@ -267,109 +267,108 @@
/* The ECDH context is not guaranteed to have an mbedtls_ecp_group structure
* in every configuration, therefore we load it separately. */
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
/* Otherwise we would have to fix the random buffer,
* as in ecdh_primitive_testvec. */
- TEST_ASSERT( grp.nbits % 8 == 0 );
+ TEST_ASSERT(grp.nbits % 8 == 0);
- TEST_ASSERT( mbedtls_ecdh_setup( &srv, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_setup(&srv, id) == 0);
/* set up restart parameters */
- mbedtls_ecp_set_max_ops( max_ops );
+ mbedtls_ecp_set_max_ops(max_ops);
- if( enable )
- {
- mbedtls_ecdh_enable_restart( &srv );
- mbedtls_ecdh_enable_restart( &cli );
+ if (enable) {
+ mbedtls_ecdh_enable_restart(&srv);
+ mbedtls_ecdh_enable_restart(&cli);
}
/* server writes its parameters */
- memset( buf, 0x00, sizeof( buf ) );
+ memset(buf, 0x00, sizeof(buf));
len = 0;
cnt_restart = 0;
do {
- ret = mbedtls_ecdh_make_params( &srv, &len, buf, sizeof( buf ),
- mbedtls_test_rnd_buffer_rand,
- &rnd_info_A );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_ecdh_make_params(&srv, &len, buf, sizeof(buf),
+ mbedtls_test_rnd_buffer_rand,
+ &rnd_info_A);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
/* client read server params */
vbuf = buf;
- TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_read_params(&cli, &vbuf, buf + len) == 0);
/* client writes its key share */
- memset( buf, 0x00, sizeof( buf ) );
+ memset(buf, 0x00, sizeof(buf));
len = 0;
cnt_restart = 0;
do {
- ret = mbedtls_ecdh_make_public( &cli, &len, buf, sizeof( buf ),
- mbedtls_test_rnd_buffer_rand,
- &rnd_info_B );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_ecdh_make_public(&cli, &len, buf, sizeof(buf),
+ mbedtls_test_rnd_buffer_rand,
+ &rnd_info_B);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
/* server reads client key share */
- TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_read_public(&srv, buf, len) == 0);
/* server computes shared secret */
- memset( buf, 0, sizeof( buf ) );
+ memset(buf, 0, sizeof(buf));
len = 0;
cnt_restart = 0;
do {
- ret = mbedtls_ecdh_calc_secret( &srv, &len, buf, sizeof( buf ),
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_ecdh_calc_secret(&srv, &len, buf, sizeof(buf),
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
- TEST_ASSERT( len == z->len );
- TEST_ASSERT( memcmp( buf, z->x, len ) == 0 );
+ TEST_ASSERT(len == z->len);
+ TEST_ASSERT(memcmp(buf, z->x, len) == 0);
/* client computes shared secret */
- memset( buf, 0, sizeof( buf ) );
+ memset(buf, 0, sizeof(buf));
len = 0;
cnt_restart = 0;
do {
- ret = mbedtls_ecdh_calc_secret( &cli, &len, buf, sizeof( buf ),
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_ecdh_calc_secret(&cli, &len, buf, sizeof(buf),
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
- TEST_ASSERT( len == z->len );
- TEST_ASSERT( memcmp( buf, z->x, len ) == 0 );
+ TEST_ASSERT(len == z->len);
+ TEST_ASSERT(memcmp(buf, z->x, len) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecdh_free( &srv );
- mbedtls_ecdh_free( &cli );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecdh_free(&srv);
+ mbedtls_ecdh_free(&cli);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecdh_exchange_calc_secret( int grp_id,
- data_t *our_private_key,
- data_t *their_point,
- int ours_first,
- data_t *expected )
+void ecdh_exchange_calc_secret(int grp_id,
+ data_t *our_private_key,
+ data_t *their_point,
+ int ours_first,
+ data_t *expected)
{
mbedtls_test_rnd_pseudo_info rnd_info;
mbedtls_ecp_keypair our_key;
@@ -378,92 +377,90 @@
unsigned char shared_secret[MBEDTLS_ECP_MAX_BYTES];
size_t shared_secret_length = 0;
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
- mbedtls_ecdh_init( &ecdh );
- mbedtls_ecp_keypair_init( &our_key );
- mbedtls_ecp_keypair_init( &their_key );
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
+ mbedtls_ecdh_init(&ecdh);
+ mbedtls_ecp_keypair_init(&our_key);
+ mbedtls_ecp_keypair_init(&their_key);
- if( ! load_private_key( grp_id, our_private_key, &our_key, &rnd_info ) )
+ if (!load_private_key(grp_id, our_private_key, &our_key, &rnd_info)) {
goto exit;
- if( ! load_public_key( grp_id, their_point, &their_key ) )
+ }
+ if (!load_public_key(grp_id, their_point, &their_key)) {
goto exit;
+ }
/* Import the keys to the ECDH calculation. */
- if( ours_first )
- {
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
- }
- else
- {
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
+ if (ours_first) {
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &our_key, MBEDTLS_ECDH_OURS) == 0);
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &their_key, MBEDTLS_ECDH_THEIRS) == 0);
+ } else {
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &their_key, MBEDTLS_ECDH_THEIRS) == 0);
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &our_key, MBEDTLS_ECDH_OURS) == 0);
}
/* Perform the ECDH calculation. */
- TEST_ASSERT( mbedtls_ecdh_calc_secret(
- &ecdh,
- &shared_secret_length,
- shared_secret, sizeof( shared_secret ),
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( shared_secret_length == expected->len );
- TEST_ASSERT( memcmp( expected->x, shared_secret,
- shared_secret_length ) == 0 );
+ TEST_ASSERT(mbedtls_ecdh_calc_secret(
+ &ecdh,
+ &shared_secret_length,
+ shared_secret, sizeof(shared_secret),
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(shared_secret_length == expected->len);
+ TEST_ASSERT(memcmp(expected->x, shared_secret,
+ shared_secret_length) == 0);
exit:
- mbedtls_ecdh_free( &ecdh );
- mbedtls_ecp_keypair_free( &our_key );
- mbedtls_ecp_keypair_free( &their_key );
+ mbedtls_ecdh_free(&ecdh);
+ mbedtls_ecp_keypair_free(&our_key);
+ mbedtls_ecp_keypair_free(&their_key);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecdh_exchange_get_params_fail( int our_grp_id,
- data_t *our_private_key,
- int their_grp_id,
- data_t *their_point,
- int ours_first,
- int expected_ret )
+void ecdh_exchange_get_params_fail(int our_grp_id,
+ data_t *our_private_key,
+ int their_grp_id,
+ data_t *their_point,
+ int ours_first,
+ int expected_ret)
{
mbedtls_test_rnd_pseudo_info rnd_info;
mbedtls_ecp_keypair our_key;
mbedtls_ecp_keypair their_key;
mbedtls_ecdh_context ecdh;
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
- mbedtls_ecdh_init( &ecdh );
- mbedtls_ecp_keypair_init( &our_key );
- mbedtls_ecp_keypair_init( &their_key );
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
+ mbedtls_ecdh_init(&ecdh);
+ mbedtls_ecp_keypair_init(&our_key);
+ mbedtls_ecp_keypair_init(&their_key);
- if( ! load_private_key( our_grp_id, our_private_key, &our_key, &rnd_info ) )
+ if (!load_private_key(our_grp_id, our_private_key, &our_key, &rnd_info)) {
goto exit;
- if( ! load_public_key( their_grp_id, their_point, &their_key ) )
- goto exit;
-
- if( ours_first )
- {
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) ==
- expected_ret );
}
- else
- {
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_get_params(
- &ecdh, &our_key, MBEDTLS_ECDH_OURS ) ==
- expected_ret );
+ if (!load_public_key(their_grp_id, their_point, &their_key)) {
+ goto exit;
+ }
+
+ if (ours_first) {
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &our_key, MBEDTLS_ECDH_OURS) == 0);
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &their_key, MBEDTLS_ECDH_THEIRS) ==
+ expected_ret);
+ } else {
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &their_key, MBEDTLS_ECDH_THEIRS) == 0);
+ TEST_ASSERT(mbedtls_ecdh_get_params(
+ &ecdh, &our_key, MBEDTLS_ECDH_OURS) ==
+ expected_ret);
}
exit:
- mbedtls_ecdh_free( &ecdh );
- mbedtls_ecp_keypair_free( &our_key );
- mbedtls_ecp_keypair_free( &their_key );
+ mbedtls_ecdh_free(&ecdh);
+ mbedtls_ecp_keypair_free(&our_key);
+ mbedtls_ecp_keypair_free(&their_key);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_ecdsa.function b/tests/suites/test_suite_ecdsa.function
index 0e2ac92..539c39d 100644
--- a/tests/suites/test_suite_ecdsa.function
+++ b/tests/suites/test_suite_ecdsa.function
@@ -2,8 +2,8 @@
#include "mbedtls/ecdsa.h"
#include "hash_info.h"
#include "mbedtls/legacy_or_psa.h"
-#if ( defined(MBEDTLS_ECDSA_DETERMINISTIC) && defined(MBEDTLS_SHA256_C) ) || \
- ( !defined(MBEDTLS_ECDSA_DETERMINISTIC) && defined(MBEDTLS_HAS_ALG_SHA_256_VIA_LOWLEVEL_OR_PSA) )
+#if (defined(MBEDTLS_ECDSA_DETERMINISTIC) && defined(MBEDTLS_SHA256_C)) || \
+ (!defined(MBEDTLS_ECDSA_DETERMINISTIC) && defined(MBEDTLS_HAS_ALG_SHA_256_VIA_LOWLEVEL_OR_PSA))
#define MBEDTLS_HAS_ALG_SHA_256_VIA_MD_IF_DETERMINISTIC
#endif
/* END_HEADER */
@@ -14,7 +14,7 @@
*/
/* BEGIN_CASE */
-void ecdsa_prim_zero( int id )
+void ecdsa_prim_zero(int id)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point Q;
@@ -22,31 +22,31 @@
mbedtls_test_rnd_pseudo_info rnd_info;
unsigned char buf[MBEDTLS_HASH_MAX_SIZE];
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &Q );
- mbedtls_mpi_init( &d ); mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
- memset( buf, 0, sizeof( buf ) );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&Q);
+ mbedtls_mpi_init(&d); mbedtls_mpi_init(&r); mbedtls_mpi_init(&s);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
+ memset(buf, 0, sizeof(buf));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
+ TEST_ASSERT(mbedtls_ecp_gen_keypair(&grp, &d, &Q,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, buf, sizeof( buf ),
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 );
+ TEST_ASSERT(mbedtls_ecdsa_sign(&grp, &r, &s, &d, buf, sizeof(buf),
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdsa_verify(&grp, buf, sizeof(buf), &Q, &r, &s) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &Q );
- mbedtls_mpi_free( &d ); mbedtls_mpi_free( &r ); mbedtls_mpi_free( &s );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&Q);
+ mbedtls_mpi_free(&d); mbedtls_mpi_free(&r); mbedtls_mpi_free(&s);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecdsa_prim_random( int id )
+void ecdsa_prim_random(int id)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point Q;
@@ -54,184 +54,183 @@
mbedtls_test_rnd_pseudo_info rnd_info;
unsigned char buf[MBEDTLS_HASH_MAX_SIZE];
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &Q );
- mbedtls_mpi_init( &d ); mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
- memset( buf, 0, sizeof( buf ) );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&Q);
+ mbedtls_mpi_init(&d); mbedtls_mpi_init(&r); mbedtls_mpi_init(&s);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
+ memset(buf, 0, sizeof(buf));
/* prepare material for signature */
- TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info,
- buf, sizeof( buf ) ) == 0 );
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_test_rnd_pseudo_rand(&rnd_info,
+ buf, sizeof(buf)) == 0);
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
+ TEST_ASSERT(mbedtls_ecp_gen_keypair(&grp, &d, &Q,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, buf, sizeof( buf ),
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 );
+ TEST_ASSERT(mbedtls_ecdsa_sign(&grp, &r, &s, &d, buf, sizeof(buf),
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdsa_verify(&grp, buf, sizeof(buf), &Q, &r, &s) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &Q );
- mbedtls_mpi_free( &d ); mbedtls_mpi_free( &r ); mbedtls_mpi_free( &s );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&Q);
+ mbedtls_mpi_free(&d); mbedtls_mpi_free(&r); mbedtls_mpi_free(&s);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str,
- char * yQ_str, data_t * rnd_buf,
- data_t * hash, char * r_str, char * s_str,
- int result )
+void ecdsa_prim_test_vectors(int id, char *d_str, char *xQ_str,
+ char *yQ_str, data_t *rnd_buf,
+ data_t *hash, char *r_str, char *s_str,
+ int result)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point Q;
mbedtls_mpi d, r, s, r_check, s_check, zero;
mbedtls_test_rnd_buf_info rnd_info;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &Q );
- mbedtls_mpi_init( &d ); mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s );
- mbedtls_mpi_init( &r_check ); mbedtls_mpi_init( &s_check );
- mbedtls_mpi_init( &zero );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&Q);
+ mbedtls_mpi_init(&d); mbedtls_mpi_init(&r); mbedtls_mpi_init(&s);
+ mbedtls_mpi_init(&r_check); mbedtls_mpi_init(&s_check);
+ mbedtls_mpi_init(&zero);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_string( &Q, 16, xQ_str, yQ_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &d, d_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &r_check, r_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &s_check, s_str ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
+ TEST_ASSERT(mbedtls_ecp_point_read_string(&Q, 16, xQ_str, yQ_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&d, d_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&r_check, r_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&s_check, s_str) == 0);
rnd_info.fallback_f_rng = mbedtls_test_rnd_std_rand;
rnd_info.fallback_p_rng = NULL;
rnd_info.buf = rnd_buf->x;
rnd_info.length = rnd_buf->len;
/* Fix rnd_buf->x by shifting it left if necessary */
- if( grp.nbits % 8 != 0 )
- {
- unsigned char shift = 8 - ( grp.nbits % 8 );
+ if (grp.nbits % 8 != 0) {
+ unsigned char shift = 8 - (grp.nbits % 8);
size_t i;
- for( i = 0; i < rnd_info.length - 1; i++ )
- rnd_buf->x[i] = rnd_buf->x[i] << shift | rnd_buf->x[i+1] >> ( 8 - shift );
+ for (i = 0; i < rnd_info.length - 1; i++) {
+ rnd_buf->x[i] = rnd_buf->x[i] << shift | rnd_buf->x[i+1] >> (8 - shift);
+ }
rnd_buf->x[rnd_info.length-1] <<= shift;
}
- TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, hash->x, hash->len,
- mbedtls_test_rnd_buffer_rand, &rnd_info ) == result );
+ TEST_ASSERT(mbedtls_ecdsa_sign(&grp, &r, &s, &d, hash->x, hash->len,
+ mbedtls_test_rnd_buffer_rand, &rnd_info) == result);
- if ( result == 0)
- {
+ if (result == 0) {
/* Check we generated the expected values */
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &r, &r_check ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &s, &s_check ), 0 );
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&r, &r_check), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&s, &s_check), 0);
/* Valid signature */
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len,
- &Q, &r_check, &s_check ), 0 );
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len,
+ &Q, &r_check, &s_check), 0);
/* Invalid signature: wrong public key (G instead of Q) */
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len,
- &grp.G, &r_check, &s_check ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len,
+ &grp.G, &r_check, &s_check), MBEDTLS_ERR_ECP_VERIFY_FAILED);
/* Invalid signatures: r or s or both one off */
- TEST_EQUAL( mbedtls_mpi_sub_int( &r, &r_check, 1 ), 0 );
- TEST_EQUAL( mbedtls_mpi_add_int( &s, &s_check, 1 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_sub_int(&r, &r_check, 1), 0);
+ TEST_EQUAL(mbedtls_mpi_add_int(&s, &s_check, 1), 0);
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r, &s_check ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r_check, &s ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r, &s ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r, &s_check), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r_check, &s), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r, &s), MBEDTLS_ERR_ECP_VERIFY_FAILED);
/* Invalid signatures: r, s or both (CVE-2022-21449) are zero */
- TEST_EQUAL( mbedtls_mpi_lset( &zero, 0 ), 0 );
+ TEST_EQUAL(mbedtls_mpi_lset(&zero, 0), 0);
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &zero, &s_check ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r_check, &zero ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &zero, &zero ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &zero, &s_check), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r_check, &zero), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &zero, &zero), MBEDTLS_ERR_ECP_VERIFY_FAILED);
/* Invalid signatures: r, s or both are == N */
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &grp.N, &s_check ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r_check, &grp.N ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &grp.N, &grp.N ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &grp.N, &s_check), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r_check, &grp.N), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &grp.N, &grp.N), MBEDTLS_ERR_ECP_VERIFY_FAILED);
/* Invalid signatures: r, s or both are negative */
- TEST_EQUAL( mbedtls_mpi_sub_mpi( &r, &r_check, &grp.N ), 0 );
- TEST_EQUAL( mbedtls_mpi_sub_mpi( &s, &s_check, &grp.N ), 0 );
+ TEST_EQUAL(mbedtls_mpi_sub_mpi(&r, &r_check, &grp.N), 0);
+ TEST_EQUAL(mbedtls_mpi_sub_mpi(&s, &s_check, &grp.N), 0);
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r, &s_check ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r_check, &s ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r, &s ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r, &s_check), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r_check, &s), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r, &s), MBEDTLS_ERR_ECP_VERIFY_FAILED);
/* Invalid signatures: r or s or both are > N */
- TEST_EQUAL( mbedtls_mpi_add_mpi( &r, &r_check, &grp.N ), 0 );
- TEST_EQUAL( mbedtls_mpi_add_mpi( &s, &s_check, &grp.N ), 0 );
+ TEST_EQUAL(mbedtls_mpi_add_mpi(&r, &r_check, &grp.N), 0);
+ TEST_EQUAL(mbedtls_mpi_add_mpi(&s, &s_check, &grp.N), 0);
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r, &s_check ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r_check, &s ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
- TEST_EQUAL( mbedtls_ecdsa_verify( &grp, hash->x, hash->len, &Q,
- &r, &s ), MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r, &s_check), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r_check, &s), MBEDTLS_ERR_ECP_VERIFY_FAILED);
+ TEST_EQUAL(mbedtls_ecdsa_verify(&grp, hash->x, hash->len, &Q,
+ &r, &s), MBEDTLS_ERR_ECP_VERIFY_FAILED);
}
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &Q );
- mbedtls_mpi_free( &d ); mbedtls_mpi_free( &r ); mbedtls_mpi_free( &s );
- mbedtls_mpi_free( &r_check ); mbedtls_mpi_free( &s_check );
- mbedtls_mpi_free( &zero );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&Q);
+ mbedtls_mpi_free(&d); mbedtls_mpi_free(&r); mbedtls_mpi_free(&s);
+ mbedtls_mpi_free(&r_check); mbedtls_mpi_free(&s_check);
+ mbedtls_mpi_free(&zero);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECDSA_DETERMINISTIC */
-void ecdsa_det_test_vectors( int id, char * d_str, int md_alg, data_t * hash,
- char * r_str, char * s_str )
+void ecdsa_det_test_vectors(int id, char *d_str, int md_alg, data_t *hash,
+ char *r_str, char *s_str)
{
mbedtls_ecp_group grp;
mbedtls_mpi d, r, s, r_check, s_check;
- mbedtls_ecp_group_init( &grp );
- mbedtls_mpi_init( &d ); mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s );
- mbedtls_mpi_init( &r_check ); mbedtls_mpi_init( &s_check );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_mpi_init(&d); mbedtls_mpi_init(&r); mbedtls_mpi_init(&s);
+ mbedtls_mpi_init(&r_check); mbedtls_mpi_init(&s_check);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &d, d_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &r_check, r_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &s_check, s_str ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&d, d_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&r_check, r_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&s_check, s_str) == 0);
TEST_ASSERT(
- mbedtls_ecdsa_sign_det_ext( &grp, &r, &s, &d,
- hash->x, hash->len, md_alg,
- mbedtls_test_rnd_std_rand,
- NULL )
- == 0 );
+ mbedtls_ecdsa_sign_det_ext(&grp, &r, &s, &d,
+ hash->x, hash->len, md_alg,
+ mbedtls_test_rnd_std_rand,
+ NULL)
+ == 0);
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &r, &r_check ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &s, &s_check ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&r, &r_check) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&s, &s_check) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_mpi_free( &d ); mbedtls_mpi_free( &r ); mbedtls_mpi_free( &s );
- mbedtls_mpi_free( &r_check ); mbedtls_mpi_free( &s_check );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_mpi_free(&d); mbedtls_mpi_free(&r); mbedtls_mpi_free(&s);
+ mbedtls_mpi_free(&r_check); mbedtls_mpi_free(&s_check);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_IF_DETERMINISTIC */
-void ecdsa_write_read_zero( int id )
+void ecdsa_write_read_zero(int id)
{
mbedtls_ecdsa_context ctx;
mbedtls_test_rnd_pseudo_info rnd_info;
@@ -239,59 +238,61 @@
unsigned char sig[200];
size_t sig_len, i;
- mbedtls_ecdsa_init( &ctx );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
- memset( hash, 0, sizeof( hash ) );
- memset( sig, 0x2a, sizeof( sig ) );
+ mbedtls_ecdsa_init(&ctx);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
+ memset(hash, 0, sizeof(hash));
+ memset(sig, 0x2a, sizeof(sig));
/* generate signing key */
- TEST_ASSERT( mbedtls_ecdsa_genkey( &ctx, id,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_ecdsa_genkey(&ctx, id,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
/* generate and write signature, then read and verify it */
- TEST_ASSERT( mbedtls_ecdsa_write_signature( &ctx, MBEDTLS_MD_SHA256,
- hash, sizeof( hash ),
- sig, sizeof( sig ), &sig_len, &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) == 0 );
+ TEST_ASSERT(mbedtls_ecdsa_write_signature(&ctx, MBEDTLS_MD_SHA256,
+ hash, sizeof(hash),
+ sig, sizeof(sig), &sig_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) == 0);
/* check we didn't write past the announced length */
- for( i = sig_len; i < sizeof( sig ); i++ )
- TEST_ASSERT( sig[i] == 0x2a );
+ for (i = sig_len; i < sizeof(sig); i++) {
+ TEST_ASSERT(sig[i] == 0x2a);
+ }
/* try verification with invalid length */
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len - 1 ) != 0 );
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len + 1 ) != 0 );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len - 1) != 0);
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len + 1) != 0);
/* try invalid sequence tag */
sig[0]++;
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) != 0 );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) != 0);
sig[0]--;
/* try modifying r */
sig[10]++;
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) == MBEDTLS_ERR_ECP_VERIFY_FAILED);
sig[10]--;
/* try modifying s */
sig[sig_len - 1]++;
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) == MBEDTLS_ERR_ECP_VERIFY_FAILED);
sig[sig_len - 1]--;
exit:
- mbedtls_ecdsa_free( &ctx );
+ mbedtls_ecdsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_IF_DETERMINISTIC */
-void ecdsa_write_read_random( int id )
+void ecdsa_write_read_random(int id)
{
mbedtls_ecdsa_context ctx;
mbedtls_test_rnd_pseudo_info rnd_info;
@@ -299,127 +300,132 @@
unsigned char sig[200];
size_t sig_len, i;
- mbedtls_ecdsa_init( &ctx );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
- memset( hash, 0, sizeof( hash ) );
- memset( sig, 0x2a, sizeof( sig ) );
+ mbedtls_ecdsa_init(&ctx);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
+ memset(hash, 0, sizeof(hash));
+ memset(sig, 0x2a, sizeof(sig));
/* prepare material for signature */
- TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info,
- hash, sizeof( hash ) ) == 0 );
+ TEST_ASSERT(mbedtls_test_rnd_pseudo_rand(&rnd_info,
+ hash, sizeof(hash)) == 0);
/* generate signing key */
- TEST_ASSERT( mbedtls_ecdsa_genkey( &ctx, id,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_ecdsa_genkey(&ctx, id,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
/* generate and write signature, then read and verify it */
- TEST_ASSERT( mbedtls_ecdsa_write_signature( &ctx, MBEDTLS_MD_SHA256,
- hash, sizeof( hash ),
- sig, sizeof( sig ), &sig_len, &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) == 0 );
+ TEST_ASSERT(mbedtls_ecdsa_write_signature(&ctx, MBEDTLS_MD_SHA256,
+ hash, sizeof(hash),
+ sig, sizeof(sig), &sig_len,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) == 0);
/* check we didn't write past the announced length */
- for( i = sig_len; i < sizeof( sig ); i++ )
- TEST_ASSERT( sig[i] == 0x2a );
+ for (i = sig_len; i < sizeof(sig); i++) {
+ TEST_ASSERT(sig[i] == 0x2a);
+ }
/* try verification with invalid length */
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len - 1 ) != 0 );
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len + 1 ) != 0 );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len - 1) != 0);
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len + 1) != 0);
/* try invalid sequence tag */
sig[0]++;
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) != 0 );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) != 0);
sig[0]--;
/* try modifying r */
sig[10]++;
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) == MBEDTLS_ERR_ECP_VERIFY_FAILED);
sig[10]--;
/* try modifying s */
sig[sig_len - 1]++;
- TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
- sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ TEST_ASSERT(mbedtls_ecdsa_read_signature(&ctx, hash, sizeof(hash),
+ sig, sig_len) == MBEDTLS_ERR_ECP_VERIFY_FAILED);
sig[sig_len - 1]--;
exit:
- mbedtls_ecdsa_free( &ctx );
+ mbedtls_ecdsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE */
-void ecdsa_read_restart( int id, data_t *pk, data_t *hash, data_t *sig,
- int max_ops, int min_restart, int max_restart )
+void ecdsa_read_restart(int id, data_t *pk, data_t *hash, data_t *sig,
+ int max_ops, int min_restart, int max_restart)
{
mbedtls_ecdsa_context ctx;
mbedtls_ecdsa_restart_ctx rs_ctx;
int ret, cnt_restart;
- mbedtls_ecdsa_init( &ctx );
- mbedtls_ecdsa_restart_init( &rs_ctx );
+ mbedtls_ecdsa_init(&ctx);
+ mbedtls_ecdsa_restart_init(&rs_ctx);
- TEST_ASSERT( mbedtls_ecp_group_load( &ctx.grp, id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_binary( &ctx.grp, &ctx.Q,
- pk->x, pk->len ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&ctx.grp, id) == 0);
+ TEST_ASSERT(mbedtls_ecp_point_read_binary(&ctx.grp, &ctx.Q,
+ pk->x, pk->len) == 0);
- mbedtls_ecp_set_max_ops( max_ops );
+ mbedtls_ecp_set_max_ops(max_ops);
cnt_restart = 0;
do {
- ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
- hash->x, hash->len, sig->x, sig->len, &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_ecdsa_read_signature_restartable(&ctx,
+ hash->x, hash->len, sig->x, sig->len,
+ &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
/* try modifying r */
- TEST_ASSERT( sig->len > 10 );
+ TEST_ASSERT(sig->len > 10);
sig->x[10]++;
do {
- ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
- hash->x, hash->len, sig->x, sig->len, &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ ret = mbedtls_ecdsa_read_signature_restartable(&ctx,
+ hash->x, hash->len, sig->x, sig->len,
+ &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_VERIFY_FAILED);
sig->x[10]--;
/* try modifying s */
sig->x[sig->len - 1]++;
do {
- ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
- hash->x, hash->len, sig->x, sig->len, &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_VERIFY_FAILED );
+ ret = mbedtls_ecdsa_read_signature_restartable(&ctx,
+ hash->x, hash->len, sig->x, sig->len,
+ &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_VERIFY_FAILED);
sig->x[sig->len - 1]--;
/* Do we leak memory when aborting an operation?
* This test only makes sense when we actually restart */
- if( min_restart > 0 )
- {
- ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
- hash->x, hash->len, sig->x, sig->len, &rs_ctx );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
+ if (min_restart > 0) {
+ ret = mbedtls_ecdsa_read_signature_restartable(&ctx,
+ hash->x, hash->len, sig->x, sig->len,
+ &rs_ctx);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
}
exit:
- mbedtls_ecdsa_free( &ctx );
- mbedtls_ecdsa_restart_free( &rs_ctx );
+ mbedtls_ecdsa_free(&ctx);
+ mbedtls_ecdsa_restart_free(&rs_ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE:MBEDTLS_ECDSA_DETERMINISTIC */
-void ecdsa_write_restart( int id, char *d_str, int md_alg,
- data_t *hash, data_t *sig_check,
- int max_ops, int min_restart, int max_restart )
+void ecdsa_write_restart(int id, char *d_str, int md_alg,
+ data_t *hash, data_t *sig_check,
+ int max_ops, int min_restart, int max_restart)
{
int ret, cnt_restart;
mbedtls_ecdsa_restart_ctx rs_ctx;
@@ -427,79 +433,92 @@
unsigned char sig[MBEDTLS_ECDSA_MAX_LEN];
size_t slen;
- mbedtls_ecdsa_restart_init( &rs_ctx );
- mbedtls_ecdsa_init( &ctx );
- memset( sig, 0, sizeof( sig ) );
+ mbedtls_ecdsa_restart_init(&rs_ctx);
+ mbedtls_ecdsa_init(&ctx);
+ memset(sig, 0, sizeof(sig));
- TEST_ASSERT( mbedtls_ecp_group_load( &ctx.grp, id ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.d, d_str ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&ctx.grp, id) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.d, d_str) == 0);
- mbedtls_ecp_set_max_ops( max_ops );
+ mbedtls_ecp_set_max_ops(max_ops);
- slen = sizeof( sig );
+ slen = sizeof(sig);
cnt_restart = 0;
do {
- ret = mbedtls_ecdsa_write_signature_restartable( &ctx,
- md_alg, hash->x, hash->len, sig, sizeof( sig ), &slen,
- mbedtls_test_rnd_std_rand, NULL, &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_ecdsa_write_signature_restartable(&ctx,
+ md_alg,
+ hash->x,
+ hash->len,
+ sig,
+ sizeof(sig),
+ &slen,
+ mbedtls_test_rnd_std_rand,
+ NULL,
+ &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( slen == sig_check->len );
- TEST_ASSERT( memcmp( sig, sig_check->x, slen ) == 0 );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(slen == sig_check->len);
+ TEST_ASSERT(memcmp(sig, sig_check->x, slen) == 0);
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
/* Do we leak memory when aborting an operation?
* This test only makes sense when we actually restart */
- if( min_restart > 0 )
- {
- ret = mbedtls_ecdsa_write_signature_restartable( &ctx,
- md_alg, hash->x, hash->len, sig, sizeof( sig ), &slen,
- mbedtls_test_rnd_std_rand, NULL, &rs_ctx );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
+ if (min_restart > 0) {
+ ret = mbedtls_ecdsa_write_signature_restartable(&ctx,
+ md_alg,
+ hash->x,
+ hash->len,
+ sig,
+ sizeof(sig),
+ &slen,
+ mbedtls_test_rnd_std_rand,
+ NULL,
+ &rs_ctx);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
}
exit:
- mbedtls_ecdsa_restart_free( &rs_ctx );
- mbedtls_ecdsa_free( &ctx );
+ mbedtls_ecdsa_restart_free(&rs_ctx);
+ mbedtls_ecdsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecdsa_verify( int grp_id, char * x, char * y, char * r, char * s, data_t * content, int expected )
+void ecdsa_verify(int grp_id, char *x, char *y, char *r, char *s, data_t *content, int expected)
{
mbedtls_ecdsa_context ctx;
mbedtls_mpi sig_r, sig_s;
- mbedtls_ecdsa_init( &ctx );
- mbedtls_mpi_init( &sig_r );
- mbedtls_mpi_init( &sig_s );
+ mbedtls_ecdsa_init(&ctx);
+ mbedtls_mpi_init(&sig_r);
+ mbedtls_mpi_init(&sig_s);
/* Prepare ECP group context */
- TEST_EQUAL( mbedtls_ecp_group_load( &ctx.grp, grp_id ), 0 );
+ TEST_EQUAL(mbedtls_ecp_group_load(&ctx.grp, grp_id), 0);
/* Prepare public key */
- TEST_EQUAL( mbedtls_test_read_mpi( &ctx.Q.X, x ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &ctx.Q.Y, y ), 0 );
- TEST_EQUAL( mbedtls_mpi_lset( &ctx.Q.Z, 1 ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi(&ctx.Q.X, x), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&ctx.Q.Y, y), 0);
+ TEST_EQUAL(mbedtls_mpi_lset(&ctx.Q.Z, 1), 0);
/* Prepare signature R & S */
- TEST_EQUAL( mbedtls_test_read_mpi( &sig_r, r ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &sig_s, s ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi(&sig_r, r), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&sig_s, s), 0);
/* Test whether public key has expected validity */
- TEST_EQUAL( mbedtls_ecp_check_pubkey( &ctx.grp, &ctx.Q ),
- expected == MBEDTLS_ERR_ECP_INVALID_KEY ? MBEDTLS_ERR_ECP_INVALID_KEY : 0 );
+ TEST_EQUAL(mbedtls_ecp_check_pubkey(&ctx.grp, &ctx.Q),
+ expected == MBEDTLS_ERR_ECP_INVALID_KEY ? MBEDTLS_ERR_ECP_INVALID_KEY : 0);
/* Verification */
- int result = mbedtls_ecdsa_verify( &ctx.grp, content->x, content->len, &ctx.Q, &sig_r, &sig_s );
+ int result = mbedtls_ecdsa_verify(&ctx.grp, content->x, content->len, &ctx.Q, &sig_r, &sig_s);
- TEST_EQUAL( result, expected );
+ TEST_EQUAL(result, expected);
exit:
- mbedtls_ecdsa_free( &ctx );
- mbedtls_mpi_free( &sig_r );
- mbedtls_mpi_free( &sig_s );
+ mbedtls_ecdsa_free(&ctx);
+ mbedtls_mpi_free(&sig_r);
+ mbedtls_mpi_free(&sig_s);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_ecjpake.function b/tests/suites/test_suite_ecjpake.function
index d90a586..d5c0f07 100644
--- a/tests/suites/test_suite_ecjpake.function
+++ b/tests/suites/test_suite_ecjpake.function
@@ -64,33 +64,33 @@
};
/* Load my private and public keys, and peer's public keys */
-static int ecjpake_test_load( mbedtls_ecjpake_context *ctx,
- const unsigned char *xm1, size_t len_xm1,
- const unsigned char *xm2, size_t len_xm2,
- const unsigned char *Xm1, size_t len_Xm1,
- const unsigned char *Xm2, size_t len_Xm2,
- const unsigned char *Xp1, size_t len_Xp1,
- const unsigned char *Xp2, size_t len_Xp2 )
+static int ecjpake_test_load(mbedtls_ecjpake_context *ctx,
+ const unsigned char *xm1, size_t len_xm1,
+ const unsigned char *xm2, size_t len_xm2,
+ const unsigned char *Xm1, size_t len_Xm1,
+ const unsigned char *Xm2, size_t len_Xm2,
+ const unsigned char *Xp1, size_t len_Xp1,
+ const unsigned char *Xp2, size_t len_Xp2)
{
int ret;
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm1, xm1, len_xm1 ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm2, xm2, len_xm2 ) );
+ MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->xm1, xm1, len_xm1));
+ MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->xm2, xm2, len_xm2));
- MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp,
- &ctx->Xm1, Xm1, len_Xm1 ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp,
- &ctx->Xm2, Xm2, len_Xm2 ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp,
- &ctx->Xp1, Xp1, len_Xp1 ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_point_read_binary( &ctx->grp,
- &ctx->Xp2, Xp2, len_Xp2 ) );
+ MBEDTLS_MPI_CHK(mbedtls_ecp_point_read_binary(&ctx->grp,
+ &ctx->Xm1, Xm1, len_Xm1));
+ MBEDTLS_MPI_CHK(mbedtls_ecp_point_read_binary(&ctx->grp,
+ &ctx->Xm2, Xm2, len_Xm2));
+ MBEDTLS_MPI_CHK(mbedtls_ecp_point_read_binary(&ctx->grp,
+ &ctx->Xp1, Xp1, len_Xp1));
+ MBEDTLS_MPI_CHK(mbedtls_ecp_point_read_binary(&ctx->grp,
+ &ctx->Xp2, Xp2, len_Xp2));
cleanup:
- return( ret );
+ return ret;
}
-#define ADD_SIZE( x ) x, sizeof( x )
+#define ADD_SIZE(x) x, sizeof(x)
#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED && MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA */
/* END_HEADER */
@@ -100,121 +100,125 @@
*/
/* BEGIN_CASE */
-void ecjpake_invalid_param( )
+void ecjpake_invalid_param()
{
mbedtls_ecjpake_context ctx;
unsigned char buf[42] = { 0 };
- size_t const len = sizeof( buf );
+ size_t const len = sizeof(buf);
mbedtls_ecjpake_role invalid_role = (mbedtls_ecjpake_role) 42;
mbedtls_md_type_t valid_md = MBEDTLS_MD_SHA256;
mbedtls_ecp_group_id valid_group = MBEDTLS_ECP_DP_SECP256R1;
- mbedtls_ecjpake_init( &ctx );
+ mbedtls_ecjpake_init(&ctx);
- TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_setup( &ctx,
- invalid_role,
- valid_md,
- valid_group,
- buf, len ) );
+ TEST_EQUAL(MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ mbedtls_ecjpake_setup(&ctx,
+ invalid_role,
+ valid_md,
+ valid_group,
+ buf, len));
exit:
return;
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void ecjpake_selftest( )
+void ecjpake_selftest()
{
- TEST_ASSERT( mbedtls_ecjpake_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_ecjpake_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA */
-void read_bad_md( data_t *msg )
+void read_bad_md(data_t *msg)
{
mbedtls_ecjpake_context corrupt_ctx;
- const unsigned char * pw = NULL;
+ const unsigned char *pw = NULL;
const size_t pw_len = 0;
int any_role = MBEDTLS_ECJPAKE_CLIENT;
- mbedtls_ecjpake_init( &corrupt_ctx );
- TEST_ASSERT( mbedtls_ecjpake_setup( &corrupt_ctx, any_role,
- MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 );
+ mbedtls_ecjpake_init(&corrupt_ctx);
+ TEST_ASSERT(mbedtls_ecjpake_setup(&corrupt_ctx, any_role,
+ MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw,
+ pw_len) == 0);
corrupt_ctx.md_type = MBEDTLS_MD_NONE;
- TEST_EQUAL( mbedtls_ecjpake_read_round_one( &corrupt_ctx, msg->x,
- msg->len ), MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_ecjpake_read_round_one(&corrupt_ctx, msg->x,
+ msg->len), MBEDTLS_ERR_MD_BAD_INPUT_DATA);
exit:
- mbedtls_ecjpake_free( &corrupt_ctx );
+ mbedtls_ecjpake_free(&corrupt_ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA */
-void read_round_one( int role, data_t * msg, int ref_ret )
+void read_round_one(int role, data_t *msg, int ref_ret)
{
mbedtls_ecjpake_context ctx;
- const unsigned char * pw = NULL;
+ const unsigned char *pw = NULL;
const size_t pw_len = 0;
- mbedtls_ecjpake_init( &ctx );
+ mbedtls_ecjpake_init(&ctx);
- TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, role,
- MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 );
+ TEST_ASSERT(mbedtls_ecjpake_setup(&ctx, role,
+ MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw,
+ pw_len) == 0);
- TEST_ASSERT( mbedtls_ecjpake_read_round_one( &ctx, msg->x, msg->len ) == ref_ret );
+ TEST_ASSERT(mbedtls_ecjpake_read_round_one(&ctx, msg->x, msg->len) == ref_ret);
exit:
- mbedtls_ecjpake_free( &ctx );
+ mbedtls_ecjpake_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA */
-void read_round_two_cli( data_t * msg, int ref_ret )
+void read_round_two_cli(data_t *msg, int ref_ret)
{
mbedtls_ecjpake_context ctx;
- const unsigned char * pw = NULL;
+ const unsigned char *pw = NULL;
const size_t pw_len = 0;
- mbedtls_ecjpake_init( &ctx );
+ mbedtls_ecjpake_init(&ctx);
- TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_CLIENT,
- MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 );
+ TEST_ASSERT(mbedtls_ecjpake_setup(&ctx, MBEDTLS_ECJPAKE_CLIENT,
+ MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw,
+ pw_len) == 0);
- TEST_ASSERT( ecjpake_test_load( &ctx,
- ADD_SIZE( ecjpake_test_x1 ), ADD_SIZE( ecjpake_test_x2 ),
- ADD_SIZE( ecjpake_test_X1 ), ADD_SIZE( ecjpake_test_X2 ),
- ADD_SIZE( ecjpake_test_X3 ), ADD_SIZE( ecjpake_test_X4 ) )
- == 0 );
+ TEST_ASSERT(ecjpake_test_load(&ctx,
+ ADD_SIZE(ecjpake_test_x1), ADD_SIZE(ecjpake_test_x2),
+ ADD_SIZE(ecjpake_test_X1), ADD_SIZE(ecjpake_test_X2),
+ ADD_SIZE(ecjpake_test_X3), ADD_SIZE(ecjpake_test_X4))
+ == 0);
- TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg->x, msg->len ) == ref_ret );
+ TEST_ASSERT(mbedtls_ecjpake_read_round_two(&ctx, msg->x, msg->len) == ref_ret);
exit:
- mbedtls_ecjpake_free( &ctx );
+ mbedtls_ecjpake_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA */
-void read_round_two_srv( data_t * msg, int ref_ret )
+void read_round_two_srv(data_t *msg, int ref_ret)
{
mbedtls_ecjpake_context ctx;
- const unsigned char * pw = NULL;
+ const unsigned char *pw = NULL;
const size_t pw_len = 0;
- mbedtls_ecjpake_init( &ctx );
+ mbedtls_ecjpake_init(&ctx);
- TEST_ASSERT( mbedtls_ecjpake_setup( &ctx, MBEDTLS_ECJPAKE_SERVER,
- MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len ) == 0 );
+ TEST_ASSERT(mbedtls_ecjpake_setup(&ctx, MBEDTLS_ECJPAKE_SERVER,
+ MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw,
+ pw_len) == 0);
- TEST_ASSERT( ecjpake_test_load( &ctx,
- ADD_SIZE( ecjpake_test_x3 ), ADD_SIZE( ecjpake_test_x4 ),
- ADD_SIZE( ecjpake_test_X3 ), ADD_SIZE( ecjpake_test_X4 ),
- ADD_SIZE( ecjpake_test_X1 ), ADD_SIZE( ecjpake_test_X2 ) )
- == 0 );
+ TEST_ASSERT(ecjpake_test_load(&ctx,
+ ADD_SIZE(ecjpake_test_x3), ADD_SIZE(ecjpake_test_x4),
+ ADD_SIZE(ecjpake_test_X3), ADD_SIZE(ecjpake_test_X4),
+ ADD_SIZE(ecjpake_test_X1), ADD_SIZE(ecjpake_test_X2))
+ == 0);
- TEST_ASSERT( mbedtls_ecjpake_read_round_two( &ctx, msg->x, msg->len ) == ref_ret );
+ TEST_ASSERT(mbedtls_ecjpake_read_round_two(&ctx, msg->x, msg->len) == ref_ret);
exit:
- mbedtls_ecjpake_free( &ctx );
+ mbedtls_ecjpake_free(&ctx);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function
index 96b9f40..394253d 100644
--- a/tests/suites/test_suite_ecp.function
+++ b/tests/suites/test_suite_ecp.function
@@ -6,52 +6,67 @@
#include "ecp_invasive.h"
#if defined(MBEDTLS_TEST_HOOKS) && \
- ( defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) )
+ (defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
+ defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
+ defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED))
#define HAVE_FIX_NEGATIVE
#endif
#define ECP_PF_UNKNOWN -1
-#define ECP_PT_RESET( x ) \
- mbedtls_ecp_point_free( x ); \
- mbedtls_ecp_point_init( x );
+#define ECP_PT_RESET(x) \
+ mbedtls_ecp_point_free(x); \
+ mbedtls_ecp_point_init(x);
/* Auxiliary function to compare two mbedtls_ecp_group objects. */
-inline static int mbedtls_ecp_group_cmp( mbedtls_ecp_group *grp1,
- mbedtls_ecp_group *grp2 )
+inline static int mbedtls_ecp_group_cmp(mbedtls_ecp_group *grp1,
+ mbedtls_ecp_group *grp2)
{
- if( mbedtls_mpi_cmp_mpi( &grp1->P, &grp2->P ) != 0 )
+ if (mbedtls_mpi_cmp_mpi(&grp1->P, &grp2->P) != 0) {
return 1;
- if( mbedtls_mpi_cmp_mpi( &grp1->A, &grp2->A ) != 0 )
+ }
+ if (mbedtls_mpi_cmp_mpi(&grp1->A, &grp2->A) != 0) {
return 1;
- if( mbedtls_mpi_cmp_mpi( &grp1->B, &grp2->B ) != 0 )
+ }
+ if (mbedtls_mpi_cmp_mpi(&grp1->B, &grp2->B) != 0) {
return 1;
- if( mbedtls_mpi_cmp_mpi( &grp1->N, &grp2->N ) != 0 )
+ }
+ if (mbedtls_mpi_cmp_mpi(&grp1->N, &grp2->N) != 0) {
return 1;
- if( mbedtls_ecp_point_cmp( &grp1->G, &grp2->G ) != 0 )
+ }
+ if (mbedtls_ecp_point_cmp(&grp1->G, &grp2->G) != 0) {
return 1;
- if( grp1->id != grp2->id )
+ }
+ if (grp1->id != grp2->id) {
return 1;
- if( grp1->pbits != grp2->pbits )
+ }
+ if (grp1->pbits != grp2->pbits) {
return 1;
- if( grp1->nbits != grp2->nbits )
+ }
+ if (grp1->nbits != grp2->nbits) {
return 1;
- if( grp1->h != grp2->h )
+ }
+ if (grp1->h != grp2->h) {
return 1;
- if( grp1->modp != grp2->modp )
+ }
+ if (grp1->modp != grp2->modp) {
return 1;
- if( grp1->t_pre != grp2->t_pre )
+ }
+ if (grp1->t_pre != grp2->t_pre) {
return 1;
- if( grp1->t_post != grp2->t_post )
+ }
+ if (grp1->t_post != grp2->t_post) {
return 1;
- if( grp1->t_data != grp2->t_data )
+ }
+ if (grp1->t_data != grp2->t_data) {
return 1;
- if( grp1->T_size != grp2->T_size )
+ }
+ if (grp1->T_size != grp2->T_size) {
return 1;
- if( grp1->T != grp2->T )
+ }
+ if (grp1->T != grp2->T) {
return 1;
+ }
return 0;
}
@@ -64,7 +79,7 @@
*/
/* BEGIN_CASE */
-void ecp_invalid_param( )
+void ecp_invalid_param()
{
mbedtls_ecp_group grp;
mbedtls_ecp_point P;
@@ -72,20 +87,20 @@
size_t olen;
unsigned char buf[42] = { 0 };
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &P );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&P);
- TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_write_binary( &grp, &P,
- invalid_fmt,
- &olen,
- buf, sizeof( buf ) ) );
- TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_point( &grp, &P,
- invalid_fmt,
- &olen,
- buf,
- sizeof( buf ) ) );
+ TEST_EQUAL(MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ mbedtls_ecp_point_write_binary(&grp, &P,
+ invalid_fmt,
+ &olen,
+ buf, sizeof(buf)));
+ TEST_EQUAL(MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ mbedtls_ecp_tls_write_point(&grp, &P,
+ invalid_fmt,
+ &olen,
+ buf,
+ sizeof(buf)));
exit:
return;
@@ -93,55 +108,55 @@
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_curve_info( int id, int tls_id, int size, char * name )
+void mbedtls_ecp_curve_info(int id, int tls_id, int size, char *name)
{
const mbedtls_ecp_curve_info *by_id, *by_tls, *by_name;
- by_id = mbedtls_ecp_curve_info_from_grp_id( id );
- by_tls = mbedtls_ecp_curve_info_from_tls_id( tls_id );
- by_name = mbedtls_ecp_curve_info_from_name( name );
- TEST_ASSERT( by_id != NULL );
- TEST_ASSERT( by_tls != NULL );
- TEST_ASSERT( by_name != NULL );
+ by_id = mbedtls_ecp_curve_info_from_grp_id(id);
+ by_tls = mbedtls_ecp_curve_info_from_tls_id(tls_id);
+ by_name = mbedtls_ecp_curve_info_from_name(name);
+ TEST_ASSERT(by_id != NULL);
+ TEST_ASSERT(by_tls != NULL);
+ TEST_ASSERT(by_name != NULL);
- TEST_ASSERT( by_id == by_tls );
- TEST_ASSERT( by_id == by_name );
+ TEST_ASSERT(by_id == by_tls);
+ TEST_ASSERT(by_id == by_name);
- TEST_ASSERT( by_id->bit_size == size );
- TEST_ASSERT( size <= MBEDTLS_ECP_MAX_BITS );
- TEST_ASSERT( size <= MBEDTLS_ECP_MAX_BYTES * 8 );
+ TEST_ASSERT(by_id->bit_size == size);
+ TEST_ASSERT(size <= MBEDTLS_ECP_MAX_BITS);
+ TEST_ASSERT(size <= MBEDTLS_ECP_MAX_BYTES * 8);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_check_pub( int grp_id, char * x_hex, char * y_hex, char * z_hex,
- int ret )
+void ecp_check_pub(int grp_id, char *x_hex, char *y_hex, char *z_hex,
+ int ret)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point P;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &P );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&P);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, grp_id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, grp_id) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &P.X, x_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &P.Y, y_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &P.Z, z_hex ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P.X, x_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&P.Y, y_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&P.Z, z_hex) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &P ) == ret );
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &P) == ret);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &P );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&P);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE */
-void ecp_test_vect_restart( int id,
- char *dA_str, char *xA_str, char *yA_str,
- char *dB_str, char *xZ_str, char *yZ_str,
- int max_ops, int min_restarts, int max_restarts )
+void ecp_test_vect_restart(int id,
+ char *dA_str, char *xA_str, char *yA_str,
+ char *dB_str, char *xZ_str, char *yZ_str,
+ int max_ops, int min_restarts, int max_restarts)
{
/*
* Test for early restart. Based on test vectors like ecp_test_vect(),
@@ -169,79 +184,78 @@
int ret;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_restart_init( &ctx );
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &R ); mbedtls_ecp_point_init( &P );
- mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &xA ); mbedtls_mpi_init( &yA );
- mbedtls_mpi_init( &dB ); mbedtls_mpi_init( &xZ ); mbedtls_mpi_init( &yZ );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_restart_init(&ctx);
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&R); mbedtls_ecp_point_init(&P);
+ mbedtls_mpi_init(&dA); mbedtls_mpi_init(&xA); mbedtls_mpi_init(&yA);
+ mbedtls_mpi_init(&dB); mbedtls_mpi_init(&xZ); mbedtls_mpi_init(&yZ);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &dA, dA_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xA, xA_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &yA, yA_str ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&dA, dA_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xA, xA_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&yA, yA_str) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &dB, dB_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xZ, xZ_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &yZ, yZ_str ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&dB, dB_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xZ, xZ_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&yZ, yZ_str) == 0);
- mbedtls_ecp_set_max_ops( (unsigned) max_ops );
+ mbedtls_ecp_set_max_ops((unsigned) max_ops);
/* Base point case */
cnt_restarts = 0;
do {
- ECP_PT_RESET( &R );
- ret = mbedtls_ecp_mul_restartable( &grp, &R, &dA, &grp.G,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info, &ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
+ ECP_PT_RESET(&R);
+ ret = mbedtls_ecp_mul_restartable(&grp, &R, &dA, &grp.G,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info, &ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xA ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yA ) == 0 );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xA) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.Y, &yA) == 0);
- TEST_ASSERT( cnt_restarts >= min_restarts );
- TEST_ASSERT( cnt_restarts <= max_restarts );
+ TEST_ASSERT(cnt_restarts >= min_restarts);
+ TEST_ASSERT(cnt_restarts <= max_restarts);
/* Non-base point case */
- mbedtls_ecp_copy( &P, &R );
+ mbedtls_ecp_copy(&P, &R);
cnt_restarts = 0;
do {
- ECP_PT_RESET( &R );
- ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &P,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info, &ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
+ ECP_PT_RESET(&R);
+ ret = mbedtls_ecp_mul_restartable(&grp, &R, &dB, &P,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info, &ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xZ ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xZ) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.Y, &yZ) == 0);
- TEST_ASSERT( cnt_restarts >= min_restarts );
- TEST_ASSERT( cnt_restarts <= max_restarts );
+ TEST_ASSERT(cnt_restarts >= min_restarts);
+ TEST_ASSERT(cnt_restarts <= max_restarts);
/* Do we leak memory when aborting an operation?
* This test only makes sense when we actually restart */
- if( min_restarts > 0 )
- {
- ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &P,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info, &ctx );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
+ if (min_restarts > 0) {
+ ret = mbedtls_ecp_mul_restartable(&grp, &R, &dB, &P,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info, &ctx);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
}
exit:
- mbedtls_ecp_restart_free( &ctx );
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &R ); mbedtls_ecp_point_free( &P );
- mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &xA ); mbedtls_mpi_free( &yA );
- mbedtls_mpi_free( &dB ); mbedtls_mpi_free( &xZ ); mbedtls_mpi_free( &yZ );
+ mbedtls_ecp_restart_free(&ctx);
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&R); mbedtls_ecp_point_free(&P);
+ mbedtls_mpi_free(&dA); mbedtls_mpi_free(&xA); mbedtls_mpi_free(&yA);
+ mbedtls_mpi_free(&dB); mbedtls_mpi_free(&xZ); mbedtls_mpi_free(&yZ);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE:MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
-void ecp_muladd_restart( int id, char *xR_str, char *yR_str,
- char *u1_str, char *u2_str,
- char *xQ_str, char *yQ_str,
- int max_ops, int min_restarts, int max_restarts )
+void ecp_muladd_restart(int id, char *xR_str, char *yR_str,
+ char *u1_str, char *u2_str,
+ char *xQ_str, char *yQ_str,
+ int max_ops, int min_restarts, int max_restarts)
{
/*
* Compute R = u1 * G + u2 * Q
@@ -256,250 +270,248 @@
int cnt_restarts;
int ret;
- mbedtls_ecp_restart_init( &ctx );
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &R );
- mbedtls_ecp_point_init( &Q );
- mbedtls_mpi_init( &u1 ); mbedtls_mpi_init( &u2 );
- mbedtls_mpi_init( &xR ); mbedtls_mpi_init( &yR );
+ mbedtls_ecp_restart_init(&ctx);
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&R);
+ mbedtls_ecp_point_init(&Q);
+ mbedtls_mpi_init(&u1); mbedtls_mpi_init(&u2);
+ mbedtls_mpi_init(&xR); mbedtls_mpi_init(&yR);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &u1, u1_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &u2, u2_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xR, xR_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &yR, yR_str ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&u1, u1_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&u2, u2_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xR, xR_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&yR, yR_str) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &Q.X, xQ_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q.Y, yQ_str ) == 0 );
- TEST_ASSERT( mbedtls_mpi_lset( &Q.Z, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q.X, xQ_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q.Y, yQ_str) == 0);
+ TEST_ASSERT(mbedtls_mpi_lset(&Q.Z, 1) == 0);
- mbedtls_ecp_set_max_ops( (unsigned) max_ops );
+ mbedtls_ecp_set_max_ops((unsigned) max_ops);
cnt_restarts = 0;
do {
- ECP_PT_RESET( &R );
- ret = mbedtls_ecp_muladd_restartable( &grp, &R,
- &u1, &grp.G, &u2, &Q, &ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
+ ECP_PT_RESET(&R);
+ ret = mbedtls_ecp_muladd_restartable(&grp, &R,
+ &u1, &grp.G, &u2, &Q, &ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xR ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yR ) == 0 );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xR) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.Y, &yR) == 0);
- TEST_ASSERT( cnt_restarts >= min_restarts );
- TEST_ASSERT( cnt_restarts <= max_restarts );
+ TEST_ASSERT(cnt_restarts >= min_restarts);
+ TEST_ASSERT(cnt_restarts <= max_restarts);
/* Do we leak memory when aborting an operation?
* This test only makes sense when we actually restart */
- if( min_restarts > 0 )
- {
- ret = mbedtls_ecp_muladd_restartable( &grp, &R,
- &u1, &grp.G, &u2, &Q, &ctx );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
+ if (min_restarts > 0) {
+ ret = mbedtls_ecp_muladd_restartable(&grp, &R,
+ &u1, &grp.G, &u2, &Q, &ctx);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
}
exit:
- mbedtls_ecp_restart_free( &ctx );
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &R );
- mbedtls_ecp_point_free( &Q );
- mbedtls_mpi_free( &u1 ); mbedtls_mpi_free( &u2 );
- mbedtls_mpi_free( &xR ); mbedtls_mpi_free( &yR );
+ mbedtls_ecp_restart_free(&ctx);
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&R);
+ mbedtls_ecp_point_free(&Q);
+ mbedtls_mpi_free(&u1); mbedtls_mpi_free(&u2);
+ mbedtls_mpi_free(&xR); mbedtls_mpi_free(&yR);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_test_vect( int id, char * dA_str, char * xA_str, char * yA_str,
- char * dB_str, char * xB_str, char * yB_str,
- char * xZ_str, char * yZ_str )
+void ecp_test_vect(int id, char *dA_str, char *xA_str, char *yA_str,
+ char *dB_str, char *xB_str, char *yB_str,
+ char *xZ_str, char *yZ_str)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point R;
mbedtls_mpi dA, xA, yA, dB, xB, yB, xZ, yZ;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &R );
- mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &xA ); mbedtls_mpi_init( &yA ); mbedtls_mpi_init( &dB );
- mbedtls_mpi_init( &xB ); mbedtls_mpi_init( &yB ); mbedtls_mpi_init( &xZ ); mbedtls_mpi_init( &yZ );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_group_init(&grp); mbedtls_ecp_point_init(&R);
+ mbedtls_mpi_init(&dA); mbedtls_mpi_init(&xA); mbedtls_mpi_init(&yA); mbedtls_mpi_init(&dB);
+ mbedtls_mpi_init(&xB); mbedtls_mpi_init(&yB); mbedtls_mpi_init(&xZ); mbedtls_mpi_init(&yZ);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &grp.G) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &dA, dA_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xA, xA_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &yA, yA_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &dB, dB_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xB, xB_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &yB, yB_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xZ, xZ_str ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &yZ, yZ_str ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&dA, dA_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xA, xA_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&yA, yA_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&dB, dB_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xB, xB_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&yB, yB_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xZ, xZ_str) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&yZ, yZ_str) == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xA ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yA ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dB, &R,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xZ ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dA, &grp.G,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xA) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.Y, &yA) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dB, &R,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xZ) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.Y, &yZ) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dB, &grp.G,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xB ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yB ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &R,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xZ ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dB, &grp.G,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xB) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.Y, &yB) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dA, &R,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xZ) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.Y, &yZ) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &R );
- mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &xA ); mbedtls_mpi_free( &yA ); mbedtls_mpi_free( &dB );
- mbedtls_mpi_free( &xB ); mbedtls_mpi_free( &yB ); mbedtls_mpi_free( &xZ ); mbedtls_mpi_free( &yZ );
+ mbedtls_ecp_group_free(&grp); mbedtls_ecp_point_free(&R);
+ mbedtls_mpi_free(&dA); mbedtls_mpi_free(&xA); mbedtls_mpi_free(&yA); mbedtls_mpi_free(&dB);
+ mbedtls_mpi_free(&xB); mbedtls_mpi_free(&yB); mbedtls_mpi_free(&xZ); mbedtls_mpi_free(&yZ);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_test_vec_x( int id, char * dA_hex, char * xA_hex, char * dB_hex,
- char * xB_hex, char * xS_hex )
+void ecp_test_vec_x(int id, char *dA_hex, char *xA_hex, char *dB_hex,
+ char *xB_hex, char *xS_hex)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point R;
mbedtls_mpi dA, xA, dB, xB, xS;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &R );
- mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &xA );
- mbedtls_mpi_init( &dB ); mbedtls_mpi_init( &xB );
- mbedtls_mpi_init( &xS );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_group_init(&grp); mbedtls_ecp_point_init(&R);
+ mbedtls_mpi_init(&dA); mbedtls_mpi_init(&xA);
+ mbedtls_mpi_init(&dB); mbedtls_mpi_init(&xB);
+ mbedtls_mpi_init(&xS);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &grp.G) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &dA, dA_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &dB, dB_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xA, xA_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xB, xB_hex ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &xS, xS_hex ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&dA, dA_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&dB, dB_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xA, xA_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xB, xB_hex) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&xS, xS_hex) == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xA ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dA, &grp.G,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xA) == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dB, &R,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xS ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dB, &R,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xS) == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dB, &grp.G,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xB ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dB, &grp.G,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xB) == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &R,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xS ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &dA, &R,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &R) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R.X, &xS) == 0);
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &R );
- mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &xA );
- mbedtls_mpi_free( &dB ); mbedtls_mpi_free( &xB );
- mbedtls_mpi_free( &xS );
+ mbedtls_ecp_group_free(&grp); mbedtls_ecp_point_free(&R);
+ mbedtls_mpi_free(&dA); mbedtls_mpi_free(&xA);
+ mbedtls_mpi_free(&dB); mbedtls_mpi_free(&xB);
+ mbedtls_mpi_free(&xS);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_test_mul( int id, data_t * n_hex,
- data_t * Px_hex, data_t * Py_hex, data_t * Pz_hex,
- data_t * nPx_hex, data_t * nPy_hex, data_t * nPz_hex,
- int expected_ret )
+void ecp_test_mul(int id, data_t *n_hex,
+ data_t *Px_hex, data_t *Py_hex, data_t *Pz_hex,
+ data_t *nPx_hex, data_t *nPy_hex, data_t *nPz_hex,
+ int expected_ret)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point P, nP, R;
mbedtls_mpi n;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &R );
- mbedtls_ecp_point_init( &P ); mbedtls_ecp_point_init( &nP );
- mbedtls_mpi_init( &n );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_group_init(&grp); mbedtls_ecp_point_init(&R);
+ mbedtls_ecp_point_init(&P); mbedtls_ecp_point_init(&nP);
+ mbedtls_mpi_init(&n);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &grp.G) == 0);
- TEST_ASSERT( mbedtls_mpi_read_binary( &n, n_hex->x, n_hex->len ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&n, n_hex->x, n_hex->len) == 0);
- TEST_ASSERT( mbedtls_mpi_read_binary( &P.X, Px_hex->x, Px_hex->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &P.Y, Py_hex->x, Py_hex->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &P.Z, Pz_hex->x, Pz_hex->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &nP.X, nPx_hex->x, nPx_hex->len )
- == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &nP.Y, nPy_hex->x, nPy_hex->len )
- == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &nP.Z, nPz_hex->x, nPz_hex->len )
- == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&P.X, Px_hex->x, Px_hex->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&P.Y, Py_hex->x, Py_hex->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&P.Z, Pz_hex->x, Pz_hex->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&nP.X, nPx_hex->x, nPx_hex->len)
+ == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&nP.Y, nPy_hex->x, nPy_hex->len)
+ == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&nP.Z, nPz_hex->x, nPz_hex->len)
+ == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &n, &P,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info )
- == expected_ret );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &R, &n, &P,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info)
+ == expected_ret);
- if( expected_ret == 0 )
- {
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &nP.X, &R.X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &nP.Y, &R.Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &nP.Z, &R.Z ) == 0 );
+ if (expected_ret == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&nP.X, &R.X) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&nP.Y, &R.Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&nP.Z, &R.Z) == 0);
}
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &R );
- mbedtls_ecp_point_free( &P ); mbedtls_ecp_point_free( &nP );
- mbedtls_mpi_free( &n );
+ mbedtls_ecp_group_free(&grp); mbedtls_ecp_point_free(&R);
+ mbedtls_ecp_point_free(&P); mbedtls_ecp_point_free(&nP);
+ mbedtls_mpi_free(&n);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_test_mul_rng( int id, data_t * d_hex)
+void ecp_test_mul_rng(int id, data_t *d_hex)
{
mbedtls_ecp_group grp;
mbedtls_mpi d;
mbedtls_ecp_point Q;
- mbedtls_ecp_group_init( &grp ); mbedtls_mpi_init( &d );
- mbedtls_ecp_point_init( &Q );
+ mbedtls_ecp_group_init(&grp); mbedtls_mpi_init(&d);
+ mbedtls_ecp_point_init(&Q);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &grp.G) == 0);
- TEST_ASSERT( mbedtls_mpi_read_binary( &d, d_hex->x, d_hex->len ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&d, d_hex->x, d_hex->len) == 0);
- TEST_ASSERT( mbedtls_ecp_mul( &grp, &Q, &d, &grp.G,
- &mbedtls_test_rnd_zero_rand, NULL )
- == MBEDTLS_ERR_ECP_RANDOM_FAILED );
+ TEST_ASSERT(mbedtls_ecp_mul(&grp, &Q, &d, &grp.G,
+ &mbedtls_test_rnd_zero_rand, NULL)
+ == MBEDTLS_ERR_ECP_RANDOM_FAILED);
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_mpi_free( &d );
- mbedtls_ecp_point_free( &Q );
+ mbedtls_ecp_group_free(&grp); mbedtls_mpi_free(&d);
+ mbedtls_ecp_point_free(&Q);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
-void ecp_muladd( int id,
- data_t *u1_bin, data_t *P1_bin,
- data_t *u2_bin, data_t *P2_bin,
- data_t *expected_result )
+void ecp_muladd(int id,
+ data_t *u1_bin, data_t *P1_bin,
+ data_t *u2_bin, data_t *P2_bin,
+ data_t *expected_result)
{
/* Compute R = u1 * P1 + u2 * P2 */
mbedtls_ecp_group grp;
@@ -508,165 +520,159 @@
uint8_t actual_result[MBEDTLS_ECP_MAX_PT_LEN];
size_t len;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &P1 );
- mbedtls_ecp_point_init( &P2 );
- mbedtls_ecp_point_init( &R );
- mbedtls_mpi_init( &u1 );
- mbedtls_mpi_init( &u2 );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&P1);
+ mbedtls_ecp_point_init(&P2);
+ mbedtls_ecp_point_init(&R);
+ mbedtls_mpi_init(&u1);
+ mbedtls_mpi_init(&u2);
- TEST_EQUAL( 0, mbedtls_ecp_group_load( &grp, id ) );
- TEST_EQUAL( 0, mbedtls_mpi_read_binary( &u1, u1_bin->x, u1_bin->len ) );
- TEST_EQUAL( 0, mbedtls_mpi_read_binary( &u2, u2_bin->x, u2_bin->len ) );
- TEST_EQUAL( 0, mbedtls_ecp_point_read_binary( &grp, &P1,
- P1_bin->x, P1_bin->len ) );
- TEST_EQUAL( 0, mbedtls_ecp_point_read_binary( &grp, &P2,
- P2_bin->x, P2_bin->len ) );
+ TEST_EQUAL(0, mbedtls_ecp_group_load(&grp, id));
+ TEST_EQUAL(0, mbedtls_mpi_read_binary(&u1, u1_bin->x, u1_bin->len));
+ TEST_EQUAL(0, mbedtls_mpi_read_binary(&u2, u2_bin->x, u2_bin->len));
+ TEST_EQUAL(0, mbedtls_ecp_point_read_binary(&grp, &P1,
+ P1_bin->x, P1_bin->len));
+ TEST_EQUAL(0, mbedtls_ecp_point_read_binary(&grp, &P2,
+ P2_bin->x, P2_bin->len));
- TEST_EQUAL( 0, mbedtls_ecp_muladd( &grp, &R, &u1, &P1, &u2, &P2 ) );
- TEST_EQUAL( 0, mbedtls_ecp_point_write_binary(
- &grp, &R, MBEDTLS_ECP_PF_UNCOMPRESSED,
- &len, actual_result, sizeof( actual_result ) ) );
- TEST_ASSERT( len <= MBEDTLS_ECP_MAX_PT_LEN );
+ TEST_EQUAL(0, mbedtls_ecp_muladd(&grp, &R, &u1, &P1, &u2, &P2));
+ TEST_EQUAL(0, mbedtls_ecp_point_write_binary(
+ &grp, &R, MBEDTLS_ECP_PF_UNCOMPRESSED,
+ &len, actual_result, sizeof(actual_result)));
+ TEST_ASSERT(len <= MBEDTLS_ECP_MAX_PT_LEN);
- ASSERT_COMPARE( expected_result->x, expected_result->len,
- actual_result, len );
+ ASSERT_COMPARE(expected_result->x, expected_result->len,
+ actual_result, len);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &P1 );
- mbedtls_ecp_point_free( &P2 );
- mbedtls_ecp_point_free( &R );
- mbedtls_mpi_free( &u1 );
- mbedtls_mpi_free( &u2 );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&P1);
+ mbedtls_ecp_point_free(&P2);
+ mbedtls_ecp_point_free(&R);
+ mbedtls_mpi_free(&u1);
+ mbedtls_mpi_free(&u2);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_fast_mod( int id, char * N_str )
+void ecp_fast_mod(int id, char *N_str)
{
mbedtls_ecp_group grp;
mbedtls_mpi N, R;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &R );
- mbedtls_ecp_group_init( &grp );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&R);
+ mbedtls_ecp_group_init(&grp);
- TEST_ASSERT( mbedtls_test_read_mpi( &N, N_str ) == 0 );
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
- TEST_ASSERT( grp.modp != NULL );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, N_str) == 0);
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
+ TEST_ASSERT(grp.modp != NULL);
/*
* Store correct result before we touch N
*/
- TEST_ASSERT( mbedtls_mpi_mod_mpi( &R, &N, &grp.P ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_mod_mpi(&R, &N, &grp.P) == 0);
- TEST_ASSERT( grp.modp( &N ) == 0 );
- TEST_ASSERT( mbedtls_mpi_bitlen( &N ) <= grp.pbits + 3 );
+ TEST_ASSERT(grp.modp(&N) == 0);
+ TEST_ASSERT(mbedtls_mpi_bitlen(&N) <= grp.pbits + 3);
/*
* Use mod rather than addition/subtraction in case previous test fails
*/
- TEST_ASSERT( mbedtls_mpi_mod_mpi( &N, &N, &grp.P ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &N, &R ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_mod_mpi(&N, &N, &grp.P) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&N, &R) == 0);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &R );
- mbedtls_ecp_group_free( &grp );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&R);
+ mbedtls_ecp_group_free(&grp);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_write_binary( int id, char * x, char * y, char * z, int format,
- data_t * out, int blen, int ret )
+void ecp_write_binary(int id, char *x, char *y, char *z, int format,
+ data_t *out, int blen, int ret)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point P;
unsigned char buf[256];
size_t olen;
- memset( buf, 0, sizeof( buf ) );
+ memset(buf, 0, sizeof(buf));
- mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &P );
+ mbedtls_ecp_group_init(&grp); mbedtls_ecp_point_init(&P);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &P.X, x ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &P.Y, y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &P.Z, z ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P.X, x) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&P.Y, y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&P.Z, z) == 0);
- TEST_ASSERT( mbedtls_ecp_point_write_binary( &grp, &P, format,
- &olen, buf, blen ) == ret );
+ TEST_ASSERT(mbedtls_ecp_point_write_binary(&grp, &P, format,
+ &olen, buf, blen) == ret);
- if( ret == 0 )
- {
- TEST_ASSERT( olen <= MBEDTLS_ECP_MAX_PT_LEN );
- TEST_ASSERT( mbedtls_test_hexcmp( buf, out->x, olen, out->len ) == 0 );
+ if (ret == 0) {
+ TEST_ASSERT(olen <= MBEDTLS_ECP_MAX_PT_LEN);
+ TEST_ASSERT(mbedtls_test_hexcmp(buf, out->x, olen, out->len) == 0);
}
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &P );
+ mbedtls_ecp_group_free(&grp); mbedtls_ecp_point_free(&P);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_read_binary( int id, data_t * buf, char * x, char * y, char * z,
- int ret )
+void ecp_read_binary(int id, data_t *buf, char *x, char *y, char *z,
+ int ret)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point P;
mbedtls_mpi X, Y, Z;
- mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &P );
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
+ mbedtls_ecp_group_init(&grp); mbedtls_ecp_point_init(&P);
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, x ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Z, z ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, x) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Z, z) == 0);
- TEST_ASSERT( mbedtls_ecp_point_read_binary( &grp, &P, buf->x, buf->len ) == ret );
+ TEST_ASSERT(mbedtls_ecp_point_read_binary(&grp, &P, buf->x, buf->len) == ret);
- if( ret == 0 )
- {
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.X, &X ) == 0 );
- if( mbedtls_ecp_get_type( &grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY )
- {
- TEST_ASSERT( mbedtls_mpi_cmp_int( &Y, 0 ) == 0 );
- TEST_ASSERT( P.Y.p == NULL );
- TEST_ASSERT( mbedtls_mpi_cmp_int( &Z, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_int( &P.Z, 1 ) == 0 );
- }
- else
- {
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.Y, &Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.Z, &Z ) == 0 );
+ if (ret == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P.X, &X) == 0);
+ if (mbedtls_ecp_get_type(&grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&Y, 0) == 0);
+ TEST_ASSERT(P.Y.p == NULL);
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&Z, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_int(&P.Z, 1) == 0);
+ } else {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P.Y, &Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P.Z, &Z) == 0);
- if( buf->x[0] == 0x04 &&
+ if (buf->x[0] == 0x04 &&
/* (reading compressed format supported only for
* Short Weierstrass curves with prime p where p = 3 mod 4) */
id != MBEDTLS_ECP_DP_SECP224R1 &&
- id != MBEDTLS_ECP_DP_SECP224K1 )
- {
+ id != MBEDTLS_ECP_DP_SECP224K1) {
/* re-encode in compressed format and test read again */
- mbedtls_mpi_free( &P.Y );
- buf->x[0] = 0x02 + mbedtls_mpi_get_bit( &Y, 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_binary( &grp, &P, buf->x, buf->len/2+1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.Y, &Y ) == 0 );
+ mbedtls_mpi_free(&P.Y);
+ buf->x[0] = 0x02 + mbedtls_mpi_get_bit(&Y, 0);
+ TEST_ASSERT(mbedtls_ecp_point_read_binary(&grp, &P, buf->x, buf->len/2+1) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P.Y, &Y) == 0);
}
}
}
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &P );
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z );
+ mbedtls_ecp_group_free(&grp); mbedtls_ecp_point_free(&P);
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_tls_read_point( int id, data_t * buf, char * x, char * y,
- char * z, int ret )
+void mbedtls_ecp_tls_read_point(int id, data_t *buf, char *x, char *y,
+ char *z, int ret)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point P;
@@ -674,33 +680,32 @@
const unsigned char *vbuf = buf->x;
- mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &P );
- mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
+ mbedtls_ecp_group_init(&grp); mbedtls_ecp_point_init(&P);
+ mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &X, x ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Y, y ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Z, z ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&X, x) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Y, y) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Z, z) == 0);
- TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &P, &vbuf, buf->len ) == ret );
+ TEST_ASSERT(mbedtls_ecp_tls_read_point(&grp, &P, &vbuf, buf->len) == ret);
- if( ret == 0 )
- {
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.X, &X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.Y, &Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P.Z, &Z ) == 0 );
- TEST_ASSERT( (uint32_t)( vbuf - buf->x ) == buf->len );
+ if (ret == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P.X, &X) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P.Y, &Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P.Z, &Z) == 0);
+ TEST_ASSERT((uint32_t) (vbuf - buf->x) == buf->len);
}
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &P );
- mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z );
+ mbedtls_ecp_group_free(&grp); mbedtls_ecp_point_free(&P);
+ mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_tls_write_read_point( int id )
+void ecp_tls_write_read_point(int id)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point pt;
@@ -708,77 +713,76 @@
const unsigned char *vbuf;
size_t olen;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &pt );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&pt);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
- TEST_ASSERT( mbedtls_ecp_tls_write_point( &grp, &grp.G,
- MBEDTLS_ECP_PF_COMPRESSED, &olen, buf, 256 ) == 0 );
- TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.G.X, &pt.X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.G.Y, &pt.Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.G.Z, &pt.Z ) == 0 );
- TEST_ASSERT( vbuf == buf + olen );
+ memset(buf, 0x00, sizeof(buf)); vbuf = buf;
+ TEST_ASSERT(mbedtls_ecp_tls_write_point(&grp, &grp.G,
+ MBEDTLS_ECP_PF_COMPRESSED, &olen, buf, 256) == 0);
+ TEST_ASSERT(mbedtls_ecp_tls_read_point(&grp, &pt, &vbuf, olen) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp.G.X, &pt.X) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp.G.Y, &pt.Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp.G.Z, &pt.Z) == 0);
+ TEST_ASSERT(vbuf == buf + olen);
- memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
- TEST_ASSERT( mbedtls_ecp_tls_write_point( &grp, &grp.G,
- MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf, 256 ) == 0 );
- TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.G.X, &pt.X ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.G.Y, &pt.Y ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.G.Z, &pt.Z ) == 0 );
- TEST_ASSERT( vbuf == buf + olen );
+ memset(buf, 0x00, sizeof(buf)); vbuf = buf;
+ TEST_ASSERT(mbedtls_ecp_tls_write_point(&grp, &grp.G,
+ MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf, 256) == 0);
+ TEST_ASSERT(mbedtls_ecp_tls_read_point(&grp, &pt, &vbuf, olen) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp.G.X, &pt.X) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp.G.Y, &pt.Y) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp.G.Z, &pt.Z) == 0);
+ TEST_ASSERT(vbuf == buf + olen);
- memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
- TEST_ASSERT( mbedtls_ecp_set_zero( &pt ) == 0 );
- TEST_ASSERT( mbedtls_ecp_tls_write_point( &grp, &pt,
- MBEDTLS_ECP_PF_COMPRESSED, &olen, buf, 256 ) == 0 );
- TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
- TEST_ASSERT( mbedtls_ecp_is_zero( &pt ) );
- TEST_ASSERT( vbuf == buf + olen );
+ memset(buf, 0x00, sizeof(buf)); vbuf = buf;
+ TEST_ASSERT(mbedtls_ecp_set_zero(&pt) == 0);
+ TEST_ASSERT(mbedtls_ecp_tls_write_point(&grp, &pt,
+ MBEDTLS_ECP_PF_COMPRESSED, &olen, buf, 256) == 0);
+ TEST_ASSERT(mbedtls_ecp_tls_read_point(&grp, &pt, &vbuf, olen) == 0);
+ TEST_ASSERT(mbedtls_ecp_is_zero(&pt));
+ TEST_ASSERT(vbuf == buf + olen);
- memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
- TEST_ASSERT( mbedtls_ecp_set_zero( &pt ) == 0 );
- TEST_ASSERT( mbedtls_ecp_tls_write_point( &grp, &pt,
- MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf, 256 ) == 0 );
- TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
- TEST_ASSERT( mbedtls_ecp_is_zero( &pt ) );
- TEST_ASSERT( vbuf == buf + olen );
+ memset(buf, 0x00, sizeof(buf)); vbuf = buf;
+ TEST_ASSERT(mbedtls_ecp_set_zero(&pt) == 0);
+ TEST_ASSERT(mbedtls_ecp_tls_write_point(&grp, &pt,
+ MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf, 256) == 0);
+ TEST_ASSERT(mbedtls_ecp_tls_read_point(&grp, &pt, &vbuf, olen) == 0);
+ TEST_ASSERT(mbedtls_ecp_is_zero(&pt));
+ TEST_ASSERT(vbuf == buf + olen);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &pt );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&pt);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_tls_read_group( data_t * buf, int result, int bits,
- int record_len )
+void mbedtls_ecp_tls_read_group(data_t *buf, int result, int bits,
+ int record_len)
{
mbedtls_ecp_group grp;
const unsigned char *vbuf = buf->x;
int ret;
- mbedtls_ecp_group_init( &grp );
+ mbedtls_ecp_group_init(&grp);
- ret = mbedtls_ecp_tls_read_group( &grp, &vbuf, buf->len );
+ ret = mbedtls_ecp_tls_read_group(&grp, &vbuf, buf->len);
- TEST_ASSERT( ret == result );
- if( ret == 0)
- {
- TEST_ASSERT( mbedtls_mpi_bitlen( &grp.P ) == (size_t) bits );
- TEST_ASSERT( vbuf - buf->x == record_len);
+ TEST_ASSERT(ret == result);
+ if (ret == 0) {
+ TEST_ASSERT(mbedtls_mpi_bitlen(&grp.P) == (size_t) bits);
+ TEST_ASSERT(vbuf - buf->x == record_len);
}
exit:
- mbedtls_ecp_group_free( &grp );
+ mbedtls_ecp_group_free(&grp);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_tls_write_read_group( int id )
+void ecp_tls_write_read_group(int id)
{
mbedtls_ecp_group grp1, grp2;
unsigned char buf[10];
@@ -786,33 +790,32 @@
size_t len;
int ret;
- mbedtls_ecp_group_init( &grp1 );
- mbedtls_ecp_group_init( &grp2 );
- memset( buf, 0x00, sizeof( buf ) );
+ mbedtls_ecp_group_init(&grp1);
+ mbedtls_ecp_group_init(&grp2);
+ memset(buf, 0x00, sizeof(buf));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp1, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp1, id) == 0);
- TEST_ASSERT( mbedtls_ecp_tls_write_group( &grp1, &len, buf, 10 ) == 0 );
- ret = mbedtls_ecp_tls_read_group( &grp2, &vbuf, len );
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(mbedtls_ecp_tls_write_group(&grp1, &len, buf, 10) == 0);
+ ret = mbedtls_ecp_tls_read_group(&grp2, &vbuf, len);
+ TEST_ASSERT(ret == 0);
- if( ret == 0 )
- {
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp1.N, &grp2.N ) == 0 );
- TEST_ASSERT( grp1.id == grp2.id );
+ if (ret == 0) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp1.N, &grp2.N) == 0);
+ TEST_ASSERT(grp1.id == grp2.id);
}
exit:
- mbedtls_ecp_group_free( &grp1 );
- mbedtls_ecp_group_free( &grp2 );
+ mbedtls_ecp_group_free(&grp1);
+ mbedtls_ecp_group_free(&grp2);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECDH_C:MBEDTLS_ECDSA_C */
-void mbedtls_ecp_group_metadata( int id, int bit_size, int crv_type,
- char* P, char* A, char* B,
- char* G_x, char* G_y, char* N,
- int tls_id )
+void mbedtls_ecp_group_metadata(int id, int bit_size, int crv_type,
+ char *P, char *A, char *B,
+ char *G_x, char *G_y, char *N,
+ int tls_id)
{
mbedtls_ecp_group grp, grp_read, grp_cpy;
const mbedtls_ecp_group_id *g_id;
@@ -825,319 +828,320 @@
const unsigned char *vbuf = buf;
size_t olen;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_group_init( &grp_read );
- mbedtls_ecp_group_init( &grp_cpy );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_group_init(&grp_read);
+ mbedtls_ecp_group_init(&grp_cpy);
- mbedtls_mpi_init( &exp_P );
- mbedtls_mpi_init( &exp_A );
- mbedtls_mpi_init( &exp_B );
- mbedtls_mpi_init( &exp_G_x );
- mbedtls_mpi_init( &exp_G_y );
- mbedtls_mpi_init( &exp_N );
+ mbedtls_mpi_init(&exp_P);
+ mbedtls_mpi_init(&exp_A);
+ mbedtls_mpi_init(&exp_B);
+ mbedtls_mpi_init(&exp_G_x);
+ mbedtls_mpi_init(&exp_G_y);
+ mbedtls_mpi_init(&exp_N);
// Read expected parameters
- TEST_EQUAL( mbedtls_test_read_mpi( &exp_P, P ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &exp_A, A ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &exp_G_x, G_x ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &exp_N, N ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &exp_B, B ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &exp_G_y, G_y ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi(&exp_P, P), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&exp_A, A), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&exp_G_x, G_x), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&exp_N, N), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&exp_B, B), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&exp_G_y, G_y), 0);
// Convert exp_A to internal representation (A+2)/4
- if( crv_type == MBEDTLS_ECP_TYPE_MONTGOMERY )
- {
- TEST_EQUAL( mbedtls_mpi_add_int( &exp_A, &exp_A, 2 ), 0 );
- TEST_EQUAL( mbedtls_mpi_div_int( &exp_A, NULL, &exp_A, 4 ), 0 );
+ if (crv_type == MBEDTLS_ECP_TYPE_MONTGOMERY) {
+ TEST_EQUAL(mbedtls_mpi_add_int(&exp_A, &exp_A, 2), 0);
+ TEST_EQUAL(mbedtls_mpi_div_int(&exp_A, NULL, &exp_A, 4), 0);
}
// Load group
- TEST_EQUAL( mbedtls_ecp_group_load( &grp, id ), 0 );
+ TEST_EQUAL(mbedtls_ecp_group_load(&grp, id), 0);
// Compare group with expected parameters
// A is NULL for SECPxxxR1 curves
// B and G_y are NULL for curve25519 and curve448
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &exp_P, &grp.P ), 0 );
- if( *A != 0 )
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &exp_A, &grp.A ), 0 );
- if( *B != 0 )
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &exp_B, &grp.B ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &exp_G_x, &grp.G.X ), 0 );
- if( *G_y != 0 )
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &exp_G_y, &grp.G.Y ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &exp_N, &grp.N ), 0 );
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&exp_P, &grp.P), 0);
+ if (*A != 0) {
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&exp_A, &grp.A), 0);
+ }
+ if (*B != 0) {
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&exp_B, &grp.B), 0);
+ }
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&exp_G_x, &grp.G.X), 0);
+ if (*G_y != 0) {
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&exp_G_y, &grp.G.Y), 0);
+ }
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&exp_N, &grp.N), 0);
// Load curve info and compare with known values
- crv = mbedtls_ecp_curve_info_from_grp_id( id );
- TEST_EQUAL( crv->grp_id, id );
- TEST_EQUAL( crv->bit_size, bit_size );
- TEST_EQUAL( crv->tls_id, tls_id );
+ crv = mbedtls_ecp_curve_info_from_grp_id(id);
+ TEST_EQUAL(crv->grp_id, id);
+ TEST_EQUAL(crv->bit_size, bit_size);
+ TEST_EQUAL(crv->tls_id, tls_id);
// Load curve from TLS ID and name, and compare IDs
- crv_tls_id = mbedtls_ecp_curve_info_from_tls_id( crv->tls_id );
- crv_name = mbedtls_ecp_curve_info_from_name( crv->name );
- TEST_EQUAL( crv_tls_id->grp_id, id );
- TEST_EQUAL( crv_name->grp_id, id );
+ crv_tls_id = mbedtls_ecp_curve_info_from_tls_id(crv->tls_id);
+ crv_name = mbedtls_ecp_curve_info_from_name(crv->name);
+ TEST_EQUAL(crv_tls_id->grp_id, id);
+ TEST_EQUAL(crv_name->grp_id, id);
// Validate write_group against test data
- TEST_EQUAL( mbedtls_ecp_tls_write_group( &grp, &olen,
- buf, sizeof( buf ) ),
- 0 );
- TEST_EQUAL( mbedtls_test_hexcmp( buf, ecparameters, olen,
- sizeof( ecparameters ) ),
- 0 );
+ TEST_EQUAL(mbedtls_ecp_tls_write_group(&grp, &olen,
+ buf, sizeof(buf)),
+ 0);
+ TEST_EQUAL(mbedtls_test_hexcmp(buf, ecparameters, olen,
+ sizeof(ecparameters)),
+ 0);
// Read group from buffer and compare with expected ID
- TEST_EQUAL( mbedtls_ecp_tls_read_group_id( &read_g_id, &vbuf, olen ),
- 0 );
- TEST_EQUAL( read_g_id, id );
+ TEST_EQUAL(mbedtls_ecp_tls_read_group_id(&read_g_id, &vbuf, olen),
+ 0);
+ TEST_EQUAL(read_g_id, id);
vbuf = buf;
- TEST_EQUAL( mbedtls_ecp_tls_read_group( &grp_read, &vbuf, olen ),
- 0 );
- TEST_EQUAL( grp_read.id, id );
+ TEST_EQUAL(mbedtls_ecp_tls_read_group(&grp_read, &vbuf, olen),
+ 0);
+ TEST_EQUAL(grp_read.id, id);
// Check curve type, and if it can be used for ECDH/ECDSA
- TEST_EQUAL( mbedtls_ecp_get_type( &grp ), crv_type );
- TEST_EQUAL( mbedtls_ecdh_can_do( id ), 1 );
- TEST_EQUAL( mbedtls_ecdsa_can_do( id ),
- crv_type == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS );
+ TEST_EQUAL(mbedtls_ecp_get_type(&grp), crv_type);
+ TEST_EQUAL(mbedtls_ecdh_can_do(id), 1);
+ TEST_EQUAL(mbedtls_ecdsa_can_do(id),
+ crv_type == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS);
// Copy group and compare with original
- TEST_EQUAL( mbedtls_ecp_group_copy( &grp_cpy, &grp ), 0 );
- TEST_EQUAL( mbedtls_ecp_group_cmp( &grp, &grp_cpy ), 0 );
+ TEST_EQUAL(mbedtls_ecp_group_copy(&grp_cpy, &grp), 0);
+ TEST_EQUAL(mbedtls_ecp_group_cmp(&grp, &grp_cpy), 0);
// Check curve is in curve list and group ID list
- for( crv = mbedtls_ecp_curve_list( );
- crv->grp_id != MBEDTLS_ECP_DP_NONE &&
- crv->grp_id != (unsigned) id;
- crv++ );
- TEST_EQUAL( crv->grp_id, id );
- for( g_id = mbedtls_ecp_grp_id_list( );
+ for (crv = mbedtls_ecp_curve_list();
+ crv->grp_id != MBEDTLS_ECP_DP_NONE &&
+ crv->grp_id != (unsigned) id;
+ crv++) {
+ ;
+ }
+ TEST_EQUAL(crv->grp_id, id);
+ for (g_id = mbedtls_ecp_grp_id_list();
*g_id != MBEDTLS_ECP_DP_NONE && *g_id != (unsigned) id;
- g_id++ );
- TEST_EQUAL( *g_id, (unsigned) id );
+ g_id++) {
+ ;
+ }
+ TEST_EQUAL(*g_id, (unsigned) id);
exit:
- mbedtls_ecp_group_free( &grp ); mbedtls_ecp_group_free( &grp_cpy );
- mbedtls_ecp_group_free( &grp_read );
- mbedtls_mpi_free( &exp_P ); mbedtls_mpi_free( &exp_A );
- mbedtls_mpi_free( &exp_B ); mbedtls_mpi_free( &exp_G_x );
- mbedtls_mpi_free( &exp_G_y ); mbedtls_mpi_free( &exp_N );
+ mbedtls_ecp_group_free(&grp); mbedtls_ecp_group_free(&grp_cpy);
+ mbedtls_ecp_group_free(&grp_read);
+ mbedtls_mpi_free(&exp_P); mbedtls_mpi_free(&exp_A);
+ mbedtls_mpi_free(&exp_B); mbedtls_mpi_free(&exp_G_x);
+ mbedtls_mpi_free(&exp_G_y); mbedtls_mpi_free(&exp_N);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_check_privkey( int id, char * key_hex, int ret )
+void mbedtls_ecp_check_privkey(int id, char *key_hex, int ret)
{
mbedtls_ecp_group grp;
mbedtls_mpi d;
- mbedtls_ecp_group_init( &grp );
- mbedtls_mpi_init( &d );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_mpi_init(&d);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &d, key_hex ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&d, key_hex) == 0);
- TEST_ASSERT( mbedtls_ecp_check_privkey( &grp, &d ) == ret );
+ TEST_ASSERT(mbedtls_ecp_check_privkey(&grp, &d) == ret);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_mpi_free( &d );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_mpi_free(&d);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_check_pub_priv( int id_pub, char * Qx_pub, char * Qy_pub,
- int id, char * d, char * Qx, char * Qy,
- int ret )
+void mbedtls_ecp_check_pub_priv(int id_pub, char *Qx_pub, char *Qy_pub,
+ int id, char *d, char *Qx, char *Qy,
+ int ret)
{
mbedtls_ecp_keypair pub, prv;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_keypair_init( &pub );
- mbedtls_ecp_keypair_init( &prv );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_keypair_init(&pub);
+ mbedtls_ecp_keypair_init(&prv);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- if( id_pub != MBEDTLS_ECP_DP_NONE )
- TEST_ASSERT( mbedtls_ecp_group_load( &pub.grp, id_pub ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_string( &pub.Q, 16, Qx_pub, Qy_pub ) == 0 );
+ if (id_pub != MBEDTLS_ECP_DP_NONE) {
+ TEST_ASSERT(mbedtls_ecp_group_load(&pub.grp, id_pub) == 0);
+ }
+ TEST_ASSERT(mbedtls_ecp_point_read_string(&pub.Q, 16, Qx_pub, Qy_pub) == 0);
- if( id != MBEDTLS_ECP_DP_NONE )
- TEST_ASSERT( mbedtls_ecp_group_load( &prv.grp, id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_string( &prv.Q, 16, Qx, Qy ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.d, d ) == 0 );
+ if (id != MBEDTLS_ECP_DP_NONE) {
+ TEST_ASSERT(mbedtls_ecp_group_load(&prv.grp, id) == 0);
+ }
+ TEST_ASSERT(mbedtls_ecp_point_read_string(&prv.Q, 16, Qx, Qy) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.d, d) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pub_priv( &pub, &prv,
- &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
+ TEST_ASSERT(mbedtls_ecp_check_pub_priv(&pub, &prv,
+ &mbedtls_test_rnd_pseudo_rand, &rnd_info) == ret);
exit:
- mbedtls_ecp_keypair_free( &pub );
- mbedtls_ecp_keypair_free( &prv );
+ mbedtls_ecp_keypair_free(&pub);
+ mbedtls_ecp_keypair_free(&prv);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_gen_keypair( int id )
+void mbedtls_ecp_gen_keypair(int id)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point Q;
mbedtls_mpi d;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &Q );
- mbedtls_mpi_init( &d );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&Q);
+ mbedtls_mpi_init(&d);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
- TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_gen_keypair(&grp, &d, &Q,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &Q ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_privkey( &grp, &d ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&grp, &Q) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_privkey(&grp, &d) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &Q );
- mbedtls_mpi_free( &d );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&Q);
+ mbedtls_mpi_free(&d);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_gen_key( int id )
+void mbedtls_ecp_gen_key(int id)
{
mbedtls_ecp_keypair key;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_ecp_keypair_init( &key );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ mbedtls_ecp_keypair_init(&key);
+ memset(&rnd_info, 0x00, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_ecp_gen_key( id, &key,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_gen_key(id, &key,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info) == 0);
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &key.grp, &key.Q ) == 0 );
- TEST_ASSERT( mbedtls_ecp_check_privkey( &key.grp, &key.d ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&key.grp, &key.Q) == 0);
+ TEST_ASSERT(mbedtls_ecp_check_privkey(&key.grp, &key.d) == 0);
exit:
- mbedtls_ecp_keypair_free( &key );
+ mbedtls_ecp_keypair_free(&key);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_ecp_read_key( int grp_id, data_t* in_key, int expected, int canonical )
+void mbedtls_ecp_read_key(int grp_id, data_t *in_key, int expected, int canonical)
{
int ret = 0;
mbedtls_ecp_keypair key;
mbedtls_ecp_keypair key2;
- mbedtls_ecp_keypair_init( &key );
- mbedtls_ecp_keypair_init( &key2 );
+ mbedtls_ecp_keypair_init(&key);
+ mbedtls_ecp_keypair_init(&key2);
- ret = mbedtls_ecp_read_key( grp_id, &key, in_key->x, in_key->len );
- TEST_ASSERT( ret == expected );
+ ret = mbedtls_ecp_read_key(grp_id, &key, in_key->x, in_key->len);
+ TEST_ASSERT(ret == expected);
- if( expected == 0 )
- {
- ret = mbedtls_ecp_check_privkey( &key.grp, &key.d );
- TEST_ASSERT( ret == 0 );
+ if (expected == 0) {
+ ret = mbedtls_ecp_check_privkey(&key.grp, &key.d);
+ TEST_ASSERT(ret == 0);
- if( canonical )
- {
+ if (canonical) {
unsigned char buf[MBEDTLS_ECP_MAX_BYTES];
- ret = mbedtls_ecp_write_key( &key, buf, in_key->len );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ecp_write_key(&key, buf, in_key->len);
+ TEST_ASSERT(ret == 0);
- ASSERT_COMPARE( in_key->x, in_key->len,
- buf, in_key->len );
- }
- else
- {
+ ASSERT_COMPARE(in_key->x, in_key->len,
+ buf, in_key->len);
+ } else {
unsigned char export1[MBEDTLS_ECP_MAX_BYTES];
unsigned char export2[MBEDTLS_ECP_MAX_BYTES];
- ret = mbedtls_ecp_write_key( &key, export1, in_key->len );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ecp_write_key(&key, export1, in_key->len);
+ TEST_ASSERT(ret == 0);
- ret = mbedtls_ecp_read_key( grp_id, &key2, export1, in_key->len );
- TEST_ASSERT( ret == expected );
+ ret = mbedtls_ecp_read_key(grp_id, &key2, export1, in_key->len);
+ TEST_ASSERT(ret == expected);
- ret = mbedtls_ecp_write_key( &key2, export2, in_key->len );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ecp_write_key(&key2, export2, in_key->len);
+ TEST_ASSERT(ret == 0);
- ASSERT_COMPARE( export1, in_key->len,
- export2, in_key->len );
+ ASSERT_COMPARE(export1, in_key->len,
+ export2, in_key->len);
}
}
exit:
- mbedtls_ecp_keypair_free( &key );
- mbedtls_ecp_keypair_free( &key2 );
+ mbedtls_ecp_keypair_free(&key);
+ mbedtls_ecp_keypair_free(&key2);
}
/* END_CASE */
/* BEGIN_CASE depends_on:HAVE_FIX_NEGATIVE */
-void fix_negative( data_t *N_bin, int c, int bits )
+void fix_negative(data_t *N_bin, int c, int bits)
{
mbedtls_mpi C, M, N;
- mbedtls_mpi_init( &C );
- mbedtls_mpi_init( &M );
- mbedtls_mpi_init( &N );
+ mbedtls_mpi_init(&C);
+ mbedtls_mpi_init(&M);
+ mbedtls_mpi_init(&N);
/* C = - c * 2^bits (positive since c is negative) */
- TEST_EQUAL( 0, mbedtls_mpi_lset( &C, -c ) );
- TEST_EQUAL( 0, mbedtls_mpi_shift_l( &C, bits ) );
+ TEST_EQUAL(0, mbedtls_mpi_lset(&C, -c));
+ TEST_EQUAL(0, mbedtls_mpi_shift_l(&C, bits));
- TEST_EQUAL( 0, mbedtls_mpi_read_binary( &N, N_bin->x, N_bin->len ) );
- TEST_EQUAL( 0, mbedtls_mpi_grow( &N, C.n ) );
+ TEST_EQUAL(0, mbedtls_mpi_read_binary(&N, N_bin->x, N_bin->len));
+ TEST_EQUAL(0, mbedtls_mpi_grow(&N, C.n));
/* M = N - C = - ( C - N ) (expected result of fix_negative) */
- TEST_EQUAL( 0, mbedtls_mpi_sub_mpi( &M, &N, &C ) );
+ TEST_EQUAL(0, mbedtls_mpi_sub_mpi(&M, &N, &C));
- mbedtls_ecp_fix_negative( &N, c, bits );
+ mbedtls_ecp_fix_negative(&N, c, bits);
- TEST_EQUAL( 0, mbedtls_mpi_cmp_mpi( &N, &M ) );
+ TEST_EQUAL(0, mbedtls_mpi_cmp_mpi(&N, &M));
exit:
- mbedtls_mpi_free( &C );
- mbedtls_mpi_free( &M );
- mbedtls_mpi_free( &N );
+ mbedtls_mpi_free(&C);
+ mbedtls_mpi_free(&M);
+ mbedtls_mpi_free(&N);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_MONTGOMERY_ENABLED */
-void genkey_mx_known_answer( int bits, data_t *seed, data_t *expected )
+void genkey_mx_known_answer(int bits, data_t *seed, data_t *expected)
{
mbedtls_test_rnd_buf_info rnd_info;
mbedtls_mpi d;
int ret;
uint8_t *actual = NULL;
- mbedtls_mpi_init( &d );
+ mbedtls_mpi_init(&d);
rnd_info.buf = seed->x;
rnd_info.length = seed->len;
rnd_info.fallback_f_rng = NULL;
rnd_info.fallback_p_rng = NULL;
- ASSERT_ALLOC( actual, expected->len );
+ ASSERT_ALLOC(actual, expected->len);
- ret = mbedtls_ecp_gen_privkey_mx( bits, &d,
- mbedtls_test_rnd_buffer_rand, &rnd_info );
+ ret = mbedtls_ecp_gen_privkey_mx(bits, &d,
+ mbedtls_test_rnd_buffer_rand, &rnd_info);
- if( expected->len == 0 )
- {
+ if (expected->len == 0) {
/* Expecting an error (happens if there isn't enough randomness) */
- TEST_ASSERT( ret != 0 );
- }
- else
- {
- TEST_EQUAL( ret, 0 );
- TEST_EQUAL( (size_t) bits + 1, mbedtls_mpi_bitlen( &d ) );
- TEST_EQUAL( 0, mbedtls_mpi_write_binary( &d, actual, expected->len ) );
+ TEST_ASSERT(ret != 0);
+ } else {
+ TEST_EQUAL(ret, 0);
+ TEST_EQUAL((size_t) bits + 1, mbedtls_mpi_bitlen(&d));
+ TEST_EQUAL(0, mbedtls_mpi_write_binary(&d, actual, expected->len));
/* Test the exact result. This assumes that the output of the
* RNG is used in a specific way, which is overly constraining.
* The advantage is that it's easier to test the expected properties
@@ -1148,146 +1152,146 @@
* (can be enforced by checking these bits).
* - Other bits must be random (by testing with different RNG outputs,
* we validate that those bits are indeed influenced by the RNG). */
- ASSERT_COMPARE( expected->x, expected->len,
- actual, expected->len );
+ ASSERT_COMPARE(expected->x, expected->len,
+ actual, expected->len);
}
exit:
- mbedtls_free( actual );
- mbedtls_mpi_free( &d );
+ mbedtls_free(actual);
+ mbedtls_mpi_free(&d);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_set_zero( int id, data_t * P_bin )
+void ecp_set_zero(int id, data_t *P_bin)
{
mbedtls_ecp_group grp;
mbedtls_ecp_point pt, zero_pt, nonzero_pt;
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &pt );
- mbedtls_ecp_point_init( &zero_pt );
- mbedtls_ecp_point_init( &nonzero_pt );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_ecp_point_init(&pt);
+ mbedtls_ecp_point_init(&zero_pt);
+ mbedtls_ecp_point_init(&nonzero_pt);
// Set zero and non-zero points for comparison
- TEST_EQUAL( mbedtls_ecp_set_zero( &zero_pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_group_load( &grp, id ), 0 );
- TEST_EQUAL( mbedtls_ecp_point_read_binary( &grp, &nonzero_pt,
- P_bin->x, P_bin->len ), 0 );
- TEST_EQUAL( mbedtls_ecp_is_zero( &zero_pt ), 1 );
- TEST_EQUAL( mbedtls_ecp_is_zero( &nonzero_pt ), 0 );
+ TEST_EQUAL(mbedtls_ecp_set_zero(&zero_pt), 0);
+ TEST_EQUAL(mbedtls_ecp_group_load(&grp, id), 0);
+ TEST_EQUAL(mbedtls_ecp_point_read_binary(&grp, &nonzero_pt,
+ P_bin->x, P_bin->len), 0);
+ TEST_EQUAL(mbedtls_ecp_is_zero(&zero_pt), 1);
+ TEST_EQUAL(mbedtls_ecp_is_zero(&nonzero_pt), 0);
// Test initialized point
- TEST_EQUAL( mbedtls_ecp_set_zero( &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_is_zero( &pt ), 1 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &zero_pt, &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &nonzero_pt, &zero_pt ),
- MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_ecp_set_zero(&pt), 0);
+ TEST_EQUAL(mbedtls_ecp_is_zero(&pt), 1);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&zero_pt, &pt), 0);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&nonzero_pt, &zero_pt),
+ MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
// Test zeroed point
- TEST_EQUAL( mbedtls_ecp_set_zero( &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_is_zero( &pt ), 1 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &zero_pt, &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &nonzero_pt, &pt ),
- MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_ecp_set_zero(&pt), 0);
+ TEST_EQUAL(mbedtls_ecp_is_zero(&pt), 1);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&zero_pt, &pt), 0);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&nonzero_pt, &pt),
+ MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
// Set point to non-zero value
- TEST_EQUAL( mbedtls_ecp_point_read_binary( &grp, &pt,
- P_bin->x, P_bin->len ), 0 );
- TEST_EQUAL( mbedtls_ecp_is_zero( &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &zero_pt, &pt ),
- MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &nonzero_pt, &pt), 0 );
+ TEST_EQUAL(mbedtls_ecp_point_read_binary(&grp, &pt,
+ P_bin->x, P_bin->len), 0);
+ TEST_EQUAL(mbedtls_ecp_is_zero(&pt), 0);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&zero_pt, &pt),
+ MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&nonzero_pt, &pt), 0);
// Test non-zero point
- TEST_EQUAL( mbedtls_ecp_set_zero( &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_is_zero( &pt ), 1 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &zero_pt, &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &nonzero_pt, &pt ),
- MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_ecp_set_zero(&pt), 0);
+ TEST_EQUAL(mbedtls_ecp_is_zero(&pt), 1);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&zero_pt, &pt), 0);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&nonzero_pt, &pt),
+ MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
// Test freed non-zero point
- TEST_EQUAL( mbedtls_ecp_point_read_binary( &grp, &pt,
- P_bin->x, P_bin->len ), 0 );
- mbedtls_ecp_point_free( &pt );
- TEST_EQUAL( mbedtls_ecp_set_zero( &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_is_zero( &pt ), 1 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &zero_pt, &pt ), 0 );
- TEST_EQUAL( mbedtls_ecp_point_cmp( &nonzero_pt, &pt),
- MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_ecp_point_read_binary(&grp, &pt,
+ P_bin->x, P_bin->len), 0);
+ mbedtls_ecp_point_free(&pt);
+ TEST_EQUAL(mbedtls_ecp_set_zero(&pt), 0);
+ TEST_EQUAL(mbedtls_ecp_is_zero(&pt), 1);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&zero_pt, &pt), 0);
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&nonzero_pt, &pt),
+ MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &pt );
- mbedtls_ecp_point_free( &zero_pt );
- mbedtls_ecp_point_free( &nonzero_pt );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_ecp_point_free(&pt);
+ mbedtls_ecp_point_free(&zero_pt);
+ mbedtls_ecp_point_free(&nonzero_pt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void ecp_selftest( )
+void ecp_selftest()
{
- TEST_ASSERT( mbedtls_ecp_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_export( int id, char * Qx, char * Qy,char * d, int expected_ret, int invalid_grp )
+void ecp_export(int id, char *Qx, char *Qy, char *d, int expected_ret, int invalid_grp)
{
mbedtls_ecp_keypair key;
mbedtls_ecp_group export_grp;
mbedtls_mpi export_d;
mbedtls_ecp_point export_Q;
- mbedtls_ecp_group_init( &export_grp );
- mbedtls_ecp_group_init( &key.grp );
- mbedtls_mpi_init( &export_d );
- mbedtls_ecp_point_init( &export_Q );
+ mbedtls_ecp_group_init(&export_grp);
+ mbedtls_ecp_group_init(&key.grp);
+ mbedtls_mpi_init(&export_d);
+ mbedtls_ecp_point_init(&export_Q);
- mbedtls_ecp_keypair_init( &key );
- if( invalid_grp == 0 )
- TEST_ASSERT( mbedtls_ecp_group_load( &key.grp, id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_string( &key.Q, 16, Qx, Qy ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &key.d, d ) == 0 );
+ mbedtls_ecp_keypair_init(&key);
+ if (invalid_grp == 0) {
+ TEST_ASSERT(mbedtls_ecp_group_load(&key.grp, id) == 0);
+ }
+ TEST_ASSERT(mbedtls_ecp_point_read_string(&key.Q, 16, Qx, Qy) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&key.d, d) == 0);
- TEST_EQUAL( mbedtls_ecp_export( &key, &export_grp,
- &export_d, &export_Q ), expected_ret );
+ TEST_EQUAL(mbedtls_ecp_export(&key, &export_grp,
+ &export_d, &export_Q), expected_ret);
- if( expected_ret == 0 )
- {
- TEST_EQUAL( mbedtls_ecp_point_cmp( &key.Q, &export_Q ), 0 );
- TEST_EQUAL( mbedtls_mpi_cmp_mpi( &key.d, &export_d ), 0 );
- TEST_EQUAL( mbedtls_ecp_group_cmp( &key.grp, &export_grp ), 0 );
+ if (expected_ret == 0) {
+ TEST_EQUAL(mbedtls_ecp_point_cmp(&key.Q, &export_Q), 0);
+ TEST_EQUAL(mbedtls_mpi_cmp_mpi(&key.d, &export_d), 0);
+ TEST_EQUAL(mbedtls_ecp_group_cmp(&key.grp, &export_grp), 0);
}
exit:
- mbedtls_ecp_keypair_free( &key );
- mbedtls_ecp_group_free( &export_grp );
- mbedtls_mpi_free( &export_d );
- mbedtls_ecp_point_free( &export_Q );
+ mbedtls_ecp_keypair_free(&key);
+ mbedtls_ecp_group_free(&export_grp);
+ mbedtls_mpi_free(&export_d);
+ mbedtls_ecp_point_free(&export_Q);
}
/* END_CASE */
/* BEGIN_CASE */
-void ecp_check_order( int id, char * expected_order_hex )
+void ecp_check_order(int id, char *expected_order_hex)
{
mbedtls_ecp_group grp;
mbedtls_mpi expected_n;
- mbedtls_ecp_group_init( &grp );
- mbedtls_mpi_init( &expected_n );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_mpi_init(&expected_n);
- TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &expected_n, expected_order_hex ) == 0);
+ TEST_ASSERT(mbedtls_ecp_group_load(&grp, id) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&expected_n, expected_order_hex) == 0);
// check sign bits are well-formed (i.e. 1 or -1) - see #5810
- TEST_ASSERT( grp.N.s == -1 || grp.N.s == 1);
- TEST_ASSERT( expected_n.s == -1 || expected_n.s == 1);
+ TEST_ASSERT(grp.N.s == -1 || grp.N.s == 1);
+ TEST_ASSERT(expected_n.s == -1 || expected_n.s == 1);
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.N, &expected_n ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&grp.N, &expected_n) == 0);
exit:
- mbedtls_ecp_group_free( &grp );
- mbedtls_mpi_free( &expected_n );
+ mbedtls_ecp_group_free(&grp);
+ mbedtls_mpi_free(&expected_n);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_entropy.function b/tests/suites/test_suite_entropy.function
index c26f4f8..c36d2c8 100644
--- a/tests/suites/test_suite_entropy.function
+++ b/tests/suites/test_suite_entropy.function
@@ -4,15 +4,13 @@
#include "mbedtls/md.h"
#include "string.h"
-typedef enum
-{
+typedef enum {
DUMMY_CONSTANT_LENGTH, /* Output context->length bytes */
DUMMY_REQUESTED_LENGTH, /* Output whatever length was requested */
DUMMY_FAIL, /* Return an error code */
} entropy_dummy_instruction;
-typedef struct
-{
+typedef struct {
entropy_dummy_instruction instruction;
size_t length; /* Length to return for DUMMY_CONSTANT_LENGTH */
size_t calls; /* Incremented at each call */
@@ -24,14 +22,13 @@
* If data is NULL, write exactly the requested length.
* Otherwise, write the length indicated by data or error if negative
*/
-static int entropy_dummy_source( void *arg, unsigned char *output,
- size_t len, size_t *olen )
+static int entropy_dummy_source(void *arg, unsigned char *output,
+ size_t len, size_t *olen)
{
entropy_dummy_context *context = arg;
++context->calls;
- switch( context->instruction )
- {
+ switch (context->instruction) {
case DUMMY_CONSTANT_LENGTH:
*olen = context->length;
break;
@@ -39,11 +36,11 @@
*olen = len;
break;
case DUMMY_FAIL:
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
- memset( output, 0x2a, *olen );
- return( 0 );
+ memset(output, 0x2a, *olen);
+ return 0;
}
/*
@@ -57,7 +54,7 @@
* This might break memory checks in the future if sources need 'free-ing' then
* as well.
*/
-static void entropy_clear_sources( mbedtls_entropy_context *ctx )
+static void entropy_clear_sources(mbedtls_entropy_context *ctx)
{
ctx->source_count = 0;
}
@@ -68,63 +65,71 @@
*/
static unsigned char buffer_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
-int buffer_nv_seed_read( unsigned char *buf, size_t buf_len )
+int buffer_nv_seed_read(unsigned char *buf, size_t buf_len)
{
- if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
- return( -1 );
+ if (buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE) {
+ return -1;
+ }
- memcpy( buf, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE );
- return( 0 );
+ memcpy(buf, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE);
+ return 0;
}
-int buffer_nv_seed_write( unsigned char *buf, size_t buf_len )
+int buffer_nv_seed_write(unsigned char *buf, size_t buf_len)
{
- if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
- return( -1 );
+ if (buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE) {
+ return -1;
+ }
- memcpy( buffer_seed, buf, MBEDTLS_ENTROPY_BLOCK_SIZE );
- return( 0 );
+ memcpy(buffer_seed, buf, MBEDTLS_ENTROPY_BLOCK_SIZE);
+ return 0;
}
/*
* NV seed read/write helpers that fill the base seedfile
*/
-static int write_nv_seed( unsigned char *buf, size_t buf_len )
+static int write_nv_seed(unsigned char *buf, size_t buf_len)
{
FILE *f;
- if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
- return( -1 );
+ if (buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE) {
+ return -1;
+ }
- if( ( f = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "w" ) ) == NULL )
- return( -1 );
+ if ((f = fopen(MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "w")) == NULL) {
+ return -1;
+ }
- if( fwrite( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) !=
- MBEDTLS_ENTROPY_BLOCK_SIZE )
- return( -1 );
+ if (fwrite(buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f) !=
+ MBEDTLS_ENTROPY_BLOCK_SIZE) {
+ return -1;
+ }
- fclose( f );
+ fclose(f);
- return( 0 );
+ return 0;
}
-int read_nv_seed( unsigned char *buf, size_t buf_len )
+int read_nv_seed(unsigned char *buf, size_t buf_len)
{
FILE *f;
- if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
- return( -1 );
+ if (buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE) {
+ return -1;
+ }
- if( ( f = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb" ) ) == NULL )
- return( -1 );
+ if ((f = fopen(MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb")) == NULL) {
+ return -1;
+ }
- if( fread( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) !=
- MBEDTLS_ENTROPY_BLOCK_SIZE )
- return( -1 );
+ if (fread(buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f) !=
+ MBEDTLS_ENTROPY_BLOCK_SIZE) {
+ return -1;
+ }
- fclose( f );
+ fclose(f);
- return( 0 );
+ return 0;
}
#endif /* MBEDTLS_ENTROPY_NV_SEED */
/* END_HEADER */
@@ -135,7 +140,7 @@
*/
/* BEGIN_CASE */
-void entropy_init_free( int reinit )
+void entropy_init_free(int reinit)
{
mbedtls_entropy_context ctx;
@@ -143,12 +148,13 @@
* to call mbedtls_entropy_free() unconditionally on an error path without
* checking whether it has already been called in the success path. */
- mbedtls_entropy_init( &ctx );
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_init(&ctx);
+ mbedtls_entropy_free(&ctx);
- if( reinit )
- mbedtls_entropy_init( &ctx );
- mbedtls_entropy_free( &ctx );
+ if (reinit) {
+ mbedtls_entropy_init(&ctx);
+ }
+ mbedtls_entropy_free(&ctx);
/* This test case always succeeds, functionally speaking. A plausible
* bug might trigger an invalid pointer dereference or a memory leak. */
@@ -157,189 +163,190 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
-void entropy_seed_file( char * path, int ret )
+void entropy_seed_file(char *path, int ret)
{
mbedtls_entropy_context ctx;
- mbedtls_entropy_init( &ctx );
+ mbedtls_entropy_init(&ctx);
- TEST_ASSERT( mbedtls_entropy_write_seed_file( &ctx, path ) == ret );
- TEST_ASSERT( mbedtls_entropy_update_seed_file( &ctx, path ) == ret );
+ TEST_ASSERT(mbedtls_entropy_write_seed_file(&ctx, path) == ret);
+ TEST_ASSERT(mbedtls_entropy_update_seed_file(&ctx, path) == ret);
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
-void entropy_write_base_seed_file( int ret )
+void entropy_write_base_seed_file(int ret)
{
mbedtls_entropy_context ctx;
- mbedtls_entropy_init( &ctx );
+ mbedtls_entropy_init(&ctx);
- TEST_ASSERT( mbedtls_entropy_write_seed_file( &ctx, MBEDTLS_PLATFORM_STD_NV_SEED_FILE ) == ret );
- TEST_ASSERT( mbedtls_entropy_update_seed_file( &ctx, MBEDTLS_PLATFORM_STD_NV_SEED_FILE ) == ret );
+ TEST_ASSERT(mbedtls_entropy_write_seed_file(&ctx, MBEDTLS_PLATFORM_STD_NV_SEED_FILE) == ret);
+ TEST_ASSERT(mbedtls_entropy_update_seed_file(&ctx, MBEDTLS_PLATFORM_STD_NV_SEED_FILE) == ret);
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void entropy_no_sources( )
+void entropy_no_sources()
{
mbedtls_entropy_context ctx;
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
- mbedtls_entropy_init( &ctx );
- entropy_clear_sources( &ctx );
- TEST_EQUAL( mbedtls_entropy_func( &ctx, buf, sizeof( buf ) ),
- MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED );
+ mbedtls_entropy_init(&ctx);
+ entropy_clear_sources(&ctx);
+ TEST_EQUAL(mbedtls_entropy_func(&ctx, buf, sizeof(buf)),
+ MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED);
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void entropy_too_many_sources( )
+void entropy_too_many_sources()
{
mbedtls_entropy_context ctx;
size_t i;
- entropy_dummy_context dummy = {DUMMY_REQUESTED_LENGTH, 0, 0};
+ entropy_dummy_context dummy = { DUMMY_REQUESTED_LENGTH, 0, 0 };
- mbedtls_entropy_init( &ctx );
+ mbedtls_entropy_init(&ctx);
/*
* It's hard to tell precisely when the error will occur,
* since we don't know how many sources were automatically added.
*/
- for( i = 0; i < MBEDTLS_ENTROPY_MAX_SOURCES; i++ )
- (void) mbedtls_entropy_add_source( &ctx, entropy_dummy_source, &dummy,
- 16, MBEDTLS_ENTROPY_SOURCE_WEAK );
+ for (i = 0; i < MBEDTLS_ENTROPY_MAX_SOURCES; i++) {
+ (void) mbedtls_entropy_add_source(&ctx, entropy_dummy_source, &dummy,
+ 16, MBEDTLS_ENTROPY_SOURCE_WEAK);
+ }
- TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source, &dummy,
- 16, MBEDTLS_ENTROPY_SOURCE_WEAK )
- == MBEDTLS_ERR_ENTROPY_MAX_SOURCES );
+ TEST_ASSERT(mbedtls_entropy_add_source(&ctx, entropy_dummy_source, &dummy,
+ 16, MBEDTLS_ENTROPY_SOURCE_WEAK)
+ == MBEDTLS_ERR_ENTROPY_MAX_SOURCES);
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:ENTROPY_HAVE_STRONG */
-void entropy_func_len( int len, int ret )
+void entropy_func_len(int len, int ret)
{
mbedtls_entropy_context ctx;
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE + 10] = { 0 };
unsigned char acc[MBEDTLS_ENTROPY_BLOCK_SIZE + 10] = { 0 };
size_t i, j;
- mbedtls_entropy_init( &ctx );
+ mbedtls_entropy_init(&ctx);
/*
* See comments in mbedtls_entropy_self_test()
*/
- for( i = 0; i < 8; i++ )
- {
- TEST_ASSERT( mbedtls_entropy_func( &ctx, buf, len ) == ret );
- for( j = 0; j < sizeof( buf ); j++ )
+ for (i = 0; i < 8; i++) {
+ TEST_ASSERT(mbedtls_entropy_func(&ctx, buf, len) == ret);
+ for (j = 0; j < sizeof(buf); j++) {
acc[j] |= buf[j];
+ }
}
- if( ret == 0 )
- for( j = 0; j < (size_t) len; j++ )
- TEST_ASSERT( acc[j] != 0 );
+ if (ret == 0) {
+ for (j = 0; j < (size_t) len; j++) {
+ TEST_ASSERT(acc[j] != 0);
+ }
+ }
- for( j = len; j < sizeof( buf ); j++ )
- TEST_ASSERT( acc[j] == 0 );
+ for (j = len; j < sizeof(buf); j++) {
+ TEST_ASSERT(acc[j] == 0);
+ }
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void entropy_source_fail( char * path )
+void entropy_source_fail(char *path)
{
mbedtls_entropy_context ctx;
unsigned char buf[16];
- entropy_dummy_context dummy = {DUMMY_FAIL, 0, 0};
+ entropy_dummy_context dummy = { DUMMY_FAIL, 0, 0 };
- mbedtls_entropy_init( &ctx );
+ mbedtls_entropy_init(&ctx);
- TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
- &dummy, 16,
- MBEDTLS_ENTROPY_SOURCE_WEAK )
- == 0 );
+ TEST_ASSERT(mbedtls_entropy_add_source(&ctx, entropy_dummy_source,
+ &dummy, 16,
+ MBEDTLS_ENTROPY_SOURCE_WEAK)
+ == 0);
- TEST_ASSERT( mbedtls_entropy_func( &ctx, buf, sizeof( buf ) )
- == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
- TEST_ASSERT( mbedtls_entropy_gather( &ctx )
- == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ TEST_ASSERT(mbedtls_entropy_func(&ctx, buf, sizeof(buf))
+ == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED);
+ TEST_ASSERT(mbedtls_entropy_gather(&ctx)
+ == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED);
#if defined(MBEDTLS_FS_IO) && defined(MBEDTLS_ENTROPY_NV_SEED)
- TEST_ASSERT( mbedtls_entropy_write_seed_file( &ctx, path )
- == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
- TEST_ASSERT( mbedtls_entropy_update_seed_file( &ctx, path )
- == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ TEST_ASSERT(mbedtls_entropy_write_seed_file(&ctx, path)
+ == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED);
+ TEST_ASSERT(mbedtls_entropy_update_seed_file(&ctx, path)
+ == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED);
#else
((void) path);
#endif
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void entropy_threshold( int threshold, int chunk_size, int result )
+void entropy_threshold(int threshold, int chunk_size, int result)
{
mbedtls_entropy_context ctx;
entropy_dummy_context strong =
- {DUMMY_CONSTANT_LENGTH, MBEDTLS_ENTROPY_BLOCK_SIZE, 0};
- entropy_dummy_context weak = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
+ { DUMMY_CONSTANT_LENGTH, MBEDTLS_ENTROPY_BLOCK_SIZE, 0 };
+ entropy_dummy_context weak = { DUMMY_CONSTANT_LENGTH, chunk_size, 0 };
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
int ret;
- mbedtls_entropy_init( &ctx );
- entropy_clear_sources( &ctx );
+ mbedtls_entropy_init(&ctx);
+ entropy_clear_sources(&ctx);
/* Set strong source that reaches its threshold immediately and
* a weak source whose threshold is a test parameter. */
- TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
- &strong, 1,
- MBEDTLS_ENTROPY_SOURCE_STRONG ) == 0 );
- TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
- &weak, threshold,
- MBEDTLS_ENTROPY_SOURCE_WEAK ) == 0 );
+ TEST_ASSERT(mbedtls_entropy_add_source(&ctx, entropy_dummy_source,
+ &strong, 1,
+ MBEDTLS_ENTROPY_SOURCE_STRONG) == 0);
+ TEST_ASSERT(mbedtls_entropy_add_source(&ctx, entropy_dummy_source,
+ &weak, threshold,
+ MBEDTLS_ENTROPY_SOURCE_WEAK) == 0);
- ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) );
+ ret = mbedtls_entropy_func(&ctx, buf, sizeof(buf));
- if( result >= 0 )
- {
- TEST_ASSERT( ret == 0 );
+ if (result >= 0) {
+ TEST_ASSERT(ret == 0);
#if defined(MBEDTLS_ENTROPY_NV_SEED)
/* If the NV seed functionality is enabled, there are two entropy
* updates: before and after updating the NV seed. */
result *= 2;
#endif
- TEST_ASSERT( weak.calls == (size_t) result );
- }
- else
- {
- TEST_ASSERT( ret == result );
+ TEST_ASSERT(weak.calls == (size_t) result);
+ } else {
+ TEST_ASSERT(ret == result);
}
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void entropy_calls( int strength1, int strength2,
- int threshold, int chunk_size,
- int result )
+void entropy_calls(int strength1, int strength2,
+ int threshold, int chunk_size,
+ int result)
{
/*
* if result >= 0: result = expected number of calls to source 1
@@ -347,101 +354,98 @@
*/
mbedtls_entropy_context ctx;
- entropy_dummy_context dummy1 = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
- entropy_dummy_context dummy2 = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
+ entropy_dummy_context dummy1 = { DUMMY_CONSTANT_LENGTH, chunk_size, 0 };
+ entropy_dummy_context dummy2 = { DUMMY_CONSTANT_LENGTH, chunk_size, 0 };
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
int ret;
- mbedtls_entropy_init( &ctx );
- entropy_clear_sources( &ctx );
+ mbedtls_entropy_init(&ctx);
+ entropy_clear_sources(&ctx);
- TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
- &dummy1, threshold,
- strength1 ) == 0 );
- TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
- &dummy2, threshold,
- strength2 ) == 0 );
+ TEST_ASSERT(mbedtls_entropy_add_source(&ctx, entropy_dummy_source,
+ &dummy1, threshold,
+ strength1) == 0);
+ TEST_ASSERT(mbedtls_entropy_add_source(&ctx, entropy_dummy_source,
+ &dummy2, threshold,
+ strength2) == 0);
- ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) );
+ ret = mbedtls_entropy_func(&ctx, buf, sizeof(buf));
- if( result >= 0 )
- {
- TEST_ASSERT( ret == 0 );
+ if (result >= 0) {
+ TEST_ASSERT(ret == 0);
#if defined(MBEDTLS_ENTROPY_NV_SEED)
/* If the NV seed functionality is enabled, there are two entropy
* updates: before and after updating the NV seed. */
result *= 2;
#endif
- TEST_ASSERT( dummy1.calls == (size_t) result );
- }
- else
- {
- TEST_ASSERT( ret == result );
+ TEST_ASSERT(dummy1.calls == (size_t) result);
+ } else {
+ TEST_ASSERT(ret == result);
}
exit:
- mbedtls_entropy_free( &ctx );
+ mbedtls_entropy_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
-void nv_seed_file_create( )
+void nv_seed_file_create()
{
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
- memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
+ memset(buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
- TEST_ASSERT( write_nv_seed( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
+ TEST_ASSERT(write_nv_seed(buf, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO:MBEDTLS_PLATFORM_NV_SEED_ALT */
-void entropy_nv_seed_std_io( )
+void entropy_nv_seed_std_io()
{
unsigned char io_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
unsigned char check_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
- memset( io_seed, 1, MBEDTLS_ENTROPY_BLOCK_SIZE );
- memset( check_seed, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
+ memset(io_seed, 1, MBEDTLS_ENTROPY_BLOCK_SIZE);
+ memset(check_seed, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
- mbedtls_platform_set_nv_seed( mbedtls_platform_std_nv_seed_read,
- mbedtls_platform_std_nv_seed_write );
+ mbedtls_platform_set_nv_seed(mbedtls_platform_std_nv_seed_read,
+ mbedtls_platform_std_nv_seed_write);
/* Check if platform NV read and write manipulate the same data */
- TEST_ASSERT( write_nv_seed( io_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
- TEST_ASSERT( mbedtls_nv_seed_read( check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) ==
- MBEDTLS_ENTROPY_BLOCK_SIZE );
+ TEST_ASSERT(write_nv_seed(io_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
+ TEST_ASSERT(mbedtls_nv_seed_read(check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) ==
+ MBEDTLS_ENTROPY_BLOCK_SIZE);
- TEST_ASSERT( memcmp( io_seed, check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
+ TEST_ASSERT(memcmp(io_seed, check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
- memset( check_seed, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
+ memset(check_seed, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
/* Check if platform NV write and raw read manipulate the same data */
- TEST_ASSERT( mbedtls_nv_seed_write( io_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) ==
- MBEDTLS_ENTROPY_BLOCK_SIZE );
- TEST_ASSERT( read_nv_seed( check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
+ TEST_ASSERT(mbedtls_nv_seed_write(io_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) ==
+ MBEDTLS_ENTROPY_BLOCK_SIZE);
+ TEST_ASSERT(read_nv_seed(check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
- TEST_ASSERT( memcmp( io_seed, check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
+ TEST_ASSERT(memcmp(io_seed, check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_MD_C:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_PLATFORM_NV_SEED_ALT */
-void entropy_nv_seed( data_t * read_seed )
+void entropy_nv_seed(data_t *read_seed)
{
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
const mbedtls_md_info_t *md_info =
- mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 );
+ mbedtls_md_info_from_type(MBEDTLS_MD_SHA512);
#elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR)
const mbedtls_md_info_t *md_info =
- mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 );
+ mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
#else
#error "Unsupported entropy accumulator"
#endif
mbedtls_md_context_t accumulator;
mbedtls_entropy_context ctx;
- int (*original_mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ) =
+ int (*original_mbedtls_nv_seed_read)(unsigned char *buf, size_t buf_len) =
mbedtls_nv_seed_read;
- int (*original_mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ) =
+ int (*original_mbedtls_nv_seed_write)(unsigned char *buf, size_t buf_len) =
mbedtls_nv_seed_write;
unsigned char header[2];
@@ -451,80 +455,80 @@
unsigned char check_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
unsigned char check_entropy[MBEDTLS_ENTROPY_BLOCK_SIZE];
- memset( entropy, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
- memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
- memset( empty, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
- memset( check_seed, 2, MBEDTLS_ENTROPY_BLOCK_SIZE );
- memset( check_entropy, 3, MBEDTLS_ENTROPY_BLOCK_SIZE );
+ memset(entropy, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
+ memset(buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
+ memset(empty, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
+ memset(check_seed, 2, MBEDTLS_ENTROPY_BLOCK_SIZE);
+ memset(check_entropy, 3, MBEDTLS_ENTROPY_BLOCK_SIZE);
// Make sure we read/write NV seed from our buffers
- mbedtls_platform_set_nv_seed( buffer_nv_seed_read, buffer_nv_seed_write );
+ mbedtls_platform_set_nv_seed(buffer_nv_seed_read, buffer_nv_seed_write);
- mbedtls_md_init( &accumulator );
- mbedtls_entropy_init( &ctx );
- entropy_clear_sources( &ctx );
+ mbedtls_md_init(&accumulator);
+ mbedtls_entropy_init(&ctx);
+ entropy_clear_sources(&ctx);
- TEST_ASSERT( mbedtls_entropy_add_source( &ctx, mbedtls_nv_seed_poll, NULL,
- MBEDTLS_ENTROPY_BLOCK_SIZE,
- MBEDTLS_ENTROPY_SOURCE_STRONG ) == 0 );
+ TEST_ASSERT(mbedtls_entropy_add_source(&ctx, mbedtls_nv_seed_poll, NULL,
+ MBEDTLS_ENTROPY_BLOCK_SIZE,
+ MBEDTLS_ENTROPY_SOURCE_STRONG) == 0);
// Set the initial NV seed to read
- TEST_ASSERT( read_seed->len >= MBEDTLS_ENTROPY_BLOCK_SIZE );
- memcpy( buffer_seed, read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE );
+ TEST_ASSERT(read_seed->len >= MBEDTLS_ENTROPY_BLOCK_SIZE);
+ memcpy(buffer_seed, read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE);
// Do an entropy run
- TEST_ASSERT( mbedtls_entropy_func( &ctx, entropy, sizeof( entropy ) ) == 0 );
+ TEST_ASSERT(mbedtls_entropy_func(&ctx, entropy, sizeof(entropy)) == 0);
// Determine what should have happened with manual entropy internal logic
// Init accumulator
header[1] = MBEDTLS_ENTROPY_BLOCK_SIZE;
- TEST_ASSERT( mbedtls_md_setup( &accumulator, md_info, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_md_setup(&accumulator, md_info, 0) == 0);
// First run for updating write_seed
header[0] = 0;
- TEST_ASSERT( mbedtls_md_starts( &accumulator ) == 0 );
- TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
- TEST_ASSERT( mbedtls_md_update( &accumulator,
- read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
- TEST_ASSERT( mbedtls_md_finish( &accumulator, buf ) == 0 );
+ TEST_ASSERT(mbedtls_md_starts(&accumulator) == 0);
+ TEST_ASSERT(mbedtls_md_update(&accumulator, header, 2) == 0);
+ TEST_ASSERT(mbedtls_md_update(&accumulator,
+ read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
+ TEST_ASSERT(mbedtls_md_finish(&accumulator, buf) == 0);
- TEST_ASSERT( mbedtls_md_starts( &accumulator ) == 0 );
- TEST_ASSERT( mbedtls_md_update( &accumulator,
- buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
+ TEST_ASSERT(mbedtls_md_starts(&accumulator) == 0);
+ TEST_ASSERT(mbedtls_md_update(&accumulator,
+ buf, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
- TEST_ASSERT( mbedtls_md( md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
- check_seed ) == 0 );
+ TEST_ASSERT(mbedtls_md(md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
+ check_seed) == 0);
// Second run for actual entropy (triggers mbedtls_entropy_update_nv_seed)
header[0] = MBEDTLS_ENTROPY_SOURCE_MANUAL;
- TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
- TEST_ASSERT( mbedtls_md_update( &accumulator,
- empty, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
+ TEST_ASSERT(mbedtls_md_update(&accumulator, header, 2) == 0);
+ TEST_ASSERT(mbedtls_md_update(&accumulator,
+ empty, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
header[0] = 0;
- TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
- TEST_ASSERT( mbedtls_md_update( &accumulator,
- check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
- TEST_ASSERT( mbedtls_md_finish( &accumulator, buf ) == 0 );
+ TEST_ASSERT(mbedtls_md_update(&accumulator, header, 2) == 0);
+ TEST_ASSERT(mbedtls_md_update(&accumulator,
+ check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
+ TEST_ASSERT(mbedtls_md_finish(&accumulator, buf) == 0);
- TEST_ASSERT( mbedtls_md( md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
- check_entropy ) == 0 );
+ TEST_ASSERT(mbedtls_md(md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
+ check_entropy) == 0);
// Check result of both NV file and entropy received with the manual calculations
- TEST_ASSERT( memcmp( check_seed, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
- TEST_ASSERT( memcmp( check_entropy, entropy, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
+ TEST_ASSERT(memcmp(check_seed, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
+ TEST_ASSERT(memcmp(check_entropy, entropy, MBEDTLS_ENTROPY_BLOCK_SIZE) == 0);
exit:
- mbedtls_md_free( &accumulator );
- mbedtls_entropy_free( &ctx );
+ mbedtls_md_free(&accumulator);
+ mbedtls_entropy_free(&ctx);
mbedtls_nv_seed_read = original_mbedtls_nv_seed_read;
mbedtls_nv_seed_write = original_mbedtls_nv_seed_write;
}
/* END_CASE */
/* BEGIN_CASE depends_on:ENTROPY_HAVE_STRONG:MBEDTLS_SELF_TEST */
-void entropy_selftest( int result )
+void entropy_selftest(int result)
{
- TEST_ASSERT( mbedtls_entropy_self_test( 1 ) == result );
+ TEST_ASSERT(mbedtls_entropy_self_test(1) == result);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_error.function b/tests/suites/test_suite_error.function
index 68831ce..4c38ab0 100644
--- a/tests/suites/test_suite_error.function
+++ b/tests/suites/test_suite_error.function
@@ -8,14 +8,14 @@
*/
/* BEGIN_CASE */
-void error_strerror( int code, char * result_str )
+void error_strerror(int code, char *result_str)
{
char buf[500];
- memset( buf, 0, sizeof( buf ) );
+ memset(buf, 0, sizeof(buf));
- mbedtls_strerror( code, buf, 500 );
+ mbedtls_strerror(code, buf, 500);
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_gcm.function b/tests/suites/test_suite_gcm.function
index eb2ced3..fd68abf 100644
--- a/tests/suites/test_suite_gcm.function
+++ b/tests/suites/test_suite_gcm.function
@@ -4,15 +4,15 @@
/* Use the multipart interface to process the encrypted data in two parts
* and check that the output matches the expected output.
* The context must have been set up with the key. */
-static int check_multipart( mbedtls_gcm_context *ctx,
- int mode,
- const data_t *iv,
- const data_t *add,
- const data_t *input,
- const data_t *expected_output,
- const data_t *tag,
- size_t n1,
- size_t n1_add)
+static int check_multipart(mbedtls_gcm_context *ctx,
+ int mode,
+ const data_t *iv,
+ const data_t *add,
+ const data_t *input,
+ const data_t *expected_output,
+ const data_t *tag,
+ size_t n1,
+ size_t n1_add)
{
int ok = 0;
uint8_t *output = NULL;
@@ -21,91 +21,90 @@
size_t olen;
/* Sanity checks on the test data */
- TEST_ASSERT( n1 <= input->len );
- TEST_ASSERT( n1_add <= add->len );
- TEST_EQUAL( input->len, expected_output->len );
+ TEST_ASSERT(n1 <= input->len);
+ TEST_ASSERT(n1_add <= add->len);
+ TEST_EQUAL(input->len, expected_output->len);
- TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode,
- iv->x, iv->len ) );
- TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x, n1_add ) );
- TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x + n1_add, n2_add ) );
+ TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode,
+ iv->x, iv->len));
+ TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, add->x, n1_add));
+ TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, add->x + n1_add, n2_add));
/* Allocate a tight buffer for each update call. This way, if the function
* tries to write beyond the advertised required buffer size, this will
* count as an overflow for memory sanitizers and static checkers. */
- ASSERT_ALLOC( output, n1 );
+ ASSERT_ALLOC(output, n1);
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_gcm_update( ctx, input->x, n1, output, n1, &olen ) );
- TEST_EQUAL( n1, olen );
- ASSERT_COMPARE( output, olen, expected_output->x, n1 );
- mbedtls_free( output );
+ TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, n1, output, n1, &olen));
+ TEST_EQUAL(n1, olen);
+ ASSERT_COMPARE(output, olen, expected_output->x, n1);
+ mbedtls_free(output);
output = NULL;
- ASSERT_ALLOC( output, n2 );
+ ASSERT_ALLOC(output, n2);
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_gcm_update( ctx, input->x + n1, n2, output, n2, &olen ) );
- TEST_EQUAL( n2, olen );
- ASSERT_COMPARE( output, olen, expected_output->x + n1, n2 );
- mbedtls_free( output );
+ TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x + n1, n2, output, n2, &olen));
+ TEST_EQUAL(n2, olen);
+ ASSERT_COMPARE(output, olen, expected_output->x + n1, n2);
+ mbedtls_free(output);
output = NULL;
- ASSERT_ALLOC( output, tag->len );
- TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, &olen, output, tag->len ) );
- TEST_EQUAL( 0, olen );
- ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
- mbedtls_free( output );
+ ASSERT_ALLOC(output, tag->len);
+ TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
+ TEST_EQUAL(0, olen);
+ ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
+ mbedtls_free(output);
output = NULL;
ok = 1;
exit:
- mbedtls_free( output );
- return( ok );
+ mbedtls_free(output);
+ return ok;
}
-static void check_cipher_with_empty_ad( mbedtls_gcm_context *ctx,
- int mode,
- const data_t *iv,
- const data_t *input,
- const data_t *expected_output,
- const data_t *tag,
- size_t ad_update_count)
+static void check_cipher_with_empty_ad(mbedtls_gcm_context *ctx,
+ int mode,
+ const data_t *iv,
+ const data_t *input,
+ const data_t *expected_output,
+ const data_t *tag,
+ size_t ad_update_count)
{
size_t n;
uint8_t *output = NULL;
size_t olen;
/* Sanity checks on the test data */
- TEST_EQUAL( input->len, expected_output->len );
+ TEST_EQUAL(input->len, expected_output->len);
- TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode,
- iv->x, iv->len ) );
+ TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode,
+ iv->x, iv->len));
- for( n = 0; n < ad_update_count; n++ )
- {
- TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, NULL, 0 ) );
+ for (n = 0; n < ad_update_count; n++) {
+ TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, NULL, 0));
}
/* Allocate a tight buffer for each update call. This way, if the function
* tries to write beyond the advertised required buffer size, this will
* count as an overflow for memory sanitizers and static checkers. */
- ASSERT_ALLOC( output, input->len );
+ ASSERT_ALLOC(output, input->len);
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_gcm_update( ctx, input->x, input->len, output, input->len, &olen ) );
- TEST_EQUAL( input->len, olen );
- ASSERT_COMPARE( output, olen, expected_output->x, input->len );
- mbedtls_free( output );
+ TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, input->len, output, input->len, &olen));
+ TEST_EQUAL(input->len, olen);
+ ASSERT_COMPARE(output, olen, expected_output->x, input->len);
+ mbedtls_free(output);
output = NULL;
- ASSERT_ALLOC( output, tag->len );
- TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, &olen, output, tag->len ) );
- TEST_EQUAL( 0, olen );
- ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
+ ASSERT_ALLOC(output, tag->len);
+ TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
+ TEST_EQUAL(0, olen);
+ ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
exit:
- mbedtls_free( output );
+ mbedtls_free(output);
}
-static void check_empty_cipher_with_ad( mbedtls_gcm_context *ctx,
+static void check_empty_cipher_with_ad(mbedtls_gcm_context *ctx,
int mode,
const data_t *iv,
const data_t *add,
@@ -114,45 +113,44 @@
{
size_t olen;
size_t n;
- uint8_t* output_tag = NULL;
+ uint8_t *output_tag = NULL;
- TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode, iv->x, iv->len ) );
- TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x, add->len ) );
+ TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode, iv->x, iv->len));
+ TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, add->x, add->len));
- for( n = 0; n < cipher_update_count; n++ )
- {
+ for (n = 0; n < cipher_update_count; n++) {
olen = 0xdeadbeef;
- TEST_EQUAL( 0, mbedtls_gcm_update( ctx, NULL, 0, NULL, 0, &olen ) );
- TEST_EQUAL( 0, olen );
+ TEST_EQUAL(0, mbedtls_gcm_update(ctx, NULL, 0, NULL, 0, &olen));
+ TEST_EQUAL(0, olen);
}
- ASSERT_ALLOC( output_tag, tag->len );
- TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, &olen,
- output_tag, tag->len ) );
- TEST_EQUAL( 0, olen );
- ASSERT_COMPARE( output_tag, tag->len, tag->x, tag->len );
+ ASSERT_ALLOC(output_tag, tag->len);
+ TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen,
+ output_tag, tag->len));
+ TEST_EQUAL(0, olen);
+ ASSERT_COMPARE(output_tag, tag->len, tag->x, tag->len);
exit:
- mbedtls_free( output_tag );
+ mbedtls_free(output_tag);
}
-static void check_no_cipher_no_ad( mbedtls_gcm_context *ctx,
- int mode,
- const data_t *iv,
- const data_t *tag )
+static void check_no_cipher_no_ad(mbedtls_gcm_context *ctx,
+ int mode,
+ const data_t *iv,
+ const data_t *tag)
{
uint8_t *output = NULL;
size_t olen = 0;
- TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode,
- iv->x, iv->len ) );
- ASSERT_ALLOC( output, tag->len );
- TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, &olen, output, tag->len ) );
- TEST_EQUAL( 0, olen );
- ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
+ TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode,
+ iv->x, iv->len));
+ ASSERT_ALLOC(output, tag->len);
+ TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
+ TEST_EQUAL(0, olen);
+ ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
exit:
- mbedtls_free( output );
+ mbedtls_free(output);
}
/* END_HEADER */
@@ -163,36 +161,37 @@
*/
/* BEGIN_CASE */
-void gcm_bad_parameters( int cipher_id, int direction,
- data_t *key_str, data_t *src_str,
- data_t *iv_str, data_t *add_str,
- int tag_len_bits, int gcm_result )
+void gcm_bad_parameters(int cipher_id, int direction,
+ data_t *key_str, data_t *src_str,
+ data_t *iv_str, data_t *add_str,
+ int tag_len_bits, int gcm_result)
{
unsigned char output[128];
unsigned char tag_output[16];
mbedtls_gcm_context ctx;
size_t tag_len = tag_len_bits / 8;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
- memset( output, 0x00, sizeof( output ) );
- memset( tag_output, 0x00, sizeof( tag_output ) );
+ memset(output, 0x00, sizeof(output));
+ memset(tag_output, 0x00, sizeof(tag_output));
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
- TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, direction, src_str->len, iv_str->x, iv_str->len,
- add_str->x, add_str->len, src_str->x, output, tag_len, tag_output ) == gcm_result );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
+ TEST_ASSERT(mbedtls_gcm_crypt_and_tag(&ctx, direction, src_str->len, iv_str->x, iv_str->len,
+ add_str->x, add_str->len, src_str->x, output, tag_len,
+ tag_output) == gcm_result);
exit:
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_encrypt_and_tag( int cipher_id, data_t * key_str,
- data_t * src_str, data_t * iv_str,
- data_t * add_str, data_t * dst,
- int tag_len_bits, data_t * tag,
- int init_result )
+void gcm_encrypt_and_tag(int cipher_id, data_t *key_str,
+ data_t *src_str, data_t *iv_str,
+ data_t *add_str, data_t *dst,
+ int tag_len_bits, data_t *tag,
+ int init_result)
{
unsigned char output[128];
unsigned char tag_output[16];
@@ -201,45 +200,45 @@
size_t n1;
size_t n1_add;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
memset(output, 0x00, 128);
memset(tag_output, 0x00, 16);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result );
- if( init_result == 0 )
- {
- TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, src_str->len, iv_str->x, iv_str->len, add_str->x, add_str->len, src_str->x, output, tag_len, tag_output ) == 0 );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == init_result);
+ if (init_result == 0) {
+ TEST_ASSERT(mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_ENCRYPT, src_str->len, iv_str->x,
+ iv_str->len, add_str->x, add_str->len, src_str->x,
+ output, tag_len, tag_output) == 0);
- ASSERT_COMPARE( output, src_str->len, dst->x, dst->len );
- ASSERT_COMPARE( tag_output, tag_len, tag->x, tag->len );
+ ASSERT_COMPARE(output, src_str->len, dst->x, dst->len);
+ ASSERT_COMPARE(tag_output, tag_len, tag->x, tag->len);
- for( n1 = 0; n1 <= src_str->len; n1 += 1 )
- {
- for( n1_add = 0; n1_add <= add_str->len; n1_add += 1 )
- {
- mbedtls_test_set_step( n1 * 10000 + n1_add );
- if( !check_multipart( &ctx, MBEDTLS_GCM_ENCRYPT,
- iv_str, add_str, src_str,
- dst, tag,
- n1, n1_add ) )
+ for (n1 = 0; n1 <= src_str->len; n1 += 1) {
+ for (n1_add = 0; n1_add <= add_str->len; n1_add += 1) {
+ mbedtls_test_set_step(n1 * 10000 + n1_add);
+ if (!check_multipart(&ctx, MBEDTLS_GCM_ENCRYPT,
+ iv_str, add_str, src_str,
+ dst, tag,
+ n1, n1_add)) {
goto exit;
+ }
}
}
}
exit:
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_decrypt_and_verify( int cipher_id, data_t * key_str,
- data_t * src_str, data_t * iv_str,
- data_t * add_str, int tag_len_bits,
- data_t * tag_str, char * result,
- data_t * pt_result, int init_result )
+void gcm_decrypt_and_verify(int cipher_id, data_t *key_str,
+ data_t *src_str, data_t *iv_str,
+ data_t *add_str, int tag_len_bits,
+ data_t *tag_str, char *result,
+ data_t *pt_result, int init_result)
{
unsigned char output[128];
mbedtls_gcm_context ctx;
@@ -248,215 +247,220 @@
size_t n1;
size_t n1_add;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
memset(output, 0x00, 128);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result );
- if( init_result == 0 )
- {
- ret = mbedtls_gcm_auth_decrypt( &ctx, src_str->len, iv_str->x, iv_str->len, add_str->x, add_str->len, tag_str->x, tag_len, src_str->x, output );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == init_result);
+ if (init_result == 0) {
+ ret = mbedtls_gcm_auth_decrypt(&ctx,
+ src_str->len,
+ iv_str->x,
+ iv_str->len,
+ add_str->x,
+ add_str->len,
+ tag_str->x,
+ tag_len,
+ src_str->x,
+ output);
- if( strcmp( "FAIL", result ) == 0 )
- {
- TEST_ASSERT( ret == MBEDTLS_ERR_GCM_AUTH_FAILED );
- }
- else
- {
- TEST_ASSERT( ret == 0 );
- ASSERT_COMPARE( output, src_str->len, pt_result->x, pt_result->len );
+ if (strcmp("FAIL", result) == 0) {
+ TEST_ASSERT(ret == MBEDTLS_ERR_GCM_AUTH_FAILED);
+ } else {
+ TEST_ASSERT(ret == 0);
+ ASSERT_COMPARE(output, src_str->len, pt_result->x, pt_result->len);
- for( n1 = 0; n1 <= src_str->len; n1 += 1 )
- {
- for( n1_add = 0; n1_add <= add_str->len; n1_add += 1 )
- {
- mbedtls_test_set_step( n1 * 10000 + n1_add );
- if( !check_multipart( &ctx, MBEDTLS_GCM_DECRYPT,
- iv_str, add_str, src_str,
- pt_result, tag_str,
- n1, n1_add ) )
+ for (n1 = 0; n1 <= src_str->len; n1 += 1) {
+ for (n1_add = 0; n1_add <= add_str->len; n1_add += 1) {
+ mbedtls_test_set_step(n1 * 10000 + n1_add);
+ if (!check_multipart(&ctx, MBEDTLS_GCM_DECRYPT,
+ iv_str, add_str, src_str,
+ pt_result, tag_str,
+ n1, n1_add)) {
goto exit;
+ }
}
}
}
}
exit:
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_decrypt_and_verify_empty_cipher( int cipher_id,
- data_t * key_str,
- data_t * iv_str,
- data_t * add_str,
- data_t * tag_str,
- int cipher_update_calls )
+void gcm_decrypt_and_verify_empty_cipher(int cipher_id,
+ data_t *key_str,
+ data_t *iv_str,
+ data_t *add_str,
+ data_t *tag_str,
+ int cipher_update_calls)
{
mbedtls_gcm_context ctx;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
- check_empty_cipher_with_ad( &ctx, MBEDTLS_GCM_DECRYPT,
- iv_str, add_str, tag_str,
- cipher_update_calls );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
+ check_empty_cipher_with_ad(&ctx, MBEDTLS_GCM_DECRYPT,
+ iv_str, add_str, tag_str,
+ cipher_update_calls);
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_decrypt_and_verify_empty_ad( int cipher_id,
- data_t * key_str,
- data_t * iv_str,
- data_t * src_str,
- data_t * tag_str,
- data_t * pt_result,
- int ad_update_calls )
+void gcm_decrypt_and_verify_empty_ad(int cipher_id,
+ data_t *key_str,
+ data_t *iv_str,
+ data_t *src_str,
+ data_t *tag_str,
+ data_t *pt_result,
+ int ad_update_calls)
{
mbedtls_gcm_context ctx;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
- check_cipher_with_empty_ad( &ctx, MBEDTLS_GCM_DECRYPT,
- iv_str, src_str, pt_result, tag_str,
- ad_update_calls );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
+ check_cipher_with_empty_ad(&ctx, MBEDTLS_GCM_DECRYPT,
+ iv_str, src_str, pt_result, tag_str,
+ ad_update_calls);
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_decrypt_and_verify_no_ad_no_cipher( int cipher_id,
- data_t * key_str,
- data_t * iv_str,
- data_t * tag_str )
+void gcm_decrypt_and_verify_no_ad_no_cipher(int cipher_id,
+ data_t *key_str,
+ data_t *iv_str,
+ data_t *tag_str)
{
mbedtls_gcm_context ctx;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
- check_no_cipher_no_ad( &ctx, MBEDTLS_GCM_DECRYPT,
- iv_str, tag_str );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
+ check_no_cipher_no_ad(&ctx, MBEDTLS_GCM_DECRYPT,
+ iv_str, tag_str);
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_encrypt_and_tag_empty_cipher( int cipher_id,
- data_t * key_str,
- data_t * iv_str,
- data_t * add_str,
- data_t * tag_str,
- int cipher_update_calls )
+void gcm_encrypt_and_tag_empty_cipher(int cipher_id,
+ data_t *key_str,
+ data_t *iv_str,
+ data_t *add_str,
+ data_t *tag_str,
+ int cipher_update_calls)
{
mbedtls_gcm_context ctx;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
- check_empty_cipher_with_ad( &ctx, MBEDTLS_GCM_ENCRYPT,
- iv_str, add_str, tag_str,
- cipher_update_calls );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
+ check_empty_cipher_with_ad(&ctx, MBEDTLS_GCM_ENCRYPT,
+ iv_str, add_str, tag_str,
+ cipher_update_calls);
exit:
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_encrypt_and_tag_empty_ad( int cipher_id,
- data_t * key_str,
- data_t * iv_str,
- data_t * src_str,
- data_t * dst,
- data_t * tag_str,
- int ad_update_calls )
+void gcm_encrypt_and_tag_empty_ad(int cipher_id,
+ data_t *key_str,
+ data_t *iv_str,
+ data_t *src_str,
+ data_t *dst,
+ data_t *tag_str,
+ int ad_update_calls)
{
mbedtls_gcm_context ctx;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
- check_cipher_with_empty_ad( &ctx, MBEDTLS_GCM_ENCRYPT,
- iv_str, src_str, dst, tag_str,
- ad_update_calls );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
+ check_cipher_with_empty_ad(&ctx, MBEDTLS_GCM_ENCRYPT,
+ iv_str, src_str, dst, tag_str,
+ ad_update_calls);
exit:
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_encrypt_and_verify_no_ad_no_cipher( int cipher_id,
- data_t * key_str,
- data_t * iv_str,
- data_t * tag_str )
+void gcm_encrypt_and_verify_no_ad_no_cipher(int cipher_id,
+ data_t *key_str,
+ data_t *iv_str,
+ data_t *tag_str)
{
mbedtls_gcm_context ctx;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
- TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
- check_no_cipher_no_ad( &ctx, MBEDTLS_GCM_ENCRYPT,
- iv_str, tag_str );
+ TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
+ check_no_cipher_no_ad(&ctx, MBEDTLS_GCM_ENCRYPT,
+ iv_str, tag_str);
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_invalid_param( )
+void gcm_invalid_param()
{
mbedtls_gcm_context ctx;
unsigned char valid_buffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
mbedtls_cipher_id_t valid_cipher = MBEDTLS_CIPHER_ID_AES;
int invalid_bitlen = 1;
- mbedtls_gcm_init( &ctx );
+ mbedtls_gcm_init(&ctx);
/* mbedtls_gcm_setkey */
TEST_EQUAL(
MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_setkey( &ctx, valid_cipher, valid_buffer, invalid_bitlen ) );
+ mbedtls_gcm_setkey(&ctx, valid_cipher, valid_buffer, invalid_bitlen));
exit:
- mbedtls_gcm_free( &ctx );
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void gcm_update_output_buffer_too_small( int cipher_id, int mode,
- data_t * key_str, const data_t *input,
- const data_t *iv )
+void gcm_update_output_buffer_too_small(int cipher_id, int mode,
+ data_t *key_str, const data_t *input,
+ const data_t *iv)
{
mbedtls_gcm_context ctx;
uint8_t *output = NULL;
size_t olen = 0;
size_t output_len = input->len - 1;
- mbedtls_gcm_init( &ctx );
- TEST_EQUAL( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ), 0 );
- TEST_EQUAL( 0, mbedtls_gcm_starts( &ctx, mode, iv->x, iv->len ) );
+ mbedtls_gcm_init(&ctx);
+ TEST_EQUAL(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8), 0);
+ TEST_EQUAL(0, mbedtls_gcm_starts(&ctx, mode, iv->x, iv->len));
- ASSERT_ALLOC( output, output_len );
- TEST_EQUAL( MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL, mbedtls_gcm_update( &ctx, input->x, input->len, output, output_len, &olen ) );
+ ASSERT_ALLOC(output, output_len);
+ TEST_EQUAL(MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL,
+ mbedtls_gcm_update(&ctx, input->x, input->len, output, output_len, &olen));
exit:
- mbedtls_free( output );
- mbedtls_gcm_free( &ctx );
+ mbedtls_free(output);
+ mbedtls_gcm_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
-void gcm_selftest( )
+void gcm_selftest()
{
- TEST_ASSERT( mbedtls_gcm_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_gcm_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_hkdf.function b/tests/suites/test_suite_hkdf.function
index 1ad6f3d..21e4439 100644
--- a/tests/suites/test_suite_hkdf.function
+++ b/tests/suites/test_suite_hkdf.function
@@ -9,47 +9,47 @@
*/
/* BEGIN_CASE */
-void test_hkdf( int md_alg, data_t *ikm, data_t *salt, data_t *info,
- data_t *expected_okm )
+void test_hkdf(int md_alg, data_t *ikm, data_t *salt, data_t *info,
+ data_t *expected_okm)
{
int ret;
unsigned char okm[128] = { '\0' };
- const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md != NULL );
+ const mbedtls_md_info_t *md = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md != NULL);
- TEST_ASSERT( expected_okm->len <= sizeof( okm ) );
+ TEST_ASSERT(expected_okm->len <= sizeof(okm));
- ret = mbedtls_hkdf( md, salt->x, salt->len, ikm->x, ikm->len,
- info->x, info->len, okm, expected_okm->len );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_hkdf(md, salt->x, salt->len, ikm->x, ikm->len,
+ info->x, info->len, okm, expected_okm->len);
+ TEST_ASSERT(ret == 0);
- ASSERT_COMPARE( okm , expected_okm->len,
- expected_okm->x, expected_okm->len );
+ ASSERT_COMPARE(okm, expected_okm->len,
+ expected_okm->x, expected_okm->len);
}
/* END_CASE */
/* BEGIN_CASE */
-void test_hkdf_extract( int md_alg,
- data_t *ikm,
- data_t *salt,
- data_t *prk )
+void test_hkdf_extract(int md_alg,
+ data_t *ikm,
+ data_t *salt,
+ data_t *prk)
{
int ret;
unsigned char *output_prk = NULL;
size_t output_prk_len;
- const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md != NULL );
+ const mbedtls_md_info_t *md = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md != NULL);
- output_prk_len = mbedtls_md_get_size( md );
- ASSERT_ALLOC( output_prk, output_prk_len );
+ output_prk_len = mbedtls_md_get_size(md);
+ ASSERT_ALLOC(output_prk, output_prk_len);
- ret = mbedtls_hkdf_extract( md, salt->x, salt->len,
- ikm->x, ikm->len, output_prk );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_hkdf_extract(md, salt->x, salt->len,
+ ikm->x, ikm->len, output_prk);
+ TEST_ASSERT(ret == 0);
- ASSERT_COMPARE( output_prk, output_prk_len, prk->x, prk->len );
+ ASSERT_COMPARE(output_prk, output_prk_len, prk->x, prk->len);
exit:
mbedtls_free(output_prk);
@@ -57,28 +57,28 @@
/* END_CASE */
/* BEGIN_CASE */
-void test_hkdf_expand( int md_alg,
- data_t *info,
- data_t *prk,
- data_t *okm )
+void test_hkdf_expand(int md_alg,
+ data_t *info,
+ data_t *prk,
+ data_t *okm)
{
enum { OKM_LEN = 1024 };
int ret;
unsigned char *output_okm = NULL;
- const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md != NULL );
+ const mbedtls_md_info_t *md = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md != NULL);
- ASSERT_ALLOC( output_okm, OKM_LEN );
+ ASSERT_ALLOC(output_okm, OKM_LEN);
- TEST_ASSERT( prk->len == mbedtls_md_get_size( md ) );
- TEST_ASSERT( okm->len < OKM_LEN );
+ TEST_ASSERT(prk->len == mbedtls_md_get_size(md));
+ TEST_ASSERT(okm->len < OKM_LEN);
- ret = mbedtls_hkdf_expand( md, prk->x, prk->len,
- info->x, info->len,
- output_okm, OKM_LEN );
- TEST_ASSERT( ret == 0 );
- ASSERT_COMPARE( output_okm, okm->len, okm->x, okm->len );
+ ret = mbedtls_hkdf_expand(md, prk->x, prk->len,
+ info->x, info->len,
+ output_okm, OKM_LEN);
+ TEST_ASSERT(ret == 0);
+ ASSERT_COMPARE(output_okm, okm->len, okm->x, okm->len);
exit:
mbedtls_free(output_okm);
@@ -86,7 +86,7 @@
/* END_CASE */
/* BEGIN_CASE */
-void test_hkdf_extract_ret( int hash_len, int ret )
+void test_hkdf_extract_ret(int hash_len, int ret)
{
int output_ret;
unsigned char *salt = NULL;
@@ -95,17 +95,17 @@
size_t salt_len, ikm_len;
struct mbedtls_md_info_t fake_md_info;
- memset( &fake_md_info, 0, sizeof( fake_md_info ) );
+ memset(&fake_md_info, 0, sizeof(fake_md_info));
fake_md_info.type = MBEDTLS_MD_NONE;
fake_md_info.size = hash_len;
- ASSERT_ALLOC( prk, MBEDTLS_MD_MAX_SIZE);
+ ASSERT_ALLOC(prk, MBEDTLS_MD_MAX_SIZE);
salt_len = 0;
ikm_len = 0;
- output_ret = mbedtls_hkdf_extract( &fake_md_info, salt, salt_len,
- ikm, ikm_len, prk );
- TEST_ASSERT( output_ret == ret );
+ output_ret = mbedtls_hkdf_extract(&fake_md_info, salt, salt_len,
+ ikm, ikm_len, prk);
+ TEST_ASSERT(output_ret == ret);
exit:
mbedtls_free(prk);
@@ -113,7 +113,7 @@
/* END_CASE */
/* BEGIN_CASE */
-void test_hkdf_expand_ret( int hash_len, int prk_len, int okm_len, int ret )
+void test_hkdf_expand_ret(int hash_len, int prk_len, int okm_len, int ret)
{
int output_ret;
unsigned char *info = NULL;
@@ -122,21 +122,23 @@
size_t info_len;
struct mbedtls_md_info_t fake_md_info;
- memset( &fake_md_info, 0, sizeof( fake_md_info ) );
+ memset(&fake_md_info, 0, sizeof(fake_md_info));
fake_md_info.type = MBEDTLS_MD_NONE;
fake_md_info.size = hash_len;
info_len = 0;
- if (prk_len > 0)
- ASSERT_ALLOC( prk, prk_len );
+ if (prk_len > 0) {
+ ASSERT_ALLOC(prk, prk_len);
+ }
- if (okm_len > 0)
- ASSERT_ALLOC( okm, okm_len );
+ if (okm_len > 0) {
+ ASSERT_ALLOC(okm, okm_len);
+ }
- output_ret = mbedtls_hkdf_expand( &fake_md_info, prk, prk_len,
- info, info_len, okm, okm_len );
- TEST_ASSERT( output_ret == ret );
+ output_ret = mbedtls_hkdf_expand(&fake_md_info, prk, prk_len,
+ info, info_len, okm, okm_len);
+ TEST_ASSERT(output_ret == ret);
exit:
mbedtls_free(prk);
diff --git a/tests/suites/test_suite_hmac_drbg.function b/tests/suites/test_suite_hmac_drbg.function
index b83d760..830155a 100644
--- a/tests/suites/test_suite_hmac_drbg.function
+++ b/tests/suites/test_suite_hmac_drbg.function
@@ -2,25 +2,25 @@
#include "mbedtls/hmac_drbg.h"
#include "string.h"
-typedef struct
-{
+typedef struct {
unsigned char *p;
size_t len;
} entropy_ctx;
-static int mbedtls_test_entropy_func( void *data, unsigned char *buf, size_t len )
+static int mbedtls_test_entropy_func(void *data, unsigned char *buf, size_t len)
{
entropy_ctx *ctx = (entropy_ctx *) data;
- if( len > ctx->len )
- return( -1 );
+ if (len > ctx->len) {
+ return -1;
+ }
- memcpy( buf, ctx->p, len );
+ memcpy(buf, ctx->p, len);
ctx->p += len;
ctx->len -= len;
- return( 0 );
+ return 0;
}
/* END_HEADER */
@@ -30,7 +30,7 @@
*/
/* BEGIN_CASE */
-void hmac_drbg_entropy_usage( int md_alg )
+void hmac_drbg_entropy_usage(int md_alg)
{
unsigned char out[16];
unsigned char buf[1024];
@@ -41,112 +41,111 @@
size_t default_entropy_len;
size_t expected_consumed_entropy = 0;
- mbedtls_hmac_drbg_init( &ctx );
- memset( buf, 0, sizeof( buf ) );
- memset( out, 0, sizeof( out ) );
+ mbedtls_hmac_drbg_init(&ctx);
+ memset(buf, 0, sizeof(buf));
+ memset(out, 0, sizeof(out));
- entropy.len = sizeof( buf );
+ entropy.len = sizeof(buf);
entropy.p = buf;
- md_info = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md_info != NULL );
- if( mbedtls_md_get_size( md_info ) <= 20 )
+ md_info = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md_info != NULL);
+ if (mbedtls_md_get_size(md_info) <= 20) {
default_entropy_len = 16;
- else if( mbedtls_md_get_size( md_info ) <= 28 )
+ } else if (mbedtls_md_get_size(md_info) <= 28) {
default_entropy_len = 24;
- else
+ } else {
default_entropy_len = 32;
+ }
/* Set reseed interval before seed */
- mbedtls_hmac_drbg_set_reseed_interval( &ctx, 2 * reps );
+ mbedtls_hmac_drbg_set_reseed_interval(&ctx, 2 * reps);
/* Init must use entropy */
- TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &entropy,
- NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_hmac_drbg_seed(&ctx, md_info, mbedtls_test_entropy_func, &entropy,
+ NULL, 0) == 0);
/* default_entropy_len of entropy, plus half as much for the nonce */
expected_consumed_entropy += default_entropy_len * 3 / 2;
- TEST_EQUAL( sizeof( buf ) - entropy.len, expected_consumed_entropy );
+ TEST_EQUAL(sizeof(buf) - entropy.len, expected_consumed_entropy);
/* By default, PR is off, and reseed interval was set to
* 2 * reps so the next few calls should not use entropy */
- for( i = 0; i < reps; i++ )
- {
- TEST_ASSERT( mbedtls_hmac_drbg_random( &ctx, out, sizeof( out ) - 4 ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, out, sizeof( out ) - 4,
- buf, 16 ) == 0 );
+ for (i = 0; i < reps; i++) {
+ TEST_ASSERT(mbedtls_hmac_drbg_random(&ctx, out, sizeof(out) - 4) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, out, sizeof(out) - 4,
+ buf, 16) == 0);
}
- TEST_EQUAL( sizeof( buf ) - entropy.len, expected_consumed_entropy );
+ TEST_EQUAL(sizeof(buf) - entropy.len, expected_consumed_entropy);
/* While at it, make sure we didn't write past the requested length */
- TEST_ASSERT( out[sizeof( out ) - 4] == 0 );
- TEST_ASSERT( out[sizeof( out ) - 3] == 0 );
- TEST_ASSERT( out[sizeof( out ) - 2] == 0 );
- TEST_ASSERT( out[sizeof( out ) - 1] == 0 );
+ TEST_ASSERT(out[sizeof(out) - 4] == 0);
+ TEST_ASSERT(out[sizeof(out) - 3] == 0);
+ TEST_ASSERT(out[sizeof(out) - 2] == 0);
+ TEST_ASSERT(out[sizeof(out) - 1] == 0);
/* There have been 2 * reps calls to random. The next call should reseed */
- TEST_ASSERT( mbedtls_hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ TEST_ASSERT(mbedtls_hmac_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_consumed_entropy += default_entropy_len;
- TEST_EQUAL( sizeof( buf ) - entropy.len, expected_consumed_entropy );
+ TEST_EQUAL(sizeof(buf) - entropy.len, expected_consumed_entropy);
/* Set reseed interval after seed */
- mbedtls_hmac_drbg_set_reseed_interval( &ctx, 4 * reps + 1);
+ mbedtls_hmac_drbg_set_reseed_interval(&ctx, 4 * reps + 1);
/* The new few calls should not reseed */
- for( i = 0; i < (2 * reps); i++ )
- {
- TEST_ASSERT( mbedtls_hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, out, sizeof( out ) ,
- buf, 16 ) == 0 );
+ for (i = 0; i < (2 * reps); i++) {
+ TEST_ASSERT(mbedtls_hmac_drbg_random(&ctx, out, sizeof(out)) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, out, sizeof(out),
+ buf, 16) == 0);
}
- TEST_EQUAL( sizeof( buf ) - entropy.len, expected_consumed_entropy );
+ TEST_EQUAL(sizeof(buf) - entropy.len, expected_consumed_entropy);
/* Now enable PR, so the next few calls should all reseed */
- mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON );
- TEST_ASSERT( mbedtls_hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ mbedtls_hmac_drbg_set_prediction_resistance(&ctx, MBEDTLS_HMAC_DRBG_PR_ON);
+ TEST_ASSERT(mbedtls_hmac_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_consumed_entropy += default_entropy_len;
- TEST_EQUAL( sizeof( buf ) - entropy.len, expected_consumed_entropy );
+ TEST_EQUAL(sizeof(buf) - entropy.len, expected_consumed_entropy);
/* Finally, check setting entropy_len */
- mbedtls_hmac_drbg_set_entropy_len( &ctx, 42 );
- TEST_ASSERT( mbedtls_hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ mbedtls_hmac_drbg_set_entropy_len(&ctx, 42);
+ TEST_ASSERT(mbedtls_hmac_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_consumed_entropy += 42;
- TEST_EQUAL( sizeof( buf ) - entropy.len, expected_consumed_entropy );
+ TEST_EQUAL(sizeof(buf) - entropy.len, expected_consumed_entropy);
- mbedtls_hmac_drbg_set_entropy_len( &ctx, 13 );
- TEST_ASSERT( mbedtls_hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ mbedtls_hmac_drbg_set_entropy_len(&ctx, 13);
+ TEST_ASSERT(mbedtls_hmac_drbg_random(&ctx, out, sizeof(out)) == 0);
expected_consumed_entropy += 13;
- TEST_EQUAL( sizeof( buf ) - entropy.len, expected_consumed_entropy );
+ TEST_EQUAL(sizeof(buf) - entropy.len, expected_consumed_entropy);
exit:
- mbedtls_hmac_drbg_free( &ctx );
+ mbedtls_hmac_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
-void hmac_drbg_seed_file( int md_alg, char * path, int ret )
+void hmac_drbg_seed_file(int md_alg, char *path, int ret)
{
const mbedtls_md_info_t *md_info;
mbedtls_hmac_drbg_context ctx;
- mbedtls_hmac_drbg_init( &ctx );
+ mbedtls_hmac_drbg_init(&ctx);
- md_info = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md_info != NULL );
+ md_info = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md_info != NULL);
- TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info,
- mbedtls_test_rnd_std_rand, NULL,
- NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_hmac_drbg_seed(&ctx, md_info,
+ mbedtls_test_rnd_std_rand, NULL,
+ NULL, 0) == 0);
- TEST_ASSERT( mbedtls_hmac_drbg_write_seed_file( &ctx, path ) == ret );
- TEST_ASSERT( mbedtls_hmac_drbg_update_seed_file( &ctx, path ) == ret );
+ TEST_ASSERT(mbedtls_hmac_drbg_write_seed_file(&ctx, path) == ret);
+ TEST_ASSERT(mbedtls_hmac_drbg_update_seed_file(&ctx, path) == ret);
exit:
- mbedtls_hmac_drbg_free( &ctx );
+ mbedtls_hmac_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void hmac_drbg_buf( int md_alg )
+void hmac_drbg_buf(int md_alg)
{
unsigned char out[16];
unsigned char buf[100];
@@ -154,30 +153,31 @@
mbedtls_hmac_drbg_context ctx;
size_t i;
- mbedtls_hmac_drbg_init( &ctx );
- memset( buf, 0, sizeof( buf ) );
- memset( out, 0, sizeof( out ) );
+ mbedtls_hmac_drbg_init(&ctx);
+ memset(buf, 0, sizeof(buf));
+ memset(out, 0, sizeof(out));
- md_info = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md_info != NULL );
- TEST_ASSERT( mbedtls_hmac_drbg_seed_buf( &ctx, md_info, buf, sizeof( buf ) ) == 0 );
+ md_info = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md_info != NULL);
+ TEST_ASSERT(mbedtls_hmac_drbg_seed_buf(&ctx, md_info, buf, sizeof(buf)) == 0);
/* Make sure it never tries to reseed (would segfault otherwise) */
- mbedtls_hmac_drbg_set_reseed_interval( &ctx, 3 );
- mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON );
+ mbedtls_hmac_drbg_set_reseed_interval(&ctx, 3);
+ mbedtls_hmac_drbg_set_prediction_resistance(&ctx, MBEDTLS_HMAC_DRBG_PR_ON);
- for( i = 0; i < 30; i++ )
- TEST_ASSERT( mbedtls_hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
+ for (i = 0; i < 30; i++) {
+ TEST_ASSERT(mbedtls_hmac_drbg_random(&ctx, out, sizeof(out)) == 0);
+ }
exit:
- mbedtls_hmac_drbg_free( &ctx );
+ mbedtls_hmac_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void hmac_drbg_no_reseed( int md_alg, data_t * entropy,
- data_t * custom, data_t * add1,
- data_t * add2, data_t * output )
+void hmac_drbg_no_reseed(int md_alg, data_t *entropy,
+ data_t *custom, data_t *add1,
+ data_t *add2, data_t *output)
{
unsigned char data[1024];
unsigned char my_output[512];
@@ -185,111 +185,111 @@
const mbedtls_md_info_t *md_info;
mbedtls_hmac_drbg_context ctx;
- mbedtls_hmac_drbg_init( &ctx );
+ mbedtls_hmac_drbg_init(&ctx);
p_entropy.p = entropy->x;
p_entropy.len = entropy->len;
- md_info = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md_info != NULL );
+ md_info = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md_info != NULL);
/* Test the simplified buffer-based variant */
- memcpy( data, entropy->x, p_entropy.len );
- memcpy( data + p_entropy.len, custom->x, custom->len );
- TEST_ASSERT( mbedtls_hmac_drbg_seed_buf( &ctx, md_info,
- data, p_entropy.len + custom->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add1->x, add1->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add2->x, add2->len ) == 0 );
+ memcpy(data, entropy->x, p_entropy.len);
+ memcpy(data + p_entropy.len, custom->x, custom->len);
+ TEST_ASSERT(mbedtls_hmac_drbg_seed_buf(&ctx, md_info,
+ data, p_entropy.len + custom->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add1->x, add1->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add2->x, add2->len) == 0);
/* Reset context for second run */
- mbedtls_hmac_drbg_free( &ctx );
+ mbedtls_hmac_drbg_free(&ctx);
- TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
+ TEST_ASSERT(memcmp(my_output, output->x, output->len) == 0);
/* And now the normal entropy-based variant */
- TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
- custom->x, custom->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add1->x, add1->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add2->x, add2->len ) == 0 );
- TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
+ TEST_ASSERT(mbedtls_hmac_drbg_seed(&ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
+ custom->x, custom->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add1->x, add1->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add2->x, add2->len) == 0);
+ TEST_ASSERT(memcmp(my_output, output->x, output->len) == 0);
exit:
- mbedtls_hmac_drbg_free( &ctx );
+ mbedtls_hmac_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void hmac_drbg_nopr( int md_alg, data_t * entropy, data_t * custom,
- data_t * add1, data_t * add2, data_t * add3,
- data_t * output )
+void hmac_drbg_nopr(int md_alg, data_t *entropy, data_t *custom,
+ data_t *add1, data_t *add2, data_t *add3,
+ data_t *output)
{
unsigned char my_output[512];
entropy_ctx p_entropy;
const mbedtls_md_info_t *md_info;
mbedtls_hmac_drbg_context ctx;
- mbedtls_hmac_drbg_init( &ctx );
+ mbedtls_hmac_drbg_init(&ctx);
p_entropy.p = entropy->x;
p_entropy.len = entropy->len;
- md_info = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md_info != NULL );
+ md_info = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md_info != NULL);
- TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
- custom->x, custom->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_reseed( &ctx, add1->x, add1->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add2->x, add2->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add3->x, add3->len ) == 0 );
+ TEST_ASSERT(mbedtls_hmac_drbg_seed(&ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
+ custom->x, custom->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_reseed(&ctx, add1->x, add1->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add2->x, add2->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add3->x, add3->len) == 0);
- TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
+ TEST_ASSERT(memcmp(my_output, output->x, output->len) == 0);
exit:
- mbedtls_hmac_drbg_free( &ctx );
+ mbedtls_hmac_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void hmac_drbg_pr( int md_alg, data_t * entropy, data_t * custom,
- data_t * add1, data_t * add2, data_t * output )
+void hmac_drbg_pr(int md_alg, data_t *entropy, data_t *custom,
+ data_t *add1, data_t *add2, data_t *output)
{
unsigned char my_output[512];
entropy_ctx p_entropy;
const mbedtls_md_info_t *md_info;
mbedtls_hmac_drbg_context ctx;
- mbedtls_hmac_drbg_init( &ctx );
+ mbedtls_hmac_drbg_init(&ctx);
p_entropy.p = entropy->x;
p_entropy.len = entropy->len;
- md_info = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md_info != NULL );
+ md_info = mbedtls_md_info_from_type(md_alg);
+ TEST_ASSERT(md_info != NULL);
- TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
- custom->x, custom->len ) == 0 );
- mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add1->x, add1->len ) == 0 );
- TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
- add2->x, add2->len ) == 0 );
+ TEST_ASSERT(mbedtls_hmac_drbg_seed(&ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
+ custom->x, custom->len) == 0);
+ mbedtls_hmac_drbg_set_prediction_resistance(&ctx, MBEDTLS_HMAC_DRBG_PR_ON);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add1->x, add1->len) == 0);
+ TEST_ASSERT(mbedtls_hmac_drbg_random_with_add(&ctx, my_output, output->len,
+ add2->x, add2->len) == 0);
- TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
+ TEST_ASSERT(memcmp(my_output, output->x, output->len) == 0);
exit:
- mbedtls_hmac_drbg_free( &ctx );
+ mbedtls_hmac_drbg_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void hmac_drbg_selftest( )
+void hmac_drbg_selftest()
{
- TEST_ASSERT( mbedtls_hmac_drbg_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_hmac_drbg_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_lmots.function b/tests/suites/test_suite_lmots.function
index fd6a89f..8f06ee5 100644
--- a/tests/suites/test_suite_lmots.function
+++ b/tests/suites/test_suite_lmots.function
@@ -3,21 +3,20 @@
#include "mbedtls/lms.h"
#if defined(MBEDTLS_TEST_HOOKS)
-int check_lmots_private_key_for_leak(unsigned char * sig)
+int check_lmots_private_key_for_leak(unsigned char *sig)
{
size_t idx;
- for( idx = MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET(MBEDTLS_LMOTS_SHA256_N32_W8);
+ for (idx = MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET(MBEDTLS_LMOTS_SHA256_N32_W8);
idx < MBEDTLS_LMOTS_SIG_LEN(MBEDTLS_LMOTS_SHA256_N32_W8);
- idx++ )
- {
- TEST_EQUAL( sig[idx], 0x7E );
+ idx++) {
+ TEST_EQUAL(sig[idx], 0x7E);
}
- return( 0 );
+ return 0;
exit:
- return( -1 );
+ return -1;
}
#endif /* defined(MBEDTLS_TEST_HOOKS) */
@@ -29,201 +28,201 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_LMS_PRIVATE */
-void lmots_sign_verify_test ( data_t *msg, data_t *key_id, int leaf_id,
- data_t *seed )
+void lmots_sign_verify_test(data_t *msg, data_t *key_id, int leaf_id,
+ data_t *seed)
{
mbedtls_lmots_public_t pub_ctx;
mbedtls_lmots_private_t priv_ctx;
unsigned char sig[MBEDTLS_LMOTS_SIG_LEN(MBEDTLS_LMOTS_SHA256_N32_W8)];
- mbedtls_lmots_public_init( &pub_ctx );
- mbedtls_lmots_private_init( &priv_ctx );
+ mbedtls_lmots_public_init(&pub_ctx);
+ mbedtls_lmots_private_init(&priv_ctx);
- TEST_EQUAL( mbedtls_lmots_generate_private_key(&priv_ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
- key_id->x, leaf_id, seed->x, seed->len ), 0 );
- TEST_EQUAL( mbedtls_lmots_calculate_public_key(&pub_ctx, &priv_ctx), 0 );
- TEST_EQUAL( mbedtls_lmots_sign(&priv_ctx, &mbedtls_test_rnd_std_rand, NULL,
- msg->x, msg->len, sig, sizeof(sig), NULL ), 0 );
- TEST_EQUAL( mbedtls_lmots_verify(&pub_ctx, msg->x, msg->len, sig, sizeof(sig)), 0 );
+ TEST_EQUAL(mbedtls_lmots_generate_private_key(&priv_ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
+ key_id->x, leaf_id, seed->x, seed->len), 0);
+ TEST_EQUAL(mbedtls_lmots_calculate_public_key(&pub_ctx, &priv_ctx), 0);
+ TEST_EQUAL(mbedtls_lmots_sign(&priv_ctx, &mbedtls_test_rnd_std_rand, NULL,
+ msg->x, msg->len, sig, sizeof(sig), NULL), 0);
+ TEST_EQUAL(mbedtls_lmots_verify(&pub_ctx, msg->x, msg->len, sig, sizeof(sig)), 0);
exit:
- mbedtls_lmots_public_free( &pub_ctx );
- mbedtls_lmots_private_free( &priv_ctx );
+ mbedtls_lmots_public_free(&pub_ctx);
+ mbedtls_lmots_private_free(&priv_ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_LMS_PRIVATE */
-void lmots_sign_verify_null_msg_test ( data_t *key_id, int leaf_id, data_t *seed )
+void lmots_sign_verify_null_msg_test(data_t *key_id, int leaf_id, data_t *seed)
{
mbedtls_lmots_public_t pub_ctx;
mbedtls_lmots_private_t priv_ctx;
unsigned char sig[MBEDTLS_LMOTS_SIG_LEN(MBEDTLS_LMOTS_SHA256_N32_W8)];
- mbedtls_lmots_public_init( &pub_ctx );
- mbedtls_lmots_private_init( &priv_ctx );
+ mbedtls_lmots_public_init(&pub_ctx);
+ mbedtls_lmots_private_init(&priv_ctx);
- TEST_EQUAL( mbedtls_lmots_generate_private_key(&priv_ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
- key_id->x, leaf_id, seed->x, seed->len ), 0 );
- TEST_EQUAL( mbedtls_lmots_calculate_public_key(&pub_ctx, &priv_ctx), 0 );
- TEST_EQUAL( mbedtls_lmots_sign(&priv_ctx, &mbedtls_test_rnd_std_rand, NULL,
- NULL, 0, sig, sizeof(sig), NULL ), 0 );
- TEST_EQUAL( mbedtls_lmots_verify(&pub_ctx, NULL, 0, sig, sizeof(sig)), 0 );
+ TEST_EQUAL(mbedtls_lmots_generate_private_key(&priv_ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
+ key_id->x, leaf_id, seed->x, seed->len), 0);
+ TEST_EQUAL(mbedtls_lmots_calculate_public_key(&pub_ctx, &priv_ctx), 0);
+ TEST_EQUAL(mbedtls_lmots_sign(&priv_ctx, &mbedtls_test_rnd_std_rand, NULL,
+ NULL, 0, sig, sizeof(sig), NULL), 0);
+ TEST_EQUAL(mbedtls_lmots_verify(&pub_ctx, NULL, 0, sig, sizeof(sig)), 0);
exit:
- mbedtls_lmots_public_free( &pub_ctx );
- mbedtls_lmots_private_free( &priv_ctx );
+ mbedtls_lmots_public_free(&pub_ctx);
+ mbedtls_lmots_private_free(&priv_ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void lmots_verify_test ( data_t *msg, data_t *sig, data_t *pub_key,
- int expected_rc )
+void lmots_verify_test(data_t *msg, data_t *sig, data_t *pub_key,
+ int expected_rc)
{
mbedtls_lmots_public_t ctx;
unsigned int size;
unsigned char *tmp_sig = NULL;
- mbedtls_lmots_public_init( &ctx );
+ mbedtls_lmots_public_init(&ctx);
- TEST_EQUAL(mbedtls_lmots_import_public_key( &ctx, pub_key->x, pub_key->len ), 0);
+ TEST_EQUAL(mbedtls_lmots_import_public_key(&ctx, pub_key->x, pub_key->len), 0);
- TEST_EQUAL(mbedtls_lmots_verify( &ctx, msg->x, msg->len, sig->x, sig->len ), expected_rc);
+ TEST_EQUAL(mbedtls_lmots_verify(&ctx, msg->x, msg->len, sig->x, sig->len), expected_rc);
/* Test negative cases if the input data is valid */
- if( expected_rc == 0 )
- {
- if( msg->len >= 1 )
- {
+ if (expected_rc == 0) {
+ if (msg->len >= 1) {
/* Altering first message byte must cause verification failure */
msg->x[0] ^= 1;
- TEST_EQUAL(mbedtls_lmots_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lmots_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
msg->x[0] ^= 1;
/* Altering last message byte must cause verification failure */
msg->x[msg->len - 1] ^= 1;
- TEST_EQUAL(mbedtls_lmots_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lmots_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
msg->x[msg->len - 1] ^= 1;
}
/* Altering first signature byte must cause verification failure */
sig->x[0] ^= 1;
- TEST_EQUAL(mbedtls_lmots_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lmots_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
sig->x[0] ^= 1;
/* Altering last signature byte must cause verification failure */
sig->x[sig->len - 1] ^= 1;
- TEST_EQUAL(mbedtls_lmots_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lmots_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
sig->x[sig->len - 1] ^= 1;
/* Signatures of all sizes must not verify, whether shorter or longer */
- for( size = 0; size < sig->len; size++ ) {
- if( size == sig->len )
+ for (size = 0; size < sig->len; size++) {
+ if (size == sig->len) {
continue;
+ }
- ASSERT_ALLOC( tmp_sig, size );
- if( tmp_sig != NULL )
- memcpy( tmp_sig, sig->x, MIN(size, sig->len) );
+ ASSERT_ALLOC(tmp_sig, size);
+ if (tmp_sig != NULL) {
+ memcpy(tmp_sig, sig->x, MIN(size, sig->len));
+ }
- TEST_EQUAL(mbedtls_lmots_verify( &ctx, msg->x, msg->len, tmp_sig, size ),
+ TEST_EQUAL(mbedtls_lmots_verify(&ctx, msg->x, msg->len, tmp_sig, size),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
- mbedtls_free( tmp_sig );
+ mbedtls_free(tmp_sig);
tmp_sig = NULL;
}
}
exit:
- mbedtls_free( tmp_sig );
- mbedtls_lmots_public_free( &ctx );
+ mbedtls_free(tmp_sig);
+ mbedtls_lmots_public_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void lmots_import_export_test ( data_t * pub_key, int expected_import_rc )
+void lmots_import_export_test(data_t *pub_key, int expected_import_rc)
{
mbedtls_lmots_public_t ctx;
unsigned char *exported_pub_key = NULL;
size_t exported_pub_key_buf_size;
size_t exported_pub_key_size;
- mbedtls_lmots_public_init( &ctx );
- TEST_EQUAL( mbedtls_lmots_import_public_key( &ctx, pub_key->x, pub_key->len ),
- expected_import_rc );
+ mbedtls_lmots_public_init(&ctx);
+ TEST_EQUAL(mbedtls_lmots_import_public_key(&ctx, pub_key->x, pub_key->len),
+ expected_import_rc);
- if( expected_import_rc == 0 )
- {
+ if (expected_import_rc == 0) {
exported_pub_key_buf_size = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8);
- ASSERT_ALLOC( exported_pub_key, exported_pub_key_buf_size );
+ ASSERT_ALLOC(exported_pub_key, exported_pub_key_buf_size);
- TEST_EQUAL( mbedtls_lmots_export_public_key( &ctx, exported_pub_key,
+ TEST_EQUAL(mbedtls_lmots_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size,
- &exported_pub_key_size ), 0 );
+ &exported_pub_key_size), 0);
- TEST_EQUAL( exported_pub_key_size,
- MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8) );
- ASSERT_COMPARE( pub_key->x, pub_key->len,
- exported_pub_key, exported_pub_key_size );
+ TEST_EQUAL(exported_pub_key_size,
+ MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8));
+ ASSERT_COMPARE(pub_key->x, pub_key->len,
+ exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
/* Export into too-small buffer should fail */
exported_pub_key_buf_size = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8) - 1;
- ASSERT_ALLOC( exported_pub_key, exported_pub_key_buf_size);
- TEST_EQUAL( mbedtls_lmots_export_public_key( &ctx, exported_pub_key,
- exported_pub_key_buf_size, NULL ),
- MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL );
+ ASSERT_ALLOC(exported_pub_key, exported_pub_key_buf_size);
+ TEST_EQUAL(mbedtls_lmots_export_public_key(&ctx, exported_pub_key,
+ exported_pub_key_buf_size, NULL),
+ MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
/* Export into too-large buffer should succeed */
exported_pub_key_buf_size = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8) + 1;
- ASSERT_ALLOC( exported_pub_key, exported_pub_key_buf_size);
- TEST_EQUAL( mbedtls_lmots_export_public_key( &ctx, exported_pub_key,
+ ASSERT_ALLOC(exported_pub_key, exported_pub_key_buf_size);
+ TEST_EQUAL(mbedtls_lmots_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size,
- &exported_pub_key_size ),
- 0 );
- ASSERT_COMPARE( pub_key->x, pub_key->len,
- exported_pub_key, exported_pub_key_size );
+ &exported_pub_key_size),
+ 0);
+ ASSERT_COMPARE(pub_key->x, pub_key->len,
+ exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
}
exit:
- mbedtls_lmots_public_free( &ctx );
- mbedtls_free( exported_pub_key );
+ mbedtls_lmots_public_free(&ctx);
+ mbedtls_free(exported_pub_key);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_LMS_PRIVATE */
-void lmots_reuse_test ( data_t *msg, data_t *key_id, int leaf_id, data_t *seed )
+void lmots_reuse_test(data_t *msg, data_t *key_id, int leaf_id, data_t *seed)
{
mbedtls_lmots_private_t ctx;
unsigned char sig[MBEDTLS_LMOTS_SIG_LEN(MBEDTLS_LMOTS_SHA256_N32_W8)];
- mbedtls_lmots_private_init( &ctx );
- TEST_EQUAL( mbedtls_lmots_generate_private_key(&ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
- key_id->x, leaf_id, seed->x,
- seed->len ), 0 );
- TEST_EQUAL( mbedtls_lmots_sign(&ctx, mbedtls_test_rnd_std_rand, NULL,
- msg->x, msg->len, sig, sizeof( sig ), NULL ), 0 );
+ mbedtls_lmots_private_init(&ctx);
+ TEST_EQUAL(mbedtls_lmots_generate_private_key(&ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
+ key_id->x, leaf_id, seed->x,
+ seed->len), 0);
+ TEST_EQUAL(mbedtls_lmots_sign(&ctx, mbedtls_test_rnd_std_rand, NULL,
+ msg->x, msg->len, sig, sizeof(sig), NULL), 0);
/* Running another sign operation should fail, since the key should now have
* been erased.
*/
- TEST_EQUAL( mbedtls_lmots_sign(&ctx, mbedtls_test_rnd_std_rand, NULL,
- msg->x, msg->len, sig, sizeof( sig ), NULL ), MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_lmots_sign(&ctx, mbedtls_test_rnd_std_rand, NULL,
+ msg->x, msg->len, sig, sizeof(sig), NULL),
+ MBEDTLS_ERR_LMS_BAD_INPUT_DATA);
exit:
- mbedtls_lmots_private_free( &ctx );
+ mbedtls_lmots_private_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_LMS_PRIVATE */
-void lmots_signature_leak_test ( data_t *msg, data_t *key_id, int leaf_id,
- data_t *seed )
+void lmots_signature_leak_test(data_t *msg, data_t *key_id, int leaf_id,
+ data_t *seed)
{
mbedtls_lmots_private_t ctx;
unsigned char sig[MBEDTLS_LMOTS_SIG_LEN(MBEDTLS_LMOTS_SHA256_N32_W8)];
@@ -231,17 +230,17 @@
mbedtls_lmots_sign_private_key_invalidated_hook = &check_lmots_private_key_for_leak;
/* Fill with recognisable pattern */
- memset( sig, 0x7E, sizeof( sig ) );
+ memset(sig, 0x7E, sizeof(sig));
- mbedtls_lmots_private_init( &ctx );
- TEST_EQUAL( mbedtls_lmots_generate_private_key(&ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
- key_id->x, leaf_id, seed->x,
- seed->len ), 0 );
- TEST_EQUAL( mbedtls_lmots_sign(&ctx, mbedtls_test_rnd_std_rand, NULL,
- msg->x, msg->len, sig, sizeof( sig ), NULL ), 0 );
+ mbedtls_lmots_private_init(&ctx);
+ TEST_EQUAL(mbedtls_lmots_generate_private_key(&ctx, MBEDTLS_LMOTS_SHA256_N32_W8,
+ key_id->x, leaf_id, seed->x,
+ seed->len), 0);
+ TEST_EQUAL(mbedtls_lmots_sign(&ctx, mbedtls_test_rnd_std_rand, NULL,
+ msg->x, msg->len, sig, sizeof(sig), NULL), 0);
exit:
- mbedtls_lmots_private_free( &ctx );
+ mbedtls_lmots_private_free(&ctx);
mbedtls_lmots_sign_private_key_invalidated_hook = NULL;
}
/* END_CASE */
diff --git a/tests/suites/test_suite_lms.function b/tests/suites/test_suite_lms.function
index c5c8aa4..bfc3e06 100644
--- a/tests/suites/test_suite_lms.function
+++ b/tests/suites/test_suite_lms.function
@@ -9,142 +9,141 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_LMS_PRIVATE */
-void lms_sign_verify_test ( data_t *msg, data_t *seed )
+void lms_sign_verify_test(data_t *msg, data_t *seed)
{
mbedtls_lms_public_t pub_ctx;
mbedtls_lms_private_t priv_ctx;
unsigned char sig[MBEDTLS_LMS_SIG_LEN(MBEDTLS_LMS_SHA256_M32_H10, MBEDTLS_LMOTS_SHA256_N32_W8)];
- mbedtls_lms_public_init( &pub_ctx );
- mbedtls_lms_private_init( &priv_ctx );
+ mbedtls_lms_public_init(&pub_ctx);
+ mbedtls_lms_private_init(&priv_ctx);
/* Allocation failure isn't a test failure, since it likely just means
* there's not enough memory to run the test.
*/
- TEST_EQUAL( mbedtls_lms_generate_private_key( &priv_ctx, MBEDTLS_LMS_SHA256_M32_H10,
- MBEDTLS_LMOTS_SHA256_N32_W8,
- mbedtls_test_rnd_std_rand, NULL,
- seed->x, seed->len ), 0 );
+ TEST_EQUAL(mbedtls_lms_generate_private_key(&priv_ctx, MBEDTLS_LMS_SHA256_M32_H10,
+ MBEDTLS_LMOTS_SHA256_N32_W8,
+ mbedtls_test_rnd_std_rand, NULL,
+ seed->x, seed->len), 0);
- TEST_EQUAL( mbedtls_lms_calculate_public_key( &pub_ctx, &priv_ctx ), 0 );
+ TEST_EQUAL(mbedtls_lms_calculate_public_key(&pub_ctx, &priv_ctx), 0);
- TEST_EQUAL( mbedtls_lms_sign( &priv_ctx, mbedtls_test_rnd_std_rand, NULL,
- msg->x, msg->len, sig, sizeof( sig ),
- NULL ), 0 );
+ TEST_EQUAL(mbedtls_lms_sign(&priv_ctx, mbedtls_test_rnd_std_rand, NULL,
+ msg->x, msg->len, sig, sizeof(sig),
+ NULL), 0);
- TEST_EQUAL( mbedtls_lms_verify( &pub_ctx, msg->x, msg->len, sig,
- sizeof( sig ) ), 0 );
+ TEST_EQUAL(mbedtls_lms_verify(&pub_ctx, msg->x, msg->len, sig,
+ sizeof(sig)), 0);
exit:
- mbedtls_lms_public_free( &pub_ctx );
- mbedtls_lms_private_free( &priv_ctx );
+ mbedtls_lms_public_free(&pub_ctx);
+ mbedtls_lms_private_free(&priv_ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_LMS_PRIVATE */
-void lms_sign_verify_null_msg_test( data_t *seed )
+void lms_sign_verify_null_msg_test(data_t *seed)
{
mbedtls_lms_public_t pub_ctx;
mbedtls_lms_private_t priv_ctx;
unsigned char sig[MBEDTLS_LMS_SIG_LEN(MBEDTLS_LMS_SHA256_M32_H10, MBEDTLS_LMOTS_SHA256_N32_W8)];
- mbedtls_lms_public_init( &pub_ctx );
- mbedtls_lms_private_init( &priv_ctx );
+ mbedtls_lms_public_init(&pub_ctx);
+ mbedtls_lms_private_init(&priv_ctx);
/* Allocation failure isn't a test failure, since it likely just means
* there's not enough memory to run the test.
*/
- TEST_EQUAL( mbedtls_lms_generate_private_key( &priv_ctx, MBEDTLS_LMS_SHA256_M32_H10,
- MBEDTLS_LMOTS_SHA256_N32_W8,
- mbedtls_test_rnd_std_rand, NULL,
- seed->x, seed->len ), 0 );
+ TEST_EQUAL(mbedtls_lms_generate_private_key(&priv_ctx, MBEDTLS_LMS_SHA256_M32_H10,
+ MBEDTLS_LMOTS_SHA256_N32_W8,
+ mbedtls_test_rnd_std_rand, NULL,
+ seed->x, seed->len), 0);
- TEST_EQUAL( mbedtls_lms_calculate_public_key( &pub_ctx, &priv_ctx ), 0 );
+ TEST_EQUAL(mbedtls_lms_calculate_public_key(&pub_ctx, &priv_ctx), 0);
- TEST_EQUAL( mbedtls_lms_sign( &priv_ctx, mbedtls_test_rnd_std_rand, NULL,
- NULL, 0, sig, sizeof( sig ),
- NULL ), 0 );
+ TEST_EQUAL(mbedtls_lms_sign(&priv_ctx, mbedtls_test_rnd_std_rand, NULL,
+ NULL, 0, sig, sizeof(sig),
+ NULL), 0);
- TEST_EQUAL( mbedtls_lms_verify( &pub_ctx, NULL, 0, sig,
- sizeof( sig ) ), 0 );
+ TEST_EQUAL(mbedtls_lms_verify(&pub_ctx, NULL, 0, sig,
+ sizeof(sig)), 0);
exit:
- mbedtls_lms_public_free( &pub_ctx );
- mbedtls_lms_private_free( &priv_ctx );
+ mbedtls_lms_public_free(&pub_ctx);
+ mbedtls_lms_private_free(&priv_ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void lms_verify_test ( data_t * msg, data_t * sig, data_t * pub_key,
- int expected_rc )
+void lms_verify_test(data_t *msg, data_t *sig, data_t *pub_key,
+ int expected_rc)
{
mbedtls_lms_public_t ctx;
unsigned int size;
unsigned char *tmp_sig = NULL;
- mbedtls_lms_public_init( &ctx);
+ mbedtls_lms_public_init(&ctx);
- TEST_EQUAL(mbedtls_lms_import_public_key( &ctx, pub_key->x, pub_key->len ), 0);
+ TEST_EQUAL(mbedtls_lms_import_public_key(&ctx, pub_key->x, pub_key->len), 0);
- TEST_EQUAL(mbedtls_lms_verify( &ctx, msg->x, msg->len, sig->x, sig->len ), expected_rc);
+ TEST_EQUAL(mbedtls_lms_verify(&ctx, msg->x, msg->len, sig->x, sig->len), expected_rc);
/* Test negative cases if the input data is valid */
- if( expected_rc == 0 )
- {
- if( msg->len >= 1 )
- {
+ if (expected_rc == 0) {
+ if (msg->len >= 1) {
/* Altering first message byte must cause verification failure */
msg->x[0] ^= 1;
- TEST_EQUAL(mbedtls_lms_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lms_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
msg->x[0] ^= 1;
/* Altering last message byte must cause verification failure */
msg->x[msg->len - 1] ^= 1;
- TEST_EQUAL(mbedtls_lms_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lms_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
msg->x[msg->len - 1] ^= 1;
}
- if( sig->len >= 1 )
- {
+ if (sig->len >= 1) {
/* Altering first signature byte must cause verification failure */
sig->x[0] ^= 1;
- TEST_EQUAL(mbedtls_lms_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lms_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
sig->x[0] ^= 1;
/* Altering last signature byte must cause verification failure */
sig->x[sig->len - 1] ^= 1;
- TEST_EQUAL(mbedtls_lms_verify( &ctx, msg->x, msg->len, sig->x, sig->len ),
+ TEST_EQUAL(mbedtls_lms_verify(&ctx, msg->x, msg->len, sig->x, sig->len),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
sig->x[sig->len - 1] ^= 1;
}
/* Signatures of all sizes must not verify, whether shorter or longer */
- for( size = 0; size < sig->len; size++ ) {
- if( size == sig->len )
+ for (size = 0; size < sig->len; size++) {
+ if (size == sig->len) {
continue;
+ }
- ASSERT_ALLOC( tmp_sig, size );
- if( tmp_sig != NULL )
- memcpy( tmp_sig, sig->x, MIN(size, sig->len) );
+ ASSERT_ALLOC(tmp_sig, size);
+ if (tmp_sig != NULL) {
+ memcpy(tmp_sig, sig->x, MIN(size, sig->len));
+ }
- TEST_EQUAL(mbedtls_lms_verify( &ctx, msg->x, msg->len, tmp_sig, size ),
+ TEST_EQUAL(mbedtls_lms_verify(&ctx, msg->x, msg->len, tmp_sig, size),
MBEDTLS_ERR_LMS_VERIFY_FAILED);
- mbedtls_free( tmp_sig );
+ mbedtls_free(tmp_sig);
tmp_sig = NULL;
}
}
exit:
- mbedtls_free( tmp_sig );
- mbedtls_lms_public_free( &ctx );
+ mbedtls_free(tmp_sig);
+ mbedtls_lms_public_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void lms_import_export_test ( data_t * pub_key, int expected_import_rc )
+void lms_import_export_test(data_t *pub_key, int expected_import_rc)
{
mbedtls_lms_public_t ctx;
size_t exported_pub_key_buf_size = 0;
@@ -152,50 +151,48 @@
unsigned char *exported_pub_key = NULL;
mbedtls_lms_public_init(&ctx);
- TEST_EQUAL( mbedtls_lms_import_public_key( &ctx, pub_key->x, pub_key->len ),
- expected_import_rc );
+ TEST_EQUAL(mbedtls_lms_import_public_key(&ctx, pub_key->x, pub_key->len),
+ expected_import_rc);
- if( expected_import_rc == 0 )
- {
+ if (expected_import_rc == 0) {
exported_pub_key_buf_size = MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10);
- ASSERT_ALLOC( exported_pub_key, exported_pub_key_buf_size );
+ ASSERT_ALLOC(exported_pub_key, exported_pub_key_buf_size);
- TEST_EQUAL( mbedtls_lms_export_public_key( &ctx, exported_pub_key,
- exported_pub_key_buf_size,
- &exported_pub_key_size ), 0 );
+ TEST_EQUAL(mbedtls_lms_export_public_key(&ctx, exported_pub_key,
+ exported_pub_key_buf_size,
+ &exported_pub_key_size), 0);
- TEST_EQUAL( exported_pub_key_size,
- MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10 ) );
- ASSERT_COMPARE( pub_key->x, pub_key->len,
- exported_pub_key, exported_pub_key_size );
+ TEST_EQUAL(exported_pub_key_size,
+ MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10));
+ ASSERT_COMPARE(pub_key->x, pub_key->len,
+ exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
/* Export into too-small buffer should fail */
exported_pub_key_buf_size = MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10) - 1;
- ASSERT_ALLOC( exported_pub_key, exported_pub_key_buf_size);
- TEST_EQUAL( mbedtls_lms_export_public_key( &ctx, exported_pub_key,
- exported_pub_key_buf_size, NULL ),
- MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL );
+ ASSERT_ALLOC(exported_pub_key, exported_pub_key_buf_size);
+ TEST_EQUAL(mbedtls_lms_export_public_key(&ctx, exported_pub_key,
+ exported_pub_key_buf_size, NULL),
+ MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
/* Export into too-large buffer should succeed */
exported_pub_key_buf_size = MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10) + 1;
- ASSERT_ALLOC( exported_pub_key, exported_pub_key_buf_size);
- TEST_EQUAL( mbedtls_lms_export_public_key( &ctx, exported_pub_key,
- exported_pub_key_buf_size,
- &exported_pub_key_size ),
- 0 );
- ASSERT_COMPARE( pub_key->x, pub_key->len,
- exported_pub_key, exported_pub_key_size );
+ ASSERT_ALLOC(exported_pub_key, exported_pub_key_buf_size);
+ TEST_EQUAL(mbedtls_lms_export_public_key(&ctx, exported_pub_key,
+ exported_pub_key_buf_size,
+ &exported_pub_key_size),
+ 0);
+ ASSERT_COMPARE(pub_key->x, pub_key->len,
+ exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
}
exit:
- mbedtls_free( exported_pub_key );
- mbedtls_lms_public_free( &ctx );
+ mbedtls_free(exported_pub_key);
+ mbedtls_lms_public_free(&ctx);
}
/* END_CASE */
-
diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function
index 602afa4..be1eab0 100644
--- a/tests/suites/test_suite_md.function
+++ b/tests/suites/test_suite_md.function
@@ -8,15 +8,15 @@
*/
/* BEGIN_CASE */
-void mbedtls_md_process( )
+void mbedtls_md_process()
{
const int *md_type_ptr;
const mbedtls_md_info_t *info;
mbedtls_md_context_t ctx;
unsigned char buf[150];
- mbedtls_md_init( &ctx );
- memset( buf, 0, sizeof( buf ) );
+ mbedtls_md_init(&ctx);
+ memset(buf, 0, sizeof(buf));
/*
* Very minimal testing of mbedtls_md_process, just make sure the various
@@ -26,161 +26,162 @@
*
* Also tests that mbedtls_md_list() only returns valid MDs.
*/
- for( md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++ )
- {
- info = mbedtls_md_info_from_type( *md_type_ptr );
- TEST_ASSERT( info != NULL );
- TEST_ASSERT( mbedtls_md_setup( &ctx, info, 0 ) == 0 );
- TEST_ASSERT( mbedtls_md_starts( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_md_process( &ctx, buf ) == 0 );
- mbedtls_md_free( &ctx );
+ for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++) {
+ info = mbedtls_md_info_from_type(*md_type_ptr);
+ TEST_ASSERT(info != NULL);
+ TEST_ASSERT(mbedtls_md_setup(&ctx, info, 0) == 0);
+ TEST_ASSERT(mbedtls_md_starts(&ctx) == 0);
+ TEST_ASSERT(mbedtls_md_process(&ctx, buf) == 0);
+ mbedtls_md_free(&ctx);
}
exit:
- mbedtls_md_free( &ctx );
+ mbedtls_md_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void md_null_args( )
+void md_null_args()
{
mbedtls_md_context_t ctx;
- const mbedtls_md_info_t *info = mbedtls_md_info_from_type( *( mbedtls_md_list() ) );
+ const mbedtls_md_info_t *info = mbedtls_md_info_from_type(*(mbedtls_md_list()));
unsigned char buf[1] = { 0 };
- mbedtls_md_init( &ctx );
+ mbedtls_md_init(&ctx);
- TEST_ASSERT( mbedtls_md_get_size( NULL ) == 0 );
- TEST_ASSERT( mbedtls_md_get_type( NULL ) == MBEDTLS_MD_NONE );
- TEST_ASSERT( mbedtls_md_get_name( NULL ) == NULL );
+ TEST_ASSERT(mbedtls_md_get_size(NULL) == 0);
+ TEST_ASSERT(mbedtls_md_get_type(NULL) == MBEDTLS_MD_NONE);
+ TEST_ASSERT(mbedtls_md_get_name(NULL) == NULL);
- TEST_ASSERT( mbedtls_md_info_from_string( NULL ) == NULL );
- TEST_ASSERT( mbedtls_md_info_from_ctx( NULL ) == NULL );
- TEST_ASSERT( mbedtls_md_info_from_ctx( &ctx ) == NULL );
+ TEST_ASSERT(mbedtls_md_info_from_string(NULL) == NULL);
+ TEST_ASSERT(mbedtls_md_info_from_ctx(NULL) == NULL);
+ TEST_ASSERT(mbedtls_md_info_from_ctx(&ctx) == NULL);
- TEST_ASSERT( mbedtls_md_setup( &ctx, NULL, 0 ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_setup( NULL, info, 0 ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_setup(&ctx, NULL, 0) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_setup(NULL, info, 0) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_starts( NULL ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_starts( &ctx ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_starts(NULL) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_starts(&ctx) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_update( NULL, buf, 1 ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_update( &ctx, buf, 1 ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_update(NULL, buf, 1) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_update(&ctx, buf, 1) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_finish( NULL, buf ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_finish( &ctx, buf ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_finish(NULL, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_finish(&ctx, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md( NULL, buf, 1, buf ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md(NULL, buf, 1, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
#if defined(MBEDTLS_FS_IO)
- TEST_ASSERT( mbedtls_md_file( NULL, "", buf ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_file(NULL, "", buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
#endif
- TEST_ASSERT( mbedtls_md_hmac_starts( NULL, buf, 1 )
- == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_hmac_starts( &ctx, buf, 1 )
- == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_hmac_starts(NULL, buf, 1)
+ == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_hmac_starts(&ctx, buf, 1)
+ == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_hmac_update( NULL, buf, 1 )
- == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_hmac_update( &ctx, buf, 1 )
- == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_hmac_update(NULL, buf, 1)
+ == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_hmac_update(&ctx, buf, 1)
+ == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_hmac_finish( NULL, buf )
- == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_hmac_finish( &ctx, buf )
- == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_hmac_finish(NULL, buf)
+ == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_hmac_finish(&ctx, buf)
+ == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_hmac_reset( NULL ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_hmac_reset( &ctx ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_hmac_reset(NULL) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_hmac_reset(&ctx) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_hmac( NULL, buf, 1, buf, 1, buf )
- == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_hmac(NULL, buf, 1, buf, 1, buf)
+ == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_md_process( NULL, buf ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
- TEST_ASSERT( mbedtls_md_process( &ctx, buf ) == MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_md_process(NULL, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
+ TEST_ASSERT(mbedtls_md_process(&ctx, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA);
/* Ok, this is not NULL arg but NULL return... */
- TEST_ASSERT( mbedtls_md_info_from_type( MBEDTLS_MD_NONE ) == NULL );
- TEST_ASSERT( mbedtls_md_info_from_string( "no such md" ) == NULL );
+ TEST_ASSERT(mbedtls_md_info_from_type(MBEDTLS_MD_NONE) == NULL);
+ TEST_ASSERT(mbedtls_md_info_from_string("no such md") == NULL);
}
/* END_CASE */
/* BEGIN_CASE */
-void md_info( int md_type, char * md_name, int md_size )
+void md_info(int md_type, char *md_name, int md_size)
{
const mbedtls_md_info_t *md_info;
const int *md_type_ptr;
int found;
- md_info = mbedtls_md_info_from_type( md_type );
- TEST_ASSERT( md_info != NULL );
- TEST_ASSERT( md_info == mbedtls_md_info_from_string( md_name ) );
+ md_info = mbedtls_md_info_from_type(md_type);
+ TEST_ASSERT(md_info != NULL);
+ TEST_ASSERT(md_info == mbedtls_md_info_from_string(md_name));
- TEST_ASSERT( mbedtls_md_get_type( md_info ) == (mbedtls_md_type_t) md_type );
- TEST_ASSERT( mbedtls_md_get_size( md_info ) == (unsigned char) md_size );
- TEST_ASSERT( strcmp( mbedtls_md_get_name( md_info ), md_name ) == 0 );
+ TEST_ASSERT(mbedtls_md_get_type(md_info) == (mbedtls_md_type_t) md_type);
+ TEST_ASSERT(mbedtls_md_get_size(md_info) == (unsigned char) md_size);
+ TEST_ASSERT(strcmp(mbedtls_md_get_name(md_info), md_name) == 0);
found = 0;
- for( md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++ )
- if( *md_type_ptr == md_type )
+ for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++) {
+ if (*md_type_ptr == md_type) {
found = 1;
- TEST_ASSERT( found == 1 );
+ }
+ }
+ TEST_ASSERT(found == 1);
}
/* END_CASE */
/* BEGIN_CASE */
-void md_text( char * text_md_name, char * text_src_string,
- data_t * hash )
+void md_text(char *text_md_name, char *text_src_string,
+ data_t *hash)
{
char md_name[100];
unsigned char src_str[1000];
unsigned char output[100];
const mbedtls_md_info_t *md_info = NULL;
- memset( md_name, 0x00, 100 );
- memset( src_str, 0x00, 1000 );
- memset( output, 0x00, 100 );
+ memset(md_name, 0x00, 100);
+ memset(src_str, 0x00, 1000);
+ memset(output, 0x00, 100);
- strncpy( (char *) src_str, text_src_string, sizeof( src_str ) - 1 );
- strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
+ strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
+ strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
md_info = mbedtls_md_info_from_string(md_name);
- TEST_ASSERT( md_info != NULL );
+ TEST_ASSERT(md_info != NULL);
- TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str, strlen( (char *) src_str ), output ) );
+ TEST_ASSERT(0 == mbedtls_md(md_info, src_str, strlen((char *) src_str), output));
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- mbedtls_md_get_size( md_info ),
- hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ mbedtls_md_get_size(md_info),
+ hash->len) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void md_hex( char * text_md_name, data_t * src_str, data_t * hash )
+void md_hex(char *text_md_name, data_t *src_str, data_t *hash)
{
char md_name[100];
unsigned char output[100];
const mbedtls_md_info_t *md_info = NULL;
- memset( md_name, 0x00, 100 );
- memset( output, 0x00, 100 );
+ memset(md_name, 0x00, 100);
+ memset(output, 0x00, 100);
- strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
- md_info = mbedtls_md_info_from_string( md_name );
- TEST_ASSERT( md_info != NULL );
+ strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
+ md_info = mbedtls_md_info_from_string(md_name);
+ TEST_ASSERT(md_info != NULL);
- TEST_ASSERT ( 0 == mbedtls_md( md_info, src_str->x, src_str->len, output ) );
+ TEST_ASSERT(0 == mbedtls_md(md_info, src_str->x, src_str->len, output));
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- mbedtls_md_get_size( md_info ),
- hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ mbedtls_md_get_size(md_info),
+ hash->len) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void md_text_multi( char * text_md_name, char * text_src_string,
- data_t * hash )
+void md_text_multi(char *text_md_name, char *text_src_string,
+ data_t *hash)
{
char md_name[100];
unsigned char src_str[1000];
@@ -190,53 +191,53 @@
const mbedtls_md_info_t *md_info = NULL;
mbedtls_md_context_t ctx, ctx_copy;
- mbedtls_md_init( &ctx );
- mbedtls_md_init( &ctx_copy );
+ mbedtls_md_init(&ctx);
+ mbedtls_md_init(&ctx_copy);
- memset( md_name, 0x00, 100 );
- memset( src_str, 0x00, 1000 );
- memset( output, 0x00, 100 );
+ memset(md_name, 0x00, 100);
+ memset(src_str, 0x00, 1000);
+ memset(output, 0x00, 100);
- strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
- strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
- len = strlen( (char *) src_str );
+ strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
+ strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
+ len = strlen((char *) src_str);
halfway = len / 2;
md_info = mbedtls_md_info_from_string(md_name);
- TEST_ASSERT( md_info != NULL );
- TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 0 ) );
- TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx_copy, md_info, 0 ) );
- TEST_ASSERT ( mbedtls_md_info_from_ctx( &ctx ) == md_info );
- TEST_ASSERT ( mbedtls_md_info_from_ctx( &ctx_copy ) == md_info );
+ TEST_ASSERT(md_info != NULL);
+ TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 0));
+ TEST_ASSERT(0 == mbedtls_md_setup(&ctx_copy, md_info, 0));
+ TEST_ASSERT(mbedtls_md_info_from_ctx(&ctx) == md_info);
+ TEST_ASSERT(mbedtls_md_info_from_ctx(&ctx_copy) == md_info);
- TEST_ASSERT ( 0 == mbedtls_md_starts( &ctx ) );
- TEST_ASSERT ( ctx.md_ctx != NULL );
- TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str, halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_clone( &ctx_copy, &ctx ) );
+ TEST_ASSERT(0 == mbedtls_md_starts(&ctx));
+ TEST_ASSERT(ctx.md_ctx != NULL);
+ TEST_ASSERT(0 == mbedtls_md_update(&ctx, src_str, halfway));
+ TEST_ASSERT(0 == mbedtls_md_clone(&ctx_copy, &ctx));
- TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str + halfway, len - halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) );
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- mbedtls_md_get_size( md_info ),
- hash->len) == 0 );
+ TEST_ASSERT(0 == mbedtls_md_update(&ctx, src_str + halfway, len - halfway));
+ TEST_ASSERT(0 == mbedtls_md_finish(&ctx, output));
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ mbedtls_md_get_size(md_info),
+ hash->len) == 0);
/* Test clone */
- memset( output, 0x00, 100 );
+ memset(output, 0x00, 100);
- TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str + halfway, len - halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- mbedtls_md_get_size( md_info ),
- hash->len ) == 0 );
+ TEST_ASSERT(0 == mbedtls_md_update(&ctx_copy, src_str + halfway, len - halfway));
+ TEST_ASSERT(0 == mbedtls_md_finish(&ctx_copy, output));
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ mbedtls_md_get_size(md_info),
+ hash->len) == 0);
exit:
- mbedtls_md_free( &ctx );
- mbedtls_md_free( &ctx_copy );
+ mbedtls_md_free(&ctx);
+ mbedtls_md_free(&ctx_copy);
}
/* END_CASE */
/* BEGIN_CASE */
-void md_hex_multi( char * text_md_name, data_t * src_str, data_t * hash )
+void md_hex_multi(char *text_md_name, data_t *src_str, data_t *hash)
{
char md_name[100];
unsigned char output[100];
@@ -244,75 +245,76 @@
mbedtls_md_context_t ctx, ctx_copy;
int halfway;
- mbedtls_md_init( &ctx );
- mbedtls_md_init( &ctx_copy );
+ mbedtls_md_init(&ctx);
+ mbedtls_md_init(&ctx_copy);
- memset( md_name, 0x00, 100 );
- memset( output, 0x00, 100 );
+ memset(md_name, 0x00, 100);
+ memset(output, 0x00, 100);
- strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
+ strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
md_info = mbedtls_md_info_from_string(md_name);
- TEST_ASSERT( md_info != NULL );
- TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 0 ) );
- TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx_copy, md_info, 0 ) );
- TEST_ASSERT ( mbedtls_md_info_from_ctx( &ctx ) == md_info );
- TEST_ASSERT ( mbedtls_md_info_from_ctx( &ctx_copy ) == md_info );
+ TEST_ASSERT(md_info != NULL);
+ TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 0));
+ TEST_ASSERT(0 == mbedtls_md_setup(&ctx_copy, md_info, 0));
+ TEST_ASSERT(mbedtls_md_info_from_ctx(&ctx) == md_info);
+ TEST_ASSERT(mbedtls_md_info_from_ctx(&ctx_copy) == md_info);
halfway = src_str->len / 2;
- TEST_ASSERT ( 0 == mbedtls_md_starts( &ctx ) );
- TEST_ASSERT ( ctx.md_ctx != NULL );
- TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str->x, halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_clone( &ctx_copy, &ctx ) );
+ TEST_ASSERT(0 == mbedtls_md_starts(&ctx));
+ TEST_ASSERT(ctx.md_ctx != NULL);
+ TEST_ASSERT(0 == mbedtls_md_update(&ctx, src_str->x, halfway));
+ TEST_ASSERT(0 == mbedtls_md_clone(&ctx_copy, &ctx));
- TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str->x + halfway, src_str->len - halfway) );
- TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) );
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- mbedtls_md_get_size( md_info ),
- hash->len ) == 0 );
+ TEST_ASSERT(0 == mbedtls_md_update(&ctx, src_str->x + halfway, src_str->len - halfway));
+ TEST_ASSERT(0 == mbedtls_md_finish(&ctx, output));
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ mbedtls_md_get_size(md_info),
+ hash->len) == 0);
/* Test clone */
- memset( output, 0x00, 100 );
+ memset(output, 0x00, 100);
- TEST_ASSERT ( 0 == mbedtls_md_update( &ctx_copy, src_str->x + halfway, src_str->len - halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx_copy, output ) );
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- mbedtls_md_get_size( md_info ),
- hash->len ) == 0 );
+ TEST_ASSERT(0 == mbedtls_md_update(&ctx_copy, src_str->x + halfway, src_str->len - halfway));
+ TEST_ASSERT(0 == mbedtls_md_finish(&ctx_copy, output));
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ mbedtls_md_get_size(md_info),
+ hash->len) == 0);
exit:
- mbedtls_md_free( &ctx );
- mbedtls_md_free( &ctx_copy );
+ mbedtls_md_free(&ctx);
+ mbedtls_md_free(&ctx_copy);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_md_hmac( char * text_md_name, int trunc_size,
- data_t * key_str, data_t * src_str,
- data_t * hash )
+void mbedtls_md_hmac(char *text_md_name, int trunc_size,
+ data_t *key_str, data_t *src_str,
+ data_t *hash)
{
char md_name[100];
unsigned char output[100];
const mbedtls_md_info_t *md_info = NULL;
- memset( md_name, 0x00, 100 );
- memset( output, 0x00, 100 );
+ memset(md_name, 0x00, 100);
+ memset(output, 0x00, 100);
- strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
- md_info = mbedtls_md_info_from_string( md_name );
- TEST_ASSERT( md_info != NULL );
+ strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
+ md_info = mbedtls_md_info_from_string(md_name);
+ TEST_ASSERT(md_info != NULL);
- TEST_ASSERT ( mbedtls_md_hmac( md_info, key_str->x, key_str->len, src_str->x, src_str->len, output ) == 0 );
+ TEST_ASSERT(mbedtls_md_hmac(md_info, key_str->x, key_str->len, src_str->x, src_str->len,
+ output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- trunc_size, hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ trunc_size, hash->len) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void md_hmac_multi( char * text_md_name, int trunc_size, data_t * key_str,
- data_t * src_str, data_t * hash )
+void md_hmac_multi(char *text_md_name, int trunc_size, data_t *key_str,
+ data_t *src_str, data_t *hash)
{
char md_name[100];
unsigned char output[100];
@@ -320,63 +322,63 @@
mbedtls_md_context_t ctx;
int halfway;
- mbedtls_md_init( &ctx );
+ mbedtls_md_init(&ctx);
- memset( md_name, 0x00, 100 );
- memset( output, 0x00, 100 );
+ memset(md_name, 0x00, 100);
+ memset(output, 0x00, 100);
- strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
- md_info = mbedtls_md_info_from_string( md_name );
- TEST_ASSERT( md_info != NULL );
- TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 1 ) );
- TEST_ASSERT ( mbedtls_md_info_from_ctx( &ctx ) == md_info );
+ strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
+ md_info = mbedtls_md_info_from_string(md_name);
+ TEST_ASSERT(md_info != NULL);
+ TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 1));
+ TEST_ASSERT(mbedtls_md_info_from_ctx(&ctx) == md_info);
halfway = src_str->len / 2;
- TEST_ASSERT ( 0 == mbedtls_md_hmac_starts( &ctx, key_str->x, key_str->len ) );
- TEST_ASSERT ( ctx.md_ctx != NULL );
- TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x, halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x + halfway, src_str->len - halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
+ TEST_ASSERT(0 == mbedtls_md_hmac_starts(&ctx, key_str->x, key_str->len));
+ TEST_ASSERT(ctx.md_ctx != NULL);
+ TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x, halfway));
+ TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway));
+ TEST_ASSERT(0 == mbedtls_md_hmac_finish(&ctx, output));
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- trunc_size, hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ trunc_size, hash->len) == 0);
/* Test again, for reset() */
- memset( output, 0x00, 100 );
+ memset(output, 0x00, 100);
- TEST_ASSERT ( 0 == mbedtls_md_hmac_reset( &ctx ) );
- TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x, halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str->x + halfway, src_str->len - halfway ) );
- TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) );
+ TEST_ASSERT(0 == mbedtls_md_hmac_reset(&ctx));
+ TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x, halfway));
+ TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway));
+ TEST_ASSERT(0 == mbedtls_md_hmac_finish(&ctx, output));
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- trunc_size, hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ trunc_size, hash->len) == 0);
exit:
- mbedtls_md_free( &ctx );
+ mbedtls_md_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
-void mbedtls_md_file( char * text_md_name, char * filename,
- data_t * hash )
+void mbedtls_md_file(char *text_md_name, char *filename,
+ data_t *hash)
{
char md_name[100];
unsigned char output[100];
const mbedtls_md_info_t *md_info = NULL;
- memset( md_name, 0x00, 100 );
- memset( output, 0x00, 100 );
+ memset(md_name, 0x00, 100);
+ memset(output, 0x00, 100);
- strncpy( (char *) md_name, text_md_name, sizeof( md_name ) - 1 );
- md_info = mbedtls_md_info_from_string( md_name );
- TEST_ASSERT( md_info != NULL );
+ strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
+ md_info = mbedtls_md_info_from_string(md_name);
+ TEST_ASSERT(md_info != NULL);
- TEST_ASSERT( mbedtls_md_file( md_info, filename, output ) == 0 );
+ TEST_ASSERT(mbedtls_md_file(md_info, filename, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- mbedtls_md_get_size( md_info ),
- hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ mbedtls_md_get_size(md_info),
+ hash->len) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_mdx.function b/tests/suites/test_suite_mdx.function
index 73f9123..93f4101 100644
--- a/tests/suites/test_suite_mdx.function
+++ b/tests/suites/test_suite_mdx.function
@@ -4,27 +4,27 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_MD5_C */
-void md5_text( char * text_src_string, data_t * hash )
+void md5_text(char *text_src_string, data_t *hash)
{
int ret;
unsigned char src_str[100];
unsigned char output[16];
- memset( src_str, 0x00, sizeof src_str );
- memset( output, 0x00, sizeof output );
+ memset(src_str, 0x00, sizeof src_str);
+ memset(output, 0x00, sizeof output);
- strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
+ strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
- ret = mbedtls_md5( src_str, strlen( (char *) src_str ), output );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_md5(src_str, strlen((char *) src_str), output);
+ TEST_ASSERT(ret == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- sizeof output, hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ sizeof output, hash->len) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */
-void ripemd160_text( char * text_src_string, data_t * hash )
+void ripemd160_text(char *text_src_string, data_t *hash)
{
int ret;
unsigned char src_str[100];
@@ -33,26 +33,26 @@
memset(src_str, 0x00, sizeof src_str);
memset(output, 0x00, sizeof output);
- strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
+ strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
- ret = mbedtls_ripemd160( src_str, strlen( (char *) src_str ), output );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ripemd160(src_str, strlen((char *) src_str), output);
+ TEST_ASSERT(ret == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
- sizeof output, hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
+ sizeof output, hash->len) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */
-void md5_selftest( )
+void md5_selftest()
{
- TEST_ASSERT( mbedtls_md5_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_md5_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */
-void ripemd160_selftest( )
+void ripemd160_selftest()
{
- TEST_ASSERT( mbedtls_ripemd160_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_ripemd160_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_memory_buffer_alloc.function b/tests/suites/test_suite_memory_buffer_alloc.function
index cc884c2..2b81097 100644
--- a/tests/suites/test_suite_memory_buffer_alloc.function
+++ b/tests/suites/test_suite_memory_buffer_alloc.function
@@ -10,34 +10,36 @@
*/
/* BEGIN_SUITE_HELPERS */
-static int check_pointer( void *p )
+static int check_pointer(void *p)
{
- if( p == NULL )
- return( -1 );
+ if (p == NULL) {
+ return -1;
+ }
- if( (size_t) p % MBEDTLS_MEMORY_ALIGN_MULTIPLE != 0 )
- return( -1 );
+ if ((size_t) p % MBEDTLS_MEMORY_ALIGN_MULTIPLE != 0) {
+ return -1;
+ }
- return( 0 );
+ return 0;
}
/* END_SUITE_HELPERS */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void mbedtls_memory_buffer_alloc_self_test( )
+void mbedtls_memory_buffer_alloc_self_test()
{
- TEST_ASSERT( mbedtls_memory_buffer_alloc_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
- int d_bytes, int free_a, int free_b,
- int free_c, int free_d, int e_bytes,
- int f_bytes )
+void memory_buffer_alloc_free_alloc(int a_bytes, int b_bytes, int c_bytes,
+ int d_bytes, int free_a, int free_b,
+ int free_c, int free_d, int e_bytes,
+ int f_bytes)
{
unsigned char buf[1024];
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL, *ptr_d = NULL,
- *ptr_e = NULL, *ptr_f = NULL;
+ *ptr_e = NULL, *ptr_f = NULL;
#if defined(MBEDTLS_MEMORY_DEBUG)
size_t reported_blocks;
@@ -45,98 +47,88 @@
#endif
size_t allocated_bytes = 0;
- mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
+ mbedtls_memory_buffer_alloc_init(buf, sizeof(buf));
- mbedtls_memory_buffer_set_verify( MBEDTLS_MEMORY_VERIFY_ALWAYS );
+ mbedtls_memory_buffer_set_verify(MBEDTLS_MEMORY_VERIFY_ALWAYS);
- if( a_bytes > 0 )
- {
- ptr_a = mbedtls_calloc( a_bytes, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_a ) == 0 );
+ if (a_bytes > 0) {
+ ptr_a = mbedtls_calloc(a_bytes, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_a) == 0);
allocated_bytes += a_bytes * sizeof(char);
}
- if( b_bytes > 0 )
- {
- ptr_b = mbedtls_calloc( b_bytes, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_b ) == 0 );
+ if (b_bytes > 0) {
+ ptr_b = mbedtls_calloc(b_bytes, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_b) == 0);
allocated_bytes += b_bytes * sizeof(char);
}
- if( c_bytes > 0 )
- {
- ptr_c = mbedtls_calloc( c_bytes, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_c ) == 0 );
+ if (c_bytes > 0) {
+ ptr_c = mbedtls_calloc(c_bytes, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_c) == 0);
allocated_bytes += c_bytes * sizeof(char);
}
- if( d_bytes > 0 )
- {
- ptr_d = mbedtls_calloc( d_bytes, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_d ) == 0 );
+ if (d_bytes > 0) {
+ ptr_d = mbedtls_calloc(d_bytes, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_d) == 0);
allocated_bytes += d_bytes * sizeof(char);
}
#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
- TEST_ASSERT( reported_bytes == allocated_bytes );
+ mbedtls_memory_buffer_alloc_cur_get(&reported_bytes, &reported_blocks);
+ TEST_ASSERT(reported_bytes == allocated_bytes);
#endif
- if( free_a )
- {
- mbedtls_free( ptr_a );
+ if (free_a) {
+ mbedtls_free(ptr_a);
ptr_a = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
allocated_bytes -= a_bytes * sizeof(char);
}
- if( free_b )
- {
- mbedtls_free( ptr_b );
+ if (free_b) {
+ mbedtls_free(ptr_b);
ptr_b = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
allocated_bytes -= b_bytes * sizeof(char);
}
- if( free_c )
- {
- mbedtls_free( ptr_c );
+ if (free_c) {
+ mbedtls_free(ptr_c);
ptr_c = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
allocated_bytes -= c_bytes * sizeof(char);
}
- if( free_d )
- {
- mbedtls_free( ptr_d );
+ if (free_d) {
+ mbedtls_free(ptr_d);
ptr_d = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
allocated_bytes -= d_bytes * sizeof(char);
}
#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
- TEST_ASSERT( reported_bytes == allocated_bytes );
+ mbedtls_memory_buffer_alloc_cur_get(&reported_bytes, &reported_blocks);
+ TEST_ASSERT(reported_bytes == allocated_bytes);
#endif
- if( e_bytes > 0 )
- {
- ptr_e = mbedtls_calloc( e_bytes, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_e ) == 0 );
+ if (e_bytes > 0) {
+ ptr_e = mbedtls_calloc(e_bytes, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_e) == 0);
}
- if( f_bytes > 0 )
- {
- ptr_f = mbedtls_calloc( f_bytes, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_f ) == 0 );
+ if (f_bytes > 0) {
+ ptr_f = mbedtls_calloc(f_bytes, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_f) == 0);
}
/* Once blocks are reallocated, the block allocated to the memory request
@@ -144,61 +136,55 @@
* bytes, and makes it hard to know what the reported size will be, so
* we don't check the size after blocks have been reallocated. */
- if( ptr_a != NULL )
- {
- mbedtls_free( ptr_a );
+ if (ptr_a != NULL) {
+ mbedtls_free(ptr_a);
ptr_a = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
}
- if( ptr_b != NULL )
- {
- mbedtls_free( ptr_b );
+ if (ptr_b != NULL) {
+ mbedtls_free(ptr_b);
ptr_b = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
}
- if( ptr_c != NULL )
- {
- mbedtls_free( ptr_c );
+ if (ptr_c != NULL) {
+ mbedtls_free(ptr_c);
ptr_c = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
}
- if( ptr_d != NULL )
- {
- mbedtls_free( ptr_d );
+ if (ptr_d != NULL) {
+ mbedtls_free(ptr_d);
ptr_d = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
}
- if( ptr_e != NULL )
- {
- mbedtls_free( ptr_e );
+ if (ptr_e != NULL) {
+ mbedtls_free(ptr_e);
ptr_e = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
}
- if( ptr_f != NULL )
- {
- mbedtls_free( ptr_f );
+ if (ptr_f != NULL) {
+ mbedtls_free(ptr_f);
ptr_f = NULL;
}
#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
- TEST_ASSERT( reported_bytes == 0 );
+ mbedtls_memory_buffer_alloc_cur_get(&reported_bytes, &reported_blocks);
+ TEST_ASSERT(reported_bytes == 0);
#endif
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
exit:
- mbedtls_memory_buffer_alloc_free( );
+ mbedtls_memory_buffer_alloc_free();
}
/* END_CASE */
/* BEGIN_CASE */
-void memory_buffer_alloc_oom_test( )
+void memory_buffer_alloc_oom_test()
{
unsigned char buf[1024];
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL;
@@ -206,71 +192,70 @@
size_t reported_blocks, reported_bytes;
#endif
- (void)ptr_c;
+ (void) ptr_c;
- mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
+ mbedtls_memory_buffer_alloc_init(buf, sizeof(buf));
- mbedtls_memory_buffer_set_verify( MBEDTLS_MEMORY_VERIFY_ALWAYS );
+ mbedtls_memory_buffer_set_verify(MBEDTLS_MEMORY_VERIFY_ALWAYS);
- ptr_a = mbedtls_calloc( 432, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_a ) == 0 );
+ ptr_a = mbedtls_calloc(432, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_a) == 0);
- ptr_b = mbedtls_calloc( 432, sizeof(char) );
- TEST_ASSERT( check_pointer( ptr_b ) == 0 );
+ ptr_b = mbedtls_calloc(432, sizeof(char));
+ TEST_ASSERT(check_pointer(ptr_b) == 0);
- ptr_c = mbedtls_calloc( 431, sizeof(char) );
- TEST_ASSERT( ptr_c == NULL );
+ ptr_c = mbedtls_calloc(431, sizeof(char));
+ TEST_ASSERT(ptr_c == NULL);
#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
- TEST_ASSERT( reported_bytes >= 864 && reported_bytes <= sizeof(buf) );
+ mbedtls_memory_buffer_alloc_cur_get(&reported_bytes, &reported_blocks);
+ TEST_ASSERT(reported_bytes >= 864 && reported_bytes <= sizeof(buf));
#endif
- mbedtls_free( ptr_a );
+ mbedtls_free(ptr_a);
ptr_a = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
- mbedtls_free( ptr_b );
+ mbedtls_free(ptr_b);
ptr_b = NULL;
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
- TEST_ASSERT( reported_bytes == 0 );
+ mbedtls_memory_buffer_alloc_cur_get(&reported_bytes, &reported_blocks);
+ TEST_ASSERT(reported_bytes == 0);
#endif
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
exit:
- mbedtls_memory_buffer_alloc_free( );
+ mbedtls_memory_buffer_alloc_free();
}
/* END_CASE */
/* BEGIN_CASE */
-void memory_buffer_heap_too_small( )
+void memory_buffer_heap_too_small()
{
unsigned char buf[1];
- mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
+ mbedtls_memory_buffer_alloc_init(buf, sizeof(buf));
/* With MBEDTLS_MEMORY_DEBUG enabled, this prints a message
* "FATAL: verification of first header failed".
*/
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() != 0 );
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() != 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void memory_buffer_underalloc( )
+void memory_buffer_underalloc()
{
unsigned char buf[100];
size_t i;
- mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
- for( i = 1; i < MBEDTLS_MEMORY_ALIGN_MULTIPLE; i++ )
- {
- TEST_ASSERT( mbedtls_calloc( 1,
- (size_t)-( MBEDTLS_MEMORY_ALIGN_MULTIPLE - i ) ) == NULL );
- TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
+ mbedtls_memory_buffer_alloc_init(buf, sizeof(buf));
+ for (i = 1; i < MBEDTLS_MEMORY_ALIGN_MULTIPLE; i++) {
+ TEST_ASSERT(mbedtls_calloc(1,
+ (size_t) -(MBEDTLS_MEMORY_ALIGN_MULTIPLE - i)) == NULL);
+ TEST_ASSERT(mbedtls_memory_buffer_alloc_verify() == 0);
}
exit:
diff --git a/tests/suites/test_suite_mps.function b/tests/suites/test_suite_mps.function
index ec1122a..6d9a8a8 100644
--- a/tests/suites/test_suite_mps.function
+++ b/tests/suites/test_suite_mps.function
@@ -25,7 +25,7 @@
*/
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_no_pausing_single_step_single_round( int with_acc )
+void mbedtls_mps_reader_no_pausing_single_step_single_round(int with_acc)
{
/* This test exercises the most basic use of the MPS reader:
* - The 'producing' layer provides a buffer
@@ -46,29 +46,31 @@
unsigned char *tmp;
int paused;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( bufA ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(bufA); i++) {
bufA[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- if( with_acc == 0 )
- mbedtls_mps_reader_init( &rd, NULL, 0 );
- else
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
+ if (with_acc == 0) {
+ mbedtls_mps_reader_init(&rd, NULL, 0);
+ } else {
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ }
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
/* Consume exactly what's available */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 100, bufA, 100 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 100, bufA, 100);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup (lower layer) */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, &paused ) == 0 );
- TEST_ASSERT( paused == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, &paused) == 0);
+ TEST_ASSERT(paused == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_no_pausing_single_step_multiple_rounds( int with_acc )
+void mbedtls_mps_reader_no_pausing_single_step_multiple_rounds(int with_acc)
{
/* This test exercises multiple rounds of the basic use of the MPS reader:
* - The 'producing' layer provides a buffer
@@ -89,37 +91,40 @@
unsigned char acc[10];
unsigned char *tmp;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( bufA ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(bufA); i++) {
bufA[i] = (unsigned char) i;
- for( size_t i=0; (unsigned) i < sizeof( bufB ); i++ )
- bufB[i] = ~ ((unsigned char) i);
+ }
+ for (size_t i = 0; (unsigned) i < sizeof(bufB); i++) {
+ bufB[i] = ~((unsigned char) i);
+ }
/* Preparation (lower layer) */
- if( with_acc == 0 )
- mbedtls_mps_reader_init( &rd, NULL, 0 );
- else
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
+ if (with_acc == 0) {
+ mbedtls_mps_reader_init(&rd, NULL, 0);
+ } else {
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ }
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
/* Consume exactly what's available */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 100, bufA, 100 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 100, bufA, 100);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Preparation */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, sizeof(bufB)) == 0);
/* Consumption */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 100, bufB, 100 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 100, bufB, 100);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup (lower layer) */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_no_pausing_multiple_steps_single_round( int with_acc )
+void mbedtls_mps_reader_no_pausing_multiple_steps_single_round(int with_acc)
{
/* This test exercises one round of the following:
* - The 'producing' layer provides a buffer
@@ -144,31 +149,33 @@
unsigned char *tmp;
mbedtls_mps_size_t tmp_len;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( buf ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(buf); i++) {
buf[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- if( with_acc == 0 )
- mbedtls_mps_reader_init( &rd, NULL, 0 );
- else
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
+ if (with_acc == 0) {
+ mbedtls_mps_reader_init(&rd, NULL, 0);
+ } else {
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ }
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, buf, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 70, buf + 10, 70 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, &tmp_len ) == 0 );
- ASSERT_COMPARE( tmp, tmp_len, buf + 80, 20 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, buf, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 70, buf + 10, 70);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, &tmp_len) == 0);
+ ASSERT_COMPARE(tmp, tmp_len, buf + 80, 20);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup (lower layer) */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_no_pausing_multiple_steps_multiple_rounds( int with_acc )
+void mbedtls_mps_reader_no_pausing_multiple_steps_multiple_rounds(int with_acc)
{
/* This test exercises one round of fetching a buffer in multiple chunks
* and passing it back to the producer afterwards, followed by another
@@ -179,35 +186,38 @@
unsigned char *tmp;
mbedtls_mps_size_t tmp_len;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( bufA ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(bufA); i++) {
bufA[i] = (unsigned char) i;
- for( size_t i=0; (unsigned) i < sizeof( bufB ); i++ )
- bufB[i] = ~ ((unsigned char) i);
+ }
+ for (size_t i = 0; (unsigned) i < sizeof(bufB); i++) {
+ bufB[i] = ~((unsigned char) i);
+ }
/* Preparation (lower layer) */
- if( with_acc == 0 )
- mbedtls_mps_reader_init( &rd, NULL, 0 );
- else
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
+ if (with_acc == 0) {
+ mbedtls_mps_reader_init(&rd, NULL, 0);
+ } else {
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ }
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 70, bufA + 10, 70 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, &tmp_len ) == 0 );
- ASSERT_COMPARE( tmp, tmp_len, bufA + 80, 20 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 70, bufA + 10, 70);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, &tmp_len) == 0);
+ ASSERT_COMPARE(tmp, tmp_len, bufA + 80, 20);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Preparation */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, sizeof(bufB)) == 0);
/* Consumption */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 100, bufB, 100 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 100, bufB, 100);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
@@ -224,22 +234,23 @@
unsigned char buf[100];
unsigned char *tmp;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( buf ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(buf); i++) {
buf[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, NULL, 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, NULL, 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 50, buf, 50 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 50, buf, 50);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Wrapup (lower layer) */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
- MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
+ MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
@@ -264,28 +275,29 @@
mbedtls_mps_reader rd;
mbedtls_mps_size_t tmp_len;
- for( size_t i=0; (unsigned) i < sizeof( buf ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(buf); i++) {
buf[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 50, buf, 50 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, buf + 50, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 50, buf, 50);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, buf + 50, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Wrapup (lower layer) */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
- MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
+ MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL);
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, &tmp_len ) == 0 );
- ASSERT_COMPARE( tmp, tmp_len, buf + 50, 50 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, &tmp_len) == 0);
+ ASSERT_COMPARE(tmp, tmp_len, buf + 50, 50);
- mbedtls_mps_reader_free( &rd );
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
@@ -304,28 +316,29 @@
unsigned char *tmp;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( buf ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(buf); i++) {
buf[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 50, buf, 50 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 50, buf, 50);
/* Excess request */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, (mbedtls_mps_size_t) -1, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, (mbedtls_mps_size_t) -1, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Wrapup (lower layer) */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
- MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
+ MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL);
- mbedtls_mps_reader_free( &rd );
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_pausing( int option )
+void mbedtls_mps_reader_pausing(int option)
{
/* This test exercises the behaviour of the reader when the
* accumulator is used to fulfill a consumer's request.
@@ -349,108 +362,108 @@
unsigned char acc[40];
int paused;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( bufA ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(bufA); i++) {
bufA[i] = (unsigned char) i;
- for( size_t i=0; (unsigned) i < sizeof( bufB ); i++ )
- bufB[i] = ~ ((unsigned char) i);
+ }
+ for (size_t i = 0; (unsigned) i < sizeof(bufB); i++) {
+ bufB[i] = ~((unsigned char) i);
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
/* Ask for more than what's available. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 80, bufA, 80 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- switch( option )
- {
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 80, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 80, bufA, 80);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ switch (option) {
case 0: /* Single uncommitted fetch at pausing */
case 1:
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
break;
default: /* Multiple uncommitted fetches at pausing */
break;
}
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Preparation */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, &paused ) == 0 );
- TEST_ASSERT( paused == 1 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, &paused) == 0);
+ TEST_ASSERT(paused == 1);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, sizeof(bufB)) == 0);
/* Consumption */
- switch( option )
- {
+ switch (option) {
case 0: /* Single fetch at pausing, re-fetch with commit. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
break;
case 1: /* Single fetch at pausing, re-fetch without commit. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
break;
case 2: /* Multiple fetches at pausing, repeat without commit. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
break;
case 3: /* Multiple fetches at pausing, repeat with commit 1. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
break;
case 4: /* Multiple fetches at pausing, repeat with commit 2. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
break;
case 5: /* Multiple fetches at pausing, repeat with commit 3. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
}
/* In all cases, fetch the rest of the second buffer. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 90, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 90, bufB + 10, 90 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 90, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 90, bufB + 10, 90);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_pausing_multiple_feeds( int option )
+void mbedtls_mps_reader_pausing_multiple_feeds(int option)
{
/* This test exercises the behaviour of the MPS reader
* in the following situation:
@@ -471,93 +484,91 @@
unsigned char acc[70];
mbedtls_mps_reader rd;
mbedtls_mps_size_t fetch_len;
- for( size_t i=0; (unsigned) i < sizeof( bufA ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(bufA); i++) {
bufA[i] = (unsigned char) i;
- for( size_t i=0; (unsigned) i < sizeof( bufB ); i++ )
- bufB[i] = ~ ((unsigned char) i);
+ }
+ for (size_t i = 0; (unsigned) i < sizeof(bufB); i++) {
+ bufB[i] = ~((unsigned char) i);
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
/* Ask for more than what's available. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 80, bufA, 80 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 80, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 80, bufA, 80);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* 20 left, ask for 70 -> 50 overhead */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Preparation */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- switch( option )
- {
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ switch (option) {
case 0: /* 10 + 10 + 80 byte feed */
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, 10 ) ==
- MBEDTLS_ERR_MPS_READER_NEED_MORE );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 10, 10 ) ==
- MBEDTLS_ERR_MPS_READER_NEED_MORE );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 20, 80 ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, 10) ==
+ MBEDTLS_ERR_MPS_READER_NEED_MORE);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB + 10, 10) ==
+ MBEDTLS_ERR_MPS_READER_NEED_MORE);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB + 20, 80) == 0);
break;
case 1: /* 50 x 1byte */
- for( size_t num_feed = 0; num_feed < 49; num_feed++ )
- {
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + num_feed, 1 ) ==
- MBEDTLS_ERR_MPS_READER_NEED_MORE );
+ for (size_t num_feed = 0; num_feed < 49; num_feed++) {
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB + num_feed, 1) ==
+ MBEDTLS_ERR_MPS_READER_NEED_MORE);
}
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 49, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB + 49, 1) == 0);
break;
case 2: /* 49 x 1byte + 51bytes */
- for( size_t num_feed = 0; num_feed < 49; num_feed++ )
- {
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + num_feed, 1 ) ==
- MBEDTLS_ERR_MPS_READER_NEED_MORE );
+ for (size_t num_feed = 0; num_feed < 49; num_feed++) {
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB + num_feed, 1) ==
+ MBEDTLS_ERR_MPS_READER_NEED_MORE);
}
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 49, 51 ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB + 49, 51) == 0);
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
break;
}
/* Consumption */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
- ASSERT_COMPARE( tmp + 20, 50, bufB, 50 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 1000, &tmp, &fetch_len ) == 0 );
- switch( option )
- {
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
+ ASSERT_COMPARE(tmp + 20, 50, bufB, 50);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 1000, &tmp, &fetch_len) == 0);
+ switch (option) {
case 0:
- TEST_ASSERT( fetch_len == 50 );
+ TEST_ASSERT(fetch_len == 50);
break;
case 1:
- TEST_ASSERT( fetch_len == 0 );
+ TEST_ASSERT(fetch_len == 0);
break;
case 2:
- TEST_ASSERT( fetch_len == 50 );
+ TEST_ASSERT(fetch_len == 50);
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
break;
}
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_reclaim_data_left( int option )
+void mbedtls_mps_reader_reclaim_data_left(int option)
{
/* This test exercises the behaviour of the MPS reader when a
* call to mbedtls_mps_reader_reclaim() is made before all data
@@ -566,53 +577,53 @@
unsigned char buf[100];
unsigned char *tmp;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( buf ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(buf); i++) {
buf[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, NULL, 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, NULL, 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
- switch( option )
- {
+ switch (option) {
case 0:
/* Fetch (but not commit) the entire buffer. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ), &tmp, NULL )
- == 0 );
- ASSERT_COMPARE( tmp, 100, buf, 100 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf), &tmp, NULL)
+ == 0);
+ ASSERT_COMPARE(tmp, 100, buf, 100);
break;
case 1:
/* Fetch (but not commit) parts of the buffer. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ) / 2,
- &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, sizeof( buf ) / 2, buf, sizeof( buf ) / 2 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf) / 2,
+ &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
break;
case 2:
/* Fetch and commit parts of the buffer, then
* fetch but not commit the rest of the buffer. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ) / 2,
- &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, sizeof( buf ) / 2, buf, sizeof( buf ) / 2 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ) / 2,
- &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, sizeof( buf ) / 2,
- buf + sizeof( buf ) / 2,
- sizeof( buf ) / 2 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf) / 2,
+ &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf) / 2,
+ &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, sizeof(buf) / 2,
+ buf + sizeof(buf) / 2,
+ sizeof(buf) / 2);
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
break;
}
/* Wrapup */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
- MBEDTLS_ERR_MPS_READER_DATA_LEFT );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
+ MBEDTLS_ERR_MPS_READER_DATA_LEFT);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
@@ -626,33 +637,34 @@
unsigned char *tmp;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( buf ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(buf); i++) {
buf[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, NULL, 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, NULL, 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 50, buf, 50 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 50, buf + 50, 50 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 50, buf, 50);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 50, buf + 50, 50);
/* Preparation */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
- MBEDTLS_ERR_MPS_READER_DATA_LEFT );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
+ MBEDTLS_ERR_MPS_READER_DATA_LEFT);
/* Consumption */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 50, buf + 50, 50 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 50, buf + 50, 50);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_mps_reader_multiple_pausing( int option )
+void mbedtls_mps_reader_multiple_pausing(int option)
{
/* This test exercises the behaviour of the MPS reader
* in the following situation:
@@ -670,126 +682,128 @@
unsigned char acc[50];
mbedtls_mps_size_t tmp_len;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( bufA ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(bufA); i++) {
bufA[i] = (unsigned char) i;
- for( size_t i=0; (unsigned) i < sizeof( bufB ); i++ )
- bufB[i] = ~ ((unsigned char) i);
- for( size_t i=0; (unsigned) i < sizeof( bufC ); i++ )
- bufC[i] = ~ ((unsigned char) i);
+ }
+ for (size_t i = 0; (unsigned) i < sizeof(bufB); i++) {
+ bufB[i] = ~((unsigned char) i);
+ }
+ for (size_t i = 0; (unsigned) i < sizeof(bufC); i++) {
+ bufC[i] = ~((unsigned char) i);
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
/* Ask for more than what's available. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 80, bufA, 80 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 80, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 80, bufA, 80);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Preparation */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, sizeof(bufB)) == 0);
- switch( option )
- {
+ switch (option) {
case 0: /* Fetch same chunks, commit afterwards, and
* then exceed bounds of new buffer; accumulator
* large enough. */
/* Consume */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, &tmp_len ) == 0 );
- ASSERT_COMPARE( tmp, tmp_len, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, &tmp_len) == 0);
+ ASSERT_COMPARE(tmp, tmp_len, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Prepare */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufC, sizeof( bufC ) ) == 0 );;
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufC, sizeof(bufC)) == 0);;
/* Consume */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufB + 10, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufC, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufB + 10, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufC, 10);
break;
case 1: /* Fetch same chunks, commit afterwards, and
* then exceed bounds of new buffer; accumulator
* not large enough. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 51, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 51, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Prepare */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
- MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
+ MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL);
break;
case 2: /* Fetch same chunks, don't commit afterwards, and
* then exceed bounds of new buffer; accumulator
* large enough. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Prepare */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufC, sizeof( bufC ) ) == 0 );;
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufC, sizeof(bufC)) == 0);;
/* Consume */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
- ASSERT_COMPARE( tmp + 20, 20, bufB, 20 );
- ASSERT_COMPARE( tmp + 40, 10, bufC, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
+ ASSERT_COMPARE(tmp + 20, 20, bufB, 20);
+ ASSERT_COMPARE(tmp + 40, 10, bufC, 10);
break;
case 3: /* Fetch same chunks, don't commit afterwards, and
* then exceed bounds of new buffer; accumulator
* not large enough. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
- ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 21, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
+ ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 21, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Prepare */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
- MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
+ MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL);
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
break;
}
- mbedtls_mps_reader_free( &rd );
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER:MBEDTLS_MPS_STATE_VALIDATION */
-void mbedtls_mps_reader_random_usage( int num_out_chunks,
- int max_chunk_size,
- int max_request,
- int acc_size )
+void mbedtls_mps_reader_random_usage(int num_out_chunks,
+ int max_chunk_size,
+ int max_request,
+ int acc_size)
{
/* Randomly pass a reader object back and forth between lower and
@@ -829,130 +843,108 @@
* returning the reader to the upper layer. */
mbedtls_mps_reader rd;
- if( acc_size > 0 )
- {
- ASSERT_ALLOC( acc, acc_size );
+ if (acc_size > 0) {
+ ASSERT_ALLOC(acc, acc_size);
}
/* This probably needs to be changed because we want
* our tests to be deterministic. */
// srand( time( NULL ) );
- ASSERT_ALLOC( outgoing, num_out_chunks * max_chunk_size );
- ASSERT_ALLOC( incoming, num_out_chunks * max_chunk_size );
+ ASSERT_ALLOC(outgoing, num_out_chunks * max_chunk_size);
+ ASSERT_ALLOC(incoming, num_out_chunks * max_chunk_size);
- mbedtls_mps_reader_init( &rd, acc, acc_size );
+ mbedtls_mps_reader_init(&rd, acc, acc_size);
cur_out_chunk = 0;
in_commit = 0;
in_fetch = 0;
out_pos = 0;
- while( cur_out_chunk < (unsigned) num_out_chunks )
- {
- if( mode == 0 )
- {
+ while (cur_out_chunk < (unsigned) num_out_chunks) {
+ if (mode == 0) {
/* Choose randomly between reclaim and feed */
rand_op = rand() % 2;
- if( rand_op == 0 )
- {
+ if (rand_op == 0) {
/* Reclaim */
- ret = mbedtls_mps_reader_reclaim( &rd, NULL );
+ ret = mbedtls_mps_reader_reclaim(&rd, NULL);
- if( ret == 0 )
- {
- TEST_ASSERT( cur_chunk != NULL );
- mbedtls_free( cur_chunk );
+ if (ret == 0) {
+ TEST_ASSERT(cur_chunk != NULL);
+ mbedtls_free(cur_chunk);
cur_chunk = NULL;
}
reclaimed = 1;
- }
- else
- {
+ } else {
/* Feed reader with a random chunk */
unsigned char *tmp = NULL;
size_t tmp_size;
- if( cur_out_chunk == (unsigned) num_out_chunks )
+ if (cur_out_chunk == (unsigned) num_out_chunks) {
continue;
+ }
- tmp_size = ( rand() % max_chunk_size ) + 1;
- ASSERT_ALLOC( tmp, tmp_size );
+ tmp_size = (rand() % max_chunk_size) + 1;
+ ASSERT_ALLOC(tmp, tmp_size);
- TEST_ASSERT( mbedtls_test_rnd_std_rand( NULL, tmp, tmp_size ) == 0 );
- ret = mbedtls_mps_reader_feed( &rd, tmp, tmp_size );
+ TEST_ASSERT(mbedtls_test_rnd_std_rand(NULL, tmp, tmp_size) == 0);
+ ret = mbedtls_mps_reader_feed(&rd, tmp, tmp_size);
- if( ret == 0 || ret == MBEDTLS_ERR_MPS_READER_NEED_MORE )
- {
+ if (ret == 0 || ret == MBEDTLS_ERR_MPS_READER_NEED_MORE) {
cur_out_chunk++;
- memcpy( outgoing + out_pos, tmp, tmp_size );
+ memcpy(outgoing + out_pos, tmp, tmp_size);
out_pos += tmp_size;
}
- if( ret == 0 )
- {
- TEST_ASSERT( cur_chunk == NULL );
+ if (ret == 0) {
+ TEST_ASSERT(cur_chunk == NULL);
cur_chunk = tmp;
- }
- else
- {
- mbedtls_free( tmp );
+ } else {
+ mbedtls_free(tmp);
}
}
/* Randomly switch to consumption mode if reclaim
* was called at least once. */
- if( reclaimed == 1 && rand() % 3 == 0 )
- {
+ if (reclaimed == 1 && rand() % 3 == 0) {
in_fetch = 0;
mode = 1;
}
- }
- else
- {
+ } else {
/* Choose randomly between get tolerating fewer data,
* get not tolerating fewer data, and commit. */
rand_op = rand() % 3;
- if( rand_op == 0 || rand_op == 1 )
- {
+ if (rand_op == 0 || rand_op == 1) {
mbedtls_mps_size_t get_size, real_size;
unsigned char *chunk_get;
- get_size = ( rand() % max_request ) + 1;
- if( rand_op == 0 )
- {
- ret = mbedtls_mps_reader_get( &rd, get_size, &chunk_get,
- &real_size );
- }
- else
- {
+ get_size = (rand() % max_request) + 1;
+ if (rand_op == 0) {
+ ret = mbedtls_mps_reader_get(&rd, get_size, &chunk_get,
+ &real_size);
+ } else {
real_size = get_size;
- ret = mbedtls_mps_reader_get( &rd, get_size, &chunk_get, NULL );
+ ret = mbedtls_mps_reader_get(&rd, get_size, &chunk_get, NULL);
}
/* Check if output is in accordance with what was written */
- if( ret == 0 )
- {
- memcpy( incoming + in_commit + in_fetch,
- chunk_get, real_size );
- TEST_ASSERT( memcmp( incoming + in_commit + in_fetch,
- outgoing + in_commit + in_fetch,
- real_size ) == 0 );
+ if (ret == 0) {
+ memcpy(incoming + in_commit + in_fetch,
+ chunk_get, real_size);
+ TEST_ASSERT(memcmp(incoming + in_commit + in_fetch,
+ outgoing + in_commit + in_fetch,
+ real_size) == 0);
in_fetch += real_size;
}
- }
- else if( rand_op == 2 ) /* Commit */
- {
- ret = mbedtls_mps_reader_commit( &rd );
- if( ret == 0 )
- {
+ } else if (rand_op == 2) { /* Commit */
+ ret = mbedtls_mps_reader_commit(&rd);
+ if (ret == 0) {
in_commit += in_fetch;
in_fetch = 0;
}
}
/* Randomly switch back to preparation */
- if( rand() % 3 == 0 )
- {
+ if (rand() % 3 == 0) {
reclaimed = 0;
mode = 0;
}
@@ -960,16 +952,16 @@
}
/* Cleanup */
- mbedtls_mps_reader_free( &rd );
- mbedtls_free( incoming );
- mbedtls_free( outgoing );
- mbedtls_free( acc );
- mbedtls_free( cur_chunk );
+ mbedtls_mps_reader_free(&rd);
+ mbedtls_free(incoming);
+ mbedtls_free(outgoing);
+ mbedtls_free(acc);
+ mbedtls_free(cur_chunk);
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
-void mbedtls_reader_inconsistent_usage( int option )
+void mbedtls_reader_inconsistent_usage(int option)
{
/* This test exercises the behaviour of the MPS reader
* in the following situation:
@@ -989,130 +981,130 @@
unsigned char acc[40];
mbedtls_mps_reader rd;
int success = 0;
- for( size_t i=0; (unsigned) i < sizeof( bufA ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(bufA); i++) {
bufA[i] = (unsigned char) i;
- for( size_t i=0; (unsigned) i < sizeof( bufB ); i++ )
- bufB[i] = ~ ((unsigned char) i);
+ }
+ for (size_t i = 0; (unsigned) i < sizeof(bufB); i++) {
+ bufB[i] = ~((unsigned char) i);
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
+ mbedtls_mps_reader_init(&rd, acc, sizeof(acc));
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 80, &tmp, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Preparation */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, sizeof(bufB)) == 0);
/* Consumption */
- switch( option )
- {
+ switch (option) {
case 0:
/* Ask for buffered data in a single chunk, no commit */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
- ASSERT_COMPARE( tmp + 20, 10, bufB, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
+ ASSERT_COMPARE(tmp + 20, 10, bufB, 10);
success = 1;
break;
case 1:
/* Ask for buffered data in a single chunk, with commit */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
- ASSERT_COMPARE( tmp + 20, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
+ ASSERT_COMPARE(tmp + 20, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
success = 1;
break;
case 2:
/* Ask for more than was requested when pausing, #1 */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 31, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 31, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS);
break;
case 3:
/* Ask for more than was requested when pausing #2 */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, (mbedtls_mps_size_t) -1, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, (mbedtls_mps_size_t) -1, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS);
break;
case 4:
/* Asking for buffered data in different
* chunks than before CAN fail. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) ==
- MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) ==
+ MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS);
break;
case 5:
/* Asking for buffered data different chunks
* than before NEED NOT fail - no commits */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
- ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
+ ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
success = 1;
break;
case 6:
/* Asking for buffered data different chunks
* than before NEED NOT fail - intermediate commit */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
- ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
+ ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
success = 1;
break;
case 7:
/* Asking for buffered data different chunks
* than before NEED NOT fail - end commit */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
- ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
+ ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
success = 1;
break;
case 8:
/* Asking for buffered data different chunks
* than before NEED NOT fail - intermediate & end commit */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
- ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
- ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
+ ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
+ ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
success = 1;
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
break;
}
- if( success == 1 )
- {
+ if (success == 1) {
/* In all succeeding cases, fetch the rest of the second buffer. */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 90, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 90, bufB + 10, 90 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 90, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 90, bufB + 10, 90);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
}
/* Wrapup */
- mbedtls_mps_reader_free( &rd );
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
@@ -1124,25 +1116,26 @@
unsigned char buf[100];
unsigned char *tmp;
mbedtls_mps_reader rd;
- for( size_t i=0; (unsigned) i < sizeof( buf ); i++ )
+ for (size_t i = 0; (unsigned) i < sizeof(buf); i++) {
buf[i] = (unsigned char) i;
+ }
/* Preparation (lower layer) */
- mbedtls_mps_reader_init( &rd, NULL, 0 );
+ mbedtls_mps_reader_init(&rd, NULL, 0);
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, NULL, sizeof( buf ) ) ==
- MBEDTLS_ERR_MPS_READER_INVALID_ARG );
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, NULL, sizeof(buf)) ==
+ MBEDTLS_ERR_MPS_READER_INVALID_ARG);
/* Subsequent feed-calls should still succeed. */
- TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
- TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
- ASSERT_COMPARE( tmp, 100, buf, 100 );
- TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
+ TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
+ ASSERT_COMPARE(tmp, 100, buf, 100);
+ TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
- TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
- mbedtls_mps_reader_free( &rd );
+ TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
+ mbedtls_mps_reader_free(&rd);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_net.function b/tests/suites/test_suite_net.function
index 08d48b3..fa09f5a 100644
--- a/tests/suites/test_suite_net.function
+++ b/tests/suites/test_suite_net.function
@@ -30,19 +30,18 @@
*
* \return \c 0 on success, a negative error code on error.
*/
-static int open_file_on_fd( mbedtls_net_context *ctx, int wanted_fd )
+static int open_file_on_fd(mbedtls_net_context *ctx, int wanted_fd)
{
- int got_fd = open( "/dev/null", O_RDONLY );
- TEST_ASSERT( got_fd >= 0 );
- if( got_fd != wanted_fd )
- {
- TEST_ASSERT( dup2( got_fd, wanted_fd ) >= 0 );
- TEST_ASSERT( close( got_fd ) >= 0 );
+ int got_fd = open("/dev/null", O_RDONLY);
+ TEST_ASSERT(got_fd >= 0);
+ if (got_fd != wanted_fd) {
+ TEST_ASSERT(dup2(got_fd, wanted_fd) >= 0);
+ TEST_ASSERT(close(got_fd) >= 0);
}
ctx->fd = wanted_fd;
- return( 0 );
+ return 0;
exit:
- return( -1 );
+ return -1;
}
#endif /* MBEDTLS_PLATFORM_IS_UNIXLIKE */
@@ -54,16 +53,17 @@
*/
/* BEGIN_CASE */
-void context_init_free( int reinit )
+void context_init_free(int reinit)
{
mbedtls_net_context ctx;
- mbedtls_net_init( &ctx );
- mbedtls_net_free( &ctx );
+ mbedtls_net_init(&ctx);
+ mbedtls_net_free(&ctx);
- if( reinit )
- mbedtls_net_init( &ctx );
- mbedtls_net_free( &ctx );
+ if (reinit) {
+ mbedtls_net_init(&ctx);
+ }
+ mbedtls_net_free(&ctx);
/* This test case always succeeds, functionally speaking. A plausible
* bug might trigger an invalid pointer dereference or a memory leak. */
@@ -72,7 +72,7 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PLATFORM_IS_UNIXLIKE */
-void poll_beyond_fd_setsize( )
+void poll_beyond_fd_setsize()
{
/* Test that mbedtls_net_poll does not misbehave when given a file
* descriptor greater or equal to FD_SETSIZE. This code is specific to
@@ -85,7 +85,7 @@
mbedtls_net_context ctx;
uint8_t buf[1];
- mbedtls_net_init( &ctx );
+ mbedtls_net_init(&ctx);
/* On many systems, by default, the maximum permitted file descriptor
* number is less than FD_SETSIZE. If so, raise the limit if
@@ -99,17 +99,16 @@
* might do); but we don't do such things in our test code, so the unit
* test will run if it can.
*/
- TEST_ASSERT( getrlimit( RLIMIT_NOFILE, &rlim_nofile ) == 0 );
- if( rlim_nofile.rlim_cur < FD_SETSIZE + 1 )
- {
+ TEST_ASSERT(getrlimit(RLIMIT_NOFILE, &rlim_nofile) == 0);
+ if (rlim_nofile.rlim_cur < FD_SETSIZE + 1) {
rlim_t old_rlim_cur = rlim_nofile.rlim_cur;
rlim_nofile.rlim_cur = FD_SETSIZE + 1;
- TEST_ASSUME( setrlimit( RLIMIT_NOFILE, &rlim_nofile ) == 0 );
+ TEST_ASSUME(setrlimit(RLIMIT_NOFILE, &rlim_nofile) == 0);
rlim_nofile.rlim_cur = old_rlim_cur;
restore_rlim_nofile = 1;
}
- TEST_ASSERT( open_file_on_fd( &ctx, FD_SETSIZE ) == 0 );
+ TEST_ASSERT(open_file_on_fd(&ctx, FD_SETSIZE) == 0);
/* In principle, mbedtls_net_poll() with valid arguments should succeed.
* However, we know that on Unix-like platforms (and others), this function
@@ -122,16 +121,17 @@
* is problematic on the particular platform where the code is running,
* a memory sanitizer such as UBSan should catch it.
*/
- ret = mbedtls_net_poll( &ctx, MBEDTLS_NET_POLL_READ, 0 );
- TEST_EQUAL( ret, MBEDTLS_ERR_NET_POLL_FAILED );
+ ret = mbedtls_net_poll(&ctx, MBEDTLS_NET_POLL_READ, 0);
+ TEST_EQUAL(ret, MBEDTLS_ERR_NET_POLL_FAILED);
/* mbedtls_net_recv_timeout() uses select() and fd_set in the same way. */
- ret = mbedtls_net_recv_timeout( &ctx, buf, sizeof( buf ), 0 );
- TEST_EQUAL( ret, MBEDTLS_ERR_NET_POLL_FAILED );
+ ret = mbedtls_net_recv_timeout(&ctx, buf, sizeof(buf), 0);
+ TEST_EQUAL(ret, MBEDTLS_ERR_NET_POLL_FAILED);
exit:
- mbedtls_net_free( &ctx );
- if( restore_rlim_nofile )
- setrlimit( RLIMIT_NOFILE, &rlim_nofile );
+ mbedtls_net_free(&ctx);
+ if (restore_rlim_nofile) {
+ setrlimit(RLIMIT_NOFILE, &rlim_nofile);
+ }
}
/* END_CASE */
diff --git a/tests/suites/test_suite_nist_kw.function b/tests/suites/test_suite_nist_kw.function
index 6a81052..f2b7944 100644
--- a/tests/suites/test_suite_nist_kw.function
+++ b/tests/suites/test_suite_nist_kw.function
@@ -8,14 +8,14 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
-void mbedtls_nist_kw_self_test( )
+void mbedtls_nist_kw_self_test()
{
- TEST_ASSERT( mbedtls_nist_kw_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
-void mbedtls_nist_kw_mix_contexts( )
+void mbedtls_nist_kw_mix_contexts()
{
mbedtls_nist_kw_context ctx1, ctx2;
unsigned char key[16];
@@ -24,129 +24,126 @@
unsigned char ciphertext2[40];
size_t output_len, i;
- memset( plaintext, 0, sizeof( plaintext ) );
- memset( ciphertext1, 0, sizeof( ciphertext1 ) );
- memset( ciphertext2, 0, sizeof( ciphertext2 ) );
- memset( key, 0, sizeof( key ) );
+ memset(plaintext, 0, sizeof(plaintext));
+ memset(ciphertext1, 0, sizeof(ciphertext1));
+ memset(ciphertext2, 0, sizeof(ciphertext2));
+ memset(key, 0, sizeof(key));
/*
* 1. Check wrap and unwrap with two separate contexts
*/
- mbedtls_nist_kw_init( &ctx1 );
- mbedtls_nist_kw_init( &ctx2 );
+ mbedtls_nist_kw_init(&ctx1);
+ mbedtls_nist_kw_init(&ctx2);
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx1,
- MBEDTLS_CIPHER_ID_AES,
- key, sizeof( key ) * 8,
- 1 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx1,
+ MBEDTLS_CIPHER_ID_AES,
+ key, sizeof(key) * 8,
+ 1) == 0);
- TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx1, MBEDTLS_KW_MODE_KW,
- plaintext, sizeof( plaintext ),
- ciphertext1, &output_len,
- sizeof( ciphertext1 ) ) == 0 );
- TEST_ASSERT( output_len == sizeof( ciphertext1 ) );
+ TEST_ASSERT(mbedtls_nist_kw_wrap(&ctx1, MBEDTLS_KW_MODE_KW,
+ plaintext, sizeof(plaintext),
+ ciphertext1, &output_len,
+ sizeof(ciphertext1)) == 0);
+ TEST_ASSERT(output_len == sizeof(ciphertext1));
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx2,
- MBEDTLS_CIPHER_ID_AES,
- key, sizeof( key ) * 8,
- 0 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx2,
+ MBEDTLS_CIPHER_ID_AES,
+ key, sizeof(key) * 8,
+ 0) == 0);
- TEST_ASSERT( mbedtls_nist_kw_unwrap( &ctx2, MBEDTLS_KW_MODE_KW,
- ciphertext1, output_len,
- plaintext, &output_len,
- sizeof( plaintext ) ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_unwrap(&ctx2, MBEDTLS_KW_MODE_KW,
+ ciphertext1, output_len,
+ plaintext, &output_len,
+ sizeof(plaintext)) == 0);
- TEST_ASSERT( output_len == sizeof( plaintext ) );
- for( i = 0; i < sizeof( plaintext ); i++ )
- {
- TEST_ASSERT( plaintext[i] == 0 );
+ TEST_ASSERT(output_len == sizeof(plaintext));
+ for (i = 0; i < sizeof(plaintext); i++) {
+ TEST_ASSERT(plaintext[i] == 0);
}
- mbedtls_nist_kw_free( &ctx1 );
- mbedtls_nist_kw_free( &ctx2 );
+ mbedtls_nist_kw_free(&ctx1);
+ mbedtls_nist_kw_free(&ctx2);
/*
* 2. Check wrapping with two modes, on same context
*/
- mbedtls_nist_kw_init( &ctx1 );
- mbedtls_nist_kw_init( &ctx2 );
- output_len = sizeof( ciphertext1 );
+ mbedtls_nist_kw_init(&ctx1);
+ mbedtls_nist_kw_init(&ctx2);
+ output_len = sizeof(ciphertext1);
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx1,
- MBEDTLS_CIPHER_ID_AES,
- key, sizeof( key ) * 8,
- 1 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx1,
+ MBEDTLS_CIPHER_ID_AES,
+ key, sizeof(key) * 8,
+ 1) == 0);
- TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx1, MBEDTLS_KW_MODE_KW,
- plaintext, sizeof( plaintext ),
- ciphertext1, &output_len,
- sizeof( ciphertext1 ) ) == 0 );
- TEST_ASSERT( output_len == sizeof( ciphertext1 ) );
+ TEST_ASSERT(mbedtls_nist_kw_wrap(&ctx1, MBEDTLS_KW_MODE_KW,
+ plaintext, sizeof(plaintext),
+ ciphertext1, &output_len,
+ sizeof(ciphertext1)) == 0);
+ TEST_ASSERT(output_len == sizeof(ciphertext1));
- TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx1, MBEDTLS_KW_MODE_KWP,
- plaintext, sizeof( plaintext ),
- ciphertext2, &output_len,
- sizeof( ciphertext2 ) ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_wrap(&ctx1, MBEDTLS_KW_MODE_KWP,
+ plaintext, sizeof(plaintext),
+ ciphertext2, &output_len,
+ sizeof(ciphertext2)) == 0);
- TEST_ASSERT( output_len == sizeof( ciphertext2 ) );
+ TEST_ASSERT(output_len == sizeof(ciphertext2));
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx2,
- MBEDTLS_CIPHER_ID_AES,
- key, sizeof( key ) * 8,
- 0 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx2,
+ MBEDTLS_CIPHER_ID_AES,
+ key, sizeof(key) * 8,
+ 0) == 0);
- TEST_ASSERT( mbedtls_nist_kw_unwrap( &ctx2, MBEDTLS_KW_MODE_KW,
- ciphertext1, sizeof( ciphertext1 ),
- plaintext, &output_len,
- sizeof( plaintext ) ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_unwrap(&ctx2, MBEDTLS_KW_MODE_KW,
+ ciphertext1, sizeof(ciphertext1),
+ plaintext, &output_len,
+ sizeof(plaintext)) == 0);
- TEST_ASSERT( output_len == sizeof( plaintext ) );
+ TEST_ASSERT(output_len == sizeof(plaintext));
- for( i = 0; i < sizeof( plaintext ); i++ )
- {
- TEST_ASSERT( plaintext[i] == 0 );
+ for (i = 0; i < sizeof(plaintext); i++) {
+ TEST_ASSERT(plaintext[i] == 0);
}
- TEST_ASSERT( mbedtls_nist_kw_unwrap( &ctx2, MBEDTLS_KW_MODE_KWP,
- ciphertext2, sizeof( ciphertext2 ),
- plaintext, &output_len,
- sizeof( plaintext ) ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_unwrap(&ctx2, MBEDTLS_KW_MODE_KWP,
+ ciphertext2, sizeof(ciphertext2),
+ plaintext, &output_len,
+ sizeof(plaintext)) == 0);
- TEST_ASSERT( output_len == sizeof( plaintext ) );
+ TEST_ASSERT(output_len == sizeof(plaintext));
- for( i = 0; i < sizeof( plaintext ); i++ )
- {
- TEST_ASSERT( plaintext[i] == 0 );
+ for (i = 0; i < sizeof(plaintext); i++) {
+ TEST_ASSERT(plaintext[i] == 0);
}
exit:
- mbedtls_nist_kw_free( &ctx1 );
- mbedtls_nist_kw_free( &ctx2 );
+ mbedtls_nist_kw_free(&ctx1);
+ mbedtls_nist_kw_free(&ctx2);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_nist_kw_setkey( int cipher_id, int key_size,
- int is_wrap, int result )
+void mbedtls_nist_kw_setkey(int cipher_id, int key_size,
+ int is_wrap, int result)
{
mbedtls_nist_kw_context ctx;
unsigned char key[32];
int ret;
- mbedtls_nist_kw_init( &ctx );
+ mbedtls_nist_kw_init(&ctx);
- memset( key, 0x2A, sizeof( key ) );
- TEST_ASSERT( (unsigned) key_size <= 8 * sizeof( key ) );
+ memset(key, 0x2A, sizeof(key));
+ TEST_ASSERT((unsigned) key_size <= 8 * sizeof(key));
- ret = mbedtls_nist_kw_setkey( &ctx, cipher_id, key, key_size, is_wrap );
- TEST_ASSERT( ret == result );
+ ret = mbedtls_nist_kw_setkey(&ctx, cipher_id, key, key_size, is_wrap);
+ TEST_ASSERT(ret == result);
exit:
- mbedtls_nist_kw_free( &ctx );
+ mbedtls_nist_kw_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
-void nist_kw_plaintext_lengths( int in_len, int out_len, int mode, int res )
+void nist_kw_plaintext_lengths(int in_len, int out_len, int mode, int res)
{
mbedtls_nist_kw_context ctx;
unsigned char key[16];
@@ -154,50 +151,46 @@
unsigned char *ciphertext = NULL;
size_t output_len = out_len;
- mbedtls_nist_kw_init( &ctx );
+ mbedtls_nist_kw_init(&ctx);
- memset( key, 0, sizeof( key ) );
+ memset(key, 0, sizeof(key));
- if( in_len != 0 )
- {
- plaintext = mbedtls_calloc( 1, in_len );
- TEST_ASSERT( plaintext != NULL );
+ if (in_len != 0) {
+ plaintext = mbedtls_calloc(1, in_len);
+ TEST_ASSERT(plaintext != NULL);
}
- if( out_len != 0 )
- {
- ciphertext = mbedtls_calloc( 1, output_len );
- TEST_ASSERT( ciphertext != NULL );
+ if (out_len != 0) {
+ ciphertext = mbedtls_calloc(1, output_len);
+ TEST_ASSERT(ciphertext != NULL);
}
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES,
- key, 8 * sizeof( key ), 1 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx, MBEDTLS_CIPHER_ID_AES,
+ key, 8 * sizeof(key), 1) == 0);
- TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx, mode, plaintext, in_len,
- ciphertext, &output_len,
- output_len ) == res );
- if( res == 0 )
- {
- if( mode == MBEDTLS_KW_MODE_KWP )
- TEST_ASSERT( output_len == (size_t) in_len + 8 -
- ( in_len % 8 ) + 8 );
- else
- TEST_ASSERT( output_len == (size_t) in_len + 8 );
- }
- else
- {
- TEST_ASSERT( output_len == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_wrap(&ctx, mode, plaintext, in_len,
+ ciphertext, &output_len,
+ output_len) == res);
+ if (res == 0) {
+ if (mode == MBEDTLS_KW_MODE_KWP) {
+ TEST_ASSERT(output_len == (size_t) in_len + 8 -
+ (in_len % 8) + 8);
+ } else {
+ TEST_ASSERT(output_len == (size_t) in_len + 8);
+ }
+ } else {
+ TEST_ASSERT(output_len == 0);
}
exit:
- mbedtls_free( ciphertext );
- mbedtls_free( plaintext );
- mbedtls_nist_kw_free( &ctx );
+ mbedtls_free(ciphertext);
+ mbedtls_free(plaintext);
+ mbedtls_nist_kw_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
-void nist_kw_ciphertext_lengths( int in_len, int out_len, int mode, int res )
+void nist_kw_ciphertext_lengths(int in_len, int out_len, int mode, int res)
{
mbedtls_nist_kw_context ctx;
unsigned char key[16];
@@ -206,111 +199,105 @@
int unwrap_ret;
size_t output_len = out_len;
- mbedtls_nist_kw_init( &ctx );
+ mbedtls_nist_kw_init(&ctx);
- memset( key, 0, sizeof( key ) );
+ memset(key, 0, sizeof(key));
- if( out_len != 0 )
- {
- plaintext = mbedtls_calloc( 1, output_len );
- TEST_ASSERT( plaintext != NULL );
+ if (out_len != 0) {
+ plaintext = mbedtls_calloc(1, output_len);
+ TEST_ASSERT(plaintext != NULL);
}
- if( in_len != 0 )
- {
- ciphertext = mbedtls_calloc( 1, in_len );
- TEST_ASSERT( ciphertext != NULL );
+ if (in_len != 0) {
+ ciphertext = mbedtls_calloc(1, in_len);
+ TEST_ASSERT(ciphertext != NULL);
}
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES,
- key, 8 * sizeof( key ), 0 ) == 0 );
- unwrap_ret = mbedtls_nist_kw_unwrap( &ctx, mode, ciphertext, in_len,
- plaintext, &output_len,
- output_len );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx, MBEDTLS_CIPHER_ID_AES,
+ key, 8 * sizeof(key), 0) == 0);
+ unwrap_ret = mbedtls_nist_kw_unwrap(&ctx, mode, ciphertext, in_len,
+ plaintext, &output_len,
+ output_len);
- if( res == 0 )
- TEST_ASSERT( unwrap_ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED );
- else
- TEST_ASSERT( unwrap_ret == res );
+ if (res == 0) {
+ TEST_ASSERT(unwrap_ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED);
+ } else {
+ TEST_ASSERT(unwrap_ret == res);
+ }
- TEST_ASSERT( output_len == 0 );
+ TEST_ASSERT(output_len == 0);
exit:
- mbedtls_free( ciphertext );
- mbedtls_free( plaintext );
- mbedtls_nist_kw_free( &ctx );
+ mbedtls_free(ciphertext);
+ mbedtls_free(plaintext);
+ mbedtls_nist_kw_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_nist_kw_wrap( int cipher_id, int mode, data_t *key, data_t *msg,
- data_t *expected_result )
+void mbedtls_nist_kw_wrap(int cipher_id, int mode, data_t *key, data_t *msg,
+ data_t *expected_result)
{
unsigned char result[528];
mbedtls_nist_kw_context ctx;
size_t result_len, i, padlen;
- mbedtls_nist_kw_init( &ctx );
+ mbedtls_nist_kw_init(&ctx);
- memset( result, '+', sizeof( result ) );
+ memset(result, '+', sizeof(result));
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, cipher_id,
- key->x, key->len * 8, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx, cipher_id,
+ key->x, key->len * 8, 1) == 0);
/* Test with input == output */
- TEST_ASSERT( mbedtls_nist_kw_wrap( &ctx, mode, msg->x, msg->len,
- result, &result_len, sizeof( result ) ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_wrap(&ctx, mode, msg->x, msg->len,
+ result, &result_len, sizeof(result)) == 0);
- TEST_ASSERT( result_len == expected_result->len );
+ TEST_ASSERT(result_len == expected_result->len);
- TEST_ASSERT( memcmp( expected_result->x, result, result_len ) == 0 );
+ TEST_ASSERT(memcmp(expected_result->x, result, result_len) == 0);
- padlen = ( msg->len % 8 != 0 ) ? 8 - (msg->len % 8 ) : 0;
+ padlen = (msg->len % 8 != 0) ? 8 - (msg->len % 8) : 0;
/* Check that the function didn't write beyond the end of the buffer. */
- for( i = msg->len + 8 + padlen; i < sizeof( result ); i++ )
- {
- TEST_ASSERT( result[i] == '+' );
+ for (i = msg->len + 8 + padlen; i < sizeof(result); i++) {
+ TEST_ASSERT(result[i] == '+');
}
exit:
- mbedtls_nist_kw_free( &ctx );
+ mbedtls_nist_kw_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_nist_kw_unwrap( int cipher_id, int mode, data_t *key, data_t *msg,
- data_t *expected_result, int expected_ret )
+void mbedtls_nist_kw_unwrap(int cipher_id, int mode, data_t *key, data_t *msg,
+ data_t *expected_result, int expected_ret)
{
unsigned char result[528];
mbedtls_nist_kw_context ctx;
size_t result_len, i;
- mbedtls_nist_kw_init( &ctx );
+ mbedtls_nist_kw_init(&ctx);
- memset( result, '+', sizeof( result ) );
+ memset(result, '+', sizeof(result));
- TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, cipher_id,
- key->x, key->len * 8, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_setkey(&ctx, cipher_id,
+ key->x, key->len * 8, 0) == 0);
/* Test with input == output */
- TEST_ASSERT( mbedtls_nist_kw_unwrap( &ctx, mode, msg->x, msg->len,
- result, &result_len, sizeof( result ) ) == expected_ret );
- if( expected_ret == 0 )
- {
- TEST_ASSERT( result_len == expected_result->len );
- TEST_ASSERT( memcmp( expected_result->x, result, result_len ) == 0 );
- }
- else
- {
- TEST_ASSERT( result_len == 0 );
+ TEST_ASSERT(mbedtls_nist_kw_unwrap(&ctx, mode, msg->x, msg->len,
+ result, &result_len, sizeof(result)) == expected_ret);
+ if (expected_ret == 0) {
+ TEST_ASSERT(result_len == expected_result->len);
+ TEST_ASSERT(memcmp(expected_result->x, result, result_len) == 0);
+ } else {
+ TEST_ASSERT(result_len == 0);
}
/* Check that the function didn't write beyond the end of the buffer. */
- for( i = msg->len - 8; i < sizeof( result ); i++ )
- {
- TEST_ASSERT( result[i] == '+' );
+ for (i = msg->len - 8; i < sizeof(result); i++) {
+ TEST_ASSERT(result[i] == '+');
}
exit:
- mbedtls_nist_kw_free( &ctx );
+ mbedtls_nist_kw_free(&ctx);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_oid.function b/tests/suites/test_suite_oid.function
index b06f524..687b216 100644
--- a/tests/suites/test_suite_oid.function
+++ b/tests/suites/test_suite_oid.function
@@ -12,7 +12,7 @@
*/
/* BEGIN_CASE */
-void oid_get_certificate_policies( data_t *oid, char *result_str )
+void oid_get_certificate_policies(data_t *oid, char *result_str)
{
mbedtls_asn1_buf asn1_buf = { 0, 0, NULL };
int ret;
@@ -22,21 +22,18 @@
asn1_buf.p = oid->x;
asn1_buf.len = oid->len;
- ret = mbedtls_oid_get_certificate_policies( &asn1_buf, &desc );
- if( strlen( result_str ) == 0 )
- {
- TEST_ASSERT( ret == MBEDTLS_ERR_OID_NOT_FOUND );
- }
- else
- {
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( strcmp( ( char* )desc, result_str ) == 0 );
+ ret = mbedtls_oid_get_certificate_policies(&asn1_buf, &desc);
+ if (strlen(result_str) == 0) {
+ TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
+ } else {
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(strcmp((char *) desc, result_str) == 0);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void oid_get_extended_key_usage( data_t *oid, char *result_str )
+void oid_get_extended_key_usage(data_t *oid, char *result_str)
{
mbedtls_asn1_buf asn1_buf = { 0, 0, NULL };
int ret;
@@ -46,21 +43,18 @@
asn1_buf.p = oid->x;
asn1_buf.len = oid->len;
- ret = mbedtls_oid_get_extended_key_usage( &asn1_buf, &desc );
- if( strlen( result_str ) == 0 )
- {
- TEST_ASSERT( ret == MBEDTLS_ERR_OID_NOT_FOUND );
- }
- else
- {
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( strcmp( ( char * )desc, result_str ) == 0 );
+ ret = mbedtls_oid_get_extended_key_usage(&asn1_buf, &desc);
+ if (strlen(result_str) == 0) {
+ TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
+ } else {
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(strcmp((char *) desc, result_str) == 0);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void oid_get_x509_extension( data_t *oid, int exp_type )
+void oid_get_x509_extension(data_t *oid, int exp_type)
{
mbedtls_asn1_buf ext_oid = { 0, 0, NULL };
int ret;
@@ -70,21 +64,18 @@
ext_oid.p = oid->x;
ext_oid.len = oid->len;
- ret = mbedtls_oid_get_x509_ext_type( &ext_oid, &ext_type );
- if( exp_type == 0 )
- {
- TEST_ASSERT( ret == MBEDTLS_ERR_OID_NOT_FOUND );
- }
- else
- {
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( ext_type == exp_type );
+ ret = mbedtls_oid_get_x509_ext_type(&ext_oid, &ext_type);
+ if (exp_type == 0) {
+ TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
+ } else {
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(ext_type == exp_type);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void oid_get_md_alg_id( data_t *oid, int exp_md_id )
+void oid_get_md_alg_id(data_t *oid, int exp_md_id)
{
mbedtls_asn1_buf md_oid = { 0, 0, NULL };
int ret;
@@ -94,17 +85,14 @@
md_oid.p = oid->x;
md_oid.len = oid->len;
- ret = mbedtls_oid_get_md_alg( &md_oid, &md_id );
+ ret = mbedtls_oid_get_md_alg(&md_oid, &md_id);
- if( exp_md_id < 0 )
- {
- TEST_ASSERT( ret == MBEDTLS_ERR_OID_NOT_FOUND );
- TEST_ASSERT( md_id == 0);
- }
- else
- {
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( (mbedtls_md_type_t)exp_md_id == md_id );
+ if (exp_md_id < 0) {
+ TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
+ TEST_ASSERT(md_id == 0);
+ } else {
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT((mbedtls_md_type_t) exp_md_id == md_id);
}
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pem.function b/tests/suites/test_suite_pem.function
index 6328247..25b66f8 100644
--- a/tests/suites/test_suite_pem.function
+++ b/tests/suites/test_suite_pem.function
@@ -8,56 +8,57 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
-void mbedtls_pem_write_buffer( char * start, char * end, data_t * buf,
- char * result_str )
+void mbedtls_pem_write_buffer(char *start, char *end, data_t *buf,
+ char *result_str)
{
unsigned char *check_buf = NULL;
int ret;
size_t olen = 0, olen2 = 0;
- ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, NULL, 0, &olen );
- TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
+ ret = mbedtls_pem_write_buffer(start, end, buf->x, buf->len, NULL, 0, &olen);
+ TEST_ASSERT(ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL);
- check_buf = (unsigned char *) mbedtls_calloc( 1, olen );
- TEST_ASSERT( check_buf != NULL );
+ check_buf = (unsigned char *) mbedtls_calloc(1, olen);
+ TEST_ASSERT(check_buf != NULL);
- ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, check_buf, olen, &olen2 );
+ ret = mbedtls_pem_write_buffer(start, end, buf->x, buf->len, check_buf, olen, &olen2);
- TEST_ASSERT( olen2 <= olen );
- TEST_ASSERT( olen > strlen( (char*) result_str ) );
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( strncmp( (char *) check_buf, (char *) result_str, olen ) == 0 );
+ TEST_ASSERT(olen2 <= olen);
+ TEST_ASSERT(olen > strlen((char *) result_str));
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(strncmp((char *) check_buf, (char *) result_str, olen) == 0);
exit:
- mbedtls_free( check_buf );
+ mbedtls_free(check_buf);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PEM_PARSE_C */
-void mbedtls_pem_read_buffer( char *header, char *footer, char *data,
- char *pwd, int res, data_t *out )
+void mbedtls_pem_read_buffer(char *header, char *footer, char *data,
+ char *pwd, int res, data_t *out)
{
mbedtls_pem_context ctx;
int ret;
size_t use_len = 0;
- size_t pwd_len = strlen( pwd );
+ size_t pwd_len = strlen(pwd);
const unsigned char *buf;
- mbedtls_pem_init( &ctx );
+ mbedtls_pem_init(&ctx);
- ret = mbedtls_pem_read_buffer( &ctx, header, footer, (unsigned char *)data,
- (unsigned char *)pwd, pwd_len, &use_len );
- TEST_ASSERT( ret == res );
- if( ret != 0 )
+ ret = mbedtls_pem_read_buffer(&ctx, header, footer, (unsigned char *) data,
+ (unsigned char *) pwd, pwd_len, &use_len);
+ TEST_ASSERT(ret == res);
+ if (ret != 0) {
goto exit;
+ }
use_len = 0;
- buf = mbedtls_pem_get_buffer( &ctx, &use_len );
- TEST_EQUAL( use_len, out->len );
- TEST_ASSERT( memcmp( out->x, buf, out->len ) == 0 );
+ buf = mbedtls_pem_get_buffer(&ctx, &use_len);
+ TEST_EQUAL(use_len, out->len);
+ TEST_ASSERT(memcmp(out->x, buf, out->len) == 0);
exit:
- mbedtls_pem_free( &ctx );
+ mbedtls_pem_free(&ctx);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function
index beb3e7c..13b5162 100644
--- a/tests/suites/test_suite_pk.function
+++ b/tests/suites/test_suite_pk.function
@@ -32,59 +32,60 @@
* generation function.
* \return -1 if the key type is not recognized.
*/
-static int pk_genkey( mbedtls_pk_context *pk, int parameter )
+static int pk_genkey(mbedtls_pk_context *pk, int parameter)
{
((void) pk);
(void) parameter;
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
- if( mbedtls_pk_get_type( pk ) == MBEDTLS_PK_RSA )
- return mbedtls_rsa_gen_key( mbedtls_pk_rsa( *pk ),
- mbedtls_test_rnd_std_rand, NULL,
- parameter, 3 );
-#endif
-#if defined(MBEDTLS_ECP_C)
- if( mbedtls_pk_get_type( pk ) == MBEDTLS_PK_ECKEY ||
- mbedtls_pk_get_type( pk ) == MBEDTLS_PK_ECKEY_DH ||
- mbedtls_pk_get_type( pk ) == MBEDTLS_PK_ECDSA )
- {
- int ret;
- if( ( ret = mbedtls_ecp_group_load( &mbedtls_pk_ec( *pk )->grp,
- parameter ) ) != 0 )
- return( ret );
-
- return mbedtls_ecp_gen_keypair( &mbedtls_pk_ec( *pk )->grp,
- &mbedtls_pk_ec( *pk )->d,
- &mbedtls_pk_ec( *pk )->Q,
- mbedtls_test_rnd_std_rand, NULL );
+ if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_RSA) {
+ return mbedtls_rsa_gen_key(mbedtls_pk_rsa(*pk),
+ mbedtls_test_rnd_std_rand, NULL,
+ parameter, 3);
}
#endif
- return( -1 );
+#if defined(MBEDTLS_ECP_C)
+ if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_ECKEY ||
+ mbedtls_pk_get_type(pk) == MBEDTLS_PK_ECKEY_DH ||
+ mbedtls_pk_get_type(pk) == MBEDTLS_PK_ECDSA) {
+ int ret;
+ if ((ret = mbedtls_ecp_group_load(&mbedtls_pk_ec(*pk)->grp,
+ parameter)) != 0) {
+ return ret;
+ }
+
+ return mbedtls_ecp_gen_keypair(&mbedtls_pk_ec(*pk)->grp,
+ &mbedtls_pk_ec(*pk)->d,
+ &mbedtls_pk_ec(*pk)->Q,
+ mbedtls_test_rnd_std_rand, NULL);
+ }
+#endif
+ return -1;
}
#if defined(MBEDTLS_RSA_C)
-int mbedtls_rsa_decrypt_func( void *ctx, size_t *olen,
- const unsigned char *input, unsigned char *output,
- size_t output_max_len )
+int mbedtls_rsa_decrypt_func(void *ctx, size_t *olen,
+ const unsigned char *input, unsigned char *output,
+ size_t output_max_len)
{
- return( mbedtls_rsa_pkcs1_decrypt( (mbedtls_rsa_context *) ctx,
- mbedtls_test_rnd_std_rand, NULL,
- olen, input, output, output_max_len ) );
+ return mbedtls_rsa_pkcs1_decrypt((mbedtls_rsa_context *) ctx,
+ mbedtls_test_rnd_std_rand, NULL,
+ olen, input, output, output_max_len);
}
-int mbedtls_rsa_sign_func( void *ctx,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- mbedtls_md_type_t md_alg, unsigned int hashlen,
- const unsigned char *hash, unsigned char *sig )
+int mbedtls_rsa_sign_func(void *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+ mbedtls_md_type_t md_alg, unsigned int hashlen,
+ const unsigned char *hash, unsigned char *sig)
{
((void) f_rng);
((void) p_rng);
- return( mbedtls_rsa_pkcs1_sign( (mbedtls_rsa_context *) ctx,
- mbedtls_test_rnd_std_rand, NULL,
- md_alg, hashlen, hash, sig ) );
+ return mbedtls_rsa_pkcs1_sign((mbedtls_rsa_context *) ctx,
+ mbedtls_test_rnd_std_rand, NULL,
+ md_alg, hashlen, hash, sig);
}
-size_t mbedtls_rsa_key_len_func( void *ctx )
+size_t mbedtls_rsa_key_len_func(void *ctx)
{
- return( ((const mbedtls_rsa_context *) ctx)->len );
+ return ((const mbedtls_rsa_context *) ctx)->len;
}
#endif /* MBEDTLS_RSA_C */
@@ -95,43 +96,43 @@
* or 0 if the key generation failed.
* The key uses NIST P-256 and is usable for signing with SHA-256.
*/
-mbedtls_svc_key_id_t pk_psa_genkey_ecc( void )
+mbedtls_svc_key_id_t pk_psa_genkey_ecc(void)
{
mbedtls_svc_key_id_t key;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const psa_key_type_t type =
- PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 );
+ PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1);
const size_t bits = 256;
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, PSA_ALG_ECDSA(PSA_ALG_SHA_256) );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
- PSA_ASSERT( psa_generate_key( &attributes, &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, PSA_ALG_ECDSA(PSA_ALG_SHA_256));
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
+ PSA_ASSERT(psa_generate_key(&attributes, &key));
exit:
- return( key );
+ return key;
}
/*
* Generate an RSA key using PSA and return the key identifier of that key,
* or 0 if the key generation failed.
*/
-mbedtls_svc_key_id_t pk_psa_genkey_rsa( void )
+mbedtls_svc_key_id_t pk_psa_genkey_rsa(void)
{
mbedtls_svc_key_id_t key;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const psa_key_type_t type = PSA_KEY_TYPE_RSA_KEY_PAIR;
const size_t bits = 1024;
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, PSA_ALG_RSA_PKCS1V15_SIGN_RAW );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
- PSA_ASSERT( psa_generate_key( &attributes, &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, PSA_ALG_RSA_PKCS1V15_SIGN_RAW);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
+ PSA_ASSERT(psa_generate_key(&attributes, &key));
exit:
- return( key );
+ return key;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* END_HEADER */
@@ -142,7 +143,7 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_USE_PSA_CRYPTO */
-void pk_psa_utils( int key_is_rsa )
+void pk_psa_utils(int key_is_rsa)
{
mbedtls_pk_context pk, pk2;
mbedtls_svc_key_id_t key;
@@ -156,146 +157,140 @@
size_t len;
mbedtls_pk_debug_item dbg;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- mbedtls_pk_init( &pk );
- mbedtls_pk_init( &pk2 );
+ mbedtls_pk_init(&pk);
+ mbedtls_pk_init(&pk2);
- TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
+ TEST_ASSERT(psa_crypto_init() == PSA_SUCCESS);
- TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, MBEDTLS_SVC_KEY_ID_INIT ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_setup_opaque(&pk, MBEDTLS_SVC_KEY_ID_INIT) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
- mbedtls_pk_free( &pk );
- mbedtls_pk_init( &pk );
+ mbedtls_pk_free(&pk);
+ mbedtls_pk_init(&pk);
- if( key_is_rsa )
- {
+ if (key_is_rsa) {
bitlen = 1024; /* hardcoded in genkey() */
key = pk_psa_genkey_rsa();
- }
- else
- {
+ } else {
bitlen = 256; /* hardcoded in genkey() */
key = pk_psa_genkey_ecc();
}
- if( mbedtls_svc_key_id_is_null( key ) )
+ if (mbedtls_svc_key_id_is_null(key)) {
goto exit;
-
- TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, key ) == 0 );
-
- TEST_ASSERT( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_OPAQUE );
- TEST_ASSERT( strcmp( mbedtls_pk_get_name( &pk), name ) == 0 );
-
- TEST_ASSERT( mbedtls_pk_get_bitlen( &pk ) == bitlen );
- TEST_ASSERT( mbedtls_pk_get_len( &pk ) == bitlen / 8 );
-
- if( key_is_rsa )
- {
- TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_ECKEY ) == 0 );
- TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_ECDSA ) == 0 );
- TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_RSA ) == 1 );
}
- else
- {
- TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_ECKEY ) == 1 );
- TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_ECDSA ) == 1 );
- TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_RSA ) == 0 );
+
+ TEST_ASSERT(mbedtls_pk_setup_opaque(&pk, key) == 0);
+
+ TEST_ASSERT(mbedtls_pk_get_type(&pk) == MBEDTLS_PK_OPAQUE);
+ TEST_ASSERT(strcmp(mbedtls_pk_get_name(&pk), name) == 0);
+
+ TEST_ASSERT(mbedtls_pk_get_bitlen(&pk) == bitlen);
+ TEST_ASSERT(mbedtls_pk_get_len(&pk) == bitlen / 8);
+
+ if (key_is_rsa) {
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, MBEDTLS_PK_ECKEY) == 0);
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, MBEDTLS_PK_ECDSA) == 0);
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, MBEDTLS_PK_RSA) == 1);
+ } else {
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, MBEDTLS_PK_ECKEY) == 1);
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, MBEDTLS_PK_ECDSA) == 1);
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, MBEDTLS_PK_RSA) == 0);
}
/* unsupported operations: verify, decrypt, encrypt */
- TEST_ASSERT( mbedtls_pk_verify( &pk, md_alg,
- b1, sizeof( b1), b2, sizeof( b2 ) )
- == MBEDTLS_ERR_PK_TYPE_MISMATCH );
- if( key_is_rsa == 0 )
- {
- TEST_ASSERT( mbedtls_pk_decrypt( &pk, b1, sizeof( b1 ),
- b2, &len, sizeof( b2 ),
- NULL, NULL )
- == MBEDTLS_ERR_PK_TYPE_MISMATCH );
+ TEST_ASSERT(mbedtls_pk_verify(&pk, md_alg,
+ b1, sizeof(b1), b2, sizeof(b2))
+ == MBEDTLS_ERR_PK_TYPE_MISMATCH);
+ if (key_is_rsa == 0) {
+ TEST_ASSERT(mbedtls_pk_decrypt(&pk, b1, sizeof(b1),
+ b2, &len, sizeof(b2),
+ NULL, NULL)
+ == MBEDTLS_ERR_PK_TYPE_MISMATCH);
}
- TEST_ASSERT( mbedtls_pk_encrypt( &pk, b1, sizeof( b1 ),
- b2, &len, sizeof( b2 ),
- NULL, NULL )
- == MBEDTLS_ERR_PK_TYPE_MISMATCH );
+ TEST_ASSERT(mbedtls_pk_encrypt(&pk, b1, sizeof(b1),
+ b2, &len, sizeof(b2),
+ NULL, NULL)
+ == MBEDTLS_ERR_PK_TYPE_MISMATCH);
/* unsupported functions: check_pair, debug */
- if( key_is_rsa )
- TEST_ASSERT( mbedtls_pk_setup( &pk2,
- mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- else
- TEST_ASSERT( mbedtls_pk_setup( &pk2,
- mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == 0 );
- TEST_ASSERT( mbedtls_pk_check_pair( &pk, &pk2,
- mbedtls_test_rnd_std_rand, NULL )
- == MBEDTLS_ERR_PK_TYPE_MISMATCH );
- TEST_ASSERT( mbedtls_pk_debug( &pk, &dbg )
- == MBEDTLS_ERR_PK_TYPE_MISMATCH );
+ if (key_is_rsa) {
+ TEST_ASSERT(mbedtls_pk_setup(&pk2,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ } else {
+ TEST_ASSERT(mbedtls_pk_setup(&pk2,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)) == 0);
+ }
+ TEST_ASSERT(mbedtls_pk_check_pair(&pk, &pk2,
+ mbedtls_test_rnd_std_rand, NULL)
+ == MBEDTLS_ERR_PK_TYPE_MISMATCH);
+ TEST_ASSERT(mbedtls_pk_debug(&pk, &dbg)
+ == MBEDTLS_ERR_PK_TYPE_MISMATCH);
/* test that freeing the context does not destroy the key */
- mbedtls_pk_free( &pk );
- TEST_ASSERT( PSA_SUCCESS == psa_get_key_attributes( key, &attributes ) );
- TEST_ASSERT( PSA_SUCCESS == psa_destroy_key( key ) );
+ mbedtls_pk_free(&pk);
+ TEST_ASSERT(PSA_SUCCESS == psa_get_key_attributes(key, &attributes));
+ TEST_ASSERT(PSA_SUCCESS == psa_destroy_key(key));
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_pk_free( &pk ); /* redundant except upon error */
- mbedtls_pk_free( &pk2 );
- USE_PSA_DONE( );
+ mbedtls_pk_free(&pk); /* redundant except upon error */
+ mbedtls_pk_free(&pk2);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_USE_PSA_CRYPTO */
-void pk_can_do_ext( int opaque_key, int key_type, int key_usage, int key_alg,
- int key_alg2, int parameter, int alg_check, int usage_check,
- int result )
+void pk_can_do_ext(int opaque_key, int key_type, int key_usage, int key_alg,
+ int key_alg2, int parameter, int alg_check, int usage_check,
+ int result)
{
mbedtls_pk_context pk;
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
- if( opaque_key == 1 )
- {
- psa_set_key_usage_flags( &attributes, key_usage );
- psa_set_key_algorithm( &attributes, key_alg );
- if( key_alg2 != 0 )
- psa_set_key_enrollment_algorithm( &attributes, key_alg2 );
- psa_set_key_type( &attributes, key_type );
- psa_set_key_bits( &attributes, parameter );
+ if (opaque_key == 1) {
+ psa_set_key_usage_flags(&attributes, key_usage);
+ psa_set_key_algorithm(&attributes, key_alg);
+ if (key_alg2 != 0) {
+ psa_set_key_enrollment_algorithm(&attributes, key_alg2);
+ }
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_bits(&attributes, parameter);
- PSA_ASSERT( psa_generate_key( &attributes, &key ) );
+ PSA_ASSERT(psa_generate_key(&attributes, &key));
- if( mbedtls_svc_key_id_is_null( key ) )
+ if (mbedtls_svc_key_id_is_null(key)) {
goto exit;
+ }
- TEST_EQUAL( mbedtls_pk_setup_opaque( &pk, key ), 0 );
+ TEST_EQUAL(mbedtls_pk_setup_opaque(&pk, key), 0);
- TEST_EQUAL( mbedtls_pk_get_type( &pk ), MBEDTLS_PK_OPAQUE );
- }
- else
- {
- TEST_EQUAL( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( key_type ) ), 0 );
- TEST_EQUAL( pk_genkey( &pk, parameter ), 0 );
- TEST_EQUAL( mbedtls_pk_get_type( &pk ), key_type );
+ TEST_EQUAL(mbedtls_pk_get_type(&pk), MBEDTLS_PK_OPAQUE);
+ } else {
+ TEST_EQUAL(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(key_type)), 0);
+ TEST_EQUAL(pk_genkey(&pk, parameter), 0);
+ TEST_EQUAL(mbedtls_pk_get_type(&pk), key_type);
}
- TEST_EQUAL( mbedtls_pk_can_do_ext( &pk, alg_check, usage_check ), result );
+ TEST_EQUAL(mbedtls_pk_can_do_ext(&pk, alg_check, usage_check), result);
exit:
- psa_reset_key_attributes( &attributes );
- PSA_ASSERT( psa_destroy_key( key ) );
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ PSA_ASSERT(psa_destroy_key(key));
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -305,228 +300,227 @@
mbedtls_pk_context ctx;
mbedtls_pk_type_t pk_type = 0;
unsigned char buf[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
- size_t buf_size = sizeof( buf );
+ size_t buf_size = sizeof(buf);
- mbedtls_pk_init( &ctx );
+ mbedtls_pk_init(&ctx);
- TEST_EQUAL( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_restartable( &ctx, MBEDTLS_MD_NONE,
- NULL, buf_size,
- buf, buf_size,
- NULL ) );
- TEST_EQUAL( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_restartable( &ctx, MBEDTLS_MD_SHA256,
- NULL, 0,
- buf, buf_size,
- NULL ) );
- TEST_EQUAL( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_ext( pk_type, NULL,
- &ctx, MBEDTLS_MD_NONE,
- NULL, buf_size,
- buf, buf_size ) );
- TEST_EQUAL( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_ext( pk_type, NULL,
- &ctx, MBEDTLS_MD_SHA256,
- NULL, 0,
- buf, buf_size ) );
- TEST_EQUAL( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign_restartable( &ctx, MBEDTLS_MD_NONE,
+ TEST_EQUAL(MBEDTLS_ERR_PK_BAD_INPUT_DATA,
+ mbedtls_pk_verify_restartable(&ctx, MBEDTLS_MD_NONE,
NULL, buf_size,
- buf, buf_size, &buf_size,
- NULL, NULL,
- NULL ) );
- TEST_EQUAL( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign_restartable( &ctx, MBEDTLS_MD_SHA256,
+ buf, buf_size,
+ NULL));
+ TEST_EQUAL(MBEDTLS_ERR_PK_BAD_INPUT_DATA,
+ mbedtls_pk_verify_restartable(&ctx, MBEDTLS_MD_SHA256,
NULL, 0,
- buf, buf_size, &buf_size,
- NULL, NULL,
- NULL ) );
+ buf, buf_size,
+ NULL));
+ TEST_EQUAL(MBEDTLS_ERR_PK_BAD_INPUT_DATA,
+ mbedtls_pk_verify_ext(pk_type, NULL,
+ &ctx, MBEDTLS_MD_NONE,
+ NULL, buf_size,
+ buf, buf_size));
+ TEST_EQUAL(MBEDTLS_ERR_PK_BAD_INPUT_DATA,
+ mbedtls_pk_verify_ext(pk_type, NULL,
+ &ctx, MBEDTLS_MD_SHA256,
+ NULL, 0,
+ buf, buf_size));
+ TEST_EQUAL(MBEDTLS_ERR_PK_BAD_INPUT_DATA,
+ mbedtls_pk_sign_restartable(&ctx, MBEDTLS_MD_NONE,
+ NULL, buf_size,
+ buf, buf_size, &buf_size,
+ NULL, NULL,
+ NULL));
+ TEST_EQUAL(MBEDTLS_ERR_PK_BAD_INPUT_DATA,
+ mbedtls_pk_sign_restartable(&ctx, MBEDTLS_MD_SHA256,
+ NULL, 0,
+ buf, buf_size, &buf_size,
+ NULL, NULL,
+ NULL));
exit:
- mbedtls_pk_free( &ctx );
+ mbedtls_pk_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void valid_parameters( )
+void valid_parameters()
{
mbedtls_pk_context pk;
unsigned char buf[1];
size_t len;
void *options = NULL;
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
- TEST_ASSERT( mbedtls_pk_setup( &pk, NULL ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, NULL) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
/* In informational functions, we accept NULL where a context pointer
* is expected because that's what the library has done forever.
* We do not document that NULL is accepted, so we may wish to change
* the behavior in a future version. */
- TEST_ASSERT( mbedtls_pk_get_bitlen( NULL ) == 0 );
- TEST_ASSERT( mbedtls_pk_get_len( NULL ) == 0 );
- TEST_ASSERT( mbedtls_pk_can_do( NULL, MBEDTLS_PK_NONE ) == 0 );
+ TEST_ASSERT(mbedtls_pk_get_bitlen(NULL) == 0);
+ TEST_ASSERT(mbedtls_pk_get_len(NULL) == 0);
+ TEST_ASSERT(mbedtls_pk_can_do(NULL, MBEDTLS_PK_NONE) == 0);
- TEST_ASSERT( mbedtls_pk_sign_restartable( &pk,
+ TEST_ASSERT(mbedtls_pk_sign_restartable(&pk,
+ MBEDTLS_MD_NONE,
+ NULL, 0,
+ buf, sizeof(buf), &len,
+ mbedtls_test_rnd_std_rand, NULL,
+ NULL) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
+
+ TEST_ASSERT(mbedtls_pk_sign_restartable(&pk,
+ MBEDTLS_MD_NONE,
+ NULL, 0,
+ buf, sizeof(buf), &len,
+ mbedtls_test_rnd_std_rand, NULL,
+ NULL) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
+
+ TEST_ASSERT(mbedtls_pk_sign(&pk,
+ MBEDTLS_MD_NONE,
+ NULL, 0,
+ buf, sizeof(buf), &len,
+ mbedtls_test_rnd_std_rand, NULL) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
+
+ TEST_ASSERT(mbedtls_pk_verify_restartable(&pk,
MBEDTLS_MD_NONE,
NULL, 0,
- buf, sizeof( buf ), &len,
- mbedtls_test_rnd_std_rand, NULL,
- NULL ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ buf, sizeof(buf),
+ NULL) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_pk_sign_restartable( &pk,
- MBEDTLS_MD_NONE,
- NULL, 0,
- buf, sizeof( buf ), &len,
- mbedtls_test_rnd_std_rand, NULL,
- NULL ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
-
- TEST_ASSERT( mbedtls_pk_sign( &pk,
+ TEST_ASSERT(mbedtls_pk_verify(&pk,
MBEDTLS_MD_NONE,
NULL, 0,
- buf, sizeof( buf ), &len,
- mbedtls_test_rnd_std_rand, NULL ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ buf, sizeof(buf)) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_pk_verify_restartable( &pk,
- MBEDTLS_MD_NONE,
- NULL, 0,
- buf, sizeof( buf ),
- NULL ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_verify_ext(MBEDTLS_PK_NONE, options,
+ &pk,
+ MBEDTLS_MD_NONE,
+ NULL, 0,
+ buf, sizeof(buf)) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_pk_verify( &pk,
- MBEDTLS_MD_NONE,
- NULL, 0,
- buf, sizeof( buf ) ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_encrypt(&pk,
+ NULL, 0,
+ NULL, &len, 0,
+ mbedtls_test_rnd_std_rand, NULL) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_pk_verify_ext( MBEDTLS_PK_NONE, options,
- &pk,
- MBEDTLS_MD_NONE,
- NULL, 0,
- buf, sizeof( buf ) ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
-
- TEST_ASSERT( mbedtls_pk_encrypt( &pk,
- NULL, 0,
- NULL, &len, 0,
- mbedtls_test_rnd_std_rand, NULL ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
-
- TEST_ASSERT( mbedtls_pk_decrypt( &pk,
- NULL, 0,
- NULL, &len, 0,
- mbedtls_test_rnd_std_rand, NULL ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_decrypt(&pk,
+ NULL, 0,
+ NULL, &len, 0,
+ mbedtls_test_rnd_std_rand, NULL) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
#if defined(MBEDTLS_PK_PARSE_C)
- TEST_ASSERT( mbedtls_pk_parse_key( &pk, NULL, 0, NULL, 1,
- mbedtls_test_rnd_std_rand, NULL ) ==
- MBEDTLS_ERR_PK_KEY_INVALID_FORMAT );
+ TEST_ASSERT(mbedtls_pk_parse_key(&pk, NULL, 0, NULL, 1,
+ mbedtls_test_rnd_std_rand, NULL) ==
+ MBEDTLS_ERR_PK_KEY_INVALID_FORMAT);
- TEST_ASSERT( mbedtls_pk_parse_public_key( &pk, NULL, 0 ) ==
- MBEDTLS_ERR_PK_KEY_INVALID_FORMAT );
+ TEST_ASSERT(mbedtls_pk_parse_public_key(&pk, NULL, 0) ==
+ MBEDTLS_ERR_PK_KEY_INVALID_FORMAT);
#endif /* MBEDTLS_PK_PARSE_C */
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PK_WRITE_C */
-void valid_parameters_pkwrite( data_t *key_data )
+void valid_parameters_pkwrite(data_t *key_data)
{
mbedtls_pk_context pk;
/* For the write tests to be effective, we need a valid key pair. */
- mbedtls_pk_init( &pk );
- TEST_ASSERT( mbedtls_pk_parse_key( &pk,
- key_data->x, key_data->len, NULL, 0,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
+ mbedtls_pk_init(&pk);
+ TEST_ASSERT(mbedtls_pk_parse_key(&pk,
+ key_data->x, key_data->len, NULL, 0,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
- TEST_ASSERT( mbedtls_pk_write_key_der( &pk, NULL, 0 ) ==
- MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
+ TEST_ASSERT(mbedtls_pk_write_key_der(&pk, NULL, 0) ==
+ MBEDTLS_ERR_ASN1_BUF_TOO_SMALL);
- TEST_ASSERT( mbedtls_pk_write_pubkey_der( &pk, NULL, 0 ) ==
- MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
+ TEST_ASSERT(mbedtls_pk_write_pubkey_der(&pk, NULL, 0) ==
+ MBEDTLS_ERR_ASN1_BUF_TOO_SMALL);
#if defined(MBEDTLS_PEM_WRITE_C)
- TEST_ASSERT( mbedtls_pk_write_key_pem( &pk, NULL, 0 ) ==
- MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
+ TEST_ASSERT(mbedtls_pk_write_key_pem(&pk, NULL, 0) ==
+ MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL);
- TEST_ASSERT( mbedtls_pk_write_pubkey_pem( &pk, NULL, 0 ) ==
- MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
+ TEST_ASSERT(mbedtls_pk_write_pubkey_pem(&pk, NULL, 0) ==
+ MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL);
#endif /* MBEDTLS_PEM_WRITE_C */
exit:
- mbedtls_pk_free( &pk );
+ mbedtls_pk_free(&pk);
}
/* END_CASE */
/* BEGIN_CASE */
-void pk_utils( int type, int parameter, int bitlen, int len, char * name )
+void pk_utils(int type, int parameter, int bitlen, int len, char *name)
{
mbedtls_pk_context pk;
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
- TEST_ASSERT( pk_genkey( &pk, parameter ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(type)) == 0);
+ TEST_ASSERT(pk_genkey(&pk, parameter) == 0);
- TEST_ASSERT( (int) mbedtls_pk_get_type( &pk ) == type );
- TEST_ASSERT( mbedtls_pk_can_do( &pk, type ) );
- TEST_ASSERT( mbedtls_pk_get_bitlen( &pk ) == (unsigned) bitlen );
- TEST_ASSERT( mbedtls_pk_get_len( &pk ) == (unsigned) len );
- TEST_ASSERT( strcmp( mbedtls_pk_get_name( &pk), name ) == 0 );
+ TEST_ASSERT((int) mbedtls_pk_get_type(&pk) == type);
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, type));
+ TEST_ASSERT(mbedtls_pk_get_bitlen(&pk) == (unsigned) bitlen);
+ TEST_ASSERT(mbedtls_pk_get_len(&pk) == (unsigned) len);
+ TEST_ASSERT(strcmp(mbedtls_pk_get_name(&pk), name) == 0);
exit:
- mbedtls_pk_free( &pk );
+ mbedtls_pk_free(&pk);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PK_PARSE_C:MBEDTLS_FS_IO */
-void mbedtls_pk_check_pair( char * pub_file, char * prv_file, int ret )
+void mbedtls_pk_check_pair(char *pub_file, char *prv_file, int ret)
{
mbedtls_pk_context pub, prv, alt;
USE_PSA_INIT();
- mbedtls_pk_init( &pub );
- mbedtls_pk_init( &prv );
- mbedtls_pk_init( &alt );
+ mbedtls_pk_init(&pub);
+ mbedtls_pk_init(&prv);
+ mbedtls_pk_init(&alt);
- TEST_ASSERT( mbedtls_pk_parse_public_keyfile( &pub, pub_file ) == 0 );
- TEST_ASSERT( mbedtls_pk_parse_keyfile( &prv, prv_file, NULL,
- mbedtls_test_rnd_std_rand, NULL )
- == 0 );
+ TEST_ASSERT(mbedtls_pk_parse_public_keyfile(&pub, pub_file) == 0);
+ TEST_ASSERT(mbedtls_pk_parse_keyfile(&prv, prv_file, NULL,
+ mbedtls_test_rnd_std_rand, NULL)
+ == 0);
- TEST_ASSERT( mbedtls_pk_check_pair( &pub, &prv,
- mbedtls_test_rnd_std_rand, NULL )
- == ret );
+ TEST_ASSERT(mbedtls_pk_check_pair(&pub, &prv,
+ mbedtls_test_rnd_std_rand, NULL)
+ == ret);
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
- if( mbedtls_pk_get_type( &prv ) == MBEDTLS_PK_RSA )
- {
- TEST_ASSERT( mbedtls_pk_setup_rsa_alt( &alt, mbedtls_pk_rsa( prv ),
- mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func,
- mbedtls_rsa_key_len_func ) == 0 );
- TEST_ASSERT( mbedtls_pk_check_pair( &pub, &alt,
- mbedtls_test_rnd_std_rand, NULL )
- == ret );
+ if (mbedtls_pk_get_type(&prv) == MBEDTLS_PK_RSA) {
+ TEST_ASSERT(mbedtls_pk_setup_rsa_alt(&alt, mbedtls_pk_rsa(prv),
+ mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func,
+ mbedtls_rsa_key_len_func) == 0);
+ TEST_ASSERT(mbedtls_pk_check_pair(&pub, &alt,
+ mbedtls_test_rnd_std_rand, NULL)
+ == ret);
}
#endif
- mbedtls_pk_free( &pub );
- mbedtls_pk_free( &prv );
- mbedtls_pk_free( &alt );
+ mbedtls_pk_free(&pub);
+ mbedtls_pk_free(&prv);
+ mbedtls_pk_free(&alt);
USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
-void pk_rsa_verify_test_vec( data_t * message_str, int digest, int mod,
- char * input_N, char * input_E,
- data_t * result_str, int result )
+void pk_rsa_verify_test_vec(data_t *message_str, int digest, int mod,
+ char *input_N, char *input_E,
+ data_t *result_str, int result)
{
mbedtls_rsa_context *rsa;
mbedtls_pk_context pk;
@@ -535,45 +529,46 @@
mbedtls_pk_restart_ctx ctx;
rs_ctx = &ctx;
- mbedtls_pk_restart_init( rs_ctx );
+ mbedtls_pk_restart_init(rs_ctx);
// this setting would ensure restart would happen if ECC was used
- mbedtls_ecp_set_max_ops( 1 );
+ mbedtls_ecp_set_max_ops(1);
#endif
USE_PSA_INIT();
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- rsa = mbedtls_pk_rsa( pk );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ rsa = mbedtls_pk_rsa(pk);
rsa->len = mod / 8;
- TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&rsa->N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&rsa->E, input_E) == 0);
- TEST_ASSERT( mbedtls_pk_verify( &pk, digest, message_str->x, 0,
- result_str->x, mbedtls_pk_get_len( &pk ) ) == result );
+ TEST_ASSERT(mbedtls_pk_verify(&pk, digest, message_str->x, 0,
+ result_str->x, mbedtls_pk_get_len(&pk)) == result);
- TEST_ASSERT( mbedtls_pk_verify_restartable( &pk, digest, message_str->x, 0,
- result_str->x, mbedtls_pk_get_len( &pk ), rs_ctx ) == result );
+ TEST_ASSERT(mbedtls_pk_verify_restartable(&pk, digest, message_str->x, 0,
+ result_str->x, mbedtls_pk_get_len(
+ &pk), rs_ctx) == result);
exit:
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- mbedtls_pk_restart_free( rs_ctx );
+ mbedtls_pk_restart_free(rs_ctx);
#endif
- mbedtls_pk_free( &pk );
+ mbedtls_pk_free(&pk);
USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
-void pk_rsa_verify_ext_test_vec( data_t * message_str, int digest,
- int mod, char * input_N,
- char * input_E, data_t * result_str,
- int pk_type, int mgf1_hash_id,
- int salt_len, int sig_len,
- int result )
+void pk_rsa_verify_ext_test_vec(data_t *message_str, int digest,
+ int mod, char *input_N,
+ char *input_E, data_t *result_str,
+ int pk_type, int mgf1_hash_id,
+ int salt_len, int sig_len,
+ int result)
{
mbedtls_rsa_context *rsa;
mbedtls_pk_context pk;
@@ -581,36 +576,32 @@
void *options;
int ret;
- USE_PSA_INIT( );
- mbedtls_pk_init( &pk );
+ USE_PSA_INIT();
+ mbedtls_pk_init(&pk);
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- rsa = mbedtls_pk_rsa( pk );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ rsa = mbedtls_pk_rsa(pk);
rsa->len = mod / 8;
- TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&rsa->N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&rsa->E, input_E) == 0);
- if( mgf1_hash_id < 0 )
- {
+ if (mgf1_hash_id < 0) {
options = NULL;
- }
- else
- {
+ } else {
options = &pss_opts;
pss_opts.mgf1_hash_id = mgf1_hash_id;
pss_opts.expected_salt_len = salt_len;
}
- ret = mbedtls_pk_verify_ext( pk_type, options, &pk,
- digest, message_str->x, message_str->len,
- result_str->x, sig_len );
+ ret = mbedtls_pk_verify_ext(pk_type, options, &pk,
+ digest, message_str->x, message_str->len,
+ result_str->x, sig_len);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- if( result == MBEDTLS_ERR_RSA_INVALID_PADDING )
- {
+ if (result == MBEDTLS_ERR_RSA_INVALID_PADDING) {
/* Mbed TLS distinguishes "invalid padding" from "valid padding but
* the rest of the signature is invalid". This has little use in
* practice and PSA doesn't report this distinction.
@@ -620,54 +611,53 @@
* PSA or the Mbed TLS API, depending on the PSS options used.
* So, it may return either INVALID_PADDING or INVALID_SIGNATURE.
*/
- TEST_ASSERT( ret == result || ret == MBEDTLS_ERR_RSA_VERIFY_FAILED );
- }
- else
+ TEST_ASSERT(ret == result || ret == MBEDTLS_ERR_RSA_VERIFY_FAILED);
+ } else
#endif
{
- TEST_EQUAL( ret, result );
+ TEST_EQUAL(ret, result);
}
exit:
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECDSA_C */
-void pk_ec_test_vec( int type, int id, data_t * key, data_t * hash,
- data_t * sig, int ret )
+void pk_ec_test_vec(int type, int id, data_t *key, data_t *hash,
+ data_t *sig, int ret)
{
mbedtls_pk_context pk;
mbedtls_ecp_keypair *eckey;
- mbedtls_pk_init( &pk );
- USE_PSA_INIT( );
+ mbedtls_pk_init(&pk);
+ USE_PSA_INIT();
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(type)) == 0);
- TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_ECDSA ) );
- eckey = mbedtls_pk_ec( pk );
+ TEST_ASSERT(mbedtls_pk_can_do(&pk, MBEDTLS_PK_ECDSA));
+ eckey = mbedtls_pk_ec(pk);
- TEST_ASSERT( mbedtls_ecp_group_load( &eckey->grp, id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_binary( &eckey->grp, &eckey->Q,
- key->x, key->len ) == 0 );
+ TEST_ASSERT(mbedtls_ecp_group_load(&eckey->grp, id) == 0);
+ TEST_ASSERT(mbedtls_ecp_point_read_binary(&eckey->grp, &eckey->Q,
+ key->x, key->len) == 0);
// MBEDTLS_MD_NONE is used since it will be ignored.
- TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_NONE,
- hash->x, hash->len, sig->x, sig->len ) == ret );
+ TEST_ASSERT(mbedtls_pk_verify(&pk, MBEDTLS_MD_NONE,
+ hash->x, hash->len, sig->x, sig->len) == ret);
exit:
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE:MBEDTLS_ECDSA_C:MBEDTLS_ECDSA_DETERMINISTIC */
-void pk_sign_verify_restart( int pk_type, int grp_id, char *d_str,
- char *QX_str, char *QY_str,
- int md_alg, data_t *hash, data_t *sig_check,
- int max_ops, int min_restart, int max_restart )
+void pk_sign_verify_restart(int pk_type, int grp_id, char *d_str,
+ char *QX_str, char *QY_str,
+ int md_alg, data_t *hash, data_t *sig_check,
+ int max_ops, int min_restart, int max_restart)
{
int ret, cnt_restart;
mbedtls_pk_restart_ctx rs_ctx;
@@ -677,174 +667,173 @@
USE_PSA_INIT();
- mbedtls_pk_restart_init( &rs_ctx );
- mbedtls_pk_init( &prv );
- mbedtls_pk_init( &pub );
- memset( sig, 0, sizeof( sig ) );
+ mbedtls_pk_restart_init(&rs_ctx);
+ mbedtls_pk_init(&prv);
+ mbedtls_pk_init(&pub);
+ memset(sig, 0, sizeof(sig));
- TEST_ASSERT( mbedtls_pk_setup( &prv, mbedtls_pk_info_from_type( pk_type ) ) == 0 );
- TEST_ASSERT( mbedtls_ecp_group_load( &mbedtls_pk_ec( prv )->grp, grp_id ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &mbedtls_pk_ec( prv )->d, d_str ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&prv, mbedtls_pk_info_from_type(pk_type)) == 0);
+ TEST_ASSERT(mbedtls_ecp_group_load(&mbedtls_pk_ec(prv)->grp, grp_id) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&mbedtls_pk_ec(prv)->d, d_str) == 0);
- TEST_ASSERT( mbedtls_pk_setup( &pub, mbedtls_pk_info_from_type( pk_type ) ) == 0 );
- TEST_ASSERT( mbedtls_ecp_group_load( &mbedtls_pk_ec( pub )->grp, grp_id ) == 0 );
- TEST_ASSERT( mbedtls_ecp_point_read_string( &mbedtls_pk_ec( pub )->Q, 16, QX_str, QY_str ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&pub, mbedtls_pk_info_from_type(pk_type)) == 0);
+ TEST_ASSERT(mbedtls_ecp_group_load(&mbedtls_pk_ec(pub)->grp, grp_id) == 0);
+ TEST_ASSERT(mbedtls_ecp_point_read_string(&mbedtls_pk_ec(pub)->Q, 16, QX_str, QY_str) == 0);
- mbedtls_ecp_set_max_ops( max_ops );
+ mbedtls_ecp_set_max_ops(max_ops);
- slen = sizeof( sig );
+ slen = sizeof(sig);
cnt_restart = 0;
do {
- ret = mbedtls_pk_sign_restartable( &prv, md_alg, hash->x, hash->len,
- sig, sizeof( sig ), &slen,
- mbedtls_test_rnd_std_rand, NULL,
- &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,
+ sig, sizeof(sig), &slen,
+ mbedtls_test_rnd_std_rand, NULL,
+ &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( slen == sig_check->len );
- TEST_ASSERT( memcmp( sig, sig_check->x, slen ) == 0 );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(slen == sig_check->len);
+ TEST_ASSERT(memcmp(sig, sig_check->x, slen) == 0);
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
cnt_restart = 0;
do {
- ret = mbedtls_pk_verify_restartable( &pub, md_alg,
- hash->x, hash->len, sig, slen, &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_pk_verify_restartable(&pub, md_alg,
+ hash->x, hash->len, sig, slen, &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
sig[0]++;
do {
- ret = mbedtls_pk_verify_restartable( &pub, md_alg,
- hash->x, hash->len, sig, slen, &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
- TEST_ASSERT( ret != 0 );
+ ret = mbedtls_pk_verify_restartable(&pub, md_alg,
+ hash->x, hash->len, sig, slen, &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
+ TEST_ASSERT(ret != 0);
sig[0]--;
/* Do we leak memory when aborting? try verify then sign
* This test only makes sense when we actually restart */
- if( min_restart > 0 )
- {
- ret = mbedtls_pk_verify_restartable( &pub, md_alg,
- hash->x, hash->len, sig, slen, &rs_ctx );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
- mbedtls_pk_restart_free( &rs_ctx );
+ if (min_restart > 0) {
+ ret = mbedtls_pk_verify_restartable(&pub, md_alg,
+ hash->x, hash->len, sig, slen, &rs_ctx);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
+ mbedtls_pk_restart_free(&rs_ctx);
- slen = sizeof( sig );
- ret = mbedtls_pk_sign_restartable( &prv, md_alg, hash->x, hash->len,
- sig, sizeof sig, &slen,
- mbedtls_test_rnd_std_rand, NULL,
- &rs_ctx );
- TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
+ slen = sizeof(sig);
+ ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,
+ sig, sizeof sig, &slen,
+ mbedtls_test_rnd_std_rand, NULL,
+ &rs_ctx);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
}
exit:
- mbedtls_pk_restart_free( &rs_ctx );
- mbedtls_pk_free( &prv );
- mbedtls_pk_free( &pub );
+ mbedtls_pk_restart_free(&rs_ctx);
+ mbedtls_pk_free(&prv);
+ mbedtls_pk_free(&pub);
USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void pk_sign_verify( int type, int parameter, int sign_ret, int verify_ret )
+void pk_sign_verify(int type, int parameter, int sign_ret, int verify_ret)
{
mbedtls_pk_context pk;
size_t sig_len;
unsigned char hash[32]; // Hard-coded for SHA256
- size_t hash_len = sizeof( hash );
+ size_t hash_len = sizeof(hash);
unsigned char sig[MBEDTLS_PK_SIGNATURE_MAX_SIZE];
void *rs_ctx = NULL;
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
mbedtls_pk_restart_ctx ctx;
rs_ctx = &ctx;
- mbedtls_pk_restart_init( rs_ctx );
+ mbedtls_pk_restart_init(rs_ctx);
/* This value is large enough that the operation will complete in one run.
* See comments at the top of ecp_test_vect_restart in
* test_suite_ecp.function for estimates of operation counts. */
- mbedtls_ecp_set_max_ops( 42000 );
+ mbedtls_ecp_set_max_ops(42000);
#endif
- mbedtls_pk_init( &pk );
- USE_PSA_INIT( );
+ mbedtls_pk_init(&pk);
+ USE_PSA_INIT();
- memset( hash, 0x2a, sizeof hash );
- memset( sig, 0, sizeof sig );
+ memset(hash, 0x2a, sizeof hash);
+ memset(sig, 0, sizeof sig);
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
- TEST_ASSERT( pk_genkey( &pk, parameter ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(type)) == 0);
+ TEST_ASSERT(pk_genkey(&pk, parameter) == 0);
- TEST_ASSERT( mbedtls_pk_sign_restartable( &pk, MBEDTLS_MD_SHA256,
- hash, hash_len,
- sig, sizeof sig, &sig_len,
- mbedtls_test_rnd_std_rand, NULL,
- rs_ctx ) == sign_ret );
- if( sign_ret == 0 )
- TEST_ASSERT( sig_len <= MBEDTLS_PK_SIGNATURE_MAX_SIZE );
- else
+ TEST_ASSERT(mbedtls_pk_sign_restartable(&pk, MBEDTLS_MD_SHA256,
+ hash, hash_len,
+ sig, sizeof sig, &sig_len,
+ mbedtls_test_rnd_std_rand, NULL,
+ rs_ctx) == sign_ret);
+ if (sign_ret == 0) {
+ TEST_ASSERT(sig_len <= MBEDTLS_PK_SIGNATURE_MAX_SIZE);
+ } else {
sig_len = MBEDTLS_PK_SIGNATURE_MAX_SIZE;
+ }
- TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA256,
- hash, hash_len, sig, sig_len ) == verify_ret );
+ TEST_ASSERT(mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256,
+ hash, hash_len, sig, sig_len) == verify_ret);
- if( verify_ret == 0 )
- {
+ if (verify_ret == 0) {
hash[0]++;
- TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA256,
- hash, hash_len, sig, sig_len ) != 0 );
+ TEST_ASSERT(mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256,
+ hash, hash_len, sig, sig_len) != 0);
hash[0]--;
sig[0]++;
- TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA256,
- hash, hash_len, sig, sig_len ) != 0 );
+ TEST_ASSERT(mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256,
+ hash, hash_len, sig, sig_len) != 0);
sig[0]--;
}
- TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256, hash, hash_len,
- sig, sizeof sig, &sig_len,
- mbedtls_test_rnd_std_rand,
- NULL ) == sign_ret );
- if( sign_ret == 0 )
- TEST_ASSERT( sig_len <= MBEDTLS_PK_SIGNATURE_MAX_SIZE );
- else
+ TEST_ASSERT(mbedtls_pk_sign(&pk, MBEDTLS_MD_SHA256, hash, hash_len,
+ sig, sizeof sig, &sig_len,
+ mbedtls_test_rnd_std_rand,
+ NULL) == sign_ret);
+ if (sign_ret == 0) {
+ TEST_ASSERT(sig_len <= MBEDTLS_PK_SIGNATURE_MAX_SIZE);
+ } else {
sig_len = MBEDTLS_PK_SIGNATURE_MAX_SIZE;
+ }
- TEST_ASSERT( mbedtls_pk_verify_restartable( &pk, MBEDTLS_MD_SHA256,
- hash, hash_len, sig, sig_len, rs_ctx ) == verify_ret );
+ TEST_ASSERT(mbedtls_pk_verify_restartable(&pk, MBEDTLS_MD_SHA256,
+ hash, hash_len, sig, sig_len, rs_ctx) == verify_ret);
- if( verify_ret == 0 )
- {
+ if (verify_ret == 0) {
hash[0]++;
- TEST_ASSERT( mbedtls_pk_verify_restartable( &pk, MBEDTLS_MD_SHA256,
- hash, sizeof hash, sig, sig_len, rs_ctx ) != 0 );
+ TEST_ASSERT(mbedtls_pk_verify_restartable(&pk, MBEDTLS_MD_SHA256,
+ hash, sizeof hash, sig, sig_len, rs_ctx) != 0);
hash[0]--;
sig[0]++;
- TEST_ASSERT( mbedtls_pk_verify_restartable( &pk, MBEDTLS_MD_SHA256,
- hash, sizeof hash, sig, sig_len, rs_ctx ) != 0 );
+ TEST_ASSERT(mbedtls_pk_verify_restartable(&pk, MBEDTLS_MD_SHA256,
+ hash, sizeof hash, sig, sig_len, rs_ctx) != 0);
sig[0]--;
}
exit:
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- mbedtls_pk_restart_free( rs_ctx );
+ mbedtls_pk_restart_free(rs_ctx);
#endif
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
-void pk_rsa_encrypt_decrypt_test( data_t * message, int mod,
- char * input_P, char * input_Q,
- char * input_N, char * input_E,
- int ret )
+void pk_rsa_encrypt_decrypt_test(data_t *message, int mod,
+ char *input_P, char *input_Q,
+ char *input_N, char *input_E,
+ int ret)
{
unsigned char output[300], result[300];
mbedtls_test_rnd_pseudo_info rnd_info;
@@ -853,75 +842,74 @@
mbedtls_pk_context pk;
size_t olen, rlen;
- mbedtls_pk_init( &pk );
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
+ mbedtls_pk_init(&pk);
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
- memset( output, 0, sizeof( output ) );
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
+ memset(output, 0, sizeof(output));
- USE_PSA_INIT( );
+ USE_PSA_INIT();
/* encryption test */
/* init pk-rsa context */
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- rsa = mbedtls_pk_rsa( pk );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ rsa = mbedtls_pk_rsa(pk);
/* load public key */
rsa->len = mod / 8;
- TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&rsa->N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&rsa->E, input_E) == 0);
- TEST_ASSERT( mbedtls_pk_encrypt( &pk, message->x, message->len,
- output, &olen, sizeof( output ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
+ TEST_ASSERT(mbedtls_pk_encrypt(&pk, message->x, message->len,
+ output, &olen, sizeof(output),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info) == ret);
/* decryption test */
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
/* init pk-rsa context */
- mbedtls_pk_free( &pk );
- TEST_ASSERT( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- rsa = mbedtls_pk_rsa( pk );
+ mbedtls_pk_free(&pk);
+ TEST_ASSERT(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ rsa = mbedtls_pk_rsa(pk);
/* load public key */
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
/* load private key */
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_rsa_import( rsa, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( rsa ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( rsa ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_rsa_import(rsa, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(rsa) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(rsa) == 0);
- memset( result, 0, sizeof( result ) );
+ memset(result, 0, sizeof(result));
rlen = 0;
- TEST_ASSERT( mbedtls_pk_decrypt( &pk, output, olen,
- result, &rlen, sizeof( result ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
- if( ret == 0 )
- {
- TEST_ASSERT( rlen == message->len );
- TEST_ASSERT( memcmp( result, message->x, rlen ) == 0 );
+ TEST_ASSERT(mbedtls_pk_decrypt(&pk, output, olen,
+ result, &rlen, sizeof(result),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info) == ret);
+ if (ret == 0) {
+ TEST_ASSERT(rlen == message->len);
+ TEST_ASSERT(memcmp(result, message->x, rlen) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
-void pk_rsa_decrypt_test_vec( data_t * cipher, int mod,
- char * input_P, char * input_Q,
- char * input_N, char * input_E,
- data_t * clear, int ret )
+void pk_rsa_decrypt_test_vec(data_t *cipher, int mod,
+ char *input_P, char *input_Q,
+ char *input_N, char *input_E,
+ data_t *clear, int ret)
{
unsigned char output[256];
mbedtls_test_rnd_pseudo_info rnd_info;
@@ -930,55 +918,54 @@
mbedtls_pk_context pk;
size_t olen;
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_pk_init( &pk );
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
+ mbedtls_pk_init(&pk);
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
/* init pk-rsa context */
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- rsa = mbedtls_pk_rsa( pk );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ rsa = mbedtls_pk_rsa(pk);
/* load public key */
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
/* load private key */
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_rsa_import( rsa, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( rsa ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( rsa ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_rsa_import(rsa, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(rsa) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(rsa) == 0);
/* decryption test */
- memset( output, 0, sizeof( output ) );
+ memset(output, 0, sizeof(output));
olen = 0;
- TEST_ASSERT( mbedtls_pk_decrypt( &pk, cipher->x, cipher->len,
- output, &olen, sizeof( output ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
- if( ret == 0 )
- {
- TEST_ASSERT( olen == clear->len );
- TEST_ASSERT( memcmp( output, clear->x, olen ) == 0 );
+ TEST_ASSERT(mbedtls_pk_decrypt(&pk, cipher->x, cipher->len,
+ output, &olen, sizeof(output),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info) == ret);
+ if (ret == 0) {
+ TEST_ASSERT(olen == clear->len);
+ TEST_ASSERT(memcmp(output, clear->x, olen) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_USE_PSA_CRYPTO */
-void pk_wrap_rsa_decrypt_test_vec( data_t * cipher, int mod,
- char * input_P, char * input_Q,
- char * input_N, char * input_E,
- data_t * clear, int ret )
+void pk_wrap_rsa_decrypt_test_vec(data_t *cipher, int mod,
+ char *input_P, char *input_Q,
+ char *input_N, char *input_E,
+ data_t *clear, int ret)
{
unsigned char output[256];
mbedtls_test_rnd_pseudo_info rnd_info;
@@ -988,60 +975,59 @@
mbedtls_svc_key_id_t key_id;
size_t olen;
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_pk_init( &pk );
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
+ mbedtls_pk_init(&pk);
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
/* init pk-rsa context */
- TEST_EQUAL( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ), 0 );
- rsa = mbedtls_pk_rsa( pk );
+ TEST_EQUAL(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)), 0);
+ rsa = mbedtls_pk_rsa(pk);
/* load public key */
- TEST_EQUAL( mbedtls_test_read_mpi( &N, input_N ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &E, input_E ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi(&N, input_N), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&E, input_E), 0);
/* load private key */
- TEST_EQUAL( mbedtls_test_read_mpi( &P, input_P ), 0 );
- TEST_EQUAL( mbedtls_test_read_mpi( &Q, input_Q ), 0 );
- TEST_EQUAL( mbedtls_rsa_import( rsa, &N, &P, &Q, NULL, &E ), 0 );
- TEST_EQUAL( mbedtls_rsa_get_len( rsa ), (size_t) ( mod / 8 ) );
- TEST_EQUAL( mbedtls_rsa_complete( rsa ), 0 );
+ TEST_EQUAL(mbedtls_test_read_mpi(&P, input_P), 0);
+ TEST_EQUAL(mbedtls_test_read_mpi(&Q, input_Q), 0);
+ TEST_EQUAL(mbedtls_rsa_import(rsa, &N, &P, &Q, NULL, &E), 0);
+ TEST_EQUAL(mbedtls_rsa_get_len(rsa), (size_t) (mod / 8));
+ TEST_EQUAL(mbedtls_rsa_complete(rsa), 0);
/* Turn PK context into an opaque one. */
- TEST_EQUAL( mbedtls_pk_wrap_as_opaque( &pk, &key_id,
- PSA_ALG_RSA_PKCS1V15_CRYPT,
- PSA_KEY_USAGE_DECRYPT,
- PSA_ALG_NONE ), 0 );
+ TEST_EQUAL(mbedtls_pk_wrap_as_opaque(&pk, &key_id,
+ PSA_ALG_RSA_PKCS1V15_CRYPT,
+ PSA_KEY_USAGE_DECRYPT,
+ PSA_ALG_NONE), 0);
/* decryption test */
- memset( output, 0, sizeof( output ) );
+ memset(output, 0, sizeof(output));
olen = 0;
- TEST_EQUAL( mbedtls_pk_decrypt( &pk, cipher->x, cipher->len,
- output, &olen, sizeof( output ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info ), ret );
- if( ret == 0 )
- {
- TEST_EQUAL( olen, clear->len );
- TEST_EQUAL( memcmp( output, clear->x, olen ), 0 );
+ TEST_EQUAL(mbedtls_pk_decrypt(&pk, cipher->x, cipher->len,
+ output, &olen, sizeof(output),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info), ret);
+ if (ret == 0) {
+ TEST_EQUAL(olen, clear->len);
+ TEST_EQUAL(memcmp(output, clear->x, olen), 0);
}
- TEST_EQUAL( PSA_SUCCESS, psa_destroy_key( key_id ) );
+ TEST_EQUAL(PSA_SUCCESS, psa_destroy_key(key_id));
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void pk_ec_nocrypt( int type )
+void pk_ec_nocrypt(int type)
{
mbedtls_pk_context pk;
unsigned char output[100];
@@ -1050,66 +1036,67 @@
size_t olen = 0;
int ret = MBEDTLS_ERR_PK_TYPE_MISMATCH;
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
- memset( output, 0, sizeof( output ) );
- memset( input, 0, sizeof( input ) );
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
+ memset(output, 0, sizeof(output));
+ memset(input, 0, sizeof(input));
- TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(type)) == 0);
- TEST_ASSERT( mbedtls_pk_encrypt( &pk, input, sizeof( input ),
- output, &olen, sizeof( output ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
+ TEST_ASSERT(mbedtls_pk_encrypt(&pk, input, sizeof(input),
+ output, &olen, sizeof(output),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info) == ret);
- TEST_ASSERT( mbedtls_pk_decrypt( &pk, input, sizeof( input ),
- output, &olen, sizeof( output ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
+ TEST_ASSERT(mbedtls_pk_decrypt(&pk, input, sizeof(input),
+ output, &olen, sizeof(output),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info) == ret);
exit:
- mbedtls_pk_free( &pk );
+ mbedtls_pk_free(&pk);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */
-void pk_rsa_overflow( )
+void pk_rsa_overflow()
{
mbedtls_pk_context pk;
size_t hash_len = SIZE_MAX, sig_len = SIZE_MAX;
unsigned char hash[50], sig[100];
- if( SIZE_MAX <= UINT_MAX )
+ if (SIZE_MAX <= UINT_MAX) {
return;
+ }
- memset( hash, 0x2a, sizeof hash );
- memset( sig, 0, sizeof sig );
+ memset(hash, 0x2a, sizeof hash);
+ memset(sig, 0, sizeof sig);
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
- TEST_ASSERT( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
#if defined(MBEDTLS_PKCS1_V21)
- TEST_ASSERT( mbedtls_pk_verify_ext( MBEDTLS_PK_RSASSA_PSS, NULL, &pk,
- MBEDTLS_MD_NONE, hash, hash_len, sig, sig_len ) ==
- MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_verify_ext(MBEDTLS_PK_RSASSA_PSS, NULL, &pk,
+ MBEDTLS_MD_NONE, hash, hash_len, sig, sig_len) ==
+ MBEDTLS_ERR_PK_BAD_INPUT_DATA);
#endif /* MBEDTLS_PKCS1_V21 */
- TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_NONE, hash, hash_len,
- sig, sig_len ) == MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_verify(&pk, MBEDTLS_MD_NONE, hash, hash_len,
+ sig, sig_len) == MBEDTLS_ERR_PK_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_NONE, hash, hash_len,
- sig, sizeof sig, &sig_len,
- mbedtls_test_rnd_std_rand, NULL )
- == MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_sign(&pk, MBEDTLS_MD_NONE, hash, hash_len,
+ sig, sizeof sig, &sig_len,
+ mbedtls_test_rnd_std_rand, NULL)
+ == MBEDTLS_ERR_PK_BAD_INPUT_DATA);
exit:
- mbedtls_pk_free( &pk );
+ mbedtls_pk_free(&pk);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_PK_RSA_ALT_SUPPORT */
-void pk_rsa_alt( )
+void pk_rsa_alt()
{
/*
* An rsa_alt context can only do private operations (decrypt, sign).
@@ -1124,79 +1111,80 @@
size_t sig_len, ciph_len, test_len;
int ret = MBEDTLS_ERR_PK_TYPE_MISMATCH;
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_rsa_init( &raw );
- mbedtls_pk_init( &rsa ); mbedtls_pk_init( &alt );
+ mbedtls_rsa_init(&raw);
+ mbedtls_pk_init(&rsa); mbedtls_pk_init(&alt);
- memset( hash, 0x2a, sizeof hash );
- memset( sig, 0, sizeof sig );
- memset( msg, 0x2a, sizeof msg );
- memset( ciph, 0, sizeof ciph );
- memset( test, 0, sizeof test );
+ memset(hash, 0x2a, sizeof hash);
+ memset(sig, 0, sizeof sig);
+ memset(msg, 0x2a, sizeof msg);
+ memset(ciph, 0, sizeof ciph);
+ memset(test, 0, sizeof test);
/* Initialize PK RSA context with random key */
- TEST_ASSERT( mbedtls_pk_setup( &rsa,
- mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- TEST_ASSERT( pk_genkey( &rsa, RSA_KEY_SIZE ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&rsa,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ TEST_ASSERT(pk_genkey(&rsa, RSA_KEY_SIZE) == 0);
/* Extract key to the raw rsa context */
- TEST_ASSERT( mbedtls_rsa_copy( &raw, mbedtls_pk_rsa( rsa ) ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_copy(&raw, mbedtls_pk_rsa(rsa)) == 0);
/* Initialize PK RSA_ALT context */
- TEST_ASSERT( mbedtls_pk_setup_rsa_alt( &alt, (void *) &raw,
- mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func, mbedtls_rsa_key_len_func ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup_rsa_alt(&alt, (void *) &raw,
+ mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func,
+ mbedtls_rsa_key_len_func) == 0);
/* Test administrative functions */
- TEST_ASSERT( mbedtls_pk_can_do( &alt, MBEDTLS_PK_RSA ) );
- TEST_ASSERT( mbedtls_pk_get_bitlen( &alt ) == RSA_KEY_SIZE );
- TEST_ASSERT( mbedtls_pk_get_len( &alt ) == RSA_KEY_LEN );
- TEST_ASSERT( mbedtls_pk_get_type( &alt ) == MBEDTLS_PK_RSA_ALT );
- TEST_ASSERT( strcmp( mbedtls_pk_get_name( &alt ), "RSA-alt" ) == 0 );
+ TEST_ASSERT(mbedtls_pk_can_do(&alt, MBEDTLS_PK_RSA));
+ TEST_ASSERT(mbedtls_pk_get_bitlen(&alt) == RSA_KEY_SIZE);
+ TEST_ASSERT(mbedtls_pk_get_len(&alt) == RSA_KEY_LEN);
+ TEST_ASSERT(mbedtls_pk_get_type(&alt) == MBEDTLS_PK_RSA_ALT);
+ TEST_ASSERT(strcmp(mbedtls_pk_get_name(&alt), "RSA-alt") == 0);
/* Test signature */
#if SIZE_MAX > UINT_MAX
- TEST_ASSERT( mbedtls_pk_sign( &alt, MBEDTLS_MD_NONE, hash, SIZE_MAX,
- sig, sizeof sig, &sig_len,
- mbedtls_test_rnd_std_rand, NULL )
- == MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_pk_sign(&alt, MBEDTLS_MD_NONE, hash, SIZE_MAX,
+ sig, sizeof sig, &sig_len,
+ mbedtls_test_rnd_std_rand, NULL)
+ == MBEDTLS_ERR_PK_BAD_INPUT_DATA);
#endif /* SIZE_MAX > UINT_MAX */
- TEST_ASSERT( mbedtls_pk_sign( &alt, MBEDTLS_MD_NONE, hash, sizeof hash,
- sig, sizeof sig, &sig_len,
- mbedtls_test_rnd_std_rand, NULL )
- == 0 );
- TEST_ASSERT( sig_len == RSA_KEY_LEN );
- TEST_ASSERT( mbedtls_pk_verify( &rsa, MBEDTLS_MD_NONE,
- hash, sizeof hash, sig, sig_len ) == 0 );
+ TEST_ASSERT(mbedtls_pk_sign(&alt, MBEDTLS_MD_NONE, hash, sizeof hash,
+ sig, sizeof sig, &sig_len,
+ mbedtls_test_rnd_std_rand, NULL)
+ == 0);
+ TEST_ASSERT(sig_len == RSA_KEY_LEN);
+ TEST_ASSERT(mbedtls_pk_verify(&rsa, MBEDTLS_MD_NONE,
+ hash, sizeof hash, sig, sig_len) == 0);
/* Test decrypt */
- TEST_ASSERT( mbedtls_pk_encrypt( &rsa, msg, sizeof msg,
- ciph, &ciph_len, sizeof ciph,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
- TEST_ASSERT( mbedtls_pk_decrypt( &alt, ciph, ciph_len,
- test, &test_len, sizeof test,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
- TEST_ASSERT( test_len == sizeof msg );
- TEST_ASSERT( memcmp( test, msg, test_len ) == 0 );
+ TEST_ASSERT(mbedtls_pk_encrypt(&rsa, msg, sizeof msg,
+ ciph, &ciph_len, sizeof ciph,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
+ TEST_ASSERT(mbedtls_pk_decrypt(&alt, ciph, ciph_len,
+ test, &test_len, sizeof test,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
+ TEST_ASSERT(test_len == sizeof msg);
+ TEST_ASSERT(memcmp(test, msg, test_len) == 0);
/* Test forbidden operations */
- TEST_ASSERT( mbedtls_pk_encrypt( &alt, msg, sizeof msg,
- ciph, &ciph_len, sizeof ciph,
- mbedtls_test_rnd_std_rand, NULL ) == ret );
- TEST_ASSERT( mbedtls_pk_verify( &alt, MBEDTLS_MD_NONE,
- hash, sizeof hash, sig, sig_len ) == ret );
- TEST_ASSERT( mbedtls_pk_debug( &alt, dbg_items ) == ret );
+ TEST_ASSERT(mbedtls_pk_encrypt(&alt, msg, sizeof msg,
+ ciph, &ciph_len, sizeof ciph,
+ mbedtls_test_rnd_std_rand, NULL) == ret);
+ TEST_ASSERT(mbedtls_pk_verify(&alt, MBEDTLS_MD_NONE,
+ hash, sizeof hash, sig, sig_len) == ret);
+ TEST_ASSERT(mbedtls_pk_debug(&alt, dbg_items) == ret);
exit:
- mbedtls_rsa_free( &raw );
- mbedtls_pk_free( &rsa ); mbedtls_pk_free( &alt );
- USE_PSA_DONE( );
+ mbedtls_rsa_free(&raw);
+ mbedtls_pk_free(&rsa); mbedtls_pk_free(&alt);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA:MBEDTLS_USE_PSA_CRYPTO */
-void pk_psa_sign( int parameter_arg,
- int psa_type_arg, int expected_bits_arg )
+void pk_psa_sign(int parameter_arg,
+ int psa_type_arg, int expected_bits_arg)
{
mbedtls_pk_context pk;
unsigned char hash[32];
@@ -1220,144 +1208,139 @@
* - parse it to a PK context and verify the signature this way
*/
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
- if( PSA_KEY_TYPE_IS_RSA( psa_type_arg ) )
- {
+ if (PSA_KEY_TYPE_IS_RSA(psa_type_arg)) {
/* Create legacy RSA public/private key in PK context. */
- mbedtls_pk_init( &pk );
- TEST_ASSERT( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
- TEST_ASSERT( mbedtls_rsa_gen_key( mbedtls_pk_rsa( pk ),
- mbedtls_test_rnd_std_rand, NULL,
- parameter_arg, 3 ) == 0 );
- alg_psa = PSA_ALG_RSA_PKCS1V15_SIGN( PSA_ALG_SHA_256 );
- }
- else
+ mbedtls_pk_init(&pk);
+ TEST_ASSERT(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
+ TEST_ASSERT(mbedtls_rsa_gen_key(mbedtls_pk_rsa(pk),
+ mbedtls_test_rnd_std_rand, NULL,
+ parameter_arg, 3) == 0);
+ alg_psa = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256);
+ } else
#endif /* MBEDTLS_RSA_C && MBEDTLS_GENPRIME */
#if defined(MBEDTLS_ECDSA_C)
- if( PSA_KEY_TYPE_IS_ECC_KEY_PAIR( psa_type_arg ) )
- {
+ if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(psa_type_arg)) {
mbedtls_ecp_group_id grpid = parameter_arg;
/* Create legacy EC public/private key in PK context. */
- mbedtls_pk_init( &pk );
- TEST_ASSERT( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == 0 );
- TEST_ASSERT( mbedtls_ecp_gen_key( grpid,
- (mbedtls_ecp_keypair*) pk.pk_ctx,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
- alg_psa = PSA_ALG_ECDSA( PSA_ALG_SHA_256 );
- }
- else
+ mbedtls_pk_init(&pk);
+ TEST_ASSERT(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)) == 0);
+ TEST_ASSERT(mbedtls_ecp_gen_key(grpid,
+ (mbedtls_ecp_keypair *) pk.pk_ctx,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
+ alg_psa = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
+ } else
#endif /* MBEDTLS_ECDSA_C */
{
(void) parameter_arg;
- TEST_ASSUME( ! "Opaque PK key not supported in this configuration" );
+ TEST_ASSUME(!"Opaque PK key not supported in this configuration");
}
/* Export underlying public key for re-importing in a legacy context. */
- ret = mbedtls_pk_write_pubkey_der( &pk, pkey_legacy,
- sizeof( pkey_legacy ) );
- TEST_ASSERT( ret >= 0 );
+ ret = mbedtls_pk_write_pubkey_der(&pk, pkey_legacy,
+ sizeof(pkey_legacy));
+ TEST_ASSERT(ret >= 0);
klen_legacy = (size_t) ret;
/* mbedtls_pk_write_pubkey_der() writes backwards in the data buffer. */
- pkey_legacy_start = pkey_legacy + sizeof( pkey_legacy ) - klen_legacy;
+ pkey_legacy_start = pkey_legacy + sizeof(pkey_legacy) - klen_legacy;
/* Turn PK context into an opaque one. */
- TEST_ASSERT( mbedtls_pk_wrap_as_opaque( &pk, &key_id, alg_psa,
- PSA_KEY_USAGE_SIGN_HASH,
- PSA_ALG_NONE ) == 0 );
+ TEST_ASSERT(mbedtls_pk_wrap_as_opaque(&pk, &key_id, alg_psa,
+ PSA_KEY_USAGE_SIGN_HASH,
+ PSA_ALG_NONE) == 0);
- PSA_ASSERT( psa_get_key_attributes( key_id, &attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ), expected_type );
- TEST_EQUAL( psa_get_key_bits( &attributes ), expected_bits );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ),
- PSA_KEY_LIFETIME_VOLATILE );
+ PSA_ASSERT(psa_get_key_attributes(key_id, &attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes), expected_type);
+ TEST_EQUAL(psa_get_key_bits(&attributes), expected_bits);
+ TEST_EQUAL(psa_get_key_lifetime(&attributes),
+ PSA_KEY_LIFETIME_VOLATILE);
- memset( hash, 0x2a, sizeof hash );
- memset( sig, 0, sizeof sig );
+ memset(hash, 0x2a, sizeof hash);
+ memset(sig, 0, sizeof sig);
- TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256,
- hash, sizeof hash, sig, sizeof sig, &sig_len,
- NULL, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_pk_sign(&pk, MBEDTLS_MD_SHA256,
+ hash, sizeof hash, sig, sizeof sig, &sig_len,
+ NULL, NULL) == 0);
/* Export underlying public key for re-importing in a psa context. */
- ret = mbedtls_pk_write_pubkey_der( &pk, pkey_psa,
- sizeof( pkey_psa ) );
- TEST_ASSERT( ret >= 0 );
+ ret = mbedtls_pk_write_pubkey_der(&pk, pkey_psa,
+ sizeof(pkey_psa));
+ TEST_ASSERT(ret >= 0);
klen_psa = (size_t) ret;
/* mbedtls_pk_write_pubkey_der() writes backwards in the data buffer. */
- pkey_psa_start = pkey_psa + sizeof( pkey_psa ) - klen_psa;
+ pkey_psa_start = pkey_psa + sizeof(pkey_psa) - klen_psa;
- TEST_ASSERT( klen_psa == klen_legacy );
- TEST_ASSERT( memcmp( pkey_psa_start, pkey_legacy_start, klen_psa ) == 0 );
+ TEST_ASSERT(klen_psa == klen_legacy);
+ TEST_ASSERT(memcmp(pkey_psa_start, pkey_legacy_start, klen_psa) == 0);
- mbedtls_pk_free( &pk );
- TEST_ASSERT( PSA_SUCCESS == psa_destroy_key( key_id ) );
+ mbedtls_pk_free(&pk);
+ TEST_ASSERT(PSA_SUCCESS == psa_destroy_key(key_id));
- mbedtls_pk_init( &pk );
- TEST_ASSERT( mbedtls_pk_parse_public_key( &pk, pkey_legacy_start,
- klen_legacy ) == 0 );
- TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA256,
- hash, sizeof hash, sig, sig_len ) == 0 );
+ mbedtls_pk_init(&pk);
+ TEST_ASSERT(mbedtls_pk_parse_public_key(&pk, pkey_legacy_start,
+ klen_legacy) == 0);
+ TEST_ASSERT(mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256,
+ hash, sizeof hash, sig, sig_len) == 0);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_pk_free( &pk );
- USE_PSA_DONE( );
+ mbedtls_pk_free(&pk);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_GENPRIME */
-void pk_psa_sign_ext( int pk_type, int parameter, int key_pk_type, int md_alg )
+void pk_psa_sign_ext(int pk_type, int parameter, int key_pk_type, int md_alg)
{
/* See the description of pk_genkey() for the description of the `parameter` argument. */
mbedtls_pk_context pk;
size_t sig_len;
unsigned char sig[MBEDTLS_PK_SIGNATURE_MAX_SIZE];
unsigned char hash[PSA_HASH_MAX_SIZE];
- size_t hash_len = mbedtls_hash_info_get_size( md_alg );
+ size_t hash_len = mbedtls_hash_info_get_size(md_alg);
void const *options = NULL;
mbedtls_pk_rsassa_pss_options rsassa_pss_options;
- memset( hash, 0x2a, sizeof( hash ) );
- memset( sig, 0, sizeof( sig ) );
+ memset(hash, 0x2a, sizeof(hash));
+ memset(sig, 0, sizeof(sig));
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
PSA_INIT();
- TEST_ASSERT( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( pk_type ) ) == 0 );
+ TEST_ASSERT(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(pk_type)) == 0);
- TEST_ASSERT( pk_genkey( &pk, parameter ) == 0 );
+ TEST_ASSERT(pk_genkey(&pk, parameter) == 0);
- TEST_ASSERT( mbedtls_pk_sign_ext( key_pk_type, &pk, md_alg, hash, hash_len,
- sig, sizeof( sig ), &sig_len,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_pk_sign_ext(key_pk_type, &pk, md_alg, hash, hash_len,
+ sig, sizeof(sig), &sig_len,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
- if( key_pk_type == MBEDTLS_PK_RSASSA_PSS )
- {
+ if (key_pk_type == MBEDTLS_PK_RSASSA_PSS) {
rsassa_pss_options.mgf1_hash_id = md_alg;
- TEST_ASSERT( hash_len != 0 );
+ TEST_ASSERT(hash_len != 0);
rsassa_pss_options.expected_salt_len = hash_len;
- options = (const void*) &rsassa_pss_options;
+ options = (const void *) &rsassa_pss_options;
}
- TEST_ASSERT( mbedtls_pk_verify_ext( key_pk_type, options, &pk, md_alg,
- hash, hash_len, sig, sig_len ) == 0 );
+ TEST_ASSERT(mbedtls_pk_verify_ext(key_pk_type, options, &pk, md_alg,
+ hash, hash_len, sig, sig_len) == 0);
exit:
- PSA_DONE( );
- mbedtls_pk_free( &pk );
+ PSA_DONE();
+ mbedtls_pk_free(&pk);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_GENPRIME:MBEDTLS_USE_PSA_CRYPTO */
-void pk_psa_wrap_sign_ext( int pk_type, int parameter, int key_pk_type, int md_alg )
+void pk_psa_wrap_sign_ext(int pk_type, int parameter, int key_pk_type, int md_alg)
{
/* See the description of mbedtls_rsa_gen_key() for the description of the `parameter` argument. */
mbedtls_pk_context pk;
@@ -1367,69 +1350,69 @@
unsigned char pkey[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE];
unsigned char *pkey_start;
unsigned char hash[PSA_HASH_MAX_SIZE];
- psa_algorithm_t psa_md_alg = mbedtls_hash_info_psa_from_md( md_alg );
+ psa_algorithm_t psa_md_alg = mbedtls_hash_info_psa_from_md(md_alg);
psa_algorithm_t psa_alg;
- size_t hash_len = PSA_HASH_LENGTH( psa_md_alg );
+ size_t hash_len = PSA_HASH_LENGTH(psa_md_alg);
void const *options = NULL;
mbedtls_pk_rsassa_pss_options rsassa_pss_options;
int ret;
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
PSA_INIT();
/* Create legacy RSA public/private key in PK context. */
- mbedtls_pk_init( &pk );
- TEST_EQUAL( mbedtls_pk_setup( &pk,
- mbedtls_pk_info_from_type( pk_type ) ), 0 );
- TEST_EQUAL( mbedtls_rsa_gen_key( mbedtls_pk_rsa( pk ),
- mbedtls_test_rnd_std_rand, NULL,
- parameter, 3 ), 0 );
+ mbedtls_pk_init(&pk);
+ TEST_EQUAL(mbedtls_pk_setup(&pk,
+ mbedtls_pk_info_from_type(pk_type)), 0);
+ TEST_EQUAL(mbedtls_rsa_gen_key(mbedtls_pk_rsa(pk),
+ mbedtls_test_rnd_std_rand, NULL,
+ parameter, 3), 0);
/* Export underlying public key for re-importing in a legacy context. */
- ret = mbedtls_pk_write_pubkey_der( &pk, pkey, sizeof( pkey ) );
- TEST_ASSERT( ret >= 0 );
+ ret = mbedtls_pk_write_pubkey_der(&pk, pkey, sizeof(pkey));
+ TEST_ASSERT(ret >= 0);
pkey_len = (size_t) ret;
/* mbedtls_pk_write_pubkey_der() writes backwards in the data buffer. */
- pkey_start = pkey + sizeof( pkey ) - pkey_len;
+ pkey_start = pkey + sizeof(pkey) - pkey_len;
- if( key_pk_type == MBEDTLS_PK_RSA )
- psa_alg = PSA_ALG_RSA_PKCS1V15_SIGN( psa_md_alg );
- else if( key_pk_type == MBEDTLS_PK_RSASSA_PSS )
- psa_alg = PSA_ALG_RSA_PSS( psa_md_alg );
- else
- TEST_ASSUME( ! "PK key type not supported in this configuration" );
+ if (key_pk_type == MBEDTLS_PK_RSA) {
+ psa_alg = PSA_ALG_RSA_PKCS1V15_SIGN(psa_md_alg);
+ } else if (key_pk_type == MBEDTLS_PK_RSASSA_PSS) {
+ psa_alg = PSA_ALG_RSA_PSS(psa_md_alg);
+ } else {
+ TEST_ASSUME(!"PK key type not supported in this configuration");
+ }
/* Turn PK context into an opaque one. */
- TEST_EQUAL( mbedtls_pk_wrap_as_opaque( &pk, &key_id, psa_alg,
- PSA_KEY_USAGE_SIGN_HASH,
- PSA_ALG_NONE ), 0 );
+ TEST_EQUAL(mbedtls_pk_wrap_as_opaque(&pk, &key_id, psa_alg,
+ PSA_KEY_USAGE_SIGN_HASH,
+ PSA_ALG_NONE), 0);
- memset( hash, 0x2a, sizeof( hash ) );
- memset( sig, 0, sizeof( sig ) );
+ memset(hash, 0x2a, sizeof(hash));
+ memset(sig, 0, sizeof(sig));
- TEST_EQUAL( mbedtls_pk_sign_ext( key_pk_type, &pk, md_alg, hash, hash_len,
- sig, sizeof( sig ), &sig_len,
- mbedtls_test_rnd_std_rand, NULL ), 0 );
+ TEST_EQUAL(mbedtls_pk_sign_ext(key_pk_type, &pk, md_alg, hash, hash_len,
+ sig, sizeof(sig), &sig_len,
+ mbedtls_test_rnd_std_rand, NULL), 0);
- mbedtls_pk_free( &pk );
- TEST_EQUAL( PSA_SUCCESS, psa_destroy_key( key_id ) );
+ mbedtls_pk_free(&pk);
+ TEST_EQUAL(PSA_SUCCESS, psa_destroy_key(key_id));
- mbedtls_pk_init( &pk );
- TEST_EQUAL( mbedtls_pk_parse_public_key( &pk, pkey_start, pkey_len ), 0 );
+ mbedtls_pk_init(&pk);
+ TEST_EQUAL(mbedtls_pk_parse_public_key(&pk, pkey_start, pkey_len), 0);
- if( key_pk_type == MBEDTLS_PK_RSASSA_PSS )
- {
+ if (key_pk_type == MBEDTLS_PK_RSASSA_PSS) {
rsassa_pss_options.mgf1_hash_id = md_alg;
- TEST_ASSERT( hash_len != 0 );
+ TEST_ASSERT(hash_len != 0);
rsassa_pss_options.expected_salt_len = hash_len;
- options = (const void*) &rsassa_pss_options;
+ options = (const void *) &rsassa_pss_options;
}
- TEST_EQUAL( mbedtls_pk_verify_ext( key_pk_type, options, &pk, md_alg,
- hash, hash_len, sig, sig_len ), 0 );
+ TEST_EQUAL(mbedtls_pk_verify_ext(key_pk_type, options, &pk, md_alg,
+ hash, hash_len, sig, sig_len), 0);
exit:
- mbedtls_pk_free( &pk );
- PSA_DONE( );
+ mbedtls_pk_free(&pk);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pkcs12.function b/tests/suites/test_suite_pkcs12.function
index 3fad814..ab51e02 100644
--- a/tests/suites/test_suite_pkcs12.function
+++ b/tests/suites/test_suite_pkcs12.function
@@ -4,10 +4,9 @@
#include "mbedtls/legacy_or_psa.h"
-typedef enum
-{
- USE_NULL_INPUT = 0,
- USE_GIVEN_INPUT = 1,
+typedef enum {
+ USE_NULL_INPUT = 0,
+ USE_GIVEN_INPUT = 1,
} input_usage_method_t;
/* END_HEADER */
@@ -18,34 +17,36 @@
*/
/* BEGIN_CASE */
-void pkcs12_derive_key( int md_type, int key_size_arg,
- data_t *password_arg, int password_usage,
- data_t *salt_arg, int salt_usage,
- int iterations,
- data_t* expected_output, int expected_status )
+void pkcs12_derive_key(int md_type, int key_size_arg,
+ data_t *password_arg, int password_usage,
+ data_t *salt_arg, int salt_usage,
+ int iterations,
+ data_t *expected_output, int expected_status)
{
- unsigned char *output_data = NULL;
+ unsigned char *output_data = NULL;
- unsigned char *password = NULL;
- size_t password_len = 0;
- unsigned char *salt = NULL;
- size_t salt_len = 0;
- size_t key_size = key_size_arg;
+ unsigned char *password = NULL;
+ size_t password_len = 0;
+ unsigned char *salt = NULL;
+ size_t salt_len = 0;
+ size_t key_size = key_size_arg;
- if( password_usage == USE_GIVEN_INPUT )
- password = password_arg->x;
+ if (password_usage == USE_GIVEN_INPUT) {
+ password = password_arg->x;
+ }
- password_len = password_arg->len;
+ password_len = password_arg->len;
- if( salt_usage == USE_GIVEN_INPUT )
- salt = salt_arg->x;
+ if (salt_usage == USE_GIVEN_INPUT) {
+ salt = salt_arg->x;
+ }
- salt_len = salt_arg->len;
+ salt_len = salt_arg->len;
- ASSERT_ALLOC( output_data, key_size );
+ ASSERT_ALLOC(output_data, key_size);
- int ret = mbedtls_pkcs12_derivation( output_data,
+ int ret = mbedtls_pkcs12_derivation(output_data,
key_size,
password,
password_len,
@@ -53,18 +54,17 @@
salt_len,
md_type,
MBEDTLS_PKCS12_DERIVE_KEY,
- iterations );
+ iterations);
- TEST_EQUAL( ret, expected_status );
+ TEST_EQUAL(ret, expected_status);
- if( expected_status == 0 )
- {
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output_data, key_size );
- }
+ if (expected_status == 0) {
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output_data, key_size);
+ }
exit:
- mbedtls_free( output_data );
+ mbedtls_free(output_data);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pkcs1_v15.function b/tests/suites/test_suite_pkcs1_v15.function
index 0fad7c6..d0ea23c 100644
--- a/tests/suites/test_suite_pkcs1_v15.function
+++ b/tests/suites/test_suite_pkcs1_v15.function
@@ -11,10 +11,10 @@
*/
/* BEGIN_CASE */
-void pkcs1_rsaes_v15_encrypt( int mod, char * input_N,
- char * input_E, int hash,
- data_t * message_str, data_t * rnd_buf,
- data_t * result_str, int result )
+void pkcs1_rsaes_v15_encrypt(int mod, char *input_N,
+ char *input_E, int hash,
+ data_t *message_str, data_t *rnd_buf,
+ data_t *result_str, int result)
{
unsigned char output[128];
mbedtls_rsa_context ctx;
@@ -26,43 +26,43 @@
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
- memset( output, 0x00, sizeof( output ) );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V15, hash) == 0);
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- if( message_str->len == 0 )
+ if (message_str->len == 0) {
message_str->x = NULL;
- TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx,
- &mbedtls_test_rnd_buffer_rand,
- &info, message_str->len,
- message_str->x,
- output ) == result );
+ }
+ TEST_ASSERT(mbedtls_rsa_pkcs1_encrypt(&ctx,
+ &mbedtls_test_rnd_buffer_rand,
+ &info, message_str->len,
+ message_str->x,
+ output) == result);
- if( result == 0 )
- {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ if (result == 0) {
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_rsaes_v15_decrypt( int mod, char * input_P, char * input_Q,
- char * input_N, char * input_E, int hash,
- data_t * result_str, char * seed,
- data_t * message_str, int result )
+void pkcs1_rsaes_v15_decrypt(int mod, char *input_P, char *input_Q,
+ char *input_N, char *input_E, int hash,
+ data_t *result_str, char *seed,
+ data_t *message_str, int result)
{
unsigned char output[128];
mbedtls_rsa_context ctx;
@@ -71,60 +71,56 @@
mbedtls_mpi N, P, Q, E;
((void) seed);
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V15, hash) == 0);
- memset( output, 0x00, sizeof( output ) );
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(output, 0x00, sizeof(output));
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
- if( result_str->len == 0 )
- {
- TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info,
- &output_len, message_str->x,
- NULL, 0 ) == result );
- }
- else
- {
- TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info,
- &output_len, message_str->x,
- output, 1000 ) == result );
- if( result == 0 )
- {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- output_len,
- result_str->len) == 0 );
+ if (result_str->len == 0) {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_decrypt(&ctx,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info,
+ &output_len, message_str->x,
+ NULL, 0) == result);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_decrypt(&ctx,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info,
+ &output_len, message_str->x,
+ output, 1000) == result);
+ if (result == 0) {
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ output_len,
+ result_str->len) == 0);
}
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_v15_decode( data_t *input,
- int expected_plaintext_length_arg,
- int output_size_arg,
- int expected_result )
+void pkcs1_v15_decode(data_t *input,
+ int expected_plaintext_length_arg,
+ int output_size_arg,
+ int expected_result)
{
size_t expected_plaintext_length = expected_plaintext_length_arg;
size_t output_size = output_size_arg;
@@ -194,43 +190,40 @@
unsigned char final[128];
size_t output_length = 0x7EA0;
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
- mbedtls_mpi_init( &Nmpi ); mbedtls_mpi_init( &Empi );
- mbedtls_mpi_init( &Pmpi ); mbedtls_mpi_init( &Qmpi );
- mbedtls_rsa_init( &ctx );
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
+ mbedtls_mpi_init(&Nmpi); mbedtls_mpi_init(&Empi);
+ mbedtls_mpi_init(&Pmpi); mbedtls_mpi_init(&Qmpi);
+ mbedtls_rsa_init(&ctx);
- TEST_ASSERT( mbedtls_mpi_read_binary( &Nmpi, N, sizeof( N ) ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &Empi, E, sizeof( E ) ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &Pmpi, P, sizeof( P ) ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &Qmpi, Q, sizeof( Q ) ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&Nmpi, N, sizeof(N)) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&Empi, E, sizeof(E)) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&Pmpi, P, sizeof(P)) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&Qmpi, Q, sizeof(Q)) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &Nmpi, &Pmpi, &Qmpi,
- NULL, &Empi ) == 0 );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &Nmpi, &Pmpi, &Qmpi,
+ NULL, &Empi) == 0);
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
- TEST_ASSERT( input->len <= sizeof( N ) );
- memcpy( original, input->x, input->len );
- memset( original + input->len, 'd', sizeof( original ) - input->len );
- TEST_ASSERT( mbedtls_rsa_public( &ctx, original, intermediate ) == 0 );
+ TEST_ASSERT(input->len <= sizeof(N));
+ memcpy(original, input->x, input->len);
+ memset(original + input->len, 'd', sizeof(original) - input->len);
+ TEST_ASSERT(mbedtls_rsa_public(&ctx, original, intermediate) == 0);
- memcpy( final, default_content, sizeof( final ) );
- TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info, &output_length,
- intermediate, final,
- output_size ) == expected_result );
- if( expected_result == 0 )
- {
- TEST_ASSERT( output_length == expected_plaintext_length );
- TEST_ASSERT( memcmp( original + sizeof( N ) - output_length,
- final,
- output_length ) == 0 );
- }
- else if( expected_result == MBEDTLS_ERR_RSA_INVALID_PADDING ||
- expected_result == MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE )
- {
+ memcpy(final, default_content, sizeof(final));
+ TEST_ASSERT(mbedtls_rsa_pkcs1_decrypt(&ctx,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info, &output_length,
+ intermediate, final,
+ output_size) == expected_result);
+ if (expected_result == 0) {
+ TEST_ASSERT(output_length == expected_plaintext_length);
+ TEST_ASSERT(memcmp(original + sizeof(N) - output_length,
+ final,
+ output_length) == 0);
+ } else if (expected_result == MBEDTLS_ERR_RSA_INVALID_PADDING ||
+ expected_result == MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) {
size_t max_payload_length =
- output_size > sizeof( N ) - 11 ? sizeof( N ) - 11 : output_size;
+ output_size > sizeof(N) - 11 ? sizeof(N) - 11 : output_size;
size_t i;
size_t count = 0;
@@ -239,34 +232,36 @@
* implementation currently does. Alternative implementations
* may produce different output, so we only perform these precise
* checks when using the default implementation. */
- TEST_ASSERT( output_length == max_payload_length );
- for( i = 0; i < max_payload_length; i++ )
- TEST_ASSERT( final[i] == 0 );
+ TEST_ASSERT(output_length == max_payload_length);
+ for (i = 0; i < max_payload_length; i++) {
+ TEST_ASSERT(final[i] == 0);
+ }
#endif
/* Even in alternative implementations, the outputs must have
* changed, otherwise it indicates at least a timing vulnerability
* because no write to the outputs is performed in the bad case. */
- TEST_ASSERT( output_length != 0x7EA0 );
- for( i = 0; i < max_payload_length; i++ )
- count += ( final[i] == default_content[i] );
+ TEST_ASSERT(output_length != 0x7EA0);
+ for (i = 0; i < max_payload_length; i++) {
+ count += (final[i] == default_content[i]);
+ }
/* If more than 16 bytes are unchanged in final, that's evidence
* that final wasn't overwritten. */
- TEST_ASSERT( count < 16 );
+ TEST_ASSERT(count < 16);
}
exit:
- mbedtls_mpi_free( &Nmpi ); mbedtls_mpi_free( &Empi );
- mbedtls_mpi_free( &Pmpi ); mbedtls_mpi_free( &Qmpi );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&Nmpi); mbedtls_mpi_free(&Empi);
+ mbedtls_mpi_free(&Pmpi); mbedtls_mpi_free(&Qmpi);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_rsassa_v15_sign( int mod, char * input_P,
- char * input_Q, char * input_N,
- char * input_E, int digest, int hash,
- data_t * message_str, data_t * rnd_buf,
- data_t * result_str, int result )
+void pkcs1_rsassa_v15_sign(int mod, char *input_P,
+ char *input_Q, char *input_N,
+ char *input_E, int digest, int hash,
+ data_t *message_str, data_t *rnd_buf,
+ data_t *result_str, int result)
{
unsigned char output[128];
mbedtls_rsa_context ctx;
@@ -278,66 +273,66 @@
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V15, hash) == 0);
- memset( output, 0x00, sizeof( output ) );
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_sign(
- &ctx, &mbedtls_test_rnd_buffer_rand, &info,
- digest, message_str->len, message_str->x,
- output ) == result );
- if( result == 0 )
- {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_sign(
+ &ctx, &mbedtls_test_rnd_buffer_rand, &info,
+ digest, message_str->len, message_str->x,
+ output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_rsassa_v15_verify( int mod, char * input_N, char * input_E,
- int digest, int hash, data_t * message_str,
- char * salt, data_t * result_str, int result )
+void pkcs1_rsassa_v15_verify(int mod, char *input_N, char *input_E,
+ int digest, int hash, data_t *message_str,
+ char *salt, data_t *result_str, int result)
{
mbedtls_rsa_context ctx;
mbedtls_mpi N, E;
((void) salt);
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V15, hash) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, digest, message_str->len, message_str->x, result_str->x ) == result );
+ TEST_ASSERT(mbedtls_rsa_pkcs1_verify(&ctx, digest, message_str->len, message_str->x,
+ result_str->x) == result);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pkcs1_v21.function b/tests/suites/test_suite_pkcs1_v21.function
index 593c047..376c752 100644
--- a/tests/suites/test_suite_pkcs1_v21.function
+++ b/tests/suites/test_suite_pkcs1_v21.function
@@ -9,9 +9,9 @@
*/
/* BEGIN_CASE */
-void pkcs1_rsaes_oaep_encrypt( int mod, data_t * input_N, data_t * input_E,
- int hash, data_t * message_str, data_t * rnd_buf,
- data_t * result_str, int result )
+void pkcs1_rsaes_oaep_encrypt(int mod, data_t *input_N, data_t *input_E,
+ int hash, data_t *message_str, data_t *rnd_buf,
+ data_t *result_str, int result)
{
unsigned char output[256];
mbedtls_rsa_context ctx;
@@ -23,41 +23,41 @@
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
- memset( output, 0x00, sizeof( output ) );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V21, hash) == 0);
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &E, input_E->x, input_E->len ) == 0 );
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&N, input_N->x, input_N->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&E, input_E->x, input_E->len) == 0);
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- if( message_str->len == 0 )
+ if (message_str->len == 0) {
message_str->x = NULL;
- TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx,
- &mbedtls_test_rnd_buffer_rand,
- &info, message_str->len,
- message_str->x,
- output ) == result );
- if( result == 0 )
- {
- ASSERT_COMPARE( output, ctx.len, result_str->x, result_str->len );
+ }
+ TEST_ASSERT(mbedtls_rsa_pkcs1_encrypt(&ctx,
+ &mbedtls_test_rnd_buffer_rand,
+ &info, message_str->len,
+ message_str->x,
+ output) == result);
+ if (result == 0) {
+ ASSERT_COMPARE(output, ctx.len, result_str->x, result_str->len);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_rsaes_oaep_decrypt( int mod, data_t * input_P, data_t * input_Q,
- data_t * input_N, data_t * input_E, int hash,
- data_t * result_str, char * seed, data_t * message_str,
- int result )
+void pkcs1_rsaes_oaep_decrypt(int mod, data_t *input_P, data_t *input_Q,
+ data_t *input_N, data_t *input_E, int hash,
+ data_t *result_str, char *seed, data_t *message_str,
+ int result)
{
unsigned char output[64];
mbedtls_rsa_context ctx;
@@ -66,61 +66,57 @@
mbedtls_mpi N, P, Q, E;
((void) seed);
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V21, hash) == 0);
- memset( output, 0x00, sizeof( output ) );
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(output, 0x00, sizeof(output));
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_mpi_read_binary( &P, input_P->x, input_P->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &Q, input_Q->x, input_Q->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &E, input_E->x, input_E->len ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&P, input_P->x, input_P->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&Q, input_Q->x, input_Q->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&N, input_N->x, input_N->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&E, input_E->x, input_E->len) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
- if( result_str->len == 0 )
- {
- TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info,
- &output_len, message_str->x,
- NULL, 0 ) == result );
- }
- else
- {
- TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info,
- &output_len, message_str->x,
- output,
- sizeof( output ) ) == result );
- if( result == 0 )
- {
- ASSERT_COMPARE( output, output_len, result_str->x, result_str->len );
+ if (result_str->len == 0) {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_decrypt(&ctx,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info,
+ &output_len, message_str->x,
+ NULL, 0) == result);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_decrypt(&ctx,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info,
+ &output_len, message_str->x,
+ output,
+ sizeof(output)) == result);
+ if (result == 0) {
+ ASSERT_COMPARE(output, output_len, result_str->x, result_str->len);
}
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_rsassa_pss_sign( int mod, data_t * input_P, data_t * input_Q,
- data_t * input_N, data_t * input_E, int digest,
- int hash, data_t * hash_digest, data_t * rnd_buf,
- data_t * result_str, int fixed_salt_length,
- int result )
+void pkcs1_rsassa_pss_sign(int mod, data_t *input_P, data_t *input_Q,
+ data_t *input_N, data_t *input_E, int digest,
+ int hash, data_t *hash_digest, data_t *rnd_buf,
+ data_t *result_str, int fixed_salt_length,
+ int result)
{
unsigned char output[512];
mbedtls_rsa_context ctx;
@@ -132,118 +128,116 @@
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V21, hash) == 0);
- memset( output, 0x00, sizeof( output ) );
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_mpi_read_binary( &P, input_P->x, input_P->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &Q, input_Q->x, input_Q->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &E, input_E->x, input_E->len ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&P, input_P->x, input_P->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&Q, input_Q->x, input_Q->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&N, input_N->x, input_N->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&E, input_E->x, input_E->len) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
- if (fixed_salt_length == MBEDTLS_RSA_SALT_LEN_ANY)
- {
- TEST_ASSERT( mbedtls_rsa_pkcs1_sign(
- &ctx, &mbedtls_test_rnd_buffer_rand, &info,
- digest, hash_digest->len, hash_digest->x, output ) == result );
- if( result == 0 )
- {
- ASSERT_COMPARE( output, ctx.len, result_str->x, result_str->len );
+ if (fixed_salt_length == MBEDTLS_RSA_SALT_LEN_ANY) {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_sign(
+ &ctx, &mbedtls_test_rnd_buffer_rand, &info,
+ digest, hash_digest->len, hash_digest->x, output) == result);
+ if (result == 0) {
+ ASSERT_COMPARE(output, ctx.len, result_str->x, result_str->len);
}
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
}
- TEST_ASSERT( mbedtls_rsa_rsassa_pss_sign_ext(
- &ctx, &mbedtls_test_rnd_buffer_rand, &info,
- digest, hash_digest->len, hash_digest->x,
- fixed_salt_length, output ) == result );
- if( result == 0 )
- {
- ASSERT_COMPARE( output, ctx.len, result_str->x, result_str->len );
+ TEST_ASSERT(mbedtls_rsa_rsassa_pss_sign_ext(
+ &ctx, &mbedtls_test_rnd_buffer_rand, &info,
+ digest, hash_digest->len, hash_digest->x,
+ fixed_salt_length, output) == result);
+ if (result == 0) {
+ ASSERT_COMPARE(output, ctx.len, result_str->x, result_str->len);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_rsassa_pss_verify( int mod, data_t * input_N, data_t * input_E,
- int digest, int hash, data_t * hash_digest,
- char * salt, data_t * result_str, int result )
+void pkcs1_rsassa_pss_verify(int mod, data_t *input_N, data_t *input_E,
+ int digest, int hash, data_t *hash_digest,
+ char *salt, data_t *result_str, int result)
{
mbedtls_rsa_context ctx;
mbedtls_mpi N, E;
((void) salt);
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V21, hash) == 0);
- TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &E, input_E->x, input_E->len ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&N, input_N->x, input_N->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&E, input_E->x, input_E->len) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, digest, hash_digest->len, hash_digest->x, result_str->x ) == result );
+ TEST_ASSERT(mbedtls_rsa_pkcs1_verify(&ctx, digest, hash_digest->len, hash_digest->x,
+ result_str->x) == result);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pkcs1_rsassa_pss_verify_ext( int mod, data_t * input_N, data_t * input_E,
- int msg_digest_id, int ctx_hash,
- int mgf_hash, int salt_len,
- data_t * hash_digest,
- data_t * result_str, int result_simple,
- int result_full )
+void pkcs1_rsassa_pss_verify_ext(int mod, data_t *input_N, data_t *input_E,
+ int msg_digest_id, int ctx_hash,
+ int mgf_hash, int salt_len,
+ data_t *hash_digest,
+ data_t *result_str, int result_simple,
+ int result_full)
{
mbedtls_rsa_context ctx;
mbedtls_mpi N, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V21, ctx_hash ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V21, ctx_hash) == 0);
- TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &E, input_E->x, input_E->len ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&N, input_N->x, input_N->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&E, input_E->x, input_E->len) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) ((mod + 7) / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, msg_digest_id,
- hash_digest->len, hash_digest->x,
- result_str->x ) == result_simple );
+ TEST_ASSERT(mbedtls_rsa_pkcs1_verify(&ctx, msg_digest_id,
+ hash_digest->len, hash_digest->x,
+ result_str->x) == result_simple);
- TEST_ASSERT( mbedtls_rsa_rsassa_pss_verify_ext( &ctx, msg_digest_id, hash_digest->len,
- hash_digest->x, mgf_hash, salt_len,
- result_str->x ) == result_full );
+ TEST_ASSERT(mbedtls_rsa_rsassa_pss_verify_ext(&ctx, msg_digest_id, hash_digest->len,
+ hash_digest->x, mgf_hash, salt_len,
+ result_str->x) == result_full);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pkcs5.function b/tests/suites/test_suite_pkcs5.function
index 7b7ed3d..fd731e9 100644
--- a/tests/suites/test_suite_pkcs5.function
+++ b/tests/suites/test_suite_pkcs5.function
@@ -9,25 +9,25 @@
*/
/* BEGIN_CASE */
-void pbkdf2_hmac( int hash, data_t * pw_str, data_t * salt_str,
- int it_cnt, int key_len, data_t * result_key_string )
+void pbkdf2_hmac(int hash, data_t *pw_str, data_t *salt_str,
+ int it_cnt, int key_len, data_t *result_key_string)
{
unsigned char key[100];
PSA_INIT_IF_NO_MD();
- TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac_ext( hash, pw_str->x, pw_str->len,
- salt_str->x, salt_str->len,
- it_cnt, key_len, key ) == 0 );
+ TEST_ASSERT(mbedtls_pkcs5_pbkdf2_hmac_ext(hash, pw_str->x, pw_str->len,
+ salt_str->x, salt_str->len,
+ it_cnt, key_len, key) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( key, result_key_string->x,
- key_len, result_key_string->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(key, result_key_string->x,
+ key_len, result_key_string->len) == 0);
PSA_DONE_IF_NO_MD();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */
-void mbedtls_pkcs5_pbes2( int params_tag, data_t *params_hex, data_t *pw,
- data_t *data, int ref_ret, data_t *ref_out )
+void mbedtls_pkcs5_pbes2(int params_tag, data_t *params_hex, data_t *pw,
+ data_t *data, int ref_ret, data_t *ref_out)
{
int my_ret;
mbedtls_asn1_buf params;
@@ -39,24 +39,25 @@
params.p = params_hex->x;
params.len = params_hex->len;
- my_out = mbedtls_test_zero_alloc( ref_out->len );
+ my_out = mbedtls_test_zero_alloc(ref_out->len);
- my_ret = mbedtls_pkcs5_pbes2( ¶ms, MBEDTLS_PKCS5_DECRYPT,
- pw->x, pw->len, data->x, data->len, my_out );
- TEST_ASSERT( my_ret == ref_ret );
+ my_ret = mbedtls_pkcs5_pbes2(¶ms, MBEDTLS_PKCS5_DECRYPT,
+ pw->x, pw->len, data->x, data->len, my_out);
+ TEST_ASSERT(my_ret == ref_ret);
- if( ref_ret == 0 )
- TEST_ASSERT( memcmp( my_out, ref_out->x, ref_out->len ) == 0 );
+ if (ref_ret == 0) {
+ TEST_ASSERT(memcmp(my_out, ref_out->x, ref_out->len) == 0);
+ }
exit:
- mbedtls_free( my_out );
+ mbedtls_free(my_out);
PSA_DONE_IF_NO_MD();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void pkcs5_selftest( )
+void pkcs5_selftest()
{
- TEST_ASSERT( mbedtls_pkcs5_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_pkcs5_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pkcs7.function b/tests/suites/test_suite_pkcs7.function
index 3d7dec6..4fc416a 100644
--- a/tests/suites/test_suite_pkcs7.function
+++ b/tests/suites/test_suite_pkcs7.function
@@ -15,7 +15,7 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
-void pkcs7_parse( char *pkcs7_file, int res_expect )
+void pkcs7_parse(char *pkcs7_file, int res_expect)
{
unsigned char *pkcs7_buf = NULL;
size_t buflen;
@@ -23,22 +23,23 @@
mbedtls_pkcs7 pkcs7;
- mbedtls_pkcs7_init( &pkcs7 );
+ mbedtls_pkcs7_init(&pkcs7);
- res = mbedtls_pk_load_file( pkcs7_file, &pkcs7_buf, &buflen );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_pk_load_file(pkcs7_file, &pkcs7_buf, &buflen);
+ TEST_EQUAL(res, 0);
- res = mbedtls_pkcs7_parse_der( &pkcs7, pkcs7_buf, buflen );
- TEST_EQUAL( res, res_expect );
+ res = mbedtls_pkcs7_parse_der(&pkcs7, pkcs7_buf, buflen);
+ TEST_EQUAL(res, res_expect);
exit:
- mbedtls_free( pkcs7_buf );
- mbedtls_pkcs7_free( &pkcs7 );
+ mbedtls_free(pkcs7_buf);
+ mbedtls_pkcs7_free(&pkcs7);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C */
-void pkcs7_verify( char *pkcs7_file, char *crt, char *filetobesigned, int do_hash_alg, int res_expect )
+void pkcs7_verify(char *pkcs7_file, char *crt, char *filetobesigned, int do_hash_alg,
+ int res_expect)
{
unsigned char *pkcs7_buf = NULL;
size_t buflen;
@@ -54,63 +55,65 @@
mbedtls_pkcs7 pkcs7;
mbedtls_x509_crt x509;
- mbedtls_pkcs7_init( &pkcs7 );
- mbedtls_x509_crt_init( &x509 );
+ mbedtls_pkcs7_init(&pkcs7);
+ mbedtls_x509_crt_init(&x509);
USE_PSA_INIT();
- res = mbedtls_x509_crt_parse_file( &x509, crt );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_x509_crt_parse_file(&x509, crt);
+ TEST_EQUAL(res, 0);
- res = mbedtls_pk_load_file( pkcs7_file, &pkcs7_buf, &buflen );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_pk_load_file(pkcs7_file, &pkcs7_buf, &buflen);
+ TEST_EQUAL(res, 0);
- res = mbedtls_pkcs7_parse_der( &pkcs7, pkcs7_buf, buflen );
- TEST_EQUAL( res, MBEDTLS_PKCS7_SIGNED_DATA );
+ res = mbedtls_pkcs7_parse_der(&pkcs7, pkcs7_buf, buflen);
+ TEST_EQUAL(res, MBEDTLS_PKCS7_SIGNED_DATA);
- res = stat( filetobesigned, &st );
- TEST_EQUAL( res, 0 );
+ res = stat(filetobesigned, &st);
+ TEST_EQUAL(res, 0);
- file = fopen( filetobesigned, "rb" );
- TEST_ASSERT( file != NULL );
+ file = fopen(filetobesigned, "rb");
+ TEST_ASSERT(file != NULL);
datalen = st.st_size;
- ASSERT_ALLOC( data, datalen );
- TEST_ASSERT( data != NULL );
+ ASSERT_ALLOC(data, datalen);
+ TEST_ASSERT(data != NULL);
- buflen = fread( (void *)data , sizeof( unsigned char ), datalen, file );
- TEST_EQUAL( buflen, datalen );
- fclose( file );
+ buflen = fread((void *) data, sizeof(unsigned char), datalen, file);
+ TEST_EQUAL(buflen, datalen);
+ fclose(file);
- if( do_hash_alg )
- {
- res = mbedtls_oid_get_md_alg( &pkcs7.signed_data.digest_alg_identifiers, &md_alg );
- TEST_EQUAL( res, 0 );
- TEST_EQUAL( md_alg, (mbedtls_md_type_t) do_hash_alg );
- md_info = mbedtls_md_info_from_type( md_alg );
+ if (do_hash_alg) {
+ res = mbedtls_oid_get_md_alg(&pkcs7.signed_data.digest_alg_identifiers, &md_alg);
+ TEST_EQUAL(res, 0);
+ TEST_EQUAL(md_alg, (mbedtls_md_type_t) do_hash_alg);
+ md_info = mbedtls_md_info_from_type(md_alg);
- res = mbedtls_md( md_info, data, datalen, hash );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_md(md_info, data, datalen, hash);
+ TEST_EQUAL(res, 0);
- res = mbedtls_pkcs7_signed_hash_verify( &pkcs7, &x509, hash, sizeof(hash) );
+ res = mbedtls_pkcs7_signed_hash_verify(&pkcs7, &x509, hash, sizeof(hash));
+ } else {
+ res = mbedtls_pkcs7_signed_data_verify(&pkcs7, &x509, data, datalen);
}
- else
- {
- res = mbedtls_pkcs7_signed_data_verify( &pkcs7, &x509, data, datalen );
- }
- TEST_EQUAL( res, res_expect );
+ TEST_EQUAL(res, res_expect);
exit:
- mbedtls_x509_crt_free( &x509 );
- mbedtls_free( data );
- mbedtls_pkcs7_free( &pkcs7 );
- mbedtls_free( pkcs7_buf );
+ mbedtls_x509_crt_free(&x509);
+ mbedtls_free(data);
+ mbedtls_pkcs7_free(&pkcs7);
+ mbedtls_free(pkcs7_buf);
USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C */
-void pkcs7_verify_multiple_signers( char *pkcs7_file, char *crt1, char *crt2, char *filetobesigned, int do_hash_alg, int res_expect )
+void pkcs7_verify_multiple_signers(char *pkcs7_file,
+ char *crt1,
+ char *crt2,
+ char *filetobesigned,
+ int do_hash_alg,
+ int res_expect)
{
unsigned char *pkcs7_buf = NULL;
size_t buflen;
@@ -127,68 +130,65 @@
mbedtls_x509_crt x509_1;
mbedtls_x509_crt x509_2;
- mbedtls_pkcs7_init( &pkcs7 );
- mbedtls_x509_crt_init( &x509_1 );
- mbedtls_x509_crt_init( &x509_2 );
+ mbedtls_pkcs7_init(&pkcs7);
+ mbedtls_x509_crt_init(&x509_1);
+ mbedtls_x509_crt_init(&x509_2);
USE_PSA_INIT();
- res = mbedtls_pk_load_file( pkcs7_file, &pkcs7_buf, &buflen );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_pk_load_file(pkcs7_file, &pkcs7_buf, &buflen);
+ TEST_EQUAL(res, 0);
- res = mbedtls_pkcs7_parse_der( &pkcs7, pkcs7_buf, buflen );
- TEST_EQUAL( res, MBEDTLS_PKCS7_SIGNED_DATA );
+ res = mbedtls_pkcs7_parse_der(&pkcs7, pkcs7_buf, buflen);
+ TEST_EQUAL(res, MBEDTLS_PKCS7_SIGNED_DATA);
- TEST_EQUAL( pkcs7.signed_data.no_of_signers, 2 );
+ TEST_EQUAL(pkcs7.signed_data.no_of_signers, 2);
- res = mbedtls_x509_crt_parse_file( &x509_1, crt1 );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_x509_crt_parse_file(&x509_1, crt1);
+ TEST_EQUAL(res, 0);
- res = mbedtls_x509_crt_parse_file( &x509_2, crt2 );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_x509_crt_parse_file(&x509_2, crt2);
+ TEST_EQUAL(res, 0);
- res = stat( filetobesigned, &st );
- TEST_EQUAL( res, 0 );
+ res = stat(filetobesigned, &st);
+ TEST_EQUAL(res, 0);
- file = fopen( filetobesigned, "rb" );
- TEST_ASSERT( file != NULL );
+ file = fopen(filetobesigned, "rb");
+ TEST_ASSERT(file != NULL);
datalen = st.st_size;
- ASSERT_ALLOC( data, datalen );
- buflen = fread( ( void * )data , sizeof( unsigned char ), datalen, file );
- TEST_EQUAL( buflen, datalen );
+ ASSERT_ALLOC(data, datalen);
+ buflen = fread((void *) data, sizeof(unsigned char), datalen, file);
+ TEST_EQUAL(buflen, datalen);
- fclose( file );
+ fclose(file);
- if( do_hash_alg )
- {
- res = mbedtls_oid_get_md_alg( &pkcs7.signed_data.digest_alg_identifiers, &md_alg );
- TEST_EQUAL( res, 0 );
- TEST_EQUAL( md_alg, MBEDTLS_MD_SHA256 );
+ if (do_hash_alg) {
+ res = mbedtls_oid_get_md_alg(&pkcs7.signed_data.digest_alg_identifiers, &md_alg);
+ TEST_EQUAL(res, 0);
+ TEST_EQUAL(md_alg, MBEDTLS_MD_SHA256);
- md_info = mbedtls_md_info_from_type( md_alg );
+ md_info = mbedtls_md_info_from_type(md_alg);
- res = mbedtls_md( md_info, data, datalen, hash );
- TEST_EQUAL( res, 0 );
+ res = mbedtls_md(md_info, data, datalen, hash);
+ TEST_EQUAL(res, 0);
- res = mbedtls_pkcs7_signed_hash_verify( &pkcs7, &x509_1, hash, sizeof(hash) );
- TEST_EQUAL( res, res_expect );
- }
- else
- {
- res = mbedtls_pkcs7_signed_data_verify( &pkcs7, &x509_1, data, datalen );
- TEST_EQUAL( res, res_expect );
+ res = mbedtls_pkcs7_signed_hash_verify(&pkcs7, &x509_1, hash, sizeof(hash));
+ TEST_EQUAL(res, res_expect);
+ } else {
+ res = mbedtls_pkcs7_signed_data_verify(&pkcs7, &x509_1, data, datalen);
+ TEST_EQUAL(res, res_expect);
}
- res = mbedtls_pkcs7_signed_data_verify( &pkcs7, &x509_2, data, datalen );
- TEST_EQUAL( res, res_expect );
+ res = mbedtls_pkcs7_signed_data_verify(&pkcs7, &x509_2, data, datalen);
+ TEST_EQUAL(res, res_expect);
exit:
- mbedtls_x509_crt_free( &x509_1 );
- mbedtls_x509_crt_free( &x509_2 );
- mbedtls_pkcs7_free( &pkcs7 );
- mbedtls_free( data );
- mbedtls_free( pkcs7_buf );
+ mbedtls_x509_crt_free(&x509_1);
+ mbedtls_x509_crt_free(&x509_2);
+ mbedtls_pkcs7_free(&pkcs7);
+ mbedtls_free(data);
+ mbedtls_free(pkcs7_buf);
USE_PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pkparse.function b/tests/suites/test_suite_pkparse.function
index c5e60ee..ff19981 100644
--- a/tests/suites/test_suite_pkparse.function
+++ b/tests/suites/test_suite_pkparse.function
@@ -11,126 +11,123 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_FS_IO */
-void pk_parse_keyfile_rsa( char * key_file, char * password, int result )
+void pk_parse_keyfile_rsa(char *key_file, char *password, int result)
{
mbedtls_pk_context ctx;
int res;
char *pwd = password;
PSA_INIT_IF_NO_MD();
- mbedtls_pk_init( &ctx );
+ mbedtls_pk_init(&ctx);
- if( strcmp( pwd, "NULL" ) == 0 )
+ if (strcmp(pwd, "NULL") == 0) {
pwd = NULL;
+ }
- res = mbedtls_pk_parse_keyfile( &ctx, key_file, pwd,
- mbedtls_test_rnd_std_rand, NULL );
+ res = mbedtls_pk_parse_keyfile(&ctx, key_file, pwd,
+ mbedtls_test_rnd_std_rand, NULL);
- TEST_ASSERT( res == result );
+ TEST_ASSERT(res == result);
- if( res == 0 )
- {
+ if (res == 0) {
mbedtls_rsa_context *rsa;
- TEST_ASSERT( mbedtls_pk_can_do( &ctx, MBEDTLS_PK_RSA ) );
- rsa = mbedtls_pk_rsa( ctx );
- TEST_ASSERT( mbedtls_rsa_check_privkey( rsa ) == 0 );
+ TEST_ASSERT(mbedtls_pk_can_do(&ctx, MBEDTLS_PK_RSA));
+ rsa = mbedtls_pk_rsa(ctx);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(rsa) == 0);
}
exit:
- mbedtls_pk_free( &ctx );
+ mbedtls_pk_free(&ctx);
PSA_DONE_IF_NO_MD();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_FS_IO */
-void pk_parse_public_keyfile_rsa( char * key_file, int result )
+void pk_parse_public_keyfile_rsa(char *key_file, int result)
{
mbedtls_pk_context ctx;
int res;
PSA_INIT_IF_NO_MD();
- mbedtls_pk_init( &ctx );
+ mbedtls_pk_init(&ctx);
- res = mbedtls_pk_parse_public_keyfile( &ctx, key_file );
+ res = mbedtls_pk_parse_public_keyfile(&ctx, key_file);
- TEST_ASSERT( res == result );
+ TEST_ASSERT(res == result);
- if( res == 0 )
- {
+ if (res == 0) {
mbedtls_rsa_context *rsa;
- TEST_ASSERT( mbedtls_pk_can_do( &ctx, MBEDTLS_PK_RSA ) );
- rsa = mbedtls_pk_rsa( ctx );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( rsa ) == 0 );
+ TEST_ASSERT(mbedtls_pk_can_do(&ctx, MBEDTLS_PK_RSA));
+ rsa = mbedtls_pk_rsa(ctx);
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(rsa) == 0);
}
exit:
- mbedtls_pk_free( &ctx );
+ mbedtls_pk_free(&ctx);
PSA_DONE_IF_NO_MD();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_ECP_C */
-void pk_parse_public_keyfile_ec( char * key_file, int result )
+void pk_parse_public_keyfile_ec(char *key_file, int result)
{
mbedtls_pk_context ctx;
int res;
- mbedtls_pk_init( &ctx );
+ mbedtls_pk_init(&ctx);
- res = mbedtls_pk_parse_public_keyfile( &ctx, key_file );
+ res = mbedtls_pk_parse_public_keyfile(&ctx, key_file);
- TEST_ASSERT( res == result );
+ TEST_ASSERT(res == result);
- if( res == 0 )
- {
+ if (res == 0) {
mbedtls_ecp_keypair *eckey;
- TEST_ASSERT( mbedtls_pk_can_do( &ctx, MBEDTLS_PK_ECKEY ) );
- eckey = mbedtls_pk_ec( ctx );
- TEST_ASSERT( mbedtls_ecp_check_pubkey( &eckey->grp, &eckey->Q ) == 0 );
+ TEST_ASSERT(mbedtls_pk_can_do(&ctx, MBEDTLS_PK_ECKEY));
+ eckey = mbedtls_pk_ec(ctx);
+ TEST_ASSERT(mbedtls_ecp_check_pubkey(&eckey->grp, &eckey->Q) == 0);
}
exit:
- mbedtls_pk_free( &ctx );
+ mbedtls_pk_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_ECP_C */
-void pk_parse_keyfile_ec( char * key_file, char * password, int result )
+void pk_parse_keyfile_ec(char *key_file, char *password, int result)
{
mbedtls_pk_context ctx;
int res;
- mbedtls_pk_init( &ctx );
+ mbedtls_pk_init(&ctx);
- res = mbedtls_pk_parse_keyfile( &ctx, key_file, password,
- mbedtls_test_rnd_std_rand, NULL );
+ res = mbedtls_pk_parse_keyfile(&ctx, key_file, password,
+ mbedtls_test_rnd_std_rand, NULL);
- TEST_ASSERT( res == result );
+ TEST_ASSERT(res == result);
- if( res == 0 )
- {
+ if (res == 0) {
mbedtls_ecp_keypair *eckey;
- TEST_ASSERT( mbedtls_pk_can_do( &ctx, MBEDTLS_PK_ECKEY ) );
- eckey = mbedtls_pk_ec( ctx );
- TEST_ASSERT( mbedtls_ecp_check_privkey( &eckey->grp, &eckey->d ) == 0 );
+ TEST_ASSERT(mbedtls_pk_can_do(&ctx, MBEDTLS_PK_ECKEY));
+ eckey = mbedtls_pk_ec(ctx);
+ TEST_ASSERT(mbedtls_ecp_check_privkey(&eckey->grp, &eckey->d) == 0);
}
exit:
- mbedtls_pk_free( &ctx );
+ mbedtls_pk_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void pk_parse_key( data_t * buf, int result )
+void pk_parse_key(data_t *buf, int result)
{
mbedtls_pk_context pk;
- mbedtls_pk_init( &pk );
+ mbedtls_pk_init(&pk);
- TEST_ASSERT( mbedtls_pk_parse_key( &pk, buf->x, buf->len, NULL, 0,
- mbedtls_test_rnd_std_rand, NULL ) == result );
+ TEST_ASSERT(mbedtls_pk_parse_key(&pk, buf->x, buf->len, NULL, 0,
+ mbedtls_test_rnd_std_rand, NULL) == result);
exit:
- mbedtls_pk_free( &pk );
+ mbedtls_pk_free(&pk);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_pkwrite.function b/tests/suites/test_suite_pkwrite.function
index d1e029a..7e8a32d 100644
--- a/tests/suites/test_suite_pkwrite.function
+++ b/tests/suites/test_suite_pkwrite.function
@@ -10,7 +10,7 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
-void pk_write_pubkey_check( char * key_file )
+void pk_write_pubkey_check(char *key_file)
{
mbedtls_pk_context key;
unsigned char buf[5000];
@@ -19,38 +19,37 @@
FILE *f;
size_t ilen, pem_len, buf_index;
- memset( buf, 0, sizeof( buf ) );
- memset( check_buf, 0, sizeof( check_buf ) );
+ memset(buf, 0, sizeof(buf));
+ memset(check_buf, 0, sizeof(check_buf));
- mbedtls_pk_init( &key );
- TEST_ASSERT( mbedtls_pk_parse_public_keyfile( &key, key_file ) == 0 );
+ mbedtls_pk_init(&key);
+ TEST_ASSERT(mbedtls_pk_parse_public_keyfile(&key, key_file) == 0);
- ret = mbedtls_pk_write_pubkey_pem( &key, buf, sizeof( buf ));
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_pk_write_pubkey_pem(&key, buf, sizeof(buf));
+ TEST_ASSERT(ret == 0);
- pem_len = strlen( (char *) buf );
+ pem_len = strlen((char *) buf);
// check that the rest of the buffer remains clear
- for( buf_index = pem_len; buf_index < sizeof( buf ); ++buf_index )
- {
- TEST_ASSERT( buf[buf_index] == 0 );
+ for (buf_index = pem_len; buf_index < sizeof(buf); ++buf_index) {
+ TEST_ASSERT(buf[buf_index] == 0);
}
- f = fopen( key_file, "r" );
- TEST_ASSERT( f != NULL );
- ilen = fread( check_buf, 1, sizeof( check_buf ), f );
- fclose( f );
+ f = fopen(key_file, "r");
+ TEST_ASSERT(f != NULL);
+ ilen = fread(check_buf, 1, sizeof(check_buf), f);
+ fclose(f);
- TEST_ASSERT( ilen == pem_len );
- TEST_ASSERT( memcmp( (char *) buf, (char *) check_buf, ilen ) == 0 );
+ TEST_ASSERT(ilen == pem_len);
+ TEST_ASSERT(memcmp((char *) buf, (char *) check_buf, ilen) == 0);
exit:
- mbedtls_pk_free( &key );
+ mbedtls_pk_free(&key);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
-void pk_write_key_check( char * key_file )
+void pk_write_key_check(char *key_file)
{
mbedtls_pk_context key;
unsigned char buf[5000];
@@ -59,33 +58,32 @@
FILE *f;
size_t ilen, pem_len, buf_index;
- memset( buf, 0, sizeof( buf ) );
- memset( check_buf, 0, sizeof( check_buf ) );
+ memset(buf, 0, sizeof(buf));
+ memset(check_buf, 0, sizeof(check_buf));
- mbedtls_pk_init( &key );
- TEST_ASSERT( mbedtls_pk_parse_keyfile( &key, key_file, NULL,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
+ mbedtls_pk_init(&key);
+ TEST_ASSERT(mbedtls_pk_parse_keyfile(&key, key_file, NULL,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
- ret = mbedtls_pk_write_key_pem( &key, buf, sizeof( buf ));
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_pk_write_key_pem(&key, buf, sizeof(buf));
+ TEST_ASSERT(ret == 0);
- pem_len = strlen( (char *) buf );
+ pem_len = strlen((char *) buf);
// check that the rest of the buffer remains clear
- for( buf_index = pem_len; buf_index < sizeof( buf ); ++buf_index )
- {
- TEST_ASSERT( buf[buf_index] == 0 );
+ for (buf_index = pem_len; buf_index < sizeof(buf); ++buf_index) {
+ TEST_ASSERT(buf[buf_index] == 0);
}
- f = fopen( key_file, "r" );
- TEST_ASSERT( f != NULL );
- ilen = fread( check_buf, 1, sizeof( check_buf ), f );
- fclose( f );
+ f = fopen(key_file, "r");
+ TEST_ASSERT(f != NULL);
+ ilen = fread(check_buf, 1, sizeof(check_buf), f);
+ fclose(f);
- TEST_ASSERT( ilen == strlen( (char *) buf ) );
- TEST_ASSERT( memcmp( (char *) buf, (char *) check_buf, ilen ) == 0 );
+ TEST_ASSERT(ilen == strlen((char *) buf));
+ TEST_ASSERT(memcmp((char *) buf, (char *) check_buf, ilen) == 0);
exit:
- mbedtls_pk_free( &key );
+ mbedtls_pk_free(&key);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_poly1305.function b/tests/suites/test_suite_poly1305.function
index 59e9277..fffa89f 100644
--- a/tests/suites/test_suite_poly1305.function
+++ b/tests/suites/test_suite_poly1305.function
@@ -9,35 +9,35 @@
*/
/* BEGIN_CASE */
-void mbedtls_poly1305( data_t *key, data_t *expected_mac, data_t *src_str )
+void mbedtls_poly1305(data_t *key, data_t *expected_mac, data_t *src_str)
{
unsigned char mac[16]; /* size set by the standard */
mbedtls_poly1305_context ctx;
- memset( mac, 0x00, sizeof( mac ) );
+ memset(mac, 0x00, sizeof(mac));
/*
* Test the integrated API
*/
- TEST_ASSERT( mbedtls_poly1305_mac( key->x, src_str->x,
- src_str->len, mac ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_mac(key->x, src_str->x,
+ src_str->len, mac) == 0);
- ASSERT_COMPARE( mac, expected_mac->len,
- expected_mac->x, expected_mac->len );
+ ASSERT_COMPARE(mac, expected_mac->len,
+ expected_mac->x, expected_mac->len);
/*
* Test the streaming API
*/
- mbedtls_poly1305_init( &ctx );
+ mbedtls_poly1305_init(&ctx);
- TEST_ASSERT( mbedtls_poly1305_starts( &ctx, key->x ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_starts(&ctx, key->x) == 0);
- TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str->x, src_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_update(&ctx, src_str->x, src_str->len) == 0);
- TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_finish(&ctx, mac) == 0);
- ASSERT_COMPARE( mac, expected_mac->len,
- expected_mac->x, expected_mac->len );
+ ASSERT_COMPARE(mac, expected_mac->len,
+ expected_mac->x, expected_mac->len);
/*
* Test the streaming API again, piecewise
@@ -45,43 +45,41 @@
/* Don't free/init the context, in order to test that starts() does the
* right thing. */
- if( src_str->len >= 1 )
- {
- TEST_ASSERT( mbedtls_poly1305_starts( &ctx, key->x ) == 0 );
+ if (src_str->len >= 1) {
+ TEST_ASSERT(mbedtls_poly1305_starts(&ctx, key->x) == 0);
- TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str->x, 1 ) == 0 );
- TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str->x + 1, src_str->len - 1 ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_update(&ctx, src_str->x, 1) == 0);
+ TEST_ASSERT(mbedtls_poly1305_update(&ctx, src_str->x + 1, src_str->len - 1) == 0);
- TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_finish(&ctx, mac) == 0);
- ASSERT_COMPARE( mac, expected_mac->len,
- expected_mac->x, expected_mac->len );
+ ASSERT_COMPARE(mac, expected_mac->len,
+ expected_mac->x, expected_mac->len);
}
/*
* Again with more pieces
*/
- if( src_str->len >= 2 )
- {
- TEST_ASSERT( mbedtls_poly1305_starts( &ctx, key->x ) == 0 );
+ if (src_str->len >= 2) {
+ TEST_ASSERT(mbedtls_poly1305_starts(&ctx, key->x) == 0);
- TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str->x, 1 ) == 0 );
- TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str->x + 1, 1 ) == 0 );
- TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str->x + 2, src_str->len - 2 ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_update(&ctx, src_str->x, 1) == 0);
+ TEST_ASSERT(mbedtls_poly1305_update(&ctx, src_str->x + 1, 1) == 0);
+ TEST_ASSERT(mbedtls_poly1305_update(&ctx, src_str->x + 2, src_str->len - 2) == 0);
- TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_finish(&ctx, mac) == 0);
- ASSERT_COMPARE( mac, expected_mac->len,
- expected_mac->x, expected_mac->len );
+ ASSERT_COMPARE(mac, expected_mac->len,
+ expected_mac->x, expected_mac->len);
}
- mbedtls_poly1305_free( &ctx );
+ mbedtls_poly1305_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void poly1305_selftest()
{
- TEST_ASSERT( mbedtls_poly1305_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_poly1305_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index a4c19b8..ea5eff5 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -29,24 +29,25 @@
/* Assert that an operation is (not) active.
* This serves as a proxy for checking if the operation is aborted. */
-#define ASSERT_OPERATION_IS_ACTIVE( operation ) TEST_ASSERT( operation.id != 0 )
-#define ASSERT_OPERATION_IS_INACTIVE( operation ) TEST_ASSERT( operation.id == 0 )
+#define ASSERT_OPERATION_IS_ACTIVE(operation) TEST_ASSERT(operation.id != 0)
+#define ASSERT_OPERATION_IS_INACTIVE(operation) TEST_ASSERT(operation.id == 0)
#if defined(PSA_WANT_ALG_JPAKE)
-int ecjpake_operation_setup( psa_pake_operation_t *operation,
- psa_pake_cipher_suite_t *cipher_suite,
- psa_pake_role_t role,
- mbedtls_svc_key_id_t key,
- size_t key_available )
+int ecjpake_operation_setup(psa_pake_operation_t *operation,
+ psa_pake_cipher_suite_t *cipher_suite,
+ psa_pake_role_t role,
+ mbedtls_svc_key_id_t key,
+ size_t key_available)
{
- PSA_ASSERT( psa_pake_abort( operation ) );
+ PSA_ASSERT(psa_pake_abort(operation));
- PSA_ASSERT( psa_pake_setup( operation, cipher_suite ) );
+ PSA_ASSERT(psa_pake_setup(operation, cipher_suite));
- PSA_ASSERT( psa_pake_set_role( operation, role) );
+ PSA_ASSERT(psa_pake_set_role(operation, role));
- if( key_available )
- PSA_ASSERT( psa_pake_set_password_key( operation, key ) );
+ if (key_available) {
+ PSA_ASSERT(psa_pake_set_password_key(operation, key));
+ }
return 0;
exit:
return 1;
@@ -67,50 +68,54 @@
* \return 1 if the buffer is all-bits-zero.
* \return 0 if there is at least one nonzero byte.
*/
-static int mem_is_char( void *buffer, unsigned char c, size_t size )
+static int mem_is_char(void *buffer, unsigned char c, size_t size)
{
size_t i;
- for( i = 0; i < size; i++ )
- {
- if( ( (unsigned char *) buffer )[i] != c )
- return( 0 );
+ for (i = 0; i < size; i++) {
+ if (((unsigned char *) buffer)[i] != c) {
+ return 0;
+ }
}
- return( 1 );
+ return 1;
}
#if defined(MBEDTLS_ASN1_WRITE_C)
/* Write the ASN.1 INTEGER with the value 2^(bits-1)+x backwards from *p. */
-static int asn1_write_10x( unsigned char **p,
- unsigned char *start,
- size_t bits,
- unsigned char x )
+static int asn1_write_10x(unsigned char **p,
+ unsigned char *start,
+ size_t bits,
+ unsigned char x)
{
int ret;
int len = bits / 8 + 1;
- if( bits == 0 )
- return( MBEDTLS_ERR_ASN1_INVALID_DATA );
- if( bits <= 8 && x >= 1 << ( bits - 1 ) )
- return( MBEDTLS_ERR_ASN1_INVALID_DATA );
- if( *p < start || *p - start < (ptrdiff_t) len )
- return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
+ if (bits == 0) {
+ return MBEDTLS_ERR_ASN1_INVALID_DATA;
+ }
+ if (bits <= 8 && x >= 1 << (bits - 1)) {
+ return MBEDTLS_ERR_ASN1_INVALID_DATA;
+ }
+ if (*p < start || *p - start < (ptrdiff_t) len) {
+ return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
+ }
*p -= len;
- ( *p )[len-1] = x;
- if( bits % 8 == 0 )
- ( *p )[1] |= 1;
- else
- ( *p )[0] |= 1 << ( bits % 8 );
- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start,
- MBEDTLS_ASN1_INTEGER ) );
- return( len );
+ (*p)[len-1] = x;
+ if (bits % 8 == 0) {
+ (*p)[1] |= 1;
+ } else {
+ (*p)[0] |= 1 << (bits % 8);
+ }
+ MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
+ MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start,
+ MBEDTLS_ASN1_INTEGER));
+ return len;
}
-static int construct_fake_rsa_key( unsigned char *buffer,
- size_t buffer_size,
- unsigned char **p,
- size_t bits,
- int keypair )
+static int construct_fake_rsa_key(unsigned char *buffer,
+ size_t buffer_size,
+ unsigned char **p,
+ size_t bits,
+ int keypair)
{
- size_t half_bits = ( bits + 1 ) / 2;
+ size_t half_bits = (bits + 1) / 2;
int ret;
int len = 0;
/* Construct something that looks like a DER encoding of
@@ -131,134 +136,132 @@
* version, modulus and publicExponent.
*/
*p = buffer + buffer_size;
- if( keypair )
- {
- MBEDTLS_ASN1_CHK_ADD( len, /* pq */
- asn1_write_10x( p, buffer, half_bits, 1 ) );
- MBEDTLS_ASN1_CHK_ADD( len, /* dq */
- asn1_write_10x( p, buffer, half_bits, 1 ) );
- MBEDTLS_ASN1_CHK_ADD( len, /* dp */
- asn1_write_10x( p, buffer, half_bits, 1 ) );
- MBEDTLS_ASN1_CHK_ADD( len, /* q */
- asn1_write_10x( p, buffer, half_bits, 1 ) );
- MBEDTLS_ASN1_CHK_ADD( len, /* p != q to pass mbedtls sanity checks */
- asn1_write_10x( p, buffer, half_bits, 3 ) );
- MBEDTLS_ASN1_CHK_ADD( len, /* d */
- asn1_write_10x( p, buffer, bits, 1 ) );
+ if (keypair) {
+ MBEDTLS_ASN1_CHK_ADD(len, /* pq */
+ asn1_write_10x(p, buffer, half_bits, 1));
+ MBEDTLS_ASN1_CHK_ADD(len, /* dq */
+ asn1_write_10x(p, buffer, half_bits, 1));
+ MBEDTLS_ASN1_CHK_ADD(len, /* dp */
+ asn1_write_10x(p, buffer, half_bits, 1));
+ MBEDTLS_ASN1_CHK_ADD(len, /* q */
+ asn1_write_10x(p, buffer, half_bits, 1));
+ MBEDTLS_ASN1_CHK_ADD(len, /* p != q to pass mbedtls sanity checks */
+ asn1_write_10x(p, buffer, half_bits, 3));
+ MBEDTLS_ASN1_CHK_ADD(len, /* d */
+ asn1_write_10x(p, buffer, bits, 1));
}
- MBEDTLS_ASN1_CHK_ADD( len, /* e = 65537 */
- asn1_write_10x( p, buffer, 17, 1 ) );
- MBEDTLS_ASN1_CHK_ADD( len, /* n */
- asn1_write_10x( p, buffer, bits, 1 ) );
- if( keypair )
- MBEDTLS_ASN1_CHK_ADD( len, /* version = 0 */
- mbedtls_asn1_write_int( p, buffer, 0 ) );
- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, buffer, len ) );
+ MBEDTLS_ASN1_CHK_ADD(len, /* e = 65537 */
+ asn1_write_10x(p, buffer, 17, 1));
+ MBEDTLS_ASN1_CHK_ADD(len, /* n */
+ asn1_write_10x(p, buffer, bits, 1));
+ if (keypair) {
+ MBEDTLS_ASN1_CHK_ADD(len, /* version = 0 */
+ mbedtls_asn1_write_int(p, buffer, 0));
+ }
+ MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, buffer, len));
{
const unsigned char tag =
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE;
- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, buffer, tag ) );
+ MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, buffer, tag));
}
- return( len );
+ return len;
}
#endif /* MBEDTLS_ASN1_WRITE_C */
-int exercise_mac_setup( psa_key_type_t key_type,
- const unsigned char *key_bytes,
- size_t key_length,
- psa_algorithm_t alg,
- psa_mac_operation_t *operation,
- psa_status_t *status )
+int exercise_mac_setup(psa_key_type_t key_type,
+ const unsigned char *key_bytes,
+ size_t key_length,
+ psa_algorithm_t alg,
+ psa_mac_operation_t *operation,
+ psa_status_t *status)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
- PSA_ASSERT( psa_import_key( &attributes, key_bytes, key_length, &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+ PSA_ASSERT(psa_import_key(&attributes, key_bytes, key_length, &key));
- *status = psa_mac_sign_setup( operation, key, alg );
+ *status = psa_mac_sign_setup(operation, key, alg);
/* Whether setup succeeded or failed, abort must succeed. */
- PSA_ASSERT( psa_mac_abort( operation ) );
+ PSA_ASSERT(psa_mac_abort(operation));
/* If setup failed, reproduce the failure, so that the caller can
* test the resulting state of the operation object. */
- if( *status != PSA_SUCCESS )
- {
- TEST_EQUAL( psa_mac_sign_setup( operation, key, alg ), *status );
+ if (*status != PSA_SUCCESS) {
+ TEST_EQUAL(psa_mac_sign_setup(operation, key, alg), *status);
}
- psa_destroy_key( key );
- return( 1 );
+ psa_destroy_key(key);
+ return 1;
exit:
- psa_destroy_key( key );
- return( 0 );
+ psa_destroy_key(key);
+ return 0;
}
-int exercise_cipher_setup( psa_key_type_t key_type,
- const unsigned char *key_bytes,
- size_t key_length,
- psa_algorithm_t alg,
- psa_cipher_operation_t *operation,
- psa_status_t *status )
+int exercise_cipher_setup(psa_key_type_t key_type,
+ const unsigned char *key_bytes,
+ size_t key_length,
+ psa_algorithm_t alg,
+ psa_cipher_operation_t *operation,
+ psa_status_t *status)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
- PSA_ASSERT( psa_import_key( &attributes, key_bytes, key_length, &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+ PSA_ASSERT(psa_import_key(&attributes, key_bytes, key_length, &key));
- *status = psa_cipher_encrypt_setup( operation, key, alg );
+ *status = psa_cipher_encrypt_setup(operation, key, alg);
/* Whether setup succeeded or failed, abort must succeed. */
- PSA_ASSERT( psa_cipher_abort( operation ) );
+ PSA_ASSERT(psa_cipher_abort(operation));
/* If setup failed, reproduce the failure, so that the caller can
* test the resulting state of the operation object. */
- if( *status != PSA_SUCCESS )
- {
- TEST_EQUAL( psa_cipher_encrypt_setup( operation, key, alg ),
- *status );
+ if (*status != PSA_SUCCESS) {
+ TEST_EQUAL(psa_cipher_encrypt_setup(operation, key, alg),
+ *status);
}
- psa_destroy_key( key );
- return( 1 );
+ psa_destroy_key(key);
+ return 1;
exit:
- psa_destroy_key( key );
- return( 0 );
+ psa_destroy_key(key);
+ return 0;
}
-static int test_operations_on_invalid_key( mbedtls_svc_key_id_t key )
+static int test_operations_on_invalid_key(mbedtls_svc_key_id_t key)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 1, 0x6964 );
+ mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make(1, 0x6964);
uint8_t buffer[1];
size_t length;
int ok = 0;
- psa_set_key_id( &attributes, key_id );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, PSA_ALG_CTR );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_AES );
- TEST_EQUAL( psa_get_key_attributes( key, &attributes ),
- PSA_ERROR_INVALID_HANDLE );
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, PSA_ALG_CTR);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
+ TEST_EQUAL(psa_get_key_attributes(key, &attributes),
+ PSA_ERROR_INVALID_HANDLE);
TEST_EQUAL(
- MBEDTLS_SVC_KEY_ID_GET_KEY_ID( psa_get_key_id( &attributes ) ), 0 );
+ MBEDTLS_SVC_KEY_ID_GET_KEY_ID(psa_get_key_id(&attributes)), 0);
TEST_EQUAL(
- MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( psa_get_key_id( &attributes ) ), 0 );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_type( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_bits( &attributes ), 0 );
+ MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(psa_get_key_id(&attributes)), 0);
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), 0);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), 0);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), 0);
+ TEST_EQUAL(psa_get_key_type(&attributes), 0);
+ TEST_EQUAL(psa_get_key_bits(&attributes), 0);
- TEST_EQUAL( psa_export_key( key, buffer, sizeof( buffer ), &length ),
- PSA_ERROR_INVALID_HANDLE );
- TEST_EQUAL( psa_export_public_key( key,
- buffer, sizeof( buffer ), &length ),
- PSA_ERROR_INVALID_HANDLE );
+ TEST_EQUAL(psa_export_key(key, buffer, sizeof(buffer), &length),
+ PSA_ERROR_INVALID_HANDLE);
+ TEST_EQUAL(psa_export_public_key(key,
+ buffer, sizeof(buffer), &length),
+ PSA_ERROR_INVALID_HANDLE);
ok = 1;
@@ -267,34 +270,34 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- return( ok );
+ return ok;
}
/* Assert that a key isn't reported as having a slot number. */
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
-#define ASSERT_NO_SLOT_NUMBER( attributes ) \
+#define ASSERT_NO_SLOT_NUMBER(attributes) \
do \
{ \
psa_key_slot_number_t ASSERT_NO_SLOT_NUMBER_slot_number; \
- TEST_EQUAL( psa_get_key_slot_number( \
- attributes, \
- &ASSERT_NO_SLOT_NUMBER_slot_number ), \
- PSA_ERROR_INVALID_ARGUMENT ); \
+ TEST_EQUAL(psa_get_key_slot_number( \
+ attributes, \
+ &ASSERT_NO_SLOT_NUMBER_slot_number), \
+ PSA_ERROR_INVALID_ARGUMENT); \
} \
- while( 0 )
+ while (0)
#else /* MBEDTLS_PSA_CRYPTO_SE_C */
-#define ASSERT_NO_SLOT_NUMBER( attributes ) \
- ( (void) 0 )
+#define ASSERT_NO_SLOT_NUMBER(attributes) \
+ ((void) 0)
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
/* An overapproximation of the amount of storage needed for a key of the
* given type and with the given content. The API doesn't make it easy
* to find a good value for the size. The current implementation doesn't
* care about the value anyway. */
-#define KEY_BITS_FROM_DATA( type, data ) \
- ( data )->len
+#define KEY_BITS_FROM_DATA(type, data) \
+ (data)->len
typedef enum {
IMPORT_KEY = 0,
@@ -302,15 +305,13 @@
DERIVE_KEY = 2
} generate_method;
-typedef enum
-{
+typedef enum {
DO_NOT_SET_LENGTHS = 0,
SET_LENGTHS_BEFORE_NONCE = 1,
SET_LENGTHS_AFTER_NONCE = 2
} set_lengths_method_t;
-typedef enum
-{
+typedef enum {
USE_NULL_TAG = 0,
USE_GIVEN_TAG = 1,
} tag_usage_method_t;
@@ -339,17 +340,17 @@
* with normal length chunks.
* \return int Zero on failure, non-zero on success.
*/
-static int aead_multipart_internal_func( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- int ad_part_len_arg,
- data_t *input_data,
- int data_part_len_arg,
- set_lengths_method_t set_lengths_method,
- data_t *expected_output,
- int is_encrypt,
- int do_zero_parts )
+static int aead_multipart_internal_func(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ int ad_part_len_arg,
+ data_t *input_data,
+ int data_part_len_arg,
+ set_lengths_method_t set_lengths_method,
+ data_t *expected_output,
+ int is_encrypt,
+ int do_zero_parts)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -378,238 +379,209 @@
int test_ok = 0;
size_t part_count = 0;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- if( is_encrypt )
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- else
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
-
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
-
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
-
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
-
- tag_length = PSA_AEAD_TAG_LENGTH( key_type, key_bits, alg );
-
- if( is_encrypt )
- {
- /* Tag gets written at end of buffer. */
- output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg,
- ( input_data->len +
- tag_length ) );
- data_true_size = input_data->len;
+ if (is_encrypt) {
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ } else {
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
}
- else
- {
- output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg,
- ( input_data->len -
- tag_length ) );
+
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
+
+ tag_length = PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg);
+
+ if (is_encrypt) {
+ /* Tag gets written at end of buffer. */
+ output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg,
+ (input_data->len +
+ tag_length));
+ data_true_size = input_data->len;
+ } else {
+ output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg,
+ (input_data->len -
+ tag_length));
/* Do not want to attempt to decrypt tag. */
data_true_size = input_data->len - tag_length;
}
- ASSERT_ALLOC( output_data, output_size );
+ ASSERT_ALLOC(output_data, output_size);
- if( is_encrypt )
- {
- final_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg );
- TEST_LE_U( final_output_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE );
- }
- else
- {
- final_output_size = PSA_AEAD_VERIFY_OUTPUT_SIZE( key_type, alg );
- TEST_LE_U( final_output_size, PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE );
+ if (is_encrypt) {
+ final_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
+ TEST_LE_U(final_output_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE);
+ } else {
+ final_output_size = PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg);
+ TEST_LE_U(final_output_size, PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE);
}
- ASSERT_ALLOC( final_data, final_output_size );
+ ASSERT_ALLOC(final_data, final_output_size);
- if( is_encrypt )
- status = psa_aead_encrypt_setup( &operation, key, alg );
- else
- status = psa_aead_decrypt_setup( &operation, key, alg );
+ if (is_encrypt) {
+ status = psa_aead_encrypt_setup(&operation, key, alg);
+ } else {
+ status = psa_aead_decrypt_setup(&operation, key, alg);
+ }
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce->len);
}
- PSA_ASSERT( status );
+ PSA_ASSERT(status);
- if( set_lengths_method == DO_NOT_SET_LENGTHS )
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
- else if( set_lengths_method == SET_LENGTHS_BEFORE_NONCE )
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- data_true_size ) );
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
- }
- else if( set_lengths_method == SET_LENGTHS_AFTER_NONCE )
- {
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ if (set_lengths_method == DO_NOT_SET_LENGTHS) {
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
+ } else if (set_lengths_method == SET_LENGTHS_BEFORE_NONCE) {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ data_true_size));
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
+ } else if (set_lengths_method == SET_LENGTHS_AFTER_NONCE) {
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- data_true_size ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ data_true_size));
}
- if( ad_part_len_arg != -1 )
- {
+ if (ad_part_len_arg != -1) {
/* Pass additional data in parts */
ad_part_len = (size_t) ad_part_len_arg;
- for( part_offset = 0, part_count = 0;
+ for (part_offset = 0, part_count = 0;
part_offset < additional_data->len;
- part_offset += part_length, part_count++ )
- {
- if( do_zero_parts && ( part_count & 0x01 ) )
- {
+ part_offset += part_length, part_count++) {
+ if (do_zero_parts && (part_count & 0x01)) {
part_length = 0;
- }
- else if( additional_data->len - part_offset < ad_part_len )
- {
+ } else if (additional_data->len - part_offset < ad_part_len) {
part_length = additional_data->len - part_offset;
- }
- else
- {
+ } else {
part_length = ad_part_len;
}
- PSA_ASSERT( psa_aead_update_ad( &operation,
- additional_data->x + part_offset,
- part_length ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation,
+ additional_data->x + part_offset,
+ part_length));
}
- }
- else
- {
+ } else {
/* Pass additional data in one go. */
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
}
- if( data_part_len_arg != -1 )
- {
+ if (data_part_len_arg != -1) {
/* Pass data in parts */
- data_part_len = ( size_t ) data_part_len_arg;
- part_data_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg,
- ( size_t ) data_part_len );
+ data_part_len = (size_t) data_part_len_arg;
+ part_data_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg,
+ (size_t) data_part_len);
- ASSERT_ALLOC( part_data, part_data_size );
+ ASSERT_ALLOC(part_data, part_data_size);
- for( part_offset = 0, part_count = 0;
+ for (part_offset = 0, part_count = 0;
part_offset < data_true_size;
- part_offset += part_length, part_count++ )
- {
- if( do_zero_parts && ( part_count & 0x01 ) )
- {
+ part_offset += part_length, part_count++) {
+ if (do_zero_parts && (part_count & 0x01)) {
part_length = 0;
- }
- else if( ( data_true_size - part_offset ) < data_part_len )
- {
- part_length = ( data_true_size - part_offset );
- }
- else
- {
+ } else if ((data_true_size - part_offset) < data_part_len) {
+ part_length = (data_true_size - part_offset);
+ } else {
part_length = data_part_len;
}
- PSA_ASSERT( psa_aead_update( &operation,
- ( input_data->x + part_offset ),
- part_length, part_data,
- part_data_size,
- &output_part_length ) );
+ PSA_ASSERT(psa_aead_update(&operation,
+ (input_data->x + part_offset),
+ part_length, part_data,
+ part_data_size,
+ &output_part_length));
- if( output_data && output_part_length )
- {
- memcpy( ( output_data + output_length ), part_data,
- output_part_length );
+ if (output_data && output_part_length) {
+ memcpy((output_data + output_length), part_data,
+ output_part_length);
}
output_length += output_part_length;
}
- }
- else
- {
+ } else {
/* Pass all data in one go. */
- PSA_ASSERT( psa_aead_update( &operation, input_data->x,
- data_true_size, output_data,
- output_size, &output_length ) );
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x,
+ data_true_size, output_data,
+ output_size, &output_length));
}
- if( is_encrypt )
- PSA_ASSERT( psa_aead_finish( &operation, final_data,
- final_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ) );
- else
- {
- PSA_ASSERT( psa_aead_verify( &operation, final_data,
- final_output_size,
- &output_part_length,
- ( input_data->x + data_true_size ),
- tag_length ) );
+ if (is_encrypt) {
+ PSA_ASSERT(psa_aead_finish(&operation, final_data,
+ final_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size));
+ } else {
+ PSA_ASSERT(psa_aead_verify(&operation, final_data,
+ final_output_size,
+ &output_part_length,
+ (input_data->x + data_true_size),
+ tag_length));
}
- if( output_data && output_part_length )
- memcpy( ( output_data + output_length ), final_data,
- output_part_length );
+ if (output_data && output_part_length) {
+ memcpy((output_data + output_length), final_data,
+ output_part_length);
+ }
output_length += output_part_length;
/* For all currently defined algorithms, PSA_AEAD_xxx_OUTPUT_SIZE
* should be exact.*/
- if( is_encrypt )
- {
- TEST_EQUAL( tag_length, tag_size );
+ if (is_encrypt) {
+ TEST_EQUAL(tag_length, tag_size);
- if( output_data && tag_length )
- memcpy( ( output_data + output_length ), tag_buffer,
- tag_length );
+ if (output_data && tag_length) {
+ memcpy((output_data + output_length), tag_buffer,
+ tag_length);
+ }
output_length += tag_length;
- TEST_EQUAL( output_length,
- PSA_AEAD_ENCRYPT_OUTPUT_SIZE( key_type, alg,
- input_data->len ) );
- TEST_LE_U( output_length,
- PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
- }
- else
- {
- TEST_EQUAL( output_length,
- PSA_AEAD_DECRYPT_OUTPUT_SIZE( key_type, alg,
- input_data->len ) );
- TEST_LE_U( output_length,
- PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
+ TEST_EQUAL(output_length,
+ PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg,
+ input_data->len));
+ TEST_LE_U(output_length,
+ PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
+ } else {
+ TEST_EQUAL(output_length,
+ PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg,
+ input_data->len));
+ TEST_LE_U(output_length,
+ PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(input_data->len));
}
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output_data, output_length );
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output_data, output_length);
test_ok = 1;
exit:
- psa_destroy_key( key );
- psa_aead_abort( &operation );
- mbedtls_free( output_data );
- mbedtls_free( part_data );
- mbedtls_free( final_data );
- PSA_DONE( );
+ psa_destroy_key(key);
+ psa_aead_abort(&operation);
+ mbedtls_free(output_data);
+ mbedtls_free(part_data);
+ mbedtls_free(final_data);
+ PSA_DONE();
- return( test_ok );
+ return test_ok;
}
/*!
@@ -627,13 +599,13 @@
* with normal length chunks.
* \return int Zero on failure, non-zero on success.
*/
-static int mac_multipart_internal_func( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *input_data,
- int data_part_len_arg,
- data_t *expected_output,
- int is_verify,
- int do_zero_parts )
+static int mac_multipart_internal_func(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *input_data,
+ int data_part_len_arg,
+ data_t *expected_output,
+ int is_verify,
+ int do_zero_parts)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -650,90 +622,80 @@
int test_ok = 0;
size_t part_count = 0;
- PSA_INIT( );
+ PSA_INIT();
- if( is_verify )
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- else
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
+ if (is_verify) {
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ } else {
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ }
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- if( is_verify )
- status = psa_mac_verify_setup( &operation, key, alg );
- else
- status = psa_mac_sign_setup( &operation, key, alg );
+ if (is_verify) {
+ status = psa_mac_verify_setup(&operation, key, alg);
+ } else {
+ status = psa_mac_sign_setup(&operation, key, alg);
+ }
- PSA_ASSERT( status );
+ PSA_ASSERT(status);
- if( data_part_len_arg != -1 )
- {
+ if (data_part_len_arg != -1) {
/* Pass data in parts */
- data_part_len = ( size_t ) data_part_len_arg;
+ data_part_len = (size_t) data_part_len_arg;
- for( part_offset = 0, part_count = 0;
+ for (part_offset = 0, part_count = 0;
part_offset < input_data->len;
- part_offset += part_length, part_count++ )
- {
- if( do_zero_parts && ( part_count & 0x01 ) )
- {
+ part_offset += part_length, part_count++) {
+ if (do_zero_parts && (part_count & 0x01)) {
part_length = 0;
- }
- else if( ( input_data->len - part_offset ) < data_part_len )
- {
- part_length = ( input_data->len - part_offset );
- }
- else
- {
+ } else if ((input_data->len - part_offset) < data_part_len) {
+ part_length = (input_data->len - part_offset);
+ } else {
part_length = data_part_len;
}
- PSA_ASSERT( psa_mac_update( &operation,
- ( input_data->x + part_offset ),
- part_length ) );
+ PSA_ASSERT(psa_mac_update(&operation,
+ (input_data->x + part_offset),
+ part_length));
}
- }
- else
- {
+ } else {
/* Pass all data in one go. */
- PSA_ASSERT( psa_mac_update( &operation, input_data->x,
- input_data->len ) );
+ PSA_ASSERT(psa_mac_update(&operation, input_data->x,
+ input_data->len));
}
- if( is_verify )
- {
- PSA_ASSERT( psa_mac_verify_finish( &operation, expected_output->x,
- expected_output->len ) );
- }
- else
- {
- PSA_ASSERT( psa_mac_sign_finish( &operation, mac,
- PSA_MAC_MAX_SIZE, &mac_len ) );
+ if (is_verify) {
+ PSA_ASSERT(psa_mac_verify_finish(&operation, expected_output->x,
+ expected_output->len));
+ } else {
+ PSA_ASSERT(psa_mac_sign_finish(&operation, mac,
+ PSA_MAC_MAX_SIZE, &mac_len));
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- mac, mac_len );
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ mac, mac_len);
}
test_ok = 1;
exit:
- psa_destroy_key( key );
- psa_mac_abort( &operation );
- PSA_DONE( );
+ psa_destroy_key(key);
+ psa_mac_abort(&operation);
+ PSA_DONE();
- return( test_ok );
+ return test_ok;
}
#if defined(PSA_WANT_ALG_JPAKE)
-static void ecjpake_do_round( psa_algorithm_t alg, unsigned int primitive,
- psa_pake_operation_t *server,
- psa_pake_operation_t *client,
- int client_input_first,
- int round, int inject_error )
+static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
+ psa_pake_operation_t *server,
+ psa_pake_operation_t *client,
+ int client_input_first,
+ int round, int inject_error)
{
unsigned char *buffer0 = NULL, *buffer1 = NULL;
size_t buffer_length = (
@@ -766,52 +728,50 @@
psa_status_t expected_status = PSA_SUCCESS;
psa_status_t status;
- ASSERT_ALLOC( buffer0, buffer_length );
- ASSERT_ALLOC( buffer1, buffer_length );
+ ASSERT_ALLOC(buffer0, buffer_length);
+ ASSERT_ALLOC(buffer1, buffer_length);
- switch( round )
- {
+ switch (round) {
case 1:
/* Server first round Output */
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_g1_len ) );
- TEST_EQUAL( s_g1_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_g1_len));
+ TEST_EQUAL(s_g1_len, expected_size_key_share);
s_g1_off = buffer0_off;
buffer0_off += s_g1_len;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x1_pk_len ) );
- TEST_EQUAL( s_x1_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x1_pk_len));
+ TEST_EQUAL(s_x1_pk_len, expected_size_zk_public);
s_x1_pk_off = buffer0_off;
buffer0_off += s_x1_pk_len;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x1_pr_len ) );
- TEST_LE_U( s_x1_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x1_pr_len));
+ TEST_LE_U(s_x1_pr_len, max_expected_size_zk_proof);
s_x1_pr_off = buffer0_off;
buffer0_off += s_x1_pr_len;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_g2_len ) );
- TEST_EQUAL( s_g2_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_g2_len));
+ TEST_EQUAL(s_g2_len, expected_size_key_share);
s_g2_off = buffer0_off;
buffer0_off += s_g2_len;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2_pk_len ) );
- TEST_EQUAL( s_x2_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2_pk_len));
+ TEST_EQUAL(s_x2_pk_len, expected_size_zk_public);
s_x2_pk_off = buffer0_off;
buffer0_off += s_x2_pk_len;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2_pr_len ) );
- TEST_LE_U( s_x2_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2_pr_len));
+ TEST_LE_U(s_x2_pr_len, max_expected_size_zk_proof);
s_x2_pr_off = buffer0_off;
buffer0_off += s_x2_pr_len;
- if( inject_error == 1 )
- {
+ if (inject_error == 1) {
buffer0[s_x1_pr_off + 8] ^= 1;
buffer0[s_x2_pr_off + 7] ^= 1;
expected_status = PSA_ERROR_DATA_INVALID;
@@ -825,297 +785,246 @@
* as an error.
*/
- if( client_input_first == 1 )
- {
+ if (client_input_first == 1) {
/* Client first round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g1_off, s_g1_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g1_off, s_g1_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x1_pk_off,
- s_x1_pk_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x1_pk_off,
+ s_x1_pk_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x1_pr_off,
- s_x1_pr_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x1_pr_off,
+ s_x1_pr_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g2_off,
- s_g2_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g2_off,
+ s_g2_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2_pk_off,
- s_x2_pk_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2_pk_off,
+ s_x2_pk_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2_pr_off,
- s_x2_pr_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2_pr_off,
+ s_x2_pr_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
/* Error didn't trigger, make test fail */
- if( inject_error == 1 )
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if (inject_error == 1) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
+ }
}
/* Client first round Output */
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_g1_len ) );
- TEST_EQUAL( c_g1_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_g1_len));
+ TEST_EQUAL(c_g1_len, expected_size_key_share);
c_g1_off = buffer1_off;
buffer1_off += c_g1_len;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x1_pk_len ) );
- TEST_EQUAL( c_x1_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x1_pk_len));
+ TEST_EQUAL(c_x1_pk_len, expected_size_zk_public);
c_x1_pk_off = buffer1_off;
buffer1_off += c_x1_pk_len;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x1_pr_len ) );
- TEST_LE_U( c_x1_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x1_pr_len));
+ TEST_LE_U(c_x1_pr_len, max_expected_size_zk_proof);
c_x1_pr_off = buffer1_off;
buffer1_off += c_x1_pr_len;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_g2_len ) );
- TEST_EQUAL( c_g2_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_g2_len));
+ TEST_EQUAL(c_g2_len, expected_size_key_share);
c_g2_off = buffer1_off;
buffer1_off += c_g2_len;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2_pk_len ) );
- TEST_EQUAL( c_x2_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2_pk_len));
+ TEST_EQUAL(c_x2_pk_len, expected_size_zk_public);
c_x2_pk_off = buffer1_off;
buffer1_off += c_x2_pk_len;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2_pr_len ) );
- TEST_LE_U( c_x2_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2_pr_len));
+ TEST_LE_U(c_x2_pr_len, max_expected_size_zk_proof);
c_x2_pr_off = buffer1_off;
buffer1_off += c_x2_pr_len;
- if( client_input_first == 0 )
- {
+ if (client_input_first == 0) {
/* Client first round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g1_off, s_g1_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g1_off, s_g1_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x1_pk_off,
- s_x1_pk_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x1_pk_off,
+ s_x1_pk_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x1_pr_off,
- s_x1_pr_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x1_pr_off,
+ s_x1_pr_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g2_off,
- s_g2_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g2_off,
+ s_g2_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2_pk_off,
- s_x2_pk_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2_pk_off,
+ s_x2_pk_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2_pr_off,
- s_x2_pr_len );
- if( inject_error == 1 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2_pr_off,
+ s_x2_pr_len);
+ if (inject_error == 1 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
/* Error didn't trigger, make test fail */
- if( inject_error == 1 )
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if (inject_error == 1) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
+ }
}
- if( inject_error == 2 )
- {
+ if (inject_error == 2) {
buffer1[c_x1_pr_off + 12] ^= 1;
buffer1[c_x2_pr_off + 7] ^= 1;
expected_status = PSA_ERROR_DATA_INVALID;
}
/* Server first round Input */
- status = psa_pake_input( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + c_g1_off, c_g1_len );
- if( inject_error == 2 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + c_g1_off, c_g1_len);
+ if (inject_error == 2 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + c_x1_pk_off, c_x1_pk_len );
- if( inject_error == 2 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + c_x1_pk_off, c_x1_pk_len);
+ if (inject_error == 2 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + c_x1_pr_off, c_x1_pr_len );
- if( inject_error == 2 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + c_x1_pr_off, c_x1_pr_len);
+ if (inject_error == 2 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + c_g2_off, c_g2_len );
- if( inject_error == 2 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + c_g2_off, c_g2_len);
+ if (inject_error == 2 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + c_x2_pk_off, c_x2_pk_len );
- if( inject_error == 2 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + c_x2_pk_off, c_x2_pk_len);
+ if (inject_error == 2 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + c_x2_pr_off, c_x2_pr_len );
- if( inject_error == 2 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + c_x2_pr_off, c_x2_pr_len);
+ if (inject_error == 2 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
/* Error didn't trigger, make test fail */
- if( inject_error == 2 )
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if (inject_error == 2) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
+ }
break;
@@ -1123,204 +1032,178 @@
/* Server second round Output */
buffer0_off = 0;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_a_len ) );
- TEST_EQUAL( s_a_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_a_len));
+ TEST_EQUAL(s_a_len, expected_size_key_share);
s_a_off = buffer0_off;
buffer0_off += s_a_len;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2s_pk_len ) );
- TEST_EQUAL( s_x2s_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2s_pk_len));
+ TEST_EQUAL(s_x2s_pk_len, expected_size_zk_public);
s_x2s_pk_off = buffer0_off;
buffer0_off += s_x2s_pk_len;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2s_pr_len ) );
- TEST_LE_U( s_x2s_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2s_pr_len));
+ TEST_LE_U(s_x2s_pr_len, max_expected_size_zk_proof);
s_x2s_pr_off = buffer0_off;
buffer0_off += s_x2s_pr_len;
- if( inject_error == 3 )
- {
+ if (inject_error == 3) {
buffer0[s_x2s_pk_off + 12] += 0x33;
expected_status = PSA_ERROR_DATA_INVALID;
}
- if( client_input_first == 1 )
- {
+ if (client_input_first == 1) {
/* Client second round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_a_off, s_a_len );
- if( inject_error == 3 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_a_off, s_a_len);
+ if (inject_error == 3 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2s_pk_off,
- s_x2s_pk_len );
- if( inject_error == 3 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2s_pk_off,
+ s_x2s_pk_len);
+ if (inject_error == 3 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2s_pr_off,
- s_x2s_pr_len );
- if( inject_error == 3 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2s_pr_off,
+ s_x2s_pr_len);
+ if (inject_error == 3 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
/* Error didn't trigger, make test fail */
- if( inject_error == 3 )
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if (inject_error == 3) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
+ }
}
/* Client second round Output */
buffer1_off = 0;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_a_len ) );
- TEST_EQUAL( c_a_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_a_len));
+ TEST_EQUAL(c_a_len, expected_size_key_share);
c_a_off = buffer1_off;
buffer1_off += c_a_len;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2s_pk_len ) );
- TEST_EQUAL( c_x2s_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2s_pk_len));
+ TEST_EQUAL(c_x2s_pk_len, expected_size_zk_public);
c_x2s_pk_off = buffer1_off;
buffer1_off += c_x2s_pk_len;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2s_pr_len ) );
- TEST_LE_U( c_x2s_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2s_pr_len));
+ TEST_LE_U(c_x2s_pr_len, max_expected_size_zk_proof);
c_x2s_pr_off = buffer1_off;
buffer1_off += c_x2s_pr_len;
- if( client_input_first == 0 )
- {
+ if (client_input_first == 0) {
/* Client second round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_a_off, s_a_len );
- if( inject_error == 3 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_a_off, s_a_len);
+ if (inject_error == 3 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2s_pk_off,
- s_x2s_pk_len );
- if( inject_error == 3 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2s_pk_off,
+ s_x2s_pk_len);
+ if (inject_error == 3 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2s_pr_off,
- s_x2s_pr_len );
- if( inject_error == 3 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2s_pr_off,
+ s_x2s_pr_len);
+ if (inject_error == 3 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
/* Error didn't trigger, make test fail */
- if( inject_error == 3 )
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if (inject_error == 3) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
+ }
}
- if( inject_error == 4 )
- {
+ if (inject_error == 4) {
buffer1[c_x2s_pk_off + 7] += 0x28;
expected_status = PSA_ERROR_DATA_INVALID;
}
/* Server second round Input */
- status = psa_pake_input( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + c_a_off, c_a_len );
- if( inject_error == 4 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + c_a_off, c_a_len);
+ if (inject_error == 4 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + c_x2s_pk_off, c_x2s_pk_len );
- if( inject_error == 4 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + c_x2s_pk_off, c_x2s_pk_len);
+ if (inject_error == 4 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + c_x2s_pr_off, c_x2s_pr_len );
- if( inject_error == 4 && status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_status );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + c_x2s_pr_off, c_x2s_pr_len);
+ if (inject_error == 4 && status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
break;
- }
- else
- {
- TEST_EQUAL( status, PSA_SUCCESS );
+ } else {
+ TEST_EQUAL(status, PSA_SUCCESS);
}
/* Error didn't trigger, make test fail */
- if( inject_error == 4 )
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if (inject_error == 4) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
+ }
break;
}
exit:
- mbedtls_free( buffer0 );
- mbedtls_free( buffer1 );
+ mbedtls_free(buffer0);
+ mbedtls_free(buffer1);
}
#endif /* PSA_WANT_ALG_JPAKE */
-typedef enum
-{
+typedef enum {
INJECT_ERR_NONE = 0,
INJECT_ERR_UNINITIALIZED_ACCESS,
INJECT_ERR_DUPLICATE_SETUP,
@@ -1345,7 +1228,7 @@
*/
/* BEGIN_CASE */
-void static_checks( )
+void static_checks()
{
size_t max_truncated_mac_size =
PSA_ALG_MAC_TRUNCATION_MASK >> PSA_MAC_TRUNCATION_OFFSET;
@@ -1353,14 +1236,14 @@
/* Check that the length for a truncated MAC always fits in the algorithm
* encoding. The shifted mask is the maximum truncated value. The
* untruncated algorithm may be one byte larger. */
- TEST_LE_U( PSA_MAC_MAX_SIZE, 1 + max_truncated_mac_size );
+ TEST_LE_U(PSA_MAC_MAX_SIZE, 1 + max_truncated_mac_size);
}
/* END_CASE */
/* BEGIN_CASE */
-void import_with_policy( int type_arg,
- int usage_arg, int alg_arg,
- int expected_status_arg )
+void import_with_policy(int type_arg,
+ int usage_arg, int alg_arg,
+ int expected_status_arg)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -1369,48 +1252,49 @@
psa_key_usage_t usage = usage_arg;
psa_algorithm_t alg = alg_arg;
psa_status_t expected_status = expected_status_arg;
- const uint8_t key_material[16] = {0};
+ const uint8_t key_material[16] = { 0 };
psa_status_t status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_type( &attributes, type );
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
+ psa_set_key_type(&attributes, type);
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
- status = psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &key );
- TEST_EQUAL( status, expected_status );
- if( status != PSA_SUCCESS )
+ status = psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &key);
+ TEST_EQUAL(status, expected_status);
+ if (status != PSA_SUCCESS) {
goto exit;
+ }
- PSA_ASSERT( psa_get_key_attributes( key, &got_attributes ) );
- TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
- TEST_EQUAL( psa_get_key_usage_flags( &got_attributes ),
- mbedtls_test_update_key_usage_flags( usage ) );
- TEST_EQUAL( psa_get_key_algorithm( &got_attributes ), alg );
- ASSERT_NO_SLOT_NUMBER( &got_attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
+ TEST_EQUAL(psa_get_key_type(&got_attributes), type);
+ TEST_EQUAL(psa_get_key_usage_flags(&got_attributes),
+ mbedtls_test_update_key_usage_flags(usage));
+ TEST_EQUAL(psa_get_key_algorithm(&got_attributes), alg);
+ ASSERT_NO_SLOT_NUMBER(&got_attributes);
- PSA_ASSERT( psa_destroy_key( key ) );
- test_operations_on_invalid_key( key );
+ PSA_ASSERT(psa_destroy_key(key));
+ test_operations_on_invalid_key(key);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &got_attributes );
+ psa_reset_key_attributes(&got_attributes);
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void import_with_data( data_t *data, int type_arg,
- int attr_bits_arg,
- int expected_status_arg )
+void import_with_data(data_t *data, int type_arg,
+ int attr_bits_arg,
+ int expected_status_arg)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -1420,41 +1304,43 @@
psa_status_t expected_status = expected_status_arg;
psa_status_t status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, attr_bits );
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, attr_bits);
- status = psa_import_key( &attributes, data->x, data->len, &key );
- TEST_EQUAL( status, expected_status );
- if( status != PSA_SUCCESS )
+ status = psa_import_key(&attributes, data->x, data->len, &key);
+ TEST_EQUAL(status, expected_status);
+ if (status != PSA_SUCCESS) {
goto exit;
+ }
- PSA_ASSERT( psa_get_key_attributes( key, &got_attributes ) );
- TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
- if( attr_bits != 0 )
- TEST_EQUAL( attr_bits, psa_get_key_bits( &got_attributes ) );
- ASSERT_NO_SLOT_NUMBER( &got_attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
+ TEST_EQUAL(psa_get_key_type(&got_attributes), type);
+ if (attr_bits != 0) {
+ TEST_EQUAL(attr_bits, psa_get_key_bits(&got_attributes));
+ }
+ ASSERT_NO_SLOT_NUMBER(&got_attributes);
- PSA_ASSERT( psa_destroy_key( key ) );
- test_operations_on_invalid_key( key );
+ PSA_ASSERT(psa_destroy_key(key));
+ test_operations_on_invalid_key(key);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &got_attributes );
+ psa_reset_key_attributes(&got_attributes);
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
/* Construct and attempt to import a large unstructured key. */
-void import_large_key( int type_arg, int byte_size_arg,
- int expected_status_arg )
+void import_large_key(int type_arg, int byte_size_arg,
+ int expected_status_arg)
{
psa_key_type_t type = type_arg;
size_t byte_size = byte_size_arg;
@@ -1468,31 +1354,32 @@
/* Skip the test case if the target running the test cannot
* accommodate large keys due to heap size constraints */
- ASSERT_ALLOC_WEAK( buffer, buffer_size );
- memset( buffer, 'K', byte_size );
+ ASSERT_ALLOC_WEAK(buffer, buffer_size);
+ memset(buffer, 'K', byte_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Try importing the key */
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, type );
- status = psa_import_key( &attributes, buffer, byte_size, &key );
- TEST_ASSUME( status != PSA_ERROR_INSUFFICIENT_MEMORY );
- TEST_EQUAL( status, expected_status );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, type);
+ status = psa_import_key(&attributes, buffer, byte_size, &key);
+ TEST_ASSUME(status != PSA_ERROR_INSUFFICIENT_MEMORY);
+ TEST_EQUAL(status, expected_status);
- if( status == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &attributes ),
- PSA_BYTES_TO_BITS( byte_size ) );
- ASSERT_NO_SLOT_NUMBER( &attributes );
- memset( buffer, 0, byte_size + 1 );
- PSA_ASSERT( psa_export_key( key, buffer, byte_size, &n ) );
- for( n = 0; n < byte_size; n++ )
- TEST_EQUAL( buffer[n], 'K' );
- for( n = byte_size; n < buffer_size; n++ )
- TEST_EQUAL( buffer[n], 0 );
+ if (status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&attributes),
+ PSA_BYTES_TO_BITS(byte_size));
+ ASSERT_NO_SLOT_NUMBER(&attributes);
+ memset(buffer, 0, byte_size + 1);
+ PSA_ASSERT(psa_export_key(key, buffer, byte_size, &n));
+ for (n = 0; n < byte_size; n++) {
+ TEST_EQUAL(buffer[n], 'K');
+ }
+ for (n = byte_size; n < buffer_size; n++) {
+ TEST_EQUAL(buffer[n], 0);
+ }
}
exit:
@@ -1500,11 +1387,11 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( buffer );
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(buffer);
}
/* END_CASE */
@@ -1512,7 +1399,7 @@
/* Import an RSA key with a valid structure (but not valid numbers
* inside, beyond having sensible size and parity). This is expected to
* fail for large keys. */
-void import_rsa_made_up( int bits_arg, int keypair, int expected_status_arg )
+void import_rsa_made_up(int bits_arg, int keypair, int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
size_t bits = bits_arg;
@@ -1521,44 +1408,45 @@
psa_key_type_t type =
keypair ? PSA_KEY_TYPE_RSA_KEY_PAIR : PSA_KEY_TYPE_RSA_PUBLIC_KEY;
size_t buffer_size = /* Slight overapproximations */
- keypair ? bits * 9 / 16 + 80 : bits / 8 + 20;
+ keypair ? bits * 9 / 16 + 80 : bits / 8 + 20;
unsigned char *buffer = NULL;
unsigned char *p;
int ret;
size_t length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
- ASSERT_ALLOC( buffer, buffer_size );
+ PSA_ASSERT(psa_crypto_init());
+ ASSERT_ALLOC(buffer, buffer_size);
- TEST_ASSERT( ( ret = construct_fake_rsa_key( buffer, buffer_size, &p,
- bits, keypair ) ) >= 0 );
+ TEST_ASSERT((ret = construct_fake_rsa_key(buffer, buffer_size, &p,
+ bits, keypair)) >= 0);
length = ret;
/* Try importing the key */
- psa_set_key_type( &attributes, type );
- status = psa_import_key( &attributes, p, length, &key );
- TEST_EQUAL( status, expected_status );
+ psa_set_key_type(&attributes, type);
+ status = psa_import_key(&attributes, p, length, &key);
+ TEST_EQUAL(status, expected_status);
- if( status == PSA_SUCCESS )
- PSA_ASSERT( psa_destroy_key( key ) );
+ if (status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_destroy_key(key));
+ }
exit:
- mbedtls_free( buffer );
- PSA_DONE( );
+ mbedtls_free(buffer);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void import_export( data_t *data,
- int type_arg,
- int usage_arg, int alg_arg,
- int lifetime_arg,
- int expected_bits,
- int export_size_delta,
- int expected_export_status_arg,
- /*whether reexport must give the original input exactly*/
- int canonical_input )
+void import_export(data_t *data,
+ int type_arg,
+ int usage_arg, int alg_arg,
+ int lifetime_arg,
+ int expected_bits,
+ int export_size_delta,
+ int expected_export_status_arg,
+ /*whether reexport must give the original input exactly*/
+ int canonical_input)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t type = type_arg;
@@ -1575,40 +1463,40 @@
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
export_size = (ptrdiff_t) data->len + export_size_delta;
- ASSERT_ALLOC( exported, export_size );
- if( ! canonical_input )
- ASSERT_ALLOC( reexported, export_size );
- PSA_ASSERT( psa_crypto_init( ) );
+ ASSERT_ALLOC(exported, export_size);
+ if (!canonical_input) {
+ ASSERT_ALLOC(reexported, export_size);
+ }
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, usage_arg );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, usage_arg);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
/* Import the key */
- PSA_ASSERT( psa_import_key( &attributes, data->x, data->len, &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, data->x, data->len, &key));
/* Test the key information */
- PSA_ASSERT( psa_get_key_attributes( key, &got_attributes ) );
- TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &got_attributes ), (size_t) expected_bits );
- ASSERT_NO_SLOT_NUMBER( &got_attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
+ TEST_EQUAL(psa_get_key_type(&got_attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&got_attributes), (size_t) expected_bits);
+ ASSERT_NO_SLOT_NUMBER(&got_attributes);
/* Export the key */
- status = psa_export_key( key, exported, export_size, &exported_length );
- TEST_EQUAL( status, expected_export_status );
+ status = psa_export_key(key, exported, export_size, &exported_length);
+ TEST_EQUAL(status, expected_export_status);
/* The exported length must be set by psa_export_key() to a value between 0
* and export_size. On errors, the exported length must be 0. */
- TEST_ASSERT( exported_length != INVALID_EXPORT_LENGTH );
- TEST_ASSERT( status == PSA_SUCCESS || exported_length == 0 );
- TEST_LE_U( exported_length, export_size );
+ TEST_ASSERT(exported_length != INVALID_EXPORT_LENGTH);
+ TEST_ASSERT(status == PSA_SUCCESS || exported_length == 0);
+ TEST_LE_U(exported_length, export_size);
- TEST_ASSERT( mem_is_char( exported + exported_length, 0,
- export_size - exported_length ) );
- if( status != PSA_SUCCESS )
- {
- TEST_EQUAL( exported_length, 0 );
+ TEST_ASSERT(mem_is_char(exported + exported_length, 0,
+ export_size - exported_length));
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(exported_length, 0);
goto destroy;
}
@@ -1616,58 +1504,57 @@
* this validates the canonical representations. For canonical inputs,
* this doesn't directly validate the implementation, but it still helps
* by cross-validating the test data with the sanity check code. */
- if( !psa_key_lifetime_is_external( lifetime ) )
- {
- if( ! mbedtls_test_psa_exercise_key( key, usage_arg, 0 ) )
+ if (!psa_key_lifetime_is_external(lifetime)) {
+ if (!mbedtls_test_psa_exercise_key(key, usage_arg, 0)) {
goto exit;
+ }
}
- if( canonical_input )
- ASSERT_COMPARE( data->x, data->len, exported, exported_length );
- else
- {
+ if (canonical_input) {
+ ASSERT_COMPARE(data->x, data->len, exported, exported_length);
+ } else {
mbedtls_svc_key_id_t key2 = MBEDTLS_SVC_KEY_ID_INIT;
- PSA_ASSERT( psa_import_key( &attributes, exported, exported_length,
- &key2 ) );
- PSA_ASSERT( psa_export_key( key2,
- reexported,
- export_size,
- &reexported_length ) );
- ASSERT_COMPARE( exported, exported_length,
- reexported, reexported_length );
- PSA_ASSERT( psa_destroy_key( key2 ) );
+ PSA_ASSERT(psa_import_key(&attributes, exported, exported_length,
+ &key2));
+ PSA_ASSERT(psa_export_key(key2,
+ reexported,
+ export_size,
+ &reexported_length));
+ ASSERT_COMPARE(exported, exported_length,
+ reexported, reexported_length);
+ PSA_ASSERT(psa_destroy_key(key2));
}
- TEST_LE_U( exported_length,
- PSA_EXPORT_KEY_OUTPUT_SIZE( type,
- psa_get_key_bits( &got_attributes ) ) );
- TEST_LE_U( exported_length, PSA_EXPORT_KEY_PAIR_MAX_SIZE );
+ TEST_LE_U(exported_length,
+ PSA_EXPORT_KEY_OUTPUT_SIZE(type,
+ psa_get_key_bits(&got_attributes)));
+ TEST_LE_U(exported_length, PSA_EXPORT_KEY_PAIR_MAX_SIZE);
destroy:
/* Destroy the key */
- PSA_ASSERT( psa_destroy_key( key ) );
- test_operations_on_invalid_key( key );
+ PSA_ASSERT(psa_destroy_key(key));
+ test_operations_on_invalid_key(key);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &got_attributes );
- psa_destroy_key( key ) ;
- mbedtls_free( exported );
- mbedtls_free( reexported );
- PSA_DONE( );
+ psa_reset_key_attributes(&got_attributes);
+ psa_destroy_key(key);
+ mbedtls_free(exported);
+ mbedtls_free(reexported);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void import_export_public_key( data_t *data,
- int type_arg, // key pair or public key
- int alg_arg,
- int lifetime_arg,
- int export_size_delta,
- int expected_export_status_arg,
- data_t *expected_public_key )
+void import_export_public_key(data_t *data,
+ int type_arg, // key pair or public key
+ int alg_arg,
+ int lifetime_arg,
+ int export_size_delta,
+ int expected_export_status_arg,
+ data_t *expected_public_key)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t type = type_arg;
@@ -1680,103 +1567,103 @@
size_t exported_length = INVALID_EXPORT_LENGTH;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
/* Import the key */
- PSA_ASSERT( psa_import_key( &attributes, data->x, data->len, &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, data->x, data->len, &key));
/* Export the public key */
- ASSERT_ALLOC( exported, export_size );
- status = psa_export_public_key( key,
- exported, export_size,
- &exported_length );
- TEST_EQUAL( status, expected_export_status );
- if( status == PSA_SUCCESS )
- {
- psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( type );
+ ASSERT_ALLOC(exported, export_size);
+ status = psa_export_public_key(key,
+ exported, export_size,
+ &exported_length);
+ TEST_EQUAL(status, expected_export_status);
+ if (status == PSA_SUCCESS) {
+ psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type);
size_t bits;
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- bits = psa_get_key_bits( &attributes );
- TEST_LE_U( expected_public_key->len,
- PSA_EXPORT_KEY_OUTPUT_SIZE( public_type, bits ) );
- TEST_LE_U( expected_public_key->len,
- PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( public_type, bits ) );
- TEST_LE_U( expected_public_key->len,
- PSA_EXPORT_PUBLIC_KEY_MAX_SIZE );
- ASSERT_COMPARE( expected_public_key->x, expected_public_key->len,
- exported, exported_length );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ bits = psa_get_key_bits(&attributes);
+ TEST_LE_U(expected_public_key->len,
+ PSA_EXPORT_KEY_OUTPUT_SIZE(public_type, bits));
+ TEST_LE_U(expected_public_key->len,
+ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_type, bits));
+ TEST_LE_U(expected_public_key->len,
+ PSA_EXPORT_PUBLIC_KEY_MAX_SIZE);
+ ASSERT_COMPARE(expected_public_key->x, expected_public_key->len,
+ exported, exported_length);
}
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_free( exported );
- psa_destroy_key( key );
- PSA_DONE( );
+ mbedtls_free(exported);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void import_and_exercise_key( data_t *data,
- int type_arg,
- int bits_arg,
- int alg_arg )
+void import_and_exercise_key(data_t *data,
+ int type_arg,
+ int bits_arg,
+ int alg_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t type = type_arg;
size_t bits = bits_arg;
psa_algorithm_t alg = alg_arg;
- psa_key_usage_t usage = mbedtls_test_psa_usage_to_exercise( type, alg );
+ psa_key_usage_t usage = mbedtls_test_psa_usage_to_exercise(type, alg);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
/* Import the key */
- PSA_ASSERT( psa_import_key( &attributes, data->x, data->len, &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, data->x, data->len, &key));
/* Test the key information */
- PSA_ASSERT( psa_get_key_attributes( key, &got_attributes ) );
- TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &got_attributes ), bits );
+ PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
+ TEST_EQUAL(psa_get_key_type(&got_attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&got_attributes), bits);
/* Do something with the key according to its type and permitted usage. */
- if( ! mbedtls_test_psa_exercise_key( key, usage, alg ) )
+ if (!mbedtls_test_psa_exercise_key(key, usage, alg)) {
goto exit;
+ }
- PSA_ASSERT( psa_destroy_key( key ) );
- test_operations_on_invalid_key( key );
+ PSA_ASSERT(psa_destroy_key(key));
+ test_operations_on_invalid_key(key);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &got_attributes );
+ psa_reset_key_attributes(&got_attributes);
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void effective_key_attributes( int type_arg, int expected_type_arg,
- int bits_arg, int expected_bits_arg,
- int usage_arg, int expected_usage_arg,
- int alg_arg, int expected_alg_arg )
+void effective_key_attributes(int type_arg, int expected_type_arg,
+ int bits_arg, int expected_bits_arg,
+ int usage_arg, int expected_usage_arg,
+ int alg_arg, int expected_alg_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = type_arg;
@@ -1789,89 +1676,89 @@
psa_key_usage_t expected_usage = expected_usage_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
- psa_set_key_bits( &attributes, bits );
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_bits(&attributes, bits);
- PSA_ASSERT( psa_generate_key( &attributes, &key ) );
- psa_reset_key_attributes( &attributes );
+ PSA_ASSERT(psa_generate_key(&attributes, &key));
+ psa_reset_key_attributes(&attributes);
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ), expected_key_type );
- TEST_EQUAL( psa_get_key_bits( &attributes ), expected_bits );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), expected_usage );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), expected_alg );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes), expected_key_type);
+ TEST_EQUAL(psa_get_key_bits(&attributes), expected_bits);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), expected_usage);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), expected_alg);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void check_key_policy( int type_arg, int bits_arg,
- int usage_arg, int alg_arg )
+void check_key_policy(int type_arg, int bits_arg,
+ int usage_arg, int alg_arg)
{
- test_effective_key_attributes( type_arg, type_arg, bits_arg, bits_arg,
- usage_arg,
- mbedtls_test_update_key_usage_flags( usage_arg ),
- alg_arg, alg_arg );
+ test_effective_key_attributes(type_arg, type_arg, bits_arg, bits_arg,
+ usage_arg,
+ mbedtls_test_update_key_usage_flags(usage_arg),
+ alg_arg, alg_arg);
goto exit;
}
/* END_CASE */
/* BEGIN_CASE */
-void key_attributes_init( )
+void key_attributes_init()
{
/* Test each valid way of initializing the object, except for `= {0}`, as
* Clang 5 complains when `-Wmissing-field-initializers` is used, even
* though it's OK by the C standard. We could test for this, but we'd need
* to suppress the Clang warning for the test. */
- psa_key_attributes_t func = psa_key_attributes_init( );
+ psa_key_attributes_t func = psa_key_attributes_init();
psa_key_attributes_t init = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t zero;
- memset( &zero, 0, sizeof( zero ) );
+ memset(&zero, 0, sizeof(zero));
- TEST_EQUAL( psa_get_key_lifetime( &func ), PSA_KEY_LIFETIME_VOLATILE );
- TEST_EQUAL( psa_get_key_lifetime( &init ), PSA_KEY_LIFETIME_VOLATILE );
- TEST_EQUAL( psa_get_key_lifetime( &zero ), PSA_KEY_LIFETIME_VOLATILE );
+ TEST_EQUAL(psa_get_key_lifetime(&func), PSA_KEY_LIFETIME_VOLATILE);
+ TEST_EQUAL(psa_get_key_lifetime(&init), PSA_KEY_LIFETIME_VOLATILE);
+ TEST_EQUAL(psa_get_key_lifetime(&zero), PSA_KEY_LIFETIME_VOLATILE);
- TEST_EQUAL( psa_get_key_type( &func ), 0 );
- TEST_EQUAL( psa_get_key_type( &init ), 0 );
- TEST_EQUAL( psa_get_key_type( &zero ), 0 );
+ TEST_EQUAL(psa_get_key_type(&func), 0);
+ TEST_EQUAL(psa_get_key_type(&init), 0);
+ TEST_EQUAL(psa_get_key_type(&zero), 0);
- TEST_EQUAL( psa_get_key_bits( &func ), 0 );
- TEST_EQUAL( psa_get_key_bits( &init ), 0 );
- TEST_EQUAL( psa_get_key_bits( &zero ), 0 );
+ TEST_EQUAL(psa_get_key_bits(&func), 0);
+ TEST_EQUAL(psa_get_key_bits(&init), 0);
+ TEST_EQUAL(psa_get_key_bits(&zero), 0);
- TEST_EQUAL( psa_get_key_usage_flags( &func ), 0 );
- TEST_EQUAL( psa_get_key_usage_flags( &init ), 0 );
- TEST_EQUAL( psa_get_key_usage_flags( &zero ), 0 );
+ TEST_EQUAL(psa_get_key_usage_flags(&func), 0);
+ TEST_EQUAL(psa_get_key_usage_flags(&init), 0);
+ TEST_EQUAL(psa_get_key_usage_flags(&zero), 0);
- TEST_EQUAL( psa_get_key_algorithm( &func ), 0 );
- TEST_EQUAL( psa_get_key_algorithm( &init ), 0 );
- TEST_EQUAL( psa_get_key_algorithm( &zero ), 0 );
+ TEST_EQUAL(psa_get_key_algorithm(&func), 0);
+ TEST_EQUAL(psa_get_key_algorithm(&init), 0);
+ TEST_EQUAL(psa_get_key_algorithm(&zero), 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_key_policy( int policy_usage_arg,
- int policy_alg_arg,
- int key_type_arg,
- data_t *key_data,
- int exercise_alg_arg,
- int expected_status_sign_arg,
- int expected_status_verify_arg )
+void mac_key_policy(int policy_usage_arg,
+ int policy_alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ int exercise_alg_arg,
+ int expected_status_sign_arg,
+ int expected_status_verify_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -1885,99 +1772,93 @@
psa_status_t expected_status_verify = expected_status_verify_arg;
unsigned char mac[PSA_MAC_MAX_SIZE];
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ),
- mbedtls_test_update_key_usage_flags( policy_usage ) );
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes),
+ mbedtls_test_update_key_usage_flags(policy_usage));
- status = psa_mac_sign_setup( &operation, key, exercise_alg );
- TEST_EQUAL( status, expected_status_sign );
+ status = psa_mac_sign_setup(&operation, key, exercise_alg);
+ TEST_EQUAL(status, expected_status_sign);
/* Calculate the MAC, one-shot case. */
- uint8_t input[128] = {0};
+ uint8_t input[128] = { 0 };
size_t mac_len;
- TEST_EQUAL( psa_mac_compute( key, exercise_alg,
- input, 128,
- mac, PSA_MAC_MAX_SIZE, &mac_len ),
- expected_status_sign );
+ TEST_EQUAL(psa_mac_compute(key, exercise_alg,
+ input, 128,
+ mac, PSA_MAC_MAX_SIZE, &mac_len),
+ expected_status_sign);
/* Calculate the MAC, multi-part case. */
- PSA_ASSERT( psa_mac_abort( &operation ) );
- status = psa_mac_sign_setup( &operation, key, exercise_alg );
- if( status == PSA_SUCCESS )
- {
- status = psa_mac_update( &operation, input, 128 );
- if( status == PSA_SUCCESS )
- TEST_EQUAL( psa_mac_sign_finish( &operation, mac, PSA_MAC_MAX_SIZE,
- &mac_len ),
- expected_status_sign );
- else
- TEST_EQUAL( status, expected_status_sign );
+ PSA_ASSERT(psa_mac_abort(&operation));
+ status = psa_mac_sign_setup(&operation, key, exercise_alg);
+ if (status == PSA_SUCCESS) {
+ status = psa_mac_update(&operation, input, 128);
+ if (status == PSA_SUCCESS) {
+ TEST_EQUAL(psa_mac_sign_finish(&operation, mac, PSA_MAC_MAX_SIZE,
+ &mac_len),
+ expected_status_sign);
+ } else {
+ TEST_EQUAL(status, expected_status_sign);
+ }
+ } else {
+ TEST_EQUAL(status, expected_status_sign);
}
- else
- {
- TEST_EQUAL( status, expected_status_sign );
- }
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Verify correct MAC, one-shot case. */
- status = psa_mac_verify( key, exercise_alg, input, 128,
- mac, mac_len );
+ status = psa_mac_verify(key, exercise_alg, input, 128,
+ mac, mac_len);
- if( expected_status_sign != PSA_SUCCESS && expected_status_verify == PSA_SUCCESS )
- TEST_EQUAL( status, PSA_ERROR_INVALID_SIGNATURE );
- else
- TEST_EQUAL( status, expected_status_verify );
+ if (expected_status_sign != PSA_SUCCESS && expected_status_verify == PSA_SUCCESS) {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_SIGNATURE);
+ } else {
+ TEST_EQUAL(status, expected_status_verify);
+ }
/* Verify correct MAC, multi-part case. */
- status = psa_mac_verify_setup( &operation, key, exercise_alg );
- if( status == PSA_SUCCESS )
- {
- status = psa_mac_update( &operation, input, 128 );
- if( status == PSA_SUCCESS )
- {
- status = psa_mac_verify_finish( &operation, mac, mac_len );
- if( expected_status_sign != PSA_SUCCESS && expected_status_verify == PSA_SUCCESS )
- TEST_EQUAL( status, PSA_ERROR_INVALID_SIGNATURE );
- else
- TEST_EQUAL( status, expected_status_verify );
+ status = psa_mac_verify_setup(&operation, key, exercise_alg);
+ if (status == PSA_SUCCESS) {
+ status = psa_mac_update(&operation, input, 128);
+ if (status == PSA_SUCCESS) {
+ status = psa_mac_verify_finish(&operation, mac, mac_len);
+ if (expected_status_sign != PSA_SUCCESS && expected_status_verify == PSA_SUCCESS) {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_SIGNATURE);
+ } else {
+ TEST_EQUAL(status, expected_status_verify);
+ }
+ } else {
+ TEST_EQUAL(status, expected_status_verify);
}
- else
- {
- TEST_EQUAL( status, expected_status_verify );
- }
- }
- else
- {
- TEST_EQUAL( status, expected_status_verify );
+ } else {
+ TEST_EQUAL(status, expected_status_verify);
}
- psa_mac_abort( &operation );
+ psa_mac_abort(&operation);
- memset( mac, 0, sizeof( mac ) );
- status = psa_mac_verify_setup( &operation, key, exercise_alg );
- TEST_EQUAL( status, expected_status_verify );
+ memset(mac, 0, sizeof(mac));
+ status = psa_mac_verify_setup(&operation, key, exercise_alg);
+ TEST_EQUAL(status, expected_status_verify);
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_key_policy( int policy_usage_arg,
- int policy_alg,
- int key_type,
- data_t *key_data,
- int exercise_alg )
+void cipher_key_policy(int policy_usage_arg,
+ int policy_alg,
+ int key_type,
+ data_t *key_data,
+ int exercise_alg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -1990,81 +1871,85 @@
uint8_t *input = NULL;
psa_status_t status;
- input_buffer_size = PSA_BLOCK_CIPHER_BLOCK_LENGTH( exercise_alg );
- output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, exercise_alg,
- input_buffer_size );
+ input_buffer_size = PSA_BLOCK_CIPHER_BLOCK_LENGTH(exercise_alg);
+ output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, exercise_alg,
+ input_buffer_size);
- ASSERT_ALLOC( input, input_buffer_size );
- ASSERT_ALLOC( output, output_buffer_size );
+ ASSERT_ALLOC(input, input_buffer_size);
+ ASSERT_ALLOC(output, output_buffer_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Check if no key usage flag implication is done */
- TEST_EQUAL( policy_usage,
- mbedtls_test_update_key_usage_flags( policy_usage ) );
+ TEST_EQUAL(policy_usage,
+ mbedtls_test_update_key_usage_flags(policy_usage));
/* Encrypt check, one-shot */
- status = psa_cipher_encrypt( key, exercise_alg, input, input_buffer_size,
- output, output_buffer_size,
- &output_length);
- if( policy_alg == exercise_alg &&
- ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = psa_cipher_encrypt(key, exercise_alg, input, input_buffer_size,
+ output, output_buffer_size,
+ &output_length);
+ if (policy_alg == exercise_alg &&
+ (policy_usage & PSA_KEY_USAGE_ENCRYPT) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
/* Encrypt check, multi-part */
- status = psa_cipher_encrypt_setup( &operation, key, exercise_alg );
- if( policy_alg == exercise_alg &&
- ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
- psa_cipher_abort( &operation );
+ status = psa_cipher_encrypt_setup(&operation, key, exercise_alg);
+ if (policy_alg == exercise_alg &&
+ (policy_usage & PSA_KEY_USAGE_ENCRYPT) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
+ psa_cipher_abort(&operation);
/* Decrypt check, one-shot */
- status = psa_cipher_decrypt( key, exercise_alg, output, output_buffer_size,
- input, input_buffer_size,
- &output_length);
- if( policy_alg == exercise_alg &&
- ( policy_usage & PSA_KEY_USAGE_DECRYPT ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = psa_cipher_decrypt(key, exercise_alg, output, output_buffer_size,
+ input, input_buffer_size,
+ &output_length);
+ if (policy_alg == exercise_alg &&
+ (policy_usage & PSA_KEY_USAGE_DECRYPT) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
/* Decrypt check, multi-part */
- status = psa_cipher_decrypt_setup( &operation, key, exercise_alg );
- if( policy_alg == exercise_alg &&
- ( policy_usage & PSA_KEY_USAGE_DECRYPT ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = psa_cipher_decrypt_setup(&operation, key, exercise_alg);
+ if (policy_alg == exercise_alg &&
+ (policy_usage & PSA_KEY_USAGE_DECRYPT) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( input );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(input);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_key_policy( int policy_usage_arg,
- int policy_alg,
- int key_type,
- data_t *key_data,
- int nonce_length_arg,
- int tag_length_arg,
- int exercise_alg,
- int expected_status_arg )
+void aead_key_policy(int policy_usage_arg,
+ int policy_alg,
+ int key_type,
+ data_t *key_data,
+ int nonce_length_arg,
+ int tag_length_arg,
+ int exercise_alg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -2072,83 +1957,87 @@
psa_key_usage_t policy_usage = policy_usage_arg;
psa_status_t status;
psa_status_t expected_status = expected_status_arg;
- unsigned char nonce[16] = {0};
+ unsigned char nonce[16] = { 0 };
size_t nonce_length = nonce_length_arg;
unsigned char tag[16];
size_t tag_length = tag_length_arg;
size_t output_length;
- TEST_LE_U( nonce_length, sizeof( nonce ) );
- TEST_LE_U( tag_length, sizeof( tag ) );
+ TEST_LE_U(nonce_length, sizeof(nonce));
+ TEST_LE_U(tag_length, sizeof(tag));
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Check if no key usage implication is done */
- TEST_EQUAL( policy_usage,
- mbedtls_test_update_key_usage_flags( policy_usage ) );
+ TEST_EQUAL(policy_usage,
+ mbedtls_test_update_key_usage_flags(policy_usage));
/* Encrypt check, one-shot */
- status = psa_aead_encrypt( key, exercise_alg,
- nonce, nonce_length,
- NULL, 0,
- NULL, 0,
- tag, tag_length,
- &output_length );
- if( ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 )
- TEST_EQUAL( status, expected_status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = psa_aead_encrypt(key, exercise_alg,
+ nonce, nonce_length,
+ NULL, 0,
+ NULL, 0,
+ tag, tag_length,
+ &output_length);
+ if ((policy_usage & PSA_KEY_USAGE_ENCRYPT) != 0) {
+ TEST_EQUAL(status, expected_status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
/* Encrypt check, multi-part */
- status = psa_aead_encrypt_setup( &operation, key, exercise_alg );
- if( ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 )
- TEST_EQUAL( status, expected_status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = psa_aead_encrypt_setup(&operation, key, exercise_alg);
+ if ((policy_usage & PSA_KEY_USAGE_ENCRYPT) != 0) {
+ TEST_EQUAL(status, expected_status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
/* Decrypt check, one-shot */
- memset( tag, 0, sizeof( tag ) );
- status = psa_aead_decrypt( key, exercise_alg,
- nonce, nonce_length,
- NULL, 0,
- tag, tag_length,
- NULL, 0,
- &output_length );
- if( ( policy_usage & PSA_KEY_USAGE_DECRYPT ) == 0 )
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
- else if( expected_status == PSA_SUCCESS )
- TEST_EQUAL( status, PSA_ERROR_INVALID_SIGNATURE );
- else
- TEST_EQUAL( status, expected_status );
+ memset(tag, 0, sizeof(tag));
+ status = psa_aead_decrypt(key, exercise_alg,
+ nonce, nonce_length,
+ NULL, 0,
+ tag, tag_length,
+ NULL, 0,
+ &output_length);
+ if ((policy_usage & PSA_KEY_USAGE_DECRYPT) == 0) {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ } else if (expected_status == PSA_SUCCESS) {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_SIGNATURE);
+ } else {
+ TEST_EQUAL(status, expected_status);
+ }
/* Decrypt check, multi-part */
- PSA_ASSERT( psa_aead_abort( &operation ) );
- status = psa_aead_decrypt_setup( &operation, key, exercise_alg );
- if( ( policy_usage & PSA_KEY_USAGE_DECRYPT ) == 0 )
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
- else
- TEST_EQUAL( status, expected_status );
+ PSA_ASSERT(psa_aead_abort(&operation));
+ status = psa_aead_decrypt_setup(&operation, key, exercise_alg);
+ if ((policy_usage & PSA_KEY_USAGE_DECRYPT) == 0) {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ } else {
+ TEST_EQUAL(status, expected_status);
+ }
exit:
- PSA_ASSERT( psa_aead_abort( &operation ) );
- psa_destroy_key( key );
- PSA_DONE( );
+ PSA_ASSERT(psa_aead_abort(&operation));
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_encryption_key_policy( int policy_usage_arg,
- int policy_alg,
- int key_type,
- data_t *key_data,
- int exercise_alg )
+void asymmetric_encryption_key_policy(int policy_usage_arg,
+ int policy_alg,
+ int key_type,
+ data_t *key_data,
+ int exercise_alg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -2159,204 +2048,210 @@
unsigned char *buffer = NULL;
size_t output_length;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Check if no key usage implication is done */
- TEST_EQUAL( policy_usage,
- mbedtls_test_update_key_usage_flags( policy_usage ) );
+ TEST_EQUAL(policy_usage,
+ mbedtls_test_update_key_usage_flags(policy_usage));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
- buffer_length = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits,
- exercise_alg );
- ASSERT_ALLOC( buffer, buffer_length );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
+ buffer_length = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits,
+ exercise_alg);
+ ASSERT_ALLOC(buffer, buffer_length);
- status = psa_asymmetric_encrypt( key, exercise_alg,
- NULL, 0,
- NULL, 0,
- buffer, buffer_length,
- &output_length );
- if( policy_alg == exercise_alg &&
- ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = psa_asymmetric_encrypt(key, exercise_alg,
+ NULL, 0,
+ NULL, 0,
+ buffer, buffer_length,
+ &output_length);
+ if (policy_alg == exercise_alg &&
+ (policy_usage & PSA_KEY_USAGE_ENCRYPT) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
- if( buffer_length != 0 )
- memset( buffer, 0, buffer_length );
- status = psa_asymmetric_decrypt( key, exercise_alg,
- buffer, buffer_length,
- NULL, 0,
- buffer, buffer_length,
- &output_length );
- if( policy_alg == exercise_alg &&
- ( policy_usage & PSA_KEY_USAGE_DECRYPT ) != 0 )
- TEST_EQUAL( status, PSA_ERROR_INVALID_PADDING );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ if (buffer_length != 0) {
+ memset(buffer, 0, buffer_length);
+ }
+ status = psa_asymmetric_decrypt(key, exercise_alg,
+ buffer, buffer_length,
+ NULL, 0,
+ buffer, buffer_length,
+ &output_length);
+ if (policy_alg == exercise_alg &&
+ (policy_usage & PSA_KEY_USAGE_DECRYPT) != 0) {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_PADDING);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( buffer );
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(buffer);
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_signature_key_policy( int policy_usage_arg,
- int policy_alg,
- int key_type,
- data_t *key_data,
- int exercise_alg,
- int payload_length_arg,
- int expected_usage_arg )
+void asymmetric_signature_key_policy(int policy_usage_arg,
+ int policy_alg,
+ int key_type,
+ data_t *key_data,
+ int exercise_alg,
+ int payload_length_arg,
+ int expected_usage_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_usage_t policy_usage = policy_usage_arg;
psa_key_usage_t expected_usage = expected_usage_arg;
psa_status_t status;
- unsigned char payload[PSA_HASH_MAX_SIZE] = {1};
+ unsigned char payload[PSA_HASH_MAX_SIZE] = { 1 };
/* If `payload_length_arg > 0`, `exercise_alg` is supposed to be
* compatible with the policy and `payload_length_arg` is supposed to be
* a valid input length to sign. If `payload_length_arg <= 0`,
* `exercise_alg` is supposed to be forbidden by the policy. */
int compatible_alg = payload_length_arg > 0;
size_t payload_length = compatible_alg ? payload_length_arg : 0;
- unsigned char signature[PSA_SIGNATURE_MAX_SIZE] = {0};
+ unsigned char signature[PSA_SIGNATURE_MAX_SIZE] = { 0 };
size_t signature_length;
/* Check if all implicit usage flags are deployed
in the expected usage flags. */
- TEST_EQUAL( expected_usage,
- mbedtls_test_update_key_usage_flags( policy_usage ) );
+ TEST_EQUAL(expected_usage,
+ mbedtls_test_update_key_usage_flags(policy_usage));
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), expected_usage );
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), expected_usage);
- status = psa_sign_hash( key, exercise_alg,
- payload, payload_length,
- signature, sizeof( signature ),
- &signature_length );
- if( compatible_alg && ( expected_usage & PSA_KEY_USAGE_SIGN_HASH ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = psa_sign_hash(key, exercise_alg,
+ payload, payload_length,
+ signature, sizeof(signature),
+ &signature_length);
+ if (compatible_alg && (expected_usage & PSA_KEY_USAGE_SIGN_HASH) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
- memset( signature, 0, sizeof( signature ) );
- status = psa_verify_hash( key, exercise_alg,
- payload, payload_length,
- signature, sizeof( signature ) );
- if( compatible_alg && ( expected_usage & PSA_KEY_USAGE_VERIFY_HASH ) != 0 )
- TEST_EQUAL( status, PSA_ERROR_INVALID_SIGNATURE );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ memset(signature, 0, sizeof(signature));
+ status = psa_verify_hash(key, exercise_alg,
+ payload, payload_length,
+ signature, sizeof(signature));
+ if (compatible_alg && (expected_usage & PSA_KEY_USAGE_VERIFY_HASH) != 0) {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_SIGNATURE);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
- if( PSA_ALG_IS_SIGN_HASH( exercise_alg ) &&
- PSA_ALG_IS_HASH( PSA_ALG_SIGN_GET_HASH( exercise_alg ) ) )
- {
- status = psa_sign_message( key, exercise_alg,
- payload, payload_length,
- signature, sizeof( signature ),
- &signature_length );
- if( compatible_alg && ( expected_usage & PSA_KEY_USAGE_SIGN_MESSAGE ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ if (PSA_ALG_IS_SIGN_HASH(exercise_alg) &&
+ PSA_ALG_IS_HASH(PSA_ALG_SIGN_GET_HASH(exercise_alg))) {
+ status = psa_sign_message(key, exercise_alg,
+ payload, payload_length,
+ signature, sizeof(signature),
+ &signature_length);
+ if (compatible_alg && (expected_usage & PSA_KEY_USAGE_SIGN_MESSAGE) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
- memset( signature, 0, sizeof( signature ) );
- status = psa_verify_message( key, exercise_alg,
- payload, payload_length,
- signature, sizeof( signature ) );
- if( compatible_alg && ( expected_usage & PSA_KEY_USAGE_VERIFY_MESSAGE ) != 0 )
- TEST_EQUAL( status, PSA_ERROR_INVALID_SIGNATURE );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ memset(signature, 0, sizeof(signature));
+ status = psa_verify_message(key, exercise_alg,
+ payload, payload_length,
+ signature, sizeof(signature));
+ if (compatible_alg && (expected_usage & PSA_KEY_USAGE_VERIFY_MESSAGE) != 0) {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_SIGNATURE);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
}
exit:
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_key_policy( int policy_usage,
- int policy_alg,
- int key_type,
- data_t *key_data,
- int exercise_alg )
+void derive_key_policy(int policy_usage,
+ int policy_alg,
+ int key_type,
+ data_t *key_data,
+ int exercise_alg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_status_t status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_key_derivation_setup( &operation, exercise_alg ) );
+ PSA_ASSERT(psa_key_derivation_setup(&operation, exercise_alg));
- if( PSA_ALG_IS_TLS12_PRF( exercise_alg ) ||
- PSA_ALG_IS_TLS12_PSK_TO_MS( exercise_alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes(
- &operation,
- PSA_KEY_DERIVATION_INPUT_SEED,
- (const uint8_t*) "", 0) );
+ if (PSA_ALG_IS_TLS12_PRF(exercise_alg) ||
+ PSA_ALG_IS_TLS12_PSK_TO_MS(exercise_alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(
+ &operation,
+ PSA_KEY_DERIVATION_INPUT_SEED,
+ (const uint8_t *) "", 0));
}
- status = psa_key_derivation_input_key( &operation,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- key );
+ status = psa_key_derivation_input_key(&operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET,
+ key);
- if( policy_alg == exercise_alg &&
- ( policy_usage & PSA_KEY_USAGE_DERIVE ) != 0 )
- PSA_ASSERT( status );
- else
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ if (policy_alg == exercise_alg &&
+ (policy_usage & PSA_KEY_USAGE_DERIVE) != 0) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
+ }
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void agreement_key_policy( int policy_usage,
- int policy_alg,
- int key_type_arg,
- data_t *key_data,
- int exercise_alg,
- int expected_status_arg )
+void agreement_key_policy(int policy_usage,
+ int policy_alg,
+ int key_type_arg,
+ data_t *key_data,
+ int exercise_alg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -2365,30 +2260,30 @@
psa_status_t status;
psa_status_t expected_status = expected_status_arg;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_key_derivation_setup( &operation, exercise_alg ) );
- status = mbedtls_test_psa_key_agreement_with_self( &operation, key );
+ PSA_ASSERT(psa_key_derivation_setup(&operation, exercise_alg));
+ status = mbedtls_test_psa_key_agreement_with_self(&operation, key);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_policy_alg2( int key_type_arg, data_t *key_data,
- int usage_arg, int alg_arg, int alg2_arg )
+void key_policy_alg2(int key_type_arg, data_t *key_data,
+ int usage_arg, int alg_arg, int alg2_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -2398,46 +2293,48 @@
psa_algorithm_t alg = alg_arg;
psa_algorithm_t alg2 = alg2_arg;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_enrollment_algorithm( &attributes, alg2 );
- psa_set_key_type( &attributes, key_type );
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_enrollment_algorithm(&attributes, alg2);
+ psa_set_key_type(&attributes, key_type);
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Update the usage flags to obtain implicit usage flags */
- usage = mbedtls_test_update_key_usage_flags( usage );
- PSA_ASSERT( psa_get_key_attributes( key, &got_attributes ) );
- TEST_EQUAL( psa_get_key_usage_flags( &got_attributes ), usage );
- TEST_EQUAL( psa_get_key_algorithm( &got_attributes ), alg );
- TEST_EQUAL( psa_get_key_enrollment_algorithm( &got_attributes ), alg2 );
+ usage = mbedtls_test_update_key_usage_flags(usage);
+ PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
+ TEST_EQUAL(psa_get_key_usage_flags(&got_attributes), usage);
+ TEST_EQUAL(psa_get_key_algorithm(&got_attributes), alg);
+ TEST_EQUAL(psa_get_key_enrollment_algorithm(&got_attributes), alg2);
- if( ! mbedtls_test_psa_exercise_key( key, usage, alg ) )
+ if (!mbedtls_test_psa_exercise_key(key, usage, alg)) {
goto exit;
- if( ! mbedtls_test_psa_exercise_key( key, usage, alg2 ) )
+ }
+ if (!mbedtls_test_psa_exercise_key(key, usage, alg2)) {
goto exit;
+ }
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &got_attributes );
+ psa_reset_key_attributes(&got_attributes);
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void raw_agreement_key_policy( int policy_usage,
- int policy_alg,
- int key_type_arg,
- data_t *key_data,
- int exercise_alg,
- int expected_status_arg )
+void raw_agreement_key_policy(int policy_usage,
+ int policy_alg,
+ int key_type_arg,
+ data_t *key_data,
+ int exercise_alg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -2446,37 +2343,37 @@
psa_status_t status;
psa_status_t expected_status = expected_status_arg;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, policy_usage );
- psa_set_key_algorithm( &attributes, policy_alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, policy_usage);
+ psa_set_key_algorithm(&attributes, policy_alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- status = mbedtls_test_psa_raw_key_agreement_with_self( exercise_alg, key );
+ status = mbedtls_test_psa_raw_key_agreement_with_self(exercise_alg, key);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void copy_success( int source_usage_arg,
- int source_alg_arg, int source_alg2_arg,
- unsigned int source_lifetime_arg,
- int type_arg, data_t *material,
- int copy_attributes,
- int target_usage_arg,
- int target_alg_arg, int target_alg2_arg,
- unsigned int target_lifetime_arg,
- int expected_usage_arg,
- int expected_alg_arg, int expected_alg2_arg )
+void copy_success(int source_usage_arg,
+ int source_alg_arg, int source_alg2_arg,
+ unsigned int source_lifetime_arg,
+ int type_arg, data_t *material,
+ int copy_attributes,
+ int target_usage_arg,
+ int target_alg_arg, int target_alg2_arg,
+ unsigned int target_lifetime_arg,
+ int expected_usage_arg,
+ int expected_alg_arg, int expected_alg2_arg)
{
psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -2489,168 +2386,170 @@
mbedtls_svc_key_id_t target_key = MBEDTLS_SVC_KEY_ID_INIT;
uint8_t *export_buffer = NULL;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Prepare the source key. */
- psa_set_key_usage_flags( &source_attributes, source_usage_arg );
- psa_set_key_algorithm( &source_attributes, source_alg_arg );
- psa_set_key_enrollment_algorithm( &source_attributes, source_alg2_arg );
- psa_set_key_type( &source_attributes, type_arg );
- psa_set_key_lifetime( &source_attributes, source_lifetime);
- PSA_ASSERT( psa_import_key( &source_attributes,
- material->x, material->len,
- &source_key ) );
- PSA_ASSERT( psa_get_key_attributes( source_key, &source_attributes ) );
+ psa_set_key_usage_flags(&source_attributes, source_usage_arg);
+ psa_set_key_algorithm(&source_attributes, source_alg_arg);
+ psa_set_key_enrollment_algorithm(&source_attributes, source_alg2_arg);
+ psa_set_key_type(&source_attributes, type_arg);
+ psa_set_key_lifetime(&source_attributes, source_lifetime);
+ PSA_ASSERT(psa_import_key(&source_attributes,
+ material->x, material->len,
+ &source_key));
+ PSA_ASSERT(psa_get_key_attributes(source_key, &source_attributes));
/* Prepare the target attributes. */
- if( copy_attributes )
- {
+ if (copy_attributes) {
target_attributes = source_attributes;
}
- psa_set_key_lifetime( &target_attributes, target_lifetime);
+ psa_set_key_lifetime(&target_attributes, target_lifetime);
- if( target_usage_arg != -1 )
- psa_set_key_usage_flags( &target_attributes, target_usage_arg );
- if( target_alg_arg != -1 )
- psa_set_key_algorithm( &target_attributes, target_alg_arg );
- if( target_alg2_arg != -1 )
- psa_set_key_enrollment_algorithm( &target_attributes, target_alg2_arg );
+ if (target_usage_arg != -1) {
+ psa_set_key_usage_flags(&target_attributes, target_usage_arg);
+ }
+ if (target_alg_arg != -1) {
+ psa_set_key_algorithm(&target_attributes, target_alg_arg);
+ }
+ if (target_alg2_arg != -1) {
+ psa_set_key_enrollment_algorithm(&target_attributes, target_alg2_arg);
+ }
/* Copy the key. */
- PSA_ASSERT( psa_copy_key( source_key,
- &target_attributes, &target_key ) );
+ PSA_ASSERT(psa_copy_key(source_key,
+ &target_attributes, &target_key));
/* Destroy the source to ensure that this doesn't affect the target. */
- PSA_ASSERT( psa_destroy_key( source_key ) );
+ PSA_ASSERT(psa_destroy_key(source_key));
/* Test that the target slot has the expected content and policy. */
- PSA_ASSERT( psa_get_key_attributes( target_key, &target_attributes ) );
- TEST_EQUAL( psa_get_key_type( &source_attributes ),
- psa_get_key_type( &target_attributes ) );
- TEST_EQUAL( psa_get_key_bits( &source_attributes ),
- psa_get_key_bits( &target_attributes ) );
- TEST_EQUAL( expected_usage, psa_get_key_usage_flags( &target_attributes ) );
- TEST_EQUAL( expected_alg, psa_get_key_algorithm( &target_attributes ) );
- TEST_EQUAL( expected_alg2,
- psa_get_key_enrollment_algorithm( &target_attributes ) );
- if( expected_usage & PSA_KEY_USAGE_EXPORT )
- {
+ PSA_ASSERT(psa_get_key_attributes(target_key, &target_attributes));
+ TEST_EQUAL(psa_get_key_type(&source_attributes),
+ psa_get_key_type(&target_attributes));
+ TEST_EQUAL(psa_get_key_bits(&source_attributes),
+ psa_get_key_bits(&target_attributes));
+ TEST_EQUAL(expected_usage, psa_get_key_usage_flags(&target_attributes));
+ TEST_EQUAL(expected_alg, psa_get_key_algorithm(&target_attributes));
+ TEST_EQUAL(expected_alg2,
+ psa_get_key_enrollment_algorithm(&target_attributes));
+ if (expected_usage & PSA_KEY_USAGE_EXPORT) {
size_t length;
- ASSERT_ALLOC( export_buffer, material->len );
- PSA_ASSERT( psa_export_key( target_key, export_buffer,
- material->len, &length ) );
- ASSERT_COMPARE( material->x, material->len,
- export_buffer, length );
+ ASSERT_ALLOC(export_buffer, material->len);
+ PSA_ASSERT(psa_export_key(target_key, export_buffer,
+ material->len, &length));
+ ASSERT_COMPARE(material->x, material->len,
+ export_buffer, length);
}
- if( !psa_key_lifetime_is_external( target_lifetime ) )
- {
- if( ! mbedtls_test_psa_exercise_key( target_key, expected_usage, expected_alg ) )
+ if (!psa_key_lifetime_is_external(target_lifetime)) {
+ if (!mbedtls_test_psa_exercise_key(target_key, expected_usage, expected_alg)) {
goto exit;
- if( ! mbedtls_test_psa_exercise_key( target_key, expected_usage, expected_alg2 ) )
+ }
+ if (!mbedtls_test_psa_exercise_key(target_key, expected_usage, expected_alg2)) {
goto exit;
+ }
}
- PSA_ASSERT( psa_destroy_key( target_key ) );
+ PSA_ASSERT(psa_destroy_key(target_key));
exit:
/*
* Source and target key attributes may have been returned by
* psa_get_key_attributes() thus reset them as required.
*/
- psa_reset_key_attributes( &source_attributes );
- psa_reset_key_attributes( &target_attributes );
+ psa_reset_key_attributes(&source_attributes);
+ psa_reset_key_attributes(&target_attributes);
- PSA_DONE( );
- mbedtls_free( export_buffer );
+ PSA_DONE();
+ mbedtls_free(export_buffer);
}
/* END_CASE */
/* BEGIN_CASE */
-void copy_fail( int source_usage_arg,
- int source_alg_arg, int source_alg2_arg,
- int source_lifetime_arg,
- int type_arg, data_t *material,
- int target_type_arg, int target_bits_arg,
- int target_usage_arg,
- int target_alg_arg, int target_alg2_arg,
- int target_id_arg, int target_lifetime_arg,
- int expected_status_arg )
+void copy_fail(int source_usage_arg,
+ int source_alg_arg, int source_alg2_arg,
+ int source_lifetime_arg,
+ int type_arg, data_t *material,
+ int target_type_arg, int target_bits_arg,
+ int target_usage_arg,
+ int target_alg_arg, int target_alg2_arg,
+ int target_id_arg, int target_lifetime_arg,
+ int expected_status_arg)
{
psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t source_key = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t target_key = MBEDTLS_SVC_KEY_ID_INIT;
- mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 1, target_id_arg );
+ mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make(1, target_id_arg);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Prepare the source key. */
- psa_set_key_usage_flags( &source_attributes, source_usage_arg );
- psa_set_key_algorithm( &source_attributes, source_alg_arg );
- psa_set_key_enrollment_algorithm( &source_attributes, source_alg2_arg );
- psa_set_key_type( &source_attributes, type_arg );
- psa_set_key_lifetime( &source_attributes, source_lifetime_arg );
- PSA_ASSERT( psa_import_key( &source_attributes,
- material->x, material->len,
- &source_key ) );
+ psa_set_key_usage_flags(&source_attributes, source_usage_arg);
+ psa_set_key_algorithm(&source_attributes, source_alg_arg);
+ psa_set_key_enrollment_algorithm(&source_attributes, source_alg2_arg);
+ psa_set_key_type(&source_attributes, type_arg);
+ psa_set_key_lifetime(&source_attributes, source_lifetime_arg);
+ PSA_ASSERT(psa_import_key(&source_attributes,
+ material->x, material->len,
+ &source_key));
/* Prepare the target attributes. */
- psa_set_key_id( &target_attributes, key_id );
- psa_set_key_lifetime( &target_attributes, target_lifetime_arg );
- psa_set_key_type( &target_attributes, target_type_arg );
- psa_set_key_bits( &target_attributes, target_bits_arg );
- psa_set_key_usage_flags( &target_attributes, target_usage_arg );
- psa_set_key_algorithm( &target_attributes, target_alg_arg );
- psa_set_key_enrollment_algorithm( &target_attributes, target_alg2_arg );
+ psa_set_key_id(&target_attributes, key_id);
+ psa_set_key_lifetime(&target_attributes, target_lifetime_arg);
+ psa_set_key_type(&target_attributes, target_type_arg);
+ psa_set_key_bits(&target_attributes, target_bits_arg);
+ psa_set_key_usage_flags(&target_attributes, target_usage_arg);
+ psa_set_key_algorithm(&target_attributes, target_alg_arg);
+ psa_set_key_enrollment_algorithm(&target_attributes, target_alg2_arg);
/* Try to copy the key. */
- TEST_EQUAL( psa_copy_key( source_key,
- &target_attributes, &target_key ),
- expected_status_arg );
+ TEST_EQUAL(psa_copy_key(source_key,
+ &target_attributes, &target_key),
+ expected_status_arg);
- PSA_ASSERT( psa_destroy_key( source_key ) );
+ PSA_ASSERT(psa_destroy_key(source_key));
exit:
- psa_reset_key_attributes( &source_attributes );
- psa_reset_key_attributes( &target_attributes );
- PSA_DONE( );
+ psa_reset_key_attributes(&source_attributes);
+ psa_reset_key_attributes(&target_attributes);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_operation_init( )
+void hash_operation_init()
{
const uint8_t input[1] = { 0 };
/* Test each valid way of initializing the object, except for `= {0}`, as
* Clang 5 complains when `-Wmissing-field-initializers` is used, even
* though it's OK by the C standard. We could test for this, but we'd need
* to suppress the Clang warning for the test. */
- psa_hash_operation_t func = psa_hash_operation_init( );
+ psa_hash_operation_t func = psa_hash_operation_init();
psa_hash_operation_t init = PSA_HASH_OPERATION_INIT;
psa_hash_operation_t zero;
- memset( &zero, 0, sizeof( zero ) );
+ memset(&zero, 0, sizeof(zero));
/* A freshly-initialized hash operation should not be usable. */
- TEST_EQUAL( psa_hash_update( &func, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_hash_update( &init, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_hash_update( &zero, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_hash_update(&func, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_hash_update(&init, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_hash_update(&zero, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
/* A default hash operation should be abortable without error. */
- PSA_ASSERT( psa_hash_abort( &func ) );
- PSA_ASSERT( psa_hash_abort( &init ) );
- PSA_ASSERT( psa_hash_abort( &zero ) );
+ PSA_ASSERT(psa_hash_abort(&func));
+ PSA_ASSERT(psa_hash_abort(&init));
+ PSA_ASSERT(psa_hash_abort(&zero));
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_setup( int alg_arg,
- int expected_status_arg )
+void hash_setup(int alg_arg,
+ int expected_status_arg)
{
psa_algorithm_t alg = alg_arg;
uint8_t *output = NULL;
@@ -2660,43 +2559,44 @@
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
psa_status_t status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Hash Setup, one-shot */
- output_size = PSA_HASH_LENGTH( alg );
- ASSERT_ALLOC( output, output_size );
+ output_size = PSA_HASH_LENGTH(alg);
+ ASSERT_ALLOC(output, output_size);
- status = psa_hash_compute( alg, NULL, 0,
- output, output_size, &output_length );
- TEST_EQUAL( status, expected_status );
+ status = psa_hash_compute(alg, NULL, 0,
+ output, output_size, &output_length);
+ TEST_EQUAL(status, expected_status);
/* Hash Setup, multi-part */
- status = psa_hash_setup( &operation, alg );
- TEST_EQUAL( status, expected_status );
+ status = psa_hash_setup(&operation, alg);
+ TEST_EQUAL(status, expected_status);
/* Whether setup succeeded or failed, abort must succeed. */
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ PSA_ASSERT(psa_hash_abort(&operation));
/* If setup failed, reproduce the failure, so as to
* test the resulting state of the operation object. */
- if( status != PSA_SUCCESS )
- TEST_EQUAL( psa_hash_setup( &operation, alg ), status );
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(psa_hash_setup(&operation, alg), status);
+ }
/* Now the operation object should be reusable. */
#if defined(KNOWN_SUPPORTED_HASH_ALG)
- PSA_ASSERT( psa_hash_setup( &operation, KNOWN_SUPPORTED_HASH_ALG ) );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ PSA_ASSERT(psa_hash_setup(&operation, KNOWN_SUPPORTED_HASH_ALG));
+ PSA_ASSERT(psa_hash_abort(&operation));
#endif
exit:
- mbedtls_free( output );
- PSA_DONE( );
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_compute_fail( int alg_arg, data_t *input,
- int output_size_arg, int expected_status_arg )
+void hash_compute_fail(int alg_arg, data_t *input,
+ int output_size_arg, int expected_status_arg)
{
psa_algorithm_t alg = alg_arg;
uint8_t *output = NULL;
@@ -2706,94 +2606,83 @@
psa_status_t expected_status = expected_status_arg;
psa_status_t status;
- ASSERT_ALLOC( output, output_size );
+ ASSERT_ALLOC(output, output_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Hash Compute, one-shot */
- status = psa_hash_compute( alg, input->x, input->len,
- output, output_size, &output_length );
- TEST_EQUAL( status, expected_status );
- TEST_LE_U( output_length, output_size );
+ status = psa_hash_compute(alg, input->x, input->len,
+ output, output_size, &output_length);
+ TEST_EQUAL(status, expected_status);
+ TEST_LE_U(output_length, output_size);
/* Hash Compute, multi-part */
- status = psa_hash_setup( &operation, alg );
- if( status == PSA_SUCCESS )
- {
- status = psa_hash_update( &operation, input->x, input->len );
- if( status == PSA_SUCCESS )
- {
- status = psa_hash_finish( &operation, output, output_size,
- &output_length );
- if( status == PSA_SUCCESS )
- TEST_LE_U( output_length, output_size );
- else
- TEST_EQUAL( status, expected_status );
+ status = psa_hash_setup(&operation, alg);
+ if (status == PSA_SUCCESS) {
+ status = psa_hash_update(&operation, input->x, input->len);
+ if (status == PSA_SUCCESS) {
+ status = psa_hash_finish(&operation, output, output_size,
+ &output_length);
+ if (status == PSA_SUCCESS) {
+ TEST_LE_U(output_length, output_size);
+ } else {
+ TEST_EQUAL(status, expected_status);
+ }
+ } else {
+ TEST_EQUAL(status, expected_status);
}
- else
- {
- TEST_EQUAL( status, expected_status );
- }
- }
- else
- {
- TEST_EQUAL( status, expected_status );
+ } else {
+ TEST_EQUAL(status, expected_status);
}
exit:
- PSA_ASSERT( psa_hash_abort( &operation ) );
- mbedtls_free( output );
- PSA_DONE( );
+ PSA_ASSERT(psa_hash_abort(&operation));
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_compare_fail( int alg_arg, data_t *input,
- data_t *reference_hash,
- int expected_status_arg )
+void hash_compare_fail(int alg_arg, data_t *input,
+ data_t *reference_hash,
+ int expected_status_arg)
{
psa_algorithm_t alg = alg_arg;
psa_status_t expected_status = expected_status_arg;
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
psa_status_t status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Hash Compare, one-shot */
- status = psa_hash_compare( alg, input->x, input->len,
- reference_hash->x, reference_hash->len );
- TEST_EQUAL( status, expected_status );
+ status = psa_hash_compare(alg, input->x, input->len,
+ reference_hash->x, reference_hash->len);
+ TEST_EQUAL(status, expected_status);
/* Hash Compare, multi-part */
- status = psa_hash_setup( &operation, alg );
- if( status == PSA_SUCCESS )
- {
- status = psa_hash_update( &operation, input->x, input->len );
- if( status == PSA_SUCCESS )
- {
- status = psa_hash_verify( &operation, reference_hash->x,
- reference_hash->len );
- TEST_EQUAL( status, expected_status );
+ status = psa_hash_setup(&operation, alg);
+ if (status == PSA_SUCCESS) {
+ status = psa_hash_update(&operation, input->x, input->len);
+ if (status == PSA_SUCCESS) {
+ status = psa_hash_verify(&operation, reference_hash->x,
+ reference_hash->len);
+ TEST_EQUAL(status, expected_status);
+ } else {
+ TEST_EQUAL(status, expected_status);
}
- else
- {
- TEST_EQUAL( status, expected_status );
- }
- }
- else
- {
- TEST_EQUAL( status, expected_status );
+ } else {
+ TEST_EQUAL(status, expected_status);
}
exit:
- PSA_ASSERT( psa_hash_abort( &operation ) );
- PSA_DONE( );
+ PSA_ASSERT(psa_hash_abort(&operation));
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_compute_compare( int alg_arg, data_t *input,
- data_t *expected_output )
+void hash_compute_compare(int alg_arg, data_t *input,
+ data_t *expected_output)
{
psa_algorithm_t alg = alg_arg;
uint8_t output[PSA_HASH_MAX_SIZE + 1];
@@ -2801,103 +2690,102 @@
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
size_t i;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Compute with tight buffer, one-shot */
- PSA_ASSERT( psa_hash_compute( alg, input->x, input->len,
- output, PSA_HASH_LENGTH( alg ),
- &output_length ) );
- TEST_EQUAL( output_length, PSA_HASH_LENGTH( alg ) );
- ASSERT_COMPARE( output, output_length,
- expected_output->x, expected_output->len );
+ PSA_ASSERT(psa_hash_compute(alg, input->x, input->len,
+ output, PSA_HASH_LENGTH(alg),
+ &output_length));
+ TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
+ ASSERT_COMPARE(output, output_length,
+ expected_output->x, expected_output->len);
/* Compute with tight buffer, multi-part */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- PSA_ASSERT( psa_hash_finish( &operation, output,
- PSA_HASH_LENGTH( alg ),
- &output_length ) );
- TEST_EQUAL( output_length, PSA_HASH_LENGTH( alg ) );
- ASSERT_COMPARE( output, output_length,
- expected_output->x, expected_output->len );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ PSA_ASSERT(psa_hash_finish(&operation, output,
+ PSA_HASH_LENGTH(alg),
+ &output_length));
+ TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
+ ASSERT_COMPARE(output, output_length,
+ expected_output->x, expected_output->len);
/* Compute with larger buffer, one-shot */
- PSA_ASSERT( psa_hash_compute( alg, input->x, input->len,
- output, sizeof( output ),
- &output_length ) );
- TEST_EQUAL( output_length, PSA_HASH_LENGTH( alg ) );
- ASSERT_COMPARE( output, output_length,
- expected_output->x, expected_output->len );
+ PSA_ASSERT(psa_hash_compute(alg, input->x, input->len,
+ output, sizeof(output),
+ &output_length));
+ TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
+ ASSERT_COMPARE(output, output_length,
+ expected_output->x, expected_output->len);
/* Compute with larger buffer, multi-part */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- PSA_ASSERT( psa_hash_finish( &operation, output,
- sizeof( output ), &output_length ) );
- TEST_EQUAL( output_length, PSA_HASH_LENGTH( alg ) );
- ASSERT_COMPARE( output, output_length,
- expected_output->x, expected_output->len );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ PSA_ASSERT(psa_hash_finish(&operation, output,
+ sizeof(output), &output_length));
+ TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
+ ASSERT_COMPARE(output, output_length,
+ expected_output->x, expected_output->len);
/* Compare with correct hash, one-shot */
- PSA_ASSERT( psa_hash_compare( alg, input->x, input->len,
- output, output_length ) );
+ PSA_ASSERT(psa_hash_compare(alg, input->x, input->len,
+ output, output_length));
/* Compare with correct hash, multi-part */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- PSA_ASSERT( psa_hash_verify( &operation, output,
- output_length ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ PSA_ASSERT(psa_hash_verify(&operation, output,
+ output_length));
/* Compare with trailing garbage, one-shot */
- TEST_EQUAL( psa_hash_compare( alg, input->x, input->len,
- output, output_length + 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ TEST_EQUAL(psa_hash_compare(alg, input->x, input->len,
+ output, output_length + 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Compare with trailing garbage, multi-part */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- TEST_EQUAL( psa_hash_verify( &operation, output, output_length + 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ TEST_EQUAL(psa_hash_verify(&operation, output, output_length + 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Compare with truncated hash, one-shot */
- TEST_EQUAL( psa_hash_compare( alg, input->x, input->len,
- output, output_length - 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ TEST_EQUAL(psa_hash_compare(alg, input->x, input->len,
+ output, output_length - 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Compare with truncated hash, multi-part */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- TEST_EQUAL( psa_hash_verify( &operation, output, output_length - 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ TEST_EQUAL(psa_hash_verify(&operation, output, output_length - 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Compare with corrupted value */
- for( i = 0; i < output_length; i++ )
- {
- mbedtls_test_set_step( i );
+ for (i = 0; i < output_length; i++) {
+ mbedtls_test_set_step(i);
output[i] ^= 1;
/* One-shot */
- TEST_EQUAL( psa_hash_compare( alg, input->x, input->len,
- output, output_length ),
- PSA_ERROR_INVALID_SIGNATURE );
+ TEST_EQUAL(psa_hash_compare(alg, input->x, input->len,
+ output, output_length),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Multi-Part */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- TEST_EQUAL( psa_hash_verify( &operation, output, output_length ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ TEST_EQUAL(psa_hash_verify(&operation, output, output_length),
+ PSA_ERROR_INVALID_SIGNATURE);
output[i] ^= 1;
}
exit:
- PSA_ASSERT( psa_hash_abort( &operation ) );
- PSA_DONE( );
+ PSA_ASSERT(psa_hash_abort(&operation));
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_SHA_256 */
-void hash_bad_order( )
+void hash_bad_order()
{
psa_algorithm_t alg = PSA_ALG_SHA_256;
unsigned char input[] = "";
@@ -2905,103 +2793,104 @@
const unsigned char valid_hash[] = {
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8,
0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
- 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55 };
+ 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
+ };
unsigned char hash[sizeof(valid_hash)] = { 0 };
size_t hash_len;
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Call setup twice in a row. */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_hash_setup( &operation, alg ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_hash_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_hash_setup(&operation, alg),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_hash_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Call update without calling setup beforehand. */
- TEST_EQUAL( psa_hash_update( &operation, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ TEST_EQUAL(psa_hash_update(&operation, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_hash_abort(&operation));
/* Check that update calls abort on error. */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
operation.id = UINT_MAX;
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_hash_update( &operation, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_hash_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_hash_update(&operation, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_hash_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Call update after finish. */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_finish( &operation,
- hash, sizeof( hash ), &hash_len ) );
- TEST_EQUAL( psa_hash_update( &operation, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_finish(&operation,
+ hash, sizeof(hash), &hash_len));
+ TEST_EQUAL(psa_hash_update(&operation, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_hash_abort(&operation));
/* Call verify without calling setup beforehand. */
- TEST_EQUAL( psa_hash_verify( &operation,
- valid_hash, sizeof( valid_hash ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ TEST_EQUAL(psa_hash_verify(&operation,
+ valid_hash, sizeof(valid_hash)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_hash_abort(&operation));
/* Call verify after finish. */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_finish( &operation,
- hash, sizeof( hash ), &hash_len ) );
- TEST_EQUAL( psa_hash_verify( &operation,
- valid_hash, sizeof( valid_hash ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_finish(&operation,
+ hash, sizeof(hash), &hash_len));
+ TEST_EQUAL(psa_hash_verify(&operation,
+ valid_hash, sizeof(valid_hash)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_hash_abort(&operation));
/* Call verify twice in a row. */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- PSA_ASSERT( psa_hash_verify( &operation,
- valid_hash, sizeof( valid_hash ) ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- TEST_EQUAL( psa_hash_verify( &operation,
- valid_hash, sizeof( valid_hash ) ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ PSA_ASSERT(psa_hash_verify(&operation,
+ valid_hash, sizeof(valid_hash)));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ TEST_EQUAL(psa_hash_verify(&operation,
+ valid_hash, sizeof(valid_hash)),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_hash_abort(&operation));
/* Call finish without calling setup beforehand. */
- TEST_EQUAL( psa_hash_finish( &operation,
- hash, sizeof( hash ), &hash_len ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ TEST_EQUAL(psa_hash_finish(&operation,
+ hash, sizeof(hash), &hash_len),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_hash_abort(&operation));
/* Call finish twice in a row. */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_finish( &operation,
- hash, sizeof( hash ), &hash_len ) );
- TEST_EQUAL( psa_hash_finish( &operation,
- hash, sizeof( hash ), &hash_len ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_finish(&operation,
+ hash, sizeof(hash), &hash_len));
+ TEST_EQUAL(psa_hash_finish(&operation,
+ hash, sizeof(hash), &hash_len),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_hash_abort(&operation));
/* Call finish after calling verify. */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_verify( &operation,
- valid_hash, sizeof( valid_hash ) ) );
- TEST_EQUAL( psa_hash_finish( &operation,
- hash, sizeof( hash ), &hash_len ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_verify(&operation,
+ valid_hash, sizeof(valid_hash)));
+ TEST_EQUAL(psa_hash_finish(&operation,
+ hash, sizeof(hash), &hash_len),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_hash_abort(&operation));
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_SHA_256 */
-void hash_verify_bad_args( )
+void hash_verify_bad_args()
{
psa_algorithm_t alg = PSA_ALG_SHA_256;
/* SHA-256 hash of an empty string with 2 extra bytes (0xaa and 0xbb)
@@ -3009,60 +2898,61 @@
unsigned char hash[] = {
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8,
0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
- 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55, 0xaa, 0xbb };
- size_t expected_size = PSA_HASH_LENGTH( alg );
+ 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55, 0xaa, 0xbb
+ };
+ size_t expected_size = PSA_HASH_LENGTH(alg);
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* psa_hash_verify with a smaller hash than expected */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_hash_verify( &operation, hash, expected_size - 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_hash_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_hash_verify(&operation, hash, expected_size - 1),
+ PSA_ERROR_INVALID_SIGNATURE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_hash_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* psa_hash_verify with a non-matching hash */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- TEST_EQUAL( psa_hash_verify( &operation, hash + 1, expected_size ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ TEST_EQUAL(psa_hash_verify(&operation, hash + 1, expected_size),
+ PSA_ERROR_INVALID_SIGNATURE);
/* psa_hash_verify with a hash longer than expected */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- TEST_EQUAL( psa_hash_verify( &operation, hash, sizeof( hash ) ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ TEST_EQUAL(psa_hash_verify(&operation, hash, sizeof(hash)),
+ PSA_ERROR_INVALID_SIGNATURE);
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_SHA_256 */
-void hash_finish_bad_args( )
+void hash_finish_bad_args()
{
psa_algorithm_t alg = PSA_ALG_SHA_256;
unsigned char hash[PSA_HASH_MAX_SIZE];
- size_t expected_size = PSA_HASH_LENGTH( alg );
+ size_t expected_size = PSA_HASH_LENGTH(alg);
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
size_t hash_len;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* psa_hash_finish with a smaller hash buffer than expected */
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- TEST_EQUAL( psa_hash_finish( &operation,
- hash, expected_size - 1, &hash_len ),
- PSA_ERROR_BUFFER_TOO_SMALL );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ TEST_EQUAL(psa_hash_finish(&operation,
+ hash, expected_size - 1, &hash_len),
+ PSA_ERROR_BUFFER_TOO_SMALL);
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_SHA_256 */
-void hash_clone_source_state( )
+void hash_clone_source_state()
{
psa_algorithm_t alg = PSA_ALG_SHA_256;
unsigned char hash[PSA_HASH_MAX_SIZE];
@@ -3073,41 +2963,41 @@
psa_hash_operation_t op_aborted = PSA_HASH_OPERATION_INIT;
size_t hash_len;
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_ASSERT( psa_hash_setup( &op_source, alg ) );
+ PSA_ASSERT(psa_crypto_init());
+ PSA_ASSERT(psa_hash_setup(&op_source, alg));
- PSA_ASSERT( psa_hash_setup( &op_setup, alg ) );
- PSA_ASSERT( psa_hash_setup( &op_finished, alg ) );
- PSA_ASSERT( psa_hash_finish( &op_finished,
- hash, sizeof( hash ), &hash_len ) );
- PSA_ASSERT( psa_hash_setup( &op_aborted, alg ) );
- PSA_ASSERT( psa_hash_abort( &op_aborted ) );
+ PSA_ASSERT(psa_hash_setup(&op_setup, alg));
+ PSA_ASSERT(psa_hash_setup(&op_finished, alg));
+ PSA_ASSERT(psa_hash_finish(&op_finished,
+ hash, sizeof(hash), &hash_len));
+ PSA_ASSERT(psa_hash_setup(&op_aborted, alg));
+ PSA_ASSERT(psa_hash_abort(&op_aborted));
- TEST_EQUAL( psa_hash_clone( &op_source, &op_setup ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_hash_clone(&op_source, &op_setup),
+ PSA_ERROR_BAD_STATE);
- PSA_ASSERT( psa_hash_clone( &op_source, &op_init ) );
- PSA_ASSERT( psa_hash_finish( &op_init,
- hash, sizeof( hash ), &hash_len ) );
- PSA_ASSERT( psa_hash_clone( &op_source, &op_finished ) );
- PSA_ASSERT( psa_hash_finish( &op_finished,
- hash, sizeof( hash ), &hash_len ) );
- PSA_ASSERT( psa_hash_clone( &op_source, &op_aborted ) );
- PSA_ASSERT( psa_hash_finish( &op_aborted,
- hash, sizeof( hash ), &hash_len ) );
+ PSA_ASSERT(psa_hash_clone(&op_source, &op_init));
+ PSA_ASSERT(psa_hash_finish(&op_init,
+ hash, sizeof(hash), &hash_len));
+ PSA_ASSERT(psa_hash_clone(&op_source, &op_finished));
+ PSA_ASSERT(psa_hash_finish(&op_finished,
+ hash, sizeof(hash), &hash_len));
+ PSA_ASSERT(psa_hash_clone(&op_source, &op_aborted));
+ PSA_ASSERT(psa_hash_finish(&op_aborted,
+ hash, sizeof(hash), &hash_len));
exit:
- psa_hash_abort( &op_source );
- psa_hash_abort( &op_init );
- psa_hash_abort( &op_setup );
- psa_hash_abort( &op_finished );
- psa_hash_abort( &op_aborted );
- PSA_DONE( );
+ psa_hash_abort(&op_source);
+ psa_hash_abort(&op_init);
+ psa_hash_abort(&op_setup);
+ psa_hash_abort(&op_finished);
+ psa_hash_abort(&op_aborted);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_SHA_256 */
-void hash_clone_target_state( )
+void hash_clone_target_state()
{
psa_algorithm_t alg = PSA_ALG_SHA_256;
unsigned char hash[PSA_HASH_MAX_SIZE];
@@ -3118,37 +3008,37 @@
psa_hash_operation_t op_target = PSA_HASH_OPERATION_INIT;
size_t hash_len;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- PSA_ASSERT( psa_hash_setup( &op_setup, alg ) );
- PSA_ASSERT( psa_hash_setup( &op_finished, alg ) );
- PSA_ASSERT( psa_hash_finish( &op_finished,
- hash, sizeof( hash ), &hash_len ) );
- PSA_ASSERT( psa_hash_setup( &op_aborted, alg ) );
- PSA_ASSERT( psa_hash_abort( &op_aborted ) );
+ PSA_ASSERT(psa_hash_setup(&op_setup, alg));
+ PSA_ASSERT(psa_hash_setup(&op_finished, alg));
+ PSA_ASSERT(psa_hash_finish(&op_finished,
+ hash, sizeof(hash), &hash_len));
+ PSA_ASSERT(psa_hash_setup(&op_aborted, alg));
+ PSA_ASSERT(psa_hash_abort(&op_aborted));
- PSA_ASSERT( psa_hash_clone( &op_setup, &op_target ) );
- PSA_ASSERT( psa_hash_finish( &op_target,
- hash, sizeof( hash ), &hash_len ) );
+ PSA_ASSERT(psa_hash_clone(&op_setup, &op_target));
+ PSA_ASSERT(psa_hash_finish(&op_target,
+ hash, sizeof(hash), &hash_len));
- TEST_EQUAL( psa_hash_clone( &op_init, &op_target ), PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_hash_clone( &op_finished, &op_target ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_hash_clone( &op_aborted, &op_target ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_hash_clone(&op_init, &op_target), PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_hash_clone(&op_finished, &op_target),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_hash_clone(&op_aborted, &op_target),
+ PSA_ERROR_BAD_STATE);
exit:
- psa_hash_abort( &op_target );
- psa_hash_abort( &op_init );
- psa_hash_abort( &op_setup );
- psa_hash_abort( &op_finished );
- psa_hash_abort( &op_aborted );
- PSA_DONE( );
+ psa_hash_abort(&op_target);
+ psa_hash_abort(&op_init);
+ psa_hash_abort(&op_setup);
+ psa_hash_abort(&op_finished);
+ psa_hash_abort(&op_aborted);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_operation_init( )
+void mac_operation_init()
{
const uint8_t input[1] = { 0 };
@@ -3156,35 +3046,35 @@
* Clang 5 complains when `-Wmissing-field-initializers` is used, even
* though it's OK by the C standard. We could test for this, but we'd need
* to suppress the Clang warning for the test. */
- psa_mac_operation_t func = psa_mac_operation_init( );
+ psa_mac_operation_t func = psa_mac_operation_init();
psa_mac_operation_t init = PSA_MAC_OPERATION_INIT;
psa_mac_operation_t zero;
- memset( &zero, 0, sizeof( zero ) );
+ memset(&zero, 0, sizeof(zero));
/* A freshly-initialized MAC operation should not be usable. */
- TEST_EQUAL( psa_mac_update( &func,
- input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_mac_update( &init,
- input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_mac_update( &zero,
- input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_mac_update(&func,
+ input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_mac_update(&init,
+ input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_mac_update(&zero,
+ input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
/* A default MAC operation should be abortable without error. */
- PSA_ASSERT( psa_mac_abort( &func ) );
- PSA_ASSERT( psa_mac_abort( &init ) );
- PSA_ASSERT( psa_mac_abort( &zero ) );
+ PSA_ASSERT(psa_mac_abort(&func));
+ PSA_ASSERT(psa_mac_abort(&init));
+ PSA_ASSERT(psa_mac_abort(&zero));
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_setup( int key_type_arg,
- data_t *key,
- int alg_arg,
- int expected_status_arg )
+void mac_setup(int key_type_arg,
+ data_t *key,
+ int alg_arg,
+ int expected_status_arg)
{
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
@@ -3195,31 +3085,33 @@
const uint8_t smoke_test_key_data[16] = "kkkkkkkkkkkkkkkk";
#endif
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- if( ! exercise_mac_setup( key_type, key->x, key->len, alg,
- &operation, &status ) )
+ if (!exercise_mac_setup(key_type, key->x, key->len, alg,
+ &operation, &status)) {
goto exit;
- TEST_EQUAL( status, expected_status );
+ }
+ TEST_EQUAL(status, expected_status);
/* The operation object should be reusable. */
#if defined(KNOWN_SUPPORTED_MAC_ALG)
- if( ! exercise_mac_setup( KNOWN_SUPPORTED_MAC_KEY_TYPE,
- smoke_test_key_data,
- sizeof( smoke_test_key_data ),
- KNOWN_SUPPORTED_MAC_ALG,
- &operation, &status ) )
+ if (!exercise_mac_setup(KNOWN_SUPPORTED_MAC_KEY_TYPE,
+ smoke_test_key_data,
+ sizeof(smoke_test_key_data),
+ KNOWN_SUPPORTED_MAC_ALG,
+ &operation, &status)) {
goto exit;
- TEST_EQUAL( status, PSA_SUCCESS );
+ }
+ TEST_EQUAL(status, PSA_SUCCESS);
#endif
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_KEY_TYPE_HMAC:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_256 */
-void mac_bad_order( )
+void mac_bad_order()
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = PSA_KEY_TYPE_HMAC;
@@ -3227,7 +3119,8 @@
const uint8_t key_data[] = {
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa };
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
+ };
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
uint8_t sign_mac[PSA_MAC_MAX_SIZE + 10] = { 0 };
@@ -3236,144 +3129,146 @@
const uint8_t verify_mac[] = {
0x74, 0x65, 0x93, 0x8c, 0xeb, 0x1d, 0xb3, 0x76, 0x5a, 0x38, 0xe7, 0xdd,
0x85, 0xc5, 0xad, 0x4f, 0x07, 0xe7, 0xd5, 0xb2, 0x64, 0xf0, 0x1a, 0x1a,
- 0x2c, 0xf9, 0x18, 0xca, 0x59, 0x7e, 0x5d, 0xf6 };
+ 0x2c, 0xf9, 0x18, 0xca, 0x59, 0x7e, 0x5d, 0xf6
+ };
- PSA_ASSERT( psa_crypto_init( ) );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ PSA_ASSERT(psa_crypto_init());
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data, sizeof( key_data ),
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data, sizeof(key_data),
+ &key));
/* Call update without calling setup beforehand. */
- TEST_EQUAL( psa_mac_update( &operation, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ TEST_EQUAL(psa_mac_update(&operation, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Call sign finish without calling setup beforehand. */
- TEST_EQUAL( psa_mac_sign_finish( &operation, sign_mac, sizeof( sign_mac ),
- &sign_mac_length),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ TEST_EQUAL(psa_mac_sign_finish(&operation, sign_mac, sizeof(sign_mac),
+ &sign_mac_length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Call verify finish without calling setup beforehand. */
- TEST_EQUAL( psa_mac_verify_finish( &operation,
- verify_mac, sizeof( verify_mac ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ TEST_EQUAL(psa_mac_verify_finish(&operation,
+ verify_mac, sizeof(verify_mac)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Call setup twice in a row. */
- PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_mac_sign_setup( &operation, key, alg ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_mac_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_mac_sign_setup(&operation, key, alg),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_mac_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Call update after sign finish. */
- PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation, input, sizeof( input ) ) );
- PSA_ASSERT( psa_mac_sign_finish( &operation,
- sign_mac, sizeof( sign_mac ),
- &sign_mac_length ) );
- TEST_EQUAL( psa_mac_update( &operation, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation, input, sizeof(input)));
+ PSA_ASSERT(psa_mac_sign_finish(&operation,
+ sign_mac, sizeof(sign_mac),
+ &sign_mac_length));
+ TEST_EQUAL(psa_mac_update(&operation, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Call update after verify finish. */
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation, input, sizeof( input ) ) );
- PSA_ASSERT( psa_mac_verify_finish( &operation,
- verify_mac, sizeof( verify_mac ) ) );
- TEST_EQUAL( psa_mac_update( &operation, input, sizeof( input ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation, input, sizeof(input)));
+ PSA_ASSERT(psa_mac_verify_finish(&operation,
+ verify_mac, sizeof(verify_mac)));
+ TEST_EQUAL(psa_mac_update(&operation, input, sizeof(input)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Call sign finish twice in a row. */
- PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation, input, sizeof( input ) ) );
- PSA_ASSERT( psa_mac_sign_finish( &operation,
- sign_mac, sizeof( sign_mac ),
- &sign_mac_length ) );
- TEST_EQUAL( psa_mac_sign_finish( &operation,
- sign_mac, sizeof( sign_mac ),
- &sign_mac_length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation, input, sizeof(input)));
+ PSA_ASSERT(psa_mac_sign_finish(&operation,
+ sign_mac, sizeof(sign_mac),
+ &sign_mac_length));
+ TEST_EQUAL(psa_mac_sign_finish(&operation,
+ sign_mac, sizeof(sign_mac),
+ &sign_mac_length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Call verify finish twice in a row. */
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation, input, sizeof( input ) ) );
- PSA_ASSERT( psa_mac_verify_finish( &operation,
- verify_mac, sizeof( verify_mac ) ) );
- TEST_EQUAL( psa_mac_verify_finish( &operation,
- verify_mac, sizeof( verify_mac ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation, input, sizeof(input)));
+ PSA_ASSERT(psa_mac_verify_finish(&operation,
+ verify_mac, sizeof(verify_mac)));
+ TEST_EQUAL(psa_mac_verify_finish(&operation,
+ verify_mac, sizeof(verify_mac)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_mac_abort(&operation));
/* Setup sign but try verify. */
- PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation, input, sizeof( input ) ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_mac_verify_finish( &operation,
- verify_mac, sizeof( verify_mac ) ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_mac_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation, input, sizeof(input)));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_mac_verify_finish(&operation,
+ verify_mac, sizeof(verify_mac)),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_mac_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Setup verify but try sign. */
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation, input, sizeof( input ) ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_mac_sign_finish( &operation,
- sign_mac, sizeof( sign_mac ),
- &sign_mac_length ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_mac_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation, input, sizeof(input)));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_mac_sign_finish(&operation,
+ sign_mac, sizeof(sign_mac),
+ &sign_mac_length),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_mac_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
- PSA_ASSERT( psa_destroy_key( key ) );
+ PSA_ASSERT(psa_destroy_key(key));
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_sign_verify_multi( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input,
- int is_verify,
- data_t *expected_mac )
+void mac_sign_verify_multi(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input,
+ int is_verify,
+ data_t *expected_mac)
{
size_t data_part_len = 0;
- for( data_part_len = 1; data_part_len <= input->len; data_part_len++ )
- {
+ for (data_part_len = 1; data_part_len <= input->len; data_part_len++) {
/* Split data into length(data_part_len) parts. */
- mbedtls_test_set_step( 2000 + data_part_len );
+ mbedtls_test_set_step(2000 + data_part_len);
- if( mac_multipart_internal_func( key_type_arg, key_data,
- alg_arg,
- input, data_part_len,
- expected_mac,
- is_verify, 0 ) == 0 )
+ if (mac_multipart_internal_func(key_type_arg, key_data,
+ alg_arg,
+ input, data_part_len,
+ expected_mac,
+ is_verify, 0) == 0) {
break;
+ }
/* length(0) part, length(data_part_len) part, length(0) part... */
- mbedtls_test_set_step( 3000 + data_part_len );
+ mbedtls_test_set_step(3000 + data_part_len);
- if( mac_multipart_internal_func( key_type_arg, key_data,
- alg_arg,
- input, data_part_len,
- expected_mac,
- is_verify, 1 ) == 0 )
+ if (mac_multipart_internal_func(key_type_arg, key_data,
+ alg_arg,
+ input, data_part_len,
+ expected_mac,
+ is_verify, 1) == 0) {
break;
+ }
}
/* Goto is required to silence warnings about unused labels, as we
@@ -3383,11 +3278,11 @@
/* END_CASE */
/* BEGIN_CASE */
-void mac_sign( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input,
- data_t *expected_mac )
+void mac_sign(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input,
+ data_t *expected_mac)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -3396,7 +3291,7 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *actual_mac = NULL;
size_t mac_buffer_size =
- PSA_MAC_LENGTH( key_type, PSA_BYTES_TO_BITS( key_data->len ), alg );
+ PSA_MAC_LENGTH(key_type, PSA_BYTES_TO_BITS(key_data->len), alg);
size_t mac_length = 0;
const size_t output_sizes_to_test[] = {
0,
@@ -3406,76 +3301,74 @@
expected_mac->len + 1,
};
- TEST_LE_U( mac_buffer_size, PSA_MAC_MAX_SIZE );
+ TEST_LE_U(mac_buffer_size, PSA_MAC_MAX_SIZE);
/* We expect PSA_MAC_LENGTH to be exact. */
- TEST_ASSERT( expected_mac->len == mac_buffer_size );
+ TEST_ASSERT(expected_mac->len == mac_buffer_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- for( size_t i = 0; i < ARRAY_LENGTH( output_sizes_to_test ); i++ )
- {
+ for (size_t i = 0; i < ARRAY_LENGTH(output_sizes_to_test); i++) {
const size_t output_size = output_sizes_to_test[i];
psa_status_t expected_status =
- ( output_size >= expected_mac->len ? PSA_SUCCESS :
- PSA_ERROR_BUFFER_TOO_SMALL );
+ (output_size >= expected_mac->len ? PSA_SUCCESS :
+ PSA_ERROR_BUFFER_TOO_SMALL);
- mbedtls_test_set_step( output_size );
- ASSERT_ALLOC( actual_mac, output_size );
+ mbedtls_test_set_step(output_size);
+ ASSERT_ALLOC(actual_mac, output_size);
/* Calculate the MAC, one-shot case. */
- TEST_EQUAL( psa_mac_compute( key, alg,
- input->x, input->len,
- actual_mac, output_size, &mac_length ),
- expected_status );
- if( expected_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( expected_mac->x, expected_mac->len,
- actual_mac, mac_length );
+ TEST_EQUAL(psa_mac_compute(key, alg,
+ input->x, input->len,
+ actual_mac, output_size, &mac_length),
+ expected_status);
+ if (expected_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_mac->x, expected_mac->len,
+ actual_mac, mac_length);
}
- if( output_size > 0 )
- memset( actual_mac, 0, output_size );
+ if (output_size > 0) {
+ memset(actual_mac, 0, output_size);
+ }
/* Calculate the MAC, multi-part case. */
- PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation,
- input->x, input->len ) );
- TEST_EQUAL( psa_mac_sign_finish( &operation,
- actual_mac, output_size,
- &mac_length ),
- expected_status );
- PSA_ASSERT( psa_mac_abort( &operation ) );
+ PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation,
+ input->x, input->len));
+ TEST_EQUAL(psa_mac_sign_finish(&operation,
+ actual_mac, output_size,
+ &mac_length),
+ expected_status);
+ PSA_ASSERT(psa_mac_abort(&operation));
- if( expected_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( expected_mac->x, expected_mac->len,
- actual_mac, mac_length );
+ if (expected_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_mac->x, expected_mac->len,
+ actual_mac, mac_length);
}
- mbedtls_free( actual_mac );
+ mbedtls_free(actual_mac);
actual_mac = NULL;
}
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( actual_mac );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(actual_mac);
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_verify( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input,
- data_t *expected_mac )
+void mac_verify(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input,
+ data_t *expected_mac)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -3484,93 +3377,92 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *perturbed_mac = NULL;
- TEST_LE_U( expected_mac->len, PSA_MAC_MAX_SIZE );
+ TEST_LE_U(expected_mac->len, PSA_MAC_MAX_SIZE);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Verify correct MAC, one-shot case. */
- PSA_ASSERT( psa_mac_verify( key, alg, input->x, input->len,
- expected_mac->x, expected_mac->len ) );
+ PSA_ASSERT(psa_mac_verify(key, alg, input->x, input->len,
+ expected_mac->x, expected_mac->len));
/* Verify correct MAC, multi-part case. */
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation,
- input->x, input->len ) );
- PSA_ASSERT( psa_mac_verify_finish( &operation,
- expected_mac->x,
- expected_mac->len ) );
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation,
+ input->x, input->len));
+ PSA_ASSERT(psa_mac_verify_finish(&operation,
+ expected_mac->x,
+ expected_mac->len));
/* Test a MAC that's too short, one-shot case. */
- TEST_EQUAL( psa_mac_verify( key, alg,
- input->x, input->len,
- expected_mac->x,
- expected_mac->len - 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ TEST_EQUAL(psa_mac_verify(key, alg,
+ input->x, input->len,
+ expected_mac->x,
+ expected_mac->len - 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Test a MAC that's too short, multi-part case. */
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation,
- input->x, input->len ) );
- TEST_EQUAL( psa_mac_verify_finish( &operation,
- expected_mac->x,
- expected_mac->len - 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation,
+ input->x, input->len));
+ TEST_EQUAL(psa_mac_verify_finish(&operation,
+ expected_mac->x,
+ expected_mac->len - 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Test a MAC that's too long, one-shot case. */
- ASSERT_ALLOC( perturbed_mac, expected_mac->len + 1 );
- memcpy( perturbed_mac, expected_mac->x, expected_mac->len );
- TEST_EQUAL( psa_mac_verify( key, alg,
- input->x, input->len,
- perturbed_mac, expected_mac->len + 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ ASSERT_ALLOC(perturbed_mac, expected_mac->len + 1);
+ memcpy(perturbed_mac, expected_mac->x, expected_mac->len);
+ TEST_EQUAL(psa_mac_verify(key, alg,
+ input->x, input->len,
+ perturbed_mac, expected_mac->len + 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Test a MAC that's too long, multi-part case. */
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation,
- input->x, input->len ) );
- TEST_EQUAL( psa_mac_verify_finish( &operation,
- perturbed_mac,
- expected_mac->len + 1 ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation,
+ input->x, input->len));
+ TEST_EQUAL(psa_mac_verify_finish(&operation,
+ perturbed_mac,
+ expected_mac->len + 1),
+ PSA_ERROR_INVALID_SIGNATURE);
/* Test changing one byte. */
- for( size_t i = 0; i < expected_mac->len; i++ )
- {
- mbedtls_test_set_step( i );
+ for (size_t i = 0; i < expected_mac->len; i++) {
+ mbedtls_test_set_step(i);
perturbed_mac[i] ^= 1;
- TEST_EQUAL( psa_mac_verify( key, alg,
- input->x, input->len,
- perturbed_mac, expected_mac->len ),
- PSA_ERROR_INVALID_SIGNATURE );
+ TEST_EQUAL(psa_mac_verify(key, alg,
+ input->x, input->len,
+ perturbed_mac, expected_mac->len),
+ PSA_ERROR_INVALID_SIGNATURE);
- PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_mac_update( &operation,
- input->x, input->len ) );
- TEST_EQUAL( psa_mac_verify_finish( &operation,
- perturbed_mac,
- expected_mac->len ),
- PSA_ERROR_INVALID_SIGNATURE );
+ PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
+ PSA_ASSERT(psa_mac_update(&operation,
+ input->x, input->len));
+ TEST_EQUAL(psa_mac_verify_finish(&operation,
+ perturbed_mac,
+ expected_mac->len),
+ PSA_ERROR_INVALID_SIGNATURE);
perturbed_mac[i] ^= 1;
}
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( perturbed_mac );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(perturbed_mac);
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_operation_init( )
+void cipher_operation_init()
{
const uint8_t input[1] = { 0 };
unsigned char output[1] = { 0 };
@@ -3579,41 +3471,41 @@
* Clang 5 complains when `-Wmissing-field-initializers` is used, even
* though it's OK by the C standard. We could test for this, but we'd need
* to suppress the Clang warning for the test. */
- psa_cipher_operation_t func = psa_cipher_operation_init( );
+ psa_cipher_operation_t func = psa_cipher_operation_init();
psa_cipher_operation_t init = PSA_CIPHER_OPERATION_INIT;
psa_cipher_operation_t zero;
- memset( &zero, 0, sizeof( zero ) );
+ memset(&zero, 0, sizeof(zero));
/* A freshly-initialized cipher operation should not be usable. */
- TEST_EQUAL( psa_cipher_update( &func,
- input, sizeof( input ),
- output, sizeof( output ),
- &output_length ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_cipher_update( &init,
- input, sizeof( input ),
- output, sizeof( output ),
- &output_length ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_cipher_update( &zero,
- input, sizeof( input ),
- output, sizeof( output ),
- &output_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_cipher_update(&func,
+ input, sizeof(input),
+ output, sizeof(output),
+ &output_length),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_cipher_update(&init,
+ input, sizeof(input),
+ output, sizeof(output),
+ &output_length),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_cipher_update(&zero,
+ input, sizeof(input),
+ output, sizeof(output),
+ &output_length),
+ PSA_ERROR_BAD_STATE);
/* A default cipher operation should be abortable without error. */
- PSA_ASSERT( psa_cipher_abort( &func ) );
- PSA_ASSERT( psa_cipher_abort( &init ) );
- PSA_ASSERT( psa_cipher_abort( &zero ) );
+ PSA_ASSERT(psa_cipher_abort(&func));
+ PSA_ASSERT(psa_cipher_abort(&init));
+ PSA_ASSERT(psa_cipher_abort(&zero));
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_setup( int key_type_arg,
- data_t *key,
- int alg_arg,
- int expected_status_arg )
+void cipher_setup(int key_type_arg,
+ data_t *key,
+ int alg_arg,
+ int expected_status_arg)
{
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
@@ -3624,32 +3516,34 @@
const uint8_t smoke_test_key_data[16] = "kkkkkkkkkkkkkkkk";
#endif
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- if( ! exercise_cipher_setup( key_type, key->x, key->len, alg,
- &operation, &status ) )
+ if (!exercise_cipher_setup(key_type, key->x, key->len, alg,
+ &operation, &status)) {
goto exit;
- TEST_EQUAL( status, expected_status );
+ }
+ TEST_EQUAL(status, expected_status);
/* The operation object should be reusable. */
#if defined(KNOWN_SUPPORTED_CIPHER_ALG)
- if( ! exercise_cipher_setup( KNOWN_SUPPORTED_CIPHER_KEY_TYPE,
- smoke_test_key_data,
- sizeof( smoke_test_key_data ),
- KNOWN_SUPPORTED_CIPHER_ALG,
- &operation, &status ) )
+ if (!exercise_cipher_setup(KNOWN_SUPPORTED_CIPHER_KEY_TYPE,
+ smoke_test_key_data,
+ sizeof(smoke_test_key_data),
+ KNOWN_SUPPORTED_CIPHER_ALG,
+ &operation, &status)) {
goto exit;
- TEST_EQUAL( status, PSA_SUCCESS );
+ }
+ TEST_EQUAL(status, PSA_SUCCESS);
#endif
exit:
- psa_cipher_abort( &operation );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_CBC_PKCS7 */
-void cipher_bad_order( )
+void cipher_bad_order()
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = PSA_KEY_TYPE_AES;
@@ -3659,180 +3553,182 @@
unsigned char iv[PSA_BLOCK_CIPHER_BLOCK_LENGTH(PSA_KEY_TYPE_AES)] = { 0 };
const uint8_t key_data[] = {
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa };
+ 0xaa, 0xaa, 0xaa, 0xaa
+ };
const uint8_t text[] = {
0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb,
- 0xbb, 0xbb, 0xbb, 0xbb };
+ 0xbb, 0xbb, 0xbb, 0xbb
+ };
uint8_t buffer[PSA_BLOCK_CIPHER_BLOCK_LENGTH(PSA_KEY_TYPE_AES)] = { 0 };
size_t length = 0;
- PSA_ASSERT( psa_crypto_init( ) );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
- PSA_ASSERT( psa_import_key( &attributes, key_data, sizeof( key_data ),
- &key ) );
+ PSA_ASSERT(psa_crypto_init());
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+ PSA_ASSERT(psa_import_key(&attributes, key_data, sizeof(key_data),
+ &key));
/* Call encrypt setup twice in a row. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_cipher_encrypt_setup( &operation, key, alg ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_cipher_encrypt_setup(&operation, key, alg),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Call decrypt setup twice in a row. */
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_cipher_decrypt_setup( &operation, key, alg ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_cipher_decrypt_setup(&operation, key, alg),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Generate an IV without calling setup beforehand. */
- TEST_EQUAL( psa_cipher_generate_iv( &operation,
- buffer, sizeof( buffer ),
- &length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ TEST_EQUAL(psa_cipher_generate_iv(&operation,
+ buffer, sizeof(buffer),
+ &length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
/* Generate an IV twice in a row. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_cipher_generate_iv( &operation,
- buffer, sizeof( buffer ),
- &length ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_cipher_generate_iv( &operation,
- buffer, sizeof( buffer ),
- &length ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ PSA_ASSERT(psa_cipher_generate_iv(&operation,
+ buffer, sizeof(buffer),
+ &length));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_cipher_generate_iv(&operation,
+ buffer, sizeof(buffer),
+ &length),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Generate an IV after it's already set. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_cipher_set_iv( &operation,
- iv, sizeof( iv ) ) );
- TEST_EQUAL( psa_cipher_generate_iv( &operation,
- buffer, sizeof( buffer ),
- &length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ PSA_ASSERT(psa_cipher_set_iv(&operation,
+ iv, sizeof(iv)));
+ TEST_EQUAL(psa_cipher_generate_iv(&operation,
+ buffer, sizeof(buffer),
+ &length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
/* Set an IV without calling setup beforehand. */
- TEST_EQUAL( psa_cipher_set_iv( &operation,
- iv, sizeof( iv ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ TEST_EQUAL(psa_cipher_set_iv(&operation,
+ iv, sizeof(iv)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
/* Set an IV after it's already set. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_cipher_set_iv( &operation,
- iv, sizeof( iv ) ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_cipher_set_iv( &operation,
- iv, sizeof( iv ) ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ PSA_ASSERT(psa_cipher_set_iv(&operation,
+ iv, sizeof(iv)));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_cipher_set_iv(&operation,
+ iv, sizeof(iv)),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Set an IV after it's already generated. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_cipher_generate_iv( &operation,
- buffer, sizeof( buffer ),
- &length ) );
- TEST_EQUAL( psa_cipher_set_iv( &operation,
- iv, sizeof( iv ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ PSA_ASSERT(psa_cipher_generate_iv(&operation,
+ buffer, sizeof(buffer),
+ &length));
+ TEST_EQUAL(psa_cipher_set_iv(&operation,
+ iv, sizeof(iv)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
/* Call update without calling setup beforehand. */
- TEST_EQUAL( psa_cipher_update( &operation,
- text, sizeof( text ),
- buffer, sizeof( buffer ),
- &length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ TEST_EQUAL(psa_cipher_update(&operation,
+ text, sizeof(text),
+ buffer, sizeof(buffer),
+ &length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
/* Call update without an IV where an IV is required. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_cipher_update( &operation,
- text, sizeof( text ),
- buffer, sizeof( buffer ),
- &length ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_cipher_update(&operation,
+ text, sizeof(text),
+ buffer, sizeof(buffer),
+ &length),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Call update after finish. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_cipher_set_iv( &operation,
- iv, sizeof( iv ) ) );
- PSA_ASSERT( psa_cipher_finish( &operation,
- buffer, sizeof( buffer ), &length ) );
- TEST_EQUAL( psa_cipher_update( &operation,
- text, sizeof( text ),
- buffer, sizeof( buffer ),
- &length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ PSA_ASSERT(psa_cipher_set_iv(&operation,
+ iv, sizeof(iv)));
+ PSA_ASSERT(psa_cipher_finish(&operation,
+ buffer, sizeof(buffer), &length));
+ TEST_EQUAL(psa_cipher_update(&operation,
+ text, sizeof(text),
+ buffer, sizeof(buffer),
+ &length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
/* Call finish without calling setup beforehand. */
- TEST_EQUAL( psa_cipher_finish( &operation,
- buffer, sizeof( buffer ), &length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ TEST_EQUAL(psa_cipher_finish(&operation,
+ buffer, sizeof(buffer), &length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
/* Call finish without an IV where an IV is required. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
/* Not calling update means we are encrypting an empty buffer, which is OK
* for cipher modes with padding. */
- ASSERT_OPERATION_IS_ACTIVE( operation );
- TEST_EQUAL( psa_cipher_finish( &operation,
- buffer, sizeof( buffer ), &length ),
- PSA_ERROR_BAD_STATE );
- ASSERT_OPERATION_IS_INACTIVE( operation );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- ASSERT_OPERATION_IS_INACTIVE( operation );
+ ASSERT_OPERATION_IS_ACTIVE(operation);
+ TEST_EQUAL(psa_cipher_finish(&operation,
+ buffer, sizeof(buffer), &length),
+ PSA_ERROR_BAD_STATE);
+ ASSERT_OPERATION_IS_INACTIVE(operation);
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ ASSERT_OPERATION_IS_INACTIVE(operation);
/* Call finish twice in a row. */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_cipher_set_iv( &operation,
- iv, sizeof( iv ) ) );
- PSA_ASSERT( psa_cipher_finish( &operation,
- buffer, sizeof( buffer ), &length ) );
- TEST_EQUAL( psa_cipher_finish( &operation,
- buffer, sizeof( buffer ), &length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ PSA_ASSERT(psa_cipher_set_iv(&operation,
+ iv, sizeof(iv)));
+ PSA_ASSERT(psa_cipher_finish(&operation,
+ buffer, sizeof(buffer), &length));
+ TEST_EQUAL(psa_cipher_finish(&operation,
+ buffer, sizeof(buffer), &length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_abort(&operation));
- PSA_ASSERT( psa_destroy_key( key ) );
+ PSA_ASSERT(psa_destroy_key(key));
exit:
- psa_cipher_abort( &operation );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_encrypt_fail( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *input,
- int expected_status_arg )
+void cipher_encrypt_fail(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *input,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_status_t expected_status = expected_status_arg;
- unsigned char iv[PSA_CIPHER_IV_MAX_SIZE] = {0};
+ unsigned char iv[PSA_CIPHER_IV_MAX_SIZE] = { 0 };
size_t iv_size = PSA_CIPHER_IV_MAX_SIZE;
size_t iv_length = 0;
unsigned char *output = NULL;
@@ -3842,74 +3738,66 @@
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- if ( PSA_ERROR_BAD_STATE != expected_status )
- {
- PSA_ASSERT( psa_crypto_init( ) );
+ if (PSA_ERROR_BAD_STATE != expected_status) {
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg,
- input->len );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg,
+ input->len);
+ ASSERT_ALLOC(output, output_buffer_size);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
}
/* Encrypt, one-shot */
- status = psa_cipher_encrypt( key, alg, input->x, input->len, output,
- output_buffer_size, &output_length );
+ status = psa_cipher_encrypt(key, alg, input->x, input->len, output,
+ output_buffer_size, &output_length);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
/* Encrypt, multi-part */
- status = psa_cipher_encrypt_setup( &operation, key, alg );
- if( status == PSA_SUCCESS )
- {
- if( alg != PSA_ALG_ECB_NO_PADDING )
- {
- PSA_ASSERT( psa_cipher_generate_iv( &operation,
- iv, iv_size,
- &iv_length ) );
+ status = psa_cipher_encrypt_setup(&operation, key, alg);
+ if (status == PSA_SUCCESS) {
+ if (alg != PSA_ALG_ECB_NO_PADDING) {
+ PSA_ASSERT(psa_cipher_generate_iv(&operation,
+ iv, iv_size,
+ &iv_length));
}
- status = psa_cipher_update( &operation, input->x, input->len,
- output, output_buffer_size,
- &function_output_length );
- if( status == PSA_SUCCESS )
- {
+ status = psa_cipher_update(&operation, input->x, input->len,
+ output, output_buffer_size,
+ &function_output_length);
+ if (status == PSA_SUCCESS) {
output_length += function_output_length;
- status = psa_cipher_finish( &operation, output + output_length,
- output_buffer_size - output_length,
- &function_output_length );
+ status = psa_cipher_finish(&operation, output + output_length,
+ output_buffer_size - output_length,
+ &function_output_length);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
+ } else {
+ TEST_EQUAL(status, expected_status);
}
- else
- {
- TEST_EQUAL( status, expected_status );
- }
- }
- else
- {
- TEST_EQUAL( status, expected_status );
+ } else {
+ TEST_EQUAL(status, expected_status);
}
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_encrypt_validate_iv_length( int alg, int key_type, data_t* key_data,
- data_t *input, int iv_length,
- int expected_result )
+void cipher_encrypt_validate_iv_length(int alg, int key_type, data_t *key_data,
+ data_t *input, int iv_length,
+ int expected_result)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
@@ -3917,32 +3805,32 @@
size_t output_buffer_size = 0;
unsigned char *output = NULL;
- output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
+ ASSERT_ALLOC(output, output_buffer_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( expected_result, psa_cipher_set_iv( &operation, output,
- iv_length ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ TEST_EQUAL(expected_result, psa_cipher_set_iv(&operation, output,
+ iv_length));
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_alg_without_iv( int alg_arg, int key_type_arg, data_t *key_data,
- data_t *plaintext, data_t *ciphertext )
+void cipher_alg_without_iv(int alg_arg, int key_type_arg, data_t *key_data,
+ data_t *plaintext, data_t *ciphertext)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -3954,111 +3842,111 @@
size_t output_length, length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Validate size macros */
- TEST_LE_U( ciphertext->len,
- PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ) );
- TEST_LE_U( PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, plaintext->len ),
- PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( plaintext->len ) );
- TEST_LE_U( plaintext->len,
- PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ) );
- TEST_LE_U( PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, ciphertext->len ),
- PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( ciphertext->len ) );
+ TEST_LE_U(ciphertext->len,
+ PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext->len));
+ TEST_LE_U(PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext->len),
+ PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(plaintext->len));
+ TEST_LE_U(plaintext->len,
+ PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext->len));
+ TEST_LE_U(PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext->len),
+ PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(ciphertext->len));
/* Set up key and output buffer */
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg,
- plaintext->len );
- ASSERT_ALLOC( output, output_buffer_size );
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg,
+ plaintext->len);
+ ASSERT_ALLOC(output, output_buffer_size);
/* set_iv() is not allowed */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( psa_cipher_set_iv( &operation, iv, sizeof( iv ) ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( psa_cipher_set_iv( &operation, iv, sizeof( iv ) ),
- PSA_ERROR_BAD_STATE );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ TEST_EQUAL(psa_cipher_set_iv(&operation, iv, sizeof(iv)),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
+ TEST_EQUAL(psa_cipher_set_iv(&operation, iv, sizeof(iv)),
+ PSA_ERROR_BAD_STATE);
/* generate_iv() is not allowed */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( psa_cipher_generate_iv( &operation, iv, sizeof( iv ),
- &length ),
- PSA_ERROR_BAD_STATE );
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( psa_cipher_generate_iv( &operation, iv, sizeof( iv ),
- &length ),
- PSA_ERROR_BAD_STATE );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ TEST_EQUAL(psa_cipher_generate_iv(&operation, iv, sizeof(iv),
+ &length),
+ PSA_ERROR_BAD_STATE);
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
+ TEST_EQUAL(psa_cipher_generate_iv(&operation, iv, sizeof(iv),
+ &length),
+ PSA_ERROR_BAD_STATE);
/* Multipart encryption */
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
output_length = 0;
length = ~0;
- PSA_ASSERT( psa_cipher_update( &operation,
- plaintext->x, plaintext->len,
- output, output_buffer_size,
- &length ) );
- TEST_LE_U( length, output_buffer_size );
+ PSA_ASSERT(psa_cipher_update(&operation,
+ plaintext->x, plaintext->len,
+ output, output_buffer_size,
+ &length));
+ TEST_LE_U(length, output_buffer_size);
output_length += length;
- PSA_ASSERT( psa_cipher_finish( &operation,
- mbedtls_buffer_offset( output, output_length ),
- output_buffer_size - output_length,
- &length ) );
+ PSA_ASSERT(psa_cipher_finish(&operation,
+ mbedtls_buffer_offset(output, output_length),
+ output_buffer_size - output_length,
+ &length));
output_length += length;
- ASSERT_COMPARE( ciphertext->x, ciphertext->len,
- output, output_length );
+ ASSERT_COMPARE(ciphertext->x, ciphertext->len,
+ output, output_length);
/* Multipart encryption */
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
output_length = 0;
length = ~0;
- PSA_ASSERT( psa_cipher_update( &operation,
- ciphertext->x, ciphertext->len,
- output, output_buffer_size,
- &length ) );
- TEST_LE_U( length, output_buffer_size );
+ PSA_ASSERT(psa_cipher_update(&operation,
+ ciphertext->x, ciphertext->len,
+ output, output_buffer_size,
+ &length));
+ TEST_LE_U(length, output_buffer_size);
output_length += length;
- PSA_ASSERT( psa_cipher_finish( &operation,
- mbedtls_buffer_offset( output, output_length ),
- output_buffer_size - output_length,
- &length ) );
+ PSA_ASSERT(psa_cipher_finish(&operation,
+ mbedtls_buffer_offset(output, output_length),
+ output_buffer_size - output_length,
+ &length));
output_length += length;
- ASSERT_COMPARE( plaintext->x, plaintext->len,
- output, output_length );
+ ASSERT_COMPARE(plaintext->x, plaintext->len,
+ output, output_length);
/* One-shot encryption */
output_length = ~0;
- PSA_ASSERT( psa_cipher_encrypt( key, alg, plaintext->x, plaintext->len,
- output, output_buffer_size,
- &output_length ) );
- ASSERT_COMPARE( ciphertext->x, ciphertext->len,
- output, output_length );
+ PSA_ASSERT(psa_cipher_encrypt(key, alg, plaintext->x, plaintext->len,
+ output, output_buffer_size,
+ &output_length));
+ ASSERT_COMPARE(ciphertext->x, ciphertext->len,
+ output, output_length);
/* One-shot decryption */
output_length = ~0;
- PSA_ASSERT( psa_cipher_decrypt( key, alg, ciphertext->x, ciphertext->len,
- output, output_buffer_size,
- &output_length ) );
- ASSERT_COMPARE( plaintext->x, plaintext->len,
- output, output_length );
+ PSA_ASSERT(psa_cipher_decrypt(key, alg, ciphertext->x, ciphertext->len,
+ output, output_buffer_size,
+ &output_length));
+ ASSERT_COMPARE(plaintext->x, plaintext->len,
+ output, output_length);
exit:
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- mbedtls_free( output );
- psa_cipher_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ mbedtls_free(output);
+ psa_cipher_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_bad_key( int alg_arg, int key_type_arg, data_t *key_data )
+void cipher_bad_key(int alg_arg, int key_type_arg, data_t *key_data)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_algorithm_t alg = alg_arg;
@@ -4067,46 +3955,46 @@
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_status_t status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
/* Usage of either of these two size macros would cause divide by zero
* with incorrect key types previously. Input length should be irrelevant
* here. */
- TEST_EQUAL( PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, 16 ),
- 0 );
- TEST_EQUAL( PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, 16 ), 0 );
+ TEST_EQUAL(PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, 16),
+ 0);
+ TEST_EQUAL(PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, 16), 0);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Should fail due to invalid alg type (to support invalid key type).
* Encrypt or decrypt will end up in the same place. */
- status = psa_cipher_encrypt_setup( &operation, key, alg );
+ status = psa_cipher_encrypt_setup(&operation, key, alg);
- TEST_EQUAL( status, PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(status, PSA_ERROR_INVALID_ARGUMENT);
exit:
- psa_cipher_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_encrypt_validation( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *input )
+void cipher_encrypt_validation(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *input)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
- size_t iv_size = PSA_CIPHER_IV_LENGTH ( key_type, alg );
+ size_t iv_size = PSA_CIPHER_IV_LENGTH(key_type, alg);
unsigned char *output1 = NULL;
size_t output1_buffer_size = 0;
size_t output1_length = 0;
@@ -4117,74 +4005,74 @@
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
- output2_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, input->len ) +
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
- ASSERT_ALLOC( output1, output1_buffer_size );
- ASSERT_ALLOC( output2, output2_buffer_size );
+ output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
+ output2_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
+ ASSERT_ALLOC(output1, output1_buffer_size);
+ ASSERT_ALLOC(output2, output2_buffer_size);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* The one-shot cipher encryption uses generated iv so validating
the output is not possible. Validating with multipart encryption. */
- PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len, output1,
- output1_buffer_size, &output1_length ) );
- TEST_LE_U( output1_length,
- PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
- TEST_LE_U( output1_length,
- PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
+ PSA_ASSERT(psa_cipher_encrypt(key, alg, input->x, input->len, output1,
+ output1_buffer_size, &output1_length));
+ TEST_LE_U(output1_length,
+ PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len));
+ TEST_LE_U(output1_length,
+ PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input->len));
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- PSA_ASSERT( psa_cipher_set_iv( &operation, output1, iv_size ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ PSA_ASSERT(psa_cipher_set_iv(&operation, output1, iv_size));
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x, input->len,
- output2, output2_buffer_size,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, input->len ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x, input->len,
+ output2, output2_buffer_size,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input->len));
output2_length += function_output_length;
- PSA_ASSERT( psa_cipher_finish( &operation,
- output2 + output2_length,
- output2_buffer_size - output2_length,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
+ PSA_ASSERT(psa_cipher_finish(&operation,
+ output2 + output2_length,
+ output2_buffer_size - output2_length,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE);
output2_length += function_output_length;
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- ASSERT_COMPARE( output1 + iv_size, output1_length - iv_size,
- output2, output2_length );
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ ASSERT_COMPARE(output1 + iv_size, output1_length - iv_size,
+ output2, output2_length);
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output1 );
- mbedtls_free( output2 );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output1);
+ mbedtls_free(output2);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
- data_t *key_data, data_t *iv,
- data_t *input,
- int first_part_size_arg,
- int output1_length_arg, int output2_length_arg,
- data_t *expected_output,
- int expected_status_arg )
+void cipher_encrypt_multipart(int alg_arg, int key_type_arg,
+ data_t *key_data, data_t *iv,
+ data_t *input,
+ int first_part_size_arg,
+ int output1_length_arg, int output2_length_arg,
+ data_t *expected_output,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -4201,92 +4089,89 @@
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
- if( iv->len > 0 )
- {
- PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
+ if (iv->len > 0) {
+ PSA_ASSERT(psa_cipher_set_iv(&operation, iv->x, iv->len));
}
- output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, input->len ) +
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
+ ASSERT_ALLOC(output, output_buffer_size);
- TEST_LE_U( first_part_size, input->len );
- PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size,
- output, output_buffer_size,
- &function_output_length ) );
- TEST_ASSERT( function_output_length == output1_length );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size) );
+ TEST_LE_U(first_part_size, input->len);
+ PSA_ASSERT(psa_cipher_update(&operation, input->x, first_part_size,
+ output, output_buffer_size,
+ &function_output_length));
+ TEST_ASSERT(function_output_length == output1_length);
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(first_part_size));
total_output_length += function_output_length;
- if( first_part_size < input->len )
- {
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x + first_part_size,
- input->len - first_part_size,
- ( output_buffer_size == 0 ? NULL :
- output + total_output_length ),
- output_buffer_size - total_output_length,
- &function_output_length ) );
- TEST_ASSERT( function_output_length == output2_length );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
- alg,
- input->len - first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
+ if (first_part_size < input->len) {
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x + first_part_size,
+ input->len - first_part_size,
+ (output_buffer_size == 0 ? NULL :
+ output + total_output_length),
+ output_buffer_size - total_output_length,
+ &function_output_length));
+ TEST_ASSERT(function_output_length == output2_length);
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type,
+ alg,
+ input->len - first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input->len));
total_output_length += function_output_length;
}
- status = psa_cipher_finish( &operation,
- ( output_buffer_size == 0 ? NULL :
- output + total_output_length ),
- output_buffer_size - total_output_length,
- &function_output_length );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
+ status = psa_cipher_finish(&operation,
+ (output_buffer_size == 0 ? NULL :
+ output + total_output_length),
+ output_buffer_size - total_output_length,
+ &function_output_length);
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE);
total_output_length += function_output_length;
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- if( expected_status == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_cipher_abort(&operation));
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output, total_output_length );
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output, total_output_length);
}
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
- data_t *key_data, data_t *iv,
- data_t *input,
- int first_part_size_arg,
- int output1_length_arg, int output2_length_arg,
- data_t *expected_output,
- int expected_status_arg )
+void cipher_decrypt_multipart(int alg_arg, int key_type_arg,
+ data_t *key_data, data_t *iv,
+ data_t *input,
+ int first_part_size_arg,
+ int output1_length_arg, int output2_length_arg,
+ data_t *expected_output,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -4303,92 +4188,89 @@
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
- if( iv->len > 0 )
- {
- PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
+ if (iv->len > 0) {
+ PSA_ASSERT(psa_cipher_set_iv(&operation, iv->x, iv->len));
}
- output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, input->len ) +
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
+ ASSERT_ALLOC(output, output_buffer_size);
- TEST_LE_U( first_part_size, input->len );
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x, first_part_size,
- output, output_buffer_size,
- &function_output_length ) );
- TEST_ASSERT( function_output_length == output1_length );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
+ TEST_LE_U(first_part_size, input->len);
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x, first_part_size,
+ output, output_buffer_size,
+ &function_output_length));
+ TEST_ASSERT(function_output_length == output1_length);
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(first_part_size));
total_output_length += function_output_length;
- if( first_part_size < input->len )
- {
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x + first_part_size,
- input->len - first_part_size,
- ( output_buffer_size == 0 ? NULL :
- output + total_output_length ),
- output_buffer_size - total_output_length,
- &function_output_length ) );
- TEST_ASSERT( function_output_length == output2_length );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
- alg,
- input->len - first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len ) );
+ if (first_part_size < input->len) {
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x + first_part_size,
+ input->len - first_part_size,
+ (output_buffer_size == 0 ? NULL :
+ output + total_output_length),
+ output_buffer_size - total_output_length,
+ &function_output_length));
+ TEST_ASSERT(function_output_length == output2_length);
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type,
+ alg,
+ input->len - first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input->len));
total_output_length += function_output_length;
}
- status = psa_cipher_finish( &operation,
- ( output_buffer_size == 0 ? NULL :
- output + total_output_length ),
- output_buffer_size - total_output_length,
- &function_output_length );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
+ status = psa_cipher_finish(&operation,
+ (output_buffer_size == 0 ? NULL :
+ output + total_output_length),
+ output_buffer_size - total_output_length,
+ &function_output_length);
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE);
total_output_length += function_output_length;
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- if( expected_status == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_cipher_abort(&operation));
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output, total_output_length );
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output, total_output_length);
}
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_decrypt_fail( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *iv,
- data_t *input_arg,
- int expected_status_arg )
+void cipher_decrypt_fail(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *iv,
+ data_t *input_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_status_t status;
@@ -4405,101 +4287,90 @@
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- if ( PSA_ERROR_BAD_STATE != expected_status )
- {
- PSA_ASSERT( psa_crypto_init( ) );
+ if (PSA_ERROR_BAD_STATE != expected_status) {
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
}
/* Allocate input buffer and copy the iv and the plaintext */
- input_buffer_size = ( (size_t) input_arg->len + (size_t) iv->len );
- if ( input_buffer_size > 0 )
- {
- ASSERT_ALLOC( input, input_buffer_size );
- memcpy( input, iv->x, iv->len );
- memcpy( input + iv->len, input_arg->x, input_arg->len );
+ input_buffer_size = ((size_t) input_arg->len + (size_t) iv->len);
+ if (input_buffer_size > 0) {
+ ASSERT_ALLOC(input, input_buffer_size);
+ memcpy(input, iv->x, iv->len);
+ memcpy(input + iv->len, input_arg->x, input_arg->len);
}
- output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, input_buffer_size );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_buffer_size);
+ ASSERT_ALLOC(output, output_buffer_size);
/* Decrypt, one-short */
- status = psa_cipher_decrypt( key, alg, input, input_buffer_size, output,
- output_buffer_size, &output_length );
- TEST_EQUAL( status, expected_status );
+ status = psa_cipher_decrypt(key, alg, input, input_buffer_size, output,
+ output_buffer_size, &output_length);
+ TEST_EQUAL(status, expected_status);
/* Decrypt, multi-part */
- status = psa_cipher_decrypt_setup( &operation, key, alg );
- if( status == PSA_SUCCESS )
- {
- output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg,
- input_arg->len ) +
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
- ASSERT_ALLOC( output_multi, output_buffer_size );
+ status = psa_cipher_decrypt_setup(&operation, key, alg);
+ if (status == PSA_SUCCESS) {
+ output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg,
+ input_arg->len) +
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
+ ASSERT_ALLOC(output_multi, output_buffer_size);
- if( iv->len > 0 )
- {
- status = psa_cipher_set_iv( &operation, iv->x, iv->len );
+ if (iv->len > 0) {
+ status = psa_cipher_set_iv(&operation, iv->x, iv->len);
- if( status != PSA_SUCCESS )
- TEST_EQUAL( status, expected_status );
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_status);
+ }
}
- if( status == PSA_SUCCESS )
- {
- status = psa_cipher_update( &operation,
- input_arg->x, input_arg->len,
- output_multi, output_buffer_size,
- &function_output_length );
- if( status == PSA_SUCCESS )
- {
+ if (status == PSA_SUCCESS) {
+ status = psa_cipher_update(&operation,
+ input_arg->x, input_arg->len,
+ output_multi, output_buffer_size,
+ &function_output_length);
+ if (status == PSA_SUCCESS) {
output_length = function_output_length;
- status = psa_cipher_finish( &operation,
- output_multi + output_length,
- output_buffer_size - output_length,
- &function_output_length );
+ status = psa_cipher_finish(&operation,
+ output_multi + output_length,
+ output_buffer_size - output_length,
+ &function_output_length);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
+ } else {
+ TEST_EQUAL(status, expected_status);
}
- else
- {
- TEST_EQUAL( status, expected_status );
- }
+ } else {
+ TEST_EQUAL(status, expected_status);
}
- else
- {
- TEST_EQUAL( status, expected_status );
- }
- }
- else
- {
- TEST_EQUAL( status, expected_status );
+ } else {
+ TEST_EQUAL(status, expected_status);
}
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( input );
- mbedtls_free( output );
- mbedtls_free( output_multi );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(input);
+ mbedtls_free(output);
+ mbedtls_free(output_multi);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_decrypt( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *iv,
- data_t *input_arg,
- data_t *expected_output )
+void cipher_decrypt(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *iv,
+ data_t *input_arg,
+ data_t *expected_output)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -4511,49 +4382,48 @@
size_t output_length = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
/* Allocate input buffer and copy the iv and the plaintext */
- input_buffer_size = ( (size_t) input_arg->len + (size_t) iv->len );
- if ( input_buffer_size > 0 )
- {
- ASSERT_ALLOC( input, input_buffer_size );
- memcpy( input, iv->x, iv->len );
- memcpy( input + iv->len, input_arg->x, input_arg->len );
+ input_buffer_size = ((size_t) input_arg->len + (size_t) iv->len);
+ if (input_buffer_size > 0) {
+ ASSERT_ALLOC(input, input_buffer_size);
+ memcpy(input, iv->x, iv->len);
+ memcpy(input + iv->len, input_arg->x, input_arg->len);
}
- output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, input_buffer_size );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_buffer_size);
+ ASSERT_ALLOC(output, output_buffer_size);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_cipher_decrypt( key, alg, input, input_buffer_size, output,
- output_buffer_size, &output_length ) );
- TEST_LE_U( output_length,
- PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, input_buffer_size ) );
- TEST_LE_U( output_length,
- PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( input_buffer_size ) );
+ PSA_ASSERT(psa_cipher_decrypt(key, alg, input, input_buffer_size, output,
+ output_buffer_size, &output_length));
+ TEST_LE_U(output_length,
+ PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_buffer_size));
+ TEST_LE_U(output_length,
+ PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_buffer_size));
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output, output_length );
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output, output_length);
exit:
- mbedtls_free( input );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ mbedtls_free(input);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_verify_output( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *input )
+void cipher_verify_output(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *input)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -4566,58 +4436,58 @@
size_t output2_length = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- output1_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
- ASSERT_ALLOC( output1, output1_size );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ output1_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
+ ASSERT_ALLOC(output1, output1_size);
- PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len,
- output1, output1_size,
- &output1_length ) );
- TEST_LE_U( output1_length,
- PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len ) );
- TEST_LE_U( output1_length,
- PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
+ PSA_ASSERT(psa_cipher_encrypt(key, alg, input->x, input->len,
+ output1, output1_size,
+ &output1_length));
+ TEST_LE_U(output1_length,
+ PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len));
+ TEST_LE_U(output1_length,
+ PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input->len));
output2_size = output1_length;
- ASSERT_ALLOC( output2, output2_size );
+ ASSERT_ALLOC(output2, output2_size);
- PSA_ASSERT( psa_cipher_decrypt( key, alg, output1, output1_length,
- output2, output2_size,
- &output2_length ) );
- TEST_LE_U( output2_length,
- PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, output1_length ) );
- TEST_LE_U( output2_length,
- PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( output1_length ) );
+ PSA_ASSERT(psa_cipher_decrypt(key, alg, output1, output1_length,
+ output2, output2_size,
+ &output2_length));
+ TEST_LE_U(output2_length,
+ PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, output1_length));
+ TEST_LE_U(output2_length,
+ PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(output1_length));
- ASSERT_COMPARE( input->x, input->len, output2, output2_length );
+ ASSERT_COMPARE(input->x, input->len, output2, output2_length);
exit:
- mbedtls_free( output1 );
- mbedtls_free( output2 );
- psa_destroy_key( key );
- PSA_DONE( );
+ mbedtls_free(output1);
+ mbedtls_free(output2);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_verify_output_multipart( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *input,
- int first_part_size_arg )
+void cipher_verify_output_multipart(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *input,
+ int first_part_size_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t first_part_size = first_part_size_arg;
- unsigned char iv[16] = {0};
+ unsigned char iv[16] = { 0 };
size_t iv_size = 16;
size_t iv_length = 0;
unsigned char *output1 = NULL;
@@ -4631,132 +4501,130 @@
psa_cipher_operation_t operation2 = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation1, key, alg ) );
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation2, key, alg ) );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation1, key, alg));
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation2, key, alg));
- if( alg != PSA_ALG_ECB_NO_PADDING )
- {
- PSA_ASSERT( psa_cipher_generate_iv( &operation1,
- iv, iv_size,
- &iv_length ) );
+ if (alg != PSA_ALG_ECB_NO_PADDING) {
+ PSA_ASSERT(psa_cipher_generate_iv(&operation1,
+ iv, iv_size,
+ &iv_length));
}
- output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
- TEST_LE_U( output1_buffer_size,
- PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE( input->len ) );
- ASSERT_ALLOC( output1, output1_buffer_size );
+ output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
+ TEST_LE_U(output1_buffer_size,
+ PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input->len));
+ ASSERT_ALLOC(output1, output1_buffer_size);
- TEST_LE_U( first_part_size, input->len );
+ TEST_LE_U(first_part_size, input->len);
- PSA_ASSERT( psa_cipher_update( &operation1, input->x, first_part_size,
- output1, output1_buffer_size,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
+ PSA_ASSERT(psa_cipher_update(&operation1, input->x, first_part_size,
+ output1, output1_buffer_size,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(first_part_size));
output1_length += function_output_length;
- PSA_ASSERT( psa_cipher_update( &operation1,
- input->x + first_part_size,
- input->len - first_part_size,
- output1, output1_buffer_size,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
- alg,
- input->len - first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( input->len - first_part_size ) );
+ PSA_ASSERT(psa_cipher_update(&operation1,
+ input->x + first_part_size,
+ input->len - first_part_size,
+ output1, output1_buffer_size,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type,
+ alg,
+ input->len - first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input->len - first_part_size));
output1_length += function_output_length;
- PSA_ASSERT( psa_cipher_finish( &operation1,
- output1 + output1_length,
- output1_buffer_size - output1_length,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
+ PSA_ASSERT(psa_cipher_finish(&operation1,
+ output1 + output1_length,
+ output1_buffer_size - output1_length,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE);
output1_length += function_output_length;
- PSA_ASSERT( psa_cipher_abort( &operation1 ) );
+ PSA_ASSERT(psa_cipher_abort(&operation1));
output2_buffer_size = output1_length;
- TEST_LE_U( output2_buffer_size,
- PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, output1_length ) );
- TEST_LE_U( output2_buffer_size,
- PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE( output1_length ) );
- ASSERT_ALLOC( output2, output2_buffer_size );
+ TEST_LE_U(output2_buffer_size,
+ PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, output1_length));
+ TEST_LE_U(output2_buffer_size,
+ PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(output1_length));
+ ASSERT_ALLOC(output2, output2_buffer_size);
- if( iv_length > 0 )
- {
- PSA_ASSERT( psa_cipher_set_iv( &operation2,
- iv, iv_length ) );
+ if (iv_length > 0) {
+ PSA_ASSERT(psa_cipher_set_iv(&operation2,
+ iv, iv_length));
}
- PSA_ASSERT( psa_cipher_update( &operation2, output1, first_part_size,
- output2, output2_buffer_size,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( first_part_size ) );
+ PSA_ASSERT(psa_cipher_update(&operation2, output1, first_part_size,
+ output2, output2_buffer_size,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(first_part_size));
output2_length += function_output_length;
- PSA_ASSERT( psa_cipher_update( &operation2,
- output1 + first_part_size,
- output1_length - first_part_size,
- output2, output2_buffer_size,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type,
- alg,
- output1_length - first_part_size ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE( output1_length - first_part_size ) );
+ PSA_ASSERT(psa_cipher_update(&operation2,
+ output1 + first_part_size,
+ output1_length - first_part_size,
+ output2, output2_buffer_size,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type,
+ alg,
+ output1_length - first_part_size));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(output1_length - first_part_size));
output2_length += function_output_length;
- PSA_ASSERT( psa_cipher_finish( &operation2,
- output2 + output2_length,
- output2_buffer_size - output2_length,
- &function_output_length ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg ) );
- TEST_LE_U( function_output_length,
- PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE );
+ PSA_ASSERT(psa_cipher_finish(&operation2,
+ output2 + output2_length,
+ output2_buffer_size - output2_length,
+ &function_output_length));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg));
+ TEST_LE_U(function_output_length,
+ PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE);
output2_length += function_output_length;
- PSA_ASSERT( psa_cipher_abort( &operation2 ) );
+ PSA_ASSERT(psa_cipher_abort(&operation2));
- ASSERT_COMPARE( input->x, input->len, output2, output2_length );
+ ASSERT_COMPARE(input->x, input->len, output2, output2_length);
exit:
- psa_cipher_abort( &operation1 );
- psa_cipher_abort( &operation2 );
- mbedtls_free( output1 );
- mbedtls_free( output2 );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation1);
+ psa_cipher_abort(&operation2);
+ mbedtls_free(output1);
+ mbedtls_free(output2);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_encrypt_decrypt( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- int expected_result_arg )
+void aead_encrypt_decrypt(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ int expected_result_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -4771,90 +4639,87 @@
psa_status_t expected_result = expected_result_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = input_data->len + PSA_AEAD_TAG_LENGTH( key_type, key_bits,
- alg );
+ output_size = input_data->len + PSA_AEAD_TAG_LENGTH(key_type, key_bits,
+ alg);
/* For all currently defined algorithms, PSA_AEAD_ENCRYPT_OUTPUT_SIZE
* should be exact. */
- if( expected_result != PSA_ERROR_INVALID_ARGUMENT &&
- expected_result != PSA_ERROR_NOT_SUPPORTED )
- {
- TEST_EQUAL( output_size,
- PSA_AEAD_ENCRYPT_OUTPUT_SIZE( key_type, alg, input_data->len ) );
- TEST_LE_U( output_size,
- PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
+ if (expected_result != PSA_ERROR_INVALID_ARGUMENT &&
+ expected_result != PSA_ERROR_NOT_SUPPORTED) {
+ TEST_EQUAL(output_size,
+ PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
+ TEST_LE_U(output_size,
+ PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
}
- ASSERT_ALLOC( output_data, output_size );
+ ASSERT_ALLOC(output_data, output_size);
- status = psa_aead_encrypt( key, alg,
- nonce->x, nonce->len,
- additional_data->x,
- additional_data->len,
- input_data->x, input_data->len,
- output_data, output_size,
- &output_length );
+ status = psa_aead_encrypt(key, alg,
+ nonce->x, nonce->len,
+ additional_data->x,
+ additional_data->len,
+ input_data->x, input_data->len,
+ output_data, output_size,
+ &output_length);
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce->len);
}
- TEST_EQUAL( status, expected_result );
+ TEST_EQUAL(status, expected_result);
- if( PSA_SUCCESS == expected_result )
- {
- ASSERT_ALLOC( output_data2, output_length );
+ if (PSA_SUCCESS == expected_result) {
+ ASSERT_ALLOC(output_data2, output_length);
/* For all currently defined algorithms, PSA_AEAD_DECRYPT_OUTPUT_SIZE
* should be exact. */
- TEST_EQUAL( input_data->len,
- PSA_AEAD_DECRYPT_OUTPUT_SIZE( key_type, alg, output_length ) );
+ TEST_EQUAL(input_data->len,
+ PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, output_length));
- TEST_LE_U( input_data->len,
- PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE( output_length ) );
+ TEST_LE_U(input_data->len,
+ PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(output_length));
- TEST_EQUAL( psa_aead_decrypt( key, alg,
- nonce->x, nonce->len,
- additional_data->x,
- additional_data->len,
- output_data, output_length,
- output_data2, output_length,
- &output_length2 ),
- expected_result );
+ TEST_EQUAL(psa_aead_decrypt(key, alg,
+ nonce->x, nonce->len,
+ additional_data->x,
+ additional_data->len,
+ output_data, output_length,
+ output_data2, output_length,
+ &output_length2),
+ expected_result);
- ASSERT_COMPARE( input_data->x, input_data->len,
- output_data2, output_length2 );
+ ASSERT_COMPARE(input_data->x, input_data->len,
+ output_data2, output_length2);
}
exit:
- psa_destroy_key( key );
- mbedtls_free( output_data );
- mbedtls_free( output_data2 );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output_data);
+ mbedtls_free(output_data2);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_encrypt( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- data_t *expected_result )
+void aead_encrypt(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ data_t *expected_result)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -4866,62 +4731,61 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = input_data->len + PSA_AEAD_TAG_LENGTH( key_type, key_bits,
- alg );
+ output_size = input_data->len + PSA_AEAD_TAG_LENGTH(key_type, key_bits,
+ alg);
/* For all currently defined algorithms, PSA_AEAD_ENCRYPT_OUTPUT_SIZE
* should be exact. */
- TEST_EQUAL( output_size,
- PSA_AEAD_ENCRYPT_OUTPUT_SIZE( key_type, alg, input_data->len ) );
- TEST_LE_U( output_size,
- PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
- ASSERT_ALLOC( output_data, output_size );
+ TEST_EQUAL(output_size,
+ PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
+ TEST_LE_U(output_size,
+ PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
+ ASSERT_ALLOC(output_data, output_size);
- status = psa_aead_encrypt( key, alg,
- nonce->x, nonce->len,
- additional_data->x, additional_data->len,
- input_data->x, input_data->len,
- output_data, output_size,
- &output_length );
+ status = psa_aead_encrypt(key, alg,
+ nonce->x, nonce->len,
+ additional_data->x, additional_data->len,
+ input_data->x, input_data->len,
+ output_data, output_size,
+ &output_length);
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce->len);
}
- PSA_ASSERT( status );
- ASSERT_COMPARE( expected_result->x, expected_result->len,
- output_data, output_length );
+ PSA_ASSERT(status);
+ ASSERT_COMPARE(expected_result->x, expected_result->len,
+ output_data, output_length);
exit:
- psa_destroy_key( key );
- mbedtls_free( output_data );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output_data);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_decrypt( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- data_t *expected_data,
- int expected_result_arg )
+void aead_decrypt(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ data_t *expected_data,
+ int expected_result_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -4934,144 +4798,145 @@
psa_status_t expected_result = expected_result_arg;
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = input_data->len - PSA_AEAD_TAG_LENGTH( key_type, key_bits,
- alg );
- if( expected_result != PSA_ERROR_INVALID_ARGUMENT &&
- expected_result != PSA_ERROR_NOT_SUPPORTED )
- {
+ output_size = input_data->len - PSA_AEAD_TAG_LENGTH(key_type, key_bits,
+ alg);
+ if (expected_result != PSA_ERROR_INVALID_ARGUMENT &&
+ expected_result != PSA_ERROR_NOT_SUPPORTED) {
/* For all currently defined algorithms, PSA_AEAD_DECRYPT_OUTPUT_SIZE
* should be exact. */
- TEST_EQUAL( output_size,
- PSA_AEAD_DECRYPT_OUTPUT_SIZE( key_type, alg, input_data->len ) );
- TEST_LE_U( output_size,
- PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
+ TEST_EQUAL(output_size,
+ PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
+ TEST_LE_U(output_size,
+ PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(input_data->len));
}
- ASSERT_ALLOC( output_data, output_size );
+ ASSERT_ALLOC(output_data, output_size);
- status = psa_aead_decrypt( key, alg,
- nonce->x, nonce->len,
- additional_data->x,
- additional_data->len,
- input_data->x, input_data->len,
- output_data, output_size,
- &output_length );
+ status = psa_aead_decrypt(key, alg,
+ nonce->x, nonce->len,
+ additional_data->x,
+ additional_data->len,
+ input_data->x, input_data->len,
+ output_data, output_size,
+ &output_length);
/* If the operation is not supported, just skip and not fail in case the
* decryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce->len);
}
- TEST_EQUAL( status, expected_result );
+ TEST_EQUAL(status, expected_result);
- if( expected_result == PSA_SUCCESS )
- ASSERT_COMPARE( expected_data->x, expected_data->len,
- output_data, output_length );
+ if (expected_result == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_data->x, expected_data->len,
+ output_data, output_length);
+ }
exit:
- psa_destroy_key( key );
- mbedtls_free( output_data );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output_data);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_encrypt( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- int do_set_lengths,
- data_t *expected_output )
+void aead_multipart_encrypt(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ int do_set_lengths,
+ data_t *expected_output)
{
size_t ad_part_len = 0;
size_t data_part_len = 0;
set_lengths_method_t set_lengths_method = DO_NOT_SET_LENGTHS;
- for( ad_part_len = 1; ad_part_len <= additional_data->len; ad_part_len++ )
- {
- mbedtls_test_set_step( ad_part_len );
+ for (ad_part_len = 1; ad_part_len <= additional_data->len; ad_part_len++) {
+ mbedtls_test_set_step(ad_part_len);
- if( do_set_lengths )
- {
- if( ad_part_len & 0x01 )
+ if (do_set_lengths) {
+ if (ad_part_len & 0x01) {
set_lengths_method = SET_LENGTHS_AFTER_NONCE;
- else
+ } else {
set_lengths_method = SET_LENGTHS_BEFORE_NONCE;
+ }
}
/* Split ad into length(ad_part_len) parts. */
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data,
- ad_part_len,
- input_data, -1,
- set_lengths_method,
- expected_output,
- 1, 0 ) )
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data,
+ ad_part_len,
+ input_data, -1,
+ set_lengths_method,
+ expected_output,
+ 1, 0)) {
break;
-
- /* length(0) part, length(ad_part_len) part, length(0) part... */
- mbedtls_test_set_step( 1000 + ad_part_len );
-
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data,
- ad_part_len,
- input_data, -1,
- set_lengths_method,
- expected_output,
- 1, 1 ) )
- break;
- }
-
- for( data_part_len = 1; data_part_len <= input_data->len; data_part_len++ )
- {
- /* Split data into length(data_part_len) parts. */
- mbedtls_test_set_step( 2000 + data_part_len );
-
- if( do_set_lengths )
- {
- if( data_part_len & 0x01 )
- set_lengths_method = SET_LENGTHS_AFTER_NONCE;
- else
- set_lengths_method = SET_LENGTHS_BEFORE_NONCE;
}
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data, -1,
- input_data, data_part_len,
- set_lengths_method,
- expected_output,
- 1, 0 ) )
+ /* length(0) part, length(ad_part_len) part, length(0) part... */
+ mbedtls_test_set_step(1000 + ad_part_len);
+
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data,
+ ad_part_len,
+ input_data, -1,
+ set_lengths_method,
+ expected_output,
+ 1, 1)) {
break;
+ }
+ }
+
+ for (data_part_len = 1; data_part_len <= input_data->len; data_part_len++) {
+ /* Split data into length(data_part_len) parts. */
+ mbedtls_test_set_step(2000 + data_part_len);
+
+ if (do_set_lengths) {
+ if (data_part_len & 0x01) {
+ set_lengths_method = SET_LENGTHS_AFTER_NONCE;
+ } else {
+ set_lengths_method = SET_LENGTHS_BEFORE_NONCE;
+ }
+ }
+
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data, -1,
+ input_data, data_part_len,
+ set_lengths_method,
+ expected_output,
+ 1, 0)) {
+ break;
+ }
/* length(0) part, length(data_part_len) part, length(0) part... */
- mbedtls_test_set_step( 3000 + data_part_len );
+ mbedtls_test_set_step(3000 + data_part_len);
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data, -1,
- input_data, data_part_len,
- set_lengths_method,
- expected_output,
- 1, 1 ) )
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data, -1,
+ input_data, data_part_len,
+ set_lengths_method,
+ expected_output,
+ 1, 1)) {
break;
+ }
}
/* Goto is required to silence warnings about unused labels, as we
@@ -5081,88 +4946,90 @@
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_decrypt( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- int do_set_lengths,
- data_t *expected_output )
+void aead_multipart_decrypt(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ int do_set_lengths,
+ data_t *expected_output)
{
size_t ad_part_len = 0;
size_t data_part_len = 0;
set_lengths_method_t set_lengths_method = DO_NOT_SET_LENGTHS;
- for( ad_part_len = 1; ad_part_len <= additional_data->len; ad_part_len++ )
- {
+ for (ad_part_len = 1; ad_part_len <= additional_data->len; ad_part_len++) {
/* Split ad into length(ad_part_len) parts. */
- mbedtls_test_set_step( ad_part_len );
+ mbedtls_test_set_step(ad_part_len);
- if( do_set_lengths )
- {
- if( ad_part_len & 0x01 )
+ if (do_set_lengths) {
+ if (ad_part_len & 0x01) {
set_lengths_method = SET_LENGTHS_AFTER_NONCE;
- else
+ } else {
set_lengths_method = SET_LENGTHS_BEFORE_NONCE;
+ }
}
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data,
- ad_part_len,
- input_data, -1,
- set_lengths_method,
- expected_output,
- 0, 0 ) )
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data,
+ ad_part_len,
+ input_data, -1,
+ set_lengths_method,
+ expected_output,
+ 0, 0)) {
break;
+ }
/* length(0) part, length(ad_part_len) part, length(0) part... */
- mbedtls_test_set_step( 1000 + ad_part_len );
+ mbedtls_test_set_step(1000 + ad_part_len);
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data,
- ad_part_len,
- input_data, -1,
- set_lengths_method,
- expected_output,
- 0, 1 ) )
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data,
+ ad_part_len,
+ input_data, -1,
+ set_lengths_method,
+ expected_output,
+ 0, 1)) {
break;
+ }
}
- for( data_part_len = 1; data_part_len <= input_data->len; data_part_len++ )
- {
+ for (data_part_len = 1; data_part_len <= input_data->len; data_part_len++) {
/* Split data into length(data_part_len) parts. */
- mbedtls_test_set_step( 2000 + data_part_len );
+ mbedtls_test_set_step(2000 + data_part_len);
- if( do_set_lengths )
- {
- if( data_part_len & 0x01 )
+ if (do_set_lengths) {
+ if (data_part_len & 0x01) {
set_lengths_method = SET_LENGTHS_AFTER_NONCE;
- else
+ } else {
set_lengths_method = SET_LENGTHS_BEFORE_NONCE;
+ }
}
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data, -1,
- input_data, data_part_len,
- set_lengths_method,
- expected_output,
- 0, 0 ) )
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data, -1,
+ input_data, data_part_len,
+ set_lengths_method,
+ expected_output,
+ 0, 0)) {
break;
+ }
/* length(0) part, length(data_part_len) part, length(0) part... */
- mbedtls_test_set_step( 3000 + data_part_len );
+ mbedtls_test_set_step(3000 + data_part_len);
- if( !aead_multipart_internal_func( key_type_arg, key_data,
- alg_arg, nonce,
- additional_data, -1,
- input_data, data_part_len,
- set_lengths_method,
- expected_output,
- 0, 1 ) )
+ if (!aead_multipart_internal_func(key_type_arg, key_data,
+ alg_arg, nonce,
+ additional_data, -1,
+ input_data, data_part_len,
+ set_lengths_method,
+ expected_output,
+ 0, 1)) {
break;
+ }
}
/* Goto is required to silence warnings about unused labels, as we
@@ -5172,13 +5039,13 @@
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_generate_nonce( int key_type_arg, data_t *key_data,
- int alg_arg,
- int nonce_length,
- int expected_nonce_length_arg,
- data_t *additional_data,
- data_t *input_data,
- int expected_status_arg )
+void aead_multipart_generate_nonce(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ int nonce_length,
+ int expected_nonce_length_arg,
+ data_t *additional_data,
+ data_t *input_data,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -5199,89 +5066,88 @@
size_t tag_length = 0;
uint8_t tag_buffer[PSA_AEAD_TAG_MAX_SIZE];
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( & attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( & attributes, alg );
- psa_set_key_type( & attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
- output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, input_data->len );
+ output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
- ASSERT_ALLOC( output, output_size );
+ ASSERT_ALLOC(output, output_size);
- ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg );
+ ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
- TEST_LE_U( ciphertext_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE );
+ TEST_LE_U(ciphertext_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE);
- ASSERT_ALLOC( ciphertext, ciphertext_size );
+ ASSERT_ALLOC(ciphertext, ciphertext_size);
- status = psa_aead_encrypt_setup( &operation, key, alg );
+ status = psa_aead_encrypt_setup(&operation, key, alg);
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce_length );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce_length);
}
- PSA_ASSERT( status );
+ PSA_ASSERT(status);
- status = psa_aead_generate_nonce( &operation, nonce_buffer,
- nonce_length,
- &actual_nonce_length );
+ status = psa_aead_generate_nonce(&operation, nonce_buffer,
+ nonce_length,
+ &actual_nonce_length);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- TEST_EQUAL( actual_nonce_length, expected_nonce_length );
+ TEST_EQUAL(actual_nonce_length, expected_nonce_length);
- if( expected_status == PSA_SUCCESS )
- TEST_EQUAL( actual_nonce_length, PSA_AEAD_NONCE_LENGTH( key_type,
- alg ) );
+ if (expected_status == PSA_SUCCESS) {
+ TEST_EQUAL(actual_nonce_length, PSA_AEAD_NONCE_LENGTH(key_type,
+ alg));
+ }
- TEST_LE_U( actual_nonce_length, PSA_AEAD_NONCE_MAX_SIZE );
+ TEST_LE_U(actual_nonce_length, PSA_AEAD_NONCE_MAX_SIZE);
- if( expected_status == PSA_SUCCESS )
- {
+ if (expected_status == PSA_SUCCESS) {
/* Ensure we can still complete operation. */
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- PSA_ASSERT( psa_aead_update( &operation, input_data->x, input_data->len,
- output, output_size,
- &ciphertext_length ) );
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x, input_data->len,
+ output, output_size,
+ &ciphertext_length));
- PSA_ASSERT( psa_aead_finish( &operation, ciphertext, ciphertext_size,
- &ciphertext_length, tag_buffer,
- PSA_AEAD_TAG_MAX_SIZE, &tag_length ) );
+ PSA_ASSERT(psa_aead_finish(&operation, ciphertext, ciphertext_size,
+ &ciphertext_length, tag_buffer,
+ PSA_AEAD_TAG_MAX_SIZE, &tag_length));
}
exit:
- psa_destroy_key( key );
- mbedtls_free( output );
- mbedtls_free( ciphertext );
- psa_aead_abort( &operation );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ mbedtls_free(ciphertext);
+ psa_aead_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_set_nonce( int key_type_arg, data_t *key_data,
- int alg_arg,
- int nonce_length_arg,
- int set_lengths_method_arg,
- data_t *additional_data,
- data_t *input_data,
- int expected_status_arg )
+void aead_multipart_set_nonce(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ int nonce_length_arg,
+ int set_lengths_method_arg,
+ data_t *additional_data,
+ data_t *input_data,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -5303,116 +5169,108 @@
size_t index = 0;
set_lengths_method_t set_lengths_method = set_lengths_method_arg;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
- output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, input_data->len );
+ output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
- ASSERT_ALLOC( output, output_size );
+ ASSERT_ALLOC(output, output_size);
- ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg );
+ ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
- TEST_LE_U( ciphertext_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE );
+ TEST_LE_U(ciphertext_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE);
- ASSERT_ALLOC( ciphertext, ciphertext_size );
+ ASSERT_ALLOC(ciphertext, ciphertext_size);
- status = psa_aead_encrypt_setup( &operation, key, alg );
+ status = psa_aead_encrypt_setup(&operation, key, alg);
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce_length_arg );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce_length_arg);
}
- PSA_ASSERT( status );
+ PSA_ASSERT(status);
/* -1 == zero length and valid buffer, 0 = zero length and NULL buffer. */
- if( nonce_length_arg == -1 )
- {
- /* Arbitrary size buffer, to test zero length valid buffer. */
- ASSERT_ALLOC( nonce_buffer, 4 );
- nonce_length = 0;
- }
- else
- {
+ if (nonce_length_arg == -1) {
+ /* Arbitrary size buffer, to test zero length valid buffer. */
+ ASSERT_ALLOC(nonce_buffer, 4);
+ nonce_length = 0;
+ } else {
/* If length is zero, then this will return NULL. */
- nonce_length = ( size_t ) nonce_length_arg;
- ASSERT_ALLOC( nonce_buffer, nonce_length );
+ nonce_length = (size_t) nonce_length_arg;
+ ASSERT_ALLOC(nonce_buffer, nonce_length);
- if( nonce_buffer )
- {
- for( index = 0; index < nonce_length - 1; ++index )
- {
+ if (nonce_buffer) {
+ for (index = 0; index < nonce_length - 1; ++index) {
nonce_buffer[index] = 'a' + index;
}
}
}
- if( set_lengths_method == SET_LENGTHS_BEFORE_NONCE )
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ if (set_lengths_method == SET_LENGTHS_BEFORE_NONCE) {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
}
- status = psa_aead_set_nonce( &operation, nonce_buffer, nonce_length );
+ status = psa_aead_set_nonce(&operation, nonce_buffer, nonce_length);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- if( expected_status == PSA_SUCCESS )
- {
- if( set_lengths_method == SET_LENGTHS_AFTER_NONCE )
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ if (expected_status == PSA_SUCCESS) {
+ if (set_lengths_method == SET_LENGTHS_AFTER_NONCE) {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
}
- if( operation.alg == PSA_ALG_CCM && set_lengths_method == DO_NOT_SET_LENGTHS )
+ if (operation.alg == PSA_ALG_CCM && set_lengths_method == DO_NOT_SET_LENGTHS) {
expected_status = PSA_ERROR_BAD_STATE;
+ }
/* Ensure we can still complete operation, unless it's CCM and we didn't set lengths. */
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ),
- expected_status );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len),
+ expected_status);
- TEST_EQUAL( psa_aead_update( &operation, input_data->x, input_data->len,
- output, output_size,
- &ciphertext_length ),
- expected_status );
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x, input_data->len,
+ output, output_size,
+ &ciphertext_length),
+ expected_status);
- TEST_EQUAL( psa_aead_finish( &operation, ciphertext, ciphertext_size,
- &ciphertext_length, tag_buffer,
- PSA_AEAD_TAG_MAX_SIZE, &tag_length ),
- expected_status );
+ TEST_EQUAL(psa_aead_finish(&operation, ciphertext, ciphertext_size,
+ &ciphertext_length, tag_buffer,
+ PSA_AEAD_TAG_MAX_SIZE, &tag_length),
+ expected_status);
}
exit:
- psa_destroy_key( key );
- mbedtls_free( output );
- mbedtls_free( ciphertext );
- mbedtls_free( nonce_buffer );
- psa_aead_abort( &operation );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ mbedtls_free(ciphertext);
+ mbedtls_free(nonce_buffer);
+ psa_aead_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_update_buffer_test( int key_type_arg, data_t *key_data,
+void aead_multipart_update_buffer_test(int key_type_arg, data_t *key_data,
int alg_arg,
int output_size_arg,
data_t *nonce,
data_t *additional_data,
data_t *input_data,
- int expected_status_arg )
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -5430,75 +5288,73 @@
size_t tag_length = 0;
uint8_t tag_buffer[PSA_AEAD_TAG_MAX_SIZE];
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
- ASSERT_ALLOC( output, output_size );
+ ASSERT_ALLOC(output, output_size);
- ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg );
+ ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
- ASSERT_ALLOC( ciphertext, ciphertext_size );
+ ASSERT_ALLOC(ciphertext, ciphertext_size);
- status = psa_aead_encrypt_setup( &operation, key, alg );
+ status = psa_aead_encrypt_setup(&operation, key, alg);
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce->len);
}
- PSA_ASSERT( status );
+ PSA_ASSERT(status);
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- status = psa_aead_update( &operation, input_data->x, input_data->len,
- output, output_size, &ciphertext_length );
+ status = psa_aead_update(&operation, input_data->x, input_data->len,
+ output, output_size, &ciphertext_length);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- if( expected_status == PSA_SUCCESS )
- {
+ if (expected_status == PSA_SUCCESS) {
/* Ensure we can still complete operation. */
- PSA_ASSERT( psa_aead_finish( &operation, ciphertext, ciphertext_size,
- &ciphertext_length, tag_buffer,
- PSA_AEAD_TAG_MAX_SIZE, &tag_length ) );
+ PSA_ASSERT(psa_aead_finish(&operation, ciphertext, ciphertext_size,
+ &ciphertext_length, tag_buffer,
+ PSA_AEAD_TAG_MAX_SIZE, &tag_length));
}
exit:
- psa_destroy_key( key );
- mbedtls_free( output );
- mbedtls_free( ciphertext );
- psa_aead_abort( &operation );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ mbedtls_free(ciphertext);
+ psa_aead_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_finish_buffer_test( int key_type_arg, data_t *key_data,
- int alg_arg,
- int finish_ciphertext_size_arg,
- int tag_size_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- int expected_status_arg )
+void aead_multipart_finish_buffer_test(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ int finish_ciphertext_size_arg,
+ int tag_size_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -5513,81 +5369,80 @@
unsigned char *tag_buffer = NULL;
size_t ciphertext_size = 0;
size_t ciphertext_length = 0;
- size_t finish_ciphertext_size = ( size_t ) finish_ciphertext_size_arg;
- size_t tag_size = ( size_t ) tag_size_arg;
+ size_t finish_ciphertext_size = (size_t) finish_ciphertext_size_arg;
+ size_t tag_size = (size_t) tag_size_arg;
size_t tag_length = 0;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
- ciphertext_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, input_data->len );
+ ciphertext_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
- ASSERT_ALLOC( ciphertext, ciphertext_size );
+ ASSERT_ALLOC(ciphertext, ciphertext_size);
- ASSERT_ALLOC( finish_ciphertext, finish_ciphertext_size );
+ ASSERT_ALLOC(finish_ciphertext, finish_ciphertext_size);
- ASSERT_ALLOC( tag_buffer, tag_size );
+ ASSERT_ALLOC(tag_buffer, tag_size);
- status = psa_aead_encrypt_setup( &operation, key, alg );
+ status = psa_aead_encrypt_setup(&operation, key, alg);
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce->len);
}
- PSA_ASSERT( status );
+ PSA_ASSERT(status);
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- PSA_ASSERT( psa_aead_update( &operation, input_data->x, input_data->len,
- ciphertext, ciphertext_size, &ciphertext_length ) );
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x, input_data->len,
+ ciphertext, ciphertext_size, &ciphertext_length));
/* Ensure we can still complete operation. */
- status = psa_aead_finish( &operation, finish_ciphertext,
- finish_ciphertext_size,
- &ciphertext_length, tag_buffer,
- tag_size, &tag_length );
+ status = psa_aead_finish(&operation, finish_ciphertext,
+ finish_ciphertext_size,
+ &ciphertext_length, tag_buffer,
+ tag_size, &tag_length);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
exit:
- psa_destroy_key( key );
- mbedtls_free( ciphertext );
- mbedtls_free( finish_ciphertext );
- mbedtls_free( tag_buffer );
- psa_aead_abort( &operation );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(ciphertext);
+ mbedtls_free(finish_ciphertext);
+ mbedtls_free(tag_buffer);
+ psa_aead_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_verify( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- data_t *tag,
- int tag_usage_arg,
- int expected_setup_status_arg,
- int expected_status_arg )
+void aead_multipart_verify(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ data_t *tag,
+ int tag_usage_arg,
+ int expected_setup_status_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -5606,82 +5461,81 @@
unsigned char *tag_buffer = NULL;
size_t tag_size = 0;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
- plaintext_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg,
- input_data->len );
+ plaintext_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg,
+ input_data->len);
- ASSERT_ALLOC( plaintext, plaintext_size );
+ ASSERT_ALLOC(plaintext, plaintext_size);
- verify_plaintext_size = PSA_AEAD_VERIFY_OUTPUT_SIZE( key_type, alg );
+ verify_plaintext_size = PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg);
- ASSERT_ALLOC( finish_plaintext, verify_plaintext_size );
+ ASSERT_ALLOC(finish_plaintext, verify_plaintext_size);
- status = psa_aead_decrypt_setup( &operation, key, alg );
+ status = psa_aead_decrypt_setup(&operation, key, alg);
/* If the operation is not supported, just skip and not fail in case the
* encryption involves a common limitation of cryptography hardwares and
* an alternative implementation. */
- if( status == PSA_ERROR_NOT_SUPPORTED )
- {
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
- MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len );
+ if (status == PSA_ERROR_NOT_SUPPORTED) {
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192(key_type, key_data->len * 8);
+ MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE(alg, nonce->len);
}
- TEST_EQUAL( status, expected_setup_status );
+ TEST_EQUAL(status, expected_setup_status);
- if( status != PSA_SUCCESS )
+ if (status != PSA_SUCCESS) {
goto exit;
+ }
- PSA_ASSERT( status );
+ PSA_ASSERT(status);
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- status = psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len );
- PSA_ASSERT( status );
+ status = psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len);
+ PSA_ASSERT(status);
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- PSA_ASSERT( psa_aead_update( &operation, input_data->x,
- input_data->len,
- plaintext, plaintext_size,
- &plaintext_length ) );
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x,
+ input_data->len,
+ plaintext, plaintext_size,
+ &plaintext_length));
- if( tag_usage == USE_GIVEN_TAG )
- {
+ if (tag_usage == USE_GIVEN_TAG) {
tag_buffer = tag->x;
tag_size = tag->len;
}
- status = psa_aead_verify( &operation, finish_plaintext,
- verify_plaintext_size,
- &plaintext_length,
- tag_buffer, tag_size );
+ status = psa_aead_verify(&operation, finish_plaintext,
+ verify_plaintext_size,
+ &plaintext_length,
+ tag_buffer, tag_size);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
exit:
- psa_destroy_key( key );
- mbedtls_free( plaintext );
- mbedtls_free( finish_plaintext );
- psa_aead_abort( &operation );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(plaintext);
+ mbedtls_free(finish_plaintext);
+ psa_aead_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_setup( int key_type_arg, data_t *key_data,
- int alg_arg, int expected_status_arg )
+void aead_multipart_setup(int key_type_arg, data_t *key_data,
+ int alg_arg, int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -5691,39 +5545,39 @@
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
psa_status_t expected_status = expected_status_arg;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- status = psa_aead_encrypt_setup( &operation, key, alg );
+ status = psa_aead_encrypt_setup(&operation, key, alg);
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
- status = psa_aead_decrypt_setup( &operation, key, alg );
+ status = psa_aead_decrypt_setup(&operation, key, alg);
- TEST_EQUAL(status, expected_status );
+ TEST_EQUAL(status, expected_status);
exit:
- psa_destroy_key( key );
- psa_aead_abort( &operation );
- PSA_DONE( );
+ psa_destroy_key(key);
+ psa_aead_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_multipart_state_test( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data )
+void aead_multipart_state_test(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -5743,833 +5597,790 @@
size_t output_part_length = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( & attributes,
- PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( & attributes, alg );
- psa_set_key_type( & attributes, key_type );
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- tag_length = PSA_AEAD_TAG_LENGTH( key_type, key_bits, alg );
+ tag_length = PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg);
- TEST_LE_U( tag_length, PSA_AEAD_TAG_MAX_SIZE );
+ TEST_LE_U(tag_length, PSA_AEAD_TAG_MAX_SIZE);
- output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, input_data->len );
+ output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
- ASSERT_ALLOC( output_data, output_size );
+ ASSERT_ALLOC(output_data, output_size);
- finish_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg );
+ finish_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
- TEST_LE_U( finish_output_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE );
+ TEST_LE_U(finish_output_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE);
- ASSERT_ALLOC( final_data, finish_output_size );
+ ASSERT_ALLOC(final_data, finish_output_size);
/* Test all operations error without calling setup first. */
- TEST_EQUAL( psa_aead_set_nonce( &operation, nonce->x, nonce->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_set_nonce(&operation, nonce->x, nonce->len),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
- TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- TEST_EQUAL( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- TEST_EQUAL( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- TEST_EQUAL( psa_aead_verify( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer,
- tag_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_verify(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer,
+ tag_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for double setups. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_encrypt_setup( &operation, key, alg ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_encrypt_setup(&operation, key, alg),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_decrypt_setup( &operation, key, alg ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_decrypt_setup(&operation, key, alg),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_decrypt_setup( &operation, key, alg ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_decrypt_setup(&operation, key, alg),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_encrypt_setup( &operation, key, alg ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_encrypt_setup(&operation, key, alg),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for not setting a nonce. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_verify( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer,
- tag_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_verify(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer,
+ tag_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for double setting nonce. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- TEST_EQUAL( psa_aead_set_nonce( &operation, nonce->x, nonce->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_set_nonce(&operation, nonce->x, nonce->len),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for double generating nonce. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
- TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for generate nonce then set and vice versa */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
- TEST_EQUAL( psa_aead_set_nonce( &operation, nonce->x, nonce->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_set_nonce(&operation, nonce->x, nonce->len),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for generating nonce after calling set lengths */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for generating nonce after calling set lengths with UINT32_MAX ad_data length */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- if( operation.alg == PSA_ALG_CCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ),
- PSA_ERROR_INVALID_ARGUMENT );
- TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ),
- PSA_ERROR_BAD_STATE );
- }
- else
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ) );
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
+ if (operation.alg == PSA_ALG_CCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len),
+ PSA_ERROR_INVALID_ARGUMENT);
+ TEST_EQUAL(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len));
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for generating nonce after calling set lengths with SIZE_MAX ad_data length */
#if SIZE_MAX > UINT32_MAX
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- if( operation.alg == PSA_ALG_CCM || operation.alg == PSA_ALG_GCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, SIZE_MAX,
- input_data->len ),
- PSA_ERROR_INVALID_ARGUMENT );
- TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ),
- PSA_ERROR_BAD_STATE );
- }
- else
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, SIZE_MAX,
- input_data->len ) );
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
+ if (operation.alg == PSA_ALG_CCM || operation.alg == PSA_ALG_GCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, SIZE_MAX,
+ input_data->len),
+ PSA_ERROR_INVALID_ARGUMENT);
+ TEST_EQUAL(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, SIZE_MAX,
+ input_data->len));
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
#endif
/* Test for calling set lengths with a UINT32_MAX ad_data length, after generating nonce */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
- if( operation.alg == PSA_ALG_CCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ),
- PSA_ERROR_INVALID_ARGUMENT );
- }
- else
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ) );
+ if (operation.alg == PSA_ALG_CCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len),
+ PSA_ERROR_INVALID_ARGUMENT);
+ } else {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
/* Test for setting nonce after calling set lengths */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for setting nonce after calling set lengths with UINT32_MAX ad_data length */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- if( operation.alg == PSA_ALG_CCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ),
- PSA_ERROR_INVALID_ARGUMENT );
- TEST_EQUAL( psa_aead_set_nonce( &operation, nonce->x, nonce->len ),
- PSA_ERROR_BAD_STATE );
- }
- else
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ) );
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ if (operation.alg == PSA_ALG_CCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len),
+ PSA_ERROR_INVALID_ARGUMENT);
+ TEST_EQUAL(psa_aead_set_nonce(&operation, nonce->x, nonce->len),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len));
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for setting nonce after calling set lengths with SIZE_MAX ad_data length */
#if SIZE_MAX > UINT32_MAX
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- if( operation.alg == PSA_ALG_CCM || operation.alg == PSA_ALG_GCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, SIZE_MAX,
- input_data->len ),
- PSA_ERROR_INVALID_ARGUMENT );
- TEST_EQUAL( psa_aead_set_nonce( &operation, nonce->x, nonce->len ),
- PSA_ERROR_BAD_STATE );
- }
- else
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, SIZE_MAX,
- input_data->len ) );
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ if (operation.alg == PSA_ALG_CCM || operation.alg == PSA_ALG_GCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, SIZE_MAX,
+ input_data->len),
+ PSA_ERROR_INVALID_ARGUMENT);
+ TEST_EQUAL(psa_aead_set_nonce(&operation, nonce->x, nonce->len),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, SIZE_MAX,
+ input_data->len));
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
#endif
/* Test for calling set lengths with an ad_data length of UINT32_MAX, after setting nonce */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- if( operation.alg == PSA_ALG_CCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ),
- PSA_ERROR_INVALID_ARGUMENT );
- }
- else
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, UINT32_MAX,
- input_data->len ) );
+ if (operation.alg == PSA_ALG_CCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len),
+ PSA_ERROR_INVALID_ARGUMENT);
+ } else {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, UINT32_MAX,
+ input_data->len));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for setting nonce after calling set lengths with plaintext length of SIZE_MAX */
#if SIZE_MAX > UINT32_MAX
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- if( operation.alg == PSA_ALG_GCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- SIZE_MAX ),
- PSA_ERROR_INVALID_ARGUMENT );
- TEST_EQUAL( psa_aead_set_nonce( &operation, nonce->x, nonce->len ),
- PSA_ERROR_BAD_STATE );
- }
- else if ( operation.alg != PSA_ALG_CCM )
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- SIZE_MAX ) );
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ if (operation.alg == PSA_ALG_GCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ SIZE_MAX),
+ PSA_ERROR_INVALID_ARGUMENT);
+ TEST_EQUAL(psa_aead_set_nonce(&operation, nonce->x, nonce->len),
+ PSA_ERROR_BAD_STATE);
+ } else if (operation.alg != PSA_ALG_CCM) {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ SIZE_MAX));
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for calling set lengths with a plaintext length of SIZE_MAX, after setting nonce */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- if( operation.alg == PSA_ALG_GCM )
- {
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- SIZE_MAX ),
- PSA_ERROR_INVALID_ARGUMENT );
- }
- else if ( operation.alg != PSA_ALG_CCM )
- {
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- SIZE_MAX ) );
+ if (operation.alg == PSA_ALG_GCM) {
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ SIZE_MAX),
+ PSA_ERROR_INVALID_ARGUMENT);
+ } else if (operation.alg != PSA_ALG_CCM) {
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ SIZE_MAX));
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
#endif
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for generating nonce in decrypt setup. */
- PSA_ASSERT( psa_aead_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
- TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for setting lengths twice. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for setting lengths after setting nonce + already starting data. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- if( operation.alg == PSA_ALG_CCM )
- {
+ if (operation.alg == PSA_ALG_CCM) {
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
+
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
}
- else
- {
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
-
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
- }
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- if( operation.alg == PSA_ALG_CCM )
- {
- TEST_EQUAL( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ),
- PSA_ERROR_BAD_STATE );
+ if (operation.alg == PSA_ALG_CCM) {
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length));
+
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
}
- else
- {
- PSA_ASSERT( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ) );
-
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
- }
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- if( operation.alg == PSA_ALG_CCM )
- {
- PSA_ASSERT( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ) );
+ if (operation.alg == PSA_ALG_CCM) {
+ PSA_ASSERT(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size));
+ } else {
+ PSA_ASSERT(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size));
+
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
}
- else
- {
- PSA_ASSERT( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ) );
-
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
- }
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for setting lengths after generating nonce + already starting data. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
- if( operation.alg == PSA_ALG_CCM )
- {
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
+ if (operation.alg == PSA_ALG_CCM) {
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
+
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
}
- else
- {
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
-
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
- }
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
- if( operation.alg == PSA_ALG_CCM )
- {
- TEST_EQUAL( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ),
- PSA_ERROR_BAD_STATE );
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
+ if (operation.alg == PSA_ALG_CCM) {
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length),
+ PSA_ERROR_BAD_STATE);
+ } else {
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length));
+
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
}
- else
- {
- PSA_ASSERT( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ) );
-
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
- }
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer,
- PSA_AEAD_NONCE_MAX_SIZE,
- &nonce_length ) );
- if( operation.alg == PSA_ALG_CCM )
- {
- PSA_ASSERT( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ) );
- }
- else
- {
- PSA_ASSERT( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ) );
+ PSA_ASSERT(psa_aead_generate_nonce(&operation, nonce_buffer,
+ PSA_AEAD_NONCE_MAX_SIZE,
+ &nonce_length));
+ if (operation.alg == PSA_ALG_CCM) {
+ PSA_ASSERT(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size));
+ } else {
+ PSA_ASSERT(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size));
- TEST_EQUAL( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len),
+ PSA_ERROR_BAD_STATE);
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for not sending any additional data or data after setting non zero
* lengths for them. (encrypt) */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- TEST_EQUAL( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for not sending any additional data or data after setting non-zero
* lengths for them. (decrypt) */
- PSA_ASSERT( psa_aead_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- TEST_EQUAL( psa_aead_verify( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer,
- tag_length ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_verify(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer,
+ tag_length),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for not sending any additional data after setting a non-zero length
* for it. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- TEST_EQUAL( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for not sending any data after setting a non-zero length for it.*/
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- TEST_EQUAL( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for sending too much additional data after setting lengths. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, 0, 0 ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, 0, 0));
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- 1 ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ 1),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test for sending too much data after setting lengths. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, 0, 0 ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, 0, 0));
- TEST_EQUAL( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* ------------------------------------------------------- */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- PSA_ASSERT( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ) );
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length));
- TEST_EQUAL( psa_aead_update( &operation, input_data->x,
- 1, output_data,
- output_size, &output_length ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_aead_update(&operation, input_data->x,
+ 1, output_data,
+ output_size, &output_length),
+ PSA_ERROR_INVALID_ARGUMENT);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test sending additional data after data. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- if( operation.alg != PSA_ALG_CCM )
- {
- PSA_ASSERT( psa_aead_update( &operation, input_data->x,
- input_data->len, output_data,
- output_size, &output_length ) );
+ if (operation.alg != PSA_ALG_CCM) {
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x,
+ input_data->len, output_data,
+ output_size, &output_length));
- TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len),
+ PSA_ERROR_BAD_STATE);
}
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test calling finish on decryption. */
- PSA_ASSERT( psa_aead_decrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- TEST_EQUAL( psa_aead_finish( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer, tag_length,
- &tag_size ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_finish(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer, tag_length,
+ &tag_size),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
/* Test calling verify on encryption. */
- PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) );
+ PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- TEST_EQUAL( psa_aead_verify( &operation, final_data,
- finish_output_size,
- &output_part_length,
- tag_buffer,
- tag_length ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_aead_verify(&operation, final_data,
+ finish_output_size,
+ &output_part_length,
+ tag_buffer,
+ tag_length),
+ PSA_ERROR_BAD_STATE);
- psa_aead_abort( &operation );
+ psa_aead_abort(&operation);
exit:
- psa_destroy_key( key );
- psa_aead_abort( &operation );
- mbedtls_free( output_data );
- mbedtls_free( final_data );
- PSA_DONE( );
+ psa_destroy_key(key);
+ psa_aead_abort(&operation);
+ mbedtls_free(output_data);
+ mbedtls_free(final_data);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void signature_size( int type_arg,
- int bits,
- int alg_arg,
- int expected_size_arg )
+void signature_size(int type_arg,
+ int bits,
+ int alg_arg,
+ int expected_size_arg)
{
psa_key_type_t type = type_arg;
psa_algorithm_t alg = alg_arg;
- size_t actual_size = PSA_SIGN_OUTPUT_SIZE( type, bits, alg );
+ size_t actual_size = PSA_SIGN_OUTPUT_SIZE(type, bits, alg);
- TEST_EQUAL( actual_size, (size_t) expected_size_arg );
+ TEST_EQUAL(actual_size, (size_t) expected_size_arg);
exit:
;
@@ -6577,9 +6388,9 @@
/* END_CASE */
/* BEGIN_CASE */
-void sign_hash_deterministic( int key_type_arg, data_t *key_data,
- int alg_arg, data_t *input_data,
- data_t *output_data )
+void sign_hash_deterministic(int key_type_arg, data_t *key_data,
+ int alg_arg, data_t *input_data,
+ data_t *output_data)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -6590,51 +6401,51 @@
size_t signature_length = 0xdeadbeef;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
/* Allocate a buffer which has the size advertised by the
* library. */
- signature_size = PSA_SIGN_OUTPUT_SIZE( key_type,
- key_bits, alg );
- TEST_ASSERT( signature_size != 0 );
- TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
- ASSERT_ALLOC( signature, signature_size );
+ signature_size = PSA_SIGN_OUTPUT_SIZE(key_type,
+ key_bits, alg);
+ TEST_ASSERT(signature_size != 0);
+ TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
+ ASSERT_ALLOC(signature, signature_size);
/* Perform the signature. */
- PSA_ASSERT( psa_sign_hash( key, alg,
- input_data->x, input_data->len,
- signature, signature_size,
- &signature_length ) );
+ PSA_ASSERT(psa_sign_hash(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_size,
+ &signature_length));
/* Verify that the signature is what is expected. */
- ASSERT_COMPARE( output_data->x, output_data->len,
- signature, signature_length );
+ ASSERT_COMPARE(output_data->x, output_data->len,
+ signature, signature_length);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void sign_hash_fail( int key_type_arg, data_t *key_data,
- int alg_arg, data_t *input_data,
- int signature_size_arg, int expected_status_arg )
+void sign_hash_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, data_t *input_data,
+ int signature_size_arg, int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -6646,39 +6457,39 @@
size_t signature_length = 0xdeadbeef;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- ASSERT_ALLOC( signature, signature_size );
+ ASSERT_ALLOC(signature, signature_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- actual_status = psa_sign_hash( key, alg,
- input_data->x, input_data->len,
- signature, signature_size,
- &signature_length );
- TEST_EQUAL( actual_status, expected_status );
+ actual_status = psa_sign_hash(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_size,
+ &signature_length);
+ TEST_EQUAL(actual_status, expected_status);
/* The value of *signature_length is unspecified on error, but
* whatever it is, it should be less than signature_size, so that
* if the caller tries to read *signature_length bytes without
* checking the error code then they don't overflow a buffer. */
- TEST_LE_U( signature_length, signature_size );
+ TEST_LE_U(signature_length, signature_size);
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void sign_verify_hash( int key_type_arg, data_t *key_data,
- int alg_arg, data_t *input_data )
+void sign_verify_hash(int key_type_arg, data_t *key_data,
+ int alg_arg, data_t *input_data)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -6689,49 +6500,48 @@
size_t signature_length = 0xdeadbeef;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
/* Allocate a buffer which has the size advertised by the
* library. */
- signature_size = PSA_SIGN_OUTPUT_SIZE( key_type,
- key_bits, alg );
- TEST_ASSERT( signature_size != 0 );
- TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
- ASSERT_ALLOC( signature, signature_size );
+ signature_size = PSA_SIGN_OUTPUT_SIZE(key_type,
+ key_bits, alg);
+ TEST_ASSERT(signature_size != 0);
+ TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
+ ASSERT_ALLOC(signature, signature_size);
/* Perform the signature. */
- PSA_ASSERT( psa_sign_hash( key, alg,
- input_data->x, input_data->len,
- signature, signature_size,
- &signature_length ) );
+ PSA_ASSERT(psa_sign_hash(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_size,
+ &signature_length));
/* Check that the signature length looks sensible. */
- TEST_LE_U( signature_length, signature_size );
- TEST_ASSERT( signature_length > 0 );
+ TEST_LE_U(signature_length, signature_size);
+ TEST_ASSERT(signature_length > 0);
/* Use the library to verify that the signature is correct. */
- PSA_ASSERT( psa_verify_hash( key, alg,
- input_data->x, input_data->len,
- signature, signature_length ) );
+ PSA_ASSERT(psa_verify_hash(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_length));
- if( input_data->len != 0 )
- {
+ if (input_data->len != 0) {
/* Flip a bit in the input and verify that the signature is now
* detected as invalid. Flip a bit at the beginning, not at the end,
* because ECDSA may ignore the last few bits of the input. */
input_data->x[0] ^= 1;
- TEST_EQUAL( psa_verify_hash( key, alg,
- input_data->x, input_data->len,
- signature, signature_length ),
- PSA_ERROR_INVALID_SIGNATURE );
+ TEST_EQUAL(psa_verify_hash(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_length),
+ PSA_ERROR_INVALID_SIGNATURE);
}
exit:
@@ -6739,51 +6549,51 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void verify_hash( int key_type_arg, data_t *key_data,
- int alg_arg, data_t *hash_data,
- data_t *signature_data )
+void verify_hash(int key_type_arg, data_t *key_data,
+ int alg_arg, data_t *hash_data,
+ data_t *signature_data)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- TEST_LE_U( signature_data->len, PSA_SIGNATURE_MAX_SIZE );
+ TEST_LE_U(signature_data->len, PSA_SIGNATURE_MAX_SIZE);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_verify_hash( key, alg,
- hash_data->x, hash_data->len,
- signature_data->x, signature_data->len ) );
+ PSA_ASSERT(psa_verify_hash(key, alg,
+ hash_data->x, hash_data->len,
+ signature_data->x, signature_data->len));
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void verify_hash_fail( int key_type_arg, data_t *key_data,
- int alg_arg, data_t *hash_data,
- data_t *signature_data,
- int expected_status_arg )
+void verify_hash_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, data_t *hash_data,
+ data_t *signature_data,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -6792,33 +6602,33 @@
psa_status_t expected_status = expected_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- actual_status = psa_verify_hash( key, alg,
- hash_data->x, hash_data->len,
- signature_data->x, signature_data->len );
- TEST_EQUAL( actual_status, expected_status );
+ actual_status = psa_verify_hash(key, alg,
+ hash_data->x, hash_data->len,
+ signature_data->x, signature_data->len);
+ TEST_EQUAL(actual_status, expected_status);
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void sign_message_deterministic( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input_data,
- data_t *output_data )
+void sign_message_deterministic(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input_data,
+ data_t *output_data)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -6829,231 +6639,230 @@
size_t signature_length = 0xdeadbeef;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
- TEST_ASSERT( signature_size != 0 );
- TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
- ASSERT_ALLOC( signature, signature_size );
+ signature_size = PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg);
+ TEST_ASSERT(signature_size != 0);
+ TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
+ ASSERT_ALLOC(signature, signature_size);
- PSA_ASSERT( psa_sign_message( key, alg,
- input_data->x, input_data->len,
- signature, signature_size,
- &signature_length ) );
+ PSA_ASSERT(psa_sign_message(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_size,
+ &signature_length));
- ASSERT_COMPARE( output_data->x, output_data->len,
- signature, signature_length );
+ ASSERT_COMPARE(output_data->x, output_data->len,
+ signature, signature_length);
exit:
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void sign_message_fail( int key_type_arg,
+void sign_message_fail(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input_data,
+ int signature_size_arg,
+ int expected_status_arg)
+{
+ mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
+ psa_key_type_t key_type = key_type_arg;
+ psa_algorithm_t alg = alg_arg;
+ size_t signature_size = signature_size_arg;
+ psa_status_t actual_status;
+ psa_status_t expected_status = expected_status_arg;
+ unsigned char *signature = NULL;
+ size_t signature_length = 0xdeadbeef;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+
+ ASSERT_ALLOC(signature, signature_size);
+
+ PSA_ASSERT(psa_crypto_init());
+
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+
+ actual_status = psa_sign_message(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_size,
+ &signature_length);
+ TEST_EQUAL(actual_status, expected_status);
+ /* The value of *signature_length is unspecified on error, but
+ * whatever it is, it should be less than signature_size, so that
+ * if the caller tries to read *signature_length bytes without
+ * checking the error code then they don't overflow a buffer. */
+ TEST_LE_U(signature_length, signature_size);
+
+exit:
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void sign_verify_message(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input_data)
+{
+ mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
+ psa_key_type_t key_type = key_type_arg;
+ psa_algorithm_t alg = alg_arg;
+ size_t key_bits;
+ unsigned char *signature = NULL;
+ size_t signature_size;
+ size_t signature_length = 0xdeadbeef;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+
+ PSA_ASSERT(psa_crypto_init());
+
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_MESSAGE |
+ PSA_KEY_USAGE_VERIFY_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
+
+ signature_size = PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg);
+ TEST_ASSERT(signature_size != 0);
+ TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
+ ASSERT_ALLOC(signature, signature_size);
+
+ PSA_ASSERT(psa_sign_message(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_size,
+ &signature_length));
+ TEST_LE_U(signature_length, signature_size);
+ TEST_ASSERT(signature_length > 0);
+
+ PSA_ASSERT(psa_verify_message(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_length));
+
+ if (input_data->len != 0) {
+ /* Flip a bit in the input and verify that the signature is now
+ * detected as invalid. Flip a bit at the beginning, not at the end,
+ * because ECDSA may ignore the last few bits of the input. */
+ input_data->x[0] ^= 1;
+ TEST_EQUAL(psa_verify_message(key, alg,
+ input_data->x, input_data->len,
+ signature, signature_length),
+ PSA_ERROR_INVALID_SIGNATURE);
+ }
+
+exit:
+ psa_reset_key_attributes(&attributes);
+
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void verify_message(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input_data,
+ data_t *signature_data)
+{
+ mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
+ psa_key_type_t key_type = key_type_arg;
+ psa_algorithm_t alg = alg_arg;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+
+ TEST_LE_U(signature_data->len, PSA_SIGNATURE_MAX_SIZE);
+
+ PSA_ASSERT(psa_crypto_init());
+
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+
+ PSA_ASSERT(psa_verify_message(key, alg,
+ input_data->x, input_data->len,
+ signature_data->x, signature_data->len));
+
+exit:
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void verify_message_fail(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *hash_data,
+ data_t *signature_data,
+ int expected_status_arg)
+{
+ mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
+ psa_key_type_t key_type = key_type_arg;
+ psa_algorithm_t alg = alg_arg;
+ psa_status_t actual_status;
+ psa_status_t expected_status = expected_status_arg;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+
+ PSA_ASSERT(psa_crypto_init());
+
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+
+ actual_status = psa_verify_message(key, alg,
+ hash_data->x, hash_data->len,
+ signature_data->x,
+ signature_data->len);
+ TEST_EQUAL(actual_status, expected_status);
+
+exit:
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void asymmetric_encrypt(int key_type_arg,
data_t *key_data,
int alg_arg,
data_t *input_data,
- int signature_size_arg,
- int expected_status_arg )
-{
- mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
- psa_key_type_t key_type = key_type_arg;
- psa_algorithm_t alg = alg_arg;
- size_t signature_size = signature_size_arg;
- psa_status_t actual_status;
- psa_status_t expected_status = expected_status_arg;
- unsigned char *signature = NULL;
- size_t signature_length = 0xdeadbeef;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
-
- ASSERT_ALLOC( signature, signature_size );
-
- PSA_ASSERT( psa_crypto_init( ) );
-
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
-
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
-
- actual_status = psa_sign_message( key, alg,
- input_data->x, input_data->len,
- signature, signature_size,
- &signature_length );
- TEST_EQUAL( actual_status, expected_status );
- /* The value of *signature_length is unspecified on error, but
- * whatever it is, it should be less than signature_size, so that
- * if the caller tries to read *signature_length bytes without
- * checking the error code then they don't overflow a buffer. */
- TEST_LE_U( signature_length, signature_size );
-
-exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void sign_verify_message( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input_data )
-{
- mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
- psa_key_type_t key_type = key_type_arg;
- psa_algorithm_t alg = alg_arg;
- size_t key_bits;
- unsigned char *signature = NULL;
- size_t signature_size;
- size_t signature_length = 0xdeadbeef;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
-
- PSA_ASSERT( psa_crypto_init( ) );
-
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_MESSAGE |
- PSA_KEY_USAGE_VERIFY_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
-
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
-
- signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
- TEST_ASSERT( signature_size != 0 );
- TEST_LE_U( signature_size, PSA_SIGNATURE_MAX_SIZE );
- ASSERT_ALLOC( signature, signature_size );
-
- PSA_ASSERT( psa_sign_message( key, alg,
- input_data->x, input_data->len,
- signature, signature_size,
- &signature_length ) );
- TEST_LE_U( signature_length, signature_size );
- TEST_ASSERT( signature_length > 0 );
-
- PSA_ASSERT( psa_verify_message( key, alg,
- input_data->x, input_data->len,
- signature, signature_length ) );
-
- if( input_data->len != 0 )
- {
- /* Flip a bit in the input and verify that the signature is now
- * detected as invalid. Flip a bit at the beginning, not at the end,
- * because ECDSA may ignore the last few bits of the input. */
- input_data->x[0] ^= 1;
- TEST_EQUAL( psa_verify_message( key, alg,
- input_data->x, input_data->len,
- signature, signature_length ),
- PSA_ERROR_INVALID_SIGNATURE );
- }
-
-exit:
- psa_reset_key_attributes( &attributes );
-
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void verify_message( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input_data,
- data_t *signature_data )
-{
- mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
- psa_key_type_t key_type = key_type_arg;
- psa_algorithm_t alg = alg_arg;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
-
- TEST_LE_U( signature_data->len, PSA_SIGNATURE_MAX_SIZE );
-
- PSA_ASSERT( psa_crypto_init( ) );
-
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
-
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
-
- PSA_ASSERT( psa_verify_message( key, alg,
- input_data->x, input_data->len,
- signature_data->x, signature_data->len ) );
-
-exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void verify_message_fail( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *hash_data,
- data_t *signature_data,
- int expected_status_arg )
-{
- mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
- psa_key_type_t key_type = key_type_arg;
- psa_algorithm_t alg = alg_arg;
- psa_status_t actual_status;
- psa_status_t expected_status = expected_status_arg;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
-
- PSA_ASSERT( psa_crypto_init( ) );
-
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
-
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
-
- actual_status = psa_verify_message( key, alg,
- hash_data->x, hash_data->len,
- signature_data->x,
- signature_data->len );
- TEST_EQUAL( actual_status, expected_status );
-
-exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void asymmetric_encrypt( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input_data,
- data_t *label,
- int expected_output_length_arg,
- int expected_status_arg )
+ data_t *label,
+ int expected_output_length_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -7067,46 +6876,46 @@
psa_status_t expected_status = expected_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Import the key */
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Determine the maximum output length */
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
- TEST_LE_U( output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE );
- ASSERT_ALLOC( output, output_size );
+ output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
+ TEST_LE_U(output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE);
+ ASSERT_ALLOC(output, output_size);
/* Encrypt the input */
- actual_status = psa_asymmetric_encrypt( key, alg,
- input_data->x, input_data->len,
- label->x, label->len,
- output, output_size,
- &output_length );
- TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( output_length, expected_output_length );
+ actual_status = psa_asymmetric_encrypt(key, alg,
+ input_data->x, input_data->len,
+ label->x, label->len,
+ output, output_size,
+ &output_length);
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_EQUAL(output_length, expected_output_length);
/* If the label is empty, the test framework puts a non-null pointer
* in label->x. Test that a null pointer works as well. */
- if( label->len == 0 )
- {
+ if (label->len == 0) {
output_length = ~0;
- if( output_size != 0 )
- memset( output, 0, output_size );
- actual_status = psa_asymmetric_encrypt( key, alg,
- input_data->x, input_data->len,
- NULL, label->len,
- output, output_size,
- &output_length );
- TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( output_length, expected_output_length );
+ if (output_size != 0) {
+ memset(output, 0, output_size);
+ }
+ actual_status = psa_asymmetric_encrypt(key, alg,
+ input_data->x, input_data->len,
+ NULL, label->len,
+ output, output_size,
+ &output_length);
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_EQUAL(output_length, expected_output_length);
}
exit:
@@ -7114,20 +6923,20 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_encrypt_decrypt( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input_data,
- data_t *label )
+void asymmetric_encrypt_decrypt(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input_data,
+ data_t *label)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -7141,70 +6950,70 @@
size_t output2_length = ~0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Determine the maximum ciphertext length */
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
- TEST_LE_U( output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE );
- ASSERT_ALLOC( output, output_size );
+ output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
+ TEST_LE_U(output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE);
+ ASSERT_ALLOC(output, output_size);
output2_size = input_data->len;
- TEST_LE_U( output2_size,
- PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE( key_type, key_bits, alg ) );
- TEST_LE_U( output2_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE );
- ASSERT_ALLOC( output2, output2_size );
+ TEST_LE_U(output2_size,
+ PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg));
+ TEST_LE_U(output2_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE);
+ ASSERT_ALLOC(output2, output2_size);
/* We test encryption by checking that encrypt-then-decrypt gives back
* the original plaintext because of the non-optional random
* part of encryption process which prevents using fixed vectors. */
- PSA_ASSERT( psa_asymmetric_encrypt( key, alg,
- input_data->x, input_data->len,
- label->x, label->len,
- output, output_size,
- &output_length ) );
+ PSA_ASSERT(psa_asymmetric_encrypt(key, alg,
+ input_data->x, input_data->len,
+ label->x, label->len,
+ output, output_size,
+ &output_length));
/* We don't know what ciphertext length to expect, but check that
* it looks sensible. */
- TEST_LE_U( output_length, output_size );
+ TEST_LE_U(output_length, output_size);
- PSA_ASSERT( psa_asymmetric_decrypt( key, alg,
- output, output_length,
- label->x, label->len,
- output2, output2_size,
- &output2_length ) );
- ASSERT_COMPARE( input_data->x, input_data->len,
- output2, output2_length );
+ PSA_ASSERT(psa_asymmetric_decrypt(key, alg,
+ output, output_length,
+ label->x, label->len,
+ output2, output2_size,
+ &output2_length));
+ ASSERT_COMPARE(input_data->x, input_data->len,
+ output2, output2_length);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( output );
- mbedtls_free( output2 );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ mbedtls_free(output2);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_decrypt( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input_data,
- data_t *label,
- data_t *expected_data )
+void asymmetric_decrypt(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input_data,
+ data_t *label,
+ data_t *expected_data)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -7215,65 +7024,65 @@
size_t output_length = ~0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
/* Determine the maximum ciphertext length */
- output_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
- TEST_LE_U( output_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE );
- ASSERT_ALLOC( output, output_size );
+ output_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
+ TEST_LE_U(output_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE);
+ ASSERT_ALLOC(output, output_size);
- PSA_ASSERT( psa_asymmetric_decrypt( key, alg,
- input_data->x, input_data->len,
- label->x, label->len,
- output,
- output_size,
- &output_length ) );
- ASSERT_COMPARE( expected_data->x, expected_data->len,
- output, output_length );
+ PSA_ASSERT(psa_asymmetric_decrypt(key, alg,
+ input_data->x, input_data->len,
+ label->x, label->len,
+ output,
+ output_size,
+ &output_length));
+ ASSERT_COMPARE(expected_data->x, expected_data->len,
+ output, output_length);
/* If the label is empty, the test framework puts a non-null pointer
* in label->x. Test that a null pointer works as well. */
- if( label->len == 0 )
- {
+ if (label->len == 0) {
output_length = ~0;
- if( output_size != 0 )
- memset( output, 0, output_size );
- PSA_ASSERT( psa_asymmetric_decrypt( key, alg,
- input_data->x, input_data->len,
- NULL, label->len,
- output,
- output_size,
- &output_length ) );
- ASSERT_COMPARE( expected_data->x, expected_data->len,
- output, output_length );
+ if (output_size != 0) {
+ memset(output, 0, output_size);
+ }
+ PSA_ASSERT(psa_asymmetric_decrypt(key, alg,
+ input_data->x, input_data->len,
+ NULL, label->len,
+ output,
+ output_size,
+ &output_length));
+ ASSERT_COMPARE(expected_data->x, expected_data->len,
+ output, output_length);
}
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_decrypt_fail( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input_data,
- data_t *label,
- int output_size_arg,
- int expected_status_arg )
+void asymmetric_decrypt_fail(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input_data,
+ data_t *label,
+ int output_size_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -7285,135 +7094,135 @@
psa_status_t expected_status = expected_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- ASSERT_ALLOC( output, output_size );
+ ASSERT_ALLOC(output, output_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- actual_status = psa_asymmetric_decrypt( key, alg,
- input_data->x, input_data->len,
- label->x, label->len,
- output, output_size,
- &output_length );
- TEST_EQUAL( actual_status, expected_status );
- TEST_LE_U( output_length, output_size );
+ actual_status = psa_asymmetric_decrypt(key, alg,
+ input_data->x, input_data->len,
+ label->x, label->len,
+ output, output_size,
+ &output_length);
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_LE_U(output_length, output_size);
/* If the label is empty, the test framework puts a non-null pointer
* in label->x. Test that a null pointer works as well. */
- if( label->len == 0 )
- {
+ if (label->len == 0) {
output_length = ~0;
- if( output_size != 0 )
- memset( output, 0, output_size );
- actual_status = psa_asymmetric_decrypt( key, alg,
- input_data->x, input_data->len,
- NULL, label->len,
- output, output_size,
- &output_length );
- TEST_EQUAL( actual_status, expected_status );
- TEST_LE_U( output_length, output_size );
+ if (output_size != 0) {
+ memset(output, 0, output_size);
+ }
+ actual_status = psa_asymmetric_decrypt(key, alg,
+ input_data->x, input_data->len,
+ NULL, label->len,
+ output, output_size,
+ &output_length);
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_LE_U(output_length, output_size);
}
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_derivation_init( )
+void key_derivation_init()
{
/* Test each valid way of initializing the object, except for `= {0}`, as
* Clang 5 complains when `-Wmissing-field-initializers` is used, even
* though it's OK by the C standard. We could test for this, but we'd need
* to suppress the Clang warning for the test. */
size_t capacity;
- psa_key_derivation_operation_t func = psa_key_derivation_operation_init( );
+ psa_key_derivation_operation_t func = psa_key_derivation_operation_init();
psa_key_derivation_operation_t init = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_derivation_operation_t zero;
- memset( &zero, 0, sizeof( zero ) );
+ memset(&zero, 0, sizeof(zero));
/* A default operation should not be able to report its capacity. */
- TEST_EQUAL( psa_key_derivation_get_capacity( &func, &capacity ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_key_derivation_get_capacity( &init, &capacity ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_key_derivation_get_capacity( &zero, &capacity ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_key_derivation_get_capacity(&func, &capacity),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_key_derivation_get_capacity(&init, &capacity),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_key_derivation_get_capacity(&zero, &capacity),
+ PSA_ERROR_BAD_STATE);
/* A default operation should be abortable without error. */
- PSA_ASSERT( psa_key_derivation_abort(&func) );
- PSA_ASSERT( psa_key_derivation_abort(&init) );
- PSA_ASSERT( psa_key_derivation_abort(&zero) );
+ PSA_ASSERT(psa_key_derivation_abort(&func));
+ PSA_ASSERT(psa_key_derivation_abort(&init));
+ PSA_ASSERT(psa_key_derivation_abort(&zero));
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_setup( int alg_arg, int expected_status_arg )
+void derive_setup(int alg_arg, int expected_status_arg)
{
psa_algorithm_t alg = alg_arg;
psa_status_t expected_status = expected_status_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- TEST_EQUAL( psa_key_derivation_setup( &operation, alg ),
- expected_status );
+ TEST_EQUAL(psa_key_derivation_setup(&operation, alg),
+ expected_status);
exit:
- psa_key_derivation_abort( &operation );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_set_capacity( int alg_arg, int capacity_arg,
- int expected_status_arg )
+void derive_set_capacity(int alg_arg, int capacity_arg,
+ int expected_status_arg)
{
psa_algorithm_t alg = alg_arg;
size_t capacity = capacity_arg;
psa_status_t expected_status = expected_status_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- PSA_ASSERT( psa_key_derivation_setup( &operation, alg ) );
+ PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
- TEST_EQUAL( psa_key_derivation_set_capacity( &operation, capacity ),
- expected_status );
+ TEST_EQUAL(psa_key_derivation_set_capacity(&operation, capacity),
+ expected_status);
exit:
- psa_key_derivation_abort( &operation );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_input( int alg_arg,
- int step_arg1, int key_type_arg1, data_t *input1,
- int expected_status_arg1,
- int step_arg2, int key_type_arg2, data_t *input2,
- int expected_status_arg2,
- int step_arg3, int key_type_arg3, data_t *input3,
- int expected_status_arg3,
- int output_key_type_arg, int expected_output_status_arg )
+void derive_input(int alg_arg,
+ int step_arg1, int key_type_arg1, data_t *input1,
+ int expected_status_arg1,
+ int step_arg2, int key_type_arg2, data_t *input2,
+ int expected_status_arg2,
+ int step_arg3, int key_type_arg3, data_t *input3,
+ int expected_status_arg3,
+ int output_key_type_arg, int expected_output_status_arg)
{
psa_algorithm_t alg = alg_arg;
- psa_key_derivation_step_t steps[] = {step_arg1, step_arg2, step_arg3};
- psa_key_type_t key_types[] = {key_type_arg1, key_type_arg2, key_type_arg3};
- psa_status_t expected_statuses[] = {expected_status_arg1,
- expected_status_arg2,
- expected_status_arg3};
- data_t *inputs[] = {input1, input2, input3};
+ psa_key_derivation_step_t steps[] = { step_arg1, step_arg2, step_arg3 };
+ psa_key_type_t key_types[] = { key_type_arg1, key_type_arg2, key_type_arg3 };
+ psa_status_t expected_statuses[] = { expected_status_arg1,
+ expected_status_arg2,
+ expected_status_arg3 };
+ data_t *inputs[] = { input1, input2, input3 };
mbedtls_svc_key_id_t keys[] = { MBEDTLS_SVC_KEY_ID_INIT,
MBEDTLS_SVC_KEY_ID_INIT,
MBEDTLS_SVC_KEY_ID_INIT };
@@ -7425,187 +7234,177 @@
psa_status_t expected_output_status = expected_output_status_arg;
psa_status_t actual_output_status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
- PSA_ASSERT( psa_key_derivation_setup( &operation, alg ) );
+ PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
- for( i = 0; i < ARRAY_LENGTH( steps ); i++ )
- {
- mbedtls_test_set_step( i );
- if( steps[i] == 0 )
- {
+ for (i = 0; i < ARRAY_LENGTH(steps); i++) {
+ mbedtls_test_set_step(i);
+ if (steps[i] == 0) {
/* Skip this step */
- }
- else if( key_types[i] != PSA_KEY_TYPE_NONE )
- {
- psa_set_key_type( &attributes, key_types[i] );
- PSA_ASSERT( psa_import_key( &attributes,
- inputs[i]->x, inputs[i]->len,
- &keys[i] ) );
- if( PSA_KEY_TYPE_IS_KEY_PAIR( key_types[i] ) &&
- steps[i] == PSA_KEY_DERIVATION_INPUT_SECRET )
- {
+ } else if (key_types[i] != PSA_KEY_TYPE_NONE) {
+ psa_set_key_type(&attributes, key_types[i]);
+ PSA_ASSERT(psa_import_key(&attributes,
+ inputs[i]->x, inputs[i]->len,
+ &keys[i]));
+ if (PSA_KEY_TYPE_IS_KEY_PAIR(key_types[i]) &&
+ steps[i] == PSA_KEY_DERIVATION_INPUT_SECRET) {
// When taking a private key as secret input, use key agreement
// to add the shared secret to the derivation
- TEST_EQUAL( mbedtls_test_psa_key_agreement_with_self(
- &operation, keys[i] ),
- expected_statuses[i] );
+ TEST_EQUAL(mbedtls_test_psa_key_agreement_with_self(
+ &operation, keys[i]),
+ expected_statuses[i]);
+ } else {
+ TEST_EQUAL(psa_key_derivation_input_key(&operation, steps[i],
+ keys[i]),
+ expected_statuses[i]);
}
- else
- {
- TEST_EQUAL( psa_key_derivation_input_key( &operation, steps[i],
- keys[i] ),
- expected_statuses[i] );
- }
- }
- else
- {
- TEST_EQUAL( psa_key_derivation_input_bytes(
- &operation, steps[i],
- inputs[i]->x, inputs[i]->len ),
- expected_statuses[i] );
+ } else {
+ TEST_EQUAL(psa_key_derivation_input_bytes(
+ &operation, steps[i],
+ inputs[i]->x, inputs[i]->len),
+ expected_statuses[i]);
}
}
- if( output_key_type != PSA_KEY_TYPE_NONE )
- {
- psa_reset_key_attributes( &attributes );
- psa_set_key_type( &attributes, output_key_type );
- psa_set_key_bits( &attributes, 8 );
+ if (output_key_type != PSA_KEY_TYPE_NONE) {
+ psa_reset_key_attributes(&attributes);
+ psa_set_key_type(&attributes, output_key_type);
+ psa_set_key_bits(&attributes, 8);
actual_output_status =
- psa_key_derivation_output_key( &attributes, &operation,
- &output_key );
- }
- else
- {
+ psa_key_derivation_output_key(&attributes, &operation,
+ &output_key);
+ } else {
uint8_t buffer[1];
actual_output_status =
- psa_key_derivation_output_bytes( &operation,
- buffer, sizeof( buffer ) );
+ psa_key_derivation_output_bytes(&operation,
+ buffer, sizeof(buffer));
}
- TEST_EQUAL( actual_output_status, expected_output_status );
+ TEST_EQUAL(actual_output_status, expected_output_status);
exit:
- psa_key_derivation_abort( &operation );
- for( i = 0; i < ARRAY_LENGTH( keys ); i++ )
- psa_destroy_key( keys[i] );
- psa_destroy_key( output_key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ for (i = 0; i < ARRAY_LENGTH(keys); i++) {
+ psa_destroy_key(keys[i]);
+ }
+ psa_destroy_key(output_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_over_capacity( int alg_arg )
+void derive_over_capacity(int alg_arg)
{
psa_algorithm_t alg = alg_arg;
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
size_t key_type = PSA_KEY_TYPE_DERIVE;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
unsigned char input1[] = "Input 1";
- size_t input1_length = sizeof( input1 );
+ size_t input1_length = sizeof(input1);
unsigned char input2[] = "Input 2";
- size_t input2_length = sizeof( input2 );
+ size_t input2_length = sizeof(input2);
uint8_t buffer[42];
- size_t capacity = sizeof( buffer );
+ size_t capacity = sizeof(buffer);
const uint8_t key_data[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
- 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b};
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes,
- key_data, sizeof( key_data ),
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_data, sizeof(key_data),
+ &key));
/* valid key derivation */
- if( !mbedtls_test_psa_setup_key_derivation_wrap( &operation, key, alg,
- input1, input1_length,
- input2, input2_length,
- capacity ) )
+ if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, key, alg,
+ input1, input1_length,
+ input2, input2_length,
+ capacity)) {
goto exit;
+ }
/* state of operation shouldn't allow additional generation */
- TEST_EQUAL( psa_key_derivation_setup( &operation, alg ),
- PSA_ERROR_BAD_STATE );
+ TEST_EQUAL(psa_key_derivation_setup(&operation, alg),
+ PSA_ERROR_BAD_STATE);
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation, buffer, capacity ) );
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation, buffer, capacity));
- TEST_EQUAL( psa_key_derivation_output_bytes( &operation, buffer, capacity ),
- PSA_ERROR_INSUFFICIENT_DATA );
+ TEST_EQUAL(psa_key_derivation_output_bytes(&operation, buffer, capacity),
+ PSA_ERROR_INSUFFICIENT_DATA);
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_actions_without_setup( )
+void derive_actions_without_setup()
{
uint8_t output_buffer[16];
size_t buffer_size = 16;
size_t capacity = 0;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
- TEST_ASSERT( psa_key_derivation_output_bytes( &operation,
- output_buffer, buffer_size )
- == PSA_ERROR_BAD_STATE );
+ TEST_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output_buffer, buffer_size)
+ == PSA_ERROR_BAD_STATE);
- TEST_ASSERT( psa_key_derivation_get_capacity( &operation, &capacity )
- == PSA_ERROR_BAD_STATE );
+ TEST_ASSERT(psa_key_derivation_get_capacity(&operation, &capacity)
+ == PSA_ERROR_BAD_STATE);
- PSA_ASSERT( psa_key_derivation_abort( &operation ) );
+ PSA_ASSERT(psa_key_derivation_abort(&operation));
- TEST_ASSERT( psa_key_derivation_output_bytes( &operation,
- output_buffer, buffer_size )
- == PSA_ERROR_BAD_STATE );
+ TEST_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output_buffer, buffer_size)
+ == PSA_ERROR_BAD_STATE);
- TEST_ASSERT( psa_key_derivation_get_capacity( &operation, &capacity )
- == PSA_ERROR_BAD_STATE );
+ TEST_ASSERT(psa_key_derivation_get_capacity(&operation, &capacity)
+ == PSA_ERROR_BAD_STATE);
exit:
- psa_key_derivation_abort( &operation );
+ psa_key_derivation_abort(&operation);
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_output( int alg_arg,
- int step1_arg, data_t *input1, int expected_status_arg1,
- int step2_arg, data_t *input2, int expected_status_arg2,
- int step3_arg, data_t *input3, int expected_status_arg3,
- int step4_arg, data_t *input4, int expected_status_arg4,
- data_t *key_agreement_peer_key,
- int requested_capacity_arg,
- data_t *expected_output1,
- data_t *expected_output2,
- int other_key_input_type,
- int key_input_type,
- int derive_type )
+void derive_output(int alg_arg,
+ int step1_arg, data_t *input1, int expected_status_arg1,
+ int step2_arg, data_t *input2, int expected_status_arg2,
+ int step3_arg, data_t *input3, int expected_status_arg3,
+ int step4_arg, data_t *input4, int expected_status_arg4,
+ data_t *key_agreement_peer_key,
+ int requested_capacity_arg,
+ data_t *expected_output1,
+ data_t *expected_output2,
+ int other_key_input_type,
+ int key_input_type,
+ int derive_type)
{
psa_algorithm_t alg = alg_arg;
- psa_key_derivation_step_t steps[] = {step1_arg, step2_arg, step3_arg, step4_arg};
- data_t *inputs[] = {input1, input2, input3, input4};
- mbedtls_svc_key_id_t keys[] = {MBEDTLS_SVC_KEY_ID_INIT,
- MBEDTLS_SVC_KEY_ID_INIT,
- MBEDTLS_SVC_KEY_ID_INIT,
- MBEDTLS_SVC_KEY_ID_INIT};
- psa_status_t statuses[] = {expected_status_arg1, expected_status_arg2,
- expected_status_arg3, expected_status_arg4};
+ psa_key_derivation_step_t steps[] = { step1_arg, step2_arg, step3_arg, step4_arg };
+ data_t *inputs[] = { input1, input2, input3, input4 };
+ mbedtls_svc_key_id_t keys[] = { MBEDTLS_SVC_KEY_ID_INIT,
+ MBEDTLS_SVC_KEY_ID_INIT,
+ MBEDTLS_SVC_KEY_ID_INIT,
+ MBEDTLS_SVC_KEY_ID_INIT };
+ psa_status_t statuses[] = { expected_status_arg1, expected_status_arg2,
+ expected_status_arg3, expected_status_arg4 };
size_t requested_capacity = requested_capacity_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
uint8_t *expected_outputs[2] =
- {expected_output1->x, expected_output2->x};
+ { expected_output1->x, expected_output2->x };
size_t output_sizes[2] =
- {expected_output1->len, expected_output2->len};
+ { expected_output1->len, expected_output2->len };
size_t output_buffer_size = 0;
uint8_t *output_buffer = NULL;
size_t expected_capacity;
@@ -7618,201 +7417,198 @@
psa_status_t status;
size_t i;
- for( i = 0; i < ARRAY_LENGTH( expected_outputs ); i++ )
- {
- if( output_sizes[i] > output_buffer_size )
+ for (i = 0; i < ARRAY_LENGTH(expected_outputs); i++) {
+ if (output_sizes[i] > output_buffer_size) {
output_buffer_size = output_sizes[i];
- if( output_sizes[i] == 0 )
+ }
+ if (output_sizes[i] == 0) {
expected_outputs[i] = NULL;
+ }
}
- ASSERT_ALLOC( output_buffer, output_buffer_size );
- PSA_ASSERT( psa_crypto_init( ) );
+ ASSERT_ALLOC(output_buffer, output_buffer_size);
+ PSA_ASSERT(psa_crypto_init());
/* Extraction phase. */
- PSA_ASSERT( psa_key_derivation_setup( &operation, alg ) );
- PSA_ASSERT( psa_key_derivation_set_capacity( &operation,
- requested_capacity ) );
- for( i = 0; i < ARRAY_LENGTH( steps ); i++ )
- {
- switch( steps[i] )
- {
+ PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
+ PSA_ASSERT(psa_key_derivation_set_capacity(&operation,
+ requested_capacity));
+ for (i = 0; i < ARRAY_LENGTH(steps); i++) {
+ switch (steps[i]) {
case 0:
break;
case PSA_KEY_DERIVATION_INPUT_SECRET:
- switch( key_input_type )
- {
+ switch (key_input_type) {
case 0: // input bytes
- TEST_EQUAL( psa_key_derivation_input_bytes(
- &operation, steps[i],
- inputs[i]->x, inputs[i]->len ),
- statuses[i] );
+ TEST_EQUAL(psa_key_derivation_input_bytes(
+ &operation, steps[i],
+ inputs[i]->x, inputs[i]->len),
+ statuses[i]);
- if( statuses[i] != PSA_SUCCESS )
+ if (statuses[i] != PSA_SUCCESS) {
goto exit;
+ }
break;
case 1: // input key
- psa_set_key_usage_flags( &attributes1, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes1, alg );
- psa_set_key_type( &attributes1, PSA_KEY_TYPE_DERIVE );
+ psa_set_key_usage_flags(&attributes1, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes1, alg);
+ psa_set_key_type(&attributes1, PSA_KEY_TYPE_DERIVE);
- PSA_ASSERT( psa_import_key( &attributes1,
- inputs[i]->x, inputs[i]->len,
- &keys[i] ) );
+ PSA_ASSERT(psa_import_key(&attributes1,
+ inputs[i]->x, inputs[i]->len,
+ &keys[i]));
- if( PSA_ALG_IS_TLS12_PSK_TO_MS( alg ) )
- {
- PSA_ASSERT( psa_get_key_attributes( keys[i], &attributes1 ) );
- TEST_LE_U( PSA_BITS_TO_BYTES( psa_get_key_bits( &attributes1 ) ),
- PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE );
+ if (PSA_ALG_IS_TLS12_PSK_TO_MS(alg)) {
+ PSA_ASSERT(psa_get_key_attributes(keys[i], &attributes1));
+ TEST_LE_U(PSA_BITS_TO_BYTES(psa_get_key_bits(&attributes1)),
+ PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE);
}
- PSA_ASSERT( psa_key_derivation_input_key( &operation,
- steps[i],
- keys[i] ) );
+ PSA_ASSERT(psa_key_derivation_input_key(&operation,
+ steps[i],
+ keys[i]));
break;
default:
- TEST_ASSERT( ! "default case not supported" );
+ TEST_ASSERT(!"default case not supported");
break;
}
break;
case PSA_KEY_DERIVATION_INPUT_OTHER_SECRET:
- switch( other_key_input_type )
- {
+ switch (other_key_input_type) {
case 0: // input bytes
- TEST_EQUAL( psa_key_derivation_input_bytes( &operation,
- steps[i],
- inputs[i]->x,
- inputs[i]->len ),
- statuses[i] );
+ TEST_EQUAL(psa_key_derivation_input_bytes(&operation,
+ steps[i],
+ inputs[i]->x,
+ inputs[i]->len),
+ statuses[i]);
break;
case 1: // input key, type DERIVE
case 11: // input key, type RAW
- psa_set_key_usage_flags( &attributes2, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes2, alg );
- psa_set_key_type( &attributes2, PSA_KEY_TYPE_DERIVE );
+ psa_set_key_usage_flags(&attributes2, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes2, alg);
+ psa_set_key_type(&attributes2, PSA_KEY_TYPE_DERIVE);
// other secret of type RAW_DATA passed with input_key
- if( other_key_input_type == 11 )
- psa_set_key_type( &attributes2, PSA_KEY_TYPE_RAW_DATA );
+ if (other_key_input_type == 11) {
+ psa_set_key_type(&attributes2, PSA_KEY_TYPE_RAW_DATA);
+ }
- PSA_ASSERT( psa_import_key( &attributes2,
- inputs[i]->x, inputs[i]->len,
- &keys[i] ) );
+ PSA_ASSERT(psa_import_key(&attributes2,
+ inputs[i]->x, inputs[i]->len,
+ &keys[i]));
- TEST_EQUAL( psa_key_derivation_input_key( &operation,
- steps[i],
- keys[i] ),
- statuses[i] );
+ TEST_EQUAL(psa_key_derivation_input_key(&operation,
+ steps[i],
+ keys[i]),
+ statuses[i]);
break;
case 2: // key agreement
- psa_set_key_usage_flags( &attributes3, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes3, alg );
- psa_set_key_type( &attributes3, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1) );
+ psa_set_key_usage_flags(&attributes3, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes3, alg);
+ psa_set_key_type(&attributes3,
+ PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
- PSA_ASSERT( psa_import_key( &attributes3,
- inputs[i]->x, inputs[i]->len,
- &keys[i] ) );
+ PSA_ASSERT(psa_import_key(&attributes3,
+ inputs[i]->x, inputs[i]->len,
+ &keys[i]));
- TEST_EQUAL( psa_key_derivation_key_agreement(
- &operation,
- PSA_KEY_DERIVATION_INPUT_OTHER_SECRET,
- keys[i], key_agreement_peer_key->x,
- key_agreement_peer_key->len ), statuses[i] );
+ TEST_EQUAL(psa_key_derivation_key_agreement(
+ &operation,
+ PSA_KEY_DERIVATION_INPUT_OTHER_SECRET,
+ keys[i], key_agreement_peer_key->x,
+ key_agreement_peer_key->len), statuses[i]);
break;
default:
- TEST_ASSERT( ! "default case not supported" );
+ TEST_ASSERT(!"default case not supported");
break;
}
- if( statuses[i] != PSA_SUCCESS )
+ if (statuses[i] != PSA_SUCCESS) {
goto exit;
+ }
break;
default:
- TEST_EQUAL( psa_key_derivation_input_bytes(
- &operation, steps[i],
- inputs[i]->x, inputs[i]->len ), statuses[i] );
+ TEST_EQUAL(psa_key_derivation_input_bytes(
+ &operation, steps[i],
+ inputs[i]->x, inputs[i]->len), statuses[i]);
- if( statuses[i] != PSA_SUCCESS )
+ if (statuses[i] != PSA_SUCCESS) {
goto exit;
+ }
break;
}
}
- PSA_ASSERT( psa_key_derivation_get_capacity( &operation,
- ¤t_capacity ) );
- TEST_EQUAL( current_capacity, requested_capacity );
+ PSA_ASSERT(psa_key_derivation_get_capacity(&operation,
+ ¤t_capacity));
+ TEST_EQUAL(current_capacity, requested_capacity);
expected_capacity = requested_capacity;
- if( derive_type == 1 ) // output key
- {
+ if (derive_type == 1) { // output key
psa_status_t expected_status = PSA_ERROR_NOT_PERMITTED;
/* For output key derivation secret must be provided using
input key, otherwise operation is not permitted. */
- if( key_input_type == 1 )
+ if (key_input_type == 1) {
expected_status = PSA_SUCCESS;
+ }
- psa_set_key_usage_flags( &attributes4, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes4, alg );
- psa_set_key_type( &attributes4, PSA_KEY_TYPE_DERIVE );
- psa_set_key_bits( &attributes4, PSA_BYTES_TO_BITS( requested_capacity ) );
+ psa_set_key_usage_flags(&attributes4, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes4, alg);
+ psa_set_key_type(&attributes4, PSA_KEY_TYPE_DERIVE);
+ psa_set_key_bits(&attributes4, PSA_BYTES_TO_BITS(requested_capacity));
- TEST_EQUAL( psa_key_derivation_output_key( &attributes4, &operation,
- &derived_key ), expected_status );
- }
- else // output bytes
- {
+ TEST_EQUAL(psa_key_derivation_output_key(&attributes4, &operation,
+ &derived_key), expected_status);
+ } else { // output bytes
/* Expansion phase. */
- for( i = 0; i < ARRAY_LENGTH( expected_outputs ); i++ )
- {
+ for (i = 0; i < ARRAY_LENGTH(expected_outputs); i++) {
/* Read some bytes. */
- status = psa_key_derivation_output_bytes( &operation,
- output_buffer, output_sizes[i] );
- if( expected_capacity == 0 && output_sizes[i] == 0 )
- {
+ status = psa_key_derivation_output_bytes(&operation,
+ output_buffer, output_sizes[i]);
+ if (expected_capacity == 0 && output_sizes[i] == 0) {
/* Reading 0 bytes when 0 bytes are available can go either way. */
- TEST_ASSERT( status == PSA_SUCCESS ||
- status == PSA_ERROR_INSUFFICIENT_DATA );
+ TEST_ASSERT(status == PSA_SUCCESS ||
+ status == PSA_ERROR_INSUFFICIENT_DATA);
continue;
- }
- else if( expected_capacity == 0 ||
- output_sizes[i] > expected_capacity )
- {
+ } else if (expected_capacity == 0 ||
+ output_sizes[i] > expected_capacity) {
/* Capacity exceeded. */
- TEST_EQUAL( status, PSA_ERROR_INSUFFICIENT_DATA );
+ TEST_EQUAL(status, PSA_ERROR_INSUFFICIENT_DATA);
expected_capacity = 0;
continue;
}
/* Success. Check the read data. */
- PSA_ASSERT( status );
- if( output_sizes[i] != 0 )
- ASSERT_COMPARE( output_buffer, output_sizes[i],
- expected_outputs[i], output_sizes[i] );
+ PSA_ASSERT(status);
+ if (output_sizes[i] != 0) {
+ ASSERT_COMPARE(output_buffer, output_sizes[i],
+ expected_outputs[i], output_sizes[i]);
+ }
/* Check the operation status. */
expected_capacity -= output_sizes[i];
- PSA_ASSERT( psa_key_derivation_get_capacity( &operation,
- ¤t_capacity ) );
- TEST_EQUAL( expected_capacity, current_capacity );
+ PSA_ASSERT(psa_key_derivation_get_capacity(&operation,
+ ¤t_capacity));
+ TEST_EQUAL(expected_capacity, current_capacity);
}
}
- PSA_ASSERT( psa_key_derivation_abort( &operation ) );
+ PSA_ASSERT(psa_key_derivation_abort(&operation));
exit:
- mbedtls_free( output_buffer );
- psa_key_derivation_abort( &operation );
- for( i = 0; i < ARRAY_LENGTH( keys ); i++ )
- psa_destroy_key( keys[i] );
- psa_destroy_key( derived_key );
- PSA_DONE( );
+ mbedtls_free(output_buffer);
+ psa_key_derivation_abort(&operation);
+ for (i = 0; i < ARRAY_LENGTH(keys); i++) {
+ psa_destroy_key(keys[i]);
+ }
+ psa_destroy_key(derived_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_full( int alg_arg,
- data_t *key_data,
- data_t *input1,
- data_t *input2,
- int requested_capacity_arg )
+void derive_full(int alg_arg,
+ data_t *key_data,
+ data_t *input1,
+ data_t *input2,
+ int requested_capacity_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_algorithm_t alg = alg_arg;
@@ -7823,59 +7619,60 @@
size_t current_capacity;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_DERIVE );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_DERIVE);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- if( !mbedtls_test_psa_setup_key_derivation_wrap( &operation, key, alg,
- input1->x, input1->len,
- input2->x, input2->len,
- requested_capacity ) )
+ if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, key, alg,
+ input1->x, input1->len,
+ input2->x, input2->len,
+ requested_capacity)) {
goto exit;
+ }
- PSA_ASSERT( psa_key_derivation_get_capacity( &operation,
- ¤t_capacity ) );
- TEST_EQUAL( current_capacity, expected_capacity );
+ PSA_ASSERT(psa_key_derivation_get_capacity(&operation,
+ ¤t_capacity));
+ TEST_EQUAL(current_capacity, expected_capacity);
/* Expansion phase. */
- while( current_capacity > 0 )
- {
- size_t read_size = sizeof( output_buffer );
- if( read_size > current_capacity )
+ while (current_capacity > 0) {
+ size_t read_size = sizeof(output_buffer);
+ if (read_size > current_capacity) {
read_size = current_capacity;
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- output_buffer,
- read_size ) );
+ }
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output_buffer,
+ read_size));
expected_capacity -= read_size;
- PSA_ASSERT( psa_key_derivation_get_capacity( &operation,
- ¤t_capacity ) );
- TEST_EQUAL( current_capacity, expected_capacity );
+ PSA_ASSERT(psa_key_derivation_get_capacity(&operation,
+ ¤t_capacity));
+ TEST_EQUAL(current_capacity, expected_capacity);
}
/* Check that the operation refuses to go over capacity. */
- TEST_EQUAL( psa_key_derivation_output_bytes( &operation, output_buffer, 1 ),
- PSA_ERROR_INSUFFICIENT_DATA );
+ TEST_EQUAL(psa_key_derivation_output_bytes(&operation, output_buffer, 1),
+ PSA_ERROR_INSUFFICIENT_DATA);
- PSA_ASSERT( psa_key_derivation_abort( &operation ) );
+ PSA_ASSERT(psa_key_derivation_abort(&operation));
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_SHA_256:MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS */
-void derive_ecjpake_to_pms( data_t *input, int expected_input_status_arg,
- int derivation_step,
- int capacity, int expected_capacity_status_arg,
- data_t *expected_output,
- int expected_output_status_arg )
+void derive_ecjpake_to_pms(data_t *input, int expected_input_status_arg,
+ int derivation_step,
+ int capacity, int expected_capacity_status_arg,
+ data_t *expected_output,
+ int expected_output_status_arg)
{
psa_algorithm_t alg = PSA_ALG_TLS12_ECJPAKE_TO_PMS;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
@@ -7886,44 +7683,46 @@
psa_status_t expected_capacity_status = (psa_status_t) expected_capacity_status_arg;
psa_status_t expected_output_status = (psa_status_t) expected_output_status_arg;
- ASSERT_ALLOC( output_buffer, expected_output->len );
- PSA_ASSERT( psa_crypto_init() );
+ ASSERT_ALLOC(output_buffer, expected_output->len);
+ PSA_ASSERT(psa_crypto_init());
- PSA_ASSERT( psa_key_derivation_setup( &operation, alg ) );
- TEST_EQUAL( psa_key_derivation_set_capacity( &operation, capacity ),
- expected_capacity_status);
+ PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
+ TEST_EQUAL(psa_key_derivation_set_capacity(&operation, capacity),
+ expected_capacity_status);
- TEST_EQUAL( psa_key_derivation_input_bytes( &operation,
- step, input->x, input->len ),
- expected_input_status );
+ TEST_EQUAL(psa_key_derivation_input_bytes(&operation,
+ step, input->x, input->len),
+ expected_input_status);
- if( ( (psa_status_t) expected_input_status ) != PSA_SUCCESS )
+ if (((psa_status_t) expected_input_status) != PSA_SUCCESS) {
goto exit;
+ }
- status = psa_key_derivation_output_bytes( &operation, output_buffer,
- expected_output->len );
+ status = psa_key_derivation_output_bytes(&operation, output_buffer,
+ expected_output->len);
- TEST_EQUAL( status, expected_output_status );
- if( expected_output->len != 0 && expected_output_status == PSA_SUCCESS )
- ASSERT_COMPARE( output_buffer, expected_output->len, expected_output->x,
- expected_output->len );
+ TEST_EQUAL(status, expected_output_status);
+ if (expected_output->len != 0 && expected_output_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(output_buffer, expected_output->len, expected_output->x,
+ expected_output->len);
+ }
exit:
- mbedtls_free( output_buffer );
- psa_key_derivation_abort( &operation );
+ mbedtls_free(output_buffer);
+ psa_key_derivation_abort(&operation);
PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_key_exercise( int alg_arg,
- data_t *key_data,
- data_t *input1,
- data_t *input2,
- int derived_type_arg,
- int derived_bits_arg,
- int derived_usage_arg,
- int derived_alg_arg )
+void derive_key_exercise(int alg_arg,
+ data_t *key_data,
+ data_t *input1,
+ data_t *input2,
+ int derived_type_arg,
+ int derived_bits_arg,
+ int derived_usage_arg,
+ int derived_alg_arg)
{
mbedtls_svc_key_id_t base_key = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t derived_key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -7932,63 +7731,65 @@
size_t derived_bits = derived_bits_arg;
psa_key_usage_t derived_usage = derived_usage_arg;
psa_algorithm_t derived_alg = derived_alg_arg;
- size_t capacity = PSA_BITS_TO_BYTES( derived_bits );
+ size_t capacity = PSA_BITS_TO_BYTES(derived_bits);
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_DERIVE );
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &base_key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_DERIVE);
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &base_key));
/* Derive a key. */
- if ( mbedtls_test_psa_setup_key_derivation_wrap( &operation, base_key, alg,
- input1->x, input1->len,
- input2->x, input2->len,
- capacity ) )
+ if (mbedtls_test_psa_setup_key_derivation_wrap(&operation, base_key, alg,
+ input1->x, input1->len,
+ input2->x, input2->len,
+ capacity)) {
goto exit;
+ }
- psa_set_key_usage_flags( &attributes, derived_usage );
- psa_set_key_algorithm( &attributes, derived_alg );
- psa_set_key_type( &attributes, derived_type );
- psa_set_key_bits( &attributes, derived_bits );
- PSA_ASSERT( psa_key_derivation_output_key( &attributes, &operation,
- &derived_key ) );
+ psa_set_key_usage_flags(&attributes, derived_usage);
+ psa_set_key_algorithm(&attributes, derived_alg);
+ psa_set_key_type(&attributes, derived_type);
+ psa_set_key_bits(&attributes, derived_bits);
+ PSA_ASSERT(psa_key_derivation_output_key(&attributes, &operation,
+ &derived_key));
/* Test the key information */
- PSA_ASSERT( psa_get_key_attributes( derived_key, &got_attributes ) );
- TEST_EQUAL( psa_get_key_type( &got_attributes ), derived_type );
- TEST_EQUAL( psa_get_key_bits( &got_attributes ), derived_bits );
+ PSA_ASSERT(psa_get_key_attributes(derived_key, &got_attributes));
+ TEST_EQUAL(psa_get_key_type(&got_attributes), derived_type);
+ TEST_EQUAL(psa_get_key_bits(&got_attributes), derived_bits);
/* Exercise the derived key. */
- if( ! mbedtls_test_psa_exercise_key( derived_key, derived_usage, derived_alg ) )
+ if (!mbedtls_test_psa_exercise_key(derived_key, derived_usage, derived_alg)) {
goto exit;
+ }
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &got_attributes );
+ psa_reset_key_attributes(&got_attributes);
- psa_key_derivation_abort( &operation );
- psa_destroy_key( base_key );
- psa_destroy_key( derived_key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(base_key);
+ psa_destroy_key(derived_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_key_export( int alg_arg,
- data_t *key_data,
- data_t *input1,
- data_t *input2,
- int bytes1_arg,
- int bytes2_arg )
+void derive_key_export(int alg_arg,
+ data_t *key_data,
+ data_t *input1,
+ data_t *input2,
+ int bytes1_arg,
+ int bytes2_arg)
{
mbedtls_svc_key_id_t base_key = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t derived_key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -8003,75 +7804,77 @@
psa_key_attributes_t derived_attributes = PSA_KEY_ATTRIBUTES_INIT;
size_t length;
- ASSERT_ALLOC( output_buffer, capacity );
- ASSERT_ALLOC( export_buffer, capacity );
- PSA_ASSERT( psa_crypto_init( ) );
+ ASSERT_ALLOC(output_buffer, capacity);
+ ASSERT_ALLOC(export_buffer, capacity);
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &base_attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &base_attributes, alg );
- psa_set_key_type( &base_attributes, PSA_KEY_TYPE_DERIVE );
- PSA_ASSERT( psa_import_key( &base_attributes, key_data->x, key_data->len,
- &base_key ) );
+ psa_set_key_usage_flags(&base_attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&base_attributes, alg);
+ psa_set_key_type(&base_attributes, PSA_KEY_TYPE_DERIVE);
+ PSA_ASSERT(psa_import_key(&base_attributes, key_data->x, key_data->len,
+ &base_key));
/* Derive some material and output it. */
- if( !mbedtls_test_psa_setup_key_derivation_wrap( &operation, base_key, alg,
- input1->x, input1->len,
- input2->x, input2->len,
- capacity ) )
+ if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, base_key, alg,
+ input1->x, input1->len,
+ input2->x, input2->len,
+ capacity)) {
goto exit;
+ }
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- output_buffer,
- capacity ) );
- PSA_ASSERT( psa_key_derivation_abort( &operation ) );
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output_buffer,
+ capacity));
+ PSA_ASSERT(psa_key_derivation_abort(&operation));
/* Derive the same output again, but this time store it in key objects. */
- if( !mbedtls_test_psa_setup_key_derivation_wrap( &operation, base_key, alg,
- input1->x, input1->len,
- input2->x, input2->len,
- capacity ) )
+ if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, base_key, alg,
+ input1->x, input1->len,
+ input2->x, input2->len,
+ capacity)) {
goto exit;
+ }
- psa_set_key_usage_flags( &derived_attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &derived_attributes, 0 );
- psa_set_key_type( &derived_attributes, PSA_KEY_TYPE_RAW_DATA );
- psa_set_key_bits( &derived_attributes, PSA_BYTES_TO_BITS( bytes1 ) );
- PSA_ASSERT( psa_key_derivation_output_key( &derived_attributes, &operation,
- &derived_key ) );
- PSA_ASSERT( psa_export_key( derived_key,
- export_buffer, bytes1,
- &length ) );
- TEST_EQUAL( length, bytes1 );
- PSA_ASSERT( psa_destroy_key( derived_key ) );
- psa_set_key_bits( &derived_attributes, PSA_BYTES_TO_BITS( bytes2 ) );
- PSA_ASSERT( psa_key_derivation_output_key( &derived_attributes, &operation,
- &derived_key ) );
- PSA_ASSERT( psa_export_key( derived_key,
- export_buffer + bytes1, bytes2,
- &length ) );
- TEST_EQUAL( length, bytes2 );
+ psa_set_key_usage_flags(&derived_attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&derived_attributes, 0);
+ psa_set_key_type(&derived_attributes, PSA_KEY_TYPE_RAW_DATA);
+ psa_set_key_bits(&derived_attributes, PSA_BYTES_TO_BITS(bytes1));
+ PSA_ASSERT(psa_key_derivation_output_key(&derived_attributes, &operation,
+ &derived_key));
+ PSA_ASSERT(psa_export_key(derived_key,
+ export_buffer, bytes1,
+ &length));
+ TEST_EQUAL(length, bytes1);
+ PSA_ASSERT(psa_destroy_key(derived_key));
+ psa_set_key_bits(&derived_attributes, PSA_BYTES_TO_BITS(bytes2));
+ PSA_ASSERT(psa_key_derivation_output_key(&derived_attributes, &operation,
+ &derived_key));
+ PSA_ASSERT(psa_export_key(derived_key,
+ export_buffer + bytes1, bytes2,
+ &length));
+ TEST_EQUAL(length, bytes2);
/* Compare the outputs from the two runs. */
- ASSERT_COMPARE( output_buffer, bytes1 + bytes2,
- export_buffer, capacity );
+ ASSERT_COMPARE(output_buffer, bytes1 + bytes2,
+ export_buffer, capacity);
exit:
- mbedtls_free( output_buffer );
- mbedtls_free( export_buffer );
- psa_key_derivation_abort( &operation );
- psa_destroy_key( base_key );
- psa_destroy_key( derived_key );
- PSA_DONE( );
+ mbedtls_free(output_buffer);
+ mbedtls_free(export_buffer);
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(base_key);
+ psa_destroy_key(derived_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_key_type( int alg_arg,
- data_t *key_data,
- data_t *input1,
- data_t *input2,
- int key_type_arg, int bits_arg,
- data_t *expected_export )
+void derive_key_type(int alg_arg,
+ data_t *key_data,
+ data_t *input1,
+ data_t *input2,
+ int key_type_arg, int bits_arg,
+ data_t *expected_export)
{
mbedtls_svc_key_id_t base_key = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t derived_key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -8080,56 +7883,57 @@
const size_t bits = bits_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
const size_t export_buffer_size =
- PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, bits );
+ PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, bits);
uint8_t *export_buffer = NULL;
psa_key_attributes_t base_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t derived_attributes = PSA_KEY_ATTRIBUTES_INIT;
size_t export_length;
- ASSERT_ALLOC( export_buffer, export_buffer_size );
- PSA_ASSERT( psa_crypto_init( ) );
+ ASSERT_ALLOC(export_buffer, export_buffer_size);
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &base_attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &base_attributes, alg );
- psa_set_key_type( &base_attributes, PSA_KEY_TYPE_DERIVE );
- PSA_ASSERT( psa_import_key( &base_attributes, key_data->x, key_data->len,
- &base_key ) );
+ psa_set_key_usage_flags(&base_attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&base_attributes, alg);
+ psa_set_key_type(&base_attributes, PSA_KEY_TYPE_DERIVE);
+ PSA_ASSERT(psa_import_key(&base_attributes, key_data->x, key_data->len,
+ &base_key));
- if( mbedtls_test_psa_setup_key_derivation_wrap(
+ if (mbedtls_test_psa_setup_key_derivation_wrap(
&operation, base_key, alg,
input1->x, input1->len,
input2->x, input2->len,
- PSA_KEY_DERIVATION_UNLIMITED_CAPACITY ) == 0 )
+ PSA_KEY_DERIVATION_UNLIMITED_CAPACITY) == 0) {
goto exit;
+ }
- psa_set_key_usage_flags( &derived_attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &derived_attributes, 0 );
- psa_set_key_type( &derived_attributes, key_type );
- psa_set_key_bits( &derived_attributes, bits );
- PSA_ASSERT( psa_key_derivation_output_key( &derived_attributes, &operation,
- &derived_key ) );
+ psa_set_key_usage_flags(&derived_attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&derived_attributes, 0);
+ psa_set_key_type(&derived_attributes, key_type);
+ psa_set_key_bits(&derived_attributes, bits);
+ PSA_ASSERT(psa_key_derivation_output_key(&derived_attributes, &operation,
+ &derived_key));
- PSA_ASSERT( psa_export_key( derived_key,
- export_buffer, export_buffer_size,
- &export_length ) );
- ASSERT_COMPARE( export_buffer, export_length,
- expected_export->x, expected_export->len );
+ PSA_ASSERT(psa_export_key(derived_key,
+ export_buffer, export_buffer_size,
+ &export_length));
+ ASSERT_COMPARE(export_buffer, export_length,
+ expected_export->x, expected_export->len);
exit:
- mbedtls_free( export_buffer );
- psa_key_derivation_abort( &operation );
- psa_destroy_key( base_key );
- psa_destroy_key( derived_key );
- PSA_DONE( );
+ mbedtls_free(export_buffer);
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(base_key);
+ psa_destroy_key(derived_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void derive_key( int alg_arg,
- data_t *key_data, data_t *input1, data_t *input2,
- int type_arg, int bits_arg,
- int expected_status_arg,
- int is_large_output )
+void derive_key(int alg_arg,
+ data_t *key_data, data_t *input1, data_t *input2,
+ int type_arg, int bits_arg,
+ int expected_status_arg,
+ int is_large_output)
{
mbedtls_svc_key_id_t base_key = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t derived_key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -8141,46 +7945,48 @@
psa_key_attributes_t base_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t derived_attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &base_attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &base_attributes, alg );
- psa_set_key_type( &base_attributes, PSA_KEY_TYPE_DERIVE );
- PSA_ASSERT( psa_import_key( &base_attributes, key_data->x, key_data->len,
- &base_key ) );
+ psa_set_key_usage_flags(&base_attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&base_attributes, alg);
+ psa_set_key_type(&base_attributes, PSA_KEY_TYPE_DERIVE);
+ PSA_ASSERT(psa_import_key(&base_attributes, key_data->x, key_data->len,
+ &base_key));
- if( !mbedtls_test_psa_setup_key_derivation_wrap( &operation, base_key, alg,
- input1->x, input1->len,
- input2->x, input2->len,
- SIZE_MAX ) )
+ if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, base_key, alg,
+ input1->x, input1->len,
+ input2->x, input2->len,
+ SIZE_MAX)) {
goto exit;
+ }
- psa_set_key_usage_flags( &derived_attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &derived_attributes, 0 );
- psa_set_key_type( &derived_attributes, type );
- psa_set_key_bits( &derived_attributes, bits );
+ psa_set_key_usage_flags(&derived_attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&derived_attributes, 0);
+ psa_set_key_type(&derived_attributes, type);
+ psa_set_key_bits(&derived_attributes, bits);
psa_status_t status =
- psa_key_derivation_output_key( &derived_attributes,
- &operation,
- &derived_key );
- if( is_large_output > 0 )
- TEST_ASSUME( status != PSA_ERROR_INSUFFICIENT_MEMORY );
- TEST_EQUAL( status, expected_status );
+ psa_key_derivation_output_key(&derived_attributes,
+ &operation,
+ &derived_key);
+ if (is_large_output > 0) {
+ TEST_ASSUME(status != PSA_ERROR_INSUFFICIENT_MEMORY);
+ }
+ TEST_EQUAL(status, expected_status);
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( base_key );
- psa_destroy_key( derived_key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(base_key);
+ psa_destroy_key(derived_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_agreement_setup( int alg_arg,
- int our_key_type_arg, int our_key_alg_arg,
- data_t *our_key_data, data_t *peer_key_data,
- int expected_status_arg )
+void key_agreement_setup(int alg_arg,
+ int our_key_type_arg, int our_key_alg_arg,
+ data_t *our_key_data, data_t *peer_key_data,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t our_key = MBEDTLS_SVC_KEY_ID_INIT;
psa_algorithm_t alg = alg_arg;
@@ -8191,45 +7997,42 @@
psa_status_t expected_status = expected_status_arg;
psa_status_t status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, our_key_alg );
- psa_set_key_type( &attributes, our_key_type );
- PSA_ASSERT( psa_import_key( &attributes,
- our_key_data->x, our_key_data->len,
- &our_key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, our_key_alg);
+ psa_set_key_type(&attributes, our_key_type);
+ PSA_ASSERT(psa_import_key(&attributes,
+ our_key_data->x, our_key_data->len,
+ &our_key));
/* The tests currently include inputs that should fail at either step.
* Test cases that fail at the setup step should be changed to call
* key_derivation_setup instead, and this function should be renamed
* to key_agreement_fail. */
- status = psa_key_derivation_setup( &operation, alg );
- if( status == PSA_SUCCESS )
- {
- TEST_EQUAL( psa_key_derivation_key_agreement(
- &operation, PSA_KEY_DERIVATION_INPUT_SECRET,
- our_key,
- peer_key_data->x, peer_key_data->len ),
- expected_status );
- }
- else
- {
- TEST_ASSERT( status == expected_status );
+ status = psa_key_derivation_setup(&operation, alg);
+ if (status == PSA_SUCCESS) {
+ TEST_EQUAL(psa_key_derivation_key_agreement(
+ &operation, PSA_KEY_DERIVATION_INPUT_SECRET,
+ our_key,
+ peer_key_data->x, peer_key_data->len),
+ expected_status);
+ } else {
+ TEST_ASSERT(status == expected_status);
}
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( our_key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(our_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void raw_key_agreement( int alg_arg,
- int our_key_type_arg, data_t *our_key_data,
- data_t *peer_key_data,
- data_t *expected_output )
+void raw_key_agreement(int alg_arg,
+ int our_key_type_arg, data_t *our_key_data,
+ data_t *peer_key_data,
+ data_t *expected_output)
{
mbedtls_svc_key_id_t our_key = MBEDTLS_SVC_KEY_ID_INIT;
psa_algorithm_t alg = alg_arg;
@@ -8239,72 +8042,72 @@
size_t output_length = ~0;
size_t key_bits;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, our_key_type );
- PSA_ASSERT( psa_import_key( &attributes,
- our_key_data->x, our_key_data->len,
- &our_key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, our_key_type);
+ PSA_ASSERT(psa_import_key(&attributes,
+ our_key_data->x, our_key_data->len,
+ &our_key));
- PSA_ASSERT( psa_get_key_attributes( our_key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(our_key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
/* Validate size macros */
- TEST_LE_U( expected_output->len,
- PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( our_key_type, key_bits ) );
- TEST_LE_U( PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( our_key_type, key_bits ),
- PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE );
+ TEST_LE_U(expected_output->len,
+ PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(our_key_type, key_bits));
+ TEST_LE_U(PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(our_key_type, key_bits),
+ PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE);
/* Good case with exact output size */
- ASSERT_ALLOC( output, expected_output->len );
- PSA_ASSERT( psa_raw_key_agreement( alg, our_key,
- peer_key_data->x, peer_key_data->len,
- output, expected_output->len,
- &output_length ) );
- ASSERT_COMPARE( output, output_length,
- expected_output->x, expected_output->len );
- mbedtls_free( output );
+ ASSERT_ALLOC(output, expected_output->len);
+ PSA_ASSERT(psa_raw_key_agreement(alg, our_key,
+ peer_key_data->x, peer_key_data->len,
+ output, expected_output->len,
+ &output_length));
+ ASSERT_COMPARE(output, output_length,
+ expected_output->x, expected_output->len);
+ mbedtls_free(output);
output = NULL;
output_length = ~0;
/* Larger buffer */
- ASSERT_ALLOC( output, expected_output->len + 1 );
- PSA_ASSERT( psa_raw_key_agreement( alg, our_key,
- peer_key_data->x, peer_key_data->len,
- output, expected_output->len + 1,
- &output_length ) );
- ASSERT_COMPARE( output, output_length,
- expected_output->x, expected_output->len );
- mbedtls_free( output );
+ ASSERT_ALLOC(output, expected_output->len + 1);
+ PSA_ASSERT(psa_raw_key_agreement(alg, our_key,
+ peer_key_data->x, peer_key_data->len,
+ output, expected_output->len + 1,
+ &output_length));
+ ASSERT_COMPARE(output, output_length,
+ expected_output->x, expected_output->len);
+ mbedtls_free(output);
output = NULL;
output_length = ~0;
/* Buffer too small */
- ASSERT_ALLOC( output, expected_output->len - 1 );
- TEST_EQUAL( psa_raw_key_agreement( alg, our_key,
- peer_key_data->x, peer_key_data->len,
- output, expected_output->len - 1,
- &output_length ),
- PSA_ERROR_BUFFER_TOO_SMALL );
+ ASSERT_ALLOC(output, expected_output->len - 1);
+ TEST_EQUAL(psa_raw_key_agreement(alg, our_key,
+ peer_key_data->x, peer_key_data->len,
+ output, expected_output->len - 1,
+ &output_length),
+ PSA_ERROR_BUFFER_TOO_SMALL);
/* Not required by the spec, but good robustness */
- TEST_LE_U( output_length, expected_output->len - 1 );
- mbedtls_free( output );
+ TEST_LE_U(output_length, expected_output->len - 1);
+ mbedtls_free(output);
output = NULL;
exit:
- mbedtls_free( output );
- psa_destroy_key( our_key );
- PSA_DONE( );
+ mbedtls_free(output);
+ psa_destroy_key(our_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_agreement_capacity( int alg_arg,
- int our_key_type_arg, data_t *our_key_data,
- data_t *peer_key_data,
- int expected_capacity_arg )
+void key_agreement_capacity(int alg_arg,
+ int our_key_type_arg, data_t *our_key_data,
+ data_t *peer_key_data,
+ int expected_capacity_arg)
{
mbedtls_svc_key_id_t our_key = MBEDTLS_SVC_KEY_ID_INIT;
psa_algorithm_t alg = alg_arg;
@@ -8314,57 +8117,55 @@
size_t actual_capacity;
unsigned char output[16];
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, our_key_type );
- PSA_ASSERT( psa_import_key( &attributes,
- our_key_data->x, our_key_data->len,
- &our_key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, our_key_type);
+ PSA_ASSERT(psa_import_key(&attributes,
+ our_key_data->x, our_key_data->len,
+ &our_key));
- PSA_ASSERT( psa_key_derivation_setup( &operation, alg ) );
- PSA_ASSERT( psa_key_derivation_key_agreement(
- &operation,
- PSA_KEY_DERIVATION_INPUT_SECRET, our_key,
- peer_key_data->x, peer_key_data->len ) );
- if( PSA_ALG_IS_HKDF( PSA_ALG_KEY_AGREEMENT_GET_KDF( alg ) ) )
- {
+ PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
+ PSA_ASSERT(psa_key_derivation_key_agreement(
+ &operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET, our_key,
+ peer_key_data->x, peer_key_data->len));
+ if (PSA_ALG_IS_HKDF(PSA_ALG_KEY_AGREEMENT_GET_KDF(alg))) {
/* The test data is for info="" */
- PSA_ASSERT( psa_key_derivation_input_bytes( &operation,
- PSA_KEY_DERIVATION_INPUT_INFO,
- NULL, 0 ) );
+ PSA_ASSERT(psa_key_derivation_input_bytes(&operation,
+ PSA_KEY_DERIVATION_INPUT_INFO,
+ NULL, 0));
}
/* Test the advertised capacity. */
- PSA_ASSERT( psa_key_derivation_get_capacity(
- &operation, &actual_capacity ) );
- TEST_EQUAL( actual_capacity, (size_t) expected_capacity_arg );
+ PSA_ASSERT(psa_key_derivation_get_capacity(
+ &operation, &actual_capacity));
+ TEST_EQUAL(actual_capacity, (size_t) expected_capacity_arg);
/* Test the actual capacity by reading the output. */
- while( actual_capacity > sizeof( output ) )
- {
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- output, sizeof( output ) ) );
- actual_capacity -= sizeof( output );
+ while (actual_capacity > sizeof(output)) {
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output, sizeof(output)));
+ actual_capacity -= sizeof(output);
}
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- output, actual_capacity ) );
- TEST_EQUAL( psa_key_derivation_output_bytes( &operation, output, 1 ),
- PSA_ERROR_INSUFFICIENT_DATA );
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ output, actual_capacity));
+ TEST_EQUAL(psa_key_derivation_output_bytes(&operation, output, 1),
+ PSA_ERROR_INSUFFICIENT_DATA);
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( our_key );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(our_key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_agreement_output( int alg_arg,
- int our_key_type_arg, data_t *our_key_data,
- data_t *peer_key_data,
- data_t *expected_output1, data_t *expected_output2 )
+void key_agreement_output(int alg_arg,
+ int our_key_type_arg, data_t *our_key_data,
+ data_t *peer_key_data,
+ data_t *expected_output1, data_t *expected_output2)
{
mbedtls_svc_key_id_t our_key = MBEDTLS_SVC_KEY_ID_INIT;
psa_algorithm_t alg = alg_arg;
@@ -8373,55 +8174,53 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *actual_output = NULL;
- ASSERT_ALLOC( actual_output, MAX( expected_output1->len,
- expected_output2->len ) );
+ ASSERT_ALLOC(actual_output, MAX(expected_output1->len,
+ expected_output2->len));
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, our_key_type );
- PSA_ASSERT( psa_import_key( &attributes,
- our_key_data->x, our_key_data->len,
- &our_key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, our_key_type);
+ PSA_ASSERT(psa_import_key(&attributes,
+ our_key_data->x, our_key_data->len,
+ &our_key));
- PSA_ASSERT( psa_key_derivation_setup( &operation, alg ) );
- PSA_ASSERT( psa_key_derivation_key_agreement(
- &operation,
- PSA_KEY_DERIVATION_INPUT_SECRET, our_key,
- peer_key_data->x, peer_key_data->len ) );
- if( PSA_ALG_IS_HKDF( PSA_ALG_KEY_AGREEMENT_GET_KDF( alg ) ) )
- {
+ PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
+ PSA_ASSERT(psa_key_derivation_key_agreement(
+ &operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET, our_key,
+ peer_key_data->x, peer_key_data->len));
+ if (PSA_ALG_IS_HKDF(PSA_ALG_KEY_AGREEMENT_GET_KDF(alg))) {
/* The test data is for info="" */
- PSA_ASSERT( psa_key_derivation_input_bytes( &operation,
- PSA_KEY_DERIVATION_INPUT_INFO,
- NULL, 0 ) );
+ PSA_ASSERT(psa_key_derivation_input_bytes(&operation,
+ PSA_KEY_DERIVATION_INPUT_INFO,
+ NULL, 0));
}
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- actual_output,
- expected_output1->len ) );
- ASSERT_COMPARE( actual_output, expected_output1->len,
- expected_output1->x, expected_output1->len );
- if( expected_output2->len != 0 )
- {
- PSA_ASSERT( psa_key_derivation_output_bytes( &operation,
- actual_output,
- expected_output2->len ) );
- ASSERT_COMPARE( actual_output, expected_output2->len,
- expected_output2->x, expected_output2->len );
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ actual_output,
+ expected_output1->len));
+ ASSERT_COMPARE(actual_output, expected_output1->len,
+ expected_output1->x, expected_output1->len);
+ if (expected_output2->len != 0) {
+ PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
+ actual_output,
+ expected_output2->len));
+ ASSERT_COMPARE(actual_output, expected_output2->len,
+ expected_output2->x, expected_output2->len);
}
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( our_key );
- PSA_DONE( );
- mbedtls_free( actual_output );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(our_key);
+ PSA_DONE();
+ mbedtls_free(actual_output);
}
/* END_CASE */
/* BEGIN_CASE */
-void generate_random( int bytes_arg )
+void generate_random(int bytes_arg)
{
size_t bytes = bytes_arg;
unsigned char *output = NULL;
@@ -8429,51 +8228,50 @@
size_t i;
unsigned run;
- TEST_ASSERT( bytes_arg >= 0 );
+ TEST_ASSERT(bytes_arg >= 0);
- ASSERT_ALLOC( output, bytes );
- ASSERT_ALLOC( changed, bytes );
+ ASSERT_ALLOC(output, bytes);
+ ASSERT_ALLOC(changed, bytes);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Run several times, to ensure that every output byte will be
* nonzero at least once with overwhelming probability
* (2^(-8*number_of_runs)). */
- for( run = 0; run < 10; run++ )
- {
- if( bytes != 0 )
- memset( output, 0, bytes );
- PSA_ASSERT( psa_generate_random( output, bytes ) );
+ for (run = 0; run < 10; run++) {
+ if (bytes != 0) {
+ memset(output, 0, bytes);
+ }
+ PSA_ASSERT(psa_generate_random(output, bytes));
- for( i = 0; i < bytes; i++ )
- {
- if( output[i] != 0 )
+ for (i = 0; i < bytes; i++) {
+ if (output[i] != 0) {
++changed[i];
+ }
}
}
/* Check that every byte was changed to nonzero at least once. This
* validates that psa_generate_random is overwriting every byte of
* the output buffer. */
- for( i = 0; i < bytes; i++ )
- {
- TEST_ASSERT( changed[i] != 0 );
+ for (i = 0; i < bytes; i++) {
+ TEST_ASSERT(changed[i] != 0);
}
exit:
- PSA_DONE( );
- mbedtls_free( output );
- mbedtls_free( changed );
+ PSA_DONE();
+ mbedtls_free(output);
+ mbedtls_free(changed);
}
/* END_CASE */
/* BEGIN_CASE */
-void generate_key( int type_arg,
- int bits_arg,
- int usage_arg,
- int alg_arg,
- int expected_status_arg,
- int is_large_key )
+void generate_key(int type_arg,
+ int bits_arg,
+ int usage_arg,
+ int alg_arg,
+ int expected_status_arg,
+ int is_large_key)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t type = type_arg;
@@ -8484,47 +8282,50 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
/* Generate a key */
- psa_status_t status = psa_generate_key( &attributes, &key );
+ psa_status_t status = psa_generate_key(&attributes, &key);
- if( is_large_key > 0 )
- TEST_ASSUME( status != PSA_ERROR_INSUFFICIENT_MEMORY );
- TEST_EQUAL( status , expected_status );
- if( expected_status != PSA_SUCCESS )
+ if (is_large_key > 0) {
+ TEST_ASSUME(status != PSA_ERROR_INSUFFICIENT_MEMORY);
+ }
+ TEST_EQUAL(status, expected_status);
+ if (expected_status != PSA_SUCCESS) {
goto exit;
+ }
/* Test the key information */
- PSA_ASSERT( psa_get_key_attributes( key, &got_attributes ) );
- TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &got_attributes ), bits );
+ PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
+ TEST_EQUAL(psa_get_key_type(&got_attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&got_attributes), bits);
/* Do something with the key according to its type and permitted usage. */
- if( ! mbedtls_test_psa_exercise_key( key, usage, alg ) )
+ if (!mbedtls_test_psa_exercise_key(key, usage, alg)) {
goto exit;
+ }
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &got_attributes );
+ psa_reset_key_attributes(&got_attributes);
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_KEY_TYPE_RSA_KEY_PAIR:PSA_WANT_ALG_RSA_PKCS1V15_CRYPT:PSA_WANT_ALG_RSA_PKCS1V15_SIGN:MBEDTLS_GENPRIME */
-void generate_key_rsa( int bits_arg,
- data_t *e_arg,
- int expected_status_arg )
+void generate_key_rsa(int bits_arg,
+ data_t *e_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t type = PSA_KEY_TYPE_RSA_KEY_PAIR;
@@ -8535,56 +8336,58 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *exported = NULL;
size_t exported_size =
- PSA_EXPORT_KEY_OUTPUT_SIZE( PSA_KEY_TYPE_RSA_PUBLIC_KEY, bits );
+ PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_KEY_TYPE_RSA_PUBLIC_KEY, bits);
size_t exported_length = SIZE_MAX;
uint8_t *e_read_buffer = NULL;
int is_default_public_exponent = 0;
- size_t e_read_size = PSA_KEY_DOMAIN_PARAMETERS_SIZE( type, bits );
+ size_t e_read_size = PSA_KEY_DOMAIN_PARAMETERS_SIZE(type, bits);
size_t e_read_length = SIZE_MAX;
- if( e_arg->len == 0 ||
- ( e_arg->len == 3 &&
- e_arg->x[0] == 1 && e_arg->x[1] == 0 && e_arg->x[2] == 1 ) )
- {
+ if (e_arg->len == 0 ||
+ (e_arg->len == 3 &&
+ e_arg->x[0] == 1 && e_arg->x[1] == 0 && e_arg->x[2] == 1)) {
is_default_public_exponent = 1;
e_read_size = 0;
}
- ASSERT_ALLOC( e_read_buffer, e_read_size );
- ASSERT_ALLOC( exported, exported_size );
+ ASSERT_ALLOC(e_read_buffer, e_read_size);
+ ASSERT_ALLOC(exported, exported_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
- PSA_ASSERT( psa_set_key_domain_parameters( &attributes, type,
- e_arg->x, e_arg->len ) );
- psa_set_key_bits( &attributes, bits );
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
+ PSA_ASSERT(psa_set_key_domain_parameters(&attributes, type,
+ e_arg->x, e_arg->len));
+ psa_set_key_bits(&attributes, bits);
/* Generate a key */
- TEST_EQUAL( psa_generate_key( &attributes, &key ), expected_status );
- if( expected_status != PSA_SUCCESS )
+ TEST_EQUAL(psa_generate_key(&attributes, &key), expected_status);
+ if (expected_status != PSA_SUCCESS) {
goto exit;
+ }
/* Test the key information */
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &attributes ), bits );
- PSA_ASSERT( psa_get_key_domain_parameters( &attributes,
- e_read_buffer, e_read_size,
- &e_read_length ) );
- if( is_default_public_exponent )
- TEST_EQUAL( e_read_length, 0 );
- else
- ASSERT_COMPARE( e_read_buffer, e_read_length, e_arg->x, e_arg->len );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&attributes), bits);
+ PSA_ASSERT(psa_get_key_domain_parameters(&attributes,
+ e_read_buffer, e_read_size,
+ &e_read_length));
+ if (is_default_public_exponent) {
+ TEST_EQUAL(e_read_length, 0);
+ } else {
+ ASSERT_COMPARE(e_read_buffer, e_read_length, e_arg->x, e_arg->len);
+ }
/* Do something with the key according to its type and permitted usage. */
- if( ! mbedtls_test_psa_exercise_key( key, usage, alg ) )
+ if (!mbedtls_test_psa_exercise_key(key, usage, alg)) {
goto exit;
+ }
/* Export the key and check the public exponent. */
- PSA_ASSERT( psa_export_public_key( key,
- exported, exported_size,
- &exported_length ) );
+ PSA_ASSERT(psa_export_public_key(key,
+ exported, exported_size,
+ &exported_length));
{
uint8_t *p = exported;
uint8_t *end = exported + exported_length;
@@ -8593,26 +8396,24 @@
* modulus INTEGER, -- n
* publicExponent INTEGER } -- e
*/
- TEST_EQUAL( 0, mbedtls_asn1_get_tag( &p, end, &len,
- MBEDTLS_ASN1_SEQUENCE |
- MBEDTLS_ASN1_CONSTRUCTED ) );
- TEST_ASSERT( mbedtls_test_asn1_skip_integer( &p, end, bits, bits, 1 ) );
- TEST_EQUAL( 0, mbedtls_asn1_get_tag( &p, end, &len,
- MBEDTLS_ASN1_INTEGER ) );
- if( len >= 1 && p[0] == 0 )
- {
+ TEST_EQUAL(0, mbedtls_asn1_get_tag(&p, end, &len,
+ MBEDTLS_ASN1_SEQUENCE |
+ MBEDTLS_ASN1_CONSTRUCTED));
+ TEST_ASSERT(mbedtls_test_asn1_skip_integer(&p, end, bits, bits, 1));
+ TEST_EQUAL(0, mbedtls_asn1_get_tag(&p, end, &len,
+ MBEDTLS_ASN1_INTEGER));
+ if (len >= 1 && p[0] == 0) {
++p;
--len;
}
- if( e_arg->len == 0 )
- {
- TEST_EQUAL( len, 3 );
- TEST_EQUAL( p[0], 1 );
- TEST_EQUAL( p[1], 0 );
- TEST_EQUAL( p[2], 1 );
+ if (e_arg->len == 0) {
+ TEST_EQUAL(len, 3);
+ TEST_EQUAL(p[0], 1);
+ TEST_EQUAL(p[1], 0);
+ TEST_EQUAL(p[2], 1);
+ } else {
+ ASSERT_COMPARE(p, len, e_arg->x, e_arg->len);
}
- else
- ASSERT_COMPARE( p, len, e_arg->x, e_arg->len );
}
exit:
@@ -8620,22 +8421,22 @@
* Key attributes may have been returned by psa_get_key_attributes() or
* set by psa_set_key_domain_parameters() thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( e_read_buffer );
- mbedtls_free( exported );
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(e_read_buffer);
+ mbedtls_free(exported);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */
-void persistent_key_load_key_from_storage( data_t *data,
- int type_arg, int bits_arg,
- int usage_flags_arg, int alg_arg,
- int generation_method )
+void persistent_key_load_key_from_storage(data_t *data,
+ int type_arg, int bits_arg,
+ int usage_flags_arg, int alg_arg,
+ int generation_method)
{
- mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 1, 1 );
+ mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make(1, 1);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t base_key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -8646,140 +8447,138 @@
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
unsigned char *first_export = NULL;
unsigned char *second_export = NULL;
- size_t export_size = PSA_EXPORT_KEY_OUTPUT_SIZE( type, bits );
+ size_t export_size = PSA_EXPORT_KEY_OUTPUT_SIZE(type, bits);
size_t first_exported_length;
size_t second_exported_length;
- if( usage_flags & PSA_KEY_USAGE_EXPORT )
- {
- ASSERT_ALLOC( first_export, export_size );
- ASSERT_ALLOC( second_export, export_size );
+ if (usage_flags & PSA_KEY_USAGE_EXPORT) {
+ ASSERT_ALLOC(first_export, export_size);
+ ASSERT_ALLOC(second_export, export_size);
}
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, key_id );
- psa_set_key_usage_flags( &attributes, usage_flags );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_usage_flags(&attributes, usage_flags);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
- switch( generation_method )
- {
+ switch (generation_method) {
case IMPORT_KEY:
/* Import the key */
- PSA_ASSERT( psa_import_key( &attributes, data->x, data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, data->x, data->len,
+ &key));
break;
case GENERATE_KEY:
/* Generate a key */
- PSA_ASSERT( psa_generate_key( &attributes, &key ) );
+ PSA_ASSERT(psa_generate_key(&attributes, &key));
break;
case DERIVE_KEY:
#if defined(PSA_WANT_ALG_HKDF) && defined(PSA_WANT_ALG_SHA_256)
- {
- /* Create base key */
- psa_algorithm_t derive_alg = PSA_ALG_HKDF( PSA_ALG_SHA_256 );
- psa_key_attributes_t base_attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_set_key_usage_flags( &base_attributes,
- PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &base_attributes, derive_alg );
- psa_set_key_type( &base_attributes, PSA_KEY_TYPE_DERIVE );
- PSA_ASSERT( psa_import_key( &base_attributes,
- data->x, data->len,
- &base_key ) );
- /* Derive a key. */
- PSA_ASSERT( psa_key_derivation_setup( &operation, derive_alg ) );
- PSA_ASSERT( psa_key_derivation_input_key(
- &operation,
- PSA_KEY_DERIVATION_INPUT_SECRET, base_key ) );
- PSA_ASSERT( psa_key_derivation_input_bytes(
- &operation, PSA_KEY_DERIVATION_INPUT_INFO,
- NULL, 0 ) );
- PSA_ASSERT( psa_key_derivation_output_key( &attributes,
- &operation,
- &key ) );
- PSA_ASSERT( psa_key_derivation_abort( &operation ) );
- PSA_ASSERT( psa_destroy_key( base_key ) );
- base_key = MBEDTLS_SVC_KEY_ID_INIT;
- }
+ {
+ /* Create base key */
+ psa_algorithm_t derive_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256);
+ psa_key_attributes_t base_attributes = PSA_KEY_ATTRIBUTES_INIT;
+ psa_set_key_usage_flags(&base_attributes,
+ PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&base_attributes, derive_alg);
+ psa_set_key_type(&base_attributes, PSA_KEY_TYPE_DERIVE);
+ PSA_ASSERT(psa_import_key(&base_attributes,
+ data->x, data->len,
+ &base_key));
+ /* Derive a key. */
+ PSA_ASSERT(psa_key_derivation_setup(&operation, derive_alg));
+ PSA_ASSERT(psa_key_derivation_input_key(
+ &operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET, base_key));
+ PSA_ASSERT(psa_key_derivation_input_bytes(
+ &operation, PSA_KEY_DERIVATION_INPUT_INFO,
+ NULL, 0));
+ PSA_ASSERT(psa_key_derivation_output_key(&attributes,
+ &operation,
+ &key));
+ PSA_ASSERT(psa_key_derivation_abort(&operation));
+ PSA_ASSERT(psa_destroy_key(base_key));
+ base_key = MBEDTLS_SVC_KEY_ID_INIT;
+ }
#else
- TEST_ASSUME( ! "KDF not supported in this configuration" );
+ TEST_ASSUME(!"KDF not supported in this configuration");
#endif
break;
default:
- TEST_ASSERT( ! "generation_method not implemented in test" );
+ TEST_ASSERT(!"generation_method not implemented in test");
break;
}
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
/* Export the key if permitted by the key policy. */
- if( usage_flags & PSA_KEY_USAGE_EXPORT )
- {
- PSA_ASSERT( psa_export_key( key,
- first_export, export_size,
- &first_exported_length ) );
- if( generation_method == IMPORT_KEY )
- ASSERT_COMPARE( data->x, data->len,
- first_export, first_exported_length );
+ if (usage_flags & PSA_KEY_USAGE_EXPORT) {
+ PSA_ASSERT(psa_export_key(key,
+ first_export, export_size,
+ &first_exported_length));
+ if (generation_method == IMPORT_KEY) {
+ ASSERT_COMPARE(data->x, data->len,
+ first_export, first_exported_length);
+ }
}
/* Shutdown and restart */
- PSA_ASSERT( psa_purge_key( key ) );
+ PSA_ASSERT(psa_purge_key(key));
PSA_DONE();
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
/* Check key slot still contains key data */
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ), key_id ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ),
- PSA_KEY_LIFETIME_PERSISTENT );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &attributes ), bits );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ),
- mbedtls_test_update_key_usage_flags( usage_flags ) );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), alg );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes), key_id));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes),
+ PSA_KEY_LIFETIME_PERSISTENT);
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&attributes), bits);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes),
+ mbedtls_test_update_key_usage_flags(usage_flags));
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), alg);
/* Export the key again if permitted by the key policy. */
- if( usage_flags & PSA_KEY_USAGE_EXPORT )
- {
- PSA_ASSERT( psa_export_key( key,
- second_export, export_size,
- &second_exported_length ) );
- ASSERT_COMPARE( first_export, first_exported_length,
- second_export, second_exported_length );
+ if (usage_flags & PSA_KEY_USAGE_EXPORT) {
+ PSA_ASSERT(psa_export_key(key,
+ second_export, export_size,
+ &second_exported_length));
+ ASSERT_COMPARE(first_export, first_exported_length,
+ second_export, second_exported_length);
}
/* Do something with the key according to its type and permitted usage. */
- if( ! mbedtls_test_psa_exercise_key( key, usage_flags, alg ) )
+ if (!mbedtls_test_psa_exercise_key(key, usage_flags, alg)) {
goto exit;
+ }
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_free( first_export );
- mbedtls_free( second_export );
- psa_key_derivation_abort( &operation );
- psa_destroy_key( base_key );
- psa_destroy_key( key );
+ mbedtls_free(first_export);
+ mbedtls_free(second_export);
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(base_key);
+ psa_destroy_key(key);
PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
-void ecjpake_setup( int alg_arg, int key_type_pw_arg, int key_usage_pw_arg,
- int primitive_arg, int hash_arg, int role_arg,
- int test_input, data_t *pw_data,
- int inj_err_type_arg,
- int expected_error_arg)
+void ecjpake_setup(int alg_arg, int key_type_pw_arg, int key_usage_pw_arg,
+ int primitive_arg, int hash_arg, int role_arg,
+ int test_input, data_t *pw_data,
+ int inj_err_type_arg,
+ int expected_error_arg)
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t operation = psa_pake_operation_init();
@@ -8797,237 +8596,213 @@
unsigned char *output_buffer = NULL;
size_t output_len = 0;
- PSA_INIT( );
+ PSA_INIT();
size_t buf_size = PSA_PAKE_OUTPUT_SIZE(alg, primitive_arg,
- PSA_PAKE_STEP_KEY_SHARE);
- ASSERT_ALLOC( output_buffer, buf_size );
+ PSA_PAKE_STEP_KEY_SHARE);
+ ASSERT_ALLOC(output_buffer, buf_size);
- if( pw_data->len > 0 )
- {
- psa_set_key_usage_flags( &attributes, key_usage_pw );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type_pw );
- PSA_ASSERT( psa_import_key( &attributes, pw_data->x, pw_data->len,
- &key ) );
+ if (pw_data->len > 0) {
+ psa_set_key_usage_flags(&attributes, key_usage_pw);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type_pw);
+ PSA_ASSERT(psa_import_key(&attributes, pw_data->x, pw_data->len,
+ &key));
}
- psa_pake_cs_set_algorithm( &cipher_suite, alg );
- psa_pake_cs_set_primitive( &cipher_suite, primitive );
- psa_pake_cs_set_hash( &cipher_suite, hash_alg );
+ psa_pake_cs_set_algorithm(&cipher_suite, alg);
+ psa_pake_cs_set_primitive(&cipher_suite, primitive);
+ psa_pake_cs_set_hash(&cipher_suite, hash_alg);
- PSA_ASSERT( psa_pake_abort( &operation ) );
+ PSA_ASSERT(psa_pake_abort(&operation));
- if ( inj_err_type == INJECT_ERR_UNINITIALIZED_ACCESS )
- {
- TEST_EQUAL( psa_pake_set_user( &operation, NULL, 0 ),
- expected_error );
- PSA_ASSERT( psa_pake_abort( &operation ) );
- TEST_EQUAL( psa_pake_set_peer( &operation, NULL, 0 ),
- expected_error );
- PSA_ASSERT( psa_pake_abort( &operation ) );
- TEST_EQUAL( psa_pake_set_password_key( &operation, key ),
- expected_error );
- PSA_ASSERT( psa_pake_abort( &operation ) );
- TEST_EQUAL( psa_pake_set_role( &operation, role ),
- expected_error );
- PSA_ASSERT( psa_pake_abort( &operation ) );
- TEST_EQUAL( psa_pake_output( &operation, PSA_PAKE_STEP_KEY_SHARE,
- NULL, 0, NULL ),
- expected_error );
- PSA_ASSERT( psa_pake_abort( &operation ) );
- TEST_EQUAL( psa_pake_input( &operation, PSA_PAKE_STEP_KEY_SHARE, NULL, 0),
- expected_error );
- PSA_ASSERT( psa_pake_abort( &operation ) );
+ if (inj_err_type == INJECT_ERR_UNINITIALIZED_ACCESS) {
+ TEST_EQUAL(psa_pake_set_user(&operation, NULL, 0),
+ expected_error);
+ PSA_ASSERT(psa_pake_abort(&operation));
+ TEST_EQUAL(psa_pake_set_peer(&operation, NULL, 0),
+ expected_error);
+ PSA_ASSERT(psa_pake_abort(&operation));
+ TEST_EQUAL(psa_pake_set_password_key(&operation, key),
+ expected_error);
+ PSA_ASSERT(psa_pake_abort(&operation));
+ TEST_EQUAL(psa_pake_set_role(&operation, role),
+ expected_error);
+ PSA_ASSERT(psa_pake_abort(&operation));
+ TEST_EQUAL(psa_pake_output(&operation, PSA_PAKE_STEP_KEY_SHARE,
+ NULL, 0, NULL),
+ expected_error);
+ PSA_ASSERT(psa_pake_abort(&operation));
+ TEST_EQUAL(psa_pake_input(&operation, PSA_PAKE_STEP_KEY_SHARE, NULL, 0),
+ expected_error);
+ PSA_ASSERT(psa_pake_abort(&operation));
goto exit;
}
- status = psa_pake_setup( &operation, &cipher_suite );
- if (status != PSA_SUCCESS)
- {
- TEST_EQUAL( status, expected_error );
+ status = psa_pake_setup(&operation, &cipher_suite);
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_error);
goto exit;
}
- if( inj_err_type == INJECT_ERR_DUPLICATE_SETUP )
- {
- TEST_EQUAL( psa_pake_setup( &operation, &cipher_suite ),
- expected_error );
+ if (inj_err_type == INJECT_ERR_DUPLICATE_SETUP) {
+ TEST_EQUAL(psa_pake_setup(&operation, &cipher_suite),
+ expected_error);
goto exit;
}
- status = psa_pake_set_role( &operation, role);
- if ( status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_error );
+ status = psa_pake_set_role(&operation, role);
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_error);
goto exit;
}
- if( pw_data->len > 0 )
- {
- status = psa_pake_set_password_key( &operation, key );
- if ( status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_error );
+ if (pw_data->len > 0) {
+ status = psa_pake_set_password_key(&operation, key);
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_error);
goto exit;
}
}
- if ( inj_err_type == INJECT_ERR_INVALID_USER )
- {
- TEST_EQUAL( psa_pake_set_user( &operation, NULL, 0 ),
- PSA_ERROR_INVALID_ARGUMENT );
+ if (inj_err_type == INJECT_ERR_INVALID_USER) {
+ TEST_EQUAL(psa_pake_set_user(&operation, NULL, 0),
+ PSA_ERROR_INVALID_ARGUMENT);
goto exit;
}
- if ( inj_err_type == INJECT_ERR_INVALID_PEER )
- {
- TEST_EQUAL( psa_pake_set_peer( &operation, NULL, 0 ),
- PSA_ERROR_INVALID_ARGUMENT );
+ if (inj_err_type == INJECT_ERR_INVALID_PEER) {
+ TEST_EQUAL(psa_pake_set_peer(&operation, NULL, 0),
+ PSA_ERROR_INVALID_ARGUMENT);
goto exit;
}
- if ( inj_err_type == INJECT_ERR_SET_USER )
- {
+ if (inj_err_type == INJECT_ERR_SET_USER) {
const uint8_t unsupported_id[] = "abcd";
- TEST_EQUAL( psa_pake_set_user( &operation, unsupported_id, 4 ),
- PSA_ERROR_NOT_SUPPORTED );
+ TEST_EQUAL(psa_pake_set_user(&operation, unsupported_id, 4),
+ PSA_ERROR_NOT_SUPPORTED);
goto exit;
}
- if ( inj_err_type == INJECT_ERR_SET_PEER )
- {
+ if (inj_err_type == INJECT_ERR_SET_PEER) {
const uint8_t unsupported_id[] = "abcd";
- TEST_EQUAL( psa_pake_set_peer( &operation, unsupported_id, 4 ),
- PSA_ERROR_NOT_SUPPORTED );
+ TEST_EQUAL(psa_pake_set_peer(&operation, unsupported_id, 4),
+ PSA_ERROR_NOT_SUPPORTED);
goto exit;
}
- const size_t size_key_share = PSA_PAKE_INPUT_SIZE( alg, primitive,
- PSA_PAKE_STEP_KEY_SHARE );
- const size_t size_zk_public = PSA_PAKE_INPUT_SIZE( alg, primitive,
- PSA_PAKE_STEP_ZK_PUBLIC );
- const size_t size_zk_proof = PSA_PAKE_INPUT_SIZE( alg, primitive,
- PSA_PAKE_STEP_ZK_PROOF );
+ const size_t size_key_share = PSA_PAKE_INPUT_SIZE(alg, primitive,
+ PSA_PAKE_STEP_KEY_SHARE);
+ const size_t size_zk_public = PSA_PAKE_INPUT_SIZE(alg, primitive,
+ PSA_PAKE_STEP_ZK_PUBLIC);
+ const size_t size_zk_proof = PSA_PAKE_INPUT_SIZE(alg, primitive,
+ PSA_PAKE_STEP_ZK_PROOF);
- if ( test_input )
- {
- if ( inj_err_type == INJECT_EMPTY_IO_BUFFER )
- {
- TEST_EQUAL( psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PROOF, NULL, 0 ),
- PSA_ERROR_INVALID_ARGUMENT );
+ if (test_input) {
+ if (inj_err_type == INJECT_EMPTY_IO_BUFFER) {
+ TEST_EQUAL(psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PROOF, NULL, 0),
+ PSA_ERROR_INVALID_ARGUMENT);
goto exit;
}
- if ( inj_err_type == INJECT_UNKNOWN_STEP )
- {
- TEST_EQUAL( psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PROOF + 10,
- output_buffer, size_zk_proof ),
- PSA_ERROR_INVALID_ARGUMENT );
+ if (inj_err_type == INJECT_UNKNOWN_STEP) {
+ TEST_EQUAL(psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PROOF + 10,
+ output_buffer, size_zk_proof),
+ PSA_ERROR_INVALID_ARGUMENT);
goto exit;
}
- if ( inj_err_type == INJECT_INVALID_FIRST_STEP )
- {
- TEST_EQUAL( psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PROOF,
- output_buffer, size_zk_proof ),
- PSA_ERROR_BAD_STATE );
+ if (inj_err_type == INJECT_INVALID_FIRST_STEP) {
+ TEST_EQUAL(psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PROOF,
+ output_buffer, size_zk_proof),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
- status = psa_pake_input( &operation, PSA_PAKE_STEP_KEY_SHARE,
- output_buffer, size_key_share );
- if ( status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_error);
+ status = psa_pake_input(&operation, PSA_PAKE_STEP_KEY_SHARE,
+ output_buffer, size_key_share);
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_error);
goto exit;
}
- if ( inj_err_type == INJECT_WRONG_BUFFER_SIZE )
- {
- TEST_EQUAL( psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public + 1 ),
- PSA_ERROR_INVALID_ARGUMENT );
+ if (inj_err_type == INJECT_WRONG_BUFFER_SIZE) {
+ TEST_EQUAL(psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public + 1),
+ PSA_ERROR_INVALID_ARGUMENT);
goto exit;
}
- if ( inj_err_type == INJECT_VALID_OPERATION_AFTER_FAILURE )
- {
+ if (inj_err_type == INJECT_VALID_OPERATION_AFTER_FAILURE) {
// Just trigger any kind of error. We don't care about the result here
- psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public + 1 );
- TEST_EQUAL( psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public ),
- PSA_ERROR_BAD_STATE );
+ psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public + 1);
+ TEST_EQUAL(psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
} else {
- if ( inj_err_type == INJECT_EMPTY_IO_BUFFER )
- {
- TEST_EQUAL( psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PROOF,
- NULL, 0, NULL ),
- PSA_ERROR_INVALID_ARGUMENT );
+ if (inj_err_type == INJECT_EMPTY_IO_BUFFER) {
+ TEST_EQUAL(psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PROOF,
+ NULL, 0, NULL),
+ PSA_ERROR_INVALID_ARGUMENT);
goto exit;
}
- if ( inj_err_type == INJECT_UNKNOWN_STEP )
- {
- TEST_EQUAL( psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PROOF + 10,
- output_buffer, buf_size, &output_len ),
- PSA_ERROR_INVALID_ARGUMENT );
+ if (inj_err_type == INJECT_UNKNOWN_STEP) {
+ TEST_EQUAL(psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PROOF + 10,
+ output_buffer, buf_size, &output_len),
+ PSA_ERROR_INVALID_ARGUMENT);
goto exit;
}
- if ( inj_err_type == INJECT_INVALID_FIRST_STEP )
- {
- TEST_EQUAL( psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PROOF,
- output_buffer, buf_size, &output_len ),
- PSA_ERROR_BAD_STATE );
+ if (inj_err_type == INJECT_INVALID_FIRST_STEP) {
+ TEST_EQUAL(psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PROOF,
+ output_buffer, buf_size, &output_len),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
- status = psa_pake_output( &operation, PSA_PAKE_STEP_KEY_SHARE,
- output_buffer, buf_size, &output_len );
- if ( status != PSA_SUCCESS )
- {
- TEST_EQUAL( status, expected_error);
+ status = psa_pake_output(&operation, PSA_PAKE_STEP_KEY_SHARE,
+ output_buffer, buf_size, &output_len);
+ if (status != PSA_SUCCESS) {
+ TEST_EQUAL(status, expected_error);
goto exit;
}
- TEST_ASSERT( output_len > 0 );
+ TEST_ASSERT(output_len > 0);
- if ( inj_err_type == INJECT_WRONG_BUFFER_SIZE )
- {
- TEST_EQUAL( psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public - 1, &output_len ),
- PSA_ERROR_BUFFER_TOO_SMALL );
+ if (inj_err_type == INJECT_WRONG_BUFFER_SIZE) {
+ TEST_EQUAL(psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public - 1, &output_len),
+ PSA_ERROR_BUFFER_TOO_SMALL);
goto exit;
}
- if ( inj_err_type == INJECT_VALID_OPERATION_AFTER_FAILURE )
- {
+ if (inj_err_type == INJECT_VALID_OPERATION_AFTER_FAILURE) {
// Just trigger any kind of error. We don't care about the result here
- psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public - 1, &output_len );
- TEST_EQUAL( psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, buf_size, &output_len ),
- PSA_ERROR_BAD_STATE );
+ psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public - 1, &output_len);
+ TEST_EQUAL(psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, buf_size, &output_len),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
}
exit:
- PSA_ASSERT( psa_destroy_key( key ) );
- PSA_ASSERT( psa_pake_abort( &operation ) );
- mbedtls_free( output_buffer );
- PSA_DONE( );
+ PSA_ASSERT(psa_destroy_key(key));
+ PSA_ASSERT(psa_pake_abort(&operation));
+ mbedtls_free(output_buffer);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
-void ecjpake_rounds_inject( int alg_arg, int primitive_arg, int hash_arg,
- int client_input_first, int inject_error,
- data_t *pw_data )
+void ecjpake_rounds_inject(int alg_arg, int primitive_arg, int hash_arg,
+ int client_input_first, int inject_error,
+ data_t *pw_data)
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t server = psa_pake_operation_init();
@@ -9037,49 +8812,50 @@
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_PASSWORD );
- PSA_ASSERT( psa_import_key( &attributes, pw_data->x, pw_data->len,
- &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
+ PSA_ASSERT(psa_import_key(&attributes, pw_data->x, pw_data->len,
+ &key));
- psa_pake_cs_set_algorithm( &cipher_suite, alg );
- psa_pake_cs_set_primitive( &cipher_suite, primitive_arg );
- psa_pake_cs_set_hash( &cipher_suite, hash_alg );
+ psa_pake_cs_set_algorithm(&cipher_suite, alg);
+ psa_pake_cs_set_primitive(&cipher_suite, primitive_arg);
+ psa_pake_cs_set_hash(&cipher_suite, hash_alg);
- PSA_ASSERT( psa_pake_setup( &server, &cipher_suite ) );
- PSA_ASSERT( psa_pake_setup( &client, &cipher_suite ) );
+ PSA_ASSERT(psa_pake_setup(&server, &cipher_suite));
+ PSA_ASSERT(psa_pake_setup(&client, &cipher_suite));
- PSA_ASSERT( psa_pake_set_role( &server, PSA_PAKE_ROLE_SERVER ) );
- PSA_ASSERT( psa_pake_set_role( &client, PSA_PAKE_ROLE_CLIENT ) );
+ PSA_ASSERT(psa_pake_set_role(&server, PSA_PAKE_ROLE_SERVER));
+ PSA_ASSERT(psa_pake_set_role(&client, PSA_PAKE_ROLE_CLIENT));
- PSA_ASSERT( psa_pake_set_password_key( &server, key ) );
- PSA_ASSERT( psa_pake_set_password_key( &client, key ) );
+ PSA_ASSERT(psa_pake_set_password_key(&server, key));
+ PSA_ASSERT(psa_pake_set_password_key(&client, key));
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, 1, inject_error );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, 1, inject_error);
- if( inject_error == 1 || inject_error == 2 )
+ if (inject_error == 1 || inject_error == 2) {
goto exit;
+ }
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, 2, inject_error );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, 2, inject_error);
exit:
- psa_destroy_key( key );
- psa_pake_abort( &server );
- psa_pake_abort( &client );
- PSA_DONE( );
+ psa_destroy_key(key);
+ psa_pake_abort(&server);
+ psa_pake_abort(&client);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
-void ecjpake_rounds( int alg_arg, int primitive_arg, int hash_arg,
- int derive_alg_arg, data_t *pw_data,
- int client_input_first, int inj_err_type_arg )
+void ecjpake_rounds(int alg_arg, int primitive_arg, int hash_arg,
+ int derive_alg_arg, data_t *pw_data,
+ int client_input_first, int inj_err_type_arg)
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t server = psa_pake_operation_init();
@@ -9090,126 +8866,123 @@
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_derivation_operation_t server_derive =
- PSA_KEY_DERIVATION_OPERATION_INIT;
+ PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_derivation_operation_t client_derive =
- PSA_KEY_DERIVATION_OPERATION_INIT;
+ PSA_KEY_DERIVATION_OPERATION_INIT;
ecjpake_injected_failure_t inj_err_type = inj_err_type_arg;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_PASSWORD );
- PSA_ASSERT( psa_import_key( &attributes, pw_data->x, pw_data->len,
- &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
+ PSA_ASSERT(psa_import_key(&attributes, pw_data->x, pw_data->len,
+ &key));
- psa_pake_cs_set_algorithm( &cipher_suite, alg );
- psa_pake_cs_set_primitive( &cipher_suite, primitive_arg );
- psa_pake_cs_set_hash( &cipher_suite, hash_alg );
+ psa_pake_cs_set_algorithm(&cipher_suite, alg);
+ psa_pake_cs_set_primitive(&cipher_suite, primitive_arg);
+ psa_pake_cs_set_hash(&cipher_suite, hash_alg);
/* Get shared key */
- PSA_ASSERT( psa_key_derivation_setup( &server_derive, derive_alg ) );
- PSA_ASSERT( psa_key_derivation_setup( &client_derive, derive_alg ) );
+ PSA_ASSERT(psa_key_derivation_setup(&server_derive, derive_alg));
+ PSA_ASSERT(psa_key_derivation_setup(&client_derive, derive_alg));
- if( PSA_ALG_IS_TLS12_PRF( derive_alg ) ||
- PSA_ALG_IS_TLS12_PSK_TO_MS( derive_alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes( &server_derive,
- PSA_KEY_DERIVATION_INPUT_SEED,
- (const uint8_t*) "", 0) );
- PSA_ASSERT( psa_key_derivation_input_bytes( &client_derive,
- PSA_KEY_DERIVATION_INPUT_SEED,
- (const uint8_t*) "", 0) );
+ if (PSA_ALG_IS_TLS12_PRF(derive_alg) ||
+ PSA_ALG_IS_TLS12_PSK_TO_MS(derive_alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(&server_derive,
+ PSA_KEY_DERIVATION_INPUT_SEED,
+ (const uint8_t *) "", 0));
+ PSA_ASSERT(psa_key_derivation_input_bytes(&client_derive,
+ PSA_KEY_DERIVATION_INPUT_SEED,
+ (const uint8_t *) "", 0));
}
- PSA_ASSERT( psa_pake_setup( &server, &cipher_suite ) );
- PSA_ASSERT( psa_pake_setup( &client, &cipher_suite ) );
+ PSA_ASSERT(psa_pake_setup(&server, &cipher_suite));
+ PSA_ASSERT(psa_pake_setup(&client, &cipher_suite));
- PSA_ASSERT( psa_pake_set_role( &server, PSA_PAKE_ROLE_SERVER ) );
- PSA_ASSERT( psa_pake_set_role( &client, PSA_PAKE_ROLE_CLIENT ) );
+ PSA_ASSERT(psa_pake_set_role(&server, PSA_PAKE_ROLE_SERVER));
+ PSA_ASSERT(psa_pake_set_role(&client, PSA_PAKE_ROLE_CLIENT));
- PSA_ASSERT( psa_pake_set_password_key( &server, key ) );
- PSA_ASSERT( psa_pake_set_password_key( &client, key ) );
+ PSA_ASSERT(psa_pake_set_password_key(&server, key));
+ PSA_ASSERT(psa_pake_set_password_key(&client, key));
- if( inj_err_type == INJECT_ANTICIPATE_KEY_DERIVATION_1 )
- {
- TEST_EQUAL( psa_pake_get_implicit_key( &server, &server_derive ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_pake_get_implicit_key( &client, &client_derive ),
- PSA_ERROR_BAD_STATE );
+ if (inj_err_type == INJECT_ANTICIPATE_KEY_DERIVATION_1) {
+ TEST_EQUAL(psa_pake_get_implicit_key(&server, &server_derive),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_pake_get_implicit_key(&client, &client_derive),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
/* First round */
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, 1, 0 );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, 1, 0);
- if ( inj_err_type == INJECT_ANTICIPATE_KEY_DERIVATION_2 )
- {
- TEST_EQUAL( psa_pake_get_implicit_key( &server, &server_derive ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_pake_get_implicit_key( &client, &client_derive ),
- PSA_ERROR_BAD_STATE );
+ if (inj_err_type == INJECT_ANTICIPATE_KEY_DERIVATION_2) {
+ TEST_EQUAL(psa_pake_get_implicit_key(&server, &server_derive),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_pake_get_implicit_key(&client, &client_derive),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
/* Second round */
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, 2, 0 );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, 2, 0);
- PSA_ASSERT( psa_pake_get_implicit_key( &server, &server_derive ) );
- PSA_ASSERT( psa_pake_get_implicit_key( &client, &client_derive ) );
+ PSA_ASSERT(psa_pake_get_implicit_key(&server, &server_derive));
+ PSA_ASSERT(psa_pake_get_implicit_key(&client, &client_derive));
exit:
- psa_key_derivation_abort( &server_derive );
- psa_key_derivation_abort( &client_derive );
- psa_destroy_key( key );
- psa_pake_abort( &server );
- psa_pake_abort( &client );
- PSA_DONE( );
+ psa_key_derivation_abort(&server_derive);
+ psa_key_derivation_abort(&client_derive);
+ psa_destroy_key(key);
+ psa_pake_abort(&server);
+ psa_pake_abort(&client);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void ecjpake_size_macros( )
+void ecjpake_size_macros()
{
const psa_algorithm_t alg = PSA_ALG_JPAKE;
const size_t bits = 256;
const psa_pake_primitive_t prim = PSA_PAKE_PRIMITIVE(
- PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, bits );
+ PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, bits);
const psa_key_type_t key_type = PSA_KEY_TYPE_ECC_KEY_PAIR(
- PSA_ECC_FAMILY_SECP_R1 );
+ PSA_ECC_FAMILY_SECP_R1);
// https://armmbed.github.io/mbed-crypto/1.1_PAKE_Extension.0-bet.0/html/pake.html#pake-step-types
/* The output for KEY_SHARE and ZK_PUBLIC is the same as a public key */
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( key_type, bits ) );
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( key_type, bits ) );
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, bits));
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, bits));
/* The output for ZK_PROOF is the same bitsize as the curve */
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_BITS_TO_BYTES( bits ) );
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_BITS_TO_BYTES(bits));
/* Input sizes are the same as output sizes */
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE) );
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC) );
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF) );
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE));
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC));
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF));
/* These inequalities will always hold even when other PAKEs are added */
- TEST_LE_U( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_PAKE_OUTPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_PAKE_OUTPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_PAKE_OUTPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_PAKE_INPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_PAKE_INPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_PAKE_INPUT_MAX_SIZE );
+ TEST_LE_U(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_PAKE_OUTPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_PAKE_OUTPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_PAKE_OUTPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_PAKE_INPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_PAKE_INPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_PAKE_INPUT_MAX_SIZE);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_attributes.function b/tests/suites/test_suite_psa_crypto_attributes.function
index ce34fae..c933cb7 100644
--- a/tests/suites/test_suite_psa_crypto_attributes.function
+++ b/tests/suites/test_suite_psa_crypto_attributes.function
@@ -8,12 +8,12 @@
*/
/* BEGIN_CASE */
-void attributes_set_get( int owner_id_arg, int id_arg, int lifetime_arg,
- int usage_flags_arg, int alg_arg,
- int type_arg, int bits_arg )
+void attributes_set_get(int owner_id_arg, int id_arg, int lifetime_arg,
+ int usage_flags_arg, int alg_arg,
+ int type_arg, int bits_arg)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( owner_id_arg, id_arg );
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(owner_id_arg, id_arg);
psa_key_lifetime_t lifetime = lifetime_arg;
psa_key_usage_t usage_flags = usage_flags_arg;
psa_algorithm_t alg = alg_arg;
@@ -21,109 +21,112 @@
size_t bits = bits_arg;
TEST_EQUAL(
- MBEDTLS_SVC_KEY_ID_GET_KEY_ID( psa_get_key_id( &attributes ) ), 0 );
+ MBEDTLS_SVC_KEY_ID_GET_KEY_ID(psa_get_key_id(&attributes)), 0);
TEST_EQUAL(
- MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( psa_get_key_id( &attributes ) ), 0 );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_type( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_bits( &attributes ), 0 );
+ MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(psa_get_key_id(&attributes)), 0);
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), 0);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), 0);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), 0);
+ TEST_EQUAL(psa_get_key_type(&attributes), 0);
+ TEST_EQUAL(psa_get_key_bits(&attributes), 0);
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, usage_flags );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, usage_flags);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ), id ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), lifetime );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), usage_flags );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), alg );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &attributes ), bits );
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes), id));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), lifetime);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), usage_flags);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), alg);
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&attributes), bits);
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
TEST_EQUAL(
- MBEDTLS_SVC_KEY_ID_GET_KEY_ID( psa_get_key_id( &attributes ) ), 0 );
+ MBEDTLS_SVC_KEY_ID_GET_KEY_ID(psa_get_key_id(&attributes)), 0);
TEST_EQUAL(
- MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( psa_get_key_id( &attributes ) ), 0 );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_type( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_bits( &attributes ), 0 );
+ MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(psa_get_key_id(&attributes)), 0);
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), 0);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), 0);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), 0);
+ TEST_EQUAL(psa_get_key_type(&attributes), 0);
+ TEST_EQUAL(psa_get_key_bits(&attributes), 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void persistence_attributes( int id1_arg, int owner_id1_arg, int lifetime_arg,
- int id2_arg, int owner_id2_arg,
- int expected_id_arg, int expected_owner_id_arg,
- int expected_lifetime_arg )
+void persistence_attributes(int id1_arg, int owner_id1_arg, int lifetime_arg,
+ int id2_arg, int owner_id2_arg,
+ int expected_id_arg, int expected_owner_id_arg,
+ int expected_lifetime_arg)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t id1 =
- mbedtls_svc_key_id_make( owner_id1_arg, id1_arg );
+ mbedtls_svc_key_id_make(owner_id1_arg, id1_arg);
psa_key_lifetime_t lifetime = lifetime_arg;
mbedtls_svc_key_id_t id2 =
- mbedtls_svc_key_id_make( owner_id2_arg, id2_arg );
+ mbedtls_svc_key_id_make(owner_id2_arg, id2_arg);
mbedtls_svc_key_id_t expected_id =
- mbedtls_svc_key_id_make( expected_owner_id_arg, expected_id_arg );
+ mbedtls_svc_key_id_make(expected_owner_id_arg, expected_id_arg);
psa_key_lifetime_t expected_lifetime = expected_lifetime_arg;
- if( id1_arg != -1 )
- psa_set_key_id( &attributes, id1 );
- if( lifetime_arg != -1 )
- psa_set_key_lifetime( &attributes, lifetime );
- if( id2_arg != -1 )
- psa_set_key_id( &attributes, id2 );
+ if (id1_arg != -1) {
+ psa_set_key_id(&attributes, id1);
+ }
+ if (lifetime_arg != -1) {
+ psa_set_key_lifetime(&attributes, lifetime);
+ }
+ if (id2_arg != -1) {
+ psa_set_key_id(&attributes, id2);
+ }
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ), expected_id ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), expected_lifetime );
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes), expected_id));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), expected_lifetime);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_SE_C */
-void slot_number_attribute( )
+void slot_number_attribute()
{
psa_key_slot_number_t slot_number = 0xdeadbeef;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* Initially, there is no slot number. */
- TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
- PSA_ERROR_INVALID_ARGUMENT );
+ TEST_EQUAL(psa_get_key_slot_number(&attributes, &slot_number),
+ PSA_ERROR_INVALID_ARGUMENT);
/* Test setting a slot number. */
- psa_set_key_slot_number( &attributes, 0 );
- PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
- TEST_EQUAL( slot_number, 0 );
+ psa_set_key_slot_number(&attributes, 0);
+ PSA_ASSERT(psa_get_key_slot_number(&attributes, &slot_number));
+ TEST_EQUAL(slot_number, 0);
/* Test changing the slot number. */
- psa_set_key_slot_number( &attributes, 42 );
- PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
- TEST_EQUAL( slot_number, 42 );
+ psa_set_key_slot_number(&attributes, 42);
+ PSA_ASSERT(psa_get_key_slot_number(&attributes, &slot_number));
+ TEST_EQUAL(slot_number, 42);
/* Test clearing the slot number. */
- psa_clear_key_slot_number( &attributes );
- TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
- PSA_ERROR_INVALID_ARGUMENT );
+ psa_clear_key_slot_number(&attributes);
+ TEST_EQUAL(psa_get_key_slot_number(&attributes, &slot_number),
+ PSA_ERROR_INVALID_ARGUMENT);
/* Clearing again should have no effect. */
- psa_clear_key_slot_number( &attributes );
- TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
- PSA_ERROR_INVALID_ARGUMENT );
+ psa_clear_key_slot_number(&attributes);
+ TEST_EQUAL(psa_get_key_slot_number(&attributes, &slot_number),
+ PSA_ERROR_INVALID_ARGUMENT);
/* Test that reset clears the slot number. */
- psa_set_key_slot_number( &attributes, 42 );
- PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
- TEST_EQUAL( slot_number, 42 );
- psa_reset_key_attributes( &attributes );
- TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
- PSA_ERROR_INVALID_ARGUMENT );
+ psa_set_key_slot_number(&attributes, 42);
+ PSA_ASSERT(psa_get_key_slot_number(&attributes, &slot_number));
+ TEST_EQUAL(slot_number, 42);
+ psa_reset_key_attributes(&attributes);
+ TEST_EQUAL(psa_get_key_slot_number(&attributes, &slot_number),
+ PSA_ERROR_INVALID_ARGUMENT);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function
index b713cb2..8bb3e35 100644
--- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function
+++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function
@@ -15,49 +15,44 @@
psa_algorithm_t alg,
const data_t *modulus, const data_t *private_exponent,
const data_t *input_data,
- uint8_t *buf, size_t length )
+ uint8_t *buf, size_t length)
{
#if defined(MBEDTLS_BIGNUM_C)
mbedtls_mpi N, D, C, X;
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &D );
- mbedtls_mpi_init( &C );
- mbedtls_mpi_init( &X );
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&D);
+ mbedtls_mpi_init(&C);
+ mbedtls_mpi_init(&X);
#endif /* MBEDTLS_BIGNUM_C */
int ok = 0;
- TEST_ASSERT( length == modulus->len );
+ TEST_ASSERT(length == modulus->len);
#if defined(MBEDTLS_BIGNUM_C)
/* Perform the private key operation */
- TEST_ASSERT( mbedtls_mpi_read_binary( &N, modulus->x, modulus->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &D,
- private_exponent->x,
- private_exponent->len ) == 0 );
- TEST_ASSERT( mbedtls_mpi_read_binary( &C, buf, length ) == 0 );
- TEST_ASSERT( mbedtls_mpi_exp_mod( &X, &C, &D, &N, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_read_binary(&N, modulus->x, modulus->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&D,
+ private_exponent->x,
+ private_exponent->len) == 0);
+ TEST_ASSERT(mbedtls_mpi_read_binary(&C, buf, length) == 0);
+ TEST_ASSERT(mbedtls_mpi_exp_mod(&X, &C, &D, &N, NULL) == 0);
/* Sanity checks on the padded plaintext */
- TEST_ASSERT( mbedtls_mpi_write_binary( &X, buf, length ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_write_binary(&X, buf, length) == 0);
- if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
- {
- TEST_ASSERT( length > input_data->len + 2 );
- TEST_EQUAL( buf[0], 0x00 );
- TEST_EQUAL( buf[1], 0x02 );
- TEST_EQUAL( buf[length - input_data->len - 1], 0x00 );
- ASSERT_COMPARE( buf + length - input_data->len, input_data->len,
- input_data->x, input_data->len );
- }
- else if( PSA_ALG_IS_RSA_OAEP( alg ) )
- {
- TEST_EQUAL( buf[0], 0x00 );
+ if (alg == PSA_ALG_RSA_PKCS1V15_CRYPT) {
+ TEST_ASSERT(length > input_data->len + 2);
+ TEST_EQUAL(buf[0], 0x00);
+ TEST_EQUAL(buf[1], 0x02);
+ TEST_EQUAL(buf[length - input_data->len - 1], 0x00);
+ ASSERT_COMPARE(buf + length - input_data->len, input_data->len,
+ input_data->x, input_data->len);
+ } else if (PSA_ALG_IS_RSA_OAEP(alg)) {
+ TEST_EQUAL(buf[0], 0x00);
/* The rest is too hard to check */
- }
- else
- {
- TEST_ASSERT( ! "Encryption result sanity check not implemented for RSA algorithm" );
+ } else {
+ TEST_ASSERT(!"Encryption result sanity check not implemented for RSA algorithm");
}
#endif /* MBEDTLS_BIGNUM_C */
@@ -65,12 +60,12 @@
exit:
#if defined(MBEDTLS_BIGNUM_C)
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &D );
- mbedtls_mpi_free( &C );
- mbedtls_mpi_free( &X );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&D);
+ mbedtls_mpi_free(&C);
+ mbedtls_mpi_free(&X);
#endif /* MBEDTLS_BIGNUM_C */
- return( ok );
+ return ok;
}
#endif
/* END_HEADER */
@@ -81,14 +76,14 @@
*/
/* BEGIN_CASE */
-void sign_hash( int key_type_arg,
- int alg_arg,
- int force_status_arg,
- data_t *key_input,
- data_t *data_input,
- data_t *expected_output,
- int fake_output,
- int expected_status_arg )
+void sign_hash(int key_type_arg,
+ int alg_arg,
+ int force_status_arg,
+ data_t *key_input,
+ data_t *data_input,
+ data_t *expected_output,
+ int fake_output,
+ int expected_status_arg)
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
@@ -104,18 +99,17 @@
mbedtls_test_driver_signature_sign_hooks =
mbedtls_test_driver_signature_hooks_init();
- PSA_ASSERT( psa_crypto_init( ) );
- psa_set_key_type( &attributes,
- key_type );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_import_key( &attributes,
- key_input->x, key_input->len,
- &key );
+ PSA_ASSERT(psa_crypto_init());
+ psa_set_key_type(&attributes,
+ key_type);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_import_key(&attributes,
+ key_input->x, key_input->len,
+ &key);
mbedtls_test_driver_signature_sign_hooks.forced_status = force_status;
- if( fake_output == 1 )
- {
+ if (fake_output == 1) {
mbedtls_test_driver_signature_sign_hooks.forced_output =
expected_output->x;
mbedtls_test_driver_signature_sign_hooks.forced_output_length =
@@ -124,104 +118,100 @@
/* Allocate a buffer which has the size advertized by the
* library. */
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
- signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
+ signature_size = PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg);
- TEST_ASSERT( signature_size != 0 );
- TEST_ASSERT( signature_size <= PSA_SIGNATURE_MAX_SIZE );
- ASSERT_ALLOC( signature, signature_size );
+ TEST_ASSERT(signature_size != 0);
+ TEST_ASSERT(signature_size <= PSA_SIGNATURE_MAX_SIZE);
+ ASSERT_ALLOC(signature, signature_size);
- actual_status = psa_sign_hash( key, alg,
- data_input->x, data_input->len,
- signature, signature_size,
- &signature_length );
- TEST_EQUAL( actual_status, expected_status );
- if( expected_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( signature, signature_length,
- expected_output->x, expected_output->len );
+ actual_status = psa_sign_hash(key, alg,
+ data_input->x, data_input->len,
+ signature, signature_size,
+ &signature_length);
+ TEST_EQUAL(actual_status, expected_status);
+ if (expected_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(signature, signature_length,
+ expected_output->x, expected_output->len);
}
- TEST_EQUAL( mbedtls_test_driver_signature_sign_hooks.hits, 1 );
+ TEST_EQUAL(mbedtls_test_driver_signature_sign_hooks.hits, 1);
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
mbedtls_test_driver_signature_sign_hooks =
mbedtls_test_driver_signature_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void verify_hash( int key_type_arg,
- int key_type_public_arg,
+void verify_hash(int key_type_arg,
+ int key_type_public_arg,
+ int alg_arg,
+ int force_status_arg,
+ int register_public_key,
+ data_t *key_input,
+ data_t *data_input,
+ data_t *signature_input,
+ int expected_status_arg)
+{
+ psa_status_t force_status = force_status_arg;
+ psa_status_t expected_status = expected_status_arg;
+ psa_algorithm_t alg = alg_arg;
+ psa_key_type_t key_type = key_type_arg;
+ psa_key_type_t key_type_public = key_type_public_arg;
+ mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ psa_status_t actual_status;
+ mbedtls_test_driver_signature_verify_hooks =
+ mbedtls_test_driver_signature_hooks_init();
+
+ PSA_ASSERT(psa_crypto_init());
+ if (register_public_key) {
+ psa_set_key_type(&attributes, key_type_public);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_import_key(&attributes,
+ key_input->x, key_input->len,
+ &key);
+ } else {
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_import_key(&attributes,
+ key_input->x, key_input->len,
+ &key);
+ }
+
+ mbedtls_test_driver_signature_verify_hooks.forced_status = force_status;
+
+ actual_status = psa_verify_hash(key, alg,
+ data_input->x, data_input->len,
+ signature_input->x, signature_input->len);
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_EQUAL(mbedtls_test_driver_signature_verify_hooks.hits, 1);
+
+exit:
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_test_driver_signature_verify_hooks =
+ mbedtls_test_driver_signature_hooks_init();
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void sign_message(int key_type_arg,
int alg_arg,
int force_status_arg,
- int register_public_key,
data_t *key_input,
data_t *data_input,
- data_t *signature_input,
- int expected_status_arg )
-{
- psa_status_t force_status = force_status_arg;
- psa_status_t expected_status = expected_status_arg;
- psa_algorithm_t alg = alg_arg;
- psa_key_type_t key_type = key_type_arg;
- psa_key_type_t key_type_public = key_type_public_arg;
- mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_status_t actual_status;
- mbedtls_test_driver_signature_verify_hooks =
- mbedtls_test_driver_signature_hooks_init();
-
- PSA_ASSERT( psa_crypto_init( ) );
- if( register_public_key )
- {
- psa_set_key_type( &attributes, key_type_public );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_import_key( &attributes,
- key_input->x, key_input->len,
- &key );
- }
- else
- {
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_import_key( &attributes,
- key_input->x, key_input->len,
- &key );
- }
-
- mbedtls_test_driver_signature_verify_hooks.forced_status = force_status;
-
- actual_status = psa_verify_hash( key, alg,
- data_input->x, data_input->len,
- signature_input->x, signature_input->len );
- TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( mbedtls_test_driver_signature_verify_hooks.hits, 1 );
-
-exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_test_driver_signature_verify_hooks =
- mbedtls_test_driver_signature_hooks_init();
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void sign_message( int key_type_arg,
- int alg_arg,
- int force_status_arg,
- data_t *key_input,
- data_t *data_input,
- data_t *expected_output,
- int fake_output,
- int expected_status_arg )
+ data_t *expected_output,
+ int fake_output,
+ int expected_status_arg)
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
@@ -237,17 +227,16 @@
mbedtls_test_driver_signature_sign_hooks =
mbedtls_test_driver_signature_hooks_init();
- PSA_ASSERT( psa_crypto_init( ) );
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_import_key( &attributes,
- key_input->x, key_input->len,
- &key );
+ PSA_ASSERT(psa_crypto_init());
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_import_key(&attributes,
+ key_input->x, key_input->len,
+ &key);
mbedtls_test_driver_signature_sign_hooks.forced_status = force_status;
- if( fake_output == 1 )
- {
+ if (fake_output == 1) {
mbedtls_test_driver_signature_sign_hooks.forced_output =
expected_output->x;
mbedtls_test_driver_signature_sign_hooks.forced_output_length =
@@ -256,48 +245,47 @@
/* Allocate a buffer which has the size advertized by the
* library. */
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
- signature_size = PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
+ signature_size = PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg);
- TEST_ASSERT( signature_size != 0 );
- TEST_ASSERT( signature_size <= PSA_SIGNATURE_MAX_SIZE );
- ASSERT_ALLOC( signature, signature_size );
+ TEST_ASSERT(signature_size != 0);
+ TEST_ASSERT(signature_size <= PSA_SIGNATURE_MAX_SIZE);
+ ASSERT_ALLOC(signature, signature_size);
- actual_status = psa_sign_message( key, alg,
- data_input->x, data_input->len,
- signature, signature_size,
- &signature_length );
- TEST_EQUAL( actual_status, expected_status );
- if( expected_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( signature, signature_length,
- expected_output->x, expected_output->len );
+ actual_status = psa_sign_message(key, alg,
+ data_input->x, data_input->len,
+ signature, signature_size,
+ &signature_length);
+ TEST_EQUAL(actual_status, expected_status);
+ if (expected_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(signature, signature_length,
+ expected_output->x, expected_output->len);
}
/* In the builtin algorithm the driver is called twice. */
- TEST_EQUAL( mbedtls_test_driver_signature_sign_hooks.hits,
- force_status == PSA_ERROR_NOT_SUPPORTED ? 2 : 1 );
+ TEST_EQUAL(mbedtls_test_driver_signature_sign_hooks.hits,
+ force_status == PSA_ERROR_NOT_SUPPORTED ? 2 : 1);
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- mbedtls_free( signature );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ mbedtls_free(signature);
+ PSA_DONE();
mbedtls_test_driver_signature_sign_hooks =
mbedtls_test_driver_signature_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void verify_message( int key_type_arg,
- int key_type_public_arg,
- int alg_arg,
- int force_status_arg,
- int register_public_key,
- data_t *key_input,
- data_t *data_input,
- data_t *signature_input,
- int expected_status_arg )
+void verify_message(int key_type_arg,
+ int key_type_public_arg,
+ int alg_arg,
+ int force_status_arg,
+ int register_public_key,
+ data_t *key_input,
+ data_t *data_input,
+ data_t *signature_input,
+ int expected_status_arg)
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
@@ -310,131 +298,123 @@
mbedtls_test_driver_signature_verify_hooks =
mbedtls_test_driver_signature_hooks_init();
- PSA_ASSERT( psa_crypto_init( ) );
- if( register_public_key )
- {
- psa_set_key_type( &attributes, key_type_public );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_import_key( &attributes,
- key_input->x, key_input->len,
- &key );
- }
- else
- {
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_MESSAGE );
- psa_set_key_algorithm( &attributes, alg );
- psa_import_key( &attributes,
- key_input->x, key_input->len,
- &key );
+ PSA_ASSERT(psa_crypto_init());
+ if (register_public_key) {
+ psa_set_key_type(&attributes, key_type_public);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_import_key(&attributes,
+ key_input->x, key_input->len,
+ &key);
+ } else {
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_MESSAGE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_import_key(&attributes,
+ key_input->x, key_input->len,
+ &key);
}
mbedtls_test_driver_signature_verify_hooks.forced_status = force_status;
- actual_status = psa_verify_message( key, alg,
- data_input->x, data_input->len,
- signature_input->x, signature_input->len );
- TEST_EQUAL( actual_status, expected_status );
+ actual_status = psa_verify_message(key, alg,
+ data_input->x, data_input->len,
+ signature_input->x, signature_input->len);
+ TEST_EQUAL(actual_status, expected_status);
/* In the builtin algorithm the driver is called twice. */
- TEST_EQUAL( mbedtls_test_driver_signature_verify_hooks.hits,
- force_status == PSA_ERROR_NOT_SUPPORTED ? 2 : 1 );
+ TEST_EQUAL(mbedtls_test_driver_signature_verify_hooks.hits,
+ force_status == PSA_ERROR_NOT_SUPPORTED ? 2 : 1);
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_signature_verify_hooks =
mbedtls_test_driver_signature_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_ECDSA:PSA_WANT_ECC_SECP_R1_256 */
-void generate_key( int force_status_arg,
- data_t *fake_output,
- int expected_status_arg )
+void generate_key(int force_status_arg,
+ data_t *fake_output,
+ int expected_status_arg)
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_algorithm_t alg = PSA_ALG_ECDSA( PSA_ALG_SHA_256 );
+ psa_algorithm_t alg = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
const uint8_t *expected_output = NULL;
size_t expected_output_length = 0;
psa_status_t actual_status;
- uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = {0};
+ uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = { 0 };
size_t actual_output_length;
mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
- psa_set_key_type( &attributes,
- PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) );
- psa_set_key_bits( &attributes, 256 );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes, alg );
+ psa_set_key_type(&attributes,
+ PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
+ psa_set_key_bits(&attributes, 256);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes, alg);
- if( fake_output->len > 0 )
- {
+ if (fake_output->len > 0) {
expected_output =
mbedtls_test_driver_key_management_hooks.forced_output =
- fake_output->x;
+ fake_output->x;
expected_output_length =
mbedtls_test_driver_key_management_hooks.forced_output_length =
- fake_output->len;
+ fake_output->len;
}
mbedtls_test_driver_key_management_hooks.hits = 0;
mbedtls_test_driver_key_management_hooks.forced_status = force_status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- actual_status = psa_generate_key( &attributes, &key );
- TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 );
- TEST_EQUAL( actual_status, expected_status );
+ actual_status = psa_generate_key(&attributes, &key);
+ TEST_EQUAL(mbedtls_test_driver_key_management_hooks.hits, 1);
+ TEST_EQUAL(actual_status, expected_status);
- if( actual_status == PSA_SUCCESS )
- {
- psa_export_key( key, actual_output, sizeof(actual_output), &actual_output_length );
+ if (actual_status == PSA_SUCCESS) {
+ psa_export_key(key, actual_output, sizeof(actual_output), &actual_output_length);
- if( fake_output->len > 0 )
- {
- ASSERT_COMPARE( actual_output, actual_output_length,
- expected_output, expected_output_length );
- }
- else
- {
+ if (fake_output->len > 0) {
+ ASSERT_COMPARE(actual_output, actual_output_length,
+ expected_output, expected_output_length);
+ } else {
size_t zeroes = 0;
- for( size_t i = 0; i < sizeof(actual_output); i++ )
- {
- if( actual_output[i] == 0)
+ for (size_t i = 0; i < sizeof(actual_output); i++) {
+ if (actual_output[i] == 0) {
zeroes++;
+ }
}
- TEST_ASSERT( zeroes != sizeof(actual_output) );
+ TEST_ASSERT(zeroes != sizeof(actual_output));
}
}
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void validate_key( int force_status_arg,
- int location,
- int owner_id_arg,
- int id_arg,
- int key_type_arg,
- data_t *key_input,
- int expected_status_arg )
+void validate_key(int force_status_arg,
+ int location,
+ int owner_id_arg,
+ int id_arg,
+ int key_type_arg,
+ data_t *key_input,
+ int expected_status_arg)
{
psa_key_lifetime_t lifetime =
- PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
- PSA_KEY_PERSISTENCE_DEFAULT, location);
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( owner_id_arg, id_arg );
+ PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
+ PSA_KEY_PERSISTENCE_DEFAULT, location);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(owner_id_arg, id_arg);
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
psa_key_type_t key_type = key_type_arg;
@@ -444,38 +424,38 @@
mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
- psa_set_key_id( &attributes, id );
- psa_set_key_type( &attributes,
- key_type );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_bits( &attributes, 0 );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_type(&attributes,
+ key_type);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_bits(&attributes, 0);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
mbedtls_test_driver_key_management_hooks.forced_status = force_status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- actual_status = psa_import_key( &attributes, key_input->x, key_input->len, &key );
- TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 );
- TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( mbedtls_test_driver_key_management_hooks.location, location );
+ actual_status = psa_import_key(&attributes, key_input->x, key_input->len, &key);
+ TEST_EQUAL(mbedtls_test_driver_key_management_hooks.hits, 1);
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_EQUAL(mbedtls_test_driver_key_management_hooks.location, location);
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void export_key( int force_status_arg,
- data_t *fake_output,
- int key_in_type_arg,
- data_t *key_in,
- int key_out_type_arg,
- data_t *expected_output,
- int expected_status_arg )
+void export_key(int force_status_arg,
+ data_t *fake_output,
+ int key_in_type_arg,
+ data_t *key_in,
+ int key_out_type_arg,
+ data_t *expected_output,
+ int expected_status_arg)
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
@@ -486,30 +466,27 @@
const uint8_t *expected_output_ptr = NULL;
size_t expected_output_length = 0;
psa_status_t actual_status;
- uint8_t actual_output[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256)] = {0};
+ uint8_t actual_output[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256)] = { 0 };
size_t actual_output_length;
mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
- psa_set_key_type( &attributes, input_key_type );
- psa_set_key_bits( &attributes, 256 );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
+ psa_set_key_type(&attributes, input_key_type);
+ psa_set_key_bits(&attributes, 256);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_ASSERT( psa_import_key( &attributes, key_in->x, key_in->len, &handle ) );
+ PSA_ASSERT(psa_crypto_init());
+ PSA_ASSERT(psa_import_key(&attributes, key_in->x, key_in->len, &handle));
- if( fake_output->len > 0 )
- {
+ if (fake_output->len > 0) {
expected_output_ptr =
mbedtls_test_driver_key_management_hooks.forced_output =
- fake_output->x;
+ fake_output->x;
expected_output_length =
mbedtls_test_driver_key_management_hooks.forced_output_length =
- fake_output->len;
- }
- else
- {
+ fake_output->len;
+ } else {
expected_output_ptr = expected_output->x;
expected_output_length = expected_output->len;
}
@@ -517,39 +494,46 @@
mbedtls_test_driver_key_management_hooks.hits = 0;
mbedtls_test_driver_key_management_hooks.forced_status = force_status;
- if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) )
- actual_status = psa_export_public_key( handle, actual_output, sizeof(actual_output), &actual_output_length );
- else
- actual_status = psa_export_key( handle, actual_output, sizeof(actual_output), &actual_output_length );
- TEST_EQUAL( actual_status, expected_status );
+ if (PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(output_key_type)) {
+ actual_status = psa_export_public_key(handle,
+ actual_output,
+ sizeof(actual_output),
+ &actual_output_length);
+ } else {
+ actual_status = psa_export_key(handle,
+ actual_output,
+ sizeof(actual_output),
+ &actual_output_length);
+ }
+ TEST_EQUAL(actual_status, expected_status);
- if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) &&
- !PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( input_key_type ) )
- TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 );
+ if (PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(output_key_type) &&
+ !PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(input_key_type)) {
+ TEST_EQUAL(mbedtls_test_driver_key_management_hooks.hits, 1);
+ }
- if( actual_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( actual_output, actual_output_length,
- expected_output_ptr, expected_output_length );
+ if (actual_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(actual_output, actual_output_length,
+ expected_output_ptr, expected_output_length);
}
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( handle );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(handle);
+ PSA_DONE();
mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_agreement( int alg_arg,
- int force_status_arg,
- int our_key_type_arg,
- data_t *our_key_data,
- data_t *peer_key_data,
- data_t *expected_output,
- data_t* fake_output,
- int expected_status_arg )
+void key_agreement(int alg_arg,
+ int force_status_arg,
+ int our_key_type_arg,
+ data_t *our_key_data,
+ data_t *peer_key_data,
+ data_t *expected_output,
+ data_t *fake_output,
+ int expected_status_arg)
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
@@ -566,35 +550,32 @@
mbedtls_test_driver_key_agreement_hooks =
mbedtls_test_driver_key_agreement_hooks_init();
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, our_key_type );
- PSA_ASSERT( psa_import_key( &attributes,
- our_key_data->x, our_key_data->len,
- &our_key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, our_key_type);
+ PSA_ASSERT(psa_import_key(&attributes,
+ our_key_data->x, our_key_data->len,
+ &our_key));
- PSA_ASSERT( psa_get_key_attributes( our_key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(our_key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- TEST_LE_U( expected_output->len,
- PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( our_key_type, key_bits ) );
- TEST_LE_U( PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE( our_key_type, key_bits ),
- PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE );
+ TEST_LE_U(expected_output->len,
+ PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(our_key_type, key_bits));
+ TEST_LE_U(PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(our_key_type, key_bits),
+ PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE);
- if( fake_output->len > 0 )
- {
+ if (fake_output->len > 0) {
expected_output_ptr =
mbedtls_test_driver_key_agreement_hooks.forced_output =
- fake_output->x;
+ fake_output->x;
expected_output_length =
mbedtls_test_driver_key_agreement_hooks.forced_output_length =
- fake_output->len;
- }
- else
- {
+ fake_output->len;
+ } else {
expected_output_ptr = expected_output->x;
expected_output_length = expected_output->len;
}
@@ -602,27 +583,26 @@
mbedtls_test_driver_key_agreement_hooks.hits = 0;
mbedtls_test_driver_key_agreement_hooks.forced_status = force_status;
- ASSERT_ALLOC( actual_output, expected_output->len );
- actual_status = psa_raw_key_agreement( alg, our_key,
- peer_key_data->x, peer_key_data->len,
- actual_output, expected_output->len,
- &actual_output_length ) ;
- TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( mbedtls_test_driver_key_agreement_hooks.hits, 1 );
+ ASSERT_ALLOC(actual_output, expected_output->len);
+ actual_status = psa_raw_key_agreement(alg, our_key,
+ peer_key_data->x, peer_key_data->len,
+ actual_output, expected_output->len,
+ &actual_output_length);
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_EQUAL(mbedtls_test_driver_key_agreement_hooks.hits, 1);
- if( actual_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( actual_output, actual_output_length,
- expected_output_ptr, expected_output_length);
+ if (actual_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(actual_output, actual_output_length,
+ expected_output_ptr, expected_output_length);
}
- mbedtls_free( actual_output );
+ mbedtls_free(actual_output);
actual_output = NULL;
actual_output_length = ~0;
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( our_key );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(our_key);
+ PSA_DONE();
mbedtls_test_driver_key_agreement_hooks =
mbedtls_test_driver_key_agreement_hooks_init();
}
@@ -630,15 +610,15 @@
/* END_CASE */
/* BEGIN_CASE */
-void cipher_encrypt_validation( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *input )
+void cipher_encrypt_validation(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *input)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
- size_t iv_size = PSA_CIPHER_IV_LENGTH ( key_type, alg );
+ size_t iv_size = PSA_CIPHER_IV_LENGTH(key_type, alg);
unsigned char *output1 = NULL;
size_t output1_buffer_size = 0;
size_t output1_length = 0;
@@ -650,81 +630,81 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE( key_type, alg, input->len );
- output2_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE( key_type, alg, input->len ) +
- PSA_CIPHER_FINISH_OUTPUT_SIZE( key_type, alg );
- ASSERT_ALLOC( output1, output1_buffer_size );
- ASSERT_ALLOC( output2, output2_buffer_size );
+ output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
+ output2_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
+ PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
+ ASSERT_ALLOC(output1, output1_buffer_size);
+ ASSERT_ALLOC(output2, output2_buffer_size);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_cipher_encrypt( key, alg, input->x, input->len, output1,
- output1_buffer_size, &output1_length ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
+ PSA_ASSERT(psa_cipher_encrypt(key, alg, input->x, input->len, output1,
+ output1_buffer_size, &output1_length));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
mbedtls_test_driver_cipher_hooks.hits = 0;
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
mbedtls_test_driver_cipher_hooks.hits = 0;
- PSA_ASSERT( psa_cipher_set_iv( &operation, output1, iv_size ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
+ PSA_ASSERT(psa_cipher_set_iv(&operation, output1, iv_size));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
mbedtls_test_driver_cipher_hooks.hits = 0;
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x, input->len,
- output2, output2_buffer_size,
- &function_output_length ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x, input->len,
+ output2, output2_buffer_size,
+ &function_output_length));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
mbedtls_test_driver_cipher_hooks.hits = 0;
output2_length += function_output_length;
- PSA_ASSERT( psa_cipher_finish( &operation,
- output2 + output2_length,
- output2_buffer_size - output2_length,
- &function_output_length ) );
+ PSA_ASSERT(psa_cipher_finish(&operation,
+ output2 + output2_length,
+ output2_buffer_size - output2_length,
+ &function_output_length));
/* Finish will have called abort as well, so expecting two hits here */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 2);
mbedtls_test_driver_cipher_hooks.hits = 0;
output2_length += function_output_length;
- PSA_ASSERT( psa_cipher_abort( &operation ) );
+ PSA_ASSERT(psa_cipher_abort(&operation));
// driver function should've been called as part of the finish() core routine
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
- ASSERT_COMPARE( output1 + iv_size, output1_length - iv_size,
- output2, output2_length );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
+ ASSERT_COMPARE(output1 + iv_size, output1_length - iv_size,
+ output2, output2_length);
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output1 );
- mbedtls_free( output2 );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output1);
+ mbedtls_free(output2);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_encrypt_multipart( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *iv,
- data_t *input,
- int first_part_size_arg,
- int output1_length_arg,
- int output2_length_arg,
- data_t *expected_output,
- int mock_output_arg,
- int force_status_arg,
- int expected_status_arg )
+void cipher_encrypt_multipart(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *iv,
+ data_t *input,
+ int first_part_size_arg,
+ int output1_length_arg,
+ int output2_length_arg,
+ data_t *expected_output,
+ int mock_output_arg,
+ int force_status_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -746,247 +726,239 @@
/* Test operation initialization */
mbedtls_psa_cipher_operation_t mbedtls_operation =
- MBEDTLS_PSA_CIPHER_OPERATION_INIT;
+ MBEDTLS_PSA_CIPHER_OPERATION_INIT;
mbedtls_transparent_test_driver_cipher_operation_t transparent_operation =
- MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT;
+ MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT;
mbedtls_opaque_test_driver_cipher_operation_t opaque_operation =
- MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT;
+ MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT;
operation.ctx.mbedtls_ctx = mbedtls_operation;
operation.ctx.transparent_test_driver_ctx = transparent_operation;
operation.ctx.opaque_test_driver_ctx = opaque_operation;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
+ PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
mbedtls_test_driver_cipher_hooks.hits = 0;
- PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
+ PSA_ASSERT(psa_cipher_set_iv(&operation, iv->x, iv->len));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, (force_status == PSA_SUCCESS ? 1 : 0));
mbedtls_test_driver_cipher_hooks.hits = 0;
- output_buffer_size = ( (size_t) input->len +
- PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = ((size_t) input->len +
+ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type));
+ ASSERT_ALLOC(output, output_buffer_size);
- if( mock_output_arg )
- {
+ if (mock_output_arg) {
mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len;
}
- TEST_ASSERT( first_part_size <= input->len );
- PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size,
- output, output_buffer_size,
- &function_output_length ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
+ TEST_ASSERT(first_part_size <= input->len);
+ PSA_ASSERT(psa_cipher_update(&operation, input->x, first_part_size,
+ output, output_buffer_size,
+ &function_output_length));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, (force_status == PSA_SUCCESS ? 1 : 0));
mbedtls_test_driver_cipher_hooks.hits = 0;
- TEST_ASSERT( function_output_length == output1_length );
+ TEST_ASSERT(function_output_length == output1_length);
total_output_length += function_output_length;
- if( first_part_size < input->len )
- {
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x + first_part_size,
- input->len - first_part_size,
- output + total_output_length,
- output_buffer_size - total_output_length,
- &function_output_length ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
+ if (first_part_size < input->len) {
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x + first_part_size,
+ input->len - first_part_size,
+ output + total_output_length,
+ output_buffer_size - total_output_length,
+ &function_output_length));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
mbedtls_test_driver_cipher_hooks.hits = 0;
- TEST_ASSERT( function_output_length == output2_length );
+ TEST_ASSERT(function_output_length == output2_length);
total_output_length += function_output_length;
}
- if( mock_output_arg )
- {
+ if (mock_output_arg) {
mbedtls_test_driver_cipher_hooks.forced_output = NULL;
mbedtls_test_driver_cipher_hooks.forced_output_length = 0;
}
- status = psa_cipher_finish( &operation,
- output + total_output_length,
- output_buffer_size - total_output_length,
- &function_output_length );
- /* Finish will have called abort as well, so expecting two hits here */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) );
- mbedtls_test_driver_cipher_hooks.hits = 0 ;
- total_output_length += function_output_length;
- TEST_EQUAL( status, expected_status );
-
- if( expected_status == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
-
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output, total_output_length );
- }
-
-exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void cipher_decrypt_multipart( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *iv,
- data_t *input,
- int first_part_size_arg,
- int output1_length_arg,
- int output2_length_arg,
- data_t *expected_output,
- int mock_output_arg,
- int force_status_arg,
- int expected_status_arg )
-{
- mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
- psa_key_type_t key_type = key_type_arg;
- psa_algorithm_t alg = alg_arg;
- psa_status_t status;
- psa_status_t expected_status = expected_status_arg;
- psa_status_t force_status = force_status_arg;
- size_t first_part_size = first_part_size_arg;
- size_t output1_length = output1_length_arg;
- size_t output2_length = output2_length_arg;
- unsigned char *output = NULL;
- size_t output_buffer_size = 0;
- size_t function_output_length = 0;
- size_t total_output_length = 0;
- psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
- mbedtls_test_driver_cipher_hooks.forced_status = force_status;
-
- /* Test operation initialization */
- mbedtls_psa_cipher_operation_t mbedtls_operation =
- MBEDTLS_PSA_CIPHER_OPERATION_INIT;
-
- mbedtls_transparent_test_driver_cipher_operation_t transparent_operation =
- MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT;
-
- mbedtls_opaque_test_driver_cipher_operation_t opaque_operation =
- MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT;
-
- operation.ctx.mbedtls_ctx = mbedtls_operation;
- operation.ctx.transparent_test_driver_ctx = transparent_operation;
- operation.ctx.opaque_test_driver_ctx = opaque_operation;
-
- PSA_ASSERT( psa_crypto_init( ) );
-
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
-
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
-
- PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- mbedtls_test_driver_cipher_hooks.hits = 0;
-
- PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
- mbedtls_test_driver_cipher_hooks.hits = 0;
-
- output_buffer_size = ( (size_t) input->len +
- PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
- ASSERT_ALLOC( output, output_buffer_size );
-
- if( mock_output_arg )
- {
- mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
- mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len;
- }
-
- TEST_ASSERT( first_part_size <= input->len );
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x, first_part_size,
- output, output_buffer_size,
- &function_output_length ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
- mbedtls_test_driver_cipher_hooks.hits = 0;
-
- TEST_ASSERT( function_output_length == output1_length );
- total_output_length += function_output_length;
-
- if( first_part_size < input->len )
- {
- PSA_ASSERT( psa_cipher_update( &operation,
- input->x + first_part_size,
- input->len - first_part_size,
- output + total_output_length,
- output_buffer_size - total_output_length,
- &function_output_length ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
- mbedtls_test_driver_cipher_hooks.hits = 0;
-
- TEST_ASSERT( function_output_length == output2_length );
- total_output_length += function_output_length;
- }
-
- if( mock_output_arg )
- {
- mbedtls_test_driver_cipher_hooks.forced_output = NULL;
- mbedtls_test_driver_cipher_hooks.forced_output_length = 0;
- }
-
- status = psa_cipher_finish( &operation,
+ status = psa_cipher_finish(&operation,
output + total_output_length,
output_buffer_size - total_output_length,
- &function_output_length );
+ &function_output_length);
/* Finish will have called abort as well, so expecting two hits here */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, (force_status == PSA_SUCCESS ? 2 : 0));
mbedtls_test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length;
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- if( expected_status == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_cipher_abort( &operation ) );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output, total_output_length );
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output, total_output_length);
}
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_decrypt( int alg_arg,
- int key_type_arg,
- data_t *key_data,
- data_t *iv,
- data_t *input_arg,
- data_t *expected_output,
- int mock_output_arg,
- int force_status_arg,
- int expected_status_arg )
+void cipher_decrypt_multipart(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *iv,
+ data_t *input,
+ int first_part_size_arg,
+ int output1_length_arg,
+ int output2_length_arg,
+ data_t *expected_output,
+ int mock_output_arg,
+ int force_status_arg,
+ int expected_status_arg)
+{
+ mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
+ psa_key_type_t key_type = key_type_arg;
+ psa_algorithm_t alg = alg_arg;
+ psa_status_t status;
+ psa_status_t expected_status = expected_status_arg;
+ psa_status_t force_status = force_status_arg;
+ size_t first_part_size = first_part_size_arg;
+ size_t output1_length = output1_length_arg;
+ size_t output2_length = output2_length_arg;
+ unsigned char *output = NULL;
+ size_t output_buffer_size = 0;
+ size_t function_output_length = 0;
+ size_t total_output_length = 0;
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
+ mbedtls_test_driver_cipher_hooks.forced_status = force_status;
+
+ /* Test operation initialization */
+ mbedtls_psa_cipher_operation_t mbedtls_operation =
+ MBEDTLS_PSA_CIPHER_OPERATION_INIT;
+
+ mbedtls_transparent_test_driver_cipher_operation_t transparent_operation =
+ MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT;
+
+ mbedtls_opaque_test_driver_cipher_operation_t opaque_operation =
+ MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT;
+
+ operation.ctx.mbedtls_ctx = mbedtls_operation;
+ operation.ctx.transparent_test_driver_ctx = transparent_operation;
+ operation.ctx.opaque_test_driver_ctx = opaque_operation;
+
+ PSA_ASSERT(psa_crypto_init());
+
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
+
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+
+ PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ mbedtls_test_driver_cipher_hooks.hits = 0;
+
+ PSA_ASSERT(psa_cipher_set_iv(&operation, iv->x, iv->len));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, (force_status == PSA_SUCCESS ? 1 : 0));
+ mbedtls_test_driver_cipher_hooks.hits = 0;
+
+ output_buffer_size = ((size_t) input->len +
+ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type));
+ ASSERT_ALLOC(output, output_buffer_size);
+
+ if (mock_output_arg) {
+ mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
+ mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len;
+ }
+
+ TEST_ASSERT(first_part_size <= input->len);
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x, first_part_size,
+ output, output_buffer_size,
+ &function_output_length));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, (force_status == PSA_SUCCESS ? 1 : 0));
+ mbedtls_test_driver_cipher_hooks.hits = 0;
+
+ TEST_ASSERT(function_output_length == output1_length);
+ total_output_length += function_output_length;
+
+ if (first_part_size < input->len) {
+ PSA_ASSERT(psa_cipher_update(&operation,
+ input->x + first_part_size,
+ input->len - first_part_size,
+ output + total_output_length,
+ output_buffer_size - total_output_length,
+ &function_output_length));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, (force_status == PSA_SUCCESS ? 1 : 0));
+ mbedtls_test_driver_cipher_hooks.hits = 0;
+
+ TEST_ASSERT(function_output_length == output2_length);
+ total_output_length += function_output_length;
+ }
+
+ if (mock_output_arg) {
+ mbedtls_test_driver_cipher_hooks.forced_output = NULL;
+ mbedtls_test_driver_cipher_hooks.forced_output_length = 0;
+ }
+
+ status = psa_cipher_finish(&operation,
+ output + total_output_length,
+ output_buffer_size - total_output_length,
+ &function_output_length);
+ /* Finish will have called abort as well, so expecting two hits here */
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, (force_status == PSA_SUCCESS ? 2 : 0));
+ mbedtls_test_driver_cipher_hooks.hits = 0;
+ total_output_length += function_output_length;
+ TEST_EQUAL(status, expected_status);
+
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_cipher_abort(&operation));
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
+
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output, total_output_length);
+ }
+
+exit:
+ psa_cipher_abort(&operation);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void cipher_decrypt(int alg_arg,
+ int key_type_arg,
+ data_t *key_data,
+ data_t *iv,
+ data_t *input_arg,
+ data_t *expected_output,
+ int mock_output_arg,
+ int force_status_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_status_t status;
@@ -1003,59 +975,56 @@
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
mbedtls_test_driver_cipher_hooks.forced_status = force_status;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
/* Allocate input buffer and copy the iv and the plaintext */
- input_buffer_size = ( (size_t) input_arg->len + (size_t) iv->len );
- if ( input_buffer_size > 0 )
- {
- ASSERT_ALLOC( input, input_buffer_size );
- memcpy( input, iv->x, iv->len );
- memcpy( input + iv->len, input_arg->x, input_arg->len );
+ input_buffer_size = ((size_t) input_arg->len + (size_t) iv->len);
+ if (input_buffer_size > 0) {
+ ASSERT_ALLOC(input, input_buffer_size);
+ memcpy(input, iv->x, iv->len);
+ memcpy(input + iv->len, input_arg->x, input_arg->len);
}
- output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE( key_type, alg, input_buffer_size );
- ASSERT_ALLOC( output, output_buffer_size );
+ output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_buffer_size);
+ ASSERT_ALLOC(output, output_buffer_size);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- if( mock_output_arg )
- {
+ if (mock_output_arg) {
mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len;
}
- status = psa_cipher_decrypt( key, alg, input, input_buffer_size, output,
- output_buffer_size, &output_length );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
+ status = psa_cipher_decrypt(key, alg, input, input_buffer_size, output,
+ output_buffer_size, &output_length);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
mbedtls_test_driver_cipher_hooks.hits = 0;
- TEST_EQUAL( status, expected_status );
+ TEST_EQUAL(status, expected_status);
- if( expected_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( expected_output->x, expected_output->len,
- output, output_length );
+ if (expected_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_output->x, expected_output->len,
+ output, output_length);
}
exit:
- mbedtls_free( input );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ mbedtls_free(input);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_entry_points( int alg_arg, int key_type_arg,
- data_t *key_data, data_t *iv,
- data_t *input )
+void cipher_entry_points(int alg_arg, int key_type_arg,
+ data_t *key_data, data_t *iv,
+ data_t *input)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_status_t status;
@@ -1068,17 +1037,17 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
- ASSERT_ALLOC( output, input->len + 16 );
+ ASSERT_ALLOC(output, input->len + 16);
output_buffer_size = input->len + 16;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/*
* Test encrypt failure
@@ -1087,195 +1056,195 @@
*/
status = psa_cipher_encrypt(
key, alg, input->x, input->len,
- output, output_buffer_size, &function_output_length );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, PSA_SUCCESS );
+ output, output_buffer_size, &function_output_length);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, PSA_SUCCESS);
mbedtls_test_driver_cipher_hooks.hits = 0;
mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
/* Set the output buffer in a given state. */
- for( size_t i = 0; i < output_buffer_size; i++ )
+ for (size_t i = 0; i < output_buffer_size; i++) {
output[i] = 0xa5;
+ }
status = psa_cipher_encrypt(
key, alg, input->x, input->len,
- output, output_buffer_size, &function_output_length );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, PSA_ERROR_GENERIC_ERROR );
+ output, output_buffer_size, &function_output_length);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, PSA_ERROR_GENERIC_ERROR);
/*
* Check that the output buffer is still in the same state.
* This will fail if the output buffer is used by the core to pass the IV
* it generated to the driver (and is not restored).
*/
- for( size_t i = 0; i < output_buffer_size; i++ )
- {
- TEST_EQUAL( output[i], 0xa5 );
+ for (size_t i = 0; i < output_buffer_size; i++) {
+ TEST_EQUAL(output[i], 0xa5);
}
mbedtls_test_driver_cipher_hooks.hits = 0;
/* Test setup call, encrypt */
mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
- status = psa_cipher_encrypt_setup( &operation, key, alg );
+ status = psa_cipher_encrypt_setup(&operation, key, alg);
/* When setup fails, it shouldn't call any further entry points */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_set_iv( &operation, iv->x, iv->len );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
+ status = psa_cipher_set_iv(&operation, iv->x, iv->len);
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
/* Test setup call failure, decrypt */
- status = psa_cipher_decrypt_setup( &operation, key, alg );
+ status = psa_cipher_decrypt_setup(&operation, key, alg);
/* When setup fails, it shouldn't call any further entry points */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_set_iv( &operation, iv->x, iv->len );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
+ status = psa_cipher_set_iv(&operation, iv->x, iv->len);
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
/* Test IV setting failure */
mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
- status = psa_cipher_encrypt_setup( &operation, key, alg );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ status = psa_cipher_encrypt_setup(&operation, key, alg);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
- status = psa_cipher_set_iv( &operation, iv->x, iv->len );
+ status = psa_cipher_set_iv(&operation, iv->x, iv->len);
/* When setting the IV fails, it should call abort too */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 2);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
/* Failure should prevent further operations from executing on the driver */
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_update( &operation,
- input->x, input->len,
- output, output_buffer_size,
- &function_output_length );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
- psa_cipher_abort( &operation );
+ status = psa_cipher_update(&operation,
+ input->x, input->len,
+ output, output_buffer_size,
+ &function_output_length);
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
+ psa_cipher_abort(&operation);
/* Test IV generation failure */
mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
- status = psa_cipher_encrypt_setup( &operation, key, alg );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ status = psa_cipher_encrypt_setup(&operation, key, alg);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
/* Set the output buffer in a given state. */
- for( size_t i = 0; i < 16; i++ )
+ for (size_t i = 0; i < 16; i++) {
output[i] = 0xa5;
+ }
- status = psa_cipher_generate_iv( &operation, output, 16, &function_output_length );
+ status = psa_cipher_generate_iv(&operation, output, 16, &function_output_length);
/* When generating the IV fails, it should call abort too */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 2);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
/*
* Check that the output buffer is still in the same state.
* This will fail if the output buffer is used by the core to pass the IV
* it generated to the driver (and is not restored).
*/
- for( size_t i = 0; i < 16; i++ )
- {
- TEST_EQUAL( output[i], 0xa5 );
+ for (size_t i = 0; i < 16; i++) {
+ TEST_EQUAL(output[i], 0xa5);
}
/* Failure should prevent further operations from executing on the driver */
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_update( &operation,
- input->x, input->len,
- output, output_buffer_size,
- &function_output_length );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
- psa_cipher_abort( &operation );
+ status = psa_cipher_update(&operation,
+ input->x, input->len,
+ output, output_buffer_size,
+ &function_output_length);
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
+ psa_cipher_abort(&operation);
/* Test update failure */
mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
- status = psa_cipher_encrypt_setup( &operation, key, alg );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ status = psa_cipher_encrypt_setup(&operation, key, alg);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_set_iv( &operation, iv->x, iv->len );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ status = psa_cipher_set_iv(&operation, iv->x, iv->len);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
- status = psa_cipher_update( &operation,
- input->x, input->len,
- output, output_buffer_size,
- &function_output_length );
+ status = psa_cipher_update(&operation,
+ input->x, input->len,
+ output, output_buffer_size,
+ &function_output_length);
/* When the update call fails, it should call abort too */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 2);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
/* Failure should prevent further operations from executing on the driver */
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_update( &operation,
- input->x, input->len,
- output, output_buffer_size,
- &function_output_length );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
- psa_cipher_abort( &operation );
+ status = psa_cipher_update(&operation,
+ input->x, input->len,
+ output, output_buffer_size,
+ &function_output_length);
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
+ psa_cipher_abort(&operation);
/* Test finish failure */
mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
- status = psa_cipher_encrypt_setup( &operation, key, alg );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ status = psa_cipher_encrypt_setup(&operation, key, alg);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_set_iv( &operation, iv->x, iv->len );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ status = psa_cipher_set_iv(&operation, iv->x, iv->len);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_update( &operation,
- input->x, input->len,
- output, output_buffer_size,
- &function_output_length );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ status = psa_cipher_update(&operation,
+ input->x, input->len,
+ output, output_buffer_size,
+ &function_output_length);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 1);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
mbedtls_test_driver_cipher_hooks.hits = 0;
mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
- status = psa_cipher_finish( &operation,
- output + function_output_length,
- output_buffer_size - function_output_length,
- &function_output_length );
+ status = psa_cipher_finish(&operation,
+ output + function_output_length,
+ output_buffer_size - function_output_length,
+ &function_output_length);
/* When the finish call fails, it should call abort too */
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
- TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 2);
+ TEST_EQUAL(status, mbedtls_test_driver_cipher_hooks.forced_status);
/* Failure should prevent further operations from executing on the driver */
mbedtls_test_driver_cipher_hooks.hits = 0;
- status = psa_cipher_update( &operation,
- input->x, input->len,
- output, output_buffer_size,
- &function_output_length );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
- psa_cipher_abort( &operation );
+ status = psa_cipher_update(&operation,
+ input->x, input->len,
+ output, output_buffer_size,
+ &function_output_length);
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
+ psa_cipher_abort(&operation);
exit:
- psa_cipher_abort( &operation );
- mbedtls_free( output );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ mbedtls_free(output);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_encrypt( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- data_t *expected_result,
- int forced_status_arg )
+void aead_encrypt(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ data_t *expected_result,
+ int forced_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -1289,62 +1258,61 @@
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = input_data->len + PSA_AEAD_TAG_LENGTH( key_type, key_bits,
- alg );
+ output_size = input_data->len + PSA_AEAD_TAG_LENGTH(key_type, key_bits,
+ alg);
/* For all currently defined algorithms, PSA_AEAD_ENCRYPT_OUTPUT_SIZE
* should be exact. */
- TEST_EQUAL( output_size,
- PSA_AEAD_ENCRYPT_OUTPUT_SIZE( key_type, alg, input_data->len ) );
- TEST_ASSERT( output_size <=
- PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
- ASSERT_ALLOC( output_data, output_size );
+ TEST_EQUAL(output_size,
+ PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
+ TEST_ASSERT(output_size <=
+ PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
+ ASSERT_ALLOC(output_data, output_size);
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
- status = psa_aead_encrypt( key, alg,
- nonce->x, nonce->len,
- additional_data->x, additional_data->len,
- input_data->x, input_data->len,
- output_data, output_size,
- &output_length );
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_encrypt, 1 );
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status );
+ status = psa_aead_encrypt(key, alg,
+ nonce->x, nonce->len,
+ additional_data->x, additional_data->len,
+ input_data->x, input_data->len,
+ output_data, output_size,
+ &output_length);
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_encrypt, 1);
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.driver_status, forced_status);
- TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ?
- PSA_SUCCESS : forced_status );
+ TEST_EQUAL(status, (forced_status == PSA_ERROR_NOT_SUPPORTED) ?
+ PSA_SUCCESS : forced_status);
- if( status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( expected_result->x, expected_result->len,
- output_data, output_length );
+ if (status == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_result->x, expected_result->len,
+ output_data, output_length);
}
exit:
- psa_destroy_key( key );
- mbedtls_free( output_data );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output_data);
+ PSA_DONE();
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_decrypt( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- data_t *expected_data,
- int forced_status_arg )
+void aead_decrypt(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ data_t *expected_data,
+ int forced_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -1358,56 +1326,55 @@
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = input_data->len - PSA_AEAD_TAG_LENGTH( key_type, key_bits,
- alg );
- ASSERT_ALLOC( output_data, output_size );
+ output_size = input_data->len - PSA_AEAD_TAG_LENGTH(key_type, key_bits,
+ alg);
+ ASSERT_ALLOC(output_data, output_size);
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
- status = psa_aead_decrypt( key, alg,
- nonce->x, nonce->len,
- additional_data->x,
- additional_data->len,
- input_data->x, input_data->len,
- output_data, output_size,
- &output_length );
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_decrypt, 1 );
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status );
+ status = psa_aead_decrypt(key, alg,
+ nonce->x, nonce->len,
+ additional_data->x,
+ additional_data->len,
+ input_data->x, input_data->len,
+ output_data, output_size,
+ &output_length);
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_decrypt, 1);
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.driver_status, forced_status);
- TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ?
- PSA_SUCCESS : forced_status );
+ TEST_EQUAL(status, (forced_status == PSA_ERROR_NOT_SUPPORTED) ?
+ PSA_SUCCESS : forced_status);
- if( status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( expected_data->x, expected_data->len,
- output_data, output_length );
+ if (status == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_data->x, expected_data->len,
+ output_data, output_length);
}
exit:
- psa_destroy_key( key );
- mbedtls_free( output_data );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output_data);
+ PSA_DONE();
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_sign( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input,
- data_t *expected_mac,
- int forced_status_arg )
+void mac_sign(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input,
+ data_t *expected_mac,
+ int forced_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -1416,74 +1383,72 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *actual_mac = NULL;
size_t mac_buffer_size =
- PSA_MAC_LENGTH( key_type, PSA_BYTES_TO_BITS( key_data->len ), alg );
+ PSA_MAC_LENGTH(key_type, PSA_BYTES_TO_BITS(key_data->len), alg);
size_t mac_length = 0;
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_status_t forced_status = forced_status_arg;
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
- TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE );
+ TEST_ASSERT(mac_buffer_size <= PSA_MAC_MAX_SIZE);
/* We expect PSA_MAC_LENGTH to be exact. */
- TEST_ASSERT( expected_mac->len == mac_buffer_size );
+ TEST_ASSERT(expected_mac->len == mac_buffer_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- ASSERT_ALLOC( actual_mac, mac_buffer_size );
+ ASSERT_ALLOC(actual_mac, mac_buffer_size);
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/*
* Calculate the MAC, one-shot case.
*/
- status = psa_mac_compute( key, alg,
- input->x, input->len,
- actual_mac, mac_buffer_size,
- &mac_length );
+ status = psa_mac_compute(key, alg,
+ input->x, input->len,
+ actual_mac, mac_buffer_size,
+ &mac_length);
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
- }
- else
- TEST_EQUAL( forced_status, status );
-
- PSA_ASSERT( psa_mac_abort( &operation ) );
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
-
- if( forced_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( expected_mac->x, expected_mac->len,
- actual_mac, mac_length );
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(forced_status, status);
}
- mbedtls_free( actual_mac );
+ PSA_ASSERT(psa_mac_abort(&operation));
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
+
+ if (forced_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_mac->x, expected_mac->len,
+ actual_mac, mac_length);
+ }
+
+ mbedtls_free(actual_mac);
actual_mac = NULL;
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( actual_mac );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(actual_mac);
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_sign_multipart( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input,
- data_t *expected_mac,
- int fragments_count,
- int forced_status_arg )
+void mac_sign_multipart(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input,
+ data_t *expected_mac,
+ int fragments_count,
+ int forced_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -1492,117 +1457,115 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *actual_mac = NULL;
size_t mac_buffer_size =
- PSA_MAC_LENGTH( key_type, PSA_BYTES_TO_BITS( key_data->len ), alg );
+ PSA_MAC_LENGTH(key_type, PSA_BYTES_TO_BITS(key_data->len), alg);
size_t mac_length = 0;
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_status_t forced_status = forced_status_arg;
uint8_t *input_x = input->x;
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
- TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE );
+ TEST_ASSERT(mac_buffer_size <= PSA_MAC_MAX_SIZE);
/* We expect PSA_MAC_LENGTH to be exact. */
- TEST_ASSERT( expected_mac->len == mac_buffer_size );
+ TEST_ASSERT(expected_mac->len == mac_buffer_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- ASSERT_ALLOC( actual_mac, mac_buffer_size );
+ ASSERT_ALLOC(actual_mac, mac_buffer_size);
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/*
* Calculate the MAC, multipart case.
*/
- status = psa_mac_sign_setup( &operation, key, alg );
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
+ status = psa_mac_sign_setup(&operation, key, alg);
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
- }
- else
- TEST_EQUAL( forced_status, status );
-
- if ( fragments_count )
- {
- TEST_ASSERT( ( input->len / fragments_count ) > 0 );
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(forced_status, status);
}
- for ( int i = 0; i < fragments_count; i++)
- {
+ if (fragments_count) {
+ TEST_ASSERT((input->len / fragments_count) > 0);
+ }
+
+ for (int i = 0; i < fragments_count; i++) {
int fragment_size = input->len / fragments_count;
- if ( i == fragments_count - 1 )
- fragment_size += ( input->len % fragments_count );
-
- status = psa_mac_update( &operation,
- input_x, fragment_size );
- if( forced_status == PSA_SUCCESS )
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 2 + i );
- else
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
+ if (i == fragments_count - 1) {
+ fragment_size += (input->len % fragments_count);
}
- else
- TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
+
+ status = psa_mac_update(&operation,
+ input_x, fragment_size);
+ if (forced_status == PSA_SUCCESS) {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 2 + i);
+ } else {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
+ }
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(PSA_ERROR_BAD_STATE, status);
+ }
input_x += fragment_size;
}
- status = psa_mac_sign_finish( &operation,
- actual_mac, mac_buffer_size,
- &mac_length );
- if( forced_status == PSA_SUCCESS )
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count );
- else
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
-
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
- }
- else
- TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
-
- PSA_ASSERT( psa_mac_abort( &operation ) );
- if( forced_status == PSA_SUCCESS )
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count );
- else
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
-
- if( forced_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( expected_mac->x, expected_mac->len,
- actual_mac, mac_length );
+ status = psa_mac_sign_finish(&operation,
+ actual_mac, mac_buffer_size,
+ &mac_length);
+ if (forced_status == PSA_SUCCESS) {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count);
+ } else {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
}
- mbedtls_free( actual_mac );
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(PSA_ERROR_BAD_STATE, status);
+ }
+
+ PSA_ASSERT(psa_mac_abort(&operation));
+ if (forced_status == PSA_SUCCESS) {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count);
+ } else {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
+ }
+
+ if (forced_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(expected_mac->x, expected_mac->len,
+ actual_mac, mac_length);
+ }
+
+ mbedtls_free(actual_mac);
actual_mac = NULL;
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( actual_mac );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(actual_mac);
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_verify( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input,
- data_t *expected_mac,
- int forced_status_arg )
+void mac_verify(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input,
+ data_t *expected_mac,
+ int forced_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -1613,52 +1576,51 @@
psa_status_t forced_status = forced_status_arg;
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
- TEST_ASSERT( expected_mac->len <= PSA_MAC_MAX_SIZE );
+ TEST_ASSERT(expected_mac->len <= PSA_MAC_MAX_SIZE);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/*
* Verify the MAC, one-shot case.
*/
- status = psa_mac_verify( key, alg,
- input->x, input->len,
- expected_mac->x, expected_mac->len );
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
+ status = psa_mac_verify(key, alg,
+ input->x, input->len,
+ expected_mac->x, expected_mac->len);
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(forced_status, status);
}
- else
- TEST_EQUAL( forced_status, status );
- PSA_ASSERT( psa_mac_abort( &operation ) );
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
+ PSA_ASSERT(psa_mac_abort(&operation));
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_verify_multipart( int key_type_arg,
- data_t *key_data,
- int alg_arg,
- data_t *input,
- data_t *expected_mac,
- int fragments_count,
- int forced_status_arg )
+void mac_verify_multipart(int key_type_arg,
+ data_t *key_data,
+ int alg_arg,
+ data_t *input,
+ data_t *expected_mac,
+ int fragments_count,
+ int forced_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -1670,99 +1632,98 @@
uint8_t *input_x = input->x;
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
- TEST_ASSERT( expected_mac->len <= PSA_MAC_MAX_SIZE );
+ TEST_ASSERT(expected_mac->len <= PSA_MAC_MAX_SIZE);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/*
* Verify the MAC, multi-part case.
*/
- status = psa_mac_verify_setup( &operation, key, alg );
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
+ status = psa_mac_verify_setup(&operation, key, alg);
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
- }
- else
- TEST_EQUAL( forced_status, status );
-
- if ( fragments_count )
- {
- TEST_ASSERT( ( input->len / fragments_count ) > 0 );
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(forced_status, status);
}
- for ( int i = 0; i < fragments_count; i++)
- {
+ if (fragments_count) {
+ TEST_ASSERT((input->len / fragments_count) > 0);
+ }
+
+ for (int i = 0; i < fragments_count; i++) {
int fragment_size = input->len / fragments_count;
- if ( i == fragments_count - 1 )
- fragment_size += ( input->len % fragments_count );
-
- status = psa_mac_update( &operation,
- input_x, fragment_size );
- if( forced_status == PSA_SUCCESS )
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 2 + i );
- else
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
-
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
+ if (i == fragments_count - 1) {
+ fragment_size += (input->len % fragments_count);
}
- else
- TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
+
+ status = psa_mac_update(&operation,
+ input_x, fragment_size);
+ if (forced_status == PSA_SUCCESS) {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 2 + i);
+ } else {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
+ }
+
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(PSA_ERROR_BAD_STATE, status);
+ }
input_x += fragment_size;
}
- status = psa_mac_verify_finish( &operation,
- expected_mac->x,
- expected_mac->len );
- if( forced_status == PSA_SUCCESS )
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count );
- else
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
-
- if( forced_status == PSA_SUCCESS ||
- forced_status == PSA_ERROR_NOT_SUPPORTED )
- {
- PSA_ASSERT( status );
+ status = psa_mac_verify_finish(&operation,
+ expected_mac->x,
+ expected_mac->len);
+ if (forced_status == PSA_SUCCESS) {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count);
+ } else {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
}
- else
- TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
+
+ if (forced_status == PSA_SUCCESS ||
+ forced_status == PSA_ERROR_NOT_SUPPORTED) {
+ PSA_ASSERT(status);
+ } else {
+ TEST_EQUAL(PSA_ERROR_BAD_STATE, status);
+ }
- PSA_ASSERT( psa_mac_abort( &operation ) );
- if( forced_status == PSA_SUCCESS )
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count );
- else
- TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
+ PSA_ASSERT(psa_mac_abort(&operation));
+ if (forced_status == PSA_SUCCESS) {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 3 + fragments_count);
+ } else {
+ TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
+ }
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key);
+ PSA_DONE();
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_CRYPTO_DRIVER_TEST:MBEDTLS_PSA_CRYPTO_DRIVERS:MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
-void builtin_key_export( int builtin_key_id_arg,
- int builtin_key_type_arg,
- int builtin_key_bits_arg,
- int builtin_key_algorithm_arg,
- data_t *expected_output,
- int expected_status_arg )
+void builtin_key_export(int builtin_key_id_arg,
+ int builtin_key_type_arg,
+ int builtin_key_bits_arg,
+ int builtin_key_algorithm_arg,
+ data_t *expected_output,
+ int expected_status_arg)
{
psa_key_id_t builtin_key_id = (psa_key_id_t) builtin_key_id_arg;
psa_key_type_t builtin_key_type = (psa_key_type_t) builtin_key_type_arg;
@@ -1771,51 +1732,49 @@
psa_status_t expected_status = expected_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_svc_key_id_t key = mbedtls_svc_key_id_make( 0, builtin_key_id );
- uint8_t* output_buffer = NULL;
+ mbedtls_svc_key_id_t key = mbedtls_svc_key_id_make(0, builtin_key_id);
+ uint8_t *output_buffer = NULL;
size_t output_size = 0;
psa_status_t actual_status;
- PSA_ASSERT( psa_crypto_init( ) );
- ASSERT_ALLOC( output_buffer, expected_output->len );
+ PSA_ASSERT(psa_crypto_init());
+ ASSERT_ALLOC(output_buffer, expected_output->len);
- actual_status = psa_export_key( key, output_buffer, expected_output->len, &output_size );
+ actual_status = psa_export_key(key, output_buffer, expected_output->len, &output_size);
- if( expected_status == PSA_SUCCESS )
- {
- PSA_ASSERT( actual_status );
- TEST_EQUAL( output_size, expected_output->len );
- ASSERT_COMPARE( output_buffer, output_size,
- expected_output->x, expected_output->len );
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(actual_status);
+ TEST_EQUAL(output_size, expected_output->len);
+ ASSERT_COMPARE(output_buffer, output_size,
+ expected_output->x, expected_output->len);
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_EQUAL( psa_get_key_bits( &attributes ), builtin_key_bits );
- TEST_EQUAL( psa_get_key_type( &attributes ), builtin_key_type );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), builtin_key_alg );
- }
- else
- {
- if( actual_status != expected_status )
- fprintf( stderr, "Expected %d but got %d\n", expected_status, actual_status );
- TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( output_size, 0 );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_EQUAL(psa_get_key_bits(&attributes), builtin_key_bits);
+ TEST_EQUAL(psa_get_key_type(&attributes), builtin_key_type);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), builtin_key_alg);
+ } else {
+ if (actual_status != expected_status) {
+ fprintf(stderr, "Expected %d but got %d\n", expected_status, actual_status);
+ }
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_EQUAL(output_size, 0);
}
exit:
- mbedtls_free( output_buffer );
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ mbedtls_free(output_buffer);
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_CRYPTO_DRIVER_TEST:MBEDTLS_PSA_CRYPTO_DRIVERS:MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
-void builtin_pubkey_export( int builtin_key_id_arg,
- int builtin_key_type_arg,
- int builtin_key_bits_arg,
- int builtin_key_algorithm_arg,
- data_t *expected_output,
- int expected_status_arg )
+void builtin_pubkey_export(int builtin_key_id_arg,
+ int builtin_key_type_arg,
+ int builtin_key_bits_arg,
+ int builtin_key_algorithm_arg,
+ data_t *expected_output,
+ int expected_status_arg)
{
psa_key_id_t builtin_key_id = (psa_key_id_t) builtin_key_id_arg;
psa_key_type_t builtin_key_type = (psa_key_type_t) builtin_key_type_arg;
@@ -1824,47 +1783,44 @@
psa_status_t expected_status = expected_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_svc_key_id_t key = mbedtls_svc_key_id_make( 0, builtin_key_id );
- uint8_t* output_buffer = NULL;
+ mbedtls_svc_key_id_t key = mbedtls_svc_key_id_make(0, builtin_key_id);
+ uint8_t *output_buffer = NULL;
size_t output_size = 0;
psa_status_t actual_status;
- PSA_ASSERT( psa_crypto_init( ) );
- ASSERT_ALLOC( output_buffer, expected_output->len );
+ PSA_ASSERT(psa_crypto_init());
+ ASSERT_ALLOC(output_buffer, expected_output->len);
- actual_status = psa_export_public_key( key, output_buffer, expected_output->len, &output_size );
+ actual_status = psa_export_public_key(key, output_buffer, expected_output->len, &output_size);
- if( expected_status == PSA_SUCCESS )
- {
- PSA_ASSERT( actual_status );
- TEST_EQUAL( output_size, expected_output->len );
- ASSERT_COMPARE( output_buffer, output_size,
- expected_output->x, expected_output->len );
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(actual_status);
+ TEST_EQUAL(output_size, expected_output->len);
+ ASSERT_COMPARE(output_buffer, output_size,
+ expected_output->x, expected_output->len);
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_EQUAL( psa_get_key_bits( &attributes ), builtin_key_bits );
- TEST_EQUAL( psa_get_key_type( &attributes ), builtin_key_type );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), builtin_key_alg );
- }
- else
- {
- TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( output_size, 0 );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_EQUAL(psa_get_key_bits(&attributes), builtin_key_bits);
+ TEST_EQUAL(psa_get_key_type(&attributes), builtin_key_type);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), builtin_key_alg);
+ } else {
+ TEST_EQUAL(actual_status, expected_status);
+ TEST_EQUAL(output_size, 0);
}
exit:
- mbedtls_free( output_buffer );
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key );
- PSA_DONE( );
+ mbedtls_free(output_buffer);
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_compute( int alg_arg,
- data_t *input, data_t *hash,
- int forced_status_arg,
- int expected_status_arg )
+void hash_compute(int alg_arg,
+ data_t *input, data_t *hash,
+ int forced_status_arg,
+ int expected_status_arg)
{
psa_algorithm_t alg = alg_arg;
psa_status_t forced_status = forced_status_arg;
@@ -1875,79 +1831,77 @@
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
mbedtls_test_driver_hash_hooks.forced_status = forced_status;
- PSA_ASSERT( psa_crypto_init( ) );
- ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
+ PSA_ASSERT(psa_crypto_init());
+ ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
- TEST_EQUAL( psa_hash_compute( alg, input->x, input->len,
- output, PSA_HASH_LENGTH( alg ),
- &output_length ), expected_status );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
+ TEST_EQUAL(psa_hash_compute(alg, input->x, input->len,
+ output, PSA_HASH_LENGTH(alg),
+ &output_length), expected_status);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 1);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
- if( expected_status == PSA_SUCCESS )
- {
- ASSERT_COMPARE( output, output_length, hash->x, hash->len );
+ if (expected_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(output, output_length, hash->x, hash->len);
}
exit:
- mbedtls_free( output );
- PSA_DONE( );
+ mbedtls_free(output);
+ PSA_DONE();
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_multipart_setup( int alg_arg,
+void hash_multipart_setup(int alg_arg,
+ data_t *input, data_t *hash,
+ int forced_status_arg,
+ int expected_status_arg)
+{
+ psa_algorithm_t alg = alg_arg;
+ psa_status_t forced_status = forced_status_arg;
+ psa_status_t expected_status = expected_status_arg;
+ unsigned char *output = NULL;
+ psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
+ size_t output_length;
+
+ mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
+ ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
+
+ PSA_ASSERT(psa_crypto_init());
+
+ mbedtls_test_driver_hash_hooks.forced_status = forced_status;
+ TEST_EQUAL(psa_hash_setup(&operation, alg), expected_status);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 1);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
+
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits,
+ forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 2);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
+
+ PSA_ASSERT(psa_hash_finish(&operation,
+ output, PSA_HASH_LENGTH(alg),
+ &output_length));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits,
+ forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
+
+ ASSERT_COMPARE(output, output_length, hash->x, hash->len);
+ }
+
+exit:
+ psa_hash_abort(&operation);
+ mbedtls_free(output);
+ PSA_DONE();
+ mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void hash_multipart_update(int alg_arg,
data_t *input, data_t *hash,
- int forced_status_arg,
- int expected_status_arg )
-{
- psa_algorithm_t alg = alg_arg;
- psa_status_t forced_status = forced_status_arg;
- psa_status_t expected_status = expected_status_arg;
- unsigned char *output = NULL;
- psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
- size_t output_length;
-
- mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
- ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
-
- PSA_ASSERT( psa_crypto_init( ) );
-
- mbedtls_test_driver_hash_hooks.forced_status = forced_status;
- TEST_EQUAL( psa_hash_setup( &operation, alg ), expected_status );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
-
- if( expected_status == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
- forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 2 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
-
- PSA_ASSERT( psa_hash_finish( &operation,
- output, PSA_HASH_LENGTH( alg ),
- &output_length ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
- forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
-
- ASSERT_COMPARE( output, output_length, hash->x, hash->len );
- }
-
-exit:
- psa_hash_abort( &operation );
- mbedtls_free( output );
- PSA_DONE( );
- mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void hash_multipart_update( int alg_arg,
- data_t *input, data_t *hash,
- int forced_status_arg )
+ int forced_status_arg)
{
psa_algorithm_t alg = alg_arg;
psa_status_t forced_status = forced_status_arg;
@@ -1956,54 +1910,53 @@
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
- ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
+ ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/*
* Update inactive operation, the driver shouldn't be called.
*/
- TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 );
+ TEST_EQUAL(psa_hash_update(&operation, input->x, input->len),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 0);
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 1);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
mbedtls_test_driver_hash_hooks.forced_status = forced_status;
- TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ),
- forced_status );
+ TEST_EQUAL(psa_hash_update(&operation, input->x, input->len),
+ forced_status);
/* One or two more calls to the driver interface: update or update + abort */
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
- forced_status == PSA_SUCCESS ? 2 : 3 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits,
+ forced_status == PSA_SUCCESS ? 2 : 3);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
- if( forced_status == PSA_SUCCESS )
- {
+ if (forced_status == PSA_SUCCESS) {
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
- PSA_ASSERT( psa_hash_finish( &operation,
- output, PSA_HASH_LENGTH( alg ),
- &output_length ) );
+ PSA_ASSERT(psa_hash_finish(&operation,
+ output, PSA_HASH_LENGTH(alg),
+ &output_length));
/* Two calls to the driver interface: update + abort */
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 2);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
- ASSERT_COMPARE( output, output_length, hash->x, hash->len );
+ ASSERT_COMPARE(output, output_length, hash->x, hash->len);
}
exit:
- psa_hash_abort( &operation );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_hash_abort(&operation);
+ mbedtls_free(output);
+ PSA_DONE();
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_multipart_finish( int alg_arg,
- data_t *input, data_t *hash,
- int forced_status_arg )
+void hash_multipart_finish(int alg_arg,
+ data_t *input, data_t *hash,
+ int forced_status_arg)
{
psa_algorithm_t alg = alg_arg;
psa_status_t forced_status = forced_status_arg;
@@ -2012,50 +1965,51 @@
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
- ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
+ ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/*
* Finish inactive operation, the driver shouldn't be called.
*/
- TEST_EQUAL( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ),
- &output_length ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 );
+ TEST_EQUAL(psa_hash_finish(&operation, output, PSA_HASH_LENGTH(alg),
+ &output_length),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 0);
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 1);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
- PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
+ PSA_ASSERT(psa_hash_update(&operation, input->x, input->len));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 2);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
mbedtls_test_driver_hash_hooks.forced_status = forced_status;
- TEST_EQUAL( psa_hash_finish( &operation,
- output, PSA_HASH_LENGTH( alg ),
- &output_length ),
- forced_status );
+ TEST_EQUAL(psa_hash_finish(&operation,
+ output, PSA_HASH_LENGTH(alg),
+ &output_length),
+ forced_status);
/* Two more calls to the driver interface: finish + abort */
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 4);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
- if( forced_status == PSA_SUCCESS )
- ASSERT_COMPARE( output, output_length, hash->x, hash->len );
+ if (forced_status == PSA_SUCCESS) {
+ ASSERT_COMPARE(output, output_length, hash->x, hash->len);
+ }
exit:
- psa_hash_abort( &operation );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_hash_abort(&operation);
+ mbedtls_free(output);
+ PSA_DONE();
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_clone( int alg_arg,
- data_t *input, data_t *hash,
- int forced_status_arg )
+void hash_clone(int alg_arg,
+ data_t *input, data_t *hash,
+ int forced_status_arg)
{
psa_algorithm_t alg = alg_arg;
psa_status_t forced_status = forced_status_arg;
@@ -2065,65 +2019,64 @@
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
- ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
+ ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/*
* Clone inactive operation, the driver shouldn't be called.
*/
- TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 );
+ TEST_EQUAL(psa_hash_clone(&source_operation, &target_operation),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 0);
- PSA_ASSERT( psa_hash_setup( &source_operation, alg ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
+ PSA_ASSERT(psa_hash_setup(&source_operation, alg));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 1);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
mbedtls_test_driver_hash_hooks.forced_status = forced_status;
- TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ),
- forced_status );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
- forced_status == PSA_SUCCESS ? 2 : 3 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
+ TEST_EQUAL(psa_hash_clone(&source_operation, &target_operation),
+ forced_status);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits,
+ forced_status == PSA_SUCCESS ? 2 : 3);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
- if( forced_status == PSA_SUCCESS )
- {
+ if (forced_status == PSA_SUCCESS) {
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
- PSA_ASSERT( psa_hash_update( &target_operation,
- input->x, input->len ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
+ PSA_ASSERT(psa_hash_update(&target_operation,
+ input->x, input->len));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 1);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
- PSA_ASSERT( psa_hash_finish( &target_operation,
- output, PSA_HASH_LENGTH( alg ),
- &output_length ) );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 3 );
- TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
+ PSA_ASSERT(psa_hash_finish(&target_operation,
+ output, PSA_HASH_LENGTH(alg),
+ &output_length));
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 3);
+ TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
- ASSERT_COMPARE( output, output_length, hash->x, hash->len );
+ ASSERT_COMPARE(output, output_length, hash->x, hash->len);
}
exit:
- psa_hash_abort( &source_operation );
- psa_hash_abort( &target_operation );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_hash_abort(&source_operation);
+ psa_hash_abort(&target_operation);
+ mbedtls_free(output);
+ PSA_DONE();
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_encrypt_decrypt( int alg_arg,
- data_t *key_data,
- data_t *input_data,
- data_t *label,
- data_t *fake_output_encrypt,
- data_t *fake_output_decrypt,
- int forced_status_encrypt_arg,
- int forced_status_decrypt_arg,
- int expected_status_encrypt_arg,
- int expected_status_decrypt_arg )
+void asymmetric_encrypt_decrypt(int alg_arg,
+ data_t *key_data,
+ data_t *input_data,
+ data_t *label,
+ data_t *fake_output_encrypt,
+ data_t *fake_output_decrypt,
+ int forced_status_encrypt_arg,
+ int forced_status_decrypt_arg,
+ int expected_status_encrypt_arg,
+ int expected_status_decrypt_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEY_PAIR;
@@ -2141,91 +2094,83 @@
psa_status_t expected_status_decrypt = expected_status_decrypt_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
mbedtls_test_driver_asymmetric_encryption_hooks =
mbedtls_test_driver_asymmetric_encryption_hooks_init();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
/* Determine the maximum ciphertext length */
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
mbedtls_test_driver_asymmetric_encryption_hooks.forced_status =
forced_status_encrypt;
- if ( fake_output_encrypt->len > 0 )
- {
+ if (fake_output_encrypt->len > 0) {
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output =
fake_output_encrypt->x;
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_encrypt->len;
output_size = fake_output_encrypt->len;
- ASSERT_ALLOC( output, output_size );
- }
- else
- {
- output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
- TEST_ASSERT( output_size <= PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE );
- ASSERT_ALLOC( output, output_size );
+ ASSERT_ALLOC(output, output_size);
+ } else {
+ output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
+ TEST_ASSERT(output_size <= PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE);
+ ASSERT_ALLOC(output, output_size);
}
/* We test encryption by checking that encrypt-then-decrypt gives back
* the original plaintext because of the non-optional random
* part of encryption process which prevents using fixed vectors. */
- TEST_EQUAL( psa_asymmetric_encrypt( key, alg,
- input_data->x, input_data->len,
- label->x, label->len,
- output, output_size,
- &output_length ), expected_status_encrypt );
+ TEST_EQUAL(psa_asymmetric_encrypt(key, alg,
+ input_data->x, input_data->len,
+ label->x, label->len,
+ output, output_size,
+ &output_length), expected_status_encrypt);
/* We don't know what ciphertext length to expect, but check that
* it looks sensible. */
- TEST_ASSERT( output_length <= output_size );
+ TEST_ASSERT(output_length <= output_size);
- if ( expected_status_encrypt == PSA_SUCCESS )
- {
- if ( fake_output_encrypt->len > 0 )
- ASSERT_COMPARE( fake_output_encrypt->x, fake_output_encrypt->len,
- output, output_length );
- else
- {
+ if (expected_status_encrypt == PSA_SUCCESS) {
+ if (fake_output_encrypt->len > 0) {
+ ASSERT_COMPARE(fake_output_encrypt->x, fake_output_encrypt->len,
+ output, output_length);
+ } else {
mbedtls_test_driver_asymmetric_encryption_hooks.forced_status =
forced_status_decrypt;
- if ( fake_output_decrypt->len > 0 )
- {
+ if (fake_output_decrypt->len > 0) {
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output =
fake_output_decrypt->x;
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_decrypt->len;
output2_size = fake_output_decrypt->len;
- ASSERT_ALLOC( output2, output2_size );
- }
- else
- {
+ ASSERT_ALLOC(output2, output2_size);
+ } else {
output2_size = input_data->len;
- TEST_ASSERT( output2_size <=
- PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE( key_type, key_bits, alg ) );
- TEST_ASSERT( output2_size <= PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE );
- ASSERT_ALLOC( output2, output2_size );
+ TEST_ASSERT(output2_size <=
+ PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg));
+ TEST_ASSERT(output2_size <= PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE);
+ ASSERT_ALLOC(output2, output2_size);
}
- TEST_EQUAL( psa_asymmetric_decrypt( key, alg,
- output, output_length,
- label->x, label->len,
- output2, output2_size,
- &output2_length ), expected_status_decrypt );
- if ( expected_status_decrypt == PSA_SUCCESS )
- {
- if ( fake_output_decrypt->len > 0 )
- ASSERT_COMPARE( fake_output_decrypt->x, fake_output_decrypt->len,
- output2, output2_length );
- else
- ASSERT_COMPARE( input_data->x, input_data->len,
- output2, output2_length );
+ TEST_EQUAL(psa_asymmetric_decrypt(key, alg,
+ output, output_length,
+ label->x, label->len,
+ output2, output2_size,
+ &output2_length), expected_status_decrypt);
+ if (expected_status_decrypt == PSA_SUCCESS) {
+ if (fake_output_decrypt->len > 0) {
+ ASSERT_COMPARE(fake_output_decrypt->x, fake_output_decrypt->len,
+ output2, output2_length);
+ } else {
+ ASSERT_COMPARE(input_data->x, input_data->len,
+ output2, output2_length);
+ }
}
}
}
@@ -2235,24 +2180,24 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( output );
- mbedtls_free( output2 );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ mbedtls_free(output2);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_decrypt( int alg_arg,
- data_t *key_data,
- data_t *input_data,
- data_t *label,
- data_t *expected_output_data,
- data_t *fake_output_decrypt,
- int forced_status_decrypt_arg,
- int expected_status_decrypt_arg )
+void asymmetric_decrypt(int alg_arg,
+ data_t *key_data,
+ data_t *input_data,
+ data_t *label,
+ data_t *expected_output_data,
+ data_t *fake_output_decrypt,
+ int forced_status_decrypt_arg,
+ int expected_status_decrypt_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEY_PAIR;
@@ -2264,69 +2209,65 @@
psa_status_t expected_status_decrypt = expected_status_decrypt_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
mbedtls_test_driver_asymmetric_encryption_hooks =
mbedtls_test_driver_asymmetric_encryption_hooks_init();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
mbedtls_test_driver_asymmetric_encryption_hooks.forced_status =
forced_status_decrypt;
- if ( fake_output_decrypt->len > 0 )
- {
+ if (fake_output_decrypt->len > 0) {
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output =
fake_output_decrypt->x;
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_decrypt->len;
output_size = fake_output_decrypt->len;
- ASSERT_ALLOC( output, output_size );
- }
- else
- {
+ ASSERT_ALLOC(output, output_size);
+ } else {
output_size = expected_output_data->len;
- ASSERT_ALLOC( output, expected_output_data->len );
+ ASSERT_ALLOC(output, expected_output_data->len);
}
- TEST_EQUAL( psa_asymmetric_decrypt( key, alg,
- input_data->x, input_data->len,
- label->x, label->len,
- output, output_size,
- &output_length ), expected_status_decrypt );
- if ( expected_status_decrypt == PSA_SUCCESS )
- {
- TEST_EQUAL( output_length, expected_output_data->len );
- ASSERT_COMPARE( expected_output_data->x, expected_output_data->len,
- output, output_length );
+ TEST_EQUAL(psa_asymmetric_decrypt(key, alg,
+ input_data->x, input_data->len,
+ label->x, label->len,
+ output, output_size,
+ &output_length), expected_status_decrypt);
+ if (expected_status_decrypt == PSA_SUCCESS) {
+ TEST_EQUAL(output_length, expected_output_data->len);
+ ASSERT_COMPARE(expected_output_data->x, expected_output_data->len,
+ output, output_length);
}
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_encrypt( int alg_arg,
- data_t *key_data,
- data_t *modulus,
- data_t *private_exponent,
- data_t *input_data,
- data_t *label,
- data_t *fake_output_encrypt,
- int forced_status_encrypt_arg,
- int expected_status_encrypt_arg )
+void asymmetric_encrypt(int alg_arg,
+ data_t *key_data,
+ data_t *modulus,
+ data_t *private_exponent,
+ data_t *input_data,
+ data_t *label,
+ data_t *fake_output_encrypt,
+ int forced_status_encrypt_arg,
+ int expected_status_encrypt_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_PUBLIC_KEY;
@@ -2338,69 +2279,61 @@
psa_status_t expected_status_encrypt = expected_status_encrypt_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
mbedtls_test_driver_asymmetric_encryption_hooks =
mbedtls_test_driver_asymmetric_encryption_hooks_init();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- size_t key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ size_t key_bits = psa_get_key_bits(&attributes);
mbedtls_test_driver_asymmetric_encryption_hooks.forced_status =
forced_status_encrypt;
- if ( fake_output_encrypt->len > 0 )
- {
+ if (fake_output_encrypt->len > 0) {
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output =
fake_output_encrypt->x;
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_encrypt->len;
output_size = fake_output_encrypt->len;
- ASSERT_ALLOC( output, output_size );
- }
- else
- {
- output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg );
- ASSERT_ALLOC( output, output_size );
+ ASSERT_ALLOC(output, output_size);
+ } else {
+ output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
+ ASSERT_ALLOC(output, output_size);
}
- TEST_EQUAL( psa_asymmetric_encrypt( key, alg,
- input_data->x, input_data->len,
- label->x, label->len,
- output, output_size,
- &output_length ), expected_status_encrypt );
- if ( expected_status_encrypt == PSA_SUCCESS )
- {
- if( fake_output_encrypt->len > 0 )
- {
- TEST_EQUAL( fake_output_encrypt->len, output_length );
- ASSERT_COMPARE( fake_output_encrypt->x, fake_output_encrypt->len,
- output, output_length );
- }
- else
- {
+ TEST_EQUAL(psa_asymmetric_encrypt(key, alg,
+ input_data->x, input_data->len,
+ label->x, label->len,
+ output, output_size,
+ &output_length), expected_status_encrypt);
+ if (expected_status_encrypt == PSA_SUCCESS) {
+ if (fake_output_encrypt->len > 0) {
+ TEST_EQUAL(fake_output_encrypt->len, output_length);
+ ASSERT_COMPARE(fake_output_encrypt->x, fake_output_encrypt->len,
+ output, output_length);
+ } else {
/* Perform sanity checks on the output */
#if PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
- if( PSA_KEY_TYPE_IS_RSA( key_type ) )
- {
- if( ! sanity_check_rsa_encryption_result(
+ if (PSA_KEY_TYPE_IS_RSA(key_type)) {
+ if (!sanity_check_rsa_encryption_result(
alg, modulus, private_exponent,
input_data,
- output, output_length ) )
+ output, output_length)) {
goto exit;
- }
- else
+ }
+ } else
#endif
{
(void) modulus;
(void) private_exponent;
- TEST_ASSERT( ! "Encryption sanity checks not implemented for this key type" );
+ TEST_ASSERT(!"Encryption sanity checks not implemented for this key type");
}
}
}
@@ -2409,24 +2342,24 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( key );
- mbedtls_free( output );
- PSA_DONE( );
+ psa_destroy_key(key);
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_encrypt_setup( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_data,
- data_t *expected_ciphertext,
- data_t *expected_tag,
- int forced_status_arg,
- int expected_status_arg )
+void aead_encrypt_setup(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_data,
+ data_t *expected_ciphertext,
+ data_t *expected_tag,
+ int forced_status_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -2447,104 +2380,103 @@
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
- PSA_INIT( );
+ PSA_INIT();
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- key_bits = psa_get_key_bits( &attributes );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ key_bits = psa_get_key_bits(&attributes);
- output_size = input_data->len + PSA_AEAD_TAG_LENGTH( key_type, key_bits,
- alg );
+ output_size = input_data->len + PSA_AEAD_TAG_LENGTH(key_type, key_bits,
+ alg);
/* For all currently defined algorithms, PSA_AEAD_ENCRYPT_OUTPUT_SIZE
* should be exact. */
- TEST_EQUAL( output_size,
- PSA_AEAD_ENCRYPT_OUTPUT_SIZE( key_type, alg, input_data->len ) );
- TEST_ASSERT( output_size <=
- PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
- ASSERT_ALLOC( output_data, output_size );
+ TEST_EQUAL(output_size,
+ PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
+ TEST_ASSERT(output_size <=
+ PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
+ ASSERT_ALLOC(output_data, output_size);
- status = psa_aead_encrypt_setup( &operation, key, alg );
+ status = psa_aead_encrypt_setup(&operation, key, alg);
- TEST_EQUAL( status, expected_status );
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_encrypt_setup, 1 );
+ TEST_EQUAL(status, expected_status);
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_encrypt_setup, 1);
- if( status == PSA_SUCCESS )
- {
+ if (status == PSA_SUCCESS) {
/* Set the nonce. */
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_set_nonce,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_set_nonce,
+ forced_status == PSA_SUCCESS ? 1 : 0);
/* Check hooks hits and
* set length (additional data and data to encrypt) */
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_data->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_data->len));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_set_lengths,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_set_lengths,
+ forced_status == PSA_SUCCESS ? 1 : 0);
/* Pass the additional data */
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_update_ad,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_update_ad,
+ forced_status == PSA_SUCCESS ? 1 : 0);
/* Pass the data to encrypt */
- PSA_ASSERT( psa_aead_update( &operation, input_data->x, input_data->len,
- output_data, output_size, &output_length ) );
+ PSA_ASSERT(psa_aead_update(&operation, input_data->x, input_data->len,
+ output_data, output_size, &output_length));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_update,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_update,
+ forced_status == PSA_SUCCESS ? 1 : 0);
/* Finish the encryption operation */
- PSA_ASSERT( psa_aead_finish( &operation, output_data + output_length,
- output_size - output_length,
- &finish_output_length, tag_buffer,
- PSA_AEAD_TAG_MAX_SIZE, &tag_length ) );
+ PSA_ASSERT(psa_aead_finish(&operation, output_data + output_length,
+ output_size - output_length,
+ &finish_output_length, tag_buffer,
+ PSA_AEAD_TAG_MAX_SIZE, &tag_length));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_finish,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_finish,
+ forced_status == PSA_SUCCESS ? 1 : 0);
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_abort,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_abort,
+ forced_status == PSA_SUCCESS ? 1 : 0);
/* Compare output_data and expected_ciphertext */
- ASSERT_COMPARE( expected_ciphertext->x, expected_ciphertext->len,
- output_data, output_length + finish_output_length );
+ ASSERT_COMPARE(expected_ciphertext->x, expected_ciphertext->len,
+ output_data, output_length + finish_output_length);
/* Compare tag and expected_tag */
- ASSERT_COMPARE( expected_tag->x, expected_tag->len, tag_buffer, tag_length );
+ ASSERT_COMPARE(expected_tag->x, expected_tag->len, tag_buffer, tag_length);
}
exit:
/* Cleanup */
- PSA_ASSERT( psa_destroy_key( key ) );
- mbedtls_free( output_data );
- PSA_DONE( );
+ PSA_ASSERT(psa_destroy_key(key));
+ mbedtls_free(output_data);
+ PSA_DONE();
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_decrypt_setup( int key_type_arg, data_t *key_data,
- int alg_arg,
- data_t *nonce,
- data_t *additional_data,
- data_t *input_ciphertext,
- data_t *input_tag,
- data_t *expected_result,
- int forced_status_arg,
- int expected_status_arg )
+void aead_decrypt_setup(int key_type_arg, data_t *key_data,
+ int alg_arg,
+ data_t *nonce,
+ data_t *additional_data,
+ data_t *input_ciphertext,
+ data_t *input_tag,
+ data_t *expected_result,
+ int forced_status_arg,
+ int expected_status_arg)
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
@@ -2561,78 +2493,77 @@
psa_aead_operation_t operation = psa_aead_operation_init();
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
output_size = input_ciphertext->len;
- ASSERT_ALLOC( output_data, output_size );
+ ASSERT_ALLOC(output_data, output_size);
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
- status = psa_aead_decrypt_setup( &operation, key, alg );
+ status = psa_aead_decrypt_setup(&operation, key, alg);
- TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ?
- PSA_SUCCESS : forced_status );
+ TEST_EQUAL(status, (forced_status == PSA_ERROR_NOT_SUPPORTED) ?
+ PSA_SUCCESS : forced_status);
- TEST_EQUAL( status, expected_status );
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_decrypt_setup, 1 );
+ TEST_EQUAL(status, expected_status);
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_decrypt_setup, 1);
- if( status == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_set_nonce,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ if (status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_set_nonce,
+ forced_status == PSA_SUCCESS ? 1 : 0);
- PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
- input_ciphertext->len ) );
+ PSA_ASSERT(psa_aead_set_lengths(&operation, additional_data->len,
+ input_ciphertext->len));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_set_lengths,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_set_lengths,
+ forced_status == PSA_SUCCESS ? 1 : 0);
- PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
- additional_data->len ) );
+ PSA_ASSERT(psa_aead_update_ad(&operation, additional_data->x,
+ additional_data->len));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_update_ad,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_update_ad,
+ forced_status == PSA_SUCCESS ? 1 : 0);
- PSA_ASSERT( psa_aead_update( &operation, input_ciphertext->x,
- input_ciphertext->len, output_data,
- output_size, &output_length ) );
+ PSA_ASSERT(psa_aead_update(&operation, input_ciphertext->x,
+ input_ciphertext->len, output_data,
+ output_size, &output_length));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_update,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_update,
+ forced_status == PSA_SUCCESS ? 1 : 0);
/* Offset applied to output_data in order to handle cases where verify()
* outputs further data */
- PSA_ASSERT( psa_aead_verify( &operation, output_data + output_length,
- output_size - output_length,
- &verify_output_length, input_tag->x,
- input_tag->len ) );
+ PSA_ASSERT(psa_aead_verify(&operation, output_data + output_length,
+ output_size - output_length,
+ &verify_output_length, input_tag->x,
+ input_tag->len));
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_verify,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_verify,
+ forced_status == PSA_SUCCESS ? 1 : 0);
/* Since this is a decryption operation,
* finish should never be hit */
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_finish, 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_finish, 0);
- TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_abort,
- forced_status == PSA_SUCCESS ? 1 : 0 );
+ TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_abort,
+ forced_status == PSA_SUCCESS ? 1 : 0);
- ASSERT_COMPARE( expected_result->x, expected_result->len,
- output_data, output_length + verify_output_length );
+ ASSERT_COMPARE(expected_result->x, expected_result->len,
+ output_data, output_length + verify_output_length);
}
exit:
- PSA_ASSERT( psa_destroy_key( key ) );
- mbedtls_free( output_data );
- PSA_DONE( );
+ PSA_ASSERT(psa_destroy_key(key));
+ mbedtls_free(output_data);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_entropy.function b/tests/suites/test_suite_psa_crypto_entropy.function
index 0a2623f..1bb9efb 100644
--- a/tests/suites/test_suite_psa_crypto_entropy.function
+++ b/tests/suites/test_suite_psa_crypto_entropy.function
@@ -8,7 +8,8 @@
#include "entropy_poll.h"
/* Calculating the minimum allowed entropy size in bytes */
-#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
+#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, \
+ MBEDTLS_ENTROPY_BLOCK_SIZE)
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
@@ -22,15 +23,16 @@
* to do this (it would be a security risk if such a function was ever
* accessible in production), implement this functionality in a white-box
* manner. */
-psa_status_t remove_seed_file( void )
+psa_status_t remove_seed_file(void)
{
#if defined(MBEDTLS_PSA_ITS_FILE_C)
- if( remove( "00000000ffffff52.psa_its" ) == 0 )
- return( PSA_SUCCESS );
- else
- return( PSA_ERROR_DOES_NOT_EXIST );
+ if (remove("00000000ffffff52.psa_its") == 0) {
+ return PSA_SUCCESS;
+ } else {
+ return PSA_ERROR_DOES_NOT_EXIST;
+ }
#else
- return( psa_its_remove( PSA_CRYPTO_ITS_RANDOM_SEED_UID ) );
+ return psa_its_remove(PSA_CRYPTO_ITS_RANDOM_SEED_UID);
#endif
}
@@ -39,44 +41,44 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void external_rng_failure_generate( )
+void external_rng_failure_generate()
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_set_key_type( &attributes, PSA_KEY_TYPE_DERIVE );
- psa_set_key_bits( &attributes, 128 );
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_DERIVE);
+ psa_set_key_bits(&attributes, 128);
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
uint8_t output[1];
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- PSA_ASSERT( psa_generate_random( output, sizeof( output ) ) );
- PSA_ASSERT( psa_generate_key( &attributes, &key ) );
- PSA_ASSERT( psa_destroy_key( key ) );
+ PSA_ASSERT(psa_generate_random(output, sizeof(output)));
+ PSA_ASSERT(psa_generate_key(&attributes, &key));
+ PSA_ASSERT(psa_destroy_key(key));
- mbedtls_test_disable_insecure_external_rng( );
- TEST_EQUAL( PSA_ERROR_INSUFFICIENT_ENTROPY,
- psa_generate_random( output, sizeof( output ) ) );
- TEST_EQUAL( PSA_ERROR_INSUFFICIENT_ENTROPY,
- psa_generate_key( &attributes, &key ) );
+ mbedtls_test_disable_insecure_external_rng();
+ TEST_EQUAL(PSA_ERROR_INSUFFICIENT_ENTROPY,
+ psa_generate_random(output, sizeof(output)));
+ TEST_EQUAL(PSA_ERROR_INSUFFICIENT_ENTROPY,
+ psa_generate_key(&attributes, &key));
exit:
- psa_destroy_key( key );
- PSA_DONE( );
+ psa_destroy_key(key);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void external_rng_failure_sign( int key_type, data_t *key_data, int alg,
- int input_size_arg )
+void external_rng_failure_sign(int key_type, data_t *key_data, int alg,
+ int input_size_arg)
{
/* This test case is only expected to pass if the signature mechanism
* requires randomness, either because it is a randomized signature
* or because the implementation uses blinding. */
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
size_t input_size = input_size_arg;
uint8_t *input = NULL;
@@ -84,43 +86,43 @@
size_t signature_size = PSA_SIGNATURE_MAX_SIZE;
size_t signature_length;
- ASSERT_ALLOC( input, input_size );
- ASSERT_ALLOC( signature, signature_size );
+ ASSERT_ALLOC(input, input_size);
+ ASSERT_ALLOC(signature, signature_size);
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- PSA_ASSERT( psa_sign_hash( key, alg,
- input, input_size,
- signature, signature_size,
- &signature_length ) );
- PSA_ASSERT( psa_destroy_key( key ) );
+ PSA_ASSERT(psa_crypto_init());
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ PSA_ASSERT(psa_sign_hash(key, alg,
+ input, input_size,
+ signature, signature_size,
+ &signature_length));
+ PSA_ASSERT(psa_destroy_key(key));
- mbedtls_test_disable_insecure_external_rng( );
+ mbedtls_test_disable_insecure_external_rng();
/* Import the key again, because for RSA Mbed TLS caches blinding values
* in the key object and this could perturb the test. */
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- TEST_EQUAL( PSA_ERROR_INSUFFICIENT_ENTROPY,
- psa_sign_hash( key, alg,
- input, input_size,
- signature, signature_size,
- &signature_length ) );
- PSA_ASSERT( psa_destroy_key( key ) );
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ TEST_EQUAL(PSA_ERROR_INSUFFICIENT_ENTROPY,
+ psa_sign_hash(key, alg,
+ input, input_size,
+ signature, signature_size,
+ &signature_length));
+ PSA_ASSERT(psa_destroy_key(key));
exit:
- psa_destroy_key( key );
- PSA_DONE( );
- mbedtls_free( input );
- mbedtls_free( signature );
+ psa_destroy_key(key);
+ PSA_DONE();
+ mbedtls_free(input);
+ mbedtls_free(signature);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_INJECT_ENTROPY */
-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 };
@@ -128,68 +130,63 @@
uint8_t *seed = NULL;
int i;
int seed_size;
- if( seed_length_a > seed_length_b )
- {
+ if (seed_length_a > seed_length_b) {
seed_size = seed_length_a;
- }
- else
- {
+ } else {
seed_size = seed_length_b;
}
- ASSERT_ALLOC( seed, seed_size );
+ ASSERT_ALLOC(seed, seed_size);
/* fill seed with some data */
- for( i = 0; i < seed_size; ++i )
- {
+ for (i = 0; i < seed_size; ++i) {
seed[i] = i;
}
- status = remove_seed_file( );
- TEST_ASSERT( ( status == PSA_SUCCESS ) ||
- ( status == PSA_ERROR_DOES_NOT_EXIST ) );
- status = mbedtls_psa_inject_entropy( seed, seed_length_a );
- TEST_EQUAL( status, expected_status_a );
- status = mbedtls_psa_inject_entropy( seed, seed_length_b );
- TEST_EQUAL( status, expected_status_b );
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_ASSERT( psa_generate_random( output,
- sizeof( output ) ) );
- TEST_ASSERT( memcmp( output, zeros, sizeof( output ) ) != 0 );
+ status = remove_seed_file();
+ TEST_ASSERT((status == PSA_SUCCESS) ||
+ (status == PSA_ERROR_DOES_NOT_EXIST));
+ status = mbedtls_psa_inject_entropy(seed, seed_length_a);
+ TEST_EQUAL(status, expected_status_a);
+ status = mbedtls_psa_inject_entropy(seed, seed_length_b);
+ TEST_EQUAL(status, expected_status_b);
+ PSA_ASSERT(psa_crypto_init());
+ PSA_ASSERT(psa_generate_random(output,
+ sizeof(output)));
+ TEST_ASSERT(memcmp(output, zeros, sizeof(output)) != 0);
exit:
- mbedtls_free( seed );
- remove_seed_file( );
- PSA_DONE( );
+ mbedtls_free(seed);
+ remove_seed_file();
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_INJECT_ENTROPY */
-void run_entropy_inject_with_crypto_init( )
+void run_entropy_inject_with_crypto_init()
{
psa_status_t status;
size_t i;
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = { 0 };
/* fill seed with some data */
- for( i = 0; i < sizeof( seed ); ++i )
- {
+ for (i = 0; i < sizeof(seed); ++i) {
seed[i] = i;
}
- status = remove_seed_file( );
- TEST_ASSERT( ( status == PSA_SUCCESS ) ||
- ( status == PSA_ERROR_DOES_NOT_EXIST ) );
- status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );
- PSA_ASSERT( status );
- status = remove_seed_file( );
- TEST_EQUAL( status, PSA_SUCCESS );
- status = psa_crypto_init( );
- TEST_EQUAL( status, PSA_ERROR_INSUFFICIENT_ENTROPY );
- status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );
- PSA_ASSERT( status );
- status = psa_crypto_init( );
- PSA_ASSERT( status );
- PSA_DONE( );
+ status = remove_seed_file();
+ TEST_ASSERT((status == PSA_SUCCESS) ||
+ (status == PSA_ERROR_DOES_NOT_EXIST));
+ status = mbedtls_psa_inject_entropy(seed, sizeof(seed));
+ PSA_ASSERT(status);
+ status = remove_seed_file();
+ TEST_EQUAL(status, PSA_SUCCESS);
+ status = psa_crypto_init();
+ TEST_EQUAL(status, PSA_ERROR_INSUFFICIENT_ENTROPY);
+ status = mbedtls_psa_inject_entropy(seed, sizeof(seed));
+ PSA_ASSERT(status);
+ status = psa_crypto_init();
+ PSA_ASSERT(status);
+ PSA_DONE();
/* The seed is written by nv_seed callback functions therefore the injection will fail */
- status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );
- TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED );
+ status = mbedtls_psa_inject_entropy(seed, sizeof(seed));
+ TEST_EQUAL(status, PSA_ERROR_NOT_PERMITTED);
exit:
- remove_seed_file( );
- PSA_DONE( );
+ remove_seed_file();
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_generate_key.function b/tests/suites/test_suite_psa_crypto_generate_key.function
index 6dc6043..366e09b 100644
--- a/tests/suites/test_suite_psa_crypto_generate_key.function
+++ b/tests/suites/test_suite_psa_crypto_generate_key.function
@@ -3,7 +3,7 @@
#include "psa/crypto.h"
#include "test/psa_crypto_helpers.h"
-#define INVALID_KEY_ID mbedtls_svc_key_id_make( 0, 0xfedcba98 )
+#define INVALID_KEY_ID mbedtls_svc_key_id_make(0, 0xfedcba98)
/* END_HEADER */
@@ -13,7 +13,7 @@
*/
/* BEGIN_CASE */
-void generate_key( int key_type_arg, int bits_arg, int expected_status_arg)
+void generate_key(int key_type_arg, int bits_arg, int expected_status_arg)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = INVALID_KEY_ID;
@@ -23,27 +23,26 @@
size_t bits = bits_arg;
psa_status_t expected_status = expected_status_arg;
- PSA_ASSERT( psa_crypto_init( ) );
- psa_set_key_type( &attributes, key_type );
- psa_set_key_bits( &attributes, bits );
- TEST_EQUAL( psa_generate_key( &attributes, &key_id ),
- expected_status );
+ PSA_ASSERT(psa_crypto_init());
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_bits(&attributes, bits);
+ TEST_EQUAL(psa_generate_key(&attributes, &key_id),
+ expected_status);
// Verify attributes of the created key on success
- if ( expected_status == PSA_SUCCESS )
- {
+ if (expected_status == PSA_SUCCESS) {
psa_reset_key_attributes(&attributes);
- PSA_ASSERT( psa_get_key_attributes( key_id, &attributes ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), PSA_KEY_LIFETIME_VOLATILE );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_type( &attributes ), key_type );
- TEST_EQUAL( psa_get_key_bits( &attributes ), bits );
+ PSA_ASSERT(psa_get_key_attributes(key_id, &attributes));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), PSA_KEY_LIFETIME_VOLATILE);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), 0);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), 0);
+ TEST_EQUAL(psa_get_key_type(&attributes), key_type);
+ TEST_EQUAL(psa_get_key_bits(&attributes), bits);
}
exit:
psa_reset_key_attributes(&attributes);
- psa_destroy_key( key_id );
- PSA_DONE( );
+ psa_destroy_key(key_id);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_hash.function b/tests/suites/test_suite_psa_crypto_hash.function
index b0da2bf..f12541d 100644
--- a/tests/suites/test_suite_psa_crypto_hash.function
+++ b/tests/suites/test_suite_psa_crypto_hash.function
@@ -10,54 +10,54 @@
*/
/* BEGIN_CASE */
-void hash_finish( int alg_arg, data_t *input, data_t *expected_hash )
+void hash_finish(int alg_arg, data_t *input, data_t *expected_hash)
{
psa_algorithm_t alg = alg_arg;
unsigned char actual_hash[PSA_HASH_MAX_SIZE];
size_t actual_hash_length;
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation,
- input->x, input->len ) );
- PSA_ASSERT( psa_hash_finish( &operation,
- actual_hash, sizeof( actual_hash ),
- &actual_hash_length ) );
- ASSERT_COMPARE( expected_hash->x, expected_hash->len,
- actual_hash, actual_hash_length );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation,
+ input->x, input->len));
+ PSA_ASSERT(psa_hash_finish(&operation,
+ actual_hash, sizeof(actual_hash),
+ &actual_hash_length));
+ ASSERT_COMPARE(expected_hash->x, expected_hash->len,
+ actual_hash, actual_hash_length);
exit:
- psa_hash_abort( &operation );
- PSA_DONE( );
+ psa_hash_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_verify( int alg_arg, data_t *input, data_t *expected_hash )
+void hash_verify(int alg_arg, data_t *input, data_t *expected_hash)
{
psa_algorithm_t alg = alg_arg;
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
- PSA_ASSERT( psa_hash_update( &operation,
- input->x,
- input->len ) );
- PSA_ASSERT( psa_hash_verify( &operation,
- expected_hash->x,
- expected_hash->len ) );
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
+ PSA_ASSERT(psa_hash_update(&operation,
+ input->x,
+ input->len));
+ PSA_ASSERT(psa_hash_verify(&operation,
+ expected_hash->x,
+ expected_hash->len));
exit:
- psa_hash_abort( &operation );
- PSA_DONE( );
+ psa_hash_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void hash_multi_part( int alg_arg, data_t *input, data_t *expected_hash )
+void hash_multi_part(int alg_arg, data_t *input, data_t *expected_hash)
{
psa_algorithm_t alg = alg_arg;
unsigned char actual_hash[PSA_HASH_MAX_SIZE];
@@ -66,37 +66,36 @@
psa_hash_operation_t operation2 = PSA_HASH_OPERATION_INIT;
uint32_t len = 0;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- do
- {
- memset( actual_hash, 0, sizeof( actual_hash ) );
- PSA_ASSERT( psa_hash_setup( &operation, alg ) );
+ do {
+ memset(actual_hash, 0, sizeof(actual_hash));
+ PSA_ASSERT(psa_hash_setup(&operation, alg));
- PSA_ASSERT( psa_hash_update( &operation,
- input->x, len ) );
- PSA_ASSERT( psa_hash_clone( &operation, &operation2 ) );
- PSA_ASSERT( psa_hash_update( &operation,
- input->x + len, input->len - len ) );
- PSA_ASSERT( psa_hash_update( &operation2,
- input->x + len, input->len - len ) );
+ PSA_ASSERT(psa_hash_update(&operation,
+ input->x, len));
+ PSA_ASSERT(psa_hash_clone(&operation, &operation2));
+ PSA_ASSERT(psa_hash_update(&operation,
+ input->x + len, input->len - len));
+ PSA_ASSERT(psa_hash_update(&operation2,
+ input->x + len, input->len - len));
- PSA_ASSERT( psa_hash_finish( &operation,
- actual_hash, sizeof( actual_hash ),
- &actual_hash_length ) );
- ASSERT_COMPARE( expected_hash->x, expected_hash->len,
- actual_hash, actual_hash_length );
+ PSA_ASSERT(psa_hash_finish(&operation,
+ actual_hash, sizeof(actual_hash),
+ &actual_hash_length));
+ ASSERT_COMPARE(expected_hash->x, expected_hash->len,
+ actual_hash, actual_hash_length);
- PSA_ASSERT( psa_hash_finish( &operation2,
- actual_hash, sizeof( actual_hash ),
- &actual_hash_length ) );
- ASSERT_COMPARE( expected_hash->x, expected_hash->len,
- actual_hash, actual_hash_length );
- } while( len++ != input->len );
+ PSA_ASSERT(psa_hash_finish(&operation2,
+ actual_hash, sizeof(actual_hash),
+ &actual_hash_length));
+ ASSERT_COMPARE(expected_hash->x, expected_hash->len,
+ actual_hash, actual_hash_length);
+ } while (len++ != input->len);
exit:
- psa_hash_abort( &operation );
- psa_hash_abort( &operation2 );
- PSA_DONE( );
+ psa_hash_abort(&operation);
+ psa_hash_abort(&operation2);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function
index 9f72b47..f0b98e7 100644
--- a/tests/suites/test_suite_psa_crypto_init.function
+++ b/tests/suites/test_suite_psa_crypto_init.function
@@ -17,7 +17,7 @@
* half the entropy length. For SHA-256, SHA-384 or SHA-512, the
* entropy length is 256 per the documentation of mbedtls_hmac_drbg_seed(),
* and PSA crypto doesn't support other hashes for HMAC_DRBG. */
-#define ENTROPY_NONCE_LEN ( 256 / 2 )
+#define ENTROPY_NONCE_LEN (256 / 2)
#else
/* PSA crypto uses the CTR_DRBG module. In some configurations, it needs
* to read from the entropy source twice: once for the initial entropy
@@ -28,28 +28,29 @@
#if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
-typedef struct
-{
+typedef struct {
size_t threshold; /* Minimum bytes to make mbedtls_entropy_func happy */
size_t max_steps;
size_t *length_sequence;
size_t step;
} fake_entropy_state_t;
-static int fake_entropy_source( void *state_arg,
- unsigned char *output, size_t len,
- size_t *olen )
+static int fake_entropy_source(void *state_arg,
+ unsigned char *output, size_t len,
+ size_t *olen)
{
fake_entropy_state_t *state = state_arg;
size_t i;
- if( state->step >= state->max_steps )
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ if (state->step >= state->max_steps) {
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
+ }
- *olen = MIN( len, state->length_sequence[state->step] );
- for( i = 0; i < *olen; i++ )
+ *olen = MIN(len, state->length_sequence[state->step]);
+ for (i = 0; i < *olen; i++) {
output[i] = i;
+ }
++state->step;
- return( 0 );
+ return 0;
}
#define ENTROPY_SOURCE_PLATFORM 0x00000001
@@ -63,54 +64,54 @@
/* This is a modified version of mbedtls_entropy_init() from entropy.c
* which chooses entropy sources dynamically. */
-static void custom_entropy_init( mbedtls_entropy_context *ctx )
+static void custom_entropy_init(mbedtls_entropy_context *ctx)
{
ctx->source_count = 0;
- memset( ctx->source, 0, sizeof( ctx->source ) );
+ memset(ctx->source, 0, sizeof(ctx->source));
#if defined(MBEDTLS_THREADING_C)
- mbedtls_mutex_init( &ctx->mutex );
+ mbedtls_mutex_init(&ctx->mutex);
#endif
ctx->accumulator_started = 0;
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
- mbedtls_sha512_init( &ctx->accumulator );
+ mbedtls_sha512_init(&ctx->accumulator);
#else
- mbedtls_sha256_init( &ctx->accumulator );
+ mbedtls_sha256_init(&ctx->accumulator);
#endif
#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
- if( custom_entropy_sources_mask & ENTROPY_SOURCE_PLATFORM )
- mbedtls_entropy_add_source( ctx, mbedtls_platform_entropy_poll, NULL,
- MBEDTLS_ENTROPY_MIN_PLATFORM,
- MBEDTLS_ENTROPY_SOURCE_STRONG );
+ if (custom_entropy_sources_mask & ENTROPY_SOURCE_PLATFORM) {
+ mbedtls_entropy_add_source(ctx, mbedtls_platform_entropy_poll, NULL,
+ MBEDTLS_ENTROPY_MIN_PLATFORM,
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
+ }
#endif
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
- if( custom_entropy_sources_mask & ENTROPY_SOURCE_HARDWARE )
- mbedtls_entropy_add_source( ctx, mbedtls_hardware_poll, NULL,
- MBEDTLS_ENTROPY_MIN_HARDWARE,
- MBEDTLS_ENTROPY_SOURCE_STRONG );
+ if (custom_entropy_sources_mask & ENTROPY_SOURCE_HARDWARE) {
+ mbedtls_entropy_add_source(ctx, mbedtls_hardware_poll, NULL,
+ MBEDTLS_ENTROPY_MIN_HARDWARE,
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
+ }
#endif
#if defined(MBEDTLS_ENTROPY_NV_SEED)
- if( custom_entropy_sources_mask & ENTROPY_SOURCE_NV_SEED )
- {
- mbedtls_entropy_add_source( ctx, mbedtls_nv_seed_poll, NULL,
- MBEDTLS_ENTROPY_BLOCK_SIZE,
- MBEDTLS_ENTROPY_SOURCE_STRONG );
+ if (custom_entropy_sources_mask & ENTROPY_SOURCE_NV_SEED) {
+ mbedtls_entropy_add_source(ctx, mbedtls_nv_seed_poll, NULL,
+ MBEDTLS_ENTROPY_BLOCK_SIZE,
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
ctx->initial_entropy_run = 0;
- }
- else
- {
+ } else {
/* Skip the NV seed even though it's compiled in. */
ctx->initial_entropy_run = 1;
}
#endif
- if( custom_entropy_sources_mask & ENTROPY_SOURCE_FAKE )
- mbedtls_entropy_add_source( ctx,
- fake_entropy_source, &fake_entropy_state,
- fake_entropy_state.threshold,
- MBEDTLS_ENTROPY_SOURCE_STRONG );
+ if (custom_entropy_sources_mask & ENTROPY_SOURCE_FAKE) {
+ mbedtls_entropy_add_source(ctx,
+ fake_entropy_source, &fake_entropy_state,
+ fake_entropy_state.threshold,
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
+ }
}
#endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
@@ -123,109 +124,106 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:!MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void create_nv_seed( )
+void create_nv_seed()
{
static unsigned char seed[ENTROPY_MIN_NV_SEED_SIZE];
- TEST_ASSERT( mbedtls_nv_seed_write( seed, sizeof( seed ) ) >= 0 );
+ TEST_ASSERT(mbedtls_nv_seed_write(seed, sizeof(seed)) >= 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void init_deinit( int count )
+void init_deinit(int count)
{
psa_status_t status;
int i;
- for( i = 0; i < count; i++ )
- {
- status = psa_crypto_init( );
- PSA_ASSERT( status );
- status = psa_crypto_init( );
- PSA_ASSERT( status );
- PSA_DONE( );
+ for (i = 0; i < count; i++) {
+ status = psa_crypto_init();
+ PSA_ASSERT(status);
+ status = psa_crypto_init();
+ PSA_ASSERT(status);
+ PSA_DONE();
}
}
/* END_CASE */
/* BEGIN_CASE */
-void deinit_without_init( int count )
+void deinit_without_init(int count)
{
int i;
- for( i = 0; i < count; i++ )
- {
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_DONE( );
+ for (i = 0; i < count; i++) {
+ PSA_ASSERT(psa_crypto_init());
+ PSA_DONE();
}
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void validate_module_init_generate_random( int count )
+void validate_module_init_generate_random(int count)
{
psa_status_t status;
uint8_t random[10] = { 0 };
int i;
- for( i = 0; i < count; i++ )
- {
- status = psa_crypto_init( );
- PSA_ASSERT( status );
- PSA_DONE( );
+ for (i = 0; i < count; i++) {
+ status = psa_crypto_init();
+ PSA_ASSERT(status);
+ PSA_DONE();
}
- status = psa_generate_random( random, sizeof( random ) );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
+ status = psa_generate_random(random, sizeof(random));
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
}
/* END_CASE */
/* BEGIN_CASE */
-void validate_module_init_key_based( int count )
+void validate_module_init_key_based(int count)
{
psa_status_t status;
uint8_t data[10] = { 0 };
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_svc_key_id_t key = mbedtls_svc_key_id_make( 0xdead, 0xdead );
+ mbedtls_svc_key_id_t key = mbedtls_svc_key_id_make(0xdead, 0xdead);
int i;
- for( i = 0; i < count; i++ )
- {
- status = psa_crypto_init( );
- PSA_ASSERT( status );
- PSA_DONE( );
+ for (i = 0; i < count; i++) {
+ status = psa_crypto_init();
+ PSA_ASSERT(status);
+ PSA_DONE();
}
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- status = psa_import_key( &attributes, data, sizeof( data ), &key );
- TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
- TEST_ASSERT( mbedtls_svc_key_id_is_null( key ) );
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ status = psa_import_key(&attributes, data, sizeof(data), &key);
+ TEST_EQUAL(status, PSA_ERROR_BAD_STATE);
+ TEST_ASSERT(mbedtls_svc_key_id_is_null(key));
}
/* END_CASE */
/* BEGIN_CASE depends_on:!MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void custom_entropy_sources( int sources_arg, int expected_init_status_arg )
+void custom_entropy_sources(int sources_arg, int expected_init_status_arg)
{
psa_status_t expected_init_status = expected_init_status_arg;
uint8_t random[10] = { 0 };
custom_entropy_sources_mask = sources_arg;
- PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
- custom_entropy_init, mbedtls_entropy_free ) );
+ PSA_ASSERT(mbedtls_psa_crypto_configure_entropy_sources(
+ custom_entropy_init, mbedtls_entropy_free));
- TEST_EQUAL( psa_crypto_init( ), expected_init_status );
- if( expected_init_status != PSA_SUCCESS )
+ TEST_EQUAL(psa_crypto_init(), expected_init_status);
+ if (expected_init_status != PSA_SUCCESS) {
goto exit;
+ }
- PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
+ PSA_ASSERT(psa_generate_random(random, sizeof(random)));
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:!MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void fake_entropy_source( int threshold,
- int amount1,
- int amount2,
- int amount3,
- int amount4,
- int expected_init_status_arg )
+void fake_entropy_source(int threshold,
+ int amount1,
+ int amount2,
+ int amount3,
+ int amount4,
+ int expected_init_status_arg)
{
psa_status_t expected_init_status = expected_init_status_arg;
uint8_t random[10] = { 0 };
@@ -234,55 +232,61 @@
fake_entropy_state.threshold = threshold;
fake_entropy_state.step = 0;
fake_entropy_state.max_steps = 0;
- if( amount1 >= 0 )
+ if (amount1 >= 0) {
lengths[fake_entropy_state.max_steps++] = amount1;
- if( amount2 >= 0 )
+ }
+ if (amount2 >= 0) {
lengths[fake_entropy_state.max_steps++] = amount2;
- if( amount3 >= 0 )
+ }
+ if (amount3 >= 0) {
lengths[fake_entropy_state.max_steps++] = amount3;
- if( amount4 >= 0 )
+ }
+ if (amount4 >= 0) {
lengths[fake_entropy_state.max_steps++] = amount4;
+ }
fake_entropy_state.length_sequence = lengths;
custom_entropy_sources_mask = ENTROPY_SOURCE_FAKE;
- PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
- custom_entropy_init, mbedtls_entropy_free ) );
+ PSA_ASSERT(mbedtls_psa_crypto_configure_entropy_sources(
+ custom_entropy_init, mbedtls_entropy_free));
- TEST_EQUAL( psa_crypto_init( ), expected_init_status );
- if( expected_init_status != PSA_SUCCESS )
+ TEST_EQUAL(psa_crypto_init(), expected_init_status);
+ if (expected_init_status != PSA_SUCCESS) {
goto exit;
+ }
- PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
+ PSA_ASSERT(psa_generate_random(random, sizeof(random)));
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:!MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void entropy_from_nv_seed( int seed_size_arg,
- int expected_init_status_arg )
+void entropy_from_nv_seed(int seed_size_arg,
+ int expected_init_status_arg)
{
psa_status_t expected_init_status = expected_init_status_arg;
uint8_t random[10] = { 0 };
uint8_t *seed = NULL;
size_t seed_size = seed_size_arg;
- ASSERT_ALLOC( seed, seed_size );
- TEST_ASSERT( mbedtls_nv_seed_write( seed, seed_size ) >= 0 );
+ ASSERT_ALLOC(seed, seed_size);
+ TEST_ASSERT(mbedtls_nv_seed_write(seed, seed_size) >= 0);
custom_entropy_sources_mask = ENTROPY_SOURCE_NV_SEED;
- PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
- custom_entropy_init, mbedtls_entropy_free ) );
+ PSA_ASSERT(mbedtls_psa_crypto_configure_entropy_sources(
+ custom_entropy_init, mbedtls_entropy_free));
- TEST_EQUAL( psa_crypto_init( ), expected_init_status );
- if( expected_init_status != PSA_SUCCESS )
+ TEST_EQUAL(psa_crypto_init(), expected_init_status);
+ if (expected_init_status != PSA_SUCCESS) {
goto exit;
+ }
- PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
+ PSA_ASSERT(psa_generate_random(random, sizeof(random)));
exit:
- mbedtls_free( seed );
- PSA_DONE( );
+ mbedtls_free(seed);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_metadata.function b/tests/suites/test_suite_psa_crypto_metadata.function
index 643a92f..b28ed2a 100644
--- a/tests/suites/test_suite_psa_crypto_metadata.function
+++ b/tests/suites/test_suite_psa_crypto_metadata.function
@@ -16,58 +16,58 @@
* category test macros, which are hard-coded in each
* category-specific function. The name of the flag is the name of the
* classification macro without the PSA_ prefix. */
-#define ALG_IS_VENDOR_DEFINED ( 1u << 0 )
-#define ALG_IS_HMAC ( 1u << 1 )
-#define ALG_IS_BLOCK_CIPHER_MAC ( 1u << 2 )
-#define ALG_IS_STREAM_CIPHER ( 1u << 3 )
-#define ALG_IS_RSA_PKCS1V15_SIGN ( 1u << 4 )
-#define ALG_IS_RSA_PSS ( 1u << 5 )
-#define ALG_IS_RSA_PSS_ANY_SALT ( 1u << 6 )
-#define ALG_IS_RSA_PSS_STANDARD_SALT ( 1u << 7 )
-#define ALG_IS_DSA ( 1u << 8 )
-#define ALG_DSA_IS_DETERMINISTIC ( 1u << 9 )
-#define ALG_IS_DETERMINISTIC_DSA ( 1u << 10 )
-#define ALG_IS_RANDOMIZED_DSA ( 1u << 11 )
-#define ALG_IS_ECDSA ( 1u << 12 )
-#define ALG_ECDSA_IS_DETERMINISTIC ( 1u << 13 )
-#define ALG_IS_DETERMINISTIC_ECDSA ( 1u << 14 )
-#define ALG_IS_RANDOMIZED_ECDSA ( 1u << 15 )
-#define ALG_IS_HASH_EDDSA ( 1u << 16 )
-#define ALG_IS_SIGN_HASH ( 1u << 17 )
-#define ALG_IS_HASH_AND_SIGN ( 1u << 18 )
-#define ALG_IS_RSA_OAEP ( 1u << 19 )
-#define ALG_IS_HKDF ( 1u << 20 )
-#define ALG_IS_HKDF_EXTRACT ( 1u << 21 )
-#define ALG_IS_HKDF_EXPAND ( 1u << 22 )
-#define ALG_IS_FFDH ( 1u << 23 )
-#define ALG_IS_ECDH ( 1u << 24 )
-#define ALG_IS_WILDCARD ( 1u << 25 )
-#define ALG_IS_RAW_KEY_AGREEMENT ( 1u << 26 )
-#define ALG_IS_AEAD_ON_BLOCK_CIPHER ( 1u << 27 )
-#define ALG_IS_TLS12_PRF ( 1u << 28 )
-#define ALG_IS_TLS12_PSK_TO_MS ( 1u << 29 )
-#define ALG_FLAG_MASK_PLUS_ONE ( 1u << 30 ) /* must be last! */
+#define ALG_IS_VENDOR_DEFINED (1u << 0)
+#define ALG_IS_HMAC (1u << 1)
+#define ALG_IS_BLOCK_CIPHER_MAC (1u << 2)
+#define ALG_IS_STREAM_CIPHER (1u << 3)
+#define ALG_IS_RSA_PKCS1V15_SIGN (1u << 4)
+#define ALG_IS_RSA_PSS (1u << 5)
+#define ALG_IS_RSA_PSS_ANY_SALT (1u << 6)
+#define ALG_IS_RSA_PSS_STANDARD_SALT (1u << 7)
+#define ALG_IS_DSA (1u << 8)
+#define ALG_DSA_IS_DETERMINISTIC (1u << 9)
+#define ALG_IS_DETERMINISTIC_DSA (1u << 10)
+#define ALG_IS_RANDOMIZED_DSA (1u << 11)
+#define ALG_IS_ECDSA (1u << 12)
+#define ALG_ECDSA_IS_DETERMINISTIC (1u << 13)
+#define ALG_IS_DETERMINISTIC_ECDSA (1u << 14)
+#define ALG_IS_RANDOMIZED_ECDSA (1u << 15)
+#define ALG_IS_HASH_EDDSA (1u << 16)
+#define ALG_IS_SIGN_HASH (1u << 17)
+#define ALG_IS_HASH_AND_SIGN (1u << 18)
+#define ALG_IS_RSA_OAEP (1u << 19)
+#define ALG_IS_HKDF (1u << 20)
+#define ALG_IS_HKDF_EXTRACT (1u << 21)
+#define ALG_IS_HKDF_EXPAND (1u << 22)
+#define ALG_IS_FFDH (1u << 23)
+#define ALG_IS_ECDH (1u << 24)
+#define ALG_IS_WILDCARD (1u << 25)
+#define ALG_IS_RAW_KEY_AGREEMENT (1u << 26)
+#define ALG_IS_AEAD_ON_BLOCK_CIPHER (1u << 27)
+#define ALG_IS_TLS12_PRF (1u << 28)
+#define ALG_IS_TLS12_PSK_TO_MS (1u << 29)
+#define ALG_FLAG_MASK_PLUS_ONE (1u << 30) /* must be last! */
/* Flags for key type classification macros. There is a flag for every
* key type classification macro PSA_KEY_TYPE_IS_xxx except for some that
* are tested as derived from other macros. The name of the flag is
* the name of the classification macro without the PSA_ prefix. */
-#define KEY_TYPE_IS_VENDOR_DEFINED ( 1u << 0 )
-#define KEY_TYPE_IS_UNSTRUCTURED ( 1u << 1 )
-#define KEY_TYPE_IS_PUBLIC_KEY ( 1u << 2 )
-#define KEY_TYPE_IS_KEY_PAIR ( 1u << 3 )
-#define KEY_TYPE_IS_RSA ( 1u << 4 )
-#define KEY_TYPE_IS_DSA ( 1u << 5 )
-#define KEY_TYPE_IS_ECC ( 1u << 6 )
-#define KEY_TYPE_IS_DH ( 1u << 7 )
-#define KEY_TYPE_FLAG_MASK_PLUS_ONE ( 1u << 8 ) /* must be last! */
+#define KEY_TYPE_IS_VENDOR_DEFINED (1u << 0)
+#define KEY_TYPE_IS_UNSTRUCTURED (1u << 1)
+#define KEY_TYPE_IS_PUBLIC_KEY (1u << 2)
+#define KEY_TYPE_IS_KEY_PAIR (1u << 3)
+#define KEY_TYPE_IS_RSA (1u << 4)
+#define KEY_TYPE_IS_DSA (1u << 5)
+#define KEY_TYPE_IS_ECC (1u << 6)
+#define KEY_TYPE_IS_DH (1u << 7)
+#define KEY_TYPE_FLAG_MASK_PLUS_ONE (1u << 8) /* must be last! */
/* Flags for lifetime classification macros. There is a flag for every
* lifetime classification macro PSA_KEY_LIFETIME_IS_xxx. The name of the
* flag is the name of the classification macro without the PSA_ prefix. */
-#define KEY_LIFETIME_IS_VOLATILE ( 1u << 0 )
-#define KEY_LIFETIME_IS_READ_ONLY ( 1u << 1 )
-#define KEY_LIFETIME_FLAG_MASK_PLUS_ONE ( 1u << 2 ) /* must be last! */
+#define KEY_LIFETIME_IS_VOLATILE (1u << 0)
+#define KEY_LIFETIME_IS_READ_ONLY (1u << 1)
+#define KEY_LIFETIME_FLAG_MASK_PLUS_ONE (1u << 2) /* must be last! */
/* Check that in the value of flags, the bit flag (which should be a macro
* expanding to a number of the form 1 << k) is set if and only if
@@ -80,19 +80,19 @@
* Unconditionally mask flag into the ambient variable
* classification_flags_tested.
*/
-#define TEST_CLASSIFICATION_MACRO( cond, flag, alg, flags ) \
+#define TEST_CLASSIFICATION_MACRO(cond, flag, alg, flags) \
do \
{ \
- if( cond ) \
+ if (cond) \
{ \
- if( ( flags ) & ( flag ) ) \
- TEST_ASSERT( PSA_##flag( alg ) ); \
+ if ((flags) & (flag)) \
+ TEST_ASSERT(PSA_##flag(alg)); \
else \
- TEST_ASSERT( ! PSA_##flag( alg ) ); \
+ TEST_ASSERT(!PSA_##flag(alg)); \
} \
- classification_flags_tested |= ( flag ); \
+ classification_flags_tested |= (flag); \
} \
- while( 0 )
+ while (0)
/* Check the parity of value.
*
@@ -106,138 +106,138 @@
* The expected parity is even so that 0 is considered a valid encoding.
*
* Return a nonzero value if value has even parity and 0 otherwise. */
-int has_even_parity( uint32_t value )
+int has_even_parity(uint32_t value)
{
value ^= value >> 16;
value ^= value >> 8;
value ^= value >> 4;
- return( 0x9669 & 1 << ( value & 0xf ) );
+ return 0x9669 & 1 << (value & 0xf);
}
-#define TEST_PARITY( value ) \
- TEST_ASSERT( has_even_parity( value ) )
+#define TEST_PARITY(value) \
+ TEST_ASSERT(has_even_parity(value))
-void algorithm_classification( psa_algorithm_t alg, unsigned flags )
+void algorithm_classification(psa_algorithm_t alg, unsigned flags)
{
unsigned classification_flags_tested = 0;
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_VENDOR_DEFINED, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_HMAC, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_BLOCK_CIPHER_MAC, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_STREAM_CIPHER, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RSA_PKCS1V15_SIGN, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RSA_PSS, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RSA_PSS_ANY_SALT, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RSA_PSS_STANDARD_SALT, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_DSA, alg, flags );
- TEST_CLASSIFICATION_MACRO( PSA_ALG_IS_DSA( alg ),
- ALG_DSA_IS_DETERMINISTIC, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_DETERMINISTIC_DSA, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RANDOMIZED_DSA, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_ECDSA, alg, flags );
- TEST_CLASSIFICATION_MACRO( PSA_ALG_IS_ECDSA( alg ),
- ALG_ECDSA_IS_DETERMINISTIC, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_DETERMINISTIC_ECDSA, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RANDOMIZED_ECDSA, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_HASH_EDDSA, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_SIGN_HASH, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_HASH_AND_SIGN, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RSA_OAEP, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_HKDF, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_HKDF_EXTRACT, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_HKDF_EXPAND, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_WILDCARD, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_ECDH, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_FFDH, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_RAW_KEY_AGREEMENT, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_AEAD_ON_BLOCK_CIPHER, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_TLS12_PRF, alg, flags );
- TEST_CLASSIFICATION_MACRO( 1, ALG_IS_TLS12_PSK_TO_MS, alg, flags );
- TEST_EQUAL( classification_flags_tested, ALG_FLAG_MASK_PLUS_ONE - 1 );
-exit: ;
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_VENDOR_DEFINED, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_HMAC, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_BLOCK_CIPHER_MAC, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_STREAM_CIPHER, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RSA_PKCS1V15_SIGN, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RSA_PSS, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RSA_PSS_ANY_SALT, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RSA_PSS_STANDARD_SALT, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_DSA, alg, flags);
+ TEST_CLASSIFICATION_MACRO(PSA_ALG_IS_DSA(alg),
+ ALG_DSA_IS_DETERMINISTIC, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_DETERMINISTIC_DSA, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RANDOMIZED_DSA, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_ECDSA, alg, flags);
+ TEST_CLASSIFICATION_MACRO(PSA_ALG_IS_ECDSA(alg),
+ ALG_ECDSA_IS_DETERMINISTIC, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_DETERMINISTIC_ECDSA, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RANDOMIZED_ECDSA, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_HASH_EDDSA, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_SIGN_HASH, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_HASH_AND_SIGN, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RSA_OAEP, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_HKDF, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_HKDF_EXTRACT, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_HKDF_EXPAND, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_WILDCARD, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_ECDH, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_FFDH, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_RAW_KEY_AGREEMENT, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_AEAD_ON_BLOCK_CIPHER, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_TLS12_PRF, alg, flags);
+ TEST_CLASSIFICATION_MACRO(1, ALG_IS_TLS12_PSK_TO_MS, alg, flags);
+ TEST_EQUAL(classification_flags_tested, ALG_FLAG_MASK_PLUS_ONE - 1);
+exit:;
}
-void key_type_classification( psa_key_type_t type, unsigned flags )
+void key_type_classification(psa_key_type_t type, unsigned flags)
{
unsigned classification_flags_tested = 0;
/* Macros tested based on the test case parameter */
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_VENDOR_DEFINED, type, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_UNSTRUCTURED, type, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_PUBLIC_KEY, type, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_KEY_PAIR, type, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_RSA, type, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_DSA, type, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_ECC, type, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_TYPE_IS_DH, type, flags );
- TEST_EQUAL( classification_flags_tested, KEY_TYPE_FLAG_MASK_PLUS_ONE - 1 );
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_VENDOR_DEFINED, type, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_UNSTRUCTURED, type, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_PUBLIC_KEY, type, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_KEY_PAIR, type, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_RSA, type, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_DSA, type, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_ECC, type, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_TYPE_IS_DH, type, flags);
+ TEST_EQUAL(classification_flags_tested, KEY_TYPE_FLAG_MASK_PLUS_ONE - 1);
/* Macros with derived semantics */
- TEST_EQUAL( PSA_KEY_TYPE_IS_ASYMMETRIC( type ),
- ( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ||
- PSA_KEY_TYPE_IS_KEY_PAIR( type ) ) );
- TEST_EQUAL( PSA_KEY_TYPE_IS_ECC_KEY_PAIR( type ),
- ( PSA_KEY_TYPE_IS_ECC( type ) &&
- PSA_KEY_TYPE_IS_KEY_PAIR( type ) ) );
- TEST_EQUAL( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( type ),
- ( PSA_KEY_TYPE_IS_ECC( type ) &&
- PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ) );
- TEST_EQUAL( PSA_KEY_TYPE_IS_DH_KEY_PAIR( type ),
- ( PSA_KEY_TYPE_IS_DH( type ) &&
- PSA_KEY_TYPE_IS_KEY_PAIR( type ) ) );
- TEST_EQUAL( PSA_KEY_TYPE_IS_DH_PUBLIC_KEY( type ),
- ( PSA_KEY_TYPE_IS_DH( type ) &&
- PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ) );
+ TEST_EQUAL(PSA_KEY_TYPE_IS_ASYMMETRIC(type),
+ (PSA_KEY_TYPE_IS_PUBLIC_KEY(type) ||
+ PSA_KEY_TYPE_IS_KEY_PAIR(type)));
+ TEST_EQUAL(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type),
+ (PSA_KEY_TYPE_IS_ECC(type) &&
+ PSA_KEY_TYPE_IS_KEY_PAIR(type)));
+ TEST_EQUAL(PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type),
+ (PSA_KEY_TYPE_IS_ECC(type) &&
+ PSA_KEY_TYPE_IS_PUBLIC_KEY(type)));
+ TEST_EQUAL(PSA_KEY_TYPE_IS_DH_KEY_PAIR(type),
+ (PSA_KEY_TYPE_IS_DH(type) &&
+ PSA_KEY_TYPE_IS_KEY_PAIR(type)));
+ TEST_EQUAL(PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(type),
+ (PSA_KEY_TYPE_IS_DH(type) &&
+ PSA_KEY_TYPE_IS_PUBLIC_KEY(type)));
- TEST_PARITY( type );
+ TEST_PARITY(type);
-exit: ;
+exit:;
}
-void mac_algorithm_core( psa_algorithm_t alg, int classification_flags,
- psa_key_type_t key_type, size_t key_bits,
- size_t length )
+void mac_algorithm_core(psa_algorithm_t alg, int classification_flags,
+ psa_key_type_t key_type, size_t key_bits,
+ size_t length)
{
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, classification_flags );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, classification_flags);
/* Length */
- TEST_EQUAL( length, PSA_MAC_LENGTH( key_type, key_bits, alg ) );
+ TEST_EQUAL(length, PSA_MAC_LENGTH(key_type, key_bits, alg));
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C)
- PSA_ASSERT( psa_mac_key_can_do( alg, key_type ) );
+ PSA_ASSERT(psa_mac_key_can_do(alg, key_type));
#endif
-exit: ;
+exit:;
}
-void aead_algorithm_core( psa_algorithm_t alg, int classification_flags,
- psa_key_type_t key_type, size_t key_bits,
- size_t tag_length )
+void aead_algorithm_core(psa_algorithm_t alg, int classification_flags,
+ psa_key_type_t key_type, size_t key_bits,
+ size_t tag_length)
{
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, classification_flags );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, classification_flags);
/* Tag length */
- TEST_EQUAL( tag_length, PSA_AEAD_TAG_LENGTH( key_type, key_bits, alg ) );
+ TEST_EQUAL(tag_length, PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg));
-exit: ;
+exit:;
}
/* END_HEADER */
@@ -248,53 +248,53 @@
*/
/* BEGIN_CASE */
-void hash_algorithm( int alg_arg, int length_arg )
+void hash_algorithm(int alg_arg, int length_arg)
{
psa_algorithm_t alg = alg_arg;
size_t length = length_arg;
- psa_algorithm_t hmac_alg = PSA_ALG_HMAC( alg );
- psa_algorithm_t rsa_pkcs1v15_sign_alg = PSA_ALG_RSA_PKCS1V15_SIGN( alg );
- psa_algorithm_t rsa_pss_alg = PSA_ALG_RSA_PSS( alg );
- psa_algorithm_t dsa_alg = PSA_ALG_DSA( alg );
- psa_algorithm_t deterministic_dsa_alg = PSA_ALG_DETERMINISTIC_DSA( alg );
- psa_algorithm_t ecdsa_alg = PSA_ALG_ECDSA( alg );
- psa_algorithm_t deterministic_ecdsa_alg = PSA_ALG_DETERMINISTIC_ECDSA( alg );
- psa_algorithm_t rsa_oaep_alg = PSA_ALG_RSA_OAEP( alg );
- psa_algorithm_t hkdf_alg = PSA_ALG_HKDF( alg );
+ psa_algorithm_t hmac_alg = PSA_ALG_HMAC(alg);
+ psa_algorithm_t rsa_pkcs1v15_sign_alg = PSA_ALG_RSA_PKCS1V15_SIGN(alg);
+ psa_algorithm_t rsa_pss_alg = PSA_ALG_RSA_PSS(alg);
+ psa_algorithm_t dsa_alg = PSA_ALG_DSA(alg);
+ psa_algorithm_t deterministic_dsa_alg = PSA_ALG_DETERMINISTIC_DSA(alg);
+ psa_algorithm_t ecdsa_alg = PSA_ALG_ECDSA(alg);
+ psa_algorithm_t deterministic_ecdsa_alg = PSA_ALG_DETERMINISTIC_ECDSA(alg);
+ psa_algorithm_t rsa_oaep_alg = PSA_ALG_RSA_OAEP(alg);
+ psa_algorithm_t hkdf_alg = PSA_ALG_HKDF(alg);
/* Algorithm classification */
- TEST_ASSERT( PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, 0 );
+ TEST_ASSERT(PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, 0);
/* Dependent algorithms */
- TEST_EQUAL( PSA_ALG_HMAC_GET_HASH( hmac_alg ), alg );
- TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( rsa_pkcs1v15_sign_alg ), alg );
- TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( rsa_pss_alg ), alg );
- TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( dsa_alg ), alg );
- TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( deterministic_dsa_alg ), alg );
- TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( ecdsa_alg ), alg );
- TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( deterministic_ecdsa_alg ), alg );
- TEST_EQUAL( PSA_ALG_RSA_OAEP_GET_HASH( rsa_oaep_alg ), alg );
- TEST_EQUAL( PSA_ALG_HKDF_GET_HASH( hkdf_alg ), alg );
+ TEST_EQUAL(PSA_ALG_HMAC_GET_HASH(hmac_alg), alg);
+ TEST_EQUAL(PSA_ALG_SIGN_GET_HASH(rsa_pkcs1v15_sign_alg), alg);
+ TEST_EQUAL(PSA_ALG_SIGN_GET_HASH(rsa_pss_alg), alg);
+ TEST_EQUAL(PSA_ALG_SIGN_GET_HASH(dsa_alg), alg);
+ TEST_EQUAL(PSA_ALG_SIGN_GET_HASH(deterministic_dsa_alg), alg);
+ TEST_EQUAL(PSA_ALG_SIGN_GET_HASH(ecdsa_alg), alg);
+ TEST_EQUAL(PSA_ALG_SIGN_GET_HASH(deterministic_ecdsa_alg), alg);
+ TEST_EQUAL(PSA_ALG_RSA_OAEP_GET_HASH(rsa_oaep_alg), alg);
+ TEST_EQUAL(PSA_ALG_HKDF_GET_HASH(hkdf_alg), alg);
/* Hash length */
- TEST_EQUAL( length, PSA_HASH_LENGTH( alg ) );
- TEST_ASSERT( length <= PSA_HASH_MAX_SIZE );
+ TEST_EQUAL(length, PSA_HASH_LENGTH(alg));
+ TEST_ASSERT(length <= PSA_HASH_MAX_SIZE);
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_algorithm( int alg_arg, int classification_flags,
- int length_arg,
- int key_type_arg, int key_bits_arg )
+void mac_algorithm(int alg_arg, int classification_flags,
+ int length_arg,
+ int key_type_arg, int key_bits_arg)
{
psa_algorithm_t alg = alg_arg;
size_t length = length_arg;
@@ -302,128 +302,125 @@
size_t key_type = key_type_arg;
size_t key_bits = key_bits_arg;
- mac_algorithm_core( alg, classification_flags,
- key_type, key_bits, length );
- TEST_EQUAL( PSA_ALG_FULL_LENGTH_MAC( alg ), alg );
- TEST_ASSERT( length <= PSA_MAC_MAX_SIZE );
+ mac_algorithm_core(alg, classification_flags,
+ key_type, key_bits, length);
+ TEST_EQUAL(PSA_ALG_FULL_LENGTH_MAC(alg), alg);
+ TEST_ASSERT(length <= PSA_MAC_MAX_SIZE);
/* Truncated versions */
- for( n = 1; n <= length; n++ )
- {
- psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC( alg, n );
- mac_algorithm_core( truncated_alg, classification_flags,
- key_type, key_bits, n );
- TEST_EQUAL( PSA_ALG_FULL_LENGTH_MAC( truncated_alg ), alg );
+ for (n = 1; n <= length; n++) {
+ psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC(alg, n);
+ mac_algorithm_core(truncated_alg, classification_flags,
+ key_type, key_bits, n);
+ TEST_EQUAL(PSA_ALG_FULL_LENGTH_MAC(truncated_alg), alg);
/* Check that calling PSA_ALG_TRUNCATED_MAC twice gives the length
* of the outer truncation (even if the outer length is smaller than
* the inner length). */
- TEST_EQUAL( PSA_ALG_TRUNCATED_MAC( truncated_alg, 1 ),
- PSA_ALG_TRUNCATED_MAC( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_TRUNCATED_MAC( truncated_alg, length - 1 ),
- PSA_ALG_TRUNCATED_MAC( alg, length - 1) );
- TEST_EQUAL( PSA_ALG_TRUNCATED_MAC( truncated_alg, length ),
- PSA_ALG_TRUNCATED_MAC( alg, length ) );
+ TEST_EQUAL(PSA_ALG_TRUNCATED_MAC(truncated_alg, 1),
+ PSA_ALG_TRUNCATED_MAC(alg, 1));
+ TEST_EQUAL(PSA_ALG_TRUNCATED_MAC(truncated_alg, length - 1),
+ PSA_ALG_TRUNCATED_MAC(alg, length - 1));
+ TEST_EQUAL(PSA_ALG_TRUNCATED_MAC(truncated_alg, length),
+ PSA_ALG_TRUNCATED_MAC(alg, length));
/* Check that calling PSA_ALG_TRUNCATED_MAC on an algorithm
* earlier constructed with PSA_ALG_AT_LEAST_THIS_LENGTH_MAC gives the
* length of the outer truncation (even if the outer length is smaller
* than the inner length). */
- TEST_EQUAL( PSA_ALG_TRUNCATED_MAC(
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( truncated_alg, n ), 1 ),
- PSA_ALG_TRUNCATED_MAC( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_TRUNCATED_MAC(
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( truncated_alg, n ), length - 1 ),
- PSA_ALG_TRUNCATED_MAC( alg, length - 1) );
- TEST_EQUAL( PSA_ALG_TRUNCATED_MAC(
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( truncated_alg, n ), length ),
- PSA_ALG_TRUNCATED_MAC( alg, length ) );
+ TEST_EQUAL(PSA_ALG_TRUNCATED_MAC(
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(truncated_alg, n), 1),
+ PSA_ALG_TRUNCATED_MAC(alg, 1));
+ TEST_EQUAL(PSA_ALG_TRUNCATED_MAC(
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(truncated_alg, n), length - 1),
+ PSA_ALG_TRUNCATED_MAC(alg, length - 1));
+ TEST_EQUAL(PSA_ALG_TRUNCATED_MAC(
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(truncated_alg, n), length),
+ PSA_ALG_TRUNCATED_MAC(alg, length));
}
/* At-leat-this-length versions */
- for( n = 1; n <= length; n++ )
- {
- psa_algorithm_t policy_alg = PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg, n );
- mac_algorithm_core( policy_alg, classification_flags | ALG_IS_WILDCARD,
- key_type, key_bits, n );
- TEST_EQUAL( PSA_ALG_FULL_LENGTH_MAC( policy_alg ), alg );
+ for (n = 1; n <= length; n++) {
+ psa_algorithm_t policy_alg = PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(alg, n);
+ mac_algorithm_core(policy_alg, classification_flags | ALG_IS_WILDCARD,
+ key_type, key_bits, n);
+ TEST_EQUAL(PSA_ALG_FULL_LENGTH_MAC(policy_alg), alg);
/* Check that calling PSA_ALG_AT_LEAST_THIS_LENGTH_MAC twice gives the
* length of the outer truncation (even if the outer length is smaller
* than the inner length). */
- TEST_EQUAL( PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( policy_alg, 1 ),
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( policy_alg, length - 1 ),
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg, length - 1) );
- TEST_EQUAL( PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( policy_alg, length ),
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg, length ) );
+ TEST_EQUAL(PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(policy_alg, 1),
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(alg, 1));
+ TEST_EQUAL(PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(policy_alg, length - 1),
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(alg, length - 1));
+ TEST_EQUAL(PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(policy_alg, length),
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(alg, length));
/* Check that calling PSA_ALG_AT_LEAST_THIS_LENGTH_MAC on an algorithm
* earlier constructed with PSA_ALG_TRUNCATED_MAC gives the length of
* the outer truncation (even if the outer length is smaller than the
* inner length). */
- TEST_EQUAL( PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(
- PSA_ALG_TRUNCATED_MAC( policy_alg, n ), 1),
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(
- PSA_ALG_TRUNCATED_MAC( policy_alg, n ), length - 1 ),
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg, length - 1) );
- TEST_EQUAL( PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(
- PSA_ALG_TRUNCATED_MAC( policy_alg, n ), length ),
- PSA_ALG_AT_LEAST_THIS_LENGTH_MAC( alg, length ) );
+ TEST_EQUAL(PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(
+ PSA_ALG_TRUNCATED_MAC(policy_alg, n), 1),
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(alg, 1));
+ TEST_EQUAL(PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(
+ PSA_ALG_TRUNCATED_MAC(policy_alg, n), length - 1),
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(alg, length - 1));
+ TEST_EQUAL(PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(
+ PSA_ALG_TRUNCATED_MAC(policy_alg, n), length),
+ PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(alg, length));
}
}
/* END_CASE */
/* BEGIN_CASE */
-void hmac_algorithm( int alg_arg,
- int length_arg,
- int block_size_arg )
+void hmac_algorithm(int alg_arg,
+ int length_arg,
+ int block_size_arg)
{
psa_algorithm_t alg = alg_arg;
- psa_algorithm_t hash_alg = PSA_ALG_HMAC_GET_HASH( alg );
+ psa_algorithm_t hash_alg = PSA_ALG_HMAC_GET_HASH(alg);
size_t block_size = block_size_arg;
size_t length = length_arg;
size_t n;
- TEST_ASSERT( PSA_ALG_IS_HASH( hash_alg ) );
- TEST_EQUAL( PSA_ALG_HMAC( hash_alg ), alg );
+ TEST_ASSERT(PSA_ALG_IS_HASH(hash_alg));
+ TEST_EQUAL(PSA_ALG_HMAC(hash_alg), alg);
- TEST_ASSERT( block_size == PSA_HASH_BLOCK_LENGTH( alg ) );
- TEST_ASSERT( block_size <= PSA_HMAC_MAX_HASH_BLOCK_SIZE );
+ TEST_ASSERT(block_size == PSA_HASH_BLOCK_LENGTH(alg));
+ TEST_ASSERT(block_size <= PSA_HMAC_MAX_HASH_BLOCK_SIZE);
- test_mac_algorithm( alg_arg, ALG_IS_HMAC, length,
- PSA_KEY_TYPE_HMAC, PSA_BYTES_TO_BITS( length ) );
+ test_mac_algorithm(alg_arg, ALG_IS_HMAC, length,
+ PSA_KEY_TYPE_HMAC, PSA_BYTES_TO_BITS(length));
- for( n = 1; n <= length; n++ )
- {
- psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC( alg, n );
- TEST_EQUAL( PSA_ALG_HMAC_GET_HASH( truncated_alg ), hash_alg );
+ for (n = 1; n <= length; n++) {
+ psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC(alg, n);
+ TEST_EQUAL(PSA_ALG_HMAC_GET_HASH(truncated_alg), hash_alg);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_algorithm( int alg_arg, int classification_flags )
+void cipher_algorithm(int alg_arg, int classification_flags)
{
psa_algorithm_t alg = alg_arg;
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, classification_flags );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, classification_flags);
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_algorithm( int alg_arg, int classification_flags,
- int tag_length_arg,
- int key_type_arg, int key_bits_arg )
+void aead_algorithm(int alg_arg, int classification_flags,
+ int tag_length_arg,
+ int key_type_arg, int key_bits_arg)
{
psa_algorithm_t alg = alg_arg;
size_t tag_length = tag_length_arg;
@@ -431,103 +428,102 @@
psa_key_type_t key_type = key_type_arg;
size_t key_bits = key_bits_arg;
- aead_algorithm_core( alg, classification_flags,
- key_type, key_bits, tag_length );
+ aead_algorithm_core(alg, classification_flags,
+ key_type, key_bits, tag_length);
/* Truncated versions */
- for( n = 1; n <= tag_length; n++ )
- {
- psa_algorithm_t truncated_alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, n );
- aead_algorithm_core( truncated_alg, classification_flags,
- key_type, key_bits, n );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG( truncated_alg ),
- alg );
+ for (n = 1; n <= tag_length; n++) {
+ psa_algorithm_t truncated_alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, n);
+ aead_algorithm_core(truncated_alg, classification_flags,
+ key_type, key_bits, n);
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(truncated_alg),
+ alg);
/* Check that calling PSA_ALG_AEAD_WITH_SHORTENED_TAG twice gives
* the length of the outer truncation (even if the outer length is
* smaller than the inner length). */
- TEST_EQUAL( PSA_ALG_AEAD_WITH_SHORTENED_TAG( truncated_alg, 1 ),
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_SHORTENED_TAG( truncated_alg, tag_length - 1 ),
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, tag_length - 1) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_SHORTENED_TAG( truncated_alg, tag_length ),
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, tag_length ) );
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_SHORTENED_TAG(truncated_alg, 1),
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_SHORTENED_TAG(truncated_alg, tag_length - 1),
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, tag_length - 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_SHORTENED_TAG(truncated_alg, tag_length),
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, tag_length));
/* Check that calling PSA_ALG_AEAD_WITH_SHORTENED_TAG on an algorithm
* earlier constructed with PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG
* gives the length of the outer truncation (even if the outer length is
* smaller than the inner length). */
- TEST_EQUAL( PSA_ALG_AEAD_WITH_SHORTENED_TAG(
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( truncated_alg, n ), 1 ),
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_SHORTENED_TAG(
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( truncated_alg, n ), tag_length - 1 ),
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, tag_length - 1) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_SHORTENED_TAG(
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( truncated_alg, n ), tag_length ),
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, tag_length ) );
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_SHORTENED_TAG(
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(truncated_alg, n), 1),
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_SHORTENED_TAG(
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(truncated_alg,
+ n), tag_length - 1),
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, tag_length - 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_SHORTENED_TAG(
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(truncated_alg, n), tag_length),
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, tag_length));
}
/* At-leat-this-length versions */
- for( n = 1; n <= tag_length; n++ )
- {
- psa_algorithm_t policy_alg = PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( alg, n );
- aead_algorithm_core( policy_alg, classification_flags | ALG_IS_WILDCARD,
- key_type, key_bits, n );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG( policy_alg ),
- alg );
+ for (n = 1; n <= tag_length; n++) {
+ psa_algorithm_t policy_alg = PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(alg, n);
+ aead_algorithm_core(policy_alg, classification_flags | ALG_IS_WILDCARD,
+ key_type, key_bits, n);
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(policy_alg),
+ alg);
/* Check that calling PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG twice
* gives the length of the outer truncation (even if the outer length is
* smaller than the inner length). */
- TEST_EQUAL( PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( policy_alg, 1 ),
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( policy_alg, tag_length - 1 ),
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( alg, tag_length - 1) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( policy_alg, tag_length ),
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( alg, tag_length ) );
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(policy_alg, 1),
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(alg, 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(policy_alg, tag_length - 1),
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(alg, tag_length - 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(policy_alg, tag_length),
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(alg, tag_length));
/* Check that calling PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG on an
* algorithm earlier constructed with PSA_ALG_AEAD_WITH_SHORTENED_TAG
* gives the length of the outer truncation (even if the outer length is
* smaller than the inner length). */
- TEST_EQUAL( PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( policy_alg, n ), 1),
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( alg, 1 ) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( policy_alg, n ), tag_length - 1 ),
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( alg, tag_length - 1) );
- TEST_EQUAL( PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(
- PSA_ALG_AEAD_WITH_SHORTENED_TAG( policy_alg, n ), tag_length ),
- PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG( alg, tag_length ) );
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(policy_alg, n), 1),
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(alg, 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(policy_alg, n), tag_length - 1),
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(alg, tag_length - 1));
+ TEST_EQUAL(PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(
+ PSA_ALG_AEAD_WITH_SHORTENED_TAG(policy_alg, n), tag_length),
+ PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(alg, tag_length));
}
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_signature_algorithm( int alg_arg, int classification_flags )
+void asymmetric_signature_algorithm(int alg_arg, int classification_flags)
{
psa_algorithm_t alg = alg_arg;
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, classification_flags );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, classification_flags);
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_signature_wildcard( int alg_arg, int classification_flags )
+void asymmetric_signature_wildcard(int alg_arg, int classification_flags)
{
classification_flags |= ALG_IS_WILDCARD;
classification_flags |= ALG_IS_SIGN_HASH;
classification_flags |= ALG_IS_HASH_AND_SIGN;
- test_asymmetric_signature_algorithm( alg_arg, classification_flags );
+ test_asymmetric_signature_algorithm(alg_arg, classification_flags);
/* Any failure of this test function comes from
* asymmetric_signature_algorithm. Pacify -Werror=unused-label. */
goto exit;
@@ -535,196 +531,194 @@
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_encryption_algorithm( int alg_arg, int classification_flags )
+void asymmetric_encryption_algorithm(int alg_arg, int classification_flags)
{
psa_algorithm_t alg = alg_arg;
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, classification_flags );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, classification_flags);
}
/* END_CASE */
/* BEGIN_CASE */
-void key_derivation_algorithm( int alg_arg, int classification_flags )
+void key_derivation_algorithm(int alg_arg, int classification_flags)
{
psa_algorithm_t alg = alg_arg;
- psa_algorithm_t ecdh_alg = PSA_ALG_KEY_AGREEMENT( PSA_ALG_ECDH, alg );
- psa_algorithm_t ffdh_alg = PSA_ALG_KEY_AGREEMENT( PSA_ALG_FFDH, alg );
+ psa_algorithm_t ecdh_alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, alg);
+ psa_algorithm_t ffdh_alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_FFDH, alg);
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, classification_flags );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, classification_flags);
/* Check combinations with key agreements */
- TEST_ASSERT( PSA_ALG_IS_KEY_AGREEMENT( ecdh_alg ) );
- TEST_ASSERT( PSA_ALG_IS_KEY_AGREEMENT( ffdh_alg ) );
- TEST_EQUAL( PSA_ALG_KEY_AGREEMENT_GET_KDF( ecdh_alg ), alg );
- TEST_EQUAL( PSA_ALG_KEY_AGREEMENT_GET_KDF( ffdh_alg ), alg );
+ TEST_ASSERT(PSA_ALG_IS_KEY_AGREEMENT(ecdh_alg));
+ TEST_ASSERT(PSA_ALG_IS_KEY_AGREEMENT(ffdh_alg));
+ TEST_EQUAL(PSA_ALG_KEY_AGREEMENT_GET_KDF(ecdh_alg), alg);
+ TEST_EQUAL(PSA_ALG_KEY_AGREEMENT_GET_KDF(ffdh_alg), alg);
}
/* END_CASE */
/* BEGIN_CASE */
-void key_agreement_algorithm( int alg_arg, int classification_flags,
- int ka_alg_arg, int kdf_alg_arg )
+void key_agreement_algorithm(int alg_arg, int classification_flags,
+ int ka_alg_arg, int kdf_alg_arg)
{
psa_algorithm_t alg = alg_arg;
- psa_algorithm_t actual_ka_alg = PSA_ALG_KEY_AGREEMENT_GET_BASE( alg );
+ psa_algorithm_t actual_ka_alg = PSA_ALG_KEY_AGREEMENT_GET_BASE(alg);
psa_algorithm_t expected_ka_alg = ka_alg_arg;
- psa_algorithm_t actual_kdf_alg = PSA_ALG_KEY_AGREEMENT_GET_KDF( alg );
+ psa_algorithm_t actual_kdf_alg = PSA_ALG_KEY_AGREEMENT_GET_KDF(alg);
psa_algorithm_t expected_kdf_alg = kdf_alg_arg;
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_PAKE( alg ) );
- algorithm_classification( alg, classification_flags );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_PAKE(alg));
+ algorithm_classification(alg, classification_flags);
/* Shared secret derivation properties */
- TEST_EQUAL( actual_ka_alg, expected_ka_alg );
- TEST_EQUAL( actual_kdf_alg, expected_kdf_alg );
+ TEST_EQUAL(actual_ka_alg, expected_ka_alg);
+ TEST_EQUAL(actual_kdf_alg, expected_kdf_alg);
}
/* END_CASE */
/* BEGIN_CASE */
-void pake_algorithm( int alg_arg )
+void pake_algorithm(int alg_arg)
{
psa_algorithm_t alg = alg_arg;
/* Algorithm classification */
- TEST_ASSERT( ! PSA_ALG_IS_HASH( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_MAC( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_CIPHER( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_AEAD( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_SIGN( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_ASYMMETRIC_ENCRYPTION( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_AGREEMENT( alg ) );
- TEST_ASSERT( ! PSA_ALG_IS_KEY_DERIVATION( alg ) );
- TEST_ASSERT( PSA_ALG_IS_PAKE( alg ) );
+ TEST_ASSERT(!PSA_ALG_IS_HASH(alg));
+ TEST_ASSERT(!PSA_ALG_IS_MAC(alg));
+ TEST_ASSERT(!PSA_ALG_IS_CIPHER(alg));
+ TEST_ASSERT(!PSA_ALG_IS_AEAD(alg));
+ TEST_ASSERT(!PSA_ALG_IS_SIGN(alg));
+ TEST_ASSERT(!PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_AGREEMENT(alg));
+ TEST_ASSERT(!PSA_ALG_IS_KEY_DERIVATION(alg));
+ TEST_ASSERT(PSA_ALG_IS_PAKE(alg));
}
/* END_CASE */
/* BEGIN_CASE */
-void key_type( int type_arg, int classification_flags )
+void key_type(int type_arg, int classification_flags)
{
psa_key_type_t type = type_arg;
- key_type_classification( type, classification_flags );
+ key_type_classification(type, classification_flags);
/* For asymmetric types, check the corresponding pair/public type */
- if( classification_flags & KEY_TYPE_IS_PUBLIC_KEY )
- {
- psa_key_type_t pair_type = PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY( type );
- TEST_EQUAL( PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( pair_type ), type );
- key_type_classification( pair_type,
- ( classification_flags
- & ~KEY_TYPE_IS_PUBLIC_KEY )
- | KEY_TYPE_IS_KEY_PAIR );
- TEST_EQUAL( PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( type ), type );
+ if (classification_flags & KEY_TYPE_IS_PUBLIC_KEY) {
+ psa_key_type_t pair_type = PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(type);
+ TEST_EQUAL(PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(pair_type), type);
+ key_type_classification(pair_type,
+ (classification_flags
+ & ~KEY_TYPE_IS_PUBLIC_KEY)
+ | KEY_TYPE_IS_KEY_PAIR);
+ TEST_EQUAL(PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type), type);
}
- if( classification_flags & KEY_TYPE_IS_KEY_PAIR )
- {
- psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( type );
- TEST_EQUAL( PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY( public_type ), type );
- key_type_classification( public_type,
- ( classification_flags
- & ~KEY_TYPE_IS_KEY_PAIR )
- | KEY_TYPE_IS_PUBLIC_KEY );
- TEST_EQUAL( PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY( type ), type );
+ if (classification_flags & KEY_TYPE_IS_KEY_PAIR) {
+ psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type);
+ TEST_EQUAL(PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(public_type), type);
+ key_type_classification(public_type,
+ (classification_flags
+ & ~KEY_TYPE_IS_KEY_PAIR)
+ | KEY_TYPE_IS_PUBLIC_KEY);
+ TEST_EQUAL(PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(type), type);
}
}
/* END_CASE */
/* BEGIN_CASE */
-void block_cipher_key_type( int type_arg, int block_size_arg )
+void block_cipher_key_type(int type_arg, int block_size_arg)
{
psa_key_type_t type = type_arg;
size_t block_size = block_size_arg;
- test_key_type( type_arg, KEY_TYPE_IS_UNSTRUCTURED );
+ test_key_type(type_arg, KEY_TYPE_IS_UNSTRUCTURED);
- TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
- PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
- TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ), block_size );
+ TEST_EQUAL(type & PSA_KEY_TYPE_CATEGORY_MASK,
+ PSA_KEY_TYPE_CATEGORY_SYMMETRIC);
+ TEST_EQUAL(PSA_BLOCK_CIPHER_BLOCK_LENGTH(type), block_size);
/* Check that the block size is a power of 2. This is required, at least,
- for PSA_ROUND_UP_TO_MULTIPLE(block_size, length) in crypto_sizes.h. */
- TEST_ASSERT( ( ( block_size - 1 ) & block_size ) == 0 );
+ for PSA_ROUND_UP_TO_MULTIPLE(block_size, length) in crypto_sizes.h. */
+ TEST_ASSERT(((block_size - 1) & block_size) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void stream_cipher_key_type( int type_arg )
+void stream_cipher_key_type(int type_arg)
{
psa_key_type_t type = type_arg;
- test_key_type( type_arg, KEY_TYPE_IS_UNSTRUCTURED );
+ test_key_type(type_arg, KEY_TYPE_IS_UNSTRUCTURED);
- TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
- PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
- TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ), 1 );
+ TEST_EQUAL(type & PSA_KEY_TYPE_CATEGORY_MASK,
+ PSA_KEY_TYPE_CATEGORY_SYMMETRIC);
+ TEST_EQUAL(PSA_BLOCK_CIPHER_BLOCK_LENGTH(type), 1);
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_KEY_TYPE_ECC_PUBLIC_KEY:PSA_KEY_TYPE_ECC_KEY_PAIR */
-void ecc_key_family( int curve_arg )
+void ecc_key_family(int curve_arg)
{
psa_ecc_family_t curve = curve_arg;
- psa_key_type_t public_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY( curve );
- psa_key_type_t pair_type = PSA_KEY_TYPE_ECC_KEY_PAIR( curve );
+ psa_key_type_t public_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve);
+ psa_key_type_t pair_type = PSA_KEY_TYPE_ECC_KEY_PAIR(curve);
- TEST_PARITY( curve );
+ TEST_PARITY(curve);
- test_key_type( public_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_PUBLIC_KEY );
- test_key_type( pair_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_KEY_PAIR );
+ test_key_type(public_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_PUBLIC_KEY);
+ test_key_type(pair_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_KEY_PAIR);
- TEST_EQUAL( PSA_KEY_TYPE_ECC_GET_FAMILY( public_type ), curve );
- TEST_EQUAL( PSA_KEY_TYPE_ECC_GET_FAMILY( pair_type ), curve );
+ TEST_EQUAL(PSA_KEY_TYPE_ECC_GET_FAMILY(public_type), curve);
+ TEST_EQUAL(PSA_KEY_TYPE_ECC_GET_FAMILY(pair_type), curve);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_DHM_C */
-void dh_key_family( int group_arg )
+void dh_key_family(int group_arg)
{
psa_dh_family_t group = group_arg;
- psa_key_type_t public_type = PSA_KEY_TYPE_DH_PUBLIC_KEY( group );
- psa_key_type_t pair_type = PSA_KEY_TYPE_DH_KEY_PAIR( group );
+ psa_key_type_t public_type = PSA_KEY_TYPE_DH_PUBLIC_KEY(group);
+ psa_key_type_t pair_type = PSA_KEY_TYPE_DH_KEY_PAIR(group);
- TEST_PARITY( group );
+ TEST_PARITY(group);
- test_key_type( public_type, KEY_TYPE_IS_DH | KEY_TYPE_IS_PUBLIC_KEY );
- test_key_type( pair_type, KEY_TYPE_IS_DH | KEY_TYPE_IS_KEY_PAIR );
+ test_key_type(public_type, KEY_TYPE_IS_DH | KEY_TYPE_IS_PUBLIC_KEY);
+ test_key_type(pair_type, KEY_TYPE_IS_DH | KEY_TYPE_IS_KEY_PAIR);
- TEST_EQUAL( PSA_KEY_TYPE_DH_GET_FAMILY( public_type ), group );
- TEST_EQUAL( PSA_KEY_TYPE_DH_GET_FAMILY( pair_type ), group );
+ TEST_EQUAL(PSA_KEY_TYPE_DH_GET_FAMILY(public_type), group);
+ TEST_EQUAL(PSA_KEY_TYPE_DH_GET_FAMILY(pair_type), group);
}
/* END_CASE */
/* BEGIN_CASE */
-void lifetime( int lifetime_arg, int classification_flags,
- int persistence_arg, int location_arg )
+void lifetime(int lifetime_arg, int classification_flags,
+ int persistence_arg, int location_arg)
{
psa_key_lifetime_t lifetime = lifetime_arg;
psa_key_persistence_t persistence = persistence_arg;
@@ -732,12 +726,12 @@
unsigned flags = classification_flags;
unsigned classification_flags_tested = 0;
- TEST_CLASSIFICATION_MACRO( 1, KEY_LIFETIME_IS_VOLATILE, lifetime, flags );
- TEST_CLASSIFICATION_MACRO( 1, KEY_LIFETIME_IS_READ_ONLY, lifetime, flags );
- TEST_EQUAL( classification_flags_tested,
- KEY_LIFETIME_FLAG_MASK_PLUS_ONE - 1 );
+ TEST_CLASSIFICATION_MACRO(1, KEY_LIFETIME_IS_VOLATILE, lifetime, flags);
+ TEST_CLASSIFICATION_MACRO(1, KEY_LIFETIME_IS_READ_ONLY, lifetime, flags);
+ TEST_EQUAL(classification_flags_tested,
+ KEY_LIFETIME_FLAG_MASK_PLUS_ONE - 1);
- TEST_EQUAL( PSA_KEY_LIFETIME_GET_PERSISTENCE( lifetime ), persistence );
- TEST_EQUAL( PSA_KEY_LIFETIME_GET_LOCATION( lifetime ), location );
+ TEST_EQUAL(PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime), persistence);
+ TEST_EQUAL(PSA_KEY_LIFETIME_GET_LOCATION(lifetime), location);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_not_supported.function b/tests/suites/test_suite_psa_crypto_not_supported.function
index e3253d8..e5e66f4 100644
--- a/tests/suites/test_suite_psa_crypto_not_supported.function
+++ b/tests/suites/test_suite_psa_crypto_not_supported.function
@@ -3,7 +3,7 @@
#include "psa/crypto.h"
#include "test/psa_crypto_helpers.h"
-#define INVALID_KEY_ID mbedtls_svc_key_id_make( 0, 0xfedcba98 )
+#define INVALID_KEY_ID mbedtls_svc_key_id_make(0, 0xfedcba98)
/* END_HEADER */
@@ -13,40 +13,40 @@
*/
/* BEGIN_CASE */
-void import_not_supported( int key_type, data_t *key_material )
+void import_not_supported(int key_type, data_t *key_material)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = INVALID_KEY_ID;
- PSA_ASSERT( psa_crypto_init( ) );
- psa_set_key_type( &attributes, key_type );
- TEST_EQUAL( psa_import_key( &attributes,
- key_material->x, key_material->len,
- &key_id ),
- PSA_ERROR_NOT_SUPPORTED );
- TEST_ASSERT( mbedtls_svc_key_id_equal( key_id, MBEDTLS_SVC_KEY_ID_INIT ) );
+ PSA_ASSERT(psa_crypto_init());
+ psa_set_key_type(&attributes, key_type);
+ TEST_EQUAL(psa_import_key(&attributes,
+ key_material->x, key_material->len,
+ &key_id),
+ PSA_ERROR_NOT_SUPPORTED);
+ TEST_ASSERT(mbedtls_svc_key_id_equal(key_id, MBEDTLS_SVC_KEY_ID_INIT));
exit:
- psa_destroy_key( key_id );
- PSA_DONE( );
+ psa_destroy_key(key_id);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void generate_not_supported( int key_type, int bits )
+void generate_not_supported(int key_type, int bits)
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = INVALID_KEY_ID;
- PSA_ASSERT( psa_crypto_init( ) );
- psa_set_key_type( &attributes, key_type );
- psa_set_key_bits( &attributes, bits );
- TEST_EQUAL( psa_generate_key( &attributes, &key_id ),
- PSA_ERROR_NOT_SUPPORTED );
- TEST_ASSERT( mbedtls_svc_key_id_equal( key_id, MBEDTLS_SVC_KEY_ID_INIT ) );
+ PSA_ASSERT(psa_crypto_init());
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_bits(&attributes, bits);
+ TEST_EQUAL(psa_generate_key(&attributes, &key_id),
+ PSA_ERROR_NOT_SUPPORTED);
+ TEST_ASSERT(mbedtls_svc_key_id_equal(key_id, MBEDTLS_SVC_KEY_ID_INIT));
exit:
- psa_destroy_key( key_id );
- PSA_DONE( );
+ psa_destroy_key(key_id);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_op_fail.function b/tests/suites/test_suite_psa_crypto_op_fail.function
index 8b50f10..046e3c3 100644
--- a/tests/suites/test_suite_psa_crypto_op_fail.function
+++ b/tests/suites/test_suite_psa_crypto_op_fail.function
@@ -3,19 +3,18 @@
#include "psa/crypto.h"
#include "test/psa_crypto_helpers.h"
-static int test_equal_status( const char *test,
- int line_no, const char* filename,
- psa_status_t value1,
- psa_status_t value2 )
+static int test_equal_status(const char *test,
+ int line_no, const char *filename,
+ psa_status_t value1,
+ psa_status_t value2)
{
- if( ( value1 == PSA_ERROR_INVALID_ARGUMENT &&
- value2 == PSA_ERROR_NOT_SUPPORTED ) ||
- ( value1 == PSA_ERROR_NOT_SUPPORTED &&
- value2 == PSA_ERROR_INVALID_ARGUMENT ) )
- {
- return( 1 );
+ if ((value1 == PSA_ERROR_INVALID_ARGUMENT &&
+ value2 == PSA_ERROR_NOT_SUPPORTED) ||
+ (value1 == PSA_ERROR_NOT_SUPPORTED &&
+ value2 == PSA_ERROR_INVALID_ARGUMENT)) {
+ return 1;
}
- return( mbedtls_test_equal( test, line_no, filename, value1, value2 ) );
+ return mbedtls_test_equal(test, line_no, filename, value1, value2);
}
/** Like #TEST_EQUAL, but expects #psa_status_t values and treats
@@ -28,12 +27,12 @@
* run, it would be better to clarify the expectations and reconcile the
* library and the test case generator.
*/
-#define TEST_STATUS( expr1, expr2 ) \
+#define TEST_STATUS(expr1, expr2) \
do { \
- if( ! test_equal_status( #expr1 " == " #expr2, __LINE__, __FILE__, \
- expr1, expr2 ) ) \
- goto exit; \
- } while( 0 )
+ if (!test_equal_status( #expr1 " == " #expr2, __LINE__, __FILE__, \
+ expr1, expr2)) \
+ goto exit; \
+ } while (0)
/* END_HEADER */
@@ -43,35 +42,35 @@
*/
/* BEGIN_CASE */
-void hash_fail( int alg_arg, int expected_status_arg )
+void hash_fail(int alg_arg, int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_algorithm_t alg = alg_arg;
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
- uint8_t input[1] = {'A'};
- uint8_t output[PSA_HASH_MAX_SIZE] = {0};
+ uint8_t input[1] = { 'A' };
+ uint8_t output[PSA_HASH_MAX_SIZE] = { 0 };
size_t length = SIZE_MAX;
- PSA_INIT( );
+ PSA_INIT();
- TEST_EQUAL( expected_status,
- psa_hash_setup( &operation, alg ) );
- TEST_EQUAL( expected_status,
- psa_hash_compute( alg, input, sizeof( input ),
- output, sizeof( output ), &length ) );
- TEST_EQUAL( expected_status,
- psa_hash_compare( alg, input, sizeof( input ),
- output, sizeof( output ) ) );
+ TEST_EQUAL(expected_status,
+ psa_hash_setup(&operation, alg));
+ TEST_EQUAL(expected_status,
+ psa_hash_compute(alg, input, sizeof(input),
+ output, sizeof(output), &length));
+ TEST_EQUAL(expected_status,
+ psa_hash_compare(alg, input, sizeof(input),
+ output, sizeof(output)));
exit:
- psa_hash_abort( &operation );
- PSA_DONE( );
+ psa_hash_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void mac_fail( int key_type_arg, data_t *key_data,
- int alg_arg, int expected_status_arg )
+void mac_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_key_type_t key_type = key_type_arg;
@@ -79,45 +78,45 @@
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
- uint8_t input[1] = {'A'};
- uint8_t output[PSA_MAC_MAX_SIZE] = {0};
+ uint8_t input[1] = { 'A' };
+ uint8_t output[PSA_MAC_MAX_SIZE] = { 0 };
size_t length = SIZE_MAX;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_SIGN_HASH |
- PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- PSA_ASSERT( psa_import_key( &attributes,
- key_data->x, key_data->len,
- &key_id ) );
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_SIGN_HASH |
+ PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_data->x, key_data->len,
+ &key_id));
- TEST_STATUS( expected_status,
- psa_mac_sign_setup( &operation, key_id, alg ) );
- TEST_STATUS( expected_status,
- psa_mac_verify_setup( &operation, key_id, alg ) );
- TEST_STATUS( expected_status,
- psa_mac_compute( key_id, alg,
- input, sizeof( input ),
- output, sizeof( output ), &length ) );
- TEST_STATUS( expected_status,
- psa_mac_verify( key_id, alg,
- input, sizeof( input ),
- output, sizeof( output ) ) );
+ TEST_STATUS(expected_status,
+ psa_mac_sign_setup(&operation, key_id, alg));
+ TEST_STATUS(expected_status,
+ psa_mac_verify_setup(&operation, key_id, alg));
+ TEST_STATUS(expected_status,
+ psa_mac_compute(key_id, alg,
+ input, sizeof(input),
+ output, sizeof(output), &length));
+ TEST_STATUS(expected_status,
+ psa_mac_verify(key_id, alg,
+ input, sizeof(input),
+ output, sizeof(output)));
exit:
- psa_mac_abort( &operation );
- psa_destroy_key( key_id );
- psa_reset_key_attributes( &attributes );
- PSA_DONE( );
+ psa_mac_abort(&operation);
+ psa_destroy_key(key_id);
+ psa_reset_key_attributes(&attributes);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void cipher_fail( int key_type_arg, data_t *key_data,
- int alg_arg, int expected_status_arg )
+void cipher_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_key_type_t key_type = key_type_arg;
@@ -125,45 +124,45 @@
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
- uint8_t input[1] = {'A'};
- uint8_t output[64] = {0};
+ uint8_t input[1] = { 'A' };
+ uint8_t output[64] = { 0 };
size_t length = SIZE_MAX;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_ENCRYPT |
- PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- PSA_ASSERT( psa_import_key( &attributes,
- key_data->x, key_data->len,
- &key_id ) );
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_ENCRYPT |
+ PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_data->x, key_data->len,
+ &key_id));
- TEST_STATUS( expected_status,
- psa_cipher_encrypt_setup( &operation, key_id, alg ) );
- TEST_STATUS( expected_status,
- psa_cipher_decrypt_setup( &operation, key_id, alg ) );
- TEST_STATUS( expected_status,
- psa_cipher_encrypt( key_id, alg,
- input, sizeof( input ),
- output, sizeof( output ), &length ) );
- TEST_STATUS( expected_status,
- psa_cipher_decrypt( key_id, alg,
- input, sizeof( input ),
- output, sizeof( output ), &length ) );
+ TEST_STATUS(expected_status,
+ psa_cipher_encrypt_setup(&operation, key_id, alg));
+ TEST_STATUS(expected_status,
+ psa_cipher_decrypt_setup(&operation, key_id, alg));
+ TEST_STATUS(expected_status,
+ psa_cipher_encrypt(key_id, alg,
+ input, sizeof(input),
+ output, sizeof(output), &length));
+ TEST_STATUS(expected_status,
+ psa_cipher_decrypt(key_id, alg,
+ input, sizeof(input),
+ output, sizeof(output), &length));
exit:
- psa_cipher_abort( &operation );
- psa_destroy_key( key_id );
- psa_reset_key_attributes( &attributes );
- PSA_DONE( );
+ psa_cipher_abort(&operation);
+ psa_destroy_key(key_id);
+ psa_reset_key_attributes(&attributes);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void aead_fail( int key_type_arg, data_t *key_data,
- int alg_arg, int expected_status_arg )
+void aead_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_key_type_t key_type = key_type_arg;
@@ -172,219 +171,217 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
uint8_t input[16] = "ABCDEFGHIJKLMNO";
- uint8_t output[64] = {0};
+ uint8_t output[64] = { 0 };
size_t length = SIZE_MAX;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_ENCRYPT |
- PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- PSA_ASSERT( psa_import_key( &attributes,
- key_data->x, key_data->len,
- &key_id ) );
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_ENCRYPT |
+ PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_data->x, key_data->len,
+ &key_id));
- TEST_STATUS( expected_status,
- psa_aead_encrypt_setup( &operation, key_id, alg ) );
- TEST_STATUS( expected_status,
- psa_aead_decrypt_setup( &operation, key_id, alg ) );
- TEST_STATUS( expected_status,
- psa_aead_encrypt( key_id, alg,
- input, sizeof( input ),
- NULL, 0, input, sizeof( input ),
- output, sizeof( output ), &length ) );
- TEST_STATUS( expected_status,
- psa_aead_decrypt( key_id, alg,
- input, sizeof( input ),
- NULL, 0, input, sizeof( input ),
- output, sizeof( output ), &length ) );
+ TEST_STATUS(expected_status,
+ psa_aead_encrypt_setup(&operation, key_id, alg));
+ TEST_STATUS(expected_status,
+ psa_aead_decrypt_setup(&operation, key_id, alg));
+ TEST_STATUS(expected_status,
+ psa_aead_encrypt(key_id, alg,
+ input, sizeof(input),
+ NULL, 0, input, sizeof(input),
+ output, sizeof(output), &length));
+ TEST_STATUS(expected_status,
+ psa_aead_decrypt(key_id, alg,
+ input, sizeof(input),
+ NULL, 0, input, sizeof(input),
+ output, sizeof(output), &length));
exit:
- psa_aead_abort( &operation );
- psa_destroy_key( key_id );
- psa_reset_key_attributes( &attributes );
- PSA_DONE( );
+ psa_aead_abort(&operation);
+ psa_destroy_key(key_id);
+ psa_reset_key_attributes(&attributes);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void sign_fail( int key_type_arg, data_t *key_data,
- int alg_arg, int private_only,
- int expected_status_arg )
+void sign_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, int private_only,
+ int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
- uint8_t input[1] = {'A'};
- uint8_t output[PSA_SIGNATURE_MAX_SIZE] = {0};
+ uint8_t input[1] = { 'A' };
+ uint8_t output[PSA_SIGNATURE_MAX_SIZE] = { 0 };
size_t length = SIZE_MAX;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_SIGN_HASH |
- PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- PSA_ASSERT( psa_import_key( &attributes,
- key_data->x, key_data->len,
- &key_id ) );
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_SIGN_HASH |
+ PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_data->x, key_data->len,
+ &key_id));
- TEST_STATUS( expected_status,
- psa_sign_hash( key_id, alg,
- input, sizeof( input ),
- output, sizeof( output ), &length ) );
- if( ! private_only )
- {
+ TEST_STATUS(expected_status,
+ psa_sign_hash(key_id, alg,
+ input, sizeof(input),
+ output, sizeof(output), &length));
+ if (!private_only) {
/* Determine a plausible signature size to avoid an INVALID_SIGNATURE
* error based on this. */
- PSA_ASSERT( psa_get_key_attributes( key_id, &attributes ) );
- size_t key_bits = psa_get_key_bits( &attributes );
- size_t output_length = sizeof( output );
- if( PSA_KEY_TYPE_IS_RSA( key_type ) )
- output_length = PSA_BITS_TO_BYTES( key_bits );
- else if( PSA_KEY_TYPE_IS_ECC( key_type ) )
- output_length = 2 * PSA_BITS_TO_BYTES( key_bits );
- TEST_ASSERT( output_length <= sizeof( output ) );
- TEST_STATUS( expected_status,
- psa_verify_hash( key_id, alg,
- input, sizeof( input ),
- output, output_length ) );
+ PSA_ASSERT(psa_get_key_attributes(key_id, &attributes));
+ size_t key_bits = psa_get_key_bits(&attributes);
+ size_t output_length = sizeof(output);
+ if (PSA_KEY_TYPE_IS_RSA(key_type)) {
+ output_length = PSA_BITS_TO_BYTES(key_bits);
+ } else if (PSA_KEY_TYPE_IS_ECC(key_type)) {
+ output_length = 2 * PSA_BITS_TO_BYTES(key_bits);
+ }
+ TEST_ASSERT(output_length <= sizeof(output));
+ TEST_STATUS(expected_status,
+ psa_verify_hash(key_id, alg,
+ input, sizeof(input),
+ output, output_length));
}
exit:
- psa_destroy_key( key_id );
- psa_reset_key_attributes( &attributes );
- PSA_DONE( );
+ psa_destroy_key(key_id);
+ psa_reset_key_attributes(&attributes);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void asymmetric_encryption_fail( int key_type_arg, data_t *key_data,
- int alg_arg, int private_only,
- int expected_status_arg )
+void asymmetric_encryption_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, int private_only,
+ int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
- uint8_t plaintext[PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE] = {0};
- uint8_t ciphertext[PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE] = {0};
+ uint8_t plaintext[PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE] = { 0 };
+ uint8_t ciphertext[PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE] = { 0 };
size_t length = SIZE_MAX;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_ENCRYPT |
- PSA_KEY_USAGE_DECRYPT );
- psa_set_key_algorithm( &attributes, alg );
- PSA_ASSERT( psa_import_key( &attributes,
- key_data->x, key_data->len,
- &key_id ) );
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_ENCRYPT |
+ PSA_KEY_USAGE_DECRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_data->x, key_data->len,
+ &key_id));
- if( ! private_only )
- {
- TEST_STATUS( expected_status,
- psa_asymmetric_encrypt( key_id, alg,
- plaintext, 1,
- NULL, 0,
- ciphertext, sizeof( ciphertext ),
- &length ) );
+ if (!private_only) {
+ TEST_STATUS(expected_status,
+ psa_asymmetric_encrypt(key_id, alg,
+ plaintext, 1,
+ NULL, 0,
+ ciphertext, sizeof(ciphertext),
+ &length));
}
- TEST_STATUS( expected_status,
- psa_asymmetric_decrypt( key_id, alg,
- ciphertext, sizeof( ciphertext ),
- NULL, 0,
- plaintext, sizeof( plaintext ),
- &length ) );
+ TEST_STATUS(expected_status,
+ psa_asymmetric_decrypt(key_id, alg,
+ ciphertext, sizeof(ciphertext),
+ NULL, 0,
+ plaintext, sizeof(plaintext),
+ &length));
exit:
- psa_destroy_key( key_id );
- psa_reset_key_attributes( &attributes );
- PSA_DONE( );
+ psa_destroy_key(key_id);
+ psa_reset_key_attributes(&attributes);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_derivation_fail( int alg_arg, int expected_status_arg )
+void key_derivation_fail(int alg_arg, int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_algorithm_t alg = alg_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
- PSA_INIT( );
+ PSA_INIT();
- TEST_EQUAL( expected_status,
- psa_key_derivation_setup( &operation, alg ) );
+ TEST_EQUAL(expected_status,
+ psa_key_derivation_setup(&operation, alg));
exit:
- psa_key_derivation_abort( &operation );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_agreement_fail( int key_type_arg, data_t *key_data,
- int alg_arg, int private_only,
- int expected_status_arg )
+void key_agreement_fail(int key_type_arg, data_t *key_data,
+ int alg_arg, int private_only,
+ int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
- uint8_t public_key[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE] = {0};
+ uint8_t public_key[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE] = { 0 };
size_t public_key_length = SIZE_MAX;
- uint8_t output[PSA_SIGNATURE_MAX_SIZE] = {0};
+ uint8_t output[PSA_SIGNATURE_MAX_SIZE] = { 0 };
size_t length = SIZE_MAX;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_type( &attributes, key_type );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- PSA_ASSERT( psa_import_key( &attributes,
- key_data->x, key_data->len,
- &key_id ) );
- if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ||
- PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) )
- {
- PSA_ASSERT( psa_export_public_key( key_id,
- public_key, sizeof( public_key ),
- &public_key_length ) );
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_data->x, key_data->len,
+ &key_id));
+ if (PSA_KEY_TYPE_IS_KEY_PAIR(key_type) ||
+ PSA_KEY_TYPE_IS_PUBLIC_KEY(key_type)) {
+ PSA_ASSERT(psa_export_public_key(key_id,
+ public_key, sizeof(public_key),
+ &public_key_length));
}
- TEST_STATUS( expected_status,
- psa_raw_key_agreement( alg, key_id,
- public_key, public_key_length,
- output, sizeof( output ), &length ) );
+ TEST_STATUS(expected_status,
+ psa_raw_key_agreement(alg, key_id,
+ public_key, public_key_length,
+ output, sizeof(output), &length));
#if defined(PSA_WANT_ALG_HKDF) && defined(PSA_WANT_ALG_SHA_256)
- PSA_ASSERT( psa_key_derivation_setup( &operation,
- PSA_ALG_HKDF( PSA_ALG_SHA_256 ) ) );
- TEST_STATUS( expected_status,
- psa_key_derivation_key_agreement(
- &operation,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- key_id,
- public_key, public_key_length ) );
+ PSA_ASSERT(psa_key_derivation_setup(&operation,
+ PSA_ALG_HKDF(PSA_ALG_SHA_256)));
+ TEST_STATUS(expected_status,
+ psa_key_derivation_key_agreement(
+ &operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET,
+ key_id,
+ public_key, public_key_length));
#endif
/* There are no public-key operations. */
(void) private_only;
exit:
- psa_key_derivation_abort( &operation );
- psa_destroy_key( key_id );
- psa_reset_key_attributes( &attributes );
- PSA_DONE( );
+ psa_key_derivation_abort(&operation);
+ psa_destroy_key(key_id);
+ psa_reset_key_attributes(&attributes);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_pake.function b/tests/suites/test_suite_psa_crypto_pake.function
index 4f000c1..4dffa3b 100644
--- a/tests/suites/test_suite_psa_crypto_pake.function
+++ b/tests/suites/test_suite_psa_crypto_pake.function
@@ -3,8 +3,7 @@
#include "psa/crypto.h"
-typedef enum
-{
+typedef enum {
ERR_NONE = 0,
/* errors forced internally in the code */
ERR_INJECT_UNINITIALIZED_ACCESS,
@@ -46,8 +45,7 @@
ERR_IN_OUTPUT,
} ecjpake_error_stage_t;
-typedef enum
-{
+typedef enum {
PAKE_ROUND_ONE,
PAKE_ROUND_TWO
} pake_round_t;
@@ -57,37 +55,37 @@
* Offset 7 is arbitrary, but chosen because it's "in the middle" of the part
* we're corrupting.
*/
-#define DO_ROUND_CONDITIONAL_INJECT( this_stage, buf ) \
- if ( this_stage == err_stage ) \
+#define DO_ROUND_CONDITIONAL_INJECT(this_stage, buf) \
+ if (this_stage == err_stage) \
{ \
- *( buf + 7) ^= 1; \
+ *(buf + 7) ^= 1; \
}
-#define DO_ROUND_UPDATE_OFFSETS( main_buf_offset, step_offset, step_size ) \
+#define DO_ROUND_UPDATE_OFFSETS(main_buf_offset, step_offset, step_size) \
{ \
step_offset = main_buf_offset; \
main_buf_offset += step_size; \
}
-#define DO_ROUND_CHECK_FAILURE( ) \
- if( err_stage != ERR_NONE && status != PSA_SUCCESS ) \
+#define DO_ROUND_CHECK_FAILURE() \
+ if (err_stage != ERR_NONE && status != PSA_SUCCESS) \
{ \
- TEST_EQUAL( status, expected_error_arg ); \
+ TEST_EQUAL(status, expected_error_arg); \
break; \
} \
else \
{ \
- TEST_EQUAL( status, PSA_SUCCESS ); \
+ TEST_EQUAL(status, PSA_SUCCESS); \
}
#if defined(PSA_WANT_ALG_JPAKE)
-static void ecjpake_do_round( psa_algorithm_t alg, unsigned int primitive,
- psa_pake_operation_t *server,
- psa_pake_operation_t *client,
- int client_input_first,
- pake_round_t round,
- ecjpake_error_stage_t err_stage,
- int expected_error_arg )
+static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
+ psa_pake_operation_t *server,
+ psa_pake_operation_t *client,
+ int client_input_first,
+ pake_round_t round,
+ ecjpake_error_stage_t err_stage,
+ int expected_error_arg)
{
unsigned char *buffer0 = NULL, *buffer1 = NULL;
size_t buffer_length = (
@@ -119,66 +117,65 @@
size_t c_x1_pr_off, c_x2_pr_off, c_x2s_pr_off;
psa_status_t status;
- ASSERT_ALLOC( buffer0, buffer_length );
- ASSERT_ALLOC( buffer1, buffer_length );
+ ASSERT_ALLOC(buffer0, buffer_length);
+ ASSERT_ALLOC(buffer1, buffer_length);
- switch( round )
- {
+ switch (round) {
case PAKE_ROUND_ONE:
/* Server first round Output */
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_g1_len ) );
- TEST_EQUAL( s_g1_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_g1_len));
+ TEST_EQUAL(s_g1_len, expected_size_key_share);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_g1_off, s_g1_len );
+ ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_g1_off, s_g1_len);
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x1_pk_len ) );
- TEST_EQUAL( s_x1_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x1_pk_len));
+ TEST_EQUAL(s_x1_pk_len, expected_size_zk_public);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_SERVER_ZK_PUBLIC_PART1,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_x1_pk_off, s_x1_pk_len );
+ ERR_INJECT_ROUND1_SERVER_ZK_PUBLIC_PART1,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x1_pk_off, s_x1_pk_len);
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x1_pr_len ) );
- TEST_LE_U( s_x1_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x1_pr_len));
+ TEST_LE_U(s_x1_pr_len, max_expected_size_zk_proof);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART1,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_x1_pr_off, s_x1_pr_len );
+ ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART1,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x1_pr_off, s_x1_pr_len);
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_g2_len ) );
- TEST_EQUAL( s_g2_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_g2_len));
+ TEST_EQUAL(s_g2_len, expected_size_key_share);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART2,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_g2_off, s_g2_len );
+ ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART2,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_g2_off, s_g2_len);
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2_pk_len ) );
- TEST_EQUAL( s_x2_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2_pk_len));
+ TEST_EQUAL(s_x2_pk_len, expected_size_zk_public);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_SERVER_ZK_PUBLIC_PART2,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_x2_pk_off, s_x2_pk_len );
+ ERR_INJECT_ROUND1_SERVER_ZK_PUBLIC_PART2,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x2_pk_off, s_x2_pk_len);
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2_pr_len ) );
- TEST_LE_U( s_x2_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2_pr_len));
+ TEST_LE_U(s_x2_pr_len, max_expected_size_zk_proof);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_x2_pr_off, s_x2_pr_len );
+ ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x2_pr_off, s_x2_pr_len);
/*
* When injecting errors in inputs, the implementation is
@@ -187,171 +184,169 @@
* sequence, if no error appears then, this will be treated
* as an error.
*/
- if( client_input_first == 1 )
- {
+ if (client_input_first == 1) {
/* Client first round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g1_off, s_g1_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g1_off, s_g1_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x1_pk_off,
- s_x1_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x1_pk_off,
+ s_x1_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x1_pr_off,
- s_x1_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x1_pr_off,
+ s_x1_pr_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g2_off,
- s_g2_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g2_off,
+ s_g2_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2_pk_off,
- s_x2_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2_pk_off,
+ s_x2_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2_pr_off,
- s_x2_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2_pr_off,
+ s_x2_pr_len);
+ DO_ROUND_CHECK_FAILURE();
/* Error didn't trigger, make test fail */
- if( ( err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1 ) &&
- ( err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2 ) )
- {
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if ((err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1) &&
+ (err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2)) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
}
}
/* Client first round Output */
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_g1_len ) );
- TEST_EQUAL( c_g1_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_g1_len));
+ TEST_EQUAL(c_g1_len, expected_size_key_share);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_CLIENT_KEY_SHARE_PART1,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_g1_off, c_g1_len );
+ ERR_INJECT_ROUND1_CLIENT_KEY_SHARE_PART1,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_g1_off, c_g1_len);
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x1_pk_len ) );
- TEST_EQUAL( c_x1_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x1_pk_len));
+ TEST_EQUAL(c_x1_pk_len, expected_size_zk_public);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_CLIENT_ZK_PUBLIC_PART1,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_x1_pk_off, c_x1_pk_len );
+ ERR_INJECT_ROUND1_CLIENT_ZK_PUBLIC_PART1,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_x1_pk_off, c_x1_pk_len);
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x1_pr_len ) );
- TEST_LE_U( c_x1_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x1_pr_len));
+ TEST_LE_U(c_x1_pr_len, max_expected_size_zk_proof);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_CLIENT_ZK_PROOF_PART1,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_x1_pr_off, c_x1_pr_len );
+ ERR_INJECT_ROUND1_CLIENT_ZK_PROOF_PART1,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_x1_pr_off, c_x1_pr_len);
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_g2_len ) );
- TEST_EQUAL( c_g2_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_g2_len));
+ TEST_EQUAL(c_g2_len, expected_size_key_share);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_CLIENT_KEY_SHARE_PART2,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_g2_off, c_g2_len );
+ ERR_INJECT_ROUND1_CLIENT_KEY_SHARE_PART2,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_g2_off, c_g2_len);
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2_pk_len ) );
- TEST_EQUAL( c_x2_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2_pk_len));
+ TEST_EQUAL(c_x2_pk_len, expected_size_zk_public);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_CLIENT_ZK_PUBLIC_PART2,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_x2_pk_off, c_x2_pk_len );
+ ERR_INJECT_ROUND1_CLIENT_ZK_PUBLIC_PART2,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_x2_pk_off, c_x2_pk_len);
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2_pr_len ) );
- TEST_LE_U( c_x2_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2_pr_len));
+ TEST_LE_U(c_x2_pr_len, max_expected_size_zk_proof);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND1_CLIENT_ZK_PROOF_PART2,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_x2_pr_off, buffer1_off );
+ ERR_INJECT_ROUND1_CLIENT_ZK_PROOF_PART2,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_x2_pr_off, buffer1_off);
- if( client_input_first == 0 )
- {
+ if (client_input_first == 0) {
/* Client first round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g1_off, s_g1_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g1_off, s_g1_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x1_pk_off,
- s_x1_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x1_pk_off,
+ s_x1_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x1_pr_off,
- s_x1_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x1_pr_off,
+ s_x1_pr_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_g2_off,
- s_g2_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_g2_off,
+ s_g2_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2_pk_off,
- s_x2_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2_pk_off,
+ s_x2_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2_pr_off,
- s_x2_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2_pr_off,
+ s_x2_pr_len);
+ DO_ROUND_CHECK_FAILURE();
/* Error didn't trigger, make test fail */
- if( ( err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1 ) &&
- ( err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2 ) )
- {
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if ((err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1) &&
+ (err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2)) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
}
}
/* Server first round Input */
- status = psa_pake_input( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + c_g1_off, c_g1_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + c_g1_off, c_g1_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + c_x1_pk_off, c_x1_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + c_x1_pk_off, c_x1_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + c_x1_pr_off, c_x1_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + c_x1_pr_off, c_x1_pr_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + c_g2_off, c_g2_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + c_g2_off, c_g2_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + c_x2_pk_off, c_x2_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + c_x2_pk_off, c_x2_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + c_x2_pr_off, c_x2_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + c_x2_pr_off, c_x2_pr_len);
+ DO_ROUND_CHECK_FAILURE();
/* Error didn't trigger, make test fail */
- if( ( err_stage >= ERR_INJECT_ROUND1_CLIENT_KEY_SHARE_PART1 ) &&
- ( err_stage <= ERR_INJECT_ROUND1_CLIENT_ZK_PROOF_PART2 ) )
- {
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if ((err_stage >= ERR_INJECT_ROUND1_CLIENT_KEY_SHARE_PART1) &&
+ (err_stage <= ERR_INJECT_ROUND1_CLIENT_ZK_PROOF_PART2)) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
}
break;
@@ -360,131 +355,129 @@
/* Server second round Output */
buffer0_off = 0;
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_a_len ) );
- TEST_EQUAL( s_a_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_a_len));
+ TEST_EQUAL(s_a_len, expected_size_key_share);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND2_SERVER_KEY_SHARE,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_a_off, s_a_len );
+ ERR_INJECT_ROUND2_SERVER_KEY_SHARE,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_a_off, s_a_len);
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2s_pk_len ) );
- TEST_EQUAL( s_x2s_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2s_pk_len));
+ TEST_EQUAL(s_x2s_pk_len, expected_size_zk_public);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND2_SERVER_ZK_PUBLIC,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_x2s_pk_off, s_x2s_pk_len );
+ ERR_INJECT_ROUND2_SERVER_ZK_PUBLIC,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x2s_pk_off, s_x2s_pk_len);
- PSA_ASSERT( psa_pake_output( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + buffer0_off,
- 512 - buffer0_off, &s_x2s_pr_len ) );
- TEST_LE_U( s_x2s_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + buffer0_off,
+ 512 - buffer0_off, &s_x2s_pr_len));
+ TEST_LE_U(s_x2s_pr_len, max_expected_size_zk_proof);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND2_SERVER_ZK_PROOF,
- buffer0 + buffer0_off );
- DO_ROUND_UPDATE_OFFSETS( buffer0_off, s_x2s_pr_off, s_x2s_pr_len );
+ ERR_INJECT_ROUND2_SERVER_ZK_PROOF,
+ buffer0 + buffer0_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x2s_pr_off, s_x2s_pr_len);
- if( client_input_first == 1 )
- {
+ if (client_input_first == 1) {
/* Client second round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_a_off, s_a_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_a_off, s_a_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2s_pk_off,
- s_x2s_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2s_pk_off,
+ s_x2s_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2s_pr_off,
- s_x2s_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2s_pr_off,
+ s_x2s_pr_len);
+ DO_ROUND_CHECK_FAILURE();
/* Error didn't trigger, make test fail */
- if( ( err_stage >= ERR_INJECT_ROUND2_SERVER_KEY_SHARE ) &&
- ( err_stage <= ERR_INJECT_ROUND2_SERVER_ZK_PROOF ) )
- {
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if ((err_stage >= ERR_INJECT_ROUND2_SERVER_KEY_SHARE) &&
+ (err_stage <= ERR_INJECT_ROUND2_SERVER_ZK_PROOF)) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
}
}
/* Client second round Output */
buffer1_off = 0;
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_a_len ) );
- TEST_EQUAL( c_a_len, expected_size_key_share );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_a_len));
+ TEST_EQUAL(c_a_len, expected_size_key_share);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND2_CLIENT_KEY_SHARE,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_a_off, c_a_len );
+ ERR_INJECT_ROUND2_CLIENT_KEY_SHARE,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_a_off, c_a_len);
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2s_pk_len ) );
- TEST_EQUAL( c_x2s_pk_len, expected_size_zk_public );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2s_pk_len));
+ TEST_EQUAL(c_x2s_pk_len, expected_size_zk_public);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND2_CLIENT_ZK_PUBLIC,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_x2s_pk_off, c_x2s_pk_len );
+ ERR_INJECT_ROUND2_CLIENT_ZK_PUBLIC,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_x2s_pk_off, c_x2s_pk_len);
- PSA_ASSERT( psa_pake_output( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + buffer1_off,
- 512 - buffer1_off, &c_x2s_pr_len ) );
- TEST_LE_U( c_x2s_pr_len, max_expected_size_zk_proof );
+ PSA_ASSERT(psa_pake_output(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + buffer1_off,
+ 512 - buffer1_off, &c_x2s_pr_len));
+ TEST_LE_U(c_x2s_pr_len, max_expected_size_zk_proof);
DO_ROUND_CONDITIONAL_INJECT(
- ERR_INJECT_ROUND2_CLIENT_ZK_PROOF,
- buffer1 + buffer1_off );
- DO_ROUND_UPDATE_OFFSETS( buffer1_off, c_x2s_pr_off, c_x2s_pr_len );
+ ERR_INJECT_ROUND2_CLIENT_ZK_PROOF,
+ buffer1 + buffer1_off);
+ DO_ROUND_UPDATE_OFFSETS(buffer1_off, c_x2s_pr_off, c_x2s_pr_len);
- if( client_input_first == 0 )
- {
+ if (client_input_first == 0) {
/* Client second round Input */
- status = psa_pake_input( client, PSA_PAKE_STEP_KEY_SHARE,
- buffer0 + s_a_off, s_a_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
+ buffer0 + s_a_off, s_a_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer0 + s_x2s_pk_off,
- s_x2s_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer0 + s_x2s_pk_off,
+ s_x2s_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( client, PSA_PAKE_STEP_ZK_PROOF,
- buffer0 + s_x2s_pr_off,
- s_x2s_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(client, PSA_PAKE_STEP_ZK_PROOF,
+ buffer0 + s_x2s_pr_off,
+ s_x2s_pr_len);
+ DO_ROUND_CHECK_FAILURE();
/* Error didn't trigger, make test fail */
- if( ( err_stage >= ERR_INJECT_ROUND2_SERVER_KEY_SHARE ) &&
- ( err_stage <= ERR_INJECT_ROUND2_SERVER_ZK_PROOF ) )
- {
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if ((err_stage >= ERR_INJECT_ROUND2_SERVER_KEY_SHARE) &&
+ (err_stage <= ERR_INJECT_ROUND2_SERVER_ZK_PROOF)) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
}
}
/* Server second round Input */
- status = psa_pake_input( server, PSA_PAKE_STEP_KEY_SHARE,
- buffer1 + c_a_off, c_a_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_KEY_SHARE,
+ buffer1 + c_a_off, c_a_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PUBLIC,
- buffer1 + c_x2s_pk_off, c_x2s_pk_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PUBLIC,
+ buffer1 + c_x2s_pk_off, c_x2s_pk_len);
+ DO_ROUND_CHECK_FAILURE();
- status = psa_pake_input( server, PSA_PAKE_STEP_ZK_PROOF,
- buffer1 + c_x2s_pr_off, c_x2s_pr_len );
- DO_ROUND_CHECK_FAILURE( );
+ status = psa_pake_input(server, PSA_PAKE_STEP_ZK_PROOF,
+ buffer1 + c_x2s_pr_off, c_x2s_pr_len);
+ DO_ROUND_CHECK_FAILURE();
/* Error didn't trigger, make test fail */
- if( ( err_stage >= ERR_INJECT_ROUND2_CLIENT_KEY_SHARE ) &&
- ( err_stage <= ERR_INJECT_ROUND2_CLIENT_ZK_PROOF ) )
- {
- TEST_ASSERT( ! "One of the last psa_pake_input() calls should have returned the expected error." );
+ if ((err_stage >= ERR_INJECT_ROUND2_CLIENT_KEY_SHARE) &&
+ (err_stage <= ERR_INJECT_ROUND2_CLIENT_ZK_PROOF)) {
+ TEST_ASSERT(
+ !"One of the last psa_pake_input() calls should have returned the expected error.");
}
break;
@@ -492,8 +485,8 @@
}
exit:
- mbedtls_free( buffer0 );
- mbedtls_free( buffer1 );
+ mbedtls_free(buffer0);
+ mbedtls_free(buffer1);
}
#endif /* PSA_WANT_ALG_JPAKE */
@@ -507,15 +500,15 @@
* - terminated with failure otherwise (either no error was expected at this
* stage or a different error code was expected)
*/
-#define SETUP_ALWAYS_CHECK_STEP( test_function, this_check_err_stage ) \
+#define SETUP_ALWAYS_CHECK_STEP(test_function, this_check_err_stage) \
status = test_function; \
- if( err_stage != this_check_err_stage ) \
+ if (err_stage != this_check_err_stage) \
{ \
- PSA_ASSERT( status ); \
+ PSA_ASSERT(status); \
} \
else \
{ \
- TEST_EQUAL( status, expected_error ); \
+ TEST_EQUAL(status, expected_error); \
goto exit; \
}
@@ -529,10 +522,10 @@
* The test succeeds if the returned error is exactly the expected one,
* otherwise it fails.
*/
-#define SETUP_CONDITIONAL_CHECK_STEP( test_function, this_check_err_stage ) \
- if( err_stage == this_check_err_stage ) \
+#define SETUP_CONDITIONAL_CHECK_STEP(test_function, this_check_err_stage) \
+ if (err_stage == this_check_err_stage) \
{ \
- TEST_EQUAL( test_function, expected_error ); \
+ TEST_EQUAL(test_function, expected_error); \
goto exit; \
}
/* END_HEADER */
@@ -543,11 +536,11 @@
*/
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
-void ecjpake_setup( int alg_arg, int key_type_pw_arg, int key_usage_pw_arg,
- int primitive_arg, int hash_arg, int role_arg,
- int test_input,
- int err_stage_arg,
- int expected_error_arg)
+void ecjpake_setup(int alg_arg, int key_type_pw_arg, int key_usage_pw_arg,
+ int primitive_arg, int hash_arg, int role_arg,
+ int test_input,
+ int err_stage_arg,
+ int expected_error_arg)
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t operation = psa_pake_operation_init();
@@ -567,161 +560,159 @@
const uint8_t unsupp_id[] = "abcd";
const uint8_t password[] = "abcd";
psa_key_derivation_operation_t key_derivation =
- PSA_KEY_DERIVATION_OPERATION_INIT;
+ PSA_KEY_DERIVATION_OPERATION_INIT;
- PSA_INIT( );
+ PSA_INIT();
- size_t buf_size = PSA_PAKE_OUTPUT_SIZE( alg, primitive_arg,
- PSA_PAKE_STEP_KEY_SHARE );
- ASSERT_ALLOC( output_buffer, buf_size );
+ size_t buf_size = PSA_PAKE_OUTPUT_SIZE(alg, primitive_arg,
+ PSA_PAKE_STEP_KEY_SHARE);
+ ASSERT_ALLOC(output_buffer, buf_size);
- psa_set_key_usage_flags( &attributes, key_usage_pw );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type_pw );
- PSA_ASSERT( psa_import_key( &attributes, password, sizeof( password ),
- &key ) );
+ psa_set_key_usage_flags(&attributes, key_usage_pw);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type_pw);
+ PSA_ASSERT(psa_import_key(&attributes, password, sizeof(password),
+ &key));
- psa_pake_cs_set_algorithm( &cipher_suite, alg );
- psa_pake_cs_set_primitive( &cipher_suite, primitive );
- psa_pake_cs_set_hash( &cipher_suite, hash_alg );
+ psa_pake_cs_set_algorithm(&cipher_suite, alg);
+ psa_pake_cs_set_primitive(&cipher_suite, primitive);
+ psa_pake_cs_set_hash(&cipher_suite, hash_alg);
- PSA_ASSERT( psa_pake_abort( &operation ) );
+ PSA_ASSERT(psa_pake_abort(&operation));
- if ( err_stage == ERR_INJECT_UNINITIALIZED_ACCESS )
- {
- TEST_EQUAL( psa_pake_set_user( &operation, NULL, 0 ),
- expected_error );
- TEST_EQUAL( psa_pake_set_peer( &operation, NULL, 0 ),
- expected_error );
- TEST_EQUAL( psa_pake_set_password_key( &operation, key ),
- expected_error );
- TEST_EQUAL( psa_pake_set_role( &operation, role ),
- expected_error );
- TEST_EQUAL( psa_pake_output( &operation, PSA_PAKE_STEP_KEY_SHARE,
- NULL, 0, NULL ),
- expected_error );
- TEST_EQUAL( psa_pake_input( &operation, PSA_PAKE_STEP_KEY_SHARE,
- NULL, 0 ),
- expected_error );
- TEST_EQUAL( psa_pake_get_implicit_key( &operation, &key_derivation ),
- expected_error );
+ if (err_stage == ERR_INJECT_UNINITIALIZED_ACCESS) {
+ TEST_EQUAL(psa_pake_set_user(&operation, NULL, 0),
+ expected_error);
+ TEST_EQUAL(psa_pake_set_peer(&operation, NULL, 0),
+ expected_error);
+ TEST_EQUAL(psa_pake_set_password_key(&operation, key),
+ expected_error);
+ TEST_EQUAL(psa_pake_set_role(&operation, role),
+ expected_error);
+ TEST_EQUAL(psa_pake_output(&operation, PSA_PAKE_STEP_KEY_SHARE,
+ NULL, 0, NULL),
+ expected_error);
+ TEST_EQUAL(psa_pake_input(&operation, PSA_PAKE_STEP_KEY_SHARE,
+ NULL, 0),
+ expected_error);
+ TEST_EQUAL(psa_pake_get_implicit_key(&operation, &key_derivation),
+ expected_error);
goto exit;
}
- SETUP_ALWAYS_CHECK_STEP( psa_pake_setup( &operation, &cipher_suite ),
- ERR_IN_SETUP );
+ SETUP_ALWAYS_CHECK_STEP(psa_pake_setup(&operation, &cipher_suite),
+ ERR_IN_SETUP);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_setup( &operation, &cipher_suite ),
- ERR_INJECT_DUPLICATE_SETUP);
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_setup(&operation, &cipher_suite),
+ ERR_INJECT_DUPLICATE_SETUP);
- SETUP_ALWAYS_CHECK_STEP( psa_pake_set_role( &operation, role),
- ERR_IN_SET_ROLE );
+ SETUP_ALWAYS_CHECK_STEP(psa_pake_set_role(&operation, role),
+ ERR_IN_SET_ROLE);
- SETUP_ALWAYS_CHECK_STEP( psa_pake_set_password_key( &operation, key ),
- ERR_IN_SET_PASSWORD_KEY );
+ SETUP_ALWAYS_CHECK_STEP(psa_pake_set_password_key(&operation, key),
+ ERR_IN_SET_PASSWORD_KEY);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_set_user( &operation, NULL, 0 ),
- ERR_INJECT_INVALID_USER );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_set_user(&operation, NULL, 0),
+ ERR_INJECT_INVALID_USER);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_set_peer( &operation, NULL, 0 ),
- ERR_INJECT_INVALID_PEER );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_set_peer(&operation, NULL, 0),
+ ERR_INJECT_INVALID_PEER);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_set_user( &operation, unsupp_id, 4 ),
- ERR_INJECT_SET_USER );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_set_user(&operation, unsupp_id, 4),
+ ERR_INJECT_SET_USER);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_set_peer( &operation, unsupp_id, 4 ),
- ERR_INJECT_SET_PEER );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_set_peer(&operation, unsupp_id, 4),
+ ERR_INJECT_SET_PEER);
- const size_t size_key_share = PSA_PAKE_INPUT_SIZE( alg, primitive,
- PSA_PAKE_STEP_KEY_SHARE );
- const size_t size_zk_public = PSA_PAKE_INPUT_SIZE( alg, primitive,
- PSA_PAKE_STEP_ZK_PUBLIC );
- const size_t size_zk_proof = PSA_PAKE_INPUT_SIZE( alg, primitive,
- PSA_PAKE_STEP_ZK_PROOF );
+ const size_t size_key_share = PSA_PAKE_INPUT_SIZE(alg, primitive,
+ PSA_PAKE_STEP_KEY_SHARE);
+ const size_t size_zk_public = PSA_PAKE_INPUT_SIZE(alg, primitive,
+ PSA_PAKE_STEP_ZK_PUBLIC);
+ const size_t size_zk_proof = PSA_PAKE_INPUT_SIZE(alg, primitive,
+ PSA_PAKE_STEP_ZK_PROOF);
- if ( test_input )
- {
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_input( &operation,
- PSA_PAKE_STEP_ZK_PROOF, NULL, 0 ),
- ERR_INJECT_EMPTY_IO_BUFFER );
+ if (test_input) {
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_input(&operation,
+ PSA_PAKE_STEP_ZK_PROOF, NULL, 0),
+ ERR_INJECT_EMPTY_IO_BUFFER);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_input( &operation,
- PSA_PAKE_STEP_ZK_PROOF + 10,
- output_buffer, size_zk_proof ),
- ERR_INJECT_UNKNOWN_STEP );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_input(&operation,
+ PSA_PAKE_STEP_ZK_PROOF + 10,
+ output_buffer, size_zk_proof),
+ ERR_INJECT_UNKNOWN_STEP);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_input( &operation,
- PSA_PAKE_STEP_ZK_PROOF,
- output_buffer, size_zk_proof ),
- ERR_INJECT_INVALID_FIRST_STEP )
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_input(&operation,
+ PSA_PAKE_STEP_ZK_PROOF,
+ output_buffer, size_zk_proof),
+ ERR_INJECT_INVALID_FIRST_STEP)
- SETUP_ALWAYS_CHECK_STEP( psa_pake_input( &operation,
- PSA_PAKE_STEP_KEY_SHARE,
- output_buffer, size_key_share ),
- ERR_IN_INPUT );
+ SETUP_ALWAYS_CHECK_STEP(psa_pake_input(&operation,
+ PSA_PAKE_STEP_KEY_SHARE,
+ output_buffer, size_key_share),
+ ERR_IN_INPUT);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_input( &operation,
- PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public + 1 ),
- ERR_INJECT_WRONG_BUFFER_SIZE );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_input(&operation,
+ PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public + 1),
+ ERR_INJECT_WRONG_BUFFER_SIZE);
SETUP_CONDITIONAL_CHECK_STEP(
- ( psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public + 1 ),
- psa_pake_input( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public ) ),
- ERR_INJECT_VALID_OPERATION_AFTER_FAILURE );
+ (psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public + 1),
+ psa_pake_input(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public)),
+ ERR_INJECT_VALID_OPERATION_AFTER_FAILURE);
} else {
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_output( &operation,
- PSA_PAKE_STEP_ZK_PROOF,
- NULL, 0, NULL ),
- ERR_INJECT_EMPTY_IO_BUFFER );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_output(&operation,
+ PSA_PAKE_STEP_ZK_PROOF,
+ NULL, 0, NULL),
+ ERR_INJECT_EMPTY_IO_BUFFER);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_output( &operation,
- PSA_PAKE_STEP_ZK_PROOF + 10,
- output_buffer, buf_size, &output_len ),
- ERR_INJECT_UNKNOWN_STEP );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_output(&operation,
+ PSA_PAKE_STEP_ZK_PROOF + 10,
+ output_buffer, buf_size, &output_len),
+ ERR_INJECT_UNKNOWN_STEP);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_output( &operation,
- PSA_PAKE_STEP_ZK_PROOF,
- output_buffer, buf_size, &output_len ),
- ERR_INJECT_INVALID_FIRST_STEP );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_output(&operation,
+ PSA_PAKE_STEP_ZK_PROOF,
+ output_buffer, buf_size, &output_len),
+ ERR_INJECT_INVALID_FIRST_STEP);
- SETUP_ALWAYS_CHECK_STEP( psa_pake_output( &operation,
- PSA_PAKE_STEP_KEY_SHARE,
- output_buffer, buf_size, &output_len ),
- ERR_IN_OUTPUT );
+ SETUP_ALWAYS_CHECK_STEP(psa_pake_output(&operation,
+ PSA_PAKE_STEP_KEY_SHARE,
+ output_buffer, buf_size, &output_len),
+ ERR_IN_OUTPUT);
- TEST_ASSERT( output_len > 0 );
+ TEST_ASSERT(output_len > 0);
- SETUP_CONDITIONAL_CHECK_STEP( psa_pake_output( &operation,
- PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public - 1,
- &output_len ),
- ERR_INJECT_WRONG_BUFFER_SIZE );
+ SETUP_CONDITIONAL_CHECK_STEP(psa_pake_output(&operation,
+ PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public - 1,
+ &output_len),
+ ERR_INJECT_WRONG_BUFFER_SIZE);
SETUP_CONDITIONAL_CHECK_STEP(
- ( psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, size_zk_public - 1, &output_len ),
- psa_pake_output( &operation, PSA_PAKE_STEP_ZK_PUBLIC,
- output_buffer, buf_size, &output_len ) ),
- ERR_INJECT_VALID_OPERATION_AFTER_FAILURE );
+ (psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, size_zk_public - 1, &output_len),
+ psa_pake_output(&operation, PSA_PAKE_STEP_ZK_PUBLIC,
+ output_buffer, buf_size, &output_len)),
+ ERR_INJECT_VALID_OPERATION_AFTER_FAILURE);
}
exit:
- PSA_ASSERT( psa_destroy_key( key ) );
- PSA_ASSERT( psa_pake_abort( &operation ) );
- mbedtls_free( output_buffer );
- PSA_DONE( );
+ PSA_ASSERT(psa_destroy_key(key));
+ PSA_ASSERT(psa_pake_abort(&operation));
+ mbedtls_free(output_buffer);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
-void ecjpake_rounds_inject( int alg_arg, int primitive_arg, int hash_arg,
- int client_input_first,
- data_t *pw_data,
- int err_stage_arg,
- int expected_error_arg )
+void ecjpake_rounds_inject(int alg_arg, int primitive_arg, int hash_arg,
+ int client_input_first,
+ data_t *pw_data,
+ int err_stage_arg,
+ int expected_error_arg)
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t server = psa_pake_operation_init();
@@ -732,51 +723,52 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
ecjpake_error_stage_t err_stage = err_stage_arg;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_PASSWORD );
- PSA_ASSERT( psa_import_key( &attributes, pw_data->x, pw_data->len,
- &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
+ PSA_ASSERT(psa_import_key(&attributes, pw_data->x, pw_data->len,
+ &key));
- psa_pake_cs_set_algorithm( &cipher_suite, alg );
- psa_pake_cs_set_primitive( &cipher_suite, primitive_arg );
- psa_pake_cs_set_hash( &cipher_suite, hash_alg );
+ psa_pake_cs_set_algorithm(&cipher_suite, alg);
+ psa_pake_cs_set_primitive(&cipher_suite, primitive_arg);
+ psa_pake_cs_set_hash(&cipher_suite, hash_alg);
- PSA_ASSERT( psa_pake_setup( &server, &cipher_suite ) );
- PSA_ASSERT( psa_pake_setup( &client, &cipher_suite ) );
+ PSA_ASSERT(psa_pake_setup(&server, &cipher_suite));
+ PSA_ASSERT(psa_pake_setup(&client, &cipher_suite));
- PSA_ASSERT( psa_pake_set_role( &server, PSA_PAKE_ROLE_SERVER ) );
- PSA_ASSERT( psa_pake_set_role( &client, PSA_PAKE_ROLE_CLIENT ) );
+ PSA_ASSERT(psa_pake_set_role(&server, PSA_PAKE_ROLE_SERVER));
+ PSA_ASSERT(psa_pake_set_role(&client, PSA_PAKE_ROLE_CLIENT));
- PSA_ASSERT( psa_pake_set_password_key( &server, key ) );
- PSA_ASSERT( psa_pake_set_password_key( &client, key ) );
+ PSA_ASSERT(psa_pake_set_password_key(&server, key));
+ PSA_ASSERT(psa_pake_set_password_key(&client, key));
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, PAKE_ROUND_ONE,
- err_stage, expected_error_arg );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, PAKE_ROUND_ONE,
+ err_stage, expected_error_arg);
- if( err_stage != ERR_NONE )
+ if (err_stage != ERR_NONE) {
goto exit;
+ }
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, PAKE_ROUND_TWO,
- err_stage, expected_error_arg );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, PAKE_ROUND_TWO,
+ err_stage, expected_error_arg);
exit:
- psa_destroy_key( key );
- psa_pake_abort( &server );
- psa_pake_abort( &client );
- PSA_DONE( );
+ psa_destroy_key(key);
+ psa_pake_abort(&server);
+ psa_pake_abort(&client);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
-void ecjpake_rounds( int alg_arg, int primitive_arg, int hash_arg,
- int derive_alg_arg, data_t *pw_data,
- int client_input_first, int destroy_key,
- int err_stage_arg )
+void ecjpake_rounds(int alg_arg, int primitive_arg, int hash_arg,
+ int derive_alg_arg, data_t *pw_data,
+ int client_input_first, int destroy_key,
+ int err_stage_arg)
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t server = psa_pake_operation_init();
@@ -787,131 +779,129 @@
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_derivation_operation_t server_derive =
- PSA_KEY_DERIVATION_OPERATION_INIT;
+ PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_derivation_operation_t client_derive =
- PSA_KEY_DERIVATION_OPERATION_INIT;
+ PSA_KEY_DERIVATION_OPERATION_INIT;
ecjpake_error_stage_t err_stage = err_stage_arg;
- PSA_INIT( );
+ PSA_INIT();
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_PASSWORD );
- PSA_ASSERT( psa_import_key( &attributes, pw_data->x, pw_data->len,
- &key ) );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
+ PSA_ASSERT(psa_import_key(&attributes, pw_data->x, pw_data->len,
+ &key));
- psa_pake_cs_set_algorithm( &cipher_suite, alg );
- psa_pake_cs_set_primitive( &cipher_suite, primitive_arg );
- psa_pake_cs_set_hash( &cipher_suite, hash_alg );
+ psa_pake_cs_set_algorithm(&cipher_suite, alg);
+ psa_pake_cs_set_primitive(&cipher_suite, primitive_arg);
+ psa_pake_cs_set_hash(&cipher_suite, hash_alg);
/* Get shared key */
- PSA_ASSERT( psa_key_derivation_setup( &server_derive, derive_alg ) );
- PSA_ASSERT( psa_key_derivation_setup( &client_derive, derive_alg ) );
+ PSA_ASSERT(psa_key_derivation_setup(&server_derive, derive_alg));
+ PSA_ASSERT(psa_key_derivation_setup(&client_derive, derive_alg));
- if( PSA_ALG_IS_TLS12_PRF( derive_alg ) ||
- PSA_ALG_IS_TLS12_PSK_TO_MS( derive_alg ) )
- {
- PSA_ASSERT( psa_key_derivation_input_bytes( &server_derive,
- PSA_KEY_DERIVATION_INPUT_SEED,
- (const uint8_t*) "", 0) );
- PSA_ASSERT( psa_key_derivation_input_bytes( &client_derive,
- PSA_KEY_DERIVATION_INPUT_SEED,
- (const uint8_t*) "", 0) );
+ if (PSA_ALG_IS_TLS12_PRF(derive_alg) ||
+ PSA_ALG_IS_TLS12_PSK_TO_MS(derive_alg)) {
+ PSA_ASSERT(psa_key_derivation_input_bytes(&server_derive,
+ PSA_KEY_DERIVATION_INPUT_SEED,
+ (const uint8_t *) "", 0));
+ PSA_ASSERT(psa_key_derivation_input_bytes(&client_derive,
+ PSA_KEY_DERIVATION_INPUT_SEED,
+ (const uint8_t *) "", 0));
}
- PSA_ASSERT( psa_pake_setup( &server, &cipher_suite ) );
- PSA_ASSERT( psa_pake_setup( &client, &cipher_suite ) );
+ PSA_ASSERT(psa_pake_setup(&server, &cipher_suite));
+ PSA_ASSERT(psa_pake_setup(&client, &cipher_suite));
- PSA_ASSERT( psa_pake_set_role( &server, PSA_PAKE_ROLE_SERVER ) );
- PSA_ASSERT( psa_pake_set_role( &client, PSA_PAKE_ROLE_CLIENT ) );
+ PSA_ASSERT(psa_pake_set_role(&server, PSA_PAKE_ROLE_SERVER));
+ PSA_ASSERT(psa_pake_set_role(&client, PSA_PAKE_ROLE_CLIENT));
- PSA_ASSERT( psa_pake_set_password_key( &server, key ) );
- PSA_ASSERT( psa_pake_set_password_key( &client, key ) );
+ PSA_ASSERT(psa_pake_set_password_key(&server, key));
+ PSA_ASSERT(psa_pake_set_password_key(&client, key));
- if( destroy_key == 1 )
- psa_destroy_key( key );
+ if (destroy_key == 1) {
+ psa_destroy_key(key);
+ }
- if( err_stage == ERR_INJECT_ANTICIPATE_KEY_DERIVATION_1 )
- {
- TEST_EQUAL( psa_pake_get_implicit_key( &server, &server_derive ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_pake_get_implicit_key( &client, &client_derive ),
- PSA_ERROR_BAD_STATE );
+ if (err_stage == ERR_INJECT_ANTICIPATE_KEY_DERIVATION_1) {
+ TEST_EQUAL(psa_pake_get_implicit_key(&server, &server_derive),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_pake_get_implicit_key(&client, &client_derive),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
/* First round */
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, PAKE_ROUND_ONE,
- ERR_NONE, PSA_SUCCESS );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, PAKE_ROUND_ONE,
+ ERR_NONE, PSA_SUCCESS);
- if ( err_stage == ERR_INJECT_ANTICIPATE_KEY_DERIVATION_2 )
- {
- TEST_EQUAL( psa_pake_get_implicit_key( &server, &server_derive ),
- PSA_ERROR_BAD_STATE );
- TEST_EQUAL( psa_pake_get_implicit_key( &client, &client_derive ),
- PSA_ERROR_BAD_STATE );
+ if (err_stage == ERR_INJECT_ANTICIPATE_KEY_DERIVATION_2) {
+ TEST_EQUAL(psa_pake_get_implicit_key(&server, &server_derive),
+ PSA_ERROR_BAD_STATE);
+ TEST_EQUAL(psa_pake_get_implicit_key(&client, &client_derive),
+ PSA_ERROR_BAD_STATE);
goto exit;
}
/* Second round */
- ecjpake_do_round( alg, primitive_arg, &server, &client,
- client_input_first, PAKE_ROUND_TWO,
- ERR_NONE, PSA_SUCCESS );
+ ecjpake_do_round(alg, primitive_arg, &server, &client,
+ client_input_first, PAKE_ROUND_TWO,
+ ERR_NONE, PSA_SUCCESS);
- PSA_ASSERT( psa_pake_get_implicit_key( &server, &server_derive ) );
- PSA_ASSERT( psa_pake_get_implicit_key( &client, &client_derive ) );
+ PSA_ASSERT(psa_pake_get_implicit_key(&server, &server_derive));
+ PSA_ASSERT(psa_pake_get_implicit_key(&client, &client_derive));
exit:
- psa_key_derivation_abort( &server_derive );
- psa_key_derivation_abort( &client_derive );
- psa_destroy_key( key );
- psa_pake_abort( &server );
- psa_pake_abort( &client );
- PSA_DONE( );
+ psa_key_derivation_abort(&server_derive);
+ psa_key_derivation_abort(&client_derive);
+ psa_destroy_key(key);
+ psa_pake_abort(&server);
+ psa_pake_abort(&client);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void ecjpake_size_macros( )
+void ecjpake_size_macros()
{
const psa_algorithm_t alg = PSA_ALG_JPAKE;
const size_t bits = 256;
const psa_pake_primitive_t prim = PSA_PAKE_PRIMITIVE(
- PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, bits );
+ PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, bits);
const psa_key_type_t key_type = PSA_KEY_TYPE_ECC_KEY_PAIR(
- PSA_ECC_FAMILY_SECP_R1 );
+ PSA_ECC_FAMILY_SECP_R1);
// https://armmbed.github.io/mbed-crypto/1.1_PAKE_Extension.0-bet.0/html/pake.html#pake-step-types
/* The output for KEY_SHARE and ZK_PUBLIC is the same as a public key */
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( key_type, bits ) );
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE( key_type, bits ) );
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, bits));
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, bits));
/* The output for ZK_PROOF is the same bitsize as the curve */
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_BITS_TO_BYTES( bits ) );
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_BITS_TO_BYTES(bits));
/* Input sizes are the same as output sizes */
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE) );
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC) );
- TEST_EQUAL( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF) );
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE));
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC));
+ TEST_EQUAL(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF));
/* These inequalities will always hold even when other PAKEs are added */
- TEST_LE_U( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_PAKE_OUTPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_PAKE_OUTPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_PAKE_OUTPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
- PSA_PAKE_INPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
- PSA_PAKE_INPUT_MAX_SIZE );
- TEST_LE_U( PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
- PSA_PAKE_INPUT_MAX_SIZE );
+ TEST_LE_U(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_PAKE_OUTPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_PAKE_OUTPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_OUTPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_PAKE_OUTPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_KEY_SHARE),
+ PSA_PAKE_INPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PUBLIC),
+ PSA_PAKE_INPUT_MAX_SIZE);
+ TEST_LE_U(PSA_PAKE_INPUT_SIZE(alg, prim, PSA_PAKE_STEP_ZK_PROOF),
+ PSA_PAKE_INPUT_MAX_SIZE);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_persistent_key.function b/tests/suites/test_suite_psa_crypto_persistent_key.function
index bb87923..23535df 100644
--- a/tests/suites/test_suite_psa_crypto_persistent_key.function
+++ b/tests/suites/test_suite_psa_crypto_persistent_key.function
@@ -20,7 +20,7 @@
#include "mbedtls/md.h"
#define PSA_KEY_STORAGE_MAGIC_HEADER "PSA\0KEY"
-#define PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH ( sizeof( PSA_KEY_STORAGE_MAGIC_HEADER ) )
+#define PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH (sizeof(PSA_KEY_STORAGE_MAGIC_HEADER))
/* Enforce the storage format for keys. The storage format is not a public
* documented interface, but it must be preserved between versions so that
@@ -29,9 +29,9 @@
typedef struct {
uint8_t magic[PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH];
uint8_t version[4];
- uint8_t lifetime[sizeof( psa_key_lifetime_t )];
+ uint8_t lifetime[sizeof(psa_key_lifetime_t)];
uint8_t type[4];
- uint8_t policy[sizeof( psa_key_policy_t )];
+ uint8_t policy[sizeof(psa_key_policy_t)];
uint8_t data_len[4];
uint8_t key_data[];
} psa_persistent_key_storage_format;
@@ -44,223 +44,222 @@
*/
/* BEGIN_CASE */
-void format_storage_data_check( data_t *key_data,
- data_t *expected_file_data,
- int key_lifetime, int key_type, int key_bits,
- int key_usage, int key_alg, int key_alg2 )
+void format_storage_data_check(data_t *key_data,
+ data_t *expected_file_data,
+ int key_lifetime, int key_type, int key_bits,
+ int key_usage, int key_alg, int key_alg2)
{
uint8_t *file_data = NULL;
size_t file_data_length =
- key_data->len + sizeof( psa_persistent_key_storage_format );
+ key_data->len + sizeof(psa_persistent_key_storage_format);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_set_key_lifetime( &attributes, key_lifetime );
- psa_set_key_type( &attributes, key_type );
- psa_set_key_bits( &attributes, key_bits );
- psa_set_key_usage_flags( &attributes, key_usage );
- psa_set_key_algorithm( &attributes, key_alg );
- psa_set_key_enrollment_algorithm( &attributes, key_alg2 );
+ psa_set_key_lifetime(&attributes, key_lifetime);
+ psa_set_key_type(&attributes, key_type);
+ psa_set_key_bits(&attributes, key_bits);
+ psa_set_key_usage_flags(&attributes, key_usage);
+ psa_set_key_algorithm(&attributes, key_alg);
+ psa_set_key_enrollment_algorithm(&attributes, key_alg2);
- ASSERT_ALLOC( file_data, file_data_length );
- psa_format_key_data_for_storage( key_data->x, key_data->len,
- &attributes.core,
- file_data );
+ ASSERT_ALLOC(file_data, file_data_length);
+ psa_format_key_data_for_storage(key_data->x, key_data->len,
+ &attributes.core,
+ file_data);
- ASSERT_COMPARE( expected_file_data->x, expected_file_data->len,
- file_data, file_data_length );
+ ASSERT_COMPARE(expected_file_data->x, expected_file_data->len,
+ file_data, file_data_length);
exit:
- mbedtls_free( file_data );
+ mbedtls_free(file_data);
}
/* END_CASE */
/* BEGIN_CASE */
-void parse_storage_data_check( data_t *file_data,
- data_t *expected_key_data,
- int expected_key_lifetime,
- int expected_key_type,
- int expected_key_bits,
- int expected_key_usage,
- int expected_key_alg,
- int expected_key_alg2,
- int expected_status )
+void parse_storage_data_check(data_t *file_data,
+ data_t *expected_key_data,
+ int expected_key_lifetime,
+ int expected_key_type,
+ int expected_key_bits,
+ int expected_key_usage,
+ int expected_key_alg,
+ int expected_key_alg2,
+ int expected_status)
{
uint8_t *key_data = NULL;
size_t key_data_length = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status;
- status = psa_parse_key_data_from_storage( file_data->x, file_data->len,
- &key_data, &key_data_length,
- &attributes.core );
+ status = psa_parse_key_data_from_storage(file_data->x, file_data->len,
+ &key_data, &key_data_length,
+ &attributes.core);
- TEST_EQUAL( status, expected_status );
- if( status != PSA_SUCCESS )
+ TEST_EQUAL(status, expected_status);
+ if (status != PSA_SUCCESS) {
goto exit;
+ }
- TEST_EQUAL( psa_get_key_lifetime( &attributes ),
- (psa_key_type_t) expected_key_lifetime );
- TEST_EQUAL( psa_get_key_type( &attributes ),
- (psa_key_type_t) expected_key_type );
- TEST_EQUAL( psa_get_key_bits( &attributes ),
- (psa_key_bits_t) expected_key_bits );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ),
- (uint32_t) expected_key_usage );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ),
- (uint32_t) expected_key_alg );
- TEST_EQUAL( psa_get_key_enrollment_algorithm( &attributes ),
- (uint32_t) expected_key_alg2 );
- ASSERT_COMPARE( expected_key_data->x, expected_key_data->len,
- key_data, key_data_length );
+ TEST_EQUAL(psa_get_key_lifetime(&attributes),
+ (psa_key_type_t) expected_key_lifetime);
+ TEST_EQUAL(psa_get_key_type(&attributes),
+ (psa_key_type_t) expected_key_type);
+ TEST_EQUAL(psa_get_key_bits(&attributes),
+ (psa_key_bits_t) expected_key_bits);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes),
+ (uint32_t) expected_key_usage);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes),
+ (uint32_t) expected_key_alg);
+ TEST_EQUAL(psa_get_key_enrollment_algorithm(&attributes),
+ (uint32_t) expected_key_alg2);
+ ASSERT_COMPARE(expected_key_data->x, expected_key_data->len,
+ key_data, key_data_length);
exit:
- mbedtls_free( key_data );
+ mbedtls_free(key_data);
}
/* END_CASE */
/* BEGIN_CASE */
-void save_large_persistent_key( int data_length_arg, int expected_status )
+void save_large_persistent_key(int data_length_arg, int expected_status)
{
- mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 1, 42 );
+ mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make(1, 42);
uint8_t *data = NULL;
size_t data_length = data_length_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- ASSERT_ALLOC( data, data_length );
+ ASSERT_ALLOC(data, data_length);
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, key_id );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
- TEST_EQUAL( psa_import_key( &attributes, data, data_length, &key_id ),
- expected_status );
+ TEST_EQUAL(psa_import_key(&attributes, data, data_length, &key_id),
+ expected_status);
- if( expected_status == PSA_SUCCESS )
- PSA_ASSERT( psa_destroy_key( key_id ) );
+ if (expected_status == PSA_SUCCESS) {
+ PSA_ASSERT(psa_destroy_key(key_id));
+ }
exit:
- mbedtls_free( data );
+ mbedtls_free(data);
PSA_DONE();
- psa_destroy_persistent_key( key_id );
+ psa_destroy_persistent_key(key_id);
}
/* END_CASE */
/* BEGIN_CASE */
-void persistent_key_destroy( int owner_id_arg, int key_id_arg, int restart,
- int first_type_arg, data_t *first_data,
- int second_type_arg, data_t *second_data )
+void persistent_key_destroy(int owner_id_arg, int key_id_arg, int restart,
+ int first_type_arg, data_t *first_data,
+ int second_type_arg, data_t *second_data)
{
mbedtls_svc_key_id_t key_id =
- mbedtls_svc_key_id_make( owner_id_arg, key_id_arg );
+ mbedtls_svc_key_id_make(owner_id_arg, key_id_arg);
mbedtls_svc_key_id_t returned_key_id = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t first_type = (psa_key_type_t) first_type_arg;
psa_key_type_t second_type = (psa_key_type_t) second_type_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, key_id );
- psa_set_key_type( &attributes, first_type );
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_type(&attributes, first_type);
- PSA_ASSERT( psa_import_key( &attributes, first_data->x, first_data->len,
- &returned_key_id ) );
+ PSA_ASSERT(psa_import_key(&attributes, first_data->x, first_data->len,
+ &returned_key_id));
- if( restart )
- {
- psa_close_key( key_id );
+ if (restart) {
+ psa_close_key(key_id);
PSA_DONE();
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
}
- TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 1 );
+ TEST_EQUAL(psa_is_key_present_in_storage(key_id), 1);
/* Destroy the key */
- PSA_ASSERT( psa_destroy_key( key_id ) );
+ PSA_ASSERT(psa_destroy_key(key_id));
/* Check key slot storage is removed */
- TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 );
+ TEST_EQUAL(psa_is_key_present_in_storage(key_id), 0);
/* Shutdown and restart */
PSA_DONE();
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
/* Create another key in the same slot */
- psa_set_key_id( &attributes, key_id );
- psa_set_key_type( &attributes, second_type );
- PSA_ASSERT( psa_import_key( &attributes, second_data->x, second_data->len,
- &returned_key_id ) );
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_type(&attributes, second_type);
+ PSA_ASSERT(psa_import_key(&attributes, second_data->x, second_data->len,
+ &returned_key_id));
- PSA_ASSERT( psa_destroy_key( key_id ) );
+ PSA_ASSERT(psa_destroy_key(key_id));
exit:
PSA_DONE();
- psa_destroy_persistent_key( key_id );
+ psa_destroy_persistent_key(key_id);
}
/* END_CASE */
/* BEGIN_CASE */
-void persistent_key_import( int owner_id_arg, int key_id_arg, int type_arg,
- data_t *data, int restart, int expected_status )
+void persistent_key_import(int owner_id_arg, int key_id_arg, int type_arg,
+ data_t *data, int restart, int expected_status)
{
mbedtls_svc_key_id_t key_id =
- mbedtls_svc_key_id_make( owner_id_arg, key_id_arg );
+ mbedtls_svc_key_id_make(owner_id_arg, key_id_arg);
mbedtls_svc_key_id_t returned_key_id;
psa_key_type_t type = (psa_key_type_t) type_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, key_id );
- psa_set_key_type( &attributes, type );
- TEST_EQUAL( psa_import_key( &attributes, data->x, data->len, &returned_key_id ),
- expected_status );
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_type(&attributes, type);
+ TEST_EQUAL(psa_import_key(&attributes, data->x, data->len, &returned_key_id),
+ expected_status);
- if( expected_status != PSA_SUCCESS )
- {
- TEST_ASSERT( mbedtls_svc_key_id_is_null( returned_key_id ) );
- TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 );
+ if (expected_status != PSA_SUCCESS) {
+ TEST_ASSERT(mbedtls_svc_key_id_is_null(returned_key_id));
+ TEST_EQUAL(psa_is_key_present_in_storage(key_id), 0);
goto exit;
}
- TEST_ASSERT( mbedtls_svc_key_id_equal( returned_key_id, key_id ) );
+ TEST_ASSERT(mbedtls_svc_key_id_equal(returned_key_id, key_id));
- if( restart )
- {
- PSA_ASSERT( psa_purge_key( key_id ) );
+ if (restart) {
+ PSA_ASSERT(psa_purge_key(key_id));
PSA_DONE();
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
}
- psa_reset_key_attributes( &attributes );
- PSA_ASSERT( psa_get_key_attributes( key_id, &attributes ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( psa_get_key_id( &attributes ),
- key_id ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ),
- PSA_KEY_LIFETIME_PERSISTENT );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
+ psa_reset_key_attributes(&attributes);
+ PSA_ASSERT(psa_get_key_attributes(key_id, &attributes));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(psa_get_key_id(&attributes),
+ key_id));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes),
+ PSA_KEY_LIFETIME_PERSISTENT);
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), 0);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), 0);
- PSA_ASSERT( psa_destroy_key( key_id ) );
+ PSA_ASSERT(psa_destroy_key(key_id));
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_persistent_key( key_id );
+ psa_destroy_persistent_key(key_id);
PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void import_export_persistent_key( data_t *data, int type_arg,
- int expected_bits,
- int restart, int key_not_exist )
+void import_export_persistent_key(data_t *data, int type_arg,
+ int expected_bits,
+ int restart, int key_not_exist)
{
- mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 1, 42 );
+ mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make(1, 42);
psa_key_type_t type = (psa_key_type_t) type_arg;
mbedtls_svc_key_id_t returned_key_id = MBEDTLS_SVC_KEY_ID_INIT;
unsigned char *exported = NULL;
@@ -268,78 +267,76 @@
size_t exported_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- ASSERT_ALLOC( exported, export_size );
+ ASSERT_ALLOC(exported, export_size);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, key_id );
- psa_set_key_type( &attributes, type );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
/* Import the key */
- PSA_ASSERT( psa_import_key( &attributes, data->x, data->len,
- &returned_key_id ) );
+ PSA_ASSERT(psa_import_key(&attributes, data->x, data->len,
+ &returned_key_id));
- if( restart )
- {
- PSA_ASSERT( psa_purge_key( key_id ) );
+ if (restart) {
+ PSA_ASSERT(psa_purge_key(key_id));
PSA_DONE();
- PSA_ASSERT( psa_crypto_init() );
+ PSA_ASSERT(psa_crypto_init());
}
/* Test the key information */
- psa_reset_key_attributes( &attributes );
- PSA_ASSERT( psa_get_key_attributes( key_id, &attributes ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ), key_id ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ),
- PSA_KEY_LIFETIME_PERSISTENT );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- TEST_EQUAL( psa_get_key_bits( &attributes ), (size_t) expected_bits );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), PSA_KEY_USAGE_EXPORT );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
+ psa_reset_key_attributes(&attributes);
+ PSA_ASSERT(psa_get_key_attributes(key_id, &attributes));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes), key_id));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes),
+ PSA_KEY_LIFETIME_PERSISTENT);
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ TEST_EQUAL(psa_get_key_bits(&attributes), (size_t) expected_bits);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), PSA_KEY_USAGE_EXPORT);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), 0);
- TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 1 );
+ TEST_EQUAL(psa_is_key_present_in_storage(key_id), 1);
- if( key_not_exist )
- {
- psa_destroy_persistent_key( key_id );
+ if (key_not_exist) {
+ psa_destroy_persistent_key(key_id);
}
/* Export the key */
- PSA_ASSERT( psa_export_key( key_id, exported, export_size,
- &exported_length ) );
+ PSA_ASSERT(psa_export_key(key_id, exported, export_size,
+ &exported_length));
- ASSERT_COMPARE( data->x, data->len, exported, exported_length );
+ ASSERT_COMPARE(data->x, data->len, exported, exported_length);
/* Destroy the key */
- PSA_ASSERT( psa_destroy_key( key_id ) );
- TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 );
+ PSA_ASSERT(psa_destroy_key(key_id));
+ TEST_EQUAL(psa_is_key_present_in_storage(key_id), 0);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- mbedtls_free( exported );
- PSA_DONE( );
- psa_destroy_persistent_key( key_id );
+ mbedtls_free(exported);
+ PSA_DONE();
+ psa_destroy_persistent_key(key_id);
}
/* END_CASE */
/* BEGIN_CASE */
-void destroy_nonexistent( int id_arg, int expected_status_arg )
+void destroy_nonexistent(int id_arg, int expected_status_arg)
{
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, id_arg );
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, id_arg);
psa_status_t expected_status = expected_status_arg;
- PSA_INIT( );
+ PSA_INIT();
- TEST_EQUAL( expected_status, psa_destroy_key( id ) );
+ TEST_EQUAL(expected_status, psa_destroy_key(id));
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal.function b/tests/suites/test_suite_psa_crypto_se_driver_hal.function
index 9f68491..5c94371 100644
--- a/tests/suites/test_suite_psa_crypto_se_driver_hal.function
+++ b/tests/suites/test_suite_psa_crypto_se_driver_hal.function
@@ -24,16 +24,16 @@
/** The location and lifetime used for tests that use a single driver. */
#define TEST_DRIVER_LOCATION 1
#define TEST_SE_PERSISTENT_LIFETIME \
- ( PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
- PSA_KEY_PERSISTENCE_DEFAULT, TEST_DRIVER_LOCATION ) )
+ (PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
+ PSA_KEY_PERSISTENCE_DEFAULT, TEST_DRIVER_LOCATION))
#define TEST_SE_VOLATILE_LIFETIME \
- ( PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
- PSA_KEY_PERSISTENCE_VOLATILE, TEST_DRIVER_LOCATION ) )
+ (PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
+ PSA_KEY_PERSISTENCE_VOLATILE, TEST_DRIVER_LOCATION))
/** The driver detected a condition that shouldn't happen.
* This is probably a bug in the library. */
-#define PSA_ERROR_DETECTED_BY_DRIVER ((psa_status_t)( -500 ))
+#define PSA_ERROR_DETECTED_BY_DRIVER ((psa_status_t) (-500))
/** Like #TEST_ASSERT for use in a driver method, with no cleanup.
*
@@ -41,14 +41,14 @@
*
* Use this macro to assert on guarantees provided by the core.
*/
-#define DRIVER_ASSERT_RETURN( TEST ) \
+#define DRIVER_ASSERT_RETURN(TEST) \
do { \
- if( ! (TEST) ) \
- { \
- mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
- return( PSA_ERROR_DETECTED_BY_DRIVER ); \
- } \
- } while( 0 )
+ if (!(TEST)) \
+ { \
+ mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
+ return PSA_ERROR_DETECTED_BY_DRIVER; \
+ } \
+ } while (0)
/** Like #TEST_ASSERT for use in a driver method, with cleanup.
*
@@ -57,15 +57,15 @@
*
* Use this macro to assert on guarantees provided by the core.
*/
-#define DRIVER_ASSERT( TEST ) \
+#define DRIVER_ASSERT(TEST) \
do { \
- if( ! (TEST) ) \
- { \
- mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
- status = PSA_ERROR_DETECTED_BY_DRIVER; \
- goto exit; \
- } \
- } while( 0 )
+ if (!(TEST)) \
+ { \
+ mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
+ status = PSA_ERROR_DETECTED_BY_DRIVER; \
+ goto exit; \
+ } \
+ } while (0)
/** Like #PSA_ASSERT for a PSA API call that calls a driver underneath.
*
@@ -78,17 +78,17 @@
* case, the test driver code is expected to have called mbedtls_test_fail()
* already, so we make sure not to overwrite the failure information.
*/
-#define PSA_ASSERT_VIA_DRIVER( expr, expected_status ) \
+#define PSA_ASSERT_VIA_DRIVER(expr, expected_status) \
do { \
- psa_status_t PSA_ASSERT_VIA_DRIVER_status = ( expr ); \
- if( PSA_ASSERT_VIA_DRIVER_status == PSA_ERROR_DETECTED_BY_DRIVER ) \
- goto exit; \
- if( PSA_ASSERT_VIA_DRIVER_status != ( expected_status ) ) \
+ psa_status_t PSA_ASSERT_VIA_DRIVER_status = (expr); \
+ if (PSA_ASSERT_VIA_DRIVER_status == PSA_ERROR_DETECTED_BY_DRIVER) \
+ goto exit; \
+ if (PSA_ASSERT_VIA_DRIVER_status != (expected_status)) \
{ \
- mbedtls_test_fail( #expr, __LINE__, __FILE__ ); \
+ mbedtls_test_fail( #expr, __LINE__, __FILE__); \
goto exit; \
} \
- } while( 0 )
+ } while (0)
@@ -97,20 +97,21 @@
/****************************************************************/
/* Return the exact bit size given a curve family and a byte length. */
-static size_t ecc_curve_bits( psa_ecc_family_t curve, size_t data_length )
+static size_t ecc_curve_bits(psa_ecc_family_t curve, size_t data_length)
{
- switch( curve )
- {
+ switch (curve) {
case PSA_ECC_FAMILY_SECP_R1:
- if( data_length == PSA_BYTES_TO_BITS( 521 ) )
- return( 521 );
+ if (data_length == PSA_BYTES_TO_BITS(521)) {
+ return 521;
+ }
break;
case PSA_ECC_FAMILY_MONTGOMERY:
- if( data_length == PSA_BYTES_TO_BITS( 255 ) )
- return( 255 );
+ if (data_length == PSA_BYTES_TO_BITS(255)) {
+ return 255;
+ }
}
/* If not listed above, assume a multiple of 8 bits. */
- return( PSA_BYTES_TO_BITS( data_length ) );
+ return PSA_BYTES_TO_BITS(data_length);
}
@@ -118,8 +119,7 @@
/* Miscellaneous driver methods */
/****************************************************************/
-typedef struct
-{
+typedef struct {
psa_key_slot_number_t slot_number;
psa_key_creation_method_t method;
psa_status_t status;
@@ -132,51 +132,53 @@
void *persistent_data,
const psa_key_attributes_t *attributes,
psa_key_creation_method_t method,
- psa_key_slot_number_t slot_number )
+ psa_key_slot_number_t slot_number)
{
(void) context;
(void) persistent_data;
(void) attributes;
- DRIVER_ASSERT_RETURN( slot_number ==
- validate_slot_number_directions.slot_number );
- DRIVER_ASSERT_RETURN( method ==
- validate_slot_number_directions.method );
- return( validate_slot_number_directions.status );
+ DRIVER_ASSERT_RETURN(slot_number ==
+ validate_slot_number_directions.slot_number);
+ DRIVER_ASSERT_RETURN(method ==
+ validate_slot_number_directions.method);
+ return validate_slot_number_directions.status;
}
/* Allocate slot numbers with a monotonic counter. */
static psa_key_slot_number_t shadow_counter;
-static void counter_reset( void )
+static void counter_reset(void)
{
shadow_counter = 0;
}
-static psa_status_t counter_allocate( psa_drv_se_context_t *context,
- void *persistent_data,
- const psa_key_attributes_t *attributes,
- psa_key_creation_method_t method,
- psa_key_slot_number_t *slot_number )
+static psa_status_t counter_allocate(psa_drv_se_context_t *context,
+ void *persistent_data,
+ const psa_key_attributes_t *attributes,
+ psa_key_creation_method_t method,
+ psa_key_slot_number_t *slot_number)
{
psa_key_slot_number_t *p_counter = persistent_data;
(void) attributes;
(void) method;
- if( context->persistent_data_size != sizeof( psa_key_slot_number_t ) )
- return( PSA_ERROR_DETECTED_BY_DRIVER );
+ if (context->persistent_data_size != sizeof(psa_key_slot_number_t)) {
+ return PSA_ERROR_DETECTED_BY_DRIVER;
+ }
++*p_counter;
- if( *p_counter == 0 )
- return( PSA_ERROR_INSUFFICIENT_STORAGE );
+ if (*p_counter == 0) {
+ return PSA_ERROR_INSUFFICIENT_STORAGE;
+ }
shadow_counter = *p_counter;
*slot_number = *p_counter;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
/* Null import: do nothing, but pretend it worked. */
#if defined(AT_LEAST_ONE_BUILTIN_KDF)
-static psa_status_t null_import( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- const psa_key_attributes_t *attributes,
- const uint8_t *data,
- size_t data_length,
- size_t *bits )
+static psa_status_t null_import(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ const psa_key_attributes_t *attributes,
+ const uint8_t *data,
+ size_t data_length,
+ size_t *bits)
{
(void) context;
(void) slot_number;
@@ -184,44 +186,43 @@
(void) data;
/* We're supposed to return a key size. Return one that's correct for
* plain data keys. */
- *bits = PSA_BYTES_TO_BITS( data_length );
- return( PSA_SUCCESS );
+ *bits = PSA_BYTES_TO_BITS(data_length);
+ return PSA_SUCCESS;
}
#endif /* AT_LEAST_ONE_BUILTIN_KDF */
/* Null generate: do nothing, but pretend it worked. */
#if defined(AT_LEAST_ONE_BUILTIN_KDF)
-static psa_status_t null_generate( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- const psa_key_attributes_t *attributes,
- uint8_t *pubkey,
- size_t pubkey_size,
- size_t *pubkey_length )
+static psa_status_t null_generate(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ const psa_key_attributes_t *attributes,
+ uint8_t *pubkey,
+ size_t pubkey_size,
+ size_t *pubkey_length)
{
(void) context;
(void) slot_number;
(void) attributes;
- DRIVER_ASSERT_RETURN( *pubkey_length == 0 );
- if( ! PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
- {
- DRIVER_ASSERT_RETURN( pubkey == NULL );
- DRIVER_ASSERT_RETURN( pubkey_size == 0 );
+ DRIVER_ASSERT_RETURN(*pubkey_length == 0);
+ if (!PSA_KEY_TYPE_IS_KEY_PAIR(psa_get_key_type(attributes))) {
+ DRIVER_ASSERT_RETURN(pubkey == NULL);
+ DRIVER_ASSERT_RETURN(pubkey_size == 0);
}
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
#endif /* AT_LEAST_ONE_BUILTIN_KDF */
/* Null destroy: do nothing, but pretend it worked. */
-static psa_status_t null_destroy( psa_drv_se_context_t *context,
- void *persistent_data,
- psa_key_slot_number_t slot_number )
+static psa_status_t null_destroy(psa_drv_se_context_t *context,
+ void *persistent_data,
+ psa_key_slot_number_t slot_number)
{
(void) context;
(void) persistent_data;
(void) slot_number;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
@@ -231,8 +232,7 @@
/****************************************************************/
#define RAM_MAX_KEY_SIZE 64
-typedef struct
-{
+typedef struct {
psa_key_lifetime_t lifetime;
psa_key_type_t type;
size_t bits;
@@ -248,9 +248,9 @@
static uint8_t ram_min_slot = 0;
-static void ram_slots_reset( void )
+static void ram_slots_reset(void)
{
- memset( ram_slots, 0, sizeof( ram_slots ) );
+ memset(ram_slots, 0, sizeof(ram_slots));
ram_min_slot = 0;
ram_shadow_slot_usage = 0;
}
@@ -263,168 +263,165 @@
* in the test case function's cleanup code) and it might be wrong
* (if slot_number is invalid).
*/
-static psa_status_t ram_create_common( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- const psa_key_attributes_t *attributes,
- size_t required_storage )
+static psa_status_t ram_create_common(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ const psa_key_attributes_t *attributes,
+ size_t required_storage)
{
(void) context;
- DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
+ DRIVER_ASSERT_RETURN(slot_number < ARRAY_LENGTH(ram_slots));
- ram_slots[slot_number].lifetime = psa_get_key_lifetime( attributes );
- ram_slots[slot_number].type = psa_get_key_type( attributes );
- ram_slots[slot_number].bits = psa_get_key_bits( attributes );
+ ram_slots[slot_number].lifetime = psa_get_key_lifetime(attributes);
+ ram_slots[slot_number].type = psa_get_key_type(attributes);
+ ram_slots[slot_number].bits = psa_get_key_bits(attributes);
- if( required_storage > sizeof( ram_slots[slot_number].content ) )
- {
- memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) );
- return( PSA_ERROR_INSUFFICIENT_STORAGE );
+ if (required_storage > sizeof(ram_slots[slot_number].content)) {
+ memset(&ram_slots[slot_number], 0, sizeof(ram_slots[slot_number]));
+ return PSA_ERROR_INSUFFICIENT_STORAGE;
}
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
/* This function does everything except actually generating key material.
* After calling it, you must copy the desired key material to
* ram_slots[slot_number].content. */
-static psa_status_t ram_fake_generate( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- const psa_key_attributes_t *attributes,
- uint8_t *pubkey,
- size_t pubkey_size,
- size_t *pubkey_length )
+static psa_status_t ram_fake_generate(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ const psa_key_attributes_t *attributes,
+ uint8_t *pubkey,
+ size_t pubkey_size,
+ size_t *pubkey_length)
{
psa_status_t status;
size_t required_storage =
- PSA_EXPORT_KEY_OUTPUT_SIZE( psa_get_key_type( attributes ),
- psa_get_key_bits( attributes ) );
+ PSA_EXPORT_KEY_OUTPUT_SIZE(psa_get_key_type(attributes),
+ psa_get_key_bits(attributes));
- DRIVER_ASSERT_RETURN( *pubkey_length == 0 );
- if( ! PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
- {
- DRIVER_ASSERT_RETURN( pubkey == NULL );
- DRIVER_ASSERT_RETURN( pubkey_size == 0 );
+ DRIVER_ASSERT_RETURN(*pubkey_length == 0);
+ if (!PSA_KEY_TYPE_IS_KEY_PAIR(psa_get_key_type(attributes))) {
+ DRIVER_ASSERT_RETURN(pubkey == NULL);
+ DRIVER_ASSERT_RETURN(pubkey_size == 0);
}
- status = ram_create_common( context, slot_number, attributes,
- required_storage );
- return( status );
+ status = ram_create_common(context, slot_number, attributes,
+ required_storage);
+ return status;
}
-static psa_status_t ram_import( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- const psa_key_attributes_t *attributes,
- const uint8_t *data,
- size_t data_length,
- size_t *bits )
+static psa_status_t ram_import(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ const psa_key_attributes_t *attributes,
+ const uint8_t *data,
+ size_t data_length,
+ size_t *bits)
{
- psa_key_type_t type = psa_get_key_type( attributes );
- psa_status_t status = ram_create_common( context, slot_number, attributes,
- data_length );
- if( status != PSA_SUCCESS )
- return( status );
+ psa_key_type_t type = psa_get_key_type(attributes);
+ psa_status_t status = ram_create_common(context, slot_number, attributes,
+ data_length);
+ if (status != PSA_SUCCESS) {
+ return status;
+ }
/* The RAM driver only works for certain key types: raw keys,
* and ECC key pairs. This is true in particular of the bit-size
* calculation here. */
- if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
- *bits = PSA_BYTES_TO_BITS( data_length );
- else if ( PSA_KEY_TYPE_IS_ECC_KEY_PAIR( type ) )
- {
- *bits = ecc_curve_bits( PSA_KEY_TYPE_ECC_GET_FAMILY( type ), data_length );
- if( *bits == 0 )
- return( PSA_ERROR_DETECTED_BY_DRIVER );
- }
- else
- {
- memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) );
- return( PSA_ERROR_NOT_SUPPORTED );
+ if (PSA_KEY_TYPE_IS_UNSTRUCTURED(type)) {
+ *bits = PSA_BYTES_TO_BITS(data_length);
+ } else if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) {
+ *bits = ecc_curve_bits(PSA_KEY_TYPE_ECC_GET_FAMILY(type), data_length);
+ if (*bits == 0) {
+ return PSA_ERROR_DETECTED_BY_DRIVER;
+ }
+ } else {
+ memset(&ram_slots[slot_number], 0, sizeof(ram_slots[slot_number]));
+ return PSA_ERROR_NOT_SUPPORTED;
}
ram_slots[slot_number].bits = *bits;
- memcpy( ram_slots[slot_number].content, data, data_length );
+ memcpy(ram_slots[slot_number].content, data, data_length);
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
-static psa_status_t ram_export( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- uint8_t *data,
- size_t data_size,
- size_t *data_length )
+static psa_status_t ram_export(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ uint8_t *data,
+ size_t data_size,
+ size_t *data_length)
{
size_t actual_size;
(void) context;
- DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
- actual_size = PSA_BITS_TO_BYTES( ram_slots[slot_number].bits );
- if( actual_size > data_size )
- return( PSA_ERROR_BUFFER_TOO_SMALL );
+ DRIVER_ASSERT_RETURN(slot_number < ARRAY_LENGTH(ram_slots));
+ actual_size = PSA_BITS_TO_BYTES(ram_slots[slot_number].bits);
+ if (actual_size > data_size) {
+ return PSA_ERROR_BUFFER_TOO_SMALL;
+ }
*data_length = actual_size;
- memcpy( data, ram_slots[slot_number].content, actual_size );
- return( PSA_SUCCESS );
+ memcpy(data, ram_slots[slot_number].content, actual_size);
+ return PSA_SUCCESS;
}
-static psa_status_t ram_export_public( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- uint8_t *data,
- size_t data_size,
- size_t *data_length )
+static psa_status_t ram_export_public(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ uint8_t *data,
+ size_t data_size,
+ size_t *data_length)
{
psa_status_t status;
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
(void) context;
- DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
+ DRIVER_ASSERT_RETURN(slot_number < ARRAY_LENGTH(ram_slots));
DRIVER_ASSERT_RETURN(
- PSA_KEY_TYPE_IS_KEY_PAIR( ram_slots[slot_number].type ) );
+ PSA_KEY_TYPE_IS_KEY_PAIR(ram_slots[slot_number].type));
- psa_set_key_type( &attributes, ram_slots[slot_number].type );
- status = psa_import_key( &attributes,
- ram_slots[slot_number].content,
- PSA_BITS_TO_BYTES( ram_slots[slot_number].bits ),
- &key );
- if( status != PSA_SUCCESS )
- return( status );
- status = psa_export_public_key( key, data, data_size, data_length );
- psa_destroy_key( key );
- return( PSA_SUCCESS );
+ psa_set_key_type(&attributes, ram_slots[slot_number].type);
+ status = psa_import_key(&attributes,
+ ram_slots[slot_number].content,
+ PSA_BITS_TO_BYTES(ram_slots[slot_number].bits),
+ &key);
+ if (status != PSA_SUCCESS) {
+ return status;
+ }
+ status = psa_export_public_key(key, data, data_size, data_length);
+ psa_destroy_key(key);
+ return PSA_SUCCESS;
}
-static psa_status_t ram_destroy( psa_drv_se_context_t *context,
- void *persistent_data,
- psa_key_slot_number_t slot_number )
+static psa_status_t ram_destroy(psa_drv_se_context_t *context,
+ void *persistent_data,
+ psa_key_slot_number_t slot_number)
{
ram_slot_usage_t *slot_usage = persistent_data;
- DRIVER_ASSERT_RETURN( context->persistent_data_size == sizeof( ram_slot_usage_t ) );
- DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
- memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) );
- *slot_usage &= ~(ram_slot_usage_t)( 1 << slot_number );
+ DRIVER_ASSERT_RETURN(context->persistent_data_size == sizeof(ram_slot_usage_t));
+ DRIVER_ASSERT_RETURN(slot_number < ARRAY_LENGTH(ram_slots));
+ memset(&ram_slots[slot_number], 0, sizeof(ram_slots[slot_number]));
+ *slot_usage &= ~(ram_slot_usage_t) (1 << slot_number);
ram_shadow_slot_usage = *slot_usage;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
-static psa_status_t ram_allocate( psa_drv_se_context_t *context,
- void *persistent_data,
- const psa_key_attributes_t *attributes,
- psa_key_creation_method_t method,
- psa_key_slot_number_t *slot_number )
+static psa_status_t ram_allocate(psa_drv_se_context_t *context,
+ void *persistent_data,
+ const psa_key_attributes_t *attributes,
+ psa_key_creation_method_t method,
+ psa_key_slot_number_t *slot_number)
{
ram_slot_usage_t *slot_usage = persistent_data;
(void) attributes;
(void) method;
- DRIVER_ASSERT_RETURN( context->persistent_data_size == sizeof( ram_slot_usage_t ) );
- for( *slot_number = ram_min_slot;
- *slot_number < ARRAY_LENGTH( ram_slots );
- ++( *slot_number ) )
- {
- if( ! ( *slot_usage & 1 << *slot_number ) )
- {
+ DRIVER_ASSERT_RETURN(context->persistent_data_size == sizeof(ram_slot_usage_t));
+ for (*slot_number = ram_min_slot;
+ *slot_number < ARRAY_LENGTH(ram_slots);
+ ++(*slot_number)) {
+ if (!(*slot_usage & 1 << *slot_number)) {
ram_shadow_slot_usage = *slot_usage;
- return( PSA_SUCCESS );
+ return PSA_SUCCESS;
}
}
- return( PSA_ERROR_INSUFFICIENT_STORAGE );
+ return PSA_ERROR_INSUFFICIENT_STORAGE;
}
static psa_status_t ram_validate_slot_number(
@@ -432,25 +429,26 @@
void *persistent_data,
const psa_key_attributes_t *attributes,
psa_key_creation_method_t method,
- psa_key_slot_number_t slot_number )
+ psa_key_slot_number_t slot_number)
{
(void) context;
(void) persistent_data;
(void) attributes;
(void) method;
- if( slot_number >= ARRAY_LENGTH( ram_slots ) )
- return( PSA_ERROR_INVALID_ARGUMENT );
- return( PSA_SUCCESS );
+ if (slot_number >= ARRAY_LENGTH(ram_slots)) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
+ return PSA_SUCCESS;
}
-static psa_status_t ram_sign( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- psa_algorithm_t alg,
- const uint8_t *hash,
- size_t hash_length,
- uint8_t *signature,
- size_t signature_size,
- size_t *signature_length )
+static psa_status_t ram_sign(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ psa_algorithm_t alg,
+ const uint8_t *hash,
+ size_t hash_length,
+ uint8_t *signature,
+ size_t signature_size,
+ size_t *signature_length)
{
ram_slot_t *slot;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -458,32 +456,32 @@
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
(void) context;
- DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
+ DRIVER_ASSERT_RETURN(slot_number < ARRAY_LENGTH(ram_slots));
slot = &ram_slots[slot_number];
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, slot->type );
- DRIVER_ASSERT( psa_import_key( &attributes,
- slot->content,
- PSA_BITS_TO_BYTES( slot->bits ),
- &key ) == PSA_SUCCESS );
- status = psa_sign_hash( key, alg,
- hash, hash_length,
- signature, signature_size, signature_length );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, slot->type);
+ DRIVER_ASSERT(psa_import_key(&attributes,
+ slot->content,
+ PSA_BITS_TO_BYTES(slot->bits),
+ &key) == PSA_SUCCESS);
+ status = psa_sign_hash(key, alg,
+ hash, hash_length,
+ signature, signature_size, signature_length);
exit:
- psa_destroy_key( key );
- return( status );
+ psa_destroy_key(key);
+ return status;
}
-static psa_status_t ram_verify( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- psa_algorithm_t alg,
- const uint8_t *hash,
- size_t hash_length,
- const uint8_t *signature,
- size_t signature_length )
+static psa_status_t ram_verify(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ psa_algorithm_t alg,
+ const uint8_t *hash,
+ size_t hash_length,
+ const uint8_t *signature,
+ size_t signature_length)
{
ram_slot_t *slot;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -491,24 +489,24 @@
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
(void) context;
- DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
+ DRIVER_ASSERT_RETURN(slot_number < ARRAY_LENGTH(ram_slots));
slot = &ram_slots[slot_number];
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, slot->type );
- DRIVER_ASSERT( psa_import_key( &attributes,
- slot->content,
- PSA_BITS_TO_BYTES( slot->bits ),
- &key ) ==
- PSA_SUCCESS );
- status = psa_verify_hash( key, alg,
- hash, hash_length,
- signature, signature_length );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, slot->type);
+ DRIVER_ASSERT(psa_import_key(&attributes,
+ slot->content,
+ PSA_BITS_TO_BYTES(slot->bits),
+ &key) ==
+ PSA_SUCCESS);
+ status = psa_verify_hash(key, alg,
+ hash, hash_length,
+ signature, signature_length);
exit:
- psa_destroy_key( key );
- return( status );
+ psa_destroy_key(key);
+ return status;
}
@@ -516,8 +514,7 @@
/* Other test helper functions */
/****************************************************************/
-typedef enum
-{
+typedef enum {
SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION,
SIGN_IN_DRIVER_AND_PARALLEL_CREATION,
SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC,
@@ -527,54 +524,49 @@
* are consistent with the attributes used when creating the key. */
static int check_key_attributes(
mbedtls_svc_key_id_t key,
- const psa_key_attributes_t *reference_attributes )
+ const psa_key_attributes_t *reference_attributes)
{
int ok = 0;
psa_key_attributes_t actual_attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_ASSERT( psa_get_key_attributes( key, &actual_attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(key, &actual_attributes));
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &actual_attributes ),
- psa_get_key_id( reference_attributes ) ) );
- TEST_EQUAL( psa_get_key_lifetime( &actual_attributes ),
- psa_get_key_lifetime( reference_attributes ) );
- TEST_EQUAL( psa_get_key_type( &actual_attributes ),
- psa_get_key_type( reference_attributes ) );
- TEST_EQUAL( psa_get_key_usage_flags( &actual_attributes ),
- psa_get_key_usage_flags( reference_attributes ) );
- TEST_EQUAL( psa_get_key_algorithm( &actual_attributes ),
- psa_get_key_algorithm( reference_attributes ) );
- TEST_EQUAL( psa_get_key_enrollment_algorithm( &actual_attributes ),
- psa_get_key_enrollment_algorithm( reference_attributes ) );
- if( psa_get_key_bits( reference_attributes ) != 0 )
- {
- TEST_EQUAL( psa_get_key_bits( &actual_attributes ),
- psa_get_key_bits( reference_attributes ) );
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&actual_attributes),
+ psa_get_key_id(reference_attributes)));
+ TEST_EQUAL(psa_get_key_lifetime(&actual_attributes),
+ psa_get_key_lifetime(reference_attributes));
+ TEST_EQUAL(psa_get_key_type(&actual_attributes),
+ psa_get_key_type(reference_attributes));
+ TEST_EQUAL(psa_get_key_usage_flags(&actual_attributes),
+ psa_get_key_usage_flags(reference_attributes));
+ TEST_EQUAL(psa_get_key_algorithm(&actual_attributes),
+ psa_get_key_algorithm(reference_attributes));
+ TEST_EQUAL(psa_get_key_enrollment_algorithm(&actual_attributes),
+ psa_get_key_enrollment_algorithm(reference_attributes));
+ if (psa_get_key_bits(reference_attributes) != 0) {
+ TEST_EQUAL(psa_get_key_bits(&actual_attributes),
+ psa_get_key_bits(reference_attributes));
}
{
psa_key_slot_number_t actual_slot_number = 0xdeadbeef;
psa_key_slot_number_t desired_slot_number = 0xb90cc011;
psa_key_lifetime_t lifetime =
- psa_get_key_lifetime( &actual_attributes );
- psa_status_t status = psa_get_key_slot_number( &actual_attributes,
- &actual_slot_number );
- if( PSA_KEY_LIFETIME_GET_LOCATION( lifetime ) < MIN_DRIVER_LOCATION )
- {
+ psa_get_key_lifetime(&actual_attributes);
+ psa_status_t status = psa_get_key_slot_number(&actual_attributes,
+ &actual_slot_number);
+ if (PSA_KEY_LIFETIME_GET_LOCATION(lifetime) < MIN_DRIVER_LOCATION) {
/* The key is not in a secure element. */
- TEST_EQUAL( status, PSA_ERROR_INVALID_ARGUMENT );
- }
- else
- {
+ TEST_EQUAL(status, PSA_ERROR_INVALID_ARGUMENT);
+ } else {
/* The key is in a secure element. If it had been created
* in a specific slot, check that it is reported there. */
- PSA_ASSERT( status );
- status = psa_get_key_slot_number( reference_attributes,
- &desired_slot_number );
- if( status == PSA_SUCCESS )
- {
- TEST_EQUAL( desired_slot_number, actual_slot_number );
+ PSA_ASSERT(status);
+ status = psa_get_key_slot_number(reference_attributes,
+ &desired_slot_number);
+ if (status == PSA_SUCCESS) {
+ TEST_EQUAL(desired_slot_number, actual_slot_number);
}
}
}
@@ -585,65 +577,65 @@
* Actual key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &actual_attributes );
+ psa_reset_key_attributes(&actual_attributes);
- return( ok );
+ return ok;
}
/* Get the file UID corresponding to the specified location.
* If this changes, the storage format version must change.
* See psa_get_se_driver_its_file_uid() in psa_crypto_se.c.
*/
-psa_storage_uid_t file_uid_for_location( psa_key_location_t location )
+psa_storage_uid_t file_uid_for_location(psa_key_location_t location)
{
- if( location > PSA_MAX_SE_LOCATION )
- return( 0 );
- return( 0xfffffe00 + location );
+ if (location > PSA_MAX_SE_LOCATION) {
+ return 0;
+ }
+ return 0xfffffe00 + location;
}
/* Check that the persistent data of a driver has its expected content. */
-static int check_persistent_data( psa_key_location_t location,
- const void *expected_data,
- size_t size )
+static int check_persistent_data(psa_key_location_t location,
+ const void *expected_data,
+ size_t size)
{
- psa_storage_uid_t uid = file_uid_for_location( location );
+ psa_storage_uid_t uid = file_uid_for_location(location);
struct psa_storage_info_t info;
uint8_t *loaded = NULL;
int ok = 0;
- PSA_ASSERT( psa_its_get_info( uid, &info ) );
- ASSERT_ALLOC( loaded, info.size );
- PSA_ASSERT( psa_its_get( uid, 0, info.size, loaded, NULL ) );
- ASSERT_COMPARE( expected_data, size, loaded, info.size );
+ PSA_ASSERT(psa_its_get_info(uid, &info));
+ ASSERT_ALLOC(loaded, info.size);
+ PSA_ASSERT(psa_its_get(uid, 0, info.size, loaded, NULL));
+ ASSERT_COMPARE(expected_data, size, loaded, info.size);
ok = 1;
exit:
- mbedtls_free( loaded );
- return( ok );
+ mbedtls_free(loaded);
+ return ok;
}
/* Check that no persistent data exists for the given location. */
-static int check_no_persistent_data( psa_key_location_t location )
+static int check_no_persistent_data(psa_key_location_t location)
{
- psa_storage_uid_t uid = file_uid_for_location( location );
+ psa_storage_uid_t uid = file_uid_for_location(location);
struct psa_storage_info_t info;
int ok = 0;
- TEST_EQUAL( psa_its_get_info( uid, &info ), PSA_ERROR_DOES_NOT_EXIST );
+ TEST_EQUAL(psa_its_get_info(uid, &info), PSA_ERROR_DOES_NOT_EXIST);
ok = 1;
exit:
- return( ok );
+ return ok;
}
/* Check that a function's return status is "smoke-free", i.e. that
* it's an acceptable error code when calling an API function that operates
* on a key with potentially bogus parameters. */
#if defined(AT_LEAST_ONE_BUILTIN_KDF)
-static int is_status_smoke_free( psa_status_t status )
+static int is_status_smoke_free(psa_status_t status)
{
- switch( status )
- {
+ switch (status) {
case PSA_SUCCESS:
case PSA_ERROR_NOT_SUPPORTED:
case PSA_ERROR_NOT_PERMITTED:
@@ -651,22 +643,22 @@
case PSA_ERROR_INVALID_ARGUMENT:
case PSA_ERROR_INVALID_SIGNATURE:
case PSA_ERROR_INVALID_PADDING:
- return( 1 );
+ return 1;
default:
- return( 0 );
+ return 0;
}
}
#endif /* AT_LEAST_ONE_BUILTIN_KDF */
-#define SMOKE_ASSERT( expr ) \
- TEST_ASSERT( is_status_smoke_free( expr ) )
+#define SMOKE_ASSERT(expr) \
+ TEST_ASSERT(is_status_smoke_free(expr))
/* Smoke test a key. There are mostly no wrong answers here since we pass
* mostly bogus parameters: the goal is to ensure that there is no memory
* corruption or crash. This test function is most useful when run under
* an environment with sanity checks such as ASan or MSan. */
#if defined(AT_LEAST_ONE_BUILTIN_KDF)
-static int smoke_test_key( mbedtls_svc_key_id_t key )
+static int smoke_test_key(mbedtls_svc_key_id_t key)
{
int ok = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -678,88 +670,88 @@
size_t length;
mbedtls_svc_key_id_t key2 = MBEDTLS_SVC_KEY_ID_INIT;
- SMOKE_ASSERT( psa_get_key_attributes( key, &attributes ) );
+ SMOKE_ASSERT(psa_get_key_attributes(key, &attributes));
- SMOKE_ASSERT( psa_export_key( key,
- buffer, sizeof( buffer ), &length ) );
- SMOKE_ASSERT( psa_export_public_key( key,
- buffer, sizeof( buffer ), &length ) );
+ SMOKE_ASSERT(psa_export_key(key,
+ buffer, sizeof(buffer), &length));
+ SMOKE_ASSERT(psa_export_public_key(key,
+ buffer, sizeof(buffer), &length));
- SMOKE_ASSERT( psa_copy_key( key, &attributes, &key2 ) );
- if( ! mbedtls_svc_key_id_is_null( key2 ) )
- PSA_ASSERT( psa_destroy_key( key2 ) );
+ SMOKE_ASSERT(psa_copy_key(key, &attributes, &key2));
+ if (!mbedtls_svc_key_id_is_null(key2)) {
+ PSA_ASSERT(psa_destroy_key(key2));
+ }
- SMOKE_ASSERT( psa_mac_sign_setup( &mac_operation, key, PSA_ALG_CMAC ) );
- PSA_ASSERT( psa_mac_abort( &mac_operation ) );
- SMOKE_ASSERT( psa_mac_verify_setup( &mac_operation, key,
- PSA_ALG_HMAC( PSA_ALG_SHA_256 ) ) );
- PSA_ASSERT( psa_mac_abort( &mac_operation ) );
+ SMOKE_ASSERT(psa_mac_sign_setup(&mac_operation, key, PSA_ALG_CMAC));
+ PSA_ASSERT(psa_mac_abort(&mac_operation));
+ SMOKE_ASSERT(psa_mac_verify_setup(&mac_operation, key,
+ PSA_ALG_HMAC(PSA_ALG_SHA_256)));
+ PSA_ASSERT(psa_mac_abort(&mac_operation));
- SMOKE_ASSERT( psa_cipher_encrypt_setup( &cipher_operation, key,
- PSA_ALG_CTR ) );
- PSA_ASSERT( psa_cipher_abort( &cipher_operation ) );
- SMOKE_ASSERT( psa_cipher_decrypt_setup( &cipher_operation, key,
- PSA_ALG_CTR ) );
- PSA_ASSERT( psa_cipher_abort( &cipher_operation ) );
+ SMOKE_ASSERT(psa_cipher_encrypt_setup(&cipher_operation, key,
+ PSA_ALG_CTR));
+ PSA_ASSERT(psa_cipher_abort(&cipher_operation));
+ SMOKE_ASSERT(psa_cipher_decrypt_setup(&cipher_operation, key,
+ PSA_ALG_CTR));
+ PSA_ASSERT(psa_cipher_abort(&cipher_operation));
- SMOKE_ASSERT( psa_aead_encrypt( key, PSA_ALG_CCM,
- buffer, sizeof( buffer ),
- NULL, 0,
- buffer, sizeof( buffer),
- buffer, sizeof( buffer), &length ) );
- SMOKE_ASSERT( psa_aead_decrypt( key, PSA_ALG_CCM,
- buffer, sizeof( buffer ),
- NULL, 0,
- buffer, sizeof( buffer),
- buffer, sizeof( buffer), &length ) );
+ SMOKE_ASSERT(psa_aead_encrypt(key, PSA_ALG_CCM,
+ buffer, sizeof(buffer),
+ NULL, 0,
+ buffer, sizeof(buffer),
+ buffer, sizeof(buffer), &length));
+ SMOKE_ASSERT(psa_aead_decrypt(key, PSA_ALG_CCM,
+ buffer, sizeof(buffer),
+ NULL, 0,
+ buffer, sizeof(buffer),
+ buffer, sizeof(buffer), &length));
- SMOKE_ASSERT( psa_sign_hash( key, PSA_ALG_ECDSA_ANY,
+ SMOKE_ASSERT(psa_sign_hash(key, PSA_ALG_ECDSA_ANY,
+ buffer, 32,
+ buffer, sizeof(buffer), &length));
+ SMOKE_ASSERT(psa_verify_hash(key, PSA_ALG_ECDSA_ANY,
buffer, 32,
- buffer, sizeof( buffer ), &length ) );
- SMOKE_ASSERT( psa_verify_hash( key, PSA_ALG_ECDSA_ANY,
- buffer, 32,
- buffer, sizeof( buffer ) ) );
+ buffer, sizeof(buffer)));
- SMOKE_ASSERT( psa_asymmetric_encrypt( key, PSA_ALG_RSA_PKCS1V15_CRYPT,
- buffer, 10, NULL, 0,
- buffer, sizeof( buffer ), &length ) );
- SMOKE_ASSERT( psa_asymmetric_decrypt( key, PSA_ALG_RSA_PKCS1V15_CRYPT,
- buffer, sizeof( buffer ), NULL, 0,
- buffer, sizeof( buffer ), &length ) );
+ SMOKE_ASSERT(psa_asymmetric_encrypt(key, PSA_ALG_RSA_PKCS1V15_CRYPT,
+ buffer, 10, NULL, 0,
+ buffer, sizeof(buffer), &length));
+ SMOKE_ASSERT(psa_asymmetric_decrypt(key, PSA_ALG_RSA_PKCS1V15_CRYPT,
+ buffer, sizeof(buffer), NULL, 0,
+ buffer, sizeof(buffer), &length));
#if defined(MBEDTLS_SHA256_C)
/* Try the key in a plain key derivation. */
- PSA_ASSERT( psa_key_derivation_setup( &derivation_operation,
- PSA_ALG_HKDF( PSA_ALG_SHA_256 ) ) );
- PSA_ASSERT( psa_key_derivation_input_bytes( &derivation_operation,
- PSA_KEY_DERIVATION_INPUT_SALT,
- NULL, 0 ) );
- SMOKE_ASSERT( psa_key_derivation_input_key( &derivation_operation,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- key ) );
- PSA_ASSERT( psa_key_derivation_abort( &derivation_operation ) );
+ PSA_ASSERT(psa_key_derivation_setup(&derivation_operation,
+ PSA_ALG_HKDF(PSA_ALG_SHA_256)));
+ PSA_ASSERT(psa_key_derivation_input_bytes(&derivation_operation,
+ PSA_KEY_DERIVATION_INPUT_SALT,
+ NULL, 0));
+ SMOKE_ASSERT(psa_key_derivation_input_key(&derivation_operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET,
+ key));
+ PSA_ASSERT(psa_key_derivation_abort(&derivation_operation));
/* If the key is asymmetric, try it in a key agreement, both as
* part of a derivation operation and standalone. */
- if( psa_export_public_key( key, buffer, sizeof( buffer ), &length ) ==
- PSA_SUCCESS )
- {
+ if (psa_export_public_key(key, buffer, sizeof(buffer), &length) ==
+ PSA_SUCCESS) {
psa_algorithm_t alg =
- PSA_ALG_KEY_AGREEMENT( PSA_ALG_ECDH,
- PSA_ALG_HKDF( PSA_ALG_SHA_256 ) );
- PSA_ASSERT( psa_key_derivation_setup( &derivation_operation, alg ) );
- PSA_ASSERT( psa_key_derivation_input_bytes(
- &derivation_operation, PSA_KEY_DERIVATION_INPUT_SALT,
- NULL, 0 ) );
- SMOKE_ASSERT( psa_key_derivation_key_agreement(
- &derivation_operation,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- key, buffer, length ) );
- PSA_ASSERT( psa_key_derivation_abort( &derivation_operation ) );
+ PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH,
+ PSA_ALG_HKDF(PSA_ALG_SHA_256));
+ PSA_ASSERT(psa_key_derivation_setup(&derivation_operation, alg));
+ PSA_ASSERT(psa_key_derivation_input_bytes(
+ &derivation_operation, PSA_KEY_DERIVATION_INPUT_SALT,
+ NULL, 0));
+ SMOKE_ASSERT(psa_key_derivation_key_agreement(
+ &derivation_operation,
+ PSA_KEY_DERIVATION_INPUT_SECRET,
+ key, buffer, length));
+ PSA_ASSERT(psa_key_derivation_abort(&derivation_operation));
- SMOKE_ASSERT( psa_raw_key_agreement(
- alg, key, buffer, length,
- buffer, sizeof( buffer ), &length ) );
+ SMOKE_ASSERT(psa_raw_key_agreement(
+ alg, key, buffer, length,
+ buffer, sizeof(buffer), &length));
}
#endif /* MBEDTLS_SHA256_C */
@@ -770,23 +762,24 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- return( ok );
+ return ok;
}
#endif /* AT_LEAST_ONE_BUILTIN_KDF */
-static void psa_purge_storage( void )
+static void psa_purge_storage(void)
{
/* The generic code in mbedtls_test_psa_purge_key_storage()
* (which is called by PSA_DONE()) doesn't take care of things that are
* specific to dynamic secure elements. */
psa_key_location_t location;
/* Purge the transaction file. */
- psa_crypto_stop_transaction( );
+ psa_crypto_stop_transaction();
/* Purge driver persistent data. */
- for( location = 0; location < PSA_MAX_SE_LOCATION; location++ )
- psa_destroy_se_persistent_data( location );
+ for (location = 0; location < PSA_MAX_SE_LOCATION; location++) {
+ psa_destroy_se_persistent_data(location);
+ }
}
/* END_HEADER */
@@ -797,205 +790,207 @@
*/
/* BEGIN_CASE */
-void register_one( int location, int version, int expected_status_arg )
+void register_one(int location, int version, int expected_status_arg)
{
psa_status_t expected_status = expected_status_arg;
psa_drv_se_t driver;
- memset( &driver, 0, sizeof( driver ) );
+ memset(&driver, 0, sizeof(driver));
driver.hal_version = version;
- TEST_EQUAL( psa_register_se_driver( location, &driver ),
- expected_status );
+ TEST_EQUAL(psa_register_se_driver(location, &driver),
+ expected_status);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void register_twice( int count )
+void register_twice(int count)
{
psa_drv_se_t driver;
psa_key_location_t location;
psa_key_location_t max = MIN_DRIVER_LOCATION + count;
- memset( &driver, 0, sizeof( driver ) );
+ memset(&driver, 0, sizeof(driver));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
- for( location = MIN_DRIVER_LOCATION; location < max; location++ )
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- for( location = MIN_DRIVER_LOCATION; location < max; location++ )
- TEST_EQUAL( psa_register_se_driver( location, &driver ),
- PSA_ERROR_ALREADY_EXISTS );
+ for (location = MIN_DRIVER_LOCATION; location < max; location++) {
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ }
+ for (location = MIN_DRIVER_LOCATION; location < max; location++) {
+ TEST_EQUAL(psa_register_se_driver(location, &driver),
+ PSA_ERROR_ALREADY_EXISTS);
+ }
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void register_max( )
+void register_max()
{
psa_drv_se_t driver;
psa_key_location_t location;
psa_key_location_t max = MIN_DRIVER_LOCATION + PSA_MAX_SE_DRIVERS;
- memset( &driver, 0, sizeof( driver ) );
+ memset(&driver, 0, sizeof(driver));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
- for( location = MIN_DRIVER_LOCATION; location < max; location++ )
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
+ for (location = MIN_DRIVER_LOCATION; location < max; location++) {
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ }
- TEST_EQUAL( psa_register_se_driver( location, &driver ),
- PSA_ERROR_INSUFFICIENT_MEMORY );
+ TEST_EQUAL(psa_register_se_driver(location, &driver),
+ PSA_ERROR_INSUFFICIENT_MEMORY);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_creation_import_export( int lifetime_arg, int min_slot, int restart )
+void key_creation_import_export(int lifetime_arg, int min_slot, int restart)
{
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = (psa_key_lifetime_t) lifetime_arg;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_handle_t handle;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
- uint8_t exported[sizeof( key_material )];
+ const uint8_t key_material[3] = { 0xfa, 0xca, 0xde };
+ uint8_t exported[sizeof(key_material)];
size_t exported_length;
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
- driver.persistent_data_size = sizeof( ram_slot_usage_t );
+ driver.persistent_data_size = sizeof(ram_slot_usage_t);
key_management.p_allocate = ram_allocate;
key_management.p_import = ram_import;
key_management.p_destroy = ram_destroy;
key_management.p_export = ram_export;
ram_min_slot = min_slot;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
/* Create a key. */
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- PSA_ASSERT( psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id ) );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id));
- if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) )
- {
+ if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) {
/* For volatile keys, check no persistent data was created */
- if( ! check_no_persistent_data( location ) )
+ if (!check_no_persistent_data(location)) {
goto exit;
- }
- else
- {
+ }
+ } else {
/* For persistent keys, check persistent data */
- if( ! check_persistent_data( location,
- &ram_shadow_slot_usage,
- sizeof( ram_shadow_slot_usage ) ) )
+ if (!check_persistent_data(location,
+ &ram_shadow_slot_usage,
+ sizeof(ram_shadow_slot_usage))) {
goto exit;
+ }
}
/* Test that the key was created in the expected slot. */
- TEST_EQUAL( ram_slots[min_slot].type, PSA_KEY_TYPE_RAW_DATA );
+ TEST_EQUAL(ram_slots[min_slot].type, PSA_KEY_TYPE_RAW_DATA);
/* Maybe restart, to check that the information is saved correctly. */
- if( restart )
- {
- mbedtls_psa_crypto_free( );
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ if (restart) {
+ mbedtls_psa_crypto_free();
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) )
- {
+ if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) {
/* Check that the PSA core has no knowledge of the volatile key */
- TEST_ASSERT( psa_open_key( returned_id, &handle ) ==
- PSA_ERROR_DOES_NOT_EXIST );
+ TEST_ASSERT(psa_open_key(returned_id, &handle) ==
+ PSA_ERROR_DOES_NOT_EXIST);
/* Drop data from our mockup driver */
ram_slots_reset();
ram_min_slot = min_slot;
/* Re-import key */
- PSA_ASSERT( psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id ) );
- }
- else
- {
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id));
+ } else {
/* Check the persistent key file */
- if( ! check_persistent_data( location,
- &ram_shadow_slot_usage,
- sizeof( ram_shadow_slot_usage ) ) )
+ if (!check_persistent_data(location,
+ &ram_shadow_slot_usage,
+ sizeof(ram_shadow_slot_usage))) {
goto exit;
+ }
}
}
/* Test that the key was created in the expected slot. */
- TEST_EQUAL( ram_slots[min_slot].type, PSA_KEY_TYPE_RAW_DATA );
+ TEST_EQUAL(ram_slots[min_slot].type, PSA_KEY_TYPE_RAW_DATA);
/* Test the key attributes, including the reported slot number. */
- psa_set_key_bits( &attributes,
- PSA_BYTES_TO_BITS( sizeof( key_material ) ) );
- psa_set_key_slot_number( &attributes, min_slot );
+ psa_set_key_bits(&attributes,
+ PSA_BYTES_TO_BITS(sizeof(key_material)));
+ psa_set_key_slot_number(&attributes, min_slot);
- if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) )
+ if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) {
attributes.core.id = returned_id;
- else
- psa_set_key_id( &attributes, returned_id );
+ } else {
+ psa_set_key_id(&attributes, returned_id);
+ }
- if( ! check_key_attributes( returned_id, &attributes ) )
+ if (!check_key_attributes(returned_id, &attributes)) {
goto exit;
+ }
/* Test the key data. */
- PSA_ASSERT( psa_export_key( returned_id,
- exported, sizeof( exported ),
- &exported_length ) );
- ASSERT_COMPARE( key_material, sizeof( key_material ),
- exported, exported_length );
+ PSA_ASSERT(psa_export_key(returned_id,
+ exported, sizeof(exported),
+ &exported_length));
+ ASSERT_COMPARE(key_material, sizeof(key_material),
+ exported, exported_length);
- PSA_ASSERT( psa_destroy_key( returned_id ) );
- if( ! check_persistent_data( location,
- &ram_shadow_slot_usage,
- sizeof( ram_shadow_slot_usage ) ) )
+ PSA_ASSERT(psa_destroy_key(returned_id));
+ if (!check_persistent_data(location,
+ &ram_shadow_slot_usage,
+ sizeof(ram_shadow_slot_usage))) {
goto exit;
- TEST_EQUAL( psa_open_key( returned_id, &handle ),
- PSA_ERROR_DOES_NOT_EXIST );
+ }
+ TEST_EQUAL(psa_open_key(returned_id, &handle),
+ PSA_ERROR_DOES_NOT_EXIST);
/* Test that the key has been erased from the designated slot. */
- TEST_EQUAL( ram_slots[min_slot].type, 0 );
+ TEST_EQUAL(ram_slots[min_slot].type, 0);
exit:
- PSA_DONE( );
- ram_slots_reset( );
- psa_purge_storage( );
+ PSA_DONE();
+ ram_slots_reset();
+ psa_purge_storage();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_creation_in_chosen_slot( int slot_arg,
- int restart,
- int expected_status_arg )
+void key_creation_in_chosen_slot(int slot_arg,
+ int restart,
+ int expected_status_arg)
{
psa_key_slot_number_t wanted_slot = slot_arg;
psa_status_t expected_status = expected_status_arg;
@@ -1003,200 +998,208 @@
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_handle_t handle;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
+ const uint8_t key_material[3] = { 0xfa, 0xca, 0xde };
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
- driver.persistent_data_size = sizeof( ram_slot_usage_t );
+ driver.persistent_data_size = sizeof(ram_slot_usage_t);
key_management.p_validate_slot_number = ram_validate_slot_number;
key_management.p_import = ram_import;
key_management.p_destroy = ram_destroy;
key_management.p_export = ram_export;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
/* Create a key. */
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- psa_set_key_slot_number( &attributes, wanted_slot );
- status = psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id );
- TEST_EQUAL( status, expected_status );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ psa_set_key_slot_number(&attributes, wanted_slot);
+ status = psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id);
+ TEST_EQUAL(status, expected_status);
- if( status != PSA_SUCCESS )
+ if (status != PSA_SUCCESS) {
goto exit;
- if( ! check_persistent_data( location,
- &ram_shadow_slot_usage,
- sizeof( ram_shadow_slot_usage ) ) )
+ }
+ if (!check_persistent_data(location,
+ &ram_shadow_slot_usage,
+ sizeof(ram_shadow_slot_usage))) {
goto exit;
+ }
/* Maybe restart, to check that the information is saved correctly. */
- if( restart )
- {
- mbedtls_psa_crypto_free( );
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
- if( ! check_persistent_data( location,
- &ram_shadow_slot_usage,
- sizeof( ram_shadow_slot_usage ) ) )
+ if (restart) {
+ mbedtls_psa_crypto_free();
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
+ if (!check_persistent_data(location,
+ &ram_shadow_slot_usage,
+ sizeof(ram_shadow_slot_usage))) {
goto exit;
+ }
}
/* Test that the key was created in the expected slot. */
- TEST_EQUAL( ram_slots[wanted_slot].type, PSA_KEY_TYPE_RAW_DATA );
+ TEST_EQUAL(ram_slots[wanted_slot].type, PSA_KEY_TYPE_RAW_DATA);
/* Test that the key is reported with the correct attributes,
* including the expected slot. */
- PSA_ASSERT( psa_get_key_attributes( id, &attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(id, &attributes));
- PSA_ASSERT( psa_destroy_key( id ) );
- if( ! check_persistent_data( location,
- &ram_shadow_slot_usage,
- sizeof( ram_shadow_slot_usage ) ) )
+ PSA_ASSERT(psa_destroy_key(id));
+ if (!check_persistent_data(location,
+ &ram_shadow_slot_usage,
+ sizeof(ram_shadow_slot_usage))) {
goto exit;
- TEST_EQUAL( psa_open_key( id, &handle ), PSA_ERROR_DOES_NOT_EXIST );
+ }
+ TEST_EQUAL(psa_open_key(id, &handle), PSA_ERROR_DOES_NOT_EXIST);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- PSA_DONE( );
- ram_slots_reset( );
- psa_purge_storage( );
+ PSA_DONE();
+ ram_slots_reset();
+ psa_purge_storage();
}
/* END_CASE */
/* BEGIN_CASE depends_on:AT_LEAST_ONE_BUILTIN_KDF */
-void import_key_smoke( int type_arg, int alg_arg,
- data_t *key_material )
+void import_key_smoke(int type_arg, int alg_arg,
+ data_t *key_material)
{
psa_key_type_t type = type_arg;
psa_algorithm_t alg = alg_arg;
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_handle_t handle;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
- driver.persistent_data_size = sizeof( psa_key_slot_number_t );
+ driver.persistent_data_size = sizeof(psa_key_slot_number_t);
key_management.p_allocate = counter_allocate;
key_management.p_import = null_import;
key_management.p_destroy = null_destroy;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
/* Create a key. */
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH |
- PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT |
- PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
- PSA_ASSERT( psa_import_key( &attributes,
- key_material->x, key_material->len,
- &returned_id ) );
- if( ! check_persistent_data( location,
- &shadow_counter, sizeof( shadow_counter ) ) )
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH |
+ PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT |
+ PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_material->x, key_material->len,
+ &returned_id));
+ if (!check_persistent_data(location,
+ &shadow_counter, sizeof(shadow_counter))) {
goto exit;
+ }
/* Do stuff with the key. */
- if( ! smoke_test_key( id ) )
+ if (!smoke_test_key(id)) {
goto exit;
+ }
/* Restart and try again. */
- mbedtls_psa_crypto_free( );
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
- if( ! check_persistent_data( location,
- &shadow_counter, sizeof( shadow_counter ) ) )
+ mbedtls_psa_crypto_free();
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
+ if (!check_persistent_data(location,
+ &shadow_counter, sizeof(shadow_counter))) {
goto exit;
- if( ! smoke_test_key( id ) )
+ }
+ if (!smoke_test_key(id)) {
goto exit;
+ }
/* We're done. */
- PSA_ASSERT( psa_destroy_key( id ) );
- if( ! check_persistent_data( location,
- &shadow_counter, sizeof( shadow_counter ) ) )
+ PSA_ASSERT(psa_destroy_key(id));
+ if (!check_persistent_data(location,
+ &shadow_counter, sizeof(shadow_counter))) {
goto exit;
- TEST_EQUAL( psa_open_key( id, &handle ), PSA_ERROR_DOES_NOT_EXIST );
+ }
+ TEST_EQUAL(psa_open_key(id, &handle), PSA_ERROR_DOES_NOT_EXIST);
exit:
- PSA_DONE( );
- counter_reset( );
- psa_purge_storage( );
+ PSA_DONE();
+ counter_reset();
+ psa_purge_storage();
}
/* END_CASE */
/* BEGIN_CASE */
-void generate_key_not_supported( int type_arg, int bits_arg )
+void generate_key_not_supported(int type_arg, int bits_arg)
{
psa_key_type_t type = type_arg;
size_t bits = bits_arg;
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
- driver.persistent_data_size = sizeof( psa_key_slot_number_t );
+ driver.persistent_data_size = sizeof(psa_key_slot_number_t);
key_management.p_allocate = counter_allocate;
/* No p_generate method */
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
- TEST_EQUAL( psa_generate_key( &attributes, &returned_id ),
- PSA_ERROR_NOT_SUPPORTED );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
+ TEST_EQUAL(psa_generate_key(&attributes, &returned_id),
+ PSA_ERROR_NOT_SUPPORTED);
exit:
- PSA_DONE( );
- counter_reset( );
- psa_purge_storage( );
+ PSA_DONE();
+ counter_reset();
+ psa_purge_storage();
}
/* END_CASE */
/* BEGIN_CASE depends_on:AT_LEAST_ONE_BUILTIN_KDF */
-void generate_key_smoke( int type_arg, int bits_arg, int alg_arg )
+void generate_key_smoke(int type_arg, int bits_arg, int alg_arg)
{
psa_key_type_t type = type_arg;
psa_key_bits_t bits = bits_arg;
@@ -1204,88 +1207,93 @@
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_handle_t handle;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
- driver.persistent_data_size = sizeof( psa_key_slot_number_t );
+ driver.persistent_data_size = sizeof(psa_key_slot_number_t);
key_management.p_allocate = counter_allocate;
key_management.p_generate = null_generate;
key_management.p_destroy = null_destroy;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
/* Create a key. */
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH |
- PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT |
- PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
- PSA_ASSERT( psa_generate_key( &attributes, &returned_id ) );
- if( ! check_persistent_data( location,
- &shadow_counter, sizeof( shadow_counter ) ) )
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH |
+ PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT |
+ PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
+ PSA_ASSERT(psa_generate_key(&attributes, &returned_id));
+ if (!check_persistent_data(location,
+ &shadow_counter, sizeof(shadow_counter))) {
goto exit;
+ }
/* Do stuff with the key. */
- if( ! smoke_test_key( id ) )
+ if (!smoke_test_key(id)) {
goto exit;
+ }
/* Restart and try again. */
- mbedtls_psa_crypto_free( );
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
- if( ! check_persistent_data( location,
- &shadow_counter, sizeof( shadow_counter ) ) )
+ mbedtls_psa_crypto_free();
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
+ if (!check_persistent_data(location,
+ &shadow_counter, sizeof(shadow_counter))) {
goto exit;
- if( ! smoke_test_key( id ) )
+ }
+ if (!smoke_test_key(id)) {
goto exit;
+ }
/* We're done. */
- PSA_ASSERT( psa_destroy_key( id ) );
- if( ! check_persistent_data( location,
- &shadow_counter, sizeof( shadow_counter ) ) )
+ PSA_ASSERT(psa_destroy_key(id));
+ if (!check_persistent_data(location,
+ &shadow_counter, sizeof(shadow_counter))) {
goto exit;
- TEST_EQUAL( psa_open_key( id, &handle ), PSA_ERROR_DOES_NOT_EXIST );
+ }
+ TEST_EQUAL(psa_open_key(id, &handle), PSA_ERROR_DOES_NOT_EXIST);
exit:
- PSA_DONE( );
- counter_reset( );
- psa_purge_storage( );
+ PSA_DONE();
+ counter_reset();
+ psa_purge_storage();
}
/* END_CASE */
/* BEGIN_CASE */
-void sign_verify( int flow,
- int type_arg, int alg_arg,
- int bits_arg, data_t *key_material,
- data_t *input )
+void sign_verify(int flow,
+ int type_arg, int alg_arg,
+ int bits_arg, data_t *key_material,
+ data_t *input)
{
psa_key_type_t type = type_arg;
psa_algorithm_t alg = alg_arg;
size_t bits = bits_arg;
/* Pass bits=0 to import, bits>0 to fake-generate */
- int generating = ( bits != 0 );
+ int generating = (bits != 0);
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_drv_se_asymmetric_t asymmetric;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
mbedtls_svc_key_id_t sw_key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t sw_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -1293,23 +1301,23 @@
uint8_t signature[PSA_SIGNATURE_MAX_SIZE];
size_t signature_length;
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
- memset( &asymmetric, 0, sizeof( asymmetric ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
+ memset(&asymmetric, 0, sizeof(asymmetric));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
driver.asymmetric = &asymmetric;
- driver.persistent_data_size = sizeof( ram_slot_usage_t );
+ driver.persistent_data_size = sizeof(ram_slot_usage_t);
key_management.p_allocate = ram_allocate;
key_management.p_destroy = ram_destroy;
- if( generating )
+ if (generating) {
key_management.p_generate = ram_fake_generate;
- else
+ } else {
key_management.p_import = ram_import;
- switch( flow )
- {
+ }
+ switch (flow) {
case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
break;
case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
@@ -1320,208 +1328,206 @@
key_management.p_export_public = ram_export_public;
break;
default:
- TEST_ASSERT( ! "unsupported flow (should be SIGN_IN_xxx)" );
+ TEST_ASSERT(!"unsupported flow (should be SIGN_IN_xxx)");
break;
}
asymmetric.p_verify = ram_verify;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
/* Prepare to create two keys with the same key material: a transparent
* key, and one that goes through the driver. */
- psa_set_key_usage_flags( &sw_attributes,
- PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &sw_attributes, alg );
- psa_set_key_type( &sw_attributes, type );
+ psa_set_key_usage_flags(&sw_attributes,
+ PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&sw_attributes, alg);
+ psa_set_key_type(&sw_attributes, type);
drv_attributes = sw_attributes;
- psa_set_key_id( &drv_attributes, id );
- psa_set_key_lifetime( &drv_attributes, lifetime );
+ psa_set_key_id(&drv_attributes, id);
+ psa_set_key_lifetime(&drv_attributes, lifetime);
/* Create the key in the driver. */
- if( generating )
- {
- psa_set_key_bits( &drv_attributes, bits );
- PSA_ASSERT( psa_generate_key( &drv_attributes, &returned_id ) );
+ if (generating) {
+ psa_set_key_bits(&drv_attributes, bits);
+ PSA_ASSERT(psa_generate_key(&drv_attributes, &returned_id));
/* Since we called a generate method that does not actually
* generate material, store the desired result of generation in
* the mock secure element storage. */
- PSA_ASSERT( psa_get_key_attributes( id, &drv_attributes ) );
- TEST_EQUAL( key_material->len, PSA_BITS_TO_BYTES( bits ) );
- memcpy( ram_slots[ram_min_slot].content, key_material->x,
- key_material->len );
- }
- else
- {
- PSA_ASSERT( psa_import_key( &drv_attributes,
- key_material->x, key_material->len,
- &returned_id ) );
+ PSA_ASSERT(psa_get_key_attributes(id, &drv_attributes));
+ TEST_EQUAL(key_material->len, PSA_BITS_TO_BYTES(bits));
+ memcpy(ram_slots[ram_min_slot].content, key_material->x,
+ key_material->len);
+ } else {
+ PSA_ASSERT(psa_import_key(&drv_attributes,
+ key_material->x, key_material->len,
+ &returned_id));
}
/* Either import the same key in software, or export the driver's
* public key and import that. */
- switch( flow )
- {
+ switch (flow) {
case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
- PSA_ASSERT( psa_import_key( &sw_attributes,
- key_material->x, key_material->len,
- &sw_key ) );
+ PSA_ASSERT(psa_import_key(&sw_attributes,
+ key_material->x, key_material->len,
+ &sw_key));
break;
case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
{
- uint8_t public_key[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE( PSA_VENDOR_ECC_MAX_CURVE_BITS )];
+ uint8_t public_key[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
+ ];
size_t public_key_length;
- PSA_ASSERT( psa_export_public_key( id,
- public_key, sizeof( public_key ),
- &public_key_length ) );
- psa_set_key_type( &sw_attributes,
- PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( type ) );
- PSA_ASSERT( psa_import_key( &sw_attributes,
- public_key, public_key_length,
- &sw_key ) );
+ PSA_ASSERT(psa_export_public_key(id,
+ public_key, sizeof(public_key),
+ &public_key_length));
+ psa_set_key_type(&sw_attributes,
+ PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type));
+ PSA_ASSERT(psa_import_key(&sw_attributes,
+ public_key, public_key_length,
+ &sw_key));
break;
}
}
/* Sign with the chosen key. */
- switch( flow )
- {
+ switch (flow) {
case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
PSA_ASSERT_VIA_DRIVER(
- psa_sign_hash( id, alg,
- input->x, input->len,
- signature, sizeof( signature ),
- &signature_length ),
- PSA_SUCCESS );
+ psa_sign_hash(id, alg,
+ input->x, input->len,
+ signature, sizeof(signature),
+ &signature_length),
+ PSA_SUCCESS);
break;
case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
- PSA_ASSERT( psa_sign_hash( sw_key, alg,
- input->x, input->len,
- signature, sizeof( signature ),
- &signature_length ) );
+ PSA_ASSERT(psa_sign_hash(sw_key, alg,
+ input->x, input->len,
+ signature, sizeof(signature),
+ &signature_length));
break;
}
/* Verify with both keys. */
- PSA_ASSERT( psa_verify_hash( sw_key, alg,
- input->x, input->len,
- signature, signature_length ) );
+ PSA_ASSERT(psa_verify_hash(sw_key, alg,
+ input->x, input->len,
+ signature, signature_length));
PSA_ASSERT_VIA_DRIVER(
- psa_verify_hash( id, alg,
- input->x, input->len,
- signature, signature_length ),
- PSA_SUCCESS );
+ psa_verify_hash(id, alg,
+ input->x, input->len,
+ signature, signature_length),
+ PSA_SUCCESS);
/* Change the signature and verify again. */
signature[0] ^= 1;
- TEST_EQUAL( psa_verify_hash( sw_key, alg,
- input->x, input->len,
- signature, signature_length ),
- PSA_ERROR_INVALID_SIGNATURE );
+ TEST_EQUAL(psa_verify_hash(sw_key, alg,
+ input->x, input->len,
+ signature, signature_length),
+ PSA_ERROR_INVALID_SIGNATURE);
PSA_ASSERT_VIA_DRIVER(
- psa_verify_hash( id, alg,
- input->x, input->len,
- signature, signature_length ),
- PSA_ERROR_INVALID_SIGNATURE );
+ psa_verify_hash(id, alg,
+ input->x, input->len,
+ signature, signature_length),
+ PSA_ERROR_INVALID_SIGNATURE);
exit:
/*
* Driver key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &drv_attributes );
+ psa_reset_key_attributes(&drv_attributes);
- psa_destroy_key( id );
- psa_destroy_key( sw_key );
- PSA_DONE( );
- ram_slots_reset( );
- psa_purge_storage( );
+ psa_destroy_key(id);
+ psa_destroy_key(sw_key);
+ PSA_DONE();
+ ram_slots_reset();
+ psa_purge_storage();
}
/* END_CASE */
/* BEGIN_CASE */
-void register_key_smoke_test( int lifetime_arg,
- int owner_id_arg,
- int id_arg,
- int validate,
- int expected_status_arg )
+void register_key_smoke_test(int lifetime_arg,
+ int owner_id_arg,
+ int id_arg,
+ int validate,
+ int expected_status_arg)
{
psa_key_lifetime_t lifetime = lifetime_arg;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
psa_status_t expected_status = expected_status_arg;
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( owner_id_arg, id_arg );
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(owner_id_arg, id_arg);
psa_key_handle_t handle;
size_t bit_size = 48;
psa_key_slot_number_t wanted_slot = 0x123456789;
psa_status_t status;
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- memset( &driver, 0, sizeof( driver ) );
+ memset(&driver, 0, sizeof(driver));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&key_management, 0, sizeof(key_management));
driver.key_management = &key_management;
key_management.p_destroy = null_destroy;
- if( validate >= 0 )
- {
+ if (validate >= 0) {
key_management.p_validate_slot_number = validate_slot_number_as_directed;
validate_slot_number_directions.slot_number = wanted_slot;
validate_slot_number_directions.method = PSA_KEY_CREATION_REGISTER;
validate_slot_number_directions.status =
- ( validate > 0 ? PSA_SUCCESS : PSA_ERROR_NOT_PERMITTED );
+ (validate > 0 ? PSA_SUCCESS : PSA_ERROR_NOT_PERMITTED);
}
- mbedtls_test_set_step( 1 );
- PSA_ASSERT( psa_register_se_driver( MIN_DRIVER_LOCATION, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ mbedtls_test_set_step(1);
+ PSA_ASSERT(psa_register_se_driver(MIN_DRIVER_LOCATION, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- psa_set_key_bits( &attributes, bit_size );
- psa_set_key_slot_number( &attributes, wanted_slot );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ psa_set_key_bits(&attributes, bit_size);
+ psa_set_key_slot_number(&attributes, wanted_slot);
- status = mbedtls_psa_register_se_key( &attributes );
- TEST_EQUAL( status, expected_status );
+ status = mbedtls_psa_register_se_key(&attributes);
+ TEST_EQUAL(status, expected_status);
- if( status != PSA_SUCCESS )
+ if (status != PSA_SUCCESS) {
goto exit;
+ }
/* Test that the key exists and has the expected attributes. */
- if( ! check_key_attributes( id, &attributes ) )
+ if (!check_key_attributes(id, &attributes)) {
goto exit;
+ }
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
mbedtls_svc_key_id_t invalid_id =
- mbedtls_svc_key_id_make( owner_id_arg + 1, id_arg );
- TEST_EQUAL( psa_open_key( invalid_id, &handle ), PSA_ERROR_DOES_NOT_EXIST );
+ mbedtls_svc_key_id_make(owner_id_arg + 1, id_arg);
+ TEST_EQUAL(psa_open_key(invalid_id, &handle), PSA_ERROR_DOES_NOT_EXIST);
#endif
- PSA_ASSERT( psa_purge_key( id ) );
+ PSA_ASSERT(psa_purge_key(id));
/* Restart and try again. */
- mbedtls_test_set_step( 2 );
- PSA_SESSION_DONE( );
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
- if( ! check_key_attributes( id, &attributes ) )
+ mbedtls_test_set_step(2);
+ PSA_SESSION_DONE();
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
+ if (!check_key_attributes(id, &attributes)) {
goto exit;
+ }
/* This time, destroy the key. */
- PSA_ASSERT( psa_destroy_key( id ) );
- TEST_EQUAL( psa_open_key( id, &handle ), PSA_ERROR_DOES_NOT_EXIST );
+ PSA_ASSERT(psa_destroy_key(id));
+ TEST_EQUAL(psa_open_key(id, &handle), PSA_ERROR_DOES_NOT_EXIST);
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( id );
- PSA_DONE( );
- psa_purge_storage( );
- memset( &validate_slot_number_directions, 0,
- sizeof( validate_slot_number_directions ) );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(id);
+ PSA_DONE();
+ psa_purge_storage();
+ memset(&validate_slot_number_directions, 0,
+ sizeof(validate_slot_number_directions));
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
index 12c58eb..6f28f93 100644
--- a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
+++ b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
@@ -7,18 +7,16 @@
/** The location and lifetime used for tests that use a single driver. */
#define TEST_DRIVER_LOCATION 1
#define TEST_SE_PERSISTENT_LIFETIME \
- ( PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
- PSA_KEY_PERSISTENCE_DEFAULT, TEST_DRIVER_LOCATION ) )
+ (PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \
+ PSA_KEY_PERSISTENCE_DEFAULT, TEST_DRIVER_LOCATION))
-static struct
-{
+static struct {
uint16_t called;
psa_key_location_t location;
psa_status_t return_value;
} mock_init_data;
-static struct
-{
+static struct {
uint16_t called;
psa_key_slot_number_t key_slot;
psa_key_attributes_t attributes;
@@ -26,8 +24,7 @@
psa_status_t return_value;
} mock_generate_data;
-static struct
-{
+static struct {
uint16_t called;
psa_key_slot_number_t key_slot;
psa_key_attributes_t attributes;
@@ -36,24 +33,21 @@
psa_status_t return_value;
} mock_import_data;
-static struct
-{
+static struct {
uint16_t called;
psa_key_slot_number_t slot_number;
size_t data_size;
psa_status_t return_value;
} mock_export_data;
-static struct
-{
+static struct {
uint16_t called;
psa_key_slot_number_t slot_number;
size_t data_size;
psa_status_t return_value;
} mock_export_public_data;
-static struct
-{
+static struct {
uint16_t called;
psa_key_slot_number_t key_slot;
psa_algorithm_t alg;
@@ -62,8 +56,7 @@
psa_status_t return_value;
} mock_sign_data;
-static struct
-{
+static struct {
uint16_t called;
psa_key_slot_number_t key_slot;
psa_algorithm_t alg;
@@ -72,21 +65,19 @@
psa_status_t return_value;
} mock_verify_data;
-static struct
-{
+static struct {
uint16_t called;
psa_status_t return_value;
} mock_allocate_data;
-static struct
-{
+static struct {
uint16_t called;
psa_key_slot_number_t slot_number;
psa_status_t return_value;
} mock_destroy_data;
#define MAX_KEY_ID_FOR_TEST 10
-static void psa_purge_storage( void )
+static void psa_purge_storage(void)
{
psa_key_id_t id;
psa_key_location_t location;
@@ -94,48 +85,50 @@
/* The tests may have potentially created key ids from 1 to
* MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
* 0, which file-based storage uses as a temporary file. */
- for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
- psa_destroy_persistent_key( mbedtls_svc_key_id_make( 1, id ) );
+ for (id = 0; id <= MAX_KEY_ID_FOR_TEST; id++) {
+ psa_destroy_persistent_key(mbedtls_svc_key_id_make(1, id));
+ }
/* Purge the transaction file. */
- psa_crypto_stop_transaction( );
+ psa_crypto_stop_transaction();
/* Purge driver persistent data. */
- for( location = 0; location < PSA_MAX_SE_LOCATION; location++ )
- psa_destroy_se_persistent_data( location );
+ for (location = 0; location < PSA_MAX_SE_LOCATION; location++) {
+ psa_destroy_se_persistent_data(location);
+ }
}
-static void mock_teardown( void )
+static void mock_teardown(void)
{
- memset( &mock_init_data, 0, sizeof( mock_init_data ) );
- memset( &mock_import_data, 0, sizeof( mock_import_data ) );
- memset( &mock_export_data, 0, sizeof( mock_export_data ) );
- memset( &mock_export_public_data, 0, sizeof( mock_export_public_data ) );
- memset( &mock_sign_data, 0, sizeof( mock_sign_data ) );
- memset( &mock_verify_data, 0, sizeof( mock_verify_data ) );
- memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
- memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
- memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
- psa_purge_storage( );
+ memset(&mock_init_data, 0, sizeof(mock_init_data));
+ memset(&mock_import_data, 0, sizeof(mock_import_data));
+ memset(&mock_export_data, 0, sizeof(mock_export_data));
+ memset(&mock_export_public_data, 0, sizeof(mock_export_public_data));
+ memset(&mock_sign_data, 0, sizeof(mock_sign_data));
+ memset(&mock_verify_data, 0, sizeof(mock_verify_data));
+ memset(&mock_allocate_data, 0, sizeof(mock_allocate_data));
+ memset(&mock_destroy_data, 0, sizeof(mock_destroy_data));
+ memset(&mock_generate_data, 0, sizeof(mock_generate_data));
+ psa_purge_storage();
}
-static psa_status_t mock_init( psa_drv_se_context_t *drv_context,
- void *persistent_data,
- psa_key_location_t location )
+static psa_status_t mock_init(psa_drv_se_context_t *drv_context,
+ void *persistent_data,
+ psa_key_location_t location)
{
(void) drv_context;
(void) persistent_data;
mock_init_data.called++;
mock_init_data.location = location;
- return( mock_init_data.return_value );
+ return mock_init_data.return_value;
}
-static psa_status_t mock_generate( psa_drv_se_context_t *drv_context,
- psa_key_slot_number_t key_slot,
- const psa_key_attributes_t *attributes,
- uint8_t *pubkey,
- size_t pubkey_size,
- size_t *pubkey_length )
+static psa_status_t mock_generate(psa_drv_se_context_t *drv_context,
+ psa_key_slot_number_t key_slot,
+ const psa_key_attributes_t *attributes,
+ uint8_t *pubkey,
+ size_t pubkey_size,
+ size_t *pubkey_length)
{
(void) drv_context;
(void) pubkey;
@@ -146,15 +139,15 @@
mock_generate_data.attributes = *attributes;
mock_generate_data.pubkey_size = pubkey_size;
- return( mock_generate_data.return_value );
+ return mock_generate_data.return_value;
}
-static psa_status_t mock_import( psa_drv_se_context_t *drv_context,
- psa_key_slot_number_t key_slot,
- const psa_key_attributes_t *attributes,
- const uint8_t *data,
- size_t data_length,
- size_t *bits )
+static psa_status_t mock_import(psa_drv_se_context_t *drv_context,
+ psa_key_slot_number_t key_slot,
+ const psa_key_attributes_t *attributes,
+ const uint8_t *data,
+ size_t data_length,
+ size_t *bits)
{
(void) drv_context;
(void) data;
@@ -166,14 +159,14 @@
mock_import_data.attributes = *attributes;
mock_import_data.data_length = data_length;
- return( mock_import_data.return_value );
+ return mock_import_data.return_value;
}
-psa_status_t mock_export( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- uint8_t *p_data,
- size_t data_size,
- size_t *p_data_length )
+psa_status_t mock_export(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ uint8_t *p_data,
+ size_t data_size,
+ size_t *p_data_length)
{
(void) context;
(void) p_data;
@@ -183,14 +176,14 @@
mock_export_data.slot_number = slot_number;
mock_export_data.data_size = data_size;
- return( mock_export_data.return_value );
+ return mock_export_data.return_value;
}
-psa_status_t mock_export_public( psa_drv_se_context_t *context,
- psa_key_slot_number_t slot_number,
- uint8_t *p_data,
- size_t data_size,
- size_t *p_data_length )
+psa_status_t mock_export_public(psa_drv_se_context_t *context,
+ psa_key_slot_number_t slot_number,
+ uint8_t *p_data,
+ size_t data_size,
+ size_t *p_data_length)
{
(void) context;
(void) p_data;
@@ -200,17 +193,17 @@
mock_export_public_data.slot_number = slot_number;
mock_export_public_data.data_size = data_size;
- return( mock_export_public_data.return_value );
+ return mock_export_public_data.return_value;
}
-psa_status_t mock_sign( psa_drv_se_context_t *context,
- psa_key_slot_number_t key_slot,
- psa_algorithm_t alg,
- const uint8_t *p_hash,
- size_t hash_length,
- uint8_t *p_signature,
- size_t signature_size,
- size_t *p_signature_length )
+psa_status_t mock_sign(psa_drv_se_context_t *context,
+ psa_key_slot_number_t key_slot,
+ psa_algorithm_t alg,
+ const uint8_t *p_hash,
+ size_t hash_length,
+ uint8_t *p_signature,
+ size_t signature_size,
+ size_t *p_signature_length)
{
(void) context;
(void) p_hash;
@@ -226,13 +219,13 @@
return mock_sign_data.return_value;
}
-psa_status_t mock_verify( psa_drv_se_context_t *context,
- psa_key_slot_number_t key_slot,
- psa_algorithm_t alg,
- const uint8_t *p_hash,
- size_t hash_length,
- const uint8_t *p_signature,
- size_t signature_length )
+psa_status_t mock_verify(psa_drv_se_context_t *context,
+ psa_key_slot_number_t key_slot,
+ psa_algorithm_t alg,
+ const uint8_t *p_hash,
+ size_t hash_length,
+ const uint8_t *p_signature,
+ size_t signature_length)
{
(void) context;
(void) p_hash;
@@ -247,11 +240,11 @@
return mock_verify_data.return_value;
}
-psa_status_t mock_allocate( psa_drv_se_context_t *drv_context,
- void *persistent_data,
- const psa_key_attributes_t *attributes,
- psa_key_creation_method_t method,
- psa_key_slot_number_t *key_slot )
+psa_status_t mock_allocate(psa_drv_se_context_t *drv_context,
+ void *persistent_data,
+ const psa_key_attributes_t *attributes,
+ psa_key_creation_method_t method,
+ psa_key_slot_number_t *key_slot)
{
(void) drv_context;
(void) persistent_data;
@@ -262,12 +255,12 @@
mock_allocate_data.called++;
*key_slot = 0;
- return( mock_allocate_data.return_value );
+ return mock_allocate_data.return_value;
}
-psa_status_t mock_destroy( psa_drv_se_context_t *context,
- void *persistent_data,
- psa_key_slot_number_t slot_number )
+psa_status_t mock_destroy(psa_drv_se_context_t *context,
+ void *persistent_data,
+ psa_key_slot_number_t slot_number)
{
(void) context;
(void) persistent_data;
@@ -275,7 +268,7 @@
mock_destroy_data.called++;
mock_destroy_data.slot_number = slot_number;
- return( mock_destroy_data.return_value );
+ return mock_destroy_data.return_value;
}
/* END_HEADER */
@@ -286,11 +279,11 @@
*/
/* BEGIN_CASE */
-void mock_init( int location_arg,
- int expected_register_status_arg,
- int driver_status_arg,
- int expected_psa_status_arg,
- int expected_called )
+void mock_init(int location_arg,
+ int expected_register_status_arg,
+ int driver_status_arg,
+ int expected_psa_status_arg,
+ int expected_called)
{
psa_key_location_t location = location_arg;
psa_status_t expected_register_status = expected_register_status_arg;
@@ -304,112 +297,110 @@
mock_init_data.return_value = driver_status;
- TEST_EQUAL( psa_register_se_driver( location, &driver ),
- expected_register_status );
+ TEST_EQUAL(psa_register_se_driver(location, &driver),
+ expected_register_status);
psa_crypto_init_called = 1;
- TEST_EQUAL( psa_crypto_init( ), expected_psa_status );
+ TEST_EQUAL(psa_crypto_init(), expected_psa_status);
- TEST_EQUAL( mock_init_data.called, expected_called );
- if( expected_called )
- TEST_EQUAL( mock_init_data.location, location );
+ TEST_EQUAL(mock_init_data.called, expected_called);
+ if (expected_called) {
+ TEST_EQUAL(mock_init_data.location, location);
+ }
exit:
- if( psa_crypto_init_called )
- PSA_DONE( );
- mock_teardown( );
+ if (psa_crypto_init_called) {
+ PSA_DONE();
+ }
+ mock_teardown();
}
/* END_CASE */
/* BEGIN_CASE */
-void mock_import( int mock_alloc_return_value,
- int mock_import_return_value,
- int bits,
- int expected_result )
+void mock_import(int mock_alloc_return_value,
+ int mock_import_return_value,
+ int bits,
+ int expected_result)
{
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
+ const uint8_t key_material[3] = { 0xfa, 0xca, 0xde };
mock_allocate_data.return_value = mock_alloc_return_value;
mock_import_data.return_value = mock_import_return_value;
mock_import_data.bits = bits;
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
key_management.p_import = mock_import;
key_management.p_destroy = mock_destroy;
key_management.p_allocate = mock_allocate;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- TEST_ASSERT( psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id ) == expected_result );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ TEST_ASSERT(psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id) == expected_result);
- TEST_ASSERT( mock_allocate_data.called == 1 );
- TEST_ASSERT( mock_import_data.called ==
- ( mock_alloc_return_value == PSA_SUCCESS? 1 : 0 ) );
+ TEST_ASSERT(mock_allocate_data.called == 1);
+ TEST_ASSERT(mock_import_data.called ==
+ (mock_alloc_return_value == PSA_SUCCESS ? 1 : 0));
- if( mock_alloc_return_value == PSA_SUCCESS )
- {
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- mock_import_data.attributes.core.id, id ) );
- }
- else
- {
- TEST_ASSERT( MBEDTLS_SVC_KEY_ID_GET_KEY_ID(
- mock_import_data.attributes.core.id ) == 0 );
- TEST_ASSERT( MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(
- mock_import_data.attributes.core.id ) == 0 );
+ if (mock_alloc_return_value == PSA_SUCCESS) {
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ mock_import_data.attributes.core.id, id));
+ } else {
+ TEST_ASSERT(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(
+ mock_import_data.attributes.core.id) == 0);
+ TEST_ASSERT(MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(
+ mock_import_data.attributes.core.id) == 0);
}
- TEST_ASSERT( mock_import_data.attributes.core.lifetime ==
- ( mock_alloc_return_value == PSA_SUCCESS? lifetime : 0 ) );
- TEST_ASSERT( mock_import_data.attributes.core.policy.usage ==
- ( mock_alloc_return_value == PSA_SUCCESS? PSA_KEY_USAGE_EXPORT : 0 ) );
- TEST_ASSERT( mock_import_data.attributes.core.type ==
- ( mock_alloc_return_value == PSA_SUCCESS? PSA_KEY_TYPE_RAW_DATA : 0 ) );
+ TEST_ASSERT(mock_import_data.attributes.core.lifetime ==
+ (mock_alloc_return_value == PSA_SUCCESS ? lifetime : 0));
+ TEST_ASSERT(mock_import_data.attributes.core.policy.usage ==
+ (mock_alloc_return_value == PSA_SUCCESS ? PSA_KEY_USAGE_EXPORT : 0));
+ TEST_ASSERT(mock_import_data.attributes.core.type ==
+ (mock_alloc_return_value == PSA_SUCCESS ? PSA_KEY_TYPE_RAW_DATA : 0));
- if( expected_result == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_destroy_key( id ) );
- TEST_ASSERT( mock_destroy_data.called == 1 );
+ if (expected_result == PSA_SUCCESS) {
+ PSA_ASSERT(psa_destroy_key(id));
+ TEST_ASSERT(mock_destroy_data.called == 1);
}
exit:
- PSA_DONE( );
- mock_teardown( );
+ PSA_DONE();
+ mock_teardown();
}
/* END_CASE */
/* BEGIN_CASE */
-void mock_export( int mock_export_return_value, int expected_result )
+void mock_export(int mock_export_return_value, int expected_result)
{
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
- uint8_t exported[sizeof( key_material )];
+ const uint8_t key_material[3] = { 0xfa, 0xca, 0xde };
+ uint8_t exported[sizeof(key_material)];
size_t exported_length;
mock_export_data.return_value = mock_export_return_value;
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
driver.p_init = mock_init;
@@ -418,119 +409,115 @@
key_management.p_destroy = mock_destroy;
key_management.p_allocate = mock_allocate;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- PSA_ASSERT( psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id ) );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id));
- TEST_ASSERT( psa_export_key( id,
- exported, sizeof( exported ),
- &exported_length ) == expected_result );
+ TEST_ASSERT(psa_export_key(id,
+ exported, sizeof(exported),
+ &exported_length) == expected_result);
- TEST_ASSERT( mock_export_data.called == 1 );
+ TEST_ASSERT(mock_export_data.called == 1);
- PSA_ASSERT( psa_destroy_key( id ) );
+ PSA_ASSERT(psa_destroy_key(id));
- TEST_ASSERT( mock_destroy_data.called == 1 );
+ TEST_ASSERT(mock_destroy_data.called == 1);
exit:
- PSA_DONE( );
- mock_teardown( );
+ PSA_DONE();
+ mock_teardown();
}
/* END_CASE */
/* BEGIN_CASE */
-void mock_generate( int mock_alloc_return_value,
- int mock_generate_return_value,
- int expected_result )
+void mock_generate(int mock_alloc_return_value,
+ int mock_generate_return_value,
+ int expected_result)
{
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mock_allocate_data.return_value = mock_alloc_return_value;
mock_generate_data.return_value = mock_generate_return_value;
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
key_management.p_generate = mock_generate;
key_management.p_destroy = mock_destroy;
key_management.p_allocate = mock_allocate;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- psa_set_key_bits( &attributes, 8 );
- TEST_ASSERT( psa_generate_key( &attributes, &returned_id) == expected_result );
- TEST_ASSERT( mock_allocate_data.called == 1 );
- TEST_ASSERT( mock_generate_data.called ==
- ( mock_alloc_return_value == PSA_SUCCESS? 1 : 0 ) );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ psa_set_key_bits(&attributes, 8);
+ TEST_ASSERT(psa_generate_key(&attributes, &returned_id) == expected_result);
+ TEST_ASSERT(mock_allocate_data.called == 1);
+ TEST_ASSERT(mock_generate_data.called ==
+ (mock_alloc_return_value == PSA_SUCCESS ? 1 : 0));
- if( mock_alloc_return_value == PSA_SUCCESS )
- {
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- mock_generate_data.attributes.core.id, id ) );
- }
- else
- {
- TEST_ASSERT( MBEDTLS_SVC_KEY_ID_GET_KEY_ID(
- mock_generate_data.attributes.core.id ) == 0 );
- TEST_ASSERT( MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(
- mock_generate_data.attributes.core.id ) == 0 );
+ if (mock_alloc_return_value == PSA_SUCCESS) {
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ mock_generate_data.attributes.core.id, id));
+ } else {
+ TEST_ASSERT(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(
+ mock_generate_data.attributes.core.id) == 0);
+ TEST_ASSERT(MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(
+ mock_generate_data.attributes.core.id) == 0);
}
- TEST_ASSERT( mock_generate_data.attributes.core.lifetime ==
- ( mock_alloc_return_value == PSA_SUCCESS? lifetime : 0 ) );
- TEST_ASSERT( mock_generate_data.attributes.core.policy.usage ==
- ( mock_alloc_return_value == PSA_SUCCESS? PSA_KEY_USAGE_EXPORT : 0 ) );
- TEST_ASSERT( mock_generate_data.attributes.core.type ==
- ( mock_alloc_return_value == PSA_SUCCESS? PSA_KEY_TYPE_RAW_DATA : 0 ) );
+ TEST_ASSERT(mock_generate_data.attributes.core.lifetime ==
+ (mock_alloc_return_value == PSA_SUCCESS ? lifetime : 0));
+ TEST_ASSERT(mock_generate_data.attributes.core.policy.usage ==
+ (mock_alloc_return_value == PSA_SUCCESS ? PSA_KEY_USAGE_EXPORT : 0));
+ TEST_ASSERT(mock_generate_data.attributes.core.type ==
+ (mock_alloc_return_value == PSA_SUCCESS ? PSA_KEY_TYPE_RAW_DATA : 0));
- if( expected_result == PSA_SUCCESS )
- {
- PSA_ASSERT( psa_destroy_key( id ) );
- TEST_ASSERT( mock_destroy_data.called == 1 );
+ if (expected_result == PSA_SUCCESS) {
+ PSA_ASSERT(psa_destroy_key(id));
+ TEST_ASSERT(mock_destroy_data.called == 1);
}
exit:
- PSA_DONE( );
- mock_teardown( );
+ PSA_DONE();
+ mock_teardown();
}
/* END_CASE */
/* BEGIN_CASE */
-void mock_export_public( int mock_export_public_return_value,
- int expected_result )
+void mock_export_public(int mock_export_public_return_value,
+ int expected_result)
{
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
- uint8_t exported[sizeof( key_material )];
+ const uint8_t key_material[3] = { 0xfa, 0xca, 0xde };
+ uint8_t exported[sizeof(key_material)];
size_t exported_length;
mock_export_public_data.return_value = mock_export_public_return_value;
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
driver.key_management = &key_management;
key_management.p_import = mock_import;
@@ -538,52 +525,52 @@
key_management.p_destroy = mock_destroy;
key_management.p_allocate = mock_allocate;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY);
- PSA_ASSERT( psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id ) );
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id));
- TEST_ASSERT( psa_export_public_key( id, exported, sizeof(exported),
- &exported_length ) == expected_result );
- TEST_ASSERT( mock_export_public_data.called == 1 );
+ TEST_ASSERT(psa_export_public_key(id, exported, sizeof(exported),
+ &exported_length) == expected_result);
+ TEST_ASSERT(mock_export_public_data.called == 1);
- PSA_ASSERT( psa_destroy_key( id ) );
- TEST_ASSERT( mock_destroy_data.called == 1 );
+ PSA_ASSERT(psa_destroy_key(id));
+ TEST_ASSERT(mock_destroy_data.called == 1);
exit:
- PSA_DONE( );
- mock_teardown( );
+ PSA_DONE();
+ mock_teardown();
}
/* END_CASE */
/* BEGIN_CASE */
-void mock_sign( int mock_sign_return_value, int expected_result )
+void mock_sign(int mock_sign_return_value, int expected_result)
{
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_drv_se_asymmetric_t asymmetric;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
+ const uint8_t key_material[3] = { 0xfa, 0xca, 0xde };
psa_algorithm_t algorithm = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
- const uint8_t hash[1] = {'H'};
- uint8_t signature[1] = {'S'};
+ const uint8_t hash[1] = { 'H' };
+ uint8_t signature[1] = { 'S' };
size_t signature_length;
mock_sign_data.return_value = mock_sign_return_value;
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
- memset( &asymmetric, 0, sizeof( asymmetric ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
+ memset(&asymmetric, 0, sizeof(asymmetric));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
@@ -595,55 +582,55 @@
driver.asymmetric = &asymmetric;
asymmetric.p_sign = mock_sign;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, algorithm );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RSA_KEY_PAIR );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, algorithm);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_KEY_PAIR);
- PSA_ASSERT( psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id ) );
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id));
- TEST_ASSERT( psa_sign_hash( id, algorithm,
- hash, sizeof( hash ),
- signature, sizeof( signature ),
- &signature_length)
- == expected_result );
- TEST_ASSERT( mock_sign_data.called == 1 );
+ TEST_ASSERT(psa_sign_hash(id, algorithm,
+ hash, sizeof(hash),
+ signature, sizeof(signature),
+ &signature_length)
+ == expected_result);
+ TEST_ASSERT(mock_sign_data.called == 1);
- PSA_ASSERT( psa_destroy_key( id ) );
- TEST_ASSERT( mock_destroy_data.called == 1 );
+ PSA_ASSERT(psa_destroy_key(id));
+ TEST_ASSERT(mock_destroy_data.called == 1);
exit:
- PSA_DONE( );
- mock_teardown( );
+ PSA_DONE();
+ mock_teardown();
}
/* END_CASE */
/* BEGIN_CASE */
-void mock_verify( int mock_verify_return_value, int expected_result )
+void mock_verify(int mock_verify_return_value, int expected_result)
{
psa_drv_se_t driver;
psa_drv_se_key_management_t key_management;
psa_drv_se_asymmetric_t asymmetric;
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
- psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, 1);
mbedtls_svc_key_id_t returned_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
+ const uint8_t key_material[3] = { 0xfa, 0xca, 0xde };
psa_algorithm_t algorithm = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
- const uint8_t hash[1] = {'H'};
- const uint8_t signature[1] = {'S'};
+ const uint8_t hash[1] = { 'H' };
+ const uint8_t signature[1] = { 'S' };
mock_verify_data.return_value = mock_verify_return_value;
- memset( &driver, 0, sizeof( driver ) );
- memset( &key_management, 0, sizeof( key_management ) );
- memset( &asymmetric, 0, sizeof( asymmetric ) );
+ memset(&driver, 0, sizeof(driver));
+ memset(&key_management, 0, sizeof(key_management));
+ memset(&asymmetric, 0, sizeof(asymmetric));
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
@@ -655,30 +642,30 @@
driver.asymmetric = &asymmetric;
asymmetric.p_verify = mock_verify;
- PSA_ASSERT( psa_register_se_driver( location, &driver ) );
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_register_se_driver(location, &driver));
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
- psa_set_key_algorithm( &attributes, algorithm );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ psa_set_key_algorithm(&attributes, algorithm);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
- PSA_ASSERT( psa_import_key( &attributes,
- key_material, sizeof( key_material ),
- &returned_id ) );
+ PSA_ASSERT(psa_import_key(&attributes,
+ key_material, sizeof(key_material),
+ &returned_id));
- TEST_ASSERT( psa_verify_hash( id, algorithm,
- hash, sizeof( hash ),
- signature, sizeof( signature ) )
- == expected_result );
- TEST_ASSERT( mock_verify_data.called == 1 );
+ TEST_ASSERT(psa_verify_hash(id, algorithm,
+ hash, sizeof(hash),
+ signature, sizeof(signature))
+ == expected_result);
+ TEST_ASSERT(mock_verify_data.called == 1);
- PSA_ASSERT( psa_destroy_key( id ) );
- TEST_ASSERT( mock_destroy_data.called == 1 );
+ PSA_ASSERT(psa_destroy_key(id));
+ TEST_ASSERT(mock_destroy_data.called == 1);
exit:
- PSA_DONE( );
- mock_teardown( );
+ PSA_DONE();
+ mock_teardown();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function
index d577663..e3bb0d3 100644
--- a/tests/suites/test_suite_psa_crypto_slot_management.function
+++ b/tests/suites/test_suite_psa_crypto_slot_management.function
@@ -4,8 +4,7 @@
#include "psa_crypto_slot_management.h"
#include "psa_crypto_storage.h"
-typedef enum
-{
+typedef enum {
/**< Close key(s) */
INVALIDATE_BY_CLOSING,
@@ -28,15 +27,13 @@
INVALIDATE_BY_PURGING_WITH_SHUTDOWN,
} invalidate_method_t;
-typedef enum
-{
+typedef enum {
KEEP_OPEN,
CLOSE_BEFORE,
CLOSE_AFTER,
} reopen_policy_t;
-typedef enum
-{
+typedef enum {
INVALID_HANDLE_0,
INVALID_HANDLE_UNOPENED,
INVALID_HANDLE_CLOSED,
@@ -46,61 +43,59 @@
/** Apply \p invalidate_method to invalidate the specified key:
* close it, destroy it, or do nothing;
*/
-static int invalidate_key( invalidate_method_t invalidate_method,
- mbedtls_svc_key_id_t key )
+static int invalidate_key(invalidate_method_t invalidate_method,
+ mbedtls_svc_key_id_t key)
{
- switch( invalidate_method )
- {
+ switch (invalidate_method) {
/* Closing the key invalidate only volatile keys, not persistent ones. */
case INVALIDATE_BY_CLOSING:
case INVALIDATE_BY_CLOSING_WITH_SHUTDOWN:
- PSA_ASSERT( psa_close_key( key ) );
+ PSA_ASSERT(psa_close_key(key));
break;
case INVALIDATE_BY_DESTROYING:
case INVALIDATE_BY_DESTROYING_WITH_SHUTDOWN:
- PSA_ASSERT( psa_destroy_key( key ) );
+ PSA_ASSERT(psa_destroy_key(key));
break;
/* Purging the key just purges RAM data of persistent keys. */
case INVALIDATE_BY_PURGING:
case INVALIDATE_BY_PURGING_WITH_SHUTDOWN:
- PSA_ASSERT( psa_purge_key( key ) );
+ PSA_ASSERT(psa_purge_key(key));
break;
case INVALIDATE_BY_SHUTDOWN:
break;
}
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
/** Restart the PSA subsystem if \p invalidate_method says so. */
-static int invalidate_psa( invalidate_method_t invalidate_method )
+static int invalidate_psa(invalidate_method_t invalidate_method)
{
- switch( invalidate_method )
- {
+ switch (invalidate_method) {
case INVALIDATE_BY_CLOSING:
case INVALIDATE_BY_DESTROYING:
case INVALIDATE_BY_PURGING:
- return( 1 );
+ return 1;
case INVALIDATE_BY_CLOSING_WITH_SHUTDOWN:
case INVALIDATE_BY_DESTROYING_WITH_SHUTDOWN:
case INVALIDATE_BY_PURGING_WITH_SHUTDOWN:
/* All keys must have been closed. */
- PSA_SESSION_DONE( );
+ PSA_SESSION_DONE();
break;
case INVALIDATE_BY_SHUTDOWN:
/* Some keys may remain behind, and we're testing that this
* properly closes them. */
- mbedtls_psa_crypto_free( );
+ mbedtls_psa_crypto_free();
break;
}
- PSA_ASSERT( psa_crypto_init( ) );
- ASSERT_PSA_PRISTINE( );
- return( 1 );
+ PSA_ASSERT(psa_crypto_init());
+ ASSERT_PSA_PRISTINE();
+ return 1;
exit:
- return( 0 );
+ return 0;
}
/* END_HEADER */
@@ -111,10 +106,10 @@
*/
/* BEGIN_CASE */
-void transient_slot_lifecycle( int owner_id_arg,
- int usage_arg, int alg_arg,
- int type_arg, data_t *key_data,
- int invalidate_method_arg )
+void transient_slot_lifecycle(int owner_id_arg,
+ int usage_arg, int alg_arg,
+ int type_arg, data_t *key_data,
+ int invalidate_method_arg)
{
psa_algorithm_t alg = alg_arg;
psa_key_usage_t usage_flags = usage_arg;
@@ -123,40 +118,40 @@
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_test_set_step( 1 );
- PSA_ASSERT( psa_crypto_init( ) );
+ mbedtls_test_set_step(1);
+ PSA_ASSERT(psa_crypto_init());
/* Import a key. */
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
mbedtls_key_owner_id_t owner_id = owner_id_arg;
- mbedtls_set_key_owner_id( &attributes, owner_id );
+ mbedtls_set_key_owner_id(&attributes, owner_id);
#else
- (void)owner_id_arg;
+ (void) owner_id_arg;
#endif
- psa_set_key_usage_flags( &attributes, usage_flags );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, type );
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &key ) );
- TEST_ASSERT( ! mbedtls_svc_key_id_is_null( key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- psa_reset_key_attributes( &attributes );
+ psa_set_key_usage_flags(&attributes, usage_flags);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, type);
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &key));
+ TEST_ASSERT(!mbedtls_svc_key_id_is_null(key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ psa_reset_key_attributes(&attributes);
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
{
psa_key_handle_t handle;
mbedtls_svc_key_id_t key_with_invalid_owner =
- mbedtls_svc_key_id_make( owner_id + 1,
- MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key ) );
+ mbedtls_svc_key_id_make(owner_id + 1,
+ MBEDTLS_SVC_KEY_ID_GET_KEY_ID(key));
- TEST_ASSERT( mbedtls_key_owner_id_equal(
- owner_id,
- MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( key ) ) );
- TEST_EQUAL( psa_open_key( key_with_invalid_owner, &handle ),
- PSA_ERROR_DOES_NOT_EXIST );
+ TEST_ASSERT(mbedtls_key_owner_id_equal(
+ owner_id,
+ MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(key)));
+ TEST_EQUAL(psa_open_key(key_with_invalid_owner, &handle),
+ PSA_ERROR_DOES_NOT_EXIST);
}
#endif
@@ -164,42 +159,44 @@
* Purge the key and make sure that it is still valid, as purging a
* volatile key shouldn't invalidate/destroy it.
*/
- PSA_ASSERT( psa_purge_key( key ) );
- PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
- psa_reset_key_attributes( &attributes );
+ PSA_ASSERT(psa_purge_key(key));
+ PSA_ASSERT(psa_get_key_attributes(key, &attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
+ psa_reset_key_attributes(&attributes);
/* Do something that invalidates the key. */
- mbedtls_test_set_step( 2 );
- if( ! invalidate_key( invalidate_method, key ) )
+ mbedtls_test_set_step(2);
+ if (!invalidate_key(invalidate_method, key)) {
goto exit;
- if( ! invalidate_psa( invalidate_method ) )
+ }
+ if (!invalidate_psa(invalidate_method)) {
goto exit;
+ }
/* Test that the key is now invalid. */
- TEST_EQUAL( psa_get_key_attributes( key, &attributes ),
- PSA_ERROR_INVALID_HANDLE );
- TEST_EQUAL( psa_close_key( key ), PSA_ERROR_INVALID_HANDLE );
+ TEST_EQUAL(psa_get_key_attributes(key, &attributes),
+ PSA_ERROR_INVALID_HANDLE);
+ TEST_EQUAL(psa_close_key(key), PSA_ERROR_INVALID_HANDLE);
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */
-void persistent_slot_lifecycle( int lifetime_arg, int owner_id_arg, int id_arg,
- int usage_arg, int alg_arg, int alg2_arg,
- int type_arg, data_t *key_data,
- int invalidate_method_arg )
+void persistent_slot_lifecycle(int lifetime_arg, int owner_id_arg, int id_arg,
+ int usage_arg, int alg_arg, int alg2_arg,
+ int type_arg, data_t *key_data,
+ int invalidate_method_arg)
{
psa_key_lifetime_t lifetime = lifetime_arg;
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( owner_id_arg, id_arg );
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(owner_id_arg, id_arg);
psa_algorithm_t alg = alg_arg;
psa_algorithm_t alg2 = alg2_arg;
psa_key_usage_t usage_flags = usage_arg;
@@ -214,112 +211,110 @@
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
mbedtls_svc_key_id_t wrong_owner_id =
- mbedtls_svc_key_id_make( owner_id_arg + 1, id_arg );
+ mbedtls_svc_key_id_make(owner_id_arg + 1, id_arg);
mbedtls_svc_key_id_t invalid_svc_key_id = MBEDTLS_SVC_KEY_ID_INIT;
#endif
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- mbedtls_test_set_step( 1 );
- PSA_ASSERT( psa_crypto_init( ) );
+ mbedtls_test_set_step(1);
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_type( &attributes, type );
- psa_set_key_usage_flags( &attributes, usage_flags );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_enrollment_algorithm( &attributes, alg2 );
- PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
- &returned_id ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( id, returned_id ) );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_usage_flags(&attributes, usage_flags);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_enrollment_algorithm(&attributes, alg2);
+ PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
+ &returned_id));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(id, returned_id));
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
- TEST_EQUAL( psa_open_key( wrong_owner_id, &invalid_svc_key_id ),
- PSA_ERROR_DOES_NOT_EXIST );
+ TEST_EQUAL(psa_open_key(wrong_owner_id, &invalid_svc_key_id),
+ PSA_ERROR_DOES_NOT_EXIST);
#endif
- PSA_ASSERT( psa_get_key_attributes( id, &attributes ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), lifetime );
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ), id ) );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ),
- mbedtls_test_update_key_usage_flags( usage_flags ) );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), alg );
- TEST_EQUAL( psa_get_key_enrollment_algorithm( &attributes ), alg2 );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
+ PSA_ASSERT(psa_get_key_attributes(id, &attributes));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), lifetime);
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes), id));
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes),
+ mbedtls_test_update_key_usage_flags(usage_flags));
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), alg);
+ TEST_EQUAL(psa_get_key_enrollment_algorithm(&attributes), alg2);
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
/* Close the key and then open it. */
- PSA_ASSERT( psa_close_key( id ) );
+ PSA_ASSERT(psa_close_key(id));
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
- TEST_EQUAL( psa_open_key( wrong_owner_id, &invalid_svc_key_id ),
- PSA_ERROR_DOES_NOT_EXIST );
+ TEST_EQUAL(psa_open_key(wrong_owner_id, &invalid_svc_key_id),
+ PSA_ERROR_DOES_NOT_EXIST);
#endif
- PSA_ASSERT( psa_open_key( id, &handle ) );
- TEST_ASSERT( ! psa_key_handle_is_null( handle ) );
- PSA_ASSERT( psa_get_key_attributes( handle, &attributes ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), lifetime );
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ), id ) );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ),
- mbedtls_test_update_key_usage_flags( usage_flags ) );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), alg );
- TEST_EQUAL( psa_get_key_enrollment_algorithm( &attributes ), alg2 );
- TEST_EQUAL( psa_get_key_type( &attributes ), type );
+ PSA_ASSERT(psa_open_key(id, &handle));
+ TEST_ASSERT(!psa_key_handle_is_null(handle));
+ PSA_ASSERT(psa_get_key_attributes(handle, &attributes));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), lifetime);
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes), id));
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes),
+ mbedtls_test_update_key_usage_flags(usage_flags));
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), alg);
+ TEST_EQUAL(psa_get_key_enrollment_algorithm(&attributes), alg2);
+ TEST_EQUAL(psa_get_key_type(&attributes), type);
/*
* Do something that wipes key data in volatile memory or destroy the
* key.
*/
- mbedtls_test_set_step( 2 );
- if( ! invalidate_key( invalidate_method, id ) )
+ mbedtls_test_set_step(2);
+ if (!invalidate_key(invalidate_method, id)) {
goto exit;
- if( ! invalidate_psa( invalidate_method ) )
+ }
+ if (!invalidate_psa(invalidate_method)) {
goto exit;
+ }
/* Try to reaccess the key. If we destroyed it, check that it doesn't
* exist. Otherwise check that it still exists and has the expected
* content. */
- switch( invalidate_method )
- {
+ switch (invalidate_method) {
case INVALIDATE_BY_CLOSING:
case INVALIDATE_BY_CLOSING_WITH_SHUTDOWN:
case INVALIDATE_BY_PURGING:
case INVALIDATE_BY_PURGING_WITH_SHUTDOWN:
case INVALIDATE_BY_SHUTDOWN:
- PSA_ASSERT( psa_open_key( id, &handle ) );
- PSA_ASSERT( psa_get_key_attributes( id, &read_attributes ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ),
- psa_get_key_lifetime( &read_attributes ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ),
- psa_get_key_id( &read_attributes ) ) );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ),
- mbedtls_test_update_key_usage_flags( usage_flags ) );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ),
- psa_get_key_algorithm( &read_attributes ) );
- TEST_EQUAL( psa_get_key_enrollment_algorithm( &attributes ),
- psa_get_key_enrollment_algorithm( &read_attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ),
- psa_get_key_type( &read_attributes ) );
- TEST_EQUAL( psa_get_key_bits( &attributes ),
- psa_get_key_bits( &read_attributes ) );
- ASSERT_ALLOC( reexported, key_data->len );
- if( usage_flags & PSA_KEY_USAGE_EXPORT )
- {
- PSA_ASSERT( psa_export_key( id, reexported, key_data->len,
- &reexported_length ) );
- ASSERT_COMPARE( key_data->x, key_data->len,
- reexported, reexported_length );
+ PSA_ASSERT(psa_open_key(id, &handle));
+ PSA_ASSERT(psa_get_key_attributes(id, &read_attributes));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes),
+ psa_get_key_lifetime(&read_attributes));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes),
+ psa_get_key_id(&read_attributes)));
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes),
+ mbedtls_test_update_key_usage_flags(usage_flags));
+ TEST_EQUAL(psa_get_key_algorithm(&attributes),
+ psa_get_key_algorithm(&read_attributes));
+ TEST_EQUAL(psa_get_key_enrollment_algorithm(&attributes),
+ psa_get_key_enrollment_algorithm(&read_attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes),
+ psa_get_key_type(&read_attributes));
+ TEST_EQUAL(psa_get_key_bits(&attributes),
+ psa_get_key_bits(&read_attributes));
+ ASSERT_ALLOC(reexported, key_data->len);
+ if (usage_flags & PSA_KEY_USAGE_EXPORT) {
+ PSA_ASSERT(psa_export_key(id, reexported, key_data->len,
+ &reexported_length));
+ ASSERT_COMPARE(key_data->x, key_data->len,
+ reexported, reexported_length);
+ } else {
+ TEST_EQUAL(psa_export_key(id, reexported,
+ key_data->len, &reexported_length),
+ PSA_ERROR_NOT_PERMITTED);
}
- else
- {
- TEST_EQUAL( psa_export_key( id, reexported,
- key_data->len, &reexported_length ),
- PSA_ERROR_NOT_PERMITTED );
- }
- PSA_ASSERT( psa_close_key( handle ) );
+ PSA_ASSERT(psa_close_key(handle));
break;
case INVALIDATE_BY_DESTROYING:
@@ -328,11 +323,11 @@
* Test that the key handle and identifier are now not referring to an
* existing key.
*/
- TEST_EQUAL( psa_get_key_attributes( handle, &read_attributes ),
- PSA_ERROR_INVALID_HANDLE );
- TEST_EQUAL( psa_close_key( handle ), PSA_ERROR_INVALID_HANDLE );
- TEST_EQUAL( psa_get_key_attributes( id, &read_attributes ),
- PSA_ERROR_INVALID_HANDLE );
+ TEST_EQUAL(psa_get_key_attributes(handle, &read_attributes),
+ PSA_ERROR_INVALID_HANDLE);
+ TEST_EQUAL(psa_close_key(handle), PSA_ERROR_INVALID_HANDLE);
+ TEST_EQUAL(psa_get_key_attributes(id, &read_attributes),
+ PSA_ERROR_INVALID_HANDLE);
break;
}
@@ -341,158 +336,159 @@
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
- psa_reset_key_attributes( &read_attributes );
+ psa_reset_key_attributes(&attributes);
+ psa_reset_key_attributes(&read_attributes);
- PSA_DONE( );
- mbedtls_free( reexported );
+ PSA_DONE();
+ mbedtls_free(reexported);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */
-void create_existent( int lifetime_arg, int owner_id_arg, int id_arg,
- int reopen_policy_arg )
+void create_existent(int lifetime_arg, int owner_id_arg, int id_arg,
+ int reopen_policy_arg)
{
psa_key_lifetime_t lifetime = lifetime_arg;
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( owner_id_arg, id_arg );
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(owner_id_arg, id_arg);
mbedtls_svc_key_id_t returned_id = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t type1 = PSA_KEY_TYPE_RAW_DATA;
const uint8_t material1[5] = "a key";
const uint8_t material2[5] = "b key";
- size_t bits1 = PSA_BYTES_TO_BITS( sizeof( material1 ) );
- uint8_t reexported[sizeof( material1 )];
+ size_t bits1 = PSA_BYTES_TO_BITS(sizeof(material1));
+ uint8_t reexported[sizeof(material1)];
size_t reexported_length;
reopen_policy_t reopen_policy = reopen_policy_arg;
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Create a key. */
- psa_set_key_id( &attributes, id );
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_type( &attributes, type1 );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes, 0 );
- PSA_ASSERT( psa_import_key( &attributes, material1, sizeof( material1 ),
- &returned_id ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( id, returned_id ) );
+ psa_set_key_id(&attributes, id);
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_type(&attributes, type1);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes, 0);
+ PSA_ASSERT(psa_import_key(&attributes, material1, sizeof(material1),
+ &returned_id));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(id, returned_id));
- if( reopen_policy == CLOSE_BEFORE )
- PSA_ASSERT( psa_close_key( id ) );
+ if (reopen_policy == CLOSE_BEFORE) {
+ PSA_ASSERT(psa_close_key(id));
+ }
/* Attempt to create a new key in the same slot. */
- TEST_EQUAL( psa_import_key( &attributes, material2, sizeof( material2 ),
- &returned_id ),
- PSA_ERROR_ALREADY_EXISTS );
- TEST_ASSERT( mbedtls_svc_key_id_is_null( returned_id ) );
+ TEST_EQUAL(psa_import_key(&attributes, material2, sizeof(material2),
+ &returned_id),
+ PSA_ERROR_ALREADY_EXISTS);
+ TEST_ASSERT(mbedtls_svc_key_id_is_null(returned_id));
- if( reopen_policy == CLOSE_AFTER )
- PSA_ASSERT( psa_close_key( id ) );
+ if (reopen_policy == CLOSE_AFTER) {
+ PSA_ASSERT(psa_close_key(id));
+ }
/* Check that the original key hasn't changed. */
- psa_reset_key_attributes( &attributes );
- PSA_ASSERT( psa_get_key_attributes( id, &attributes ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes ), id ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes ), lifetime );
- TEST_EQUAL( psa_get_key_type( &attributes ), type1 );
- TEST_EQUAL( psa_get_key_bits( &attributes ), bits1 );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes ), PSA_KEY_USAGE_EXPORT );
- TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
+ psa_reset_key_attributes(&attributes);
+ PSA_ASSERT(psa_get_key_attributes(id, &attributes));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes), id));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes), lifetime);
+ TEST_EQUAL(psa_get_key_type(&attributes), type1);
+ TEST_EQUAL(psa_get_key_bits(&attributes), bits1);
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes), PSA_KEY_USAGE_EXPORT);
+ TEST_EQUAL(psa_get_key_algorithm(&attributes), 0);
- PSA_ASSERT( psa_export_key( id,
- reexported, sizeof( reexported ),
- &reexported_length ) );
- ASSERT_COMPARE( material1, sizeof( material1 ),
- reexported, reexported_length );
+ PSA_ASSERT(psa_export_key(id,
+ reexported, sizeof(reexported),
+ &reexported_length));
+ ASSERT_COMPARE(material1, sizeof(material1),
+ reexported, reexported_length);
- PSA_ASSERT( psa_close_key( id ) );
+ PSA_ASSERT(psa_close_key(id));
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void open_fail( int id_arg,
- int expected_status_arg )
+void open_fail(int id_arg,
+ int expected_status_arg)
{
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, id_arg );
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, id_arg);
psa_status_t expected_status = expected_status_arg;
- psa_key_handle_t handle = mbedtls_svc_key_id_make( 0xdead, 0xdead );
+ psa_key_handle_t handle = mbedtls_svc_key_id_make(0xdead, 0xdead);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- TEST_EQUAL( psa_open_key( id, &handle ), expected_status );
- TEST_ASSERT( psa_key_handle_is_null( handle ) );
+ TEST_EQUAL(psa_open_key(id, &handle), expected_status);
+ TEST_ASSERT(psa_key_handle_is_null(handle));
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void create_fail( int lifetime_arg, int id_arg,
- int expected_status_arg )
+void create_fail(int lifetime_arg, int id_arg,
+ int expected_status_arg)
{
psa_key_lifetime_t lifetime = lifetime_arg;
- mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, id_arg );
+ mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make(1, id_arg);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t expected_status = expected_status_arg;
mbedtls_svc_key_id_t returned_id =
- mbedtls_svc_key_id_make( 0xdead, 0xdead );
- uint8_t material[1] = {'k'};
+ mbedtls_svc_key_id_make(0xdead, 0xdead);
+ uint8_t material[1] = { 'k' };
- TEST_USES_KEY_ID( id );
+ TEST_USES_KEY_ID(id);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_lifetime( &attributes, lifetime );
- if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) )
- {
+ psa_set_key_lifetime(&attributes, lifetime);
+ if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) {
/*
* Not possible to set a key identifier different from 0 through
* PSA key attributes APIs thus accessing to the attributes
* directly.
*/
attributes.core.id = id;
+ } else {
+ psa_set_key_id(&attributes, id);
}
- else
- psa_set_key_id( &attributes, id );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- TEST_EQUAL( psa_import_key( &attributes, material, sizeof( material ),
- &returned_id ),
- expected_status );
- TEST_ASSERT( mbedtls_svc_key_id_is_null( returned_id ) );
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ TEST_EQUAL(psa_import_key(&attributes, material, sizeof(material),
+ &returned_id),
+ expected_status);
+ TEST_ASSERT(mbedtls_svc_key_id_is_null(returned_id));
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void copy_across_lifetimes( int source_lifetime_arg, int source_owner_id_arg,
- int source_id_arg, int source_usage_arg,
- int source_alg_arg, int source_alg2_arg,
- int type_arg, data_t *material,
- int target_lifetime_arg, int target_owner_id_arg,
- int target_id_arg, int target_usage_arg,
- int target_alg_arg, int target_alg2_arg,
- int expected_usage_arg,
- int expected_alg_arg, int expected_alg2_arg )
+void copy_across_lifetimes(int source_lifetime_arg, int source_owner_id_arg,
+ int source_id_arg, int source_usage_arg,
+ int source_alg_arg, int source_alg2_arg,
+ int type_arg, data_t *material,
+ int target_lifetime_arg, int target_owner_id_arg,
+ int target_id_arg, int target_usage_arg,
+ int target_alg_arg, int target_alg2_arg,
+ int expected_usage_arg,
+ int expected_alg_arg, int expected_alg2_arg)
{
psa_key_lifetime_t source_lifetime = source_lifetime_arg;
mbedtls_svc_key_id_t source_id =
- mbedtls_svc_key_id_make( source_owner_id_arg, source_id_arg );
+ mbedtls_svc_key_id_make(source_owner_id_arg, source_id_arg);
psa_key_usage_t source_usage = source_usage_arg;
psa_algorithm_t source_alg = source_alg_arg;
psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -500,7 +496,7 @@
mbedtls_svc_key_id_t returned_source_id = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_lifetime_t target_lifetime = target_lifetime_arg;
mbedtls_svc_key_id_t target_id =
- mbedtls_svc_key_id_make( target_owner_id_arg, target_id_arg );
+ mbedtls_svc_key_id_make(target_owner_id_arg, target_id_arg);
psa_key_usage_t target_usage = target_usage_arg;
psa_algorithm_t target_alg = target_alg_arg;
psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -511,127 +507,120 @@
psa_algorithm_t expected_alg2 = expected_alg2_arg;
uint8_t *export_buffer = NULL;
- TEST_USES_KEY_ID( source_id );
- TEST_USES_KEY_ID( target_id );
+ TEST_USES_KEY_ID(source_id);
+ TEST_USES_KEY_ID(target_id);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Populate the source slot. */
- psa_set_key_id( &source_attributes, source_id );
- psa_set_key_lifetime( &source_attributes, source_lifetime );
+ psa_set_key_id(&source_attributes, source_id);
+ psa_set_key_lifetime(&source_attributes, source_lifetime);
- psa_set_key_type( &source_attributes, source_type );
- psa_set_key_usage_flags( &source_attributes, source_usage );
- psa_set_key_algorithm( &source_attributes, source_alg );
- psa_set_key_enrollment_algorithm( &source_attributes, source_alg2_arg );
- PSA_ASSERT( psa_import_key( &source_attributes,
- material->x, material->len,
- &returned_source_id ) );
+ psa_set_key_type(&source_attributes, source_type);
+ psa_set_key_usage_flags(&source_attributes, source_usage);
+ psa_set_key_algorithm(&source_attributes, source_alg);
+ psa_set_key_enrollment_algorithm(&source_attributes, source_alg2_arg);
+ PSA_ASSERT(psa_import_key(&source_attributes,
+ material->x, material->len,
+ &returned_source_id));
/* Update the attributes with the bit size. */
- PSA_ASSERT( psa_get_key_attributes( returned_source_id,
- &source_attributes ) );
+ PSA_ASSERT(psa_get_key_attributes(returned_source_id,
+ &source_attributes));
/* Prepare the target slot. */
- psa_set_key_id( &target_attributes, target_id );
- psa_set_key_lifetime( &target_attributes, target_lifetime );
+ psa_set_key_id(&target_attributes, target_id);
+ psa_set_key_lifetime(&target_attributes, target_lifetime);
- psa_set_key_usage_flags( &target_attributes, target_usage );
- psa_set_key_algorithm( &target_attributes, target_alg );
- psa_set_key_enrollment_algorithm( &target_attributes, target_alg2_arg );
+ psa_set_key_usage_flags(&target_attributes, target_usage);
+ psa_set_key_algorithm(&target_attributes, target_alg);
+ psa_set_key_enrollment_algorithm(&target_attributes, target_alg2_arg);
/* Copy the key. */
- PSA_ASSERT( psa_copy_key( returned_source_id,
- &target_attributes, &returned_target_id ) );
+ PSA_ASSERT(psa_copy_key(returned_source_id,
+ &target_attributes, &returned_target_id));
/* Destroy the source to ensure that this doesn't affect the target. */
- PSA_ASSERT( psa_destroy_key( returned_source_id ) );
+ PSA_ASSERT(psa_destroy_key(returned_source_id));
/* If the target key is persistent, restart the system to make
* sure that the material is still alive. */
- if( ! PSA_KEY_LIFETIME_IS_VOLATILE( target_lifetime ) )
- {
- mbedtls_psa_crypto_free( );
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_ASSERT( psa_open_key( target_id, &target_handle ) );
+ if (!PSA_KEY_LIFETIME_IS_VOLATILE(target_lifetime)) {
+ mbedtls_psa_crypto_free();
+ PSA_ASSERT(psa_crypto_init());
+ PSA_ASSERT(psa_open_key(target_id, &target_handle));
}
/* Test that the target slot has the expected content. */
- psa_reset_key_attributes( &target_attributes );
- PSA_ASSERT( psa_get_key_attributes( returned_target_id,
- &target_attributes ) );
+ psa_reset_key_attributes(&target_attributes);
+ PSA_ASSERT(psa_get_key_attributes(returned_target_id,
+ &target_attributes));
- if( ! PSA_KEY_LIFETIME_IS_VOLATILE( target_lifetime ) )
- {
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- target_id, psa_get_key_id( &target_attributes ) ) );
- }
- else
- {
+ if (!PSA_KEY_LIFETIME_IS_VOLATILE(target_lifetime)) {
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ target_id, psa_get_key_id(&target_attributes)));
+ } else {
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
- TEST_EQUAL( MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( returned_target_id ),
- target_owner_id_arg );
+ TEST_EQUAL(MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(returned_target_id),
+ target_owner_id_arg);
#endif
}
- TEST_EQUAL( target_lifetime, psa_get_key_lifetime( &target_attributes ) );
- TEST_EQUAL( source_type, psa_get_key_type( &target_attributes ) );
- TEST_EQUAL( psa_get_key_bits( &source_attributes ),
- psa_get_key_bits( &target_attributes ) );
- TEST_EQUAL( expected_usage, psa_get_key_usage_flags( &target_attributes ) );
- TEST_EQUAL( expected_alg, psa_get_key_algorithm( &target_attributes ) );
- TEST_EQUAL( expected_alg2,
- psa_get_key_enrollment_algorithm( &target_attributes ) );
- if( expected_usage & PSA_KEY_USAGE_EXPORT )
- {
+ TEST_EQUAL(target_lifetime, psa_get_key_lifetime(&target_attributes));
+ TEST_EQUAL(source_type, psa_get_key_type(&target_attributes));
+ TEST_EQUAL(psa_get_key_bits(&source_attributes),
+ psa_get_key_bits(&target_attributes));
+ TEST_EQUAL(expected_usage, psa_get_key_usage_flags(&target_attributes));
+ TEST_EQUAL(expected_alg, psa_get_key_algorithm(&target_attributes));
+ TEST_EQUAL(expected_alg2,
+ psa_get_key_enrollment_algorithm(&target_attributes));
+ if (expected_usage & PSA_KEY_USAGE_EXPORT) {
size_t length;
- ASSERT_ALLOC( export_buffer, material->len );
- PSA_ASSERT( psa_export_key( returned_target_id, export_buffer,
- material->len, &length ) );
- ASSERT_COMPARE( material->x, material->len,
- export_buffer, length );
- }
- else
- {
+ ASSERT_ALLOC(export_buffer, material->len);
+ PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
+ material->len, &length));
+ ASSERT_COMPARE(material->x, material->len,
+ export_buffer, length);
+ } else {
size_t length;
/* Check that the key is actually non-exportable. */
- TEST_EQUAL( psa_export_key( returned_target_id, export_buffer,
- material->len, &length ),
- PSA_ERROR_NOT_PERMITTED );
+ TEST_EQUAL(psa_export_key(returned_target_id, export_buffer,
+ material->len, &length),
+ PSA_ERROR_NOT_PERMITTED);
}
- PSA_ASSERT( psa_destroy_key( returned_target_id ) );
+ PSA_ASSERT(psa_destroy_key(returned_target_id));
exit:
/*
* Source and target key attributes may have been returned by
* psa_get_key_attributes() thus reset them as required.
*/
- psa_reset_key_attributes( &source_attributes );
- psa_reset_key_attributes( &target_attributes );
+ psa_reset_key_attributes(&source_attributes);
+ psa_reset_key_attributes(&target_attributes);
- PSA_DONE( );
- mbedtls_free( export_buffer );
+ PSA_DONE();
+ mbedtls_free(export_buffer);
}
/* END_CASE */
/* BEGIN_CASE */
-void copy_to_occupied( int source_lifetime_arg, int source_id_arg,
- int source_usage_arg, int source_alg_arg,
- int source_type_arg, data_t *source_material,
- int target_lifetime_arg, int target_id_arg,
- int target_usage_arg, int target_alg_arg,
- int target_type_arg, data_t *target_material )
+void copy_to_occupied(int source_lifetime_arg, int source_id_arg,
+ int source_usage_arg, int source_alg_arg,
+ int source_type_arg, data_t *source_material,
+ int target_lifetime_arg, int target_id_arg,
+ int target_usage_arg, int target_alg_arg,
+ int target_type_arg, data_t *target_material)
{
psa_key_lifetime_t source_lifetime = source_lifetime_arg;
mbedtls_svc_key_id_t source_id =
- mbedtls_svc_key_id_make( 1, source_id_arg );
+ mbedtls_svc_key_id_make(1, source_id_arg);
psa_key_usage_t source_usage = source_usage_arg;
psa_algorithm_t source_alg = source_alg_arg;
psa_key_type_t source_type = source_type_arg;
mbedtls_svc_key_id_t returned_source_id = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_lifetime_t target_lifetime = target_lifetime_arg;
mbedtls_svc_key_id_t target_id =
- mbedtls_svc_key_id_make( 1, target_id_arg );
+ mbedtls_svc_key_id_make(1, target_id_arg);
psa_key_usage_t target_usage = target_usage_arg;
psa_algorithm_t target_alg = target_alg_arg;
psa_key_type_t target_type = target_type_arg;
@@ -642,96 +631,92 @@
psa_key_attributes_t attributes1 = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t attributes2 = PSA_KEY_ATTRIBUTES_INIT;
- TEST_USES_KEY_ID( source_id );
- TEST_USES_KEY_ID( target_id );
+ TEST_USES_KEY_ID(source_id);
+ TEST_USES_KEY_ID(target_id);
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Populate the source slot. */
- if( ! PSA_KEY_LIFETIME_IS_VOLATILE( source_lifetime ) )
- {
- psa_set_key_id( &attributes, source_id );
- psa_set_key_lifetime( &attributes, source_lifetime );
+ if (!PSA_KEY_LIFETIME_IS_VOLATILE(source_lifetime)) {
+ psa_set_key_id(&attributes, source_id);
+ psa_set_key_lifetime(&attributes, source_lifetime);
}
- psa_set_key_type( &attributes, source_type );
- psa_set_key_usage_flags( &attributes, source_usage );
- psa_set_key_algorithm( &attributes, source_alg );
- PSA_ASSERT( psa_import_key( &attributes,
- source_material->x, source_material->len,
- &returned_source_id ) );
+ psa_set_key_type(&attributes, source_type);
+ psa_set_key_usage_flags(&attributes, source_usage);
+ psa_set_key_algorithm(&attributes, source_alg);
+ PSA_ASSERT(psa_import_key(&attributes,
+ source_material->x, source_material->len,
+ &returned_source_id));
/* Populate the target slot. */
- if( mbedtls_svc_key_id_equal( target_id, source_id ) )
- {
+ if (mbedtls_svc_key_id_equal(target_id, source_id)) {
returned_target_id = returned_source_id;
- }
- else
- {
- psa_set_key_id( &attributes1, target_id );
- psa_set_key_lifetime( &attributes1, target_lifetime );
- psa_set_key_type( &attributes1, target_type );
- psa_set_key_usage_flags( &attributes1, target_usage );
- psa_set_key_algorithm( &attributes1, target_alg );
- PSA_ASSERT( psa_import_key( &attributes1,
- target_material->x, target_material->len,
- &returned_target_id ) );
+ } else {
+ psa_set_key_id(&attributes1, target_id);
+ psa_set_key_lifetime(&attributes1, target_lifetime);
+ psa_set_key_type(&attributes1, target_type);
+ psa_set_key_usage_flags(&attributes1, target_usage);
+ psa_set_key_algorithm(&attributes1, target_alg);
+ PSA_ASSERT(psa_import_key(&attributes1,
+ target_material->x, target_material->len,
+ &returned_target_id));
}
- PSA_ASSERT( psa_get_key_attributes( returned_target_id, &attributes1 ) );
+ PSA_ASSERT(psa_get_key_attributes(returned_target_id, &attributes1));
/* Make a copy attempt. */
- psa_set_key_id( &attributes, target_id );
- psa_set_key_lifetime( &attributes, target_lifetime );
- TEST_EQUAL( psa_copy_key( returned_source_id,
- &attributes, &new_key ),
- PSA_ERROR_ALREADY_EXISTS );
- TEST_ASSERT( mbedtls_svc_key_id_is_null( new_key ) );
+ psa_set_key_id(&attributes, target_id);
+ psa_set_key_lifetime(&attributes, target_lifetime);
+ TEST_EQUAL(psa_copy_key(returned_source_id,
+ &attributes, &new_key),
+ PSA_ERROR_ALREADY_EXISTS);
+ TEST_ASSERT(mbedtls_svc_key_id_is_null(new_key));
/* Test that the target slot is unaffected. */
- PSA_ASSERT( psa_get_key_attributes( returned_target_id, &attributes2 ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal(
- psa_get_key_id( &attributes1 ),
- psa_get_key_id( &attributes2 ) ) );
- TEST_EQUAL( psa_get_key_lifetime( &attributes1 ),
- psa_get_key_lifetime( &attributes2 ) );
- TEST_EQUAL( psa_get_key_type( &attributes1 ),
- psa_get_key_type( &attributes2 ) );
- TEST_EQUAL( psa_get_key_bits( &attributes1 ),
- psa_get_key_bits( &attributes2 ) );
- TEST_EQUAL( psa_get_key_usage_flags( &attributes1 ),
- psa_get_key_usage_flags( &attributes2 ) );
- TEST_EQUAL( psa_get_key_algorithm( &attributes1 ),
- psa_get_key_algorithm( &attributes2 ) );
- if( target_usage & PSA_KEY_USAGE_EXPORT )
- {
+ PSA_ASSERT(psa_get_key_attributes(returned_target_id, &attributes2));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(
+ psa_get_key_id(&attributes1),
+ psa_get_key_id(&attributes2)));
+ TEST_EQUAL(psa_get_key_lifetime(&attributes1),
+ psa_get_key_lifetime(&attributes2));
+ TEST_EQUAL(psa_get_key_type(&attributes1),
+ psa_get_key_type(&attributes2));
+ TEST_EQUAL(psa_get_key_bits(&attributes1),
+ psa_get_key_bits(&attributes2));
+ TEST_EQUAL(psa_get_key_usage_flags(&attributes1),
+ psa_get_key_usage_flags(&attributes2));
+ TEST_EQUAL(psa_get_key_algorithm(&attributes1),
+ psa_get_key_algorithm(&attributes2));
+ if (target_usage & PSA_KEY_USAGE_EXPORT) {
size_t length;
- ASSERT_ALLOC( export_buffer, target_material->len );
- PSA_ASSERT( psa_export_key( returned_target_id, export_buffer,
- target_material->len, &length ) );
- ASSERT_COMPARE( target_material->x, target_material->len,
- export_buffer, length );
+ ASSERT_ALLOC(export_buffer, target_material->len);
+ PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
+ target_material->len, &length));
+ ASSERT_COMPARE(target_material->x, target_material->len,
+ export_buffer, length);
}
- PSA_ASSERT( psa_destroy_key( returned_source_id ) );
- if( ! mbedtls_svc_key_id_equal( target_id, source_id ) )
- PSA_ASSERT( psa_destroy_key( returned_target_id ) );
+ PSA_ASSERT(psa_destroy_key(returned_source_id));
+ if (!mbedtls_svc_key_id_equal(target_id, source_id)) {
+ PSA_ASSERT(psa_destroy_key(returned_target_id));
+ }
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes1 );
- psa_reset_key_attributes( &attributes2 );
+ psa_reset_key_attributes(&attributes1);
+ psa_reset_key_attributes(&attributes2);
- PSA_DONE( );
- mbedtls_free( export_buffer );
+ PSA_DONE();
+ mbedtls_free(export_buffer);
}
/* END_CASE */
/* BEGIN_CASE */
-void invalid_handle( int handle_construction,
- int close_status_arg )
+void invalid_handle(int handle_construction,
+ int close_status_arg)
{
psa_key_handle_t valid_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t invalid_handle = PSA_KEY_HANDLE_INIT;
@@ -740,20 +725,19 @@
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t material[1] = "a";
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
/* Allocate a handle and store a key in it. */
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
- psa_set_key_usage_flags( &attributes, 0 );
- psa_set_key_algorithm( &attributes, 0 );
- PSA_ASSERT( psa_import_key( &attributes,
- material, sizeof( material ),
- &valid_handle ) );
- TEST_ASSERT( ! psa_key_handle_is_null( valid_handle ) );
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
+ psa_set_key_usage_flags(&attributes, 0);
+ psa_set_key_algorithm(&attributes, 0);
+ PSA_ASSERT(psa_import_key(&attributes,
+ material, sizeof(material),
+ &valid_handle));
+ TEST_ASSERT(!psa_key_handle_is_null(valid_handle));
/* Construct an invalid handle as specified in the test case data. */
- switch( handle_construction )
- {
+ switch (handle_construction) {
case INVALID_HANDLE_0:
invalid_handle = PSA_KEY_HANDLE_INIT;
break;
@@ -770,129 +754,129 @@
* unopened and thus invalid identifier.
*/
- if( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( valid_handle ) ==
- PSA_KEY_ID_VOLATILE_MIN )
+ if (MBEDTLS_SVC_KEY_ID_GET_KEY_ID(valid_handle) ==
+ PSA_KEY_ID_VOLATILE_MIN) {
key_id = PSA_KEY_ID_VOLATILE_MIN + 1;
- else
- key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( valid_handle ) - 1;
+ } else {
+ key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID(valid_handle) - 1;
+ }
invalid_handle =
- mbedtls_svc_key_id_make( 0, key_id );
+ mbedtls_svc_key_id_make(0, key_id);
break;
case INVALID_HANDLE_CLOSED:
- PSA_ASSERT( psa_import_key( &attributes,
- material, sizeof( material ),
- &invalid_handle ) );
- PSA_ASSERT( psa_destroy_key( invalid_handle ) );
+ PSA_ASSERT(psa_import_key(&attributes,
+ material, sizeof(material),
+ &invalid_handle));
+ PSA_ASSERT(psa_destroy_key(invalid_handle));
break;
case INVALID_HANDLE_HUGE:
invalid_handle =
- mbedtls_svc_key_id_make( 0, PSA_KEY_ID_VENDOR_MAX + 1 );
+ mbedtls_svc_key_id_make(0, PSA_KEY_ID_VENDOR_MAX + 1);
break;
default:
- TEST_ASSERT( ! "unknown handle construction" );
+ TEST_ASSERT(!"unknown handle construction");
}
/* Attempt to use the invalid handle. */
- TEST_EQUAL( psa_get_key_attributes( invalid_handle, &attributes ),
- PSA_ERROR_INVALID_HANDLE );
- TEST_EQUAL( psa_close_key( invalid_handle ), close_status );
- TEST_EQUAL( psa_destroy_key( invalid_handle ), close_status );
+ TEST_EQUAL(psa_get_key_attributes(invalid_handle, &attributes),
+ PSA_ERROR_INVALID_HANDLE);
+ TEST_EQUAL(psa_close_key(invalid_handle), close_status);
+ TEST_EQUAL(psa_destroy_key(invalid_handle), close_status);
/* After all this, check that the original handle is intact. */
- PSA_ASSERT( psa_get_key_attributes( valid_handle, &attributes ) );
- TEST_EQUAL( psa_get_key_type( &attributes ), PSA_KEY_TYPE_RAW_DATA );
- TEST_EQUAL( psa_get_key_bits( &attributes ),
- PSA_BYTES_TO_BITS( sizeof( material ) ) );
- PSA_ASSERT( psa_close_key( valid_handle ) );
+ PSA_ASSERT(psa_get_key_attributes(valid_handle, &attributes));
+ TEST_EQUAL(psa_get_key_type(&attributes), PSA_KEY_TYPE_RAW_DATA);
+ TEST_EQUAL(psa_get_key_bits(&attributes),
+ PSA_BYTES_TO_BITS(sizeof(material)));
+ PSA_ASSERT(psa_close_key(valid_handle));
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void many_transient_keys( int max_keys_arg )
+void many_transient_keys(int max_keys_arg)
{
mbedtls_svc_key_id_t *keys = NULL;
size_t max_keys = max_keys_arg;
size_t i, j;
psa_status_t status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- uint8_t exported[sizeof( size_t )];
+ uint8_t exported[sizeof(size_t)];
size_t exported_length;
- ASSERT_ALLOC( keys, max_keys );
- PSA_ASSERT( psa_crypto_init( ) );
+ ASSERT_ALLOC(keys, max_keys);
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes, 0 );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes, 0);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
- for( i = 0; i < max_keys; i++ )
- {
- status = psa_import_key( &attributes,
- (uint8_t *) &i, sizeof( i ),
- &keys[i] );
- if( status == PSA_ERROR_INSUFFICIENT_MEMORY )
+ for (i = 0; i < max_keys; i++) {
+ status = psa_import_key(&attributes,
+ (uint8_t *) &i, sizeof(i),
+ &keys[i]);
+ if (status == PSA_ERROR_INSUFFICIENT_MEMORY) {
break;
- PSA_ASSERT( status );
- TEST_ASSERT( ! mbedtls_svc_key_id_is_null( keys[i] ) );
- for( j = 0; j < i; j++ )
- TEST_ASSERT( ! mbedtls_svc_key_id_equal( keys[i], keys[j] ) );
+ }
+ PSA_ASSERT(status);
+ TEST_ASSERT(!mbedtls_svc_key_id_is_null(keys[i]));
+ for (j = 0; j < i; j++) {
+ TEST_ASSERT(!mbedtls_svc_key_id_equal(keys[i], keys[j]));
+ }
}
max_keys = i;
- for( i = 1; i < max_keys; i++ )
- {
- PSA_ASSERT( psa_close_key( keys[i - 1] ) );
- PSA_ASSERT( psa_export_key( keys[i],
- exported, sizeof( exported ),
- &exported_length ) );
- ASSERT_COMPARE( exported, exported_length,
- (uint8_t *) &i, sizeof( i ) );
+ for (i = 1; i < max_keys; i++) {
+ PSA_ASSERT(psa_close_key(keys[i - 1]));
+ PSA_ASSERT(psa_export_key(keys[i],
+ exported, sizeof(exported),
+ &exported_length));
+ ASSERT_COMPARE(exported, exported_length,
+ (uint8_t *) &i, sizeof(i));
}
- PSA_ASSERT( psa_close_key( keys[i - 1] ) );
+ PSA_ASSERT(psa_close_key(keys[i - 1]));
exit:
- PSA_DONE( );
- mbedtls_free( keys );
+ PSA_DONE();
+ mbedtls_free(keys);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */
-void key_slot_eviction_to_import_new_key( int lifetime_arg )
+void key_slot_eviction_to_import_new_key(int lifetime_arg)
{
- psa_key_lifetime_t lifetime = (psa_key_lifetime_t)lifetime_arg;
+ psa_key_lifetime_t lifetime = (psa_key_lifetime_t) lifetime_arg;
size_t i;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- uint8_t exported[sizeof( size_t )];
+ uint8_t exported[sizeof(size_t)];
size_t exported_length;
mbedtls_svc_key_id_t key, returned_key_id;
- PSA_ASSERT( psa_crypto_init( ) );
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
- psa_set_key_algorithm( &attributes, 0 );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
+ psa_set_key_algorithm(&attributes, 0);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
/*
* Create MBEDTLS_PSA_KEY_SLOT_COUNT persistent keys.
*/
- for( i = 0; i < MBEDTLS_PSA_KEY_SLOT_COUNT; i++ )
- {
- key = mbedtls_svc_key_id_make( i, i + 1 );
- psa_set_key_id( &attributes, key );
- PSA_ASSERT( psa_import_key( &attributes,
- (uint8_t *) &i, sizeof( i ),
- &returned_key_id ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( returned_key_id, key ) );
+ for (i = 0; i < MBEDTLS_PSA_KEY_SLOT_COUNT; i++) {
+ key = mbedtls_svc_key_id_make(i, i + 1);
+ psa_set_key_id(&attributes, key);
+ PSA_ASSERT(psa_import_key(&attributes,
+ (uint8_t *) &i, sizeof(i),
+ &returned_key_id));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(returned_key_id, key));
}
/*
@@ -902,18 +886,19 @@
* description in RAM.
*/
i = MBEDTLS_PSA_KEY_SLOT_COUNT;
- key = mbedtls_svc_key_id_make( i, i + 1 );
- psa_set_key_id( &attributes, key );
- psa_set_key_lifetime( &attributes, lifetime );
+ key = mbedtls_svc_key_id_make(i, i + 1);
+ psa_set_key_id(&attributes, key);
+ psa_set_key_lifetime(&attributes, lifetime);
- PSA_ASSERT( psa_import_key( &attributes,
- (uint8_t *) &i, sizeof( i ),
- &returned_key_id ) );
- if( lifetime != PSA_KEY_LIFETIME_VOLATILE )
- TEST_ASSERT( mbedtls_svc_key_id_equal( returned_key_id, key ) );
- else
- TEST_ASSERT( psa_key_id_is_volatile(
- MBEDTLS_SVC_KEY_ID_GET_KEY_ID( returned_key_id ) ) );
+ PSA_ASSERT(psa_import_key(&attributes,
+ (uint8_t *) &i, sizeof(i),
+ &returned_key_id));
+ if (lifetime != PSA_KEY_LIFETIME_VOLATILE) {
+ TEST_ASSERT(mbedtls_svc_key_id_equal(returned_key_id, key));
+ } else {
+ TEST_ASSERT(psa_key_id_is_volatile(
+ MBEDTLS_SVC_KEY_ID_GET_KEY_ID(returned_key_id)));
+ }
/*
* Check that we can export all ( MBEDTLS_PSA_KEY_SLOT_COUNT + 1 ) keys,
@@ -922,120 +907,118 @@
* slots when creating the last key is restored in a RAM slot to export
* its value.
*/
- for( i = 0; i <= MBEDTLS_PSA_KEY_SLOT_COUNT; i++ )
- {
- if( i < MBEDTLS_PSA_KEY_SLOT_COUNT )
- key = mbedtls_svc_key_id_make( i, i + 1 );
- else
+ for (i = 0; i <= MBEDTLS_PSA_KEY_SLOT_COUNT; i++) {
+ if (i < MBEDTLS_PSA_KEY_SLOT_COUNT) {
+ key = mbedtls_svc_key_id_make(i, i + 1);
+ } else {
key = returned_key_id;
+ }
- PSA_ASSERT( psa_export_key( key,
- exported, sizeof( exported ),
- &exported_length ) );
- ASSERT_COMPARE( exported, exported_length,
- (uint8_t *) &i, sizeof( i ) );
- PSA_ASSERT( psa_destroy_key( key ) );
+ PSA_ASSERT(psa_export_key(key,
+ exported, sizeof(exported),
+ &exported_length));
+ ASSERT_COMPARE(exported, exported_length,
+ (uint8_t *) &i, sizeof(i));
+ PSA_ASSERT(psa_destroy_key(key));
}
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */
-void non_reusable_key_slots_integrity_in_case_of_key_slot_starvation( )
+void non_reusable_key_slots_integrity_in_case_of_key_slot_starvation()
{
psa_status_t status;
size_t i;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- uint8_t exported[sizeof( size_t )];
+ uint8_t exported[sizeof(size_t)];
size_t exported_length;
mbedtls_svc_key_id_t persistent_key = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t persistent_key2 = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t returned_key_id = MBEDTLS_SVC_KEY_ID_INIT;
mbedtls_svc_key_id_t *keys = NULL;
- TEST_ASSERT( MBEDTLS_PSA_KEY_SLOT_COUNT >= 1 );
+ TEST_ASSERT(MBEDTLS_PSA_KEY_SLOT_COUNT >= 1);
- ASSERT_ALLOC( keys, MBEDTLS_PSA_KEY_SLOT_COUNT );
- PSA_ASSERT( psa_crypto_init( ) );
+ ASSERT_ALLOC(keys, MBEDTLS_PSA_KEY_SLOT_COUNT);
+ PSA_ASSERT(psa_crypto_init());
- psa_set_key_usage_flags( &attributes,
- PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_COPY );
- psa_set_key_algorithm( &attributes, 0 );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
+ psa_set_key_usage_flags(&attributes,
+ PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_COPY);
+ psa_set_key_algorithm(&attributes, 0);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
/*
* Create a persistent key
*/
- persistent_key = mbedtls_svc_key_id_make( 0x100, 0x205 );
- psa_set_key_id( &attributes, persistent_key );
- PSA_ASSERT( psa_import_key( &attributes,
- (uint8_t *) &persistent_key,
- sizeof( persistent_key ),
- &returned_key_id ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( returned_key_id, persistent_key ) );
+ persistent_key = mbedtls_svc_key_id_make(0x100, 0x205);
+ psa_set_key_id(&attributes, persistent_key);
+ PSA_ASSERT(psa_import_key(&attributes,
+ (uint8_t *) &persistent_key,
+ sizeof(persistent_key),
+ &returned_key_id));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(returned_key_id, persistent_key));
/*
* Create MBEDTLS_PSA_KEY_SLOT_COUNT volatile keys
*/
- psa_set_key_lifetime( &attributes, PSA_KEY_LIFETIME_VOLATILE );
- for( i = 0; i < MBEDTLS_PSA_KEY_SLOT_COUNT; i++ )
- {
- PSA_ASSERT( psa_import_key( &attributes,
- (uint8_t *) &i, sizeof( i ),
- &keys[i]) );
+ psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_VOLATILE);
+ for (i = 0; i < MBEDTLS_PSA_KEY_SLOT_COUNT; i++) {
+ PSA_ASSERT(psa_import_key(&attributes,
+ (uint8_t *) &i, sizeof(i),
+ &keys[i]));
}
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
/*
* Check that we cannot access the persistent key as all slots are
* occupied by volatile keys and the implementation needs to load the
* persistent key description in a slot to be able to access it.
*/
- status = psa_get_key_attributes( persistent_key, &attributes );
- TEST_EQUAL( status, PSA_ERROR_INSUFFICIENT_MEMORY );
+ status = psa_get_key_attributes(persistent_key, &attributes);
+ TEST_EQUAL(status, PSA_ERROR_INSUFFICIENT_MEMORY);
/*
* Check we can export the volatile key created last and that it has the
* expected value. Then, destroy it.
*/
- PSA_ASSERT( psa_export_key( keys[MBEDTLS_PSA_KEY_SLOT_COUNT - 1],
- exported, sizeof( exported ),
- &exported_length ) );
+ PSA_ASSERT(psa_export_key(keys[MBEDTLS_PSA_KEY_SLOT_COUNT - 1],
+ exported, sizeof(exported),
+ &exported_length));
i = MBEDTLS_PSA_KEY_SLOT_COUNT - 1;
- ASSERT_COMPARE( exported, exported_length, (uint8_t *) &i, sizeof( i ) );
- PSA_ASSERT( psa_destroy_key( keys[MBEDTLS_PSA_KEY_SLOT_COUNT - 1] ) );
+ ASSERT_COMPARE(exported, exported_length, (uint8_t *) &i, sizeof(i));
+ PSA_ASSERT(psa_destroy_key(keys[MBEDTLS_PSA_KEY_SLOT_COUNT - 1]));
/*
* Check that we can now access the persistent key again.
*/
- PSA_ASSERT( psa_get_key_attributes( persistent_key, &attributes ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( attributes.core.id,
- persistent_key ) );
+ PSA_ASSERT(psa_get_key_attributes(persistent_key, &attributes));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(attributes.core.id,
+ persistent_key));
/*
* Check that we cannot copy the persistent key as all slots are occupied
* by the persistent key and the volatile keys and the slot containing the
* persistent key cannot be reclaimed as it contains the key to copy.
*/
- persistent_key2 = mbedtls_svc_key_id_make( 0x100, 0x204 );
- psa_set_key_id( &attributes, persistent_key2 );
- status = psa_copy_key( persistent_key, &attributes, &returned_key_id );
- TEST_EQUAL( status, PSA_ERROR_INSUFFICIENT_MEMORY );
+ persistent_key2 = mbedtls_svc_key_id_make(0x100, 0x204);
+ psa_set_key_id(&attributes, persistent_key2);
+ status = psa_copy_key(persistent_key, &attributes, &returned_key_id);
+ TEST_EQUAL(status, PSA_ERROR_INSUFFICIENT_MEMORY);
/*
* Check we can export the remaining volatile keys and that they have the
* expected values.
*/
- for( i = 0; i < ( MBEDTLS_PSA_KEY_SLOT_COUNT - 1 ); i++ )
- {
- PSA_ASSERT( psa_export_key( keys[i],
- exported, sizeof( exported ),
- &exported_length ) );
- ASSERT_COMPARE( exported, exported_length,
- (uint8_t *) &i, sizeof( i ) );
- PSA_ASSERT( psa_destroy_key( keys[i] ) );
+ for (i = 0; i < (MBEDTLS_PSA_KEY_SLOT_COUNT - 1); i++) {
+ PSA_ASSERT(psa_export_key(keys[i],
+ exported, sizeof(exported),
+ &exported_length));
+ ASSERT_COMPARE(exported, exported_length,
+ (uint8_t *) &i, sizeof(i));
+ PSA_ASSERT(psa_destroy_key(keys[i]));
}
/*
@@ -1043,19 +1026,19 @@
* value.
*/
- PSA_ASSERT( psa_export_key( persistent_key, exported, sizeof( exported ),
- &exported_length ) );
- ASSERT_COMPARE( exported, exported_length,
- (uint8_t *) &persistent_key, sizeof( persistent_key ) );
+ PSA_ASSERT(psa_export_key(persistent_key, exported, sizeof(exported),
+ &exported_length));
+ ASSERT_COMPARE(exported, exported_length,
+ (uint8_t *) &persistent_key, sizeof(persistent_key));
exit:
/*
* Key attributes may have been returned by psa_get_key_attributes()
* thus reset them as required.
*/
- psa_reset_key_attributes( &attributes );
+ psa_reset_key_attributes(&attributes);
- psa_destroy_key( persistent_key );
- PSA_DONE( );
- mbedtls_free( keys );
+ psa_destroy_key(persistent_key);
+ PSA_DONE();
+ mbedtls_free(keys);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_storage_format.function b/tests/suites/test_suite_psa_crypto_storage_format.function
index 1fd267a..8434fc1 100644
--- a/tests/suites/test_suite_psa_crypto_storage_format.function
+++ b/tests/suites/test_suite_psa_crypto_storage_format.function
@@ -16,10 +16,10 @@
* On error, including if the key representation in storage differs,
* mark the test case as failed and return 0. On success, return 1.
*/
-static int test_written_key( const psa_key_attributes_t *attributes,
- const data_t *material,
- psa_storage_uid_t uid,
- const data_t *expected_representation )
+static int test_written_key(const psa_key_attributes_t *attributes,
+ const data_t *material,
+ psa_storage_uid_t uid,
+ const data_t *expected_representation)
{
mbedtls_svc_key_id_t created_key_id = MBEDTLS_SVC_KEY_ID_INIT;
uint8_t *actual_representation = NULL;
@@ -28,132 +28,144 @@
int ok = 0;
/* Create a key with the given parameters. */
- PSA_ASSERT( psa_import_key( attributes, material->x, material->len,
- &created_key_id ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( psa_get_key_id( attributes ),
- created_key_id ) );
+ PSA_ASSERT(psa_import_key(attributes, material->x, material->len,
+ &created_key_id));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(psa_get_key_id(attributes),
+ created_key_id));
/* Check that the key is represented as expected. */
- PSA_ASSERT( psa_its_get_info( uid, &storage_info ) );
- TEST_EQUAL( storage_info.size, expected_representation->len );
- ASSERT_ALLOC( actual_representation, storage_info.size );
- PSA_ASSERT( psa_its_get( uid, 0, storage_info.size,
- actual_representation, &length ) );
- ASSERT_COMPARE( expected_representation->x, expected_representation->len,
- actual_representation, length );
+ PSA_ASSERT(psa_its_get_info(uid, &storage_info));
+ TEST_EQUAL(storage_info.size, expected_representation->len);
+ ASSERT_ALLOC(actual_representation, storage_info.size);
+ PSA_ASSERT(psa_its_get(uid, 0, storage_info.size,
+ actual_representation, &length));
+ ASSERT_COMPARE(expected_representation->x, expected_representation->len,
+ actual_representation, length);
ok = 1;
exit:
- mbedtls_free( actual_representation );
- return( ok );
+ mbedtls_free(actual_representation);
+ return ok;
}
/** Check if a key is exportable. */
-static int can_export( const psa_key_attributes_t *attributes )
+static int can_export(const psa_key_attributes_t *attributes)
{
- if( psa_get_key_usage_flags( attributes ) & PSA_KEY_USAGE_EXPORT )
- return( 1 );
- else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( psa_get_key_type( attributes ) ) )
- return( 1 );
- else
- return( 0 );
+ if (psa_get_key_usage_flags(attributes) & PSA_KEY_USAGE_EXPORT) {
+ return 1;
+ } else if (PSA_KEY_TYPE_IS_PUBLIC_KEY(psa_get_key_type(attributes))) {
+ return 1;
+ } else {
+ return 0;
+ }
}
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
-static int is_accelerated_rsa( psa_algorithm_t alg )
+static int is_accelerated_rsa(psa_algorithm_t alg)
{
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN)
- if ( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) )
- return( 1 );
+ if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg)) {
+ return 1;
+ }
#endif
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
- if( PSA_ALG_IS_RSA_PSS( alg ) )
- return( 1 );
+ if (PSA_ALG_IS_RSA_PSS(alg)) {
+ return 1;
+ }
#endif
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP)
- if( PSA_ALG_IS_RSA_OAEP( alg ) )
- return( 1 );
+ if (PSA_ALG_IS_RSA_OAEP(alg)) {
+ return 1;
+ }
#endif
(void) alg;
- return( 0 );
+ return 0;
}
/* Whether the algorithm is implemented as a builtin, i.e. not accelerated,
* and calls mbedtls_md() functions that require the hash algorithm to
* also be built-in. */
-static int is_builtin_calling_md( psa_algorithm_t alg )
+static int is_builtin_calling_md(psa_algorithm_t alg)
{
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
- if( PSA_ALG_IS_RSA_PSS( alg ) )
+ if (PSA_ALG_IS_RSA_PSS(alg))
#if defined(MBEDTLS_MD_C)
- return( 1 );
+ { return 1; }
#else
- return( 0 );
+ { return 0; }
#endif
#endif
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
- if( PSA_ALG_IS_RSA_OAEP( alg ) )
+ if (PSA_ALG_IS_RSA_OAEP(alg))
#if defined(MBEDTLS_MD_C)
- return( 1 );
+ { return 1; }
#else
- return( 0 );
+ { return 0; }
#endif
#endif
#if defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
- if( PSA_ALG_IS_DETERMINISTIC_ECDSA( alg ) )
- return( 1 );
+ if (PSA_ALG_IS_DETERMINISTIC_ECDSA(alg)) {
+ return 1;
+ }
#endif
(void) alg;
- return( 0 );
+ return 0;
}
-static int has_builtin_hash( psa_algorithm_t alg )
+static int has_builtin_hash(psa_algorithm_t alg)
{
#if !defined(MBEDTLS_MD5_C)
- if( alg == PSA_ALG_MD5 )
- return( 0 );
+ if (alg == PSA_ALG_MD5) {
+ return 0;
+ }
#endif
#if !defined(MBEDTLS_RIPEMD160_C)
- if( alg == PSA_ALG_RIPEMD160 )
- return( 0 );
+ if (alg == PSA_ALG_RIPEMD160) {
+ return 0;
+ }
#endif
#if !defined(MBEDTLS_SHA1_C)
- if( alg == PSA_ALG_SHA_1 )
- return( 0 );
+ if (alg == PSA_ALG_SHA_1) {
+ return 0;
+ }
#endif
#if !defined(MBEDTLS_SHA224_C)
- if( alg == PSA_ALG_SHA_224 )
- return( 0 );
+ if (alg == PSA_ALG_SHA_224) {
+ return 0;
+ }
#endif
#if !defined(MBEDTLS_SHA256_C)
- if( alg == PSA_ALG_SHA_256 )
- return( 0 );
+ if (alg == PSA_ALG_SHA_256) {
+ return 0;
+ }
#endif
#if !defined(MBEDTLS_SHA384_C)
- if( alg == PSA_ALG_SHA_384 )
- return( 0 );
+ if (alg == PSA_ALG_SHA_384) {
+ return 0;
+ }
#endif
#if !defined(MBEDTLS_SHA512_C)
- if( alg == PSA_ALG_SHA_512 )
- return( 0 );
+ if (alg == PSA_ALG_SHA_512) {
+ return 0;
+ }
#endif
(void) alg;
- return( 1 );
+ return 1;
}
#endif
/* Mbed TLS doesn't support certain combinations of key type and algorithm
* in certain configurations. */
-static int can_exercise( const psa_key_attributes_t *attributes )
+static int can_exercise(const psa_key_attributes_t *attributes)
{
- psa_key_type_t key_type = psa_get_key_type( attributes );
- psa_algorithm_t alg = psa_get_key_algorithm( attributes );
+ psa_key_type_t key_type = psa_get_key_type(attributes);
+ psa_algorithm_t alg = psa_get_key_algorithm(attributes);
psa_algorithm_t hash_alg =
- PSA_ALG_IS_HASH_AND_SIGN( alg ) ? PSA_ALG_SIGN_GET_HASH( alg ) :
- PSA_ALG_IS_RSA_OAEP( alg ) ? PSA_ALG_RSA_OAEP_GET_HASH( alg ) :
+ PSA_ALG_IS_HASH_AND_SIGN(alg) ? PSA_ALG_SIGN_GET_HASH(alg) :
+ PSA_ALG_IS_RSA_OAEP(alg) ? PSA_ALG_RSA_OAEP_GET_HASH(alg) :
PSA_ALG_NONE;
- psa_key_usage_t usage = psa_get_key_usage_flags( attributes );
+ psa_key_usage_t usage = psa_get_key_usage_flags(attributes);
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
/* We test some configurations using drivers where the driver doesn't
@@ -167,32 +179,28 @@
* affected. All RSA signatures are affected except raw PKCS#1v1.5.
* OAEP is also affected.
*/
- if( PSA_ALG_IS_DETERMINISTIC_ECDSA( alg ) &&
- ! ( usage & ( PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_SIGN_MESSAGE ) ) )
- {
+ if (PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) &&
+ !(usage & (PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_SIGN_MESSAGE))) {
/* Verification only. Verification doesn't use the hash algorithm. */
- return( 1 );
+ return 1;
}
#if defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
- if( PSA_ALG_IS_DETERMINISTIC_ECDSA( alg ) &&
- ( hash_alg == PSA_ALG_MD5 ||
- hash_alg == PSA_ALG_RIPEMD160 ||
- hash_alg == PSA_ALG_SHA_1 ) )
- {
- return( 0 );
+ if (PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) &&
+ (hash_alg == PSA_ALG_MD5 ||
+ hash_alg == PSA_ALG_RIPEMD160 ||
+ hash_alg == PSA_ALG_SHA_1)) {
+ return 0;
}
#endif
- if( is_accelerated_rsa( alg ) &&
- ( hash_alg == PSA_ALG_RIPEMD160 || hash_alg == PSA_ALG_SHA_384 ) )
- {
- return( 0 );
+ if (is_accelerated_rsa(alg) &&
+ (hash_alg == PSA_ALG_RIPEMD160 || hash_alg == PSA_ALG_SHA_384)) {
+ return 0;
}
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP)
- if( PSA_ALG_IS_RSA_OAEP( alg ) &&
- ( hash_alg == PSA_ALG_RIPEMD160 || hash_alg == PSA_ALG_SHA_384 ) )
- {
- return( 0 );
+ if (PSA_ALG_IS_RSA_OAEP(alg) &&
+ (hash_alg == PSA_ALG_RIPEMD160 || hash_alg == PSA_ALG_SHA_384)) {
+ return 0;
}
#endif
@@ -200,9 +208,8 @@
* hash internally only dispatch to the internal md module, not to
* PSA. Until this is supported, don't try to actually perform
* operations when the operation is built-in and the hash isn't. */
- if( is_builtin_calling_md( alg ) && ! has_builtin_hash( hash_alg ) )
- {
- return( 0 );
+ if (is_builtin_calling_md(alg) && !has_builtin_hash(hash_alg)) {
+ return 0;
}
#endif /* MBEDTLS_TEST_LIBTESTDRIVER1 */
@@ -210,7 +217,7 @@
(void) alg;
(void) hash_alg;
(void) usage;
- return( 1 );
+ return 1;
}
/** Write a key with the given representation to storage, then check
@@ -219,78 +226,73 @@
* On error, including if the key representation in storage differs,
* mark the test case as failed and return 0. On success, return 1.
*/
-static int test_read_key( const psa_key_attributes_t *expected_attributes,
- const data_t *expected_material,
- psa_storage_uid_t uid,
- const data_t *representation,
- int flags )
+static int test_read_key(const psa_key_attributes_t *expected_attributes,
+ const data_t *expected_material,
+ psa_storage_uid_t uid,
+ const data_t *representation,
+ int flags)
{
psa_key_attributes_t actual_attributes = PSA_KEY_ATTRIBUTES_INIT;
- mbedtls_svc_key_id_t key_id = psa_get_key_id( expected_attributes );
+ mbedtls_svc_key_id_t key_id = psa_get_key_id(expected_attributes);
struct psa_storage_info_t storage_info;
int ok = 0;
uint8_t *exported_material = NULL;
size_t length;
/* Prime the storage with a key file. */
- PSA_ASSERT( psa_its_set( uid, representation->len, representation->x, 0 ) );
+ PSA_ASSERT(psa_its_set(uid, representation->len, representation->x, 0));
/* Check that the injected key exists and looks as expected. */
- PSA_ASSERT( psa_get_key_attributes( key_id, &actual_attributes ) );
- TEST_ASSERT( mbedtls_svc_key_id_equal( key_id,
- psa_get_key_id( &actual_attributes ) ) );
- TEST_EQUAL( psa_get_key_lifetime( expected_attributes ),
- psa_get_key_lifetime( &actual_attributes ) );
- TEST_EQUAL( psa_get_key_type( expected_attributes ),
- psa_get_key_type( &actual_attributes ) );
- TEST_EQUAL( psa_get_key_bits( expected_attributes ),
- psa_get_key_bits( &actual_attributes ) );
- TEST_EQUAL( psa_get_key_usage_flags( expected_attributes ),
- psa_get_key_usage_flags( &actual_attributes ) );
- TEST_EQUAL( psa_get_key_algorithm( expected_attributes ),
- psa_get_key_algorithm( &actual_attributes ) );
- TEST_EQUAL( psa_get_key_enrollment_algorithm( expected_attributes ),
- psa_get_key_enrollment_algorithm( &actual_attributes ) );
- if( can_export( expected_attributes ) )
- {
- ASSERT_ALLOC( exported_material, expected_material->len );
- PSA_ASSERT( psa_export_key( key_id,
- exported_material, expected_material->len,
- &length ) );
- ASSERT_COMPARE( expected_material->x, expected_material->len,
- exported_material, length );
+ PSA_ASSERT(psa_get_key_attributes(key_id, &actual_attributes));
+ TEST_ASSERT(mbedtls_svc_key_id_equal(key_id,
+ psa_get_key_id(&actual_attributes)));
+ TEST_EQUAL(psa_get_key_lifetime(expected_attributes),
+ psa_get_key_lifetime(&actual_attributes));
+ TEST_EQUAL(psa_get_key_type(expected_attributes),
+ psa_get_key_type(&actual_attributes));
+ TEST_EQUAL(psa_get_key_bits(expected_attributes),
+ psa_get_key_bits(&actual_attributes));
+ TEST_EQUAL(psa_get_key_usage_flags(expected_attributes),
+ psa_get_key_usage_flags(&actual_attributes));
+ TEST_EQUAL(psa_get_key_algorithm(expected_attributes),
+ psa_get_key_algorithm(&actual_attributes));
+ TEST_EQUAL(psa_get_key_enrollment_algorithm(expected_attributes),
+ psa_get_key_enrollment_algorithm(&actual_attributes));
+ if (can_export(expected_attributes)) {
+ ASSERT_ALLOC(exported_material, expected_material->len);
+ PSA_ASSERT(psa_export_key(key_id,
+ exported_material, expected_material->len,
+ &length));
+ ASSERT_COMPARE(expected_material->x, expected_material->len,
+ exported_material, length);
}
- if( ( flags & TEST_FLAG_EXERCISE ) && can_exercise( &actual_attributes ) )
- {
- TEST_ASSERT( mbedtls_test_psa_exercise_key(
- key_id,
- psa_get_key_usage_flags( expected_attributes ),
- psa_get_key_algorithm( expected_attributes ) ) );
+ if ((flags & TEST_FLAG_EXERCISE) && can_exercise(&actual_attributes)) {
+ TEST_ASSERT(mbedtls_test_psa_exercise_key(
+ key_id,
+ psa_get_key_usage_flags(expected_attributes),
+ psa_get_key_algorithm(expected_attributes)));
}
- if( flags & TEST_FLAG_READ_ONLY )
- {
+ if (flags & TEST_FLAG_READ_ONLY) {
/* Read-only keys cannot be removed through the API.
* The key will be removed through ITS in the cleanup code below. */
- TEST_EQUAL( PSA_ERROR_NOT_PERMITTED, psa_destroy_key( key_id ) );
- }
- else
- {
+ TEST_EQUAL(PSA_ERROR_NOT_PERMITTED, psa_destroy_key(key_id));
+ } else {
/* Destroy the key. Confirm through direct access to the storage. */
- PSA_ASSERT( psa_destroy_key( key_id ) );
- TEST_EQUAL( PSA_ERROR_DOES_NOT_EXIST,
- psa_its_get_info( uid, &storage_info ) );
+ PSA_ASSERT(psa_destroy_key(key_id));
+ TEST_EQUAL(PSA_ERROR_DOES_NOT_EXIST,
+ psa_its_get_info(uid, &storage_info));
}
ok = 1;
exit:
- psa_reset_key_attributes( &actual_attributes );
- psa_its_remove( uid );
- mbedtls_free( exported_material );
- return( ok );
+ psa_reset_key_attributes(&actual_attributes);
+ psa_its_remove(uid);
+ mbedtls_free(exported_material);
+ return ok;
}
/* END_HEADER */
@@ -301,10 +303,10 @@
*/
/* BEGIN_CASE */
-void key_storage_save( int lifetime_arg, int type_arg, int bits_arg,
- int usage_arg, int alg_arg, int alg2_arg,
- data_t *material,
- data_t *representation )
+void key_storage_save(int lifetime_arg, int type_arg, int bits_arg,
+ int usage_arg, int alg_arg, int alg2_arg,
+ data_t *material,
+ data_t *representation)
{
/* Forward compatibility: save a key in the current format and
* check that it has the expected format so that future versions
@@ -316,40 +318,40 @@
psa_key_usage_t usage = usage_arg;
psa_algorithm_t alg = alg_arg;
psa_algorithm_t alg2 = alg2_arg;
- mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 0, 1 );
+ mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make(0, 1);
psa_storage_uid_t uid = 1;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_INIT( );
- TEST_USES_KEY_ID( key_id );
+ PSA_INIT();
+ TEST_USES_KEY_ID(key_id);
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_id( &attributes, key_id );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_enrollment_algorithm( &attributes, alg2 );
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_enrollment_algorithm(&attributes, alg2);
/* This is the current storage format. Test that we know exactly how
* the key is stored. The stability of the test data in future
* versions of Mbed TLS will guarantee that future versions
* can read back what this version wrote. */
- TEST_ASSERT( test_written_key( &attributes, material,
- uid, representation ) );
+ TEST_ASSERT(test_written_key(&attributes, material,
+ uid, representation));
exit:
- psa_reset_key_attributes( &attributes );
- psa_destroy_key( key_id );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ psa_destroy_key(key_id);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void key_storage_read( int lifetime_arg, int type_arg, int bits_arg,
- int usage_arg, int alg_arg, int alg2_arg,
- data_t *material,
- data_t *representation, int flags )
+void key_storage_read(int lifetime_arg, int type_arg, int bits_arg,
+ int usage_arg, int alg_arg, int alg2_arg,
+ data_t *material,
+ data_t *representation, int flags)
{
/* Backward compatibility: read a key in the format of a past version
* and check that this version can use it. */
@@ -360,29 +362,29 @@
psa_key_usage_t usage = usage_arg;
psa_algorithm_t alg = alg_arg;
psa_algorithm_t alg2 = alg2_arg;
- mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 0, 1 );
+ mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make(0, 1);
psa_storage_uid_t uid = 1;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- PSA_INIT( );
- TEST_USES_KEY_ID( key_id );
+ PSA_INIT();
+ TEST_USES_KEY_ID(key_id);
- psa_set_key_lifetime( &attributes, lifetime );
- psa_set_key_id( &attributes, key_id );
- psa_set_key_type( &attributes, type );
- psa_set_key_bits( &attributes, bits );
- psa_set_key_usage_flags( &attributes, usage );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_enrollment_algorithm( &attributes, alg2 );
+ psa_set_key_lifetime(&attributes, lifetime);
+ psa_set_key_id(&attributes, key_id);
+ psa_set_key_type(&attributes, type);
+ psa_set_key_bits(&attributes, bits);
+ psa_set_key_usage_flags(&attributes, usage);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_enrollment_algorithm(&attributes, alg2);
/* Test that we can use a key with the given representation. This
* guarantees backward compatibility with keys that were stored by
* past versions of Mbed TLS. */
- TEST_ASSERT( test_read_key( &attributes, material,
- uid, representation, flags ) );
+ TEST_ASSERT(test_read_key(&attributes, material,
+ uid, representation, flags));
exit:
- psa_reset_key_attributes( &attributes );
- PSA_DONE( );
+ psa_reset_key_attributes(&attributes);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_psa_its.function b/tests/suites/test_suite_psa_its.function
index 12878b5..7864b9c 100644
--- a/tests/suites/test_suite_psa_its.function
+++ b/tests/suites/test_suite_psa_its.function
@@ -20,23 +20,23 @@
#define PSA_ITS_STORAGE_FILENAME_PATTERN "%08lx%08lx"
#define PSA_ITS_STORAGE_SUFFIX ".psa_its"
#define PSA_ITS_STORAGE_FILENAME_LENGTH \
- ( sizeof( PSA_ITS_STORAGE_PREFIX ) - 1 + /*prefix without terminating 0*/ \
- 16 + /*UID (64-bit number in hex)*/ \
- 16 + /*UID (64-bit number in hex)*/ \
- sizeof( PSA_ITS_STORAGE_SUFFIX ) - 1 + /*suffix without terminating 0*/ \
- 1 /*terminating null byte*/ )
+ (sizeof(PSA_ITS_STORAGE_PREFIX) - 1 + /*prefix without terminating 0*/ \
+ 16 + /*UID (64-bit number in hex)*/ \
+ 16 + /*UID (64-bit number in hex)*/ \
+ sizeof(PSA_ITS_STORAGE_SUFFIX) - 1 + /*suffix without terminating 0*/ \
+ 1 /*terminating null byte*/)
#define PSA_ITS_STORAGE_TEMP \
PSA_ITS_STORAGE_PREFIX "tempfile" PSA_ITS_STORAGE_SUFFIX
-static void psa_its_fill_filename( psa_storage_uid_t uid, char *filename )
+static void psa_its_fill_filename(psa_storage_uid_t uid, char *filename)
{
/* Break up the UID into two 32-bit pieces so as not to rely on
* long long support in snprintf. */
- mbedtls_snprintf( filename, PSA_ITS_STORAGE_FILENAME_LENGTH,
- "%s" PSA_ITS_STORAGE_FILENAME_PATTERN "%s",
- PSA_ITS_STORAGE_PREFIX,
- (unsigned long) ( uid >> 32 ),
- (unsigned long) ( uid & 0xffffffff ),
- PSA_ITS_STORAGE_SUFFIX );
+ mbedtls_snprintf(filename, PSA_ITS_STORAGE_FILENAME_LENGTH,
+ "%s" PSA_ITS_STORAGE_FILENAME_PATTERN "%s",
+ PSA_ITS_STORAGE_PREFIX,
+ (unsigned long) (uid >> 32),
+ (unsigned long) (uid & 0xffffffff),
+ PSA_ITS_STORAGE_SUFFIX);
}
/* Maximum uid used by the test, recorded so that cleanup() can delete
@@ -44,7 +44,7 @@
* need to and should not be taken into account for uid_max. */
static psa_storage_uid_t uid_max = 0;
-static void cleanup( void )
+static void cleanup(void)
{
/* Call remove() on all the files that a test might have created.
* We ignore the error if the file exists but remove() fails because
@@ -55,25 +55,25 @@
* test case. */
char filename[PSA_ITS_STORAGE_FILENAME_LENGTH];
psa_storage_uid_t uid;
- for( uid = 0; uid < uid_max; uid++ )
- {
- psa_its_fill_filename( uid, filename );
- (void) remove( filename );
+ for (uid = 0; uid < uid_max; uid++) {
+ psa_its_fill_filename(uid, filename);
+ (void) remove(filename);
}
- psa_its_fill_filename( (psa_storage_uid_t)( -1 ), filename );
- (void) remove( filename );
- (void) remove( PSA_ITS_STORAGE_TEMP );
+ psa_its_fill_filename((psa_storage_uid_t) (-1), filename);
+ (void) remove(filename);
+ (void) remove(PSA_ITS_STORAGE_TEMP);
uid_max = 0;
}
-static psa_status_t psa_its_set_wrap( psa_storage_uid_t uid,
- uint32_t data_length,
- const void *p_data,
- psa_storage_create_flags_t create_flags )
+static psa_status_t psa_its_set_wrap(psa_storage_uid_t uid,
+ uint32_t data_length,
+ const void *p_data,
+ psa_storage_create_flags_t create_flags)
{
- if( uid_max != (psa_storage_uid_t)( -1 ) && uid_max < uid )
+ if (uid_max != (psa_storage_uid_t) (-1) && uid_max < uid) {
uid_max = uid;
- return( psa_its_set( uid, data_length, p_data, create_flags ) );
+ }
+ return psa_its_set(uid, data_length, p_data, create_flags);
}
/* END_HEADER */
@@ -84,7 +84,7 @@
*/
/* BEGIN_CASE */
-void set_get_remove( int uid_arg, int flags_arg, data_t *data )
+void set_get_remove(int uid_arg, int flags_arg, data_t *data)
{
psa_storage_uid_t uid = uid_arg;
uint32_t flags = flags_arg;
@@ -92,28 +92,28 @@
unsigned char *buffer = NULL;
size_t ret_len = 0;
- ASSERT_ALLOC( buffer, data->len );
+ ASSERT_ALLOC(buffer, data->len);
- PSA_ASSERT( psa_its_set_wrap( uid, data->len, data->x, flags ) );
+ PSA_ASSERT(psa_its_set_wrap(uid, data->len, data->x, flags));
- PSA_ASSERT( psa_its_get_info( uid, &info ) );
- TEST_ASSERT( info.size == data->len );
- TEST_ASSERT( info.flags == flags );
- PSA_ASSERT( psa_its_get( uid, 0, data->len, buffer, &ret_len ) );
- ASSERT_COMPARE( data->x, data->len, buffer, ret_len );
+ PSA_ASSERT(psa_its_get_info(uid, &info));
+ TEST_ASSERT(info.size == data->len);
+ TEST_ASSERT(info.flags == flags);
+ PSA_ASSERT(psa_its_get(uid, 0, data->len, buffer, &ret_len));
+ ASSERT_COMPARE(data->x, data->len, buffer, ret_len);
- PSA_ASSERT( psa_its_remove( uid ) );
+ PSA_ASSERT(psa_its_remove(uid));
exit:
- mbedtls_free( buffer );
- cleanup( );
+ mbedtls_free(buffer);
+ cleanup();
}
/* END_CASE */
/* BEGIN_CASE */
-void set_overwrite( int uid_arg,
- int flags1_arg, data_t *data1,
- int flags2_arg, data_t *data2 )
+void set_overwrite(int uid_arg,
+ int flags1_arg, data_t *data1,
+ int flags2_arg, data_t *data2)
{
psa_storage_uid_t uid = uid_arg;
uint32_t flags1 = flags1_arg;
@@ -122,33 +122,33 @@
unsigned char *buffer = NULL;
size_t ret_len = 0;
- ASSERT_ALLOC( buffer, MAX( data1->len, data2->len ) );
+ ASSERT_ALLOC(buffer, MAX(data1->len, data2->len));
- PSA_ASSERT( psa_its_set_wrap( uid, data1->len, data1->x, flags1 ) );
- PSA_ASSERT( psa_its_get_info( uid, &info ) );
- TEST_ASSERT( info.size == data1->len );
- TEST_ASSERT( info.flags == flags1 );
- PSA_ASSERT( psa_its_get( uid, 0, data1->len, buffer, &ret_len ) );
- ASSERT_COMPARE( data1->x, data1->len, buffer, ret_len );
+ PSA_ASSERT(psa_its_set_wrap(uid, data1->len, data1->x, flags1));
+ PSA_ASSERT(psa_its_get_info(uid, &info));
+ TEST_ASSERT(info.size == data1->len);
+ TEST_ASSERT(info.flags == flags1);
+ PSA_ASSERT(psa_its_get(uid, 0, data1->len, buffer, &ret_len));
+ ASSERT_COMPARE(data1->x, data1->len, buffer, ret_len);
- PSA_ASSERT( psa_its_set_wrap( uid, data2->len, data2->x, flags2 ) );
- PSA_ASSERT( psa_its_get_info( uid, &info ) );
- TEST_ASSERT( info.size == data2->len );
- TEST_ASSERT( info.flags == flags2 );
+ PSA_ASSERT(psa_its_set_wrap(uid, data2->len, data2->x, flags2));
+ PSA_ASSERT(psa_its_get_info(uid, &info));
+ TEST_ASSERT(info.size == data2->len);
+ TEST_ASSERT(info.flags == flags2);
ret_len = 0;
- PSA_ASSERT( psa_its_get( uid, 0, data2->len, buffer, &ret_len ) );
- ASSERT_COMPARE( data2->x, data2->len, buffer, ret_len );
+ PSA_ASSERT(psa_its_get(uid, 0, data2->len, buffer, &ret_len));
+ ASSERT_COMPARE(data2->x, data2->len, buffer, ret_len);
- PSA_ASSERT( psa_its_remove( uid ) );
+ PSA_ASSERT(psa_its_remove(uid));
exit:
- mbedtls_free( buffer );
- cleanup( );
+ mbedtls_free(buffer);
+ cleanup();
}
/* END_CASE */
/* BEGIN_CASE */
-void set_multiple( int first_id, int count )
+void set_multiple(int first_id, int count)
{
psa_storage_uid_t uid0 = first_id;
psa_storage_uid_t uid;
@@ -156,58 +156,55 @@
char retrieved[40];
size_t ret_len = 0;
- memset( stored, '.', sizeof( stored ) );
- for( uid = uid0; uid < uid0 + count; uid++ )
- {
- mbedtls_snprintf( stored, sizeof( stored ),
- "Content of file 0x%08lx", (unsigned long) uid );
- PSA_ASSERT( psa_its_set_wrap( uid, sizeof( stored ), stored, 0 ) );
+ memset(stored, '.', sizeof(stored));
+ for (uid = uid0; uid < uid0 + count; uid++) {
+ mbedtls_snprintf(stored, sizeof(stored),
+ "Content of file 0x%08lx", (unsigned long) uid);
+ PSA_ASSERT(psa_its_set_wrap(uid, sizeof(stored), stored, 0));
}
- for( uid = uid0; uid < uid0 + count; uid++ )
- {
- mbedtls_snprintf( stored, sizeof( stored ),
- "Content of file 0x%08lx", (unsigned long) uid );
- PSA_ASSERT( psa_its_get( uid, 0, sizeof( stored ), retrieved, &ret_len ) );
- ASSERT_COMPARE( retrieved, ret_len,
- stored, sizeof( stored ) );
- PSA_ASSERT( psa_its_remove( uid ) );
- TEST_ASSERT( psa_its_get( uid, 0, 0, NULL, NULL ) ==
- PSA_ERROR_DOES_NOT_EXIST );
+ for (uid = uid0; uid < uid0 + count; uid++) {
+ mbedtls_snprintf(stored, sizeof(stored),
+ "Content of file 0x%08lx", (unsigned long) uid);
+ PSA_ASSERT(psa_its_get(uid, 0, sizeof(stored), retrieved, &ret_len));
+ ASSERT_COMPARE(retrieved, ret_len,
+ stored, sizeof(stored));
+ PSA_ASSERT(psa_its_remove(uid));
+ TEST_ASSERT(psa_its_get(uid, 0, 0, NULL, NULL) ==
+ PSA_ERROR_DOES_NOT_EXIST);
}
exit:
- cleanup( );
+ cleanup();
}
/* END_CASE */
/* BEGIN_CASE */
-void nonexistent( int uid_arg, int create_and_remove )
+void nonexistent(int uid_arg, int create_and_remove)
{
psa_storage_uid_t uid = uid_arg;
struct psa_storage_info_t info;
- if( create_and_remove )
- {
- PSA_ASSERT( psa_its_set_wrap( uid, 0, NULL, 0 ) );
- PSA_ASSERT( psa_its_remove( uid ) );
+ if (create_and_remove) {
+ PSA_ASSERT(psa_its_set_wrap(uid, 0, NULL, 0));
+ PSA_ASSERT(psa_its_remove(uid));
}
- TEST_ASSERT( psa_its_remove( uid ) == PSA_ERROR_DOES_NOT_EXIST );
- TEST_ASSERT( psa_its_get_info( uid, &info ) ==
- PSA_ERROR_DOES_NOT_EXIST );
- TEST_ASSERT( psa_its_get( uid, 0, 0, NULL, NULL ) ==
- PSA_ERROR_DOES_NOT_EXIST );
+ TEST_ASSERT(psa_its_remove(uid) == PSA_ERROR_DOES_NOT_EXIST);
+ TEST_ASSERT(psa_its_get_info(uid, &info) ==
+ PSA_ERROR_DOES_NOT_EXIST);
+ TEST_ASSERT(psa_its_get(uid, 0, 0, NULL, NULL) ==
+ PSA_ERROR_DOES_NOT_EXIST);
exit:
- cleanup( );
+ cleanup();
}
/* END_CASE */
/* BEGIN_CASE */
-void get_at( int uid_arg, data_t *data,
- int offset, int length_arg,
- int expected_status )
+void get_at(int uid_arg, data_t *data,
+ int offset, int length_arg,
+ int expected_status)
{
psa_storage_uid_t uid = uid_arg;
unsigned char *buffer = NULL;
@@ -217,31 +214,33 @@
size_t i;
size_t ret_len = 0;
- ASSERT_ALLOC( buffer, length + 16 );
+ ASSERT_ALLOC(buffer, length + 16);
trailer = buffer + length;
- memset( trailer, '-', 16 );
+ memset(trailer, '-', 16);
- PSA_ASSERT( psa_its_set_wrap( uid, data->len, data->x, 0 ) );
+ PSA_ASSERT(psa_its_set_wrap(uid, data->len, data->x, 0));
- status = psa_its_get( uid, offset, length_arg, buffer, &ret_len );
- TEST_ASSERT( status == (psa_status_t) expected_status );
- if( status == PSA_SUCCESS )
- ASSERT_COMPARE( data->x + offset, (size_t) length_arg,
- buffer, ret_len );
- for( i = 0; i < 16; i++ )
- TEST_ASSERT( trailer[i] == '-' );
- PSA_ASSERT( psa_its_remove( uid ) );
+ status = psa_its_get(uid, offset, length_arg, buffer, &ret_len);
+ TEST_ASSERT(status == (psa_status_t) expected_status);
+ if (status == PSA_SUCCESS) {
+ ASSERT_COMPARE(data->x + offset, (size_t) length_arg,
+ buffer, ret_len);
+ }
+ for (i = 0; i < 16; i++) {
+ TEST_ASSERT(trailer[i] == '-');
+ }
+ PSA_ASSERT(psa_its_remove(uid));
exit:
- mbedtls_free( buffer );
- cleanup( );
+ mbedtls_free(buffer);
+ cleanup();
}
/* END_CASE */
/* BEGIN_CASE */
-void get_fail( int uid_arg, data_t *data,
- int overwrite_magic, int cut_header,
- int expected_status )
+void get_fail(int uid_arg, data_t *data,
+ int overwrite_magic, int cut_header,
+ int expected_status)
{
psa_storage_uid_t uid = uid_arg;
unsigned char *buffer = NULL;
@@ -252,54 +251,53 @@
FILE *stream = NULL;
char bad_char = 'X';
- PSA_ASSERT( psa_its_set_wrap( uid, data->len, data->x, 0 ) );
+ PSA_ASSERT(psa_its_set_wrap(uid, data->len, data->x, 0));
- psa_its_fill_filename( uid, filename );
- stream = fopen( filename, "rb+" );
- TEST_ASSERT( NULL != stream );
- if( 0 != overwrite_magic )
- {
+ psa_its_fill_filename(uid, filename);
+ stream = fopen(filename, "rb+");
+ TEST_ASSERT(NULL != stream);
+ if (0 != overwrite_magic) {
/* Overwrite the 1st byte of the file, the ITS magic number */
- TEST_ASSERT( fseek( stream, 0, SEEK_SET ) == 0 );
- n = fwrite( &bad_char, 1, 1, stream );
- TEST_ASSERT( 1 == n );
+ TEST_ASSERT(fseek(stream, 0, SEEK_SET) == 0);
+ n = fwrite(&bad_char, 1, 1, stream);
+ TEST_ASSERT(1 == n);
}
- if( 0 != cut_header )
- {
+ if (0 != cut_header) {
/* Reopen file and truncate it to 0 byte by specifying the 'w' flag */
- stream = freopen( filename, "wb", stream );
- TEST_ASSERT( NULL != stream );
+ stream = freopen(filename, "wb", stream);
+ TEST_ASSERT(NULL != stream);
}
- fclose( stream );
+ fclose(stream);
stream = NULL;
- status = psa_its_get( uid, 0, 0, buffer, &ret_len );
- TEST_ASSERT( status == (psa_status_t) expected_status );
- TEST_ASSERT( 0 == ret_len );
- PSA_ASSERT( psa_its_remove( uid ) );
+ status = psa_its_get(uid, 0, 0, buffer, &ret_len);
+ TEST_ASSERT(status == (psa_status_t) expected_status);
+ TEST_ASSERT(0 == ret_len);
+ PSA_ASSERT(psa_its_remove(uid));
/* Check if the file is really deleted. */
- stream = fopen( filename, "rb" );
- TEST_ASSERT( NULL == stream );
+ stream = fopen(filename, "rb");
+ TEST_ASSERT(NULL == stream);
exit:
- if( stream != NULL )
- fclose( stream );
+ if (stream != NULL) {
+ fclose(stream);
+ }
- mbedtls_free( buffer );
- cleanup( );
+ mbedtls_free(buffer);
+ cleanup();
}
/* END_CASE */
/* BEGIN_CASE */
-void set_fail( int uid_arg, data_t *data,
- int expected_status )
+void set_fail(int uid_arg, data_t *data,
+ int expected_status)
{
psa_storage_uid_t uid = uid_arg;
- TEST_ASSERT( psa_its_set_wrap( uid, data->len, data->x, 0 ) ==
- (psa_status_t) expected_status );
+ TEST_ASSERT(psa_its_set_wrap(uid, data->len, data->x, 0) ==
+ (psa_status_t) expected_status);
- exit:
- cleanup( );
+exit:
+ cleanup();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_random.function b/tests/suites/test_suite_random.function
index c532c8a..3026bae 100644
--- a/tests/suites/test_suite_random.function
+++ b/tests/suites/test_suite_random.function
@@ -19,7 +19,7 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_C:MBEDTLS_CTR_DRBG_C */
-void random_twice_with_ctr_drbg( )
+void random_twice_with_ctr_drbg()
{
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context drbg;
@@ -27,176 +27,176 @@
unsigned char output2[OUTPUT_SIZE];
/* First round */
- mbedtls_entropy_init( &entropy );
- mbedtls_ctr_drbg_init( &drbg );
- TEST_EQUAL( 0, mbedtls_ctr_drbg_seed( &drbg,
- mbedtls_entropy_func, &entropy,
- NULL, 0 ) );
- TEST_EQUAL( 0, mbedtls_ctr_drbg_random( &drbg,
- output1, sizeof( output1 ) ) );
- mbedtls_ctr_drbg_free( &drbg );
- mbedtls_entropy_free( &entropy );
+ mbedtls_entropy_init(&entropy);
+ mbedtls_ctr_drbg_init(&drbg);
+ TEST_EQUAL(0, mbedtls_ctr_drbg_seed(&drbg,
+ mbedtls_entropy_func, &entropy,
+ NULL, 0));
+ TEST_EQUAL(0, mbedtls_ctr_drbg_random(&drbg,
+ output1, sizeof(output1)));
+ mbedtls_ctr_drbg_free(&drbg);
+ mbedtls_entropy_free(&entropy);
/* Second round */
- mbedtls_entropy_init( &entropy );
- mbedtls_ctr_drbg_init( &drbg );
- TEST_EQUAL( 0, mbedtls_ctr_drbg_seed( &drbg,
- mbedtls_entropy_func, &entropy,
- NULL, 0 ) );
- TEST_EQUAL( 0, mbedtls_ctr_drbg_random( &drbg,
- output2, sizeof( output2 ) ) );
- mbedtls_ctr_drbg_free( &drbg );
- mbedtls_entropy_free( &entropy );
+ mbedtls_entropy_init(&entropy);
+ mbedtls_ctr_drbg_init(&drbg);
+ TEST_EQUAL(0, mbedtls_ctr_drbg_seed(&drbg,
+ mbedtls_entropy_func, &entropy,
+ NULL, 0));
+ TEST_EQUAL(0, mbedtls_ctr_drbg_random(&drbg,
+ output2, sizeof(output2)));
+ mbedtls_ctr_drbg_free(&drbg);
+ mbedtls_entropy_free(&entropy);
/* The two rounds must generate different random data. */
- TEST_ASSERT( memcmp( output1, output2, OUTPUT_SIZE ) != 0 );
+ TEST_ASSERT(memcmp(output1, output2, OUTPUT_SIZE) != 0);
exit:
- mbedtls_ctr_drbg_free( &drbg );
- mbedtls_entropy_free( &entropy );
+ mbedtls_ctr_drbg_free(&drbg);
+ mbedtls_entropy_free(&entropy);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_C:MBEDTLS_HMAC_DRBG_C */
-void random_twice_with_hmac_drbg( int md_type )
+void random_twice_with_hmac_drbg(int md_type)
{
mbedtls_entropy_context entropy;
mbedtls_hmac_drbg_context drbg;
unsigned char output1[OUTPUT_SIZE];
unsigned char output2[OUTPUT_SIZE];
- const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_type );
+ const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(md_type);
/* First round */
- mbedtls_entropy_init( &entropy );
- mbedtls_hmac_drbg_init( &drbg );
- TEST_EQUAL( 0, mbedtls_hmac_drbg_seed( &drbg, md_info,
- mbedtls_entropy_func, &entropy,
- NULL, 0 ) );
- TEST_EQUAL( 0, mbedtls_hmac_drbg_random( &drbg,
- output1, sizeof( output1 ) ) );
- mbedtls_hmac_drbg_free( &drbg );
- mbedtls_entropy_free( &entropy );
+ mbedtls_entropy_init(&entropy);
+ mbedtls_hmac_drbg_init(&drbg);
+ TEST_EQUAL(0, mbedtls_hmac_drbg_seed(&drbg, md_info,
+ mbedtls_entropy_func, &entropy,
+ NULL, 0));
+ TEST_EQUAL(0, mbedtls_hmac_drbg_random(&drbg,
+ output1, sizeof(output1)));
+ mbedtls_hmac_drbg_free(&drbg);
+ mbedtls_entropy_free(&entropy);
/* Second round */
- mbedtls_entropy_init( &entropy );
- mbedtls_hmac_drbg_init( &drbg );
- TEST_EQUAL( 0, mbedtls_hmac_drbg_seed( &drbg, md_info,
- mbedtls_entropy_func, &entropy,
- NULL, 0 ) );
- TEST_EQUAL( 0, mbedtls_hmac_drbg_random( &drbg,
- output2, sizeof( output2 ) ) );
- mbedtls_hmac_drbg_free( &drbg );
- mbedtls_entropy_free( &entropy );
+ mbedtls_entropy_init(&entropy);
+ mbedtls_hmac_drbg_init(&drbg);
+ TEST_EQUAL(0, mbedtls_hmac_drbg_seed(&drbg, md_info,
+ mbedtls_entropy_func, &entropy,
+ NULL, 0));
+ TEST_EQUAL(0, mbedtls_hmac_drbg_random(&drbg,
+ output2, sizeof(output2)));
+ mbedtls_hmac_drbg_free(&drbg);
+ mbedtls_entropy_free(&entropy);
/* The two rounds must generate different random data. */
- TEST_ASSERT( memcmp( output1, output2, OUTPUT_SIZE ) != 0 );
+ TEST_ASSERT(memcmp(output1, output2, OUTPUT_SIZE) != 0);
exit:
- mbedtls_hmac_drbg_free( &drbg );
- mbedtls_entropy_free( &entropy );
+ mbedtls_hmac_drbg_free(&drbg);
+ mbedtls_entropy_free(&entropy);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_C:!MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void random_twice_with_psa_from_classic( )
+void random_twice_with_psa_from_classic()
{
unsigned char output1[OUTPUT_SIZE];
unsigned char output2[OUTPUT_SIZE];
/* First round */
- PSA_ASSERT( psa_crypto_init( ) );
- TEST_EQUAL( 0, mbedtls_psa_get_random( MBEDTLS_PSA_RANDOM_STATE,
- output1, sizeof( output1 ) ) );
- PSA_DONE( );
+ PSA_ASSERT(psa_crypto_init());
+ TEST_EQUAL(0, mbedtls_psa_get_random(MBEDTLS_PSA_RANDOM_STATE,
+ output1, sizeof(output1)));
+ PSA_DONE();
/* Second round */
- PSA_ASSERT( psa_crypto_init( ) );
- TEST_EQUAL( 0, mbedtls_psa_get_random( MBEDTLS_PSA_RANDOM_STATE,
- output2, sizeof( output2 ) ) );
- PSA_DONE( );
+ PSA_ASSERT(psa_crypto_init());
+ TEST_EQUAL(0, mbedtls_psa_get_random(MBEDTLS_PSA_RANDOM_STATE,
+ output2, sizeof(output2)));
+ PSA_DONE();
/* The two rounds must generate different random data. */
- TEST_ASSERT( memcmp( output1, output2, OUTPUT_SIZE ) != 0 );
+ TEST_ASSERT(memcmp(output1, output2, OUTPUT_SIZE) != 0);
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_C:!MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
-void random_twice_with_psa_from_psa( )
+void random_twice_with_psa_from_psa()
{
unsigned char output1[OUTPUT_SIZE];
unsigned char output2[OUTPUT_SIZE];
/* First round */
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_ASSERT( psa_generate_random( output1, sizeof( output1 ) ) );
- PSA_DONE( );
+ PSA_ASSERT(psa_crypto_init());
+ PSA_ASSERT(psa_generate_random(output1, sizeof(output1)));
+ PSA_DONE();
/* Second round */
- PSA_ASSERT( psa_crypto_init( ) );
- PSA_ASSERT( psa_generate_random( output2, sizeof( output2 ) ) );
- PSA_DONE( );
+ PSA_ASSERT(psa_crypto_init());
+ PSA_ASSERT(psa_generate_random(output2, sizeof(output2)));
+ PSA_DONE();
/* The two rounds must generate different random data. */
- TEST_ASSERT( memcmp( output1, output2, OUTPUT_SIZE ) != 0 );
+ TEST_ASSERT(memcmp(output1, output2, OUTPUT_SIZE) != 0);
exit:
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_C */
-void mbedtls_psa_get_random_no_init( )
+void mbedtls_psa_get_random_no_init()
{
unsigned char output[1];
- TEST_ASSERT( mbedtls_psa_get_random( MBEDTLS_PSA_RANDOM_STATE,
- output, sizeof( output ) ) != 0 );
+ TEST_ASSERT(mbedtls_psa_get_random(MBEDTLS_PSA_RANDOM_STATE,
+ output, sizeof(output)) != 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_C */
-void mbedtls_psa_get_random_length( int n )
+void mbedtls_psa_get_random_length(int n)
{
unsigned char *output = NULL;
- PSA_ASSERT( psa_crypto_init( ) );
- ASSERT_ALLOC( output, n );
+ PSA_ASSERT(psa_crypto_init());
+ ASSERT_ALLOC(output, n);
- TEST_EQUAL( 0, mbedtls_psa_get_random( MBEDTLS_PSA_RANDOM_STATE,
- output, n ) );
+ TEST_EQUAL(0, mbedtls_psa_get_random(MBEDTLS_PSA_RANDOM_STATE,
+ output, n));
exit:
- mbedtls_free( output );
- PSA_DONE( );
+ mbedtls_free(output);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_ECDSA_C */
-void mbedtls_psa_get_random_ecdsa_sign( int curve )
+void mbedtls_psa_get_random_ecdsa_sign(int curve)
{
mbedtls_ecp_group grp;
mbedtls_mpi d, r, s;
unsigned char buf[] = "This is not a hash.";
- mbedtls_ecp_group_init( &grp );
- mbedtls_mpi_init( &d );
- mbedtls_mpi_init( &r );
- mbedtls_mpi_init( &s );
+ mbedtls_ecp_group_init(&grp);
+ mbedtls_mpi_init(&d);
+ mbedtls_mpi_init(&r);
+ mbedtls_mpi_init(&s);
- TEST_EQUAL( 0, mbedtls_mpi_lset( &d, 123456789 ) );
- TEST_EQUAL( 0, mbedtls_ecp_group_load( &grp, curve ) );
- PSA_ASSERT( psa_crypto_init( ) );
- TEST_EQUAL( 0, mbedtls_ecdsa_sign( &grp, &r, &s, &d,
- buf, sizeof( buf ),
- mbedtls_psa_get_random,
- MBEDTLS_PSA_RANDOM_STATE ) );
+ TEST_EQUAL(0, mbedtls_mpi_lset(&d, 123456789));
+ TEST_EQUAL(0, mbedtls_ecp_group_load(&grp, curve));
+ PSA_ASSERT(psa_crypto_init());
+ TEST_EQUAL(0, mbedtls_ecdsa_sign(&grp, &r, &s, &d,
+ buf, sizeof(buf),
+ mbedtls_psa_get_random,
+ MBEDTLS_PSA_RANDOM_STATE));
exit:
- mbedtls_mpi_free( &d );
- mbedtls_mpi_free( &r );
- mbedtls_mpi_free( &s );
- mbedtls_ecp_group_free( &grp );
- PSA_DONE( );
+ mbedtls_mpi_free(&d);
+ mbedtls_mpi_free(&r);
+ mbedtls_mpi_free(&s);
+ mbedtls_ecp_group_free(&grp);
+ PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function
index 65731ed..a2fe6c8 100644
--- a/tests/suites/test_suite_rsa.function
+++ b/tests/suites/test_suite_rsa.function
@@ -11,131 +11,131 @@
*/
/* BEGIN_CASE */
-void rsa_invalid_param( )
+void rsa_invalid_param()
{
mbedtls_rsa_context ctx;
const int invalid_padding = 42;
const int invalid_hash_id = 0xff;
- unsigned char buf[] = {0x00,0x01,0x02,0x03,0x04,0x05};
- size_t buf_len = sizeof( buf );
+ unsigned char buf[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
+ size_t buf_len = sizeof(buf);
- mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init(&ctx);
- TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
- invalid_padding,
- MBEDTLS_MD_NONE ),
- MBEDTLS_ERR_RSA_INVALID_PADDING );
+ TEST_EQUAL(mbedtls_rsa_set_padding(&ctx,
+ invalid_padding,
+ MBEDTLS_MD_NONE),
+ MBEDTLS_ERR_RSA_INVALID_PADDING);
- TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V21,
- invalid_hash_id ),
- MBEDTLS_ERR_RSA_INVALID_PADDING );
+ TEST_EQUAL(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V21,
+ invalid_hash_id),
+ MBEDTLS_ERR_RSA_INVALID_PADDING);
- TEST_EQUAL( mbedtls_rsa_pkcs1_sign(&ctx, NULL,
- NULL, MBEDTLS_MD_NONE,
- buf_len,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_pkcs1_sign(&ctx, NULL,
+ NULL, MBEDTLS_MD_NONE,
+ buf_len,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_pkcs1_sign(&ctx, NULL,
- NULL, MBEDTLS_MD_SHA256,
- 0,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_pkcs1_sign(&ctx, NULL,
+ NULL, MBEDTLS_MD_SHA256,
+ 0,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_pkcs1_verify(&ctx, MBEDTLS_MD_NONE,
- buf_len,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_pkcs1_verify(&ctx, MBEDTLS_MD_NONE,
+ buf_len,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_pkcs1_verify(&ctx, MBEDTLS_MD_SHA256,
- 0,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_pkcs1_verify(&ctx, MBEDTLS_MD_SHA256,
+ 0,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
#if !defined(MBEDTLS_PKCS1_V15)
- TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V15,
- MBEDTLS_MD_NONE ),
- MBEDTLS_ERR_RSA_INVALID_PADDING );
+ TEST_EQUAL(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V15,
+ MBEDTLS_MD_NONE),
+ MBEDTLS_ERR_RSA_INVALID_PADDING);
#endif
#if defined(MBEDTLS_PKCS1_V15)
- TEST_EQUAL( mbedtls_rsa_rsassa_pkcs1_v15_sign(&ctx, NULL,
- NULL, MBEDTLS_MD_NONE,
- buf_len,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pkcs1_v15_sign(&ctx, NULL,
+ NULL, MBEDTLS_MD_NONE,
+ buf_len,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pkcs1_v15_sign(&ctx, NULL,
- NULL, MBEDTLS_MD_SHA256,
- 0,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pkcs1_v15_sign(&ctx, NULL,
+ NULL, MBEDTLS_MD_SHA256,
+ 0,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pkcs1_v15_verify(&ctx, MBEDTLS_MD_NONE,
- buf_len,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pkcs1_v15_verify(&ctx, MBEDTLS_MD_NONE,
+ buf_len,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pkcs1_v15_verify(&ctx, MBEDTLS_MD_SHA256,
- 0,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pkcs1_v15_verify(&ctx, MBEDTLS_MD_SHA256,
+ 0,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
#endif
#if !defined(MBEDTLS_PKCS1_V21)
- TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
- MBEDTLS_RSA_PKCS_V21,
- MBEDTLS_MD_NONE ),
- MBEDTLS_ERR_RSA_INVALID_PADDING );
+ TEST_EQUAL(mbedtls_rsa_set_padding(&ctx,
+ MBEDTLS_RSA_PKCS_V21,
+ MBEDTLS_MD_NONE),
+ MBEDTLS_ERR_RSA_INVALID_PADDING);
#endif
#if defined(MBEDTLS_PKCS1_V21)
- TEST_EQUAL( mbedtls_rsa_rsassa_pss_sign_ext(&ctx, NULL, NULL,
- MBEDTLS_MD_NONE, buf_len,
- NULL, buf_len,
- buf ),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pss_sign_ext(&ctx, NULL, NULL,
+ MBEDTLS_MD_NONE, buf_len,
+ NULL, buf_len,
+ buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pss_sign_ext(&ctx, NULL, NULL,
- MBEDTLS_MD_SHA256, 0,
- NULL, buf_len,
- buf ),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pss_sign_ext(&ctx, NULL, NULL,
+ MBEDTLS_MD_SHA256, 0,
+ NULL, buf_len,
+ buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pss_verify_ext(&ctx, MBEDTLS_MD_NONE,
- buf_len, NULL,
- MBEDTLS_MD_NONE,
- buf_len, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pss_verify_ext(&ctx, MBEDTLS_MD_NONE,
+ buf_len, NULL,
+ MBEDTLS_MD_NONE,
+ buf_len, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pss_verify_ext(&ctx, MBEDTLS_MD_SHA256,
- 0, NULL,
- MBEDTLS_MD_NONE,
- buf_len, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pss_verify_ext(&ctx, MBEDTLS_MD_SHA256,
+ 0, NULL,
+ MBEDTLS_MD_NONE,
+ buf_len, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pss_verify(&ctx, MBEDTLS_MD_NONE,
- buf_len,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pss_verify(&ctx, MBEDTLS_MD_NONE,
+ buf_len,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
- TEST_EQUAL( mbedtls_rsa_rsassa_pss_verify(&ctx, MBEDTLS_MD_SHA256,
- 0,
- NULL, buf),
- MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ TEST_EQUAL(mbedtls_rsa_rsassa_pss_verify(&ctx, MBEDTLS_MD_SHA256,
+ 0,
+ NULL, buf),
+ MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
#endif
exit:
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void rsa_init_free( int reinit )
+void rsa_init_free(int reinit)
{
mbedtls_rsa_context ctx;
@@ -144,12 +144,13 @@
* unconditionally on an error path without checking whether it has
* already been called in the success path. */
- mbedtls_rsa_init( &ctx );
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_init(&ctx);
+ mbedtls_rsa_free(&ctx);
- if( reinit )
- mbedtls_rsa_init( &ctx );
- mbedtls_rsa_free( &ctx );
+ if (reinit) {
+ mbedtls_rsa_init(&ctx);
+ }
+ mbedtls_rsa_free(&ctx);
/* This test case always succeeds, functionally speaking. A plausible
* bug might trigger an invalid pointer dereference or a memory leak. */
@@ -158,257 +159,256 @@
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
- int digest, int mod, char * input_P,
- char * input_Q, char * input_N, char * input_E,
- data_t * result_str, int result )
+void mbedtls_rsa_pkcs1_sign(data_t *message_str, int padding_mode,
+ int digest, int mod, char *input_P,
+ char *input_Q, char *input_N, char *input_E,
+ data_t *result_str, int result)
{
unsigned char output[256];
mbedtls_rsa_context ctx;
mbedtls_mpi N, P, Q, E;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,padding_mode,
- MBEDTLS_MD_NONE ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx, padding_mode,
+ MBEDTLS_MD_NONE) == 0);
- memset( output, 0x00, sizeof( output ) );
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(output, 0x00, sizeof(output));
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_sign(
- &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
- digest, message_str->len, message_str->x,
- output ) == result );
- if( result == 0 )
- {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_sign(
+ &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
+ digest, message_str->len, message_str->x,
+ output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_pkcs1_verify( data_t * message_str, int padding_mode,
- int digest, int mod,
- char * input_N, char * input_E,
- data_t * result_str, int result )
+void mbedtls_rsa_pkcs1_verify(data_t *message_str, int padding_mode,
+ int digest, int mod,
+ char *input_N, char *input_E,
+ data_t *result_str, int result)
{
mbedtls_rsa_context ctx;
mbedtls_mpi N, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
- MBEDTLS_MD_NONE ) == 0 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx, padding_mode,
+ MBEDTLS_MD_NONE) == 0);
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, digest, message_str->len, message_str->x, result_str->x ) == result );
+ TEST_ASSERT(mbedtls_rsa_pkcs1_verify(&ctx, digest, message_str->len, message_str->x,
+ result_str->x) == result);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void rsa_pkcs1_sign_raw( data_t * hash_result,
- int padding_mode, int mod,
- char * input_P, char * input_Q,
- char * input_N, char * input_E,
- data_t * result_str )
+void rsa_pkcs1_sign_raw(data_t *hash_result,
+ int padding_mode, int mod,
+ char *input_P, char *input_Q,
+ char *input_N, char *input_E,
+ data_t *result_str)
{
unsigned char output[256];
mbedtls_rsa_context ctx;
mbedtls_mpi N, P, Q, E;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_rsa_init( &ctx );
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
+ mbedtls_rsa_init(&ctx);
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
- MBEDTLS_MD_NONE ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx, padding_mode,
+ MBEDTLS_MD_NONE) == 0);
- memset( output, 0x00, sizeof( output ) );
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(output, 0x00, sizeof(output));
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &mbedtls_test_rnd_pseudo_rand,
- &rnd_info, MBEDTLS_MD_NONE,
- hash_result->len,
- hash_result->x, output ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_pkcs1_sign(&ctx, &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info, MBEDTLS_MD_NONE,
+ hash_result->len,
+ hash_result->x, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void rsa_pkcs1_verify_raw( data_t * hash_result,
- int padding_mode, int mod,
- char * input_N, char * input_E,
- data_t * result_str, int correct )
+void rsa_pkcs1_verify_raw(data_t *hash_result,
+ int padding_mode, int mod,
+ char *input_N, char *input_E,
+ data_t *result_str, int correct)
{
unsigned char output[256];
mbedtls_rsa_context ctx;
mbedtls_mpi N, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
- MBEDTLS_MD_NONE ) == 0 );
- memset( output, 0x00, sizeof( output ) );
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx, padding_mode,
+ MBEDTLS_MD_NONE) == 0);
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, MBEDTLS_MD_NONE, hash_result->len, hash_result->x, result_str->x ) == correct );
+ TEST_ASSERT(mbedtls_rsa_pkcs1_verify(&ctx, MBEDTLS_MD_NONE, hash_result->len, hash_result->x,
+ result_str->x) == correct);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_pkcs1_encrypt( data_t * message_str, int padding_mode,
- int mod, char * input_N, char * input_E,
- data_t * result_str, int result )
+void mbedtls_rsa_pkcs1_encrypt(data_t *message_str, int padding_mode,
+ int mod, char *input_N, char *input_E,
+ data_t *result_str, int result)
{
unsigned char output[256];
mbedtls_rsa_context ctx;
mbedtls_test_rnd_pseudo_info rnd_info;
mbedtls_mpi N, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
- MBEDTLS_MD_NONE ) == 0 );
- memset( output, 0x00, sizeof( output ) );
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx, padding_mode,
+ MBEDTLS_MD_NONE) == 0);
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info, message_str->len,
- message_str->x,
- output ) == result );
- if( result == 0 )
- {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_encrypt(&ctx,
+ &mbedtls_test_rnd_pseudo_rand,
+ &rnd_info, message_str->len,
+ message_str->x,
+ output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void rsa_pkcs1_encrypt_bad_rng( data_t * message_str, int padding_mode,
- int mod, char * input_N, char * input_E,
- data_t * result_str, int result )
+void rsa_pkcs1_encrypt_bad_rng(data_t *message_str, int padding_mode,
+ int mod, char *input_N, char *input_E,
+ data_t *result_str, int result)
{
unsigned char output[256];
mbedtls_rsa_context ctx;
mbedtls_mpi N, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
- MBEDTLS_MD_NONE ) == 0 );
- memset( output, 0x00, sizeof( output ) );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx, padding_mode,
+ MBEDTLS_MD_NONE) == 0);
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &mbedtls_test_rnd_zero_rand,
- NULL, message_str->len,
- message_str->x,
- output ) == result );
- if( result == 0 )
- {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_encrypt(&ctx, &mbedtls_test_rnd_zero_rand,
+ NULL, message_str->len,
+ message_str->x,
+ output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, int padding_mode,
- int mod, char * input_P,
- char * input_Q, char * input_N,
- char * input_E, int max_output,
- data_t * result_str, int result )
+void mbedtls_rsa_pkcs1_decrypt(data_t *message_str, int padding_mode,
+ int mod, char *input_P,
+ char *input_Q, char *input_N,
+ char *input_E, int max_output,
+ data_t *result_str, int result)
{
unsigned char output[32];
mbedtls_rsa_context ctx;
@@ -416,109 +416,106 @@
mbedtls_test_rnd_pseudo_info rnd_info;
mbedtls_mpi N, P, Q, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
- mbedtls_rsa_init( &ctx );
- TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
- MBEDTLS_MD_NONE ) == 0 );
+ mbedtls_rsa_init(&ctx);
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx, padding_mode,
+ MBEDTLS_MD_NONE) == 0);
- memset( output, 0x00, sizeof( output ) );
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(output, 0x00, sizeof(output));
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
output_len = 0;
- TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, mbedtls_test_rnd_pseudo_rand,
- &rnd_info,
- &output_len, message_str->x, output,
- max_output ) == result );
- if( result == 0 )
- {
+ TEST_ASSERT(mbedtls_rsa_pkcs1_decrypt(&ctx, mbedtls_test_rnd_pseudo_rand,
+ &rnd_info,
+ &output_len, message_str->x, output,
+ max_output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- output_len,
- result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ output_len,
+ result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_public( data_t * message_str, int mod,
- char * input_N, char * input_E,
- data_t * result_str, int result )
+void mbedtls_rsa_public(data_t *message_str, int mod,
+ char *input_N, char *input_E,
+ data_t *result_str, int result)
{
unsigned char output[256];
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
mbedtls_mpi N, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- mbedtls_rsa_init( &ctx2 );
- memset( output, 0x00, sizeof( output ) );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ mbedtls_rsa_init(&ctx2);
+ memset(output, 0x00, sizeof(output));
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
/* Check test data consistency */
- TEST_ASSERT( message_str->len == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
+ TEST_ASSERT(message_str->len == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == 0);
- TEST_ASSERT( mbedtls_rsa_public( &ctx, message_str->x, output ) == result );
- if( result == 0 )
- {
+ TEST_ASSERT(mbedtls_rsa_public(&ctx, message_str->x, output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
}
/* And now with the copy */
- TEST_ASSERT( mbedtls_rsa_copy( &ctx2, &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_copy(&ctx2, &ctx) == 0);
/* clear the original to be sure */
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx2 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx2) == 0);
- memset( output, 0x00, sizeof( output ) );
- TEST_ASSERT( mbedtls_rsa_public( &ctx2, message_str->x, output ) == result );
- if( result == 0 )
- {
+ memset(output, 0x00, sizeof(output));
+ TEST_ASSERT(mbedtls_rsa_public(&ctx2, message_str->x, output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len, result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len, result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
- mbedtls_rsa_free( &ctx2 );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
+ mbedtls_rsa_free(&ctx2);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_private( data_t * message_str, int mod,
- char * input_P, char * input_Q,
- char * input_N, char * input_E,
- data_t * result_str, int result )
+void mbedtls_rsa_private(data_t *message_str, int mod,
+ char *input_P, char *input_Q,
+ char *input_N, char *input_E,
+ data_t *result_str, int result)
{
unsigned char output[256];
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
@@ -526,149 +523,136 @@
mbedtls_test_rnd_pseudo_info rnd_info;
int i;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
- mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
- mbedtls_rsa_init( &ctx2 );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&P);
+ mbedtls_mpi_init(&Q); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
+ mbedtls_rsa_init(&ctx2);
- memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(&rnd_info, 0, sizeof(mbedtls_test_rnd_pseudo_info));
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, &P, &Q, NULL, &E) == 0);
/* Check test data consistency */
- TEST_ASSERT( message_str->len == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
+ TEST_ASSERT(message_str->len == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_get_len(&ctx) == (size_t) (mod / 8));
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
/* repeat three times to test updating of blinding values */
- for( i = 0; i < 3; i++ )
- {
- memset( output, 0x00, sizeof( output ) );
- TEST_ASSERT( mbedtls_rsa_private( &ctx, mbedtls_test_rnd_pseudo_rand,
- &rnd_info, message_str->x,
- output ) == result );
- if( result == 0 )
- {
+ for (i = 0; i < 3; i++) {
+ memset(output, 0x00, sizeof(output));
+ TEST_ASSERT(mbedtls_rsa_private(&ctx, mbedtls_test_rnd_pseudo_rand,
+ &rnd_info, message_str->x,
+ output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx.len,
- result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx.len,
+ result_str->len) == 0);
}
}
/* And now one more time with the copy */
- TEST_ASSERT( mbedtls_rsa_copy( &ctx2, &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_copy(&ctx2, &ctx) == 0);
/* clear the original to be sure */
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx2 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx2) == 0);
- memset( output, 0x00, sizeof( output ) );
- TEST_ASSERT( mbedtls_rsa_private( &ctx2, mbedtls_test_rnd_pseudo_rand,
- &rnd_info, message_str->x,
- output ) == result );
- if( result == 0 )
- {
+ memset(output, 0x00, sizeof(output));
+ TEST_ASSERT(mbedtls_rsa_private(&ctx2, mbedtls_test_rnd_pseudo_rand,
+ &rnd_info, message_str->x,
+ output) == result);
+ if (result == 0) {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- ctx2.len,
- result_str->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ ctx2.len,
+ result_str->len) == 0);
}
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P );
- mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &E );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&P);
+ mbedtls_mpi_free(&Q); mbedtls_mpi_free(&E);
- mbedtls_rsa_free( &ctx ); mbedtls_rsa_free( &ctx2 );
+ mbedtls_rsa_free(&ctx); mbedtls_rsa_free(&ctx2);
}
/* END_CASE */
/* BEGIN_CASE */
-void rsa_check_privkey_null( )
+void rsa_check_privkey_null()
{
mbedtls_rsa_context ctx;
- memset( &ctx, 0x00, sizeof( mbedtls_rsa_context ) );
+ memset(&ctx, 0x00, sizeof(mbedtls_rsa_context));
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == MBEDTLS_ERR_RSA_KEY_CHECK_FAILED);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_check_pubkey( char * input_N, char * input_E, int result )
+void mbedtls_rsa_check_pubkey(char *input_N, char *input_E, int result)
{
mbedtls_rsa_context ctx;
mbedtls_mpi N, E;
- mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx );
+ mbedtls_mpi_init(&N); mbedtls_mpi_init(&E);
+ mbedtls_rsa_init(&ctx);
- if( strlen( input_N ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
+ if (strlen(input_N)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
}
- if( strlen( input_E ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ if (strlen(input_E)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
}
- TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == result );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx, &N, NULL, NULL, NULL, &E) == 0);
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == result);
exit:
- mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E );
- mbedtls_rsa_free( &ctx );
+ mbedtls_mpi_free(&N); mbedtls_mpi_free(&E);
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_check_privkey( int mod, char * input_P, char * input_Q,
- char * input_N, char * input_E, char * input_D,
- char * input_DP, char * input_DQ, char * input_QP,
- int result )
+void mbedtls_rsa_check_privkey(int mod, char *input_P, char *input_Q,
+ char *input_N, char *input_E, char *input_D,
+ char *input_DP, char *input_DQ, char *input_QP,
+ int result)
{
mbedtls_rsa_context ctx;
- mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init(&ctx);
ctx.len = mod / 8;
- if( strlen( input_P ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.P, input_P ) == 0 );
+ if (strlen(input_P)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.P, input_P) == 0);
}
- if( strlen( input_Q ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.Q, input_Q ) == 0 );
+ if (strlen(input_Q)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.Q, input_Q) == 0);
}
- if( strlen( input_N ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.N, input_N ) == 0 );
+ if (strlen(input_N)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.N, input_N) == 0);
}
- if( strlen( input_E ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.E, input_E ) == 0 );
+ if (strlen(input_E)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.E, input_E) == 0);
}
- if( strlen( input_D ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.D, input_D ) == 0 );
+ if (strlen(input_D)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.D, input_D) == 0);
}
#if !defined(MBEDTLS_RSA_NO_CRT)
- if( strlen( input_DP ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.DP, input_DP ) == 0 );
+ if (strlen(input_DP)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.DP, input_DP) == 0);
}
- if( strlen( input_DQ ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.DQ, input_DQ ) == 0 );
+ if (strlen(input_DQ)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.DQ, input_DQ) == 0);
}
- if( strlen( input_QP ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &ctx.QP, input_QP ) == 0 );
+ if (strlen(input_QP)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&ctx.QP, input_QP) == 0);
}
#else
((void) input_DP);
@@ -676,68 +660,58 @@
((void) input_QP);
#endif
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == result );
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == result);
exit:
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void rsa_check_pubpriv( int mod, char * input_Npub, char * input_Epub,
- char * input_P, char * input_Q, char * input_N,
- char * input_E, char * input_D, char * input_DP,
- char * input_DQ, char * input_QP, int result )
+void rsa_check_pubpriv(int mod, char *input_Npub, char *input_Epub,
+ char *input_P, char *input_Q, char *input_N,
+ char *input_E, char *input_D, char *input_DP,
+ char *input_DQ, char *input_QP, int result)
{
mbedtls_rsa_context pub, prv;
- mbedtls_rsa_init( &pub );
- mbedtls_rsa_init( &prv );
+ mbedtls_rsa_init(&pub);
+ mbedtls_rsa_init(&prv);
pub.len = mod / 8;
prv.len = mod / 8;
- if( strlen( input_Npub ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &pub.N, input_Npub ) == 0 );
+ if (strlen(input_Npub)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&pub.N, input_Npub) == 0);
}
- if( strlen( input_Epub ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &pub.E, input_Epub ) == 0 );
+ if (strlen(input_Epub)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&pub.E, input_Epub) == 0);
}
- if( strlen( input_P ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.P, input_P ) == 0 );
+ if (strlen(input_P)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.P, input_P) == 0);
}
- if( strlen( input_Q ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.Q, input_Q ) == 0 );
+ if (strlen(input_Q)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.Q, input_Q) == 0);
}
- if( strlen( input_N ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.N, input_N ) == 0 );
+ if (strlen(input_N)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.N, input_N) == 0);
}
- if( strlen( input_E ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.E, input_E ) == 0 );
+ if (strlen(input_E)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.E, input_E) == 0);
}
- if( strlen( input_D ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.D, input_D ) == 0 );
+ if (strlen(input_D)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.D, input_D) == 0);
}
#if !defined(MBEDTLS_RSA_NO_CRT)
- if( strlen( input_DP ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.DP, input_DP ) == 0 );
+ if (strlen(input_DP)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.DP, input_DP) == 0);
}
- if( strlen( input_DQ ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.DQ, input_DQ ) == 0 );
+ if (strlen(input_DQ)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.DQ, input_DQ) == 0);
}
- if( strlen( input_QP ) )
- {
- TEST_ASSERT( mbedtls_test_read_mpi( &prv.QP, input_QP ) == 0 );
+ if (strlen(input_QP)) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&prv.QP, input_QP) == 0);
}
#else
((void) input_DP);
@@ -745,145 +719,143 @@
((void) input_QP);
#endif
- TEST_ASSERT( mbedtls_rsa_check_pub_priv( &pub, &prv ) == result );
+ TEST_ASSERT(mbedtls_rsa_check_pub_priv(&pub, &prv) == result);
exit:
- mbedtls_rsa_free( &pub );
- mbedtls_rsa_free( &prv );
+ mbedtls_rsa_free(&pub);
+ mbedtls_rsa_free(&prv);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_gen_key( int nrbits, int exponent, int result)
+void mbedtls_rsa_gen_key(int nrbits, int exponent, int result)
{
mbedtls_rsa_context ctx;
- mbedtls_rsa_init ( &ctx );
+ mbedtls_rsa_init(&ctx);
/* This test uses an insecure RNG, suitable only for testing.
* In production, always use a cryptographically strong RNG! */
- TEST_ASSERT( mbedtls_rsa_gen_key( &ctx, mbedtls_test_rnd_std_rand, NULL, nrbits, exponent ) == result );
- if( result == 0 )
- {
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &ctx.P, &ctx.Q ) > 0 );
+ TEST_ASSERT(mbedtls_rsa_gen_key(&ctx, mbedtls_test_rnd_std_rand, NULL, nrbits,
+ exponent) == result);
+ if (result == 0) {
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&ctx.P, &ctx.Q) > 0);
}
exit:
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_deduce_primes( char *input_N,
- char *input_D,
- char *input_E,
- char *output_P,
- char *output_Q,
- int corrupt, int result )
+void mbedtls_rsa_deduce_primes(char *input_N,
+ char *input_D,
+ char *input_E,
+ char *output_P,
+ char *output_Q,
+ int corrupt, int result)
{
mbedtls_mpi N, P, Pp, Q, Qp, D, E;
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
- mbedtls_mpi_init( &Pp ); mbedtls_mpi_init( &Qp );
- mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
+ mbedtls_mpi_init(&Pp); mbedtls_mpi_init(&Qp);
+ mbedtls_mpi_init(&D); mbedtls_mpi_init(&E);
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &D, input_D ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Qp, output_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Pp, output_Q ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&D, input_D) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Qp, output_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Pp, output_Q) == 0);
- if( corrupt )
- TEST_ASSERT( mbedtls_mpi_add_int( &D, &D, 2 ) == 0 );
+ if (corrupt) {
+ TEST_ASSERT(mbedtls_mpi_add_int(&D, &D, 2) == 0);
+ }
/* Try to deduce P, Q from N, D, E only. */
- TEST_ASSERT( mbedtls_rsa_deduce_primes( &N, &D, &E, &P, &Q ) == result );
+ TEST_ASSERT(mbedtls_rsa_deduce_primes(&N, &D, &E, &P, &Q) == result);
- if( !corrupt )
- {
+ if (!corrupt) {
/* Check if (P,Q) = (Pp, Qp) or (P,Q) = (Qp, Pp) */
- TEST_ASSERT( ( mbedtls_mpi_cmp_mpi( &P, &Pp ) == 0 && mbedtls_mpi_cmp_mpi( &Q, &Qp ) == 0 ) ||
- ( mbedtls_mpi_cmp_mpi( &P, &Qp ) == 0 && mbedtls_mpi_cmp_mpi( &Q, &Pp ) == 0 ) );
+ TEST_ASSERT((mbedtls_mpi_cmp_mpi(&P, &Pp) == 0 && mbedtls_mpi_cmp_mpi(&Q, &Qp) == 0) ||
+ (mbedtls_mpi_cmp_mpi(&P, &Qp) == 0 && mbedtls_mpi_cmp_mpi(&Q, &Pp) == 0));
}
exit:
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q );
- mbedtls_mpi_free( &Pp ); mbedtls_mpi_free( &Qp );
- mbedtls_mpi_free( &D ); mbedtls_mpi_free( &E );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
+ mbedtls_mpi_free(&Pp); mbedtls_mpi_free(&Qp);
+ mbedtls_mpi_free(&D); mbedtls_mpi_free(&E);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_deduce_private_exponent( char *input_P,
- char *input_Q,
- char *input_E,
- char *output_D,
- int corrupt, int result )
+void mbedtls_rsa_deduce_private_exponent(char *input_P,
+ char *input_Q,
+ char *input_E,
+ char *output_D,
+ int corrupt, int result)
{
mbedtls_mpi P, Q, D, Dp, E, R, Rp;
- mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
- mbedtls_mpi_init( &D ); mbedtls_mpi_init( &Dp );
- mbedtls_mpi_init( &E );
- mbedtls_mpi_init( &R ); mbedtls_mpi_init( &Rp );
+ mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
+ mbedtls_mpi_init(&D); mbedtls_mpi_init(&Dp);
+ mbedtls_mpi_init(&E);
+ mbedtls_mpi_init(&R); mbedtls_mpi_init(&Rp);
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
- TEST_ASSERT( mbedtls_test_read_mpi( &Dp, output_D ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ TEST_ASSERT(mbedtls_test_read_mpi(&Dp, output_D) == 0);
- if( corrupt )
- {
+ if (corrupt) {
/* Make E even */
- TEST_ASSERT( mbedtls_mpi_set_bit( &E, 0, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_set_bit(&E, 0, 0) == 0);
}
/* Try to deduce D from N, P, Q, E. */
- TEST_ASSERT( mbedtls_rsa_deduce_private_exponent( &P, &Q,
- &E, &D ) == result );
+ TEST_ASSERT(mbedtls_rsa_deduce_private_exponent(&P, &Q,
+ &E, &D) == result);
- if( !corrupt )
- {
+ if (!corrupt) {
/*
* Check that D and Dp agree modulo LCM(P-1, Q-1).
*/
/* Replace P,Q by P-1, Q-1 */
- TEST_ASSERT( mbedtls_mpi_sub_int( &P, &P, 1 ) == 0 );
- TEST_ASSERT( mbedtls_mpi_sub_int( &Q, &Q, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_sub_int(&P, &P, 1) == 0);
+ TEST_ASSERT(mbedtls_mpi_sub_int(&Q, &Q, 1) == 0);
/* Check D == Dp modulo P-1 */
- TEST_ASSERT( mbedtls_mpi_mod_mpi( &R, &D, &P ) == 0 );
- TEST_ASSERT( mbedtls_mpi_mod_mpi( &Rp, &Dp, &P ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R, &Rp ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_mod_mpi(&R, &D, &P) == 0);
+ TEST_ASSERT(mbedtls_mpi_mod_mpi(&Rp, &Dp, &P) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R, &Rp) == 0);
/* Check D == Dp modulo Q-1 */
- TEST_ASSERT( mbedtls_mpi_mod_mpi( &R, &D, &Q ) == 0 );
- TEST_ASSERT( mbedtls_mpi_mod_mpi( &Rp, &Dp, &Q ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R, &Rp ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_mod_mpi(&R, &D, &Q) == 0);
+ TEST_ASSERT(mbedtls_mpi_mod_mpi(&Rp, &Dp, &Q) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&R, &Rp) == 0);
}
exit:
- mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q );
- mbedtls_mpi_free( &D ); mbedtls_mpi_free( &Dp );
- mbedtls_mpi_free( &E );
- mbedtls_mpi_free( &R ); mbedtls_mpi_free( &Rp );
+ mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
+ mbedtls_mpi_free(&D); mbedtls_mpi_free(&Dp);
+ mbedtls_mpi_free(&E);
+ mbedtls_mpi_free(&R); mbedtls_mpi_free(&Rp);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_import( char *input_N,
- char *input_P,
- char *input_Q,
- char *input_D,
- char *input_E,
- int successive,
- int is_priv,
- int res_check,
- int res_complete )
+void mbedtls_rsa_import(char *input_N,
+ char *input_P,
+ char *input_Q,
+ char *input_D,
+ char *input_E,
+ int successive,
+ int is_priv,
+ int res_check,
+ int res_complete)
{
mbedtls_mpi N, P, Q, D, E;
mbedtls_rsa_context ctx;
@@ -893,136 +865,139 @@
unsigned char *buf_enc = NULL;
unsigned char *buf_dec = NULL;
- const int have_N = ( strlen( input_N ) > 0 );
- const int have_P = ( strlen( input_P ) > 0 );
- const int have_Q = ( strlen( input_Q ) > 0 );
- const int have_D = ( strlen( input_D ) > 0 );
- const int have_E = ( strlen( input_E ) > 0 );
+ const int have_N = (strlen(input_N) > 0);
+ const int have_P = (strlen(input_P) > 0);
+ const int have_Q = (strlen(input_Q) > 0);
+ const int have_D = (strlen(input_D) > 0);
+ const int have_E = (strlen(input_E) > 0);
- mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init(&ctx);
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
- mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
+ mbedtls_mpi_init(&D); mbedtls_mpi_init(&E);
- if( have_N )
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
-
- if( have_P )
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
-
- if( have_Q )
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
-
- if( have_D )
- TEST_ASSERT( mbedtls_test_read_mpi( &D, input_D ) == 0 );
-
- if( have_E )
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
-
- if( !successive )
- {
- TEST_ASSERT( mbedtls_rsa_import( &ctx,
- have_N ? &N : NULL,
- have_P ? &P : NULL,
- have_Q ? &Q : NULL,
- have_D ? &D : NULL,
- have_E ? &E : NULL ) == 0 );
+ if (have_N) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
}
- else
- {
+
+ if (have_P) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ }
+
+ if (have_Q) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ }
+
+ if (have_D) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&D, input_D) == 0);
+ }
+
+ if (have_E) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ }
+
+ if (!successive) {
+ TEST_ASSERT(mbedtls_rsa_import(&ctx,
+ have_N ? &N : NULL,
+ have_P ? &P : NULL,
+ have_Q ? &Q : NULL,
+ have_D ? &D : NULL,
+ have_E ? &E : NULL) == 0);
+ } else {
/* Import N, P, Q, D, E separately.
* This should make no functional difference. */
- TEST_ASSERT( mbedtls_rsa_import( &ctx,
- have_N ? &N : NULL,
- NULL, NULL, NULL, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx,
+ have_N ? &N : NULL,
+ NULL, NULL, NULL, NULL) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx,
- NULL,
- have_P ? &P : NULL,
- NULL, NULL, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx,
+ NULL,
+ have_P ? &P : NULL,
+ NULL, NULL, NULL) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx,
- NULL, NULL,
- have_Q ? &Q : NULL,
- NULL, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx,
+ NULL, NULL,
+ have_Q ? &Q : NULL,
+ NULL, NULL) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx,
- NULL, NULL, NULL,
- have_D ? &D : NULL,
- NULL ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx,
+ NULL, NULL, NULL,
+ have_D ? &D : NULL,
+ NULL) == 0);
- TEST_ASSERT( mbedtls_rsa_import( &ctx,
- NULL, NULL, NULL, NULL,
- have_E ? &E : NULL ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx,
+ NULL, NULL, NULL, NULL,
+ have_E ? &E : NULL) == 0);
}
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == res_complete );
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == res_complete);
/* On expected success, perform some public and private
* key operations to check if the key is working properly. */
- if( res_complete == 0 )
- {
- if( is_priv )
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == res_check );
- else
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == res_check );
+ if (res_complete == 0) {
+ if (is_priv) {
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == res_check);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == res_check);
+ }
- if( res_check != 0 )
+ if (res_check != 0) {
goto exit;
+ }
- buf_orig = mbedtls_calloc( 1, mbedtls_rsa_get_len( &ctx ) );
- buf_enc = mbedtls_calloc( 1, mbedtls_rsa_get_len( &ctx ) );
- buf_dec = mbedtls_calloc( 1, mbedtls_rsa_get_len( &ctx ) );
- if( buf_orig == NULL || buf_enc == NULL || buf_dec == NULL )
+ buf_orig = mbedtls_calloc(1, mbedtls_rsa_get_len(&ctx));
+ buf_enc = mbedtls_calloc(1, mbedtls_rsa_get_len(&ctx));
+ buf_dec = mbedtls_calloc(1, mbedtls_rsa_get_len(&ctx));
+ if (buf_orig == NULL || buf_enc == NULL || buf_dec == NULL) {
goto exit;
+ }
/* This test uses an insecure RNG, suitable only for testing.
* In production, always use a cryptographically strong RNG! */
- TEST_ASSERT( mbedtls_test_rnd_std_rand( NULL,
- buf_orig, mbedtls_rsa_get_len( &ctx ) ) == 0 );
+ TEST_ASSERT(mbedtls_test_rnd_std_rand(NULL,
+ buf_orig, mbedtls_rsa_get_len(&ctx)) == 0);
/* Make sure the number we're generating is smaller than the modulus */
buf_orig[0] = 0x00;
- TEST_ASSERT( mbedtls_rsa_public( &ctx, buf_orig, buf_enc ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_public(&ctx, buf_orig, buf_enc) == 0);
- if( is_priv )
- {
+ if (is_priv) {
/* This test uses an insecure RNG, suitable only for testing.
* In production, always use a cryptographically strong RNG! */
- TEST_ASSERT( mbedtls_rsa_private( &ctx, mbedtls_test_rnd_std_rand,
- NULL, buf_enc,
- buf_dec ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_private(&ctx, mbedtls_test_rnd_std_rand,
+ NULL, buf_enc,
+ buf_dec) == 0);
- TEST_ASSERT( memcmp( buf_orig, buf_dec,
- mbedtls_rsa_get_len( &ctx ) ) == 0 );
+ TEST_ASSERT(memcmp(buf_orig, buf_dec,
+ mbedtls_rsa_get_len(&ctx)) == 0);
}
}
exit:
- mbedtls_free( buf_orig );
- mbedtls_free( buf_enc );
- mbedtls_free( buf_dec );
+ mbedtls_free(buf_orig);
+ mbedtls_free(buf_enc);
+ mbedtls_free(buf_dec);
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q );
- mbedtls_mpi_free( &D ); mbedtls_mpi_free( &E );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
+ mbedtls_mpi_free(&D); mbedtls_mpi_free(&E);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_export( char *input_N,
- char *input_P,
- char *input_Q,
- char *input_D,
- char *input_E,
- int is_priv,
- int successive )
+void mbedtls_rsa_export(char *input_N,
+ char *input_P,
+ char *input_Q,
+ char *input_D,
+ char *input_E,
+ int is_priv,
+ int successive)
{
/* Original MPI's with which we set up the RSA context */
mbedtls_mpi N, P, Q, D, E;
@@ -1030,173 +1005,179 @@
/* Exported MPI's */
mbedtls_mpi Ne, Pe, Qe, De, Ee;
- const int have_N = ( strlen( input_N ) > 0 );
- const int have_P = ( strlen( input_P ) > 0 );
- const int have_Q = ( strlen( input_Q ) > 0 );
- const int have_D = ( strlen( input_D ) > 0 );
- const int have_E = ( strlen( input_E ) > 0 );
+ const int have_N = (strlen(input_N) > 0);
+ const int have_P = (strlen(input_P) > 0);
+ const int have_Q = (strlen(input_Q) > 0);
+ const int have_D = (strlen(input_D) > 0);
+ const int have_E = (strlen(input_E) > 0);
mbedtls_rsa_context ctx;
- mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init(&ctx);
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
- mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
+ mbedtls_mpi_init(&D); mbedtls_mpi_init(&E);
- mbedtls_mpi_init( &Ne );
- mbedtls_mpi_init( &Pe ); mbedtls_mpi_init( &Qe );
- mbedtls_mpi_init( &De ); mbedtls_mpi_init( &Ee );
+ mbedtls_mpi_init(&Ne);
+ mbedtls_mpi_init(&Pe); mbedtls_mpi_init(&Qe);
+ mbedtls_mpi_init(&De); mbedtls_mpi_init(&Ee);
/* Setup RSA context */
- if( have_N )
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
+ if (have_N) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ }
- if( have_P )
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
+ if (have_P) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ }
- if( have_Q )
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
+ if (have_Q) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ }
- if( have_D )
- TEST_ASSERT( mbedtls_test_read_mpi( &D, input_D ) == 0 );
+ if (have_D) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&D, input_D) == 0);
+ }
- if( have_E )
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ if (have_E) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ }
- TEST_ASSERT( mbedtls_rsa_import( &ctx,
- strlen( input_N ) ? &N : NULL,
- strlen( input_P ) ? &P : NULL,
- strlen( input_Q ) ? &Q : NULL,
- strlen( input_D ) ? &D : NULL,
- strlen( input_E ) ? &E : NULL ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import(&ctx,
+ strlen(input_N) ? &N : NULL,
+ strlen(input_P) ? &P : NULL,
+ strlen(input_Q) ? &Q : NULL,
+ strlen(input_D) ? &D : NULL,
+ strlen(input_E) ? &E : NULL) == 0);
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
/*
* Export parameters and compare to original ones.
*/
/* N and E must always be present. */
- if( !successive )
- {
- TEST_ASSERT( mbedtls_rsa_export( &ctx, &Ne, NULL, NULL, NULL, &Ee ) == 0 );
+ if (!successive) {
+ TEST_ASSERT(mbedtls_rsa_export(&ctx, &Ne, NULL, NULL, NULL, &Ee) == 0);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_export(&ctx, &Ne, NULL, NULL, NULL, NULL) == 0);
+ TEST_ASSERT(mbedtls_rsa_export(&ctx, NULL, NULL, NULL, NULL, &Ee) == 0);
}
- else
- {
- TEST_ASSERT( mbedtls_rsa_export( &ctx, &Ne, NULL, NULL, NULL, NULL ) == 0 );
- TEST_ASSERT( mbedtls_rsa_export( &ctx, NULL, NULL, NULL, NULL, &Ee ) == 0 );
- }
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &N, &Ne ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &E, &Ee ) == 0 );
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&N, &Ne) == 0);
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&E, &Ee) == 0);
/* If we were providing enough information to setup a complete private context,
* we expect to be able to export all core parameters. */
- if( is_priv )
- {
- if( !successive )
- {
- TEST_ASSERT( mbedtls_rsa_export( &ctx, NULL, &Pe, &Qe,
- &De, NULL ) == 0 );
- }
- else
- {
- TEST_ASSERT( mbedtls_rsa_export( &ctx, NULL, &Pe, NULL,
- NULL, NULL ) == 0 );
- TEST_ASSERT( mbedtls_rsa_export( &ctx, NULL, NULL, &Qe,
- NULL, NULL ) == 0 );
- TEST_ASSERT( mbedtls_rsa_export( &ctx, NULL, NULL, NULL,
- &De, NULL ) == 0 );
+ if (is_priv) {
+ if (!successive) {
+ TEST_ASSERT(mbedtls_rsa_export(&ctx, NULL, &Pe, &Qe,
+ &De, NULL) == 0);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_export(&ctx, NULL, &Pe, NULL,
+ NULL, NULL) == 0);
+ TEST_ASSERT(mbedtls_rsa_export(&ctx, NULL, NULL, &Qe,
+ NULL, NULL) == 0);
+ TEST_ASSERT(mbedtls_rsa_export(&ctx, NULL, NULL, NULL,
+ &De, NULL) == 0);
}
- if( have_P )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &P, &Pe ) == 0 );
+ if (have_P) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&P, &Pe) == 0);
+ }
- if( have_Q )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Q, &Qe ) == 0 );
+ if (have_Q) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&Q, &Qe) == 0);
+ }
- if( have_D )
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &D, &De ) == 0 );
+ if (have_D) {
+ TEST_ASSERT(mbedtls_mpi_cmp_mpi(&D, &De) == 0);
+ }
/* While at it, perform a sanity check */
- TEST_ASSERT( mbedtls_rsa_validate_params( &Ne, &Pe, &Qe, &De, &Ee,
- NULL, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_validate_params(&Ne, &Pe, &Qe, &De, &Ee,
+ NULL, NULL) == 0);
}
exit:
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q );
- mbedtls_mpi_free( &D ); mbedtls_mpi_free( &E );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
+ mbedtls_mpi_free(&D); mbedtls_mpi_free(&E);
- mbedtls_mpi_free( &Ne );
- mbedtls_mpi_free( &Pe ); mbedtls_mpi_free( &Qe );
- mbedtls_mpi_free( &De ); mbedtls_mpi_free( &Ee );
+ mbedtls_mpi_free(&Ne);
+ mbedtls_mpi_free(&Pe); mbedtls_mpi_free(&Qe);
+ mbedtls_mpi_free(&De); mbedtls_mpi_free(&Ee);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_validate_params( char *input_N,
- char *input_P,
- char *input_Q,
- char *input_D,
- char *input_E,
- int prng, int result )
+void mbedtls_rsa_validate_params(char *input_N,
+ char *input_P,
+ char *input_Q,
+ char *input_D,
+ char *input_E,
+ int prng, int result)
{
/* Original MPI's with which we set up the RSA context */
mbedtls_mpi N, P, Q, D, E;
- const int have_N = ( strlen( input_N ) > 0 );
- const int have_P = ( strlen( input_P ) > 0 );
- const int have_Q = ( strlen( input_Q ) > 0 );
- const int have_D = ( strlen( input_D ) > 0 );
- const int have_E = ( strlen( input_E ) > 0 );
+ const int have_N = (strlen(input_N) > 0);
+ const int have_P = (strlen(input_P) > 0);
+ const int have_Q = (strlen(input_Q) > 0);
+ const int have_D = (strlen(input_D) > 0);
+ const int have_E = (strlen(input_E) > 0);
- mbedtls_mpi_init( &N );
- mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
- mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E );
+ mbedtls_mpi_init(&N);
+ mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
+ mbedtls_mpi_init(&D); mbedtls_mpi_init(&E);
- if( have_N )
- TEST_ASSERT( mbedtls_test_read_mpi( &N, input_N ) == 0 );
+ if (have_N) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&N, input_N) == 0);
+ }
- if( have_P )
- TEST_ASSERT( mbedtls_test_read_mpi( &P, input_P ) == 0 );
+ if (have_P) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&P, input_P) == 0);
+ }
- if( have_Q )
- TEST_ASSERT( mbedtls_test_read_mpi( &Q, input_Q ) == 0 );
+ if (have_Q) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&Q, input_Q) == 0);
+ }
- if( have_D )
- TEST_ASSERT( mbedtls_test_read_mpi( &D, input_D ) == 0 );
+ if (have_D) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&D, input_D) == 0);
+ }
- if( have_E )
- TEST_ASSERT( mbedtls_test_read_mpi( &E, input_E ) == 0 );
+ if (have_E) {
+ TEST_ASSERT(mbedtls_test_read_mpi(&E, input_E) == 0);
+ }
/* This test uses an insecure RNG, suitable only for testing.
* In production, always use a cryptographically strong RNG! */
- TEST_ASSERT( mbedtls_rsa_validate_params( have_N ? &N : NULL,
- have_P ? &P : NULL,
- have_Q ? &Q : NULL,
- have_D ? &D : NULL,
- have_E ? &E : NULL,
- prng ? mbedtls_test_rnd_std_rand : NULL,
- prng ? NULL : NULL ) == result );
+ TEST_ASSERT(mbedtls_rsa_validate_params(have_N ? &N : NULL,
+ have_P ? &P : NULL,
+ have_Q ? &Q : NULL,
+ have_D ? &D : NULL,
+ have_E ? &E : NULL,
+ prng ? mbedtls_test_rnd_std_rand : NULL,
+ prng ? NULL : NULL) == result);
exit:
- mbedtls_mpi_free( &N );
- mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q );
- mbedtls_mpi_free( &D ); mbedtls_mpi_free( &E );
+ mbedtls_mpi_free(&N);
+ mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
+ mbedtls_mpi_free(&D); mbedtls_mpi_free(&E);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_export_raw( data_t *input_N, data_t *input_P,
- data_t *input_Q, data_t *input_D,
- data_t *input_E, int is_priv,
- int successive )
+void mbedtls_rsa_export_raw(data_t *input_N, data_t *input_P,
+ data_t *input_Q, data_t *input_D,
+ data_t *input_E, int is_priv,
+ int successive)
{
/* Exported buffers */
unsigned char bufNe[256];
@@ -1207,94 +1188,90 @@
mbedtls_rsa_context ctx;
- mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init(&ctx);
/* Setup RSA context */
- TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
- input_N->len ? input_N->x : NULL, input_N->len,
- input_P->len ? input_P->x : NULL, input_P->len,
- input_Q->len ? input_Q->x : NULL, input_Q->len,
- input_D->len ? input_D->x : NULL, input_D->len,
- input_E->len ? input_E->x : NULL, input_E->len ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import_raw(&ctx,
+ input_N->len ? input_N->x : NULL, input_N->len,
+ input_P->len ? input_P->x : NULL, input_P->len,
+ input_Q->len ? input_Q->x : NULL, input_Q->len,
+ input_D->len ? input_D->x : NULL, input_D->len,
+ input_E->len ? input_E->x : NULL, input_E->len) == 0);
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == 0);
/*
* Export parameters and compare to original ones.
*/
/* N and E must always be present. */
- if( !successive )
- {
- TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, bufNe, input_N->len,
- NULL, 0, NULL, 0, NULL, 0,
- bufEe, input_E->len ) == 0 );
+ if (!successive) {
+ TEST_ASSERT(mbedtls_rsa_export_raw(&ctx, bufNe, input_N->len,
+ NULL, 0, NULL, 0, NULL, 0,
+ bufEe, input_E->len) == 0);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_export_raw(&ctx, bufNe, input_N->len,
+ NULL, 0, NULL, 0, NULL, 0,
+ NULL, 0) == 0);
+ TEST_ASSERT(mbedtls_rsa_export_raw(&ctx, NULL, 0,
+ NULL, 0, NULL, 0, NULL, 0,
+ bufEe, input_E->len) == 0);
}
- else
- {
- TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, bufNe, input_N->len,
- NULL, 0, NULL, 0, NULL, 0,
- NULL, 0 ) == 0 );
- TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0,
- NULL, 0, NULL, 0, NULL, 0,
- bufEe, input_E->len ) == 0 );
- }
- TEST_ASSERT( memcmp( input_N->x, bufNe, input_N->len ) == 0 );
- TEST_ASSERT( memcmp( input_E->x, bufEe, input_E->len ) == 0 );
+ TEST_ASSERT(memcmp(input_N->x, bufNe, input_N->len) == 0);
+ TEST_ASSERT(memcmp(input_E->x, bufEe, input_E->len) == 0);
/* If we were providing enough information to setup a complete private context,
* we expect to be able to export all core parameters. */
- if( is_priv )
- {
- if( !successive )
- {
- TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0,
- bufPe, input_P->len ? input_P->len : sizeof( bufPe ),
- bufQe, input_Q->len ? input_Q->len : sizeof( bufQe ),
- bufDe, input_D->len ? input_D->len : sizeof( bufDe ),
- NULL, 0 ) == 0 );
- }
- else
- {
- TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0,
- bufPe, input_P->len ? input_P->len : sizeof( bufPe ),
- NULL, 0, NULL, 0,
- NULL, 0 ) == 0 );
+ if (is_priv) {
+ if (!successive) {
+ TEST_ASSERT(mbedtls_rsa_export_raw(&ctx, NULL, 0,
+ bufPe, input_P->len ? input_P->len : sizeof(bufPe),
+ bufQe, input_Q->len ? input_Q->len : sizeof(bufQe),
+ bufDe, input_D->len ? input_D->len : sizeof(bufDe),
+ NULL, 0) == 0);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_export_raw(&ctx, NULL, 0,
+ bufPe, input_P->len ? input_P->len : sizeof(bufPe),
+ NULL, 0, NULL, 0,
+ NULL, 0) == 0);
- TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, NULL, 0,
- bufQe, input_Q->len ? input_Q->len : sizeof( bufQe ),
- NULL, 0, NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_export_raw(&ctx, NULL, 0, NULL, 0,
+ bufQe, input_Q->len ? input_Q->len : sizeof(bufQe),
+ NULL, 0, NULL, 0) == 0);
- TEST_ASSERT( mbedtls_rsa_export_raw( &ctx, NULL, 0, NULL, 0, NULL, 0,
- bufDe, input_D->len ? input_D->len : sizeof( bufDe ),
- NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_export_raw(&ctx, NULL, 0, NULL, 0, NULL, 0,
+ bufDe, input_D->len ? input_D->len : sizeof(bufDe),
+ NULL, 0) == 0);
}
- if( input_P->len )
- TEST_ASSERT( memcmp( input_P->x, bufPe, input_P->len ) == 0 );
+ if (input_P->len) {
+ TEST_ASSERT(memcmp(input_P->x, bufPe, input_P->len) == 0);
+ }
- if( input_Q->len )
- TEST_ASSERT( memcmp( input_Q->x, bufQe, input_Q->len ) == 0 );
+ if (input_Q->len) {
+ TEST_ASSERT(memcmp(input_Q->x, bufQe, input_Q->len) == 0);
+ }
- if( input_D->len )
- TEST_ASSERT( memcmp( input_D->x, bufDe, input_D->len ) == 0 );
+ if (input_D->len) {
+ TEST_ASSERT(memcmp(input_D->x, bufDe, input_D->len) == 0);
+ }
}
exit:
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE */
-void mbedtls_rsa_import_raw( data_t *input_N,
- data_t *input_P, data_t *input_Q,
- data_t *input_D, data_t *input_E,
- int successive,
- int is_priv,
- int res_check,
- int res_complete )
+void mbedtls_rsa_import_raw(data_t *input_N,
+ data_t *input_P, data_t *input_Q,
+ data_t *input_D, data_t *input_E,
+ int successive,
+ int is_priv,
+ int res_check,
+ int res_complete)
{
/* Buffers used for encryption-decryption test */
unsigned char *buf_orig = NULL;
@@ -1303,102 +1280,102 @@
mbedtls_rsa_context ctx;
- mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init(&ctx);
- if( !successive )
- {
- TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
- ( input_N->len > 0 ) ? input_N->x : NULL, input_N->len,
- ( input_P->len > 0 ) ? input_P->x : NULL, input_P->len,
- ( input_Q->len > 0 ) ? input_Q->x : NULL, input_Q->len,
- ( input_D->len > 0 ) ? input_D->x : NULL, input_D->len,
- ( input_E->len > 0 ) ? input_E->x : NULL, input_E->len ) == 0 );
- }
- else
- {
+ if (!successive) {
+ TEST_ASSERT(mbedtls_rsa_import_raw(&ctx,
+ (input_N->len > 0) ? input_N->x : NULL, input_N->len,
+ (input_P->len > 0) ? input_P->x : NULL, input_P->len,
+ (input_Q->len > 0) ? input_Q->x : NULL, input_Q->len,
+ (input_D->len > 0) ? input_D->x : NULL, input_D->len,
+ (input_E->len > 0) ? input_E->x : NULL,
+ input_E->len) == 0);
+ } else {
/* Import N, P, Q, D, E separately.
* This should make no functional difference. */
- TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
- ( input_N->len > 0 ) ? input_N->x : NULL, input_N->len,
- NULL, 0, NULL, 0, NULL, 0, NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import_raw(&ctx,
+ (input_N->len > 0) ? input_N->x : NULL, input_N->len,
+ NULL, 0, NULL, 0, NULL, 0, NULL, 0) == 0);
- TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
- NULL, 0,
- ( input_P->len > 0 ) ? input_P->x : NULL, input_P->len,
- NULL, 0, NULL, 0, NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import_raw(&ctx,
+ NULL, 0,
+ (input_P->len > 0) ? input_P->x : NULL, input_P->len,
+ NULL, 0, NULL, 0, NULL, 0) == 0);
- TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
- NULL, 0, NULL, 0,
- ( input_Q->len > 0 ) ? input_Q->x : NULL, input_Q->len,
- NULL, 0, NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import_raw(&ctx,
+ NULL, 0, NULL, 0,
+ (input_Q->len > 0) ? input_Q->x : NULL, input_Q->len,
+ NULL, 0, NULL, 0) == 0);
- TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
- NULL, 0, NULL, 0, NULL, 0,
- ( input_D->len > 0 ) ? input_D->x : NULL, input_D->len,
- NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import_raw(&ctx,
+ NULL, 0, NULL, 0, NULL, 0,
+ (input_D->len > 0) ? input_D->x : NULL, input_D->len,
+ NULL, 0) == 0);
- TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
- NULL, 0, NULL, 0, NULL, 0, NULL, 0,
- ( input_E->len > 0 ) ? input_E->x : NULL, input_E->len ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_import_raw(&ctx,
+ NULL, 0, NULL, 0, NULL, 0, NULL, 0,
+ (input_E->len > 0) ? input_E->x : NULL,
+ input_E->len) == 0);
}
- TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == res_complete );
+ TEST_ASSERT(mbedtls_rsa_complete(&ctx) == res_complete);
/* On expected success, perform some public and private
* key operations to check if the key is working properly. */
- if( res_complete == 0 )
- {
- if( is_priv )
- TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == res_check );
- else
- TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == res_check );
+ if (res_complete == 0) {
+ if (is_priv) {
+ TEST_ASSERT(mbedtls_rsa_check_privkey(&ctx) == res_check);
+ } else {
+ TEST_ASSERT(mbedtls_rsa_check_pubkey(&ctx) == res_check);
+ }
- if( res_check != 0 )
+ if (res_check != 0) {
goto exit;
+ }
- buf_orig = mbedtls_calloc( 1, mbedtls_rsa_get_len( &ctx ) );
- buf_enc = mbedtls_calloc( 1, mbedtls_rsa_get_len( &ctx ) );
- buf_dec = mbedtls_calloc( 1, mbedtls_rsa_get_len( &ctx ) );
- if( buf_orig == NULL || buf_enc == NULL || buf_dec == NULL )
+ buf_orig = mbedtls_calloc(1, mbedtls_rsa_get_len(&ctx));
+ buf_enc = mbedtls_calloc(1, mbedtls_rsa_get_len(&ctx));
+ buf_dec = mbedtls_calloc(1, mbedtls_rsa_get_len(&ctx));
+ if (buf_orig == NULL || buf_enc == NULL || buf_dec == NULL) {
goto exit;
+ }
/* This test uses an insecure RNG, suitable only for testing.
* In production, always use a cryptographically strong RNG! */
- TEST_ASSERT( mbedtls_test_rnd_std_rand( NULL,
- buf_orig, mbedtls_rsa_get_len( &ctx ) ) == 0 );
+ TEST_ASSERT(mbedtls_test_rnd_std_rand(NULL,
+ buf_orig, mbedtls_rsa_get_len(&ctx)) == 0);
/* Make sure the number we're generating is smaller than the modulus */
buf_orig[0] = 0x00;
- TEST_ASSERT( mbedtls_rsa_public( &ctx, buf_orig, buf_enc ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_public(&ctx, buf_orig, buf_enc) == 0);
- if( is_priv )
- {
+ if (is_priv) {
/* This test uses an insecure RNG, suitable only for testing.
* In production, always use a cryptographically strong RNG! */
- TEST_ASSERT( mbedtls_rsa_private( &ctx, mbedtls_test_rnd_std_rand,
- NULL, buf_enc,
- buf_dec ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_private(&ctx, mbedtls_test_rnd_std_rand,
+ NULL, buf_enc,
+ buf_dec) == 0);
- TEST_ASSERT( memcmp( buf_orig, buf_dec,
- mbedtls_rsa_get_len( &ctx ) ) == 0 );
+ TEST_ASSERT(memcmp(buf_orig, buf_dec,
+ mbedtls_rsa_get_len(&ctx)) == 0);
}
}
exit:
- mbedtls_free( buf_orig );
- mbedtls_free( buf_enc );
- mbedtls_free( buf_dec );
+ mbedtls_free(buf_orig);
+ mbedtls_free(buf_enc);
+ mbedtls_free(buf_dec);
- mbedtls_rsa_free( &ctx );
+ mbedtls_rsa_free(&ctx);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
-void rsa_selftest( )
+void rsa_selftest()
{
- TEST_ASSERT( mbedtls_rsa_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_rsa_self_test(1) == 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_shax.function b/tests/suites/test_suite_shax.function
index 79afe01..60dd3c8 100644
--- a/tests/suites/test_suite_shax.function
+++ b/tests/suites/test_suite_shax.function
@@ -5,33 +5,33 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
-void mbedtls_sha1( data_t * src_str, data_t * hash )
+void mbedtls_sha1(data_t *src_str, data_t *hash)
{
unsigned char output[41];
memset(output, 0x00, 41);
- TEST_ASSERT( mbedtls_sha1( src_str->x, src_str->len, output ) == 0 );
+ TEST_ASSERT(mbedtls_sha1(src_str->x, src_str->len, output) == 0);
- TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 20, hash->len ) == 0 );
+ TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, 20, hash->len) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
-void sha256_invalid_param( )
+void sha256_invalid_param()
{
mbedtls_sha256_context ctx;
unsigned char buf[64] = { 0 };
- size_t const buflen = sizeof( buf );
+ size_t const buflen = sizeof(buf);
int invalid_type = 42;
- TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_starts( &ctx, invalid_type ) );
+ TEST_EQUAL(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
+ mbedtls_sha256_starts(&ctx, invalid_type));
- TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256( buf, buflen,
- buf, invalid_type ) );
+ TEST_EQUAL(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
+ mbedtls_sha256(buf, buflen,
+ buf, invalid_type));
exit:
return;
@@ -39,47 +39,47 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA224_C */
-void sha224( data_t * src_str, data_t * hash )
+void sha224(data_t *src_str, data_t *hash)
{
unsigned char output[57];
memset(output, 0x00, 57);
- TEST_EQUAL( mbedtls_sha256( src_str->x, src_str->len, output, 1 ), 0 );
+ TEST_EQUAL(mbedtls_sha256(src_str->x, src_str->len, output, 1), 0);
- TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 28, hash->len ), 0 );
+ TEST_EQUAL(mbedtls_test_hexcmp(output, hash->x, 28, hash->len), 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
-void mbedtls_sha256( data_t * src_str, data_t * hash )
+void mbedtls_sha256(data_t *src_str, data_t *hash)
{
unsigned char output[65];
memset(output, 0x00, 65);
- TEST_EQUAL( mbedtls_sha256( src_str->x, src_str->len, output, 0 ), 0 );
+ TEST_EQUAL(mbedtls_sha256(src_str->x, src_str->len, output, 0), 0);
- TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 32, hash->len ), 0 );
+ TEST_EQUAL(mbedtls_test_hexcmp(output, hash->x, 32, hash->len), 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
-void sha512_invalid_param( )
+void sha512_invalid_param()
{
mbedtls_sha512_context ctx;
unsigned char buf[64] = { 0 };
- size_t const buflen = sizeof( buf );
+ size_t const buflen = sizeof(buf);
int invalid_type = 42;
- TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_starts( &ctx, invalid_type ) );
+ TEST_EQUAL(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
+ mbedtls_sha512_starts(&ctx, invalid_type));
- TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512( buf, buflen,
- buf, invalid_type ) );
+ TEST_EQUAL(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
+ mbedtls_sha512(buf, buflen,
+ buf, invalid_type));
exit:
return;
@@ -87,64 +87,64 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA384_C */
-void sha384( data_t * src_str, data_t * hash )
+void sha384(data_t *src_str, data_t *hash)
{
unsigned char output[97];
memset(output, 0x00, 97);
- TEST_EQUAL( mbedtls_sha512( src_str->x, src_str->len, output, 1 ), 0 );
+ TEST_EQUAL(mbedtls_sha512(src_str->x, src_str->len, output, 1), 0);
- TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 48, hash->len ), 0 );
+ TEST_EQUAL(mbedtls_test_hexcmp(output, hash->x, 48, hash->len), 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
-void mbedtls_sha512( data_t * src_str, data_t * hash )
+void mbedtls_sha512(data_t *src_str, data_t *hash)
{
unsigned char output[129];
memset(output, 0x00, 129);
- TEST_EQUAL( mbedtls_sha512( src_str->x, src_str->len, output, 0 ), 0 );
+ TEST_EQUAL(mbedtls_sha512(src_str->x, src_str->len, output, 0), 0);
- TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 64, hash->len ), 0 );
+ TEST_EQUAL(mbedtls_test_hexcmp(output, hash->x, 64, hash->len), 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
-void sha1_selftest( )
+void sha1_selftest()
{
- TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
+ TEST_ASSERT(mbedtls_sha1_self_test(1) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA224_C:MBEDTLS_SELF_TEST */
-void sha224_selftest( )
+void sha224_selftest()
{
- TEST_EQUAL( mbedtls_sha224_self_test( 1 ), 0 );
+ TEST_EQUAL(mbedtls_sha224_self_test(1), 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
-void sha256_selftest( )
+void sha256_selftest()
{
- TEST_EQUAL( mbedtls_sha256_self_test( 1 ), 0 );
+ TEST_EQUAL(mbedtls_sha256_self_test(1), 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA384_C:MBEDTLS_SELF_TEST */
-void sha384_selftest( )
+void sha384_selftest()
{
- TEST_EQUAL( mbedtls_sha384_self_test( 1 ), 0 );
+ TEST_EQUAL(mbedtls_sha384_self_test(1), 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
-void sha512_selftest( )
+void sha512_selftest()
{
- TEST_EQUAL( mbedtls_sha512_self_test( 1 ), 0 );
+ TEST_EQUAL(mbedtls_sha512_self_test(1), 0);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function
index 274a894..3652e1b 100644
--- a/tests/suites/test_suite_ssl.function
+++ b/tests/suites/test_suite_ssl.function
@@ -17,27 +17,26 @@
#include <constant_time_internal.h>
#include <test/constant_flow.h>
-enum
-{
-#define MBEDTLS_SSL_TLS1_3_LABEL( name, string ) \
- tls13_label_ ## name,
-MBEDTLS_SSL_TLS1_3_LABEL_LIST
+enum {
+#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
+ tls13_label_ ## name,
+ MBEDTLS_SSL_TLS1_3_LABEL_LIST
#undef MBEDTLS_SSL_TLS1_3_LABEL
};
-typedef struct log_pattern
-{
+typedef struct log_pattern {
const char *pattern;
size_t counter;
} log_pattern;
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
static int rng_seed = 0xBEEF;
-static int rng_get( void *p_rng, unsigned char *output, size_t output_len )
+static int rng_get(void *p_rng, unsigned char *output, size_t output_len)
{
(void) p_rng;
- for( size_t i = 0; i < output_len; i++ )
+ for (size_t i = 0; i < output_len; i++) {
output[i] = rand();
+ }
return 0;
}
@@ -48,9 +47,9 @@
* this case, it will count the instances of a log_pattern in the received
* logged messages.
*/
-void log_analyzer( void *ctx, int level,
- const char *file, int line,
- const char *str )
+void log_analyzer(void *ctx, int level,
+ const char *file, int line,
+ const char *str)
{
log_pattern *p = (log_pattern *) ctx;
@@ -58,16 +57,14 @@
(void) line;
(void) file;
- if( NULL != p &&
+ if (NULL != p &&
NULL != p->pattern &&
- NULL != strstr( str, p->pattern ) )
- {
+ NULL != strstr(str, p->pattern)) {
p->counter++;
}
}
-typedef struct handshake_test_options
-{
+typedef struct handshake_test_options {
const char *cipher;
mbedtls_ssl_protocol_version client_min_version;
mbedtls_ssl_protocol_version client_max_version;
@@ -101,10 +98,10 @@
#endif
} handshake_test_options;
-void init_handshake_options( handshake_test_options *opts )
+void init_handshake_options(handshake_test_options *opts)
{
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
- srand( rng_seed );
+ srand(rng_seed);
rng_seed += 0xD0;
#endif
opts->cipher = "";
@@ -137,18 +134,18 @@
opts->resize_buffers = 1;
#if defined(MBEDTLS_SSL_CACHE_C)
opts->cache = NULL;
- ASSERT_ALLOC( opts->cache, 1 );
- mbedtls_ssl_cache_init( opts->cache );
+ ASSERT_ALLOC(opts->cache, 1);
+ mbedtls_ssl_cache_init(opts->cache);
exit:
return;
#endif
}
-void free_handshake_options( handshake_test_options *opts )
+void free_handshake_options(handshake_test_options *opts)
{
#if defined(MBEDTLS_SSL_CACHE_C)
- mbedtls_ssl_cache_free( opts->cache );
- mbedtls_free( opts->cache );
+ mbedtls_ssl_cache_free(opts->cache);
+ mbedtls_free(opts->cache);
#else
(void) opts;
#endif
@@ -157,16 +154,16 @@
#if defined(MBEDTLS_TEST_HOOKS)
static void set_chk_buf_ptr_args(
mbedtls_ssl_chk_buf_ptr_args *args,
- unsigned char *cur, unsigned char *end, size_t need )
+ unsigned char *cur, unsigned char *end, size_t need)
{
args->cur = cur;
args->end = end;
args->need = need;
}
-static void reset_chk_buf_ptr_args( mbedtls_ssl_chk_buf_ptr_args *args )
+static void reset_chk_buf_ptr_args(mbedtls_ssl_chk_buf_ptr_args *args)
{
- memset( args, 0, sizeof( *args ) );
+ memset(args, 0, sizeof(*args));
}
#endif /* MBEDTLS_TEST_HOOKS */
@@ -174,8 +171,7 @@
* Buffer structure for custom I/O callbacks.
*/
-typedef struct mbedtls_test_buffer
-{
+typedef struct mbedtls_test_buffer {
size_t start;
size_t content_length;
size_t capacity;
@@ -186,32 +182,34 @@
* Initialises \p buf. After calling this function it is safe to call
* `mbedtls_test_buffer_free()` on \p buf.
*/
-void mbedtls_test_buffer_init( mbedtls_test_buffer *buf )
+void mbedtls_test_buffer_init(mbedtls_test_buffer *buf)
{
- memset( buf, 0, sizeof( *buf ) );
+ memset(buf, 0, sizeof(*buf));
}
/*
* Sets up \p buf. After calling this function it is safe to call
* `mbedtls_test_buffer_put()` and `mbedtls_test_buffer_get()` on \p buf.
*/
-int mbedtls_test_buffer_setup( mbedtls_test_buffer *buf, size_t capacity )
+int mbedtls_test_buffer_setup(mbedtls_test_buffer *buf, size_t capacity)
{
- buf->buffer = (unsigned char*) mbedtls_calloc( capacity,
- sizeof(unsigned char) );
- if( NULL == buf->buffer )
+ buf->buffer = (unsigned char *) mbedtls_calloc(capacity,
+ sizeof(unsigned char));
+ if (NULL == buf->buffer) {
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
+ }
buf->capacity = capacity;
return 0;
}
-void mbedtls_test_buffer_free( mbedtls_test_buffer *buf )
+void mbedtls_test_buffer_free(mbedtls_test_buffer *buf)
{
- if( buf->buffer != NULL )
- mbedtls_free( buf->buffer );
+ if (buf->buffer != NULL) {
+ mbedtls_free(buf->buffer);
+ }
- memset( buf, 0, sizeof( *buf ) );
+ memset(buf, 0, sizeof(*buf));
}
/*
@@ -225,49 +223,44 @@
* \retval -1, if \p buf is NULL, it hasn't been set up or \p input_len is not
* zero and \p input is NULL.
*/
-int mbedtls_test_buffer_put( mbedtls_test_buffer *buf,
- const unsigned char *input, size_t input_len )
+int mbedtls_test_buffer_put(mbedtls_test_buffer *buf,
+ const unsigned char *input, size_t input_len)
{
size_t overflow = 0;
- if( ( buf == NULL ) || ( buf->buffer == NULL ) )
+ if ((buf == NULL) || (buf->buffer == NULL)) {
return -1;
+ }
/* Reduce input_len to a number that fits in the buffer. */
- if ( ( buf->content_length + input_len ) > buf->capacity )
- {
+ if ((buf->content_length + input_len) > buf->capacity) {
input_len = buf->capacity - buf->content_length;
}
- if( input == NULL )
- {
- return ( input_len == 0 ) ? 0 : -1;
+ if (input == NULL) {
+ return (input_len == 0) ? 0 : -1;
}
- /* Check if the buffer has not come full circle and free space is not in
- * the middle */
- if( buf->start + buf->content_length < buf->capacity )
- {
+ /* Check if the buffer has not come full circle and free space is not in
+ * the middle */
+ if (buf->start + buf->content_length < buf->capacity) {
/* Calculate the number of bytes that need to be placed at lower memory
- * address */
- if( buf->start + buf->content_length + input_len
- > buf->capacity )
- {
- overflow = ( buf->start + buf->content_length + input_len )
- % buf->capacity;
+ * address */
+ if (buf->start + buf->content_length + input_len
+ > buf->capacity) {
+ overflow = (buf->start + buf->content_length + input_len)
+ % buf->capacity;
}
- memcpy( buf->buffer + buf->start + buf->content_length, input,
- input_len - overflow );
- memcpy( buf->buffer, input + input_len - overflow, overflow );
+ memcpy(buf->buffer + buf->start + buf->content_length, input,
+ input_len - overflow);
+ memcpy(buf->buffer, input + input_len - overflow, overflow);
- }
- else
- {
+ } else {
/* The buffer has come full circle and free space is in the middle */
- memcpy( buf->buffer + buf->start + buf->content_length - buf->capacity,
- input, input_len );
+ memcpy(buf->buffer + buf->start + buf->content_length - buf->capacity,
+ input, input_len);
}
buf->content_length += input_len;
@@ -286,35 +279,36 @@
* \retval 0 <= value < \p output_len, if the data is not available.
* \retval -1, if \buf is NULL or it hasn't been set up.
*/
-int mbedtls_test_buffer_get( mbedtls_test_buffer *buf,
- unsigned char* output, size_t output_len )
+int mbedtls_test_buffer_get(mbedtls_test_buffer *buf,
+ unsigned char *output, size_t output_len)
{
size_t overflow = 0;
- if( ( buf == NULL ) || ( buf->buffer == NULL ) )
+ if ((buf == NULL) || (buf->buffer == NULL)) {
return -1;
+ }
- if( output == NULL && output_len == 0 )
+ if (output == NULL && output_len == 0) {
return 0;
+ }
- if( buf->content_length < output_len )
+ if (buf->content_length < output_len) {
output_len = buf->content_length;
+ }
/* Calculate the number of bytes that need to be drawn from lower memory
* address */
- if( buf->start + output_len > buf->capacity )
- {
- overflow = ( buf->start + output_len ) % buf->capacity;
+ if (buf->start + output_len > buf->capacity) {
+ overflow = (buf->start + output_len) % buf->capacity;
}
- if( output != NULL )
- {
- memcpy( output, buf->buffer + buf->start, output_len - overflow );
- memcpy( output + output_len - overflow, buf->buffer, overflow );
+ if (output != NULL) {
+ memcpy(output, buf->buffer + buf->start, output_len - overflow);
+ memcpy(output + output_len - overflow, buf->buffer, overflow);
}
buf->content_length -= output_len;
- buf->start = ( buf->start + output_len ) % buf->capacity;
+ buf->start = (buf->start + output_len) % buf->capacity;
return output_len;
}
@@ -328,8 +322,7 @@
/*
* Context for a message metadata queue (fifo) that is on top of the ring buffer.
*/
-typedef struct mbedtls_test_message_queue
-{
+typedef struct mbedtls_test_message_queue {
size_t *messages;
int pos;
int num;
@@ -345,12 +338,13 @@
* \retval 0, if a metadata queue of a given length can be allocated.
* \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation failed.
*/
-int mbedtls_test_message_queue_setup( mbedtls_test_message_queue *queue,
- size_t capacity )
+int mbedtls_test_message_queue_setup(mbedtls_test_message_queue *queue,
+ size_t capacity)
{
- queue->messages = (size_t*) mbedtls_calloc( capacity, sizeof(size_t) );
- if( NULL == queue->messages )
+ queue->messages = (size_t *) mbedtls_calloc(capacity, sizeof(size_t));
+ if (NULL == queue->messages) {
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
+ }
queue->capacity = capacity;
queue->pos = 0;
@@ -359,15 +353,17 @@
return 0;
}
-void mbedtls_test_message_queue_free( mbedtls_test_message_queue *queue )
+void mbedtls_test_message_queue_free(mbedtls_test_message_queue *queue)
{
- if( queue == NULL )
+ if (queue == NULL) {
return;
+ }
- if( queue->messages != NULL )
- mbedtls_free( queue->messages );
+ if (queue->messages != NULL) {
+ mbedtls_free(queue->messages);
+ }
- memset( queue, 0, sizeof( *queue ) );
+ memset(queue, 0, sizeof(*queue));
}
/*
@@ -378,17 +374,19 @@
* \retval MBEDTLS_ERR_SSL_WANT_WRITE, if the queue is full.
* \retval \p len, if the push was successful.
*/
-int mbedtls_test_message_queue_push_info( mbedtls_test_message_queue *queue,
- size_t len )
+int mbedtls_test_message_queue_push_info(mbedtls_test_message_queue *queue,
+ size_t len)
{
int place;
- if( queue == NULL )
+ if (queue == NULL) {
return MBEDTLS_TEST_ERROR_ARG_NULL;
+ }
- if( queue->num >= queue->capacity )
+ if (queue->num >= queue->capacity) {
return MBEDTLS_ERR_SSL_WANT_WRITE;
+ }
- place = ( queue->pos + queue->num ) % queue->capacity;
+ place = (queue->pos + queue->num) % queue->capacity;
queue->messages[place] = len;
queue->num++;
return len;
@@ -404,24 +402,27 @@
* \retval message length, if the pop was successful, up to the given
\p buf_len.
*/
-int mbedtls_test_message_queue_pop_info( mbedtls_test_message_queue *queue,
- size_t buf_len )
+int mbedtls_test_message_queue_pop_info(mbedtls_test_message_queue *queue,
+ size_t buf_len)
{
size_t message_length;
- if( queue == NULL )
+ if (queue == NULL) {
return MBEDTLS_TEST_ERROR_ARG_NULL;
- if( queue->num == 0 )
+ }
+ if (queue->num == 0) {
return MBEDTLS_ERR_SSL_WANT_READ;
+ }
message_length = queue->messages[queue->pos];
queue->messages[queue->pos] = 0;
queue->num--;
queue->pos++;
queue->pos %= queue->capacity;
- if( queue->pos < 0 )
+ if (queue->pos < 0) {
queue->pos += queue->capacity;
+ }
- return ( message_length > buf_len ) ? buf_len : message_length;
+ return (message_length > buf_len) ? buf_len : message_length;
}
/*
@@ -436,16 +437,18 @@
* set to the full message length so that the
* caller knows what portion of the message can be dropped.
*/
-int mbedtls_test_message_queue_peek_info( mbedtls_test_message_queue *queue,
- size_t buf_len, size_t* msg_len )
+int mbedtls_test_message_queue_peek_info(mbedtls_test_message_queue *queue,
+ size_t buf_len, size_t *msg_len)
{
- if( queue == NULL || msg_len == NULL )
+ if (queue == NULL || msg_len == NULL) {
return MBEDTLS_TEST_ERROR_ARG_NULL;
- if( queue->num == 0 )
+ }
+ if (queue->num == 0) {
return MBEDTLS_ERR_SSL_WANT_READ;
+ }
*msg_len = queue->messages[queue->pos];
- return ( *msg_len > buf_len ) ? MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED : 0;
+ return (*msg_len > buf_len) ? MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED : 0;
}
/*
* Context for the I/O callbacks simulating network connection.
@@ -453,8 +456,7 @@
#define MBEDTLS_MOCK_SOCKET_CONNECTED 1
-typedef struct mbedtls_mock_socket
-{
+typedef struct mbedtls_mock_socket {
int status;
mbedtls_test_buffer *input;
mbedtls_test_buffer *output;
@@ -464,9 +466,9 @@
/*
* Setup and teardown functions for mock sockets.
*/
-void mbedtls_mock_socket_init( mbedtls_mock_socket *socket )
+void mbedtls_mock_socket_init(mbedtls_mock_socket *socket)
{
- memset( socket, 0, sizeof( *socket ) );
+ memset(socket, 0, sizeof(*socket));
}
/*
@@ -482,27 +484,27 @@
* phenomenon that when closing a UDP connection the peer is not aware of the
* connection having been closed.
*/
-void mbedtls_mock_socket_close( mbedtls_mock_socket* socket )
+void mbedtls_mock_socket_close(mbedtls_mock_socket *socket)
{
- if( socket == NULL )
+ if (socket == NULL) {
return;
-
- if( socket->input != NULL )
- {
- mbedtls_test_buffer_free( socket->input );
- mbedtls_free( socket->input );
}
- if( socket->output != NULL )
- {
- mbedtls_test_buffer_free( socket->output );
- mbedtls_free( socket->output );
+ if (socket->input != NULL) {
+ mbedtls_test_buffer_free(socket->input);
+ mbedtls_free(socket->input);
}
- if( socket->peer != NULL )
- memset( socket->peer, 0, sizeof( *socket->peer ) );
+ if (socket->output != NULL) {
+ mbedtls_test_buffer_free(socket->output);
+ mbedtls_free(socket->output);
+ }
- memset( socket, 0, sizeof( *socket ) );
+ if (socket->peer != NULL) {
+ memset(socket->peer, 0, sizeof(*socket->peer));
+ }
+
+ memset(socket, 0, sizeof(*socket));
}
/*
@@ -515,35 +517,31 @@
* the correct value allows for simulation of MTU, sanity testing the mock
* implementation and mocking TCP connections with lower memory cost.
*/
-int mbedtls_mock_socket_connect( mbedtls_mock_socket* peer1,
- mbedtls_mock_socket* peer2,
- size_t bufsize )
+int mbedtls_mock_socket_connect(mbedtls_mock_socket *peer1,
+ mbedtls_mock_socket *peer2,
+ size_t bufsize)
{
int ret = -1;
peer1->output =
- (mbedtls_test_buffer*) mbedtls_calloc( 1, sizeof(mbedtls_test_buffer) );
- if( peer1->output == NULL )
- {
+ (mbedtls_test_buffer *) mbedtls_calloc(1, sizeof(mbedtls_test_buffer));
+ if (peer1->output == NULL) {
ret = MBEDTLS_ERR_SSL_ALLOC_FAILED;
goto exit;
}
- mbedtls_test_buffer_init( peer1->output );
- if( 0 != ( ret = mbedtls_test_buffer_setup( peer1->output, bufsize ) ) )
- {
+ mbedtls_test_buffer_init(peer1->output);
+ if (0 != (ret = mbedtls_test_buffer_setup(peer1->output, bufsize))) {
goto exit;
}
peer2->output =
- (mbedtls_test_buffer*) mbedtls_calloc( 1, sizeof(mbedtls_test_buffer) );
- if( peer2->output == NULL )
- {
+ (mbedtls_test_buffer *) mbedtls_calloc(1, sizeof(mbedtls_test_buffer));
+ if (peer2->output == NULL) {
ret = MBEDTLS_ERR_SSL_ALLOC_FAILED;
goto exit;
}
- mbedtls_test_buffer_init( peer2->output );
- if( 0 != ( ret = mbedtls_test_buffer_setup( peer2->output, bufsize ) ) )
- {
+ mbedtls_test_buffer_init(peer2->output);
+ if (0 != (ret = mbedtls_test_buffer_setup(peer2->output, bufsize))) {
goto exit;
}
@@ -557,10 +555,9 @@
exit:
- if( ret != 0 )
- {
- mbedtls_mock_socket_close( peer1 );
- mbedtls_mock_socket_close( peer2 );
+ if (ret != 0) {
+ mbedtls_mock_socket_close(peer1);
+ mbedtls_mock_socket_close(peer2);
}
return ret;
@@ -570,58 +567,60 @@
* Callbacks for simulating blocking I/O over connection-oriented transport.
*/
-int mbedtls_mock_tcp_send_b( void *ctx, const unsigned char *buf, size_t len )
+int mbedtls_mock_tcp_send_b(void *ctx, const unsigned char *buf, size_t len)
{
- mbedtls_mock_socket *socket = (mbedtls_mock_socket*) ctx;
+ mbedtls_mock_socket *socket = (mbedtls_mock_socket *) ctx;
- if( socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED )
+ if (socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED) {
return -1;
+ }
- return mbedtls_test_buffer_put( socket->output, buf, len );
+ return mbedtls_test_buffer_put(socket->output, buf, len);
}
-int mbedtls_mock_tcp_recv_b( void *ctx, unsigned char *buf, size_t len )
+int mbedtls_mock_tcp_recv_b(void *ctx, unsigned char *buf, size_t len)
{
- mbedtls_mock_socket *socket = (mbedtls_mock_socket*) ctx;
+ mbedtls_mock_socket *socket = (mbedtls_mock_socket *) ctx;
- if( socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED )
+ if (socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED) {
return -1;
+ }
- return mbedtls_test_buffer_get( socket->input, buf, len );
+ return mbedtls_test_buffer_get(socket->input, buf, len);
}
/*
* Callbacks for simulating non-blocking I/O over connection-oriented transport.
*/
-int mbedtls_mock_tcp_send_nb( void *ctx, const unsigned char *buf, size_t len )
+int mbedtls_mock_tcp_send_nb(void *ctx, const unsigned char *buf, size_t len)
{
- mbedtls_mock_socket *socket = (mbedtls_mock_socket*) ctx;
+ mbedtls_mock_socket *socket = (mbedtls_mock_socket *) ctx;
- if( socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED )
+ if (socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED) {
return -1;
+ }
- if( socket->output->capacity == socket->output->content_length )
- {
+ if (socket->output->capacity == socket->output->content_length) {
return MBEDTLS_ERR_SSL_WANT_WRITE;
}
- return mbedtls_test_buffer_put( socket->output, buf, len );
+ return mbedtls_test_buffer_put(socket->output, buf, len);
}
-int mbedtls_mock_tcp_recv_nb( void *ctx, unsigned char *buf, size_t len )
+int mbedtls_mock_tcp_recv_nb(void *ctx, unsigned char *buf, size_t len)
{
- mbedtls_mock_socket *socket = (mbedtls_mock_socket*) ctx;
+ mbedtls_mock_socket *socket = (mbedtls_mock_socket *) ctx;
- if( socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED )
+ if (socket == NULL || socket->status != MBEDTLS_MOCK_SOCKET_CONNECTED) {
return -1;
+ }
- if( socket->input->content_length == 0 )
- {
+ if (socket->input->content_length == 0) {
return MBEDTLS_ERR_SSL_WANT_READ;
}
- return mbedtls_test_buffer_get( socket->input, buf, len );
+ return mbedtls_test_buffer_get(socket->input, buf, len);
}
/* Errors used in the message socket mocks */
@@ -637,14 +636,13 @@
* considered as an owner of the input queue only, which is initialized and
* freed in the respective setup and free calls.
*/
-typedef struct mbedtls_test_message_socket_context
-{
- mbedtls_test_message_queue* queue_input;
- mbedtls_test_message_queue* queue_output;
- mbedtls_mock_socket* socket;
+typedef struct mbedtls_test_message_socket_context {
+ mbedtls_test_message_queue *queue_input;
+ mbedtls_test_message_queue *queue_output;
+ mbedtls_mock_socket *socket;
} mbedtls_test_message_socket_context;
-void mbedtls_message_socket_init( mbedtls_test_message_socket_context *ctx )
+void mbedtls_message_socket_init(mbedtls_test_message_socket_context *ctx)
{
ctx->queue_input = NULL;
ctx->queue_output = NULL;
@@ -660,19 +658,20 @@
* \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation of a message
* queue failed.
*/
-int mbedtls_message_socket_setup( mbedtls_test_message_queue* queue_input,
- mbedtls_test_message_queue* queue_output,
- size_t queue_capacity,
- mbedtls_mock_socket* socket,
- mbedtls_test_message_socket_context* ctx )
+int mbedtls_message_socket_setup(mbedtls_test_message_queue *queue_input,
+ mbedtls_test_message_queue *queue_output,
+ size_t queue_capacity,
+ mbedtls_mock_socket *socket,
+ mbedtls_test_message_socket_context *ctx)
{
- int ret = mbedtls_test_message_queue_setup( queue_input, queue_capacity );
- if( ret != 0 )
+ int ret = mbedtls_test_message_queue_setup(queue_input, queue_capacity);
+ if (ret != 0) {
return ret;
+ }
ctx->queue_input = queue_input;
ctx->queue_output = queue_output;
ctx->socket = socket;
- mbedtls_mock_socket_init( socket );
+ mbedtls_mock_socket_init(socket);
return 0;
}
@@ -681,14 +680,15 @@
* Close a given message socket context, along with the socket itself. Free the
* memory allocated by the input queue.
*/
-void mbedtls_message_socket_close( mbedtls_test_message_socket_context* ctx )
+void mbedtls_message_socket_close(mbedtls_test_message_socket_context *ctx)
{
- if( ctx == NULL )
+ if (ctx == NULL) {
return;
+ }
- mbedtls_test_message_queue_free( ctx->queue_input );
- mbedtls_mock_socket_close( ctx->socket );
- memset( ctx, 0, sizeof( *ctx ) );
+ mbedtls_test_message_queue_free(ctx->queue_input);
+ mbedtls_mock_socket_close(ctx->socket);
+ memset(ctx, 0, sizeof(*ctx));
}
/*
@@ -703,28 +703,29 @@
* This function will also return any error from
* mbedtls_test_message_queue_push_info.
*/
-int mbedtls_mock_tcp_send_msg( void *ctx, const unsigned char *buf, size_t len )
+int mbedtls_mock_tcp_send_msg(void *ctx, const unsigned char *buf, size_t len)
{
- mbedtls_test_message_queue* queue;
- mbedtls_mock_socket* socket;
- mbedtls_test_message_socket_context *context = (mbedtls_test_message_socket_context*) ctx;
+ mbedtls_test_message_queue *queue;
+ mbedtls_mock_socket *socket;
+ mbedtls_test_message_socket_context *context = (mbedtls_test_message_socket_context *) ctx;
- if( context == NULL || context->socket == NULL
- || context->queue_output == NULL )
- {
+ if (context == NULL || context->socket == NULL
+ || context->queue_output == NULL) {
return MBEDTLS_TEST_ERROR_CONTEXT_ERROR;
}
queue = context->queue_output;
socket = context->socket;
- if( queue->num >= queue->capacity )
+ if (queue->num >= queue->capacity) {
return MBEDTLS_ERR_SSL_WANT_WRITE;
+ }
- if( mbedtls_mock_tcp_send_b( socket, buf, len ) != (int) len )
+ if (mbedtls_mock_tcp_send_b(socket, buf, len) != (int) len) {
return MBEDTLS_TEST_ERROR_SEND_FAILED;
+ }
- return mbedtls_test_message_queue_push_info( queue, len );
+ return mbedtls_test_message_queue_push_info(queue, len);
}
/*
@@ -739,18 +740,17 @@
* This function will also return any error other than
* MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED from mbedtls_test_message_queue_peek_info.
*/
-int mbedtls_mock_tcp_recv_msg( void *ctx, unsigned char *buf, size_t buf_len )
+int mbedtls_mock_tcp_recv_msg(void *ctx, unsigned char *buf, size_t buf_len)
{
- mbedtls_test_message_queue* queue;
- mbedtls_mock_socket* socket;
- mbedtls_test_message_socket_context *context = (mbedtls_test_message_socket_context*) ctx;
+ mbedtls_test_message_queue *queue;
+ mbedtls_mock_socket *socket;
+ mbedtls_test_message_socket_context *context = (mbedtls_test_message_socket_context *) ctx;
size_t drop_len = 0;
size_t msg_len;
int ret;
- if( context == NULL || context->socket == NULL
- || context->queue_input == NULL )
- {
+ if (context == NULL || context->socket == NULL
+ || context->queue_input == NULL) {
return MBEDTLS_TEST_ERROR_CONTEXT_ERROR;
}
@@ -759,33 +759,30 @@
/* Peek first, so that in case of a socket error the data remains in
* the queue. */
- ret = mbedtls_test_message_queue_peek_info( queue, buf_len, &msg_len );
- if( ret == MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED )
- {
+ ret = mbedtls_test_message_queue_peek_info(queue, buf_len, &msg_len);
+ if (ret == MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED) {
/* Calculate how much to drop */
drop_len = msg_len - buf_len;
/* Set the requested message len to be buffer length */
msg_len = buf_len;
- } else if( ret != 0 )
- {
+ } else if (ret != 0) {
return ret;
}
- if( mbedtls_mock_tcp_recv_b( socket, buf, msg_len ) != (int) msg_len )
+ if (mbedtls_mock_tcp_recv_b(socket, buf, msg_len) != (int) msg_len) {
return MBEDTLS_TEST_ERROR_RECV_FAILED;
+ }
- if( ret == MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED )
- {
+ if (ret == MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED) {
/* Drop the remaining part of the message */
- if( mbedtls_mock_tcp_recv_b( socket, NULL, drop_len ) != (int) drop_len )
- {
- /* Inconsistent state - part of the message was read,
- * and a part couldn't. Not much we can do here, but it should not
- * happen in test environment, unless forced manually. */
+ if (mbedtls_mock_tcp_recv_b(socket, NULL, drop_len) != (int) drop_len) {
+ /* Inconsistent state - part of the message was read,
+ * and a part couldn't. Not much we can do here, but it should not
+ * happen in test environment, unless forced manually. */
}
}
- mbedtls_test_message_queue_pop_info( queue, buf_len );
+ mbedtls_test_message_queue_pop_info(queue, buf_len);
return msg_len;
}
@@ -795,18 +792,16 @@
/*
* Structure with endpoint's certificates for SSL communication tests.
*/
-typedef struct mbedtls_endpoint_certificate
-{
- mbedtls_x509_crt* ca_cert;
- mbedtls_x509_crt* cert;
- mbedtls_pk_context* pkey;
+typedef struct mbedtls_endpoint_certificate {
+ mbedtls_x509_crt *ca_cert;
+ mbedtls_x509_crt *cert;
+ mbedtls_pk_context *pkey;
} mbedtls_endpoint_certificate;
/*
* Endpoint structure for SSL communication tests.
*/
-typedef struct mbedtls_endpoint
-{
+typedef struct mbedtls_endpoint {
const char *name;
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
@@ -817,34 +812,29 @@
/*
* Deinitializes certificates from endpoint represented by \p ep.
*/
-void mbedtls_endpoint_certificate_free( mbedtls_endpoint *ep )
+void mbedtls_endpoint_certificate_free(mbedtls_endpoint *ep)
{
- mbedtls_endpoint_certificate *cert = &( ep->cert );
- if( cert != NULL )
- {
- if( cert->ca_cert != NULL )
- {
- mbedtls_x509_crt_free( cert->ca_cert );
- mbedtls_free( cert->ca_cert );
+ mbedtls_endpoint_certificate *cert = &(ep->cert);
+ if (cert != NULL) {
+ if (cert->ca_cert != NULL) {
+ mbedtls_x509_crt_free(cert->ca_cert);
+ mbedtls_free(cert->ca_cert);
cert->ca_cert = NULL;
}
- if( cert->cert != NULL )
- {
- mbedtls_x509_crt_free( cert->cert );
- mbedtls_free( cert->cert );
+ if (cert->cert != NULL) {
+ mbedtls_x509_crt_free(cert->cert);
+ mbedtls_free(cert->cert);
cert->cert = NULL;
}
- if( cert->pkey != NULL )
- {
+ if (cert->pkey != NULL) {
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- if( mbedtls_pk_get_type( cert->pkey ) == MBEDTLS_PK_OPAQUE )
- {
+ if (mbedtls_pk_get_type(cert->pkey) == MBEDTLS_PK_OPAQUE) {
mbedtls_svc_key_id_t *key_slot = cert->pkey->pk_ctx;
- psa_destroy_key( *key_slot );
+ psa_destroy_key(*key_slot);
}
#endif
- mbedtls_pk_free( cert->pkey );
- mbedtls_free( cert->pkey );
+ mbedtls_pk_free(cert->pkey);
+ mbedtls_free(cert->pkey);
cert->pkey = NULL;
}
}
@@ -856,9 +846,9 @@
*
* \retval 0 on success, otherwise error code.
*/
-int mbedtls_endpoint_certificate_init( mbedtls_endpoint *ep, int pk_alg,
- int opaque_alg, int opaque_alg2,
- int opaque_usage )
+int mbedtls_endpoint_certificate_init(mbedtls_endpoint *ep, int pk_alg,
+ int opaque_alg, int opaque_alg2,
+ int opaque_usage)
{
int i = 0;
int ret = -1;
@@ -867,97 +857,85 @@
mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT;
#endif
- if( ep == NULL )
- {
+ if (ep == NULL) {
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
}
- cert = &( ep->cert );
- ASSERT_ALLOC( cert->ca_cert, 1 );
- ASSERT_ALLOC( cert->cert, 1 );
- ASSERT_ALLOC( cert->pkey, 1 );
+ cert = &(ep->cert);
+ ASSERT_ALLOC(cert->ca_cert, 1);
+ ASSERT_ALLOC(cert->cert, 1);
+ ASSERT_ALLOC(cert->pkey, 1);
- mbedtls_x509_crt_init( cert->ca_cert );
- mbedtls_x509_crt_init( cert->cert );
- mbedtls_pk_init( cert->pkey );
+ mbedtls_x509_crt_init(cert->ca_cert);
+ mbedtls_x509_crt_init(cert->cert);
+ mbedtls_pk_init(cert->pkey);
/* Load the trusted CA */
- for( i = 0; mbedtls_test_cas_der[i] != NULL; i++ )
- {
- ret = mbedtls_x509_crt_parse_der( cert->ca_cert,
- (const unsigned char *) mbedtls_test_cas_der[i],
- mbedtls_test_cas_der_len[i] );
- TEST_ASSERT( ret == 0 );
+ for (i = 0; mbedtls_test_cas_der[i] != NULL; i++) {
+ ret = mbedtls_x509_crt_parse_der(cert->ca_cert,
+ (const unsigned char *) mbedtls_test_cas_der[i],
+ mbedtls_test_cas_der_len[i]);
+ TEST_ASSERT(ret == 0);
}
/* Load own certificate and private key */
- if( ep->conf.endpoint == MBEDTLS_SSL_IS_SERVER )
- {
- if( pk_alg == MBEDTLS_PK_RSA )
- {
- ret = mbedtls_x509_crt_parse( cert->cert,
- (const unsigned char*) mbedtls_test_srv_crt_rsa_sha256_der,
- mbedtls_test_srv_crt_rsa_sha256_der_len );
- TEST_ASSERT( ret == 0 );
+ if (ep->conf.endpoint == MBEDTLS_SSL_IS_SERVER) {
+ if (pk_alg == MBEDTLS_PK_RSA) {
+ ret = mbedtls_x509_crt_parse(cert->cert,
+ (const unsigned char *) mbedtls_test_srv_crt_rsa_sha256_der,
+ mbedtls_test_srv_crt_rsa_sha256_der_len);
+ TEST_ASSERT(ret == 0);
- ret = mbedtls_pk_parse_key( cert->pkey,
- (const unsigned char*) mbedtls_test_srv_key_rsa_der,
- mbedtls_test_srv_key_rsa_der_len, NULL, 0,
- mbedtls_test_rnd_std_rand, NULL );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_pk_parse_key(cert->pkey,
+ (const unsigned char *) mbedtls_test_srv_key_rsa_der,
+ mbedtls_test_srv_key_rsa_der_len, NULL, 0,
+ mbedtls_test_rnd_std_rand, NULL);
+ TEST_ASSERT(ret == 0);
+ } else {
+ ret = mbedtls_x509_crt_parse(cert->cert,
+ (const unsigned char *) mbedtls_test_srv_crt_ec_der,
+ mbedtls_test_srv_crt_ec_der_len);
+ TEST_ASSERT(ret == 0);
+
+ ret = mbedtls_pk_parse_key(cert->pkey,
+ (const unsigned char *) mbedtls_test_srv_key_ec_der,
+ mbedtls_test_srv_key_ec_der_len, NULL, 0,
+ mbedtls_test_rnd_std_rand, NULL);
+ TEST_ASSERT(ret == 0);
}
- else
- {
- ret = mbedtls_x509_crt_parse( cert->cert,
- (const unsigned char*) mbedtls_test_srv_crt_ec_der,
- mbedtls_test_srv_crt_ec_der_len );
- TEST_ASSERT( ret == 0 );
+ } else {
+ if (pk_alg == MBEDTLS_PK_RSA) {
+ ret = mbedtls_x509_crt_parse(cert->cert,
+ (const unsigned char *) mbedtls_test_cli_crt_rsa_der,
+ mbedtls_test_cli_crt_rsa_der_len);
+ TEST_ASSERT(ret == 0);
- ret = mbedtls_pk_parse_key( cert->pkey,
- (const unsigned char*) mbedtls_test_srv_key_ec_der,
- mbedtls_test_srv_key_ec_der_len, NULL, 0,
- mbedtls_test_rnd_std_rand, NULL );
- TEST_ASSERT( ret == 0 );
- }
- }
- else
- {
- if( pk_alg == MBEDTLS_PK_RSA )
- {
- ret = mbedtls_x509_crt_parse( cert->cert,
- (const unsigned char *) mbedtls_test_cli_crt_rsa_der,
- mbedtls_test_cli_crt_rsa_der_len );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_pk_parse_key(cert->pkey,
+ (const unsigned char *) mbedtls_test_cli_key_rsa_der,
+ mbedtls_test_cli_key_rsa_der_len, NULL, 0,
+ mbedtls_test_rnd_std_rand, NULL);
+ TEST_ASSERT(ret == 0);
+ } else {
+ ret = mbedtls_x509_crt_parse(cert->cert,
+ (const unsigned char *) mbedtls_test_cli_crt_ec_der,
+ mbedtls_test_cli_crt_ec_len);
+ TEST_ASSERT(ret == 0);
- ret = mbedtls_pk_parse_key( cert->pkey,
- (const unsigned char *) mbedtls_test_cli_key_rsa_der,
- mbedtls_test_cli_key_rsa_der_len, NULL, 0,
- mbedtls_test_rnd_std_rand, NULL );
- TEST_ASSERT( ret == 0 );
- }
- else
- {
- ret = mbedtls_x509_crt_parse( cert->cert,
- (const unsigned char *) mbedtls_test_cli_crt_ec_der,
- mbedtls_test_cli_crt_ec_len );
- TEST_ASSERT( ret == 0 );
-
- ret = mbedtls_pk_parse_key( cert->pkey,
- (const unsigned char *) mbedtls_test_cli_key_ec_der,
- mbedtls_test_cli_key_ec_der_len, NULL, 0,
- mbedtls_test_rnd_std_rand, NULL );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_pk_parse_key(cert->pkey,
+ (const unsigned char *) mbedtls_test_cli_key_ec_der,
+ mbedtls_test_cli_key_ec_der_len, NULL, 0,
+ mbedtls_test_rnd_std_rand, NULL);
+ TEST_ASSERT(ret == 0);
}
}
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- if( opaque_alg != 0 )
- {
- TEST_EQUAL( mbedtls_pk_wrap_as_opaque( cert->pkey, &key_slot,
- opaque_alg, opaque_usage,
- opaque_alg2 ), 0 );
+ if (opaque_alg != 0) {
+ TEST_EQUAL(mbedtls_pk_wrap_as_opaque(cert->pkey, &key_slot,
+ opaque_alg, opaque_usage,
+ opaque_alg2), 0);
}
#else
(void) opaque_alg;
@@ -965,25 +943,24 @@
(void) opaque_usage;
#endif
- mbedtls_ssl_conf_ca_chain( &( ep->conf ), cert->ca_cert, NULL );
+ mbedtls_ssl_conf_ca_chain(&(ep->conf), cert->ca_cert, NULL);
- ret = mbedtls_ssl_conf_own_cert( &( ep->conf ), cert->cert,
- cert->pkey );
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( ep->conf.key_cert != NULL );
+ ret = mbedtls_ssl_conf_own_cert(&(ep->conf), cert->cert,
+ cert->pkey);
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(ep->conf.key_cert != NULL);
- ret = mbedtls_ssl_conf_own_cert( &( ep->conf ), NULL, NULL );
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( ep->conf.key_cert == NULL );
+ ret = mbedtls_ssl_conf_own_cert(&(ep->conf), NULL, NULL);
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(ep->conf.key_cert == NULL);
- ret = mbedtls_ssl_conf_own_cert( &( ep->conf ), cert->cert,
- cert->pkey );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ssl_conf_own_cert(&(ep->conf), cert->cert,
+ cert->pkey);
+ TEST_ASSERT(ret == 0);
exit:
- if( ret != 0 )
- {
- mbedtls_endpoint_certificate_free( ep );
+ if (ret != 0) {
+ mbedtls_endpoint_certificate_free(ep);
}
return ret;
@@ -1003,107 +980,104 @@
*
* \retval 0 on success, otherwise error code.
*/
-int mbedtls_endpoint_init( mbedtls_endpoint *ep, int endpoint_type,
- handshake_test_options *options,
- mbedtls_test_message_socket_context *dtls_context,
- mbedtls_test_message_queue *input_queue,
- mbedtls_test_message_queue *output_queue,
- uint16_t* group_list )
+int mbedtls_endpoint_init(mbedtls_endpoint *ep, int endpoint_type,
+ handshake_test_options *options,
+ mbedtls_test_message_socket_context *dtls_context,
+ mbedtls_test_message_queue *input_queue,
+ mbedtls_test_message_queue *output_queue,
+ uint16_t *group_list)
{
int ret = -1;
uintptr_t user_data_n;
- if( dtls_context != NULL && ( input_queue == NULL || output_queue == NULL ) )
+ if (dtls_context != NULL && (input_queue == NULL || output_queue == NULL)) {
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
-
- if( ep == NULL )
- return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
-
- memset( ep, 0, sizeof( *ep ) );
-
- ep->name = ( endpoint_type == MBEDTLS_SSL_IS_SERVER ) ? "Server" : "Client";
-
- mbedtls_ssl_init( &( ep->ssl ) );
- mbedtls_ssl_config_init( &( ep->conf ) );
- mbedtls_ssl_conf_rng( &( ep->conf ), rng_get, NULL );
-
- TEST_ASSERT( mbedtls_ssl_conf_get_user_data_p( &ep->conf ) == NULL );
- TEST_EQUAL( mbedtls_ssl_conf_get_user_data_n( &ep->conf ), 0 );
- TEST_ASSERT( mbedtls_ssl_get_user_data_p( &ep->ssl ) == NULL );
- TEST_EQUAL( mbedtls_ssl_get_user_data_n( &ep->ssl ), 0 );
-
- (void) mbedtls_test_rnd_std_rand( NULL,
- (void*) &user_data_n,
- sizeof( user_data_n ) );
- mbedtls_ssl_conf_set_user_data_n( &ep->conf, user_data_n );
- mbedtls_ssl_set_user_data_n( &ep->ssl, user_data_n );
-
- if( dtls_context != NULL )
- {
- TEST_ASSERT( mbedtls_message_socket_setup( input_queue, output_queue,
- 100, &( ep->socket ),
- dtls_context ) == 0 );
}
- else
- {
- mbedtls_mock_socket_init( &( ep->socket ) );
+
+ if (ep == NULL) {
+ return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
+ }
+
+ memset(ep, 0, sizeof(*ep));
+
+ ep->name = (endpoint_type == MBEDTLS_SSL_IS_SERVER) ? "Server" : "Client";
+
+ mbedtls_ssl_init(&(ep->ssl));
+ mbedtls_ssl_config_init(&(ep->conf));
+ mbedtls_ssl_conf_rng(&(ep->conf), rng_get, NULL);
+
+ TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&ep->conf) == NULL);
+ TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf), 0);
+ TEST_ASSERT(mbedtls_ssl_get_user_data_p(&ep->ssl) == NULL);
+ TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), 0);
+
+ (void) mbedtls_test_rnd_std_rand(NULL,
+ (void *) &user_data_n,
+ sizeof(user_data_n));
+ mbedtls_ssl_conf_set_user_data_n(&ep->conf, user_data_n);
+ mbedtls_ssl_set_user_data_n(&ep->ssl, user_data_n);
+
+ if (dtls_context != NULL) {
+ TEST_ASSERT(mbedtls_message_socket_setup(input_queue, output_queue,
+ 100, &(ep->socket),
+ dtls_context) == 0);
+ } else {
+ mbedtls_mock_socket_init(&(ep->socket));
}
/* Non-blocking callbacks without timeout */
- if( dtls_context != NULL )
- {
- mbedtls_ssl_set_bio( &( ep->ssl ), dtls_context,
- mbedtls_mock_tcp_send_msg,
- mbedtls_mock_tcp_recv_msg,
- NULL );
- }
- else
- {
- mbedtls_ssl_set_bio( &( ep->ssl ), &( ep->socket ),
- mbedtls_mock_tcp_send_nb,
- mbedtls_mock_tcp_recv_nb,
- NULL );
+ if (dtls_context != NULL) {
+ mbedtls_ssl_set_bio(&(ep->ssl), dtls_context,
+ mbedtls_mock_tcp_send_msg,
+ mbedtls_mock_tcp_recv_msg,
+ NULL);
+ } else {
+ mbedtls_ssl_set_bio(&(ep->ssl), &(ep->socket),
+ mbedtls_mock_tcp_send_nb,
+ mbedtls_mock_tcp_recv_nb,
+ NULL);
}
- ret = mbedtls_ssl_config_defaults( &( ep->conf ), endpoint_type,
- ( dtls_context != NULL ) ?
- MBEDTLS_SSL_TRANSPORT_DATAGRAM :
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ssl_config_defaults(&(ep->conf), endpoint_type,
+ (dtls_context != NULL) ?
+ MBEDTLS_SSL_TRANSPORT_DATAGRAM :
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT);
+ TEST_ASSERT(ret == 0);
- if( group_list != NULL )
- mbedtls_ssl_conf_groups( &(ep->conf), group_list );
+ if (group_list != NULL) {
+ mbedtls_ssl_conf_groups(&(ep->conf), group_list);
+ }
- mbedtls_ssl_conf_authmode( &( ep->conf ), MBEDTLS_SSL_VERIFY_REQUIRED );
+ mbedtls_ssl_conf_authmode(&(ep->conf), MBEDTLS_SSL_VERIFY_REQUIRED);
#if defined(MBEDTLS_SSL_CACHE_C) && defined(MBEDTLS_SSL_SRV_C)
- if( endpoint_type == MBEDTLS_SSL_IS_SERVER && options->cache != NULL )
- {
- mbedtls_ssl_conf_session_cache( &( ep->conf ), options->cache,
- mbedtls_ssl_cache_get,
- mbedtls_ssl_cache_set );
+ if (endpoint_type == MBEDTLS_SSL_IS_SERVER && options->cache != NULL) {
+ mbedtls_ssl_conf_session_cache(&(ep->conf), options->cache,
+ mbedtls_ssl_cache_get,
+ mbedtls_ssl_cache_set);
}
#endif
- ret = mbedtls_ssl_setup( &( ep->ssl ), &( ep->conf ) );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ssl_setup(&(ep->ssl), &(ep->conf));
+ TEST_ASSERT(ret == 0);
#if defined(MBEDTLS_SSL_PROTO_DTLS) && defined(MBEDTLS_SSL_SRV_C)
- if( endpoint_type == MBEDTLS_SSL_IS_SERVER && dtls_context != NULL )
- mbedtls_ssl_conf_dtls_cookies( &( ep->conf ), NULL, NULL, NULL );
+ if (endpoint_type == MBEDTLS_SSL_IS_SERVER && dtls_context != NULL) {
+ mbedtls_ssl_conf_dtls_cookies(&(ep->conf), NULL, NULL, NULL);
+ }
#endif
- ret = mbedtls_endpoint_certificate_init( ep, options->pk_alg,
- options->opaque_alg,
- options->opaque_alg2,
- options->opaque_usage );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_endpoint_certificate_init(ep, options->pk_alg,
+ options->opaque_alg,
+ options->opaque_alg2,
+ options->opaque_usage);
+ TEST_ASSERT(ret == 0);
- TEST_EQUAL( mbedtls_ssl_conf_get_user_data_n( &ep->conf ), user_data_n );
- mbedtls_ssl_conf_set_user_data_p( &ep->conf, ep );
- TEST_EQUAL( mbedtls_ssl_get_user_data_n( &ep->ssl ), user_data_n );
- mbedtls_ssl_set_user_data_p( &ep->ssl, ep );
+ TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf), user_data_n);
+ mbedtls_ssl_conf_set_user_data_p(&ep->conf, ep);
+ TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), user_data_n);
+ mbedtls_ssl_set_user_data_p(&ep->ssl, ep);
exit:
return ret;
@@ -1112,21 +1086,18 @@
/*
* Deinitializes endpoint represented by \p ep.
*/
-void mbedtls_endpoint_free( mbedtls_endpoint *ep,
- mbedtls_test_message_socket_context *context )
+void mbedtls_endpoint_free(mbedtls_endpoint *ep,
+ mbedtls_test_message_socket_context *context)
{
- mbedtls_endpoint_certificate_free( ep );
+ mbedtls_endpoint_certificate_free(ep);
- mbedtls_ssl_free( &( ep->ssl ) );
- mbedtls_ssl_config_free( &( ep->conf ) );
+ mbedtls_ssl_free(&(ep->ssl));
+ mbedtls_ssl_config_free(&(ep->conf));
- if( context != NULL )
- {
- mbedtls_message_socket_close( context );
- }
- else
- {
- mbedtls_mock_socket_close( &( ep->socket ) );
+ if (context != NULL) {
+ mbedtls_message_socket_close(context);
+ } else {
+ mbedtls_mock_socket_close(&(ep->socket));
}
}
@@ -1137,45 +1108,40 @@
*
* \retval 0 on success, otherwise error code.
*/
-int mbedtls_move_handshake_to_state( mbedtls_ssl_context *ssl,
- mbedtls_ssl_context *second_ssl,
- int state )
+int mbedtls_move_handshake_to_state(mbedtls_ssl_context *ssl,
+ mbedtls_ssl_context *second_ssl,
+ int state)
{
enum { BUFFSIZE = 1024 };
int max_steps = 1000;
int ret = 0;
- if( ssl == NULL || second_ssl == NULL )
- {
+ if (ssl == NULL || second_ssl == NULL) {
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
}
/* Perform communication via connected sockets */
- while( ( ssl->state != state ) && ( --max_steps >= 0 ) )
- {
+ while ((ssl->state != state) && (--max_steps >= 0)) {
/* If /p second_ssl ends the handshake procedure before /p ssl then
* there is no need to call the next step */
- if( !mbedtls_ssl_is_handshake_over( second_ssl ) )
- {
- ret = mbedtls_ssl_handshake_step( second_ssl );
- if( ret != 0 && ret != MBEDTLS_ERR_SSL_WANT_READ &&
- ret != MBEDTLS_ERR_SSL_WANT_WRITE )
- {
+ if (!mbedtls_ssl_is_handshake_over(second_ssl)) {
+ ret = mbedtls_ssl_handshake_step(second_ssl);
+ if (ret != 0 && ret != MBEDTLS_ERR_SSL_WANT_READ &&
+ ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
return ret;
}
}
/* We only care about the \p ssl state and returns, so we call it last,
* to leave the iteration as soon as the state is as expected. */
- ret = mbedtls_ssl_handshake_step( ssl );
- if( ret != 0 && ret != MBEDTLS_ERR_SSL_WANT_READ &&
- ret != MBEDTLS_ERR_SSL_WANT_WRITE )
- {
+ ret = mbedtls_ssl_handshake_step(ssl);
+ if (ret != 0 && ret != MBEDTLS_ERR_SSL_WANT_READ &&
+ ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
return ret;
}
}
- return ( max_steps >= 0 ) ? ret : -1;
+ return (max_steps >= 0) ? ret : -1;
}
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
@@ -1183,38 +1149,32 @@
/*
* Write application data. Increase write counter if necessary.
*/
-int mbedtls_ssl_write_fragment( mbedtls_ssl_context *ssl, unsigned char *buf,
- int buf_len, int *written,
- const int expected_fragments )
+int mbedtls_ssl_write_fragment(mbedtls_ssl_context *ssl, unsigned char *buf,
+ int buf_len, int *written,
+ const int expected_fragments)
{
- int ret = mbedtls_ssl_write( ssl, buf + *written, buf_len - *written );
- if( ret > 0 )
- {
+ int ret = mbedtls_ssl_write(ssl, buf + *written, buf_len - *written);
+ if (ret > 0) {
*written += ret;
}
- if( expected_fragments == 0 )
- {
+ if (expected_fragments == 0) {
/* Used for DTLS and the message size larger than MFL. In that case
* the message can not be fragmented and the library should return
* MBEDTLS_ERR_SSL_BAD_INPUT_DATA error. This error must be returned
* to prevent a dead loop inside mbedtls_exchange_data(). */
return ret;
- }
- else if( expected_fragments == 1 )
- {
+ } else if (expected_fragments == 1) {
/* Used for TLS/DTLS and the message size lower than MFL */
- TEST_ASSERT( ret == buf_len ||
- ret == MBEDTLS_ERR_SSL_WANT_READ ||
- ret == MBEDTLS_ERR_SSL_WANT_WRITE );
- }
- else
- {
+ TEST_ASSERT(ret == buf_len ||
+ ret == MBEDTLS_ERR_SSL_WANT_READ ||
+ ret == MBEDTLS_ERR_SSL_WANT_WRITE);
+ } else {
/* Used for TLS and the message size larger than MFL */
- TEST_ASSERT( expected_fragments > 1 );
- TEST_ASSERT( ( ret >= 0 && ret <= buf_len ) ||
- ret == MBEDTLS_ERR_SSL_WANT_READ ||
- ret == MBEDTLS_ERR_SSL_WANT_WRITE );
+ TEST_ASSERT(expected_fragments > 1);
+ TEST_ASSERT((ret >= 0 && ret <= buf_len) ||
+ ret == MBEDTLS_ERR_SSL_WANT_READ ||
+ ret == MBEDTLS_ERR_SSL_WANT_WRITE);
}
return 0;
@@ -1227,33 +1187,27 @@
/*
* Read application data and increase read counter and fragments counter if necessary.
*/
-int mbedtls_ssl_read_fragment( mbedtls_ssl_context *ssl, unsigned char *buf,
- int buf_len, int *read,
- int *fragments, const int expected_fragments )
+int mbedtls_ssl_read_fragment(mbedtls_ssl_context *ssl, unsigned char *buf,
+ int buf_len, int *read,
+ int *fragments, const int expected_fragments)
{
- int ret = mbedtls_ssl_read( ssl, buf + *read, buf_len - *read );
- if( ret > 0 )
- {
- ( *fragments )++;
+ int ret = mbedtls_ssl_read(ssl, buf + *read, buf_len - *read);
+ if (ret > 0) {
+ (*fragments)++;
*read += ret;
}
- if( expected_fragments == 0 )
- {
- TEST_ASSERT( ret == 0 );
- }
- else if( expected_fragments == 1 )
- {
- TEST_ASSERT( ret == buf_len ||
- ret == MBEDTLS_ERR_SSL_WANT_READ ||
- ret == MBEDTLS_ERR_SSL_WANT_WRITE );
- }
- else
- {
- TEST_ASSERT( expected_fragments > 1 );
- TEST_ASSERT( ( ret >= 0 && ret <= buf_len ) ||
- ret == MBEDTLS_ERR_SSL_WANT_READ ||
- ret == MBEDTLS_ERR_SSL_WANT_WRITE );
+ if (expected_fragments == 0) {
+ TEST_ASSERT(ret == 0);
+ } else if (expected_fragments == 1) {
+ TEST_ASSERT(ret == buf_len ||
+ ret == MBEDTLS_ERR_SSL_WANT_READ ||
+ ret == MBEDTLS_ERR_SSL_WANT_WRITE);
+ } else {
+ TEST_ASSERT(expected_fragments > 1);
+ TEST_ASSERT((ret >= 0 && ret <= buf_len) ||
+ ret == MBEDTLS_ERR_SSL_WANT_READ ||
+ ret == MBEDTLS_ERR_SSL_WANT_WRITE);
}
return 0;
@@ -1269,54 +1223,52 @@
* and version.
*/
-#define CHK( x ) \
+#define CHK(x) \
do \
{ \
- if( !( x ) ) \
+ if (!(x)) \
{ \
ret = -1; \
goto cleanup; \
} \
- } while( 0 )
+ } while (0)
-void set_ciphersuite( mbedtls_ssl_config *conf, const char *cipher,
- int* forced_ciphersuite )
+void set_ciphersuite(mbedtls_ssl_config *conf, const char *cipher,
+ int *forced_ciphersuite)
{
const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
- forced_ciphersuite[0] = mbedtls_ssl_get_ciphersuite_id( cipher );
+ forced_ciphersuite[0] = mbedtls_ssl_get_ciphersuite_id(cipher);
forced_ciphersuite[1] = 0;
ciphersuite_info =
- mbedtls_ssl_ciphersuite_from_id( forced_ciphersuite[0] );
+ mbedtls_ssl_ciphersuite_from_id(forced_ciphersuite[0]);
- TEST_ASSERT( ciphersuite_info != NULL );
- TEST_ASSERT( ciphersuite_info->min_tls_version <= conf->max_tls_version );
- TEST_ASSERT( ciphersuite_info->max_tls_version >= conf->min_tls_version );
+ TEST_ASSERT(ciphersuite_info != NULL);
+ TEST_ASSERT(ciphersuite_info->min_tls_version <= conf->max_tls_version);
+ TEST_ASSERT(ciphersuite_info->max_tls_version >= conf->min_tls_version);
- if( conf->max_tls_version > ciphersuite_info->max_tls_version )
- {
+ if (conf->max_tls_version > ciphersuite_info->max_tls_version) {
conf->max_tls_version = ciphersuite_info->max_tls_version;
}
- if( conf->min_tls_version < ciphersuite_info->min_tls_version )
- {
+ if (conf->min_tls_version < ciphersuite_info->min_tls_version) {
conf->min_tls_version = ciphersuite_info->min_tls_version;
}
- mbedtls_ssl_conf_ciphersuites( conf, forced_ciphersuite );
+ mbedtls_ssl_conf_ciphersuites(conf, forced_ciphersuite);
exit:
return;
}
-int psk_dummy_callback( void *p_info, mbedtls_ssl_context *ssl,
- const unsigned char *name, size_t name_len )
+int psk_dummy_callback(void *p_info, mbedtls_ssl_context *ssl,
+ const unsigned char *name, size_t name_len)
{
(void) p_info;
(void) ssl;
(void) name;
(void) name_len;
- return ( 0 );
+ return 0;
}
#if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX
@@ -1327,55 +1279,59 @@
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_AES_C)
-static int psa_cipher_encrypt_helper( mbedtls_ssl_transform *transform,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen )
+static int psa_cipher_encrypt_helper(mbedtls_ssl_transform *transform,
+ const unsigned char *iv, size_t iv_len,
+ const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen)
{
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_cipher_operation_t cipher_op = PSA_CIPHER_OPERATION_INIT;
size_t part_len;
- status = psa_cipher_encrypt_setup( &cipher_op,
- transform->psa_key_enc, transform->psa_alg );
+ status = psa_cipher_encrypt_setup(&cipher_op,
+ transform->psa_key_enc, transform->psa_alg);
- if( status != PSA_SUCCESS )
- return( psa_ssl_status_to_mbedtls( status ) );
+ if (status != PSA_SUCCESS) {
+ return psa_ssl_status_to_mbedtls(status);
+ }
- status = psa_cipher_set_iv( &cipher_op, iv, iv_len );
+ status = psa_cipher_set_iv(&cipher_op, iv, iv_len);
- if( status != PSA_SUCCESS )
- return( psa_ssl_status_to_mbedtls( status ) );
+ if (status != PSA_SUCCESS) {
+ return psa_ssl_status_to_mbedtls(status);
+ }
- status = psa_cipher_update( &cipher_op,
- input, ilen, output, ilen, olen );
+ status = psa_cipher_update(&cipher_op,
+ input, ilen, output, ilen, olen);
- if( status != PSA_SUCCESS )
- return( psa_ssl_status_to_mbedtls( status ) );
+ if (status != PSA_SUCCESS) {
+ return psa_ssl_status_to_mbedtls(status);
+ }
- status = psa_cipher_finish( &cipher_op,
- output + *olen, ilen - *olen, &part_len );
+ status = psa_cipher_finish(&cipher_op,
+ output + *olen, ilen - *olen, &part_len);
- if( status != PSA_SUCCESS )
- return( psa_ssl_status_to_mbedtls( status ) );
+ if (status != PSA_SUCCESS) {
+ return psa_ssl_status_to_mbedtls(status);
+ }
*olen += part_len;
- return( 0 );
+ return 0;
#else
- return mbedtls_cipher_crypt( &transform->cipher_ctx_enc,
- iv, iv_len, input, ilen, output, olen );
+ return mbedtls_cipher_crypt(&transform->cipher_ctx_enc,
+ iv, iv_len, input, ilen, output, olen);
#endif /* MBEDTLS_USE_PSA_CRYPTO */
}
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_CIPHER_MODE_CBC && MBEDTLS_AES_C */
-static int build_transforms( mbedtls_ssl_transform *t_in,
- mbedtls_ssl_transform *t_out,
- int cipher_type, int hash_id,
- int etm, int tag_mode,
- mbedtls_ssl_protocol_version tls_version,
- size_t cid0_len,
- size_t cid1_len )
+static int build_transforms(mbedtls_ssl_transform *t_in,
+ mbedtls_ssl_transform *t_out,
+ int cipher_type, int hash_id,
+ int etm, int tag_mode,
+ mbedtls_ssl_protocol_version tls_version,
+ size_t cid0_len,
+ size_t cid1_len)
{
mbedtls_cipher_info_t const *cipher_info;
int ret = 0;
@@ -1394,11 +1350,11 @@
unsigned char iv_enc[16], iv_dec[16];
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- unsigned char cid0[ SSL_CID_LEN_MIN ];
- unsigned char cid1[ SSL_CID_LEN_MIN ];
+ unsigned char cid0[SSL_CID_LEN_MIN];
+ unsigned char cid1[SSL_CID_LEN_MIN];
- mbedtls_test_rnd_std_rand( NULL, cid0, sizeof( cid0 ) );
- mbedtls_test_rnd_std_rand( NULL, cid1, sizeof( cid1 ) );
+ mbedtls_test_rnd_std_rand(NULL, cid0, sizeof(cid0));
+ mbedtls_test_rnd_std_rand(NULL, cid1, sizeof(cid1));
#else
((void) cid0_len);
((void) cid1_len);
@@ -1407,123 +1363,122 @@
maclen = 0;
/* Pick cipher */
- cipher_info = mbedtls_cipher_info_from_type( cipher_type );
- CHK( cipher_info != NULL );
- CHK( cipher_info->iv_size <= 16 );
- CHK( cipher_info->key_bitlen % 8 == 0 );
+ cipher_info = mbedtls_cipher_info_from_type(cipher_type);
+ CHK(cipher_info != NULL);
+ CHK(cipher_info->iv_size <= 16);
+ CHK(cipher_info->key_bitlen % 8 == 0);
/* Pick keys */
keylen = cipher_info->key_bitlen / 8;
/* Allocate `keylen + 1` bytes to ensure that we get
* a non-NULL pointers from `mbedtls_calloc` even if
* `keylen == 0` in the case of the NULL cipher. */
- CHK( ( key0 = mbedtls_calloc( 1, keylen + 1 ) ) != NULL );
- CHK( ( key1 = mbedtls_calloc( 1, keylen + 1 ) ) != NULL );
- memset( key0, 0x1, keylen );
- memset( key1, 0x2, keylen );
+ CHK((key0 = mbedtls_calloc(1, keylen + 1)) != NULL);
+ CHK((key1 = mbedtls_calloc(1, keylen + 1)) != NULL);
+ memset(key0, 0x1, keylen);
+ memset(key1, 0x2, keylen);
#if !defined(MBEDTLS_USE_PSA_CRYPTO)
/* Setup cipher contexts */
- CHK( mbedtls_cipher_setup( &t_in->cipher_ctx_enc, cipher_info ) == 0 );
- CHK( mbedtls_cipher_setup( &t_in->cipher_ctx_dec, cipher_info ) == 0 );
- CHK( mbedtls_cipher_setup( &t_out->cipher_ctx_enc, cipher_info ) == 0 );
- CHK( mbedtls_cipher_setup( &t_out->cipher_ctx_dec, cipher_info ) == 0 );
+ CHK(mbedtls_cipher_setup(&t_in->cipher_ctx_enc, cipher_info) == 0);
+ CHK(mbedtls_cipher_setup(&t_in->cipher_ctx_dec, cipher_info) == 0);
+ CHK(mbedtls_cipher_setup(&t_out->cipher_ctx_enc, cipher_info) == 0);
+ CHK(mbedtls_cipher_setup(&t_out->cipher_ctx_dec, cipher_info) == 0);
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- if( cipher_info->mode == MBEDTLS_MODE_CBC )
- {
- CHK( mbedtls_cipher_set_padding_mode( &t_in->cipher_ctx_enc,
- MBEDTLS_PADDING_NONE ) == 0 );
- CHK( mbedtls_cipher_set_padding_mode( &t_in->cipher_ctx_dec,
- MBEDTLS_PADDING_NONE ) == 0 );
- CHK( mbedtls_cipher_set_padding_mode( &t_out->cipher_ctx_enc,
- MBEDTLS_PADDING_NONE ) == 0 );
- CHK( mbedtls_cipher_set_padding_mode( &t_out->cipher_ctx_dec,
- MBEDTLS_PADDING_NONE ) == 0 );
+ if (cipher_info->mode == MBEDTLS_MODE_CBC) {
+ CHK(mbedtls_cipher_set_padding_mode(&t_in->cipher_ctx_enc,
+ MBEDTLS_PADDING_NONE) == 0);
+ CHK(mbedtls_cipher_set_padding_mode(&t_in->cipher_ctx_dec,
+ MBEDTLS_PADDING_NONE) == 0);
+ CHK(mbedtls_cipher_set_padding_mode(&t_out->cipher_ctx_enc,
+ MBEDTLS_PADDING_NONE) == 0);
+ CHK(mbedtls_cipher_set_padding_mode(&t_out->cipher_ctx_dec,
+ MBEDTLS_PADDING_NONE) == 0);
}
#endif /* MBEDTLS_CIPHER_MODE_CBC */
- CHK( mbedtls_cipher_setkey( &t_in->cipher_ctx_enc, key0,
- keylen << 3, MBEDTLS_ENCRYPT ) == 0 );
- CHK( mbedtls_cipher_setkey( &t_in->cipher_ctx_dec, key1,
- keylen << 3, MBEDTLS_DECRYPT ) == 0 );
- CHK( mbedtls_cipher_setkey( &t_out->cipher_ctx_enc, key1,
- keylen << 3, MBEDTLS_ENCRYPT ) == 0 );
- CHK( mbedtls_cipher_setkey( &t_out->cipher_ctx_dec, key0,
- keylen << 3, MBEDTLS_DECRYPT ) == 0 );
+ CHK(mbedtls_cipher_setkey(&t_in->cipher_ctx_enc, key0,
+ keylen << 3, MBEDTLS_ENCRYPT) == 0);
+ CHK(mbedtls_cipher_setkey(&t_in->cipher_ctx_dec, key1,
+ keylen << 3, MBEDTLS_DECRYPT) == 0);
+ CHK(mbedtls_cipher_setkey(&t_out->cipher_ctx_enc, key1,
+ keylen << 3, MBEDTLS_ENCRYPT) == 0);
+ CHK(mbedtls_cipher_setkey(&t_out->cipher_ctx_dec, key0,
+ keylen << 3, MBEDTLS_DECRYPT) == 0);
#endif
/* Setup MAC contexts */
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
- if( cipher_info->mode == MBEDTLS_MODE_CBC ||
- cipher_info->mode == MBEDTLS_MODE_STREAM )
- {
+ if (cipher_info->mode == MBEDTLS_MODE_CBC ||
+ cipher_info->mode == MBEDTLS_MODE_STREAM) {
#if !defined(MBEDTLS_USE_PSA_CRYPTO)
- mbedtls_md_info_t const *md_info = mbedtls_md_info_from_type( hash_id );
- CHK( md_info != NULL );
+ mbedtls_md_info_t const *md_info = mbedtls_md_info_from_type(hash_id);
+ CHK(md_info != NULL);
#endif
- maclen = mbedtls_hash_info_get_size( hash_id );
- CHK( maclen != 0 );
+ maclen = mbedtls_hash_info_get_size(hash_id);
+ CHK(maclen != 0);
/* Pick hash keys */
- CHK( ( md0 = mbedtls_calloc( 1, maclen ) ) != NULL );
- CHK( ( md1 = mbedtls_calloc( 1, maclen ) ) != NULL );
- memset( md0, 0x5, maclen );
- memset( md1, 0x6, maclen );
+ CHK((md0 = mbedtls_calloc(1, maclen)) != NULL);
+ CHK((md1 = mbedtls_calloc(1, maclen)) != NULL);
+ memset(md0, 0x5, maclen);
+ memset(md1, 0x6, maclen);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- alg = mbedtls_hash_info_psa_from_md( hash_id );
+ alg = mbedtls_hash_info_psa_from_md(hash_id);
- CHK( alg != 0 );
+ CHK(alg != 0);
- t_out->psa_mac_alg = PSA_ALG_HMAC( alg );
- t_in->psa_mac_alg = PSA_ALG_HMAC( alg );
+ t_out->psa_mac_alg = PSA_ALG_HMAC(alg);
+ t_in->psa_mac_alg = PSA_ALG_HMAC(alg);
t_in->psa_mac_enc = MBEDTLS_SVC_KEY_ID_INIT;
t_out->psa_mac_enc = MBEDTLS_SVC_KEY_ID_INIT;
t_in->psa_mac_dec = MBEDTLS_SVC_KEY_ID_INIT;
t_out->psa_mac_dec = MBEDTLS_SVC_KEY_ID_INIT;
- psa_reset_key_attributes( &attributes );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_MESSAGE );
- psa_set_key_algorithm( &attributes, PSA_ALG_HMAC( alg ) );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_HMAC );
+ psa_reset_key_attributes(&attributes);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_MESSAGE);
+ psa_set_key_algorithm(&attributes, PSA_ALG_HMAC(alg));
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_HMAC);
- CHK( psa_import_key( &attributes,
- md0, maclen,
- &t_in->psa_mac_enc ) == PSA_SUCCESS );
+ CHK(psa_import_key(&attributes,
+ md0, maclen,
+ &t_in->psa_mac_enc) == PSA_SUCCESS);
- CHK( psa_import_key( &attributes,
- md1, maclen,
- &t_out->psa_mac_enc ) == PSA_SUCCESS );
+ CHK(psa_import_key(&attributes,
+ md1, maclen,
+ &t_out->psa_mac_enc) == PSA_SUCCESS);
- if( cipher_info->mode == MBEDTLS_MODE_STREAM ||
- etm == MBEDTLS_SSL_ETM_DISABLED )
+ if (cipher_info->mode == MBEDTLS_MODE_STREAM ||
+ etm == MBEDTLS_SSL_ETM_DISABLED) {
/* mbedtls_ct_hmac() requires the key to be exportable */
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT |
- PSA_KEY_USAGE_VERIFY_HASH );
- else
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT |
+ PSA_KEY_USAGE_VERIFY_HASH);
+ } else {
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
+ }
- CHK( psa_import_key( &attributes,
- md1, maclen,
- &t_in->psa_mac_dec ) == PSA_SUCCESS );
+ CHK(psa_import_key(&attributes,
+ md1, maclen,
+ &t_in->psa_mac_dec) == PSA_SUCCESS);
- CHK( psa_import_key( &attributes,
- md0, maclen,
- &t_out->psa_mac_dec ) == PSA_SUCCESS );
+ CHK(psa_import_key(&attributes,
+ md0, maclen,
+ &t_out->psa_mac_dec) == PSA_SUCCESS);
#else
- CHK( mbedtls_md_setup( &t_out->md_ctx_enc, md_info, 1 ) == 0 );
- CHK( mbedtls_md_setup( &t_out->md_ctx_dec, md_info, 1 ) == 0 );
- CHK( mbedtls_md_setup( &t_in->md_ctx_enc, md_info, 1 ) == 0 );
- CHK( mbedtls_md_setup( &t_in->md_ctx_dec, md_info, 1 ) == 0 );
+ CHK(mbedtls_md_setup(&t_out->md_ctx_enc, md_info, 1) == 0);
+ CHK(mbedtls_md_setup(&t_out->md_ctx_dec, md_info, 1) == 0);
+ CHK(mbedtls_md_setup(&t_in->md_ctx_enc, md_info, 1) == 0);
+ CHK(mbedtls_md_setup(&t_in->md_ctx_dec, md_info, 1) == 0);
- CHK( mbedtls_md_hmac_starts( &t_in->md_ctx_enc,
- md0, maclen ) == 0 );
- CHK( mbedtls_md_hmac_starts( &t_in->md_ctx_dec,
- md1, maclen ) == 0 );
- CHK( mbedtls_md_hmac_starts( &t_out->md_ctx_enc,
- md1, maclen ) == 0 );
- CHK( mbedtls_md_hmac_starts( &t_out->md_ctx_dec,
- md0, maclen ) == 0 );
+ CHK(mbedtls_md_hmac_starts(&t_in->md_ctx_enc,
+ md0, maclen) == 0);
+ CHK(mbedtls_md_hmac_starts(&t_in->md_ctx_dec,
+ md1, maclen) == 0);
+ CHK(mbedtls_md_hmac_starts(&t_out->md_ctx_enc,
+ md1, maclen) == 0);
+ CHK(mbedtls_md_hmac_starts(&t_out->md_ctx_dec,
+ md0, maclen) == 0);
#endif
}
#else
@@ -1534,8 +1489,8 @@
/* Pick IV's (regardless of whether they
* are being used by the transform). */
ivlen = cipher_info->iv_size;
- memset( iv_enc, 0x3, sizeof( iv_enc ) );
- memset( iv_dec, 0x4, sizeof( iv_dec ) );
+ memset(iv_enc, 0x3, sizeof(iv_enc));
+ memset(iv_dec, 0x4, sizeof(iv_dec));
/*
* Setup transforms
@@ -1554,17 +1509,14 @@
t_out->ivlen = ivlen;
t_in->ivlen = ivlen;
- switch( cipher_info->mode )
- {
+ switch (cipher_info->mode) {
case MBEDTLS_MODE_GCM:
case MBEDTLS_MODE_CCM:
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if( tls_version == MBEDTLS_SSL_VERSION_TLS1_3 )
- {
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
t_out->fixed_ivlen = 12;
t_in->fixed_ivlen = 12;
- }
- else
+ } else
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
{
t_out->fixed_ivlen = 4;
@@ -1572,8 +1524,7 @@
}
t_out->maclen = 0;
t_in->maclen = 0;
- switch( tag_mode )
- {
+ switch (tag_mode) {
case 0: /* Full tag */
t_out->taglen = 16;
t_in->taglen = 16;
@@ -1593,8 +1544,7 @@
t_in->fixed_ivlen = 12;
t_out->maclen = 0;
t_in->maclen = 0;
- switch( tag_mode )
- {
+ switch (tag_mode) {
case 0: /* Full tag */
t_out->taglen = 16;
t_in->taglen = 16;
@@ -1615,8 +1565,7 @@
t_in->fixed_ivlen = 0; /* redundant, must be 0 */
t_out->taglen = 0;
t_in->taglen = 0;
- switch( tag_mode )
- {
+ switch (tag_mode) {
case 0: /* Full tag */
t_out->maclen = maclen;
t_in->maclen = maclen;
@@ -1634,89 +1583,83 @@
/* Setup IV's */
- memcpy( &t_in->iv_dec, iv_dec, sizeof( iv_dec ) );
- memcpy( &t_in->iv_enc, iv_enc, sizeof( iv_enc ) );
- memcpy( &t_out->iv_dec, iv_enc, sizeof( iv_enc ) );
- memcpy( &t_out->iv_enc, iv_dec, sizeof( iv_dec ) );
+ memcpy(&t_in->iv_dec, iv_dec, sizeof(iv_dec));
+ memcpy(&t_in->iv_enc, iv_enc, sizeof(iv_enc));
+ memcpy(&t_out->iv_dec, iv_enc, sizeof(iv_enc));
+ memcpy(&t_out->iv_enc, iv_dec, sizeof(iv_dec));
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
/* Add CID */
- memcpy( &t_in->in_cid, cid0, cid0_len );
- memcpy( &t_in->out_cid, cid1, cid1_len );
+ memcpy(&t_in->in_cid, cid0, cid0_len);
+ memcpy(&t_in->out_cid, cid1, cid1_len);
t_in->in_cid_len = cid0_len;
t_in->out_cid_len = cid1_len;
- memcpy( &t_out->in_cid, cid1, cid1_len );
- memcpy( &t_out->out_cid, cid0, cid0_len );
+ memcpy(&t_out->in_cid, cid1, cid1_len);
+ memcpy(&t_out->out_cid, cid0, cid0_len);
t_out->in_cid_len = cid1_len;
t_out->out_cid_len = cid0_len;
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- status = mbedtls_ssl_cipher_to_psa( cipher_type,
- t_in->taglen,
- &alg,
- &key_type,
- &key_bits );
+ status = mbedtls_ssl_cipher_to_psa(cipher_type,
+ t_in->taglen,
+ &alg,
+ &key_type,
+ &key_bits);
- if ( status != PSA_SUCCESS )
- {
- ret = psa_ssl_status_to_mbedtls( status );
+ if (status != PSA_SUCCESS) {
+ ret = psa_ssl_status_to_mbedtls(status);
goto cleanup;
}
t_in->psa_alg = alg;
t_out->psa_alg = alg;
- if ( alg != MBEDTLS_SSL_NULL_CIPHER )
- {
- psa_reset_key_attributes( &attributes );
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
- psa_set_key_algorithm( &attributes, alg );
- psa_set_key_type( &attributes, key_type );
+ if (alg != MBEDTLS_SSL_NULL_CIPHER) {
+ psa_reset_key_attributes(&attributes);
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
+ psa_set_key_algorithm(&attributes, alg);
+ psa_set_key_type(&attributes, key_type);
- status = psa_import_key( &attributes,
- key0,
- PSA_BITS_TO_BYTES( key_bits ),
- &t_in->psa_key_enc );
+ status = psa_import_key(&attributes,
+ key0,
+ PSA_BITS_TO_BYTES(key_bits),
+ &t_in->psa_key_enc);
- if ( status != PSA_SUCCESS )
- {
- ret = psa_ssl_status_to_mbedtls( status );
+ if (status != PSA_SUCCESS) {
+ ret = psa_ssl_status_to_mbedtls(status);
goto cleanup;
}
- status = psa_import_key( &attributes,
- key1,
- PSA_BITS_TO_BYTES( key_bits ),
- &t_out->psa_key_enc );
+ status = psa_import_key(&attributes,
+ key1,
+ PSA_BITS_TO_BYTES(key_bits),
+ &t_out->psa_key_enc);
- if ( status != PSA_SUCCESS )
- {
- ret = psa_ssl_status_to_mbedtls( status );
+ if (status != PSA_SUCCESS) {
+ ret = psa_ssl_status_to_mbedtls(status);
goto cleanup;
}
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT);
- status = psa_import_key( &attributes,
- key1,
- PSA_BITS_TO_BYTES( key_bits ),
- &t_in->psa_key_dec );
+ status = psa_import_key(&attributes,
+ key1,
+ PSA_BITS_TO_BYTES(key_bits),
+ &t_in->psa_key_dec);
- if ( status != PSA_SUCCESS )
- {
- ret = psa_ssl_status_to_mbedtls( status );
+ if (status != PSA_SUCCESS) {
+ ret = psa_ssl_status_to_mbedtls(status);
goto cleanup;
}
- status = psa_import_key( &attributes,
- key0,
- PSA_BITS_TO_BYTES( key_bits ),
- &t_out->psa_key_dec );
+ status = psa_import_key(&attributes,
+ key0,
+ PSA_BITS_TO_BYTES(key_bits),
+ &t_out->psa_key_dec);
- if ( status != PSA_SUCCESS )
- {
- ret = psa_ssl_status_to_mbedtls( status );
+ if (status != PSA_SUCCESS) {
+ ret = psa_ssl_status_to_mbedtls(status);
goto cleanup;
}
}
@@ -1724,82 +1667,85 @@
cleanup:
- mbedtls_free( key0 );
- mbedtls_free( key1 );
+ mbedtls_free(key0);
+ mbedtls_free(key1);
- mbedtls_free( md0 );
- mbedtls_free( md1 );
+ mbedtls_free(md0);
+ mbedtls_free(md1);
- return( ret );
+ return ret;
}
/*
* Populate a session structure for serialization tests.
* Choose dummy values, mostly non-0 to distinguish from the init default.
*/
-static int ssl_tls12_populate_session( mbedtls_ssl_session *session,
- int ticket_len,
- const char *crt_file )
+static int ssl_tls12_populate_session(mbedtls_ssl_session *session,
+ int ticket_len,
+ const char *crt_file)
{
#if defined(MBEDTLS_HAVE_TIME)
- session->start = mbedtls_time( NULL ) - 42;
+ session->start = mbedtls_time(NULL) - 42;
#endif
session->tls_version = MBEDTLS_SSL_VERSION_TLS1_2;
session->ciphersuite = 0xabcd;
- session->id_len = sizeof( session->id );
- memset( session->id, 66, session->id_len );
- memset( session->master, 17, sizeof( session->master ) );
+ session->id_len = sizeof(session->id);
+ memset(session->id, 66, session->id_len);
+ memset(session->master, 17, sizeof(session->master));
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) && defined(MBEDTLS_FS_IO)
- if( crt_file != NULL && strlen( crt_file ) != 0 )
- {
+ if (crt_file != NULL && strlen(crt_file) != 0) {
mbedtls_x509_crt tmp_crt;
int ret;
- mbedtls_x509_crt_init( &tmp_crt );
- ret = mbedtls_x509_crt_parse_file( &tmp_crt, crt_file );
- if( ret != 0 )
- return( ret );
+ mbedtls_x509_crt_init(&tmp_crt);
+ ret = mbedtls_x509_crt_parse_file(&tmp_crt, crt_file);
+ if (ret != 0) {
+ return ret;
+ }
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
/* Move temporary CRT. */
- session->peer_cert = mbedtls_calloc( 1, sizeof( *session->peer_cert ) );
- if( session->peer_cert == NULL )
- return( -1 );
+ session->peer_cert = mbedtls_calloc(1, sizeof(*session->peer_cert));
+ if (session->peer_cert == NULL) {
+ return -1;
+ }
*session->peer_cert = tmp_crt;
- memset( &tmp_crt, 0, sizeof( tmp_crt ) );
+ memset(&tmp_crt, 0, sizeof(tmp_crt));
#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
/* Calculate digest of temporary CRT. */
session->peer_cert_digest =
- mbedtls_calloc( 1, MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN );
- if( session->peer_cert_digest == NULL )
- return( -1 );
+ mbedtls_calloc(1, MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN);
+ if (session->peer_cert_digest == NULL) {
+ return -1;
+ }
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_algorithm_t psa_alg = mbedtls_hash_info_psa_from_md(
- MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE );
+ MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE);
size_t hash_size = 0;
- psa_status_t status = psa_hash_compute( psa_alg, tmp_crt.raw.p,
- tmp_crt.raw.len,
- session->peer_cert_digest,
- MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN,
- &hash_size);
- ret = psa_ssl_status_to_mbedtls( status );
+ psa_status_t status = psa_hash_compute(psa_alg, tmp_crt.raw.p,
+ tmp_crt.raw.len,
+ session->peer_cert_digest,
+ MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN,
+ &hash_size);
+ ret = psa_ssl_status_to_mbedtls(status);
#else
- ret = mbedtls_md( mbedtls_md_info_from_type(
- MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE ),
- tmp_crt.raw.p, tmp_crt.raw.len,
- session->peer_cert_digest );
+ ret = mbedtls_md(mbedtls_md_info_from_type(
+ MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE),
+ tmp_crt.raw.p, tmp_crt.raw.len,
+ session->peer_cert_digest);
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- if( ret != 0 )
- return( ret );
+ if (ret != 0) {
+ return ret;
+ }
session->peer_cert_digest_type =
MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE;
session->peer_cert_digest_len =
MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN;
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
- mbedtls_x509_crt_free( &tmp_crt );
+ mbedtls_x509_crt_free(&tmp_crt);
}
#else /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED && MBEDTLS_FS_IO */
(void) crt_file;
@@ -1807,12 +1753,12 @@
session->verify_result = 0xdeadbeef;
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
- if( ticket_len != 0 )
- {
- session->ticket = mbedtls_calloc( 1, ticket_len );
- if( session->ticket == NULL )
- return( -1 );
- memset( session->ticket, 33, ticket_len );
+ if (ticket_len != 0) {
+ session->ticket = mbedtls_calloc(1, ticket_len);
+ if (session->ticket == NULL) {
+ return -1;
+ }
+ memset(session->ticket, 33, ticket_len);
}
session->ticket_len = ticket_len;
session->ticket_lifetime = 86401;
@@ -1827,52 +1773,50 @@
session->encrypt_then_mac = 1;
#endif
- return( 0 );
+ return 0;
}
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
-static int ssl_tls13_populate_session( mbedtls_ssl_session *session,
- int ticket_len,
- int endpoint_type )
+static int ssl_tls13_populate_session(mbedtls_ssl_session *session,
+ int ticket_len,
+ int endpoint_type)
{
((void) ticket_len);
session->tls_version = MBEDTLS_SSL_VERSION_TLS1_3;
session->endpoint = endpoint_type == MBEDTLS_SSL_IS_CLIENT ?
- MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER;
+ MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER;
session->ciphersuite = 0xabcd;
session->ticket_age_add = 0x87654321;
session->ticket_flags = 0x7;
session->resumption_key_len = 32;
- memset( session->resumption_key, 0x99, sizeof( session->resumption_key ) );
+ memset(session->resumption_key, 0x99, sizeof(session->resumption_key));
#if defined(MBEDTLS_HAVE_TIME)
- if( session->endpoint == MBEDTLS_SSL_IS_SERVER )
- {
- session->start = mbedtls_time( NULL ) - 42;
+ if (session->endpoint == MBEDTLS_SSL_IS_SERVER) {
+ session->start = mbedtls_time(NULL) - 42;
}
#endif
#if defined(MBEDTLS_SSL_CLI_C)
- if( session->endpoint == MBEDTLS_SSL_IS_CLIENT )
- {
+ if (session->endpoint == MBEDTLS_SSL_IS_CLIENT) {
#if defined(MBEDTLS_HAVE_TIME)
- session->ticket_received = mbedtls_time( NULL ) - 40;
+ session->ticket_received = mbedtls_time(NULL) - 40;
#endif
session->ticket_lifetime = 0xfedcba98;
session->ticket_len = ticket_len;
- if( ticket_len != 0 )
- {
- session->ticket = mbedtls_calloc( 1, ticket_len );
- if( session->ticket == NULL )
- return( -1 );
- memset( session->ticket, 33, ticket_len );
+ if (ticket_len != 0) {
+ session->ticket = mbedtls_calloc(1, ticket_len);
+ if (session->ticket == NULL) {
+ return -1;
+ }
+ memset(session->ticket, 33, ticket_len);
}
}
#endif /* MBEDTLS_SSL_CLI_C */
- return( 0 );
+ return 0;
}
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
@@ -1896,22 +1840,21 @@
*
* \retval 0 on success, otherwise error code.
*/
-int mbedtls_exchange_data( mbedtls_ssl_context *ssl_1,
- int msg_len_1, const int expected_fragments_1,
- mbedtls_ssl_context *ssl_2,
- int msg_len_2, const int expected_fragments_2 )
+int mbedtls_exchange_data(mbedtls_ssl_context *ssl_1,
+ int msg_len_1, const int expected_fragments_1,
+ mbedtls_ssl_context *ssl_2,
+ int msg_len_2, const int expected_fragments_2)
{
- unsigned char *msg_buf_1 = malloc( msg_len_1 );
- unsigned char *msg_buf_2 = malloc( msg_len_2 );
- unsigned char *in_buf_1 = malloc( msg_len_2 );
- unsigned char *in_buf_2 = malloc( msg_len_1 );
+ unsigned char *msg_buf_1 = malloc(msg_len_1);
+ unsigned char *msg_buf_2 = malloc(msg_len_2);
+ unsigned char *in_buf_1 = malloc(msg_len_2);
+ unsigned char *in_buf_2 = malloc(msg_len_1);
int msg_type, ret = -1;
/* Perform this test with two message types. At first use a message
* consisting of only 0x00 for the client and only 0xFF for the server.
* At the second time use message with generated data */
- for( msg_type = 0; msg_type < 2; msg_type++ )
- {
+ for (msg_type = 0; msg_type < 2; msg_type++) {
int written_1 = 0;
int written_2 = 0;
int read_1 = 0;
@@ -1919,99 +1862,83 @@
int fragments_1 = 0;
int fragments_2 = 0;
- if( msg_type == 0 )
- {
- memset( msg_buf_1, 0x00, msg_len_1 );
- memset( msg_buf_2, 0xff, msg_len_2 );
- }
- else
- {
+ if (msg_type == 0) {
+ memset(msg_buf_1, 0x00, msg_len_1);
+ memset(msg_buf_2, 0xff, msg_len_2);
+ } else {
int i, j = 0;
- for( i = 0; i < msg_len_1; i++ )
- {
+ for (i = 0; i < msg_len_1; i++) {
msg_buf_1[i] = j++ & 0xFF;
}
- for( i = 0; i < msg_len_2; i++ )
- {
- msg_buf_2[i] = ( j -= 5 ) & 0xFF;
+ for (i = 0; i < msg_len_2; i++) {
+ msg_buf_2[i] = (j -= 5) & 0xFF;
}
}
- while( read_1 < msg_len_2 || read_2 < msg_len_1 )
- {
+ while (read_1 < msg_len_2 || read_2 < msg_len_1) {
/* ssl_1 sending */
- if( msg_len_1 > written_1 )
- {
- ret = mbedtls_ssl_write_fragment( ssl_1, msg_buf_1,
- msg_len_1, &written_1,
- expected_fragments_1 );
- if( expected_fragments_1 == 0 )
- {
+ if (msg_len_1 > written_1) {
+ ret = mbedtls_ssl_write_fragment(ssl_1, msg_buf_1,
+ msg_len_1, &written_1,
+ expected_fragments_1);
+ if (expected_fragments_1 == 0) {
/* This error is expected when the message is too large and
* cannot be fragmented */
- TEST_ASSERT( ret == MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ TEST_ASSERT(ret == MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
msg_len_1 = 0;
- }
- else
- {
- TEST_ASSERT( ret == 0 );
+ } else {
+ TEST_ASSERT(ret == 0);
}
}
/* ssl_2 sending */
- if( msg_len_2 > written_2 )
- {
- ret = mbedtls_ssl_write_fragment( ssl_2, msg_buf_2,
- msg_len_2, &written_2,
- expected_fragments_2 );
- if( expected_fragments_2 == 0 )
- {
+ if (msg_len_2 > written_2) {
+ ret = mbedtls_ssl_write_fragment(ssl_2, msg_buf_2,
+ msg_len_2, &written_2,
+ expected_fragments_2);
+ if (expected_fragments_2 == 0) {
/* This error is expected when the message is too large and
* cannot be fragmented */
- TEST_ASSERT( ret == MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ TEST_ASSERT(ret == MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
msg_len_2 = 0;
- }
- else
- {
- TEST_ASSERT( ret == 0 );
+ } else {
+ TEST_ASSERT(ret == 0);
}
}
/* ssl_1 reading */
- if( read_1 < msg_len_2 )
- {
- ret = mbedtls_ssl_read_fragment( ssl_1, in_buf_1,
- msg_len_2, &read_1,
- &fragments_2,
- expected_fragments_2 );
- TEST_ASSERT( ret == 0 );
+ if (read_1 < msg_len_2) {
+ ret = mbedtls_ssl_read_fragment(ssl_1, in_buf_1,
+ msg_len_2, &read_1,
+ &fragments_2,
+ expected_fragments_2);
+ TEST_ASSERT(ret == 0);
}
/* ssl_2 reading */
- if( read_2 < msg_len_1 )
- {
- ret = mbedtls_ssl_read_fragment( ssl_2, in_buf_2,
- msg_len_1, &read_2,
- &fragments_1,
- expected_fragments_1 );
- TEST_ASSERT( ret == 0 );
+ if (read_2 < msg_len_1) {
+ ret = mbedtls_ssl_read_fragment(ssl_2, in_buf_2,
+ msg_len_1, &read_2,
+ &fragments_1,
+ expected_fragments_1);
+ TEST_ASSERT(ret == 0);
}
}
ret = -1;
- TEST_ASSERT( 0 == memcmp( msg_buf_1, in_buf_2, msg_len_1 ) );
- TEST_ASSERT( 0 == memcmp( msg_buf_2, in_buf_1, msg_len_2 ) );
- TEST_ASSERT( fragments_1 == expected_fragments_1 );
- TEST_ASSERT( fragments_2 == expected_fragments_2 );
+ TEST_ASSERT(0 == memcmp(msg_buf_1, in_buf_2, msg_len_1));
+ TEST_ASSERT(0 == memcmp(msg_buf_2, in_buf_1, msg_len_2));
+ TEST_ASSERT(fragments_1 == expected_fragments_1);
+ TEST_ASSERT(fragments_2 == expected_fragments_2);
}
ret = 0;
exit:
- free( msg_buf_1 );
- free( in_buf_1 );
- free( msg_buf_2 );
- free( in_buf_2 );
+ free(msg_buf_1);
+ free(in_buf_1);
+ free(msg_buf_2);
+ free(in_buf_2);
return ret;
}
@@ -2022,55 +1949,53 @@
*
* \retval 0 on success, otherwise error code.
*/
-int exchange_data( mbedtls_ssl_context *ssl_1,
- mbedtls_ssl_context *ssl_2 )
+int exchange_data(mbedtls_ssl_context *ssl_1,
+ mbedtls_ssl_context *ssl_2)
{
- return mbedtls_exchange_data( ssl_1, 256, 1,
- ssl_2, 256, 1 );
+ return mbedtls_exchange_data(ssl_1, 256, 1,
+ ssl_2, 256, 1);
}
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
-static int check_ssl_version( mbedtls_ssl_protocol_version expected_negotiated_version,
- const mbedtls_ssl_context *ssl )
+static int check_ssl_version(mbedtls_ssl_protocol_version expected_negotiated_version,
+ const mbedtls_ssl_context *ssl)
{
- const char *version_string = mbedtls_ssl_get_version( ssl );
+ const char *version_string = mbedtls_ssl_get_version(ssl);
mbedtls_ssl_protocol_version version_number =
- mbedtls_ssl_get_version_number( ssl );
+ mbedtls_ssl_get_version_number(ssl);
- TEST_EQUAL( ssl->tls_version, expected_negotiated_version );
+ TEST_EQUAL(ssl->tls_version, expected_negotiated_version);
- if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
- {
- TEST_EQUAL( version_string[0], 'D' );
+ if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
+ TEST_EQUAL(version_string[0], 'D');
++version_string;
}
- switch( expected_negotiated_version )
- {
+ switch (expected_negotiated_version) {
case MBEDTLS_SSL_VERSION_TLS1_2:
- TEST_EQUAL( version_number, MBEDTLS_SSL_VERSION_TLS1_2 );
- TEST_ASSERT( strcmp( version_string, "TLSv1.2" ) == 0 );
+ TEST_EQUAL(version_number, MBEDTLS_SSL_VERSION_TLS1_2);
+ TEST_ASSERT(strcmp(version_string, "TLSv1.2") == 0);
break;
case MBEDTLS_SSL_VERSION_TLS1_3:
- TEST_EQUAL( version_number, MBEDTLS_SSL_VERSION_TLS1_3 );
- TEST_ASSERT( strcmp( version_string, "TLSv1.3" ) == 0 );
+ TEST_EQUAL(version_number, MBEDTLS_SSL_VERSION_TLS1_3);
+ TEST_ASSERT(strcmp(version_string, "TLSv1.3") == 0);
break;
default:
- TEST_ASSERT( ! "Version check not implemented for this protocol version" );
+ TEST_ASSERT(!"Version check not implemented for this protocol version");
}
- return( 1 );
+ return 1;
exit:
- return( 0 );
+ return 0;
}
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
-void perform_handshake( handshake_test_options *options )
+void perform_handshake(handshake_test_options *options)
{
/* forced_ciphersuite needs to last until the end of the handshake */
int forced_ciphersuite[2];
@@ -2091,381 +2016,355 @@
#endif
int expected_handshake_result = options->expected_handshake_result;
- USE_PSA_INIT( );
- mbedtls_platform_zeroize( &client, sizeof(client) );
- mbedtls_platform_zeroize( &server, sizeof(server) );
+ USE_PSA_INIT();
+ mbedtls_platform_zeroize(&client, sizeof(client));
+ mbedtls_platform_zeroize(&server, sizeof(server));
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
/* Client side */
- if( options->dtls != 0 )
- {
- TEST_ASSERT( mbedtls_endpoint_init( &client, MBEDTLS_SSL_IS_CLIENT,
- options, &client_context,
- &client_queue,
- &server_queue, NULL ) == 0 );
+ if (options->dtls != 0) {
+ TEST_ASSERT(mbedtls_endpoint_init(&client, MBEDTLS_SSL_IS_CLIENT,
+ options, &client_context,
+ &client_queue,
+ &server_queue, NULL) == 0);
#if defined(MBEDTLS_TIMING_C)
- mbedtls_ssl_set_timer_cb( &client.ssl, &timer_client,
- mbedtls_timing_set_delay,
- mbedtls_timing_get_delay );
+ mbedtls_ssl_set_timer_cb(&client.ssl, &timer_client,
+ mbedtls_timing_set_delay,
+ mbedtls_timing_get_delay);
#endif
- }
- else
- {
- TEST_ASSERT( mbedtls_endpoint_init( &client, MBEDTLS_SSL_IS_CLIENT,
- options, NULL, NULL,
- NULL, NULL ) == 0 );
+ } else {
+ TEST_ASSERT(mbedtls_endpoint_init(&client, MBEDTLS_SSL_IS_CLIENT,
+ options, NULL, NULL,
+ NULL, NULL) == 0);
}
- if( options->client_min_version != MBEDTLS_SSL_VERSION_UNKNOWN )
- {
- mbedtls_ssl_conf_min_tls_version( &client.conf,
- options->client_min_version );
+ if (options->client_min_version != MBEDTLS_SSL_VERSION_UNKNOWN) {
+ mbedtls_ssl_conf_min_tls_version(&client.conf,
+ options->client_min_version);
}
- if( options->client_max_version != MBEDTLS_SSL_VERSION_UNKNOWN )
- {
- mbedtls_ssl_conf_max_tls_version( &client.conf,
- options->client_max_version );
+ if (options->client_max_version != MBEDTLS_SSL_VERSION_UNKNOWN) {
+ mbedtls_ssl_conf_max_tls_version(&client.conf,
+ options->client_max_version);
}
- if( strlen( options->cipher ) > 0 )
- {
- set_ciphersuite( &client.conf, options->cipher, forced_ciphersuite );
+ if (strlen(options->cipher) > 0) {
+ set_ciphersuite(&client.conf, options->cipher, forced_ciphersuite);
}
-#if defined (MBEDTLS_DEBUG_C)
- if( options->cli_log_fun )
- {
- mbedtls_debug_set_threshold( 4 );
- mbedtls_ssl_conf_dbg( &client.conf, options->cli_log_fun,
- options->cli_log_obj );
+#if defined(MBEDTLS_DEBUG_C)
+ if (options->cli_log_fun) {
+ mbedtls_debug_set_threshold(4);
+ mbedtls_ssl_conf_dbg(&client.conf, options->cli_log_fun,
+ options->cli_log_obj);
}
#endif
/* Server side */
- if( options->dtls != 0 )
- {
- TEST_ASSERT( mbedtls_endpoint_init( &server, MBEDTLS_SSL_IS_SERVER,
- options, &server_context,
- &server_queue,
- &client_queue, NULL ) == 0 );
+ if (options->dtls != 0) {
+ TEST_ASSERT(mbedtls_endpoint_init(&server, MBEDTLS_SSL_IS_SERVER,
+ options, &server_context,
+ &server_queue,
+ &client_queue, NULL) == 0);
#if defined(MBEDTLS_TIMING_C)
- mbedtls_ssl_set_timer_cb( &server.ssl, &timer_server,
- mbedtls_timing_set_delay,
- mbedtls_timing_get_delay );
+ mbedtls_ssl_set_timer_cb(&server.ssl, &timer_server,
+ mbedtls_timing_set_delay,
+ mbedtls_timing_get_delay);
#endif
- }
- else
- {
- TEST_ASSERT( mbedtls_endpoint_init( &server, MBEDTLS_SSL_IS_SERVER,
- options, NULL, NULL, NULL,
- NULL ) == 0 );
+ } else {
+ TEST_ASSERT(mbedtls_endpoint_init(&server, MBEDTLS_SSL_IS_SERVER,
+ options, NULL, NULL, NULL,
+ NULL) == 0);
}
- mbedtls_ssl_conf_authmode( &server.conf, options->srv_auth_mode );
+ mbedtls_ssl_conf_authmode(&server.conf, options->srv_auth_mode);
- if( options->server_min_version != MBEDTLS_SSL_VERSION_UNKNOWN )
- {
- mbedtls_ssl_conf_min_tls_version( &server.conf,
- options->server_min_version );
+ if (options->server_min_version != MBEDTLS_SSL_VERSION_UNKNOWN) {
+ mbedtls_ssl_conf_min_tls_version(&server.conf,
+ options->server_min_version);
}
- if( options->server_max_version != MBEDTLS_SSL_VERSION_UNKNOWN )
- {
- mbedtls_ssl_conf_max_tls_version( &server.conf,
- options->server_max_version );
+ if (options->server_max_version != MBEDTLS_SSL_VERSION_UNKNOWN) {
+ mbedtls_ssl_conf_max_tls_version(&server.conf,
+ options->server_max_version);
}
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- TEST_ASSERT( mbedtls_ssl_conf_max_frag_len( &(server.conf),
- (unsigned char) options->mfl ) == 0 );
- TEST_ASSERT( mbedtls_ssl_conf_max_frag_len( &(client.conf),
- (unsigned char) options->mfl ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_conf_max_frag_len(&(server.conf),
+ (unsigned char) options->mfl) == 0);
+ TEST_ASSERT(mbedtls_ssl_conf_max_frag_len(&(client.conf),
+ (unsigned char) options->mfl) == 0);
#else
- TEST_ASSERT( MBEDTLS_SSL_MAX_FRAG_LEN_NONE == options->mfl );
+ TEST_ASSERT(MBEDTLS_SSL_MAX_FRAG_LEN_NONE == options->mfl);
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
- if( options->psk_str != NULL && options->psk_str->len > 0 )
- {
- TEST_ASSERT( mbedtls_ssl_conf_psk( &client.conf, options->psk_str->x,
- options->psk_str->len,
- (const unsigned char *) psk_identity,
- strlen( psk_identity ) ) == 0 );
+ if (options->psk_str != NULL && options->psk_str->len > 0) {
+ TEST_ASSERT(mbedtls_ssl_conf_psk(&client.conf, options->psk_str->x,
+ options->psk_str->len,
+ (const unsigned char *) psk_identity,
+ strlen(psk_identity)) == 0);
- TEST_ASSERT( mbedtls_ssl_conf_psk( &server.conf, options->psk_str->x,
- options->psk_str->len,
- (const unsigned char *) psk_identity,
- strlen( psk_identity ) ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_conf_psk(&server.conf, options->psk_str->x,
+ options->psk_str->len,
+ (const unsigned char *) psk_identity,
+ strlen(psk_identity)) == 0);
#if defined(MBEDTLS_SSL_SRV_C)
- mbedtls_ssl_conf_psk_cb( &server.conf, psk_dummy_callback, NULL );
+ mbedtls_ssl_conf_psk_cb(&server.conf, psk_dummy_callback, NULL);
#endif
}
#endif
#if defined(MBEDTLS_SSL_RENEGOTIATION)
- if( options->renegotiate )
- {
- mbedtls_ssl_conf_renegotiation( &(server.conf),
- MBEDTLS_SSL_RENEGOTIATION_ENABLED );
- mbedtls_ssl_conf_renegotiation( &(client.conf),
- MBEDTLS_SSL_RENEGOTIATION_ENABLED );
+ if (options->renegotiate) {
+ mbedtls_ssl_conf_renegotiation(&(server.conf),
+ MBEDTLS_SSL_RENEGOTIATION_ENABLED);
+ mbedtls_ssl_conf_renegotiation(&(client.conf),
+ MBEDTLS_SSL_RENEGOTIATION_ENABLED);
- mbedtls_ssl_conf_legacy_renegotiation( &(server.conf),
- options->legacy_renegotiation );
- mbedtls_ssl_conf_legacy_renegotiation( &(client.conf),
- options->legacy_renegotiation );
+ mbedtls_ssl_conf_legacy_renegotiation(&(server.conf),
+ options->legacy_renegotiation);
+ mbedtls_ssl_conf_legacy_renegotiation(&(client.conf),
+ options->legacy_renegotiation);
}
#endif /* MBEDTLS_SSL_RENEGOTIATION */
-#if defined (MBEDTLS_DEBUG_C)
- if( options->srv_log_fun )
- {
- mbedtls_debug_set_threshold( 4 );
- mbedtls_ssl_conf_dbg( &server.conf, options->srv_log_fun,
- options->srv_log_obj );
+#if defined(MBEDTLS_DEBUG_C)
+ if (options->srv_log_fun) {
+ mbedtls_debug_set_threshold(4);
+ mbedtls_ssl_conf_dbg(&server.conf, options->srv_log_fun,
+ options->srv_log_obj);
}
#endif
- TEST_ASSERT( mbedtls_mock_socket_connect( &(client.socket),
- &(server.socket),
- BUFFSIZE ) == 0 );
+ TEST_ASSERT(mbedtls_mock_socket_connect(&(client.socket),
+ &(server.socket),
+ BUFFSIZE) == 0);
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
- if( options->resize_buffers != 0 )
- {
+ if (options->resize_buffers != 0) {
/* Ensure that the buffer sizes are appropriate before resizes */
- TEST_ASSERT( client.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN );
- TEST_ASSERT( client.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN );
- TEST_ASSERT( server.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN );
- TEST_ASSERT( server.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN );
+ TEST_ASSERT(client.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN);
+ TEST_ASSERT(client.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN);
+ TEST_ASSERT(server.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN);
+ TEST_ASSERT(server.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN);
}
#endif
- if( options->expected_negotiated_version == MBEDTLS_SSL_VERSION_UNKNOWN )
- {
+ if (options->expected_negotiated_version == MBEDTLS_SSL_VERSION_UNKNOWN) {
expected_handshake_result = MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION;
}
- TEST_ASSERT( mbedtls_move_handshake_to_state( &(client.ssl),
- &(server.ssl),
- MBEDTLS_SSL_HANDSHAKE_OVER )
- == expected_handshake_result );
+ TEST_ASSERT(mbedtls_move_handshake_to_state(&(client.ssl),
+ &(server.ssl),
+ MBEDTLS_SSL_HANDSHAKE_OVER)
+ == expected_handshake_result);
- if( expected_handshake_result != 0 )
- {
+ if (expected_handshake_result != 0) {
/* Connection will have failed by this point, skip to cleanup */
goto exit;
}
- TEST_ASSERT( mbedtls_ssl_is_handshake_over( &client.ssl ) == 1 );
+ TEST_ASSERT(mbedtls_ssl_is_handshake_over(&client.ssl) == 1);
/* Make sure server state is moved to HANDSHAKE_OVER also. */
- TEST_EQUAL( mbedtls_move_handshake_to_state( &(server.ssl),
- &(client.ssl),
- MBEDTLS_SSL_HANDSHAKE_OVER ), 0 );
+ TEST_EQUAL(mbedtls_move_handshake_to_state(&(server.ssl),
+ &(client.ssl),
+ MBEDTLS_SSL_HANDSHAKE_OVER), 0);
- TEST_ASSERT( mbedtls_ssl_is_handshake_over( &server.ssl ) == 1 );
+ TEST_ASSERT(mbedtls_ssl_is_handshake_over(&server.ssl) == 1);
/* Check that both sides have negotiated the expected version. */
- mbedtls_test_set_step( 0 );
- if( ! check_ssl_version( options->expected_negotiated_version,
- &client.ssl ) )
+ mbedtls_test_set_step(0);
+ if (!check_ssl_version(options->expected_negotiated_version,
+ &client.ssl)) {
goto exit;
+ }
- mbedtls_test_set_step( 1 );
- if( ! check_ssl_version( options->expected_negotiated_version,
- &server.ssl ) )
+ mbedtls_test_set_step(1);
+ if (!check_ssl_version(options->expected_negotiated_version,
+ &server.ssl)) {
goto exit;
+ }
- if( options->expected_ciphersuite != 0 )
- {
- TEST_EQUAL( server.ssl.session->ciphersuite,
- options->expected_ciphersuite );
+ if (options->expected_ciphersuite != 0) {
+ TEST_EQUAL(server.ssl.session->ciphersuite,
+ options->expected_ciphersuite);
}
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
- if( options->resize_buffers != 0 )
- {
+ if (options->resize_buffers != 0) {
/* A server, when using DTLS, might delay a buffer resize to happen
* after it receives a message, so we force it. */
- TEST_ASSERT( exchange_data( &(client.ssl), &(server.ssl) ) == 0 );
+ TEST_ASSERT(exchange_data(&(client.ssl), &(server.ssl)) == 0);
- TEST_ASSERT( client.ssl.out_buf_len ==
- mbedtls_ssl_get_output_buflen( &client.ssl ) );
- TEST_ASSERT( client.ssl.in_buf_len ==
- mbedtls_ssl_get_input_buflen( &client.ssl ) );
- TEST_ASSERT( server.ssl.out_buf_len ==
- mbedtls_ssl_get_output_buflen( &server.ssl ) );
- TEST_ASSERT( server.ssl.in_buf_len ==
- mbedtls_ssl_get_input_buflen( &server.ssl ) );
+ TEST_ASSERT(client.ssl.out_buf_len ==
+ mbedtls_ssl_get_output_buflen(&client.ssl));
+ TEST_ASSERT(client.ssl.in_buf_len ==
+ mbedtls_ssl_get_input_buflen(&client.ssl));
+ TEST_ASSERT(server.ssl.out_buf_len ==
+ mbedtls_ssl_get_output_buflen(&server.ssl));
+ TEST_ASSERT(server.ssl.in_buf_len ==
+ mbedtls_ssl_get_input_buflen(&server.ssl));
}
#endif
- if( options->cli_msg_len != 0 || options->srv_msg_len != 0 )
- {
+ if (options->cli_msg_len != 0 || options->srv_msg_len != 0) {
/* Start data exchanging test */
- TEST_ASSERT( mbedtls_exchange_data( &(client.ssl), options->cli_msg_len,
- options->expected_cli_fragments,
- &(server.ssl), options->srv_msg_len,
- options->expected_srv_fragments )
- == 0 );
+ TEST_ASSERT(mbedtls_exchange_data(&(client.ssl), options->cli_msg_len,
+ options->expected_cli_fragments,
+ &(server.ssl), options->srv_msg_len,
+ options->expected_srv_fragments)
+ == 0);
}
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
- if( options->serialize == 1 )
- {
- TEST_ASSERT( options->dtls == 1 );
+ if (options->serialize == 1) {
+ TEST_ASSERT(options->dtls == 1);
- TEST_ASSERT( mbedtls_ssl_context_save( &(server.ssl), NULL,
- 0, &context_buf_len )
- == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
+ TEST_ASSERT(mbedtls_ssl_context_save(&(server.ssl), NULL,
+ 0, &context_buf_len)
+ == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
- context_buf = mbedtls_calloc( 1, context_buf_len );
- TEST_ASSERT( context_buf != NULL );
+ context_buf = mbedtls_calloc(1, context_buf_len);
+ TEST_ASSERT(context_buf != NULL);
- TEST_ASSERT( mbedtls_ssl_context_save( &(server.ssl), context_buf,
- context_buf_len,
- &context_buf_len ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_context_save(&(server.ssl), context_buf,
+ context_buf_len,
+ &context_buf_len) == 0);
- mbedtls_ssl_free( &(server.ssl) );
- mbedtls_ssl_init( &(server.ssl) );
+ mbedtls_ssl_free(&(server.ssl));
+ mbedtls_ssl_init(&(server.ssl));
- TEST_ASSERT( mbedtls_ssl_setup( &(server.ssl), &(server.conf) ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_setup(&(server.ssl), &(server.conf)) == 0);
- mbedtls_ssl_set_bio( &( server.ssl ), &server_context,
- mbedtls_mock_tcp_send_msg,
- mbedtls_mock_tcp_recv_msg,
- NULL );
+ mbedtls_ssl_set_bio(&(server.ssl), &server_context,
+ mbedtls_mock_tcp_send_msg,
+ mbedtls_mock_tcp_recv_msg,
+ NULL);
- mbedtls_ssl_set_user_data_p( &server.ssl, &server );
+ mbedtls_ssl_set_user_data_p(&server.ssl, &server);
#if defined(MBEDTLS_TIMING_C)
- mbedtls_ssl_set_timer_cb( &server.ssl, &timer_server,
- mbedtls_timing_set_delay,
- mbedtls_timing_get_delay );
+ mbedtls_ssl_set_timer_cb(&server.ssl, &timer_server,
+ mbedtls_timing_set_delay,
+ mbedtls_timing_get_delay);
#endif
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
- if( options->resize_buffers != 0 )
- {
+ if (options->resize_buffers != 0) {
/* Ensure that the buffer sizes are appropriate before resizes */
- TEST_ASSERT( server.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN );
- TEST_ASSERT( server.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN );
+ TEST_ASSERT(server.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN);
+ TEST_ASSERT(server.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN);
}
#endif
- TEST_ASSERT( mbedtls_ssl_context_load( &( server.ssl ), context_buf,
- context_buf_len ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_context_load(&(server.ssl), context_buf,
+ context_buf_len) == 0);
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
/* Validate buffer sizes after context deserialization */
- if( options->resize_buffers != 0 )
- {
- TEST_ASSERT( server.ssl.out_buf_len ==
- mbedtls_ssl_get_output_buflen( &server.ssl ) );
- TEST_ASSERT( server.ssl.in_buf_len ==
- mbedtls_ssl_get_input_buflen( &server.ssl ) );
+ if (options->resize_buffers != 0) {
+ TEST_ASSERT(server.ssl.out_buf_len ==
+ mbedtls_ssl_get_output_buflen(&server.ssl));
+ TEST_ASSERT(server.ssl.in_buf_len ==
+ mbedtls_ssl_get_input_buflen(&server.ssl));
}
#endif
/* Retest writing/reading */
- if( options->cli_msg_len != 0 || options->srv_msg_len != 0 )
- {
- TEST_ASSERT( mbedtls_exchange_data( &(client.ssl),
- options->cli_msg_len,
- options->expected_cli_fragments,
- &(server.ssl),
- options->srv_msg_len,
- options->expected_srv_fragments )
- == 0 );
+ if (options->cli_msg_len != 0 || options->srv_msg_len != 0) {
+ TEST_ASSERT(mbedtls_exchange_data(&(client.ssl),
+ options->cli_msg_len,
+ options->expected_cli_fragments,
+ &(server.ssl),
+ options->srv_msg_len,
+ options->expected_srv_fragments)
+ == 0);
}
}
#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
#if defined(MBEDTLS_SSL_RENEGOTIATION)
- if( options->renegotiate )
- {
+ if (options->renegotiate) {
/* Start test with renegotiation */
- TEST_ASSERT( server.ssl.renego_status ==
- MBEDTLS_SSL_INITIAL_HANDSHAKE );
- TEST_ASSERT( client.ssl.renego_status ==
- MBEDTLS_SSL_INITIAL_HANDSHAKE );
+ TEST_ASSERT(server.ssl.renego_status ==
+ MBEDTLS_SSL_INITIAL_HANDSHAKE);
+ TEST_ASSERT(client.ssl.renego_status ==
+ MBEDTLS_SSL_INITIAL_HANDSHAKE);
/* After calling this function for the server, it only sends a handshake
* request. All renegotiation should happen during data exchanging */
- TEST_ASSERT( mbedtls_ssl_renegotiate( &(server.ssl) ) == 0 );
- TEST_ASSERT( server.ssl.renego_status ==
- MBEDTLS_SSL_RENEGOTIATION_PENDING );
- TEST_ASSERT( client.ssl.renego_status ==
- MBEDTLS_SSL_INITIAL_HANDSHAKE );
+ TEST_ASSERT(mbedtls_ssl_renegotiate(&(server.ssl)) == 0);
+ TEST_ASSERT(server.ssl.renego_status ==
+ MBEDTLS_SSL_RENEGOTIATION_PENDING);
+ TEST_ASSERT(client.ssl.renego_status ==
+ MBEDTLS_SSL_INITIAL_HANDSHAKE);
- TEST_ASSERT( exchange_data( &(client.ssl), &(server.ssl) ) == 0 );
- TEST_ASSERT( server.ssl.renego_status ==
- MBEDTLS_SSL_RENEGOTIATION_DONE );
- TEST_ASSERT( client.ssl.renego_status ==
- MBEDTLS_SSL_RENEGOTIATION_DONE );
+ TEST_ASSERT(exchange_data(&(client.ssl), &(server.ssl)) == 0);
+ TEST_ASSERT(server.ssl.renego_status ==
+ MBEDTLS_SSL_RENEGOTIATION_DONE);
+ TEST_ASSERT(client.ssl.renego_status ==
+ MBEDTLS_SSL_RENEGOTIATION_DONE);
/* After calling mbedtls_ssl_renegotiate for the client all renegotiation
* should happen inside this function. However in this test, we cannot
* perform simultaneous communication between client and server so this
* function will return waiting error on the socket. All rest of
* renegotiation should happen during data exchanging */
- ret = mbedtls_ssl_renegotiate( &(client.ssl) );
+ ret = mbedtls_ssl_renegotiate(&(client.ssl));
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
- if( options->resize_buffers != 0 )
- {
+ if (options->resize_buffers != 0) {
/* Ensure that the buffer sizes are appropriate before resizes */
- TEST_ASSERT( client.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN );
- TEST_ASSERT( client.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN );
+ TEST_ASSERT(client.ssl.out_buf_len == MBEDTLS_SSL_OUT_BUFFER_LEN);
+ TEST_ASSERT(client.ssl.in_buf_len == MBEDTLS_SSL_IN_BUFFER_LEN);
}
#endif
- TEST_ASSERT( ret == 0 ||
- ret == MBEDTLS_ERR_SSL_WANT_READ ||
- ret == MBEDTLS_ERR_SSL_WANT_WRITE );
- TEST_ASSERT( server.ssl.renego_status ==
- MBEDTLS_SSL_RENEGOTIATION_DONE );
- TEST_ASSERT( client.ssl.renego_status ==
- MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS );
+ TEST_ASSERT(ret == 0 ||
+ ret == MBEDTLS_ERR_SSL_WANT_READ ||
+ ret == MBEDTLS_ERR_SSL_WANT_WRITE);
+ TEST_ASSERT(server.ssl.renego_status ==
+ MBEDTLS_SSL_RENEGOTIATION_DONE);
+ TEST_ASSERT(client.ssl.renego_status ==
+ MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS);
- TEST_ASSERT( exchange_data( &(client.ssl), &(server.ssl) ) == 0 );
- TEST_ASSERT( server.ssl.renego_status ==
- MBEDTLS_SSL_RENEGOTIATION_DONE );
- TEST_ASSERT( client.ssl.renego_status ==
- MBEDTLS_SSL_RENEGOTIATION_DONE );
+ TEST_ASSERT(exchange_data(&(client.ssl), &(server.ssl)) == 0);
+ TEST_ASSERT(server.ssl.renego_status ==
+ MBEDTLS_SSL_RENEGOTIATION_DONE);
+ TEST_ASSERT(client.ssl.renego_status ==
+ MBEDTLS_SSL_RENEGOTIATION_DONE);
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
/* Validate buffer sizes after renegotiation */
- if( options->resize_buffers != 0 )
- {
- TEST_ASSERT( client.ssl.out_buf_len ==
- mbedtls_ssl_get_output_buflen( &client.ssl ) );
- TEST_ASSERT( client.ssl.in_buf_len ==
- mbedtls_ssl_get_input_buflen( &client.ssl ) );
- TEST_ASSERT( server.ssl.out_buf_len ==
- mbedtls_ssl_get_output_buflen( &server.ssl ) );
- TEST_ASSERT( server.ssl.in_buf_len ==
- mbedtls_ssl_get_input_buflen( &server.ssl ) );
+ if (options->resize_buffers != 0) {
+ TEST_ASSERT(client.ssl.out_buf_len ==
+ mbedtls_ssl_get_output_buflen(&client.ssl));
+ TEST_ASSERT(client.ssl.in_buf_len ==
+ mbedtls_ssl_get_input_buflen(&client.ssl));
+ TEST_ASSERT(server.ssl.out_buf_len ==
+ mbedtls_ssl_get_output_buflen(&server.ssl));
+ TEST_ASSERT(server.ssl.in_buf_len ==
+ mbedtls_ssl_get_input_buflen(&server.ssl));
}
#endif /* MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH */
}
#endif /* MBEDTLS_SSL_RENEGOTIATION */
- TEST_ASSERT( mbedtls_ssl_conf_get_user_data_p( &client.conf ) == &client );
- TEST_ASSERT( mbedtls_ssl_get_user_data_p( &client.ssl ) == &client );
- TEST_ASSERT( mbedtls_ssl_conf_get_user_data_p( &server.conf ) == &server );
- TEST_ASSERT( mbedtls_ssl_get_user_data_p( &server.ssl ) == &server );
+ TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&client.conf) == &client);
+ TEST_ASSERT(mbedtls_ssl_get_user_data_p(&client.ssl) == &client);
+ TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&server.conf) == &server);
+ TEST_ASSERT(mbedtls_ssl_get_user_data_p(&server.ssl) == &server);
exit:
- mbedtls_endpoint_free( &client, options->dtls != 0 ? &client_context : NULL );
- mbedtls_endpoint_free( &server, options->dtls != 0 ? &server_context : NULL );
-#if defined (MBEDTLS_DEBUG_C)
- if( options->cli_log_fun || options->srv_log_fun )
- {
- mbedtls_debug_set_threshold( 0 );
+ mbedtls_endpoint_free(&client, options->dtls != 0 ? &client_context : NULL);
+ mbedtls_endpoint_free(&server, options->dtls != 0 ? &server_context : NULL);
+#if defined(MBEDTLS_DEBUG_C)
+ if (options->cli_log_fun || options->srv_log_fun) {
+ mbedtls_debug_set_threshold(0);
}
#endif
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
- if( context_buf != NULL )
- mbedtls_free( context_buf );
+ if (context_buf != NULL) {
+ mbedtls_free(context_buf);
+ }
#endif
- USE_PSA_DONE( );
+ USE_PSA_DONE();
}
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
@@ -2483,7 +2382,7 @@
*/
int tweak_tls13_certificate_msg_vector_len(
unsigned char *buf, unsigned char **end, int tweak,
- int *expected_result, mbedtls_ssl_chk_buf_ptr_args *args )
+ int *expected_result, mbedtls_ssl_chk_buf_ptr_args *args)
{
/*
* The definition of the tweaks assume that the certificate list contains only
@@ -2506,96 +2405,95 @@
unsigned char *p_certificate_list_len = buf + 1 + certificate_request_context_len;
unsigned char *certificate_list = p_certificate_list_len + 3;
- size_t certificate_list_len = MBEDTLS_GET_UINT24_BE( p_certificate_list_len, 0 );
+ size_t certificate_list_len = MBEDTLS_GET_UINT24_BE(p_certificate_list_len, 0);
unsigned char *p_cert_data_len = certificate_list;
unsigned char *cert_data = p_cert_data_len + 3;
- size_t cert_data_len = MBEDTLS_GET_UINT24_BE( p_cert_data_len, 0 );
+ size_t cert_data_len = MBEDTLS_GET_UINT24_BE(p_cert_data_len, 0);
unsigned char *p_extensions_len = cert_data + cert_data_len;
unsigned char *extensions = p_extensions_len + 2;
- size_t extensions_len = MBEDTLS_GET_UINT16_BE( p_extensions_len, 0 );
+ size_t extensions_len = MBEDTLS_GET_UINT16_BE(p_extensions_len, 0);
*expected_result = MBEDTLS_ERR_SSL_DECODE_ERROR;
- switch( tweak )
- {
+ switch (tweak) {
case 1:
- /* Failure when checking if the certificate request context length and
- * certificate list length can be read
- */
- *end = buf + 3;
- set_chk_buf_ptr_args( args, buf, *end, 4 );
- break;
+ /* Failure when checking if the certificate request context length and
+ * certificate list length can be read
+ */
+ *end = buf + 3;
+ set_chk_buf_ptr_args(args, buf, *end, 4);
+ break;
case 2:
- /* Invalid certificate request context length.
- */
- *p_certificate_request_context_len =
- certificate_request_context_len + 1;
- reset_chk_buf_ptr_args( args );
- break;
+ /* Invalid certificate request context length.
+ */
+ *p_certificate_request_context_len =
+ certificate_request_context_len + 1;
+ reset_chk_buf_ptr_args(args);
+ break;
case 3:
- /* Failure when checking if certificate_list data can be read. */
- MBEDTLS_PUT_UINT24_BE( certificate_list_len + 1,
- p_certificate_list_len, 0 );
- set_chk_buf_ptr_args( args, certificate_list, *end,
- certificate_list_len + 1 );
- break;
+ /* Failure when checking if certificate_list data can be read. */
+ MBEDTLS_PUT_UINT24_BE(certificate_list_len + 1,
+ p_certificate_list_len, 0);
+ set_chk_buf_ptr_args(args, certificate_list, *end,
+ certificate_list_len + 1);
+ break;
case 4:
- /* Failure when checking if the cert_data length can be read. */
- MBEDTLS_PUT_UINT24_BE( 2, p_certificate_list_len, 0 );
- set_chk_buf_ptr_args( args, p_cert_data_len, certificate_list + 2, 3 );
- break;
+ /* Failure when checking if the cert_data length can be read. */
+ MBEDTLS_PUT_UINT24_BE(2, p_certificate_list_len, 0);
+ set_chk_buf_ptr_args(args, p_cert_data_len, certificate_list + 2, 3);
+ break;
case 5:
- /* Failure when checking if cert_data data can be read. */
- MBEDTLS_PUT_UINT24_BE( certificate_list_len - 3 + 1,
- p_cert_data_len, 0 );
- set_chk_buf_ptr_args( args, cert_data,
- certificate_list + certificate_list_len,
- certificate_list_len - 3 + 1 );
- break;
+ /* Failure when checking if cert_data data can be read. */
+ MBEDTLS_PUT_UINT24_BE(certificate_list_len - 3 + 1,
+ p_cert_data_len, 0);
+ set_chk_buf_ptr_args(args, cert_data,
+ certificate_list + certificate_list_len,
+ certificate_list_len - 3 + 1);
+ break;
case 6:
- /* Failure when checking if the extensions length can be read. */
- MBEDTLS_PUT_UINT24_BE( certificate_list_len - extensions_len - 1,
- p_certificate_list_len, 0 );
- set_chk_buf_ptr_args( args, p_extensions_len,
- certificate_list + certificate_list_len - extensions_len - 1, 2 );
- break;
+ /* Failure when checking if the extensions length can be read. */
+ MBEDTLS_PUT_UINT24_BE(certificate_list_len - extensions_len - 1,
+ p_certificate_list_len, 0);
+ set_chk_buf_ptr_args(args, p_extensions_len,
+ certificate_list + certificate_list_len - extensions_len - 1, 2);
+ break;
case 7:
- /* Failure when checking if extensions data can be read. */
- MBEDTLS_PUT_UINT16_BE( extensions_len + 1, p_extensions_len, 0 );
+ /* Failure when checking if extensions data can be read. */
+ MBEDTLS_PUT_UINT16_BE(extensions_len + 1, p_extensions_len, 0);
- set_chk_buf_ptr_args( args, extensions,
- certificate_list + certificate_list_len, extensions_len + 1 );
- break;
+ set_chk_buf_ptr_args(args, extensions,
+ certificate_list + certificate_list_len, extensions_len + 1);
+ break;
default:
- return( -1 );
+ return -1;
}
- return( 0 );
+ return 0;
}
#endif /* MBEDTLS_TEST_HOOKS */
#define ECJPAKE_TEST_PWD "bla"
-#if defined( MBEDTLS_USE_PSA_CRYPTO )
-#define ECJPAKE_TEST_SET_PASSWORD( exp_ret_val ) \
- ret = ( use_opaque_arg ) ? \
- mbedtls_ssl_set_hs_ecjpake_password_opaque( &ssl, pwd_slot ) : \
- mbedtls_ssl_set_hs_ecjpake_password( &ssl, pwd_string, pwd_len ); \
- TEST_EQUAL( ret, exp_ret_val )
+#if defined(MBEDTLS_USE_PSA_CRYPTO)
+#define ECJPAKE_TEST_SET_PASSWORD(exp_ret_val) \
+ ret = (use_opaque_arg) ? \
+ mbedtls_ssl_set_hs_ecjpake_password_opaque(&ssl, pwd_slot) : \
+ mbedtls_ssl_set_hs_ecjpake_password(&ssl, pwd_string, pwd_len); \
+ TEST_EQUAL(ret, exp_ret_val)
#else
-#define ECJPAKE_TEST_SET_PASSWORD( exp_ret_val ) \
- ret = mbedtls_ssl_set_hs_ecjpake_password( &ssl, \
- pwd_string, pwd_len ); \
- TEST_EQUAL( ret, exp_ret_val )
+#define ECJPAKE_TEST_SET_PASSWORD(exp_ret_val) \
+ ret = mbedtls_ssl_set_hs_ecjpake_password(&ssl, \
+ pwd_string, pwd_len); \
+ TEST_EQUAL(ret, exp_ret_val)
#endif
/* END_HEADER */
@@ -2612,56 +2510,56 @@
unsigned char input[MSGLEN];
unsigned char output[MSGLEN];
- memset( input, 0, sizeof(input) );
+ memset(input, 0, sizeof(input));
/* Make sure calling put and get on NULL buffer results in error. */
- TEST_ASSERT( mbedtls_test_buffer_put( NULL, input, sizeof( input ) )
- == -1 );
- TEST_ASSERT( mbedtls_test_buffer_get( NULL, output, sizeof( output ) )
- == -1 );
- TEST_ASSERT( mbedtls_test_buffer_put( NULL, NULL, sizeof( input ) ) == -1 );
+ TEST_ASSERT(mbedtls_test_buffer_put(NULL, input, sizeof(input))
+ == -1);
+ TEST_ASSERT(mbedtls_test_buffer_get(NULL, output, sizeof(output))
+ == -1);
+ TEST_ASSERT(mbedtls_test_buffer_put(NULL, NULL, sizeof(input)) == -1);
- TEST_ASSERT( mbedtls_test_buffer_put( NULL, NULL, 0 ) == -1 );
- TEST_ASSERT( mbedtls_test_buffer_get( NULL, NULL, 0 ) == -1 );
+ TEST_ASSERT(mbedtls_test_buffer_put(NULL, NULL, 0) == -1);
+ TEST_ASSERT(mbedtls_test_buffer_get(NULL, NULL, 0) == -1);
/* Make sure calling put and get on a buffer that hasn't been set up results
* in error. */
- mbedtls_test_buffer_init( &buf );
+ mbedtls_test_buffer_init(&buf);
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, input, sizeof( input ) ) == -1 );
- TEST_ASSERT( mbedtls_test_buffer_get( &buf, output, sizeof( output ) )
- == -1 );
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, NULL, sizeof( input ) ) == -1 );
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, input, sizeof(input)) == -1);
+ TEST_ASSERT(mbedtls_test_buffer_get(&buf, output, sizeof(output))
+ == -1);
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, NULL, sizeof(input)) == -1);
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, NULL, 0 ) == -1 );
- TEST_ASSERT( mbedtls_test_buffer_get( &buf, NULL, 0 ) == -1 );
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, NULL, 0) == -1);
+ TEST_ASSERT(mbedtls_test_buffer_get(&buf, NULL, 0) == -1);
/* Make sure calling put and get on NULL input only results in
* error if the length is not zero, and that a NULL output is valid for data
* dropping.
*/
- TEST_ASSERT( mbedtls_test_buffer_setup( &buf, sizeof( input ) ) == 0 );
+ TEST_ASSERT(mbedtls_test_buffer_setup(&buf, sizeof(input)) == 0);
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, NULL, sizeof( input ) ) == -1 );
- TEST_ASSERT( mbedtls_test_buffer_get( &buf, NULL, sizeof( output ) )
- == 0 );
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, NULL, 0 ) == 0 );
- TEST_ASSERT( mbedtls_test_buffer_get( &buf, NULL, 0 ) == 0 );
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, NULL, sizeof(input)) == -1);
+ TEST_ASSERT(mbedtls_test_buffer_get(&buf, NULL, sizeof(output))
+ == 0);
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, NULL, 0) == 0);
+ TEST_ASSERT(mbedtls_test_buffer_get(&buf, NULL, 0) == 0);
/* Make sure calling put several times in the row is safe */
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, input, sizeof( input ) )
- == sizeof( input ) );
- TEST_ASSERT( mbedtls_test_buffer_get( &buf, output, 2 ) == 2 );
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, input, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, input, 2 ) == 1 );
- TEST_ASSERT( mbedtls_test_buffer_put( &buf, input, 2 ) == 0 );
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, input, sizeof(input))
+ == sizeof(input));
+ TEST_ASSERT(mbedtls_test_buffer_get(&buf, output, 2) == 2);
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, input, 1) == 1);
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, input, 2) == 1);
+ TEST_ASSERT(mbedtls_test_buffer_put(&buf, input, 2) == 0);
exit:
- mbedtls_test_buffer_free( &buf );
+ mbedtls_test_buffer_free(&buf);
}
/* END_CASE */
@@ -2679,9 +2577,9 @@
*/
/* BEGIN_CASE */
-void test_callback_buffer( int size, int put1, int put1_ret,
- int get1, int get1_ret, int put2, int put2_ret,
- int get2, int get2_ret )
+void test_callback_buffer(int size, int put1, int put1_ret,
+ int get1, int get1_ret, int put2, int put2_ret,
+ int get2, int get2_ret)
{
enum { ROUNDS = 2 };
size_t put[ROUNDS];
@@ -2689,96 +2587,91 @@
size_t get[ROUNDS];
int get_ret[ROUNDS];
mbedtls_test_buffer buf;
- unsigned char* input = NULL;
+ unsigned char *input = NULL;
size_t input_len;
- unsigned char* output = NULL;
+ unsigned char *output = NULL;
size_t output_len;
size_t i, j, written, read;
- mbedtls_test_buffer_init( &buf );
- TEST_ASSERT( mbedtls_test_buffer_setup( &buf, size ) == 0 );
+ mbedtls_test_buffer_init(&buf);
+ TEST_ASSERT(mbedtls_test_buffer_setup(&buf, size) == 0);
/* Check the sanity of input parameters and initialise local variables. That
* is, ensure that the amount of data is not negative and that we are not
* expecting more to put or get than we actually asked for. */
- TEST_ASSERT( put1 >= 0 );
+ TEST_ASSERT(put1 >= 0);
put[0] = put1;
put_ret[0] = put1_ret;
- TEST_ASSERT( put1_ret <= put1 );
- TEST_ASSERT( put2 >= 0 );
+ TEST_ASSERT(put1_ret <= put1);
+ TEST_ASSERT(put2 >= 0);
put[1] = put2;
put_ret[1] = put2_ret;
- TEST_ASSERT( put2_ret <= put2 );
+ TEST_ASSERT(put2_ret <= put2);
- TEST_ASSERT( get1 >= 0 );
+ TEST_ASSERT(get1 >= 0);
get[0] = get1;
get_ret[0] = get1_ret;
- TEST_ASSERT( get1_ret <= get1 );
- TEST_ASSERT( get2 >= 0 );
+ TEST_ASSERT(get1_ret <= get1);
+ TEST_ASSERT(get2 >= 0);
get[1] = get2;
get_ret[1] = get2_ret;
- TEST_ASSERT( get2_ret <= get2 );
+ TEST_ASSERT(get2_ret <= get2);
input_len = 0;
/* Calculate actual input and output lengths */
- for( j = 0; j < ROUNDS; j++ )
- {
- if( put_ret[j] > 0 )
- {
+ for (j = 0; j < ROUNDS; j++) {
+ if (put_ret[j] > 0) {
input_len += put_ret[j];
}
}
/* In order to always have a valid pointer we always allocate at least 1
* byte. */
- if( input_len == 0 )
+ if (input_len == 0) {
input_len = 1;
- ASSERT_ALLOC( input, input_len );
+ }
+ ASSERT_ALLOC(input, input_len);
output_len = 0;
- for( j = 0; j < ROUNDS; j++ )
- {
- if( get_ret[j] > 0 )
- {
+ for (j = 0; j < ROUNDS; j++) {
+ if (get_ret[j] > 0) {
output_len += get_ret[j];
}
}
- TEST_ASSERT( output_len <= input_len );
+ TEST_ASSERT(output_len <= input_len);
/* In order to always have a valid pointer we always allocate at least 1
* byte. */
- if( output_len == 0 )
+ if (output_len == 0) {
output_len = 1;
- ASSERT_ALLOC( output, output_len );
+ }
+ ASSERT_ALLOC(output, output_len);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < input_len; i++ )
- {
+ for (i = 0; i < input_len; i++) {
input[i] = i & 0xFF;
}
written = read = 0;
- for( j = 0; j < ROUNDS; j++ )
- {
- TEST_ASSERT( put_ret[j] == mbedtls_test_buffer_put( &buf,
- input + written, put[j] ) );
+ for (j = 0; j < ROUNDS; j++) {
+ TEST_ASSERT(put_ret[j] == mbedtls_test_buffer_put(&buf,
+ input + written, put[j]));
written += put_ret[j];
- TEST_ASSERT( get_ret[j] == mbedtls_test_buffer_get( &buf,
- output + read, get[j] ) );
+ TEST_ASSERT(get_ret[j] == mbedtls_test_buffer_get(&buf,
+ output + read, get[j]));
read += get_ret[j];
- TEST_ASSERT( read <= written );
- if( get_ret[j] > 0 )
- {
- TEST_ASSERT( memcmp( output + read - get_ret[j],
- input + read - get_ret[j], get_ret[j] )
- == 0 );
+ TEST_ASSERT(read <= written);
+ if (get_ret[j] > 0) {
+ TEST_ASSERT(memcmp(output + read - get_ret[j],
+ input + read - get_ret[j], get_ret[j])
+ == 0);
}
}
exit:
- mbedtls_free( input );
- mbedtls_free( output );
- mbedtls_test_buffer_free( &buf );
+ mbedtls_free(input);
+ mbedtls_free(output);
+ mbedtls_test_buffer_free(&buf);
}
/* END_CASE */
@@ -2788,30 +2681,30 @@
*/
/* BEGIN_CASE */
-void ssl_mock_sanity( )
+void ssl_mock_sanity()
{
enum { MSGLEN = 105 };
unsigned char message[MSGLEN] = { 0 };
unsigned char received[MSGLEN] = { 0 };
mbedtls_mock_socket socket;
- mbedtls_mock_socket_init( &socket );
- TEST_ASSERT( mbedtls_mock_tcp_send_b( &socket, message, MSGLEN ) < 0 );
- mbedtls_mock_socket_close( &socket );
- mbedtls_mock_socket_init( &socket );
- TEST_ASSERT( mbedtls_mock_tcp_recv_b( &socket, received, MSGLEN ) < 0 );
- mbedtls_mock_socket_close( &socket );
+ mbedtls_mock_socket_init(&socket);
+ TEST_ASSERT(mbedtls_mock_tcp_send_b(&socket, message, MSGLEN) < 0);
+ mbedtls_mock_socket_close(&socket);
+ mbedtls_mock_socket_init(&socket);
+ TEST_ASSERT(mbedtls_mock_tcp_recv_b(&socket, received, MSGLEN) < 0);
+ mbedtls_mock_socket_close(&socket);
- mbedtls_mock_socket_init( &socket );
- TEST_ASSERT( mbedtls_mock_tcp_send_nb( &socket, message, MSGLEN ) < 0 );
- mbedtls_mock_socket_close( &socket );
- mbedtls_mock_socket_init( &socket );
- TEST_ASSERT( mbedtls_mock_tcp_recv_nb( &socket, received, MSGLEN ) < 0 );
- mbedtls_mock_socket_close( &socket );
+ mbedtls_mock_socket_init(&socket);
+ TEST_ASSERT(mbedtls_mock_tcp_send_nb(&socket, message, MSGLEN) < 0);
+ mbedtls_mock_socket_close(&socket);
+ mbedtls_mock_socket_init(&socket);
+ TEST_ASSERT(mbedtls_mock_tcp_recv_nb(&socket, received, MSGLEN) < 0);
+ mbedtls_mock_socket_close(&socket);
exit:
- mbedtls_mock_socket_close( &socket );
+ mbedtls_mock_socket_close(&socket);
}
/* END_CASE */
@@ -2821,7 +2714,7 @@
*/
/* BEGIN_CASE */
-void ssl_mock_tcp( int blocking )
+void ssl_mock_tcp(int blocking)
{
enum { MSGLEN = 105 };
enum { BUFLEN = MSGLEN / 5 };
@@ -2835,94 +2728,76 @@
mbedtls_ssl_recv_t *recv;
unsigned i;
- if( blocking == 0 )
- {
+ if (blocking == 0) {
send = mbedtls_mock_tcp_send_nb;
recv = mbedtls_mock_tcp_recv_nb;
- }
- else
- {
+ } else {
send = mbedtls_mock_tcp_send_b;
recv = mbedtls_mock_tcp_recv_b;
}
- mbedtls_mock_socket_init( &client );
- mbedtls_mock_socket_init( &server );
+ mbedtls_mock_socket_init(&client);
+ mbedtls_mock_socket_init(&server);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
/* Make sure that sending a message takes a few iterations. */
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server, BUFLEN ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server, BUFLEN));
/* Send the message to the server */
send_ret = recv_ret = 1;
written = read = 0;
- while( send_ret != 0 || recv_ret != 0 )
- {
- send_ret = send( &client, message + written, MSGLEN - written );
+ while (send_ret != 0 || recv_ret != 0) {
+ send_ret = send(&client, message + written, MSGLEN - written);
- TEST_ASSERT( send_ret >= 0 );
- TEST_ASSERT( send_ret <= BUFLEN );
+ TEST_ASSERT(send_ret >= 0);
+ TEST_ASSERT(send_ret <= BUFLEN);
written += send_ret;
/* If the buffer is full we can test blocking and non-blocking send */
- if ( send_ret == BUFLEN )
- {
- int blocking_ret = send( &client, message , 1 );
- if ( blocking )
- {
- TEST_ASSERT( blocking_ret == 0 );
- }
- else
- {
- TEST_ASSERT( blocking_ret == MBEDTLS_ERR_SSL_WANT_WRITE );
+ if (send_ret == BUFLEN) {
+ int blocking_ret = send(&client, message, 1);
+ if (blocking) {
+ TEST_ASSERT(blocking_ret == 0);
+ } else {
+ TEST_ASSERT(blocking_ret == MBEDTLS_ERR_SSL_WANT_WRITE);
}
}
- recv_ret = recv( &server, received + read, MSGLEN - read );
+ recv_ret = recv(&server, received + read, MSGLEN - read);
/* The result depends on whether any data was sent */
- if ( send_ret > 0 )
- {
- TEST_ASSERT( recv_ret > 0 );
- TEST_ASSERT( recv_ret <= BUFLEN );
+ if (send_ret > 0) {
+ TEST_ASSERT(recv_ret > 0);
+ TEST_ASSERT(recv_ret <= BUFLEN);
read += recv_ret;
- }
- else if( blocking )
- {
- TEST_ASSERT( recv_ret == 0 );
- }
- else
- {
- TEST_ASSERT( recv_ret == MBEDTLS_ERR_SSL_WANT_READ );
+ } else if (blocking) {
+ TEST_ASSERT(recv_ret == 0);
+ } else {
+ TEST_ASSERT(recv_ret == MBEDTLS_ERR_SSL_WANT_READ);
recv_ret = 0;
}
/* If the buffer is empty we can test blocking and non-blocking read */
- if ( recv_ret == BUFLEN )
- {
- int blocking_ret = recv( &server, received, 1 );
- if ( blocking )
- {
- TEST_ASSERT( blocking_ret == 0 );
- }
- else
- {
- TEST_ASSERT( blocking_ret == MBEDTLS_ERR_SSL_WANT_READ );
+ if (recv_ret == BUFLEN) {
+ int blocking_ret = recv(&server, received, 1);
+ if (blocking) {
+ TEST_ASSERT(blocking_ret == 0);
+ } else {
+ TEST_ASSERT(blocking_ret == MBEDTLS_ERR_SSL_WANT_READ);
}
}
}
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
exit:
- mbedtls_mock_socket_close( &client );
- mbedtls_mock_socket_close( &server );
+ mbedtls_mock_socket_close(&client);
+ mbedtls_mock_socket_close(&server);
}
/* END_CASE */
@@ -2933,7 +2808,7 @@
*/
/* BEGIN_CASE */
-void ssl_mock_tcp_interleaving( int blocking )
+void ssl_mock_tcp_interleaving(int blocking)
{
enum { ROUNDS = 2 };
enum { MSGLEN = 105 };
@@ -2950,305 +2825,283 @@
mbedtls_ssl_send_t *send;
mbedtls_ssl_recv_t *recv;
- if( blocking == 0 )
- {
+ if (blocking == 0) {
send = mbedtls_mock_tcp_send_nb;
recv = mbedtls_mock_tcp_recv_nb;
- }
- else
- {
+ } else {
send = mbedtls_mock_tcp_send_b;
recv = mbedtls_mock_tcp_recv_b;
}
- mbedtls_mock_socket_init( &client );
- mbedtls_mock_socket_init( &server );
+ mbedtls_mock_socket_init(&client);
+ mbedtls_mock_socket_init(&server);
/* Fill up the buffers with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < ROUNDS; i++ )
- {
- for( j = 0; j < MSGLEN; j++ )
- {
- message[i][j] = ( i * MSGLEN + j ) & 0xFF;
+ for (i = 0; i < ROUNDS; i++) {
+ for (j = 0; j < MSGLEN; j++) {
+ message[i][j] = (i * MSGLEN + j) & 0xFF;
}
}
/* Make sure that sending a message takes a few iterations. */
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server, BUFLEN ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server, BUFLEN));
/* Send the message from both sides, interleaving. */
progress = 1;
- for( i = 0; i < ROUNDS; i++ )
- {
+ for (i = 0; i < ROUNDS; i++) {
written[i] = 0;
read[i] = 0;
}
/* This loop does not stop as long as there was a successful write or read
* of at least one byte on either side. */
- while( progress != 0 )
- {
+ while (progress != 0) {
mbedtls_mock_socket *socket;
- for( i = 0; i < ROUNDS; i++ )
- {
+ for (i = 0; i < ROUNDS; i++) {
/* First sending is from the client */
- socket = ( i % 2 == 0 ) ? ( &client ) : ( &server );
+ socket = (i % 2 == 0) ? (&client) : (&server);
- send_ret[i] = send( socket, message[i] + written[i],
- MSGLEN - written[i] );
- TEST_ASSERT( send_ret[i] >= 0 );
- TEST_ASSERT( send_ret[i] <= BUFLEN );
+ send_ret[i] = send(socket, message[i] + written[i],
+ MSGLEN - written[i]);
+ TEST_ASSERT(send_ret[i] >= 0);
+ TEST_ASSERT(send_ret[i] <= BUFLEN);
written[i] += send_ret[i];
/* If the buffer is full we can test blocking and non-blocking
* send */
- if ( send_ret[i] == BUFLEN )
- {
- int blocking_ret = send( socket, message[i] , 1 );
- if ( blocking )
- {
- TEST_ASSERT( blocking_ret == 0 );
- }
- else
- {
- TEST_ASSERT( blocking_ret == MBEDTLS_ERR_SSL_WANT_WRITE );
+ if (send_ret[i] == BUFLEN) {
+ int blocking_ret = send(socket, message[i], 1);
+ if (blocking) {
+ TEST_ASSERT(blocking_ret == 0);
+ } else {
+ TEST_ASSERT(blocking_ret == MBEDTLS_ERR_SSL_WANT_WRITE);
}
}
}
- for( i = 0; i < ROUNDS; i++ )
- {
+ for (i = 0; i < ROUNDS; i++) {
/* First receiving is from the server */
- socket = ( i % 2 == 0 ) ? ( &server ) : ( &client );
+ socket = (i % 2 == 0) ? (&server) : (&client);
- recv_ret[i] = recv( socket, received[i] + read[i],
- MSGLEN - read[i] );
+ recv_ret[i] = recv(socket, received[i] + read[i],
+ MSGLEN - read[i]);
/* The result depends on whether any data was sent */
- if ( send_ret[i] > 0 )
- {
- TEST_ASSERT( recv_ret[i] > 0 );
- TEST_ASSERT( recv_ret[i] <= BUFLEN );
+ if (send_ret[i] > 0) {
+ TEST_ASSERT(recv_ret[i] > 0);
+ TEST_ASSERT(recv_ret[i] <= BUFLEN);
read[i] += recv_ret[i];
- }
- else if( blocking )
- {
- TEST_ASSERT( recv_ret[i] == 0 );
- }
- else
- {
- TEST_ASSERT( recv_ret[i] == MBEDTLS_ERR_SSL_WANT_READ );
+ } else if (blocking) {
+ TEST_ASSERT(recv_ret[i] == 0);
+ } else {
+ TEST_ASSERT(recv_ret[i] == MBEDTLS_ERR_SSL_WANT_READ);
recv_ret[i] = 0;
}
/* If the buffer is empty we can test blocking and non-blocking
* read */
- if ( recv_ret[i] == BUFLEN )
- {
- int blocking_ret = recv( socket, received[i], 1 );
- if ( blocking )
- {
- TEST_ASSERT( blocking_ret == 0 );
- }
- else
- {
- TEST_ASSERT( blocking_ret == MBEDTLS_ERR_SSL_WANT_READ );
+ if (recv_ret[i] == BUFLEN) {
+ int blocking_ret = recv(socket, received[i], 1);
+ if (blocking) {
+ TEST_ASSERT(blocking_ret == 0);
+ } else {
+ TEST_ASSERT(blocking_ret == MBEDTLS_ERR_SSL_WANT_READ);
}
}
}
progress = 0;
- for( i = 0; i < ROUNDS; i++ )
- {
+ for (i = 0; i < ROUNDS; i++) {
progress += send_ret[i] + recv_ret[i];
}
}
- for( i = 0; i < ROUNDS; i++ )
- TEST_ASSERT( memcmp( message[i], received[i], MSGLEN ) == 0 );
+ for (i = 0; i < ROUNDS; i++) {
+ TEST_ASSERT(memcmp(message[i], received[i], MSGLEN) == 0);
+ }
exit:
- mbedtls_mock_socket_close( &client );
- mbedtls_mock_socket_close( &server );
+ mbedtls_mock_socket_close(&client);
+ mbedtls_mock_socket_close(&server);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_queue_sanity( )
+void ssl_message_queue_sanity()
{
mbedtls_test_message_queue queue;
/* Trying to push/pull to an empty queue */
- TEST_ASSERT( mbedtls_test_message_queue_push_info( NULL, 1 )
- == MBEDTLS_TEST_ERROR_ARG_NULL );
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( NULL, 1 )
- == MBEDTLS_TEST_ERROR_ARG_NULL );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(NULL, 1)
+ == MBEDTLS_TEST_ERROR_ARG_NULL);
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(NULL, 1)
+ == MBEDTLS_TEST_ERROR_ARG_NULL);
- TEST_ASSERT( mbedtls_test_message_queue_setup( &queue, 3 ) == 0 );
- TEST_ASSERT( queue.capacity == 3 );
- TEST_ASSERT( queue.num == 0 );
+ TEST_ASSERT(mbedtls_test_message_queue_setup(&queue, 3) == 0);
+ TEST_ASSERT(queue.capacity == 3);
+ TEST_ASSERT(queue.num == 0);
exit:
- mbedtls_test_message_queue_free( &queue );
+ mbedtls_test_message_queue_free(&queue);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_queue_basic( )
+void ssl_message_queue_basic()
{
mbedtls_test_message_queue queue;
- TEST_ASSERT( mbedtls_test_message_queue_setup( &queue, 3 ) == 0 );
+ TEST_ASSERT(mbedtls_test_message_queue_setup(&queue, 3) == 0);
/* Sanity test - 3 pushes and 3 pops with sufficient space */
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 1 ) == 1 );
- TEST_ASSERT( queue.capacity == 3 );
- TEST_ASSERT( queue.num == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 1 ) == 1 );
- TEST_ASSERT( queue.capacity == 3 );
- TEST_ASSERT( queue.num == 2 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 2 ) == 2 );
- TEST_ASSERT( queue.capacity == 3 );
- TEST_ASSERT( queue.num == 3 );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 1) == 1);
+ TEST_ASSERT(queue.capacity == 3);
+ TEST_ASSERT(queue.num == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 1) == 1);
+ TEST_ASSERT(queue.capacity == 3);
+ TEST_ASSERT(queue.num == 2);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 2) == 2);
+ TEST_ASSERT(queue.capacity == 3);
+ TEST_ASSERT(queue.num == 3);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 2 ) == 2 );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 2) == 2);
exit:
- mbedtls_test_message_queue_free( &queue );
+ mbedtls_test_message_queue_free(&queue);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_queue_overflow_underflow( )
+void ssl_message_queue_overflow_underflow()
{
mbedtls_test_message_queue queue;
- TEST_ASSERT( mbedtls_test_message_queue_setup( &queue, 3 ) == 0 );
+ TEST_ASSERT(mbedtls_test_message_queue_setup(&queue, 3) == 0);
/* 4 pushes (last one with an error), 4 pops (last one with an error) */
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 2 ) == 2 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 3 )
- == MBEDTLS_ERR_SSL_WANT_WRITE );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 2) == 2);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 3)
+ == MBEDTLS_ERR_SSL_WANT_WRITE);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 2 ) == 2 );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 2) == 2);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 1 )
- == MBEDTLS_ERR_SSL_WANT_READ );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 1)
+ == MBEDTLS_ERR_SSL_WANT_READ);
exit:
- mbedtls_test_message_queue_free( &queue );
+ mbedtls_test_message_queue_free(&queue);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_queue_interleaved( )
+void ssl_message_queue_interleaved()
{
mbedtls_test_message_queue queue;
- TEST_ASSERT( mbedtls_test_message_queue_setup( &queue, 3 ) == 0 );
+ TEST_ASSERT(mbedtls_test_message_queue_setup(&queue, 3) == 0);
/* Interleaved test - [2 pushes, 1 pop] twice, and then two pops
* (to wrap around the buffer) */
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 1 ) == 1 );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 1) == 1);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 1 ) == 1 );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 1) == 1);
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 2 ) == 2 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 3 ) == 3 );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 2) == 2);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 3) == 3);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 1 ) == 1 );
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 2 ) == 2 );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 1) == 1);
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 2) == 2);
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 5 ) == 5 );
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, 8 ) == 8 );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 5) == 5);
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, 8) == 8);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 3 ) == 3 );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 3) == 3);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 5 ) == 5 );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 5) == 5);
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, 8 ) == 8 );
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, 8) == 8);
exit:
- mbedtls_test_message_queue_free( &queue );
+ mbedtls_test_message_queue_free(&queue);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_queue_insufficient_buffer( )
+void ssl_message_queue_insufficient_buffer()
{
mbedtls_test_message_queue queue;
size_t message_len = 10;
size_t buffer_len = 5;
- TEST_ASSERT( mbedtls_test_message_queue_setup( &queue, 1 ) == 0 );
+ TEST_ASSERT(mbedtls_test_message_queue_setup(&queue, 1) == 0);
/* Popping without a sufficient buffer */
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &queue, message_len )
- == (int) message_len );
- TEST_ASSERT( mbedtls_test_message_queue_pop_info( &queue, buffer_len )
- == (int) buffer_len );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&queue, message_len)
+ == (int) message_len);
+ TEST_ASSERT(mbedtls_test_message_queue_pop_info(&queue, buffer_len)
+ == (int) buffer_len);
exit:
- mbedtls_test_message_queue_free( &queue );
+ mbedtls_test_message_queue_free(&queue);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_uninitialized( )
+void ssl_message_mock_uninitialized()
{
enum { MSGLEN = 10 };
- unsigned char message[MSGLEN] = {0}, received[MSGLEN];
+ unsigned char message[MSGLEN] = { 0 }, received[MSGLEN];
mbedtls_mock_socket client, server;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
/* Send with a NULL context */
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( NULL, message, MSGLEN )
- == MBEDTLS_TEST_ERROR_CONTEXT_ERROR );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(NULL, message, MSGLEN)
+ == MBEDTLS_TEST_ERROR_CONTEXT_ERROR);
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( NULL, message, MSGLEN )
- == MBEDTLS_TEST_ERROR_CONTEXT_ERROR );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(NULL, message, MSGLEN)
+ == MBEDTLS_TEST_ERROR_CONTEXT_ERROR);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 1,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 1,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 1,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 1,
+ &client,
+ &client_context) == 0);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message, MSGLEN )
- == MBEDTLS_TEST_ERROR_SEND_FAILED );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message, MSGLEN)
+ == MBEDTLS_TEST_ERROR_SEND_FAILED);
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MBEDTLS_ERR_SSL_WANT_READ );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MBEDTLS_ERR_SSL_WANT_READ);
/* Push directly to a queue to later simulate a disconnected behavior */
- TEST_ASSERT( mbedtls_test_message_queue_push_info( &server_queue, MSGLEN )
- == MSGLEN );
+ TEST_ASSERT(mbedtls_test_message_queue_push_info(&server_queue, MSGLEN)
+ == MSGLEN);
/* Test if there's an error when trying to read from a disconnected
* socket */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MBEDTLS_TEST_ERROR_RECV_FAILED );
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MBEDTLS_TEST_ERROR_RECV_FAILED);
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_basic( )
+void ssl_message_mock_basic()
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
@@ -3256,54 +3109,53 @@
unsigned i;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 1,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 1,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 1,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 1,
+ &client,
+ &client_context) == 0);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server,
- MSGLEN ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server,
+ MSGLEN));
/* Send the message to the server */
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
/* Read from the server */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
- memset( received, 0, MSGLEN );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
+ memset(received, 0, MSGLEN);
/* Send the message to the client */
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &server_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&server_context, message,
+ MSGLEN) == MSGLEN);
/* Read from the client */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &client_context, received, MSGLEN )
- == MSGLEN );
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&client_context, received, MSGLEN)
+ == MSGLEN);
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_queue_overflow_underflow( )
+void ssl_message_mock_queue_overflow_underflow()
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
@@ -3311,57 +3163,56 @@
unsigned i;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 2,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 2,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 2,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 2,
+ &client,
+ &client_context) == 0);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server,
- MSGLEN*2 ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server,
+ MSGLEN*2));
/* Send three message to the server, last one with an error */
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN - 1 ) == MSGLEN - 1 );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN - 1) == MSGLEN - 1);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN )
- == MBEDTLS_ERR_SSL_WANT_WRITE );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN)
+ == MBEDTLS_ERR_SSL_WANT_WRITE);
/* Read three messages from the server, last one with an error */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received,
- MSGLEN - 1 ) == MSGLEN - 1 );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received,
+ MSGLEN - 1) == MSGLEN - 1);
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MBEDTLS_ERR_SSL_WANT_READ );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MBEDTLS_ERR_SSL_WANT_READ);
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_socket_overflow( )
+void ssl_message_mock_socket_overflow()
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
@@ -3369,48 +3220,47 @@
unsigned i;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 2,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 2,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 2,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 2,
+ &client,
+ &client_context) == 0);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server,
- MSGLEN ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server,
+ MSGLEN));
/* Send two message to the server, second one with an error */
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN )
- == MBEDTLS_TEST_ERROR_SEND_FAILED );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN)
+ == MBEDTLS_TEST_ERROR_SEND_FAILED);
/* Read the only message from the server */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_truncated( )
+void ssl_message_mock_truncated()
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
@@ -3418,58 +3268,57 @@
unsigned i;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 2,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 2,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 2,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 2,
+ &client,
+ &client_context) == 0);
- memset( received, 0, MSGLEN );
+ memset(received, 0, MSGLEN);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server,
- 2 * MSGLEN ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server,
+ 2 * MSGLEN));
/* Send two messages to the server, the second one small enough to fit in the
* receiver's buffer. */
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN / 2 ) == MSGLEN / 2 );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN / 2) == MSGLEN / 2);
/* Read a truncated message from the server */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN/2 )
- == MSGLEN/2 );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN/2)
+ == MSGLEN/2);
/* Test that the first half of the message is valid, and second one isn't */
- TEST_ASSERT( memcmp( message, received, MSGLEN/2 ) == 0 );
- TEST_ASSERT( memcmp( message + MSGLEN/2, received + MSGLEN/2, MSGLEN/2 )
- != 0 );
- memset( received, 0, MSGLEN );
+ TEST_ASSERT(memcmp(message, received, MSGLEN/2) == 0);
+ TEST_ASSERT(memcmp(message + MSGLEN/2, received + MSGLEN/2, MSGLEN/2)
+ != 0);
+ memset(received, 0, MSGLEN);
/* Read a full message from the server */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN/2 )
- == MSGLEN / 2 );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN/2)
+ == MSGLEN / 2);
/* Test that the first half of the message is valid */
- TEST_ASSERT( memcmp( message, received, MSGLEN/2 ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN/2) == 0);
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_socket_read_error( )
+void ssl_message_mock_socket_read_error()
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
@@ -3477,53 +3326,52 @@
unsigned i;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 1,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 1,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 1,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 1,
+ &client,
+ &client_context) == 0);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server,
- MSGLEN ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server,
+ MSGLEN));
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
/* Force a read error by disconnecting the socket by hand */
server.status = 0;
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MBEDTLS_TEST_ERROR_RECV_FAILED );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MBEDTLS_TEST_ERROR_RECV_FAILED);
/* Return to a valid state */
server.status = MBEDTLS_MOCK_SOCKET_CONNECTED;
- memset( received, 0, sizeof( received ) );
+ memset(received, 0, sizeof(received));
/* Test that even though the server tried to read once disconnected, the
* continuity is preserved */
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_interleaved_one_way( )
+void ssl_message_mock_interleaved_one_way()
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
@@ -3531,59 +3379,56 @@
unsigned i;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 3,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 3,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 3,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 3,
+ &client,
+ &client_context) == 0);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server,
- MSGLEN*3 ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server,
+ MSGLEN*3));
/* Interleaved test - [2 sends, 1 read] twice, and then two reads
* (to wrap around the buffer) */
- for( i = 0; i < 2; i++ )
- {
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ for (i = 0; i < 2; i++) {
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received,
- MSGLEN ) == MSGLEN );
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
- memset( received, 0, sizeof( received ) );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received,
+ MSGLEN) == MSGLEN);
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
+ memset(received, 0, sizeof(received));
}
- for( i = 0; i < 2; i++ )
- {
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received,
- MSGLEN ) == MSGLEN );
+ for (i = 0; i < 2; i++) {
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
}
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MBEDTLS_ERR_SSL_WANT_READ );
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MBEDTLS_ERR_SSL_WANT_READ);
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_message_mock_interleaved_two_ways( )
+void ssl_message_mock_interleaved_two_ways()
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
@@ -3591,132 +3436,128 @@
unsigned i;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_message_socket_setup( &server_queue, &client_queue, 3,
- &server,
- &server_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&server_queue, &client_queue, 3,
+ &server,
+ &server_context) == 0);
- TEST_ASSERT( mbedtls_message_socket_setup( &client_queue, &server_queue, 3,
- &client,
- &client_context ) == 0 );
+ TEST_ASSERT(mbedtls_message_socket_setup(&client_queue, &server_queue, 3,
+ &client,
+ &client_context) == 0);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
- for( i = 0; i < MSGLEN; i++ )
- {
+ for (i = 0; i < MSGLEN; i++) {
message[i] = i & 0xFF;
}
- TEST_ASSERT( 0 == mbedtls_mock_socket_connect( &client, &server,
- MSGLEN*3 ) );
+ TEST_ASSERT(0 == mbedtls_mock_socket_connect(&client, &server,
+ MSGLEN*3));
/* Interleaved test - [2 sends, 1 read] twice, both ways, and then two reads
* (to wrap around the buffer) both ways. */
- for( i = 0; i < 2; i++ )
- {
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ for (i = 0; i < 2; i++) {
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &client_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&client_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &server_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&server_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_send_msg( &server_context, message,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_send_msg(&server_context, message,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
- memset( received, 0, sizeof( received ) );
+ memset(received, 0, sizeof(received));
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &client_context, received,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&client_context, received,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
- memset( received, 0, sizeof( received ) );
+ memset(received, 0, sizeof(received));
}
- for( i = 0; i < 2; i++ )
- {
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received,
- MSGLEN ) == MSGLEN );
+ for (i = 0; i < 2; i++) {
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
- memset( received, 0, sizeof( received ) );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
+ memset(received, 0, sizeof(received));
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &client_context, received,
- MSGLEN ) == MSGLEN );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&client_context, received,
+ MSGLEN) == MSGLEN);
- TEST_ASSERT( memcmp( message, received, MSGLEN ) == 0 );
- memset( received, 0, sizeof( received ) );
+ TEST_ASSERT(memcmp(message, received, MSGLEN) == 0);
+ memset(received, 0, sizeof(received));
}
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &server_context, received, MSGLEN )
- == MBEDTLS_ERR_SSL_WANT_READ );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&server_context, received, MSGLEN)
+ == MBEDTLS_ERR_SSL_WANT_READ);
- TEST_ASSERT( mbedtls_mock_tcp_recv_msg( &client_context, received, MSGLEN )
- == MBEDTLS_ERR_SSL_WANT_READ );
- exit:
- mbedtls_message_socket_close( &server_context );
- mbedtls_message_socket_close( &client_context );
+ TEST_ASSERT(mbedtls_mock_tcp_recv_msg(&client_context, received, MSGLEN)
+ == MBEDTLS_ERR_SSL_WANT_READ);
+exit:
+ mbedtls_message_socket_close(&server_context);
+ mbedtls_message_socket_close(&client_context);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_DTLS_ANTI_REPLAY */
-void ssl_dtls_replay( data_t * prevs, data_t * new, int ret )
+void ssl_dtls_replay(data_t *prevs, data_t *new, int ret)
{
uint32_t len = 0;
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
- TEST_ASSERT( mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_DATAGRAM,
- MBEDTLS_SSL_PRESET_DEFAULT ) == 0 );
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_DATAGRAM,
+ MBEDTLS_SSL_PRESET_DEFAULT) == 0);
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
/* Read previous record numbers */
- for( len = 0; len < prevs->len; len += 6 )
- {
- memcpy( ssl.in_ctr + 2, prevs->x + len, 6 );
- mbedtls_ssl_dtls_replay_update( &ssl );
+ for (len = 0; len < prevs->len; len += 6) {
+ memcpy(ssl.in_ctr + 2, prevs->x + len, 6);
+ mbedtls_ssl_dtls_replay_update(&ssl);
}
/* Check new number */
- memcpy( ssl.in_ctr + 2, new->x, 6 );
- TEST_ASSERT( mbedtls_ssl_dtls_replay_check( &ssl ) == ret );
+ memcpy(ssl.in_ctr + 2, new->x, 6);
+ TEST_ASSERT(mbedtls_ssl_dtls_replay_check(&ssl) == ret);
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
-void ssl_set_hostname_twice( char *hostname0, char *hostname1 )
+void ssl_set_hostname_twice(char *hostname0, char *hostname1)
{
mbedtls_ssl_context ssl;
- mbedtls_ssl_init( &ssl );
+ mbedtls_ssl_init(&ssl);
- TEST_ASSERT( mbedtls_ssl_set_hostname( &ssl, hostname0 ) == 0 );
- TEST_ASSERT( mbedtls_ssl_set_hostname( &ssl, hostname1 ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_set_hostname(&ssl, hostname0) == 0);
+ TEST_ASSERT(mbedtls_ssl_set_hostname(&ssl, hostname1) == 0);
- mbedtls_ssl_free( &ssl );
+ mbedtls_ssl_free(&ssl);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_crypt_record( int cipher_type, int hash_id,
- int etm, int tag_mode, int ver,
- int cid0_len, int cid1_len )
+void ssl_crypt_record(int cipher_type, int hash_id,
+ int etm, int tag_mode, int ver,
+ int cid0_len, int cid1_len)
{
/*
* Test several record encryptions and decryptions
@@ -3733,31 +3574,27 @@
size_t const buflen = 512;
mbedtls_record rec, rec_backup;
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_transform_init( &t0 );
- mbedtls_ssl_transform_init( &t1 );
- ret = build_transforms( &t0, &t1, cipher_type, hash_id,
- etm, tag_mode, ver,
- (size_t) cid0_len,
- (size_t) cid1_len );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_transform_init(&t0);
+ mbedtls_ssl_transform_init(&t1);
+ ret = build_transforms(&t0, &t1, cipher_type, hash_id,
+ etm, tag_mode, ver,
+ (size_t) cid0_len,
+ (size_t) cid1_len);
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(ret == 0);
- TEST_ASSERT( ( buf = mbedtls_calloc( 1, buflen ) ) != NULL );
+ TEST_ASSERT((buf = mbedtls_calloc(1, buflen)) != NULL);
- while( num_records-- > 0 )
- {
+ while (num_records-- > 0) {
mbedtls_ssl_transform *t_dec, *t_enc;
/* Take turns in who's sending and who's receiving. */
- if( num_records % 3 == 0 )
- {
+ if (num_records % 3 == 0) {
t_dec = &t0;
t_enc = &t1;
- }
- else
- {
+ } else {
t_dec = &t1;
t_enc = &t0;
}
@@ -3774,7 +3611,7 @@
* type is sensible.
*/
- memset( rec.ctr, num_records, sizeof( rec.ctr ) );
+ memset(rec.ctr, num_records, sizeof(rec.ctr));
rec.type = 42;
rec.ver[0] = num_records;
rec.ver[1] = num_records;
@@ -3789,72 +3626,69 @@
* paddings. */
rec.data_len = 1 + num_records;
- memset( rec.buf + rec.data_offset, 42, rec.data_len );
+ memset(rec.buf + rec.data_offset, 42, rec.data_len);
/* Make a copy for later comparison */
rec_backup = rec;
/* Encrypt record */
- ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec,
- mbedtls_test_rnd_std_rand, NULL );
- TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
- if( ret != 0 )
- {
+ ret = mbedtls_ssl_encrypt_buf(&ssl, t_enc, &rec,
+ mbedtls_test_rnd_std_rand, NULL);
+ TEST_ASSERT(ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
+ if (ret != 0) {
continue;
}
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- if( rec.cid_len != 0 )
- {
+ if (rec.cid_len != 0) {
/* DTLS 1.2 + CID hides the real content type and
* uses a special CID content type in the protected
* record. Double-check this. */
- TEST_ASSERT( rec.type == MBEDTLS_SSL_MSG_CID );
+ TEST_ASSERT(rec.type == MBEDTLS_SSL_MSG_CID);
}
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if( t_enc->tls_version == MBEDTLS_SSL_VERSION_TLS1_3 )
- {
+ if (t_enc->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
/* TLS 1.3 hides the real content type and
* always uses Application Data as the content type
* for protected records. Double-check this. */
- TEST_ASSERT( rec.type == MBEDTLS_SSL_MSG_APPLICATION_DATA );
+ TEST_ASSERT(rec.type == MBEDTLS_SSL_MSG_APPLICATION_DATA);
}
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
/* Decrypt record with t_dec */
- ret = mbedtls_ssl_decrypt_buf( &ssl, t_dec, &rec );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_ssl_decrypt_buf(&ssl, t_dec, &rec);
+ TEST_ASSERT(ret == 0);
/* Compare results */
- TEST_ASSERT( rec.type == rec_backup.type );
- TEST_ASSERT( memcmp( rec.ctr, rec_backup.ctr, 8 ) == 0 );
- TEST_ASSERT( rec.ver[0] == rec_backup.ver[0] );
- TEST_ASSERT( rec.ver[1] == rec_backup.ver[1] );
- TEST_ASSERT( rec.data_len == rec_backup.data_len );
- TEST_ASSERT( rec.data_offset == rec_backup.data_offset );
- TEST_ASSERT( memcmp( rec.buf + rec.data_offset,
- rec_backup.buf + rec_backup.data_offset,
- rec.data_len ) == 0 );
+ TEST_ASSERT(rec.type == rec_backup.type);
+ TEST_ASSERT(memcmp(rec.ctr, rec_backup.ctr, 8) == 0);
+ TEST_ASSERT(rec.ver[0] == rec_backup.ver[0]);
+ TEST_ASSERT(rec.ver[1] == rec_backup.ver[1]);
+ TEST_ASSERT(rec.data_len == rec_backup.data_len);
+ TEST_ASSERT(rec.data_offset == rec_backup.data_offset);
+ TEST_ASSERT(memcmp(rec.buf + rec.data_offset,
+ rec_backup.buf + rec_backup.data_offset,
+ rec.data_len) == 0);
}
exit:
/* Cleanup */
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_transform_free( &t0 );
- mbedtls_ssl_transform_free( &t1 );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_transform_free(&t0);
+ mbedtls_ssl_transform_free(&t1);
- mbedtls_free( buf );
- USE_PSA_DONE( );
+ mbedtls_free(buf);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_crypt_record_small( int cipher_type, int hash_id,
- int etm, int tag_mode, int ver,
- int cid0_len, int cid1_len )
+void ssl_crypt_record_small(int cipher_type, int hash_id,
+ int etm, int tag_mode, int ver,
+ int cid0_len, int cid1_len)
{
/*
* Test pairs of encryption and decryption with an increasing
@@ -3894,30 +3728,28 @@
int seen_success; /* Indicates if in the current mode we've
* already seen a successful test. */
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_transform_init( &t0 );
- mbedtls_ssl_transform_init( &t1 );
- ret = build_transforms( &t0, &t1, cipher_type, hash_id,
- etm, tag_mode, ver,
- (size_t) cid0_len,
- (size_t) cid1_len );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_transform_init(&t0);
+ mbedtls_ssl_transform_init(&t1);
+ ret = build_transforms(&t0, &t1, cipher_type, hash_id,
+ etm, tag_mode, ver,
+ (size_t) cid0_len,
+ (size_t) cid1_len);
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(ret == 0);
- TEST_ASSERT( ( buf = mbedtls_calloc( 1, buflen ) ) != NULL );
+ TEST_ASSERT((buf = mbedtls_calloc(1, buflen)) != NULL);
- for( mode=1; mode <= 3; mode++ )
- {
+ for (mode = 1; mode <= 3; mode++) {
seen_success = 0;
- for( offset=0; offset <= threshold; offset++ )
- {
+ for (offset = 0; offset <= threshold; offset++) {
mbedtls_ssl_transform *t_dec, *t_enc;
t_dec = &t0;
t_enc = &t1;
- memset( rec.ctr, offset, sizeof( rec.ctr ) );
+ memset(rec.ctr, offset, sizeof(rec.ctr));
rec.type = 42;
rec.ver[0] = offset;
rec.ver[1] = offset;
@@ -3927,8 +3759,7 @@
rec.cid_len = 0;
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- switch( mode )
- {
+ switch (mode) {
case 1: /* Space in the beginning */
rec.data_offset = offset;
rec.data_len = buflen - offset - default_post_padding;
@@ -3945,86 +3776,83 @@
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
break;
}
- memset( rec.buf + rec.data_offset, 42, rec.data_len );
+ memset(rec.buf + rec.data_offset, 42, rec.data_len);
/* Make a copy for later comparison */
rec_backup = rec;
/* Encrypt record */
- ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec,
- mbedtls_test_rnd_std_rand, NULL );
+ ret = mbedtls_ssl_encrypt_buf(&ssl, t_enc, &rec,
+ mbedtls_test_rnd_std_rand, NULL);
- if( ( mode == 1 || mode == 2 ) && seen_success )
- {
- TEST_ASSERT( ret == 0 );
- }
- else
- {
- TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
- if( ret == 0 )
+ if ((mode == 1 || mode == 2) && seen_success) {
+ TEST_ASSERT(ret == 0);
+ } else {
+ TEST_ASSERT(ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
+ if (ret == 0) {
seen_success = 1;
+ }
}
- if( ret != 0 )
+ if (ret != 0) {
continue;
+ }
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- if( rec.cid_len != 0 )
- {
+ if (rec.cid_len != 0) {
/* DTLS 1.2 + CID hides the real content type and
* uses a special CID content type in the protected
* record. Double-check this. */
- TEST_ASSERT( rec.type == MBEDTLS_SSL_MSG_CID );
+ TEST_ASSERT(rec.type == MBEDTLS_SSL_MSG_CID);
}
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if( t_enc->tls_version == MBEDTLS_SSL_VERSION_TLS1_3 )
- {
+ if (t_enc->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
/* TLS 1.3 hides the real content type and
* always uses Application Data as the content type
* for protected records. Double-check this. */
- TEST_ASSERT( rec.type == MBEDTLS_SSL_MSG_APPLICATION_DATA );
+ TEST_ASSERT(rec.type == MBEDTLS_SSL_MSG_APPLICATION_DATA);
}
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
/* Decrypt record with t_dec */
- TEST_ASSERT( mbedtls_ssl_decrypt_buf( &ssl, t_dec, &rec ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_decrypt_buf(&ssl, t_dec, &rec) == 0);
/* Compare results */
- TEST_ASSERT( rec.type == rec_backup.type );
- TEST_ASSERT( memcmp( rec.ctr, rec_backup.ctr, 8 ) == 0 );
- TEST_ASSERT( rec.ver[0] == rec_backup.ver[0] );
- TEST_ASSERT( rec.ver[1] == rec_backup.ver[1] );
- TEST_ASSERT( rec.data_len == rec_backup.data_len );
- TEST_ASSERT( rec.data_offset == rec_backup.data_offset );
- TEST_ASSERT( memcmp( rec.buf + rec.data_offset,
- rec_backup.buf + rec_backup.data_offset,
- rec.data_len ) == 0 );
+ TEST_ASSERT(rec.type == rec_backup.type);
+ TEST_ASSERT(memcmp(rec.ctr, rec_backup.ctr, 8) == 0);
+ TEST_ASSERT(rec.ver[0] == rec_backup.ver[0]);
+ TEST_ASSERT(rec.ver[1] == rec_backup.ver[1]);
+ TEST_ASSERT(rec.data_len == rec_backup.data_len);
+ TEST_ASSERT(rec.data_offset == rec_backup.data_offset);
+ TEST_ASSERT(memcmp(rec.buf + rec.data_offset,
+ rec_backup.buf + rec_backup.data_offset,
+ rec.data_len) == 0);
}
- TEST_ASSERT( seen_success == 1 );
+ TEST_ASSERT(seen_success == 1);
}
exit:
/* Cleanup */
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_transform_free( &t0 );
- mbedtls_ssl_transform_free( &t1 );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_transform_free(&t0);
+ mbedtls_ssl_transform_free(&t1);
- mbedtls_free( buf );
- USE_PSA_DONE( );
+ mbedtls_free(buf);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_AES_C:MBEDTLS_SSL_PROTO_TLS1_2 */
-void ssl_decrypt_non_etm_cbc( int cipher_type, int hash_id, int trunc_hmac,
- int length_selector )
+void ssl_decrypt_non_etm_cbc(int cipher_type, int hash_id, int trunc_hmac,
+ int length_selector)
{
/*
* Test record decryption for CBC without EtM, focused on the verification
@@ -4061,57 +3889,55 @@
int ret;
const unsigned char pad_max_len = 255; /* Per the standard */
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_transform_init( &t0 );
- mbedtls_ssl_transform_init( &t1 );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_transform_init(&t0);
+ mbedtls_ssl_transform_init(&t1);
/* Set up transforms with dummy keys */
- ret = build_transforms( &t0, &t1, cipher_type, hash_id,
- 0, trunc_hmac,
- MBEDTLS_SSL_VERSION_TLS1_2,
- 0 , 0 );
+ ret = build_transforms(&t0, &t1, cipher_type, hash_id,
+ 0, trunc_hmac,
+ MBEDTLS_SSL_VERSION_TLS1_2,
+ 0, 0);
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(ret == 0);
/* Determine padding/plaintext length */
- TEST_ASSERT( length_selector >= -2 && length_selector <= 255 );
+ TEST_ASSERT(length_selector >= -2 && length_selector <= 255);
block_size = t0.ivlen;
- if( length_selector < 0 )
- {
+ if (length_selector < 0) {
plaintext_len = 0;
/* Minimal padding
* The +1 is for the padding_length byte, not counted in padlen. */
- padlen = block_size - ( t0.maclen + 1 ) % block_size;
+ padlen = block_size - (t0.maclen + 1) % block_size;
/* Maximal padding? */
- if( length_selector == -2 )
- padlen += block_size * ( ( pad_max_len - padlen ) / block_size );
- }
- else
- {
+ if (length_selector == -2) {
+ padlen += block_size * ((pad_max_len - padlen) / block_size);
+ }
+ } else {
padlen = length_selector;
/* Minimal non-zero plaintext_length giving desired padding.
* The +1 is for the padding_length byte, not counted in padlen. */
- plaintext_len = block_size - ( padlen + t0.maclen + 1 ) % block_size;
+ plaintext_len = block_size - (padlen + t0.maclen + 1) % block_size;
}
/* Prepare a buffer for record data */
buflen = block_size
- + plaintext_len
- + t0.maclen
- + padlen + 1;
- ASSERT_ALLOC( buf, buflen );
- ASSERT_ALLOC( buf_save, buflen );
+ + plaintext_len
+ + t0.maclen
+ + padlen + 1;
+ ASSERT_ALLOC(buf, buflen);
+ ASSERT_ALLOC(buf_save, buflen);
/* Prepare a dummy record header */
- memset( rec.ctr, 0, sizeof( rec.ctr ) );
+ memset(rec.ctr, 0, sizeof(rec.ctr));
rec.type = MBEDTLS_SSL_MSG_APPLICATION_DATA;
- mbedtls_ssl_write_version( rec.ver, MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_VERSION_TLS1_2 );
+ mbedtls_ssl_write_version(rec.ver, MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_VERSION_TLS1_2);
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
rec.cid_len = 0;
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
@@ -4121,19 +3947,19 @@
rec.buf_len = buflen;
rec.data_offset = block_size;
rec.data_len = plaintext_len;
- memset( rec.buf + rec.data_offset, 42, rec.data_len );
+ memset(rec.buf + rec.data_offset, 42, rec.data_len);
/* Serialized version of record header for MAC purposes */
- memcpy( add_data, rec.ctr, 8 );
+ memcpy(add_data, rec.ctr, 8);
add_data[8] = rec.type;
add_data[9] = rec.ver[0];
add_data[10] = rec.ver[1];
- add_data[11] = ( rec.data_len >> 8 ) & 0xff;
- add_data[12] = ( rec.data_len >> 0 ) & 0xff;
+ add_data[11] = (rec.data_len >> 8) & 0xff;
+ add_data[12] = (rec.data_len >> 0) & 0xff;
/* Set dummy IV */
- memset( t0.iv_enc, 0x55, t0.ivlen );
- memcpy( rec.buf, t0.iv_enc, t0.ivlen );
+ memset(t0.iv_enc, 0x55, t0.ivlen);
+ memcpy(rec.buf, t0.iv_enc, t0.ivlen);
/*
* Prepare a pre-encryption record (with MAC and padding), and save it.
@@ -4141,73 +3967,72 @@
/* MAC with additional data */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- TEST_EQUAL( PSA_SUCCESS, psa_mac_sign_setup( &operation,
- t0.psa_mac_enc,
- t0.psa_mac_alg ) );
- TEST_EQUAL( PSA_SUCCESS, psa_mac_update( &operation, add_data, 13 ) );
- TEST_EQUAL( PSA_SUCCESS, psa_mac_update( &operation,
- rec.buf + rec.data_offset,
- rec.data_len ) );
- TEST_EQUAL( PSA_SUCCESS, psa_mac_sign_finish( &operation,
- mac, sizeof(mac),
- &sign_mac_length ) );
-#else
- TEST_EQUAL( 0, mbedtls_md_hmac_update( &t0.md_ctx_enc, add_data, 13 ) );
- TEST_EQUAL( 0, mbedtls_md_hmac_update( &t0.md_ctx_enc,
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_sign_setup(&operation,
+ t0.psa_mac_enc,
+ t0.psa_mac_alg));
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_update(&operation, add_data, 13));
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_update(&operation,
rec.buf + rec.data_offset,
- rec.data_len ) );
- TEST_EQUAL( 0, mbedtls_md_hmac_finish( &t0.md_ctx_enc, mac ) );
+ rec.data_len));
+ TEST_EQUAL(PSA_SUCCESS, psa_mac_sign_finish(&operation,
+ mac, sizeof(mac),
+ &sign_mac_length));
+#else
+ TEST_EQUAL(0, mbedtls_md_hmac_update(&t0.md_ctx_enc, add_data, 13));
+ TEST_EQUAL(0, mbedtls_md_hmac_update(&t0.md_ctx_enc,
+ rec.buf + rec.data_offset,
+ rec.data_len));
+ TEST_EQUAL(0, mbedtls_md_hmac_finish(&t0.md_ctx_enc, mac));
#endif
- memcpy( rec.buf + rec.data_offset + rec.data_len, mac, t0.maclen );
+ memcpy(rec.buf + rec.data_offset + rec.data_len, mac, t0.maclen);
rec.data_len += t0.maclen;
/* Pad */
- memset( rec.buf + rec.data_offset + rec.data_len, padlen, padlen + 1 );
+ memset(rec.buf + rec.data_offset + rec.data_len, padlen, padlen + 1);
rec.data_len += padlen + 1;
/* Save correct pre-encryption record */
rec_save = rec;
rec_save.buf = buf_save;
- memcpy( buf_save, buf, buflen );
+ memcpy(buf_save, buf, buflen);
/*
* Encrypt and decrypt the correct record, expecting success
*/
- TEST_EQUAL( 0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen,
- rec.buf + rec.data_offset, rec.data_len,
- rec.buf + rec.data_offset, &olen ) );
+ TEST_EQUAL(0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen,
+ rec.buf + rec.data_offset, rec.data_len,
+ rec.buf + rec.data_offset, &olen));
rec.data_offset -= t0.ivlen;
rec.data_len += t0.ivlen;
- TEST_EQUAL( 0, mbedtls_ssl_decrypt_buf( &ssl, &t1, &rec ) );
+ TEST_EQUAL(0, mbedtls_ssl_decrypt_buf(&ssl, &t1, &rec));
/*
* Modify each byte of the pre-encryption record before encrypting and
* decrypting it, expecting failure every time.
*/
- for( i = block_size; i < buflen; i++ )
- {
- mbedtls_test_set_step( i );
+ for (i = block_size; i < buflen; i++) {
+ mbedtls_test_set_step(i);
/* Restore correct pre-encryption record */
rec = rec_save;
rec.buf = buf;
- memcpy( buf, buf_save, buflen );
+ memcpy(buf, buf_save, buflen);
/* Corrupt one byte of the data (could be plaintext, MAC or padding) */
rec.buf[i] ^= 0x01;
/* Encrypt */
- TEST_EQUAL( 0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen,
- rec.buf + rec.data_offset, rec.data_len,
- rec.buf + rec.data_offset, &olen ) );
+ TEST_EQUAL(0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen,
+ rec.buf + rec.data_offset, rec.data_len,
+ rec.buf + rec.data_offset, &olen));
rec.data_offset -= t0.ivlen;
rec.data_len += t0.ivlen;
/* Decrypt and expect failure */
- TEST_EQUAL( MBEDTLS_ERR_SSL_INVALID_MAC,
- mbedtls_ssl_decrypt_buf( &ssl, &t1, &rec ) );
+ TEST_EQUAL(MBEDTLS_ERR_SSL_INVALID_MAC,
+ mbedtls_ssl_decrypt_buf(&ssl, &t1, &rec));
}
/*
@@ -4222,353 +4047,352 @@
* (Start the loop with correct padding, just to double-check that record
* saving did work, and that we're overwriting the correct bytes.)
*/
- for( i = padlen; i <= pad_max_len; i++ )
- {
- mbedtls_test_set_step( i );
+ for (i = padlen; i <= pad_max_len; i++) {
+ mbedtls_test_set_step(i);
/* Restore correct pre-encryption record */
rec = rec_save;
rec.buf = buf;
- memcpy( buf, buf_save, buflen );
+ memcpy(buf, buf_save, buflen);
/* Set padding bytes to new value */
- memset( buf + buflen - padlen - 1, i, padlen + 1 );
+ memset(buf + buflen - padlen - 1, i, padlen + 1);
/* Encrypt */
- TEST_EQUAL( 0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen,
- rec.buf + rec.data_offset, rec.data_len,
- rec.buf + rec.data_offset, &olen ) );
+ TEST_EQUAL(0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen,
+ rec.buf + rec.data_offset, rec.data_len,
+ rec.buf + rec.data_offset, &olen));
rec.data_offset -= t0.ivlen;
rec.data_len += t0.ivlen;
/* Decrypt and expect failure except the first time */
- exp_ret = ( i == padlen ) ? 0 : MBEDTLS_ERR_SSL_INVALID_MAC;
- TEST_EQUAL( exp_ret, mbedtls_ssl_decrypt_buf( &ssl, &t1, &rec ) );
+ exp_ret = (i == padlen) ? 0 : MBEDTLS_ERR_SSL_INVALID_MAC;
+ TEST_EQUAL(exp_ret, mbedtls_ssl_decrypt_buf(&ssl, &t1, &rec));
}
exit:
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_transform_free( &t0 );
- mbedtls_ssl_transform_free( &t1 );
- mbedtls_free( buf );
- mbedtls_free( buf_save );
- USE_PSA_DONE( );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_transform_free(&t0);
+ mbedtls_ssl_transform_free(&t1);
+ mbedtls_free(buf);
+ mbedtls_free(buf_save);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_hkdf_expand_label( int hash_alg,
- data_t *secret,
- int label_idx,
- data_t *ctx,
- int desired_length,
- data_t *expected )
+void ssl_tls13_hkdf_expand_label(int hash_alg,
+ data_t *secret,
+ int label_idx,
+ data_t *ctx,
+ int desired_length,
+ data_t *expected)
{
- unsigned char dst[ 100 ];
+ unsigned char dst[100];
unsigned char const *lbl = NULL;
size_t lbl_len;
-#define MBEDTLS_SSL_TLS1_3_LABEL( name, string ) \
- if( label_idx == (int) tls13_label_ ## name ) \
+#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
+ if (label_idx == (int) tls13_label_ ## name) \
{ \
lbl = mbedtls_ssl_tls13_labels.name; \
- lbl_len = sizeof( mbedtls_ssl_tls13_labels.name ); \
+ lbl_len = sizeof(mbedtls_ssl_tls13_labels.name); \
}
-MBEDTLS_SSL_TLS1_3_LABEL_LIST
+ MBEDTLS_SSL_TLS1_3_LABEL_LIST
#undef MBEDTLS_SSL_TLS1_3_LABEL
- TEST_ASSERT( lbl != NULL );
+ TEST_ASSERT(lbl != NULL);
/* Check sanity of test parameters. */
- TEST_ASSERT( (size_t) desired_length <= sizeof(dst) );
- TEST_ASSERT( (size_t) desired_length == expected->len );
+ TEST_ASSERT((size_t) desired_length <= sizeof(dst));
+ TEST_ASSERT((size_t) desired_length == expected->len);
- PSA_INIT( );
+ PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_hkdf_expand_label(
- (psa_algorithm_t) hash_alg,
- secret->x, secret->len,
- lbl, lbl_len,
- ctx->x, ctx->len,
- dst, desired_length ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_hkdf_expand_label(
+ (psa_algorithm_t) hash_alg,
+ secret->x, secret->len,
+ lbl, lbl_len,
+ ctx->x, ctx->len,
+ dst, desired_length) == 0);
- ASSERT_COMPARE( dst, (size_t) desired_length,
- expected->x, (size_t) expected->len );
+ ASSERT_COMPARE(dst, (size_t) desired_length,
+ expected->x, (size_t) expected->len);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_traffic_key_generation( int hash_alg,
- data_t *server_secret,
- data_t *client_secret,
- int desired_iv_len,
- int desired_key_len,
- data_t *expected_server_write_key,
- data_t *expected_server_write_iv,
- data_t *expected_client_write_key,
- data_t *expected_client_write_iv )
+void ssl_tls13_traffic_key_generation(int hash_alg,
+ data_t *server_secret,
+ data_t *client_secret,
+ int desired_iv_len,
+ int desired_key_len,
+ data_t *expected_server_write_key,
+ data_t *expected_server_write_iv,
+ data_t *expected_client_write_key,
+ data_t *expected_client_write_iv)
{
mbedtls_ssl_key_set keys;
/* Check sanity of test parameters. */
- TEST_ASSERT( client_secret->len == server_secret->len );
- TEST_ASSERT( expected_client_write_iv->len == expected_server_write_iv->len &&
- expected_client_write_iv->len == (size_t) desired_iv_len );
- TEST_ASSERT( expected_client_write_key->len == expected_server_write_key->len &&
- expected_client_write_key->len == (size_t) desired_key_len );
+ TEST_ASSERT(client_secret->len == server_secret->len);
+ TEST_ASSERT(expected_client_write_iv->len == expected_server_write_iv->len &&
+ expected_client_write_iv->len == (size_t) desired_iv_len);
+ TEST_ASSERT(expected_client_write_key->len == expected_server_write_key->len &&
+ expected_client_write_key->len == (size_t) desired_key_len);
- PSA_INIT( );
+ PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_make_traffic_keys(
- (psa_algorithm_t) hash_alg,
- client_secret->x,
- server_secret->x,
- client_secret->len /* == server_secret->len */,
- desired_key_len, desired_iv_len,
- &keys ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_make_traffic_keys(
+ (psa_algorithm_t) hash_alg,
+ client_secret->x,
+ server_secret->x,
+ client_secret->len /* == server_secret->len */,
+ desired_key_len, desired_iv_len,
+ &keys) == 0);
- ASSERT_COMPARE( keys.client_write_key,
- keys.key_len,
- expected_client_write_key->x,
- (size_t) desired_key_len );
- ASSERT_COMPARE( keys.server_write_key,
- keys.key_len,
- expected_server_write_key->x,
- (size_t) desired_key_len );
- ASSERT_COMPARE( keys.client_write_iv,
- keys.iv_len,
- expected_client_write_iv->x,
- (size_t) desired_iv_len );
- ASSERT_COMPARE( keys.server_write_iv,
- keys.iv_len,
- expected_server_write_iv->x,
- (size_t) desired_iv_len );
+ ASSERT_COMPARE(keys.client_write_key,
+ keys.key_len,
+ expected_client_write_key->x,
+ (size_t) desired_key_len);
+ ASSERT_COMPARE(keys.server_write_key,
+ keys.key_len,
+ expected_server_write_key->x,
+ (size_t) desired_key_len);
+ ASSERT_COMPARE(keys.client_write_iv,
+ keys.iv_len,
+ expected_client_write_iv->x,
+ (size_t) desired_iv_len);
+ ASSERT_COMPARE(keys.server_write_iv,
+ keys.iv_len,
+ expected_server_write_iv->x,
+ (size_t) desired_iv_len);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_derive_secret( int hash_alg,
- data_t *secret,
- int label_idx,
- data_t *ctx,
- int desired_length,
- int already_hashed,
- data_t *expected )
+void ssl_tls13_derive_secret(int hash_alg,
+ data_t *secret,
+ int label_idx,
+ data_t *ctx,
+ int desired_length,
+ int already_hashed,
+ data_t *expected)
{
- unsigned char dst[ 100 ];
+ unsigned char dst[100];
unsigned char const *lbl = NULL;
size_t lbl_len;
-#define MBEDTLS_SSL_TLS1_3_LABEL( name, string ) \
- if( label_idx == (int) tls13_label_ ## name ) \
+#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
+ if (label_idx == (int) tls13_label_ ## name) \
{ \
lbl = mbedtls_ssl_tls13_labels.name; \
- lbl_len = sizeof( mbedtls_ssl_tls13_labels.name ); \
+ lbl_len = sizeof(mbedtls_ssl_tls13_labels.name); \
}
-MBEDTLS_SSL_TLS1_3_LABEL_LIST
+ MBEDTLS_SSL_TLS1_3_LABEL_LIST
#undef MBEDTLS_SSL_TLS1_3_LABEL
- TEST_ASSERT( lbl != NULL );
+ TEST_ASSERT(lbl != NULL);
/* Check sanity of test parameters. */
- TEST_ASSERT( (size_t) desired_length <= sizeof(dst) );
- TEST_ASSERT( (size_t) desired_length == expected->len );
+ TEST_ASSERT((size_t) desired_length <= sizeof(dst));
+ TEST_ASSERT((size_t) desired_length == expected->len);
- PSA_INIT( );
+ PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_derive_secret(
- (psa_algorithm_t) hash_alg,
- secret->x, secret->len,
- lbl, lbl_len,
- ctx->x, ctx->len,
- already_hashed,
- dst, desired_length ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_derive_secret(
+ (psa_algorithm_t) hash_alg,
+ secret->x, secret->len,
+ lbl, lbl_len,
+ ctx->x, ctx->len,
+ already_hashed,
+ dst, desired_length) == 0);
- ASSERT_COMPARE( dst, desired_length,
- expected->x, desired_length );
+ ASSERT_COMPARE(dst, desired_length,
+ expected->x, desired_length);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_derive_early_secrets( int hash_alg,
- data_t *secret,
- data_t *transcript,
- data_t *traffic_expected,
- data_t *exporter_expected )
+void ssl_tls13_derive_early_secrets(int hash_alg,
+ data_t *secret,
+ data_t *transcript,
+ data_t *traffic_expected,
+ data_t *exporter_expected)
{
mbedtls_ssl_tls13_early_secrets secrets;
/* Double-check that we've passed sane parameters. */
psa_algorithm_t alg = (psa_algorithm_t) hash_alg;
- size_t const hash_len = PSA_HASH_LENGTH( alg );
- TEST_ASSERT( PSA_ALG_IS_HASH( alg ) &&
- secret->len == hash_len &&
- transcript->len == hash_len &&
- traffic_expected->len == hash_len &&
- exporter_expected->len == hash_len );
+ size_t const hash_len = PSA_HASH_LENGTH(alg);
+ TEST_ASSERT(PSA_ALG_IS_HASH(alg) &&
+ secret->len == hash_len &&
+ transcript->len == hash_len &&
+ traffic_expected->len == hash_len &&
+ exporter_expected->len == hash_len);
- PSA_INIT( );
+ PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_derive_early_secrets(
- alg, secret->x, transcript->x, transcript->len,
- &secrets ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_derive_early_secrets(
+ alg, secret->x, transcript->x, transcript->len,
+ &secrets) == 0);
- ASSERT_COMPARE( secrets.client_early_traffic_secret, hash_len,
- traffic_expected->x, traffic_expected->len );
- ASSERT_COMPARE( secrets.early_exporter_master_secret, hash_len,
- exporter_expected->x, exporter_expected->len );
+ ASSERT_COMPARE(secrets.client_early_traffic_secret, hash_len,
+ traffic_expected->x, traffic_expected->len);
+ ASSERT_COMPARE(secrets.early_exporter_master_secret, hash_len,
+ exporter_expected->x, exporter_expected->len);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_derive_handshake_secrets( int hash_alg,
- data_t *secret,
- data_t *transcript,
- data_t *client_expected,
- data_t *server_expected )
+void ssl_tls13_derive_handshake_secrets(int hash_alg,
+ data_t *secret,
+ data_t *transcript,
+ data_t *client_expected,
+ data_t *server_expected)
{
mbedtls_ssl_tls13_handshake_secrets secrets;
/* Double-check that we've passed sane parameters. */
psa_algorithm_t alg = (psa_algorithm_t) hash_alg;
- size_t const hash_len = PSA_HASH_LENGTH( alg );
- TEST_ASSERT( PSA_ALG_IS_HASH( alg ) &&
- secret->len == hash_len &&
- transcript->len == hash_len &&
- client_expected->len == hash_len &&
- server_expected->len == hash_len );
+ size_t const hash_len = PSA_HASH_LENGTH(alg);
+ TEST_ASSERT(PSA_ALG_IS_HASH(alg) &&
+ secret->len == hash_len &&
+ transcript->len == hash_len &&
+ client_expected->len == hash_len &&
+ server_expected->len == hash_len);
- PSA_INIT( );
+ PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_derive_handshake_secrets(
- alg, secret->x, transcript->x, transcript->len,
- &secrets ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_derive_handshake_secrets(
+ alg, secret->x, transcript->x, transcript->len,
+ &secrets) == 0);
- ASSERT_COMPARE( secrets.client_handshake_traffic_secret, hash_len,
- client_expected->x, client_expected->len );
- ASSERT_COMPARE( secrets.server_handshake_traffic_secret, hash_len,
- server_expected->x, server_expected->len );
+ ASSERT_COMPARE(secrets.client_handshake_traffic_secret, hash_len,
+ client_expected->x, client_expected->len);
+ ASSERT_COMPARE(secrets.server_handshake_traffic_secret, hash_len,
+ server_expected->x, server_expected->len);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_derive_application_secrets( int hash_alg,
- data_t *secret,
- data_t *transcript,
- data_t *client_expected,
- data_t *server_expected,
- data_t *exporter_expected )
-{
- mbedtls_ssl_tls13_application_secrets secrets;
-
- /* Double-check that we've passed sane parameters. */
- psa_algorithm_t alg = (psa_algorithm_t) hash_alg;
- size_t const hash_len = PSA_HASH_LENGTH( alg );
- TEST_ASSERT( PSA_ALG_IS_HASH( alg ) &&
- secret->len == hash_len &&
- transcript->len == hash_len &&
- client_expected->len == hash_len &&
- server_expected->len == hash_len &&
- exporter_expected->len == hash_len );
-
- PSA_INIT( );
-
- TEST_ASSERT( mbedtls_ssl_tls13_derive_application_secrets(
- alg, secret->x, transcript->x, transcript->len,
- &secrets ) == 0 );
-
- ASSERT_COMPARE( secrets.client_application_traffic_secret_N, hash_len,
- client_expected->x, client_expected->len );
- ASSERT_COMPARE( secrets.server_application_traffic_secret_N, hash_len,
- server_expected->x, server_expected->len );
- ASSERT_COMPARE( secrets.exporter_master_secret, hash_len,
- exporter_expected->x, exporter_expected->len );
-
- PSA_DONE( );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_derive_resumption_secrets( int hash_alg,
+void ssl_tls13_derive_application_secrets(int hash_alg,
data_t *secret,
data_t *transcript,
- data_t *resumption_expected )
+ data_t *client_expected,
+ data_t *server_expected,
+ data_t *exporter_expected)
{
mbedtls_ssl_tls13_application_secrets secrets;
/* Double-check that we've passed sane parameters. */
psa_algorithm_t alg = (psa_algorithm_t) hash_alg;
- size_t const hash_len = PSA_HASH_LENGTH( alg );
- TEST_ASSERT( PSA_ALG_IS_HASH( alg ) &&
- secret->len == hash_len &&
- transcript->len == hash_len &&
- resumption_expected->len == hash_len );
+ size_t const hash_len = PSA_HASH_LENGTH(alg);
+ TEST_ASSERT(PSA_ALG_IS_HASH(alg) &&
+ secret->len == hash_len &&
+ transcript->len == hash_len &&
+ client_expected->len == hash_len &&
+ server_expected->len == hash_len &&
+ exporter_expected->len == hash_len);
- PSA_INIT( );
+ PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_derive_resumption_master_secret(
- alg, secret->x, transcript->x, transcript->len,
- &secrets ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_derive_application_secrets(
+ alg, secret->x, transcript->x, transcript->len,
+ &secrets) == 0);
- ASSERT_COMPARE( secrets.resumption_master_secret, hash_len,
- resumption_expected->x, resumption_expected->len );
+ ASSERT_COMPARE(secrets.client_application_traffic_secret_N, hash_len,
+ client_expected->x, client_expected->len);
+ ASSERT_COMPARE(secrets.server_application_traffic_secret_N, hash_len,
+ server_expected->x, server_expected->len);
+ ASSERT_COMPARE(secrets.exporter_master_secret, hash_len,
+ exporter_expected->x, exporter_expected->len);
- PSA_DONE( );
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_create_psk_binder( int hash_alg,
- data_t *psk,
- int psk_type,
- data_t *transcript,
- data_t *binder_expected )
+void ssl_tls13_derive_resumption_secrets(int hash_alg,
+ data_t *secret,
+ data_t *transcript,
+ data_t *resumption_expected)
{
- unsigned char binder[ MBEDTLS_HASH_MAX_SIZE ];
+ mbedtls_ssl_tls13_application_secrets secrets;
/* Double-check that we've passed sane parameters. */
psa_algorithm_t alg = (psa_algorithm_t) hash_alg;
- size_t const hash_len = PSA_HASH_LENGTH( alg );
- TEST_ASSERT( PSA_ALG_IS_HASH( alg ) &&
- transcript->len == hash_len &&
- binder_expected->len == hash_len );
+ size_t const hash_len = PSA_HASH_LENGTH(alg);
+ TEST_ASSERT(PSA_ALG_IS_HASH(alg) &&
+ secret->len == hash_len &&
+ transcript->len == hash_len &&
+ resumption_expected->len == hash_len);
- PSA_INIT( );
+ PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_create_psk_binder(
- NULL, /* SSL context for debugging only */
- alg,
- psk->x, psk->len,
- psk_type,
- transcript->x,
- binder ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_derive_resumption_master_secret(
+ alg, secret->x, transcript->x, transcript->len,
+ &secrets) == 0);
- ASSERT_COMPARE( binder, hash_len,
- binder_expected->x, binder_expected->len );
+ ASSERT_COMPARE(secrets.resumption_master_secret, hash_len,
+ resumption_expected->x, resumption_expected->len);
- PSA_DONE( );
+ PSA_DONE();
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
+void ssl_tls13_create_psk_binder(int hash_alg,
+ data_t *psk,
+ int psk_type,
+ data_t *transcript,
+ data_t *binder_expected)
+{
+ unsigned char binder[MBEDTLS_HASH_MAX_SIZE];
+
+ /* Double-check that we've passed sane parameters. */
+ psa_algorithm_t alg = (psa_algorithm_t) hash_alg;
+ size_t const hash_len = PSA_HASH_LENGTH(alg);
+ TEST_ASSERT(PSA_ALG_IS_HASH(alg) &&
+ transcript->len == hash_len &&
+ binder_expected->len == hash_len);
+
+ PSA_INIT();
+
+ TEST_ASSERT(mbedtls_ssl_tls13_create_psk_binder(
+ NULL, /* SSL context for debugging only */
+ alg,
+ psk->x, psk->len,
+ psk_type,
+ transcript->x,
+ binder) == 0);
+
+ ASSERT_COMPARE(binder, hash_len,
+ binder_expected->x, binder_expected->len);
+
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void ssl_tls13_record_protection( int ciphersuite,
- int endpoint,
- int ctr,
- int padding_used,
- data_t *server_write_key,
- data_t *server_write_iv,
- data_t *client_write_key,
- data_t *client_write_iv,
- data_t *plaintext,
- data_t *ciphertext )
+void ssl_tls13_record_protection(int ciphersuite,
+ int endpoint,
+ int ctr,
+ int padding_used,
+ data_t *server_write_key,
+ data_t *server_write_iv,
+ data_t *client_write_key,
+ data_t *client_write_iv,
+ data_t *plaintext,
+ data_t *ciphertext)
{
mbedtls_ssl_key_set keys;
mbedtls_ssl_transform transform_send;
@@ -4578,140 +4402,141 @@
size_t buf_len;
int other_endpoint;
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- TEST_ASSERT( endpoint == MBEDTLS_SSL_IS_CLIENT ||
- endpoint == MBEDTLS_SSL_IS_SERVER );
+ TEST_ASSERT(endpoint == MBEDTLS_SSL_IS_CLIENT ||
+ endpoint == MBEDTLS_SSL_IS_SERVER);
- if( endpoint == MBEDTLS_SSL_IS_SERVER )
+ if (endpoint == MBEDTLS_SSL_IS_SERVER) {
other_endpoint = MBEDTLS_SSL_IS_CLIENT;
- if( endpoint == MBEDTLS_SSL_IS_CLIENT )
+ }
+ if (endpoint == MBEDTLS_SSL_IS_CLIENT) {
other_endpoint = MBEDTLS_SSL_IS_SERVER;
+ }
- TEST_ASSERT( server_write_key->len == client_write_key->len );
- TEST_ASSERT( server_write_iv->len == client_write_iv->len );
+ TEST_ASSERT(server_write_key->len == client_write_key->len);
+ TEST_ASSERT(server_write_iv->len == client_write_iv->len);
- memcpy( keys.client_write_key,
- client_write_key->x, client_write_key->len );
- memcpy( keys.client_write_iv,
- client_write_iv->x, client_write_iv->len );
- memcpy( keys.server_write_key,
- server_write_key->x, server_write_key->len );
- memcpy( keys.server_write_iv,
- server_write_iv->x, server_write_iv->len );
+ memcpy(keys.client_write_key,
+ client_write_key->x, client_write_key->len);
+ memcpy(keys.client_write_iv,
+ client_write_iv->x, client_write_iv->len);
+ memcpy(keys.server_write_key,
+ server_write_key->x, server_write_key->len);
+ memcpy(keys.server_write_iv,
+ server_write_iv->x, server_write_iv->len);
keys.key_len = server_write_key->len;
keys.iv_len = server_write_iv->len;
- mbedtls_ssl_transform_init( &transform_recv );
- mbedtls_ssl_transform_init( &transform_send );
+ mbedtls_ssl_transform_init(&transform_recv);
+ mbedtls_ssl_transform_init(&transform_send);
- TEST_ASSERT( mbedtls_ssl_tls13_populate_transform(
- &transform_send, endpoint,
- ciphersuite, &keys, NULL ) == 0 );
- TEST_ASSERT( mbedtls_ssl_tls13_populate_transform(
- &transform_recv, other_endpoint,
- ciphersuite, &keys, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_populate_transform(
+ &transform_send, endpoint,
+ ciphersuite, &keys, NULL) == 0);
+ TEST_ASSERT(mbedtls_ssl_tls13_populate_transform(
+ &transform_recv, other_endpoint,
+ ciphersuite, &keys, NULL) == 0);
/* Make sure we have enough space in the buffer even if
* we use more padding than the KAT. */
buf_len = ciphertext->len + MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY;
- ASSERT_ALLOC( buf, buf_len );
+ ASSERT_ALLOC(buf, buf_len);
rec.type = MBEDTLS_SSL_MSG_APPLICATION_DATA;
/* TLS 1.3 uses the version identifier from TLS 1.2 on the wire. */
- mbedtls_ssl_write_version( rec.ver,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_VERSION_TLS1_2 );
+ mbedtls_ssl_write_version(rec.ver,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_VERSION_TLS1_2);
/* Copy plaintext into record structure */
rec.buf = buf;
rec.buf_len = buf_len;
rec.data_offset = 0;
- TEST_ASSERT( plaintext->len <= ciphertext->len );
- memcpy( rec.buf + rec.data_offset, plaintext->x, plaintext->len );
+ TEST_ASSERT(plaintext->len <= ciphertext->len);
+ memcpy(rec.buf + rec.data_offset, plaintext->x, plaintext->len);
rec.data_len = plaintext->len;
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
rec.cid_len = 0;
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- memset( &rec.ctr[0], 0, 8 );
+ memset(&rec.ctr[0], 0, 8);
rec.ctr[7] = ctr;
- TEST_ASSERT( mbedtls_ssl_encrypt_buf( NULL, &transform_send, &rec,
- NULL, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_encrypt_buf(NULL, &transform_send, &rec,
+ NULL, NULL) == 0);
- if( padding_used == MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY )
- {
- ASSERT_COMPARE( rec.buf + rec.data_offset, rec.data_len,
- ciphertext->x, ciphertext->len );
+ if (padding_used == MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY) {
+ ASSERT_COMPARE(rec.buf + rec.data_offset, rec.data_len,
+ ciphertext->x, ciphertext->len);
}
- TEST_ASSERT( mbedtls_ssl_decrypt_buf( NULL, &transform_recv, &rec ) == 0 );
- ASSERT_COMPARE( rec.buf + rec.data_offset, rec.data_len,
- plaintext->x, plaintext->len );
+ TEST_ASSERT(mbedtls_ssl_decrypt_buf(NULL, &transform_recv, &rec) == 0);
+ ASSERT_COMPARE(rec.buf + rec.data_offset, rec.data_len,
+ plaintext->x, plaintext->len);
- mbedtls_free( buf );
- mbedtls_ssl_transform_free( &transform_send );
- mbedtls_ssl_transform_free( &transform_recv );
- USE_PSA_DONE( );
+ mbedtls_free(buf);
+ mbedtls_ssl_transform_free(&transform_send);
+ mbedtls_ssl_transform_free(&transform_recv);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
-void ssl_tls13_key_evolution( int hash_alg,
- data_t *secret,
- data_t *input,
- data_t *expected )
+void ssl_tls13_key_evolution(int hash_alg,
+ data_t *secret,
+ data_t *input,
+ data_t *expected)
{
- unsigned char secret_new[ MBEDTLS_HASH_MAX_SIZE ];
+ unsigned char secret_new[MBEDTLS_HASH_MAX_SIZE];
PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls13_evolve_secret(
- (psa_algorithm_t) hash_alg,
- secret->len ? secret->x : NULL,
- input->len ? input->x : NULL, input->len,
- secret_new ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_tls13_evolve_secret(
+ (psa_algorithm_t) hash_alg,
+ secret->len ? secret->x : NULL,
+ input->len ? input->x : NULL, input->len,
+ secret_new) == 0);
- ASSERT_COMPARE( secret_new, (size_t) expected->len,
- expected->x, (size_t) expected->len );
+ ASSERT_COMPARE(secret_new, (size_t) expected->len,
+ expected->x, (size_t) expected->len);
PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_2 */
-void ssl_tls_prf( int type, data_t * secret, data_t * random,
- char *label, data_t *result_str, int exp_ret )
+void ssl_tls_prf(int type, data_t *secret, data_t *random,
+ char *label, data_t *result_str, int exp_ret)
{
unsigned char *output;
- output = mbedtls_calloc( 1, result_str->len );
- if( output == NULL )
+ output = mbedtls_calloc(1, result_str->len);
+ if (output == NULL) {
goto exit;
+ }
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- TEST_ASSERT( mbedtls_ssl_tls_prf( type, secret->x, secret->len,
- label, random->x, random->len,
- output, result_str->len ) == exp_ret );
+ TEST_ASSERT(mbedtls_ssl_tls_prf(type, secret->x, secret->len,
+ label, random->x, random->len,
+ output, result_str->len) == exp_ret);
- if( exp_ret == 0 )
- {
- TEST_ASSERT( mbedtls_test_hexcmp( output, result_str->x,
- result_str->len, result_str->len ) == 0 );
+ if (exp_ret == 0) {
+ TEST_ASSERT(mbedtls_test_hexcmp(output, result_str->x,
+ result_str->len, result_str->len) == 0);
}
exit:
- mbedtls_free( output );
- USE_PSA_DONE( );
+ mbedtls_free(output);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_serialize_session_save_load( int ticket_len, char *crt_file,
- int endpoint_type, int tls_version )
+void ssl_serialize_session_save_load(int ticket_len, char *crt_file,
+ int endpoint_type, int tls_version)
{
mbedtls_ssl_session original, restored;
unsigned char *buf = NULL;
@@ -4721,139 +4546,128 @@
* Test that a save-load pair is the identity
*/
- mbedtls_ssl_session_init( &original );
- mbedtls_ssl_session_init( &restored );
+ mbedtls_ssl_session_init(&original);
+ mbedtls_ssl_session_init(&restored);
/* Prepare a dummy session to work on */
((void) endpoint_type);
((void) tls_version);
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if( tls_version == MBEDTLS_SSL_VERSION_TLS1_3 )
- {
- TEST_ASSERT( ssl_tls13_populate_session(
- &original, 0, endpoint_type ) == 0 );
- }
- else
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
+ TEST_ASSERT(ssl_tls13_populate_session(
+ &original, 0, endpoint_type) == 0);
+ } else
#endif
{
- TEST_ASSERT( ssl_tls12_populate_session(
- &original, ticket_len, crt_file ) == 0 );
+ TEST_ASSERT(ssl_tls12_populate_session(
+ &original, ticket_len, crt_file) == 0);
}
/* Serialize it */
- TEST_ASSERT( mbedtls_ssl_session_save( &original, NULL, 0, &len )
- == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
- TEST_ASSERT( ( buf = mbedtls_calloc( 1, len ) ) != NULL );
- TEST_ASSERT( mbedtls_ssl_session_save( &original, buf, len, &len )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_session_save(&original, NULL, 0, &len)
+ == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
+ TEST_ASSERT((buf = mbedtls_calloc(1, len)) != NULL);
+ TEST_ASSERT(mbedtls_ssl_session_save(&original, buf, len, &len)
+ == 0);
/* Restore session from serialized data */
- TEST_ASSERT( mbedtls_ssl_session_load( &restored, buf, len) == 0 );
+ TEST_ASSERT(mbedtls_ssl_session_load(&restored, buf, len) == 0);
/*
* Make sure both session structures are identical
*/
#if defined(MBEDTLS_HAVE_TIME)
- TEST_ASSERT( original.start == restored.start );
+ TEST_ASSERT(original.start == restored.start);
#endif
- TEST_ASSERT( original.tls_version == restored.tls_version );
- TEST_ASSERT( original.ciphersuite == restored.ciphersuite );
+ TEST_ASSERT(original.tls_version == restored.tls_version);
+ TEST_ASSERT(original.ciphersuite == restored.ciphersuite);
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( tls_version == MBEDTLS_SSL_VERSION_TLS1_2 )
- {
- TEST_ASSERT( original.id_len == restored.id_len );
- TEST_ASSERT( memcmp( original.id,
- restored.id, sizeof( original.id ) ) == 0 );
- TEST_ASSERT( memcmp( original.master,
- restored.master, sizeof( original.master ) ) == 0 );
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_2) {
+ TEST_ASSERT(original.id_len == restored.id_len);
+ TEST_ASSERT(memcmp(original.id,
+ restored.id, sizeof(original.id)) == 0);
+ TEST_ASSERT(memcmp(original.master,
+ restored.master, sizeof(original.master)) == 0);
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
- TEST_ASSERT( ( original.peer_cert == NULL ) ==
- ( restored.peer_cert == NULL ) );
- if( original.peer_cert != NULL )
- {
- TEST_ASSERT( original.peer_cert->raw.len ==
- restored.peer_cert->raw.len );
- TEST_ASSERT( memcmp( original.peer_cert->raw.p,
- restored.peer_cert->raw.p,
- original.peer_cert->raw.len ) == 0 );
+ TEST_ASSERT((original.peer_cert == NULL) ==
+ (restored.peer_cert == NULL));
+ if (original.peer_cert != NULL) {
+ TEST_ASSERT(original.peer_cert->raw.len ==
+ restored.peer_cert->raw.len);
+ TEST_ASSERT(memcmp(original.peer_cert->raw.p,
+ restored.peer_cert->raw.p,
+ original.peer_cert->raw.len) == 0);
}
#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
- TEST_ASSERT( original.peer_cert_digest_type ==
- restored.peer_cert_digest_type );
- TEST_ASSERT( original.peer_cert_digest_len ==
- restored.peer_cert_digest_len );
- TEST_ASSERT( ( original.peer_cert_digest == NULL ) ==
- ( restored.peer_cert_digest == NULL ) );
- if( original.peer_cert_digest != NULL )
- {
- TEST_ASSERT( memcmp( original.peer_cert_digest,
- restored.peer_cert_digest,
- original.peer_cert_digest_len ) == 0 );
+ TEST_ASSERT(original.peer_cert_digest_type ==
+ restored.peer_cert_digest_type);
+ TEST_ASSERT(original.peer_cert_digest_len ==
+ restored.peer_cert_digest_len);
+ TEST_ASSERT((original.peer_cert_digest == NULL) ==
+ (restored.peer_cert_digest == NULL));
+ if (original.peer_cert_digest != NULL) {
+ TEST_ASSERT(memcmp(original.peer_cert_digest,
+ restored.peer_cert_digest,
+ original.peer_cert_digest_len) == 0);
}
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
- TEST_ASSERT( original.verify_result == restored.verify_result );
+ TEST_ASSERT(original.verify_result == restored.verify_result);
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- TEST_ASSERT( original.mfl_code == restored.mfl_code );
+ TEST_ASSERT(original.mfl_code == restored.mfl_code);
#endif
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
- TEST_ASSERT( original.encrypt_then_mac == restored.encrypt_then_mac );
+ TEST_ASSERT(original.encrypt_then_mac == restored.encrypt_then_mac);
#endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
- TEST_ASSERT( original.ticket_len == restored.ticket_len );
- if( original.ticket_len != 0 )
- {
- TEST_ASSERT( original.ticket != NULL );
- TEST_ASSERT( restored.ticket != NULL );
- TEST_ASSERT( memcmp( original.ticket,
- restored.ticket, original.ticket_len ) == 0 );
+ TEST_ASSERT(original.ticket_len == restored.ticket_len);
+ if (original.ticket_len != 0) {
+ TEST_ASSERT(original.ticket != NULL);
+ TEST_ASSERT(restored.ticket != NULL);
+ TEST_ASSERT(memcmp(original.ticket,
+ restored.ticket, original.ticket_len) == 0);
}
- TEST_ASSERT( original.ticket_lifetime == restored.ticket_lifetime );
+ TEST_ASSERT(original.ticket_lifetime == restored.ticket_lifetime);
#endif
}
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if( tls_version == MBEDTLS_SSL_VERSION_TLS1_3 )
- {
- TEST_ASSERT( original.endpoint == restored.endpoint );
- TEST_ASSERT( original.ciphersuite == restored.ciphersuite );
- TEST_ASSERT( original.ticket_age_add == restored.ticket_age_add );
- TEST_ASSERT( original.ticket_flags == restored.ticket_flags );
- TEST_ASSERT( original.resumption_key_len == restored.resumption_key_len );
- if( original.resumption_key_len != 0 )
- {
- TEST_ASSERT( original.resumption_key != NULL );
- TEST_ASSERT( restored.resumption_key != NULL );
- TEST_ASSERT( memcmp( original.resumption_key,
- restored.resumption_key,
- original.resumption_key_len ) == 0 );
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
+ TEST_ASSERT(original.endpoint == restored.endpoint);
+ TEST_ASSERT(original.ciphersuite == restored.ciphersuite);
+ TEST_ASSERT(original.ticket_age_add == restored.ticket_age_add);
+ TEST_ASSERT(original.ticket_flags == restored.ticket_flags);
+ TEST_ASSERT(original.resumption_key_len == restored.resumption_key_len);
+ if (original.resumption_key_len != 0) {
+ TEST_ASSERT(original.resumption_key != NULL);
+ TEST_ASSERT(restored.resumption_key != NULL);
+ TEST_ASSERT(memcmp(original.resumption_key,
+ restored.resumption_key,
+ original.resumption_key_len) == 0);
}
#if defined(MBEDTLS_HAVE_TIME) && defined(MBEDTLS_SSL_SRV_C)
- if( endpoint_type == MBEDTLS_SSL_IS_SERVER )
- {
- TEST_ASSERT( original.start == restored.start );
+ if (endpoint_type == MBEDTLS_SSL_IS_SERVER) {
+ TEST_ASSERT(original.start == restored.start);
}
#endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
- if( endpoint_type == MBEDTLS_SSL_IS_CLIENT)
- {
+ if (endpoint_type == MBEDTLS_SSL_IS_CLIENT) {
#if defined(MBEDTLS_HAVE_TIME)
- TEST_ASSERT( original.ticket_received == restored.ticket_received );
+ TEST_ASSERT(original.ticket_received == restored.ticket_received);
#endif
- TEST_ASSERT( original.ticket_lifetime == restored.ticket_lifetime );
- TEST_ASSERT( original.ticket_len == restored.ticket_len );
- if( original.ticket_len != 0 )
- {
- TEST_ASSERT( original.ticket != NULL );
- TEST_ASSERT( restored.ticket != NULL );
- TEST_ASSERT( memcmp( original.ticket,
- restored.ticket,
- original.ticket_len ) == 0 );
+ TEST_ASSERT(original.ticket_lifetime == restored.ticket_lifetime);
+ TEST_ASSERT(original.ticket_len == restored.ticket_len);
+ if (original.ticket_len != 0) {
+ TEST_ASSERT(original.ticket != NULL);
+ TEST_ASSERT(restored.ticket != NULL);
+ TEST_ASSERT(memcmp(original.ticket,
+ restored.ticket,
+ original.ticket_len) == 0);
}
}
@@ -4862,15 +4676,15 @@
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
exit:
- mbedtls_ssl_session_free( &original );
- mbedtls_ssl_session_free( &restored );
- mbedtls_free( buf );
+ mbedtls_ssl_session_free(&original);
+ mbedtls_ssl_session_free(&restored);
+ mbedtls_free(buf);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_serialize_session_load_save( int ticket_len, char *crt_file,
- int endpoint_type, int tls_version )
+void ssl_serialize_session_load_save(int ticket_len, char *crt_file,
+ int endpoint_type, int tls_version)
{
mbedtls_ssl_session session;
unsigned char *buf1 = NULL, *buf2 = NULL;
@@ -4880,61 +4694,59 @@
* Test that a load-save pair is the identity
*/
- mbedtls_ssl_session_init( &session );
+ mbedtls_ssl_session_init(&session);
/* Prepare a dummy session to work on */
((void) endpoint_type);
((void) tls_version);
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if(tls_version == MBEDTLS_SSL_VERSION_TLS1_3)
- {
- TEST_ASSERT( ssl_tls13_populate_session(
- &session, 0, endpoint_type ) == 0 );
- }
- else
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
+ TEST_ASSERT(ssl_tls13_populate_session(
+ &session, 0, endpoint_type) == 0);
+ } else
#endif
{
- TEST_ASSERT( ssl_tls12_populate_session(
- &session, ticket_len, crt_file ) == 0 );
+ TEST_ASSERT(ssl_tls12_populate_session(
+ &session, ticket_len, crt_file) == 0);
}
/* Get desired buffer size for serializing */
- TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &len0 )
- == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
+ TEST_ASSERT(mbedtls_ssl_session_save(&session, NULL, 0, &len0)
+ == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
/* Allocate first buffer */
- buf1 = mbedtls_calloc( 1, len0 );
- TEST_ASSERT( buf1 != NULL );
+ buf1 = mbedtls_calloc(1, len0);
+ TEST_ASSERT(buf1 != NULL);
/* Serialize to buffer and free live session */
- TEST_ASSERT( mbedtls_ssl_session_save( &session, buf1, len0, &len1 )
- == 0 );
- TEST_ASSERT( len0 == len1 );
- mbedtls_ssl_session_free( &session );
+ TEST_ASSERT(mbedtls_ssl_session_save(&session, buf1, len0, &len1)
+ == 0);
+ TEST_ASSERT(len0 == len1);
+ mbedtls_ssl_session_free(&session);
/* Restore session from serialized data */
- TEST_ASSERT( mbedtls_ssl_session_load( &session, buf1, len1 ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_session_load(&session, buf1, len1) == 0);
/* Allocate second buffer and serialize to it */
- buf2 = mbedtls_calloc( 1, len0 );
- TEST_ASSERT( buf2 != NULL );
- TEST_ASSERT( mbedtls_ssl_session_save( &session, buf2, len0, &len2 )
- == 0 );
+ buf2 = mbedtls_calloc(1, len0);
+ TEST_ASSERT(buf2 != NULL);
+ TEST_ASSERT(mbedtls_ssl_session_save(&session, buf2, len0, &len2)
+ == 0);
/* Make sure both serialized versions are identical */
- TEST_ASSERT( len1 == len2 );
- TEST_ASSERT( memcmp( buf1, buf2, len1 ) == 0 );
+ TEST_ASSERT(len1 == len2);
+ TEST_ASSERT(memcmp(buf1, buf2, len1) == 0);
exit:
- mbedtls_ssl_session_free( &session );
- mbedtls_free( buf1 );
- mbedtls_free( buf2 );
+ mbedtls_ssl_session_free(&session);
+ mbedtls_free(buf1);
+ mbedtls_free(buf2);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_serialize_session_save_buf_size( int ticket_len, char *crt_file,
- int endpoint_type, int tls_version )
+void ssl_serialize_session_save_buf_size(int ticket_len, char *crt_file,
+ int endpoint_type, int tls_version)
{
mbedtls_ssl_session session;
unsigned char *buf = NULL;
@@ -4944,47 +4756,44 @@
* Test that session_save() fails cleanly on small buffers
*/
- mbedtls_ssl_session_init( &session );
+ mbedtls_ssl_session_init(&session);
/* Prepare dummy session and get serialized size */
((void) endpoint_type);
((void) tls_version);
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if(tls_version == MBEDTLS_SSL_VERSION_TLS1_3)
- {
- TEST_ASSERT( ssl_tls13_populate_session(
- &session, 0, endpoint_type ) == 0 );
- }
- else
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
+ TEST_ASSERT(ssl_tls13_populate_session(
+ &session, 0, endpoint_type) == 0);
+ } else
#endif
{
- TEST_ASSERT( ssl_tls12_populate_session(
- &session, ticket_len, crt_file ) == 0 );
+ TEST_ASSERT(ssl_tls12_populate_session(
+ &session, ticket_len, crt_file) == 0);
}
- TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &good_len )
- == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
+ TEST_ASSERT(mbedtls_ssl_session_save(&session, NULL, 0, &good_len)
+ == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
/* Try all possible bad lengths */
- for( bad_len = 1; bad_len < good_len; bad_len++ )
- {
+ for (bad_len = 1; bad_len < good_len; bad_len++) {
/* Allocate exact size so that asan/valgrind can detect any overwrite */
- mbedtls_free( buf );
- TEST_ASSERT( ( buf = mbedtls_calloc( 1, bad_len ) ) != NULL );
- TEST_ASSERT( mbedtls_ssl_session_save( &session, buf, bad_len,
- &test_len )
- == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
- TEST_ASSERT( test_len == good_len );
+ mbedtls_free(buf);
+ TEST_ASSERT((buf = mbedtls_calloc(1, bad_len)) != NULL);
+ TEST_ASSERT(mbedtls_ssl_session_save(&session, buf, bad_len,
+ &test_len)
+ == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
+ TEST_ASSERT(test_len == good_len);
}
exit:
- mbedtls_ssl_session_free( &session );
- mbedtls_free( buf );
+ mbedtls_ssl_session_free(&session);
+ mbedtls_free(buf);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_serialize_session_load_buf_size( int ticket_len, char *crt_file,
- int endpoint_type, int tls_version )
+void ssl_serialize_session_load_buf_size(int ticket_len, char *crt_file,
+ int endpoint_type, int tls_version)
{
mbedtls_ssl_session session;
unsigned char *good_buf = NULL, *bad_buf = NULL;
@@ -4994,59 +4803,56 @@
* Test that session_load() fails cleanly on small buffers
*/
- mbedtls_ssl_session_init( &session );
+ mbedtls_ssl_session_init(&session);
/* Prepare serialized session data */
((void) endpoint_type);
((void) tls_version);
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if(tls_version == MBEDTLS_SSL_VERSION_TLS1_3)
- {
- TEST_ASSERT( ssl_tls13_populate_session(
- &session, 0, endpoint_type ) == 0 );
- }
- else
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
+ TEST_ASSERT(ssl_tls13_populate_session(
+ &session, 0, endpoint_type) == 0);
+ } else
#endif
{
- TEST_ASSERT( ssl_tls12_populate_session(
- &session, ticket_len, crt_file ) == 0 );
+ TEST_ASSERT(ssl_tls12_populate_session(
+ &session, ticket_len, crt_file) == 0);
}
- TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &good_len )
- == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
- TEST_ASSERT( ( good_buf = mbedtls_calloc( 1, good_len ) ) != NULL );
- TEST_ASSERT( mbedtls_ssl_session_save( &session, good_buf, good_len,
- &good_len ) == 0 );
- mbedtls_ssl_session_free( &session );
+ TEST_ASSERT(mbedtls_ssl_session_save(&session, NULL, 0, &good_len)
+ == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL);
+ TEST_ASSERT((good_buf = mbedtls_calloc(1, good_len)) != NULL);
+ TEST_ASSERT(mbedtls_ssl_session_save(&session, good_buf, good_len,
+ &good_len) == 0);
+ mbedtls_ssl_session_free(&session);
/* Try all possible bad lengths */
- for( bad_len = 0; bad_len < good_len; bad_len++ )
- {
+ for (bad_len = 0; bad_len < good_len; bad_len++) {
/* Allocate exact size so that asan/valgrind can detect any overread */
- mbedtls_free( bad_buf );
- bad_buf = mbedtls_calloc( 1, bad_len ? bad_len : 1 );
- TEST_ASSERT( bad_buf != NULL );
- memcpy( bad_buf, good_buf, bad_len );
+ mbedtls_free(bad_buf);
+ bad_buf = mbedtls_calloc(1, bad_len ? bad_len : 1);
+ TEST_ASSERT(bad_buf != NULL);
+ memcpy(bad_buf, good_buf, bad_len);
- TEST_ASSERT( mbedtls_ssl_session_load( &session, bad_buf, bad_len )
- == MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_ssl_session_load(&session, bad_buf, bad_len)
+ == MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
}
exit:
- mbedtls_ssl_session_free( &session );
- mbedtls_free( good_buf );
- mbedtls_free( bad_buf );
+ mbedtls_ssl_session_free(&session);
+ mbedtls_free(good_buf);
+ mbedtls_free(bad_buf);
}
/* END_CASE */
/* BEGIN_CASE */
-void ssl_session_serialize_version_check( int corrupt_major,
- int corrupt_minor,
- int corrupt_patch,
- int corrupt_config,
- int endpoint_type,
- int tls_version )
+void ssl_session_serialize_version_check(int corrupt_major,
+ int corrupt_minor,
+ int corrupt_patch,
+ int corrupt_config,
+ int endpoint_type,
+ int tls_version)
{
- unsigned char serialized_session[ 2048 ];
+ unsigned char serialized_session[2048];
size_t serialized_session_len;
unsigned cur_byte;
mbedtls_ssl_session session;
@@ -5056,56 +4862,53 @@
corrupt_config == 1,
corrupt_config == 1 };
- mbedtls_ssl_session_init( &session );
+ mbedtls_ssl_session_init(&session);
((void) endpoint_type);
((void) tls_version);
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
- if(tls_version == MBEDTLS_SSL_VERSION_TLS1_3)
- {
- TEST_ASSERT( ssl_tls13_populate_session(
- &session, 0, endpoint_type ) == 0 );
- }
- else
+ if (tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
+ TEST_ASSERT(ssl_tls13_populate_session(
+ &session, 0, endpoint_type) == 0);
+ } else
#endif
- TEST_ASSERT( ssl_tls12_populate_session( &session, 0, NULL ) == 0 );
+ TEST_ASSERT(ssl_tls12_populate_session(&session, 0, NULL) == 0);
/* Infer length of serialized session. */
- TEST_ASSERT( mbedtls_ssl_session_save( &session,
- serialized_session,
- sizeof( serialized_session ),
- &serialized_session_len ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_session_save(&session,
+ serialized_session,
+ sizeof(serialized_session),
+ &serialized_session_len) == 0);
- mbedtls_ssl_session_free( &session );
+ mbedtls_ssl_session_free(&session);
/* Without any modification, we should be able to successfully
* de-serialize the session - double-check that. */
- TEST_ASSERT( mbedtls_ssl_session_load( &session,
- serialized_session,
- serialized_session_len ) == 0 );
- mbedtls_ssl_session_free( &session );
+ TEST_ASSERT(mbedtls_ssl_session_load(&session,
+ serialized_session,
+ serialized_session_len) == 0);
+ mbedtls_ssl_session_free(&session);
/* Go through the bytes in the serialized session header and
* corrupt them bit-by-bit. */
- for( cur_byte = 0; cur_byte < sizeof( should_corrupt_byte ); cur_byte++ )
- {
+ for (cur_byte = 0; cur_byte < sizeof(should_corrupt_byte); cur_byte++) {
int cur_bit;
- unsigned char * const byte = &serialized_session[ cur_byte ];
+ unsigned char * const byte = &serialized_session[cur_byte];
- if( should_corrupt_byte[ cur_byte ] == 0 )
+ if (should_corrupt_byte[cur_byte] == 0) {
continue;
+ }
- for( cur_bit = 0; cur_bit < CHAR_BIT; cur_bit++ )
- {
+ for (cur_bit = 0; cur_bit < CHAR_BIT; cur_bit++) {
unsigned char const corrupted_bit = 0x1u << cur_bit;
/* Modify a single bit in the serialized session. */
*byte ^= corrupted_bit;
/* Attempt to deserialize */
- TEST_ASSERT( mbedtls_ssl_session_load( &session,
- serialized_session,
- serialized_session_len ) ==
- MBEDTLS_ERR_SSL_VERSION_MISMATCH );
+ TEST_ASSERT(mbedtls_ssl_session_load(&session,
+ serialized_session,
+ serialized_session_len) ==
+ MBEDTLS_ERR_SSL_VERSION_MISMATCH);
/* Undo the change */
*byte ^= corrupted_bit;
@@ -5116,29 +4919,29 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void mbedtls_endpoint_sanity( int endpoint_type )
+void mbedtls_endpoint_sanity(int endpoint_type)
{
enum { BUFFSIZE = 1024 };
mbedtls_endpoint ep;
int ret = -1;
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.pk_alg = MBEDTLS_PK_RSA;
- ret = mbedtls_endpoint_init( NULL, endpoint_type, &options,
- NULL, NULL, NULL, NULL );
- TEST_ASSERT( MBEDTLS_ERR_SSL_BAD_INPUT_DATA == ret );
+ ret = mbedtls_endpoint_init(NULL, endpoint_type, &options,
+ NULL, NULL, NULL, NULL);
+ TEST_ASSERT(MBEDTLS_ERR_SSL_BAD_INPUT_DATA == ret);
- ret = mbedtls_endpoint_certificate_init( NULL, options.pk_alg, 0, 0, 0 );
- TEST_ASSERT( MBEDTLS_ERR_SSL_BAD_INPUT_DATA == ret );
+ ret = mbedtls_endpoint_certificate_init(NULL, options.pk_alg, 0, 0, 0);
+ TEST_ASSERT(MBEDTLS_ERR_SSL_BAD_INPUT_DATA == ret);
- ret = mbedtls_endpoint_init( &ep, endpoint_type, &options,
- NULL, NULL, NULL, NULL );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_endpoint_init(&ep, endpoint_type, &options,
+ NULL, NULL, NULL, NULL);
+ TEST_ASSERT(ret == 0);
exit:
- mbedtls_endpoint_free( &ep, NULL );
- free_handshake_options( &options );
+ mbedtls_endpoint_free(&ep, NULL);
+ free_handshake_options(&options);
}
/* END_CASE */
@@ -5149,62 +4952,59 @@
mbedtls_endpoint base_ep, second_ep;
int ret = -1;
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.pk_alg = MBEDTLS_PK_RSA;
- USE_PSA_INIT( );
- mbedtls_platform_zeroize( &base_ep, sizeof(base_ep) );
- mbedtls_platform_zeroize( &second_ep, sizeof(second_ep) );
+ USE_PSA_INIT();
+ mbedtls_platform_zeroize(&base_ep, sizeof(base_ep));
+ mbedtls_platform_zeroize(&second_ep, sizeof(second_ep));
- ret = mbedtls_endpoint_init( &base_ep, endpoint_type, &options,
- NULL, NULL, NULL, NULL );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_endpoint_init(&base_ep, endpoint_type, &options,
+ NULL, NULL, NULL, NULL);
+ TEST_ASSERT(ret == 0);
- ret = mbedtls_endpoint_init( &second_ep,
- ( endpoint_type == MBEDTLS_SSL_IS_SERVER ) ?
- MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
- &options, NULL, NULL, NULL, NULL );
+ ret = mbedtls_endpoint_init(&second_ep,
+ (endpoint_type == MBEDTLS_SSL_IS_SERVER) ?
+ MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
+ &options, NULL, NULL, NULL, NULL);
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(ret == 0);
- ret = mbedtls_mock_socket_connect( &(base_ep.socket),
- &(second_ep.socket),
- BUFFSIZE );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_mock_socket_connect(&(base_ep.socket),
+ &(second_ep.socket),
+ BUFFSIZE);
+ TEST_ASSERT(ret == 0);
- ret = mbedtls_move_handshake_to_state( &(base_ep.ssl),
- &(second_ep.ssl),
- state );
- if( need_pass )
- {
- TEST_ASSERT( ret == 0 ||
- ret == MBEDTLS_ERR_SSL_WANT_READ ||
- ret == MBEDTLS_ERR_SSL_WANT_WRITE );
- TEST_ASSERT( base_ep.ssl.state == state );
- }
- else
- {
- TEST_ASSERT( ret != 0 &&
- ret != MBEDTLS_ERR_SSL_WANT_READ &&
- ret != MBEDTLS_ERR_SSL_WANT_WRITE );
- TEST_ASSERT( base_ep.ssl.state != state );
+ ret = mbedtls_move_handshake_to_state(&(base_ep.ssl),
+ &(second_ep.ssl),
+ state);
+ if (need_pass) {
+ TEST_ASSERT(ret == 0 ||
+ ret == MBEDTLS_ERR_SSL_WANT_READ ||
+ ret == MBEDTLS_ERR_SSL_WANT_WRITE);
+ TEST_ASSERT(base_ep.ssl.state == state);
+ } else {
+ TEST_ASSERT(ret != 0 &&
+ ret != MBEDTLS_ERR_SSL_WANT_READ &&
+ ret != MBEDTLS_ERR_SSL_WANT_WRITE);
+ TEST_ASSERT(base_ep.ssl.state != state);
}
exit:
- free_handshake_options( &options );
- mbedtls_endpoint_free( &base_ep, NULL );
- mbedtls_endpoint_free( &second_ep, NULL );
- USE_PSA_DONE( );
+ free_handshake_options(&options);
+ mbedtls_endpoint_free(&base_ep, NULL);
+ mbedtls_endpoint_free(&second_ep, NULL);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA:MBEDTLS_ECP_C */
-void handshake_version( int dtls, int client_min_version, int client_max_version,
- int server_min_version, int server_max_version,
- int expected_negotiated_version )
+void handshake_version(int dtls, int client_min_version, int client_max_version,
+ int server_min_version, int server_max_version,
+ int expected_negotiated_version)
{
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.client_min_version = client_min_version;
options.client_max_version = client_max_version;
@@ -5213,41 +5013,41 @@
options.expected_negotiated_version = expected_negotiated_version;
options.dtls = dtls;
- perform_handshake( &options );
+ perform_handshake(&options);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void handshake_psk_cipher( char* cipher, int pk_alg, data_t *psk_str, int dtls )
+void handshake_psk_cipher(char *cipher, int pk_alg, data_t *psk_str, int dtls)
{
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.cipher = cipher;
options.dtls = dtls;
options.psk_str = psk_str;
options.pk_alg = pk_alg;
- perform_handshake( &options );
+ perform_handshake(&options);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void handshake_cipher( char* cipher, int pk_alg, int dtls )
+void handshake_cipher(char *cipher, int pk_alg, int dtls)
{
- test_handshake_psk_cipher( cipher, pk_alg, NULL, dtls );
+ test_handshake_psk_cipher(cipher, pk_alg, NULL, dtls);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
@@ -5255,13 +5055,13 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void handshake_ciphersuite_select( char* cipher, int pk_alg, data_t *psk_str,
- int psa_alg, int psa_alg2, int psa_usage,
- int expected_handshake_result,
- int expected_ciphersuite )
+void handshake_ciphersuite_select(char *cipher, int pk_alg, data_t *psk_str,
+ int psa_alg, int psa_alg2, int psa_usage,
+ int expected_handshake_result,
+ int expected_ciphersuite)
{
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.cipher = cipher;
options.psk_str = psk_str;
@@ -5271,23 +5071,23 @@
options.opaque_usage = psa_usage;
options.expected_handshake_result = expected_handshake_result;
options.expected_ciphersuite = expected_ciphersuite;
- perform_handshake( &options );
+ perform_handshake(&options);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void app_data( int mfl, int cli_msg_len, int srv_msg_len,
- int expected_cli_fragments,
- int expected_srv_fragments, int dtls )
+void app_data(int mfl, int cli_msg_len, int srv_msg_len,
+ int expected_cli_fragments,
+ int expected_srv_fragments, int dtls)
{
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.mfl = mfl;
options.cli_msg_len = cli_msg_len;
@@ -5295,62 +5095,64 @@
options.expected_cli_fragments = expected_cli_fragments;
options.expected_srv_fragments = expected_srv_fragments;
options.dtls = dtls;
-#if ! defined(MBEDTLS_SSL_PROTO_TLS1_2)
+#if !defined(MBEDTLS_SSL_PROTO_TLS1_2)
options.expected_negotiated_version = MBEDTLS_SSL_VERSION_TLS1_3;
#endif
- perform_handshake( &options );
+ perform_handshake(&options);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA:MBEDTLS_ECP_C */
-void app_data_tls( int mfl, int cli_msg_len, int srv_msg_len,
- int expected_cli_fragments,
- int expected_srv_fragments )
+void app_data_tls(int mfl, int cli_msg_len, int srv_msg_len,
+ int expected_cli_fragments,
+ int expected_srv_fragments)
{
- test_app_data( mfl, cli_msg_len, srv_msg_len, expected_cli_fragments,
- expected_srv_fragments, 0 );
+ test_app_data(mfl, cli_msg_len, srv_msg_len, expected_cli_fragments,
+ expected_srv_fragments, 0);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_SSL_PROTO_DTLS:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void app_data_dtls( int mfl, int cli_msg_len, int srv_msg_len,
- int expected_cli_fragments,
- int expected_srv_fragments )
+void app_data_dtls(int mfl, int cli_msg_len, int srv_msg_len,
+ int expected_cli_fragments,
+ int expected_srv_fragments)
{
- test_app_data( mfl, cli_msg_len, srv_msg_len, expected_cli_fragments,
- expected_srv_fragments, 1 );
+ test_app_data(mfl, cli_msg_len, srv_msg_len, expected_cli_fragments,
+ expected_srv_fragments, 1);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_SSL_PROTO_DTLS:MBEDTLS_SSL_RENEGOTIATION:MBEDTLS_SSL_CONTEXT_SERIALIZATION:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void handshake_serialization( )
+void handshake_serialization()
{
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.serialize = 1;
options.dtls = 1;
- perform_handshake( &options );
+ perform_handshake(&options);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_DEBUG_C:MBEDTLS_SSL_MAX_FRAGMENT_LENGTH:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void handshake_fragmentation( int mfl, int expected_srv_hs_fragmentation, int expected_cli_hs_fragmentation)
+void handshake_fragmentation(int mfl,
+ int expected_srv_hs_fragmentation,
+ int expected_cli_hs_fragmentation)
{
handshake_test_options options;
log_pattern srv_pattern, cli_pattern;
@@ -5359,7 +5161,7 @@
srv_pattern.counter = 0;
cli_pattern.counter = 0;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.dtls = 1;
options.mfl = mfl;
/* Set cipher to one using CBC so that record splitting can be tested */
@@ -5370,49 +5172,47 @@
options.srv_log_fun = log_analyzer;
options.cli_log_fun = log_analyzer;
- perform_handshake( &options );
+ perform_handshake(&options);
/* Test if the server received a fragmented handshake */
- if( expected_srv_hs_fragmentation )
- {
- TEST_ASSERT( srv_pattern.counter >= 1 );
+ if (expected_srv_hs_fragmentation) {
+ TEST_ASSERT(srv_pattern.counter >= 1);
}
/* Test if the client received a fragmented handshake */
- if( expected_cli_hs_fragmentation )
- {
- TEST_ASSERT( cli_pattern.counter >= 1 );
+ if (expected_cli_hs_fragmentation) {
+ TEST_ASSERT(cli_pattern.counter >= 1);
}
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_SSL_PROTO_DTLS:MBEDTLS_SSL_RENEGOTIATION:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void renegotiation( int legacy_renegotiation )
+void renegotiation(int legacy_renegotiation)
{
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.renegotiate = 1;
options.legacy_renegotiation = legacy_renegotiation;
options.dtls = 1;
- perform_handshake( &options );
+ perform_handshake(&options);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void resize_buffers( int mfl, int renegotiation, int legacy_renegotiation,
- int serialize, int dtls, char *cipher )
+void resize_buffers(int mfl, int renegotiation, int legacy_renegotiation,
+ int serialize, int dtls, char *cipher)
{
handshake_test_options options;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.mfl = mfl;
options.cipher = cipher;
@@ -5422,20 +5222,20 @@
options.dtls = dtls;
options.resize_buffers = 1;
- perform_handshake( &options );
+ perform_handshake(&options);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
exit:
- free_handshake_options( &options );
+ free_handshake_options(&options);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH:MBEDTLS_SSL_CONTEXT_SERIALIZATION:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_SSL_PROTO_DTLS:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void resize_buffers_serialize_mfl( int mfl )
+void resize_buffers_serialize_mfl(int mfl)
{
- test_resize_buffers( mfl, 0, MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION, 1, 1,
- (char *) "" );
+ test_resize_buffers(mfl, 0, MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION, 1, 1,
+ (char *) "");
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
@@ -5443,10 +5243,10 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH:MBEDTLS_SSL_RENEGOTIATION:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void resize_buffers_renegotiate_mfl( int mfl, int legacy_renegotiation,
- char *cipher )
+void resize_buffers_renegotiate_mfl(int mfl, int legacy_renegotiation,
+ char *cipher)
{
- test_resize_buffers( mfl, 1, legacy_renegotiation, 0, 1, cipher );
+ test_resize_buffers(mfl, 1, legacy_renegotiation, 0, 1, cipher);
/* The goto below is used to avoid an "unused label" warning.*/
goto exit;
@@ -5464,27 +5264,27 @@
mbedtls_ssl_config conf;
- USE_PSA_INIT( );
- mbedtls_ssl_config_init( &conf );
+ USE_PSA_INIT();
+ mbedtls_ssl_config_init(&conf);
- TEST_ASSERT( mbedtls_ssl_conf_psk( &conf,
- psk0, sizeof( psk0 ),
- psk0_identity, sizeof( psk0_identity ) ) == 0 );
- TEST_ASSERT( mbedtls_ssl_conf_psk( &conf,
- psk1, sizeof( psk1 ),
- psk1_identity, sizeof( psk1_identity ) ) ==
- MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
+ TEST_ASSERT(mbedtls_ssl_conf_psk(&conf,
+ psk0, sizeof(psk0),
+ psk0_identity, sizeof(psk0_identity)) == 0);
+ TEST_ASSERT(mbedtls_ssl_conf_psk(&conf,
+ psk1, sizeof(psk1),
+ psk1_identity, sizeof(psk1_identity)) ==
+ MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE);
exit:
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_config_free(&conf);
- USE_PSA_DONE( );
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED:MBEDTLS_USE_PSA_CRYPTO */
-void test_multiple_psks_opaque( int mode )
+void test_multiple_psks_opaque(int mode)
{
/*
* Mode 0: Raw PSK, then opaque PSK
@@ -5495,95 +5295,98 @@
unsigned char psk0_raw[10] = { 0 };
unsigned char psk0_raw_identity[] = { 'f', 'o', 'o' };
- mbedtls_svc_key_id_t psk0_opaque = mbedtls_svc_key_id_make( 0x1, (psa_key_id_t) 1 );
+ mbedtls_svc_key_id_t psk0_opaque = mbedtls_svc_key_id_make(0x1, (psa_key_id_t) 1);
unsigned char psk0_opaque_identity[] = { 'f', 'o', 'o' };
unsigned char psk1_raw[10] = { 0 };
unsigned char psk1_raw_identity[] = { 'b', 'a', 'r' };
- mbedtls_svc_key_id_t psk1_opaque = mbedtls_svc_key_id_make( 0x1, (psa_key_id_t) 2 );
+ mbedtls_svc_key_id_t psk1_opaque = mbedtls_svc_key_id_make(0x1, (psa_key_id_t) 2);
unsigned char psk1_opaque_identity[] = { 'b', 'a', 'r' };
mbedtls_ssl_config conf;
- USE_PSA_INIT( );
- mbedtls_ssl_config_init( &conf );
+ USE_PSA_INIT();
+ mbedtls_ssl_config_init(&conf);
- switch( mode )
- {
+ switch (mode) {
case 0:
- TEST_ASSERT( mbedtls_ssl_conf_psk( &conf,
- psk0_raw, sizeof( psk0_raw ),
- psk0_raw_identity, sizeof( psk0_raw_identity ) )
- == 0 );
- TEST_ASSERT( mbedtls_ssl_conf_psk_opaque( &conf,
- psk1_opaque,
- psk1_opaque_identity, sizeof( psk1_opaque_identity ) )
- == MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
+ TEST_ASSERT(mbedtls_ssl_conf_psk(&conf,
+ psk0_raw, sizeof(psk0_raw),
+ psk0_raw_identity, sizeof(psk0_raw_identity))
+ == 0);
+ TEST_ASSERT(mbedtls_ssl_conf_psk_opaque(&conf,
+ psk1_opaque,
+ psk1_opaque_identity,
+ sizeof(psk1_opaque_identity))
+ == MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE);
break;
case 1:
- TEST_ASSERT( mbedtls_ssl_conf_psk_opaque( &conf,
- psk0_opaque,
- psk0_opaque_identity, sizeof( psk0_opaque_identity ) )
- == 0 );
- TEST_ASSERT( mbedtls_ssl_conf_psk( &conf,
- psk1_raw, sizeof( psk1_raw ),
- psk1_raw_identity, sizeof( psk1_raw_identity ) )
- == MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
+ TEST_ASSERT(mbedtls_ssl_conf_psk_opaque(&conf,
+ psk0_opaque,
+ psk0_opaque_identity,
+ sizeof(psk0_opaque_identity))
+ == 0);
+ TEST_ASSERT(mbedtls_ssl_conf_psk(&conf,
+ psk1_raw, sizeof(psk1_raw),
+ psk1_raw_identity, sizeof(psk1_raw_identity))
+ == MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE);
break;
case 2:
- TEST_ASSERT( mbedtls_ssl_conf_psk_opaque( &conf,
- psk0_opaque,
- psk0_opaque_identity, sizeof( psk0_opaque_identity ) )
- == 0 );
- TEST_ASSERT( mbedtls_ssl_conf_psk_opaque( &conf,
- psk1_opaque,
- psk1_opaque_identity, sizeof( psk1_opaque_identity ) )
- == MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
+ TEST_ASSERT(mbedtls_ssl_conf_psk_opaque(&conf,
+ psk0_opaque,
+ psk0_opaque_identity,
+ sizeof(psk0_opaque_identity))
+ == 0);
+ TEST_ASSERT(mbedtls_ssl_conf_psk_opaque(&conf,
+ psk1_opaque,
+ psk1_opaque_identity,
+ sizeof(psk1_opaque_identity))
+ == MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE);
break;
default:
- TEST_ASSERT( 0 );
+ TEST_ASSERT(0);
break;
}
exit:
- mbedtls_ssl_config_free( &conf );
- USE_PSA_DONE( );
+ mbedtls_ssl_config_free(&conf);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE */
-void conf_version( int endpoint, int transport,
- int min_tls_version, int max_tls_version,
- int expected_ssl_setup_result )
+void conf_version(int endpoint, int transport,
+ int min_tls_version, int max_tls_version,
+ int expected_ssl_setup_result)
{
mbedtls_ssl_config conf;
mbedtls_ssl_context ssl;
- mbedtls_ssl_config_init( &conf );
- mbedtls_ssl_init( &ssl );
+ mbedtls_ssl_config_init(&conf);
+ mbedtls_ssl_init(&ssl);
- mbedtls_ssl_conf_endpoint( &conf, endpoint );
- mbedtls_ssl_conf_transport( &conf, transport );
- mbedtls_ssl_conf_min_tls_version( &conf, min_tls_version );
- mbedtls_ssl_conf_max_tls_version( &conf, max_tls_version );
+ mbedtls_ssl_conf_endpoint(&conf, endpoint);
+ mbedtls_ssl_conf_transport(&conf, transport);
+ mbedtls_ssl_conf_min_tls_version(&conf, min_tls_version);
+ mbedtls_ssl_conf_max_tls_version(&conf, max_tls_version);
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == expected_ssl_setup_result );
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == expected_ssl_setup_result);
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
@@ -5601,30 +5404,32 @@
MBEDTLS_SSL_IANA_TLS_GROUP_NONE };
mbedtls_ssl_config conf;
- mbedtls_ssl_config_init( &conf );
+ mbedtls_ssl_config_init(&conf);
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
- mbedtls_ssl_conf_max_tls_version( &conf, MBEDTLS_SSL_VERSION_TLS1_2 );
- mbedtls_ssl_conf_min_tls_version( &conf, MBEDTLS_SSL_VERSION_TLS1_2 );
+ mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
+ mbedtls_ssl_conf_min_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
#else
- mbedtls_ssl_conf_max_tls_version( &conf, MBEDTLS_SSL_VERSION_TLS1_3 );
- mbedtls_ssl_conf_min_tls_version( &conf, MBEDTLS_SSL_VERSION_TLS1_3 );
+ mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_3);
+ mbedtls_ssl_conf_min_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_3);
#endif
- mbedtls_ssl_conf_curves( &conf, curve_list );
+ mbedtls_ssl_conf_curves(&conf, curve_list);
mbedtls_ssl_context ssl;
- mbedtls_ssl_init( &ssl );
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ mbedtls_ssl_init(&ssl);
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
- TEST_ASSERT( ssl.handshake != NULL && ssl.handshake->group_list != NULL );
- TEST_ASSERT( ssl.conf != NULL && ssl.conf->group_list == NULL );
+ TEST_ASSERT(ssl.handshake != NULL && ssl.handshake->group_list != NULL);
+ TEST_ASSERT(ssl.conf != NULL && ssl.conf->group_list == NULL);
- TEST_EQUAL( ssl.handshake->group_list[ARRAY_LENGTH( iana_tls_group_list ) - 1], MBEDTLS_SSL_IANA_TLS_GROUP_NONE );
+ TEST_EQUAL(ssl.handshake->group_list[ARRAY_LENGTH(iana_tls_group_list) - 1],
+ MBEDTLS_SSL_IANA_TLS_GROUP_NONE);
- for( size_t i = 0; i < ARRAY_LENGTH( iana_tls_group_list ); i++ )
- TEST_EQUAL( iana_tls_group_list[i], ssl.handshake->group_list[i] );
+ for (size_t i = 0; i < ARRAY_LENGTH(iana_tls_group_list); i++) {
+ TEST_EQUAL(iana_tls_group_list[i], ssl.handshake->group_list[i]);
+ }
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
@@ -5632,36 +5437,38 @@
void conf_group()
{
uint16_t iana_tls_group_list[] = { MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1,
- MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1,
- MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1,
- MBEDTLS_SSL_IANA_TLS_GROUP_NONE };
+ MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1,
+ MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1,
+ MBEDTLS_SSL_IANA_TLS_GROUP_NONE };
mbedtls_ssl_config conf;
- mbedtls_ssl_config_init( &conf );
+ mbedtls_ssl_config_init(&conf);
- mbedtls_ssl_conf_max_tls_version( &conf, MBEDTLS_SSL_VERSION_TLS1_2 );
- mbedtls_ssl_conf_min_tls_version( &conf, MBEDTLS_SSL_VERSION_TLS1_2 );
+ mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
+ mbedtls_ssl_conf_min_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
- mbedtls_ssl_conf_groups( &conf, iana_tls_group_list );
+ mbedtls_ssl_conf_groups(&conf, iana_tls_group_list);
mbedtls_ssl_context ssl;
- mbedtls_ssl_init( &ssl );
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ mbedtls_ssl_init(&ssl);
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
- TEST_ASSERT( ssl.conf != NULL && ssl.conf->group_list != NULL );
+ TEST_ASSERT(ssl.conf != NULL && ssl.conf->group_list != NULL);
- TEST_EQUAL( ssl.conf->group_list[ARRAY_LENGTH( iana_tls_group_list ) - 1], MBEDTLS_SSL_IANA_TLS_GROUP_NONE );
+ TEST_EQUAL(ssl.conf->group_list[ARRAY_LENGTH(iana_tls_group_list) - 1],
+ MBEDTLS_SSL_IANA_TLS_GROUP_NONE);
- for( size_t i = 0; i < ARRAY_LENGTH( iana_tls_group_list ); i++ )
- TEST_EQUAL( iana_tls_group_list[i], ssl.conf->group_list[i] );
+ for (size_t i = 0; i < ARRAY_LENGTH(iana_tls_group_list); i++) {
+ TEST_EQUAL(iana_tls_group_list[i], ssl.conf->group_list[i]);
+ }
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SRV_C:MBEDTLS_SSL_CACHE_C:!MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_DEBUG_C:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_PKCS1_V15:MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void force_bad_session_id_len( )
+void force_bad_session_id_len()
{
enum { BUFFSIZE = 1024 };
handshake_test_options options;
@@ -5671,103 +5478,102 @@
srv_pattern.pattern = cli_pattern.pattern = "cache did not store session";
srv_pattern.counter = 0;
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.srv_log_obj = &srv_pattern;
options.srv_log_fun = log_analyzer;
- USE_PSA_INIT( );
- mbedtls_platform_zeroize( &client, sizeof(client) );
- mbedtls_platform_zeroize( &server, sizeof(server) );
+ USE_PSA_INIT();
+ mbedtls_platform_zeroize(&client, sizeof(client));
+ mbedtls_platform_zeroize(&server, sizeof(server));
- mbedtls_message_socket_init( &server_context );
- mbedtls_message_socket_init( &client_context );
+ mbedtls_message_socket_init(&server_context);
+ mbedtls_message_socket_init(&client_context);
- TEST_ASSERT( mbedtls_endpoint_init( &client, MBEDTLS_SSL_IS_CLIENT,
- &options, NULL, NULL,
- NULL, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_endpoint_init(&client, MBEDTLS_SSL_IS_CLIENT,
+ &options, NULL, NULL,
+ NULL, NULL) == 0);
- TEST_ASSERT( mbedtls_endpoint_init( &server, MBEDTLS_SSL_IS_SERVER,
- &options, NULL, NULL, NULL,
- NULL ) == 0 );
+ TEST_ASSERT(mbedtls_endpoint_init(&server, MBEDTLS_SSL_IS_SERVER,
+ &options, NULL, NULL, NULL,
+ NULL) == 0);
- mbedtls_debug_set_threshold( 1 );
- mbedtls_ssl_conf_dbg( &server.conf, options.srv_log_fun,
- options.srv_log_obj );
+ mbedtls_debug_set_threshold(1);
+ mbedtls_ssl_conf_dbg(&server.conf, options.srv_log_fun,
+ options.srv_log_obj);
- TEST_ASSERT( mbedtls_mock_socket_connect( &(client.socket),
- &(server.socket),
- BUFFSIZE ) == 0 );
+ TEST_ASSERT(mbedtls_mock_socket_connect(&(client.socket),
+ &(server.socket),
+ BUFFSIZE) == 0);
- TEST_ASSERT( mbedtls_move_handshake_to_state( &(client.ssl),
- &(server.ssl),
- MBEDTLS_SSL_HANDSHAKE_WRAPUP )
- == 0 );
+ TEST_ASSERT(mbedtls_move_handshake_to_state(&(client.ssl),
+ &(server.ssl),
+ MBEDTLS_SSL_HANDSHAKE_WRAPUP)
+ == 0);
/* Force a bad session_id_len that will be read by the server in
* mbedtls_ssl_cache_set. */
server.ssl.session_negotiate->id_len = 33;
- if( options.cli_msg_len != 0 || options.srv_msg_len != 0 )
- {
+ if (options.cli_msg_len != 0 || options.srv_msg_len != 0) {
/* Start data exchanging test */
- TEST_ASSERT( mbedtls_exchange_data( &(client.ssl), options.cli_msg_len,
- options.expected_cli_fragments,
- &(server.ssl), options.srv_msg_len,
- options.expected_srv_fragments )
- == 0 );
+ TEST_ASSERT(mbedtls_exchange_data(&(client.ssl), options.cli_msg_len,
+ options.expected_cli_fragments,
+ &(server.ssl), options.srv_msg_len,
+ options.expected_srv_fragments)
+ == 0);
}
/* Make sure that the cache did not store the session */
- TEST_EQUAL( srv_pattern.counter, 1 );
+ TEST_EQUAL(srv_pattern.counter, 1);
exit:
- mbedtls_endpoint_free( &client, NULL );
- mbedtls_endpoint_free( &server, NULL );
- free_handshake_options( &options );
- mbedtls_debug_set_threshold( 0 );
- USE_PSA_DONE( );
+ mbedtls_endpoint_free(&client, NULL);
+ mbedtls_endpoint_free(&server, NULL);
+ free_handshake_options(&options);
+ mbedtls_debug_set_threshold(0);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SRV_C:MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE:MBEDTLS_TEST_HOOKS */
-void cookie_parsing( data_t *cookie, int exp_ret )
+void cookie_parsing(data_t *cookie, int exp_ret)
{
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
size_t len;
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
- TEST_EQUAL( mbedtls_ssl_config_defaults( &conf, MBEDTLS_SSL_IS_SERVER,
- MBEDTLS_SSL_TRANSPORT_DATAGRAM,
- MBEDTLS_SSL_PRESET_DEFAULT ),
- 0 );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
+ TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, MBEDTLS_SSL_IS_SERVER,
+ MBEDTLS_SSL_TRANSPORT_DATAGRAM,
+ MBEDTLS_SSL_PRESET_DEFAULT),
+ 0);
- TEST_EQUAL( mbedtls_ssl_setup( &ssl, &conf ), 0 );
- TEST_EQUAL( mbedtls_ssl_check_dtls_clihlo_cookie( &ssl, ssl.cli_id,
- ssl.cli_id_len,
- cookie->x, cookie->len,
- ssl.out_buf,
- MBEDTLS_SSL_OUT_CONTENT_LEN,
- &len ),
- exp_ret );
+ TEST_EQUAL(mbedtls_ssl_setup(&ssl, &conf), 0);
+ TEST_EQUAL(mbedtls_ssl_check_dtls_clihlo_cookie(&ssl, ssl.cli_id,
+ ssl.cli_id_len,
+ cookie->x, cookie->len,
+ ssl.out_buf,
+ MBEDTLS_SSL_OUT_CONTENT_LEN,
+ &len),
+ exp_ret);
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TIMING_C:MBEDTLS_HAVE_TIME */
-void timing_final_delay_accessor( )
+void timing_final_delay_accessor()
{
mbedtls_timing_delay_context delay_context;
- mbedtls_timing_set_delay( &delay_context, 50, 100 );
+ mbedtls_timing_set_delay(&delay_context, 50, 100);
- TEST_ASSERT( mbedtls_timing_get_final_delay( &delay_context ) == 100 );
+ TEST_ASSERT(mbedtls_timing_get_final_delay(&delay_context) == 100);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_DTLS_CONNECTION_ID */
-void cid_sanity( )
+void cid_sanity()
{
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
@@ -5777,78 +5583,78 @@
int cid_enabled;
size_t own_cid_len;
- mbedtls_test_rnd_std_rand( NULL, own_cid, sizeof( own_cid ) );
+ mbedtls_test_rnd_std_rand(NULL, own_cid, sizeof(own_cid));
- mbedtls_ssl_init( &ssl );
- mbedtls_ssl_config_init( &conf );
+ mbedtls_ssl_init(&ssl);
+ mbedtls_ssl_config_init(&conf);
- TEST_ASSERT( mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT)
+ == 0);
- TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
/* Can't use CID functions with stream transport. */
- TEST_ASSERT( mbedtls_ssl_set_cid( &ssl, MBEDTLS_SSL_CID_ENABLED, own_cid,
- sizeof( own_cid ) )
- == MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_ssl_set_cid(&ssl, MBEDTLS_SSL_CID_ENABLED, own_cid,
+ sizeof(own_cid))
+ == MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_ssl_get_own_cid( &ssl, &cid_enabled, test_cid,
- &own_cid_len )
- == MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_ssl_get_own_cid(&ssl, &cid_enabled, test_cid,
+ &own_cid_len)
+ == MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_DATAGRAM,
- MBEDTLS_SSL_PRESET_DEFAULT )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_DATAGRAM,
+ MBEDTLS_SSL_PRESET_DEFAULT)
+ == 0);
/* Attempt to set config cid size too big. */
- TEST_ASSERT( mbedtls_ssl_conf_cid( &conf, MBEDTLS_SSL_CID_IN_LEN_MAX + 1,
- MBEDTLS_SSL_UNEXPECTED_CID_IGNORE )
- == MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_ssl_conf_cid(&conf, MBEDTLS_SSL_CID_IN_LEN_MAX + 1,
+ MBEDTLS_SSL_UNEXPECTED_CID_IGNORE)
+ == MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_ssl_conf_cid( &conf, sizeof( own_cid ),
- MBEDTLS_SSL_UNEXPECTED_CID_IGNORE )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_conf_cid(&conf, sizeof(own_cid),
+ MBEDTLS_SSL_UNEXPECTED_CID_IGNORE)
+ == 0);
/* Attempt to set CID length not matching config. */
- TEST_ASSERT( mbedtls_ssl_set_cid( &ssl, MBEDTLS_SSL_CID_ENABLED, own_cid,
- MBEDTLS_SSL_CID_IN_LEN_MAX - 1 )
- == MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ TEST_ASSERT(mbedtls_ssl_set_cid(&ssl, MBEDTLS_SSL_CID_ENABLED, own_cid,
+ MBEDTLS_SSL_CID_IN_LEN_MAX - 1)
+ == MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
- TEST_ASSERT( mbedtls_ssl_set_cid( &ssl, MBEDTLS_SSL_CID_ENABLED, own_cid,
- sizeof( own_cid ) )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_set_cid(&ssl, MBEDTLS_SSL_CID_ENABLED, own_cid,
+ sizeof(own_cid))
+ == 0);
/* Test we get back what we put in. */
- TEST_ASSERT( mbedtls_ssl_get_own_cid( &ssl, &cid_enabled, test_cid,
- &own_cid_len )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_get_own_cid(&ssl, &cid_enabled, test_cid,
+ &own_cid_len)
+ == 0);
- TEST_EQUAL( cid_enabled, MBEDTLS_SSL_CID_ENABLED );
- ASSERT_COMPARE( own_cid, own_cid_len, test_cid, own_cid_len );
+ TEST_EQUAL(cid_enabled, MBEDTLS_SSL_CID_ENABLED);
+ ASSERT_COMPARE(own_cid, own_cid_len, test_cid, own_cid_len);
/* Test disabling works. */
- TEST_ASSERT( mbedtls_ssl_set_cid( &ssl, MBEDTLS_SSL_CID_DISABLED, NULL,
- 0 )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_set_cid(&ssl, MBEDTLS_SSL_CID_DISABLED, NULL,
+ 0)
+ == 0);
- TEST_ASSERT( mbedtls_ssl_get_own_cid( &ssl, &cid_enabled, test_cid,
- &own_cid_len )
- == 0 );
+ TEST_ASSERT(mbedtls_ssl_get_own_cid(&ssl, &cid_enabled, test_cid,
+ &own_cid_len)
+ == 0);
- TEST_EQUAL( cid_enabled, MBEDTLS_SSL_CID_DISABLED );
+ TEST_EQUAL(cid_enabled, MBEDTLS_SSL_CID_DISABLED);
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_ECDSA_C */
-void raw_key_agreement_fail( int bad_server_ecdhe_key )
+void raw_key_agreement_fail(int bad_server_ecdhe_key)
{
enum { BUFFSIZE = 17000 };
mbedtls_endpoint client, server;
@@ -5858,68 +5664,68 @@
uint16_t iana_tls_group_list[] = { MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1,
MBEDTLS_SSL_IANA_TLS_GROUP_NONE };
- USE_PSA_INIT( );
- mbedtls_platform_zeroize( &client, sizeof(client) );
- mbedtls_platform_zeroize( &server, sizeof(server) );
+ USE_PSA_INIT();
+ mbedtls_platform_zeroize(&client, sizeof(client));
+ mbedtls_platform_zeroize(&server, sizeof(server));
- init_handshake_options( &options );
+ init_handshake_options(&options);
options.pk_alg = MBEDTLS_PK_ECDSA;
/* Client side, force SECP256R1 to make one key bitflip fail
* the raw key agreement. Flipping the first byte makes the
* required 0x04 identifier invalid. */
- TEST_EQUAL( mbedtls_endpoint_init( &client, MBEDTLS_SSL_IS_CLIENT,
- &options, NULL, NULL,
- NULL, iana_tls_group_list ), 0 );
+ TEST_EQUAL(mbedtls_endpoint_init(&client, MBEDTLS_SSL_IS_CLIENT,
+ &options, NULL, NULL,
+ NULL, iana_tls_group_list), 0);
/* Server side */
- TEST_EQUAL( mbedtls_endpoint_init( &server, MBEDTLS_SSL_IS_SERVER,
- &options, NULL, NULL,
- NULL, NULL ), 0 );
+ TEST_EQUAL(mbedtls_endpoint_init(&server, MBEDTLS_SSL_IS_SERVER,
+ &options, NULL, NULL,
+ NULL, NULL), 0);
- TEST_EQUAL( mbedtls_mock_socket_connect( &(client.socket),
- &(server.socket),
- BUFFSIZE ), 0 );
+ TEST_EQUAL(mbedtls_mock_socket_connect(&(client.socket),
+ &(server.socket),
+ BUFFSIZE), 0);
- TEST_EQUAL( mbedtls_move_handshake_to_state( &(client.ssl),
- &(server.ssl),
- MBEDTLS_SSL_CLIENT_KEY_EXCHANGE )
- , 0 );
+ TEST_EQUAL(mbedtls_move_handshake_to_state(&(client.ssl),
+ &(server.ssl),
+ MBEDTLS_SSL_CLIENT_KEY_EXCHANGE)
+ , 0);
- mbedtls_psa_get_stats( &stats );
+ mbedtls_psa_get_stats(&stats);
/* Save the number of slots in use up to this point.
* With PSA, one can be used for the ECDH private key. */
free_slots_before = stats.empty_slots;
- if( bad_server_ecdhe_key )
- {
+ if (bad_server_ecdhe_key) {
/* Force a simulated bitflip in the server key. to make the
* raw key agreement in ssl_write_client_key_exchange fail. */
(client.ssl).handshake->ecdh_psa_peerkey[0] ^= 0x02;
}
- TEST_EQUAL( mbedtls_move_handshake_to_state( &(client.ssl),
- &(server.ssl),
- MBEDTLS_SSL_HANDSHAKE_OVER ),
- bad_server_ecdhe_key ? MBEDTLS_ERR_SSL_HW_ACCEL_FAILED : 0 );
+ TEST_EQUAL(mbedtls_move_handshake_to_state(&(client.ssl),
+ &(server.ssl),
+ MBEDTLS_SSL_HANDSHAKE_OVER),
+ bad_server_ecdhe_key ? MBEDTLS_ERR_SSL_HW_ACCEL_FAILED : 0);
- mbedtls_psa_get_stats( &stats );
+ mbedtls_psa_get_stats(&stats);
/* Make sure that the key slot is already destroyed in case of failure,
* without waiting to close the connection. */
- if( bad_server_ecdhe_key )
- TEST_EQUAL( free_slots_before, stats.empty_slots );
+ if (bad_server_ecdhe_key) {
+ TEST_EQUAL(free_slots_before, stats.empty_slots);
+ }
exit:
- mbedtls_endpoint_free( &client, NULL );
- mbedtls_endpoint_free( &server, NULL );
- free_handshake_options( &options );
+ mbedtls_endpoint_free(&client, NULL);
+ mbedtls_endpoint_free(&server, NULL);
+ free_handshake_options(&options);
- USE_PSA_DONE( );
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_SSL_PROTO_TLS1_3:!MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_SSL_CLI_C:MBEDTLS_SSL_SRV_C:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:MBEDTLS_ECP_DP_SECP384R1_ENABLED */
-void tls13_server_certificate_msg_invalid_vector_len( )
+void tls13_server_certificate_msg_invalid_vector_len()
{
int ret = -1;
mbedtls_endpoint client_ep, server_ep;
@@ -5934,47 +5740,46 @@
/*
* Test set-up
*/
- USE_PSA_INIT( );
- mbedtls_platform_zeroize( &client_ep, sizeof(client_ep) );
- mbedtls_platform_zeroize( &server_ep, sizeof(server_ep) );
+ USE_PSA_INIT();
+ mbedtls_platform_zeroize(&client_ep, sizeof(client_ep));
+ mbedtls_platform_zeroize(&server_ep, sizeof(server_ep));
- init_handshake_options( &client_options );
+ init_handshake_options(&client_options);
client_options.pk_alg = MBEDTLS_PK_ECDSA;
- ret = mbedtls_endpoint_init( &client_ep, MBEDTLS_SSL_IS_CLIENT,
- &client_options, NULL, NULL, NULL, NULL );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_endpoint_init(&client_ep, MBEDTLS_SSL_IS_CLIENT,
+ &client_options, NULL, NULL, NULL, NULL);
+ TEST_EQUAL(ret, 0);
- init_handshake_options( &server_options );
+ init_handshake_options(&server_options);
server_options.pk_alg = MBEDTLS_PK_ECDSA;
- ret = mbedtls_endpoint_init( &server_ep, MBEDTLS_SSL_IS_SERVER,
- &server_options, NULL, NULL, NULL, NULL );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_endpoint_init(&server_ep, MBEDTLS_SSL_IS_SERVER,
+ &server_options, NULL, NULL, NULL, NULL);
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_mock_socket_connect( &(client_ep.socket),
- &(server_ep.socket), 1024 );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_mock_socket_connect(&(client_ep.socket),
+ &(server_ep.socket), 1024);
+ TEST_EQUAL(ret, 0);
- while( 1 )
- {
- mbedtls_test_set_step( ++step );
+ while (1) {
+ mbedtls_test_set_step(++step);
- ret = mbedtls_move_handshake_to_state( &(server_ep.ssl),
- &(client_ep.ssl),
- MBEDTLS_SSL_CERTIFICATE_VERIFY );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_move_handshake_to_state(&(server_ep.ssl),
+ &(client_ep.ssl),
+ MBEDTLS_SSL_CERTIFICATE_VERIFY);
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_ssl_flush_output( &(server_ep.ssl) );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_ssl_flush_output(&(server_ep.ssl));
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_move_handshake_to_state( &(client_ep.ssl),
- &(server_ep.ssl),
- MBEDTLS_SSL_SERVER_CERTIFICATE );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_move_handshake_to_state(&(client_ep.ssl),
+ &(server_ep.ssl),
+ MBEDTLS_SSL_SERVER_CERTIFICATE);
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_ssl_tls13_fetch_handshake_msg( &(client_ep.ssl),
- MBEDTLS_SSL_HS_CERTIFICATE,
- &buf, &buf_len );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_ssl_tls13_fetch_handshake_msg(&(client_ep.ssl),
+ MBEDTLS_SSL_HS_CERTIFICATE,
+ &buf, &buf_len);
+ TEST_EQUAL(ret, 0);
end = buf + buf_len;
@@ -5983,114 +5788,113 @@
*/
ret = tweak_tls13_certificate_msg_vector_len(
- buf, &end, step, &expected_result, &expected_chk_buf_ptr_args );
+ buf, &end, step, &expected_result, &expected_chk_buf_ptr_args);
- if( ret != 0 )
+ if (ret != 0) {
break;
+ }
- ret = mbedtls_ssl_tls13_parse_certificate( &(client_ep.ssl), buf, end );
- TEST_EQUAL( ret, expected_result );
+ ret = mbedtls_ssl_tls13_parse_certificate(&(client_ep.ssl), buf, end);
+ TEST_EQUAL(ret, expected_result);
- TEST_ASSERT( mbedtls_ssl_cmp_chk_buf_ptr_fail_args(
- &expected_chk_buf_ptr_args ) == 0 );
+ TEST_ASSERT(mbedtls_ssl_cmp_chk_buf_ptr_fail_args(
+ &expected_chk_buf_ptr_args) == 0);
- mbedtls_ssl_reset_chk_buf_ptr_fail_args( );
+ mbedtls_ssl_reset_chk_buf_ptr_fail_args();
- ret = mbedtls_ssl_session_reset( &(client_ep.ssl) );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_ssl_session_reset(&(client_ep.ssl));
+ TEST_EQUAL(ret, 0);
- ret = mbedtls_ssl_session_reset( &(server_ep.ssl) );
- TEST_EQUAL( ret, 0 );
+ ret = mbedtls_ssl_session_reset(&(server_ep.ssl));
+ TEST_EQUAL(ret, 0);
}
exit:
- mbedtls_ssl_reset_chk_buf_ptr_fail_args( );
- mbedtls_endpoint_free( &client_ep, NULL );
- mbedtls_endpoint_free( &server_ep, NULL );
- free_handshake_options( &client_options );
- free_handshake_options( &server_options );
- USE_PSA_DONE( );
+ mbedtls_ssl_reset_chk_buf_ptr_fail_args();
+ mbedtls_endpoint_free(&client_ep, NULL);
+ mbedtls_endpoint_free(&server_ep, NULL);
+ free_handshake_options(&client_options);
+ free_handshake_options(&server_options);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
-void ssl_ecjpake_set_password( int use_opaque_arg )
+void ssl_ecjpake_set_password(int use_opaque_arg)
{
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
-#if defined( MBEDTLS_USE_PSA_CRYPTO )
+#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_svc_key_id_t pwd_slot = MBEDTLS_SVC_KEY_ID_INIT;
#else /* MBEDTLS_USE_PSA_CRYPTO */
(void) use_opaque_arg;
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- unsigned char pwd_string[ sizeof(ECJPAKE_TEST_PWD) ] = "";
+ unsigned char pwd_string[sizeof(ECJPAKE_TEST_PWD)] = "";
size_t pwd_len = 0;
int ret;
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_ssl_init( &ssl );
+ mbedtls_ssl_init(&ssl);
/* test with uninitalized SSL context */
- ECJPAKE_TEST_SET_PASSWORD( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ ECJPAKE_TEST_SET_PASSWORD(MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
- mbedtls_ssl_config_init( &conf );
+ mbedtls_ssl_config_init(&conf);
- TEST_EQUAL( mbedtls_ssl_config_defaults( &conf,
- MBEDTLS_SSL_IS_CLIENT,
- MBEDTLS_SSL_TRANSPORT_STREAM,
- MBEDTLS_SSL_PRESET_DEFAULT ), 0 );
+ TEST_EQUAL(mbedtls_ssl_config_defaults(&conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT), 0);
- TEST_EQUAL( mbedtls_ssl_setup( &ssl, &conf ), 0 );
+ TEST_EQUAL(mbedtls_ssl_setup(&ssl, &conf), 0);
/* test with empty password or unitialized password key (depending on use_opaque_arg) */
- ECJPAKE_TEST_SET_PASSWORD( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ ECJPAKE_TEST_SET_PASSWORD(MBEDTLS_ERR_SSL_BAD_INPUT_DATA);
- pwd_len = strlen( ECJPAKE_TEST_PWD );
- memcpy( pwd_string, ECJPAKE_TEST_PWD, pwd_len );
+ pwd_len = strlen(ECJPAKE_TEST_PWD);
+ memcpy(pwd_string, ECJPAKE_TEST_PWD, pwd_len);
-#if defined( MBEDTLS_USE_PSA_CRYPTO )
- if( use_opaque_arg )
- {
+#if defined(MBEDTLS_USE_PSA_CRYPTO)
+ if (use_opaque_arg) {
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t check_attributes = PSA_KEY_ATTRIBUTES_INIT;
/* First try with an invalid usage */
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
- psa_set_key_algorithm( &attributes, PSA_ALG_JPAKE );
- psa_set_key_type( &attributes, PSA_KEY_TYPE_PASSWORD );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
+ psa_set_key_algorithm(&attributes, PSA_ALG_JPAKE);
+ psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
- PSA_ASSERT( psa_import_key( &attributes, pwd_string,
- pwd_len, &pwd_slot ) );
+ PSA_ASSERT(psa_import_key(&attributes, pwd_string,
+ pwd_len, &pwd_slot));
- ECJPAKE_TEST_SET_PASSWORD( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
+ ECJPAKE_TEST_SET_PASSWORD(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED);
/* check that the opaque key is still valid after failure */
- TEST_EQUAL( psa_get_key_attributes( pwd_slot, &check_attributes ),
- PSA_SUCCESS );
+ TEST_EQUAL(psa_get_key_attributes(pwd_slot, &check_attributes),
+ PSA_SUCCESS);
- psa_destroy_key( pwd_slot );
+ psa_destroy_key(pwd_slot);
/* Then set the correct usage */
- psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DERIVE );
+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
- PSA_ASSERT( psa_import_key( &attributes, pwd_string,
- pwd_len, &pwd_slot ) );
+ PSA_ASSERT(psa_import_key(&attributes, pwd_string,
+ pwd_len, &pwd_slot));
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* final check which should work without errors */
- ECJPAKE_TEST_SET_PASSWORD( 0 );
+ ECJPAKE_TEST_SET_PASSWORD(0);
-#if defined( MBEDTLS_USE_PSA_CRYPTO )
- if( use_opaque_arg )
- {
- psa_destroy_key( pwd_slot );
+#if defined(MBEDTLS_USE_PSA_CRYPTO)
+ if (use_opaque_arg) {
+ psa_destroy_key(pwd_slot);
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- mbedtls_ssl_free( &ssl );
- mbedtls_ssl_config_free( &conf );
+ mbedtls_ssl_free(&ssl);
+ mbedtls_ssl_config_free(&conf);
- USE_PSA_DONE( );
+ USE_PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_timing.function b/tests/suites/test_suite_timing.function
index 3483d85..821ebd6 100644
--- a/tests/suites/test_suite_timing.function
+++ b/tests/suites/test_suite_timing.function
@@ -17,32 +17,29 @@
*/
/* BEGIN_CASE */
-void timing_get_timer( )
+void timing_get_timer()
{
struct mbedtls_timing_hr_time time;
- (void) mbedtls_timing_get_timer( &time, 1 );
- (void) mbedtls_timing_get_timer( &time, 0 );
+ (void) mbedtls_timing_get_timer(&time, 1);
+ (void) mbedtls_timing_get_timer(&time, 0);
/* This goto is added to avoid warnings from the generated code. */
goto exit;
}
/* END_CASE */
/* BEGIN_CASE */
-void timing_delay( int fin_ms )
+void timing_delay(int fin_ms)
{
mbedtls_timing_delay_context ctx;
int result;
- if( fin_ms == 0 )
- {
- mbedtls_timing_set_delay( &ctx, 0, 0 );
- result = mbedtls_timing_get_delay( &ctx );
- TEST_ASSERT( result == -1 );
- }
- else
- {
- mbedtls_timing_set_delay( &ctx, fin_ms / 2, fin_ms );
- result = mbedtls_timing_get_delay( &ctx );
- TEST_ASSERT( result >= 0 && result <= 2 );
+ if (fin_ms == 0) {
+ mbedtls_timing_set_delay(&ctx, 0, 0);
+ result = mbedtls_timing_get_delay(&ctx);
+ TEST_ASSERT(result == -1);
+ } else {
+ mbedtls_timing_set_delay(&ctx, fin_ms / 2, fin_ms);
+ result = mbedtls_timing_get_delay(&ctx);
+ TEST_ASSERT(result >= 0 && result <= 2);
}
}
/* END_CASE */
diff --git a/tests/suites/test_suite_version.function b/tests/suites/test_suite_version.function
index 7d59794..981f8ab 100644
--- a/tests/suites/test_suite_version.function
+++ b/tests/suites/test_suite_version.function
@@ -8,34 +8,34 @@
*/
/* BEGIN_CASE */
-void check_compiletime_version( char * version_str )
+void check_compiletime_version(char *version_str)
{
char build_str[100];
char build_str_full[100];
unsigned int build_int;
- memset( build_str, 0, 100 );
- memset( build_str_full, 0, 100 );
+ memset(build_str, 0, 100);
+ memset(build_str_full, 0, 100);
- mbedtls_snprintf( build_str, 100, "%d.%d.%d", MBEDTLS_VERSION_MAJOR,
- MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH );
+ mbedtls_snprintf(build_str, 100, "%d.%d.%d", MBEDTLS_VERSION_MAJOR,
+ MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH);
- mbedtls_snprintf( build_str_full, 100, "mbed TLS %d.%d.%d", MBEDTLS_VERSION_MAJOR,
- MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH );
+ mbedtls_snprintf(build_str_full, 100, "mbed TLS %d.%d.%d", MBEDTLS_VERSION_MAJOR,
+ MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH);
build_int = MBEDTLS_VERSION_MAJOR << 24 |
- MBEDTLS_VERSION_MINOR << 16 |
- MBEDTLS_VERSION_PATCH << 8;
+ MBEDTLS_VERSION_MINOR << 16 |
+ MBEDTLS_VERSION_PATCH << 8;
- TEST_ASSERT( build_int == MBEDTLS_VERSION_NUMBER );
- TEST_ASSERT( strcmp( build_str, MBEDTLS_VERSION_STRING ) == 0 );
- TEST_ASSERT( strcmp( build_str_full, MBEDTLS_VERSION_STRING_FULL ) == 0 );
- TEST_ASSERT( strcmp( version_str, MBEDTLS_VERSION_STRING ) == 0 );
+ TEST_ASSERT(build_int == MBEDTLS_VERSION_NUMBER);
+ TEST_ASSERT(strcmp(build_str, MBEDTLS_VERSION_STRING) == 0);
+ TEST_ASSERT(strcmp(build_str_full, MBEDTLS_VERSION_STRING_FULL) == 0);
+ TEST_ASSERT(strcmp(version_str, MBEDTLS_VERSION_STRING) == 0);
}
/* END_CASE */
/* BEGIN_CASE */
-void check_runtime_version( char * version_str )
+void check_runtime_version(char *version_str)
{
char build_str[100];
char get_str[100];
@@ -43,31 +43,31 @@
char get_str_full[100];
unsigned int get_int;
- memset( build_str, 0, 100 );
- memset( get_str, 0, 100 );
- memset( build_str_full, 0, 100 );
- memset( get_str_full, 0, 100 );
+ memset(build_str, 0, 100);
+ memset(get_str, 0, 100);
+ memset(build_str_full, 0, 100);
+ memset(get_str_full, 0, 100);
get_int = mbedtls_version_get_number();
- mbedtls_version_get_string( get_str );
- mbedtls_version_get_string_full( get_str_full );
+ mbedtls_version_get_string(get_str);
+ mbedtls_version_get_string_full(get_str_full);
- mbedtls_snprintf( build_str, 100, "%u.%u.%u",
- (get_int >> 24) & 0xFF,
- (get_int >> 16) & 0xFF,
- (get_int >> 8) & 0xFF );
- mbedtls_snprintf( build_str_full, 100, "mbed TLS %s", version_str );
+ mbedtls_snprintf(build_str, 100, "%u.%u.%u",
+ (get_int >> 24) & 0xFF,
+ (get_int >> 16) & 0xFF,
+ (get_int >> 8) & 0xFF);
+ mbedtls_snprintf(build_str_full, 100, "mbed TLS %s", version_str);
- TEST_ASSERT( strcmp( build_str, version_str ) == 0 );
- TEST_ASSERT( strcmp( build_str_full, get_str_full ) == 0 );
- TEST_ASSERT( strcmp( version_str, get_str ) == 0 );
+ TEST_ASSERT(strcmp(build_str, version_str) == 0);
+ TEST_ASSERT(strcmp(build_str_full, get_str_full) == 0);
+ TEST_ASSERT(strcmp(version_str, get_str) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_VERSION_FEATURES */
-void check_feature( char *feature, int result )
+void check_feature(char *feature, int result)
{
- int check = mbedtls_version_check_feature( feature );
- TEST_ASSERT( check == result );
+ int check = mbedtls_version_check_feature(feature);
+ TEST_ASSERT(check == result);
}
/* END_CASE */
diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function
index 388d45e..5d896bf 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -14,8 +14,8 @@
#if MBEDTLS_X509_MAX_INTERMEDIATE_CA > 19
#error "The value of MBEDTLS_X509_MAX_INTERMEDIATE_C is larger \
-than the current threshold 19. To test larger values, please \
-adapt the script tests/data_files/dir-max/long.sh."
+ than the current threshold 19. To test larger values, please \
+ adapt the script tests/data_files/dir-max/long.sh."
#endif
/* Test-only profile allowing all digests, PK algorithms, and curves. */
@@ -31,12 +31,12 @@
profile. */
const mbedtls_x509_crt_profile compat_profile =
{
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ) |
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_RIPEMD160 ) |
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 ) |
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 ) |
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 ) |
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ),
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) |
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_RIPEMD160) |
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) |
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) |
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) |
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512),
0xFFFFFFFF, /* Any PK alg */
0xFFFFFFFF, /* Any curve */
1024,
@@ -44,23 +44,23 @@
const mbedtls_x509_crt_profile profile_rsa3072 =
{
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 ) |
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 ) |
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ),
- MBEDTLS_X509_ID_FLAG( MBEDTLS_PK_RSA ),
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) |
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) |
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512),
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_RSA),
0,
3072,
};
const mbedtls_x509_crt_profile profile_sha512 =
{
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ),
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512),
0xFFFFFFFF, /* Any PK alg */
0xFFFFFFFF, /* Any curve */
1024,
};
-int verify_none( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
+int verify_none(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags)
{
((void) data);
((void) crt);
@@ -70,7 +70,7 @@
return 0;
}
-int verify_all( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
+int verify_all(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags)
{
((void) data);
((void) crt);
@@ -81,7 +81,7 @@
}
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
-int ca_callback_fail( void *data, mbedtls_x509_crt const *child, mbedtls_x509_crt **candidates )
+int ca_callback_fail(void *data, mbedtls_x509_crt const *child, mbedtls_x509_crt **candidates)
{
((void) data);
((void) child);
@@ -90,8 +90,8 @@
return -1;
}
#if defined(MBEDTLS_X509_CRT_PARSE_C)
-int ca_callback( void *data, mbedtls_x509_crt const *child,
- mbedtls_x509_crt **candidates )
+int ca_callback(void *data, mbedtls_x509_crt const *child,
+ mbedtls_x509_crt **candidates)
{
int ret = 0;
mbedtls_x509_crt *ca = (mbedtls_x509_crt *) data;
@@ -107,25 +107,21 @@
* and parent `Subject` field. */
((void) child);
- first = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );
- if( first == NULL )
- {
+ first = mbedtls_calloc(1, sizeof(mbedtls_x509_crt));
+ if (first == NULL) {
ret = -1;
goto exit;
}
- mbedtls_x509_crt_init( first );
+ mbedtls_x509_crt_init(first);
- if( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) != 0 )
- {
+ if (mbedtls_x509_crt_parse_der(first, ca->raw.p, ca->raw.len) != 0) {
ret = -1;
goto exit;
}
- while( ca->next != NULL )
- {
+ while (ca->next != NULL) {
ca = ca->next;
- if( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) != 0 )
- {
+ if (mbedtls_x509_crt_parse_der(first, ca->raw.p, ca->raw.len) != 0) {
ret = -1;
goto exit;
}
@@ -133,20 +129,19 @@
exit:
- if( ret != 0 )
- {
- mbedtls_x509_crt_free( first );
- mbedtls_free( first );
+ if (ret != 0) {
+ mbedtls_x509_crt_free(first);
+ mbedtls_free(first);
first = NULL;
}
*candidates = first;
- return( ret );
+ return ret;
}
#endif /* MBEDTLS_X509_CRT_PARSE_C */
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
-int verify_fatal( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
+int verify_fatal(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags)
{
int *levels = (int *) data;
@@ -154,13 +149,12 @@
((void) certificate_depth);
/* Simulate a fatal error in the callback */
- if( *levels & ( 1 << certificate_depth ) )
- {
- *flags |= ( 1 << certificate_depth );
- return( -1 - certificate_depth );
+ if (*levels & (1 << certificate_depth)) {
+ *flags |= (1 << certificate_depth);
+ return -1 - certificate_depth;
}
- return( 0 );
+ return 0;
}
/* strsep() not available on Windows */
@@ -169,28 +163,27 @@
const char *p;
char *ret = *stringp;
- if( *stringp == NULL )
- return( NULL );
+ if (*stringp == NULL) {
+ return NULL;
+ }
- for( ; ; (*stringp)++ )
- {
- if( **stringp == '\0' )
- {
+ for (;; (*stringp)++) {
+ if (**stringp == '\0') {
*stringp = NULL;
goto done;
}
- for( p = delim; *p != '\0'; p++ )
- if( **stringp == *p )
- {
+ for (p = delim; *p != '\0'; p++) {
+ if (**stringp == *p) {
**stringp = '\0';
(*stringp)++;
goto done;
}
+ }
}
done:
- return( ret );
+ return ret;
}
#if defined(MBEDTLS_X509_CRT_PARSE_C)
@@ -199,195 +192,204 @@
char *p;
} verify_print_context;
-void verify_print_init( verify_print_context *ctx )
+void verify_print_init(verify_print_context *ctx)
{
- memset( ctx, 0, sizeof( verify_print_context ) );
+ memset(ctx, 0, sizeof(verify_print_context));
ctx->p = ctx->buf;
}
-int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
+int verify_print(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags)
{
int ret;
verify_print_context *ctx = (verify_print_context *) data;
char *p = ctx->p;
- size_t n = ctx->buf + sizeof( ctx->buf ) - ctx->p;
+ size_t n = ctx->buf + sizeof(ctx->buf) - ctx->p;
((void) flags);
- ret = mbedtls_snprintf( p, n, "depth %d - serial ", certificate_depth );
+ ret = mbedtls_snprintf(p, n, "depth %d - serial ", certificate_depth);
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_x509_serial_gets( p, n, &crt->serial );
+ ret = mbedtls_x509_serial_gets(p, n, &crt->serial);
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, " - subject " );
+ ret = mbedtls_snprintf(p, n, " - subject ");
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_x509_dn_gets( p, n, &crt->subject );
+ ret = mbedtls_x509_dn_gets(p, n, &crt->subject);
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, " - flags 0x%08x\n", *flags );
+ ret = mbedtls_snprintf(p, n, " - flags 0x%08x\n", *flags);
MBEDTLS_X509_SAFE_SNPRINTF;
ctx->p = p;
- return( 0 );
+ return 0;
}
-int verify_parse_san( mbedtls_x509_subject_alternative_name *san,
- char **buf, size_t *size )
+int verify_parse_san(mbedtls_x509_subject_alternative_name *san,
+ char **buf, size_t *size)
{
int ret;
size_t i;
char *p = *buf;
size_t n = *size;
- ret = mbedtls_snprintf( p, n, "type : %d", san->type );
+ ret = mbedtls_snprintf(p, n, "type : %d", san->type);
MBEDTLS_X509_SAFE_SNPRINTF;
- switch( san->type )
- {
- case( MBEDTLS_X509_SAN_OTHER_NAME ):
- ret = mbedtls_snprintf( p, n, "\notherName :");
+ switch (san->type) {
+ case (MBEDTLS_X509_SAN_OTHER_NAME):
+ ret = mbedtls_snprintf(p, n, "\notherName :");
MBEDTLS_X509_SAFE_SNPRINTF;
- if( MBEDTLS_OID_CMP( MBEDTLS_OID_ON_HW_MODULE_NAME,
- &san->san.other_name.value.hardware_module_name.oid ) != 0 )
- {
- ret = mbedtls_snprintf( p, n, " hardware module name :" );
+ if (MBEDTLS_OID_CMP(MBEDTLS_OID_ON_HW_MODULE_NAME,
+ &san->san.other_name.value.hardware_module_name.oid) != 0) {
+ ret = mbedtls_snprintf(p, n, " hardware module name :");
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, " hardware type : " );
+ ret = mbedtls_snprintf(p, n, " hardware type : ");
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_oid_get_numeric_string( p, n,
- &san->san.other_name.value.hardware_module_name.oid );
+ ret = mbedtls_oid_get_numeric_string(p,
+ n,
+ &san->san.other_name.value.hardware_module_name.oid);
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, ", hardware serial number : " );
+ ret = mbedtls_snprintf(p, n, ", hardware serial number : ");
MBEDTLS_X509_SAFE_SNPRINTF;
- for( i = 0; i < san->san.other_name.value.hardware_module_name.val.len; i++ )
- {
- ret = mbedtls_snprintf( p, n, "%02X", san->san.other_name.value.hardware_module_name.val.p[i] );
+ for (i = 0; i < san->san.other_name.value.hardware_module_name.val.len; i++) {
+ ret = mbedtls_snprintf(p,
+ n,
+ "%02X",
+ san->san.other_name.value.hardware_module_name.val.p[i]);
MBEDTLS_X509_SAFE_SNPRINTF;
}
}
- break;/* MBEDTLS_OID_ON_HW_MODULE_NAME */
- case( MBEDTLS_X509_SAN_DNS_NAME ):
- ret = mbedtls_snprintf( p, n, "\ndNSName : " );
+ break;/* MBEDTLS_OID_ON_HW_MODULE_NAME */
+ case (MBEDTLS_X509_SAN_DNS_NAME):
+ ret = mbedtls_snprintf(p, n, "\ndNSName : ");
MBEDTLS_X509_SAFE_SNPRINTF;
- if( san->san.unstructured_name.len >= n )
- {
+ if (san->san.unstructured_name.len >= n) {
*p = '\0';
- return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL );
+ return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
}
n -= san->san.unstructured_name.len;
- for( i = 0; i < san->san.unstructured_name.len; i++ )
+ for (i = 0; i < san->san.unstructured_name.len; i++) {
*p++ = san->san.unstructured_name.p[i];
- break;/* MBEDTLS_X509_SAN_DNS_NAME */
+ }
+ break;/* MBEDTLS_X509_SAN_DNS_NAME */
default:
- /*
- * Should not happen.
- */
- return( -1 );
+ /*
+ * Should not happen.
+ */
+ return -1;
}
- ret = mbedtls_snprintf( p, n, "\n" );
+ ret = mbedtls_snprintf(p, n, "\n");
MBEDTLS_X509_SAFE_SNPRINTF;
*size = n;
*buf = p;
- return( 0 );
+ return 0;
}
-int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf const *oid,
- int critical, const unsigned char *cp, const unsigned char *end )
+int parse_crt_ext_cb(void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf const *oid,
+ int critical, const unsigned char *cp, const unsigned char *end)
{
- ( void ) crt;
- ( void ) critical;
- mbedtls_x509_buf *new_oid = (mbedtls_x509_buf *)p_ctx;
- if( oid->tag == MBEDTLS_ASN1_OID &&
- MBEDTLS_OID_CMP( MBEDTLS_OID_CERTIFICATE_POLICIES, oid ) == 0 )
- {
+ (void) crt;
+ (void) critical;
+ mbedtls_x509_buf *new_oid = (mbedtls_x509_buf *) p_ctx;
+ if (oid->tag == MBEDTLS_ASN1_OID &&
+ MBEDTLS_OID_CMP(MBEDTLS_OID_CERTIFICATE_POLICIES, oid) == 0) {
/* Handle unknown certificate policy */
int ret, parse_ret = 0;
size_t len;
- unsigned char **p = (unsigned char **)&cp;
+ unsigned char **p = (unsigned char **) &cp;
/* Get main sequence tag */
- ret = mbedtls_asn1_get_tag( p, end, &len,
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE );
- if( ret != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ ret = mbedtls_asn1_get_tag(p, end, &len,
+ MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
+ if (ret != 0) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+ }
- if( *p + len != end )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
+ if (*p + len != end) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+ }
/*
* Cannot be an empty sequence.
*/
- if( len == 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
+ if (len == 0) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+ }
- while( *p < end )
- {
+ while (*p < end) {
const unsigned char *policy_end;
/*
* Get the policy sequence
*/
- if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ if ((ret = mbedtls_asn1_get_tag(p, end, &len,
+ MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) !=
+ 0) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+ }
policy_end = *p + len;
- if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len,
- MBEDTLS_ASN1_OID ) ) != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len,
+ MBEDTLS_ASN1_OID)) != 0) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+ }
/*
* Recognize exclusively the policy with OID 1
*/
- if( len != 1 || *p[0] != 1 )
+ if (len != 1 || *p[0] != 1) {
parse_ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
+ }
*p += len;
- /*
- * If there is an optional qualifier, then *p < policy_end
- * Check the Qualifier len to verify it doesn't exceed policy_end.
- */
- if( *p < policy_end )
- {
- if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len,
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
+ /*
+ * If there is an optional qualifier, then *p < policy_end
+ * Check the Qualifier len to verify it doesn't exceed policy_end.
+ */
+ if (*p < policy_end) {
+ if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len,
+ MBEDTLS_ASN1_CONSTRUCTED |
+ MBEDTLS_ASN1_SEQUENCE)) != 0) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
+ }
/*
* Skip the optional policy qualifiers.
*/
*p += len;
}
- if( *p != policy_end )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
+ if (*p != policy_end) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+ }
}
- if( *p != end )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
+ if (*p != end) {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
+ }
- return( parse_ret );
+ return parse_ret;
+ } else if (new_oid != NULL && new_oid->tag == oid->tag && new_oid->len == oid->len &&
+ memcmp(new_oid->p, oid->p, oid->len) == 0) {
+ return 0;
+ } else {
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
+ MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
}
- else if( new_oid != NULL && new_oid->tag == oid->tag && new_oid->len == oid->len &&
- memcmp( new_oid->p, oid->p, oid->len ) == 0 )
- return( 0 );
- else
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
- MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
}
#endif /* MBEDTLS_X509_CRT_PARSE_C */
/* END_HEADER */
@@ -398,23 +400,23 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
-void x509_accessor_ext_types( int ext_type, int has_ext_type )
+void x509_accessor_ext_types(int ext_type, int has_ext_type)
{
mbedtls_x509_crt crt;
int expected_result = ext_type & has_ext_type;
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
crt.ext_types = ext_type;
- TEST_ASSERT( mbedtls_x509_crt_has_ext_type( &crt, has_ext_type ) == expected_result );
+ TEST_ASSERT(mbedtls_x509_crt_has_ext_type(&crt, has_ext_type) == expected_result);
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void x509_parse_san( char * crt_file, char * result_str )
+void x509_parse_san(char *crt_file, char *result_str)
{
int ret;
mbedtls_x509_crt crt;
@@ -422,142 +424,141 @@
mbedtls_x509_sequence *cur = NULL;
char buf[2000];
char *p = buf;
- size_t n = sizeof( buf );
+ size_t n = sizeof(buf);
- mbedtls_x509_crt_init( &crt );
- memset( buf, 0, 2000 );
+ mbedtls_x509_crt_init(&crt);
+ memset(buf, 0, 2000);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
- if( crt.ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME )
- {
+ if (crt.ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME) {
cur = &crt.subject_alt_names;
- while( cur != NULL )
- {
- ret = mbedtls_x509_parse_subject_alt_name( &cur->buf, &san );
- TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE );
+ while (cur != NULL) {
+ ret = mbedtls_x509_parse_subject_alt_name(&cur->buf, &san);
+ TEST_ASSERT(ret == 0 || ret == MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE);
/*
* If san type not supported, ignore.
*/
- if( ret == 0)
- TEST_ASSERT( verify_parse_san( &san, &p, &n ) == 0 );
+ if (ret == 0) {
+ TEST_ASSERT(verify_parse_san(&san, &p, &n) == 0);
+ }
cur = cur->next;
}
}
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:!MBEDTLS_X509_REMOVE_INFO:MBEDTLS_X509_CRT_PARSE_C */
-void x509_cert_info( char * crt_file, char * result_str )
+void x509_cert_info(char *crt_file, char *result_str)
{
mbedtls_x509_crt crt;
char buf[2000];
int res;
- mbedtls_x509_crt_init( &crt );
- memset( buf, 0, 2000 );
+ mbedtls_x509_crt_init(&crt);
+ memset(buf, 0, 2000);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
- res = mbedtls_x509_crt_info( buf, 2000, "", &crt );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
+ res = mbedtls_x509_crt_info(buf, 2000, "", &crt);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void mbedtls_x509_crl_info( char * crl_file, char * result_str )
+void mbedtls_x509_crl_info(char *crl_file, char *result_str)
{
mbedtls_x509_crl crl;
char buf[2000];
int res;
- mbedtls_x509_crl_init( &crl );
- memset( buf, 0, 2000 );
+ mbedtls_x509_crl_init(&crl);
+ memset(buf, 0, 2000);
- TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 );
- res = mbedtls_x509_crl_info( buf, 2000, "", &crl );
+ TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == 0);
+ res = mbedtls_x509_crl_info(buf, 2000, "", &crl);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
exit:
- mbedtls_x509_crl_free( &crl );
+ mbedtls_x509_crl_free(&crl);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */
-void mbedtls_x509_crl_parse( char * crl_file, int result )
+void mbedtls_x509_crl_parse(char *crl_file, int result)
{
mbedtls_x509_crl crl;
char buf[2000];
- mbedtls_x509_crl_init( &crl );
- memset( buf, 0, 2000 );
+ mbedtls_x509_crl_init(&crl);
+ memset(buf, 0, 2000);
- TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == result );
+ TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == result);
exit:
- mbedtls_x509_crl_free( &crl );
+ mbedtls_x509_crl_free(&crl);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void mbedtls_x509_csr_info( char * csr_file, char * result_str )
+void mbedtls_x509_csr_info(char *csr_file, char *result_str)
{
mbedtls_x509_csr csr;
char buf[2000];
int res;
- mbedtls_x509_csr_init( &csr );
- memset( buf, 0, 2000 );
+ mbedtls_x509_csr_init(&csr);
+ memset(buf, 0, 2000);
- TEST_ASSERT( mbedtls_x509_csr_parse_file( &csr, csr_file ) == 0 );
- res = mbedtls_x509_csr_info( buf, 2000, "", &csr );
+ TEST_ASSERT(mbedtls_x509_csr_parse_file(&csr, csr_file) == 0);
+ res = mbedtls_x509_csr_info(buf, 2000, "", &csr);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
exit:
- mbedtls_x509_csr_free( &csr );
+ mbedtls_x509_csr_free(&csr);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void x509_verify_info( int flags, char * prefix, char * result_str )
+void x509_verify_info(int flags, char *prefix, char *result_str)
{
char buf[2000];
int res;
- memset( buf, 0, sizeof( buf ) );
+ memset(buf, 0, sizeof(buf));
- res = mbedtls_x509_crt_verify_info( buf, sizeof( buf ), prefix, flags );
+ res = mbedtls_x509_crt_verify_info(buf, sizeof(buf), prefix, flags);
- TEST_ASSERT( res >= 0 );
+ TEST_ASSERT(res >= 0);
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C:MBEDTLS_ECP_RESTARTABLE:MBEDTLS_ECDSA_C */
-void x509_verify_restart( char *crt_file, char *ca_file,
- int result, int flags_result,
- int max_ops, int min_restart, int max_restart )
+void x509_verify_restart(char *crt_file, char *ca_file,
+ int result, int flags_result,
+ int max_ops, int min_restart, int max_restart)
{
int ret, cnt_restart;
mbedtls_x509_crt_restart_ctx rs_ctx;
@@ -575,49 +576,49 @@
* - x509_verify() for server10 -> int-ca3 -> int-ca2: ~ 25500
*/
- mbedtls_x509_crt_restart_init( &rs_ctx );
- mbedtls_x509_crt_init( &crt );
- mbedtls_x509_crt_init( &ca );
+ mbedtls_x509_crt_restart_init(&rs_ctx);
+ mbedtls_x509_crt_init(&crt);
+ mbedtls_x509_crt_init(&ca);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0);
- mbedtls_ecp_set_max_ops( max_ops );
+ mbedtls_ecp_set_max_ops(max_ops);
cnt_restart = 0;
do {
- ret = mbedtls_x509_crt_verify_restartable( &crt, &ca, NULL,
- &mbedtls_x509_crt_profile_default, NULL, &flags,
- NULL, NULL, &rs_ctx );
- } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
+ ret = mbedtls_x509_crt_verify_restartable(&crt, &ca, NULL,
+ &mbedtls_x509_crt_profile_default, NULL, &flags,
+ NULL, NULL, &rs_ctx);
+ } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart);
- TEST_ASSERT( ret == result );
- TEST_ASSERT( flags == (uint32_t) flags_result );
+ TEST_ASSERT(ret == result);
+ TEST_ASSERT(flags == (uint32_t) flags_result);
- TEST_ASSERT( cnt_restart >= min_restart );
- TEST_ASSERT( cnt_restart <= max_restart );
+ TEST_ASSERT(cnt_restart >= min_restart);
+ TEST_ASSERT(cnt_restart <= max_restart);
/* Do we leak memory when aborting? */
- ret = mbedtls_x509_crt_verify_restartable( &crt, &ca, NULL,
- &mbedtls_x509_crt_profile_default, NULL, &flags,
- NULL, NULL, &rs_ctx );
- TEST_ASSERT( ret == result || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
+ ret = mbedtls_x509_crt_verify_restartable(&crt, &ca, NULL,
+ &mbedtls_x509_crt_profile_default, NULL, &flags,
+ NULL, NULL, &rs_ctx);
+ TEST_ASSERT(ret == result || ret == MBEDTLS_ERR_ECP_IN_PROGRESS);
exit:
- mbedtls_x509_crt_restart_free( &rs_ctx );
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_free( &ca );
- USE_PSA_DONE( );
+ mbedtls_x509_crt_restart_free(&rs_ctx);
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_free(&ca);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C */
-void x509_verify( char *crt_file, char *ca_file, char *crl_file,
- char *cn_name_str, int result, int flags_result,
- char *profile_str,
- char *verify_callback )
+void x509_verify(char *crt_file, char *ca_file, char *crl_file,
+ char *cn_name_str, int result, int flags_result,
+ char *profile_str,
+ char *verify_callback)
{
mbedtls_x509_crt crt;
mbedtls_x509_crt ca;
@@ -625,103 +626,120 @@
uint32_t flags = 0;
int res;
int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *) = NULL;
- char * cn_name = NULL;
+ char *cn_name = NULL;
const mbedtls_x509_crt_profile *profile;
- mbedtls_x509_crt_init( &crt );
- mbedtls_x509_crt_init( &ca );
- mbedtls_x509_crl_init( &crl );
+ mbedtls_x509_crt_init(&crt);
+ mbedtls_x509_crt_init(&ca);
+ mbedtls_x509_crl_init(&crl);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- if( strcmp( cn_name_str, "NULL" ) != 0 )
+ if (strcmp(cn_name_str, "NULL") != 0) {
cn_name = cn_name_str;
+ }
- if( strcmp( profile_str, "" ) == 0 )
+ if (strcmp(profile_str, "") == 0) {
profile = &mbedtls_x509_crt_profile_default;
- else if( strcmp( profile_str, "next" ) == 0 )
+ } else if (strcmp(profile_str, "next") == 0) {
profile = &mbedtls_x509_crt_profile_next;
- else if( strcmp( profile_str, "suite_b" ) == 0 )
+ } else if (strcmp(profile_str, "suite_b") == 0) {
profile = &mbedtls_x509_crt_profile_suiteb;
- else if( strcmp( profile_str, "compat" ) == 0 )
+ } else if (strcmp(profile_str, "compat") == 0) {
profile = &compat_profile;
- else if( strcmp( profile_str, "all" ) == 0 )
+ } else if (strcmp(profile_str, "all") == 0) {
profile = &profile_all;
- else
- TEST_ASSERT( "Unknown algorithm profile" == 0 );
+ } else {
+ TEST_ASSERT("Unknown algorithm profile" == 0);
+ }
- if( strcmp( verify_callback, "NULL" ) == 0 )
+ if (strcmp(verify_callback, "NULL") == 0) {
f_vrfy = NULL;
- else if( strcmp( verify_callback, "verify_none" ) == 0 )
+ } else if (strcmp(verify_callback, "verify_none") == 0) {
f_vrfy = verify_none;
- else if( strcmp( verify_callback, "verify_all" ) == 0 )
+ } else if (strcmp(verify_callback, "verify_all") == 0) {
f_vrfy = verify_all;
- else
- TEST_ASSERT( "No known verify callback selected" == 0 );
+ } else {
+ TEST_ASSERT("No known verify callback selected" == 0);
+ }
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
- TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0);
+ TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == 0);
- res = mbedtls_x509_crt_verify_with_profile( &crt, &ca, &crl, profile, cn_name, &flags, f_vrfy, NULL );
+ res = mbedtls_x509_crt_verify_with_profile(&crt,
+ &ca,
+ &crl,
+ profile,
+ cn_name,
+ &flags,
+ f_vrfy,
+ NULL);
- TEST_EQUAL( res, result );
- TEST_EQUAL( flags, (uint32_t) flags_result );
+ TEST_EQUAL(res, result);
+ TEST_EQUAL(flags, (uint32_t) flags_result);
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
/* CRLs aren't supported with CA callbacks, so skip the CA callback
* version of the test if CRLs are in use. */
- if( crl_file == NULL || strcmp( crl_file, "" ) == 0 )
- {
+ if (crl_file == NULL || strcmp(crl_file, "") == 0) {
flags = 0;
- res = mbedtls_x509_crt_verify_with_ca_cb( &crt, ca_callback, &ca, profile, cn_name, &flags, f_vrfy, NULL );
+ res = mbedtls_x509_crt_verify_with_ca_cb(&crt,
+ ca_callback,
+ &ca,
+ profile,
+ cn_name,
+ &flags,
+ f_vrfy,
+ NULL);
- TEST_ASSERT( res == ( result ) );
- TEST_ASSERT( flags == (uint32_t)( flags_result ) );
+ TEST_ASSERT(res == (result));
+ TEST_ASSERT(flags == (uint32_t) (flags_result));
}
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
exit:
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_free( &ca );
- mbedtls_x509_crl_free( &crl );
- USE_PSA_DONE( );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_free(&ca);
+ mbedtls_x509_crl_free(&crl);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C:MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
-void x509_verify_ca_cb_failure( char *crt_file, char *ca_file, char *name,
- int exp_ret )
+void x509_verify_ca_cb_failure(char *crt_file, char *ca_file, char *name,
+ int exp_ret)
{
int ret;
mbedtls_x509_crt crt;
mbedtls_x509_crt ca;
uint32_t flags = 0;
- mbedtls_x509_crt_init( &crt );
- mbedtls_x509_crt_init( &ca );
+ mbedtls_x509_crt_init(&crt);
+ mbedtls_x509_crt_init(&ca);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0);
- if( strcmp( name, "NULL" ) == 0 )
+ if (strcmp(name, "NULL") == 0) {
name = NULL;
+ }
- ret = mbedtls_x509_crt_verify_with_ca_cb( &crt, ca_callback_fail, &ca,
- &compat_profile, name, &flags,
- NULL, NULL );
+ ret = mbedtls_x509_crt_verify_with_ca_cb(&crt, ca_callback_fail, &ca,
+ &compat_profile, name, &flags,
+ NULL, NULL);
- TEST_ASSERT( ret == exp_ret );
- TEST_ASSERT( flags == (uint32_t)( -1 ) );
+ TEST_ASSERT(ret == exp_ret);
+ TEST_ASSERT(flags == (uint32_t) (-1));
exit:
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_free( &ca );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_free(&ca);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void x509_verify_callback( char *crt_file, char *ca_file, char *name,
- int exp_ret, char *exp_vrfy_out )
+void x509_verify_callback(char *crt_file, char *ca_file, char *name,
+ int exp_ret, char *exp_vrfy_out)
{
int ret;
mbedtls_x509_crt crt;
@@ -729,94 +747,96 @@
uint32_t flags = 0;
verify_print_context vrfy_ctx;
- mbedtls_x509_crt_init( &crt );
- mbedtls_x509_crt_init( &ca );
- verify_print_init( &vrfy_ctx );
+ mbedtls_x509_crt_init(&crt);
+ mbedtls_x509_crt_init(&ca);
+ verify_print_init(&vrfy_ctx);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0);
- if( strcmp( name, "NULL" ) == 0 )
+ if (strcmp(name, "NULL") == 0) {
name = NULL;
+ }
- ret = mbedtls_x509_crt_verify_with_profile( &crt, &ca, NULL,
- &compat_profile,
- name, &flags,
- verify_print, &vrfy_ctx );
+ ret = mbedtls_x509_crt_verify_with_profile(&crt, &ca, NULL,
+ &compat_profile,
+ name, &flags,
+ verify_print, &vrfy_ctx);
- TEST_ASSERT( ret == exp_ret );
- TEST_ASSERT( strcmp( vrfy_ctx.buf, exp_vrfy_out ) == 0 );
+ TEST_ASSERT(ret == exp_ret);
+ TEST_ASSERT(strcmp(vrfy_ctx.buf, exp_vrfy_out) == 0);
exit:
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_free( &ca );
- USE_PSA_DONE( );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_free(&ca);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void mbedtls_x509_dn_gets_subject_replace( char * crt_file, char * new_subject_ou, char * result_str, int ret )
+void mbedtls_x509_dn_gets_subject_replace(char *crt_file,
+ char *new_subject_ou,
+ char *result_str,
+ int ret)
{
mbedtls_x509_crt crt;
char buf[2000];
int res = 0;
- mbedtls_x509_crt_init( &crt );
- memset( buf, 0, 2000 );
+ mbedtls_x509_crt_init(&crt);
+ memset(buf, 0, 2000);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
crt.subject.next->val.p = (unsigned char *) new_subject_ou;
- crt.subject.next->val.len = strlen( new_subject_ou );
+ crt.subject.next->val.len = strlen(new_subject_ou);
- res = mbedtls_x509_dn_gets( buf, 2000, &crt.subject );
+ res = mbedtls_x509_dn_gets(buf, 2000, &crt.subject);
- if ( ret != 0 )
- {
- TEST_ASSERT( res == ret );
- }
- else
- {
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ if (ret != 0) {
+ TEST_ASSERT(res == ret);
+ } else {
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
}
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void mbedtls_x509_dn_gets( char * crt_file, char * entity, char * result_str )
+void mbedtls_x509_dn_gets(char *crt_file, char *entity, char *result_str)
{
mbedtls_x509_crt crt;
char buf[2000];
int res = 0;
- mbedtls_x509_crt_init( &crt );
- memset( buf, 0, 2000 );
+ mbedtls_x509_crt_init(&crt);
+ memset(buf, 0, 2000);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
- if( strcmp( entity, "subject" ) == 0 )
- res = mbedtls_x509_dn_gets( buf, 2000, &crt.subject );
- else if( strcmp( entity, "issuer" ) == 0 )
- res = mbedtls_x509_dn_gets( buf, 2000, &crt.issuer );
- else
- TEST_ASSERT( "Unknown entity" == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
+ if (strcmp(entity, "subject") == 0) {
+ res = mbedtls_x509_dn_gets(buf, 2000, &crt.subject);
+ } else if (strcmp(entity, "issuer") == 0) {
+ res = mbedtls_x509_dn_gets(buf, 2000, &crt.issuer);
+ } else {
+ TEST_ASSERT("Unknown entity" == 0);
+ }
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+ TEST_ASSERT(strcmp(buf, result_str) == 0);
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
-void mbedtls_x509_get_name( char * rdn_sequence, int exp_ret )
+void mbedtls_x509_get_name(char *rdn_sequence, int exp_ret)
{
unsigned char *name;
unsigned char *p;
@@ -824,23 +844,28 @@
mbedtls_x509_name head;
int ret;
- memset( &head, 0, sizeof( head ) );
+ memset(&head, 0, sizeof(head));
- name = mbedtls_test_unhexify_alloc( rdn_sequence, &name_len );
+ name = mbedtls_test_unhexify_alloc(rdn_sequence, &name_len);
p = name;
- ret = mbedtls_x509_get_name( &p, ( name + name_len ), &head );
- if( ret == 0 )
- mbedtls_asn1_free_named_data_list_shallow( head.next );
+ ret = mbedtls_x509_get_name(&p, (name + name_len), &head);
+ if (ret == 0) {
+ mbedtls_asn1_free_named_data_list_shallow(head.next);
+ }
- TEST_EQUAL( ret, exp_ret );
+ TEST_EQUAL(ret, exp_ret);
- mbedtls_free( name );
+ mbedtls_free(name);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CREATE_C:MBEDTLS_X509_USE_C:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void mbedtls_x509_dn_get_next( char * name_str, int next_merged, char * expected_oids, int exp_count, char * exp_dn_gets )
+void mbedtls_x509_dn_get_next(char *name_str,
+ int next_merged,
+ char *expected_oids,
+ int exp_count,
+ char *exp_dn_gets)
{
int ret = 0, i;
size_t len = 0, out_size;
@@ -850,26 +875,25 @@
unsigned char buf[80], *out = NULL, *c;
const char *short_name;
- memset( &parsed, 0, sizeof( parsed ) );
- memset( buf, 0, sizeof( buf ) );
- c = buf + sizeof( buf );
+ memset(&parsed, 0, sizeof(parsed));
+ memset(buf, 0, sizeof(buf));
+ c = buf + sizeof(buf);
// Additional size required for trailing space
- out_size = strlen( expected_oids ) + 2;
- ASSERT_ALLOC( out, out_size );
+ out_size = strlen(expected_oids) + 2;
+ ASSERT_ALLOC(out, out_size);
- TEST_EQUAL( mbedtls_x509_string_to_names( &names, name_str ), 0 );
+ TEST_EQUAL(mbedtls_x509_string_to_names(&names, name_str), 0);
- ret = mbedtls_x509_write_names( &c, buf, names );
- TEST_LE_S( 0, ret );
+ ret = mbedtls_x509_write_names(&c, buf, names);
+ TEST_LE_S(0, ret);
- TEST_EQUAL( mbedtls_asn1_get_tag( &c, buf + sizeof( buf ), &len,
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ), 0 );
- TEST_EQUAL( mbedtls_x509_get_name( &c, buf + sizeof( buf ), &parsed ), 0 );
+ TEST_EQUAL(mbedtls_asn1_get_tag(&c, buf + sizeof(buf), &len,
+ MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE), 0);
+ TEST_EQUAL(mbedtls_x509_get_name(&c, buf + sizeof(buf), &parsed), 0);
// Iterate over names and set next_merged nodes
parsed_cur = &parsed;
- for( ; next_merged != 0 && parsed_cur != NULL; next_merged = next_merged >> 1 )
- {
+ for (; next_merged != 0 && parsed_cur != NULL; next_merged = next_merged >> 1) {
parsed_cur->next_merged = next_merged & 0x01;
parsed_cur = parsed_cur->next;
}
@@ -877,90 +901,91 @@
// Iterate over RDN nodes and print OID of first element to buffer
parsed_cur = &parsed;
len = 0;
- for( i = 0; parsed_cur != NULL; i++ )
- {
- TEST_EQUAL( mbedtls_oid_get_attr_short_name( &parsed_cur->oid,
- &short_name ), 0 );
- len += mbedtls_snprintf( (char*) out + len, out_size - len, "%s ", short_name );
- parsed_cur = mbedtls_x509_dn_get_next( parsed_cur );
+ for (i = 0; parsed_cur != NULL; i++) {
+ TEST_EQUAL(mbedtls_oid_get_attr_short_name(&parsed_cur->oid,
+ &short_name), 0);
+ len += mbedtls_snprintf((char *) out + len, out_size - len, "%s ", short_name);
+ parsed_cur = mbedtls_x509_dn_get_next(parsed_cur);
}
out[len-1] = 0;
- TEST_EQUAL( exp_count, i );
- TEST_EQUAL( strcmp( (char *) out, expected_oids ), 0 );
- mbedtls_free( out );
+ TEST_EQUAL(exp_count, i);
+ TEST_EQUAL(strcmp((char *) out, expected_oids), 0);
+ mbedtls_free(out);
out = NULL;
- out_size = strlen( exp_dn_gets ) + 1;
- ASSERT_ALLOC( out, out_size );
+ out_size = strlen(exp_dn_gets) + 1;
+ ASSERT_ALLOC(out, out_size);
- TEST_LE_S( 0, mbedtls_x509_dn_gets( (char *) out, out_size, &parsed ) );
- TEST_EQUAL( strcmp( (char *) out, exp_dn_gets ), 0 );
+ TEST_LE_S(0, mbedtls_x509_dn_gets((char *) out, out_size, &parsed));
+ TEST_EQUAL(strcmp((char *) out, exp_dn_gets), 0);
exit:
- mbedtls_free( out );
- mbedtls_asn1_free_named_data_list( &names );
- mbedtls_asn1_free_named_data_list_shallow( parsed.next );
+ mbedtls_free(out);
+ mbedtls_asn1_free_named_data_list(&names);
+ mbedtls_asn1_free_named_data_list_shallow(parsed.next);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void mbedtls_x509_time_is_past( char * crt_file, char * entity, int result )
+void mbedtls_x509_time_is_past(char *crt_file, char *entity, int result)
{
mbedtls_x509_crt crt;
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
- if( strcmp( entity, "valid_from" ) == 0 )
- TEST_ASSERT( mbedtls_x509_time_is_past( &crt.valid_from ) == result );
- else if( strcmp( entity, "valid_to" ) == 0 )
- TEST_ASSERT( mbedtls_x509_time_is_past( &crt.valid_to ) == result );
- else
- TEST_ASSERT( "Unknown entity" == 0 );
+ if (strcmp(entity, "valid_from") == 0) {
+ TEST_ASSERT(mbedtls_x509_time_is_past(&crt.valid_from) == result);
+ } else if (strcmp(entity, "valid_to") == 0) {
+ TEST_ASSERT(mbedtls_x509_time_is_past(&crt.valid_to) == result);
+ } else {
+ TEST_ASSERT("Unknown entity" == 0);
+ }
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void mbedtls_x509_time_is_future( char * crt_file, char * entity, int result )
+void mbedtls_x509_time_is_future(char *crt_file, char *entity, int result)
{
mbedtls_x509_crt crt;
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
- if( strcmp( entity, "valid_from" ) == 0 )
- TEST_ASSERT( mbedtls_x509_time_is_future( &crt.valid_from ) == result );
- else if( strcmp( entity, "valid_to" ) == 0 )
- TEST_ASSERT( mbedtls_x509_time_is_future( &crt.valid_to ) == result );
- else
- TEST_ASSERT( "Unknown entity" == 0 );
+ if (strcmp(entity, "valid_from") == 0) {
+ TEST_ASSERT(mbedtls_x509_time_is_future(&crt.valid_from) == result);
+ } else if (strcmp(entity, "valid_to") == 0) {
+ TEST_ASSERT(mbedtls_x509_time_is_future(&crt.valid_to) == result);
+ } else {
+ TEST_ASSERT("Unknown entity" == 0);
+ }
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */
-void x509parse_crt_file( char * crt_file, int result )
+void x509parse_crt_file(char *crt_file, int result)
{
mbedtls_x509_crt crt;
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == result );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == result);
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
-void x509parse_crt( data_t * buf, char * result_str, int result )
+void x509parse_crt(data_t *buf, char *result_str, int result)
{
mbedtls_x509_crt crt;
#if !defined(MBEDTLS_X509_REMOVE_INFO)
@@ -970,80 +995,78 @@
((void) result_str);
#endif
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_der( &crt, buf->x, buf->len ) == ( result ) );
+ TEST_ASSERT(mbedtls_x509_crt_parse_der(&crt, buf->x, buf->len) == (result));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
- if( ( result ) == 0 )
- {
- res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ if ((result) == 0) {
+ res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
+ TEST_ASSERT(strcmp((char *) output, result_str) == 0);
}
- memset( output, 0, 2000 );
+ memset(output, 0, 2000);
#endif
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_der_nocopy( &crt, buf->x, buf->len ) == ( result ) );
+ TEST_ASSERT(mbedtls_x509_crt_parse_der_nocopy(&crt, buf->x, buf->len) == (result));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
- if( ( result ) == 0 )
- {
- memset( output, 0, 2000 );
+ if ((result) == 0) {
+ memset(output, 0, 2000);
- res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
+ res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
+ TEST_ASSERT(strcmp((char *) output, result_str) == 0);
}
- memset( output, 0, 2000 );
+ memset(output, 0, 2000);
#endif /* !MBEDTLS_X509_REMOVE_INFO */
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 0, NULL, NULL ) == ( result ) );
+ TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, NULL,
+ NULL) == (result));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
- if( ( result ) == 0 )
- {
- res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
+ if ((result) == 0) {
+ res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
+ TEST_ASSERT(strcmp((char *) output, result_str) == 0);
}
- memset( output, 0, 2000 );
+ memset(output, 0, 2000);
#endif /* !MBEDTLS_X509_REMOVE_INFO */
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 1, NULL, NULL ) == ( result ) );
+ TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, NULL,
+ NULL) == (result));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
- if( ( result ) == 0 )
- {
- res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
+ if ((result) == 0) {
+ res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
+ TEST_ASSERT(strcmp((char *) output, result_str) == 0);
}
#endif /* !MBEDTLS_X509_REMOVE_INFO */
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
-void x509parse_crt_cb( data_t * buf, char * result_str, int result )
+void x509parse_crt_cb(data_t *buf, char *result_str, int result)
{
mbedtls_x509_crt crt;
mbedtls_x509_buf oid;
@@ -1057,122 +1080,122 @@
oid.tag = MBEDTLS_ASN1_OID;
oid.len = MBEDTLS_OID_SIZE(MBEDTLS_OID_PKIX "\x01\x1F");
- oid.p = (unsigned char *)MBEDTLS_OID_PKIX "\x01\x1F";
+ oid.p = (unsigned char *) MBEDTLS_OID_PKIX "\x01\x1F";
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 0, parse_crt_ext_cb, &oid ) == ( result ) );
+ TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, parse_crt_ext_cb,
+ &oid) == (result));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
- if( ( result ) == 0 )
- {
- res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
+ if ((result) == 0) {
+ res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
+ TEST_ASSERT(strcmp((char *) output, result_str) == 0);
}
- memset( output, 0, 2000 );
+ memset(output, 0, 2000);
#endif /* !MBEDTLS_X509_REMOVE_INFO */
- mbedtls_x509_crt_free( &crt );
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_free(&crt);
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 1, parse_crt_ext_cb, &oid ) == ( result ) );
+ TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, parse_crt_ext_cb,
+ &oid) == (result));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
- if( ( result ) == 0 )
- {
- res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
+ if ((result) == 0) {
+ res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
+ TEST_ASSERT(strcmp((char *) output, result_str) == 0);
}
#endif /* !MBEDTLS_X509_REMOVE_INFO */
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void x509parse_crl( data_t * buf, char * result_str, int result )
+void x509parse_crl(data_t *buf, char *result_str, int result)
{
mbedtls_x509_crl crl;
unsigned char output[2000];
int res;
- mbedtls_x509_crl_init( &crl );
- memset( output, 0, 2000 );
+ mbedtls_x509_crl_init(&crl);
+ memset(output, 0, 2000);
- TEST_ASSERT( mbedtls_x509_crl_parse( &crl, buf->x, buf->len ) == ( result ) );
- if( ( result ) == 0 )
- {
- res = mbedtls_x509_crl_info( (char *) output, 2000, "", &crl );
+ TEST_ASSERT(mbedtls_x509_crl_parse(&crl, buf->x, buf->len) == (result));
+ if ((result) == 0) {
+ res = mbedtls_x509_crl_info((char *) output, 2000, "", &crl);
- TEST_ASSERT( res != -1 );
- TEST_ASSERT( res != -2 );
+ TEST_ASSERT(res != -1);
+ TEST_ASSERT(res != -2);
- TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
+ TEST_ASSERT(strcmp((char *) output, result_str) == 0);
}
exit:
- mbedtls_x509_crl_free( &crl );
+ mbedtls_x509_crl_free(&crl);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
-void mbedtls_x509_csr_parse( data_t * csr_der, char * ref_out, int ref_ret )
+void mbedtls_x509_csr_parse(data_t *csr_der, char *ref_out, int ref_ret)
{
mbedtls_x509_csr csr;
char my_out[1000];
int my_ret;
- mbedtls_x509_csr_init( &csr );
- memset( my_out, 0, sizeof( my_out ) );
+ mbedtls_x509_csr_init(&csr);
+ memset(my_out, 0, sizeof(my_out));
- my_ret = mbedtls_x509_csr_parse_der( &csr, csr_der->x, csr_der->len );
- TEST_ASSERT( my_ret == ref_ret );
+ my_ret = mbedtls_x509_csr_parse_der(&csr, csr_der->x, csr_der->len);
+ TEST_ASSERT(my_ret == ref_ret);
- if( ref_ret == 0 )
- {
- size_t my_out_len = mbedtls_x509_csr_info( my_out, sizeof( my_out ), "", &csr );
- TEST_ASSERT( my_out_len == strlen( ref_out ) );
- TEST_ASSERT( strcmp( my_out, ref_out ) == 0 );
+ if (ref_ret == 0) {
+ size_t my_out_len = mbedtls_x509_csr_info(my_out, sizeof(my_out), "", &csr);
+ TEST_ASSERT(my_out_len == strlen(ref_out));
+ TEST_ASSERT(strcmp(my_out, ref_out) == 0);
}
exit:
- mbedtls_x509_csr_free( &csr );
+ mbedtls_x509_csr_free(&csr);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void mbedtls_x509_crt_parse_path( char * crt_path, int ret, int nb_crt )
+void mbedtls_x509_crt_parse_path(char *crt_path, int ret, int nb_crt)
{
mbedtls_x509_crt chain, *cur;
int i;
- mbedtls_x509_crt_init( &chain );
+ mbedtls_x509_crt_init(&chain);
- TEST_ASSERT( mbedtls_x509_crt_parse_path( &chain, crt_path ) == ret );
+ TEST_ASSERT(mbedtls_x509_crt_parse_path(&chain, crt_path) == ret);
/* Check how many certs we got */
- for( i = 0, cur = &chain; cur != NULL; cur = cur->next )
- if( cur->raw.p != NULL )
+ for (i = 0, cur = &chain; cur != NULL; cur = cur->next) {
+ if (cur->raw.p != NULL) {
i++;
+ }
+ }
- TEST_ASSERT( i == nb_crt );
+ TEST_ASSERT(i == nb_crt);
exit:
- mbedtls_x509_crt_free( &chain );
+ mbedtls_x509_crt_free(&chain);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void mbedtls_x509_crt_verify_max( char *ca_file, char *chain_dir, int nb_int,
- int ret_chk, int flags_chk )
+void mbedtls_x509_crt_verify_max(char *ca_file, char *chain_dir, int nb_int,
+ int ret_chk, int flags_chk)
{
char file_buf[128];
int ret;
@@ -1184,80 +1207,82 @@
* with NN.crt signed by NN-1.crt
*/
- mbedtls_x509_crt_init( &trusted );
- mbedtls_x509_crt_init( &chain );
+ mbedtls_x509_crt_init(&trusted);
+ mbedtls_x509_crt_init(&chain);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
/* Load trusted root */
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &trusted, ca_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&trusted, ca_file) == 0);
/* Load a chain with nb_int intermediates (from 01 to nb_int),
* plus one "end-entity" cert (nb_int + 1) */
- ret = mbedtls_snprintf( file_buf, sizeof file_buf, "%s/c%02d.pem", chain_dir,
- nb_int + 1 );
- TEST_ASSERT( ret > 0 && (size_t) ret < sizeof file_buf );
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &chain, file_buf ) == 0 );
+ ret = mbedtls_snprintf(file_buf, sizeof file_buf, "%s/c%02d.pem", chain_dir,
+ nb_int + 1);
+ TEST_ASSERT(ret > 0 && (size_t) ret < sizeof file_buf);
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&chain, file_buf) == 0);
/* Try to verify that chain */
- ret = mbedtls_x509_crt_verify( &chain, &trusted, NULL, NULL, &flags,
- NULL, NULL );
- TEST_ASSERT( ret == ret_chk );
- TEST_ASSERT( flags == (uint32_t) flags_chk );
+ ret = mbedtls_x509_crt_verify(&chain, &trusted, NULL, NULL, &flags,
+ NULL, NULL);
+ TEST_ASSERT(ret == ret_chk);
+ TEST_ASSERT(flags == (uint32_t) flags_chk);
exit:
- mbedtls_x509_crt_free( &chain );
- mbedtls_x509_crt_free( &trusted );
- USE_PSA_DONE( );
+ mbedtls_x509_crt_free(&chain);
+ mbedtls_x509_crt_free(&trusted);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void mbedtls_x509_crt_verify_chain( char *chain_paths, char *trusted_ca,
- int flags_result, int result,
- char *profile_name, int vrfy_fatal_lvls )
+void mbedtls_x509_crt_verify_chain(char *chain_paths, char *trusted_ca,
+ int flags_result, int result,
+ char *profile_name, int vrfy_fatal_lvls)
{
- char* act;
+ char *act;
uint32_t flags;
int res;
mbedtls_x509_crt trusted, chain;
const mbedtls_x509_crt_profile *profile = NULL;
- mbedtls_x509_crt_init( &chain );
- mbedtls_x509_crt_init( &trusted );
+ mbedtls_x509_crt_init(&chain);
+ mbedtls_x509_crt_init(&trusted);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- while( ( act = mystrsep( &chain_paths, " " ) ) != NULL )
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &chain, act ) == 0 );
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &trusted, trusted_ca ) == 0 );
+ while ((act = mystrsep(&chain_paths, " ")) != NULL) {
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&chain, act) == 0);
+ }
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&trusted, trusted_ca) == 0);
- if( strcmp( profile_name, "" ) == 0 )
+ if (strcmp(profile_name, "") == 0) {
profile = &mbedtls_x509_crt_profile_default;
- else if( strcmp( profile_name, "next" ) == 0 )
+ } else if (strcmp(profile_name, "next") == 0) {
profile = &mbedtls_x509_crt_profile_next;
- else if( strcmp( profile_name, "suiteb" ) == 0 )
+ } else if (strcmp(profile_name, "suiteb") == 0) {
profile = &mbedtls_x509_crt_profile_suiteb;
- else if( strcmp( profile_name, "rsa3072" ) == 0 )
+ } else if (strcmp(profile_name, "rsa3072") == 0) {
profile = &profile_rsa3072;
- else if( strcmp( profile_name, "sha512" ) == 0 )
+ } else if (strcmp(profile_name, "sha512") == 0) {
profile = &profile_sha512;
+ }
- res = mbedtls_x509_crt_verify_with_profile( &chain, &trusted, NULL, profile,
- NULL, &flags, verify_fatal, &vrfy_fatal_lvls );
+ res = mbedtls_x509_crt_verify_with_profile(&chain, &trusted, NULL, profile,
+ NULL, &flags, verify_fatal, &vrfy_fatal_lvls);
- TEST_ASSERT( res == ( result ) );
- TEST_ASSERT( flags == (uint32_t)( flags_result ) );
+ TEST_ASSERT(res == (result));
+ TEST_ASSERT(flags == (uint32_t) (flags_result));
exit:
- mbedtls_x509_crt_free( &trusted );
- mbedtls_x509_crt_free( &chain );
- USE_PSA_DONE( );
+ mbedtls_x509_crt_free(&trusted);
+ mbedtls_x509_crt_free(&chain);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C:!MBEDTLS_X509_REMOVE_INFO */
-void x509_oid_desc( data_t * buf, char * ref_desc )
+void x509_oid_desc(data_t *buf, char *ref_desc)
{
mbedtls_x509_buf oid;
const char *desc = NULL;
@@ -1268,114 +1293,110 @@
oid.p = buf->x;
oid.len = buf->len;
- ret = mbedtls_oid_get_extended_key_usage( &oid, &desc );
+ ret = mbedtls_oid_get_extended_key_usage(&oid, &desc);
- if( strcmp( ref_desc, "notfound" ) == 0 )
- {
- TEST_ASSERT( ret != 0 );
- TEST_ASSERT( desc == NULL );
- }
- else
- {
- TEST_ASSERT( ret == 0 );
- TEST_ASSERT( desc != NULL );
- TEST_ASSERT( strcmp( desc, ref_desc ) == 0 );
+ if (strcmp(ref_desc, "notfound") == 0) {
+ TEST_ASSERT(ret != 0);
+ TEST_ASSERT(desc == NULL);
+ } else {
+ TEST_ASSERT(ret == 0);
+ TEST_ASSERT(desc != NULL);
+ TEST_ASSERT(strcmp(desc, ref_desc) == 0);
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
-void x509_oid_numstr( data_t * oid_buf, char * numstr, int blen, int ret )
+void x509_oid_numstr(data_t *oid_buf, char *numstr, int blen, int ret)
{
mbedtls_x509_buf oid;
char num_buf[100];
- memset( num_buf, 0x2a, sizeof num_buf );
+ memset(num_buf, 0x2a, sizeof num_buf);
oid.tag = MBEDTLS_ASN1_OID;
oid.p = oid_buf->x;
oid.len = oid_buf->len;
- TEST_ASSERT( (size_t) blen <= sizeof num_buf );
+ TEST_ASSERT((size_t) blen <= sizeof num_buf);
- TEST_ASSERT( mbedtls_oid_get_numeric_string( num_buf, blen, &oid ) == ret );
+ TEST_ASSERT(mbedtls_oid_get_numeric_string(num_buf, blen, &oid) == ret);
- if( ret >= 0 )
- {
- TEST_ASSERT( num_buf[ret] == 0 );
- TEST_ASSERT( strcmp( num_buf, numstr ) == 0 );
+ if (ret >= 0) {
+ TEST_ASSERT(num_buf[ret] == 0);
+ TEST_ASSERT(strcmp(num_buf, numstr) == 0);
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void x509_check_key_usage( char * crt_file, int usage, int ret )
+void x509_check_key_usage(char *crt_file, int usage, int ret)
{
mbedtls_x509_crt crt;
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
- TEST_ASSERT( mbedtls_x509_crt_check_key_usage( &crt, usage ) == ret );
+ TEST_ASSERT(mbedtls_x509_crt_check_key_usage(&crt, usage) == ret);
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
-void x509_check_extended_key_usage( char * crt_file, data_t * oid, int ret
- )
+void x509_check_extended_key_usage(char *crt_file, data_t *oid, int ret
+ )
{
mbedtls_x509_crt crt;
- mbedtls_x509_crt_init( &crt );
+ mbedtls_x509_crt_init(&crt);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
- TEST_ASSERT( mbedtls_x509_crt_check_extended_key_usage( &crt, (const char *)oid->x, oid->len ) == ret );
+ TEST_ASSERT(mbedtls_x509_crt_check_extended_key_usage(&crt, (const char *) oid->x,
+ oid->len) == ret);
exit:
- mbedtls_x509_crt_free( &crt );
+ mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
-void x509_get_time( int tag, char * time_str, int ret, int year, int mon,
- int day, int hour, int min, int sec )
+void x509_get_time(int tag, char *time_str, int ret, int year, int mon,
+ int day, int hour, int min, int sec)
{
mbedtls_x509_time time;
unsigned char buf[21];
- unsigned char* start = buf;
- unsigned char* end = buf;
+ unsigned char *start = buf;
+ unsigned char *end = buf;
- memset( &time, 0x00, sizeof( time ) );
- *end = (unsigned char)tag; end++;
- *end = strlen( time_str );
- TEST_ASSERT( *end < 20 );
+ memset(&time, 0x00, sizeof(time));
+ *end = (unsigned char) tag; end++;
+ *end = strlen(time_str);
+ TEST_ASSERT(*end < 20);
end++;
- memcpy( end, time_str, (size_t)*(end - 1) );
+ memcpy(end, time_str, (size_t) *(end - 1));
end += *(end - 1);
- TEST_ASSERT( mbedtls_x509_get_time( &start, end, &time ) == ret );
- if( ret == 0 )
- {
- TEST_ASSERT( year == time.year );
- TEST_ASSERT( mon == time.mon );
- TEST_ASSERT( day == time.day );
- TEST_ASSERT( hour == time.hour );
- TEST_ASSERT( min == time.min );
- TEST_ASSERT( sec == time.sec );
+ TEST_ASSERT(mbedtls_x509_get_time(&start, end, &time) == ret);
+ if (ret == 0) {
+ TEST_ASSERT(year == time.year);
+ TEST_ASSERT(mon == time.mon);
+ TEST_ASSERT(day == time.day);
+ TEST_ASSERT(hour == time.hour);
+ TEST_ASSERT(min == time.min);
+ TEST_ASSERT(sec == time.sec);
}
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */
-void x509_parse_rsassa_pss_params( data_t * params, int params_tag,
- int ref_msg_md, int ref_mgf_md,
- int ref_salt_len, int ref_ret )
+void x509_parse_rsassa_pss_params(data_t *params, int params_tag,
+ int ref_msg_md, int ref_mgf_md,
+ int ref_salt_len, int ref_ret)
{
int my_ret;
mbedtls_x509_buf buf;
@@ -1386,16 +1407,15 @@
buf.len = params->len;
buf.tag = params_tag;
- my_ret = mbedtls_x509_get_rsassa_pss_params( &buf, &my_msg_md, &my_mgf_md,
- &my_salt_len );
+ my_ret = mbedtls_x509_get_rsassa_pss_params(&buf, &my_msg_md, &my_mgf_md,
+ &my_salt_len);
- TEST_ASSERT( my_ret == ref_ret );
+ TEST_ASSERT(my_ret == ref_ret);
- if( ref_ret == 0 )
- {
- TEST_ASSERT( my_msg_md == (mbedtls_md_type_t) ref_msg_md );
- TEST_ASSERT( my_mgf_md == (mbedtls_md_type_t) ref_mgf_md );
- TEST_ASSERT( my_salt_len == ref_salt_len );
+ if (ref_ret == 0) {
+ TEST_ASSERT(my_msg_md == (mbedtls_md_type_t) ref_msg_md);
+ TEST_ASSERT(my_mgf_md == (mbedtls_md_type_t) ref_mgf_md);
+ TEST_ASSERT(my_salt_len == ref_salt_len);
}
exit:
diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function
index 5bd814a..a21ad47 100644
--- a/tests/suites/test_suite_x509write.function
+++ b/tests/suites/test_suite_x509write.function
@@ -11,67 +11,64 @@
#include "mbedtls/legacy_or_psa.h"
#if defined(MBEDTLS_RSA_C)
-int mbedtls_rsa_decrypt_func( void *ctx, size_t *olen,
- const unsigned char *input, unsigned char *output,
- size_t output_max_len )
+int mbedtls_rsa_decrypt_func(void *ctx, size_t *olen,
+ const unsigned char *input, unsigned char *output,
+ size_t output_max_len)
{
- return( mbedtls_rsa_pkcs1_decrypt( (mbedtls_rsa_context *) ctx, NULL, NULL,
- olen, input, output, output_max_len ) );
+ return mbedtls_rsa_pkcs1_decrypt((mbedtls_rsa_context *) ctx, NULL, NULL,
+ olen, input, output, output_max_len);
}
-int mbedtls_rsa_sign_func( void *ctx,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- mbedtls_md_type_t md_alg, unsigned int hashlen,
- const unsigned char *hash, unsigned char *sig )
+int mbedtls_rsa_sign_func(void *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+ mbedtls_md_type_t md_alg, unsigned int hashlen,
+ const unsigned char *hash, unsigned char *sig)
{
- return( mbedtls_rsa_pkcs1_sign( (mbedtls_rsa_context *) ctx, f_rng, p_rng,
- md_alg, hashlen, hash, sig ) );
+ return mbedtls_rsa_pkcs1_sign((mbedtls_rsa_context *) ctx, f_rng, p_rng,
+ md_alg, hashlen, hash, sig);
}
-size_t mbedtls_rsa_key_len_func( void *ctx )
+size_t mbedtls_rsa_key_len_func(void *ctx)
{
- return( ((const mbedtls_rsa_context *) ctx)->len );
+ return ((const mbedtls_rsa_context *) ctx)->len;
}
#endif /* MBEDTLS_RSA_C */
#if defined(MBEDTLS_USE_PSA_CRYPTO) && \
defined(MBEDTLS_PEM_WRITE_C) && defined(MBEDTLS_X509_CSR_WRITE_C)
-static int x509_crt_verifycsr( const unsigned char *buf, size_t buflen )
+static int x509_crt_verifycsr(const unsigned char *buf, size_t buflen)
{
unsigned char hash[PSA_HASH_MAX_SIZE];
mbedtls_x509_csr csr;
int ret = 0;
- mbedtls_x509_csr_init( &csr );
+ mbedtls_x509_csr_init(&csr);
- if( mbedtls_x509_csr_parse( &csr, buf, buflen ) != 0 )
- {
+ if (mbedtls_x509_csr_parse(&csr, buf, buflen) != 0) {
ret = MBEDTLS_ERR_X509_BAD_INPUT_DATA;
goto cleanup;
}
- psa_algorithm_t psa_alg = mbedtls_hash_info_psa_from_md( csr.sig_md );
+ psa_algorithm_t psa_alg = mbedtls_hash_info_psa_from_md(csr.sig_md);
size_t hash_size = 0;
- psa_status_t status = psa_hash_compute( psa_alg, csr.cri.p, csr.cri.len,
- hash, PSA_HASH_MAX_SIZE, &hash_size );
+ psa_status_t status = psa_hash_compute(psa_alg, csr.cri.p, csr.cri.len,
+ hash, PSA_HASH_MAX_SIZE, &hash_size);
- if( status != PSA_SUCCESS )
- {
+ if (status != PSA_SUCCESS) {
/* Note: this can't happen except after an internal error */
ret = MBEDTLS_ERR_X509_BAD_INPUT_DATA;
goto cleanup;
}
- if( mbedtls_pk_verify_ext( csr.sig_pk, csr.sig_opts, &csr.pk,
- csr.sig_md, hash, mbedtls_hash_info_get_size( csr.sig_md ),
- csr.sig.p, csr.sig.len ) != 0 )
- {
+ if (mbedtls_pk_verify_ext(csr.sig_pk, csr.sig_opts, &csr.pk,
+ csr.sig_md, hash, mbedtls_hash_info_get_size(csr.sig_md),
+ csr.sig.p, csr.sig.len) != 0) {
ret = MBEDTLS_ERR_X509_CERT_VERIFY_FAILED;
goto cleanup;
}
cleanup:
- mbedtls_x509_csr_free( &csr );
- return( ret );
+ mbedtls_x509_csr_free(&csr);
+ return ret;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO && MBEDTLS_PEM_WRITE_C && MBEDTLS_X509_CSR_WRITE_C */
@@ -97,11 +94,11 @@
*/
#define EXT_KEY_USAGE_TMP_BUF_MAX_LENGTH 12
-static int csr_set_extended_key_usage( mbedtls_x509write_csr *ctx,
- const char *oid, size_t oid_len )
+static int csr_set_extended_key_usage(mbedtls_x509write_csr *ctx,
+ const char *oid, size_t oid_len)
{
unsigned char buf[EXT_KEY_USAGE_TMP_BUF_MAX_LENGTH] = { 0 };
- unsigned char *p = buf + sizeof( buf );
+ unsigned char *p = buf + sizeof(buf);
int ret;
size_t len = 0;
@@ -109,18 +106,22 @@
* Following functions fail anyway if the temporary buffer is not large,
* but we set an extra check here to emphasize a possible source of errors
*/
- if ( oid_len > EXT_KEY_USAGE_TMP_BUF_MAX_LENGTH )
- {
+ if (oid_len > EXT_KEY_USAGE_TMP_BUF_MAX_LENGTH) {
return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
}
- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_oid( &p, buf, oid, oid_len ) );
- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &p, buf, ret ) );
- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &p, buf,
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) );
+ MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(&p, buf, oid, oid_len));
+ MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&p, buf, ret));
+ MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&p, buf,
+ MBEDTLS_ASN1_CONSTRUCTED |
+ MBEDTLS_ASN1_SEQUENCE));
- ret = mbedtls_x509write_csr_set_extension( ctx, MBEDTLS_OID_EXTENDED_KEY_USAGE,
- MBEDTLS_OID_SIZE( MBEDTLS_OID_EXTENDED_KEY_USAGE ), 0, p, len );
+ ret = mbedtls_x509write_csr_set_extension(ctx,
+ MBEDTLS_OID_EXTENDED_KEY_USAGE,
+ MBEDTLS_OID_SIZE(MBEDTLS_OID_EXTENDED_KEY_USAGE),
+ 0,
+ p,
+ len);
return ret;
}
@@ -133,9 +134,9 @@
*/
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C:MBEDTLS_X509_CSR_WRITE_C */
-void x509_csr_check( char * key_file, char * cert_req_check_file, int md_type,
- int key_usage, int set_key_usage, int cert_type,
- int set_cert_type, int set_extension )
+void x509_csr_check(char *key_file, char *cert_req_check_file, int md_type,
+ int key_usage, int set_key_usage, int cert_type,
+ int set_cert_type, int set_extension)
{
mbedtls_pk_context key;
mbedtls_x509write_csr req;
@@ -151,60 +152,63 @@
const char *subject_name = "C=NL,O=PolarSSL,CN=PolarSSL Server 1";
mbedtls_test_rnd_pseudo_info rnd_info;
- memset( &rnd_info, 0x2a, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(&rnd_info, 0x2a, sizeof(mbedtls_test_rnd_pseudo_info));
- mbedtls_x509write_csr_init( &req );
+ mbedtls_x509write_csr_init(&req);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_pk_init( &key );
- TEST_ASSERT( mbedtls_pk_parse_keyfile( &key, key_file, NULL,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
+ mbedtls_pk_init(&key);
+ TEST_ASSERT(mbedtls_pk_parse_keyfile(&key, key_file, NULL,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
- mbedtls_x509write_csr_set_md_alg( &req, md_type );
- mbedtls_x509write_csr_set_key( &req, &key );
- TEST_ASSERT( mbedtls_x509write_csr_set_subject_name( &req, subject_name ) == 0 );
- if( set_key_usage != 0 )
- TEST_ASSERT( mbedtls_x509write_csr_set_key_usage( &req, key_usage ) == 0 );
- if( set_cert_type != 0 )
- TEST_ASSERT( mbedtls_x509write_csr_set_ns_cert_type( &req, cert_type ) == 0 );
- if ( set_extension != 0 )
- TEST_ASSERT( csr_set_extended_key_usage( &req, MBEDTLS_OID_SERVER_AUTH,
- MBEDTLS_OID_SIZE( MBEDTLS_OID_SERVER_AUTH ) ) == 0 );
+ mbedtls_x509write_csr_set_md_alg(&req, md_type);
+ mbedtls_x509write_csr_set_key(&req, &key);
+ TEST_ASSERT(mbedtls_x509write_csr_set_subject_name(&req, subject_name) == 0);
+ if (set_key_usage != 0) {
+ TEST_ASSERT(mbedtls_x509write_csr_set_key_usage(&req, key_usage) == 0);
+ }
+ if (set_cert_type != 0) {
+ TEST_ASSERT(mbedtls_x509write_csr_set_ns_cert_type(&req, cert_type) == 0);
+ }
+ if (set_extension != 0) {
+ TEST_ASSERT(csr_set_extended_key_usage(&req, MBEDTLS_OID_SERVER_AUTH,
+ MBEDTLS_OID_SIZE(MBEDTLS_OID_SERVER_AUTH)) == 0);
+ }
- ret = mbedtls_x509write_csr_pem( &req, buf, sizeof( buf ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_x509write_csr_pem(&req, buf, sizeof(buf),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info);
+ TEST_ASSERT(ret == 0);
- pem_len = strlen( (char *) buf );
+ pem_len = strlen((char *) buf);
- for( buf_index = pem_len; buf_index < sizeof( buf ); ++buf_index )
- {
- TEST_ASSERT( buf[buf_index] == 0 );
+ for (buf_index = pem_len; buf_index < sizeof(buf); ++buf_index) {
+ TEST_ASSERT(buf[buf_index] == 0);
}
#if defined(MBEDTLS_USE_PSA_CRYPTO)
// When using PSA crypto, RNG isn't controllable, so cert_req_check_file can't be used
- (void)cert_req_check_file;
+ (void) cert_req_check_file;
buf[pem_len] = '\0';
- TEST_ASSERT( x509_crt_verifycsr( buf, pem_len + 1 ) == 0 );
+ TEST_ASSERT(x509_crt_verifycsr(buf, pem_len + 1) == 0);
#else
- f = fopen( cert_req_check_file, "r" );
- TEST_ASSERT( f != NULL );
- olen = fread( check_buf, 1, sizeof( check_buf ), f );
- fclose( f );
+ f = fopen(cert_req_check_file, "r");
+ TEST_ASSERT(f != NULL);
+ olen = fread(check_buf, 1, sizeof(check_buf), f);
+ fclose(f);
- TEST_ASSERT( olen >= pem_len - 1 );
- TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
+ TEST_ASSERT(olen >= pem_len - 1);
+ TEST_ASSERT(memcmp(buf, check_buf, pem_len - 1) == 0);
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- der_len = mbedtls_x509write_csr_der( &req, buf, sizeof( buf ),
- mbedtls_test_rnd_pseudo_rand,
- &rnd_info );
- TEST_ASSERT( der_len >= 0 );
+ der_len = mbedtls_x509write_csr_der(&req, buf, sizeof(buf),
+ mbedtls_test_rnd_pseudo_rand,
+ &rnd_info);
+ TEST_ASSERT(der_len >= 0);
- if( der_len == 0 )
+ if (der_len == 0) {
goto exit;
+ }
#if defined(MBEDTLS_USE_PSA_CRYPTO)
// When using PSA crypto, RNG isn't controllable, result length isn't
@@ -214,20 +218,20 @@
#else
der_len -= 1;
#endif
- ret = mbedtls_x509write_csr_der( &req, buf, (size_t)( der_len ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info );
- TEST_ASSERT( ret == MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
+ ret = mbedtls_x509write_csr_der(&req, buf, (size_t) (der_len),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ASN1_BUF_TOO_SMALL);
exit:
- mbedtls_x509write_csr_free( &req );
- mbedtls_pk_free( &key );
- USE_PSA_DONE( );
+ mbedtls_x509write_csr_free(&req);
+ mbedtls_pk_free(&key);
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C:MBEDTLS_X509_CSR_WRITE_C:MBEDTLS_USE_PSA_CRYPTO */
-void x509_csr_check_opaque( char *key_file, int md_type, int key_usage,
- int cert_type )
+void x509_csr_check_opaque(char *key_file, int md_type, int key_usage,
+ int cert_type)
{
mbedtls_pk_context key;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
@@ -239,66 +243,69 @@
const char *subject_name = "C=NL,O=PolarSSL,CN=PolarSSL Server 1";
mbedtls_test_rnd_pseudo_info rnd_info;
- memset( &rnd_info, 0x2a, sizeof( mbedtls_test_rnd_pseudo_info ) );
+ memset(&rnd_info, 0x2a, sizeof(mbedtls_test_rnd_pseudo_info));
- mbedtls_x509write_csr_init( &req );
+ mbedtls_x509write_csr_init(&req);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- md_alg_psa = mbedtls_hash_info_psa_from_md( (mbedtls_md_type_t) md_type );
- TEST_ASSERT( md_alg_psa != MBEDTLS_MD_NONE );
+ md_alg_psa = mbedtls_hash_info_psa_from_md((mbedtls_md_type_t) md_type);
+ TEST_ASSERT(md_alg_psa != MBEDTLS_MD_NONE);
- mbedtls_pk_init( &key );
- TEST_ASSERT( mbedtls_pk_parse_keyfile( &key, key_file, NULL,
- mbedtls_test_rnd_std_rand, NULL ) == 0 );
+ mbedtls_pk_init(&key);
+ TEST_ASSERT(mbedtls_pk_parse_keyfile(&key, key_file, NULL,
+ mbedtls_test_rnd_std_rand, NULL) == 0);
- if( mbedtls_pk_get_type( &key ) == MBEDTLS_PK_ECKEY )
- alg_psa = PSA_ALG_ECDSA( md_alg_psa );
- else if( mbedtls_pk_get_type( &key ) == MBEDTLS_PK_RSA )
- alg_psa = PSA_ALG_RSA_PKCS1V15_SIGN( md_alg_psa );
- else
- TEST_ASSUME( ! "PK key type not supported in this configuration" );
+ if (mbedtls_pk_get_type(&key) == MBEDTLS_PK_ECKEY) {
+ alg_psa = PSA_ALG_ECDSA(md_alg_psa);
+ } else if (mbedtls_pk_get_type(&key) == MBEDTLS_PK_RSA) {
+ alg_psa = PSA_ALG_RSA_PKCS1V15_SIGN(md_alg_psa);
+ } else {
+ TEST_ASSUME(!"PK key type not supported in this configuration");
+ }
- TEST_ASSERT( mbedtls_pk_wrap_as_opaque( &key, &key_id, alg_psa,
- PSA_KEY_USAGE_SIGN_HASH,
- PSA_ALG_NONE ) == 0 );
+ TEST_ASSERT(mbedtls_pk_wrap_as_opaque(&key, &key_id, alg_psa,
+ PSA_KEY_USAGE_SIGN_HASH,
+ PSA_ALG_NONE) == 0);
- mbedtls_x509write_csr_set_md_alg( &req, md_type );
- mbedtls_x509write_csr_set_key( &req, &key );
- TEST_ASSERT( mbedtls_x509write_csr_set_subject_name( &req, subject_name ) == 0 );
- if( key_usage != 0 )
- TEST_ASSERT( mbedtls_x509write_csr_set_key_usage( &req, key_usage ) == 0 );
- if( cert_type != 0 )
- TEST_ASSERT( mbedtls_x509write_csr_set_ns_cert_type( &req, cert_type ) == 0 );
+ mbedtls_x509write_csr_set_md_alg(&req, md_type);
+ mbedtls_x509write_csr_set_key(&req, &key);
+ TEST_ASSERT(mbedtls_x509write_csr_set_subject_name(&req, subject_name) == 0);
+ if (key_usage != 0) {
+ TEST_ASSERT(mbedtls_x509write_csr_set_key_usage(&req, key_usage) == 0);
+ }
+ if (cert_type != 0) {
+ TEST_ASSERT(mbedtls_x509write_csr_set_ns_cert_type(&req, cert_type) == 0);
+ }
- ret = mbedtls_x509write_csr_pem( &req, buf, sizeof( buf ) - 1,
- mbedtls_test_rnd_pseudo_rand, &rnd_info );
+ ret = mbedtls_x509write_csr_pem(&req, buf, sizeof(buf) - 1,
+ mbedtls_test_rnd_pseudo_rand, &rnd_info);
- TEST_ASSERT( ret == 0 );
+ TEST_ASSERT(ret == 0);
- pem_len = strlen( (char *) buf );
+ pem_len = strlen((char *) buf);
buf[pem_len] = '\0';
- TEST_ASSERT( x509_crt_verifycsr( buf, pem_len + 1 ) == 0 );
+ TEST_ASSERT(x509_crt_verifycsr(buf, pem_len + 1) == 0);
exit:
- mbedtls_x509write_csr_free( &req );
- mbedtls_pk_free( &key );
- psa_destroy_key( key_id );
- PSA_DONE( );
+ mbedtls_x509write_csr_free(&req);
+ mbedtls_pk_free(&key);
+ psa_destroy_key(key_id);
+ PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C:MBEDTLS_X509_CRT_WRITE_C:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
-void x509_crt_check( char *subject_key_file, char *subject_pwd,
- char *subject_name, char *issuer_key_file,
- char *issuer_pwd, char *issuer_name,
- char *serial_str, char *not_before, char *not_after,
- int md_type, int key_usage, int set_key_usage,
- char *ext_key_usage,
- int cert_type, int set_cert_type, int auth_ident,
- int ver, char *cert_check_file, int pk_wrap, int is_ca,
- char *cert_verify_file )
+void x509_crt_check(char *subject_key_file, char *subject_pwd,
+ char *subject_name, char *issuer_key_file,
+ char *issuer_pwd, char *issuer_name,
+ char *serial_str, char *not_before, char *not_after,
+ int md_type, int key_usage, int set_key_usage,
+ char *ext_key_usage,
+ int cert_type, int set_cert_type, int auth_ident,
+ int ver, char *cert_check_file, int pk_wrap, int is_ca,
+ char *cert_verify_file)
{
mbedtls_pk_context subject_key, issuer_key, issuer_key_alt;
mbedtls_pk_context *key = &issuer_key;
@@ -319,34 +326,33 @@
#endif
mbedtls_pk_type_t issuer_key_type;
- memset( &rnd_info, 0x2a, sizeof( mbedtls_test_rnd_pseudo_info ) );
- mbedtls_mpi_init( &serial );
+ memset(&rnd_info, 0x2a, sizeof(mbedtls_test_rnd_pseudo_info));
+ mbedtls_mpi_init(&serial);
- USE_PSA_INIT( );
+ USE_PSA_INIT();
- mbedtls_pk_init( &subject_key );
- mbedtls_pk_init( &issuer_key );
- mbedtls_pk_init( &issuer_key_alt );
+ mbedtls_pk_init(&subject_key);
+ mbedtls_pk_init(&issuer_key);
+ mbedtls_pk_init(&issuer_key_alt);
- mbedtls_x509write_crt_init( &crt );
+ mbedtls_x509write_crt_init(&crt);
- TEST_ASSERT( mbedtls_pk_parse_keyfile( &subject_key, subject_key_file,
- subject_pwd, mbedtls_test_rnd_std_rand, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_pk_parse_keyfile(&subject_key, subject_key_file,
+ subject_pwd, mbedtls_test_rnd_std_rand, NULL) == 0);
- TEST_ASSERT( mbedtls_pk_parse_keyfile( &issuer_key, issuer_key_file,
- issuer_pwd, mbedtls_test_rnd_std_rand, NULL ) == 0 );
+ TEST_ASSERT(mbedtls_pk_parse_keyfile(&issuer_key, issuer_key_file,
+ issuer_pwd, mbedtls_test_rnd_std_rand, NULL) == 0);
- issuer_key_type = mbedtls_pk_get_type( &issuer_key );
+ issuer_key_type = mbedtls_pk_get_type(&issuer_key);
#if defined(MBEDTLS_RSA_C)
/* For RSA PK contexts, create a copy as an alternative RSA context. */
- if( pk_wrap == 1 && issuer_key_type == MBEDTLS_PK_RSA )
- {
- TEST_ASSERT( mbedtls_pk_setup_rsa_alt( &issuer_key_alt,
- mbedtls_pk_rsa( issuer_key ),
- mbedtls_rsa_decrypt_func,
- mbedtls_rsa_sign_func,
- mbedtls_rsa_key_len_func ) == 0 );
+ if (pk_wrap == 1 && issuer_key_type == MBEDTLS_PK_RSA) {
+ TEST_ASSERT(mbedtls_pk_setup_rsa_alt(&issuer_key_alt,
+ mbedtls_pk_rsa(issuer_key),
+ mbedtls_rsa_decrypt_func,
+ mbedtls_rsa_sign_func,
+ mbedtls_rsa_key_len_func) == 0);
key = &issuer_key_alt;
}
@@ -354,216 +360,206 @@
#if defined(MBEDTLS_USE_PSA_CRYPTO)
/* For Opaque PK contexts, wrap key as an Opaque RSA context. */
- if( pk_wrap == 2 )
- {
+ if (pk_wrap == 2) {
psa_algorithm_t alg_psa, md_alg_psa;
- md_alg_psa = mbedtls_hash_info_psa_from_md( (mbedtls_md_type_t) md_type );
- TEST_ASSERT( md_alg_psa != MBEDTLS_MD_NONE );
+ md_alg_psa = mbedtls_hash_info_psa_from_md((mbedtls_md_type_t) md_type);
+ TEST_ASSERT(md_alg_psa != MBEDTLS_MD_NONE);
- if( mbedtls_pk_get_type( &issuer_key ) == MBEDTLS_PK_ECKEY )
- alg_psa = PSA_ALG_ECDSA( md_alg_psa );
- else if( mbedtls_pk_get_type( &issuer_key ) == MBEDTLS_PK_RSA )
- alg_psa = PSA_ALG_RSA_PKCS1V15_SIGN( md_alg_psa );
- else
- TEST_ASSUME( ! "PK key type not supported in this configuration" );
+ if (mbedtls_pk_get_type(&issuer_key) == MBEDTLS_PK_ECKEY) {
+ alg_psa = PSA_ALG_ECDSA(md_alg_psa);
+ } else if (mbedtls_pk_get_type(&issuer_key) == MBEDTLS_PK_RSA) {
+ alg_psa = PSA_ALG_RSA_PKCS1V15_SIGN(md_alg_psa);
+ } else {
+ TEST_ASSUME(!"PK key type not supported in this configuration");
+ }
- TEST_ASSERT( mbedtls_pk_wrap_as_opaque( &issuer_key, &key_id, alg_psa,
- PSA_KEY_USAGE_SIGN_HASH,
- PSA_ALG_NONE ) == 0 );
+ TEST_ASSERT(mbedtls_pk_wrap_as_opaque(&issuer_key, &key_id, alg_psa,
+ PSA_KEY_USAGE_SIGN_HASH,
+ PSA_ALG_NONE) == 0);
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- if( pk_wrap == 2 )
- TEST_ASSERT( mbedtls_pk_get_type( &issuer_key ) == MBEDTLS_PK_OPAQUE );
+ if (pk_wrap == 2) {
+ TEST_ASSERT(mbedtls_pk_get_type(&issuer_key) == MBEDTLS_PK_OPAQUE);
+ }
- TEST_ASSERT( mbedtls_test_read_mpi( &serial, serial_str ) == 0 );
+ TEST_ASSERT(mbedtls_test_read_mpi(&serial, serial_str) == 0);
- if( ver != -1 )
- mbedtls_x509write_crt_set_version( &crt, ver );
+ if (ver != -1) {
+ mbedtls_x509write_crt_set_version(&crt, ver);
+ }
- TEST_ASSERT( mbedtls_x509write_crt_set_serial( &crt, &serial ) == 0 );
- TEST_ASSERT( mbedtls_x509write_crt_set_validity( &crt, not_before,
- not_after ) == 0 );
- mbedtls_x509write_crt_set_md_alg( &crt, md_type );
- TEST_ASSERT( mbedtls_x509write_crt_set_issuer_name( &crt, issuer_name ) == 0 );
- TEST_ASSERT( mbedtls_x509write_crt_set_subject_name( &crt, subject_name ) == 0 );
- mbedtls_x509write_crt_set_subject_key( &crt, &subject_key );
+ TEST_ASSERT(mbedtls_x509write_crt_set_serial(&crt, &serial) == 0);
+ TEST_ASSERT(mbedtls_x509write_crt_set_validity(&crt, not_before,
+ not_after) == 0);
+ mbedtls_x509write_crt_set_md_alg(&crt, md_type);
+ TEST_ASSERT(mbedtls_x509write_crt_set_issuer_name(&crt, issuer_name) == 0);
+ TEST_ASSERT(mbedtls_x509write_crt_set_subject_name(&crt, subject_name) == 0);
+ mbedtls_x509write_crt_set_subject_key(&crt, &subject_key);
- mbedtls_x509write_crt_set_issuer_key( &crt, key );
+ mbedtls_x509write_crt_set_issuer_key(&crt, key);
- if( crt.version >= MBEDTLS_X509_CRT_VERSION_3 )
- {
+ if (crt.version >= MBEDTLS_X509_CRT_VERSION_3) {
/* For the CA case, a path length of -1 means unlimited. */
- TEST_ASSERT( mbedtls_x509write_crt_set_basic_constraints( &crt, is_ca,
- (is_ca ? -1 : 0) ) == 0 );
- TEST_ASSERT( mbedtls_x509write_crt_set_subject_key_identifier( &crt ) == 0 );
- if( auth_ident )
- TEST_ASSERT( mbedtls_x509write_crt_set_authority_key_identifier( &crt ) == 0 );
- if( set_key_usage != 0 )
- TEST_ASSERT( mbedtls_x509write_crt_set_key_usage( &crt, key_usage ) == 0 );
- if( set_cert_type != 0 )
- TEST_ASSERT( mbedtls_x509write_crt_set_ns_cert_type( &crt, cert_type ) == 0 );
- if( strcmp( ext_key_usage, "NULL" ) != 0 )
- {
+ TEST_ASSERT(mbedtls_x509write_crt_set_basic_constraints(&crt, is_ca,
+ (is_ca ? -1 : 0)) == 0);
+ TEST_ASSERT(mbedtls_x509write_crt_set_subject_key_identifier(&crt) == 0);
+ if (auth_ident) {
+ TEST_ASSERT(mbedtls_x509write_crt_set_authority_key_identifier(&crt) == 0);
+ }
+ if (set_key_usage != 0) {
+ TEST_ASSERT(mbedtls_x509write_crt_set_key_usage(&crt, key_usage) == 0);
+ }
+ if (set_cert_type != 0) {
+ TEST_ASSERT(mbedtls_x509write_crt_set_ns_cert_type(&crt, cert_type) == 0);
+ }
+ if (strcmp(ext_key_usage, "NULL") != 0) {
mbedtls_asn1_sequence exts[2];
- memset( exts, 0, sizeof(exts) );
+ memset(exts, 0, sizeof(exts));
#define SET_OID(x, oid) \
do { \
x.len = MBEDTLS_OID_SIZE(oid); \
- x.p = (unsigned char*)oid; \
+ x.p = (unsigned char *) oid; \
x.tag = MBEDTLS_ASN1_OID; \
} \
- while( 0 )
+ while (0)
- if( strcmp( ext_key_usage, "serverAuth" ) == 0 )
- {
- SET_OID( exts[0].buf, MBEDTLS_OID_SERVER_AUTH );
- }
- else if( strcmp( ext_key_usage, "codeSigning,timeStamping" ) == 0 )
- {
- SET_OID( exts[0].buf, MBEDTLS_OID_CODE_SIGNING );
+ if (strcmp(ext_key_usage, "serverAuth") == 0) {
+ SET_OID(exts[0].buf, MBEDTLS_OID_SERVER_AUTH);
+ } else if (strcmp(ext_key_usage, "codeSigning,timeStamping") == 0) {
+ SET_OID(exts[0].buf, MBEDTLS_OID_CODE_SIGNING);
exts[0].next = &exts[1];
- SET_OID( exts[1].buf, MBEDTLS_OID_TIME_STAMPING );
+ SET_OID(exts[1].buf, MBEDTLS_OID_TIME_STAMPING);
}
- TEST_ASSERT( mbedtls_x509write_crt_set_ext_key_usage( &crt, exts ) == 0 );
+ TEST_ASSERT(mbedtls_x509write_crt_set_ext_key_usage(&crt, exts) == 0);
}
}
- ret = mbedtls_x509write_crt_pem( &crt, buf, sizeof( buf ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info );
- TEST_ASSERT( ret == 0 );
+ ret = mbedtls_x509write_crt_pem(&crt, buf, sizeof(buf),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info);
+ TEST_ASSERT(ret == 0);
- pem_len = strlen( (char *) buf );
+ pem_len = strlen((char *) buf);
// check that the rest of the buffer remains clear
- for( buf_index = pem_len; buf_index < sizeof( buf ); ++buf_index )
- {
- TEST_ASSERT( buf[buf_index] == 0 );
+ for (buf_index = pem_len; buf_index < sizeof(buf); ++buf_index) {
+ TEST_ASSERT(buf[buf_index] == 0);
}
- if( issuer_key_type != MBEDTLS_PK_RSA )
- {
+ if (issuer_key_type != MBEDTLS_PK_RSA) {
mbedtls_x509_crt crt_parse, trusted;
uint32_t flags;
- mbedtls_x509_crt_init( &crt_parse );
- mbedtls_x509_crt_init( &trusted );
+ mbedtls_x509_crt_init(&crt_parse);
+ mbedtls_x509_crt_init(&trusted);
- TEST_ASSERT( mbedtls_x509_crt_parse_file( &trusted,
- cert_verify_file ) == 0 );
- TEST_ASSERT( mbedtls_x509_crt_parse( &crt_parse,
- buf, sizeof( buf ) ) == 0 );
+ TEST_ASSERT(mbedtls_x509_crt_parse_file(&trusted,
+ cert_verify_file) == 0);
+ TEST_ASSERT(mbedtls_x509_crt_parse(&crt_parse,
+ buf, sizeof(buf)) == 0);
- ret = mbedtls_x509_crt_verify( &crt_parse, &trusted, NULL, NULL, &flags,
- NULL, NULL );
+ ret = mbedtls_x509_crt_verify(&crt_parse, &trusted, NULL, NULL, &flags,
+ NULL, NULL);
- mbedtls_x509_crt_free( &crt_parse );
- mbedtls_x509_crt_free( &trusted );
+ mbedtls_x509_crt_free(&crt_parse);
+ mbedtls_x509_crt_free(&trusted);
- TEST_EQUAL( flags, 0 );
- TEST_EQUAL( ret, 0 );
- }
- else if( *cert_check_file != '\0' )
- {
- f = fopen( cert_check_file, "r" );
- TEST_ASSERT( f != NULL );
- olen = fread( check_buf, 1, sizeof( check_buf ), f );
- fclose( f );
- TEST_ASSERT( olen < sizeof( check_buf ) );
+ TEST_EQUAL(flags, 0);
+ TEST_EQUAL(ret, 0);
+ } else if (*cert_check_file != '\0') {
+ f = fopen(cert_check_file, "r");
+ TEST_ASSERT(f != NULL);
+ olen = fread(check_buf, 1, sizeof(check_buf), f);
+ fclose(f);
+ TEST_ASSERT(olen < sizeof(check_buf));
- TEST_EQUAL( olen, pem_len );
- TEST_ASSERT( olen >= pem_len - 1 );
- TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
+ TEST_EQUAL(olen, pem_len);
+ TEST_ASSERT(olen >= pem_len - 1);
+ TEST_ASSERT(memcmp(buf, check_buf, pem_len - 1) == 0);
}
- der_len = mbedtls_x509write_crt_der( &crt, buf, sizeof( buf ),
- mbedtls_test_rnd_pseudo_rand,
- &rnd_info );
- TEST_ASSERT( der_len >= 0 );
+ der_len = mbedtls_x509write_crt_der(&crt, buf, sizeof(buf),
+ mbedtls_test_rnd_pseudo_rand,
+ &rnd_info);
+ TEST_ASSERT(der_len >= 0);
- if( der_len == 0 )
+ if (der_len == 0) {
goto exit;
+ }
// Not testing against file, check date format
- if( *cert_check_file == '\0' )
- {
+ if (*cert_check_file == '\0') {
// UTC tag if before 2050, 2 digits less for year
- if( not_before[0] == '2' && ( not_before[1] > '0' || not_before[2] > '4' ) )
- {
+ if (not_before[0] == '2' && (not_before[1] > '0' || not_before[2] > '4')) {
before_tag = MBEDTLS_ASN1_GENERALIZED_TIME;
- }
- else
- {
+ } else {
before_tag = MBEDTLS_ASN1_UTC_TIME;
not_before += 2;
}
- if( not_after[0] == '2' && ( not_after[1] > '0' || not_after[2] > '4' ) )
- {
+ if (not_after[0] == '2' && (not_after[1] > '0' || not_after[2] > '4')) {
after_tag = MBEDTLS_ASN1_GENERALIZED_TIME;
- }
- else
- {
+ } else {
after_tag = MBEDTLS_ASN1_UTC_TIME;
not_after += 2;
}
- end = buf + sizeof( buf );
- for( p = end - der_len ; p < end ; )
- {
+ end = buf + sizeof(buf);
+ for (p = end - der_len; p < end;) {
tag = *p++;
sz = *p++;
- if( tag == MBEDTLS_ASN1_UTC_TIME || tag == MBEDTLS_ASN1_GENERALIZED_TIME )
- {
+ if (tag == MBEDTLS_ASN1_UTC_TIME || tag == MBEDTLS_ASN1_GENERALIZED_TIME) {
// Check correct tag and time written
- TEST_ASSERT( before_tag == tag );
- TEST_ASSERT( memcmp( p, not_before, sz - 1 ) == 0 );
+ TEST_ASSERT(before_tag == tag);
+ TEST_ASSERT(memcmp(p, not_before, sz - 1) == 0);
p += sz;
tag = *p++;
sz = *p++;
- TEST_ASSERT( after_tag == tag );
- TEST_ASSERT( memcmp( p, not_after, sz - 1 ) == 0 );
+ TEST_ASSERT(after_tag == tag);
+ TEST_ASSERT(memcmp(p, not_after, sz - 1) == 0);
break;
}
// Increment if long form ASN1 length
- if( sz & 0x80 )
+ if (sz & 0x80) {
p += sz & 0x0F;
- if( tag != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) )
+ }
+ if (tag != (MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) {
p += sz;
+ }
}
- TEST_ASSERT( p < end );
+ TEST_ASSERT(p < end);
}
#if defined(MBEDTLS_USE_PSA_CRYPTO)
// When using PSA crypto, RNG isn't controllable, result length isn't
// deterministic over multiple runs, removing a single byte isn't enough to
// go into the MBEDTLS_ERR_ASN1_BUF_TOO_SMALL error case
- if( issuer_key_type != MBEDTLS_PK_RSA )
+ if (issuer_key_type != MBEDTLS_PK_RSA) {
der_len /= 2;
- else
+ } else
#endif
- der_len -= 1;
+ der_len -= 1;
- ret = mbedtls_x509write_crt_der( &crt, buf, (size_t)( der_len ),
- mbedtls_test_rnd_pseudo_rand, &rnd_info );
- TEST_ASSERT( ret == MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
+ ret = mbedtls_x509write_crt_der(&crt, buf, (size_t) (der_len),
+ mbedtls_test_rnd_pseudo_rand, &rnd_info);
+ TEST_ASSERT(ret == MBEDTLS_ERR_ASN1_BUF_TOO_SMALL);
exit:
- mbedtls_x509write_crt_free( &crt );
- mbedtls_pk_free( &issuer_key_alt );
- mbedtls_pk_free( &subject_key );
- mbedtls_pk_free( &issuer_key );
- mbedtls_mpi_free( &serial );
+ mbedtls_x509write_crt_free(&crt);
+ mbedtls_pk_free(&issuer_key_alt);
+ mbedtls_pk_free(&subject_key);
+ mbedtls_pk_free(&issuer_key);
+ mbedtls_mpi_free(&serial);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_destroy_key( key_id );
+ psa_destroy_key(key_id);
#endif
- USE_PSA_DONE( );
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CREATE_C:MBEDTLS_X509_USE_C */
-void mbedtls_x509_string_to_names( char * name, char * parsed_name, int result
- )
+void mbedtls_x509_string_to_names(char *name, char *parsed_name, int result
+ )
{
int ret;
size_t len = 0;
@@ -571,38 +567,38 @@
mbedtls_x509_name parsed, *parsed_cur, *parsed_prv;
unsigned char buf[1024], out[1024], *c;
- memset( &parsed, 0, sizeof( parsed ) );
- memset( out, 0, sizeof( out ) );
- memset( buf, 0, sizeof( buf ) );
- c = buf + sizeof( buf );
+ memset(&parsed, 0, sizeof(parsed));
+ memset(out, 0, sizeof(out));
+ memset(buf, 0, sizeof(buf));
+ c = buf + sizeof(buf);
- ret = mbedtls_x509_string_to_names( &names, name );
- TEST_ASSERT( ret == result );
+ ret = mbedtls_x509_string_to_names(&names, name);
+ TEST_ASSERT(ret == result);
- if( ret != 0 )
+ if (ret != 0) {
goto exit;
+ }
- ret = mbedtls_x509_write_names( &c, buf, names );
- TEST_ASSERT( ret > 0 );
+ ret = mbedtls_x509_write_names(&c, buf, names);
+ TEST_ASSERT(ret > 0);
- TEST_ASSERT( mbedtls_asn1_get_tag( &c, buf + sizeof( buf ), &len,
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) == 0 );
- TEST_ASSERT( mbedtls_x509_get_name( &c, buf + sizeof( buf ), &parsed ) == 0 );
+ TEST_ASSERT(mbedtls_asn1_get_tag(&c, buf + sizeof(buf), &len,
+ MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) == 0);
+ TEST_ASSERT(mbedtls_x509_get_name(&c, buf + sizeof(buf), &parsed) == 0);
- ret = mbedtls_x509_dn_gets( (char *) out, sizeof( out ), &parsed );
- TEST_ASSERT( ret > 0 );
+ ret = mbedtls_x509_dn_gets((char *) out, sizeof(out), &parsed);
+ TEST_ASSERT(ret > 0);
- TEST_ASSERT( strcmp( (char *) out, parsed_name ) == 0 );
+ TEST_ASSERT(strcmp((char *) out, parsed_name) == 0);
exit:
- mbedtls_asn1_free_named_data_list( &names );
+ mbedtls_asn1_free_named_data_list(&names);
parsed_cur = parsed.next;
- while( parsed_cur != 0 )
- {
+ while (parsed_cur != 0) {
parsed_prv = parsed_cur;
parsed_cur = parsed_cur->next;
- mbedtls_free( parsed_prv );
+ mbedtls_free(parsed_prv);
}
}
/* END_CASE */