From patchwork Mon Aug 5 17:00:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 170589 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4537886ile; Mon, 5 Aug 2019 10:01:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUutdq9XdpB9JPcQYHVq93HzOiTUog5JOM/bCzC87qTpBGaL9Icp/HdFYeIelNm71yZ7d6 X-Received: by 2002:a63:5648:: with SMTP id g8mr20697101pgm.81.1565024510900; Mon, 05 Aug 2019 10:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024510; cv=none; d=google.com; s=arc-20160816; b=BNqHMtjvxi0Wf5VE+f1OYuBP6/RioOFtlc+f99j2rHKTgKrZRRP/s+XMZju8m2o31h bpoqhZgn3Ag/UC2rZeWzEFJkEuHDjdt8JGGow6yYblKOp6Qpcu2yg0hKHLvzlg11W4rI Wgejc4pYiq1/7zGFJw6h+akH2PshTTakWq0tlRbctI0ZYOxVdnGvZSz39RKUdGEQIzSU h0QPptaHtWAVX8Z2Wau1AbPoZeHEMeoc/wgbszs1GrzkA9UCk/fJSiwyNKMM2V7YMHhF GHpkp0HcUEHB5p7gcP9vX2W7udA+s949RHxRxFDIpS8iB0ou06TfJflCgH9g4PEyXCvy SfbQ== 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:dkim-signature; bh=ebKJGCN9vei2NZ41HobpihwjzZEEneemyNbb+2I2Vi4=; b=qMxOYJ+31OIdQ1mtsRqRw8YuDD7K52hqwKwST5W+dMEf8ClsLc8xGpgBMyJOXeAbua mAjYd1JoWScmE6VfcXbdYDOmah1nN2pp2anbHRKJZlsmLtmFf55QF7uZmktcDCutpgmf VIBOYhlPZJMiG/x553knVLWEf53e3Y11QbhoL0SVBbiDCvhFZZHfQaAgjaz/RYDzmzVN pFM8A7VZypT1TXv2QZnSQP7OTrKbAxuxJbkU8w6bPGtzI/P3jKLXWU/eE+V6IapCPgZy kDOo2QfDZV+aPTA0+DzKWVV6gOT4jedASfxUGbcl87bF7xNGPGqbmBKJmXKWu5Hu0OF6 07sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hE16ffik; 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 w10si41995852plq.403.2019.08.05.10.01.50; Mon, 05 Aug 2019 10:01:50 -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=hE16ffik; 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 S1728871AbfHERBu (ORCPT + 3 others); Mon, 5 Aug 2019 13:01:50 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51817 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbfHERBt (ORCPT ); Mon, 5 Aug 2019 13:01:49 -0400 Received: by mail-wm1-f67.google.com with SMTP id 207so75474062wma.1 for ; Mon, 05 Aug 2019 10:01:49 -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; bh=ebKJGCN9vei2NZ41HobpihwjzZEEneemyNbb+2I2Vi4=; b=hE16ffikpFg5KluY4EIhjXP1l87Zw8OlUUUbZDkhnOyQeav0oqhK63QK8ewWaXCsHG 41P4UCw1fNC5kYtkMuJf932qYoefI47AoA6jo1uoZDVleFuCjq1KD/aA/0ZmyayNev3s DS7HXI8GI4BWldcx04nZr0p78/fLsF1BBak3K83zpyAQX0H32vKxuOCwugbc8e6a5vaF SP6r2nwOEj1j+9uZ/JzsRrjtLSCTiIa6ispJS1K8VYf7KTIKz+7QGdNWQxX09/hWAMhd fAbovueVdmYMm8lshk2ES/LXaFBjKChNqeUnfaiHO4MLkCPwUaunBv1GV1R3OgR7sY7C F3Bw== 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; bh=ebKJGCN9vei2NZ41HobpihwjzZEEneemyNbb+2I2Vi4=; b=CYcUUtzJzG/qzCpLONxrdYdoF5K7jqu66O5YFTMfVnAqtzkVlOFydbjdLiW178dJiW HqEChVNsrqO/UPtP4dHFzCP94UAHv9SEVJQe8cTzGc+Z2RYVKiyJgYVoajnbwTYKKF6n ZLlKo6M2EiZgFzCquG3lt6NoRl+PgnKQduT6fFDOwsyNPOEEpUWniwaYHo0pCfInD8bO 8Jl7sKAA7bCCTAQzqTN9K127yfOsNCPj+5Rrbm9IyTvxIWrmCh+maicw56WgCc8x8DdW asC90GbDK8zdwxCNRyUiuu6vj5IviAVq9/PJYqnUXDQRQPwWoz6SyAz2QsE9wb7FIniS C03A== X-Gm-Message-State: APjAAAUV1rNU86Yju+iwSX4H36ve+PuRDxfagalMiYAV2r3FZez9RYdF nsVBn1J7Z0ynhs6w1iMDZQkRSakP72ydYQ== X-Received: by 2002:a1c:5f87:: with SMTP id t129mr20677270wmb.150.1565024508294; Mon, 05 Aug 2019 10:01:48 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:a407:da00:582f:8334:9cd9:7241]) by smtp.gmail.com with ESMTPSA id j9sm95669383wrn.81.2019.08.05.10.01.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 10:01:47 -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 v4 13/30] crypto: safexcel/des - switch to new verification routines Date: Mon, 5 Aug 2019 20:00:20 +0300 Message-Id: <20190805170037.31330-14-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190805170037.31330-1-ard.biesheuvel@linaro.org> References: <20190805170037.31330-1-ard.biesheuvel@linaro.org> 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/inside-secure/safexcel_cipher.c | 27 ++++++-------------- 1 file changed, 8 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c index 477e0ec35f45..b49e7587ba07 100644 --- a/drivers/crypto/inside-secure/safexcel_cipher.c +++ b/drivers/crypto/inside-secure/safexcel_cipher.c @@ -219,7 +219,6 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key, struct safexcel_crypto_priv *priv = ctx->priv; struct crypto_authenc_keys keys; struct crypto_aes_ctx aes; - u32 flags; int err = -EINVAL; if (crypto_authenc_extractkeys(&keys, key, len) != 0) @@ -238,12 +237,10 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key, /* Encryption key */ switch (ctx->alg) { case SAFEXCEL_3DES: - if (keys.enckeylen != 24) + if (keys.enckeylen != DES3_EDE_KEY_SIZE) goto badkey; - flags = crypto_aead_get_flags(ctfm); - err = __des3_verify_key(&flags, keys.enckey); - crypto_aead_set_flags(ctfm, flags); - + err = crypto_des3_ede_verify_key(crypto_aead_tfm(ctfm), + keys.enckey); if (unlikely(err)) goto badkey_expflags; break; @@ -1191,19 +1188,11 @@ static int safexcel_des_setkey(struct crypto_skcipher *ctfm, const u8 *key, { struct crypto_tfm *tfm = crypto_skcipher_tfm(ctfm); struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); - u32 tmp[DES_EXPKEY_WORDS]; int ret; - if (len != DES_KEY_SIZE) { - crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } - - ret = des_ekey(tmp, key); - if (!ret && (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + ret = crypto_des_verify_key(tfm, key); + if (ret) + return ret; /* if context exits and key changed, need to invalidate it */ if (ctx->base.ctxr_dma) @@ -1301,8 +1290,8 @@ static int safexcel_des3_ede_setkey(struct crypto_skcipher *ctfm, struct safexcel_cipher_ctx *ctx = crypto_skcipher_ctx(ctfm); int err; - err = des3_verify_key(ctfm, key); - if (unlikely(err)) + err = crypto_des3_ede_verify_key(crypto_skcipher_tfm(ctfm), key); + if (err) return err; /* if context exits and key changed, need to invalidate it */