Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp442744pxb; Fri, 15 Apr 2022 03:21:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo6JL46PXxD1vjRiVrUzZE/XQmzxrnC9oe+EzufRSCwv0EZNGod3qYGloh1vKXc9WlgPgz X-Received: by 2002:a63:2214:0:b0:398:ee6c:e5f7 with SMTP id i20-20020a632214000000b00398ee6ce5f7mr5945356pgi.625.1650018066279; Fri, 15 Apr 2022 03:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650018066; cv=none; d=google.com; s=arc-20160816; b=JxiOO1Uj+37pqYnqYkqRo1dwZ/2Y+RYmF9/PLEDTLYOpOnDKKtBBaLqtU7fRXFH3iX yYm9gjs+HU6b5+OlpOxcwTYonQE5kaY1LHEOv6/5TLGDlq0FVRPEHIzmc0+JZz9ALAgl 8y6SPrpGGQUDvhSqvHpDGkqlTpX2IiMmXKYHDkJzdPontqxMvO2/RfUSoFeA4jQvq/gO /KecJ1fXStlsp/YSr9zoUM+Ufn4aKzPKEYgNwoQMSzKHeLHsaBHfGKNVhEjTnpYJF7ea uiP5wzJw3ScbrMcTvErupPxHYgamblLjo8+Gsb7sjEhAQROjkzQMpcuOqLCq6iKzadTu B22g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=bgazmtNpxc4LJEURUJ9+Mc4+L6cw+cd/0441RGzqEAE=; b=kGkJPtobToDHSvfzENODDR/XX347/+pa23msfona28RqErqtxJiFsDt4siYvJJ2tB/ bYYFiPVT5WW9vLftaTcGe5+sH5GpwPR6w2umw1qf07caAN0YTcapnid48Y9YXn6Hdz68 oHWpqOppvBNGK8jeMzHDkMDQCJ8OJg49T+Db+ag24iXT4wGsxwckrVliBt0/w+0DZ7GS Evl+No8Pos+VxjUxQ9AIYkCTBFYbptCbVsNd0UpnUziR1BpenUgRPRN5+Pt3CEAYlJXQ zSDsu0DZHEnnafKf6LyIjYz6cFNHDJ3uAkF32pxjFWzdjPS1VXxd3mc4YDy7c2MmDM7/ usTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HmbY9jAH; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v4-20020a17090a898400b001bf040acc3dsi3708467pjn.170.2022.04.15.03.20.38; Fri, 15 Apr 2022 03:21:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HmbY9jAH; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239479AbiDNPKq (ORCPT + 99 others); Thu, 14 Apr 2022 11:10:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351199AbiDNOao (ORCPT ); Thu, 14 Apr 2022 10:30:44 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5083022BF2 for ; Thu, 14 Apr 2022 07:19:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id B5030CE29FD for ; Thu, 14 Apr 2022 14:19:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 069ABC385A5 for ; Thu, 14 Apr 2022 14:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649945951; bh=Q1WpI1P2qqbFgHB/7bjfsFc19FhHImxCTccviOynmi4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=HmbY9jAHlchFisUj26Z0tCXjqt61T3Gpr+PXMA+xpI0rmrQwd1ao/bvGNhjCoqMTW 2sqzE7MOH5eEIb3iL5wAB9Eno6w2B/V6ltpzT5eOqR2r/ZNys1xUFjd9zFfs9DB3uB qwodabxc5qmi4N8+TeZ2cN6cJxwPB+SWrYIryF7aksQYTBgCh60i+Ztz9MCDxNOg+Z 6ex0tUh/KNKUySVoho+CFg8prxWhJyLIiuuBe8NQsT++SLQonGO94RZUf46+HpKooa b8ELBGH2UekSx62l61lC3y7eh20XsEzRTin8Fsh5KkUCTP7bj4bnBTZsHExtZwUL0D iqbhhwe4kJL9g== Received: by mail-oi1-f172.google.com with SMTP id w127so5500645oig.10 for ; Thu, 14 Apr 2022 07:19:10 -0700 (PDT) X-Gm-Message-State: AOAM532T1PY55VOZSRhzMtiZMdnqA+c47SCzDiob6loWDG7LFAfrWQT9 U6hUy/C83VaEpH7JKBHZs/NxC44k/JWk0AkMCsk= X-Received: by 2002:a05:6808:1513:b0:2fa:7a40:c720 with SMTP id u19-20020a056808151300b002fa7a40c720mr1446182oiw.126.1649945950087; Thu, 14 Apr 2022 07:19:10 -0700 (PDT) MIME-Version: 1.0 References: <20220412172816.917723-1-nhuck@google.com> In-Reply-To: <20220412172816.917723-1-nhuck@google.com> From: Ard Biesheuvel Date: Thu, 14 Apr 2022 16:18:58 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 0/8] crypto: HCTR2 support To: Nathan Huckleberry Cc: Linux Crypto Mailing List , Herbert Xu , "David S. Miller" , Linux ARM , Paul Crowley , Eric Biggers , Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, 12 Apr 2022 at 19:28, Nathan Huckleberry wrote: > > HCTR2 is a length-preserving encryption mode that is efficient on > processors with instructions to accelerate AES and carryless > multiplication, e.g. x86 processors with AES-NI and CLMUL, and ARM > processors with the ARMv8 Crypto Extensions. > > HCTR2 is specified in https://ia.cr/2021/1441 "Length-preserving encrypti= on > with HCTR2" which shows that if AES is secure and HCTR2 is instantiated > with AES, then HCTR2 is secure. Reference code and test vectors are at > https://github.com/google/hctr2. > > As a length-preserving encryption mode, HCTR2 is suitable for application= s > such as storage encryption where ciphertext expansion is not possible, an= d > thus authenticated encryption cannot be used. Currently, such applicatio= ns > usually use XTS, or in some cases Adiantum. XTS has the disadvantage tha= t > it is a narrow-block mode: a bitflip will only change 16 bytes in the > resulting ciphertext or plaintext. This reveals more information to an > attacker than necessary. > > HCTR2 is a wide-block mode, so it provides a stronger security property: = a > bitflip will change the entire message. HCTR2 is somewhat similar to > Adiantum, which is also a wide-block mode. However, HCTR2 is designed to > take advantage of existing crypto instructions, while Adiantum targets > devices without such hardware support. Adiantum is also designed with > longer messages in mind, while HCTR2 is designed to be efficient even on > short messages. > > The first intended use of this mode in the kernel is for the encryption o= f > filenames, where for efficiency reasons encryption must be fully > deterministic (only one ciphertext for each plaintext) and the existing C= BC > solution leaks more information than necessary for filenames with common > prefixes. > > HCTR2 uses two passes of an =CE=B5-almost-=E2=88=86-universal hash functi= on called > POLYVAL and one pass of a block cipher mode called XCTR. POLYVAL is a > polynomial hash designed for efficiency on modern processors and was > originally specified for use in AES-GCM-SIV (RFC 8452). XCTR mode is a > variant of CTR mode that is more efficient on little-endian machines. > > This patchset adds HCTR2 to Linux's crypto API, including generic > implementations of XCTR and POLYVAL, hardware accelerated implementations > of XCTR and POLYVAL for both x86-64 and ARM64, a templated implementation > of HCTR2, and an fscrypt policy for using HCTR2 for filename encryption. > > Changes in v4: > * Small style fixes in generic POLYVAL and XCTR > * Move HCTR2 hash exporting/importing to helper functions > * Rewrite montgomery reduction for x86-64 POLYVAL > * Rewrite partial block handling for x86-64 POLYVAL > * Optimize x86-64 POLYVAL loop handling > * Remove ahash wrapper from x86-64 POLYVAL > * Add simd-unavailable handling to x86-64 POLYVAL > * Rewrite montgomery reduction for ARM64 POLYVAL > * Rewrite partial block handling for ARM64 POLYVAL > * Optimize ARM64 POLYVAL loop handling > * Remove ahash wrapper from ARM64 POLYVAL > * Add simd-unavailable handling to ARM64 POLYVAL > > Changes in v3: > * Improve testvec coverage for XCTR, POLYVAL and HCTR2 > * Fix endianness bug in xctr.c > * Fix alignment issues in polyval-generic.c > * Optimize hctr2.c by exporting/importing hash states > * Fix blockcipher name derivation in hctr2.c > * Move x86-64 XCTR implementation into aes_ctrby8_avx-x86_64.S > * Reuse ARM64 CTR mode tail handling in ARM64 XCTR > * Fix x86-64 POLYVAL comments > * Fix x86-64 POLYVAL key_powers type to match asm > * Fix ARM64 POLYVAL comments > * Fix ARM64 POLYVAL key_powers type to match asm > * Add XTS + HCTR2 policy to fscrypt > > Nathan Huckleberry (8): > crypto: xctr - Add XCTR support > crypto: polyval - Add POLYVAL support > crypto: hctr2 - Add HCTR2 support > crypto: x86/aesni-xctr: Add accelerated implementation of XCTR > crypto: arm64/aes-xctr: Add accelerated implementation of XCTR > crypto: x86/polyval: Add PCLMULQDQ accelerated implementation of > POLYVAL > crypto: arm64/polyval: Add PMULL accelerated implementation of POLYVAL > fscrypt: Add HCTR2 support for filename encryption > This is looking very good, thanks for your continued efforts on this. Once Eric's feeback has been addressed, feel free to add Reviewed-by: Ard Biesheuvel to the series. > Documentation/filesystems/fscrypt.rst | 19 +- > arch/arm64/crypto/Kconfig | 10 +- > arch/arm64/crypto/Makefile | 3 + > arch/arm64/crypto/aes-glue.c | 65 +- > arch/arm64/crypto/aes-modes.S | 134 ++ > arch/arm64/crypto/polyval-ce-core.S | 366 ++++++ > arch/arm64/crypto/polyval-ce-glue.c | 240 ++++ > arch/x86/crypto/Makefile | 3 + > arch/x86/crypto/aes_ctrby8_avx-x86_64.S | 233 ++-- > arch/x86/crypto/aesni-intel_asm.S | 70 ++ > arch/x86/crypto/aesni-intel_glue.c | 89 ++ > arch/x86/crypto/polyval-clmulni_asm.S | 333 +++++ > arch/x86/crypto/polyval-clmulni_glue.c | 234 ++++ > crypto/Kconfig | 40 +- > crypto/Makefile | 3 + > crypto/hctr2.c | 616 +++++++++ > crypto/polyval-generic.c | 214 ++++ > crypto/tcrypt.c | 10 + > crypto/testmgr.c | 20 + > crypto/testmgr.h | 1536 +++++++++++++++++++++++ > crypto/xctr.c | 191 +++ > fs/crypto/fscrypt_private.h | 2 +- > fs/crypto/keysetup.c | 7 + > fs/crypto/policy.c | 4 + > include/crypto/polyval.h | 17 + > include/uapi/linux/fscrypt.h | 3 +- > tools/include/uapi/linux/fscrypt.h | 3 +- > 27 files changed, 4376 insertions(+), 89 deletions(-) > create mode 100644 arch/arm64/crypto/polyval-ce-core.S > create mode 100644 arch/arm64/crypto/polyval-ce-glue.c > create mode 100644 arch/x86/crypto/polyval-clmulni_asm.S > create mode 100644 arch/x86/crypto/polyval-clmulni_glue.c > create mode 100644 crypto/hctr2.c > create mode 100644 crypto/polyval-generic.c > create mode 100644 crypto/xctr.c > create mode 100644 include/crypto/polyval.h > > -- > 2.35.1.1178.g4f1659d476-goog >