From patchwork Tue Jul 2 16:48:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 168339 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp4130194ock; Tue, 2 Jul 2019 09:48:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaU19VxAEg22JdrDvzDaQf0odB//jWlnmB1/V1YqTJq266ljO/93O0aZk2YSQqOojrYqDO X-Received: by 2002:a17:90a:bd8c:: with SMTP id z12mr6684111pjr.60.1562086117715; Tue, 02 Jul 2019 09:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562086117; cv=none; d=google.com; s=arc-20160816; b=byMzXwZAALgj/ZBOqKn7hpjWwlnt6+Y4mgkBevbzpU4kcMNgma0dcSPlJi/w2X4MRm 9c/GXEjJiwcxLPScF2QMMoLA8v2g5RBWUiOP7vW8et/jCR8herGGPLxHevkSyMdK6kV4 6pGOaDQwONqMpA2EIVa81YUv+sgGwWkor6B8KIA/2Je6zpHPSioLhxlDumPIIbrpPweu XR5JSK15qx6nxbKXTsqacRZNflchT64uKDDVnthvUS683zHZkTcIPu45V/3hISxpW3/H ojGn0tK9/a/wknKlagPz1baAq5QbI5OMMWLmqZG9JHDMY3AI7+edktgajj9bNNXOEOTk FvaQ== 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=HomCk1VsjwBWm0dP9ApxcCmxBO/okyV8Fp4po7N++dQ=; b=YeKIsGHO7KwVqhQYvpCUeQTl+wWeYrbUaY5qNocezmhh9LaoFZqOuuQz32YXjeqo1b 8vK48+zF3bk/0MhD7fc9etDnOoQPpjGG+diZxkNAfxHBu0cR71P6WeV2KeHDod32u4kb I1vHyWp6XQywxFVvlxYxS5fPf99d8oM833n8Tyl3roL02wDGOqZAu+6vRnn+Jbu7OkB4 p25PHaArzqFFS6xYP51FpmW2lZ/9QMBCrn2OPECBqXvgPMRrxNRCdcTjHvLHput9Hqqy TpE0OJS3+SjeeE8k2AuIh20cmWYTwjgQg3EMySS4NL3LrJA/n6DWlTScwi5otDARvalI b3bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kGbzR475; 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 k21si3770572pls.202.2019.07.02.09.48.37; Tue, 02 Jul 2019 09:48:37 -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=kGbzR475; 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 S1726736AbfGBQsh (ORCPT + 3 others); Tue, 2 Jul 2019 12:48:37 -0400 Received: from mail-lf1-f54.google.com ([209.85.167.54]:46175 "EHLO mail-lf1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbfGBQsf (ORCPT ); Tue, 2 Jul 2019 12:48:35 -0400 Received: by mail-lf1-f54.google.com with SMTP id z15so11867764lfh.13 for ; Tue, 02 Jul 2019 09:48:34 -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=HomCk1VsjwBWm0dP9ApxcCmxBO/okyV8Fp4po7N++dQ=; b=kGbzR475Fk1fnv5DaMFggiI54T2jNgT0VfoTwrbGvLoGWXuBb84+6vXzgRGOv3lHD3 pFnmstTbfqpQ3r+5GGapEUM/AFpcxk1qkqCeD/hYJeQv1nXCsioGDiiz3vB+0qwkUf+x ymm9GqdyrQz69UDZoUR/o3Lg3cqzx2dd6s5sOcugMOF2FGSh7IWDv75ds/N4sd+iDJEq 7Fd6DawFuubuNNR5DGCqGtRSre8yWN6EkF8UYPrGv0+ShfCwt2iUIDRn3/5YMvTHaUAf BueHb4O6F8TB4SWbLJtd55hq0gO6UOPrvWy3MG9jktf1tU9K5nqa5QkeFwkQWcwbLY9v bUdw== 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=HomCk1VsjwBWm0dP9ApxcCmxBO/okyV8Fp4po7N++dQ=; b=dK9+dInT/K5KYzP57X6wpIEsHHDGxXCrdvmI/o0f24zLkvKW2xviGMsPP9I5HYU4z1 Er9nzFs7t3Rul3R+5NQT1np6OvTu1vVKnXS1X1RGLEXaNMaQMrc617sTceM4O0fCmZmI 944mdRASPAxmVbcpcwDk+Tgh8J9CHk+NxQ2UQ+aTHEFqxuw+LDCRqSvjjh/jc2AjXH8p eyoWTva3gmWK4NHIH96MslmNuPS+ihXg5OvucDXmCKUGXwz68a33WoeRtkx/8yOI0Qn0 tRriQrFv7JoI+At55HV3nyaFAu0K+yD5DFPEGDUCLm3p4GZshbYXkFp6cTojoVakW1y2 dDWg== X-Gm-Message-State: APjAAAVxaKm++kK96aaUtzMmhGbkkIJigXbuAnDNKR2eyq16q6ac7IZ2 uxPwieRjCMLGV46J1tWJieTTKUqgVeFJs2a7 X-Received: by 2002:a19:41cc:: with SMTP id o195mr13813141lfa.166.1562086113634; Tue, 02 Jul 2019 09:48:33 -0700 (PDT) Received: from e111045-lin.arm.com (89-212-78-239.static.t-2.net. [89.212.78.239]) by smtp.gmail.com with ESMTPSA id r17sm3906055ljc.85.2019.07.02.09.48.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 09:48:33 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , Eric Biggers , dm-devel@redhat.com, linux-fscrypt@vger.kernel.org, Gilad Ben-Yossef , Milan Broz Subject: [PATCH v7 3/7] md: dm-crypt: infer ESSIV block cipher from cipher string directly Date: Tue, 2 Jul 2019 18:48:11 +0200 Message-Id: <20190702164815.6341-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702164815.6341-1-ard.biesheuvel@linaro.org> References: <20190702164815.6341-1-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of allocating a crypto skcipher tfm 'foo' and attempting to infer the encapsulated block cipher from the driver's 'name' field, directly parse the string that we used to allocated the tfm. These are always identical (unless the allocation failed, in which case we bail anyway), but using the string allows us to use it in the allocation, which is something we will need when switching to the 'essiv' crypto API template. Reviewed-by: Milan Broz Signed-off-by: Ard Biesheuvel --- drivers/md/dm-crypt.c | 41 +++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) -- 2.17.1 diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 1b16d34bb785..3c17d588f6db 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -2321,25 +2321,17 @@ static int crypt_ctr_ivmode(struct dm_target *ti, const char *ivmode) * The cc->cipher is currently used only in ESSIV. * This should be probably done by crypto-api calls (once available...) */ -static int crypt_ctr_blkdev_cipher(struct crypt_config *cc) +static int crypt_ctr_blkdev_cipher(struct crypt_config *cc, char *alg_name) { - const char *alg_name = NULL; char *start, *end; if (crypt_integrity_aead(cc)) { - alg_name = crypto_tfm_alg_name(crypto_aead_tfm(any_tfm_aead(cc))); - if (!alg_name) - return -EINVAL; if (crypt_integrity_hmac(cc)) { alg_name = strchr(alg_name, ','); if (!alg_name) return -EINVAL; } alg_name++; - } else { - alg_name = crypto_tfm_alg_name(crypto_skcipher_tfm(any_tfm(cc))); - if (!alg_name) - return -EINVAL; } start = strchr(alg_name, '('); @@ -2434,32 +2426,35 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key if (*ivmode && !strcmp(*ivmode, "lmk")) cc->tfms_count = 64; - cc->key_parts = cc->tfms_count; - - /* Allocate cipher */ - ret = crypt_alloc_tfms(cc, cipher_api); - if (ret < 0) { - ti->error = "Error allocating crypto tfm"; - return ret; - } - /* Alloc AEAD, can be used only in new format. */ if (crypt_integrity_aead(cc)) { ret = crypt_ctr_auth_cipher(cc, cipher_api); if (ret < 0) { ti->error = "Invalid AEAD cipher spec"; return -ENOMEM; - } - cc->iv_size = crypto_aead_ivsize(any_tfm_aead(cc)); - } else - cc->iv_size = crypto_skcipher_ivsize(any_tfm(cc)); + } + } - ret = crypt_ctr_blkdev_cipher(cc); + ret = crypt_ctr_blkdev_cipher(cc, cipher_api); if (ret < 0) { ti->error = "Cannot allocate cipher string"; return -ENOMEM; } + cc->key_parts = cc->tfms_count; + + /* Allocate cipher */ + ret = crypt_alloc_tfms(cc, cipher_api); + if (ret < 0) { + ti->error = "Error allocating crypto tfm"; + return ret; + } + + if (crypt_integrity_aead(cc)) + cc->iv_size = crypto_aead_ivsize(any_tfm_aead(cc)); + else + cc->iv_size = crypto_skcipher_ivsize(any_tfm(cc)); + return 0; }