Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2396630ybi; Thu, 18 Jul 2019 07:47:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqybruAv8m1hdt4kwPhFR1a6dN3gxSVLRF5zgtYw7JJD1JqEO48Fpg48X/nviz15cc+Qs5xC X-Received: by 2002:a17:90a:b115:: with SMTP id z21mr51434757pjq.64.1563461245801; Thu, 18 Jul 2019 07:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563461245; cv=none; d=google.com; s=arc-20160816; b=y+bXMJNmkJHlNCUA06ZhmLQq7EYFMMA4RuwsVTfNwirEHtFRT8Z4YXrXV1H0ULtOlY mQoC4BD+QEPDT7FjNIQjkGP3fsywQF2/lPDQJbdMIKorW0hyNmzzF4o7c5DdyiP4Ftod zOCZrWRTDF33m7cIfLLm0kve/27Ao3d2UVVuj4yAqO7mUPwgJYFgOwy4c3dZzPZISQ+D k2Os+2adHRA1XU9wD7HagHJBxqxcCEpjCS2ukXu5jjtbMQ6X2fQAfPuHtgVhuw8wWO5p vAbLerMOuoFiKqRe5Rq1RabEHhBvvQoXrgPhko20smu6gkWrhGVzG43qUoAoYpusTJxc nkiA== 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=0PMNHGj3HUlGS+kIMLWquDw2mQLen+mhtplQmtDsMEw=; b=mdZrnxxVpJA6uRWXJvdfTb25jOelUUsafirCXI1I22kuvfz3xCKQEzwfKvhqT3L9AJ gKTsgsVHhHo62yn5ZZuVP3gHcCozEiqcRs7TVRC7f+Vh8YSWF2XPcDDbo9f6nSfCaphy 6Tah7ZyAOv1VaaVvRcMT9FdZzoGQ9T1I1VeVfTCeKVAMCef411HuRlwxuBFMNHi+R4um yjM5Kmx5XuFvlJjnfE4F+JzyOPugKxIOKzuaV6n/IhFKpVQAcrExkrwtK5WoUVImaplA fPVv4VdDGMhVbkY1bO7BrxFcKpW8pIEdc9WDF/3htMqIAFKpVdhFrLpv9FgzAr5OhbPC 6ITQ== 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 x16si1453596plr.214.2019.07.18.07.47.12; Thu, 18 Jul 2019 07:47:25 -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 S2390978AbfGROq3 (ORCPT + 99 others); Thu, 18 Jul 2019 10:46:29 -0400 Received: from inva020.nxp.com ([92.121.34.13]:49466 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbfGROpk (ORCPT ); Thu, 18 Jul 2019 10:45:40 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 987571A02BB; Thu, 18 Jul 2019 16:45:38 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 8B8B81A0006; Thu, 18 Jul 2019 16:45: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 3CED1205C7; Thu, 18 Jul 2019 16:45: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 05/14] crypto: caam - check authsize Date: Thu, 18 Jul 2019 17:45:15 +0300 Message-Id: <1563461124-24641-6-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1563461124-24641-1-git-send-email-iuliana.prodan@nxp.com> References: <1563461124-24641-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 | 14 ++++++++++++++ drivers/crypto/caam/caamalg_qi2.c | 14 ++++++++++++++ drivers/crypto/caam/common_if.c | 40 +++++++++++++++++++++++++++++++++++++++ drivers/crypto/caam/common_if.h | 4 ++++ 5 files changed, 85 insertions(+) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 6ac59b1..6682e67 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -377,6 +377,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); @@ -440,6 +445,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); @@ -504,6 +514,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 46097e3..5f9b14a 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 "common_if.h" /* * crypto alg @@ -371,6 +372,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 +478,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); @@ -581,6 +592,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 da4abf1..0b4de21 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -10,6 +10,7 @@ #include "dpseci_cmd.h" #include "desc_constr.h" #include "error.h" +#include "common_if.h" #include "sg_sw_sec4.h" #include "sg_sw_qm2.h" #include "key_gen.h" @@ -719,6 +720,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 +817,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); @@ -913,6 +924,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/common_if.c b/drivers/crypto/caam/common_if.c index 859d4b4..fcf47e6 100644 --- a/drivers/crypto/caam/common_if.c +++ b/drivers/crypto/caam/common_if.c @@ -26,6 +26,46 @@ int check_aes_keylen(unsigned int keylen) } EXPORT_SYMBOL(check_aes_keylen); +/* + * validate authentication tag for GCM + */ +int check_gcm_authsize(unsigned int authsize) +{ + switch (authsize) { + case 4: + case 8: + case 12: + case 13: + case 14: + case 15: + case 16: + break; + default: + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL(check_gcm_authsize); + +/* + * validate authentication tag for RFC4106 + */ +int check_rfc4106_authsize(unsigned int authsize) +{ + switch (authsize) { + case 8: + case 12: + case 16: + break; + default: + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL(check_rfc4106_authsize); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("FSL CAAM drivers common location"); MODULE_AUTHOR("NXP Semiconductors"); diff --git a/drivers/crypto/caam/common_if.h b/drivers/crypto/caam/common_if.h index 6964ba3..b17386a 100644 --- a/drivers/crypto/caam/common_if.h +++ b/drivers/crypto/caam/common_if.h @@ -10,4 +10,8 @@ int check_aes_keylen(unsigned int keylen); +int check_gcm_authsize(unsigned int authsize); + +int check_rfc4106_authsize(unsigned int authsize); + #endif /* CAAM_COMMON_LOCATION_H */ -- 2.1.0