From patchwork Thu Nov 22 19:12:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 201150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 1D27F2C0089 for ; Fri, 23 Nov 2012 06:17:20 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9108B4A0F3; Thu, 22 Nov 2012 20:16:57 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A9pRE1pOhxVX; Thu, 22 Nov 2012 20:16:57 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A731B4A0F5; Thu, 22 Nov 2012 20:15:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3955B4A0A2 for ; Thu, 22 Nov 2012 20:15:06 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LqDe5ejB0Oa2 for ; Thu, 22 Nov 2012 20:15:05 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-vc0-f202.google.com (mail-vc0-f202.google.com [209.85.220.202]) by theia.denx.de (Postfix) with ESMTPS id 6B7754A039 for ; Thu, 22 Nov 2012 20:14:47 +0100 (CET) Received: by mail-vc0-f202.google.com with SMTP id m8so442435vcd.3 for ; Thu, 22 Nov 2012 11:14:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=lEv4ef+/l6C7r0VwOQg0J31mE9h8l0YPOnsucTMebtY=; b=jSVHQPRiVEvwW/aOKe3vaDbFA7QQXI3ObA82jcrsHMrWo3KGHvWn5fkMImxadr2kav 1q7rbBXWYUch/dx+hhSu5X/qZtCtraaXzo5Gqt8z7l1hjR1rrf0pGpp7vJL3pFlcfK5p ZrBkASKoiCgS9e4yrXXKzhn1eQk6Ot6dYqomBwxKAbL6NpkhI4nNAiodD3HgwD2A0cFG DDDbOMuVK4veaOy+AtOXMh8nuHUmKStuAQY67tT25cN/OCrDc48g3trfzxHconnk+iHI GyVmDFrEQpXdWESsHb9N0sE6flSS0NLMYPcPZxONr3zcj6lUNNTpbwNS/DiHWm9iLBe+ BACw== Received: by 10.236.151.39 with SMTP id a27mr885163yhk.42.1353611686681; Thu, 22 Nov 2012 11:14:46 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id h50si280041yhi.3.2012.11.22.11.14.46 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 22 Nov 2012 11:14:46 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 8261282004A; Thu, 22 Nov 2012 11:14:46 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 3AD65160C95; Thu, 22 Nov 2012 11:14:46 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 22 Nov 2012 11:12:56 -0800 Message-Id: <1353611587-18186-13-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1353611587-18186-1-git-send-email-sjg@chromium.org> References: <1353611587-18186-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlQpRlRfMc5O3bz/Aw/ZfO6HQAP7vpcHe/uxOMo7JapG9JHTxxfHQX3EMPY6NcZqaOa08GPN+zUjiWh0mOgmIPGH9SMwn84DZRrOpviKSquehMp3ovVePHHYuXBlPFJtro2HX3WGb+2FLlEI//g+K/CmI3A61/xOuVYraK/bKYh5tl4Z3hzQ2dNH57YkmccARAFw2EN Cc: Tom Rini Subject: [U-Boot] [PATCH v2 12/23] Add hash command to perform hashing using various algorithms X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This new command supports hashing SHA1 and SHA256. It could be extended to others such as MD5 and the CRC algorithms. The syntax is modeled on those: hash
[* | ] to calculate a hash, and: hash -v
[* | ] to verify a hash. Use CONFIG_CMD_HASH to enable the command, CONFIG_SHA1 to enable SHA1 and CONFIG_SHA256 to enable SHA256. The existing sha1sum command remains. Signed-off-by: Simon Glass --- Changes in v2: - Add new hash command to support generic hash API README | 18 +++++++++++++ common/Makefile | 1 + common/cmd_hash.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ include/config_cmd_all.h | 1 + 4 files changed, 83 insertions(+), 0 deletions(-) create mode 100644 common/cmd_hash.c diff --git a/README b/README index 6378101..2a0098d 100644 --- a/README +++ b/README @@ -822,6 +822,7 @@ The following options need to be configured: CONFIG_CMD_GETTIME * Get time since boot CONFIG_CMD_GO * the 'go' command (exec code) CONFIG_CMD_GREPENV * search environment + CONFIG_CMD_HASH * calculate hash / digest CONFIG_CMD_HWFLOW * RTS/CTS hw flow control CONFIG_CMD_I2C * I2C serial bus support CONFIG_CMD_IDE * IDE harddisk support @@ -2391,6 +2392,23 @@ CBFS (Coreboot Filesystem) support A better solution is to properly configure the firewall, but sometimes that is not allowed. +- Hashing support: + CONFIG_CMD_HASH + + This enables a generic 'hash' command which can produce + hashes / digests from a few algorithms (e.g. SHA1, SHA256). + + CONFIG_HASH_VERIFY + + Enable the hash verify command (hash -v). This adds to code + size a little. + + CONFIG_SHA1 - support SHA1 hashing + CONFIG_SHA256 - support SHA256 hashing + + Note: There is also a sha1sum command, which should perhaps + be deprecated in favour of 'hash sha1'. + - Show boot progress: CONFIG_SHOW_BOOT_PROGRESS diff --git a/common/Makefile b/common/Makefile index eb175c1..56ec4e4 100644 --- a/common/Makefile +++ b/common/Makefile @@ -104,6 +104,7 @@ COBJS-$(CONFIG_CMD_FS_GENERIC) += cmd_fs.o COBJS-$(CONFIG_CMD_GETTIME) += cmd_gettime.o COBJS-$(CONFIG_CMD_GPIO) += cmd_gpio.o COBJS-$(CONFIG_CMD_I2C) += cmd_i2c.o +COBJS-$(CONFIG_CMD_HASH) += cmd_hash.o COBJS-$(CONFIG_CMD_IDE) += cmd_ide.o COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o COBJS-$(CONFIG_CMD_INI) += cmd_ini.o diff --git a/common/cmd_hash.c b/common/cmd_hash.c new file mode 100644 index 0000000..10ce03e --- /dev/null +++ b/common/cmd_hash.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012 The Chromium OS Authors. + * + * (C) Copyright 2011 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * (C) Copyright 2000 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * 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 +#include +#include + +static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ +#ifdef CONFIG_HASH_VERIFY + int verify = 0; + + if (!strcmp(argv[1], "-v")) { + verify = 1; + argc--; + argv++; + } +#endif + /* Move forward to 'algorithm' parameter */ + argc--; + argv++; + return hash_command(*argv, verify, cmdtp, flag, argc - 1, argv + 1); +} + +#ifdef CONFIG_HASH_VERIFY +U_BOOT_CMD( + hash, 6, 1, do_hash, + "compute hash message digest", + "algorithm address count [[*]sum_dest]\n" + " - compute message digest [save to env var / *address]\n" + "sha1sum -v algorithm address count [*]sum\n" + " - verify sha1sum of memory area with env var / *address" +); +#else +U_BOOT_CMD( + hash, 5, 1, do_hash, + "compute message digest", + "algorithm address count [[*]sum_dest]\n" + " - compute message digest [save to env var / *address]" +); +#endif diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h index 148d676..124d51f 100644 --- a/include/config_cmd_all.h +++ b/include/config_cmd_all.h @@ -41,6 +41,7 @@ #define CONFIG_CMD_FLASH /* flinfo, erase, protect */ #define CONFIG_CMD_FPGA /* FPGA configuration Support */ #define CONFIG_CMD_GETTIME /* Get time since boot */ +#define CONFIG_CMD_HASH /* calculate hash / digest */ #define CONFIG_CMD_HWFLOW /* RTS/CTS hw flow control */ #define CONFIG_CMD_I2C /* I2C serial bus support */ #define CONFIG_CMD_IDE /* IDE harddisk support */