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/9] command: digest/hashsum: set key command level
Date: Wed, 25 Mar 2015 12:56:12 +0100	[thread overview]
Message-ID: <1427284580-30218-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20150325115140.GD8125@ns203013.ovh.net>

and only set the key when specified

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/digest.c   | 27 ++++++++++-----------------
 commands/hashsum.c  | 10 ++++++++--
 commands/internal.h |  3 +--
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/commands/digest.c b/commands/digest.c
index 876c37a..79ce705 100644
--- a/commands/digest.c
+++ b/commands/digest.c
@@ -17,8 +17,7 @@
 
 #include "internal.h"
 
-int __do_digest(struct digest *d, unsigned char *key, int keylen,
-		       unsigned char *sig,
+int __do_digest(struct digest *d, unsigned char *sig,
 		       int argc, char *argv[])
 {
 	int ret = COMMAND_ERROR_USAGE;
@@ -28,17 +27,6 @@ int __do_digest(struct digest *d, unsigned char *key, int keylen,
 	if (argc < 1)
 		goto err;
 
-	if (key) {
-		ret = digest_set_key(d, key, keylen);
-		if (ret) {
-			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));
 	if (!hash) {
 		perror("calloc");
@@ -147,10 +135,15 @@ static int do_digest(int argc, char *argv[])
 		}
 	}
 
-	ret = digest_set_key(d, key, keylen);
-	free(tmp_key);
-	if (ret)
+	if (key) {
+		ret = digest_set_key(d, key, keylen);
+		free(tmp_key);
+		if (ret)
+			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;
+	}
 
 	if (sigfile) {
 		sig = tmp_sig = read_file(sigfile, &siglen);
@@ -178,7 +171,7 @@ static int do_digest(int argc, char *argv[])
 		}
 	}
 
-	ret = __do_digest(d, NULL, 0, sig, argc, argv);
+	ret = __do_digest(d, sig, argc, argv);
 	free(tmp_sig);
 	return ret;
 
diff --git a/commands/hashsum.c b/commands/hashsum.c
index dc48af5..071fb84 100644
--- a/commands/hashsum.c
+++ b/commands/hashsum.c
@@ -49,15 +49,21 @@ static int do_hash(char *algo, int argc, char *argv[])
 		char *tmp = asprintf("hmac(%s)", algo);
 		d = digest_alloc(tmp);
 		free(tmp);
+		BUG_ON(!d);
+
+		ret = digest_set_key(d, key, keylen);
+		if (ret) {
+			perror("set_key");
+			return ret;
 	} else {
 		d = digest_alloc(algo);
+		BUG_ON(!d);
 	}
-	BUG_ON(!d);
 
 	argc -= optind;
 	argv += optind;
 
-	return __do_digest(d, key, keylen, NULL, argc, argv);
+	return __do_digest(d, NULL, argc, argv);
 }
 
 #ifdef CONFIG_CMD_MD5SUM
diff --git a/commands/internal.h b/commands/internal.h
index 29cc656..21d1408 100644
--- a/commands/internal.h
+++ b/commands/internal.h
@@ -1,3 +1,2 @@
-int __do_digest(struct digest *d, unsigned char *key, int keylen,
-		       unsigned char *sig,
+int __do_digest(struct digest *d, unsigned char *sig,
 		       int argc, char *argv[]);
-- 
2.1.4


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

  reply	other threads:[~2015-03-25 11:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-25 11:51 [PATCH 0/9 v3] digest: allow multiple implementation of digest Jean-Christophe PLAGNIOL-VILLARD
2015-03-25 11:56 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2015-03-25 11:56   ` [PATCH 2/9] digest: allow algo to specify their length at runtime Jean-Christophe PLAGNIOL-VILLARD
2015-03-25 11:56   ` [PATCH 3/9] crypto: prepare to allow multiple digest driver Jean-Christophe PLAGNIOL-VILLARD
2015-03-25 11:56   ` [PATCH 4/9] crypto: hmac: move register to hmac Jean-Christophe PLAGNIOL-VILLARD
2015-06-15 14:27     ` Marc Kleine-Budde
2015-03-25 11:56   ` [PATCH 5/9] crypto: sha1: switch to linux implementation Jean-Christophe PLAGNIOL-VILLARD
2015-03-25 11:56   ` [PATCH 6/9] crypto: sha256: " Jean-Christophe PLAGNIOL-VILLARD
2015-03-25 11:56   ` [PATCH 7/9] crypto: sha512: " Jean-Christophe PLAGNIOL-VILLARD
2015-03-25 11:56   ` [PATCH 8/9] arm: crypto: add sha1 assembly support Jean-Christophe PLAGNIOL-VILLARD
2015-03-25 11:56   ` [PATCH 9/9] arm: crypto: add sha256 " Jean-Christophe PLAGNIOL-VILLARD
2015-03-26  6:46 ` [PATCH 0/9 v3] digest: allow multiple implementation of digest Sascha Hauer
2015-03-31 15:44 ` Antony Pavlov
2015-03-31 17:33   ` Jean-Christophe PLAGNIOL-VILLARD

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=1427284580-30218-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