From patchwork Tue Sep 22 16:03:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252955 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 63B4BC4363D for ; Tue, 22 Sep 2020 16:04:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B13B208A9 for ; Tue, 22 Sep 2020 16:04:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="PLJeQv7P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbgIVQEH (ORCPT ); Tue, 22 Sep 2020 12:04:07 -0400 Received: from mail-eopbgr60083.outbound.protection.outlook.com ([40.107.6.83]:40665 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726586AbgIVQEG (ORCPT ); Tue, 22 Sep 2020 12:04:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SHb2DASt23ZLFKeyuTwh+lSVOk8+p38r/GTehayBRIGB2CwblxSczvkgriCjNvBsWxK99uunN4LkDwsXI9uKxze7NfcDZaa2F0fUrBAzwdnn4udTxVKzllDV9bcq9yc0QnqLsnAdbL7TJZuSLniXsz62jxJTu8fPiqYMG83x7drEe9k1Pmnno6MlbrcMLQ1RUqBP8HQ7EdYdnryhrIpVasmujDOIWZdxtDUlA36bABdNIVKFQ/NZc7aLFNm09USCjI8wt2FLbAwxtRpbwcCpJSo412wAsNfPFDT8CrRRelD/UtR0YWLxBzjVZxyN6zAOnruPkRNxiyXcerDd8hu+MQ== 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=G9IswZaaECesAyJAPZilmBumSFjPTWEh7lQ3za6oqHQ=; b=IofoAx3z8uxEHMp4WclU888CUF5ZbgmuN/Soa2+DJsachfuGS+OOeJCNxdWusIJqBEQQRJq0k1h5S9ywl6rlOl0vPmsVzl8Q/qZ3O3oKs0Su54DhvLcwpjtvvIE6L3mtGwrU0jyssUOrCdQGgMQRzZL/peD52go3QBQhyitbH5V/3+DcQiEpuJ6pxpLkmDPaMXuiKbhC2c4eOLq/rgQLChRk3pUV3KEs/UZgyc+NS2htmLmeTKIZXv0M84kw65od7mrdNgxt9+DcIbCIb746koxLUWwM3uVrOOeUSCD7npveyYC5e+4ngSsv9m6u4KjSkoLgauIrvGBknO8LxpJpjA== 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=G9IswZaaECesAyJAPZilmBumSFjPTWEh7lQ3za6oqHQ=; b=PLJeQv7Pkx/86u8CsUhiqa+k6l+tZmLgcaxw4Yj5T+25lOblocoVZRDECLfAFuWEBCCkTdFGTW4KVifS30vFJp6vEMdAtnYbby3pWMu4pMLL3XL7AVHLamKNMyJxo0iyybH6DVqkKh/WCQlnUFvVbDRk7dn6xmo+uZsm7DLnQoI= 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 VI1PR04MB7072.eurprd04.prod.outlook.com (2603:10a6:800:12c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Tue, 22 Sep 2020 16:04:00 +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.027; Tue, 22 Sep 2020 16:04:00 +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 v3 01/10] crypto: caam/jr - add fallback for XTS with more than 8B IV Date: Tue, 22 Sep 2020 19:03:19 +0300 Message-Id: <20200922160328.28926-2-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200922160328.28926-1-andrei.botila@oss.nxp.com> References: <20200922160328.28926-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) 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 AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Tue, 22 Sep 2020 16:03:59 +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: fc5000a8-eb89-4e8f-a3d1-08d85f111e50 X-MS-TrafficTypeDiagnostic: VI1PR04MB7072: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nz4ZX4p/dfHnZiBbZXCerT/JcaxfgDDE6OIkzl2HrakCyuK3VMCjPjIwk5I12IyPhNLuNIQxcHJ0DO1pVeGaaosw8TLkJI1thki+h2/z0ZoachGEtIFjDdSlPgMsZBm7yoLJQPBvhgczPwiZ7mLQslFGON6j7Om1NamabFhai1b7C2jtb3wgLpy0UXIObaEUyIddzwWJjvOrdiqvuFiTfiwxq71JsN/nye8vrYUN0mOmvLd0kXFH/LAdRNvYCf3rx8RcMuPK3ns1Ayj6UoP9kiVJCvCfVDKLpBuNWIxIPO7Fp1SQuq8UngRLcC4/r474wD8cewHigFXTt/1cAtErB4zI92mm7V+br43L+8W6LXhoUhG/yMcHcWK4YkNckzfg 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)(396003)(376002)(366004)(346002)(39860400002)(136003)(1076003)(4326008)(2616005)(6512007)(83380400001)(186003)(16526019)(2906002)(956004)(5660300002)(66556008)(66476007)(8936002)(316002)(6506007)(44832011)(66946007)(52116002)(6486002)(478600001)(110136005)(8676002)(26005)(86362001)(6666004)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: jnvEX1axivGDzgGlX10JrGG6EfklCEAyyuu+4iULAAOllTZ3k0kCPGU8Q94MNKvosLnXIDY5BGLhsDg0XvTtCWXsH5+idHu0VLbltnuhbjg3sLNG7wX29xQnnYm3c6mD0vBxU7YFaGz4ZqNnknSKbAblE7HjNUtPw+ZWbfV4983svs11CtaVwH/9U3PHwpsy7ilKmh7NChTdth0TP+MzIo5BJnZ98qHixBK960SvMIqO3erSsU0otboJc3tSUL/cFoZvBIVEKp5WOTollHBMn1U+P3TXva4dr9Llriqu4mm/KFTpJYwHC9HoCrFZBF/P6iE9IQtkDF1shzEeqmi5KLvJ80Foi20KNe6wrsZz9/SYXT+vwk/ge10XBgvnkut8va1FtngMv/8jm/nDgEZ6/oUUeO5zl42ccgI5p6vbgKBsdnFgnHfpP0vlY2uMM65k/S7JRy5Ma7pMwk+dqHrbxYGzdgKQBClVUJWtCxsJHbTObeL9Te3g2XCWtWAoy61qauMbc1xpCdS5d7h1eeQLiSBDn3aRrKzFkdY6dFLElqZ5X0GuksMNI+qxQ14+wNfFg6PcP79KYnoDauOfpC5PT9GeI6a12x+knq+Al6fFhDCyqNCeHQg1nfRHVpCs8J5Lz8JNxyLF/Tw4O4ronCLy2w== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc5000a8-eb89-4e8f-a3d1-08d85f111e50 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2020 16:04:00.2578 (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: i2E+/H1dgLdVFUUR12QI4peK0OHzSgvvv9q2uoNoLkC+JoemP2fdEPloaiUdvfYJBdOotq0dmWLd5m5UW6VVeA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7072 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: c6415a6016bf ("crypto: caam - add support for acipher xts(aes)") Cc: # v4.4+ Signed-off-by: Andrei Botila --- drivers/crypto/caam/Kconfig | 1 + drivers/crypto/caam/caamalg.c | 72 +++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig index bc35aa0ec07a..dfeaad8dfe81 100644 --- a/drivers/crypto/caam/Kconfig +++ b/drivers/crypto/caam/Kconfig @@ -101,6 +101,7 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API select CRYPTO_AUTHENC select CRYPTO_SKCIPHER select CRYPTO_LIB_DES + select CRYPTO_XTS help Selecting this will offload crypto for users of the scatterlist crypto API (such as the linux native IPSec diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 91feda5b63f6..adb2c05a8bde 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -57,6 +57,7 @@ #include "key_gen.h" #include "caamalg_desc.h" #include +#include /* * crypto alg @@ -114,10 +115,12 @@ struct caam_ctx { struct alginfo adata; struct alginfo cdata; unsigned int authsize; + struct crypto_skcipher *fallback; }; struct caam_skcipher_req_ctx { struct skcipher_edesc *edesc; + struct skcipher_request fallback_req; }; struct caam_aead_req_ctx { @@ -830,12 +833,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; u32 *desc; + 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; @@ -1755,6 +1763,14 @@ static int skcipher_do_one_req(struct crypto_engine *engine, void *areq) return ret; } +static inline bool xts_skcipher_ivsize(struct skcipher_request *req) +{ + struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); + unsigned int ivsize = crypto_skcipher_ivsize(skcipher); + + return !!get_unaligned((u64 *)(req->iv + (ivsize / 2))); +} + static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) { struct skcipher_edesc *edesc; @@ -1768,6 +1784,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); + } + /* allocate extended descriptor */ edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ); if (IS_ERR(edesc)) @@ -1905,6 +1936,7 @@ static struct caam_skcipher_alg driver_algs[] = { .base = { .cra_name = "xts(aes)", .cra_driver_name = "xts-aes-caam", + .cra_flags = CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = AES_BLOCK_SIZE, }, .setkey = xts_skcipher_setkey, @@ -3344,13 +3376,35 @@ static int caam_cra_init(struct crypto_skcipher *tfm) struct caam_skcipher_alg *caam_alg = container_of(alg, typeof(*caam_alg), skcipher); struct caam_ctx *ctx = crypto_skcipher_ctx(tfm); - - crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_skcipher_req_ctx)); + u32 alg_aai = caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; + int ret = 0; ctx->enginectx.op.do_one_request = skcipher_do_one_req; - return caam_init_common(crypto_skcipher_ctx(tfm), &caam_alg->caam, - false); + 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); + } + + ctx->fallback = fallback; + crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_skcipher_req_ctx) + + crypto_skcipher_reqsize(fallback)); + } else { + crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_skcipher_req_ctx)); + } + + ret = caam_init_common(ctx, &caam_alg->caam, false); + if (ret && ctx->fallback) + crypto_free_skcipher(ctx->fallback); + + return ret; } static int caam_aead_init(struct crypto_aead *tfm) @@ -3378,7 +3432,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) @@ -3412,8 +3470,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 Tue Sep 22 16:03:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252954 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 343EBC2D0E2 for ; Tue, 22 Sep 2020 16:04:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2B3C208A9 for ; Tue, 22 Sep 2020 16:04:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="jj4OOGnU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbgIVQET (ORCPT ); Tue, 22 Sep 2020 12:04:19 -0400 Received: from mail-eopbgr60083.outbound.protection.outlook.com ([40.107.6.83]:40665 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726643AbgIVQEP (ORCPT ); Tue, 22 Sep 2020 12:04:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LXwe1E3ccCgxXpblrgBEFZS6fYvoyKN5LZoU+4OEjIWdA+dWkL4f2xf59+ZcWBXEU6MNzL/Gj+d4B4MZpBIv4WPlavzQOXkO8QnbdAvzvgxqROCUiMkOyRE1HIVIns50G+h9d7YYFtxTnjGWlaZIGTda2cN8Agpi2OvD+y5Di+zi9S9m0BQetKbUbvC4tRwEjOqBSDwvFyf/zkJ/6X6Ri6hW9btoT9L1KH/gUqJgjmqQ8lAw9NU2aRsd7o4F/x6eSQtnUypS7TBFr45fKC8HgAHw5rpTLPdf3CftYpagYxQk5G0wDMiyeaVC6LdvxGaicRlLZKloP8pkugPy4lloiA== 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=25rAbYU/5sLGxzc9ZY0sRC5+V14HYibf8FJTfunPEek=; b=g56COYwsSgHDJf9+69hzR6l9mMUNXOmwL76XJHG4khHIcH26iZhCxxBwhKJoP4QNrLg/bJUCcgfInLomxX2ZvDSGtKthYje421U5w9ImLxNKGtVJQOsXq9rp29LtUgAxnmw9HZZZKRFvcTIw8cdTtpnY8xiR/+XfuY8/tOYw0jG1YCphVcJUo+NU0Y5/YQy4KgMRuXrhk8X0iT60SVg7KRdk/COIQ0wwy8LkOqS397E2k2oaQXzuIdqmKiot1XHtFlvOKruv14FFGn70eNOBnLWpIxZnO4U1UmuyRrrfTf80nFnPDJcBmoN/z0uD7uv1sltJPEbSG0Gek+WY5/p4bg== 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=25rAbYU/5sLGxzc9ZY0sRC5+V14HYibf8FJTfunPEek=; b=jj4OOGnULVw2Ef9mOt0+/4kyHDIVXpXuR6L4ug4JYaplK3GRHRJ8WE5B+wDWat+47FPw6YiEc532//sB1JoL0WkyIjxo1h3UJ59bZrG4CPkaiIfIepxEs7MMy2tXpbnRwR5RjEgqJQNy3xLMDqe9/M4YehG+hFop5lgo5UG4+is= 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 VI1PR04MB7072.eurprd04.prod.outlook.com (2603:10a6:800:12c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Tue, 22 Sep 2020 16:04:03 +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.027; Tue, 22 Sep 2020 16:04:03 +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 v3 04/10] crypto: caam/jr - add support for more XTS key lengths Date: Tue, 22 Sep 2020 19:03:22 +0300 Message-Id: <20200922160328.28926-5-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200922160328.28926-1-andrei.botila@oss.nxp.com> References: <20200922160328.28926-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) 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 AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Tue, 22 Sep 2020 16:04:02 +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: 268c5f26-a828-4992-0def-08d85f111fee X-MS-TrafficTypeDiagnostic: VI1PR04MB7072: 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: 5LOxeSEmWlqgm5vTRb+O6TcIufmbqBl/BR4czbEulxCduEyLgpVETsMJcTWZqeZY/IGKadva8U18cpATghf0AqWP1nz49zalmpGWXBn0JRqZrW3S5DJA4XS984Aq6Q6nm4uhFlPnsHKuPwfUhsjRD3tUbJw8VJVpGd1z0y3ctjCRlMG1LqDYkxke0Lk25QhYhPpklUGUVIgEblAsgvSJCNQegJaRJ6NJz0c1jOM/TQ+naARaDEzoKzjfvtrRoRnKU2zeSG3HAdXkBk9fZ/OrcgegT27KpxxYcRGloJg/o+81/MainRMzGu4GhOclSd+10/FoW4CUVxht0yBopva4Bg== 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)(396003)(376002)(366004)(346002)(39860400002)(136003)(1076003)(4326008)(2616005)(6512007)(83380400001)(186003)(16526019)(2906002)(956004)(5660300002)(66556008)(66476007)(8936002)(316002)(6506007)(44832011)(66946007)(52116002)(6486002)(478600001)(110136005)(8676002)(26005)(86362001)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nB6bCGjSQ6av4dcv/e/B2zIpT7cjMPGzRZVpAfI8KysPeM9bBuaNHtZnawbxq6sBIBJwNFf4kHAeYcjV4iLxpJJb5bOTiioTzSwmR8sqzX06Uk8VtBnQy7e/t0qWUMyCkrv3OPcJj2r3DIsmoXbyl/FOhoOp8IAUBQ5nhVACYPI0ulVA2IpDsWBPFZEPU+E9pdqB3Jn6XVdBnorNxbkM+gHVnpFlcfIQKX7zm0xifwPEuei6b8uUx/gPSFhZQsphb+ea546w72kXfRxlSz5elfcoKDJMqwhxLtgxIfJrMjbh6kl2PLlT7OjxZZRlPdvQUytudnF77nLEpBgGOK7NQWWzf6H3+W2UQZd30fmAgqRcBO1lmN2l9cK5/9VE5S1zlkqOiH3+miTlJF3qpmkGQSTlNHGlaJZ3K3hZdD5rtwrV8w64dzw4b/aSiYU045ssIo6P5jiunlBzSYcI8Ag35y9lL6of3HRKENsdBODWreUC3DhynLR2/NZVLMQLCRqPbeU7I/hfM1j6WtsYybaLogUFDHciR66+T58NsO1JAsQQ0JNxXHGuCz7bRtr07Cu3FHRYKqGq7kMEKap8Wc0E/bIEMZF1bEYGsbBCZKkJGHhrQDC3gRyT/rvntCHCGtlEhEhf/yT3zPLh0EGbAzZq7Q== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 268c5f26-a828-4992-0def-08d85f111fee X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2020 16:04:02.9911 (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: Uve9KK3eW6/BKWsbqQhxXFC/rnU+6J5mvCfM4pWwAv0J1+NNd73rMHY+yeWkfjrSQHRPUe6iTysEdjaE5pBA9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7072 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: c6415a6016bf ("crypto: caam - add support for acipher xts(aes)") Cc: # v4.4+ Signed-off-by: Andrei Botila --- drivers/crypto/caam/caamalg.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index adb2c05a8bde..a79b26f84169 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -57,6 +57,7 @@ #include "key_gen.h" #include "caamalg_desc.h" #include +#include #include /* @@ -115,6 +116,7 @@ struct caam_ctx { struct alginfo adata; struct alginfo cdata; unsigned int authsize; + bool xts_key_fallback; struct crypto_skcipher *fallback; }; @@ -835,11 +837,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(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; @@ -1784,7 +1790,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 Tue Sep 22 16:03:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252951 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 C6EF6C4727D for ; Tue, 22 Sep 2020 16:04:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 824722399A for ; Tue, 22 Sep 2020 16:04:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="l7lUgBCw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726781AbgIVQEc (ORCPT ); Tue, 22 Sep 2020 12:04:32 -0400 Received: from mail-eopbgr60083.outbound.protection.outlook.com ([40.107.6.83]:40665 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726686AbgIVQEU (ORCPT ); Tue, 22 Sep 2020 12:04:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j9LFYUhHzLHfS5RHimcYxbW9Fkt1UvC9R//H2944MMyP4lnbArIgx5gtnO0lEfDSNv3io84PoZ5uNP64kHRz+NywSY7gTxd6nEZle3f4oEzTCp9raec+CdTP/wGiDLmCvvmK62R6jZedwleHio8gFXZDPQDReCEfkPUSwOCEynQrsqm8L7WY+ehXAFVdVNpS0HgElHm6EpPcSGIIDvOugcW6ztmt7XHKYAmkkicgmHLImQCgeMExPK9MMi3rDmeRe/G7zmJfxQXHnwO0/WqCwv2kOEw4yH+7HuKi2+R/3k2zIRN09czLlhC7SUh5yjyGd5rky7UaIDHFQdwSWP7oWw== 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=laPo1FlHkzXyhfDF4v0FpI8og+Wt4VtXWIaKVkWosQY=; b=SW0pYgjeAy0ODc80KfqfKkLyjyIvHydRv58CXrEjZ14EboSvZ6rnz8pKrvPZu/5SlqG0euVAP4Nd9yM9HFC3Tw+QUUW42y4ZjQKbgPBahXKhy204aGYZnhYVKwS6DIIEaUx4Mje4ubQ1RAH8+Mh2MSRBs7d9On/m2bmJWdzAA1H9eZybFlVaNZ/1J+sg3FJHMEz9o003whdrmyPLGQrXl4UkkyjJ1S4br5Jq3ygipk6bEEjix5wnRun+U49HswDfK+eXB8g+bilduRNIA8zkTDQst2O3tFVn3R6OAuKrjmgAz+EYkBdJTIy6mv98WGGf0uzXMDz16MZ+lph+b3A5jA== 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=laPo1FlHkzXyhfDF4v0FpI8og+Wt4VtXWIaKVkWosQY=; b=l7lUgBCwCsVEHGjeUVOOHXjWzffTl/WzjxD7EVULfIRfraavEkndvEW1GOCGDehy+NGN/pq5nBGBqrIFmMcyyWUti1hVIe8CsbXXdHmpZl0+bOo2nAazRcT+CIry2B3S1QPXwD2nBsegqTvs16UP99LpBetFKG1n+KzXGud2PRQ= 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 VI1PR04MB7072.eurprd04.prod.outlook.com (2603:10a6:800:12c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Tue, 22 Sep 2020 16:04:05 +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.027; Tue, 22 Sep 2020 16:04:05 +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 v3 06/10] crypto: caam/qi2 - add support for more XTS key lengths Date: Tue, 22 Sep 2020 19:03:24 +0300 Message-Id: <20200922160328.28926-7-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200922160328.28926-1-andrei.botila@oss.nxp.com> References: <20200922160328.28926-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) 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 AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Tue, 22 Sep 2020 16:04:04 +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: 18061e8d-16ba-47cf-25c9-08d85f11211c X-MS-TrafficTypeDiagnostic: VI1PR04MB7072: 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: IMpgX0wf0ZvZWV9gyK4jOjVFFhkVr+MFdYb95XcPn6qOz7vOF/JdZ94plve/NzCYOsrMgkMBQpGujkignzi0omnLXETVV+kwCUmPqQJtxhxU6Gm5QAfHpT8jOVGvzWdfvTVON/xHEuz3HsuswqVNFD9Snj9xQ7fv2tPNpF3e7kgUh6nrk0uBeOuNe3lBU3oR1H3OnXT08zSO7dgJn3ZnCb085jgk5U6t6o4Pu95V08fZGVgrPAEHUf3wdICUj5Z6TS4ju/8p8+C4hORUY6nMZU1atkCDz8fnrs6OyPVaO/a9wJZZZXJHrpNZf+S1zPPTL9b0PCy47hRKj7kuw1GhoQ== 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)(396003)(376002)(366004)(346002)(39860400002)(136003)(1076003)(4326008)(2616005)(6512007)(83380400001)(186003)(16526019)(2906002)(956004)(5660300002)(66556008)(66476007)(8936002)(316002)(6506007)(44832011)(66946007)(52116002)(6486002)(478600001)(110136005)(8676002)(26005)(86362001)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 16aplXrL+yut3eDN9IyeTv6Az+DjIzoz1kM+I2ZN5ETrE+Y4xtqAbVElK/QT7+me+u1JmJP4M/fW8PNFGpxCzqFOm0ahfc2QUL52HJudyi725LYJArXw0N+3qUd1bRYKOzCO/tz9pTIPdmAFwhe5B73vbBw7zH952Hopec81y5sTg+3s6FP1IUSN2eGZdMT9fRDYkzpzfeU3/QVScPyccOcWaZZnPfVTydcqY0DdTydbTfJkOFPg8tC3uh+3d0uhWD1ZFAGd4INDwX3RkAK5Cl0N+V0FUf2Yd3v1QFRVu1sylTznJ5LNcNW57Nn6tfvcXWhqn5pdpwT9ScvIc0oNMv0+xe/GJEl0isyI2iiGacBWZvEFyM4L4jKHLxJHdjAgs2NhYQDStSLAaI/4/Hb+vmgTqHWcGPjQGAHAShV97Jc0iq7azNfmlgWCH1GxDzIlVt3Kc1vs8P0rl+vgZv/ptIE0/xLFkrfd5dFd6+MNzzi3duFf+akGyt0lGaXI9BmHeDAoy6mYf4IJGz9Z0Tgs2WGtUrhQVucokIQTewKn/1GlQfgPPdPw7glaQJhYpgnKlzOrkfGqs7emSk3RYAZ7e2fYlRhXfU8b5uaPA9JVAs7Sz0EG6plNZwS2UyV1RPXPdjlwY5YQcjSlEjKg1Nv31A== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18061e8d-16ba-47cf-25c9-08d85f11211c X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2020 16:04:04.9989 (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: cK7HL8NDBpFiic1AQRHneVrih8HTtGmnNU4iIlGte6cxcUp94KgPpkbz8SPNqZSyaNRS+PJgbsoTSuy8oU5O5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7072 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 c36d11820db3..255b818c82b2 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; @@ -1469,7 +1475,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, @@ -1512,7 +1519,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 Tue Sep 22 16:03:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252953 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 198BCC4363D for ; Tue, 22 Sep 2020 16:04:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C065D2388B for ; Tue, 22 Sep 2020 16:04:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="f1RtOkqp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbgIVQEg (ORCPT ); Tue, 22 Sep 2020 12:04:36 -0400 Received: from mail-eopbgr40081.outbound.protection.outlook.com ([40.107.4.81]:27291 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726631AbgIVQEf (ORCPT ); Tue, 22 Sep 2020 12:04:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H9wvK7E+VoHGlz1SB74602Gil4ZPzlBTu4X4d+tjhbELHWmhYfxgCyvI52dO1mo8VoxAhjH9wCL+ghRm9YDLrNQPscsmHf7mxHpqu8MEaa5NKRdCaufR1x6i+TCVFZM43rXhgrSdPiwojgP5K0WBv82tIkSeMycbPvyGuhDdfi6DN6dO8AtaiaCFpTDVuYZqGUsixvtxICC7yiBjNj0/RsFehtLSBYXON8Ueqf9BXVb0bQ3VneFJDRjuU2zOXWsTUs+c3gioVOLOtOl1Q+e3USrM6NCCJWh26qczcEtLUkmiZG6j3ZE8WhyRV0fEBAJUFdV7LhO7BjhNr3723xqpog== 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=7eP4HS2WnZIWUkNBbirjDIRkmlqTNzjp2B6fDiruTLw=; b=NZp63SZBhf73adhxBaMOOMoMnup9QkoKBbzn064mNoMUeKKQKP4A77DLG2MZiLviJxf+bd9Ln7RC8hr6xb1X338PGv146hZrLngDX8cao8un7gm7+SoCDUSeqxj8LmGQwTWI/y3APx2gh7N00ZknFunvsRxlzh0Zp6PguKbQ5sEqwPC5u20GAHahAGGPn4G5LjBht5AunfryMerHKt2uoPS2hHOwdyfh/bkt/8sf10pVktH2uH79anpBP2sBKwzyHv8iqvr0OcMgQoepUI50yhXtN7qSrNA9JNfcOg/ASTSBuMxYOTrEJHpAMjByLfiCJpDsDmeg9pwdENHoBHI7Uw== 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=7eP4HS2WnZIWUkNBbirjDIRkmlqTNzjp2B6fDiruTLw=; b=f1RtOkqpudOGW1OiHgAbXCU9xiHs1CpYnJZjr9HHTrxLgbWmR77YcF5JqH6ntHS6ApU4Nx3m5dP2hWTTE5ePCjgiboB/vplLcAfouQTBQgjAzYcPmC7Sh73MQnFTVhszdvjlTEK9iXkIk11+kly5XowvCvCYpu3mtlUrMe2E+bg= 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 VI1PR04MB7072.eurprd04.prod.outlook.com (2603:10a6:800:12c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Tue, 22 Sep 2020 16:04:07 +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.027; Tue, 22 Sep 2020 16:04:07 +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 v3 08/10] crypto: caam/jr - add support for XTS with 16B IV Date: Tue, 22 Sep 2020 19:03:26 +0300 Message-Id: <20200922160328.28926-9-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200922160328.28926-1-andrei.botila@oss.nxp.com> References: <20200922160328.28926-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) 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 AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Tue, 22 Sep 2020 16:04:06 +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: 1db477ec-dd9a-4bd7-8c6e-08d85f112241 X-MS-TrafficTypeDiagnostic: VI1PR04MB7072: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ezGwZhvqP7r1woN5bg5mSy+iVZfG+T8kUgXXDyzyXupRLFShfBZUHNOqXVWesdnuS+ycuM8wtuXnJaIX7Ge+L2dihVNO1Tm5+71dvWwFGAaasjk0z7XKT1tzCAHc0/mzrUOQqfsYg2Y1gXXITx2EYofQvc3mF1hDrww5PWu9EmBjOo5Xsipy2GRxnIDxLPmG/Y8lUuF7pws0/Z3PRi96RcuCpk+VzqMP5NO/EYSuEYZ1fk4ng/V9gzGEXzvV1bdCAusW+VhTPJsrl8Txou2/sezlNjWz0NM/Irs8C+il/9Ag8g+4SYWbXedDd0ZP4SZWHw1MIsII5JN8IaaVffKMKg== 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)(396003)(376002)(366004)(346002)(39860400002)(136003)(1076003)(4326008)(2616005)(6512007)(83380400001)(186003)(16526019)(2906002)(956004)(5660300002)(66556008)(66476007)(8936002)(316002)(6506007)(44832011)(66946007)(52116002)(6486002)(478600001)(110136005)(8676002)(26005)(86362001)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: tlQ7/CR0TMG6tntrnZbMtQ3aytnRxuUIm/6T1wMjIad4KM4ddw3aZzJpWcC/eX+bmqumCyX6puH2pAHcJlNZbqAiHjqaebfVNTXgCPP1d2LtZfoL0uCNQ8pdpo2AfQpvLOBscopxxbknZYrLbj8q9dlY+P7/O+rmmqxuilora4qDxhw/smsuB4P5ondgIh/Vj/hDzLVVcdyutKFngAV5+0WOwvqKB2KmUGTkgR4qfZRwHunJBOKGUxHAoEksjnI+Ml5OG6fJoMGmVTnml3WX97zdPEcEeCn+sPrixFAUIq1qpx6nIznmNReFuP3tiL2NSITad/f9dHbFCl2Tl+Mhze4pF8IyuxP1y5oytLsSo37clvTNYCcTXzGN56ZlPCOZg68syWQmW7oTK96Avt7r/L+9DuTBjmmvDma2GLGWl12cGv9xSzS0zMwIKzg0HxO5BPHwdj1MgLJC6C0PjDwvFdfH+23hdSlPJwqeHBiO40Sfkma+Hh+jSNijT4to0nQ207MJrdFBcc8nUpNAmd+pkqmjN4DTMTAEalTu3TvARakK1JdlhMseByiI3ftLINZ8LlquG/oFanRkBZu1O7GgSKvF87ZBSlXiH5kxZ6jmO82YI4QzbCblF9bD20V9xvMqEzOjPxABJ0/ikjyTFoWSYQ== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1db477ec-dd9a-4bd7-8c6e-08d85f112241 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2020 16:04:06.8537 (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: zELyboB/5xuZf2iv9bsRk7zULKH/qGoxKB/Rlhd2eRC7wT2SqHEDMZ5aei3WQAwetYvcuL/eM+zAzp8rUzmh5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7072 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.c | 12 ++++++++---- drivers/crypto/caam/caamalg_desc.c | 27 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index e72aa3e2e065..cf5bd7666dfc 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -834,6 +834,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); u32 *desc; int err; @@ -846,9 +847,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; @@ -1784,6 +1787,7 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); struct device *jrdev = ctx->jrdev; struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev); + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent); u32 *desc; int ret = 0; @@ -1795,7 +1799,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); diff --git a/drivers/crypto/caam/caamalg_desc.c b/drivers/crypto/caam/caamalg_desc.c index f0f0fdd1ef32..7571e1ac913b 100644 --- a/drivers/crypto/caam/caamalg_desc.c +++ b/drivers/crypto/caam/caamalg_desc.c @@ -1551,13 +1551,14 @@ void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata) set_jump_tgt_here(desc, key_jump_cmd); /* - * create sequence for loading the sector index - * Upper 8B of IV - will be used as sector index - * Lower 8B of IV - will be discarded + * create sequence for loading the sector index / 16B tweak value + * Lower 8B of IV - sector index / tweak lower half + * Upper 8B of IV - upper half of 16B tweak */ append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | (0x20 << LDST_OFFSET_SHIFT)); - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP); + append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | + (0x30 << LDST_OFFSET_SHIFT)); /* Load operation */ append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL | @@ -1566,9 +1567,11 @@ void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata) /* Perform operation */ skcipher_append_src_dst(desc); - /* Store upper 8B of IV */ + /* Store lower 8B and upper 8B of IV */ append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | (0x20 << LDST_OFFSET_SHIFT)); + append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | + (0x30 << LDST_OFFSET_SHIFT)); print_hex_dump_debug("xts skcipher enc shdesc@" __stringify(__LINE__) ": ", DUMP_PREFIX_ADDRESS, 16, 4, @@ -1610,23 +1613,25 @@ void cnstr_shdsc_xts_skcipher_decap(u32 * const desc, struct alginfo *cdata) set_jump_tgt_here(desc, key_jump_cmd); /* - * create sequence for loading the sector index - * Upper 8B of IV - will be used as sector index - * Lower 8B of IV - will be discarded + * create sequence for loading the sector index / 16B tweak value + * Lower 8B of IV - sector index / tweak lower half + * Upper 8B of IV - upper half of 16B tweak */ append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | (0x20 << LDST_OFFSET_SHIFT)); - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP); - + append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | + (0x30 << LDST_OFFSET_SHIFT)); /* Load operation */ append_dec_op1(desc, cdata->algtype); /* Perform operation */ skcipher_append_src_dst(desc); - /* Store upper 8B of IV */ + /* Store lower 8B and upper 8B of IV */ append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | (0x20 << LDST_OFFSET_SHIFT)); + append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | + (0x30 << LDST_OFFSET_SHIFT)); print_hex_dump_debug("xts skcipher dec shdesc@" __stringify(__LINE__) ": ", DUMP_PREFIX_ADDRESS, 16, 4, desc, From patchwork Tue Sep 22 16:03:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 252952 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 393A0C4727C for ; Tue, 22 Sep 2020 16:04:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC739208A9 for ; Tue, 22 Sep 2020 16:04:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="WXQwkRIx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbgIVQEp (ORCPT ); Tue, 22 Sep 2020 12:04:45 -0400 Received: from mail-eopbgr60083.outbound.protection.outlook.com ([40.107.6.83]:40665 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726686AbgIVQEi (ORCPT ); Tue, 22 Sep 2020 12:04:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cvIdZZJ09jqJ4FkSCQ41F81UFnRbz8bgcfIPgE31K9uZ9nr/56qI3eFd4psrs3GPckv3j6q3mTHuSJh3M4X1mAWkFHVReSa5xZ7FEQhdHEhas9JsZsrlPCIUEPum9+Qu2jLaIlfC4vV1NHQDuayw+FA/lH6cTyYlbx5v3SOaHzIP5Vv+8zk0IZ2g2lkYQf5aesI2LnmoBtzLI4Q/SOqwhPf3zvPvUzycoN+X3+LUEYcnQblVcjzLAL8NqOJUZQD4l5xSveHTirl1AerTezvHUHSYOFW9hJjOrbO9YFYF3AxMjBviXmLJgkag0ekQHEkyTSk2Ws6JntfhQRGRM1OXPA== 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=pdmwAi6lysV7Yyany96bcPU+bY7oIv/8W/poR+1o11U=; b=LviCofloKfvwBd+vsRsI0GPAe9f+p8Hq/CrjF46a5SWEDwukUDKNCnUrGEyTo4Mk4+zGpCZ+fb1m2SvmafkHzhnpWFzob9NYH2hlK6bhbTIdkhRvvpj2BQGvWaGI6v/ergU7Rq76Tn6Ih1353q0XY+fRifRQPupADD48/KMm/K6NwMnT36DSJ870G5FF7XWbFJ7JKJCEP8EY/hGNLoGrnufqF+2zk3xvyAb28YFvRg2XmkdQkeblx2k0LPQM2TOwu+519yaEabebzOrDr2shiuT4G1tuNf/sMVa5AgtKtWnD78U0x/zZrLP1dJm+3kpIqwgICnMD8Rgc0WXgqG6OYg== 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=pdmwAi6lysV7Yyany96bcPU+bY7oIv/8W/poR+1o11U=; b=WXQwkRIxsVUeADx/rYoMmSMb5YjZSkzTlKJIY3k9txDusuwK96PFTIZZ8mgIuSONeKaCPfqbmd4Cy/RNiUO/cMhe9CYPAqCxJKOSvGk2XuNeXNnw4xEWWwJan2KH8DhP7nyvnBGtJaKO4b57TC6Y92qrB1ddbinvfs3nj41Cup4= 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 VI1PR04MB7072.eurprd04.prod.outlook.com (2603:10a6:800:12c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Tue, 22 Sep 2020 16:04:07 +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.027; Tue, 22 Sep 2020 16:04:07 +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 v3 09/10] crypto: caam/qi - add support for XTS with 16B IV Date: Tue, 22 Sep 2020 19:03:27 +0300 Message-Id: <20200922160328.28926-10-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200922160328.28926-1-andrei.botila@oss.nxp.com> References: <20200922160328.28926-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) 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 AM4PR0302CA0022.eurprd03.prod.outlook.com (2603:10a6:205:2::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Tue, 22 Sep 2020 16:04:07 +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: b14814fc-2879-4d94-0ca5-08d85f1122c8 X-MS-TrafficTypeDiagnostic: VI1PR04MB7072: 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: aKGVkwk0VrBcJ75Tf8NsSqekfEXqFmZRGS1xNUTkMgsvX4dpwDVta8Vc8WFh9XG4CeV4OZQRu2G7Fvpf3P+X5KKJvZoyOSFvj8je+jM4s5DDapapapik3u3CSfbAg+XctMRY3C/nyWC8vdteCb2Pznj1kOBAih6+OKl4k5YBqBl12M0iHQ/Wqcvcf1bDZQ6ba7XkopD7cS4PyibvX4GFYOwoXftO4INpaRBQvHfqT3ZjziMBoHIcXGs/TN5vHV0GoqCbNf1uKztpGcxefuClaNX73kPMKtfsOlJEk4gp0wRK4JRdYrSINwsnMTNpPQNL/uwb7sHuMyUi5X92WQNMXA== 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)(396003)(376002)(366004)(346002)(39860400002)(136003)(1076003)(4326008)(2616005)(6512007)(83380400001)(186003)(16526019)(2906002)(956004)(5660300002)(66556008)(66476007)(8936002)(316002)(6506007)(44832011)(66946007)(52116002)(6486002)(478600001)(110136005)(8676002)(26005)(86362001)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: w+oHvRNQuuf4V2m3bPNODJMmW5AxCCIg2nK3TM2IjexVoCkzcpbyT41hgyVbNZ4Q9uGwENCsCUv4RJb8H1Pzd6BQzf8vLxmDZxRA7UT9fw0hf0bgLhFEHPzrxyTnrBlpX7H/n11JtHkXv2YERp08Zb1OvS94YUEHwRqdiKQRmIbaRX7CGx9mSZ41raFLxtdALPJPArOe/Jkfbztjh0h/o/IDKeXaRhGjsr2NLW7aiLNap4ZzHmM8rQKzn1FV4X1dbrQe1Oq+FhdXqhduFGT+zezPbv4SunnzCUCHf0WhYzedhDc2H0FVrDofqQgvX/q55HBmbBFLbw6hg94qjXqFbxYZjsnFExxovlEKPZbP1Cd1J0+bJwhd739cXLSUIb7Cseio6zRflcp6cbQXhY8mtBIXXpwFzjF/k/wrO/HG5iShawWBJjJvAC6sXhDmhRblXCeWmBCMOvECqCKVTNLxvz95v5VBxxwIUnGKHFOFcoGjTOydbfiKUXhajIP6qPU0VP+1AAm1a28jy4tu3N9uaao5W2aoq9WGDTTZmZ/OpmFXKKRD4OLfFQxu7BBRzTlO6t8uFT6n1f1tpQi4hY2OVNx2Wc+GTFGAo8w5Swn3+rQBaaHUuyD7OgBJ4uOseiJF4HHC2EyJFpVsgrChZMNLxA== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b14814fc-2879-4d94-0ca5-08d85f1122c8 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2020 16:04:07.7452 (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: 9qMkB6CMQRnW9YxSzPZDD3U9gNQhi2dvZljKhticdNsthiPrRa8AZPY0/fQNmi4j7JPU0aOAN2LDMWrSJ3IuBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7072 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 efcc7cb050fc..66f60d78bdc8 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; @@ -1403,6 +1406,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; /* @@ -1413,7 +1417,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);