Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fscrypt: Add SM4 XTS/CTS symmetric algorithm support

Add support for XTS and CTS mode variant of SM4 algorithm. The former is
used to encrypt file contents, while the latter (SM4-CTS-CBC) is used to
encrypt filenames.

SM4 is a symmetric algorithm widely used in China, and is even mandatory
algorithm in some special scenarios. We need to provide these users with
the ability to encrypt files or disks using SM4-XTS.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Link: https://lore.kernel.org/r/20221201125819.36932-3-tianjia.zhang@linux.alibaba.com

authored by

Tianjia Zhang and committed by
Eric Biggers
e0cefada d209ce35

+23
+1
Documentation/filesystems/fscrypt.rst
··· 338 338 - AES-128-CBC for contents and AES-128-CTS-CBC for filenames 339 339 - Adiantum for both contents and filenames 340 340 - AES-256-XTS for contents and AES-256-HCTR2 for filenames (v2 policies only) 341 + - SM4-XTS for contents and SM4-CTS-CBC for filenames (v2 policies only) 341 342 342 343 If unsure, you should use the (AES-256-XTS, AES-256-CTS-CBC) pair. 343 344
+15
fs/crypto/keysetup.c
··· 44 44 .security_strength = 16, 45 45 .ivsize = 16, 46 46 }, 47 + [FSCRYPT_MODE_SM4_XTS] = { 48 + .friendly_name = "SM4-XTS", 49 + .cipher_str = "xts(sm4)", 50 + .keysize = 32, 51 + .security_strength = 16, 52 + .ivsize = 16, 53 + .blk_crypto_mode = BLK_ENCRYPTION_MODE_SM4_XTS, 54 + }, 55 + [FSCRYPT_MODE_SM4_CTS] = { 56 + .friendly_name = "SM4-CTS-CBC", 57 + .cipher_str = "cts(cbc(sm4))", 58 + .keysize = 16, 59 + .security_strength = 16, 60 + .ivsize = 16, 61 + }, 47 62 [FSCRYPT_MODE_ADIANTUM] = { 48 63 .friendly_name = "Adiantum", 49 64 .cipher_str = "adiantum(xchacha12,aes)",
+5
fs/crypto/policy.c
··· 90 90 if (contents_mode == FSCRYPT_MODE_AES_256_XTS && 91 91 filenames_mode == FSCRYPT_MODE_AES_256_HCTR2) 92 92 return true; 93 + 94 + if (contents_mode == FSCRYPT_MODE_SM4_XTS && 95 + filenames_mode == FSCRYPT_MODE_SM4_CTS) 96 + return true; 97 + 93 98 return fscrypt_valid_enc_modes_v1(contents_mode, filenames_mode); 94 99 } 95 100
+2
include/uapi/linux/fscrypt.h
··· 26 26 #define FSCRYPT_MODE_AES_256_CTS 4 27 27 #define FSCRYPT_MODE_AES_128_CBC 5 28 28 #define FSCRYPT_MODE_AES_128_CTS 6 29 + #define FSCRYPT_MODE_SM4_XTS 7 30 + #define FSCRYPT_MODE_SM4_CTS 8 29 31 #define FSCRYPT_MODE_ADIANTUM 9 30 32 #define FSCRYPT_MODE_AES_256_HCTR2 10 31 33 /* If adding a mode number > 10, update FSCRYPT_MODE_MAX in fscrypt_private.h */