From patchwork Mon Sep 21 07:31:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ED67C43463 for ; Mon, 21 Sep 2020 07:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FEAA2085B for ; Mon, 21 Sep 2020 07:32:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="MGjmJXrN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726556AbgIUHcb (ORCPT ); Mon, 21 Sep 2020 03:32:31 -0400 Received: from mail-eopbgr60075.outbound.protection.outlook.com ([40.107.6.75]:47332 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726513AbgIUHc3 (ORCPT ); Mon, 21 Sep 2020 03:32:29 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jo3Yev+wo5CH05G3qPIPgy/ABGQR1BT2xS7lai5ihD8hmPkhUO3SH4XO9LotChJG370jm75fxz6+BQRFMfR6VLwXzVhlDZRi9b8N7DHZVMq+CCUa1HtxzgAKdEturAS9jVPTlBzARobxZbNuDiVKhPr7EsnFEj20QlBuACMSYP0OjVp2CgeTzVs+KXGTIoiDHaHJbKg1xOADiN0U7ZeCPaq8Y4dJDLe3xySgj8m7z4MOv3XqAg+5WTi6tio7yZjdsD5HUIPrZFr3KzZbpTIVbB8CAjHguyWaEEIuI2efTCfqchkzkvJ1UpEYJbazvBgzVX4heEFEQxyMWrL53ytM+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wV5Jeqec6a6GKJwdyGstsaj3hp1Fvs3Dx6RmSZmBRQE=; b=GvbUURqI29CLXHmzSVWT/kHOScRKB8usW2MOGQIg7MYEu/TqUeCz2VK2u1tQ8BqgazWOtMPYx+AS5khlLJssXCeRpnw2+sJjegMinMS396yKKDrhiwvjwFgaKAKCQWMw7DhzllkBI22TnRqruw7bUZEGBQR1difM54B2KZ+oK8/GZlIwPFp3BuyPnf/ftNqlakl/hOA2rbCAJ1/+C+8tMOVT06AvIjws1qCDRzb5zcRb4w9jSrNSmcvOxsgKrnA2qd9KUij0MYoGXormFJf0JCwzoDHZAtqrjIwWwyrFhKQ3W35XOXKHbc2WXovfLGaxDNgRWzBfzCwNtF8nJOxMjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wV5Jeqec6a6GKJwdyGstsaj3hp1Fvs3Dx6RmSZmBRQE=; b=MGjmJXrNSpdpxU4MY2ldw/V+LrrhxZcq7AYAJUXd4+GgvB+3WToKD+swSRGbq33gPr1A6G+UQ6RW/GfFaj3IA+WYEOWQbpL5rRpozN5/k08Gjqa7AS88tJKlLq+eTEuUMe8WUlNLX+1G9nwRjF5LX52dDtdoaKmgndV1qSr2A1w= Authentication-Results: nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) by VI1PR0402MB3903.eurprd04.prod.outlook.com (2603:10a6:803:21::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Mon, 21 Sep 2020 07:32:23 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c%7]) with mapi id 15.20.3391.011; Mon, 21 Sep 2020 07:32:23 +0000 From: Andrei Botila To: Horia Geanta , Aymen Sghaier , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/12] crypto: caam/qi - add fallback for XTS with more than 8B IV Date: Mon, 21 Sep 2020 10:31:55 +0300 Message-Id: <20200921073205.24742-3-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200921073205.24742-1-andrei.botila@oss.nxp.com> References: <20200921073205.24742-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) To VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15007.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Mon, 21 Sep 2020 07:32:23 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8651a0bb-7862-4102-1b88-08d85e007b64 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3903: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4kg+Ve7goSFuucjxG7RoqTRH0b6bmY4Dkp/Q09oNn9LC58/9o8RUhs8zWuVHnc6JP0jdZtIe2CdSaE+PXmZoe0cY6PBaTDGFvJoh/s0m99iaLi9cJtlXnek/z/wagFZvRV1lumriK9rUJLMAUp5sXBHZ19lZRL6gpmhS2Da0q25Z8ZyAbYDX3xtBFJ02F5Z7PTi+kIl89PaR5c9tH9Tbxg//Zu5tEdkwJet9yU3MAZo/NYCdy7OKXIC5/pY9PJM5qI0BGUL4WSfjclgpeEtFH0F53UHHXvx8oG00pMohyoX1PGOV/x7NXMM9t1/GEGS0xhq/yS7xj8a3KzGezQ9i2tf/jaAyJR6cplAsxq3+71yrYR+8YF9MV1XY/XdyXEuQXw80EUslymDJdnh+cNGT1Dgf4xGMP+zr6QUAY+fnUJc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6608.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39860400002)(136003)(346002)(396003)(66476007)(66556008)(2906002)(4326008)(44832011)(956004)(2616005)(6512007)(1076003)(8936002)(8676002)(6666004)(52116002)(66946007)(478600001)(316002)(5660300002)(6506007)(6486002)(83380400001)(186003)(16526019)(26005)(86362001)(110136005)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: h5a1t9ImLdGqMRXM6sASYscNJ2VshEFrLyGkC6SeF8x7T5qTDes9uwB4oHOkmbnoraCAXdIdEDaseplj6oPJGo5QZREqJAkcaCO2sJuhbS31uU+XYV+jAxenhOhG0Bxikj1XlrFMTli350p3U9TgThNvUXQz1MtRM26KMBf4JpUMTQ5ba/C2OFfIwqzXu0ADWth3/06NeceHuWJZ13351+aPetEQeFQBWWC9jy9o88egQfeeLHU3CtGPrDB7Ktjbv8Q020jEjSq3353h0rauDGai3EnFKa0zIVLbSXNW8VkpTB26CEcG4UlwFM4uiw+NnXVqSL5IWWTPkZUArlSnRw+fH6WuWJ3lUDjcsRLM+e1sbS64Zl0cqaJJ2EXeXseia67niscsdZa9guIIKB+Sd1/N9YAU8+uLQGUjtwJ8RcYI3DfhItl+DjHaJs47XQt7ngjTV+hG6Y7nyo0EtGKJ20ksRirdp/91VjcumKtrt8nqRAWvqhMONqnVdm+C5tUVl7PAe+lhbhml2myrOWeO2F203uhPEzQ3eKiOPjV0fcDthwC2CjwKL4qON6FeL6KdXSQzhWRbRD6RFqwQXpzqbpajgqoA9jPGtU/5MMvezRzrlPPQPPtq034D6JdjWJ23QSZhazko/uD0QEF4jm0E+Q== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8651a0bb-7862-4102-1b88-08d85e007b64 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 07:32:23.8313 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FZKjS5pdgiOaRlxG1mlJVvF8BC/Ly2MnV//fhsSkSvHCyNxH2oSsLfVJeS8gOHnteQXe+cm8eE1ClF3CgUSlzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3903 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Andrei Botila A hardware limitation exists for CAAM until Era 9 which restricts the accelerator to IVs with only 8 bytes. When CAAM has a lower era a fallback is necessary to process 16 bytes IV. Fixes: b189817cf789 ("crypto: caam/qi - add ablkcipher and authenc algorithms") Cc: # v4.12+ Signed-off-by: Andrei Botila --- drivers/crypto/caam/Kconfig | 1 + drivers/crypto/caam/caamalg_qi.c | 70 +++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig index dfeaad8dfe81..8169e6cd04e6 100644 --- a/drivers/crypto/caam/Kconfig +++ b/drivers/crypto/caam/Kconfig @@ -115,6 +115,7 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI select CRYPTO_AUTHENC select CRYPTO_SKCIPHER select CRYPTO_DES + select CRYPTO_XTS help Selecting this will use CAAM Queue Interface (QI) for sending & receiving crypto jobs to/from CAAM. This gives better performance diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index bb1c0106a95c..2b5e694fdaf6 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -18,6 +18,7 @@ #include "qi.h" #include "jr.h" #include "caamalg_desc.h" +#include /* * crypto alg @@ -67,6 +68,11 @@ struct caam_ctx { struct device *qidev; spinlock_t lock; /* Protects multiple init of driver context */ struct caam_drv_ctx *drv_ctx[NUM_OP]; + struct crypto_skcipher *fallback; +}; + +struct caam_skcipher_req_ctx { + struct skcipher_request fallback_req; }; static int aead_set_sh_desc(struct crypto_aead *aead) @@ -726,12 +732,17 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); struct device *jrdev = ctx->jrdev; int ret = 0; + int err; if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { dev_dbg(jrdev, "key size mismatch\n"); return -EINVAL; } + err = crypto_skcipher_setkey(ctx->fallback, key, keylen); + if (err) + return err; + ctx->cdata.keylen = keylen; ctx->cdata.key_virt = key; ctx->cdata.key_inline = true; @@ -1373,6 +1384,17 @@ static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req, return edesc; } +static bool xts_skcipher_ivsize(struct skcipher_request *req) +{ + struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); + unsigned int ivsize = crypto_skcipher_ivsize(skcipher); + u64 size = 0; + + size = get_unaligned((u64 *)(req->iv + (ivsize / 2))); + + return !!size; +} + static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) { struct skcipher_edesc *edesc; @@ -1383,6 +1405,21 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) if (!req->cryptlen) return 0; + if (ctx->fallback && xts_skcipher_ivsize(req)) { + struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req); + + skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); + skcipher_request_set_callback(&rctx->fallback_req, + req->base.flags, + req->base.complete, + req->base.data); + skcipher_request_set_crypt(&rctx->fallback_req, req->src, + req->dst, req->cryptlen, req->iv); + + return encrypt ? crypto_skcipher_encrypt(&rctx->fallback_req) : + crypto_skcipher_decrypt(&rctx->fallback_req); + } + if (unlikely(caam_congested)) return -EAGAIN; @@ -1507,6 +1544,7 @@ static struct caam_skcipher_alg driver_algs[] = { .base = { .cra_name = "xts(aes)", .cra_driver_name = "xts-aes-caam-qi", + .cra_flags = CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = AES_BLOCK_SIZE, }, .setkey = xts_skcipher_setkey, @@ -2440,9 +2478,27 @@ static int caam_cra_init(struct crypto_skcipher *tfm) struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct caam_skcipher_alg *caam_alg = container_of(alg, typeof(*caam_alg), skcipher); + struct caam_ctx *ctx = crypto_skcipher_ctx(tfm); + u32 alg_aai = caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; + + if (alg_aai == OP_ALG_AAI_XTS) { + const char *tfm_name = crypto_tfm_alg_name(&tfm->base); + struct crypto_skcipher *fallback; + + fallback = crypto_alloc_skcipher(tfm_name, 0, + CRYPTO_ALG_NEED_FALLBACK); + if (IS_ERR(fallback)) { + dev_err(ctx->jrdev, "Failed to allocate %s fallback: %ld\n", + tfm_name, PTR_ERR(fallback)); + return PTR_ERR(fallback); + } - return caam_init_common(crypto_skcipher_ctx(tfm), &caam_alg->caam, - false); + ctx->fallback = fallback; + crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_skcipher_req_ctx) + + crypto_skcipher_reqsize(fallback)); + } + + return caam_init_common(ctx, &caam_alg->caam, false); } static int caam_aead_init(struct crypto_aead *tfm) @@ -2468,7 +2524,11 @@ static void caam_exit_common(struct caam_ctx *ctx) static void caam_cra_exit(struct crypto_skcipher *tfm) { - caam_exit_common(crypto_skcipher_ctx(tfm)); + struct caam_ctx *ctx = crypto_skcipher_ctx(tfm); + + if (ctx->fallback) + crypto_free_skcipher(ctx->fallback); + caam_exit_common(ctx); } static void caam_aead_exit(struct crypto_aead *tfm) @@ -2502,8 +2562,8 @@ static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg) alg->base.cra_module = THIS_MODULE; alg->base.cra_priority = CAAM_CRA_PRIORITY; alg->base.cra_ctxsize = sizeof(struct caam_ctx); - alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_KERN_DRIVER_ONLY; + alg->base.cra_flags |= (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_KERN_DRIVER_ONLY); alg->init = caam_cra_init; alg->exit = caam_cra_exit; From patchwork Mon Sep 21 07:31:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05236C43465 for ; Mon, 21 Sep 2020 07:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2D482085B for ; Mon, 21 Sep 2020 07:32:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="aCW8XUcK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726576AbgIUHce (ORCPT ); Mon, 21 Sep 2020 03:32:34 -0400 Received: from mail-eopbgr60075.outbound.protection.outlook.com ([40.107.6.75]:47332 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726494AbgIUHcd (ORCPT ); Mon, 21 Sep 2020 03:32:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UhKEpO9EKMQ+PfnioEmRv/C0scPHjMDJN56I6JfmBRK1BsmNdrQ1kYM9KuN6vryFoDP9jIN/w6vMbKUECKGXO6XxK7IKB/Gntv0L+9DaAG31OcQDxCDAFGpOsQK4cEtlyeDveMo/L7qZbOffrHERRik4sxnfL9q41YKeNK20faVUP+cKdX6mw0kj8j/NRt5VDUyUPjcLAEhnQzL4RKixRabFPsJAQQ1K/RHcybBgoI0dpgE16w52YgM1Du+NoTKuWnPWD0O1aNbcKEIOgU+7ylcXZhBcKHRpr7qULX2lm7EdQjyhK4SD0qBNQYZbM0MoNk1/G+2dpkcEt87K33E6Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xg58v4+wP3PLcvJ8/XF+CqOjuRC5AfA1/K8dmPFBTNk=; b=QI3YVMo0p3+Vad3D6i3FHrHQ/xYlfywN2pttU9wjqiBpVs9QVbF8kZB4lky1mIeCfYXwlCxNryp51ndqKHiP/0qxHjmq0tCAX3j7DT/HprypQOraSOBF22WRUFQtki9RAJWcQzHnhXIqc01GJjQ+l9W3j3/frNOgsTML+nm/JcyOoFxZj99q6KB8rnymM8GHi4QdwTFWnquOWJTKnUkfbzPwjV4l/Etz7Qb+YYAoqbaXwxzeohvdELPFBODmegxG6kwD7NOa+FAXveDrlPvV/AoQ6LFh+C6ArHIG9vnMGE8gdJyq2vjZM1D1wxChCDGj5s7hHzl8bBk/LiMGwO1q1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xg58v4+wP3PLcvJ8/XF+CqOjuRC5AfA1/K8dmPFBTNk=; b=aCW8XUcKmbIgQNjo3wCS+VzX/oJdWa+OiKUC0PP3rLSgW8gU7EpciGFyKSniw7D6R0u7s7fjZKYHtNeCc1Jxy9BMGGtGWBbRVpZR7bA0YWPJ0xHv/xkPvrEhBxeAOEGfC+FFba4t8q1+x5nN4hplZDoPRpNoN8oST7NOdlRp65A= Authentication-Results: nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) by VI1PR0402MB3903.eurprd04.prod.outlook.com (2603:10a6:803:21::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Mon, 21 Sep 2020 07:32:24 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c%7]) with mapi id 15.20.3391.011; Mon, 21 Sep 2020 07:32:24 +0000 From: Andrei Botila To: Horia Geanta , Aymen Sghaier , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/12] crypto: caam/qi2 - add fallback for XTS with more than 8B IV Date: Mon, 21 Sep 2020 10:31:56 +0300 Message-Id: <20200921073205.24742-4-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200921073205.24742-1-andrei.botila@oss.nxp.com> References: <20200921073205.24742-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) To VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15007.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Mon, 21 Sep 2020 07:32:24 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 68356d17-1d13-4aeb-978f-08d85e007bf5 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3903: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nSpa+0Y2NpreLMYn9a1NvhbAIRtd9rus/Yi/wRVYvGqAZNWn02boNjXZ0SZHlkH93DoJl20/bOAXa8uqZZuEfei+SCqBepdcifnRZDlRil6Ifl48a6b5X+MkBJ+zhb5Ueq7YCThjVGqKpghnBPgVgzdtsVsifuPCWjR2x3ZN9dt1VR/X1XH46Vmvloqo7rz0iFOvCQbAevBGJkUTl0OxW07fUGP3+R5NmnlQ0xjeUpUjpNS0jKvSvTJ4NFWpwI7+/d8ueeavvEUo8MvfUtFFdg+NgNnUeZCXvbrdS1Gk3zBEqau8I+NzgO/gZZPlQnc78TBRhfr2AwVNN/2gkbh+R4x0b2ktSFya6Wcpkq51c4xpRehqrsZB/rPq2Kp8rRvSx3KNzdfdcRKrDxMQKGdgnj9AWk3s9t84zXTTJBHYvrc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6608.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39860400002)(136003)(346002)(396003)(66476007)(66556008)(2906002)(4326008)(44832011)(956004)(2616005)(6512007)(1076003)(8936002)(8676002)(6666004)(52116002)(66946007)(478600001)(316002)(5660300002)(6506007)(6486002)(83380400001)(186003)(16526019)(26005)(86362001)(110136005)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: fw1OYkczXw5F2AaqTcPTEYRaOCZCtpsLRRlTL6C8njOyLHuimwc2gFEYSx4VxAALCWZ3BfnTIKUiN955S9vAQcQec8npqN+pp3z1ubvXQzH9NWyVlLvYK9hrXPDaF2KTQgWWHJhSDEJ6XkU2Puxi2RBg9seJzEWR5Iv9zP+Te6inahxSYLIx5dtpsjLlNtKG/2NwwO14LMAZS1noQNFaek2pbZKrs4i437Fs4s5KDcXdy4n1USHilYVEemh7pKNnP+lT91IznZBdPf4NKKpaIKtzQU8b07rwmidHirar89+2ZlR7fzcOamOC57BSnTS0Y9YjgwvudDtC20srj5QWNPkHlbYNBt7AvCv268kMT5Xcq9iJdQyJgTNCN1cM3QqxGAHdT4uQL/qsV3AP+p8BYp0PH3Jfk6ZF8dXmGMvWhvOWrxS5T5srWC6uPo7Gy/9YOEzMYp9q7Pyelk6ku3hva3x7zaAgqhrakrIYDvTkoPcCo6QCpKaGfSvX0SfTs2Fa+GGnnW8c5m3CZoFk8u8scob2/t1M3t8diI0oa1vz6IRCwwg0os0xhjyPEcXkEA9ImSRqhag7qnSiwhr8W4RvgOogmpN9pvyXYcpSleErQ33UXOsREdpRHegfWDOlL79ElkNmBrIl4xxb5O/ZsQ3Osg== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68356d17-1d13-4aeb-978f-08d85e007bf5 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 07:32:24.7637 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gqwNJihkJ2xx5yc6Gb2VueZkWrBAB1Ke1C6/ApAndgumRdgBKWLffTYteSZC0WdSZ4baQZ/YxJEXQMdHJ41xLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3903 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Andrei Botila A hardware limitation exists for CAAM until Era 9 which restricts the accelerator to IVs with only 8 bytes. When CAAM has a lower era a fallback is necessary to process 16 bytes IV. Fixes: 226853ac3ebe ("crypto: caam/qi2 - add skcipher algorithms") Cc: # v4.20+ Signed-off-by: Andrei Botila --- drivers/crypto/caam/Kconfig | 1 + drivers/crypto/caam/caamalg_qi2.c | 78 +++++++++++++++++++++++++++++-- drivers/crypto/caam/caamalg_qi2.h | 2 + 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig index 8169e6cd04e6..84ea7cba5ee5 100644 --- a/drivers/crypto/caam/Kconfig +++ b/drivers/crypto/caam/Kconfig @@ -167,6 +167,7 @@ config CRYPTO_DEV_FSL_DPAA2_CAAM select CRYPTO_AEAD select CRYPTO_HASH select CRYPTO_DES + select CRYPTO_XTS help CAAM driver for QorIQ Data Path Acceleration Architecture 2. It handles DPSECI DPAA2 objects that sit on the Management Complex diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index 66ae1d581168..2e37e6e63c8c 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -19,6 +19,7 @@ #include #include #include +#include #define CAAM_CRA_PRIORITY 2000 @@ -80,6 +81,7 @@ struct caam_ctx { struct alginfo adata; struct alginfo cdata; unsigned int authsize; + struct crypto_skcipher *fallback; }; static void *dpaa2_caam_iova_to_virt(struct dpaa2_caam_priv *priv, @@ -1056,12 +1058,17 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, struct device *dev = ctx->dev; struct caam_flc *flc; u32 *desc; + int err; if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { dev_dbg(dev, "key size mismatch\n"); return -EINVAL; } + err = crypto_skcipher_setkey(ctx->fallback, key, keylen); + if (err) + return err; + ctx->cdata.keylen = keylen; ctx->cdata.key_virt = key; ctx->cdata.key_inline = true; @@ -1443,6 +1450,17 @@ static void skcipher_decrypt_done(void *cbk_ctx, u32 status) skcipher_request_complete(req, ecode); } +static bool xts_skcipher_ivsize(struct skcipher_request *req) +{ + struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); + unsigned int ivsize = crypto_skcipher_ivsize(skcipher); + u64 size = 0; + + size = get_unaligned((u64 *)(req->iv + (ivsize / 2))); + + return !!size; +} + static int skcipher_encrypt(struct skcipher_request *req) { struct skcipher_edesc *edesc; @@ -1454,6 +1472,18 @@ static int skcipher_encrypt(struct skcipher_request *req) if (!req->cryptlen) return 0; + if (ctx->fallback && xts_skcipher_ivsize(req)) { + skcipher_request_set_tfm(&caam_req->fallback_req, ctx->fallback); + skcipher_request_set_callback(&caam_req->fallback_req, + req->base.flags, + req->base.complete, + req->base.data); + skcipher_request_set_crypt(&caam_req->fallback_req, req->src, + req->dst, req->cryptlen, req->iv); + + return crypto_skcipher_encrypt(&caam_req->fallback_req); + } + /* allocate extended descriptor */ edesc = skcipher_edesc_alloc(req); if (IS_ERR(edesc)) @@ -1484,6 +1514,19 @@ static int skcipher_decrypt(struct skcipher_request *req) if (!req->cryptlen) return 0; + + if (ctx->fallback && xts_skcipher_ivsize(req)) { + skcipher_request_set_tfm(&caam_req->fallback_req, ctx->fallback); + skcipher_request_set_callback(&caam_req->fallback_req, + req->base.flags, + req->base.complete, + req->base.data); + skcipher_request_set_crypt(&caam_req->fallback_req, req->src, + req->dst, req->cryptlen, req->iv); + + return crypto_skcipher_decrypt(&caam_req->fallback_req); + } + /* allocate extended descriptor */ edesc = skcipher_edesc_alloc(req); if (IS_ERR(edesc)) @@ -1537,9 +1580,29 @@ static int caam_cra_init_skcipher(struct crypto_skcipher *tfm) struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct caam_skcipher_alg *caam_alg = container_of(alg, typeof(*caam_alg), skcipher); + struct caam_ctx *ctx = crypto_skcipher_ctx(tfm); + u32 alg_aai = caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; + + if (alg_aai == OP_ALG_AAI_XTS) { + const char *tfm_name = crypto_tfm_alg_name(&tfm->base); + struct crypto_skcipher *fallback; + + fallback = crypto_alloc_skcipher(tfm_name, 0, + CRYPTO_ALG_NEED_FALLBACK); + if (IS_ERR(fallback)) { + dev_err(ctx->dev, "Failed to allocate %s fallback: %ld\n", + tfm_name, PTR_ERR(fallback)); + return PTR_ERR(fallback); + } - crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_request)); - return caam_cra_init(crypto_skcipher_ctx(tfm), &caam_alg->caam, false); + ctx->fallback = fallback; + crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_request) + + crypto_skcipher_reqsize(fallback)); + } else { + crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_request)); + } + + return caam_cra_init(ctx, &caam_alg->caam, false); } static int caam_cra_init_aead(struct crypto_aead *tfm) @@ -1562,7 +1625,11 @@ static void caam_exit_common(struct caam_ctx *ctx) static void caam_cra_exit(struct crypto_skcipher *tfm) { - caam_exit_common(crypto_skcipher_ctx(tfm)); + struct caam_ctx *ctx = crypto_skcipher_ctx(tfm); + + if (ctx->fallback) + crypto_free_skcipher(ctx->fallback); + caam_exit_common(ctx); } static void caam_cra_exit_aead(struct crypto_aead *tfm) @@ -1665,6 +1732,7 @@ static struct caam_skcipher_alg driver_algs[] = { .base = { .cra_name = "xts(aes)", .cra_driver_name = "xts-aes-caam-qi2", + .cra_flags = CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = AES_BLOCK_SIZE, }, .setkey = xts_skcipher_setkey, @@ -2912,8 +2980,8 @@ static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg) alg->base.cra_module = THIS_MODULE; alg->base.cra_priority = CAAM_CRA_PRIORITY; alg->base.cra_ctxsize = sizeof(struct caam_ctx); - alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_KERN_DRIVER_ONLY; + alg->base.cra_flags |= (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_KERN_DRIVER_ONLY); alg->init = caam_cra_init_skcipher; alg->exit = caam_cra_exit; diff --git a/drivers/crypto/caam/caamalg_qi2.h b/drivers/crypto/caam/caamalg_qi2.h index f29cb7bd7dd3..d35253407ade 100644 --- a/drivers/crypto/caam/caamalg_qi2.h +++ b/drivers/crypto/caam/caamalg_qi2.h @@ -13,6 +13,7 @@ #include #include "dpseci.h" #include "desc_constr.h" +#include #define DPAA2_CAAM_STORE_SIZE 16 /* NAPI weight *must* be a multiple of the store size. */ @@ -186,6 +187,7 @@ struct caam_request { void (*cbk)(void *ctx, u32 err); void *ctx; void *edesc; + struct skcipher_request fallback_req; }; /** From patchwork Mon Sep 21 07:31:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75763C43465 for ; Mon, 21 Sep 2020 07:32:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23FF8214F1 for ; Mon, 21 Sep 2020 07:32:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="ZJx00N57" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726593AbgIUHcl (ORCPT ); Mon, 21 Sep 2020 03:32:41 -0400 Received: from mail-eopbgr60075.outbound.protection.outlook.com ([40.107.6.75]:47332 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726513AbgIUHcg (ORCPT ); Mon, 21 Sep 2020 03:32:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kq+EOUysVdsOh9axZvrikGyAeIPcWJfN4+CY9tir6xGqQTKtfrm7I05JlWhxN8YZpqxHNqraLjYvrRZEjK37mMSwihTICmhaADR11ZoaYgDIg9z8G8JmpGuX6k/auBoppCyHQAV+h3LAhCTURap21W3yzz63Im5gRZeWb5aPq2Dzx8XZ5R1+1Owa0S3YBYBrnIHt4wVEo1ukZ6e7S8bJypO8FFyrNna+9AWPn65VTfUXwiMbwLmrmI9lVE8xJorhcgY0IS9rufzpz3ppJP6uZB26UPqVexVCtDxYOBsWa70W/h5ccpMlU/PhxARcsg6AZuFlCu0nfb/PcYWwU5Z4tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zl61BGFfdJndxx6p7qMFE/zAW9VmRM43BnNTjbArpz8=; b=gZ1fZ8io/ghsT4BjRxEKUMgGe0kYxrdvkN1PHYQoE1U6hMwnjVd0pms/iHxkUU3X30mW7QWi8DhrVMbRafz7z5r/fvNFI49Jt0wU27tHprSGDeqoXe3+AQSeglLJObEwhL06qlG3E2IespnJUqND+6tK6r2R3whkTjBN2tQUtR7+MjBWl/rP+XZ2ogNpRI9TJrkHfd+/xgN/h2kQgD00aHP/Wx6UWCF8JnaBZNrMFVn8bfN+Nw6U2oNcPp8nLoRJbRLmzx/aO3bItRWO6yXCHKOQnxfb6qGZMJ72UvkGiX4YnCM+01gmoNdWb7YGHHw8LlndK4CnkVuNCwgQrCCL7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zl61BGFfdJndxx6p7qMFE/zAW9VmRM43BnNTjbArpz8=; b=ZJx00N57jvHNcz3m7ZAh8rKiEp7fDtKJusobWas0iz2EhJEeTFbQTw/0Nx3z2+XiIneWm8bLNBtKmV16cKlnJPgrLRJJCi6j4gdu43xwjpUednGjuVKhT6QA9TBcnEkQA01bW2MctpscL3Dk5hD3fSyDIt20N/U2tiyNCviyKiI= Authentication-Results: nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) by VI1PR0402MB3903.eurprd04.prod.outlook.com (2603:10a6:803:21::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Mon, 21 Sep 2020 07:32:27 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c%7]) with mapi id 15.20.3391.011; Mon, 21 Sep 2020 07:32:27 +0000 From: Andrei Botila To: Horia Geanta , Aymen Sghaier , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/12] crypto: caam/qi - add support for more XTS key lengths Date: Mon, 21 Sep 2020 10:31:58 +0300 Message-Id: <20200921073205.24742-6-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200921073205.24742-1-andrei.botila@oss.nxp.com> References: <20200921073205.24742-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) To VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15007.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Mon, 21 Sep 2020 07:32:25 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7f7af105-e40a-4b80-cc73-08d85e007d17 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3903: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2043; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jY1cRdg22M336s3rNZXvQBaeIskp6NIan0Qr6c+P2T2Dfs300j8ttFfdwBPIJv/U50ocJu2V04Qfm41/LIRMszUHNzFEwb75Uz1mdLwcOwLXf7WeziSkkVdE/AioJBFkdF4oEvU2N0fLgYETTLjGTCSVUzsQIdhfTocuG59mzAy2R4bSd7R/Ot1FyH964iHXap5B13BNW4Za0tbuiFzduQY9lbuF4Ss246IRXlOwWIVGvEgwWgy15IhETJT6A0WgcqqChwSSg5RLFnGNIqRhbWYx1IyJCF7TOYgjkTqqg9GwoOfJyfQAcpMKbs3VGB7Obab7J/aTgPII8EvvuEWEYFI7Kp3fyGvm6xCJjwhST+I4uqRl1riJdRFykevM0WcP X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6608.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39860400002)(136003)(346002)(396003)(66476007)(66556008)(2906002)(4326008)(44832011)(956004)(2616005)(6512007)(1076003)(8936002)(8676002)(6666004)(52116002)(66946007)(478600001)(316002)(5660300002)(6506007)(6486002)(83380400001)(186003)(16526019)(26005)(86362001)(110136005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Y2UyT+baaWEpBAQzwx3xVTpeAcLN6sP+avm8LYVDF+a/uAuoSShUX8X115zHdqiqgiaqTnn54Cn6pO1FKqPuzZZe2BbZa+aF54A0FDTPz2OFMroeFG44bqrdKtkoMCgDOZk/My6MA0tQU2EvrmPAqApqa687fjCw1fl58AFTWe2KG1w0MDM9ENFqau+rcBhY2fe21dhx8+x0Dxyil0JPqf5ky9RgyrB2xSPeTy/2+Au8CjIljBP3TaXB2CP+5BjjVR2M94Z5RXZFX8VeKU1XZVlL7d2Vz9usygi7wSfKSWL5sajwN/aUc80w1s6nmFg6PxlP7JmagzCuZxYOxcxwqu0Hif6PShgqDgSYFM2os/jnjsmUAh7pJlQKSM5Kkem5aVBoM44C1LCBJFHm55dGbSm4Hb2bN9s2XzeipHS0kLbA1Y9RWgmqJKzTUrf6npOVqAvF3cdhRu1D4quU8BHnMpmWga1Gcd1MIg2ZMKpY7u+ozaJurFPpMbde9U8JRLjT/y0CY2wWCLDzEIY6pZniCEzdt0zY99mZ2RRMYpePye64+tywZlcsi4+WmFxurmvylaGl3zB/xotF5DXuch7e2tayms10h2b0kBn30OJ6XkmhOcBozEBV/4IXKGZmwbuKd//siSuhssrhqGMQKUm43g== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f7af105-e40a-4b80-cc73-08d85e007d17 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 07:32:27.0204 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pGieC2d8oij33QOYDyBABf3PMdsEn5imCPs65chp7IwfbnIXqf55nh15XNPihmnTeMXTObre4BUOpaehp9/vFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3903 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Andrei Botila CAAM accelerator only supports XTS-AES-128 and XTS-AES-256 since it adheres strictly to the standard. All the other key lengths are accepted and processed through a fallback as long as they pass the xts_verify_key() checks. Fixes: b189817cf789 ("crypto: caam/qi - add ablkcipher and authenc algorithms") Cc: # v4.12+ Signed-off-by: Andrei Botila --- drivers/crypto/caam/caamalg_qi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index 2b5e694fdaf6..ac89d1dc361f 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -18,6 +18,7 @@ #include "qi.h" #include "jr.h" #include "caamalg_desc.h" +#include #include /* @@ -68,6 +69,7 @@ struct caam_ctx { struct device *qidev; spinlock_t lock; /* Protects multiple init of driver context */ struct caam_drv_ctx *drv_ctx[NUM_OP]; + bool xts_key_fallback; struct crypto_skcipher *fallback; }; @@ -734,11 +736,15 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, int ret = 0; int err; - if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { + err = xts_verify_key(skcipher, key, keylen); + if (err) { dev_dbg(jrdev, "key size mismatch\n"); - return -EINVAL; + return err; } + if (keylen != 2 * AES_KEYSIZE_128 && keylen != 2 * AES_KEYSIZE_256) + ctx->xts_key_fallback = true; + err = crypto_skcipher_setkey(ctx->fallback, key, keylen); if (err) return err; @@ -1405,7 +1411,8 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) if (!req->cryptlen) return 0; - if (ctx->fallback && xts_skcipher_ivsize(req)) { + if (ctx->fallback && (xts_skcipher_ivsize(req) || + ctx->xts_key_fallback)) { struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req); skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); From patchwork Mon Sep 21 07:31:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C0A5C43464 for ; Mon, 21 Sep 2020 07:32:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3454620709 for ; Mon, 21 Sep 2020 07:32:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="ZL8QI6vB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726607AbgIUHcr (ORCPT ); Mon, 21 Sep 2020 03:32:47 -0400 Received: from mail-eopbgr20064.outbound.protection.outlook.com ([40.107.2.64]:32604 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726494AbgIUHcl (ORCPT ); Mon, 21 Sep 2020 03:32:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JPLQo6EEzLwBxoCMcVDMKaX2EZ7S6HrZLHNuNoNtpyj9e7l2ASm/7K6hiJD8F1BLbASoUleHks6BRK+cRfHS0t2JW50mmgsyyaZ7xYFvZJr6G08hdOk1OJoHUQI/KzzuCQESf8iXY9HASHu3ZO6exCYUHPBQF0GmdyIgmdDwyXYXnfJ81GFzcGY2gsUn07uocAKOfjQ3XulQ2hEdwav/kIl6d9ASB07p9VF9nJ541DYFhc+5nTHmwhAQdFuq8msnefcHlg0DQnJcL/XqGUEAVXjtqsa2vKJkm3knQzgu9JGyJcGsZpUgJGZryBCaVDhTvnXPfcysQ1u+VqOWBy9O4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eOCaSLPSl1cbuw2fC3MU/bwkJ1zDeTkbIYnCB4Dr3cY=; b=NStwnTrlyvhBT/5qd0A/vsypozRh/OeOqvS4TLZfqKS2dLMtlcO323kJ6FBzacrNSo3/31iYaeKpn7IuMmVInfzFM8F07bTx8YGtUPykIE7PR40utZ7we3MbbcuILtOl0E3/Jk7Y7Zh+SqLfI8eL75jW4yzvsr9YUb3IAsr2NOHpwN41+DNmmbYinh9uebQHTlyN1OKA6W79fQJGRTyE7Y9IpzgSk5ZouNnPpxspt5TjkDPFZQjgM0MZo6ff1HZzL8s1md0VxGobHvAqZYLdn2nekBJYbhbjcOTK1CQaCDMJ5V+nfVmrpA6Bi/K8dKJ2DHgkQU8EAw/m9fCsWGkTug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eOCaSLPSl1cbuw2fC3MU/bwkJ1zDeTkbIYnCB4Dr3cY=; b=ZL8QI6vBFalJc80Uqlkz4H4NSKFOVYOfBaXUoNMn3jPkogFh8GWt57YAwc6/idoWn4xRaqBd98/tMYXYBCwrQGOaCsOni5oYqYoBN3c4MddyDcost82eohbWMhBs56z82ymbyN3ehJPfwUPYTbpUa3NVtQd2OqNzMyZOhmQG9xs= Authentication-Results: nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) by VI1PR0402MB3903.eurprd04.prod.outlook.com (2603:10a6:803:21::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Mon, 21 Sep 2020 07:32:28 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c%7]) with mapi id 15.20.3391.011; Mon, 21 Sep 2020 07:32:28 +0000 From: Andrei Botila To: Horia Geanta , Aymen Sghaier , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/12] crypto: caam/qi2 - add support for more XTS key lengths Date: Mon, 21 Sep 2020 10:31:59 +0300 Message-Id: <20200921073205.24742-7-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200921073205.24742-1-andrei.botila@oss.nxp.com> References: <20200921073205.24742-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) To VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15007.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Mon, 21 Sep 2020 07:32:27 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: afbc2dd2-05f0-47ad-0e20-08d85e007e00 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3903: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5uc1S0V0B9isZM3+2JklCGFGgAqKVr36z5yW+X9Ea0YeqCXNAwBTx0A4XfgT1l6KWdPknC7Q9fQ6oAwi8z5vJuQIeXU4NGVyrsCP5V06gPfxW+bGcOOwIU+4Adf+XW1wt5f1OeXgiFJYw8ylEtK68nZpvdwN2agJJtroqH3Ar7p53lrk6ljxGiuxQd56sgJWAO5LI+Z1j2sCprTdpv6/KPyn5VZWQG2QPP6vwlUNi+AtOQn+2gL/QSaonUQYNFG2ylP0c+Xv1T3jzt2DMASHqBY2levoe89DYYn5dYpDwUrIjaDx1azwf/i3JYEQAfjokY0qwzgQDw+n20fpAf3hIE3zt8XDha3FoAMwsi+COENa24nj1YC/7WTxex6WRDaT X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6608.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39860400002)(136003)(346002)(396003)(66476007)(66556008)(2906002)(4326008)(44832011)(956004)(2616005)(6512007)(1076003)(8936002)(8676002)(6666004)(52116002)(66946007)(478600001)(316002)(5660300002)(6506007)(6486002)(83380400001)(186003)(16526019)(26005)(86362001)(110136005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hrLCVz7pp+MNJvF6EzQF1Yh0+LmNafR/jS7EXOLHdZ8Ne86QmQFM6hJ0IP/ZYmU0s0iluMpMkXunBEKDk8Q2vfvYBNKAa/MojCgzIWpXe3qDXTgebDklzwavQpdGUF2vboReULAlkzH/yjdSc1YZdZUl/Wkg7aqoSga3shWG4Wf2ijUAxYB7jnEHq1yI1URRh61+vQHwtv7WJpcMy7q0m8FtB2BowV58+3cQpDWmGQ6DKp86xKT7ODNWRub4Vo9luD+a6T8tF5iG2E4E7DH5h4lt3RsLI5MoXQjoiEAhr3lMlVHCYbjlOdJUaP6ZhqZdhyRQGgL7F9n1dRdVXObhtlIMy86N3KNoq9TgBCO7VQ8ruy6I3ARlCkulw8hq0CHmDUFXUUNorkyfMI9Z7bniHDdTpV4eGmJauiUmDLMicOD4eUijPoaHNICXXRSFctLFO6d3L+UfZHG0GK1LT6F50lJMLfzEQe5ERLKBgiKaXndlkGMeYLxhrq8Ra6ftReuJzguxtOuP1/E86Vdj9O9sABipkTAUMyh3lclhVKaGVclhX+gKBqfGaQrmbrEQw3SkMf63RbPeqXr9jTeeqUojSTQjrDozQzFml1ElcS3LQXY0gebHRmSbnQauY+AosEYMOGh8NCkf6xC6E0tGj/3QaQ== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: afbc2dd2-05f0-47ad-0e20-08d85e007e00 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 07:32:28.3117 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 97rLDDCMUafaYVYdu4G2GFZC0EINBPCPkShHxF4l0/rLEZE6hL4lTZF1aZ9GnDHj2raVnmH4pvF1KKBqBLCHEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3903 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Andrei Botila CAAM accelerator only supports XTS-AES-128 and XTS-AES-256 since it adheres strictly to the standard. All the other key lengths are accepted and processed through a fallback as long as they pass the xts_verify_key() checks. Fixes: 226853ac3ebe ("crypto: caam/qi2 - add skcipher algorithms") Cc: # v4.20+ Signed-off-by: Andrei Botila --- drivers/crypto/caam/caamalg_qi2.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index 2e37e6e63c8c..5d2e554774c9 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #define CAAM_CRA_PRIORITY 2000 @@ -81,6 +82,7 @@ struct caam_ctx { struct alginfo adata; struct alginfo cdata; unsigned int authsize; + bool xts_key_fallback; struct crypto_skcipher *fallback; }; @@ -1060,11 +1062,15 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, u32 *desc; int err; - if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { + err = xts_verify_key(skcipher, key, keylen); + if (err) { dev_dbg(dev, "key size mismatch\n"); - return -EINVAL; + return err; } + if (keylen != 2 * AES_KEYSIZE_128 && keylen != 2 * AES_KEYSIZE_256) + ctx->xts_key_fallback = true; + err = crypto_skcipher_setkey(ctx->fallback, key, keylen); if (err) return err; @@ -1472,7 +1478,8 @@ static int skcipher_encrypt(struct skcipher_request *req) if (!req->cryptlen) return 0; - if (ctx->fallback && xts_skcipher_ivsize(req)) { + if (ctx->fallback && (xts_skcipher_ivsize(req) || + ctx->xts_key_fallback)) { skcipher_request_set_tfm(&caam_req->fallback_req, ctx->fallback); skcipher_request_set_callback(&caam_req->fallback_req, req->base.flags, @@ -1515,7 +1522,8 @@ static int skcipher_decrypt(struct skcipher_request *req) if (!req->cryptlen) return 0; - if (ctx->fallback && xts_skcipher_ivsize(req)) { + if (ctx->fallback && (xts_skcipher_ivsize(req) || + ctx->xts_key_fallback)) { skcipher_request_set_tfm(&caam_req->fallback_req, ctx->fallback); skcipher_request_set_callback(&caam_req->fallback_req, req->base.flags, From patchwork Mon Sep 21 07:32:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35B70C43463 for ; Mon, 21 Sep 2020 07:33:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E633B20874 for ; Mon, 21 Sep 2020 07:33:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="BH6EGFKy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726494AbgIUHcy (ORCPT ); Mon, 21 Sep 2020 03:32:54 -0400 Received: from mail-eopbgr60075.outbound.protection.outlook.com ([40.107.6.75]:47332 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726503AbgIUHcs (ORCPT ); Mon, 21 Sep 2020 03:32:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PWe1PGP31Bnd9MZJQAzwf1p3B2aqrHgGTD//8vu3hMsgvIyvCtpc9cXFsfOOIBGiz+zxzG3ZFLDCqR3WOJFo6qjnPbc+iBW/0P4o/gcxNmorshyXZW5KjL3+mkD4hjxDf2pW7hW/kTmaUNzvOFQLa66VyN+yIbNKuBsDYnzSY30xSH/zHkSA3gu0MFsYn6lBseIfe0x6vy0YO3/joGdUi2oy/mtjCs5N0sFOx59uwjr0SBkbdFvTOsivcGMqnRajOOcMT9dfFgJOXtumV2KCwqwlmmav2VQtHaG8yrKU3mgFyr0ZbZbaIIV+m4EyRnTR4+692jI7hRi4oEp2RSoHTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dS1yV9os3Ty8N468x7XG1hAh3a47TnEB83v8a6v6KsQ=; b=oQeV1LWIv1sbnvdA85XPhQRgcut6VhSHF9tlRecxmT9tZVNzSoxgrRSPvlIWmTAyU4OYtO8VBugegVB6rkqWczMTxuX4kvPsBxNPBAM6ZCZSyYAycoZER/kZMyQhNjJyTDjMyT7ANWzDWys62dSaOdW/CUnp/IJ35JNtkSjiGSOk7FgK1DtWnnxW8KmXVhU/E9nTwO1NSLVIuCBpH0hLxtXIII+hFF4EOdDQoiW5v3TlhsGZQqaBw2hUmxKRV+2xBFkmV5gIp3hMmLeHgP3sauucWPx3HlzJwe6nmeVNWSYEnA4NE3LHzhohVtS8d6DwtNB4RgdaIXBxH7zzVuLfBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dS1yV9os3Ty8N468x7XG1hAh3a47TnEB83v8a6v6KsQ=; b=BH6EGFKyUEHpzXehtqynoTLfuDhU2CaXCclOSIHAHWEb03Jhg8nKOS+jEXKq9/WmW9jtONKT6U2504MCkMXsXX1oZmbM6/ydeoV1zlgBKK0LB+SYwNcGE+pxFIiom3C/iQa3EqyuqRpb735kQayTxOnnU5o7qz7Q1rlIs6SQTuw= Authentication-Results: nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) by VI1PR0402MB3903.eurprd04.prod.outlook.com (2603:10a6:803:21::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Mon, 21 Sep 2020 07:32:31 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c%7]) with mapi id 15.20.3391.011; Mon, 21 Sep 2020 07:32:31 +0000 From: Andrei Botila To: Horia Geanta , Aymen Sghaier , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/12] crypto: caam/qi2 - add xts check for block length equal to zero Date: Mon, 21 Sep 2020 10:32:02 +0300 Message-Id: <20200921073205.24742-10-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200921073205.24742-1-andrei.botila@oss.nxp.com> References: <20200921073205.24742-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) To VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15007.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Mon, 21 Sep 2020 07:32:30 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f287febb-7e84-498e-c9de-08d85e007fd1 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3903: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pep1j9F9s7aVVduWrjVvC+CJcs8ptO8pvIflB66FYdNTTjUGEq7AeRfACGXadMtDI6ITGsNhKfvLi+vRpzk878QNkUQ6A8nCp/5p1LL52pzOVnS0aq9PWcIv6BjtVzcasSwUwG70ZCYgzzWO98GvqND9tCh9VWI8fO925DKQE/fPJpO736vsZ1utOGXCgo9h3J+Tw3LKxlOGKabv5SzbVNt91LEeZtNyHUx3MjU/KZrukY62np3ymlmE6OkqALVU6Fc/gtXm3WOIOxkK3XwgHAbcoouKcLp+MScrX9tWN+dLogDwQyd5/oEEqpLWtgzAYdaIqQx64uODwFzG5utTkaSxSG2fVrzdcq288fjCRoTol0pQuOH2+gExduzYu8ug X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6608.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39860400002)(136003)(346002)(396003)(66476007)(66556008)(2906002)(4326008)(44832011)(956004)(2616005)(6512007)(1076003)(8936002)(8676002)(6666004)(52116002)(66946007)(478600001)(316002)(5660300002)(6506007)(6486002)(83380400001)(186003)(16526019)(26005)(86362001)(110136005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: jBzKk+2Fw0fwHAWxxYxGB11lQR7O656RJuCyPeDLX5kKEBfQOkPsTwHfdMukrMnMkPmiTCZBtvEKKnU8PxbtcEAOOHxS3e2QE77chmEmVBG2dvY4RRe4KAh5jv6iKsfeX0V4zMyGVkRXt2D1wYmTm+mJLgonRzWbj5RmrbaUtzBxGhYr7Fo9ltqiH8AVTTHoiTtVct4QsC6iE//8C44Rz4TCa/dRa68ks0t1D6gxppk4SIAMavgcpA+0lXlnc5LtlBGuZ0Ehm4rp7hBC9hdnYeiqYBSBhGBG3yJoFumPyCeK65UjhhmMVtoU5WK8zrvxXXlNZFNe21RF6Y1kjFgJOxSuIabMBm2pCx6dvBxc2yhx8slZblmFTSpniTuivIXM1x7T3razto4aBwS8FkgfNEif7EAhSujuS0+NIskzQSIBnnyv3UWV+sPV0DMIEe8SoWPnkqF2y3y3jPV3hd/KI0giqx6Wyyj0D476ursOCKSRI35TT48kRhH1EpcI8phfDvXfbXLJueC74YCMo3BiOhOaIdTbVTHhxxFMWmlMiCpsvaDmPk+OmYimCeyKkNwmpeJYKxdtLorCDkXhgDIZHFHWsXIYPpfQodnXLDuV0oRreBwrd6DtA46+KtqTJ/5Cu520LXsmiWLwyOx4/zMUBg== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f287febb-7e84-498e-c9de-08d85e007fd1 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 07:32:31.2320 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: djDOvyHv8+1054BuhlPVLLeQCKrf+fBn/jb+XCsz1glUmSZZBCVdwqgsiGNSI1eKUGtq7gH1FoT3/tgHzJ94mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3903 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Andrei Botila XTS should not return succes when dealing with block length equal to zero. This is different than the rest of the skcipher algorithms. Fixes: 31bb2f0da1b50 ("crypto: caam - check zero-length input") Cc: # v5.4+ Signed-off-by: Andrei Botila --- drivers/crypto/caam/caamalg_qi2.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index 5d2e554774c9..592f4a0344ff 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -1475,7 +1475,12 @@ static int skcipher_encrypt(struct skcipher_request *req) struct caam_request *caam_req = skcipher_request_ctx(req); int ret; - if (!req->cryptlen) + /* + * XTS is expected to return an error even for input length = 0 + * Note that the case input length < block size will be caught during + * HW offloading and return an error. + */ + if (!req->cryptlen && !ctx->fallback) return 0; if (ctx->fallback && (xts_skcipher_ivsize(req) || @@ -1519,7 +1524,12 @@ static int skcipher_decrypt(struct skcipher_request *req) struct caam_request *caam_req = skcipher_request_ctx(req); int ret; - if (!req->cryptlen) + /* + * XTS is expected to return an error even for input length = 0 + * Note that the case input length < block size will be caught during + * HW offloading and return an error. + */ + if (!req->cryptlen && !ctx->fallback) return 0; if (ctx->fallback && (xts_skcipher_ivsize(req) || From patchwork Mon Sep 21 07:32:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FD1CC43463 for ; Mon, 21 Sep 2020 07:33:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4D04218AC for ; Mon, 21 Sep 2020 07:33:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="RyXudyZJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726510AbgIUHdP (ORCPT ); Mon, 21 Sep 2020 03:33:15 -0400 Received: from mail-eopbgr60075.outbound.protection.outlook.com ([40.107.6.75]:47332 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726489AbgIUHdJ (ORCPT ); Mon, 21 Sep 2020 03:33:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kHQ3V9DOQNFZ4eTkXVb1K79LzbcVog84ucFXihq4VTS1lbncIg5q/2dwqVe26c2e+o559ZJauJ3C+8LkxfGLfioGUrnnKZzu2p9typtL86xGOfxJFgg2sI631j3/Xafct0TFUdxvcVMgGmWn2PHGbX1Wz/fdeVTytIipDxqJ0hoeyxR4omXIFI+c2zjbsSX7tOfIC7ido53yVSoAnE1/EP3Ik5CsXwEVo2hJ/36X78ij21903nSEGguQJyFGTa4w8zAIf1Gq5OHRa2okV/wuguXXMhUerWlUQ36KwO1ugbZGYtZPMSI44PkwVXU9REC7VXRBsUDj2Qv1ItH8n7LF5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t48bUselI1r0GF/+r5CwLTQuYChjGC2OLYgTa/EBvW4=; b=JmU5ls8RsAoteAWa958uYFdOYpi0hCEzigO00/yFn+Mo23kKZ4leE4nsbPB6P6Mn1puS3zSTGv7v5x2CjSCfCEgTIBXB75VB2V4uyiuWFwhncZKWWEsvfJkjcPr9yzOtItlX6tWtct6fRi2KjnIiFtBNbf3XsmrPT//YCP2hj/aOHcmzY/fP2lzQgeA+cowe83v5moaN15rZ5QEsM3XBeHm8HBDHLM+SO4xQtwzZtv/mmCKCwPzRm7YreUBqYKoax6tj3gU7kuWzWvIR3ymo5lUbfporreg37sGcUnw4pe7Ders4oTTtD32FgCZo6ZDpdZPsTalcVtRq8zLv1PIWaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t48bUselI1r0GF/+r5CwLTQuYChjGC2OLYgTa/EBvW4=; b=RyXudyZJez3JUXhK5wJPIlINfkHpICsS4G/uPcr4eeZy0A1T8XLgzSz3dOUobctPyU57gNE/3cp7M1HkG9cdHpDsJmeX04kjX0uNIvY3A8NvvGc+T5HlFtI49AuXTIEk1Ixby2IAG5z/xnBjo1/OgjAAWelzrTwPGXAc/7A2A6w= Authentication-Results: nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) by VI1PR0402MB3903.eurprd04.prod.outlook.com (2603:10a6:803:21::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Mon, 21 Sep 2020 07:32:33 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::34b6:beed:6762:a67c%7]) with mapi id 15.20.3391.011; Mon, 21 Sep 2020 07:32:33 +0000 From: Andrei Botila To: Horia Geanta , Aymen Sghaier , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/12] crypto: caam/qi - add support for XTS with 16B IV Date: Mon, 21 Sep 2020 10:32:04 +0300 Message-Id: <20200921073205.24742-12-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200921073205.24742-1-andrei.botila@oss.nxp.com> References: <20200921073205.24742-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) To VE1PR04MB6608.eurprd04.prod.outlook.com (2603:10a6:803:125::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15007.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR02CA0016.eurprd02.prod.outlook.com (2603:10a6:208:3e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Mon, 21 Sep 2020 07:32:32 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fe7b40af-5233-4e82-67b2-08d85e0080e8 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3903: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ed28INyL7vdwNK1sCUWL/bxjgp1CPMIZNX7l/gkgzB/CwuN4e9KeHYwkFeWd/uqIOV1vtKwUjMxyEkcREY/01rSJu8jqsDQOlzvkuwbNvSETEpHtAvlrCpfKYw0279DEEjgZwRfdnQabxt/B2dzFj0jq53YweH0cFJz/cRW9KiYrpMsV7FJYAdBqjfpVLF+N1YoUwwIUCcg87/rCaov/7Yqn3QM3OJNyUATSFihTCxcOKE0MXY+CDP3dTp0P1Ggd2ptPbMiAW/eDLjV12wg0wwU44cov5QW8i1ysYN9rJrRthkfOYXqy36zPM+GW+55RUucncyYmFxGMQcg1GKtyIqT5gnvZ+P8RPsSfLzd5GWx1N7Sb+dsjGba/p01kE1J+ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6608.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(39860400002)(136003)(346002)(396003)(66476007)(66556008)(2906002)(4326008)(44832011)(956004)(2616005)(6512007)(1076003)(8936002)(8676002)(6666004)(52116002)(66946007)(478600001)(316002)(5660300002)(6506007)(6486002)(83380400001)(186003)(16526019)(26005)(86362001)(110136005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mAe7EpM+xYlCPdUsHl4b9LaOr7z+efApntnkzg279c4fMd0FrWTWI5efZQw9uD/fswlUt4W9LFOs7C5deRBTExcui8OMzHsXHNx06yQwyw/uK+DcjvHBC5ASWSKAPaQ1kF7Z65LJ3Vc9i1gzYgxJliJnUkBJ+vLuayR7flDIHmNWM5naIzHxnAkqNcUPiFdyWUcRvSWy3nXD7PmSIs66tPVtLSBlbBHFdpSOrnztOv8M8eafLQDKatp6AbU3U6ByFvezEdCiiLhk+1GrCDRA/ObSDLCRmU/GqhDki5d7t/4kwamVDh079fsPUeeu81Uybq8EWef5JUJlY5cy3SuBKKie+qTgNVQKZEQf08bWF2iJ8FM8/tVj8IxftUfr5t1XCbyUKKVlz06YrcCWmZ8yuUn/zyxWFLljKaPrMWbAMxSHYpn4VgAH8s0PEyfFlrGOeXAc9cGnRvMtvAFsf8s7lvgBvwPkGX3QAXxCJ5OHMmcQU779LgMBpjNFWS4CbXO1WHkBQYjJmY7JboL4MTV0bWWKyYfxHOn2eMH76CKsqrekDteRXyBbLQsBLYf5IsiVexaxi1dHKU63yOeMeeuqzULnNPHdKGOLeypowacSP3HyRH74iMHrYqwQM2DUE01UnPlN5vAIipLoOvjpwLv7BA== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe7b40af-5233-4e82-67b2-08d85e0080e8 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 07:32:33.0579 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: s48oNrT/8UMMVSJjhTXt3A59yFdZi68ZkHdowsdYLUCLfvNboI7It6jW4IVQomw3sqPyP9fkFVUdLhJXxV3wjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3903 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Andrei Botila Newer CAAM versions (Era 9+) support 16B IVs. Since for these devices the HW limitation is no longer present newer version should process the requests containing 16B IVs directly in hardware without using a fallback. Signed-off-by: Andrei Botila --- drivers/crypto/caam/caamalg_qi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index a897eea59790..88d767910874 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -733,6 +733,7 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, { struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); struct device *jrdev = ctx->jrdev; + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent); int ret = 0; int err; @@ -745,9 +746,11 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, if (keylen != 2 * AES_KEYSIZE_128 && keylen != 2 * AES_KEYSIZE_256) ctx->xts_key_fallback = true; - err = crypto_skcipher_setkey(ctx->fallback, key, keylen); - if (err) - return err; + if (ctrlpriv->era <= 8 || ctx->xts_key_fallback) { + err = crypto_skcipher_setkey(ctx->fallback, key, keylen); + if (err) + return err; + } ctx->cdata.keylen = keylen; ctx->cdata.key_virt = key; @@ -1406,6 +1409,7 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) struct skcipher_edesc *edesc; struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); + struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent); int ret; /* @@ -1416,7 +1420,7 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) if (!req->cryptlen && !ctx->fallback) return 0; - if (ctx->fallback && (xts_skcipher_ivsize(req) || + if (ctx->fallback && ((ctrlpriv->era <= 8 && xts_skcipher_ivsize(req)) || ctx->xts_key_fallback)) { struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req);