From patchwork Sat Jun 22 00:30:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167437 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1376674ilk; Fri, 21 Jun 2019 17:32:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDr0zVVhZZREZyzpK1zSXu7qog6qiT2SMwJNe8fQmVkg4oFqFNrCH1FHOJmMB2O9PZIiin X-Received: by 2002:a17:90a:a00d:: with SMTP id q13mr9937630pjp.80.1561163520834; Fri, 21 Jun 2019 17:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561163520; cv=none; d=google.com; s=arc-20160816; b=uiUgi6+nGHZfdRvnECeYo7UxlhES1N4N4Xy3E0Zvy/3UCJFFigyx90HTGeLY5/JiYI 3xxXmhmWwWGDvGYhuDirIkH/954uxyF4u/cWm1x7V1aDOLVW/Y4XtULpv8bxE6M5I058 MZBGGxzY6v9CPXkTBaY0YuKPVgOMwwEB0sLMjvz7ITrlQ08sLCK4qoUqDhwl4DrnJYNs /jcHKeWmmQEt7TXegHt0zEypGzS8GeIOXCm8+RbatQdcvlgDAU/OZ20OUSowkt0MVUDZ /R7Odllos68A+1I+bHkG7dJT+05e0+twDKsK08ErYlObb+nkNvwRg24C0h0Yg3jfkfQN FeaA== 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=I5vcNvV5pKsNXmEt0eCjUJ4deAdaj9PR1+fxGr7yxD8=; b=GJ7UWzxurnbQMR9ibXmSsZpQ8GzhzBauLJhvmZsdOblZucqmYlHJBkNUuDAQhE4JHo fJi1swGQ4XKaGMqzoQ9aQbVUilgsEfs9745TF5zKv2H+mVy/3MF+qeon9GdNUZUDQ0Cy KJ3W6iLLelP1Ni4jGcLpHZwuGP2/ZSZ4XWBlfxeDAvhNxyGzZXlPGm8I+IPML6Y6CnL1 VVzrwV+ZeVHWCydNLN4Eb9cjOg+fSbrv1tBa/s/NbGb0n8M+ZCGvLapEszx+Ejvat0Fv chf8Ez7gGpHdhbal7MH9C5KB/i/SeM8uSCXd0jCh82UNFHxBYsF3ONSz6qQZQd+s5ZKd cJjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ElYHiGYq; 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 v10si4096271plg.320.2019.06.21.17.32.00; Fri, 21 Jun 2019 17:32:00 -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=ElYHiGYq; 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 S1726202AbfFVAcA (ORCPT + 3 others); Fri, 21 Jun 2019 20:32:00 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35811 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726049AbfFVAb7 (ORCPT ); Fri, 21 Jun 2019 20:31:59 -0400 Received: by mail-wr1-f68.google.com with SMTP id m3so8142294wrv.2 for ; Fri, 21 Jun 2019 17:31:58 -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=I5vcNvV5pKsNXmEt0eCjUJ4deAdaj9PR1+fxGr7yxD8=; b=ElYHiGYqrNfyG5oAsejxiKcl1Cs/6X2b/n4a6+SidJfAxwyxZqMHLd0TtMy4xYFBKN 8YoeRfAqLH7nzSQzrnKCn3Bizunten2kEwvLaAZFMcAjxcSfKMSVx9Kfjle3vcV2XaQ2 RqWI6xiuIyFUBaydP43880AMd/Xahd5UqGx0XiADRK7MXManUlo8ECbMPBEyPrT+XY4b 0EukO1IjSFIMV48CbgHImjT5PJjwdg8zkqFdCqRJhQav+g1fZ+91hVAMRgUsNGclO+JO tEtZy08USEBHJgosNBs2pMn4WTFij+hhMD+FEKwy4wggItVVH+2oYst1jf7GrWaoP1ur egZA== 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=I5vcNvV5pKsNXmEt0eCjUJ4deAdaj9PR1+fxGr7yxD8=; b=iETuGDt1JahI3CbEPU40hxQxS2A9fm/dpXc1eeNAlVTW1X7cyE7IQhAs29CQ1Bpmzo yGMKUkXwAks9xOUxSrV9i4bcDtikLBMUYi39nVg1TKD8CtiRtudQv73NngUDpONbHwHC r4z1P9wEyiK5oKpq68C9e9CYIAT7G5crOuvbEKK8ulopL2KL+zKcRmkoAG6ixlF5MgbK P2CNxKA7d1lJrjV1frmI2qCxRSZABjhVeajtHkDVDZxP/ta7pZwc6OTwoJ0Mq/M8QMJE Rt7wOCeIsscQJ+EZVb7pZNCx8rA1M6F+bCMvGNIbhhtZkVy1nqg9lvLXsdQk01RUhwWm cZ4g== X-Gm-Message-State: APjAAAVq55EKB7np1U0Di15J0uYvGVxPg1Su7NO3oJGyirISs74t6TFc W/68Ls4vtt+FPwK60YLt4O+4zBXVQmafiSba X-Received: by 2002:adf:f181:: with SMTP id h1mr2508620wro.18.1561163516946; Fri, 21 Jun 2019 17:31:56 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:99d4:1ff0:ed6:dfbb]) by smtp.gmail.com with ESMTPSA id v18sm4792019wrd.51.2019.06.21.17.31.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 17:31:56 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@google.com, Ard Biesheuvel Subject: [RFC PATCH 12/30] crypto: hisilicon/des - switch to new verification routines Date: Sat, 22 Jun 2019 02:30:54 +0200 Message-Id: <20190622003112.31033-13-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190622003112.31033-1-ard.biesheuvel@linaro.org> References: <20190622003112.31033-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/hisilicon/sec/sec_algs.c | 34 ++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/drivers/crypto/hisilicon/sec/sec_algs.c b/drivers/crypto/hisilicon/sec/sec_algs.c index 02768af0dccd..7d563188d80c 100644 --- a/drivers/crypto/hisilicon/sec/sec_algs.c +++ b/drivers/crypto/hisilicon/sec/sec_algs.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -347,8 +347,11 @@ static int sec_alg_skcipher_setkey_aes_xts(struct crypto_skcipher *tfm, static int sec_alg_skcipher_setkey_des_ecb(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - if (keylen != DES_KEY_SIZE) - return -EINVAL; + int err; + + err = crypto_des_verify_key(crypto_skcipher_tfm(tfm), key, keylen); + if (unlikely(err)) + return err; return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_ECB_64); } @@ -356,8 +359,11 @@ static int sec_alg_skcipher_setkey_des_ecb(struct crypto_skcipher *tfm, static int sec_alg_skcipher_setkey_des_cbc(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - if (keylen != DES_KEY_SIZE) - return -EINVAL; + int err; + + err = crypto_des_verify_key(crypto_skcipher_tfm(tfm), key, keylen); + if (unlikely(err)) + return err; return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_CBC_64); } @@ -365,16 +371,26 @@ static int sec_alg_skcipher_setkey_des_cbc(struct crypto_skcipher *tfm, static int sec_alg_skcipher_setkey_3des_ecb(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - return unlikely(des3_verify_key(tfm, key)) ?: - sec_alg_skcipher_setkey(tfm, key, keylen, + int err; + + err = crypto_des3_ede_verify_key(crypto_skcipher_tfm(tfm), key, keylen); + if (unlikely(err)) + return err; + + return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_3DES_ECB_192_3KEY); } static int sec_alg_skcipher_setkey_3des_cbc(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - return unlikely(des3_verify_key(tfm, key)) ?: - sec_alg_skcipher_setkey(tfm, key, keylen, + int err; + + err = crypto_des3_ede_verify_key(crypto_skcipher_tfm(tfm), key, keylen); + if (unlikely(err)) + return err; + + return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_3DES_CBC_192_3KEY); }