From: Marc Kleine-Budde <mkl@pengutronix.de>
To: barebox@lists.infradead.org
Cc: kernel@pengutronix.de
Subject: [PATCH 1/3] crypto: add enum
Date: Tue, 5 Jan 2016 09:11:01 +0100 [thread overview]
Message-ID: <1451981463-23604-2-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1451981463-23604-1-git-send-email-mkl@pengutronix.de>
From: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
arch/arm/crypto/sha1_glue.c | 1 +
arch/arm/crypto/sha256_glue.c | 2 ++
crypto/digest.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
crypto/md5.c | 1 +
crypto/sha1.c | 1 +
crypto/sha2.c | 2 ++
crypto/sha4.c | 2 ++
include/digest.h | 23 +++++++++++++++++++++++
8 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/arch/arm/crypto/sha1_glue.c b/arch/arm/crypto/sha1_glue.c
index 176aa9ec69e0..57cd9d101458 100644
--- a/arch/arm/crypto/sha1_glue.c
+++ b/arch/arm/crypto/sha1_glue.c
@@ -119,6 +119,7 @@ static struct digest_algo m = {
.name = "sha1",
.driver_name = "sha1-asm",
.priority = 150,
+ .algo = HASH_ALGO_SHA1,
},
.init = sha1_init,
diff --git a/arch/arm/crypto/sha256_glue.c b/arch/arm/crypto/sha256_glue.c
index f8086f6ac7f7..e649609a8eef 100644
--- a/arch/arm/crypto/sha256_glue.c
+++ b/arch/arm/crypto/sha256_glue.c
@@ -173,6 +173,7 @@ static struct digest_algo sha224 = {
.name = "sha224",
.driver_name = "sha224-asm",
.priority = 150,
+ .algo = HASH_ALGO_SHA224,
},
.length = SHA224_DIGEST_SIZE,
@@ -195,6 +196,7 @@ static struct digest_algo sha256 = {
.name = "sha256",
.driver_name = "sha256-asm",
.priority = 150,
+ .algo = HASH_ALGO_SHA256,
},
.length = SHA256_DIGEST_SIZE,
diff --git a/crypto/digest.c b/crypto/digest.c
index a90e4ff79f89..46600f246ece 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -116,7 +116,27 @@ static struct digest_algo *digest_algo_get_by_name(const char *name)
list_for_each_entry(tmp, &digests, list) {
if (strcmp(tmp->base.name, name) != 0)
continue;
-
+
+ if (tmp->base.priority <= priority)
+ continue;
+
+ d = tmp;
+ priority = tmp->base.priority;
+ }
+
+ return d;
+}
+
+static struct digest_algo *digest_algo_get_by_algo(enum hash_algo algo)
+{
+ struct digest_algo *d = NULL;
+ struct digest_algo *tmp;
+ int priority = -1;
+
+ list_for_each_entry(tmp, &digests, list) {
+ if (tmp->base.algo != algo)
+ continue;
+
if (tmp->base.priority <= priority)
continue;
@@ -160,6 +180,27 @@ struct digest *digest_alloc(const char *name)
}
EXPORT_SYMBOL_GPL(digest_alloc);
+struct digest *digest_alloc_by_algo(enum hash_algo hash_algo)
+{
+ struct digest *d;
+ struct digest_algo *algo;
+
+ algo = digest_algo_get_by_algo(hash_algo);
+ if (!algo)
+ return NULL;
+
+ d = xzalloc(sizeof(*d));
+ d->algo = algo;
+ d->ctx = xzalloc(algo->ctx_length);
+ if (d->algo->alloc(d)) {
+ digest_free(d);
+ return NULL;
+ }
+
+ return d;
+}
+EXPORT_SYMBOL_GPL(digest_alloc_by_algo);
+
void digest_free(struct digest *d)
{
if (!d)
diff --git a/crypto/md5.c b/crypto/md5.c
index 23892babce6c..f8f52bf4a505 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -293,6 +293,7 @@ static struct digest_algo md5 = {
.name = "md5",
.driver_name = "md5-generic",
.priority = 0,
+ .algo = HASH_ALGO_MD5,
},
.init = digest_md5_init,
.update = digest_md5_update,
diff --git a/crypto/sha1.c b/crypto/sha1.c
index a3de2719d8fc..cbde4d28e475 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -287,6 +287,7 @@ static struct digest_algo m = {
.name = "sha1",
.driver_name = "sha1-generic",
.priority = 0,
+ .algo = HASH_ALGO_SHA1,
},
.init = sha1_init,
diff --git a/crypto/sha2.c b/crypto/sha2.c
index 6ac552702807..df566c8a4b3b 100644
--- a/crypto/sha2.c
+++ b/crypto/sha2.c
@@ -327,6 +327,7 @@ static struct digest_algo m224 = {
.name = "sha224",
.driver_name = "sha224-generic",
.priority = 0,
+ .algo = HASH_ALGO_SHA224,
},
.init = sha224_init,
@@ -352,6 +353,7 @@ static struct digest_algo m256 = {
.name = "sha256",
.driver_name = "sha256-generic",
.priority = 0,
+ .algo = HASH_ALGO_SHA256,
},
.init = sha256_init,
diff --git a/crypto/sha4.c b/crypto/sha4.c
index 187a91ef584d..4ce37b73e4ae 100644
--- a/crypto/sha4.c
+++ b/crypto/sha4.c
@@ -246,6 +246,7 @@ static struct digest_algo m384 = {
.name = "sha384",
.driver_name = "sha384-generic",
.priority = 0,
+ .algo = HASH_ALGO_SHA384,
},
.init = sha384_init,
@@ -272,6 +273,7 @@ static struct digest_algo m512 = {
.name = "sha512",
.driver_name = "sha512-generic",
.priority = 0,
+ .algo = HASH_ALGO_SHA512,
},
.init = sha512_init,
diff --git a/include/digest.h b/include/digest.h
index 3a9d305963ef..fe30cc27e0fc 100644
--- a/include/digest.h
+++ b/include/digest.h
@@ -23,12 +23,34 @@
struct digest;
+enum hash_algo {
+ HASH_ALGO_MD4,
+ HASH_ALGO_MD5,
+ HASH_ALGO_SHA1,
+ HASH_ALGO_RIPE_MD_160,
+ HASH_ALGO_SHA224,
+ HASH_ALGO_SHA256,
+ HASH_ALGO_SHA384,
+ HASH_ALGO_SHA512,
+ HASH_ALGO_RIPE_MD_128,
+ HASH_ALGO_RIPE_MD_256,
+ HASH_ALGO_RIPE_MD_320,
+ HASH_ALGO_WP_256,
+ HASH_ALGO_WP_384,
+ HASH_ALGO_WP_512,
+ HASH_ALGO_TGR_128,
+ HASH_ALGO_TGR_160,
+ HASH_ALGO_TGR_192,
+ HASH_ALGO__LAST
+};
+
struct crypto_alg {
char *name;
char *driver_name;
int priority;
#define DIGEST_ALGO_NEED_KEY (1 << 0)
unsigned int flags;
+ enum hash_algo algo;
};
struct digest_algo {
@@ -65,6 +87,7 @@ void digest_algo_unregister(struct digest_algo *d);
void digest_algo_prints(const char *prefix);
struct digest *digest_alloc(const char *name);
+struct digest *digest_alloc_by_algo(enum hash_algo);
void digest_free(struct digest *d);
int digest_file_window(struct digest *d, const char *filename,
--
2.6.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-01-05 8:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-05 8:11 [PATCH 0/3] FIT Support Marc Kleine-Budde
2016-01-05 8:11 ` Marc Kleine-Budde [this message]
2016-01-05 16:54 ` [PATCH 1/3] crypto: add enum Sam Ravnborg
2016-01-06 14:39 ` Marc Kleine-Budde
2016-01-06 16:55 ` Sam Ravnborg
2016-01-05 8:11 ` [PATCH 2/3] crypto: add RSA support Marc Kleine-Budde
2016-01-05 8:11 ` [PATCH 3/3] bootm: add initial FIT support Marc Kleine-Budde
2016-01-05 10:28 ` Yegor Yefremov
2016-01-05 10:32 ` Marc Kleine-Budde
2016-01-05 10:40 ` Yegor Yefremov
2016-01-05 11:54 ` Marc Kleine-Budde
2016-01-05 13:05 ` Yegor Yefremov
2016-01-05 13:50 ` Marc Kleine-Budde
2016-01-05 13:58 ` Yegor Yefremov
2016-01-07 17:09 ` Jan Lübbe
2016-01-08 10:36 ` Yegor Yefremov
2016-01-05 20:28 ` Trent Piepho
2016-01-06 16:09 ` Marc Kleine-Budde
2016-01-07 17:00 ` Jan Lübbe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1451981463-23604-2-git-send-email-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=kernel@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox