From patchwork Thu Aug 6 16:35:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 253205 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=-10.2 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=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 82C19C433E0 for ; Thu, 6 Aug 2020 16:39:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7FA023125 for ; Thu, 6 Aug 2020 16:39:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="PEqDAAwr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728068AbgHFQif (ORCPT ); Thu, 6 Aug 2020 12:38:35 -0400 Received: from mail-am6eur05on2053.outbound.protection.outlook.com ([40.107.22.53]:9601 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729036AbgHFQhB (ORCPT ); Thu, 6 Aug 2020 12:37:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B8/obt20CWh5g1ecCxs/S69a/b50G0jwdGtmhkKE/pOjUdSzLnBEKTPsV6uGR+WjgkVaUJDTKUILXWbcNuPVqb5NRF62ez18NxdQ1TqofdZXAU50PJFc39YUJFwFc/5Rr89oMVQNmKQYMRO9WwfItTfc03GKxuhrdVb4j7qU1wJjGLRLsClsmlIxxH2Cu4dKzFr7eOU61CkwjnLK8rkWnMAcy8+Hd85mNt4M51ewkUSXBEXRLgxc0kwJJc6OgITW8OLPnIVopxCPxRTVssTVUvrIe/6dX/q7jkN7RcwHUi7qeaCEZLyYLK9ViDSDwA2jYPclFvSboeM1TSuyoxX2OQ== 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=rUOaFR+51/hMGHZ1OqrVUqDtVfGLQpzNtoWYvUv9n6w=; b=LpQzAtWQdO3zoAlFKRUA6kZzMeW3wZFKPXNKH1PB4kvIhcgMJ6OpmuMGDXccwfT5u84CWEm9Ct6xPD3mj4q66fP2LMJyJWK1lBoXgdlSXxUhNR1gVDsu3H0s8Qwfhd3KxpezV67nAlamIlcgs4qiFLm4N3fcQWl67y0AjBZFexN/xsvMPKBYAiVz2kQOBhXiaFWbV/HofitKqFOwK1g6AG6AQI1SO1VK0/+a8/bO5lOht0TbkC4Gs6/wbz5dfgm6SGaQUJJvTmKkSWoSn1j5aq7b/yDEP8W+jfaj7HzorIsrc8+A1UWtz1HvXS1gh3Li2yoU4XQD+MC0uoIxMt/GJA== 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=rUOaFR+51/hMGHZ1OqrVUqDtVfGLQpzNtoWYvUv9n6w=; b=PEqDAAwr7b0HXuI47FTStIxNvFpRrnyvPUq1uVmx9ntF7O+HhHI8siCMTFCQSt2CTvCsj5DWzigF5R3eVBfSmpXypNn/qhj1eVO5a/3yskbELLGGu2C5IogBt/lmApijzEMI9BL68ls0r2JtJmh30NVw8rGR3YFCinleLksf+jw= 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 VI1PR04MB4992.eurprd04.prod.outlook.com (2603:10a6:803:51::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 6 Aug 2020 16:36:10 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d%6]) with mapi id 15.20.3261.019; Thu, 6 Aug 2020 16:36:10 +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 RESEND 1/9] crypto: caam/jr - add fallback for XTS with more than 8B IV Date: Thu, 6 Aug 2020 19:35:43 +0300 Message-Id: <20200806163551.14395-2-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806163551.14395-1-andrei.botila@oss.nxp.com> References: <20200806163551.14395-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) 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 AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Thu, 6 Aug 2020 16:36:09 +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: ba56a126-2b9d-4643-c115-08d83a26d381 X-MS-TrafficTypeDiagnostic: VI1PR04MB4992: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2887; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nEn9/B5WclBZ7EN8nhd5jhsq/lCLspOTEj7Jzo/Q/nDQbKN69P9y7JEG5U+Ov+2pYcb8DpmMlu2mbf/dOPzrVa2KUXxceZ2rIfYKECMdEW+WDPBD103NEqZtJNWms06IJi2n/8zFofCW9lpegSeGRX4PCrt8W2aZwHBbwtjP2SzpJ9Oq28bZIZZCuT2l9MuYGdIiG+FKA438BB1kBm2CaMCIfyZx7CZgKJwiaEU6wGfEfravA8Zx0jn0a6o/M3rRoBaoxPmobvLDFa8P96kzvnNYGYClwrRvDzg7q0Ri2CYMem+W+r4DJvYl979dZ5nWDvlYHhsNdo3kFRorxXSqJo23s8YfqdOkL1mtxtjqcNUowM/Dxu+JxaypCLw+73j9 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; SFTY:; SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(66476007)(86362001)(26005)(6512007)(16526019)(186003)(66556008)(66946007)(1076003)(110136005)(8936002)(316002)(8676002)(478600001)(2906002)(6506007)(4326008)(44832011)(2616005)(956004)(83380400001)(6486002)(6666004)(52116002)(5660300002)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: YKY3eCy5mEwT8lfHc+Cli9irCmYElX1TBmtUm95BWSjRd5AgyqFOFBWATmb/F0EObJCYpV+3FVRM/UlqpCYXfVYBksfVMltQjethe+DacbFPjvh7IgFCNFL3QS8qf7Qitbt+rScnKTJb46/vMSMCGnCV29r2bxx3D+/Q5IvGQcbzAs8Yug5/jEbVbyUT7ooEpmOfJU10rAJxwWvGSc94bnLKhJHDNJf8CKeMbhywZEG7PkPd1G26jWM2RXjtA4+6YjP9JKeL73A0z1/m+EQRX2ENAGpF4CVoYl1T+MK+WFwLzBDcepCTmWT2nn6VS+XPDZ2LcjrR2etRjdjkvrq0y7Q89Eqtof9YnrNUD5RNr+wolxu42DeBkYB6tudBQXsRmdff904Eu1j9d4biCW1c1MXMiM2IMxrW/WuFpviNdAmXGEXPFkzGHfxBvGS3DWXIs4L38XpZdQ9gvXgLnKNrOUjIh81o/tjSSzqS4lUkZTtwu6DwS1vXIzwgvbHq2QUMyfZ8CEEc6DN3drpZEDbFFrUl3e6j3MxE7wXxPzotUaqTymBH9iExntLVn73dkDzqCS64NSn9i7pQB+Dvlv77lZ6Wv68HDpBHHFsxsZzVWNHrnSPD1SCOneTX0zTj+J7/Q26i+G/eI67rpAiPvS9HBg== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba56a126-2b9d-4643-c115-08d83a26d381 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2020 16:36:10.5898 (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: hkRbcUCloYrCLw5VuU85iIxYGdOXViBt601MH/RoDI3ri1RKdFqNXVTO+52NDvyfBXMn9URZc/1sSJdrtiBkLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4992 Sender: linux-crypto-owner@vger.kernel.org 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/caamalg.c | 68 ++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 91feda5b63f6..ebf4dc87ca2e 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,20 @@ static int skcipher_do_one_req(struct crypto_engine *engine, void *areq) return ret; } +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; + + if (IS_ALIGNED((unsigned long)req->iv, __alignof__(u64))) + size = *(u64 *)(req->iv + (ivsize / 2)); + else + 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; @@ -1768,6 +1790,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 +1942,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,12 +3382,30 @@ 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); + u32 alg_aai = caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_skcipher_req_ctx)); ctx->enginectx.op.do_one_request = skcipher_do_one_req; - return caam_init_common(crypto_skcipher_ctx(tfm), &caam_alg->caam, + 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)) { + pr_err("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)); + } + + return caam_init_common(ctx, &caam_alg->caam, false); } @@ -3378,7 +3434,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 +3472,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 Thu Aug 6 16:35:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 253196 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=-13.0 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 E4352C433E0 for ; Thu, 6 Aug 2020 17:46:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B5E5206B2 for ; Thu, 6 Aug 2020 17:46:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="L8BkBjPT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728023AbgHFRqy (ORCPT ); Thu, 6 Aug 2020 13:46:54 -0400 Received: from mail-eopbgr20062.outbound.protection.outlook.com ([40.107.2.62]:57504 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728919AbgHFQh1 (ORCPT ); Thu, 6 Aug 2020 12:37:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D1y00xQoTgVZwvVHEZHnCMmcMgIMPJH2dNiqbLA5ARCUW5amCJrfeUAtLaP9rb2+KTNtN2nEuw9l9AE+3hKxfE7m2kUy25Tav0YbhgC0prK18NVCfGkt406KMce3b4sIvZAb2trmJpU/KELUHvwMEJ7Nzzig+uio/uZbu9TBVZoC6XiS7SKyTE1vkknIHCuLxAuQWLm+9iG0NxW5OZl9/9HzHFxlkkZFXTBpgwot9Z/7co47yO4qaloXcgN5lDWjVOtu/nrBJkBQ2olvGPxRD4Yomcpg/fEz1uL8K68F8QQuEJx+WnaKOgmK26QTRrUvt+cUiwB3chuiQdBNfJfLgQ== 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=NG2G62cTP09RqCfsYGO6Dz0qWH/f02540G3LYJKbnCY=; b=YarYoQ0+Jm2PxGtV+O+3JA4Fkm42oKiIZUwdgSifrxjudZh57ozP1LX1YRSZ7B7QTuyO705Prd3TGazqWCd/6vjvNUblWfYoX0WNZVO3MbznN1DX7gyTn0anG7bzHYeDM/+8Mk3AuV97gsCILIiRWpPcF55VL8t3OSO/1F5W0VUHbt2wQFp+43KxV/LONDDSUCLPotqstL3GMk5Di8kwEY9U5bLmo5niEAEwIXF818jD3F6qBORRlzI/+LvAtgy2FxhYtVDziBmHu+08v3XDTS2KbdhbUoX4K3R95ETyUiIYgYDsI/WjUhLPvTLdRsvvGU9CUW7r2BfbaXB/nV7aqQ== 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=NG2G62cTP09RqCfsYGO6Dz0qWH/f02540G3LYJKbnCY=; b=L8BkBjPTCBZrZ0qA9ZicXYY+KJyIzZg7SC1d/Y4jL/O1e06zbIp05iFg7BJ3zNDylsYQ+oBraBXAQzU5LCwhg6OktlB7gUJXfLGq97ap5gREUZGPET23GKsHP8kof4FLx1Btgv9SZUTVUhWsdB6+Aij367z0T0JnhR/xw7YGQBM= 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 VI1PR04MB4992.eurprd04.prod.outlook.com (2603:10a6:803:51::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 6 Aug 2020 16:36:14 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d%6]) with mapi id 15.20.3261.019; Thu, 6 Aug 2020 16:36:14 +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 RESEND 3/9] crypto: caam/qi2 - add fallback for XTS with more than 8B IV Date: Thu, 6 Aug 2020 19:35:45 +0300 Message-Id: <20200806163551.14395-4-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806163551.14395-1-andrei.botila@oss.nxp.com> References: <20200806163551.14395-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) 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 AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Thu, 6 Aug 2020 16:36:13 +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: 6d48b07f-4ba4-49ed-a879-08d83a26d5cb X-MS-TrafficTypeDiagnostic: VI1PR04MB4992: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tMuCEIIvzl66aLMT/SieQygwtxeo9kODObOi7jg429+QUiGGNrXus55tkpGOymRScoMF/aO7Usxqdi97ODn/NfRxhAUDqFBqYeG6WVYZ2d9NHBqtNLNeJ4SE4y5e1nMf+mNm6iq6fM0HYR0lIhtTLn8mKUA8JvkbQCAe0ctcf+ZjVK4G4LSJEYaW33oNEU2VRWs4u+vg/g8xUyebiujevCpJFCGxXDOqZW/4RsIfPBMbYUkNsPj3nWBaGK/GK0shKuuj0EphlnzJea5PvwMD81rwKIMavKPvWnbk146R84i8t2Yz2JhQ9EwKYGoKX+G7PPjQ3y3L7QvMVeLoS0dWPdYbiTPxxICmMAXaQG//ra2GTVpvJ38fuBbCCYgz5Ph/ 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; SFTY:; SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(66476007)(86362001)(26005)(6512007)(16526019)(186003)(66556008)(66946007)(1076003)(110136005)(8936002)(316002)(8676002)(478600001)(2906002)(6506007)(4326008)(44832011)(2616005)(956004)(83380400001)(6486002)(6666004)(52116002)(5660300002)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1RPuCCQP99Ztp5gCImHlNVdIe8M/MzdJJnx/6DgyI4znqHTafpE8HYusv2XdIYoKqLj7HruvWPZhLtEARt7dvJnC18Dz8J9oZj1EVhwqCeBXDYBUl3Uq5IMitV8+rGHTuIG19htTvWAmzi2kS7tjFpGQbZHZLXEK2a0r6WMuZDOQhsj655kHolmVlsP4Nhe6CQrvXe5sKSAJF39fg4otqrP3yWdjlhI4J33hbk1OZpAlcip0vyeXnpnyN5eGCliYKOpHIYhEz+u1DESACL2UyouGV56Vikx/aCC7vvNtu4g9ss3dBgOs2PBm3QhBoEK2+IMxbBfAVQJG4BtpyQAhOiVHtgCoCkkYof7TLFOI3+LIJTUdfgrIl6730YMKvILh5V7AiXJI3R55JAlnB7xPXrOTpUjOsUoW+lXCZF8IN/8F6qcqqT3KTyiVxGJcjnyJ+5SBtj0IFodETHfzxr5QKePZZdvQH41N+I9/Oi5iEw2leISwRuQjR+gu/m2mxJKDCIME/38aZW/hGhSCkxhkTpPCQWdPwV7D+xP/14Sgt2LYfhXwYJEpdHJhA8vCigqgSL9PmO3kJ/OZEV9N743Kzm+hoId6TkGxfSQTuSpAeC2utmUizNQaW4xUWU6nOi+1ECyMDOrlneTXFyQIIGCp6Q== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d48b07f-4ba4-49ed-a879-08d83a26d5cb X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2020 16:36:14.4356 (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: 2lAWihSl2V7tqzyOruGmWDe4hgZ7VAgh2iCUI6jqV5mf2oaFXyYuDVnIPBPsLCIQF4i7VdP8isgLgwLIQCeLsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4992 Sender: linux-crypto-owner@vger.kernel.org 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/caamalg_qi2.c | 79 +++++++++++++++++++++++++++++-- drivers/crypto/caam/caamalg_qi2.h | 2 + 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index 66ae1d581168..a0b13bf6b528 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,20 @@ 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; + + if (IS_ALIGNED((unsigned long)req->iv, __alignof__(u64))) + size = *(u64 *)(req->iv + (ivsize / 2)); + else + size = get_unaligned((u64 *)(req->iv + (ivsize / 2))); + + return !!size; +} + static int skcipher_encrypt(struct skcipher_request *req) { struct skcipher_edesc *edesc; @@ -1454,6 +1475,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 +1517,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 +1583,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; crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_request)); - return caam_cra_init(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)) { + pr_err("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_request) + + crypto_skcipher_reqsize(fallback)); + } + + return caam_cra_init(ctx, &caam_alg->caam, false); } static int caam_cra_init_aead(struct crypto_aead *tfm) @@ -1562,7 +1628,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 +1735,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 +2983,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 Thu Aug 6 16:35:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 253204 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=-13.0 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, 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 CEBB7C433DF for ; Thu, 6 Aug 2020 16:41:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F3362311A for ; Thu, 6 Aug 2020 16:41:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="Jy6yHHYd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728740AbgHFQkl (ORCPT ); Thu, 6 Aug 2020 12:40:41 -0400 Received: from mail-eopbgr20041.outbound.protection.outlook.com ([40.107.2.41]:26854 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728211AbgHFQik (ORCPT ); Thu, 6 Aug 2020 12:38:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HPmuvwC0Tk1nSSB2O2YKuAEr5A6U++eFK8x5qkfwS3W0EuHMzl1OGdAPXaZwA1p+XOCpC67+NO6HFUdF2wKs+nxkg2M8UawP8ZBg4TSwGmqMrrC+rmBKiLef18WQVyf/I9qq+GrU4bY2hifgYboGq8xUrXIULTSo+kSWLBp0AsY9efkZ43ttsshRHXK9f11vUFWGpECZsqgi/4Fz6hDbq9Y3cDCwa/v0xh51V8r9JWAFqsoXxNNf6v0qC5Zs+pGnFPvepHNhFrCKxxEBcF0Hyapc7ouT/UAdMfvt4xBlOi23DAXVy/I/LPUaBQ4r8j/WnMp8oiMU+B/pHrKw2wnG0A== 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=R6DWGyZrcAc23RA5Q5rukWQiiaO8jxUB3Q0Ppn4lOOc=; b=n2IuKtMHcdMT8B8m5hErMgblSlN+VnsejLZicPJVRnq4XKsWmlKQR+p+kYQDb3D+12xcXVK3zuYyMsKQpVOnnONZTBb4FLY3eqw9iYdPRLW0Rx28t58blFAblj2v+4P7R20+y8cwr5aqwOZ59CF1PBnAFMwz2VZobYfUr7qFS9A54ULTD+RA4moE0J6mnZFoNgfyzPWnjYAWQW7D6Mjz0n026vFT06l2suSgtS7Tuazw/bdOZEOb/vVfB9eXBi4AP86yF9cyudtG1a0Nau2r6BgT0DBd5kEALL+NsNabzCpVd7fHIsssqvmJNfeXQFot+o11mJc6nxZQk4+5WdQCLg== 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=R6DWGyZrcAc23RA5Q5rukWQiiaO8jxUB3Q0Ppn4lOOc=; b=Jy6yHHYdLUDnUVzhL4g24prjFe0l9FQWT3/GfmWawTCJle4zgm7XuMihIte3PlTHzXzp3dhov7gGEdyHeX6Hg95gBiolTi5DFLUFqirvI5USSBsZlxfiTmk+6kX8sbJC/06C6NJXYZYJI9Mi2rGWFX7it60jVKV9yut/BsSH17A= 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 VI1PR04MB4992.eurprd04.prod.outlook.com (2603:10a6:803:51::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 6 Aug 2020 16:36:18 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d%6]) with mapi id 15.20.3261.019; Thu, 6 Aug 2020 16:36:18 +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 RESEND 5/9] crypto: caam/qi - add support for more XTS key lengths Date: Thu, 6 Aug 2020 19:35:47 +0300 Message-Id: <20200806163551.14395-6-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806163551.14395-1-andrei.botila@oss.nxp.com> References: <20200806163551.14395-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) 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 AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Thu, 6 Aug 2020 16:36:17 +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: 300b8447-c9c1-40d6-5f36-08d83a26d822 X-MS-TrafficTypeDiagnostic: VI1PR04MB4992: 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: rQR5yrT0MsZvZTk7j+hK0kq1/WtWRwAMVUpoWNYUqm3z7AN643RCjHluoLcp7XqfQe3n7Hac4QrqaZe6jT2IVvxbv+qi7oCrjqMEn+mtVIM1O+/c411bm8L0VNZ20uXRQT83vZioJuRGGYt8why95lSvJdMm6matDQminKObCymb/vzFuul5Z0jaWgEK5O/pIbWdi31JXOUGyibREiSERdf4pMum85ygKLzlNDzxOqw+g8NnlzHT8rGOW548+ceTrfturoIebFrNLsLPiKcHrsweCNn3A1Y/2E1T7YsdtJ/A7Tbk/J8lvKFwyfl9BgT95pivUoilvZBYmxCYQ8tmlw== 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; SFTY:; SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(66476007)(86362001)(26005)(6512007)(16526019)(186003)(66556008)(66946007)(1076003)(110136005)(8936002)(316002)(8676002)(478600001)(2906002)(6506007)(4326008)(44832011)(2616005)(956004)(83380400001)(6486002)(6666004)(52116002)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1H+n//K6n5Nx+I/122KVhPeLFUEtjoAjmhw75i9CpIxFXOZeFCDGEZU3qdbj31tNhUXTwi7WVlpLBHplHm75hDa3pr1PZmMHQpBBnA1mM0i7rVD1H9zoJ15zDM0V3cjW2dfUjAdHygc2DIU6gTGBVyG1bRgaVz4uLGQhnc7pWnoqvNxHTjUfYjee2lXUkxmIXJP8ltZzX6aDTimqMiXzgjXRi1tnPbeCP5NfFE0RRs7Bg5g3cRsLRdSN6sJens90UFBIAqd7d8ccsakAEQB1VlYlz+leso9J1iNcinqzTbf9Zq0pXC3E9akcFD9Ir1/6uUVU40VZr+GfrsL4Bc/6dzAMO2Ru8b8ZjCcmEpfMaRf2gusEXqv24jGdnzfwQeoSCfWgVlII14PxO42y+mFrSOfRJcioR8yH0Lst4BLqFnoM8IyR1X72yr2bmMyjdoV/nyN2Rhhjzns/mD9dfMIZKNBJN+RZZsfYwwid/y9A67YmEHQaFEyeUhdzNeTnKmzCJDPKk4am90JmOmVbbk9j8KxubbR9lMhF31AsU9vnWOCfEjewSFaQQzDVrAMfxlPLz7QqToufb6Z9DFiMnOrxry/MRFa6z6atXB1F/inDHE0WedAarQ1EoSIMdF6MnjqbV4RVGxtJrMsQu/Ypp/iHAg== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 300b8447-c9c1-40d6-5f36-08d83a26d822 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2020 16:36:18.3553 (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: 7bMCyWRHXQcJKXBtmcVqQlnm0wMupvrhbIRumQmwhoYkHgngb03Z+G2ZC2nCcYq93W9Pk3jIqyTTHVJ7LkQL9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4992 Sender: linux-crypto-owner@vger.kernel.org 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index 05cb50561381..1d775a55fcf5 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 /* @@ -734,9 +735,10 @@ 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; } err = crypto_skcipher_setkey(ctx->fallback, key, keylen); @@ -1408,7 +1410,9 @@ 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->cdata.keylen != 2 * AES_KEYSIZE_128 && + ctx->cdata.keylen != 2 * AES_KEYSIZE_256))) { struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req); skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); From patchwork Thu Aug 6 16:35:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Botila X-Patchwork-Id: 253197 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=-13.0 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 7B4BBC433E1 for ; Thu, 6 Aug 2020 17:46:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C011F206B2 for ; Thu, 6 Aug 2020 17:46: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="Nx8Ed/wB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730222AbgHFRpX (ORCPT ); Thu, 6 Aug 2020 13:45:23 -0400 Received: from mail-db8eur05on2045.outbound.protection.outlook.com ([40.107.20.45]:21984 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728973AbgHFQid (ORCPT ); Thu, 6 Aug 2020 12:38:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wq9i+MsSsbXnMznX0BrExpsutyEjWyAWMptx/r4sUGbyXJN4Oz5Kn9wtpAHZgXdh4H8Pgjrv7gm4Q5ejP9lTOhyslOtsf+Zayve4tFyDaRhZJudLf5P6X0sMh24Rs3lC0oiyFElkme+9MZhpE5BKyHgbqvmV1Si917xTtRY7AGX0XX/kbkeYswCGjGg0w1299bC/CK+aiSrzCn7v7+L+TP+zDNEEj7kj5fKGyH31vhdmKDH1+AuQUcr6bSJMrKlbH9XwaH9Lr07jUefkwV350Bj6en5hnfDRTtxC+MjA+XWDSDEgIfW8uhWvRq2pdV+YzOQigpF+Hljdfb6LlSnd8A== 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=HgZtPL4Ibx4wosYkqrEpR4/2iTIOpPK1UPEReGFUPoc=; b=AcmFGvCSgZzgtlyFms2hZbcE+7kI/lYvdc3uBVBpTF/iJ8LLxdbeo4DouiWO1CjAjqiYWb/l0l93Jlq8yItwMBQr1BIOAa/zdOKs9KIfAvrKsso3bpUGgIzpklLsc3M2rMVntymJjb7v8i20QvCNXln39tuxCvi5SFWn+fH87hDgnP8i2WjU1wqnK72LQkFjU6s9naeihQcUtFXgisU32omzp1QtrzlF516cq2c9MXrFsG/W5szrnY/0f71VQn8kUEKTO4R0X4b5JebW5aDG/WsUBDnzk6bnkpAhPAQqGTBcDsIb6uIVeNEbAwXY9/OMYfEattuCGLXh4Eunxgzj2Q== 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=HgZtPL4Ibx4wosYkqrEpR4/2iTIOpPK1UPEReGFUPoc=; b=Nx8Ed/wBrAR1SrJ2uD9weVt24bLEnUh9menpStJeRbqKEsPZnoO8t07OCykZQIRbZTCyxQcTqEnwT5nu1DEwza9xlLl0WNBLc3kxchW/UqV+nTnvhNLIctlg996k+wbcvbyBTB4GC2xIyfrR5aBcMzeIZmAiXo+I5ZMuxfmsmvs= 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 VI1PR04MB6959.eurprd04.prod.outlook.com (2603:10a6:803:139::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20; Thu, 6 Aug 2020 16:36:24 +0000 Received: from VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d]) by VE1PR04MB6608.eurprd04.prod.outlook.com ([fe80::a856:c104:11c7:258d%6]) with mapi id 15.20.3261.019; Thu, 6 Aug 2020 16:36: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 RESEND 8/9] crypto: caam/qi - add support for XTS with 16B IV Date: Thu, 6 Aug 2020 19:35:50 +0300 Message-Id: <20200806163551.14395-9-andrei.botila@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806163551.14395-1-andrei.botila@oss.nxp.com> References: <20200806163551.14395-1-andrei.botila@oss.nxp.com> X-ClientProxiedBy: AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) 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 AM4PR0902CA0015.eurprd09.prod.outlook.com (2603:10a6:200:9b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Thu, 6 Aug 2020 16:36: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: 48ca1fea-dac6-481c-fd82-08d83a26db91 X-MS-TrafficTypeDiagnostic: VI1PR04MB6959: 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: SGV1s/nVHnfHTaLOy0J4g3b+7ViKm5jgKcrWPknigje+z3ZZcyKw8P+YnzVwBPfxpIi6fBOA45ctvgQJCR3mULVMmahGLINs2B7W/XHqp7khyaxWUvV2jhTKUd/WhfcCh2+/rGtIIFBaOg1D/bpEweAshPtBbI5ovl7WRaKECN8IEo6uGtvThr6FyH5mRsQjYVyeVzyPwufOEoaa4zpXLS3LZ/ZB0UXBTNOLP/xsMtU5JMVmpyBDsGgcbidqnvipLQz/qNj464WZyGGytb4cpLgREseF3vlEvlJvQ88K9QOjiTwt9uDVN3g5hARiZUvHV6GqPoVpdsATStOgcIRRZQ== 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; SFTY:; SFS:(4636009)(376002)(346002)(136003)(396003)(39860400002)(366004)(186003)(2906002)(16526019)(6486002)(8676002)(4326008)(6512007)(26005)(83380400001)(5660300002)(2616005)(956004)(6506007)(478600001)(8936002)(44832011)(66946007)(316002)(86362001)(66476007)(66556008)(110136005)(1076003)(6666004)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Muss0W++fF65bqTOVQv2LZADiRuNLRxIGLhgR+c1FQ11GiujXqBWsTB23hJ1F3sRSxSYCFWla5go3UogWTJPbmvXQwFAuwWTpuuq33F+w8Pz95jlnGPE5PAYu+zLsmZkYO4G/dwsIA2fZE+VhZefHxGWLd/c6c6nOg8ss+MKJUczHuB7QlqRwjU4fWQAOPA+YUdr4+eLzyEjBWZ2Xbdf8Oc8Gs038r+LwGx7YUbZfC5RpWR6wPkNGjtn34hJ5r3bL/5gN7rV+QtcqOw/ctb/tDStLnlWRfseWuBpQLGOjqdJAMPjw4RXd4YMuJ9kFIw9STR2HI7kgj99lU3SYCQNJ8V5LEYYRU2vKyRZSCaz6W+y1L63WbieEPuhb81lW2yII1VQBIjsHXTUpPL1qnWPji3h4YP6TohbgDvNFck4xgJHpgLQmaNWgEB+nIiDSk6P9LZ30s32y4B0NiitvPLzEapde6vBOZpjqx113cW5nL1tp1Kb7JMmyj5T6cnKWpZWNJp8rYa9ND87gGO6vTKanYMLP3mi9oRLBT8PSKXeDYS1ELuSr9if4+YiK25zeVHhE2x+jo1/B9v2/dilPg68Qq73A6lTmQMfVtQxDICN0fP1wVA5OTcXadx+tcPbnzR28RDClS22p80vE+tb5KQ8/g== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48ca1fea-dac6-481c-fd82-08d83a26db91 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6608.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2020 16:36:24.1220 (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: 3lR+Z4cv16GoAK7ls0EzKP1A+rOPKyiiZNNugocySfnJsawINjGq6cBNFRPr7NlE009Gtb4+CJXE0EA8PY8Hcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6959 Sender: linux-crypto-owner@vger.kernel.org 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index 1d775a55fcf5..df58a899e97d 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -732,6 +732,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; @@ -741,9 +742,12 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, return err; } - err = crypto_skcipher_setkey(ctx->fallback, key, keylen); - if (err) - return err; + if (ctrlpriv->era <= 8 || (keylen != 2 * AES_KEYSIZE_128 && + keylen != 2 * AES_KEYSIZE_256)) { + err = crypto_skcipher_setkey(ctx->fallback, key, keylen); + if (err) + return err; + } ctx->cdata.keylen = keylen; ctx->cdata.key_virt = key; @@ -1405,12 +1409,13 @@ 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; if (!req->cryptlen) return 0; - if (ctx->fallback && (xts_skcipher_ivsize(req) || + if (ctx->fallback && ((ctrlpriv->era <= 8 && xts_skcipher_ivsize(req)) || (ctx->cdata.keylen != 2 * AES_KEYSIZE_128 && ctx->cdata.keylen != 2 * AES_KEYSIZE_256))) { struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req);