generic: test HCTR2 filename encryption
v4 cover generic: test HCTR2 filename encryption
This patchset is not intended to be accepted yet. It is reliant on HCTR2 support in the kernel which has not yet been accepted. See the HCTR2 patchset
here: https://lore.kernel.org/all/[email protected]/
HCTR2 is a new wide-block encryption mode that can used for filename encryption in fscrypt. This patchset adds a reference implementation of HCTR2 to the fscrypt testing utility and adds tests for filename encryption with HCTR2.
More information on HCTR2 can be found here: "Length-preserving encryption with HCTR2": https://ia.cr/2021/1441
Changes in v4:
* Add helper functions for HCTR2 hashing
* Fix accumulator alignment bug
* Small style fixes
Changes in v3:
* Consolidate tests into one file
Changes in v2:
* Use POLYVAL multiplication directly instead of using GHASH trick
* Split reference implementation and tests into two patches
* Remove v1 policy tests
* Various small style fixes
Nathan Huckleberry (2):
fscrypt-crypt-util: add HCTR2 implementation
generic: add tests for fscrypt policies with HCTR2
common/encrypt | 2 + src/fscrypt-crypt-util.c | 341 ++++++++++++++++++++++++++++++++------- tests/generic/900 | 28 ++++ tests/generic/900.out | 16 ++ 4 files changed, 330 insertions(+), 57 deletions(-) create mode 100755 tests/generic/900 create mode 100644 tests/generic/900.out
Signature · 1 line
2.36.1.255.ge46751e96f-goog
RFC PATCH v4 1/2 fscrypt-crypt-util: add HCTR2 implementation
This patch adds an implementation of HCTR2 to the fscrypt testing utility.
More information on HCTR2 can be found here: "Length-preserving encryption with HCTR2": https://ia.cr/2021/1441
--- common/encrypt | 2 + src/fscrypt-crypt-util.c | 341 ++++++++++++++++++++++++++++++++------- 2 files changed, 286 insertions(+), 57 deletions(-)
common/encrypt +2 -0
@@ -767,6 +767,7 @@ FSCRYPT_MODE_AES_256_CTS=4 FSCRYPT_MODE_AES_128_CBC=5 FSCRYPT_MODE_AES_128_CTS=6 FSCRYPT_MODE_ADIANTUM=9 +FSCRYPT_MODE_AES_256_HCTR2=10 FSCRYPT_POLICY_FLAG_DIRECT_KEY=0x04 FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64=0x08
@@ -785,6 +786,7 @@ _fscrypt_mode_name_to_num() AES-128-CBC-ESSIV) echo $FSCRYPT_MODE_AES_128_CBC ;; AES-128-CTS-CBC) echo $FSCRYPT_MODE_AES_128_CTS ;; Adiantum) echo $FSCRYPT_MODE_ADIANTUM ;; + AES-256-HCTR2) echo $FSCRYPT_MODE_AES_256_HCTR2 ;; *) _fail "Unknown fscrypt mode: $name" ;; esac }
src/fscrypt-crypt-util.c +284 -57
407 lines not on this page · raw message
Signature · 1 line
2.36.1.255.ge46751e96f-goog
Eric Biggers
maintainerRe: [RFC PATCH v4 1/2] fscrypt-crypt-util: add HCTR2 implementation
Quoted 1 line · Nathan Huckleberry
src/fscrypt-crypt-util.c +0
-0
[...]
src/fscrypt-crypt-util.c static inline void gf2_128_mul_x(ble128 *t) · line 371
Quoted 2 lines
src/fscrypt-crypt-util.c +2
-0+void gf2_128_mul_polyval (ble128 *r,const ble128 *b) +{
This function should be static.
Quoted 3 lines
+/*----------------------------------------------------------------------------*
+ * POLYVAL *
+ *----------------------------------------------------------------------------*/
This could use a link to a specification, similar to the other more "unusual" algorithms in this file. Try:
git grep -A1 'Reference:' src/fscrypt-crypt-util.c
Likewise for HCTR2. The commit message has a link to the HCTR2 paper, but it should be in the code itself too.
Quoted 15 lines
src/fscrypt-crypt-util.c +15
-0+static void polyval_update (const u8 key[POLYVAL_KEY_SIZE ], +const u8 *msg,size_t msglen, +u8 accumulator[POLYVAL_BLOCK_SIZE ]) +{ +ble128 h; +ble128 aligned_accumulator; +size_t chunk_size; +// x^{-128} = x^127 + x^124 + x^121 + x^114 + 1 +static const ble128 inv128 = { +cpu_to_le64 (1 ), +cpu_to_le64 (0x9204ULL <<48 ) + }; + +memcpy (&h, key,POLYVAL_BLOCK_SIZE ); +memcpy (&aligned_accumulator, accumulator,POLYVAL_BLOCK_SIZE );
src/fscrypt-crypt-util.c static void test_hkdf_sha512(void) · line 1021
Quoted 10 lines
src/fscrypt-crypt-util.c +10
-0+gf2_128_mul_polyval (&h, &inv128); + +while (msglen >0 ) { + chunk_size =MIN (POLYVAL_BLOCK_SIZE , msglen); +xor ((u8 *)&aligned_accumulator, (u8 *)&aligned_accumulator, msg, + chunk_size); +gf2_128_mul_polyval (&aligned_accumulator, &h); + msg += chunk_size; + msglen -= chunk_size; + }
The partial block support is unnecessary, so POLYVAL_BLOCK_SIZE could be used instead of chunk_size, and an assertion ASSERT(msglen % POLYVAL_BLOCK_SIZE ==
0) could be added. See poly1305() in the same file which works similarly.
Otherwise this looks good, thanks!
- Eric
RFC PATCH v4 2/2 generic: add tests for fscrypt policies with HCTR2
In reply to Nathan HuckleberryThis patch adds fscrypt policy tests for filename encryption using HCTR2.
More information on HCTR2 can be found here: "Length-preserving encryption with HCTR2" https://ia.cr/2021/1441
--- tests/generic/900 | 28 ++++++++++++++++++++++++++++ tests/generic/900.out | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 tests/generic/900 create mode 100644 tests/generic/900.out
tests/generic/900 new file +28 -0
@@ -0,0 +1,28 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2022 Google LLC +# +# FS QA Test No. generic/900 +# +# Verify ciphertext for v2 encryption policies that use AES-256-XTS to encrypt +# file contents and AES-256-HCTR2 to encrypt file names. +# +. ./common/preamble +_begin_fstest auto quick encrypt + +# Import common functions. +. ./common/filter +. ./common/encrypt + +# real QA test starts here +_supported_fs generic + +_verify_ciphertext_for_encryption_policy AES-256-XTS AES-256-HCTR2 v2 +_verify_ciphertext_for_encryption_policy AES-256-XTS AES-256-HCTR2 \ + v2 iv_ino_lblk_32 +_verify_ciphertext_for_encryption_policy AES-256-XTS AES-256-HCTR2 \ + v2 iv_ino_lblk_64 + +# success, all done +status=0 +exit
tests/generic/900.out new file +16 -0
@@ -0,0 +1,16 @@ +QA output created by 900 + +Verifying ciphertext with parameters: + contents_encryption_mode: AES-256-XTS + filenames_encryption_mode: AES-256-HCTR2 + options: v2 + +Verifying ciphertext with parameters: + contents_encryption_mode: AES-256-XTS + filenames_encryption_mode: AES-256-HCTR2 + options: v2 iv_ino_lblk_32 + +Verifying ciphertext with parameters: + contents_encryption_mode: AES-256-XTS + filenames_encryption_mode: AES-256-HCTR2 + options: v2 iv_ino_lblk_64
Signature · 1 line
2.36.1.255.ge46751e96f-goog
Eric Biggers
maintainerRe: [RFC PATCH v4 2/2] generic: add tests for fscrypt policies with HCTR2
Quoted 6 lines · Nathan Huckleberry
tests/generic/900 new file +0
-0
tests/generic/900 line 9
Quoted 9 lines
tests/generic/900 new file +9
-0@@ -0,0 +1,28 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2022 Google LLC +# +# FS QA Test No. generic/900 +# +# Verify ciphertext for v2 encryption policies that use AES-256-XTS to encrypt +# file contents and AES-256-HCTR2 to encrypt file names. +#
How about mentioning here the commit that introduced this feature upstream?
Otherwise this patch looks good.
- Eric