[PATCH 5/8] rsa: Add iterator for rsa keys

Sascha Hauer s.hauer at pengutronix.de
Wed May 4 06:14:13 PDT 2022


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 crypto/rsa.c  | 9 +++++++++
 include/rsa.h | 4 ++++
 2 files changed, 13 insertions(+)

diff --git a/crypto/rsa.c b/crypto/rsa.c
index 4e2d463b54..2eeb9984b1 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -446,6 +446,15 @@ void rsa_key_free(struct rsa_public_key *key)
 
 static LIST_HEAD(rsa_keys);
 
+const struct rsa_public_key *rsa_key_next(const struct rsa_public_key *prev)
+{
+	prev = list_prepare_entry(prev, &rsa_keys, list);
+	list_for_each_entry_continue(prev, &rsa_keys, list)
+		return prev;
+
+	return NULL;
+}
+
 const struct rsa_public_key *rsa_get_key(const char *name)
 {
 	const struct rsa_public_key *key;
diff --git a/include/rsa.h b/include/rsa.h
index 4ef16ea5a8..650fb234f2 100644
--- a/include/rsa.h
+++ b/include/rsa.h
@@ -55,4 +55,8 @@ struct rsa_public_key *rsa_of_read_key(struct device_node *node);
 void rsa_key_free(struct rsa_public_key *key);
 const struct rsa_public_key *rsa_get_key(const char *name);
 
+const struct rsa_public_key *rsa_key_next(const struct rsa_public_key *prev);
+
+#define for_each_rsa_key(key) \
+		for (key = rsa_key_next(NULL); key; key = rsa_key_next(key))
 #endif
-- 
2.30.2




More information about the barebox mailing list