From patchwork Thu Jul 4 18:30:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 168491 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2582047ilk; Thu, 4 Jul 2019 11:30:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqza+K2ljrxPoH5IMveCFM9vsui2t3IiXdh4X8f9jpvP4YcYZ0DzrzId6FM3e6T1KEnzXi1U X-Received: by 2002:a63:b904:: with SMTP id z4mr9270354pge.388.1562265049740; Thu, 04 Jul 2019 11:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562265049; cv=none; d=google.com; s=arc-20160816; b=ptsh7lKrW8Ezgrb+oh9PueigUKcDMnBaHV1QVKQdwuW/9sTL8z7LAX15xipnRZDSRv Retu9wbNb4iS0K4V1b9c2tDfEWHQ37UqWOo+au8kXHLFKnxoPuOIL3FuKE4FvdvzrBns tOhmWgg/MP/Y8PUKOupmzo99QV5o5sniYB+f/XmiaI2bG1DJgoqtrPN4ThPFCf/l84tJ tccKbpEFX1MlwqkLxdo6iGXX74Q8/5nxNHiSfePEp4X25KmWsi3FSMGfxrQYJYQXYnOj rzUDmQ/21qRaerQLsx4iFCA4bHaE77zQLhr2aILOAVR8Fi/X/frnrk/6uK/ZOqt4g7tv EO2w== 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=JacwhcGTgI7h8AT4t1QXUKRiggdiMJC9ecGBGIHzJnGqXAhH92VNMYsv96ttofu4i7 8cOff/pCxwbB85W1IN3CSX6Qh1cPjmaKlIlJtFW0B2KPtQyXTomY4fdhT/IfC2eTVyFL 7MMyvBajAitlzDcYi2aK1P4zcNnWSbkHhQFAm6mqx4gxT9dMzVpljMLNqLm2ZUn8CSB4 tDoi+25DCCNFeScxFk5zBInnejFAsrjUai9MqVjQIWMzUaGugaLvBih+irnW/cQZDp46 2FvyUz58cHDLRu4MkTf4mUn0RekCSEeWNEG9cggkBqTidPi284dJewACV/nmq2YeCnq5 eVeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JCPKfk7Z; 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 i69si6197528pge.366.2019.07.04.11.30.49; Thu, 04 Jul 2019 11:30:49 -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=JCPKfk7Z; 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 S1727014AbfGDSar (ORCPT + 3 others); Thu, 4 Jul 2019 14:30:47 -0400 Received: from mail-wr1-f44.google.com ([209.85.221.44]:37460 "EHLO mail-wr1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727018AbfGDSar (ORCPT ); Thu, 4 Jul 2019 14:30:47 -0400 Received: by mail-wr1-f44.google.com with SMTP id v14so7523717wrr.4 for ; Thu, 04 Jul 2019 11:30:46 -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=JCPKfk7ZExLY06Ns+/JxSMk3qpW7waz8rQbYKrVyVsI7deea8HckVyvq4YL3XFrUbC xtsO0mTEttwgKRZGcIPG1l3UARCxTePSEmP4tYU2y0aHI+vsaS0T8Pk0Ljqmo3VKmmGN k8BePG67m7sg2re2lqDgG2ZmMO9QKmdRu19P9bDZrCS0ZpfhdfJ4Ryr5FVfDL/w8kd9F 6xXFaA/dwRo0RgkwouDkK8KLbmbCq3x0Jy311vMRrDG+HUgFySh36N6LO6xkVji4y05t E29IBsgq/HEdkIvNZK4EGM9Y1IUaQW35zd5evMQPPfU2guPp5ubuCBPc2bJuS6iR+vXa P/Xg== 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=YGJvm6L94Lp8y6R7I+amVFT+HLq2HriK0n8d8E+nkaJcJ+iWAVPaDSqy0D31TDrCRW MMkdeY56dDpJCfh85dctTpsSOLaez7ivCyk5E4wCkJoWAZM0QEnAXus2ghogMPHPXDvc cbIJISWvfAt0HCIBleLi3rEj4zhAy3tWFO7BqnxyI3YGZ8ortH/pz4R6VD+ztlP+XU2b 9j0KpaN2idAzqIxpsuesi69p3qPIjFM5qTb9csr+FPnACZSg8VNkXOSqvhPnza6mJSFA AUz5RC/EaVa7xMkA//a+I8YpZZl3OllpJgL5Oz4+SN+eFYhB2iRoQVYW7ufsbmPnMZ1z iNnA== X-Gm-Message-State: APjAAAXbIwpsrVsLH1oNrjG15iinDklf5TZAbYDBMyEvqEBi9DtD4ysk nQLV0o6dBkg/k3HVw8JcMdiqbsWdLsuQGQ== X-Received: by 2002:a5d:4403:: with SMTP id z3mr10882wrq.29.1562265045221; Thu, 04 Jul 2019 11:30:45 -0700 (PDT) Received: from e111045-lin.arm.com (93-143-123-179.adsl.net.t-com.hr. [93.143.123.179]) by smtp.gmail.com with ESMTPSA id o6sm11114695wra.27.2019.07.04.11.30.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 11:30:44 -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 v8 3/7] md: dm-crypt: infer ESSIV block cipher from cipher string directly Date: Thu, 4 Jul 2019 20:30:13 +0200 Message-Id: <20190704183017.31570-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190704183017.31570-1-ard.biesheuvel@linaro.org> References: <20190704183017.31570-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; }