| Submitter | Simon Glass |
|---|---|
| Date | Nov. 3, 2012, 12:27 a.m. |
| Message ID | <1351902453-27956-10-git-send-email-sjg@chromium.org> |
| Download | mbox | patch |
| Permalink | /patch/196785/ |
| State | Superseded, archived |
| Delegated to: | Tom Rini |
| Headers | show |
Comments
Dear Simon Glass, In message <1351902453-27956-10-git-send-email-sjg@chromium.org> you wrote: > From: ARUN MANKUZHI <arun.m@samsung.com> > > sha256 command is added which can be used to test SHA 256 hash > algorithm. > > Signed-off-by: ARUN MANKUZHI <arun.m@samsung.com> > Signed-off-by: Simon Glass <sjg@chromium.org> > --- > README | 1 + > common/Makefile | 1 + > common/cmd_sha256.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ > include/config_cmd_all.h | 1 + > 4 files changed, 60 insertions(+), 0 deletions(-) > create mode 100644 common/cmd_sha256.c Please make sure interface and functionality is similar to what we do elsewhere, i. e. with the crc32 command. > +U_BOOT_CMD( > + sha256, 4, 1, do_sha256, > + "print hash result", > + "<input> <inputlength> <output>" > +); What is "<input>" or "<output>" supposed to mean? I don;t understand this. "<output>" should not be mandatory. I would appreciate if we could use similar help text as with the crc32 command: crc32 - checksum calculation Usage: crc32 address count [addr] - compute CRC32 checksum [save at addr] Best regards, Wolfgang Denk
Hi Wolfgang, On Sat, Nov 3, 2012 at 8:23 AM, Wolfgang Denk <wd@denx.de> wrote: > Dear Simon Glass, > > In message <1351902453-27956-10-git-send-email-sjg@chromium.org> you wrote: >> From: ARUN MANKUZHI <arun.m@samsung.com> >> >> sha256 command is added which can be used to test SHA 256 hash >> algorithm. >> >> Signed-off-by: ARUN MANKUZHI <arun.m@samsung.com> >> Signed-off-by: Simon Glass <sjg@chromium.org> >> --- >> README | 1 + >> common/Makefile | 1 + >> common/cmd_sha256.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ >> include/config_cmd_all.h | 1 + >> 4 files changed, 60 insertions(+), 0 deletions(-) >> create mode 100644 common/cmd_sha256.c > > Please make sure interface and functionality is similar to what we do > elsewhere, i. e. with the crc32 command. OK I didn't notice some new patches in SHA1 also, which provide an enhanced command similar to crc32. It's isn't really sensible to duplicate that code. Thanks for pointing that out. I think we should come up with some sort of generic hashing command which can deal with multiple algorithms. Then SHA1 and SHA256 at least can share the same basic parsing / verification code. I will take a look at this, and put it in a new version of this series. > >> +U_BOOT_CMD( >> + sha256, 4, 1, do_sha256, >> + "print hash result", >> + "<input> <inputlength> <output>" >> +); > > What is "<input>" or "<output>" supposed to mean? I don;t understand > this. > > "<output>" should not be mandatory. I would appreciate if we > could use similar help text as with the crc32 command: > > crc32 - checksum calculation > > Usage: > crc32 address count [addr] > - compute CRC32 checksum [save at addr] > > > Best regards, > > Wolfgang Denk > > -- > DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de > "Love is an ideal thing, marriage a real thing; a confusion of the > real with the ideal never goes unpunished." - Goethe Regards, Simon
Patch
diff --git a/README b/README index 785953f..31e25fe 100644 --- a/README +++ b/README @@ -861,6 +861,7 @@ The following options need to be configured: (requires CONFIG_CMD_I2C) CONFIG_CMD_SETGETDCR Support for DCR Register access (4xx only) + CONFIG_CMD_SHA256 * Calculate SHA256 for block CONFIG_CMD_SF * Read/write/erase SPI NOR flash CONFIG_CMD_SHA1SUM print sha1 memory digest (requires CONFIG_CMD_MEMORY) diff --git a/common/Makefile b/common/Makefile index 84968f8..6f6f0fa 100644 --- a/common/Makefile +++ b/common/Makefile @@ -150,6 +150,7 @@ COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o COBJS-$(CONFIG_CMD_SHA1SUM) += cmd_sha1sum.o COBJS-$(CONFIG_CMD_SETEXPR) += cmd_setexpr.o +COBJS-$(CONFIG_CMD_SHA256) += cmd_sha256.o COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o COBJS-$(CONFIG_CMD_SPIBOOTLDR) += cmd_spibootldr.o COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o diff --git a/common/cmd_sha256.c b/common/cmd_sha256.c new file mode 100644 index 0000000..006391d --- /dev/null +++ b/common/cmd_sha256.c @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <command.h> +#include <sha256.h> + +int do_sha256(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + unsigned long inlen; + unsigned char *input, *out; + int i; + sha256_context sha_cnxt; + if (argc < 4) { + printf("usage: sha256 <input> <input length> <output>\n"); + return 0; + } + input = (unsigned char *)simple_strtoul(argv[1], NULL, 16); + inlen = simple_strtoul(argv[2], NULL, 16); + out = (unsigned char *)simple_strtoul(argv[3], NULL, 16); + + sha256_starts(&sha_cnxt); + sha256_update(&sha_cnxt, input, inlen); + sha256_finish(&sha_cnxt, out); + + for (i = 0; i < 32; i++) + printf("0x%02X ", out[i]); + printf("\n"); + + return 0; +} + +U_BOOT_CMD( + sha256, 4, 1, do_sha256, + "print hash result", + "<input> <inputlength> <output>" +); diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h index 148d676..efd17e6 100644 --- a/include/config_cmd_all.h +++ b/include/config_cmd_all.h @@ -79,6 +79,7 @@ #define CONFIG_CMD_SDRAM /* SDRAM DIMM SPD info printout */ #define CONFIG_CMD_SETEXPR /* setexpr support */ #define CONFIG_CMD_SETGETDCR /* DCR support on 4xx */ +#define CONFIG_CMD_SHA256 /* Calculate SHA256 for block */ #define CONFIG_CMD_SNTP /* SNTP support */ #define CONFIG_CMD_SOURCE /* "source" command support */ #define CONFIG_CMD_SPI /* SPI utility */