From patchwork Tue Oct 27 13:45:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 289727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, 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 5FD46C63697 for ; Tue, 27 Oct 2020 15:28:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12518206F4 for ; Tue, 27 Oct 2020 15:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812505; bh=XtdJE6dWAtutXnXj6NmWoMsVjBAWDBhrlV/tcxgTGvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Y6dgK3a4l6uGQx7aSB8tSxY2pe7yosOxW3XsNYBOhVZXVbbdAEKgzj8IuC7YRgczx q1ala6K8LdYSBU+s2tfxSYiM4S3U5o3qNRq6oExGhAZpAT1nPW+QVmZrEA/qZmnRk2 BIJk7K4CAAII2bAKnNkQ1cXxgubmT5sx365GS5Qk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1798501AbgJ0P2V (ORCPT ); Tue, 27 Oct 2020 11:28:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:35736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1797028AbgJ0PVM (ORCPT ); Tue, 27 Oct 2020 11:21:12 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4F9F620728; Tue, 27 Oct 2020 15:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812071; bh=XtdJE6dWAtutXnXj6NmWoMsVjBAWDBhrlV/tcxgTGvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t4b4aEH5XX1lyZjSVamm40m8iwa2CRawIdt1NYQPj2aAzaMWq/8XJWNBQY+PtHFQk FWF+VLEM5izFVEwkFS4d3zCVKLeXVIYpCPLgqPUJpachJsT7XKyacxD66v/JS3PKTd j76jUw9BJXqgMEdg3ne085QFxVMEqsvQRQT+eaho= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrei Botila , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu Subject: [PATCH 5.9 083/757] crypto: caam/qi - add support for more XTS key lengths Date: Tue, 27 Oct 2020 14:45:33 +0100 Message-Id: <20201027135454.444949724@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Andrei Botila commit 62b9a6690926ee199445b23fd46e6349d9057146 upstream. 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 Reviewed-by: Horia Geantă Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/caam/caamalg_qi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -18,6 +18,7 @@ #include "qi.h" #include "jr.h" #include "caamalg_desc.h" +#include #include /* @@ -68,6 +69,7 @@ struct caam_ctx { struct device *qidev; spinlock_t lock; /* Protects multiple init of driver context */ struct caam_drv_ctx *drv_ctx[NUM_OP]; + bool xts_key_fallback; struct crypto_skcipher *fallback; }; @@ -734,11 +736,15 @@ static int xts_skcipher_setkey(struct cr int ret = 0; int err; - if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { + err = xts_verify_key(skcipher, key, keylen); + if (err) { dev_dbg(jrdev, "key size mismatch\n"); - return -EINVAL; + return err; } + if (keylen != 2 * AES_KEYSIZE_128 && keylen != 2 * AES_KEYSIZE_256) + ctx->xts_key_fallback = true; + err = crypto_skcipher_setkey(ctx->fallback, key, keylen); if (err) return err; @@ -1407,7 +1413,8 @@ static inline int skcipher_crypt(struct if (!req->cryptlen && !ctx->fallback) 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);