mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 7/7] command: add generic digest command
Date: Fri, 13 Mar 2015 09:32:11 +0100	[thread overview]
Message-ID: <20150313083211.GW30554@ns203013.ovh.net> (raw)
In-Reply-To: <20150313072616.GK24885@pengutronix.de>

> > +
> > +static int do_digest(int argc, char *argv[])
> > +{
> > +	struct digest *d;
> > +	unsigned char *tmp_key = NULL;
> > +	unsigned char *tmp_sig = NULL;
> > +	char *sig = NULL;
> > +	char *sigfile = NULL;
> > +	size_t siglen = 0;
> > +	char *key = NULL;
> > +	char *keyfile = NULL;
> > +	size_t keylen = 0;
> > +	size_t digestlen = 0;
> > +	char *algo = NULL;
> > +	int opt, ret;
> > +
> > +	if (argc < 2) {
> > +		__prints_algo();
> > +		return 0;
> > +	}
> 
> This is an untuitive trigger to print the available algos. Can we add an
> explicit option here?

I would have prefer via help cmd but not possible to have runtime help txt
> 
> > +
> > +	while((opt = getopt(argc, argv, "a:k:K:s:S:")) > 0) {
> > +		switch(opt) {
> > +		case 'k':
> > +			key = optarg;
> > +			keylen = strlen(key);
> > +			break;
> > +		case 'K':
> > +			keyfile = optarg;
> > +			break;
> > +		case 'a':
> > +			algo = optarg;
> > +			break;
> > +		case 's':
> > +			sig = optarg;
> > +			siglen = strlen(sig);
> > +			break;
> > +		case 'S':
> > +			sigfile = optarg;
> > +			break;
> > +		}
> > +	}
> > +
> > +	if (!algo)
> > +		return COMMAND_ERROR_USAGE;
> > +
> > +	d = digest_alloc(algo);
> > +	if (!d) {
> > +		eprintf("algo '%s' not found\n", algo);
> > +		__prints_algo();
> > +		return COMMAND_ERROR_USAGE;
> > +	}
> > +
> > +	argc -= optind;
> > +	argv += optind;
> > +
> > +	if (keyfile) {
> > +		tmp_key = key = read_file(keyfile, &keylen);
> 
> Why two variables? Both tmp_key and key are never changed.
'key' can be from optarg so we can not free it

otherwise if need to xstrdup it when parsing the getopt
> 
> > +		if (!key) {
> > +			eprintf("file '%s' not found\n", keyfile);
> > +			goto err;
> > +		}
> > +	}
> > +
> > +	digest_set_key(d, key, keylen);
> 
> This can fail. You should check the error code.
yeah
> 
> > +unsigned char to_digit(unsigned char c)
> > +{
> > +	if (c >= '0' && c <= '9')
> > +		c -= '0';
> > +	else
> > +		c -= 'a' - 10;
> > +
> > +	return c;
> > +}
> > +
> > +unsigned char to_hexa(unsigned char c)
> > +{
> > +	if (c < 10)
> > +		c += '0';
> > +	else
> > +		c += 'a' - 10;
> > +
> > +	return c;
> > +}
> > +
> > +int base64_to_hex(const unsigned char *sum, unsigned char *buf, size_t length)
> > +{
> 
> The ASCII input here contains hex digits, base64 is something different.
> Also these functions are useful enough to be always available, not only
> when digest is enabled.
> 
> I just sent a patch containing the kernels implementation of bin2hex and
> hex2bin. Please base on this one.

ok

Best Regards,
J.

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

  reply	other threads:[~2015-03-13  8:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-12 14:19 [PATCH 0/7] prepare for rsa support Jean-Christophe PLAGNIOL-VILLARD
2015-03-12 14:22 ` [PATCH 1/7] digest: fix and add missing copyright Jean-Christophe PLAGNIOL-VILLARD
2015-03-12 14:22   ` [PATCH 2/7] digest: hmac: fix set_key prototype Jean-Christophe PLAGNIOL-VILLARD
2015-03-12 14:22   ` [PATCH 3/7] crypto: add pbkdf2 hmac key generator Jean-Christophe PLAGNIOL-VILLARD
2015-03-12 14:22   ` [PATCH 4/7] digest: add verify callback Jean-Christophe PLAGNIOL-VILLARD
2015-03-12 14:55     ` Jan Lübbe
2015-03-12 17:41     ` Sascha Hauer
2015-03-12 18:56       ` Jean-Christophe PLAGNIOL-VILLARD
2015-03-12 14:22   ` [PATCH 5/7] digest: allow algo to specify their length at runtime Jean-Christophe PLAGNIOL-VILLARD
2015-03-13  7:28     ` Sascha Hauer
2015-03-12 14:22   ` [PATCH 6/7] command: rename digest.c to hashsum.c Jean-Christophe PLAGNIOL-VILLARD
2015-03-12 14:22   ` [PATCH 7/7] command: add generic digest command Jean-Christophe PLAGNIOL-VILLARD
2015-03-13  7:26     ` Sascha Hauer
2015-03-13  8:32       ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2015-03-13  8:42         ` [PATCH 1/1] command: allow runtime usage Jean-Christophe PLAGNIOL-VILLARD
2015-03-13 18:46           ` Robert Schwebel
2015-03-13  7:33   ` [PATCH 1/7] digest: fix and add missing copyright 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=20150313083211.GW30554@ns203013.ovh.net \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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