Skip to content

Commit e0cefad

Browse files
uudiinebiggers
authored andcommitted
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 <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d209ce3 commit e0cefad

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

Documentation/filesystems/fscrypt.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ Currently, the following pairs of encryption modes are supported:
338338
- AES-128-CBC for contents and AES-128-CTS-CBC for filenames
339339
- Adiantum for both contents and filenames
340340
- 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)
341342

342343
If unsure, you should use the (AES-256-XTS, AES-256-CTS-CBC) pair.
343344

fs/crypto/keysetup.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ struct fscrypt_mode fscrypt_modes[] = {
4444
.security_strength = 16,
4545
.ivsize = 16,
4646
},
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+
},
4762
[FSCRYPT_MODE_ADIANTUM] = {
4863
.friendly_name = "Adiantum",
4964
.cipher_str = "adiantum(xchacha12,aes)",

fs/crypto/policy.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ static bool fscrypt_valid_enc_modes_v2(u32 contents_mode, u32 filenames_mode)
9090
if (contents_mode == FSCRYPT_MODE_AES_256_XTS &&
9191
filenames_mode == FSCRYPT_MODE_AES_256_HCTR2)
9292
return true;
93+
94+
if (contents_mode == FSCRYPT_MODE_SM4_XTS &&
95+
filenames_mode == FSCRYPT_MODE_SM4_CTS)
96+
return true;
97+
9398
return fscrypt_valid_enc_modes_v1(contents_mode, filenames_mode);
9499
}
95100

include/uapi/linux/fscrypt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define FSCRYPT_MODE_AES_256_CTS 4
2727
#define FSCRYPT_MODE_AES_128_CBC 5
2828
#define FSCRYPT_MODE_AES_128_CTS 6
29+
#define FSCRYPT_MODE_SM4_XTS 7
30+
#define FSCRYPT_MODE_SM4_CTS 8
2931
#define FSCRYPT_MODE_ADIANTUM 9
3032
#define FSCRYPT_MODE_AES_256_HCTR2 10
3133
/* If adding a mode number > 10, update FSCRYPT_MODE_MAX in fscrypt_private.h */

0 commit comments

Comments
 (0)