summaryrefslogtreecommitdiffstats
path: root/commands/digest.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2015-03-25 12:56:12 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-03-27 07:49:37 +0100
commit5afec9c781406a0aa3080c9aacb17c3f75abc0aa (patch)
tree355be5f292a43c7923bd07e3715cff4087518d3b /commands/digest.c
parente49a47fba8bce3bc4457d7b5133d7366b99513e3 (diff)
downloadbarebox-5afec9c781406a0aa3080c9aacb17c3f75abc0aa.tar.gz
barebox-5afec9c781406a0aa3080c9aacb17c3f75abc0aa.tar.xz
command: digest/hashsum: set key at command level
and only set the key when specified Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/digest.c')
-rw-r--r--commands/digest.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/commands/digest.c b/commands/digest.c
index b6bce88297..340c07a248 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;