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

crypto: padlock-sha - Use core import and export for fallback

As padlock-sha is block-only, it needs to use core import and
export on the fallback.

Also call sha256_block_init instead of sha256_init although this
is harmless as sha256_init doesn't write into the partial block
area.

Fixes: 63dc06cd12f9 ("crypto: padlock-sha - Use API partial block handling")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Herbert Xu 870c1f0d 88bca957

+20 -14
+20 -14
drivers/crypto/padlock-sha.c
··· 42 42 43 43 static int padlock_sha256_init(struct shash_desc *desc) 44 44 { 45 - struct sha256_state *sctx = padlock_shash_desc_ctx(desc); 45 + struct crypto_sha256_state *sctx = padlock_shash_desc_ctx(desc); 46 46 47 - sha256_init(sctx); 47 + sha256_block_init(sctx); 48 48 return 0; 49 49 } 50 50 51 51 static int padlock_sha_update(struct shash_desc *desc, 52 52 const u8 *data, unsigned int length) 53 53 { 54 - struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm); 55 54 u8 *state = padlock_shash_desc_ctx(desc); 56 - HASH_REQUEST_ON_STACK(req, ctx->fallback); 57 - int remain; 55 + struct crypto_shash *tfm = desc->tfm; 56 + int err, remain; 58 57 59 - ahash_request_set_callback(req, 0, NULL, NULL); 60 - ahash_request_set_virt(req, data, NULL, length); 61 - remain = crypto_ahash_import(req, state) ?: 62 - crypto_ahash_update(req); 63 - if (remain < 0) 64 - return remain; 65 - return crypto_ahash_export(req, state) ?: remain; 58 + remain = length - round_down(length, crypto_shash_blocksize(tfm)); 59 + { 60 + struct padlock_sha_ctx *ctx = crypto_shash_ctx(tfm); 61 + HASH_REQUEST_ON_STACK(req, ctx->fallback); 62 + 63 + ahash_request_set_callback(req, 0, NULL, NULL); 64 + ahash_request_set_virt(req, data, NULL, length - remain); 65 + err = crypto_ahash_import_core(req, state) ?: 66 + crypto_ahash_update(req) ?: 67 + crypto_ahash_export_core(req, state); 68 + HASH_REQUEST_ZERO(req); 69 + } 70 + 71 + return err ?: remain; 66 72 } 67 73 68 74 static int padlock_sha_export(struct shash_desc *desc, void *out) ··· 107 101 108 102 ahash_request_set_callback(req, 0, NULL, NULL); 109 103 ahash_request_set_virt(req, in, out, count); 110 - return crypto_ahash_import(req, padlock_shash_desc_ctx(desc)) ?: 104 + return crypto_ahash_import_core(req, padlock_shash_desc_ctx(desc)) ?: 111 105 crypto_ahash_finup(req); 112 106 } 113 107 ··· 171 165 return PTR_ERR(fallback_tfm); 172 166 } 173 167 174 - if (crypto_shash_statesize(hash) < 168 + if (crypto_shash_statesize(hash) != 175 169 crypto_ahash_statesize(fallback_tfm)) { 176 170 crypto_free_ahash(fallback_tfm); 177 171 return -EINVAL;