feat(auth): add crypto_mod_finish() function
Adding crypto_mod_finish() function to be run at the end of crypto usage
to cleanup.
Signed-off-by: Lauren Wehrmeister <lauren.wehrmeister@arm.com>
Change-Id: Ib6d099ddaa278f293fe14b805070985522a85686
diff --git a/drivers/auth/crypto_mod.c b/drivers/auth/crypto_mod.c
index e36b285..882ca8e 100644
--- a/drivers/auth/crypto_mod.c
+++ b/drivers/auth/crypto_mod.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -187,3 +187,12 @@
key_len, key_flags, iv, iv_len, tag,
tag_len);
}
+
+/* Perform end of psa crypto usage calls to finish */
+void crypto_mod_finish(void)
+{
+ if (crypto_lib_desc.finish != NULL) {
+ crypto_lib_desc.finish();
+ INFO("Finished using crypto library '%s'\n", crypto_lib_desc.name);
+ }
+}
diff --git a/include/drivers/auth/crypto_mod.h b/include/drivers/auth/crypto_mod.h
index bec19da..fd49b2d 100644
--- a/include/drivers/auth/crypto_mod.h
+++ b/include/drivers/auth/crypto_mod.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -79,6 +79,12 @@
unsigned int key_flags, const void *iv,
unsigned int iv_len, const void *tag,
unsigned int tag_len);
+
+ /*
+ * Finish using the crypto library,
+ * anything to be done to wrap up crypto usage done here.
+ */
+ void (*finish)(void);
} crypto_lib_desc_t;
/* Public functions */
@@ -118,9 +124,17 @@
int crypto_mod_convert_pk(void *full_pk_ptr, unsigned int full_pk_len,
void **hashed_pk_ptr, unsigned int *hashed_pk_len);
+#if CRYPTO_SUPPORT
+void crypto_mod_finish(void);
+#else
+static inline void crypto_mod_finish(void)
+{
+}
+#endif /* CRYPTO_SUPPORT */
+
/* Macro to register a cryptographic library */
#define REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash, \
- _calc_hash, _auth_decrypt, _convert_pk) \
+ _calc_hash, _auth_decrypt, _convert_pk, _finish) \
const crypto_lib_desc_t crypto_lib_desc = { \
.name = _name, \
.init = _init, \
@@ -128,7 +142,8 @@
.verify_hash = _verify_hash, \
.calc_hash = _calc_hash, \
.auth_decrypt = _auth_decrypt, \
- .convert_pk = _convert_pk \
+ .convert_pk = _convert_pk, \
+ .finish = _finish \
}
extern const crypto_lib_desc_t crypto_lib_desc;