mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Modified dlopen.c and tfpsacrypto_dlopen.c so that they use PSA API-only dynamic loading
- Replaced soon-deprecated mbedtls_md_list() in dlopen.c with psa_hash_compute() - Added tfpsacrypto_dlopen.c as a PSA-only shared-library loading test - Enabled -fPIC for tf-psa-crypto builtins to support shared linking - Confirmed clean builds and successful dlopen() test execution. Signed-off-by: Ari Weiler-Ofek <ari.weiler-ofek@arm.com>
This commit is contained in:
committed by
Ari Weiler-Ofek
parent
ba2376c580
commit
abcfd4c160
@@ -98,16 +98,42 @@ int main(void)
|
||||
* "gcc -std=c99 -pedantic" complains about it, but it is perfectly
|
||||
* fine on platforms that have dlsym(). */
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
const int *(*md_list)(void) =
|
||||
dlsym(crypto_so, "mbedtls_md_list");
|
||||
psa_status_t (*dyn_psa_crypto_init)(void) =
|
||||
dlsym(crypto_so, "psa_crypto_init");
|
||||
psa_status_t (*dyn_psa_hash_compute)(psa_algorithm_t, const uint8_t *, size_t, uint8_t *,
|
||||
size_t, size_t *) =
|
||||
dlsym(crypto_so, "psa_hash_compute");
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
CHECK_DLERROR("dlsym", "mbedtls_md_list");
|
||||
const int *mds = md_list();
|
||||
for (n = 0; mds[n] != 0; n++) {/* nothing to do, we're just counting */
|
||||
;
|
||||
/* Use psa_hash_compute from PSA Crypto API instead of deprecated mbedtls_md_list()
|
||||
* to demonstrate runtime linking of libmbedcrypto / libtfpsacrypto */
|
||||
|
||||
CHECK_DLERROR("dlsym", "psa_crypto_init");
|
||||
CHECK_DLERROR("dlsym", "psa_hash_compute");
|
||||
|
||||
psa_status_t status = dyn_psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "psa_crypto_init failed: %d\n", (int) status);
|
||||
mbedtls_exit(MBEDTLS_EXIT_FAILURE);
|
||||
}
|
||||
mbedtls_printf("dlopen(%s): %u hashes\n",
|
||||
crypto_so_filename, n);
|
||||
|
||||
const uint8_t input[] = "hello world";
|
||||
uint8_t hash[32]; // Buffer to hold the output hash
|
||||
size_t hash_len = 0;
|
||||
|
||||
status = dyn_psa_hash_compute(PSA_ALG_SHA_256,
|
||||
input, sizeof(input) - 1,
|
||||
hash, sizeof(hash),
|
||||
&hash_len);
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "psa_hash_compute failed: %d\n", (int) status);
|
||||
mbedtls_exit(MBEDTLS_EXIT_FAILURE);
|
||||
}
|
||||
|
||||
mbedtls_printf("dlopen(%s): psa_hash_compute succeeded. SHA-256 output length: %zu\n",
|
||||
crypto_so_filename, hash_len);
|
||||
|
||||
|
||||
dlclose(crypto_so);
|
||||
CHECK_DLERROR("dlclose", crypto_so_filename);
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
Reference in New Issue
Block a user