Merge pull request #10256 from ariwo17/psa-dlopen-demo
Modify dlopen.c and tfpsacrypto_dlopen.c so that they use PSA API-only dynamic loading
diff --git a/programs/test/dlopen.c b/programs/test/dlopen.c
index bb7fba8..58a6af5 100644
--- a/programs/test/dlopen.c
+++ b/programs/test/dlopen.c
@@ -98,16 +98,41 @@
* "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 */
- ;
+ /* Demonstrate hashing a message with PSA Crypto */
+
+ 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 */
diff --git a/tf-psa-crypto b/tf-psa-crypto
index 110b9a4..b1c98eb 160000
--- a/tf-psa-crypto
+++ b/tf-psa-crypto
@@ -1 +1 @@
-Subproject commit 110b9a44d79975c0eab61f46c65837abc5c9309a
+Subproject commit b1c98ebee82c1056cec0f64e24f1b780a5889a0d