From patchwork Thu Jun 27 12:03:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167960 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2249872ilk; Thu, 27 Jun 2019 05:03:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuMyA4xnYiUMJA5BJxnQwg6RDV1JR4dzETI6TB0qDIdj/D/WtnpCoijniYK8b3ewTxuah1 X-Received: by 2002:a17:902:7448:: with SMTP id e8mr4357412plt.222.1561637034808; Thu, 27 Jun 2019 05:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561637034; cv=none; d=google.com; s=arc-20160816; b=UbM9ejLzQS2PqsoqoWdET+nnwneUQMNsV3UBKBXzmsBgSOIIXzOBnmLtuOEO1Q4fgy tEUxq1Sdzvpe4TuS8uIijN7uN8sceWIhAc9E8liAOP+SW80P8RRA3rfEH//YnINy9Asy yGq5El872AfcBfghFmkclt4uNvMLWCNQ/xqnvH967Cm4Dsk+zvuY3DXKbN595Tlt+zaa KBD0VZhVFef+GRv9kqTUzxjVizJu+x3xmRXxQ/OPndHhf9zzfvsGPZONoFdUEDzduBLP XcoSfPwZ3a3w1BiafendmAAzNvnjMKx4zC7m1gkpoP9W+/GCt0SUNJy2zzdEvcUXEglN I4oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K+e75pqvyX8YF44FDsxuzr3TRtIJEnQtyvl35LqdHDo=; b=ilvVTi1bhnu+IOoqi8ap7FjQOpzkmay3T/N4lcTXkkwnnFVH/pDqiz0w2gFPWA55bV LfdhRj60LPBbC4xhyn2X5gJ0UESEGOfnrc8+kASdDOmFoJxzqWnKcUoMecKNTU4SWaoY sLDamxKMgKpDZGSBxmHWZN9oCYAvr6jdE2yE3Z4b2z0IsMpLPiigEMi5r0XBgO+TpLUc HAMPXjUtjmSLiskjbbPc+MwSCaznDhX5SAZS+GmluQw1lusuEI/kxSBP34rHGGzpfZAO uAgbxeK57p1C9pxvF7UUIilX1pPv28xIb+e5pE8VoTBC8CwyIeyN+554ecXmfNwwqS5s Xkng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZZmIZvX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 100si2163460pla.158.2019.06.27.05.03.54; Thu, 27 Jun 2019 05:03:54 -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; dkim=pass header.i=@linaro.org header.s=google header.b=MZZmIZvX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbfF0MDx (ORCPT + 3 others); Thu, 27 Jun 2019 08:03:53 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40678 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbfF0MDw (ORCPT ); Thu, 27 Jun 2019 08:03:52 -0400 Received: by mail-wm1-f65.google.com with SMTP id v19so5399139wmj.5 for ; Thu, 27 Jun 2019 05:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K+e75pqvyX8YF44FDsxuzr3TRtIJEnQtyvl35LqdHDo=; b=MZZmIZvX5I7gzj2TvovtkfJh2LpPobIOIvy3y/rOcoR4z8HzpGrDMeW2I3eWAYhWnY OpvoVzF7CnplEpEzTQmJVFgdIp9CUwxKuwhhZnREfp6mYMmoFUg/pjwxz4qsv20fIZhD N0LGjNBKX3Fwp3RNJRxPzX5Bhzxpk3ZhhBn8RjSzcPT/dRViT1ECmxTtJBlGDy4Om7L8 immsLupNgMR5Urs5spn3nVktSrkzHyeH8W/pzMVB6x5cHTKEXhKbk0q+J+9kh/bgdXUY Qy3sk4dmOTv/8WvhIV9zEEaLEnDYEA8jXRzxCrJ4Sh8Js1v3ogWZkHsXuRH8GqV1QDca K3oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K+e75pqvyX8YF44FDsxuzr3TRtIJEnQtyvl35LqdHDo=; b=p9p6WrP+iyHTDZY6Msot4AGpo0Ik0466OQSGaWmb5cuzkcc4UPks5UYf3E7j9oZNrB 37J1yLHfQZhB+uRINFIOZnYEc39AOubi5lEqNlzo/Lg6HAdKuYGtKdQx3dmZdReQAL9M YHF4KgwDsNKwPHEA+MoZ6JxlKvQ8VZiiDEQ6ZeuxlPfz1YfQBTn8s/jvxs7o7xE5o3eV sTlDhVo0OC+KRoWmUQ0xUHVyUBWXHoY0BXFbXsXAxdhfs0ZYqXF/iEqVz5ofU7dJ9ESh Eb+0FbCSJF9hCtkTdyRBgbRVl4TGt7DQ5tsr1AlgB6opDBEzTQ3K9rY/l63OVAZyge1T ZpCg== X-Gm-Message-State: APjAAAXUWKWWYfL/tojbqIvxdGVypanU+hb7oZBafpI7aeOqQ1oTXfmJ 7OjnWenWDbAMEdx6P4THReqfNtpF2npowA== X-Received: by 2002:a7b:c347:: with SMTP id l7mr2910218wmj.163.1561637031148; Thu, 27 Jun 2019 05:03:51 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id z126sm7732431wmb.32.2019.06.27.05.03.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 05:03:50 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@kernel.org, horia.geanta@nxp.com, Ard Biesheuvel Subject: [PATCH v2 23/30] crypto: talitos/des - switch to new verification routines Date: Thu, 27 Jun 2019 14:03:07 +0200 Message-Id: <20190627120314.7197-24-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190627120314.7197-1-ard.biesheuvel@linaro.org> References: <20190627120314.7197-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Signed-off-by: Ard Biesheuvel --- drivers/crypto/talitos.c | 28 +++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) -- 2.20.1 diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index c865f5d5eaba..022292aed9f9 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include #include @@ -923,12 +923,9 @@ static int aead_des3_setkey(struct crypto_aead *authenc, if (keys.enckeylen != DES3_EDE_KEY_SIZE) goto badkey; - flags = crypto_aead_get_flags(authenc); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(authenc, flags); + err = crypto_des3_ede_verify_key(crypto_aead_tfm(authenc), keys.enckey); + if (unlikely(err)) goto out; - } if (ctx->keylen) dma_unmap_single(dev, ctx->dma_key, ctx->keylen, DMA_TO_DEVICE); @@ -1538,14 +1535,11 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *cipher, static int ablkcipher_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - u32 tmp[DES_EXPKEY_WORDS]; + int err; - if (unlikely(crypto_ablkcipher_get_flags(cipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) && - !des_ekey(tmp, key)) { - crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; - } + err = crypto_des_verify_key(crypto_ablkcipher_tfm(cipher), key); + if (unlikely(err)) + return err; return ablkcipher_setkey(cipher, key, keylen); } @@ -1553,15 +1547,11 @@ static int ablkcipher_des_setkey(struct crypto_ablkcipher *cipher, static int ablkcipher_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - u32 flags; int err; - flags = crypto_ablkcipher_get_flags(cipher); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(cipher, flags); + err = crypto_des3_ede_verify_key(crypto_ablkcipher_tfm(cipher), key); + if (unlikely(err)) return err; - } return ablkcipher_setkey(cipher, key, keylen); }