Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3844864ybl; Mon, 12 Aug 2019 07:20:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqx9l2Xt+8DRxBKOp+sBiYX0q5QTOTfLzGGU+0gzaqsPN3hWxYr1rotRrnpbtQ141UGm/zGn X-Received: by 2002:a62:303:: with SMTP id 3mr35652996pfd.118.1565619616654; Mon, 12 Aug 2019 07:20:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565619616; cv=none; d=google.com; s=arc-20160816; b=u+xpifjA4l8o4NDmY0BNSmUAr5O52eJVOyjmz0p+zhzrunESjFlhHCxym8y5QbONfi WHxdXfGN22sYRUhAzymDRlVgQx0Kgvmq1Slhoox6f4RXBMsaikEhzQ6q+AJ1PR/Ar4yg 25VPLw3f+QWCCR88nEjGWqoaOpGUJduPxRzP6nQ0pluYbhixPGfkzgdD3oBMdLtGeHmc hQwWm6YkRa7MJynlYAd5nXc4VaddZk0r9S1J2r1zf0eOXHISOA0P9dfoUtUgUIjOgur5 kZ60s/8QXtGOIF9JXVif7WnaUKc9WNl5Hx+nC1XLfUqAooGLeSb+A/chRBir623AFscv r3cQ== 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=rjvKcpCdQy4Fb58ugbqz4IBMCEH2qfwlqKGn/IbXyKU=; b=OjOhtNd/e55n/qEcSjMRYqbXA7QWjMpa31J5j37Q3xphh6V51dcmfl6CTkARZ6JGqL NzKyQVkgYGnK4l4osHzukxNX9+VdS0+rSbjtIF6KW3phYE5EEImjVPDP9nLiiH5rHMUW nZYTzZzacG+NPaTuQ90N49WaXvkCN0luh0Pdn+XLBsaEfj1xN5iLfcPX1qmpQP8hKNHy vBPtNBdirXMWAmah0FXNUHuEvZqf49eigRPUgHoU2sGSL+t9P8ZMQPzNF01Lp9Zu6Msl CZbyH2ZHTdqcoNON4LNwqQE2vUg15aIdwFWFUIQ9ZMGVlFwXFQvfiDLuAZAIKiKA9XNU Ixnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yLeiwepq; 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 r3si60841069pls.176.2019.08.12.07.20.03; Mon, 12 Aug 2019 07:20:16 -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=yLeiwepq; 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 S1726696AbfHLOTo (ORCPT + 99 others); Mon, 12 Aug 2019 10:19:44 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53838 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727206AbfHLOTo (ORCPT ); Mon, 12 Aug 2019 10:19:44 -0400 Received: by mail-wm1-f65.google.com with SMTP id 10so12345984wmp.3 for ; Mon, 12 Aug 2019 07:19:42 -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=rjvKcpCdQy4Fb58ugbqz4IBMCEH2qfwlqKGn/IbXyKU=; b=yLeiwepqLD+fzOmGB/TMVxXWqsg3LGD/Cy06GePwEfqZyBsQqvcRzYytHbubf9vGzJ UeQ6AiHpX+UcjO0lvm/+A0PBPQthqa+VDCNMuaR2jeS//V48OwMA9DyEN23wTBL+NQiS LIaLMhAVDcg/ZCW68Qkl8BrZBKsxPEAlhcMtBSEw4BVgfsq9j68BMbpvO2hO0zHN63Jv OLoEUWsQkXqv+sQ22DecHcDZF57LLQiQrfG0r3edOgvFpVeQQv0TgdW/czCr1Vw0thzW 6OR98OuImqfAOK3t32AfccRgC0XAjeJzEkeHMylCHcfk5RFyD0otVSJtLfIg24DOCa30 7Rsw== 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=rjvKcpCdQy4Fb58ugbqz4IBMCEH2qfwlqKGn/IbXyKU=; b=G6HZgPnIrof81tgwCkJSez8kxsW1e06+Ho54HBKid8ovTBxTySSJ4Jqk9BV6Y/Ubno Gesv4Ykz2NV6uVNh2YqFYBo2O+iKy69p2QriUMHOa2dRBnuA/IaRDaCI6FVDB8dShl8O Q72SearEjRdTMEe3C76gsjXXs62Mi+5tJ3LnrFSm5Qw36x0MsFBC9gHx1FCMG32wQk1B oKzuATQvaWoP+v4CFNSMgZnH6T+8IWXz6AQT2PKlBO4Izp0TYgTCrkr9RZFC4ng+Oo5l 4MTyvxTjOVDB5w2bkHSo1hoTrvt99ps/1ofoLyJPzXIayQn93vHLUrjAgKQTJ8LmPTpZ 0DaA== X-Gm-Message-State: APjAAAXkXFsUzyNGFxy2Ssk+wNvj0eskEmjmS0YASGuFp2NiKF1jjF2z Y0iHjrpxyTvqJwGRgWPnQHI8Y+wSdIQ1j6nUKuVKDA== X-Received: by 2002:a05:600c:231a:: with SMTP id 26mr13970077wmo.136.1565619581427; Mon, 12 Aug 2019 07:19:41 -0700 (PDT) MIME-Version: 1.0 References: <20190810094053.7423-1-ard.biesheuvel@linaro.org> <20190810094053.7423-4-ard.biesheuvel@linaro.org> <8679d2f5-b005-cd89-957e-d79440b78086@gmail.com> <82a87cae-8eb7-828c-35c3-fb39a9abe692@gmail.com> <7b3365a9-42ca-5426-660f-e87898bb9f7a@gmail.com> In-Reply-To: <7b3365a9-42ca-5426-660f-e87898bb9f7a@gmail.com> From: Ard Biesheuvel Date: Mon, 12 Aug 2019 17:19:29 +0300 Message-ID: Subject: Re: [PATCH v9 3/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, 12 Aug 2019 at 16:51, Milan Broz wrote: > > On 12/08/2019 09:50, Ard Biesheuvel wrote: > > On Mon, 12 Aug 2019 at 10:44, Milan Broz wrote: > >> > >> On 12/08/2019 08:54, Ard Biesheuvel wrote: > >>> On Mon, 12 Aug 2019 at 09:33, Milan Broz wrote: > >>>> Try for example > >>>> # cryptsetup luksFormat /dev/sdc -c aes-cbc-essiv:sha256 --integrity hmac-sha256 -q -i1 > >>>> > >>>> It should produce Crypto API string > >>>> authenc(hmac(sha256),essiv(cbc(aes),sha256)) > >>>> while it produces > >>>> essiv(authenc(hmac(sha256),cbc(aes)),sha256) > >>>> (and fails). > >>>> > >>> > >>> No. I don't know why it fails, but the latter is actually the correct > >>> string. The essiv template is instantiated either as a skcipher or as > >>> an aead, and it encapsulates the entire transformation. (This is > >>> necessary considering that the IV is passed via the AAD and so the > >>> ESSIV handling needs to touch that as well) > >> > >> Hm. Constructing these strings seems to be more confusing than dmcrypt mode combinations :-) > >> > >> But you are right, I actually tried the former string (authenc(hmac(sha256),essiv(cbc(aes),sha256))) > >> and it worked, but I guess the authenticated IV (AAD) was actually the input to IV (plain sector number) > >> not the output of ESSIV? Do I understand it correctly now? > >> > > > > Indeed. The former string instantiates the skcipher version of the > > ESSIV template, and so the AAD handling is omitted, and we end up > > using the plain IV in the authentication rather than the encrypted IV. > > > > So when using the latter string, does it produce any error messages > > when it fails? > > The error is > table: 253:1: crypt: Error decoding and setting key > > and it is failing in crypt_setkey() int this crypto_aead_setkey(); > > And it is because it now wrongly calculates MAC key length. > (We have two keys here - one for length-preserving CBC-ESSIV encryption > and one for HMAC.) > > This super-ugly hotfix helps here... I guess it can be done better :-) > Weird. It did work fine before, but now that I have dropped the 'md: dm-crypt: infer ESSIV block cipher from cipher string directly' patch, we are probably taking a different code path and hitting this error. I'll try to fix this cleanly. Thanks for doing the diagnosis. > diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c > index e9a0093c88ee..7b06d975a2e1 100644 > --- a/drivers/md/dm-crypt.c > +++ b/drivers/md/dm-crypt.c > @@ -2342,6 +2342,9 @@ static int crypt_ctr_auth_cipher(struct crypt_config *cc, char *cipher_api) > char *start, *end, *mac_alg = NULL; > struct crypto_ahash *mac; > > + if (strstarts(cipher_api, "essiv(authenc(")) > + cipher_api += strlen("essiv("); > + > if (!strstarts(cipher_api, "authenc(")) > return 0; > > Milan