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: zynqmp-sha - Use API partial block handling

Use the Crypto API partial block handling.

As this was the last user of the extra fields in struct sha3_state,
remove them.

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

+22 -54
+22 -49
drivers/crypto/xilinx/zynqmp-sha.c
··· 3 3 * Xilinx ZynqMP SHA Driver. 4 4 * Copyright (c) 2022 Xilinx Inc. 5 5 */ 6 - #include <crypto/hash.h> 7 6 #include <crypto/internal/hash.h> 8 7 #include <crypto/sha3.h> 9 8 #include <linux/cacheflush.h> ··· 36 37 struct crypto_shash *fbk_tfm; 37 38 }; 38 39 39 - struct zynqmp_sha_desc_ctx { 40 - struct shash_desc fbk_req; 41 - }; 42 - 43 40 static dma_addr_t update_dma_addr, final_dma_addr; 44 41 static char *ubuf, *fbuf; 45 42 ··· 59 64 return PTR_ERR(fallback_tfm); 60 65 61 66 if (crypto_shash_descsize(hash) < 62 - sizeof(struct zynqmp_sha_desc_ctx) + 63 67 crypto_shash_descsize(tfm_ctx->fbk_tfm)) { 64 68 crypto_free_shash(fallback_tfm); 65 69 return -EINVAL; ··· 73 79 { 74 80 struct zynqmp_sha_tfm_ctx *tfm_ctx = crypto_shash_ctx(hash); 75 81 76 - if (tfm_ctx->fbk_tfm) { 77 - crypto_free_shash(tfm_ctx->fbk_tfm); 78 - tfm_ctx->fbk_tfm = NULL; 79 - } 80 - 81 - memzero_explicit(tfm_ctx, sizeof(struct zynqmp_sha_tfm_ctx)); 82 + crypto_free_shash(tfm_ctx->fbk_tfm); 82 83 } 83 84 84 85 static int zynqmp_sha_init(struct shash_desc *desc) 85 86 { 86 - struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc); 87 87 struct zynqmp_sha_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); 88 + struct crypto_shash *fbtfm = tctx->fbk_tfm; 89 + SHASH_DESC_ON_STACK(fbdesc, fbtfm); 88 90 89 - dctx->fbk_req.tfm = tctx->fbk_tfm; 90 - return crypto_shash_init(&dctx->fbk_req); 91 + fbdesc->tfm = fbtfm; 92 + return crypto_shash_init(fbdesc) ?: 93 + crypto_shash_export_core(fbdesc, shash_desc_ctx(desc)); 91 94 } 92 95 93 96 static int zynqmp_sha_update(struct shash_desc *desc, const u8 *data, unsigned int length) 94 97 { 95 - struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc); 98 + struct zynqmp_sha_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); 99 + struct crypto_shash *fbtfm = tctx->fbk_tfm; 100 + SHASH_DESC_ON_STACK(fbdesc, fbtfm); 96 101 97 - return crypto_shash_update(&dctx->fbk_req, data, length); 98 - } 99 - 100 - static int zynqmp_sha_final(struct shash_desc *desc, u8 *out) 101 - { 102 - struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc); 103 - 104 - return crypto_shash_final(&dctx->fbk_req, out); 102 + fbdesc->tfm = fbtfm; 103 + return crypto_shash_import_core(fbdesc, shash_desc_ctx(desc)) ?: 104 + crypto_shash_update(fbdesc, data, length) ?: 105 + crypto_shash_export_core(fbdesc, shash_desc_ctx(desc)); 105 106 } 106 107 107 108 static int zynqmp_sha_finup(struct shash_desc *desc, const u8 *data, unsigned int length, u8 *out) 108 109 { 109 - struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc); 110 - 111 - return crypto_shash_finup(&dctx->fbk_req, data, length, out); 112 - } 113 - 114 - static int zynqmp_sha_import(struct shash_desc *desc, const void *in) 115 - { 116 - struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc); 117 110 struct zynqmp_sha_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); 111 + struct crypto_shash *fbtfm = tctx->fbk_tfm; 112 + SHASH_DESC_ON_STACK(fbdesc, fbtfm); 118 113 119 - dctx->fbk_req.tfm = tctx->fbk_tfm; 120 - return crypto_shash_import(&dctx->fbk_req, in); 121 - } 122 - 123 - static int zynqmp_sha_export(struct shash_desc *desc, void *out) 124 - { 125 - struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc); 126 - 127 - return crypto_shash_export(&dctx->fbk_req, out); 114 + fbdesc->tfm = fbtfm; 115 + return crypto_shash_import_core(fbdesc, shash_desc_ctx(desc)) ?: 116 + crypto_shash_finup(fbdesc, data, length, out); 128 117 } 129 118 130 119 static int __zynqmp_sha_digest(struct shash_desc *desc, const u8 *data, ··· 156 179 .sha3_384 = { 157 180 .init = zynqmp_sha_init, 158 181 .update = zynqmp_sha_update, 159 - .final = zynqmp_sha_final, 160 182 .finup = zynqmp_sha_finup, 161 183 .digest = zynqmp_sha_digest, 162 - .export = zynqmp_sha_export, 163 - .import = zynqmp_sha_import, 164 184 .init_tfm = zynqmp_sha_init_tfm, 165 185 .exit_tfm = zynqmp_sha_exit_tfm, 166 - .descsize = sizeof(struct zynqmp_sha_desc_ctx) + 167 - sizeof(struct sha3_state), 168 - .statesize = sizeof(struct sha3_state), 186 + .descsize = sizeof(struct sha3_state), 169 187 .digestsize = SHA3_384_DIGEST_SIZE, 170 188 .base = { 171 189 .cra_name = "sha3-384", 172 190 .cra_driver_name = "zynqmp-sha3-384", 173 191 .cra_priority = 300, 174 192 .cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY | 175 - CRYPTO_ALG_ALLOCATES_MEMORY | 176 - CRYPTO_ALG_NEED_FALLBACK, 193 + CRYPTO_ALG_NEED_FALLBACK | 194 + CRYPTO_AHASH_ALG_BLOCK_ONLY | 195 + CRYPTO_AHASH_ALG_FINUP_MAX, 177 196 .cra_blocksize = SHA3_384_BLOCK_SIZE, 178 197 .cra_ctxsize = sizeof(struct zynqmp_sha_tfm_ctx), 179 198 .cra_module = THIS_MODULE,
-5
include/crypto/sha3.h
··· 25 25 26 26 struct sha3_state { 27 27 u64 st[SHA3_STATE_SIZE / 8]; 28 - unsigned int rsiz; 29 - unsigned int rsizw; 30 - 31 - unsigned int partial; 32 - u8 buf[SHA3_224_BLOCK_SIZE]; 33 28 }; 34 29 35 30 int crypto_sha3_init(struct shash_desc *desc);