summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2015-03-11 17:53:09 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-03-13 08:32:28 +0100
commit102d59f91fdd327c68c1b7a8c43f3f4685422f52 (patch)
treec000562ea082fd45641872c6b3e016ad3a4852e0 /commands
parent2f3c3f512b2ff5023a4177e167eb6b55055fe883 (diff)
downloadbarebox-102d59f91fdd327c68c1b7a8c43f3f4685422f52.tar.gz
barebox-102d59f91fdd327c68c1b7a8c43f3f4685422f52.tar.xz
command: add hmac sum supportfor md5, sha1, sha224, sha256, sha384, sha512
pass the key via -h param barebox@barebox sandbox:/ sha256sum -h test /dev/fd0 c297473e9bb221c5dc51d47ad75c76095f1bdc4ca9dff1d5931c2e22bf11a0de /dev/fd0 0x00000000 ... 0xffffffffffffffff use the same idea as openssl command $ openssl dgst -sha256 -hmac "test" TODO HMAC-SHA256(TODO)= c297473e9bb221c5dc51d47ad75c76095f1bdc4ca9dff1d5931c2e22bf11a0de Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/digest.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/commands/digest.c b/commands/digest.c
index 20fa13f303..701e6a16fa 100644
--- a/commands/digest.c
+++ b/commands/digest.c
@@ -25,6 +25,7 @@
#include <xfuncs.h>
#include <malloc.h>
#include <digest.h>
+#include <getopt.h>
static int do_digest(char *algorithm, int argc, char *argv[])
{
@@ -32,11 +33,32 @@ static int do_digest(char *algorithm, int argc, char *argv[])
int ret = 0;
int i;
unsigned char *hash;
+ unsigned char *key = NULL;
+ size_t keylen = 0;
+ int opt;
+
+ while((opt = getopt(argc, argv, "h:")) > 0) {
+ switch(opt) {
+ case 'h':
+ key = optarg;
+ keylen = strlen(key);
+ break;
+ }
+ }
- d = digest_alloc(algorithm);
+ argc -= optind;
+ argv += optind;
+
+ if (key) {
+ char *tmp = asprintf("hmac(%s)", algorithm);
+ d = digest_alloc(tmp);
+ free(tmp);
+ } else {
+ d = digest_alloc(algorithm);
+ }
BUG_ON(!d);
- if (argc < 2)
+ if (argc < 1)
return COMMAND_ERROR_USAGE;
hash = calloc(digest_length(d), sizeof(unsigned char));
@@ -45,7 +67,6 @@ static int do_digest(char *algorithm, int argc, char *argv[])
return COMMAND_ERROR_USAGE;
}
- argv++;
while (*argv) {
char *filename = "/dev/mem";
loff_t start = 0, size = ~0;
@@ -53,11 +74,14 @@ static int do_digest(char *algorithm, int argc, char *argv[])
/* arguments are either file, file+area or area */
if (parse_area_spec(*argv, &start, &size)) {
filename = *argv;
- if (argv[1] && !parse_area_spec(argv[1], &start, &size))
+ if (argv[0] && !parse_area_spec(argv[0], &start, &size))
argv++;
}
- if (digest_file_window(d, filename, hash, start, size) < 0) {
+ ret = digest_file_window(d, filename,
+ key, keylen,
+ hash, start, size);
+ if (ret < 0) {
ret = 1;
} else {
for (i = 0; i < digest_length(d); i++)