Skip to contentSkip to conversation

Add ACE HW support for SHA 256

PATCH Superseded Akshay Saraswat 3 participants 8 messages Feb 28, 2013

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add ACE HW support for SHA 256

This patch set adds hardware acceleration for SHA 256 with the help of ACE.

Changes since v1:
- Patch-1: Fixed few nits.
- Patch-2: Removed not required config.
- Patch-3: Added sha256 to hash command instead of new sha256 command.

Akshay Saraswat (3):
Exynos: Add hardware accelerated SHA 256
Exynos: config: Enable ACE HW for SHA 256 for Exynos
gen: Add sha256 option to hash command

 Makefile                               |   1 +
 arch/arm/include/asm/arch-exynos/cpu.h |   4 +
 common/cmd_hash.c                      |  46 ++++-
 drivers/crypto/Makefile                |  47 +++++
 drivers/crypto/ace_sfr.h               | 310 +++++++++++++++++++++++++++++++++
 drivers/crypto/ace_sha.c               | 122 +++++++++++++
 include/ace_sha.h                      |  41 +++++
 include/configs/exynos5250-dt.h        |   4 +
 8 files changed, 574 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/Makefile
 create mode 100644 drivers/crypto/ace_sfr.h
 create mode 100644 drivers/crypto/ace_sha.c
 create mode 100644 include/ace_sha.h
Signature · 1 line
1.8.0
#1 lore raw

PATCH v2 1/3 Exynos: Add hardware accelerated SHA 256

SHA-256 and SHA-1 accelerated using ACE hardware.

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.

---
Changes since v1:
- Moved code to drivers/crypto.
- Fixed few other nits.

 Makefile                               |   1 +
 arch/arm/include/asm/arch-exynos/cpu.h |   4 +
 drivers/crypto/Makefile                |  47 +++++
 drivers/crypto/ace_sfr.h               | 310 +++++++++++++++++++++++++++++++++
 drivers/crypto/ace_sha.c               | 122 +++++++++++++
 include/ace_sha.h                      |  41 +++++
 6 files changed, 525 insertions(+)
 create mode 100644 drivers/crypto/Makefile
 create mode 100644 drivers/crypto/ace_sfr.h
 create mode 100644 drivers/crypto/ace_sha.c
 create mode 100644 include/ace_sha.h
Makefile +1 -0
index fc18dd4..4c41130 100644
@@ -272,6 +272,7 @@ LIBS-y += disk/libdisk.o
 LIBS-y += drivers/bios_emulator/libatibiosemu.o
 LIBS-y += drivers/block/libblock.o
 LIBS-$(CONFIG_BOOTCOUNT_LIMIT) += drivers/bootcount/libbootcount.o
+LIBS-y += drivers/crypto/libcrypto.o
 LIBS-y += drivers/dma/libdma.o
 LIBS-y += drivers/fpga/libfpga.o
 LIBS-y += drivers/gpio/libgpio.o
arch/arm/include/asm/arch-exynos/cpu.h +4 -0
index eb34422..2a20558 100644
@@ -62,6 +62,7 @@
 #define EXYNOS4_GPIO_PART4_BASE		DEVICE_NOT_AVAILABLE
 #define EXYNOS4_DP_BASE			DEVICE_NOT_AVAILABLE
 #define EXYNOS4_SPI_ISP_BASE		DEVICE_NOT_AVAILABLE
+#define EXYNOS4_ACE_SFR_BASE		DEVICE_NOT_AVAILABLE
 
 /* EXYNOS4X12 */
 #define EXYNOS4X12_GPIO_PART3_BASE	0x03860000
@@ -95,6 +96,7 @@
 #define EXYNOS4X12_I2S_BASE            DEVICE_NOT_AVAILABLE
 #define EXYNOS4X12_SPI_BASE            DEVICE_NOT_AVAILABLE
 #define EXYNOS4X12_SPI_ISP_BASE                DEVICE_NOT_AVAILABLE
+#define EXYNOS4X12_ACE_SFR_BASE		DEVICE_NOT_AVAILABLE
 
 /* EXYNOS5 Common*/
 #define EXYNOS5_I2C_SPACING		0x10000
@@ -106,6 +108,7 @@
 #define EXYNOS5_SWRESET			0x10040400
 #define EXYNOS5_SYSREG_BASE		0x10050000
 #define EXYNOS5_WATCHDOG_BASE		0x101D0000
+#define EXYNOS5_ACE_SFR_BASE            0x10830000
 #define EXYNOS5_DMC_PHY0_BASE		0x10C00000
 #define EXYNOS5_DMC_PHY1_BASE		0x10C10000
 #define EXYNOS5_GPIO_PART3_BASE		0x10D10000
@@ -205,6 +208,7 @@ static inline unsigned int samsung_get_base_##device(void)	\
 
 SAMSUNG_BASE(adc, ADC_BASE)
 SAMSUNG_BASE(clock, CLOCK_BASE)
+SAMSUNG_BASE(ace_sfr, ACE_SFR_BASE)
 SAMSUNG_BASE(dp, DP_BASE)
 SAMSUNG_BASE(sysreg, SYSREG_BASE)
 SAMSUNG_BASE(fimd, FIMD_BASE)
drivers/crypto/Makefile new file +47 -0

47 lines not on this page · raw message

drivers/crypto/ace_sfr.h new file +310 -0

310 lines not on this page · raw message

drivers/crypto/ace_sha.c new file +122 -0

122 lines not on this page · raw message

include/ace_sha.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
1.8.0
#2 lore raw

PATCH v2 1/3 Exynos: Add hardware accelerated SHA 256

Hi Akshay,

Quoted 8 lines · Akshay Saraswat

SHA-256 and SHA-1 accelerated using ACE hardware.

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.

This looks OK but I think the plumbing in the other patch needs to move to hash.c before I can do a final review.

Regards,
Simon

#3 lore raw

PATCH v2 1/3 Exynos: Add hardware accelerated SHA 256

In reply to Akshay Saraswat
Quoted 4 lines · On Thu, 28 Feb 2013 06:00:21 -0500 Akshay Saraswat <[email protected]> wrote:

---
Changes since v1:
- Moved code to drivers/crypto.
- Fixed few other nits.

be more specific wrt changes between revisions.

drivers/crypto/ace_sha.c line 64

Quoted 11 lines
drivers/crypto/ace_sha.c new file +11 -0
+	if (buf_len == 0) {
+		/* ACE H/W cannot compute hash value for empty string */
+		if (hash_type == ACE_SHA_TYPE_SHA1)
+			memcpy(pout, sha1_digest_emptymsg, SHA1_SUM_LEN);
+		else
+			memcpy(pout, sha256_digest_emptymsg, SHA256_SUM_LEN);
+		return 0;
+	} else if (buf_len > BUF_LIMIT) {
+		debug("%s: Buffer length beyond limit\n", __func__);
+		return -1;
+	}

erroring out just because the user asked for a hash on something larger than 8MB is unacceptable: any hash implementation that replaces a corresponding software implementation must not introduce new limitations and regressions.

If the hardware supports hash updating - which is likely - use that to perform hashes >8MB. If not, revert to software. And for the 0 length case.

drivers/crypto/ace_sha.c line 99

Quoted 4 lines
drivers/crypto/ace_sha.c new file +4 -0
+	start = get_timer(0);
+
+	while ((readl(&ace_sha_reg->hash_status) & ACE_HASH_MSGDONE_MASK) ==
+		ACE_HASH_MSGDONE_OFF) {

alignment - the 'A' in ACE_H*_OFF should fall directly below the '(' in 'readl('.

drivers/crypto/ace_sha.c line 102

Quoted 2 lines
drivers/crypto/ace_sha.c new file +2 -0
+		if (get_timer(start) > TIMEOUT_MS) {
+			debug("%s: Timeout waiting for ACE\n", __func__);

see my other email to v1 of this patch wrt timing-out.

drivers/crypto/ace_sha.c line 113

Quoted 2 lines
drivers/crypto/ace_sha.c new file +2 -0
+	len = (hash_type == ACE_SHA_TYPE_SHA1) ? SHA1_SUM_LEN / 4
+							: SHA256_SUM_LEN / 4;

alignment

a more recent version of checkpatch finds other such problems:

CHECK: No space is necessary after a cast
#610: FILE: drivers/crypto/ace_sha.c:52:
+ struct exynos_ace_sfr *ace_sha_reg =
+ (struct exynos_ace_sfr *) samsung_get_base_ace_sfr();

CHECK: Alignment should match open parenthesis
#630: FILE: drivers/crypto/ace_sha.c:72:
+ writel(ACE_HASH_SWAPDI_ON | ACE_HASH_SWAPDO_ON | ACE_HASH_SWAPIV_ON,
+ &ace_sha_reg->hash_byteswap);

CHECK: Blank lines aren't necessary after an open brace '{' #658: FILE: drivers/crypto/ace_sha.c:100:
+ ACE_HASH_MSGDONE_OFF) {
+

CHECK: space prohibited before semicolon
#673: FILE: drivers/crypto/ace_sha.c:115:
+ for (i = 0; i < len ; i++)

Kim

#4 lore raw

PATCH v2 2/3 Exynos: config: Enable ACE HW for SHA 256 for Exynos

In reply to Akshay Saraswat

This enables SHA 256 for exynos.

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.

---
Changes since v1:
- Removed not required config.

 include/configs/exynos5250-dt.h | 3 +++
 1 file changed, 3 insertions(+)
include/configs/exynos5250-dt.h +3 -0
index cabd2f2..f6df734 100644
@@ -45,6 +45,9 @@
 /* Keep L2 Cache Disabled */
 #define CONFIG_SYS_DCACHE_OFF
 
+/* Enable ACE acceleration for SHA256 */
+#define CONFIG_EXYNOS_ACE_SHA
+
 #define CONFIG_SYS_SDRAM_BASE		0x40000000
 #define CONFIG_SYS_TEXT_BASE		0x43E00000
 
Signature · 1 line
1.8.0
#5 lore raw

PATCH v2 2/3 Exynos: config: Enable ACE HW for SHA 256 for Exynos

Hi Akshay,

Quoted 20 lines · Akshay Saraswat

This enables SHA 256 for exynos.

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.

---
Changes since v1:
- Removed not required config.

 include/configs/exynos5250-dt.h | 3 +++
 1 file changed, 3 insertions(+)
include/configs/exynos5250-dt.h +0 -0
index cabd2f2..f6df734 100644

include/configs/exynos5250-dt.h line 48

Quoted 4 lines
include/configs/exynos5250-dt.h +1 -0
@@ -45,6 +45,9 @@
 /* Keep L2 Cache Disabled */
 #define CONFIG_SYS_DCACHE_OFF
 
+/* Enable ACE acceleration for SHA256 */

and SHA1?

Quoted 8 lines
include/configs/exynos5250-dt.h +2 -1
+#define CONFIG_EXYNOS_ACE_SHA
+
 #define CONFIG_SYS_SDRAM_BASE          0x40000000
 #define CONFIG_SYS_TEXT_BASE           0x43E00000
 
--

1.8.0

Regards,
Simon

#6 lore raw

PATCH v2 3/3 gen: Add sha256 option to hash command

In reply to Akshay Saraswat

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.

---
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(-)
common/cmd_hash.c +45 -1
index 689c608..a2cb65a 100644
@@ -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]"
 );
include/configs/exynos5250-dt.h +1 -0
index f6df734..4a4a2bb 100644
@@ -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
Signature · 1 line
1.8.0
#7 lore raw

PATCH v2 3/3 gen: Add sha256 option to hash command

Hi Akshay,

Quoted 7 lines · Akshay Saraswat

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.

Quoted 8 lines

---
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 +

This code should go in hash.c. Please see 'struct hash_algo' at the top of this file. You can add your new hash function in there. There really is no need to change cmd_hash I think.

Also the config file change should go in a separate patch.

Quoted 2 lines
 2 files changed, 46 insertions(+), 1 deletion(-)

Regards,
Simon