Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3050713ybi; Tue, 2 Jul 2019 01:09:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyotNSyzoqTdgGsUOKCiJen4RFDB2jWiQFHlo52sjUxkX4P48ftMKYS0HGik4m8JHnuvaMe X-Received: by 2002:a63:7b18:: with SMTP id w24mr25936921pgc.328.1562054976928; Tue, 02 Jul 2019 01:09:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562054976; cv=none; d=google.com; s=arc-20160816; b=Wrqme8/+r8Opi4MMNDkANp03kItt9Nh5KHjg7pKyWIwZ12BusH6BwqtitlbbD8YK1h ssRXzb4WfKKs6wyPDeUTImUO82gYlEIN5mFnPe3VnCGmEVKCNPwIn/1KY1Nodmmc5mgP hptPSkT+xw+qepG9037VXlJnBiaEuU6tWT0Z8lrE0vpbFCILuQ02Zyy0qeIWBwPjtMhH AGFuoiUPkCchWAXvWNODmd2nT1kfL4YQcOwUZIVzZSGcVZYfHSZrqLcphr4V/jQ7U0dk /Pq47yBZIy15sqJC+IufQFijBNaF1SYHhai/4sO7oJcBlYpDxBF9m32FohCaxQNlw4Im ZyDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fVYsMgjvlhzbh/TqKhi7d4SFK7B/Ukhib20YGwD2OlM=; b=bPWMdXmCSS4BL6NOBl1tFiQLVx0D12RuTNlGTgEEIhQet17tq8isURvluy6SfIaQUd J6lHrEvmE/sqwfC92y2azli/mozvreg3SxEubptXDJHRSJiEHWlZqQsnoxsGze0epzqn zXpvkztR73Wt+BngIp7r28V40E58b6jpSa6QdZHPBnxE/b5d90Y+D1vF7oLHvaGEwQCK cQRA3gzTAfgJMXABZOVM/G8Ksef8gk/ErAFaVTOgzqwV/L18EY7gsetzi3EfEGsz1gRJ N7T3VI8B72P7iqy4E4TkDESrryGbTQFe6sDIgTkKHmVIA1Ajc90EZCMbDl519ciul71w VTgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q9ZilC05; 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 j23si12123007pll.214.2019.07.02.01.09.21; Tue, 02 Jul 2019 01:09:36 -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=q9ZilC05; 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 S1728323AbfGBIHq (ORCPT + 99 others); Tue, 2 Jul 2019 04:07:46 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36369 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728318AbfGBIHp (ORCPT ); Tue, 2 Jul 2019 04:07:45 -0400 Received: by mail-wr1-f65.google.com with SMTP id n4so16660944wrs.3 for ; Tue, 02 Jul 2019 01:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fVYsMgjvlhzbh/TqKhi7d4SFK7B/Ukhib20YGwD2OlM=; b=q9ZilC05a2m+mrPUNO5+3iadDkIlMvNCFVYKl5FwLDPma2TRWE2R0chNTM9iMMEJrH ln26Gtv3kLxEQ7ulT1DkTflxRzOwddrLnWXMwiWJwKlsKAnIi7J33WBU5V1Quqvbc72s dd52JvuRxilYVEeEFwthTvCbMFJTWKlEdApwk2O4qdpjwKuR8kZiIU2pFTfsAa23aVMb 8FwY1p93XrB1ewOEpLAGY23N5AibhbXyLd4QbBrI/O8VD+2yiqIzRtZrmonKEEpGn9wS WRwgd95Nut+jEnE6ytQXprbCcr0g9xR14lMdywhfUMDKpnS6rB3KHbxwPdR0YL1tJpfH RWlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fVYsMgjvlhzbh/TqKhi7d4SFK7B/Ukhib20YGwD2OlM=; b=M/wUCgSlENmBDAS2i7/d4Ps6z40/HzwSubVGW1L7e0oUDG3UyijJGiL6GJxDo9KXcn T1ehq7+bvpqAlZiNepfo9G5sCc/zzEUTfBxh5l0hsLJESxIFtrr7KErRq5qLkbjuhyZ0 bePGLHjUmAtqThsMzJ/6scBn9luxals1K+Mj67voNueI0EqA7whZGntz4SrDkJ6F/wA0 MZxSo4gybvnqiKfA1o6DLthVOGaxn7X5RUTPQk3vAfwdBDGGftySMxXAsLOm38/SNlmd zj7i5P8+5JU8D2ZCbMNm/aSJqLFbriSQ3lqAavblfufDh4X5/1ajXSJ/Cv8pfGUAs5Q3 9wJA== X-Gm-Message-State: APjAAAXWjxN3UaKkzQPyIJtG7esfgZMbUvjMIH8eLwRUQH5pkCFgiVmh IkpcL3u6tqWhpijb6uhBCQ6UzdfrnCGl0D3dNjGehg== X-Received: by 2002:a5d:6b07:: with SMTP id v7mr7958887wrw.169.1562054863371; Tue, 02 Jul 2019 01:07:43 -0700 (PDT) MIME-Version: 1.0 References: <20190628152112.914-1-ard.biesheuvel@linaro.org> <20190628152112.914-5-ard.biesheuvel@linaro.org> In-Reply-To: From: Ard Biesheuvel Date: Tue, 2 Jul 2019 10:07:32 +0200 Message-ID: Subject: Re: [PATCH v6 4/7] md: dm-crypt: switch to ESSIV crypto API template To: Milan Broz Cc: "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Herbert Xu , Eric Biggers , device-mapper development , linux-fscrypt@vger.kernel.org, Gilad Ben-Yossef Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, 1 Jul 2019 at 10:59, Milan Broz wrote: > > On 28/06/2019 17:21, Ard Biesheuvel wrote: > > Replace the explicit ESSIV handling in the dm-crypt driver with calls > > into the crypto API, which now possesses the capability to perform > > this processing within the crypto subsystem. > > > > Signed-off-by: Ard Biesheuvel > > > drivers/md/dm-crypt.c | 200 ++++---------------- > > ... > > > -/* Wipe salt and reset key derived from volume key */ > > -static int crypt_iv_essiv_wipe(struct crypt_config *cc) > > Do I understand it correctly, that this is now called inside the whole cipher > set key in wipe command (in crypt_wipe_key())? > > (Wipe message is meant to suspend the device and wipe all key material > from memory without actually destroying the device.) > Yes, setting the random key in wipe() triggers the SHA256 operation as normal, which is slightly wasteful but not a big deal imo. > > -{ > > - struct iv_essiv_private *essiv = &cc->iv_gen_private.essiv; > > - unsigned salt_size = crypto_shash_digestsize(essiv->hash_tfm); > > - struct crypto_cipher *essiv_tfm; > > - int r, err = 0; > > - > > - memset(essiv->salt, 0, salt_size); > > - > > - essiv_tfm = cc->iv_private; > > - r = crypto_cipher_setkey(essiv_tfm, essiv->salt, salt_size); > > - if (r) > > - err = r; > > - > > - return err; > > -} > > ... > > > @@ -2435,9 +2281,19 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key > > } > > > > ret = crypt_ctr_blkdev_cipher(cc, cipher_api); > > - if (ret < 0) { > > - ti->error = "Cannot allocate cipher string"; > > - return -ENOMEM; > > + if (ret < 0) > > + goto bad_mem; > > + > > + if (*ivmode && !strcmp(*ivmode, "essiv")) { > > + if (!*ivopts) { > > + ti->error = "Digest algorithm missing for ESSIV mode"; > > + return -EINVAL; > > + } > > + ret = snprintf(buf, CRYPTO_MAX_ALG_NAME, "essiv(%s,%s,%s)", > > + cipher_api, cc->cipher, *ivopts); > > + if (ret < 0 || ret >= CRYPTO_MAX_ALG_NAME) > > + goto bad_mem; > > Hm, nitpicking, but goto from only one place while we have another -ENOMEM above... > > Just place this here without goto? > OK > > + ti->error = "Cannot allocate cipher string"; > > + return -ENOMEM; > > Otherwise > > Reviewed-by: Milan Broz > > Thanks, > Milan