PK: fix test failures
Introduce MD_OR_USE_PSA_INIT/DONE. This will likely be used everywhere in X.509 and SSL/TLS, but most places in PK only need USE_PSA_INIT/DONE. Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
parent
0b8095d96a
commit
fa99afa2bc
3 changed files with 64 additions and 28 deletions
|
@ -36,14 +36,6 @@
|
|||
#include "mbedtls/md.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD_SOME_PSA)
|
||||
#define MD_PSA_INIT() PSA_INIT()
|
||||
#define MD_PSA_DONE() PSA_DONE()
|
||||
#else /* MBEDTLS_MD_SOME_PSA */
|
||||
#define MD_PSA_INIT() ((void) 0)
|
||||
#define MD_PSA_DONE() ((void) 0)
|
||||
#endif /* MBEDTLS_MD_SOME_PSA */
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
/** Initialize the PSA Crypto subsystem. */
|
||||
#define PSA_INIT() PSA_ASSERT(psa_crypto_init())
|
||||
|
@ -304,31 +296,24 @@ int mbedtls_test_fail_if_psa_leaking(int line_no, const char *filename);
|
|||
} \
|
||||
while (0)
|
||||
|
||||
#if !defined(MBEDTLS_MD_C)
|
||||
#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)
|
||||
#endif
|
||||
|
||||
/** \def USE_PSA_INIT
|
||||
*
|
||||
* Call this macro to initialize the PSA subsystem if #MBEDTLS_USE_PSA_CRYPTO
|
||||
* or #MBEDTLS_SSL_PROTO_TLS1_3 (In contrast to TLS 1.2 implementation, the
|
||||
* TLS 1.3 one uses PSA independently of the definition of
|
||||
* #MBEDTLS_USE_PSA_CRYPTO) is enabled and do nothing otherwise. If the
|
||||
* initialization fails, mark the test case as failed and jump to the \p exit
|
||||
* label.
|
||||
* #MBEDTLS_USE_PSA_CRYPTO) is enabled and do nothing otherwise.
|
||||
*
|
||||
* If the initialization fails, mark the test case as failed and jump to the
|
||||
* \p exit label.
|
||||
*/
|
||||
/** \def USE_PSA_DONE
|
||||
*
|
||||
* Call this macro at the end of a test case if you called #USE_PSA_INIT.
|
||||
* This is like #PSA_DONE, except that it does nothing if
|
||||
* #MBEDTLS_USE_PSA_CRYPTO is disabled.
|
||||
*
|
||||
* This is like #PSA_DONE except it does nothing under the same conditions as
|
||||
* #USE_PSA_INIT.
|
||||
*/
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
#define USE_PSA_INIT() PSA_INIT()
|
||||
|
@ -341,4 +326,52 @@ int mbedtls_test_fail_if_psa_leaking(int line_no, const char *filename);
|
|||
#define USE_PSA_DONE() ((void) 0)
|
||||
#endif /* !MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_SSL_PROTO_TLS1_3 */
|
||||
|
||||
/** \def MD_PSA_INIT
|
||||
*
|
||||
* Call this macro to initialize the PSA subsystem if MD uses a driver,
|
||||
* and do nothing otherwise.
|
||||
*
|
||||
* If the initialization fails, mark the test case as failed and jump to the
|
||||
* \p exit label.
|
||||
*/
|
||||
/** \def MD_PSA_DONE
|
||||
*
|
||||
* Call this macro at the end of a test case if you called #MD_PSA_INIT.
|
||||
*
|
||||
* This is like #PSA_DONE except it does nothing under the same conditions as
|
||||
* #MD_PSA_INIT.
|
||||
*/
|
||||
#if defined(MBEDTLS_MD_SOME_PSA)
|
||||
#define MD_PSA_INIT() PSA_INIT()
|
||||
#define MD_PSA_DONE() PSA_DONE()
|
||||
#else /* MBEDTLS_MD_SOME_PSA */
|
||||
#define MD_PSA_INIT() ((void) 0)
|
||||
#define MD_PSA_DONE() ((void) 0)
|
||||
#endif /* MBEDTLS_MD_SOME_PSA */
|
||||
|
||||
/** \def MD_OR_USE_PSA_INIT
|
||||
*
|
||||
* Call this macro to initialize the PSA subsystem if MD uses a driver,
|
||||
* of if #MBEDTLS_USE_PSA_CRYPTO or #MBEDTLS_SSL_PROTO_TLS1_3 is enabled,
|
||||
* and do nothing otherwise.
|
||||
*
|
||||
* If the initialization fails, mark the test case as failed and jump to the
|
||||
* \p exit label.
|
||||
*/
|
||||
/** \def MD_OR_USE_PSA_DONE
|
||||
*
|
||||
* Call this macro at the end of a test case if you called #MD_OR_USE_PSA_INIT.
|
||||
*
|
||||
* This is like #PSA_DONE except it does nothing under the same conditions as
|
||||
* #MD_OR_USE_PSA_INIT.
|
||||
*/
|
||||
#if defined(MBEDTLS_MD_SOME_PSA) || \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
#define MD_OR_USE_PSA_INIT() PSA_INIT()
|
||||
#define MD_OR_USE_PSA_DONE() PSA_DONE()
|
||||
#else
|
||||
#define MD_OR_USE_PSA_INIT() ((void) 0)
|
||||
#define MD_OR_USE_PSA_DONE() ((void) 0)
|
||||
#endif
|
||||
|
||||
#endif /* PSA_CRYPTO_HELPERS_H */
|
||||
|
|
|
@ -576,7 +576,7 @@ void pk_rsa_verify_ext_test_vec(data_t *message_str, int digest,
|
|||
void *options;
|
||||
int ret;
|
||||
|
||||
USE_PSA_INIT();
|
||||
MD_OR_USE_PSA_INIT();
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
TEST_ASSERT(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == 0);
|
||||
|
@ -620,7 +620,7 @@ void pk_rsa_verify_ext_test_vec(data_t *message_str, int digest,
|
|||
|
||||
exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
USE_PSA_DONE();
|
||||
MD_OR_USE_PSA_DONE();
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ void pk_parse_keyfile_rsa(char *key_file, char *password, int result)
|
|||
int res;
|
||||
char *pwd = password;
|
||||
|
||||
PSA_INIT_IF_NO_MD();
|
||||
MD_PSA_INIT();
|
||||
|
||||
mbedtls_pk_init(&ctx);
|
||||
|
||||
if (strcmp(pwd, "NULL") == 0) {
|
||||
|
@ -39,8 +40,9 @@ void pk_parse_keyfile_rsa(char *key_file, char *password, int result)
|
|||
|
||||
exit:
|
||||
mbedtls_pk_free(&ctx);
|
||||
PSA_DONE_IF_NO_MD();
|
||||
MD_PSA_DONE();
|
||||
}
|
||||
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_FS_IO */
|
||||
|
@ -49,7 +51,8 @@ void pk_parse_public_keyfile_rsa(char *key_file, int result)
|
|||
mbedtls_pk_context ctx;
|
||||
int res;
|
||||
|
||||
PSA_INIT_IF_NO_MD();
|
||||
MD_PSA_INIT();
|
||||
|
||||
mbedtls_pk_init(&ctx);
|
||||
|
||||
res = mbedtls_pk_parse_public_keyfile(&ctx, key_file);
|
||||
|
@ -65,7 +68,7 @@ void pk_parse_public_keyfile_rsa(char *key_file, int result)
|
|||
|
||||
exit:
|
||||
mbedtls_pk_free(&ctx);
|
||||
PSA_DONE_IF_NO_MD();
|
||||
MD_PSA_DONE();
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
|
Loading…
Reference in a new issue