From patchwork Tue Jun 18 21:27:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167200 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4728861ilk; Tue, 18 Jun 2019 14:28:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqBCgIzPpM78eQfFw05cBZiLRorcKpSFq/uhMq+770F9ogJsMxIex79x6JkqOzhI2jo0uk X-Received: by 2002:a62:750c:: with SMTP id q12mr102931640pfc.59.1560893292457; Tue, 18 Jun 2019 14:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560893292; cv=none; d=google.com; s=arc-20160816; b=u7MewQr8ETVMfRYHToUwJBQmtdJbLskZTQXrkEwz0LDrrHs2mDuZGDQRia6k48dPtH RveLmyfde7H0+6gdj5CZOtgzXsunT2XOOr2jx9TLZIDnw9TlUBAKx8q4lQuqEuj891f6 23LnnJyCPGqw4HMgXNQXixHyd7z+oSfQ5Py2+BO+e7upxoZQvkY+t4W2dv8zLO8wgNAp omBhXvSv5UtNIUo/RwfCTgfcfLtrhsYmAbwBWMKGfLWQxmf3kMzMMYTBEhcNIaOCVvuD Qn89msm7MjvmUzVtvCGJqfRIPWBOQhgbBaKPqFy8QFXYCdQDIaGPrv/uXVpYXr+MiNj5 gSZQ== 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=GeHdLEIiKMp7/1v0iGs3g+X9QZKIHHe69xTr11ESOuo=; b=iJbOEAcNRvhQMbXw5HDZxxbKAquJY/TeTuiwHJdvxExVF+OzxZ2H8pnZct46ArJGek EeRjgumMVURJhcs+hTaKzm/v6/1KeTgI8YrH6kLU477vZOl8c/I4cPj9auDZBTVRIp4I 80uToIZWiArmGw/wJSMH0SMvyJR42NdaA5n7R+6iVCo/oA3HTFetmyjzlnWKBMb4aEDm EqIK6q3HFoN0LEu8etDsr8DkDIo6to1ENNg+gZNprkDykWRg6Wrflx7PE15EY4Lk4+T8 mW/xE7A7T/9GkDru6H0lMqdkombNzzG4H3pn0FfmeEXoFU8OIDmkOLjGdTl22Q24Y9zb 9kdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DpMBBmk2; 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 m11si3179923pjs.35.2019.06.18.14.28.12; Tue, 18 Jun 2019 14:28:12 -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=DpMBBmk2; 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 S1730102AbfFRV2L (ORCPT + 3 others); Tue, 18 Jun 2019 17:28:11 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35194 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730181AbfFRV2K (ORCPT ); Tue, 18 Jun 2019 17:28:10 -0400 Received: by mail-wr1-f66.google.com with SMTP id m3so1077590wrv.2 for ; Tue, 18 Jun 2019 14:28:09 -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=GeHdLEIiKMp7/1v0iGs3g+X9QZKIHHe69xTr11ESOuo=; b=DpMBBmk2kGfOoo1UtTp/w94N831+KzjoBk3fn3kDgIehYo2zHzDHet8G50UyVgSnkj Ri7viZOAMYnfQlbiBROYFUGsC8zcCtmfXSojqaDC9MzX4vaRpw5QI1V7asBop9WLTO2j wsEA2nLW8zhKKaQAAQWnZVPMSfYDBaz3KDsD9NkzSLcwkCl3/rCc5C0YcN0DwoBmkVkU TocNSZisIrDSrXt8tigpeHNZ1KIumRySoF5YEILpwiYVKrvvJfFabZyDI3kUKVvF60am 48ebFFYnCX04XSgYR/7FBhetbNqG9K2Xiw996Fh3tdv1+8ayMXQ/loeD4ES2iuwF1b0F FXAA== 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=GeHdLEIiKMp7/1v0iGs3g+X9QZKIHHe69xTr11ESOuo=; b=c5qvrZSiPdrIDpjwQuNP4DNeF++c0+j5qSpMceylaj1cqhouJPmaD9pdQKReyjY454 HQG5yAmHg3GKHQ2HlpeLPmeNNJh+rlNHUGl/8NZZL28y3nW8UoWHUmRx71w0LNsRrUjF PojnB1leCip/74d11DZ5iGtvqjoiIt6t6kp61p0BZrl23xZT7KsVqwBwg/ifJbgKP9S7 N2qCUFh0A0LxApOmCTuWVLfmYOODj9zHm1kMrwRErFu4grRE/UvOMHc8qtcErfU4Wc+4 yEH2omSkcjKEGHUWep/MyLpLrJiMMqWTAtB6+vxw/D8RmzNuZvGaQ+xhBW6Ql4HSmNRE ks9g== X-Gm-Message-State: APjAAAV8JGQ8j1sBs4h3vARdcROQiQKnfqniRWsRMWBCKjnQdmK0R2L2 TIL3XDmKo9J4SqUaFXHlV454YJcNHjvV3viw X-Received: by 2002:adf:e88e:: with SMTP id d14mr4948391wrm.189.1560893288980; Tue, 18 Jun 2019 14:28:08 -0700 (PDT) Received: from e111045-lin.arm.com (lfbn-nic-1-216-10.w2-15.abo.wanadoo.fr. [2.15.62.10]) by smtp.gmail.com with ESMTPSA id h21sm2273831wmb.47.2019.06.18.14.28.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 14:28:08 -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 v2 3/4] md: dm-crypt: infer ESSIV block cipher from cipher string directly Date: Tue, 18 Jun 2019 23:27:48 +0200 Message-Id: <20190618212749.8995-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190618212749.8995-1-ard.biesheuvel@linaro.org> References: <20190618212749.8995-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. Signed-off-by: Ard Biesheuvel --- drivers/md/dm-crypt.c | 35 +++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) -- 2.17.1 diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 1b16d34bb785..f001f1104cb5 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,6 +2426,20 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key if (*ivmode && !strcmp(*ivmode, "lmk")) cc->tfms_count = 64; + if (crypt_integrity_aead(cc)) { + ret = crypt_ctr_auth_cipher(cc, cipher_api); + if (ret < 0) { + ti->error = "Invalid AEAD cipher spec"; + return -ENOMEM; + } + } + + 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 */ @@ -2445,21 +2451,10 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key /* 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); - if (ret < 0) { - ti->error = "Cannot allocate cipher string"; - return -ENOMEM; - } - return 0; }