Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10945035ybi; Thu, 25 Jul 2019 07:26:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWp43rn1MvjiliG3NjE9zKK1M506bvbjgPBXwogY73FRS8vPQQ83SJGsoRxtj6CDBFRXUO X-Received: by 2002:a62:e910:: with SMTP id j16mr17452872pfh.123.1564064789344; Thu, 25 Jul 2019 07:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564064789; cv=none; d=google.com; s=arc-20160816; b=cwWNse3iKYSoYOUw9WW0ITgCkpOkQ9EFLFlNFEBM/gtsmOVjmDiQxBoitt8v4hBitt jJOtZbQzalxixfjpfTSso6nLJ/wUv7CFL3bT14wSZybTqtfvugyXZyK13buWKpRNlLVs +UTtxkrDQg160udkyxCKvxfuIqX4wLfgsMgMOxiqA7A3v19eMQSGxv6sK/m9qh5K9ksp opO7IgJBPc7OARzZu4WbnRKgamlWmioXLnNDE+I1xXOGWvuWkbXK6drzpdCwCZCvYrTT QDpKrCjFsvOrwwYi1XvHUsHTsnoSsTK5PWtzKXtW1f8EbyRv6Mgf6KImXshJ5onHHgkS zD+Q== 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=obsI52WFqrNupr5pBTaAEc/Gw3AX7/XijSLsg4hAnMI=; b=GFqpmlpbk3e+mo+LHDyYm0uPuR2f8uS/dCoJnvZ+m60v1JlX4QgRWsHmKWF8jf1pZs R3R+muH+bycRWkfC57JiniWrmDVrMFK1yfMrnWLmHLb4fnBW2NY2e70K+D7dLieZsvVM XQNOwz4euBiMbSeisX8tclYCFhxVwGpOQ/HHPLK1LVTO9Ur7zQAtRYLGZZlxKL9DvAAW 6QCfb4/Qo0STEPLItR09uszmMLoNUqXyVhkdBwIUevshmTQn4nr/byJTQN19hVrk2G2m cyr5kHa03MZMIDTnIPT/sy1WFBARlXhCEUXaTu7DevP0fJS9+S64M0giuijMwD6VUnjY 6LiQ== 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 o75si17929956pje.87.2019.07.25.07.26.15; Thu, 25 Jul 2019 07:26:29 -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 S2390704AbfGYN7a (ORCPT + 99 others); Thu, 25 Jul 2019 09:59:30 -0400 Received: from inva021.nxp.com ([92.121.34.21]:58346 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404172AbfGYN6l (ORCPT ); Thu, 25 Jul 2019 09:58:41 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 81364200721; Thu, 25 Jul 2019 15:58:38 +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 66F0A20071D; Thu, 25 Jul 2019 15:58:38 +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 13778205E8; Thu, 25 Jul 2019 15:58:38 +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 v3 05/14] crypto: caam - check authsize Date: Thu, 25 Jul 2019 16:58:17 +0300 Message-Id: <1564063106-9552-6-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1564063106-9552-1-git-send-email-iuliana.prodan@nxp.com> References: <1564063106-9552-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 --- 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 d379ea6..dcc1b89 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 = check_gcm_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 = check_rfc4106_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 6d8cdba..8bc7564 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 = check_gcm_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 = check_rfc4106_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 a13d05e..faea744 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 = check_gcm_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 = check_rfc4106_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