From patchwork Tue Jul 2 16:48:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11028303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BBA01902 for ; Tue, 2 Jul 2019 16:48:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AFBF28925 for ; Tue, 2 Jul 2019 16:48:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F4062898B; Tue, 2 Jul 2019 16:48:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 281152895F for ; Tue, 2 Jul 2019 16:48:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbfGBQsd (ORCPT ); Tue, 2 Jul 2019 12:48:33 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41861 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbfGBQsd (ORCPT ); Tue, 2 Jul 2019 12:48:33 -0400 Received: by mail-lf1-f66.google.com with SMTP id 62so1850927lfa.8 for ; Tue, 02 Jul 2019 09:48:30 -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=n1MiZRQXY1X5/1Lfb3V7ryug15xS4eKlSLkntpBu3p8=; b=NIJMyvki0ukOG2yDafz+vzWNfARdo8Xk/QtUd/vJ7S0VvPLvYhtPx+yljhwzrIwBgp ZHrdkqMPUVVi/CvG+sI1nJuPrW9eu6gdPDCtrLf/KAs9oULJ5LVZ6xmwcU3gggS1V3YX RRQfRx4AnhZfszYn+TgMjNuMWUqMe1rQtWczE8wooWj9HNx+wi9t6Z2XAHVSqmm/NZys toRno9eyuR3rnF1tV4J39kZksTHQKYXCBpCBLXmz+d+ZhJedVQ9rDmk3WZXZYkL3b3BF 6OkSPIxoH6OxV8W9DJmweixQrtpwwtogPYtbIuNprMVTPmDNQEQehjmxF5tYs4W/yAzB pQRQ== 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=n1MiZRQXY1X5/1Lfb3V7ryug15xS4eKlSLkntpBu3p8=; b=h3dJa+YeVY7LTkhUAWR59xMcvjgAm6fAdIS6bTjTjQ89VdwVRI3939THNO6XSWYf9y sL5TDwz2I0fgM+Lb+rbQaVtRQYmpAr6wPB4pwGtHlc0sHXJNMg3upQHGzlMw6uV9+rG0 aLyq049Nd4zsn6+YbxtKLToYmCAMxrxFZ3CFdTqdb5x3FggNkuONAtSGFu3QWyaRe5CU l7rezRfJXyjQpmJmbROnIlNpICQtVvq+C03puBzdIo+TIOW5HXMdwxDB1ZERI48ywoff MkZFK4ZtAuyK0sG+9ta/YrLAWOODrgiL3ZAmCSLvDPu4jIv+22IS1FE326HQpvoXmMCq fNag== X-Gm-Message-State: APjAAAWb/EexoptOzps/btoL2MtjN6TOttd4IbIDDeTv0DFaXnggBNnJ ittG14tJj9N+MGywqlO77Erz6Q== X-Google-Smtp-Source: APXvYqxF+/r4KCOGGCedGogDPlPJlaPfEYSAVZQw5bwdbPZFxOAbCJwriqBGDvCHDVCPc2LEE6pGJg== X-Received: by 2002:ac2:48a5:: with SMTP id u5mr15588960lfg.62.1562086108660; Tue, 02 Jul 2019 09:48:28 -0700 (PDT) Received: from e111045-lin.arm.com (89-212-78-239.static.t-2.net. [89.212.78.239]) by smtp.gmail.com with ESMTPSA id r17sm3906055ljc.85.2019.07.02.09.48.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 09:48:27 -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 v7 0/7] crypto: switch to crypto API for ESSIV generation Date: Tue, 2 Jul 2019 18:48:08 +0200 Message-Id: <20190702164815.6341-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 #4. This code has been tested using the fscrypt test suggested by Eric (generic/549), as well as the mode-test script suggested by Milan for the dm-crypt case. I also tested the aead case in a virtual machine, but it definitely needs some wider testing from the dm-crypt experts. The consensus appears to be that it would be useful if the crypto API encapsulates the handling of multiple subsequent blocks that are encrypted using a 64-bit LE counter as IV, and makes it the duty of the algo to increment the counter between blocks. However, this is equally suitable for non-ESSIV transforms (or even more so), and so this is left as a future enhancement to be applied on top. 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 Scroll down for tcrypt speed test result comparing the essiv template with the asm implementation. Bare cbc(aes) tests included for reference as well. Taken on a 2GHz Cortex-A57 (AMD Seattle) Code can be found here https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=essiv-v6 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: infer ESSIV block cipher from cipher string directly md: dm-crypt: switch to ESSIV crypto API template crypto: essiv - add test vector for essiv(cbc(aes),aes,sha256) crypto: arm64/aes-cts-cbc - factor out CBC en/decryption of a walk crypto: arm64/aes - implement accelerated ESSIV/CBC mode arch/arm64/crypto/aes-glue.c | 205 +++++-- arch/arm64/crypto/aes-modes.S | 29 +- crypto/Kconfig | 28 + crypto/Makefile | 1 + crypto/essiv.c | 640 ++++++++++++++++++++ crypto/tcrypt.c | 9 + crypto/testmgr.c | 14 + crypto/testmgr.h | 497 +++++++++++++++ drivers/md/Kconfig | 1 + drivers/md/dm-crypt.c | 235 ++----- fs/crypto/Kconfig | 1 + fs/crypto/crypto.c | 5 - fs/crypto/fscrypt_private.h | 9 - fs/crypto/keyinfo.c | 95 +-- 14 files changed, 1436 insertions(+), 333 deletions(-) create mode 100644 crypto/essiv.c