Skip to contentSkip to conversation

crypto/fsl - Add progressive hashing support using hardware acceleration.

PATCH New Gaurav Rana 3 participants 3 messages Feb 20, 2015 – Feb 25, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 crypto/fsl - Add progressive hashing support using hardware acceleration.

Currently only normal hashing is supported using hardware acceleration. Added support for progressive hashing using hardware.

---
Changes in v6:
Modify description for CONFIG_SHA256, CONFIG_SHA256, CONFIG_SHA_PROG_HW_ACCEL, CONFIG_SHA_HW_ACCEL in README and Kconfig.

Changes in v5:
Modify description for CONFIG_SHA256, CONFIG_SHA256.

Changes in v4:
Add CONFIG_SHA256, CONFIG_SHA256, CONFIG_SHA_PROG_HW_ACCEL, CONFIG_SHA_HW_ACCEL to Kconfig. Modify README for these configs descriptions.

Changes in v3:
Remove duplication of code and create function gen_hash_type. Modify MAX_SG to MAX_SG_32

Changes in v2:
Merge to common functions for SHA1 and SHA256.
Replace malloc and memset with calloc.
Remove cast conversions for void* pointers.
Replace hardcoded errors with Macros.
Corrected comments.

 Kconfig                       |   4 +-
 README                        |  20 ++++--
 common/hash.c                 |  10 +++
 drivers/crypto/fsl/fsl_hash.c | 138 +++++++++++++++++++++++++++++++++++++++++-
 drivers/crypto/fsl/fsl_hash.h |  34 +++++++++++
 include/fsl_sec.h             |  26 ++++++++
 include/hw_sha.h              |  41 ++++++++++++-
 lib/Kconfig                   |  36 +++++++++++
 8 files changed, 302 insertions(+), 7 deletions(-)
 create mode 100644 drivers/crypto/fsl/fsl_hash.h
Kconfig +3 -1
index 75bab7f..fb012cf 100644
@@ -141,7 +141,9 @@ config FIT_SIGNATURE
 	select RSA
 	help
 	  This option enables signature verification of FIT uImages,
-	  using a hash signed and verified using RSA.
+	  using a hash signed and verified using RSA. If
+	  CONFIG_SHA_PROG_HW_ACCEL is defined, i.e support for progressive
+	  hashing is available using hardware, RSA library will use it.
 	  See doc/uImage.FIT/signature.txt for more details.
 
 config SYS_EXTRA_OPTIONS
README +16 -4
index ba57dc5..9c139a0 100644
@@ -3152,8 +3152,18 @@ CBFS (Coreboot Filesystem) support
 		Enable the hash verify command (hash -v). This adds to code
 		size a little.
 
-		CONFIG_SHA1 - support SHA1 hashing
-		CONFIG_SHA256 - support SHA256 hashing
+		CONFIG_SHA1 - This option enables support of hashing using SHA1
+		algorithm. The hash is calculated in software.
+		CONFIG_SHA256 - This option enables support of hashing using
+		SHA256 algorithm. The hash is calculated in software.
+		CONFIG_SHA_HW_ACCEL - This option enables hardware acceleration
+		for SHA1/SHA256 hashing.
+		This affects the 'hash' command and also the
+		hash_lookup_algo() function.
+		CONFIG_SHA_PROG_HW_ACCEL - This option enables
+		hardware-acceleration for SHA1/SHA256 progressive hashing.
+		Data can be streamed in a block at a time and the hashing
+		is performed in hardware.
 
 		Note: There is also a sha1sum command, which should perhaps
 		be deprecated in favour of 'hash sha1'.
@@ -3447,8 +3457,10 @@ FIT uImage format:
 
 		CONFIG_FIT_SIGNATURE
 		This option enables signature verification of FIT uImages,
-		using a hash signed and verified using RSA. See
-		doc/uImage.FIT/signature.txt for more details.
+		using a hash signed and verified using RSA. If
+		CONFIG_SHA_PROG_HW_ACCEL is defined, i.e support for progressive
+		hashing is available using hardware, RSA library will use it.
+		See doc/uImage.FIT/signature.txt for more details.
 
 		WARNING: When relying on signed FIT images with required
 		signature check the legacy image format is default
common/hash.c +10 -0
index d154d02..9e9f84b 100644
@@ -127,11 +127,21 @@ static struct hash_algo hash_algo[] = {
 		SHA1_SUM_LEN,
 		hw_sha1,
 		CHUNKSZ_SHA1,
+#ifdef CONFIG_SHA_PROG_HW_ACCEL
+		hw_sha_init,
+		hw_sha_update,
+		hw_sha_finish,
+#endif
 	}, {
 		"sha256",
 		SHA256_SUM_LEN,
 		hw_sha256,
 		CHUNKSZ_SHA256,
+#ifdef CONFIG_SHA_PROG_HW_ACCEL
+		hw_sha_init,
+		hw_sha_update,
+		hw_sha_finish,
+#endif
 	},
 #endif
 #ifdef CONFIG_SHA1
drivers/crypto/fsl/fsl_hash.c +137 -1

159 lines not on this page · raw message

drivers/crypto/fsl/fsl_hash.h new file +34 -0
new file mode 100644
index 0000000..f5be651
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ */
+
+#ifndef _SHA_H
+#define _SHA_H
+
+#include <fsl_sec.h>
+#include <hash.h>
+#include "jr.h"
+
+/* We support at most 32 Scatter/Gather Entries.*/
+#define MAX_SG_32	32
+
+/*
+ * Hash context contains the following fields
+ * @sha_desc: Sha Descriptor
+ * @sg_num: number of entries in sg table
+ * @len: total length of buffer
+ * @sg_tbl: sg entry table
+ * @hash: index to the hash calculated
+ */
+struct sha_ctx {
+	uint32_t sha_desc[64];
+	uint32_t sg_num;
+	uint32_t len;
+	struct sg_entry sg_tbl[MAX_SG_32];
+	u8 hash[HASH_MAX_DIGEST_SIZE];
+};
+
+#endif
include/fsl_sec.h +26 -0
index aa850a3..b6e6f04 100644
@@ -175,6 +175,32 @@ struct jr_regs {
 	u32 jrcr;
 };
 
+/*
+ * Scatter Gather Entry - Specifies the the Scatter Gather Format
+ * related information
+ */
+struct sg_entry {
+#ifdef CONFIG_SYS_FSL_SEC_LE
+	uint32_t addr_lo;	/* Memory Address - lo */
+	uint16_t addr_hi;	/* Memory Address of start of buffer - hi */
+	uint16_t reserved_zero;
+#else
+	uint16_t reserved_zero;
+	uint16_t addr_hi;	/* Memory Address of start of buffer - hi */
+	uint32_t addr_lo;	/* Memory Address - lo */
+#endif
+
+	uint32_t len_flag;	/* Length of the data in the frame */
+#define SG_ENTRY_LENGTH_MASK	0x3FFFFFFF
+#define SG_ENTRY_EXTENSION_BIT	0x80000000
+#define SG_ENTRY_FINAL_BIT	0x40000000
+	uint32_t bpid_offset;
+#define SG_ENTRY_BPID_MASK	0x00FF0000
+#define SG_ENTRY_BPID_SHIFT	16
+#define SG_ENTRY_OFFSET_MASK	0x00001FFF
+#define SG_ENTRY_OFFSET_SHIFT	0
+};
+
 int sec_init(void);
 #endif
 
include/hw_sha.h +40 -1

51 lines not on this page · raw message

lib/Kconfig +36 -0
index a1f30a2..c9d2767 100644
@@ -29,4 +29,40 @@ config SYS_HZ
 
 source lib/rsa/Kconfig
 
+menu "Hashing Support"
+
+config SHA1
+	bool "Enable SHA1 support"
+	help
+	  This option enables support of hashing using SHA1 algorithm.
+	  The hash is calculated in software.
+	  The SHA1 algorithm produces a 160-bit (20-byte) hash value
+	  (digest).
+
+config SHA256
+	bool "Enable SHA256 support"
+	help
+	  This option enables support of hashing using SHA256 algorithm.
+	  The hash is calculated in software.
+	  The SHA256 algorithm produces a 256-bit (32-byte) hash value
+	  (digest).
+
+config SHA_HW_ACCEL
+	bool "Enable hashing using hardware"
+	help
+	  This option enables hardware acceleration
+	  for SHA1/SHA256 hashing.
+	  This affects the 'hash' command and also the
+	  hash_lookup_algo() function.
+
+config SHA_PROG_HW_ACCEL
+	bool "Enable Progressive hashing support using hardware"
+	depends on SHA_HW_ACCEL
+	help
+	  This option enables hardware-acceleration for
+	  SHA1/SHA256 progressive hashing.
+	  Data can be streamed in a block at a time and the hashing
+	  is performed in hardware.
+endmenu
+
 endmenu
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v6 1/1 crypto/fsl - Add progressive hashing support using hardware acceleration.

Quoted 10 lines · Gaurav Rana

Currently only normal hashing is supported using hardware acceleration. Added support for progressive hashing using hardware.

---
Changes in v6:
Modify description for CONFIG_SHA256, CONFIG_SHA256, CONFIG_SHA_PROG_HW_ACCEL, CONFIG_SHA_HW_ACCEL in README and Kconfig.

Quoted 29 lines

Changes in v5:
Modify description for CONFIG_SHA256, CONFIG_SHA256.

Changes in v4:
Add CONFIG_SHA256, CONFIG_SHA256, CONFIG_SHA_PROG_HW_ACCEL, CONFIG_SHA_HW_ACCEL to Kconfig. Modify README for these configs descriptions.

Changes in v3:
Remove duplication of code and create function gen_hash_type. Modify MAX_SG to MAX_SG_32

Changes in v2:
Merge to common functions for SHA1 and SHA256.
Replace malloc and memset with calloc.
Remove cast conversions for void* pointers.
Replace hardcoded errors with Macros.
Corrected comments.

 Kconfig                       |   4 +-
 README                        |  20 ++++--
 common/hash.c                 |  10 +++
 drivers/crypto/fsl/fsl_hash.c | 138 +++++++++++++++++++++++++++++++++++++++++-
 drivers/crypto/fsl/fsl_hash.h |  34 +++++++++++
 include/fsl_sec.h             |  26 ++++++++
 include/hw_sha.h              |  41 ++++++++++++-
 lib/Kconfig                   |  36 +++++++++++
 8 files changed, 302 insertions(+), 7 deletions(-)
 create mode 100644 drivers/crypto/fsl/fsl_hash.h
#2 lore raw

PATCH v6 1/1 crypto/fsl - Add progressive hashing support using hardware acceleration.

Quoted 12 lines · Simon Glass
Quoted 10 lines · Gaurav Rana

Currently only normal hashing is supported using hardware acceleration. Added support for progressive hashing using hardware.

---
Changes in v6:
Modify description for CONFIG_SHA256, CONFIG_SHA256, CONFIG_SHA_PROG_HW_ACCEL, CONFIG_SHA_HW_ACCEL in README and Kconfig.

Quoted 2 lines

Applied to u-boot-fsl-qoriq master branch, awaiting upstream.

York