From patchwork Mon Aug 12 14:53:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171078 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2938468ily; Mon, 12 Aug 2019 07:53:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSRrMnzY9MVuOMPWJiQ0+HLHtr430szd2ZI5jrnZKV+zodS6jELfuAbTxyUB7KL3KWmmD4 X-Received: by 2002:aa7:8b10:: with SMTP id f16mr36542866pfd.44.1565621623171; Mon, 12 Aug 2019 07:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565621623; cv=none; d=google.com; s=arc-20160816; b=fdTGCp1Ypdq1rsbJ4QzK+6D03WcTq1EFeG3guHooapr+64sliSWT0IGnCOLrUyXeau WBs46VjSeHTdVnqYI5j1iXjpFPqQcMDjog33CqtOnim5z6Wxg4GPrnpoO2p6g7de+CdK 4roA00SoD6LzZqlfD9V5F0J1kK9AasBOgC7eTI6iLvX0YQrPIgALF1U3bgPgXLBO6kug XJDQuXzEhwqw8eNLaIvjZid1kOnHUHNcZdX+8gpvxmiNf0LWWfjlHaEtsg5/ZSec03ta g+nJzrZVN+cMyA9OYyF1NWYFQ9vpPwWzrUlv5WUJuv/srlsA5Ih5B5DLuT5Bf+vhfmgB PaNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=E/iJgOe1+kHrTZkg6t1LtxFkxOFOrmmNA7lNv6Yq4sY=; b=G5t5EEXyGn3Na5A4K9/ssLOGTmFjLM7QOAg76u6W7XZQap1FGPwX2Q0jok+i1gcVp0 ElYHMrOZ/BNQdGnYtLLppHSDZ5YvjM2gHzxYmNbMNzgc4hetI30IW232lblsJ0EphWMO 9HF0uVF79v1OJDlhh2fb280uc5RzSBg/34kBwEi2RCf0hsZ8r1t4oJhIR4FV960yRSKm bvWWiBjQlei/yY3rwjhcIQMlh0YTm9juaPX6JiC/SCoHquZVuHNArvkTrSfzrJeJFdga 3RGALYxRUg2OAqbGiMoeAa9eayyLsV3HXj5eJ+R9hViy/30qvG0bTmqxs2ksSivOZDah EdGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nFZeAGDh; 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 z8si25456965pgr.359.2019.08.12.07.53.42; Mon, 12 Aug 2019 07:53:43 -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=nFZeAGDh; 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 S1726689AbfHLOxl (ORCPT + 3 others); Mon, 12 Aug 2019 10:53:41 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39995 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbfHLOxl (ORCPT ); Mon, 12 Aug 2019 10:53:41 -0400 Received: by mail-wm1-f66.google.com with SMTP id v19so12039221wmj.5 for ; Mon, 12 Aug 2019 07:53:39 -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; bh=E/iJgOe1+kHrTZkg6t1LtxFkxOFOrmmNA7lNv6Yq4sY=; b=nFZeAGDhDtTlyI9xCJJy0yK7E9fYUG4hVcFkeA+obzFvwRHdfb6glnILFHoujsUdgv gHp3QMjIt7CyXy998ZHCwoT1q8l9cUB7w5RSkpDrPii4PV8EJ7xxDeQFQJQos0eqN4Lb VW5UvRe6wYWux6KG0gjvi9b3bYh3XOwgIh66/g7NXvO6YSNnccCRL0CyRuqy8xta5Bko CDDVajsO7gG3hK1r2DhRjaBo5Y307VuumorZGb7vdFAS70dPWqsTIbq46qx/z/meYYXL fdKxpERdeZo9xIt2sbsR0RexlO8YXmC2/3PtjBnjJOnvO8cEMzdPEpfMoOzD/rx3IX2U 68Sg== 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; bh=E/iJgOe1+kHrTZkg6t1LtxFkxOFOrmmNA7lNv6Yq4sY=; b=D+VkKY2DGFWCp8ayiiuvkkmQbqHwKXQTvWLfua7+mC5chsvLraDyIk7KkngFeGNEs3 BfmiMWX4HeanoS1SUg2NIq7nivraRYQNtLgvf1fuH+mnzJxn3v+DvN5INQqIRjOQSw7m Ok4DeAgHk1h3ReXoWZp9E8uyhK4BzusSwf8d4W+a25MMuswiq/kqK7gtlcPwsiz9LEgQ r02bFGGhIsyXqXxzlUOg2Ky3l8fy7QKCUdTUKVaDvkDMGUtap2OD/5RHvQo6RZXKjV/e EaHRODUF80FFXI225e4XbCWhZj3eyGEuUG7/j7Qffvu6Or6aQushPBs0O+pPPbVrdH5o v/bQ== X-Gm-Message-State: APjAAAXAo6+YVEAjuCPJkmFshrRqr/5bAysimh/kNgNQ0RwGMq8matpp h9v6HYtE/EyigGLi4bS6XRmuccy9GRLiYg== X-Received: by 2002:a1c:2015:: with SMTP id g21mr27621200wmg.33.1565621618996; Mon, 12 Aug 2019 07:53:38 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:a407:da00:1c0e:f938:89a1:8e17]) by smtp.gmail.com with ESMTPSA id k13sm23369190wro.97.2019.08.12.07.53.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Aug 2019 07:53:37 -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 v10 0/7] crypto: switch to crypto API for ESSIV generation Date: Mon, 12 Aug 2019 17:53:17 +0300 Message-Id: <20190812145324.27090-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This series creates an ESSIV template that produces a skcipher or AEAD transform based on a tuple of the form ',' (or ',' for the AEAD case). It exposes the encapsulated sync or async skcipher/aead by passing through all operations, while using the cipher/shash pair to transform the input IV into an ESSIV output IV. This matches what both users of ESSIV in the kernel do, and so it is proposed as a replacement for those, in patches #2 and #3. Changes since v9: - Fix cipher_api parsing bug that was introduced by dropping the cipher name parsing patch in v9 (#3). Thanks to Milan for finding it. - Fix a couple of instances where the old essiv(x,y,z) format was used in comments instead of the essiv(x,z) format we adopted in v9 Changes since v8: - Remove 'cipher' argument from essiv() template, and instead, parse the cra_name of the skcipher to obtain the cipher. This is slightly cleaner than what dm-crypt currently does, since we can get the cra_name from the spawn, and we don't have to actually allocate the TFM. Since this implies that dm-crypt does not need to provide the cipher, we can drop the parsing code from it entirely (assuming the eboiv patch I sent out recently is applied first) (patch #7) - Restrict the essiv() AEAD instantiation to AEADs whose cra_name starts with 'authenc(' - Rebase onto cryptodev/master - Drop dm-crypt to reorder/refactor cipher name parsing, since it was wrong and it is no longer needed. - Drop Milan's R-b since the code has changed - Fix bug in accelerated arm64 implementation. Changes since v7: - rebase onto cryptodev/master - drop change to ivsize in #2 - add Milan's R-b's Changes since v6: - make CRYPTO_ESSIV user selectable so we can opt out of selecting it even if FS_ENCRYPTION (which cannot be built as a module) is enabled - move a comment along with the code it referred to (#3), not that this change and removing some redundant braces makes the diff look totally different - add Milan's R-b to #3 and #4 Changes since v5: - drop redundant #includes and drop some unneeded braces (#2) - add test case for essiv(authenc(hmac(sha256),cbc(aes)),aes,sha256) - make ESSIV driver deal with assoc data that is described by more than two scatterlist entries - this only happens when the extended tests are being performed, so don't optimize for it - clarify that both fscrypt and dm-crypt only use ESSIV in special cases (#7) Changes since v4: - make the ESSIV template IV size equal the IV size of the encapsulated cipher - defining it as 8 bytes was needlessly restrictive, and also complicated the code for no reason - add a missing kfree() spotted by Smatch - add additional algo length name checks when constructing the essiv() cipher name - reinstate the 'essiv' IV generation implementation in dm-crypt, but make its generation function identical to plain64le (and drop the other methods) - fix a bug in the arm64 CE/NEON code - simplify the arm64 code by reusing more of the existing CBC implementation (patch #6 is new to this series and was added for this reason) Changes since v3: - address various review comments from Eric on patch #1 - use Kconfig's 'imply' instead of 'select' to permit CRYPTO_ESSIV to be enabled as a module or disabled entirely even if fscrypt is compiled in (#2) - fix an issue in the AEAD encrypt path caused by the IV being clobbered by the inner skcipher before the hmac was being calculated Changes since v2: - fixed a couple of bugs that snuck in after I'd done the bulk of my testing - some cosmetic tweaks to the ESSIV template skcipher setkey function to align it with the aead one - add a test case for essiv(cbc(aes),aes,sha256) - add an accelerated implementation for arm64 that combines the IV derivation and the actual en/decryption in a single asm routine Code can be found here https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=essiv-v10 Cc: Herbert Xu Cc: Eric Biggers Cc: dm-devel@redhat.com Cc: linux-fscrypt@vger.kernel.org Cc: Gilad Ben-Yossef Cc: Milan Broz Ard Biesheuvel (7): crypto: essiv - create wrapper template for ESSIV generation fs: crypto: invoke crypto API for ESSIV handling md: dm-crypt: switch to ESSIV crypto API template crypto: essiv - add tests for essiv in cbc(aes)+sha256 mode crypto: arm64/aes-cts-cbc - factor out CBC en/decryption of a walk crypto: arm64/aes - implement accelerated ESSIV/CBC mode md: dm-crypt: omit parsing of the encapsulated cipher arch/arm64/crypto/aes-glue.c | 205 ++++-- arch/arm64/crypto/aes-modes.S | 28 + crypto/Kconfig | 28 + crypto/Makefile | 1 + crypto/essiv.c | 665 ++++++++++++++++++++ crypto/tcrypt.c | 9 + crypto/testmgr.c | 14 + crypto/testmgr.h | 497 +++++++++++++++ drivers/md/Kconfig | 1 + drivers/md/dm-crypt.c | 271 ++------ fs/crypto/Kconfig | 1 + fs/crypto/crypto.c | 5 - fs/crypto/fscrypt_private.h | 9 - fs/crypto/keyinfo.c | 92 +-- 14 files changed, 1453 insertions(+), 373 deletions(-) create mode 100644 crypto/essiv.c -- 2.17.1