diff mbox series

[2/3] util: Add support for clearing the aes decryption key

Message ID 20231126132417.107606-2-Michael.Glembotzki@iris-sensing.com
State Changes Requested
Headers show
Series [1/3] Add support for asymmetric decryption | expand

Commit Message

Michael Glembotzki Nov. 26, 2023, 1:24 p.m. UTC
Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>
---
 core/util.c    | 14 ++++++++++++++
 include/util.h |  1 +
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index cb2cf78..ef51d9e 100644
--- a/core/util.c
+++ b/core/util.c
@@ -563,6 +563,20 @@  int set_aes_key(const char *key, const char *ivt)
 	return 0;
 }
 
+void clear_aes_key(void) {
+	if (!aes_key) {
+		return;
+	}
+#ifdef CONFIG_PKCS11
+	free(aes_key->key);
+	aes_key->key = NULL;
+#else
+	memset(aes_key->key, 0, sizeof(aes_key->key));
+#endif
+	memset(aes_key->ivt, 0, sizeof(aes_key->ivt));
+	aes_key->keylen = 0;
+}
+
 const char *get_fwenv_config(void) {
 	if (!fwenv_config)
 #if defined(CONFIG_UBOOT)
diff --git a/include/util.h b/include/util.h
index dc0b957..ad7a6b7 100644
--- a/include/util.h
+++ b/include/util.h
@@ -243,6 +243,7 @@  unsigned char *get_aes_key(void);
 char get_aes_keylen(void);
 unsigned char *get_aes_ivt(void);
 int set_aes_key(const char *key, const char *ivt);
+void clear_aes_key(void);
 
 /* Getting global information */
 int get_install_info(sourcetype *source, char *buf, size_t len);