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

crypto: picoxcell - Use skcipher for fallback

This patch replaces use of the obsolete ablkcipher with skcipher.

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

+31 -29
+31 -29
drivers/crypto/picoxcell_crypto.c
··· 171 171 * The fallback cipher. If the operation can't be done in hardware, 172 172 * fallback to a software version. 173 173 */ 174 - struct crypto_ablkcipher *sw_cipher; 174 + struct crypto_skcipher *sw_cipher; 175 175 }; 176 176 177 177 /* AEAD cipher context. */ ··· 789 789 * request for any other size (192 bits) then we need to do a software 790 790 * fallback. 791 791 */ 792 - if (len != AES_KEYSIZE_128 && len != AES_KEYSIZE_256 && 793 - ctx->sw_cipher) { 792 + if (len != AES_KEYSIZE_128 && len != AES_KEYSIZE_256) { 793 + if (!ctx->sw_cipher) 794 + return -EINVAL; 795 + 794 796 /* 795 797 * Set the fallback transform to use the same request flags as 796 798 * the hardware transform. 797 799 */ 798 - ctx->sw_cipher->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; 799 - ctx->sw_cipher->base.crt_flags |= 800 - cipher->base.crt_flags & CRYPTO_TFM_REQ_MASK; 800 + crypto_skcipher_clear_flags(ctx->sw_cipher, 801 + CRYPTO_TFM_REQ_MASK); 802 + crypto_skcipher_set_flags(ctx->sw_cipher, 803 + cipher->base.crt_flags & 804 + CRYPTO_TFM_REQ_MASK); 801 805 802 - err = crypto_ablkcipher_setkey(ctx->sw_cipher, key, len); 806 + err = crypto_skcipher_setkey(ctx->sw_cipher, key, len); 807 + 808 + tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; 809 + tfm->crt_flags |= 810 + crypto_skcipher_get_flags(ctx->sw_cipher) & 811 + CRYPTO_TFM_RES_MASK; 812 + 803 813 if (err) 804 814 goto sw_setkey_failed; 805 - } else if (len != AES_KEYSIZE_128 && len != AES_KEYSIZE_256 && 806 - !ctx->sw_cipher) 807 - err = -EINVAL; 815 + } 808 816 809 817 memcpy(ctx->key, key, len); 810 818 ctx->key_len = len; 811 819 812 820 sw_setkey_failed: 813 - if (err && ctx->sw_cipher) { 814 - tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; 815 - tfm->crt_flags |= 816 - ctx->sw_cipher->base.crt_flags & CRYPTO_TFM_RES_MASK; 817 - } 818 - 819 821 return err; 820 822 } 821 823 ··· 912 910 struct crypto_tfm *old_tfm = 913 911 crypto_ablkcipher_tfm(crypto_ablkcipher_reqtfm(req)); 914 912 struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(old_tfm); 913 + SKCIPHER_REQUEST_ON_STACK(subreq, ctx->sw_cipher); 915 914 int err; 916 - 917 - if (!ctx->sw_cipher) 918 - return -EINVAL; 919 915 920 916 /* 921 917 * Change the request to use the software fallback transform, and once 922 918 * the ciphering has completed, put the old transform back into the 923 919 * request. 924 920 */ 925 - ablkcipher_request_set_tfm(req, ctx->sw_cipher); 926 - err = is_encrypt ? crypto_ablkcipher_encrypt(req) : 927 - crypto_ablkcipher_decrypt(req); 928 - ablkcipher_request_set_tfm(req, __crypto_ablkcipher_cast(old_tfm)); 921 + skcipher_request_set_tfm(subreq, ctx->sw_cipher); 922 + skcipher_request_set_callback(subreq, req->base.flags, NULL, NULL); 923 + skcipher_request_set_crypt(subreq, req->src, req->dst, 924 + req->nbytes, req->info); 925 + err = is_encrypt ? crypto_skcipher_encrypt(subreq) : 926 + crypto_skcipher_decrypt(subreq); 927 + skcipher_request_zero(subreq); 929 928 930 929 return err; 931 930 } ··· 1018 1015 ctx->generic.flags = spacc_alg->type; 1019 1016 ctx->generic.engine = engine; 1020 1017 if (alg->cra_flags & CRYPTO_ALG_NEED_FALLBACK) { 1021 - ctx->sw_cipher = crypto_alloc_ablkcipher(alg->cra_name, 0, 1022 - CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK); 1018 + ctx->sw_cipher = crypto_alloc_skcipher( 1019 + alg->cra_name, 0, CRYPTO_ALG_ASYNC | 1020 + CRYPTO_ALG_NEED_FALLBACK); 1023 1021 if (IS_ERR(ctx->sw_cipher)) { 1024 1022 dev_warn(engine->dev, "failed to allocate fallback for %s\n", 1025 1023 alg->cra_name); 1026 - ctx->sw_cipher = NULL; 1024 + return PTR_ERR(ctx->sw_cipher); 1027 1025 } 1028 1026 } 1029 1027 ctx->generic.key_offs = spacc_alg->key_offs; ··· 1039 1035 { 1040 1036 struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm); 1041 1037 1042 - if (ctx->sw_cipher) 1043 - crypto_free_ablkcipher(ctx->sw_cipher); 1044 - ctx->sw_cipher = NULL; 1038 + crypto_free_skcipher(ctx->sw_cipher); 1045 1039 } 1046 1040 1047 1041 static int spacc_ablk_encrypt(struct ablkcipher_request *req)