[U-Boot] [PATCH 3/3 v2] gen: Add sha256 option to hash command
Akshay Saraswat
akshay.s at samsung.com
Thu Feb 28 12:00:23 CET 2013
sha256 support is added to "hash" command which can be used
to test SHA 256 hash algorithm.
Tested with command "hash sha256 0x40008000 0x2B 0x40009000".
Used mm and md to write a standard string to memory location
0x40008000 and ran the above command to verify the output.
Signed-off-by: ARUN MANKUZHI <arun.m at samsung.com>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
---
Changes since v1:
- Added sha256 support to "hash" command instead of new sha256 command.
common/cmd_hash.c | 46 ++++++++++++++++++++++++++++++++++++++++-
include/configs/exynos5250-dt.h | 1 +
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/common/cmd_hash.c b/common/cmd_hash.c
index 689c608..a2cb65a 100644
--- a/common/cmd_hash.c
+++ b/common/cmd_hash.c
@@ -26,13 +26,55 @@
#include <common.h>
#include <command.h>
#include <hash.h>
+#ifdef CONFIG_EXYNOS_ACE_SHA
+#include <ace_sha.h>
+#else
+#include <sha256.h>
+#endif
+
+static int do_sha256(const char *input, const char *length, const char *output)
+{
+ unsigned long in_len;
+ unsigned char *in_addr, *out_addr;
+ int i;
+
+#ifndef CONFIG_EXYNOS_ACE_SHA
+ sha256_context sha_cnxt;
+#endif
+ in_addr = (unsigned char *)simple_strtoul(input, NULL, 16);
+ in_len = simple_strtoul(length, NULL, 16);
+ out_addr = (unsigned char *)simple_strtoul(output, NULL, 16);
+
+#ifdef CONFIG_EXYNOS_ACE_SHA
+ ace_sha_hash_digest(out_addr, in_addr, in_len, 2);
+#else
+ sha256_starts(&sha_cnxt);
+
+ sha256_update(&sha_cnxt, in_addr, in_len);
+
+ sha256_finish(&sha_cnxt, out_addr);
+#endif
+
+ for (i = 0; i < 32; i++)
+ printf("0x%02X ", out_addr[i]);
+ printf("\n");
+
+ return 0;
+}
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")) {
+ if (!strcmp(argv[1], "sha256")) {
+ if (argc < 5) {
+ printf("usage: hash sha256 <input-address>"
+ " <length> <output-address>\n");
+ return 0;
+ }
+ return do_sha256(argv[2], argv[3], argv[4]);
+ } else if (!strcmp(argv[1], "-v")) {
verify = 1;
argc--;
argv++;
@@ -48,6 +90,7 @@ static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(
hash, 6, 1, do_hash,
"compute hash message digest",
+ "hash sha256 <input-address> <length> <output-address>\n"
"algorithm address count [[*]sum_dest]\n"
" - compute message digest [save to env var / *address]\n"
"hash -v algorithm address count [*]sum\n"
@@ -57,6 +100,7 @@ U_BOOT_CMD(
U_BOOT_CMD(
hash, 5, 1, do_hash,
"compute message digest",
+ "hash sha256 <input-address> <length> <output-address>\n"
"algorithm address count [[*]sum_dest]\n"
" - compute message digest [save to env var / *address]"
);
diff --git a/include/configs/exynos5250-dt.h b/include/configs/exynos5250-dt.h
index f6df734..4a4a2bb 100644
--- a/include/configs/exynos5250-dt.h
+++ b/include/configs/exynos5250-dt.h
@@ -116,6 +116,7 @@
#define CONFIG_CMD_EXT2
#define CONFIG_CMD_FAT
#define CONFIG_CMD_NET
+#define CONFIG_CMD_HASH
#define CONFIG_BOOTDELAY 3
#define CONFIG_ZERO_BOOTDELAY_CHECK
--
1.8.0
More information about the U-Boot
mailing list