Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15833256rwd; Mon, 26 Jun 2023 01:50:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5SNOlnt7ric9vwbBRG1Js3qajEDE2gNSlcQh0lkSLVx6j/KW0eV5TgE47IOAZPWs1/RCYG X-Received: by 2002:a05:6a00:4192:b0:668:70af:b5c1 with SMTP id ca18-20020a056a00419200b0066870afb5c1mr24776018pfb.1.1687769451415; Mon, 26 Jun 2023 01:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687769451; cv=none; d=google.com; s=arc-20160816; b=ikl2fUZ8SNBt9tvomlFCu8ZhgYfjauKmFMGJCaUUHSKX2tLRu33+kXfqoEllVDtxrS jIvDNyBSNukhwYsOf8WfI4CyCYg4mWjcJAP1tWBx3t7V8I3k+DOVereBB/mPqXQTQZhk MsxptaQmkwUtv7PkaIdRg48aGXpHGev0xbFaiiH3eas1lcO0v3U5OtlJ4SFxa4EDQery M6nyvc3Q4l+kASpER5EKJomk137exOy4DxXrP976GCF0TcZfl8EhQHzSBuxJWTV2J0EH DS8/c797mTbvhbEcAQaYvvHOe9EIRlGvBO01errnOAt6T/sZL78rSsKDb/jfF0q2CTic 71DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DyrfY0crg++/09jon1RFZl0ms2Mo5gm3lj4/Yg6if8A=; fh=BVM8Lk95Ribzx1+wPOAl8bTKP3+yC0sKPvoVd2D5Lf4=; b=ahAx3/rDLz2igBFaOO87nQgg2x/QPvzJr11KxLa9cks+kZfwN8AQ5xZ6UAX0oN1eHX +mG8OdCh6iU2U8h4RwHdZXc+JMaF9dZ9UIM9IkYusJ8K+LnZ0zh3XPth1OTWcTHWdf0v 4vEwabFfSfozZ6lG7Lao3+W7vzOK3D8OQQWAfG8EolFiUiKtC+jtlOfT6jBML2P+UBLU LiooAXDcSb2duKJsrLiC+XTcAo9V+SrfMQv8Kt+UVo/2yHyW6WeCHFL73atPzh5EPTDH tPOKeOSxuUVpGP8zeACrPddLbgYp12yHljK7GzcBl8rZl+1cgrtKe044LnW2hLFxgRYW 2mxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@nsr.re.kr header.s=LIY0OQ3MUMW6182UNI14 header.b=JZqEocwr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=nsr.re.kr Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c22-20020a056a00249600b0064f50a4a515si4568343pfv.37.2023.06.26.01.50.34; Mon, 26 Jun 2023 01:50:51 -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=temperror (no key for signature) header.i=@nsr.re.kr header.s=LIY0OQ3MUMW6182UNI14 header.b=JZqEocwr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=nsr.re.kr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjFZItT (ORCPT + 99 others); Mon, 26 Jun 2023 04:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjFZIsg (ORCPT ); Mon, 26 Jun 2023 04:48:36 -0400 Received: from mail.nsr.re.kr (unknown [210.104.33.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2C3A10E2; Mon, 26 Jun 2023 01:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; s=LIY0OQ3MUMW6182UNI14; d=nsr.re.kr; t=1687769154; c=relaxed/relaxed; h=content-type:date:from:message-id:mime-version:subject:to; bh=DyrfY0crg++/09jon1RFZl0ms2Mo5gm3lj4/Yg6if8A=; b=JZqEocwr89SrJWgT9XpYUcsO0hpZVR+K2HkMNYsKyzguFCzpgkKrsst4qeue2jiMNfTPmmpMNLgzVXGgnOFtn8QmbLZk9n9KLw5Ndwr+39G1aNaPYJwrBx+avkv0oSqtlndideAAyQvZxwb7j3MYlI5Da1qokWni/o/C7LvmHRjdWauDJDhSuUuaxugWsAXz4IM9FIYNIzG/UF8/v+Ll3W+6tH6Ezg3FEe5ldzsJdV2r1nnAUE3SBj2kXDhey0eQzgFuEuO7mJZ+V5RIzHsh8jYUu3O5JYFNJEYfECeqZY1hZ/9ABG6QCm6BEzUugvx9MmrUeqRnbWxhsWhuX/ZLpQ== Received: from 210.104.33.70 (nsr.re.kr) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128 bits)) by mail.nsr.re.kr with SMTP; Mon, 26 Jun 2023 17:45:39 +0900 Received: from 192.168.155.188 ([192.168.155.188]) by mail.nsr.re.kr (Crinity Message Backbone-7.0.1) with SMTP ID 334; Mon, 26 Jun 2023 17:47:46 +0900 (KST) From: Dongsoo Lee To: Herbert Xu , "David S. Miller" , Jens Axboe , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim Cc: linux-crypto@vger.kernel.org, linux-block@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, Dongsoo Lee Subject: [PATCH v3 0/4] crypto: LEA block cipher implementation Date: Mon, 26 Jun 2023 17:46:59 +0900 Message-Id: <20230626084703.907331-1-letrhee@nsr.re.kr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no 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 This submission contains a generic C implementation of the LEA cipher algorithm and test vectors for it. It also includes modifications to use the LEA in fscrypt. The LEA algorithm is a lightweight block cipher that processes data blocks of 128-bits and has three different key lengths, each with a different number of rounds: - LEA-128: 128-bit key, 24 rounds, - LEA-192: 192-bit key, 28 rounds, and - LEA-256: 256-bit key, 32 rounds. The round function of LEA consists of 32-bit ARX(modular Addition, bitwise Rotation, and bitwise XOR) operations. See [2, 5, 7] for details. LEA is a Korean national standard block cipher, described in "KS X 3246"[1] and is also included in the international standard, "ISO/IEC 29192-2:2019 standard"[2]. It is one of the approved block ciphers for the current Korean Cryptographic Module Validation Program (KCMVP). We expect that the first application of the patch would be disk encryption on the Gooroom platform ('Gooroom' is a Korean word, meaning 'cloud') [3]. Currently, the Gooroom platform uses AES-XTS for disk encryption. The main reason for submitting this patch is to make disk encryption with LEA (e.g. LEA-XTS) available on there. It is possible to use LEA without any additional modifications in dm-crypt, a module that provides disk encryption functionality within the kernel. This patch also includes a modification to enable LEA for use in fscrypt, another data-at-rest method available within the kernel, and a modification to blk-crypto-fallback to enable the "inlinecrypt" mount option in fscrypt. The Gooroom platform is a government-driven Debian-based Linux distribution in South Korea. In Korea, there are many crypto companies that want to bundle Linux into their products and sell them. They create their own Gooroom platforms by modifying the original Gooroom platform for their services. (Of course, the Gooroom platform is not mandatory, and companies wishing to use Linux are free to choose an appropriate distribution.) BTW, in Korea, many crypto companies want to use LEA, because LEA is one of the block ciphers of the KCMVP, a validation program for commercial crypto S/W to be delivered to the Korean government. The Linux Crypto API already has another Korean block cipher, ARIA, also one of the block ciphers of the KCVMP. However, LEA is more widely used than ARIA in industry nowadays, because LEA is one of the lightweight cryptography standard of ISO/IEC [2] and performs well on low-end devices that support 32-bit operations. So we think they are complementary to each other. In general, it's obvious that the hardware-accelerated AES is the best performer. However, there exist not only environments where the hardware-accelerated AES is not supported, but also situations where AES is not preferred for various reasons. In these cases, if someone wants to encrypt using a block cipher, LEA could be an alternative. There are also SIMD implementations for efficiently using LEA, which is not included in this patch. We have SSE2 and AVX2 assembly implementations, some of which were included in the previous version of the patch. The SIMD implementations are being re-implemented to support a wider range of environments. Apart from this, we also have implemented LEA in lightweight environments such as 8-bit AVR, 16-bit MSP and 32-bit ARM [4]. If LEA were to be included in the Linux kernel, it would be possible to modify and supplement the submission with lightweight implementations to provide efficient encryption on embedded linux devices. Although the designers of LEA did not provide test vectors in their paper [5], the ISO/IEC standard [2] and the KS standard [1] do. Furthermore, the Block Cipher LEA Specification("블록암호 LEA 규격서", written in Korean) document on the LEA introduction page [6] and the Wikipedia article on LEA [7] show the same test vectors as in the standards. The test vectors for ECB, CBC, CTR, and GCM modes included in the testmgr module are taken from the KCMVP Cryptographic Algorithm Verification Criteria V3.0("KCMVP 검증대상 암호알고리즘 검증기준 V3.0", written in Korean) [8]. Test vectors for the XTS mode were generated by ourselves, and we crosschecked them using Crypto++ [9] and testmgr on Linux. The implementation has been tested with kernel module tcrypt.ko and has passed the selftest using above-mentioned test vectors. It also has been tested with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS. The fscrypt patch was tested using a modified tool by forking https://github.com/google/fscrypt. [1] KS X 3246, 128-bit block cipher LEA. [2] ISO/IEC 29192-2:2019, Information security — Lightweight cryptography — Part 2: Block ciphers. [3] https://github.com/gooroom https://www.gooroom.kr/ [4] https://github.com/cryptolu/FELICS/tree/master/block_ciphers/source/ciphers/LEA_128_128_v01/source [5] Hong, Deukjo, et al. "LEA: A 128-bit block cipher for fast encryption on common processors.", WISA 2013. [6] https://seed.kisa.or.kr/kisa/algorithm/EgovLeaInfo.do [7] https://en.wikipedia.org/wiki/LEA_(cipher) [8] https://seed.kisa.or.kr/kisa/kcmvp/EgovVerification.do [9] https://www.cryptopp.com/ Changelog: v3: - Added implementations to enable LEA in fscrypt and blk-crypt. v2: - Reimplemented the Generic C implementation as a Loop version. - The decryption code was adapted from an optimized implementation by Eric Biggers. https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/commit/?h=old/wip-lea&id=1d1cbba14380f8a1abc76baf939b9e51de047fb6 - Removed AVX2 SIMD implementation. - Added comments for functions. - Improved the description in Kconfig. - Added test vectors from the standard documentation. Dongsoo Lee (4): crypto: LEA block cipher implementation crypto: add LEA testmgr tests blk-crypto: Add LEA-256-XTS blk-crypto support fscrypt: Add LEA-256-XTS, LEA-256-CTS support Documentation/filesystems/fscrypt.rst | 12 + block/blk-crypto.c | 6 + crypto/Kconfig | 18 + crypto/Makefile | 1 + crypto/lea_generic.c | 410 ++++++++ crypto/tcrypt.c | 73 ++ crypto/testmgr.c | 32 + crypto/testmgr.h | 1241 +++++++++++++++++++++++++ fs/crypto/fscrypt_private.h | 2 +- fs/crypto/keysetup.c | 15 + fs/crypto/policy.c | 4 + include/crypto/lea.h | 44 + include/linux/blk-crypto.h | 1 + include/uapi/linux/fscrypt.h | 4 +- tools/include/uapi/linux/fscrypt.h | 4 +- 15 files changed, 1864 insertions(+), 3 deletions(-) create mode 100644 crypto/lea_generic.c create mode 100644 include/crypto/lea.h -- 2.34.1