crypto: sha256 - Merge crypto/sha256.h into crypto/sha.h
Subsystems (10)
cover crypto: sha256 - Merge crypto/sha256.h into crypto/sha.h
Hi All,
As promised here is a follow-up series to my earlier sha256 series.
Note I have only compiled and tested this series on x86_64 !!
All changes to architecture specific code on other archs have not even been tested to compile! With that said most of these changes were done using my editors search - replace function so things should be fine... (and FWIW I did do a Kconfig hack to compile test the ccree change).
The first patch in this series rename various file local functions / arrays to avoid conflicts with the new include/crypto/sha256.h, followed by a patch merging include/crypto/sha256.h into include/crypto/sha.h.
The last patch makes use of this merging to remove a bit more code duplication, making sha256_generic use sha256_init and sha224_init from lib/crypto/sha256.c. An added advantage of this, is that this gives these 2 functions coverage by the crypto selftests.
Regards,
Hans
PATCH 1/9 crypto: arm - Rename functions to avoid conflict with crypto/sha256.h
Rename static / file-local functions so that they do not conflict with the functions declared in crypto/sha256.h.
This is a preparation patch for folding crypto/sha256.h into crypto/sha.h.
--- arch/arm/crypto/sha256_glue.c | 8 ++++---- arch/arm/crypto/sha256_neon_glue.c | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-)
arch/arm/crypto/sha256_glue.c +4 -4
@@ -39,7 +39,7 @@ int crypto_sha256_arm_update(struct shash_desc *desc, const u8 *data, }EXPORT_SYMBOL (crypto_sha256_arm_update); -static int sha256_final (struct shash_desc *desc,u8 *out) +static int crypto_sha256_arm_final (struct shash_desc *desc,u8 *out) {sha256_base_do_finalize (desc, (sha256_block_fn *)sha256_block_data_order);
@@ -51,7 +51,7 @@ int crypto_sha256_arm_finup(struct shash_desc *desc, const u8 *data, {sha256_base_do_update (desc, data, len, (sha256_block_fn *)sha256_block_data_order); -return sha256_final (desc, out); +return crypto_sha256_arm_final (desc, out); }EXPORT_SYMBOL (crypto_sha256_arm_finup);
@@ -59,7 +59,7 @@ static struct shash_alg algs[] = { { .digestsize = SHA256_DIGEST_SIZE, .init = sha256_base_init, .update = crypto_sha256_arm_update, - .final = sha256_final, + .final = crypto_sha256_arm_final, .finup = crypto_sha256_arm_finup, .descsize = sizeof(struct sha256_state), .base = {
@@ -73,7 +73,7 @@ static struct shash_alg algs[] = { { .digestsize = SHA224_DIGEST_SIZE, .init = sha224_base_init, .update = crypto_sha256_arm_update, - .final = sha256_final, + .final = crypto_sha256_arm_final, .finup = crypto_sha256_arm_finup, .descsize = sizeof(struct sha256_state), .base = {
arch/arm/crypto/sha256_neon_glue.c +12 -12
@@ -25,8 +25,8 @@ asmlinkage void sha256_block_data_order_neon(u32 *digest, const void *data,unsigned int num_blks); -static int sha256_update (struct shash_desc *desc,const u8 *data, -unsigned int len) +static int crypto_sha256_neon_update (struct shash_desc *desc,const u8 *data, +unsigned int len) {struct sha256_state *sctx =shash_desc_ctx (desc);
@@ -42,8 +42,8 @@ static int sha256_update(struct shash_desc *desc, const u8 *data,return 0 ; } -static int sha256_finup (struct shash_desc *desc,const u8 *data, -unsigned int len,u8 *out) +static int crypto_sha256_neon_finup (struct shash_desc *desc,const u8 *data, +unsigned int len,u8 *out) {if (!crypto_simd_usable ())return crypto_sha256_arm_finup (desc, data, len, out);
@@ -59,17 +59,17 @@ static int sha256_finup(struct shash_desc *desc, const u8 *data,return sha256_base_finish (desc, out); } -static int sha256_final (struct shash_desc *desc,u8 *out) +static int crypto_sha256_neon_final (struct shash_desc *desc,u8 *out) { -return sha256_finup (desc,NULL ,0 , out); +return crypto_sha256_neon_finup (desc,NULL ,0 , out); }struct shash_alg sha256_neon_algs[] = { { .digestsize =SHA256_DIGEST_SIZE , .init = sha256_base_init, - .update = sha256_update, - .final = sha256_final, - .finup = sha256_finup, + .update = crypto_sha256_neon_update, + .final = crypto_sha256_neon_final, + .finup = crypto_sha256_neon_finup, .descsize =sizeof (struct sha256_state ), .base = { .cra_name ="sha256" ,
@@ -81,9 +81,9 @@ struct shash_alg sha256_neon_algs[] = { { }, { .digestsize = SHA224_DIGEST_SIZE, .init = sha224_base_init, - .update = sha256_update, - .final = sha256_final, - .finup = sha256_finup, + .update = crypto_sha256_neon_update, + .final = crypto_sha256_neon_final, + .finup = crypto_sha256_neon_finup, .descsize = sizeof(struct sha256_state), .base = { .cra_name = "sha224",
Signature · 1 line
2.23.0
PATCH 2/9 crypto: arm64 - Rename functions to avoid conflict with crypto/sha256.h
In reply to Hans de GoedeRename static / file-local functions so that they do not conflict with the functions declared in crypto/sha256.h.
This is a preparation patch for folding crypto/sha256.h into crypto/sha.h.
--- arch/arm64/crypto/sha256-glue.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
arch/arm64/crypto/sha256-glue.c +12 -12
@@ -30,15 +30,15 @@ EXPORT_SYMBOL(sha256_block_data_order); asmlinkage void sha256_block_neon(u32 *digest, const void *data,unsigned int num_blks); -static int sha256_update (struct shash_desc *desc,const u8 *data, -unsigned int len) +static int crypto_sha256_arm64_update (struct shash_desc *desc,const u8 *data, +unsigned int len) {return sha256_base_do_update (desc, data, len, (sha256_block_fn *)sha256_block_data_order); } -static int sha256_finup (struct shash_desc *desc,const u8 *data, -unsigned int len,u8 *out) +static int crypto_sha256_arm64_finup (struct shash_desc *desc,const u8 *data, +unsigned int len,u8 *out) {if (len) sha256_base_do_update(desc, data, len,
@@ -49,17 +49,17 @@ static int sha256_finup(struct shash_desc *desc, const u8 *data,return sha256_base_finish (desc, out); } -static int sha256_final (struct shash_desc *desc,u8 *out) +static int crypto_sha256_arm64_final (struct shash_desc *desc,u8 *out) { -return sha256_finup (desc,NULL ,0 , out); +return crypto_sha256_arm64_finup (desc,NULL ,0 , out); }static struct shash_alg algs[] = { { .digestsize =SHA256_DIGEST_SIZE , .init = sha256_base_init, - .update = sha256_update, - .final = sha256_final, - .finup = sha256_finup, + .update = crypto_sha256_arm64_update, + .final = crypto_sha256_arm64_final, + .finup = crypto_sha256_arm64_finup, .descsize =sizeof (struct sha256_state ), .base.cra_name ="sha256" , .base.cra_driver_name ="sha256-arm64" ,
@@ -69,9 +69,9 @@ static struct shash_alg algs[] = { { }, { .digestsize = SHA224_DIGEST_SIZE, .init = sha224_base_init, - .update = sha256_update, - .final = sha256_final, - .finup = sha256_finup, + .update = crypto_sha256_arm64_update, + .final = crypto_sha256_arm64_final, + .finup = crypto_sha256_arm64_finup, .descsize = sizeof(struct sha256_state), .base.cra_name = "sha224", .base.cra_driver_name = "sha224-arm64",
Signature · 1 line
2.23.0
PATCH 3/9 crypto: s390 - Rename functions to avoid conflict with crypto/sha256.h
In reply to Hans de GoedeRename static / file-local functions so that they do not conflict with the functions declared in crypto/sha256.h.
This is a preparation patch for folding crypto/sha256.h into crypto/sha.h.
--- arch/s390/crypto/sha256_s390.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/s390/crypto/sha256_s390.c +4 -4
@@ -17,7 +17,7 @@#include "sha.h" -static int sha256_init (struct shash_desc *desc) +static int s390_sha256_init (struct shash_desc *desc) {struct s390_sha_ctx *sctx =shash_desc_ctx (desc);
@@ -60,7 +60,7 @@ static int sha256_import(struct shash_desc *desc, const void *in)static struct shash_alg sha256_alg = { .digestsize =SHA256_DIGEST_SIZE , - .init = sha256_init, + .init = s390_sha256_init, .update = s390_sha_update, .final = s390_sha_final, .export = sha256_export,
@@ -76,7 +76,7 @@ static struct shash_alg sha256_alg = { } }; -static int sha224_init (struct shash_desc *desc) +static int s390_sha224_init (struct shash_desc *desc) {struct s390_sha_ctx *sctx =shash_desc_ctx (desc);
@@ -96,7 +96,7 @@ static int sha224_init(struct shash_desc *desc)static struct shash_alg sha224_alg = { .digestsize =SHA224_DIGEST_SIZE , - .init = sha224_init, + .init = s390_sha224_init, .update = s390_sha_update, .final = s390_sha_final, .export = sha256_export,
Signature · 1 line
2.23.0
PATCH 4/9 crypto: x86 - Rename functions to avoid conflict with crypto/sha256.h
In reply to Hans de GoedeRename static / file-local functions so that they do not conflict with the functions declared in crypto/sha256.h.
This is a preparation patch for folding crypto/sha256.h into crypto/sha.h.
--- arch/x86/crypto/sha256_ssse3_glue.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/crypto/sha256_ssse3_glue.c +6 -6
@@ -45,8 +45,8 @@ asmlinkage void sha256_transform_ssse3(u32 *digest, const char *data, u64 rounds);typedef void (sha256_transform_fn )(u32 *digest,const char *data,u64 rounds); -static int sha256_update (struct shash_desc *desc,const u8 *data, -unsigned int len,sha256_transform_fn *sha256_xform) +static int _sha256_update (struct shash_desc *desc,const u8 *data, +unsigned int len,sha256_transform_fn *sha256_xform) {struct sha256_state *sctx =shash_desc_ctx (desc);
@@ -84,7 +84,7 @@ static int sha256_finup(struct shash_desc *desc, const u8 *data,static int sha256_ssse3_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha256_update (desc, data, len, sha256_transform_ssse3); +return _sha256_update (desc, data, len, sha256_transform_ssse3); } static int sha256_ssse3_finup(struct shash_desc *desc, const u8 *data,
@@ -151,7 +151,7 @@ asmlinkage void sha256_transform_avx(u32 *digest, const char *data,static int sha256_avx_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha256_update (desc, data, len, sha256_transform_avx); +return _sha256_update (desc, data, len, sha256_transform_avx); } static int sha256_avx_finup(struct shash_desc *desc, const u8 *data,
@@ -233,7 +233,7 @@ asmlinkage void sha256_transform_rorx(u32 *digest, const char *data,static int sha256_avx2_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha256_update (desc, data, len, sha256_transform_rorx); +return _sha256_update (desc, data, len, sha256_transform_rorx); } static int sha256_avx2_finup(struct shash_desc *desc, const u8 *data,
@@ -313,7 +313,7 @@ asmlinkage void sha256_ni_transform(u32 *digest, const char *data,static int sha256_ni_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -return sha256_update (desc, data, len, sha256_ni_transform); +return _sha256_update (desc, data, len, sha256_ni_transform); } static int sha256_ni_finup(struct shash_desc *desc, const u8 *data,
Signature · 1 line
2.23.0
PATCH 5/9 crypto: ccree - Rename arrays to avoid conflict with crypto/sha256.h
In reply to Hans de GoedeRename the algo_init arrays to cc_algo_init so that they do not conflict with the functions declared in crypto/sha256.h.
This is a preparation patch for folding crypto/sha256.h into crypto/sha.h.
--- drivers/crypto/ccree/cc_hash.c | 153 +++++++++++++++++---------------- 1 file changed, 77 insertions(+), 76 deletions(-)
drivers/crypto/ccree/cc_hash.c +77 -76
@@ -25,27 +25,27 @@ struct cc_hash_handle {struct list_head hash_list; }; -static const u32 digest_len_init[] = { +static const u32 cc_digest_len_init[] = {0x00000040 ,0x00000000 ,0x00000000 ,0x00000000 }; -static const u32 md5_init[] = { +static const u32 cc_md5_init[] = {SHA1_H3 ,SHA1_H2 ,SHA1_H1 ,SHA1_H0 }; -static const u32 sha1_init[] = { +static const u32 cc_sha1_init[] = {SHA1_H4 ,SHA1_H3 ,SHA1_H2 ,SHA1_H1 ,SHA1_H0 }; -static const u32 sha224_init[] = { +static const u32 cc_sha224_init[] = {SHA224_H7 ,SHA224_H6 ,SHA224_H5 ,SHA224_H4 ,SHA224_H3 ,SHA224_H2 ,SHA224_H1 ,SHA224_H0 }; -static const u32 sha256_init[] = { +static const u32 cc_sha256_init[] = {SHA256_H7 ,SHA256_H6 ,SHA256_H5 ,SHA256_H4 ,SHA256_H3 ,SHA256_H2 ,SHA256_H1 ,SHA256_H0 }; -static const u32 digest_len_sha512_init[] = { +static const u32 cc_digest_len_sha512_init[] = {0x00000080 ,0x00000000 ,0x00000000 ,0x00000000 }; -static u64 sha384_init[] = { +static u64 cc_sha384_init[] = {SHA384_H7 ,SHA384_H6 ,SHA384_H5 ,SHA384_H4 ,SHA384_H3 ,SHA384_H2 ,SHA384_H1 ,SHA384_H0 }; -static u64 sha512_init[] = { +static u64 cc_sha512_init[] = {SHA512_H7 ,SHA512_H6 ,SHA512_H5 ,SHA512_H4 ,SHA512_H3 ,SHA512_H2 ,SHA512_H1 ,SHA512_H0 }; -static const u32 sm3_init[] = { +static const u32 cc_sm3_init[] = {SM3_IVH ,SM3_IVG ,SM3_IVF ,SM3_IVE ,SM3_IVD ,SM3_IVC ,SM3_IVB ,SM3_IVA };
@@ -144,10 +144,11 @@ static void cc_init_req(struct device *dev, struct ahash_req_ctx *state,if (ctx->hash_mode ==DRV_HASH_SHA512 || ctx->hash_mode ==DRV_HASH_SHA384 )memcpy (state->digest_bytes_len, - digest_len_sha512_init, + cc_digest_len_sha512_init, ctx->hash_len);else -memcpy (state->digest_bytes_len, digest_len_init, +memcpy (state->digest_bytes_len, + cc_digest_len_init, ctx->hash_len); }
@@ -1873,26 +1874,26 @@ int cc_init_hash_sram(struct cc_drvdata *drvdata)int rc =0 ;/* Copy-to-sram digest-len */ -cc_set_sram_desc (digest_len_init, sram_buff_ofs, -ARRAY_SIZE (digest_len_init), larval_seq, +cc_set_sram_desc (cc_digest_len_init, sram_buff_ofs, +ARRAY_SIZE (cc_digest_len_init), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (digest_len_init); + sram_buff_ofs +=sizeof (cc_digest_len_init); larval_seq_len =0 ;if (large_sha_supported) {/* Copy-to-sram digest-len for sha384/512 */ -cc_set_sram_desc (digest_len_sha512_init, sram_buff_ofs, -ARRAY_SIZE (digest_len_sha512_init), +cc_set_sram_desc (cc_digest_len_sha512_init, sram_buff_ofs, +ARRAY_SIZE (cc_digest_len_sha512_init), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (digest_len_sha512_init); + sram_buff_ofs +=sizeof (cc_digest_len_sha512_init); larval_seq_len =0 ; }
@@ -1900,64 +1901,64 @@ int cc_init_hash_sram(struct cc_drvdata *drvdata) hash_handle->larval_digest_sram_addr = sram_buff_ofs;/* Copy-to-sram initial SHA* digests */ -cc_set_sram_desc (md5_init, sram_buff_ofs,ARRAY_SIZE (md5_init), +cc_set_sram_desc (cc_md5_init, sram_buff_ofs,ARRAY_SIZE (cc_md5_init), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (md5_init); + sram_buff_ofs +=sizeof (cc_md5_init); larval_seq_len =0 ; -cc_set_sram_desc (sha1_init, sram_buff_ofs, -ARRAY_SIZE (sha1_init), larval_seq, +cc_set_sram_desc (cc_sha1_init, sram_buff_ofs, +ARRAY_SIZE (cc_sha1_init), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (sha1_init); + sram_buff_ofs +=sizeof (cc_sha1_init); larval_seq_len =0 ; -cc_set_sram_desc (sha224_init, sram_buff_ofs, -ARRAY_SIZE (sha224_init), larval_seq, +cc_set_sram_desc (cc_sha224_init, sram_buff_ofs, +ARRAY_SIZE (cc_sha224_init), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (sha224_init); + sram_buff_ofs +=sizeof (cc_sha224_init); larval_seq_len =0 ; -cc_set_sram_desc (sha256_init, sram_buff_ofs, -ARRAY_SIZE (sha256_init), larval_seq, +cc_set_sram_desc (cc_sha256_init, sram_buff_ofs, +ARRAY_SIZE (cc_sha256_init), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (sha256_init); + sram_buff_ofs +=sizeof (cc_sha256_init); larval_seq_len =0 ;if (sm3_supported) { -cc_set_sram_desc (sm3_init, sram_buff_ofs, -ARRAY_SIZE (sm3_init), larval_seq, +cc_set_sram_desc (cc_sm3_init, sram_buff_ofs, +ARRAY_SIZE (cc_sm3_init), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (sm3_init); + sram_buff_ofs +=sizeof (cc_sm3_init); larval_seq_len =0 ; }if (large_sha_supported) { -cc_set_sram_desc ((u32 *)sha384_init, sram_buff_ofs, - (ARRAY_SIZE (sha384_init) *2 ), larval_seq, +cc_set_sram_desc ((u32 *)cc_sha384_init, sram_buff_ofs, + (ARRAY_SIZE (cc_sha384_init) *2 ), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc) goto init_digest_const_err; - sram_buff_ofs +=sizeof (sha384_init); + sram_buff_ofs +=sizeof (cc_sha384_init); larval_seq_len =0 ; -cc_set_sram_desc ((u32 *)sha512_init, sram_buff_ofs, - (ARRAY_SIZE (sha512_init) *2 ), larval_seq, +cc_set_sram_desc ((u32 *)cc_sha512_init, sram_buff_ofs, + (ARRAY_SIZE (cc_sha512_init) *2 ), larval_seq, &larval_seq_len); rc =send_request_init (drvdata, larval_seq, larval_seq_len);if (rc)
@@ -1986,8 +1987,8 @@ static void __init cc_swap_dwords(u32 *buf, unsigned long size)*/ void __init cc_hash_global_init (void ) { -cc_swap_dwords ((u32 *)&sha384_init, (ARRAY_SIZE (sha384_init) *2 )); -cc_swap_dwords ((u32 *)&sha512_init, (ARRAY_SIZE (sha512_init) *2 )); +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)
@@ -2006,18 +2007,18 @@ int cc_hash_alloc(struct cc_drvdata *drvdata)INIT_LIST_HEAD (&hash_handle->hash_list); drvdata->hash_handle = hash_handle; - sram_size_to_alloc =sizeof (digest_len_init) + -sizeof (md5_init) + -sizeof (sha1_init) + -sizeof (sha224_init) + -sizeof (sha256_init); + sram_size_to_alloc =sizeof (cc_digest_len_init) + +sizeof (cc_md5_init) + +sizeof (cc_sha1_init) + +sizeof (cc_sha224_init) + +sizeof (cc_sha256_init);if (drvdata->hw_rev >=CC_HW_REV_713 ) - sram_size_to_alloc +=sizeof (sm3_init); + sram_size_to_alloc +=sizeof (cc_sm3_init);if (drvdata->hw_rev >=CC_HW_REV_712 ) - sram_size_to_alloc +=sizeof (digest_len_sha512_init) + -sizeof (sha384_init) +sizeof (sha512_init); + sram_size_to_alloc +=sizeof (cc_digest_len_sha512_init) + +sizeof (cc_sha384_init) +sizeof (cc_sha512_init); sram_buff =cc_sram_alloc (drvdata, sram_size_to_alloc);if (sram_buff ==NULL_SRAM_ADDR ) {
@@ -2258,22 +2259,22 @@ static const void *cc_larval_digest(struct device *dev, u32 mode) {switch (mode) {case DRV_HASH_MD5 : -return md5_init; +return cc_md5_init;case DRV_HASH_SHA1 : -return sha1_init; +return cc_sha1_init;case DRV_HASH_SHA224 : -return sha224_init; +return cc_sha224_init;case DRV_HASH_SHA256 : -return sha256_init; +return cc_sha256_init;case DRV_HASH_SHA384 : -return sha384_init; +return cc_sha384_init;case DRV_HASH_SHA512 : -return sha512_init; +return cc_sha512_init;case DRV_HASH_SM3 : -return sm3_init; +return cc_sm3_init;default :dev_err (dev,"Invalid hash mode (%d)\n" , mode); -return md5_init; +return cc_md5_init; } }
@@ -2301,40 +2302,40 @@ cc_sram_addr_t cc_larval_digest_addr(void *drvdata, u32 mode)return (hash_handle->larval_digest_sram_addr);case DRV_HASH_SHA1 :return (hash_handle->larval_digest_sram_addr + -sizeof (md5_init)); +sizeof (cc_md5_init));case DRV_HASH_SHA224 :return (hash_handle->larval_digest_sram_addr + -sizeof (md5_init) + -sizeof (sha1_init)); +sizeof (cc_md5_init) + +sizeof (cc_sha1_init));case DRV_HASH_SHA256 :return (hash_handle->larval_digest_sram_addr + -sizeof (md5_init) + -sizeof (sha1_init) + -sizeof (sha224_init)); +sizeof (cc_md5_init) + +sizeof (cc_sha1_init) + +sizeof (cc_sha224_init));case DRV_HASH_SM3 :return (hash_handle->larval_digest_sram_addr + -sizeof (md5_init) + -sizeof (sha1_init) + -sizeof (sha224_init) + -sizeof (sha256_init)); +sizeof (cc_md5_init) + +sizeof (cc_sha1_init) + +sizeof (cc_sha224_init) + +sizeof (cc_sha256_init));case DRV_HASH_SHA384 : addr = (hash_handle->larval_digest_sram_addr + -sizeof (md5_init) + -sizeof (sha1_init) + -sizeof (sha224_init) + -sizeof (sha256_init)); +sizeof (cc_md5_init) + +sizeof (cc_sha1_init) + +sizeof (cc_sha224_init) + +sizeof (cc_sha256_init));if (sm3_supported) - addr +=sizeof (sm3_init); + addr +=sizeof (cc_sm3_init);return addr;case DRV_HASH_SHA512 : addr = (hash_handle->larval_digest_sram_addr + -sizeof (md5_init) + -sizeof (sha1_init) + -sizeof (sha224_init) + -sizeof (sha256_init) + -sizeof (sha384_init)); +sizeof (cc_md5_init) + +sizeof (cc_sha1_init) + +sizeof (cc_sha224_init) + +sizeof (cc_sha256_init) + +sizeof (cc_sha384_init));if (sm3_supported) - addr +=sizeof (sm3_init); + addr +=sizeof (cc_sm3_init);return addr;default :dev_err (dev,"Invalid hash mode (%d)\n" , mode);
@@ -2360,7 +2361,7 @@ cc_digest_len_addr(void *drvdata, u32 mode)#if (CC_DEV_SHA_MAX >256 )case DRV_HASH_SHA384 :case DRV_HASH_SHA512 : -return digest_len_addr +sizeof (digest_len_init); +return digest_len_addr +sizeof (cc_digest_len_init);#endif default :return digest_len_addr;/*to avoid kernel crash*/
Signature · 1 line
2.23.0
Gilad Ben-Yossef
maintainerRe: [PATCH 5/9] crypto: ccree - Rename arrays to avoid conflict with crypto/sha256.h
Quoted 5 lines · Hans de Goede
Rename the
algo_initarrays tocc_algo_initso that they do not conflict with the functions declared incrypto/sha256.h.This is a preparation patch for folding
crypto/sha256.hintocrypto/sha.h.
I'm fine with the renaming.
Thanks,
Gilad
Re: [PATCH 5/9] crypto: ccree - Rename arrays to avoid conflict with crypto/sha256.h
Hi,
Quoted 10 lines · Gilad Ben-Yossef
Quoted 5 lines · Hans de Goede
Rename the
algo_initarrays tocc_algo_initso that they do not conflict with the functions declared incrypto/sha256.h.This is a preparation patch for folding
crypto/sha256.hintocrypto/sha.h.I'm fine with the renaming.
Signed-off-by Gilad Ben-Yossef <[email protected]>
Your Signed-off-by is only used when the patches passes through your hands, since Herbert will likely apply this directly that is not the case.
You want either Acked-by or Reviewed-by to signal that you are ok with this patch.
Regards,
Hans
Re: [PATCH 5/9] crypto: ccree - Rename arrays to avoid conflict with crypto/sha256.h
Quoted 11 lines · Hans de Goede
Hi,
Quoted 7 lines · Gilad Ben-Yossef
Quoted 5 lines · Hans de Goede
Rename the
algo_initarrays tocc_algo_initso that they do not conflict with the functions declared incrypto/sha256.h.This is a preparation patch for folding
crypto/sha256.hintocrypto/sha.h.
Quoted 9 lines
Quoted 3 lines
I'm fine with the renaming.
Signed-off-by Gilad Ben-Yossef <[email protected]>Your Signed-off-by is only used when the patches passes through your hands, since Herbert will likely apply this directly that is not the case.
You want either Acked-by or Reviewed-by to signal that you are ok with this patch.
Yes, you are right of course. Wrong macro... sorry about that.
Signature · 4 lines
Gilad Ben-Yossef Chief Coffee Drinker values of β will give rise to dom!
PATCH 6/9 crypto: chelsio - Rename arrays to avoid conflict with crypto/sha256.h
In reply to Hans de GoedeRename the sha*_init arrays to chcr_sha*_init so that they do not conflict with the functions declared in crypto/sha256.h.
This is a preparation patch for folding crypto/sha256.h into crypto/sha.h.
--- drivers/crypto/chelsio/chcr_algo.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/crypto/chelsio/chcr_algo.h +10 -10
@@ -333,26 +333,26 @@ struct phys_sge_pairs { }; -static const u32 sha1_init[SHA1_DIGEST_SIZE /4 ] = { +static const u32 chcr_sha1_init[SHA1_DIGEST_SIZE /4 ] = {SHA1_H0 ,SHA1_H1 ,SHA1_H2 ,SHA1_H3 ,SHA1_H4 , }; -static const u32 sha224_init[SHA256_DIGEST_SIZE /4 ] = { +static const u32 chcr_sha224_init[SHA256_DIGEST_SIZE /4 ] = {SHA224_H0 ,SHA224_H1 ,SHA224_H2 ,SHA224_H3 ,SHA224_H4 ,SHA224_H5 ,SHA224_H6 ,SHA224_H7 , }; -static const u32 sha256_init[SHA256_DIGEST_SIZE /4 ] = { +static const u32 chcr_sha256_init[SHA256_DIGEST_SIZE /4 ] = {SHA256_H0 ,SHA256_H1 ,SHA256_H2 ,SHA256_H3 ,SHA256_H4 ,SHA256_H5 ,SHA256_H6 ,SHA256_H7 , }; -static const u64 sha384_init[SHA512_DIGEST_SIZE /8 ] = { +static const u64 chcr_sha384_init[SHA512_DIGEST_SIZE /8 ] = {SHA384_H0 ,SHA384_H1 ,SHA384_H2 ,SHA384_H3 ,SHA384_H4 ,SHA384_H5 ,SHA384_H6 ,SHA384_H7 , }; -static const u64 sha512_init[SHA512_DIGEST_SIZE /8 ] = { +static const u64 chcr_sha512_init[SHA512_DIGEST_SIZE /8 ] = {SHA512_H0 ,SHA512_H1 ,SHA512_H2 ,SHA512_H3 ,SHA512_H4 ,SHA512_H5 ,SHA512_H6 ,SHA512_H7 , };
@@ -362,21 +362,21 @@ static inline void copy_hash_init_values(char *key, int digestsize)u8 i;__be32 *dkey = (__be32 *)key;u64 *ldkey = (u64 *)key; -__be64 *sha384 = (__be64 *)sha384_init; -__be64 *sha512 = (__be64 *)sha512_init; +__be64 *sha384 = (__be64 *)chcr_sha384_init; +__be64 *sha512 = (__be64 *)chcr_sha512_init;switch (digestsize) {case SHA1_DIGEST_SIZE :for (i =0 ; i <SHA1_INIT_STATE ; i++) - dkey[i] =cpu_to_be32 (sha1_init[i]); + dkey[i] =cpu_to_be32 (chcr_sha1_init[i]);break ;case SHA224_DIGEST_SIZE :for (i =0 ; i <SHA224_INIT_STATE ; i++) - dkey[i] =cpu_to_be32 (sha224_init[i]); + dkey[i] =cpu_to_be32 (chcr_sha224_init[i]);break ;case SHA256_DIGEST_SIZE :for (i =0 ; i <SHA256_INIT_STATE ; i++) - dkey[i] =cpu_to_be32 (sha256_init[i]); + dkey[i] =cpu_to_be32 (chcr_sha256_init[i]);break ;case SHA384_DIGEST_SIZE :for (i =0 ; i <SHA384_INIT_STATE ; i++)
Signature · 1 line
2.23.0
PATCH 7/9 crypto: n2 - Rename arrays to avoid conflict with crypto/sha256.h
In reply to Hans de GoedeRename the sha*_init arrays to n2_sha*_init so that they do not conflict with the functions declared in crypto/sha256.h.
Also rename md5_init to n2_md5_init for consistency.
This is a preparation patch for folding crypto/sha256.h into crypto/sha.h.
--- drivers/crypto/n2_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/crypto/n2_core.c +8 -8
@@ -1295,20 +1295,20 @@ struct n2_hash_tmpl {u8 hmac_type; }; -static const u32 md5_init[MD5_HASH_WORDS ] = { +static const u32 n2_md5_init[MD5_HASH_WORDS ] = {cpu_to_le32 (MD5_H0 ),cpu_to_le32 (MD5_H1 ),cpu_to_le32 (MD5_H2 ),cpu_to_le32 (MD5_H3 ), }; -static const u32 sha1_init[SHA1_DIGEST_SIZE /4 ] = { +static const u32 n2_sha1_init[SHA1_DIGEST_SIZE /4 ] = {SHA1_H0 ,SHA1_H1 ,SHA1_H2 ,SHA1_H3 ,SHA1_H4 , }; -static const u32 sha256_init[SHA256_DIGEST_SIZE /4 ] = { +static const u32 n2_sha256_init[SHA256_DIGEST_SIZE /4 ] = {SHA256_H0 ,SHA256_H1 ,SHA256_H2 ,SHA256_H3 ,SHA256_H4 ,SHA256_H5 ,SHA256_H6 ,SHA256_H7 , }; -static const u32 sha224_init[SHA256_DIGEST_SIZE /4 ] = { +static const u32 n2_sha224_init[SHA256_DIGEST_SIZE /4 ] = {SHA224_H0 ,SHA224_H1 ,SHA224_H2 ,SHA224_H3 ,SHA224_H4 ,SHA224_H5 ,SHA224_H6 ,SHA224_H7 , };
@@ -1316,7 +1316,7 @@ static const u32 sha224_init[SHA256_DIGEST_SIZE / 4] = {static const struct n2_hash_tmpl hash_tmpls[] = { { .name ="md5" , .hash_zero = md5_zero_message_hash, - .hash_init = md5_init, + .hash_init = n2_md5_init, .auth_type =AUTH_TYPE_MD5 , .hmac_type =AUTH_TYPE_HMAC_MD5 , .hw_op_hashsz =MD5_DIGEST_SIZE ,
@@ -1324,7 +1324,7 @@ static const struct n2_hash_tmpl hash_tmpls[] = { .block_size = MD5_HMAC_BLOCK_SIZE }, { .name = "sha1", .hash_zero = sha1_zero_message_hash, - .hash_init = sha1_init, + .hash_init = n2_sha1_init, .auth_type = AUTH_TYPE_SHA1, .hmac_type = AUTH_TYPE_HMAC_SHA1, .hw_op_hashsz = SHA1_DIGEST_SIZE,
@@ -1332,7 +1332,7 @@ static const struct n2_hash_tmpl hash_tmpls[] = { .block_size = SHA1_BLOCK_SIZE }, { .name = "sha256", .hash_zero = sha256_zero_message_hash, - .hash_init = sha256_init, + .hash_init = n2_sha256_init, .auth_type = AUTH_TYPE_SHA256, .hmac_type = AUTH_TYPE_HMAC_SHA256, .hw_op_hashsz = SHA256_DIGEST_SIZE,
@@ -1340,7 +1340,7 @@ static const struct n2_hash_tmpl hash_tmpls[] = { .block_size = SHA256_BLOCK_SIZE }, { .name = "sha224", .hash_zero = sha224_zero_message_hash, - .hash_init = sha224_init, + .hash_init = n2_sha224_init, .auth_type = AUTH_TYPE_SHA256, .hmac_type = AUTH_TYPE_RESERVED, .hw_op_hashsz = SHA256_DIGEST_SIZE,
Signature · 1 line
2.23.0
PATCH 8/9 crypto: sha256 - Merge crypto/sha256.h into crypto/sha.h
In reply to Hans de GoedeThe generic sha256 implementation from lib/crypto/sha256.c uses data structs defined in crypto/sha.h, so lets move the function prototypes there too.
--- arch/s390/purgatory/purgatory.c | 2 +- arch/x86/purgatory/purgatory.c | 2 +- crypto/sha256_generic.c | 1 - include/crypto/sha.h | 21 ++++++++++++++++++++ include/crypto/sha256.h | 34 --------------------------------- lib/crypto/sha256.c | 2 +- 6 files changed, 24 insertions(+), 38 deletions(-) delete mode 100644 include/crypto/sha256.h
arch/s390/purgatory/purgatory.c +1 -1
@@ -9,7 +9,7 @@#include <linux/kexec.h> #include <linux/string.h> -#include <crypto/sha256.h> +#include <crypto/sha.h> #include <asm/purgatory.h> int verify_sha256_digest (void )
arch/x86/purgatory/purgatory.c +1 -1
@@ -9,7 +9,7 @@*/ #include <linux/bug.h> -#include <crypto/sha256.h> +#include <crypto/sha.h> #include <asm/purgatory.h> #include "../boot/string.h"
crypto/sha256_generic.c +0 -1
@@ -13,7 +13,6 @@#include <linux/mm.h> #include <linux/types.h> #include <crypto/sha.h> -#include <crypto/sha256.h> #include <crypto/sha256_base.h> #include <asm/byteorder.h> #include <asm/unaligned.h>
include/crypto/sha.h +21 -0
@@ -112,4 +112,25 @@ extern int crypto_sha512_update(struct shash_desc *desc, const u8 *data,extern int crypto_sha512_finup (struct shash_desc *desc,const u8 *data,unsigned int len,u8 *hash); + +/* +* Stand-alone implementation of the SHA256 algorithm. It is designed to +* have as little dependencies as possible so it can be used in the +* kexec_file purgatory. In other cases you should generally use the +* hash APIs from include/crypto/hash.h. Especially when hashing large +* amounts of data as those APIs may be hw-accelerated. +* +* For details see lib/crypto/sha256.c +*/ + +extern int sha256_init (struct sha256_state *sctx); +extern int sha256_update (struct sha256_state *sctx,const u8 *input, +unsigned int length); +extern int sha256_final (struct sha256_state *sctx,u8 *hash); + +extern int sha224_init (struct sha256_state *sctx); +extern int sha224_update (struct sha256_state *sctx,const u8 *input, +unsigned int length); +extern int sha224_final (struct sha256_state *sctx,u8 *hash); +#endif
include/crypto/sha256.h deleted +0 -34
@@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* Copyright (C) 2014 Red Hat Inc. -* -* Author: Vivek Goyal <[email protected]> -*/ - -#ifndef SHA256_H -#define SHA256_H - -#include <linux/types.h> -#include <crypto/sha.h> - -/* -* Stand-alone implementation of the SHA256 algorithm. It is designed to -* have as little dependencies as possible so it can be used in the -* kexec_file purgatory. In other cases you should generally use the -* hash APIs from include/crypto/hash.h. Especially when hashing large -* amounts of data as those APIs may be hw-accelerated. -* -* For details see lib/crypto/sha256.c -*/ - -extern int sha256_init (struct sha256_state *sctx); -extern int sha256_update (struct sha256_state *sctx,const u8 *input, -unsigned int length); -extern int sha256_final (struct sha256_state *sctx,u8 *hash); - -extern int sha224_init (struct sha256_state *sctx); -extern int sha224_update (struct sha256_state *sctx,const u8 *input, -unsigned int length); -extern int sha224_final (struct sha256_state *sctx,u8 *hash); - -#endif /* SHA256_H */
lib/crypto/sha256.c +1 -1
@@ -15,7 +15,7 @@#include <linux/export.h> #include <linux/module.h> #include <linux/string.h> -#include <crypto/sha256.h> +#include <crypto/sha.h> #include <asm/unaligned.h> static inline u32 Ch (u32 x,u32 y,u32 z)
Signature · 1 line
2.23.0
PATCH 9/9 crypto: sha256 - Remove sha256/224_init code duplication
In reply to Hans de Goedelib/crypto/sha256.c and include/crypto/sha256_base.h define 99% identical functions to init a sha256_state struct for sha224 or sha256 use.
This commit moves the functions from lib/crypto/sha256.c to include/crypto/sha.h (making them static inline) and makes the sha224/256_base_init static inline functions from include/crypto/sha256_base.h wrappers around the now also static inline include/crypto/sha.h functions.
--- include/crypto/sha.h | 30 ++++++++++++++++++++++++++++-- include/crypto/sha256_base.h | 24 ++---------------------- lib/crypto/sha256.c | 32 -------------------------------- 3 files changed, 30 insertions(+), 56 deletions(-)
include/crypto/sha.h +28 -2
@@ -123,12 +123,38 @@ extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data,* For details see lib/crypto/sha256.c */ -extern int sha256_init (struct sha256_state *sctx); +static inline int sha256_init (struct sha256_state *sctx) +{ + sctx->state[0 ] =SHA256_H0 ; + sctx->state[1 ] =SHA256_H1 ; + sctx->state[2 ] =SHA256_H2 ; + sctx->state[3 ] =SHA256_H3 ; + sctx->state[4 ] =SHA256_H4 ; + sctx->state[5 ] =SHA256_H5 ; + sctx->state[6 ] =SHA256_H6 ; + sctx->state[7 ] =SHA256_H7 ; + sctx->count =0 ; + +return 0 ; +}extern int sha256_update (struct sha256_state *sctx,const u8 *input,unsigned int length);extern int sha256_final (struct sha256_state *sctx,u8 *hash); -extern int sha224_init (struct sha256_state *sctx); +static inline int sha224_init (struct sha256_state *sctx) +{ + sctx->state[0 ] =SHA224_H0 ; + sctx->state[1 ] =SHA224_H1 ; + sctx->state[2 ] =SHA224_H2 ; + sctx->state[3 ] =SHA224_H3 ; + sctx->state[4 ] =SHA224_H4 ; + sctx->state[5 ] =SHA224_H5 ; + sctx->state[6 ] =SHA224_H6 ; + sctx->state[7 ] =SHA224_H7 ; + sctx->count =0 ; + +return 0 ; +}extern int sha224_update (struct sha256_state *sctx,const u8 *input,unsigned int length);extern int sha224_final (struct sha256_state *sctx,u8 *hash);
include/crypto/sha256_base.h +2 -22
@@ -19,34 +19,14 @@ static inline int sha224_base_init(struct shash_desc *desc) {struct sha256_state *sctx =shash_desc_ctx (desc); - sctx->state[0 ] =SHA224_H0 ; - sctx->state[1 ] =SHA224_H1 ; - sctx->state[2 ] =SHA224_H2 ; - sctx->state[3 ] =SHA224_H3 ; - sctx->state[4 ] =SHA224_H4 ; - sctx->state[5 ] =SHA224_H5 ; - sctx->state[6 ] =SHA224_H6 ; - sctx->state[7 ] =SHA224_H7 ; - sctx->count =0 ; - -return 0 ; +return sha224_init (sctx); }static inline int sha256_base_init (struct shash_desc *desc) {struct sha256_state *sctx =shash_desc_ctx (desc); - sctx->state[0 ] =SHA256_H0 ; - sctx->state[1 ] =SHA256_H1 ; - sctx->state[2 ] =SHA256_H2 ; - sctx->state[3 ] =SHA256_H3 ; - sctx->state[4 ] =SHA256_H4 ; - sctx->state[5 ] =SHA256_H5 ; - sctx->state[6 ] =SHA256_H6 ; - sctx->state[7 ] =SHA256_H7 ; - sctx->count =0 ; - -return 0 ; +return sha256_init (sctx); } static inline int sha256_base_do_update(struct shash_desc *desc,
lib/crypto/sha256.c +0 -32
@@ -206,38 +206,6 @@ static void sha256_transform(u32 *state, const u8 *input)memzero_explicit (W ,64 *sizeof (u32)); } -int sha256_init (struct sha256_state *sctx) -{ - sctx->state[0 ] =SHA256_H0 ; - sctx->state[1 ] =SHA256_H1 ; - sctx->state[2 ] =SHA256_H2 ; - sctx->state[3 ] =SHA256_H3 ; - sctx->state[4 ] =SHA256_H4 ; - sctx->state[5 ] =SHA256_H5 ; - sctx->state[6 ] =SHA256_H6 ; - sctx->state[7 ] =SHA256_H7 ; - sctx->count =0 ; - -return 0 ; -} -EXPORT_SYMBOL (sha256_init); - -int sha224_init (struct sha256_state *sctx) -{ - sctx->state[0 ] =SHA224_H0 ; - sctx->state[1 ] =SHA224_H1 ; - sctx->state[2 ] =SHA224_H2 ; - sctx->state[3 ] =SHA224_H3 ; - sctx->state[4 ] =SHA224_H4 ; - sctx->state[5 ] =SHA224_H5 ; - sctx->state[6 ] =SHA224_H6 ; - sctx->state[7 ] =SHA224_H7 ; - sctx->count =0 ; - -return 0 ; -} -EXPORT_SYMBOL (sha224_init); -int sha256_update (struct sha256_state *sctx,const u8 *data,unsigned int len) {unsigned int partial, done;
Signature · 1 line
2.23.0
Quoted 12 lines · Hans de Goede
Hi All,
As promised here is a follow-up series to my earlier sha256 series.
Note I have only compiled and tested this series on
x86_64!!All changes to architecture specific code on other archs have not even been tested to compile! With that said most of these changes were done using my editors search - replace function so things should be fine... (and FWIW I did do a
Kconfighack to compile test the ccree change).
Quoted 9 lines
The first patch in this series rename various file local functions / arrays to avoid conflicts with the new
include/crypto/sha256.h, followed by a patch merginginclude/crypto/sha256.hintoinclude/crypto/sha.h.The last patch makes use of this merging to remove a bit more code duplication, making
sha256_genericusesha256_initandsha224_initfromlib/crypto/sha256.c. An added advantage of this, is that this gives these 2 functions coverage by the crypto selftests.
For the series,
Thanks Hans.
Herbert Xu
maintainerQuoted 11 lines · Hans de Goede
Hi All,
As promised here is a follow-up series to my earlier sha256 series.
Note I have only compiled and tested this series on
x86_64!!All changes to architecture specific code on other archs have not even been tested to compile! With that said most of these changes were done using my editors search - replace function so things should be fine... (and FWIW I did do a
Kconfighack to compile test the ccree change).
Quoted 8 lines
The first patch in this series rename various file local functions / arrays to avoid conflicts with the new
include/crypto/sha256.h, followed by a patch merginginclude/crypto/sha256.hintoinclude/crypto/sha.h.The last patch makes use of this merging to remove a bit more code duplication, making
sha256_genericusesha256_initandsha224_initfromlib/crypto/sha256.c. An added advantage of this, is that this gives these 2 functions coverage by the crypto selftests.
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt