Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5962899ybi; Wed, 31 Jul 2019 06:10:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGvjPHSTUKVVtV4T9eIGBKwt5GFRv9xTYbAge3x2cMdwELUcIMuHNUJUJG5CzssYGqU3Zi X-Received: by 2002:a63:a302:: with SMTP id s2mr8384248pge.125.1564578617643; Wed, 31 Jul 2019 06:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564578617; cv=none; d=google.com; s=arc-20160816; b=IWCIVj/ZBK4cgWZm01jOXIjmoEOBVtDAsXOR2hw2wvfpKhZjDlyuj7ZcCmgMgU8/nG Dn3qODkgVo7MTid7UAWtrZ5vcp21uY6/rG2PONkMyxSY9+d2CovMmVDUT9uNpXY1lEyS clDHr48b8+2oINxls5ZVrEaIIhWZSybyVLlmA5dkxpZma4KUSiaA/RUOqv090t0ALKeZ aK/NTTEQsdcWSkpRvFwbXfOW3MnZ3WFYprC7w8K3vVZaDkmAjhUbIGf/eeigllZtuDOo bDaTlGbB2BUTpjHZxF9aYAlbXWZZgrxdLs/fpAEixJu/3PFimCxkpeaJ2Y7oqRC9Ld8s 14QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=AHnW0Nzf7PorFJwL0Meovf7I1uEmxaxsnablUtr5DZs=; b=QvP8RB2d3fKpxkvOjSXm4S+JcfT6a80/WhtctWsCxyaDNNnmbcZWLhneh4gjn0Hikt ogq8FhAkYpxPM1fcR24HbX9y9hs2BqCqS8Dl8XjxiRmsMGQg79v1gjKcQppaNj6d7XEY lBzB6nsldCoP8bWBKEETciZU163IAtRJIbhgvnhRp4uIem8T/9R871cFv6ak7aWVjroE b/Cr1BF301ybUK8BjRQHY0kfeBHpVAytNoC6S6Tsf1n+8mvbEJ+wCr2MXEM5wt+um7ya /WvYAri/CU/0H5l8gnFRgIavq12T8GmWgdQ/6kqslZoD7QQ9fotio1C4K9/oXdFM5Mp2 vpuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13si793418pgb.533.2019.07.31.06.10.04; Wed, 31 Jul 2019 06:10:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388125AbfGaNIZ (ORCPT + 99 others); Wed, 31 Jul 2019 09:08:25 -0400 Received: from inva021.nxp.com ([92.121.34.21]:42766 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729233AbfGaNIZ (ORCPT ); Wed, 31 Jul 2019 09:08:25 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id DA6FC200A25; Wed, 31 Jul 2019 15:08:22 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id CDE78200A23; Wed, 31 Jul 2019 15:08:22 +0200 (CEST) Received: from lorenz.ea.freescale.net (lorenz.ea.freescale.net [10.171.71.5]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 7A4EA205F3; Wed, 31 Jul 2019 15:08:22 +0200 (CEST) From: Iuliana Prodan To: Herbert Xu , Horia Geanta , Aymen Sghaier Cc: "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx Subject: [PATCH v5 05/14] crypto: caam - check authsize Date: Wed, 31 Jul 2019 16:08:06 +0300 Message-Id: <1564578495-9883-6-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1564578495-9883-1-git-send-email-iuliana.prodan@nxp.com> References: <1564578495-9883-1-git-send-email-iuliana.prodan@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Check authsize to solve the extra tests that expect -EINVAL to be returned when the authentication tag size is not valid. Validated authsize for GCM, RFC4106 and RFC4543. Signed-off-by: Iuliana Prodan Reviewed-by: Horia Geanta --- drivers/crypto/caam/caamalg.c | 13 +++++++++++++ drivers/crypto/caam/caamalg_qi.c | 13 +++++++++++++ drivers/crypto/caam/caamalg_qi2.c | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index ce50ae1..5919069 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -376,6 +376,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + int err; + + err = crypto_gcm_check_authsize(authsize); + if (err) + return err; ctx->authsize = authsize; gcm_set_sh_desc(authenc); @@ -439,6 +444,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + int err; + + err = crypto_rfc4106_check_authsize(authsize); + if (err) + return err; ctx->authsize = authsize; rfc4106_set_sh_desc(authenc); @@ -503,6 +513,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc, { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + if (authsize != 16) + return -EINVAL; + ctx->authsize = authsize; rfc4543_set_sh_desc(authenc); diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index b8854f2..6c69f54 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -371,6 +371,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + int err; + + err = crypto_gcm_check_authsize(authsize); + if (err) + return err; ctx->authsize = authsize; gcm_set_sh_desc(authenc); @@ -472,6 +477,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + int err; + + err = crypto_rfc4106_check_authsize(authsize); + if (err) + return err; ctx->authsize = authsize; rfc4106_set_sh_desc(authenc); @@ -578,6 +588,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc, { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + if (authsize != 16) + return -EINVAL; + ctx->authsize = authsize; rfc4543_set_sh_desc(authenc); diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index fd38639..b5baa17 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -719,6 +719,11 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + int err; + + err = crypto_gcm_check_authsize(authsize); + if (err) + return err; ctx->authsize = authsize; gcm_set_sh_desc(authenc); @@ -811,6 +816,11 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + int err; + + err = crypto_rfc4106_check_authsize(authsize); + if (err) + return err; ctx->authsize = authsize; rfc4106_set_sh_desc(authenc); @@ -910,6 +920,9 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc, { struct caam_ctx *ctx = crypto_aead_ctx(authenc); + if (authsize != 16) + return -EINVAL; + ctx->authsize = authsize; rfc4543_set_sh_desc(authenc); -- 2.1.0