linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Gilad Ben-Yossef <gilad@benyossef.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	linux-crypto@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH v2 05/34] crypto: ccree - swap SHA384 and SHA512 larval hashes at build time
Date: Tue, 11 Feb 2020 19:18:59 +0100	[thread overview]
Message-ID: <20200211181928.15178-6-geert+renesas@glider.be> (raw)
In-Reply-To: <20200211181928.15178-1-geert+renesas@glider.be>

Due to the way the hardware works, every double word in the SHA384 and
SHA512 larval hashes must be swapped.  Currently this is done at run
time, during driver initialization.

However, this swapping can easily be done at build time.  Treating each
double word as two words has the benefit of changing the larval hashes'
types from u64[] to u32[], like for all other hashes, and allows
dropping the casts and size doublings when calling cc_set_sram_desc().

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - New.

 drivers/crypto/ccree/cc_driver.c |  1 -
 drivers/crypto/ccree/cc_hash.c   | 49 +++++++++++---------------------
 drivers/crypto/ccree/cc_hash.h   |  2 --
 3 files changed, 17 insertions(+), 35 deletions(-)

diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c
index 532bc95a83736f94..fc34d152f42090fc 100644
--- a/drivers/crypto/ccree/cc_driver.c
+++ b/drivers/crypto/ccree/cc_driver.c
@@ -653,7 +653,6 @@ static struct platform_driver ccree_driver = {
 
 static int __init ccree_init(void)
 {
-	cc_hash_global_init();
 	cc_debugfs_global_init();
 
 	return platform_driver_register(&ccree_driver);
diff --git a/drivers/crypto/ccree/cc_hash.c b/drivers/crypto/ccree/cc_hash.c
index 36ce015716c317df..c3146f550268e7ab 100644
--- a/drivers/crypto/ccree/cc_hash.c
+++ b/drivers/crypto/ccree/cc_hash.c
@@ -39,12 +39,19 @@ static const u32 cc_sha256_init[] = {
 	SHA256_H3, SHA256_H2, SHA256_H1, SHA256_H0 };
 static const u32 cc_digest_len_sha512_init[] = {
 	0x00000080, 0x00000000, 0x00000000, 0x00000000 };
-static u64 cc_sha384_init[] = {
-	SHA384_H7, SHA384_H6, SHA384_H5, SHA384_H4,
-	SHA384_H3, SHA384_H2, SHA384_H1, SHA384_H0 };
-static u64 cc_sha512_init[] = {
-	SHA512_H7, SHA512_H6, SHA512_H5, SHA512_H4,
-	SHA512_H3, SHA512_H2, SHA512_H1, SHA512_H0 };
+
+/*
+ * Due to the way the HW works, every double word in the SHA384 and SHA512
+ * larval hashes must be stored in hi/lo order
+ */
+#define hilo(x)	upper_32_bits(x), lower_32_bits(x)
+static const u32 cc_sha384_init[] = {
+	hilo(SHA384_H7), hilo(SHA384_H6), hilo(SHA384_H5), hilo(SHA384_H4),
+	hilo(SHA384_H3), hilo(SHA384_H2), hilo(SHA384_H1), hilo(SHA384_H0) };
+static const u32 cc_sha512_init[] = {
+	hilo(SHA512_H7), hilo(SHA512_H6), hilo(SHA512_H5), hilo(SHA512_H4),
+	hilo(SHA512_H3), hilo(SHA512_H2), hilo(SHA512_H1), hilo(SHA512_H0) };
+
 static const u32 cc_sm3_init[] = {
 	SM3_IVH, SM3_IVG, SM3_IVF, SM3_IVE,
 	SM3_IVD, SM3_IVC, SM3_IVB, SM3_IVA };
@@ -1942,8 +1949,8 @@ int cc_init_hash_sram(struct cc_drvdata *drvdata)
 	}
 
 	if (large_sha_supported) {
-		cc_set_sram_desc((u32 *)cc_sha384_init, sram_buff_ofs,
-				 (ARRAY_SIZE(cc_sha384_init) * 2), larval_seq,
+		cc_set_sram_desc(cc_sha384_init, sram_buff_ofs,
+				 ARRAY_SIZE(cc_sha384_init), larval_seq,
 				 &larval_seq_len);
 		rc = send_request_init(drvdata, larval_seq, larval_seq_len);
 		if (rc)
@@ -1951,8 +1958,8 @@ int cc_init_hash_sram(struct cc_drvdata *drvdata)
 		sram_buff_ofs += sizeof(cc_sha384_init);
 		larval_seq_len = 0;
 
-		cc_set_sram_desc((u32 *)cc_sha512_init, sram_buff_ofs,
-				 (ARRAY_SIZE(cc_sha512_init) * 2), larval_seq,
+		cc_set_sram_desc(cc_sha512_init, sram_buff_ofs,
+				 ARRAY_SIZE(cc_sha512_init), larval_seq,
 				 &larval_seq_len);
 		rc = send_request_init(drvdata, larval_seq, larval_seq_len);
 		if (rc)
@@ -1963,28 +1970,6 @@ int cc_init_hash_sram(struct cc_drvdata *drvdata)
 	return rc;
 }
 
-static void __init cc_swap_dwords(u32 *buf, unsigned long size)
-{
-	int i;
-	u32 tmp;
-
-	for (i = 0; i < size; i += 2) {
-		tmp = buf[i];
-		buf[i] = buf[i + 1];
-		buf[i + 1] = tmp;
-	}
-}
-
-/*
- * Due to the way the HW works we need to swap every
- * double word in the SHA384 and SHA512 larval hashes
- */
-void __init cc_hash_global_init(void)
-{
-	cc_swap_dwords((u32 *)&cc_sha384_init, (ARRAY_SIZE(cc_sha384_init) * 2));
-	cc_swap_dwords((u32 *)&cc_sha512_init, (ARRAY_SIZE(cc_sha512_init) * 2));
-}
-
 int cc_hash_alloc(struct cc_drvdata *drvdata)
 {
 	struct cc_hash_handle *hash_handle;
diff --git a/drivers/crypto/ccree/cc_hash.h b/drivers/crypto/ccree/cc_hash.h
index 0d6dc61484d79bc8..3dbd0abefea0546c 100644
--- a/drivers/crypto/ccree/cc_hash.h
+++ b/drivers/crypto/ccree/cc_hash.h
@@ -104,6 +104,4 @@ cc_digest_len_addr(void *drvdata, u32 mode);
  */
 cc_sram_addr_t cc_larval_digest_addr(void *drvdata, u32 mode);
 
-void cc_hash_global_init(void);
-
 #endif /*__CC_HASH_H__*/
-- 
2.17.1


  parent reply	other threads:[~2020-02-11 18:20 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 18:18 [PATCH v2 00/34] crypto: ccree - miscellaneous fixes and improvements Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 01/34] debugfs: regset32: Add Runtime PM support Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 02/34] crypto: ccree - fix debugfs register access while suspended Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 03/34] crypto: ccree - fix retry handling in cc_send_sync_request() Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 04/34] crypto: ccree - remove unneeded casts Geert Uytterhoeven
2020-02-11 18:18 ` Geert Uytterhoeven [this message]
2020-02-11 18:19 ` [PATCH v2 06/34] crypto: ccree - drop duplicated error message on SRAM exhaustion Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 07/34] crypto: ccree - remove empty cc_sram_mgr_fini() Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 08/34] crypto: ccree - clean up clock handling Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 09/34] crypto: ccree - make mlli_params.mlli_virt_addr void * Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 10/34] crypto: ccree - use existing helpers to split 64-bit addresses Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 11/34] crypto: ccree - defer larval_digest_addr init until needed Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 12/34] crypto: ccree - remove bogus paragraph about freeing SRAM Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 13/34] crypto: ccree - use u32 for SRAM addresses Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 14/34] crypto: ccree - simplify Runtime PM handling Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 15/34] crypto: ccree - use of_device_get_match_data() Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 16/34] crypto: ccree - remove cc_pm_is_dev_suspended() wrapper Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 17/34] crypto: ccree - make cc_pm_{suspend,resume}() static Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 18/34] crypto: ccree - remove struct cc_sram_ctx Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 19/34] crypto: ccree - remove struct cc_debugfs_ctx Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 20/34] crypto: ccree - remove struct buff_mgr_handle Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 21/34] crypto: ccree - remove struct cc_cipher_handle Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 22/34] crypto: ccree - extract cc_init_copy_sram() Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 23/34] crypto: ccree - remove bogus kerneldoc markers Geert Uytterhoeven
2020-02-11 18:44   ` Sergei Shtylyov
2020-02-11 18:19 ` [PATCH v2 24/34] crypto: ccree - improve kerneldoc in cc_hw_queue_defs.h Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 25/34] crypto: ccree - improve kerneldoc in cc_buffer_mgr.c Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 26/34] crypto: ccree - improve kerneldoc in cc_hash.[ch] Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 27/34] crypto: ccree - improve kerneldoc in cc_request_mgr.[ch] Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 28/34] crypto: ccree - improve kerneldoc in cc_sram_mgr.[ch] Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 29/34] crypto: ccree - spelling s/Crytpcell/Cryptocell/ Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 30/34] crypto: ccree - grammar s/not room/no room/ Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 31/34] crypto: ccree - use existing dev helper in init_cc_resources() Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 32/34] crypto: ccree - use devm_k[mz]alloc() for AEAD data Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 33/34] crypto: ccree - use devm_k[mz]alloc() for cipher data Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 34/34] crypto: ccree - use devm_kzalloc() for hash data Geert Uytterhoeven
     [not found] ` <CAOtvUMfs84VXAecVNShoEg-CU6APjyiVTUBkogpFq_c3fbaX+Q@mail.gmail.com>
2020-02-13  7:47   ` [PATCH v2 00/34] crypto: ccree - miscellaneous fixes and improvements Geert Uytterhoeven
2020-02-19 15:41     ` Gilad Ben-Yossef
2020-02-20 12:29 ` Gilad Ben-Yossef
2020-02-22  1:42 ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200211181928.15178-6-geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=davem@davemloft.net \
    --cc=gilad@benyossef.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).