mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 4/9] digest: add digest callback
Date: Tue, 17 Mar 2015 12:53:11 +0100	[thread overview]
Message-ID: <1426593196-12509-4-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1426593196-12509-1-git-send-email-plagnioj@jcrosoft.com>

Combination of @init and @update and @final. This function
effectively behaves as the entire chain of operations, @init,
@update and @final issued in sequence. This is added for hardware
which cannot do even the @finup, but can only do the whole
transformation in one run.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 crypto/digest.c   | 18 ++++++++++++++++++
 crypto/hmac.c     |  1 +
 crypto/internal.h |  2 ++
 crypto/md5.c      |  1 +
 crypto/sha1.c     |  1 +
 crypto/sha2.c     |  1 +
 crypto/sha4.c     |  1 +
 include/digest.h  |  8 ++++++++
 8 files changed, 33 insertions(+)

diff --git a/crypto/digest.c b/crypto/digest.c
index 7869c04..7670ed0 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -58,6 +58,24 @@ end:
 	return ret;
 }
 
+int digest_generic_digest(struct digest *d, const void *data,
+			  unsigned int len, u8 *md)
+
+{
+	int ret;
+
+	if (!data || len == 0 || !md)
+		return -EINVAL;
+
+	ret = digest_init(d);
+	if (ret)
+		return ret;
+	ret = digest_update(d, data, len);
+	if (ret)
+		return ret;
+	return digest_final(d, md);
+}
+
 int digest_algo_register(struct digest_algo *d)
 {
 	if (!d || !d->name || !d->update || !d->final || !d->verify ||
diff --git a/crypto/hmac.c b/crypto/hmac.c
index f39e4c8..b1c17af 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -136,6 +136,7 @@ struct digest_algo hmac_algo = {
 	.init = digest_hmac_init,
 	.update = digest_hmac_update,
 	.final = digest_hmac_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.set_key = digest_hmac_set_key,
 	.free = digest_hmac_free,
diff --git a/crypto/internal.h b/crypto/internal.h
index f482654..c6f5908 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -15,3 +15,5 @@ static inline int digest_hmac_register(struct digest_algo *algo,
 #endif
 
 int digest_generic_verify(struct digest *d, const unsigned char *md);
+int digest_generic_digest(struct digest *d, const void *data,
+			  unsigned int len, u8 *out);
diff --git a/crypto/md5.c b/crypto/md5.c
index 4847b38..b7ad6f2 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -294,6 +294,7 @@ static struct digest_algo md5 = {
 	.init = digest_md5_init,
 	.update = digest_md5_update,
 	.final = digest_md5_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = 16,
 	.ctx_length = sizeof(struct MD5Context),
diff --git a/crypto/sha1.c b/crypto/sha1.c
index 09dee87..b108f8a 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -315,6 +315,7 @@ static struct digest_algo m = {
 	.init = digest_sha1_init,
 	.update = digest_sha1_update,
 	.final = digest_sha1_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = SHA1_SUM_LEN,
 	.ctx_length = sizeof(sha1_context),
diff --git a/crypto/sha2.c b/crypto/sha2.c
index 9bf6541..375a40e 100644
--- a/crypto/sha2.c
+++ b/crypto/sha2.c
@@ -336,6 +336,7 @@ static struct digest_algo m256 = {
 	.init = digest_sha256_init,
 	.update = digest_sha2_update,
 	.final = digest_sha2_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = SHA256_SUM_LEN,
 	.ctx_length = sizeof(sha2_context),
diff --git a/crypto/sha4.c b/crypto/sha4.c
index 5c3097d..1b91e7f 100644
--- a/crypto/sha4.c
+++ b/crypto/sha4.c
@@ -342,6 +342,7 @@ static struct digest_algo m512 = {
 	.init = digest_sha512_init,
 	.update = digest_sha4_update,
 	.final = digest_sha4_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = SHA512_SUM_LEN,
 	.ctx_length = sizeof(sha4_context),
diff --git a/include/digest.h b/include/digest.h
index 5d1d80c..718793a 100644
--- a/include/digest.h
+++ b/include/digest.h
@@ -31,6 +31,8 @@ struct digest_algo {
 	int (*init)(struct digest *d);
 	int (*update)(struct digest *d, const void *data, unsigned long len);
 	int (*final)(struct digest *d, unsigned char *md);
+	int (*digest)(struct digest *d, const void *data,
+		      unsigned int len, u8 *out);
 	int (*set_key)(struct digest *d, const unsigned char *key, unsigned int len);
 	int (*verify)(struct digest *d, const unsigned char *md);
 
@@ -78,6 +80,12 @@ static inline int digest_final(struct digest *d, unsigned char *md)
 	return d->algo->final(d, md);
 }
 
+static inline int digest_digest(struct digest *d, const void *data,
+		      unsigned int len, u8 *md)
+{
+	return d->algo->digest(d, data, len, md);
+}
+
 static inline int digest_verify(struct digest *d, const unsigned char *md)
 {
 	return d->algo->verify(d, md);
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-03-17 11:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-17 11:49 [PATCH 0/9 v4] prepare for rsa support Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53 ` [PATCH 1/9] crypto: digest: digest_file_window: check every digest_xxx return Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53   ` [PATCH 2/9] crypto: digest: digest_file_window/digest_file/digest_file_by_name drop key params Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53   ` [PATCH 3/9] digest: add verify callback Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2015-03-17 11:53   ` [PATCH 5/9] crypto: hmac: use digest_digest and check the return of every digest_xxx Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53   ` [PATCH 6/9] crypto: add pbkdf2 hmac key generator Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53   ` [PATCH 7/9] command: allow runtime usage Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53   ` [PATCH 8/9] command: rename digest.c to hashsum.c Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 11:53   ` [PATCH 9/9] command: add generic digest command Jean-Christophe PLAGNIOL-VILLARD
2015-03-17 12:54 ` [PATCH 0/9 v4] prepare for rsa support Jan Lübbe
2015-03-18  7:44 ` Sascha Hauer

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=1426593196-12509-4-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /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