summaryrefslogtreecommitdiffstats
path: root/commands/hashsum.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/hashsum.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/hashsum.c')
-rw-r--r--commands/hashsum.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/commands/hashsum.c b/commands/hashsum.c
index dc48af53d8..e2dc70e68d 100644
--- a/commands/hashsum.c
+++ b/commands/hashsum.c
@@ -34,7 +34,7 @@ static int do_hash(char *algo, int argc, char *argv[])
struct digest *d;
unsigned char *key = NULL;
size_t keylen = 0;
- int opt;
+ int opt, ret;
while((opt = getopt(argc, argv, "h:")) > 0) {
switch(opt) {
@@ -49,15 +49,22 @@ 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