]> git.baikalelectronics.ru Git - kernel.git/commitdiff
crypto: ccree - swap SHA384 and SHA512 larval hashes at build time
authorGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 11 Feb 2020 18:18:59 +0000 (19:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:18 +0000 (11:41 +0100)
[ Upstream commit f2602e0611d2b0102376798dda3b1d628fb72c33 ]

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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: 4f1c596df706 ("crypto: ccree - Remove debugfs when platform_driver_register failed")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/ccree/cc_driver.c
drivers/crypto/ccree/cc_hash.c
drivers/crypto/ccree/cc_hash.h

index 8b8eee513c279815223d05c731066476184653c8..58ca59af0b2eac70229a2af23c6b01d245ea1754 100644 (file)
@@ -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);
index bc71bdf44a9ff195ee4d64b72e5fd8a1fff940e7..9f67df0a4921b570f220d82260d73f9cf2030dd7 100644 (file)
@@ -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 };
@@ -1948,8 +1955,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)
@@ -1957,8 +1964,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)
@@ -1969,28 +1976,6 @@ init_digest_const_err:
        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;
index 0d6dc61484d79bc872f7ed41c00f96fdd2d1197c..3dbd0abefea0546c043c26f27d751f108f670173 100644 (file)
@@ -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__*/