summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-05-26 08:37:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-05-26 08:39:47 +0200
commitbd36442bbe8e58df192e642a75192241a234f9e5 (patch)
treed386f01fe1da079560de42afa418e780d5975e8b /crypto
parentf2829aaca55c40010311f8fc3a1adf1dfb349c57 (diff)
downloadbarebox-bd36442bbe8e58df192e642a75192241a234f9e5.tar.gz
barebox-bd36442bbe8e58df192e642a75192241a234f9e5.tar.xz
crypto: digest: match driver name if no algo name matches
The digest command lists all registered digest implementations, but there's no way to select a specific implementation when another higher priority one exists for the same algorithm. Let's support this, by having digest_algo_get_by_name fallback to look up by driver name if an exact match couldn't be found by algo name. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230526063746.1155297-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/digest.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/crypto/digest.c b/crypto/digest.c
index 621d384168..dd2c2ee317 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -27,8 +27,6 @@
static LIST_HEAD(digests);
-static struct digest_algo *digest_algo_get_by_name(const char *name);
-
static int dummy_init(struct digest *d)
{
return 0;
@@ -106,7 +104,7 @@ EXPORT_SYMBOL(digest_algo_unregister);
static struct digest_algo *digest_algo_get_by_name(const char *name)
{
- struct digest_algo *d = NULL;
+ struct digest_algo *d_by_name = NULL, *d_by_driver = NULL;
struct digest_algo *tmp;
int priority = -1;
@@ -114,17 +112,20 @@ static struct digest_algo *digest_algo_get_by_name(const char *name)
return NULL;
list_for_each_entry(tmp, &digests, list) {
+ if (strcmp(tmp->base.driver_name, name) == 0)
+ d_by_driver = tmp;
+
if (strcmp(tmp->base.name, name) != 0)
continue;
if (tmp->base.priority <= priority)
continue;
- d = tmp;
+ d_by_name = tmp;
priority = tmp->base.priority;
}
- return d;
+ return d_by_name ?: d_by_driver;
}
static struct digest_algo *digest_algo_get_by_algo(enum hash_algo algo)