From patchwork Thu Feb 10 23:28:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nathan Huckleberry X-Patchwork-Id: 12742576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9FCD9C433EF for ; Thu, 10 Feb 2022 23:29:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=3uN7uO8x9aH66ovfSntsItnMk1es+v3Ws+JhXraOfA8=; b=tMW Jx+FBSB2Z5zXYV18RwacikXra0ec2RmH5qOPH3zl1zibZbga5JfERDkOQzstM4DdQO4QZmJxyAi6e UZmz+xxcUI2tdbhMPDSPiSvGT4pOYWVooYRXuPfXlUx2vNG1dYNcsNxaT80bh/Fs+N6vMgnIZEnGt 9eTiyFXrlIyvPCd1AX9Yge1L4aRpd7hx60O5iLM5R1f/X9JrXL3qjbbPBOyJ889EVXjkKDPp2FZrP eKbjHC0Lsy5oTk5YWKa81WEFDne5YQXm2Qrcbwtqi6npSQF0yCJM8iDGeVLOw2z7JnemanbJh/SH3 4Q1iXdy42Q1nYJEVPaCrhVUy9EO+zUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIIrf-005AEd-H2; Thu, 10 Feb 2022 23:28:39 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIIrb-005AE2-VE for linux-arm-kernel@lists.infradead.org; Thu, 10 Feb 2022 23:28:37 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id c5-20020a25f305000000b0061dd6123f18so15237249ybs.17 for ; Thu, 10 Feb 2022 15:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=X4pGovICiPQ0U+Wm+4Mu3dfpVMwLlQ+3KkIwYwKv2HY=; b=JwD33JaCAdwyGy0A45Vk6WDnFItu+aqp8GMTky89wFARQDZXlfOVNqaT9dWXtuQT0W oIIYuvVAGp5n3+826axpuJSMg9Ywdo+SGL8/b7YiTHwrZMcSnXamKw9lqcbjMmVCT0Kd Tv36pXuj+yUVH6Xe7DoITIf74d4kX+Vh3eWP3jpNPZwuveodR/20y9cieYqS+Wu2g48a zCocD7ZuDG7AG2MunqE34VUGiJGG3cFJG2x8PAeVt4JDg7ZBDuo1ChClCnvjMVxSk057 8QP4ueC/UG2ztofFRdQKXWJcpMXr1MAwtMm+ZV1+lNV60BD6xSedODK4Y+qaZHGQvpf5 fqCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=X4pGovICiPQ0U+Wm+4Mu3dfpVMwLlQ+3KkIwYwKv2HY=; b=An3gUZxz6W2JdWtAh17jH0bitWOEX7EcjbxSQGKVNryyStlc5Uml0ixLp1FZUmCGVH Z9Hy0U7NeiBjop5JYwshFnI8G706pTYf0dc1EhtZoeEIW1dhPD2dM5nH4RiqiRTgxTzY QfhgdS9GciV7HPgINvUHGX2IjEMttU2BBaj2lGhxpBSYIJTQjE+bBroMxxENojHcNP89 HoBcc52sxHB7A8EPtGotf/68asWRKFqN7vdJIyzhd1pN/W9RswxtIQ3bBUIkP/I71+9D 1HpD6yAVjYwcU2JDDILcoB4fq+zLtQeYDn7Q/0Ns/RVdWgMRIOM/fh27uFVKi6T9/9Wm 0w9w== X-Gm-Message-State: AOAM531UNI5XirbKZysVLSsBK3B3ow2BtalY0mtDEXDQ+0YC/We5sEu4 NmnnLRYNWyq3vYebFo+/Tpk66fM8DQ== X-Google-Smtp-Source: ABdhPJxwZ4Y6YJ+RiwWywKVKfsWcJiykReiGnNG6XrsemntyXE/P+wYILD44hJRaJ3u7EJU7Kuy7AT51Ww== X-Received: from nhuck.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:39cc]) (user=nhuck job=sendgmr) by 2002:a25:30d4:: with SMTP id w203mr9052733ybw.511.1644535714443; Thu, 10 Feb 2022 15:28:34 -0800 (PST) Date: Thu, 10 Feb 2022 23:28:05 +0000 Message-Id: <20220210232812.798387-1-nhuck@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [RFC PATCH v2 0/7] crypto: HCTR2 support From: Nathan Huckleberry To: linux-crypto@vger.kernel.org Cc: Herbert Xu , "David S. Miller" , linux-arm-kernel@lists.infradead.org, Paul Crowley , Eric Biggers , Sami Tolvanen , Ard Biesheuvel , Nathan Huckleberry X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_152836_364352_76802A87 X-CRM114-Status: GOOD ( 16.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 encryption 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 applications such as storage encryption where ciphertext expansion is not possible, and thus authenticated encryption cannot be used. Currently, such applications usually use XTS, or in some cases Adiantum. XTS has the disadvantage that 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 of filenames, where for efficiency reasons encryption must be fully deterministic (only one ciphertext for each plaintext) and the existing CBC solution leaks more information than necessary for filenames with common prefixes. HCTR2 uses two passes of an ε-almost-∆-universal hash function 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, and a templated implementation of HCTR2. Nathan Huckleberry (7): 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 arch/arm64/crypto/Kconfig | 11 +- arch/arm64/crypto/Makefile | 3 + arch/arm64/crypto/aes-glue.c | 72 +- arch/arm64/crypto/aes-modes.S | 130 ++ arch/arm64/crypto/polyval-ce-core.S | 405 ++++++ arch/arm64/crypto/polyval-ce-glue.c | 365 ++++++ arch/x86/crypto/Makefile | 5 +- arch/x86/crypto/aes_xctrby8_avx-x86_64.S | 529 ++++++++ arch/x86/crypto/aesni-intel_asm.S | 70 + arch/x86/crypto/aesni-intel_glue.c | 89 ++ arch/x86/crypto/polyval-clmulni_asm.S | 414 ++++++ arch/x86/crypto/polyval-clmulni_glue.c | 365 ++++++ crypto/Kconfig | 38 + crypto/Makefile | 3 + crypto/hctr2.c | 532 ++++++++ crypto/polyval-generic.c | 199 +++ crypto/tcrypt.c | 10 + crypto/testmgr.c | 20 + crypto/testmgr.h | 1500 ++++++++++++++++++++++ crypto/xctr.c | 193 +++ include/crypto/polyval.h | 22 + 21 files changed, 4970 insertions(+), 5 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/aes_xctrby8_avx-x86_64.S 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