Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: s390/sha3 - Use API partial block handling

Use the Crypto API partial block handling.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+56 -75
+27 -33
arch/s390/crypto/sha3_256_s390.c
··· 8 8 * Copyright IBM Corp. 2019 9 9 * Author(s): Joerg Schmidbauer (jschmidb@de.ibm.com) 10 10 */ 11 - #include <crypto/internal/hash.h> 12 - #include <linux/init.h> 13 - #include <linux/module.h> 14 - #include <linux/cpufeature.h> 15 - #include <crypto/sha3.h> 16 11 #include <asm/cpacf.h> 12 + #include <crypto/internal/hash.h> 13 + #include <crypto/sha3.h> 14 + #include <linux/cpufeature.h> 15 + #include <linux/errno.h> 16 + #include <linux/kernel.h> 17 + #include <linux/module.h> 18 + #include <linux/string.h> 17 19 18 20 #include "sha.h" 19 21 ··· 23 21 { 24 22 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 25 23 26 - if (!test_facility(86)) /* msa 12 */ 24 + sctx->first_message_part = test_facility(86); 25 + if (!sctx->first_message_part) 27 26 memset(sctx->state, 0, sizeof(sctx->state)); 28 27 sctx->count = 0; 29 28 sctx->func = CPACF_KIMD_SHA3_256; 30 - sctx->first_message_part = 1; 31 29 32 30 return 0; 33 31 } ··· 37 35 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 38 36 struct sha3_state *octx = out; 39 37 40 - octx->rsiz = sctx->count; 38 + if (sctx->first_message_part) { 39 + memset(sctx->state, 0, sizeof(sctx->state)); 40 + sctx->first_message_part = 0; 41 + } 41 42 memcpy(octx->st, sctx->state, sizeof(octx->st)); 42 - memcpy(octx->buf, sctx->buf, sizeof(octx->buf)); 43 - octx->partial = sctx->first_message_part; 44 - 45 43 return 0; 46 44 } 47 45 ··· 50 48 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 51 49 const struct sha3_state *ictx = in; 52 50 53 - sctx->count = ictx->rsiz; 51 + sctx->count = 0; 54 52 memcpy(sctx->state, ictx->st, sizeof(ictx->st)); 55 - memcpy(sctx->buf, ictx->buf, sizeof(ictx->buf)); 56 - sctx->first_message_part = ictx->partial; 53 + sctx->first_message_part = 0; 57 54 sctx->func = CPACF_KIMD_SHA3_256; 58 55 59 56 return 0; ··· 61 60 static int sha3_224_import(struct shash_desc *desc, const void *in) 62 61 { 63 62 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 64 - const struct sha3_state *ictx = in; 65 63 66 - sctx->count = ictx->rsiz; 67 - memcpy(sctx->state, ictx->st, sizeof(ictx->st)); 68 - memcpy(sctx->buf, ictx->buf, sizeof(ictx->buf)); 69 - sctx->first_message_part = ictx->partial; 64 + sha3_256_import(desc, in); 70 65 sctx->func = CPACF_KIMD_SHA3_224; 71 - 72 66 return 0; 73 67 } 74 68 75 69 static struct shash_alg sha3_256_alg = { 76 70 .digestsize = SHA3_256_DIGEST_SIZE, /* = 32 */ 77 71 .init = sha3_256_init, 78 - .update = s390_sha_update, 79 - .final = s390_sha_final, 72 + .update = s390_sha_update_blocks, 73 + .finup = s390_sha_finup, 80 74 .export = sha3_256_export, 81 75 .import = sha3_256_import, 82 - .descsize = sizeof(struct s390_sha_ctx), 83 - .statesize = sizeof(struct sha3_state), 76 + .descsize = S390_SHA_CTX_SIZE, 77 + .statesize = SHA3_STATE_SIZE, 84 78 .base = { 85 79 .cra_name = "sha3-256", 86 80 .cra_driver_name = "sha3-256-s390", 87 81 .cra_priority = 300, 82 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 88 83 .cra_blocksize = SHA3_256_BLOCK_SIZE, 89 84 .cra_module = THIS_MODULE, 90 85 } ··· 90 93 { 91 94 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 92 95 93 - if (!test_facility(86)) /* msa 12 */ 94 - memset(sctx->state, 0, sizeof(sctx->state)); 95 - sctx->count = 0; 96 + sha3_256_init(desc); 96 97 sctx->func = CPACF_KIMD_SHA3_224; 97 - sctx->first_message_part = 1; 98 - 99 98 return 0; 100 99 } 101 100 102 101 static struct shash_alg sha3_224_alg = { 103 102 .digestsize = SHA3_224_DIGEST_SIZE, 104 103 .init = sha3_224_init, 105 - .update = s390_sha_update, 106 - .final = s390_sha_final, 104 + .update = s390_sha_update_blocks, 105 + .finup = s390_sha_finup, 107 106 .export = sha3_256_export, /* same as for 256 */ 108 107 .import = sha3_224_import, /* function code different! */ 109 - .descsize = sizeof(struct s390_sha_ctx), 110 - .statesize = sizeof(struct sha3_state), 108 + .descsize = S390_SHA_CTX_SIZE, 109 + .statesize = SHA3_STATE_SIZE, 111 110 .base = { 112 111 .cra_name = "sha3-224", 113 112 .cra_driver_name = "sha3-224-s390", 114 113 .cra_priority = 300, 114 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 115 115 .cra_blocksize = SHA3_224_BLOCK_SIZE, 116 116 .cra_module = THIS_MODULE, 117 117 }
+27 -40
arch/s390/crypto/sha3_512_s390.c
··· 7 7 * Copyright IBM Corp. 2019 8 8 * Author(s): Joerg Schmidbauer (jschmidb@de.ibm.com) 9 9 */ 10 - #include <crypto/internal/hash.h> 11 - #include <linux/init.h> 12 - #include <linux/module.h> 13 - #include <linux/cpufeature.h> 14 - #include <crypto/sha3.h> 15 10 #include <asm/cpacf.h> 11 + #include <crypto/internal/hash.h> 12 + #include <crypto/sha3.h> 13 + #include <linux/cpufeature.h> 14 + #include <linux/errno.h> 15 + #include <linux/kernel.h> 16 + #include <linux/module.h> 17 + #include <linux/string.h> 16 18 17 19 #include "sha.h" 18 20 ··· 22 20 { 23 21 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 24 22 25 - if (!test_facility(86)) /* msa 12 */ 23 + sctx->first_message_part = test_facility(86); 24 + if (!sctx->first_message_part) 26 25 memset(sctx->state, 0, sizeof(sctx->state)); 27 26 sctx->count = 0; 28 27 sctx->func = CPACF_KIMD_SHA3_512; 29 - sctx->first_message_part = 1; 30 28 31 29 return 0; 32 30 } ··· 36 34 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 37 35 struct sha3_state *octx = out; 38 36 39 - octx->rsiz = sctx->count; 40 - octx->rsizw = sctx->count >> 32; 41 37 38 + if (sctx->first_message_part) { 39 + memset(sctx->state, 0, sizeof(sctx->state)); 40 + sctx->first_message_part = 0; 41 + } 42 42 memcpy(octx->st, sctx->state, sizeof(octx->st)); 43 - memcpy(octx->buf, sctx->buf, sizeof(octx->buf)); 44 - octx->partial = sctx->first_message_part; 45 - 46 43 return 0; 47 44 } 48 45 ··· 50 49 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 51 50 const struct sha3_state *ictx = in; 52 51 53 - if (unlikely(ictx->rsizw)) 54 - return -ERANGE; 55 - sctx->count = ictx->rsiz; 56 - 52 + sctx->count = 0; 57 53 memcpy(sctx->state, ictx->st, sizeof(ictx->st)); 58 - memcpy(sctx->buf, ictx->buf, sizeof(ictx->buf)); 59 - sctx->first_message_part = ictx->partial; 54 + sctx->first_message_part = 0; 60 55 sctx->func = CPACF_KIMD_SHA3_512; 61 56 62 57 return 0; ··· 61 64 static int sha3_384_import(struct shash_desc *desc, const void *in) 62 65 { 63 66 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 64 - const struct sha3_state *ictx = in; 65 67 66 - if (unlikely(ictx->rsizw)) 67 - return -ERANGE; 68 - sctx->count = ictx->rsiz; 69 - 70 - memcpy(sctx->state, ictx->st, sizeof(ictx->st)); 71 - memcpy(sctx->buf, ictx->buf, sizeof(ictx->buf)); 72 - sctx->first_message_part = ictx->partial; 68 + sha3_512_import(desc, in); 73 69 sctx->func = CPACF_KIMD_SHA3_384; 74 - 75 70 return 0; 76 71 } 77 72 78 73 static struct shash_alg sha3_512_alg = { 79 74 .digestsize = SHA3_512_DIGEST_SIZE, 80 75 .init = sha3_512_init, 81 - .update = s390_sha_update, 82 - .final = s390_sha_final, 76 + .update = s390_sha_update_blocks, 77 + .finup = s390_sha_finup, 83 78 .export = sha3_512_export, 84 79 .import = sha3_512_import, 85 - .descsize = sizeof(struct s390_sha_ctx), 86 - .statesize = sizeof(struct sha3_state), 80 + .descsize = S390_SHA_CTX_SIZE, 81 + .statesize = SHA3_STATE_SIZE, 87 82 .base = { 88 83 .cra_name = "sha3-512", 89 84 .cra_driver_name = "sha3-512-s390", 90 85 .cra_priority = 300, 86 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 91 87 .cra_blocksize = SHA3_512_BLOCK_SIZE, 92 88 .cra_module = THIS_MODULE, 93 89 } ··· 92 102 { 93 103 struct s390_sha_ctx *sctx = shash_desc_ctx(desc); 94 104 95 - if (!test_facility(86)) /* msa 12 */ 96 - memset(sctx->state, 0, sizeof(sctx->state)); 97 - sctx->count = 0; 105 + sha3_512_init(desc); 98 106 sctx->func = CPACF_KIMD_SHA3_384; 99 - sctx->first_message_part = 1; 100 - 101 107 return 0; 102 108 } 103 109 104 110 static struct shash_alg sha3_384_alg = { 105 111 .digestsize = SHA3_384_DIGEST_SIZE, 106 112 .init = sha3_384_init, 107 - .update = s390_sha_update, 108 - .final = s390_sha_final, 113 + .update = s390_sha_update_blocks, 114 + .finup = s390_sha_finup, 109 115 .export = sha3_512_export, /* same as for 512 */ 110 116 .import = sha3_384_import, /* function code different! */ 111 - .descsize = sizeof(struct s390_sha_ctx), 112 - .statesize = sizeof(struct sha3_state), 117 + .descsize = S390_SHA_CTX_SIZE, 118 + .statesize = SHA3_STATE_SIZE, 113 119 .base = { 114 120 .cra_name = "sha3-384", 115 121 .cra_driver_name = "sha3-384-s390", 116 122 .cra_priority = 300, 123 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 117 124 .cra_blocksize = SHA3_384_BLOCK_SIZE, 118 125 .cra_ctxsize = sizeof(struct s390_sha_ctx), 119 126 .cra_module = THIS_MODULE,
+2 -2
arch/s390/crypto/sha_common.c
··· 29 29 30 30 fc = ctx->func; 31 31 if (ctx->first_message_part) 32 - fc |= test_facility(86) ? CPACF_KIMD_NIP : 0; 32 + fc |= CPACF_KIMD_NIP; 33 33 34 34 /* process one stored block */ 35 35 if (index) { ··· 68 68 69 69 fc = ctx->func; 70 70 if (ctx->first_message_part) 71 - fc |= test_facility(86) ? CPACF_KIMD_NIP : 0; 71 + fc |= CPACF_KIMD_NIP; 72 72 73 73 /* process as many blocks as possible */ 74 74 n = (len / bsize) * bsize;