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 1/2] crypto: digest: speficied when a digest need a key to be used
Date: Wed, 18 Mar 2015 10:37:53 +0100	[thread overview]
Message-ID: <1426671474-13613-1-git-send-email-plagnioj@jcrosoft.com> (raw)

such as for hmac(xxx) you must provide a key

This will allow to enforce the correct parameter at digest command

<digest>sum is not impacted

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/digest.c |  3 +++
 crypto/hmac.c     |  1 +
 include/digest.h  | 12 ++++++++++++
 3 files changed, 16 insertions(+)

diff --git a/commands/digest.c b/commands/digest.c
index fa47f24..876c37a 100644
--- a/commands/digest.c
+++ b/commands/digest.c
@@ -34,6 +34,9 @@ int __do_digest(struct digest *d, unsigned char *key, int keylen,
 			perror("set_key");
 			goto err;
 		}
+	} else if (digest_is_flags(d, DIGEST_ALGO_NEED_KEY)) {
+		eprintf("%s need a key to be used\n", digest_name(d));
+		goto err;
 	}
 
 	hash = calloc(digest_length(d), sizeof(unsigned char));
diff --git a/crypto/hmac.c b/crypto/hmac.c
index c2195d9..4c6a703 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -145,6 +145,7 @@ err:
 }
 
 struct digest_algo hmac_algo = {
+	.flags = DIGEST_ALGO_NEED_KEY,
 	.alloc = digest_hmac_alloc,
 	.init = digest_hmac_init,
 	.update = digest_hmac_update,
diff --git a/include/digest.h b/include/digest.h
index 300ea4e..c574b4d 100644
--- a/include/digest.h
+++ b/include/digest.h
@@ -25,6 +25,8 @@ struct digest;
 
 struct digest_algo {
 	char *name;
+#define DIGEST_ALGO_NEED_KEY	(1 << 0)
+	unsigned int flags;
 
 	int (*alloc)(struct digest *d);
 	void (*free)(struct digest *d);
@@ -109,4 +111,14 @@ static inline int digest_set_key(struct digest *d, const unsigned char *key,
 	return d->algo->set_key(d, key, len);
 }
 
+static inline int digest_is_flags(struct digest *d, unsigned int flags)
+{
+	return d->algo->flags & flags;
+}
+
+static inline const char *digest_name(struct digest *d)
+{
+	return d->algo->name;
+}
+
 #endif /* __SH_ST_DEVICES_H__ */
-- 
2.1.4


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

             reply	other threads:[~2015-03-18  9:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18  9:37 Jean-Christophe PLAGNIOL-VILLARD [this message]
2015-03-18  9:37 ` [PATCH 2/2] password: add pbkdf2 support Jean-Christophe PLAGNIOL-VILLARD
2015-03-19  6:53 ` [PATCH 1/2] crypto: digest: speficied when a digest need a key to be used 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=1426671474-13613-1-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