From patchwork Thu Jun 27 12:02:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167945 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2249642ilk; Thu, 27 Jun 2019 05:03:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKSFLLizbD5d96isyBuAfi9j/arWuMuB7Hbi0rzH7EvCcf6JV77v9AjgjKaGwbIhd8SXD8 X-Received: by 2002:a65:5c0a:: with SMTP id u10mr3573558pgr.412.1561637025909; Thu, 27 Jun 2019 05:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561637025; cv=none; d=google.com; s=arc-20160816; b=M3I+to1S9yuxw/vr5M2lFbt73cjP92zdjOzUpHSr55HuzbaoZkAKU/pDKNRNKgqXwy l6dgRK6jWDzknyajA0uxh6FsdQ1XJmE8OSQAssdlbx5OF7KQQLy7FlkggHqYpp8NqSSn yH89sqkmNnRI84q81suNWciUnZY6TXBqE4grP0VUnDmz+XHuJaFwblM2WxGTcWsL0TxM W6L3zX3nD7i5u9L5s21vHS0unGs47DC19U+ZFJjrWHgGuFdKJSXPzEYhflC98gddGRNL f38phaGB0ePcvyXaImoLTK32qnc3X+i+FK3lECyAuXmAfSjMWQY6AnsFcAkPNXCrmDIn F1Ww== 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=5HboD4VROuuvSQnBndoFi8xj33eFhhiW3nT7m1ffU7k=; b=htmWSiEOcOvxPIf1tdOKnrikHhNtII1xBhS5eKlGYD9I9zyJo2Em3MW1BHHYSL2HCJ hMk4Z1hMFk+oK9X4VejngtGg2QcTu1k+DLZ7L76tA5KXpRL3iy5swtTaJYgJiEqqEaTO 6mBzf5Au2KI1SvZNeFxSfMe2Tk4BFUmub6gUrbEjF+tH7VVgN8VqGRXBwGkk8f9FMxlc syBIU44/ctorV4n7Iha+jH8kkULhu9nJyOIkCQm4lLjlH4fOVvfcbmoTL+ZyjC6sNAp9 c4xyUBUdICyoPifv9bfrAuhf+8jtm8Ppyf1pbWxwDuNjjUg0VQm3VDP3vpqQsWT/dpKC ErvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GJhQ+Fpq; 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 m39si2229121plg.155.2019.06.27.05.03.45; Thu, 27 Jun 2019 05:03:45 -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=GJhQ+Fpq; 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 S1726681AbfF0MDo (ORCPT + 3 others); Thu, 27 Jun 2019 08:03:44 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38009 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbfF0MDm (ORCPT ); Thu, 27 Jun 2019 08:03:42 -0400 Received: by mail-wm1-f66.google.com with SMTP id s15so5396632wmj.3 for ; Thu, 27 Jun 2019 05:03:40 -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=5HboD4VROuuvSQnBndoFi8xj33eFhhiW3nT7m1ffU7k=; b=GJhQ+FpqiHab2q5JhLnWlOyLkAry3iAr9aalzJlVBsh1Hcjxv325F1Bf9LzD/qa0Ea 4rPX2/Vxhz/pWtDM396oz6BFsNIazAXKh7qW+Z7pzZmyQ5L/rJUc7qzA3hCOEQ+PkoDz C+rn1fpBNo5ZTMccCSSFAkyaZgRm8jTHG3FejczhsXeymnD6ruiTuh1fLc+Ye2L+johb 7wrzfuz5zh9WEaQfyG3DFuH25HJDeRosEI3E0gSx1gHoXIQj76YjKiIbybzQmbizzN8q hO7Xv8Lt8MpC5MlYcbv5j37b5ynKWQVLUCjUikNQ/kqsOfOZEJF/f5rM4N7f4fRxMo3J nPUQ== 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=5HboD4VROuuvSQnBndoFi8xj33eFhhiW3nT7m1ffU7k=; b=oDizvcdMuAj1fS58AjTWNntq5qlANn2XqDGBxZsFrfZ46hpZlM89ye7PM3QJ4OmlA1 8A7UvIODkPwl57x/9Jf+zcd6xc3oDmGCNT6lwmFKsKk3JdBNbegEj6cYlgs4CzNpcTBe 5fg1vA/M6/omP8JcZEBkci6v5+ABEeawQkeVCesIgyR2Bqj3ha1QzFyNFa5undmTw119 h635Qx1ktR7hXNZYS0aMtyWt07Cb+/Lw6mG4cSgFDazapxOMvQYJOU22zI2rAZkH2O/e owsQW5mmdWHUNUKm+cyhOm+vSlw/9G3MmbXILPagcS3DLDx4PQ6ZmlQYgMZuTC8EIi88 jleg== X-Gm-Message-State: APjAAAUUWl0OP4vKKrtLid+zEagSn8Wrb9nQU1Ns6drtwNjBHvOyrfSd CaNhbAMgtSw1nrTiIa5Nho5wOsNyrN8hgg== X-Received: by 2002:a1c:a483:: with SMTP id n125mr2957518wme.3.1561637019648; Thu, 27 Jun 2019 05:03:39 -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.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 05:03:38 -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 12/30] crypto: hisilicon/des - switch to new verification routines Date: Thu, 27 Jun 2019 14:02:56 +0200 Message-Id: <20190627120314.7197-13-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/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..0dc828b9c4a1 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); + 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); + 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); + 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); + if (unlikely(err)) + return err; + + return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_3DES_CBC_192_3KEY); }