2020
2121static struct crypto_shash * essiv_hash_tfm ;
2222
23- /* Table of keys referenced by FS_POLICY_FLAG_DIRECT_KEY policies */
23+ /* Table of keys referenced by DIRECT_KEY policies */
2424static DEFINE_HASHTABLE (fscrypt_master_keys , 6 ) ; /* 6 bits = 64 buckets */
2525static DEFINE_SPINLOCK (fscrypt_master_keys_lock );
2626
@@ -77,7 +77,7 @@ static int derive_key_aes(const u8 *master_key,
7777 */
7878static struct key *
7979find_and_lock_process_key (const char * prefix ,
80- const u8 descriptor [FS_KEY_DESCRIPTOR_SIZE ],
80+ const u8 descriptor [FSCRYPT_KEY_DESCRIPTOR_SIZE ],
8181 unsigned int min_keysize ,
8282 const struct fscrypt_key * * payload_ret )
8383{
@@ -87,7 +87,7 @@ find_and_lock_process_key(const char *prefix,
8787 const struct fscrypt_key * payload ;
8888
8989 description = kasprintf (GFP_NOFS , "%s%*phN" , prefix ,
90- FS_KEY_DESCRIPTOR_SIZE , descriptor );
90+ FSCRYPT_KEY_DESCRIPTOR_SIZE , descriptor );
9191 if (!description )
9292 return ERR_PTR (- ENOMEM );
9393
@@ -105,7 +105,7 @@ find_and_lock_process_key(const char *prefix,
105105 payload = (const struct fscrypt_key * )ukp -> data ;
106106
107107 if (ukp -> datalen != sizeof (struct fscrypt_key ) ||
108- payload -> size < 1 || payload -> size > FS_MAX_KEY_SIZE ) {
108+ payload -> size < 1 || payload -> size > FSCRYPT_MAX_KEY_SIZE ) {
109109 fscrypt_warn (NULL ,
110110 "key with description '%s' has invalid payload" ,
111111 key -> description );
@@ -129,32 +129,32 @@ find_and_lock_process_key(const char *prefix,
129129}
130130
131131static struct fscrypt_mode available_modes [] = {
132- [FS_ENCRYPTION_MODE_AES_256_XTS ] = {
132+ [FSCRYPT_MODE_AES_256_XTS ] = {
133133 .friendly_name = "AES-256-XTS" ,
134134 .cipher_str = "xts(aes)" ,
135135 .keysize = 64 ,
136136 .ivsize = 16 ,
137137 },
138- [FS_ENCRYPTION_MODE_AES_256_CTS ] = {
138+ [FSCRYPT_MODE_AES_256_CTS ] = {
139139 .friendly_name = "AES-256-CTS-CBC" ,
140140 .cipher_str = "cts(cbc(aes))" ,
141141 .keysize = 32 ,
142142 .ivsize = 16 ,
143143 },
144- [FS_ENCRYPTION_MODE_AES_128_CBC ] = {
144+ [FSCRYPT_MODE_AES_128_CBC ] = {
145145 .friendly_name = "AES-128-CBC" ,
146146 .cipher_str = "cbc(aes)" ,
147147 .keysize = 16 ,
148148 .ivsize = 16 ,
149149 .needs_essiv = true,
150150 },
151- [FS_ENCRYPTION_MODE_AES_128_CTS ] = {
151+ [FSCRYPT_MODE_AES_128_CTS ] = {
152152 .friendly_name = "AES-128-CTS-CBC" ,
153153 .cipher_str = "cts(cbc(aes))" ,
154154 .keysize = 16 ,
155155 .ivsize = 16 ,
156156 },
157- [FS_ENCRYPTION_MODE_ADIANTUM ] = {
157+ [FSCRYPT_MODE_ADIANTUM ] = {
158158 .friendly_name = "Adiantum" ,
159159 .cipher_str = "adiantum(xchacha12,aes)" ,
160160 .keysize = 32 ,
@@ -192,7 +192,7 @@ static int find_and_derive_key(const struct inode *inode,
192192 const struct fscrypt_key * payload ;
193193 int err ;
194194
195- key = find_and_lock_process_key (FS_KEY_DESC_PREFIX ,
195+ key = find_and_lock_process_key (FSCRYPT_KEY_DESC_PREFIX ,
196196 ctx -> master_key_descriptor ,
197197 mode -> keysize , & payload );
198198 if (key == ERR_PTR (- ENOKEY ) && inode -> i_sb -> s_cop -> key_prefix ) {
@@ -203,7 +203,7 @@ static int find_and_derive_key(const struct inode *inode,
203203 if (IS_ERR (key ))
204204 return PTR_ERR (key );
205205
206- if (ctx -> flags & FS_POLICY_FLAG_DIRECT_KEY ) {
206+ if (ctx -> flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY ) {
207207 if (mode -> ivsize < offsetofend (union fscrypt_iv , nonce )) {
208208 fscrypt_warn (inode ,
209209 "Direct key mode not allowed with %s" ,
@@ -272,14 +272,14 @@ allocate_skcipher_for_mode(struct fscrypt_mode *mode, const u8 *raw_key,
272272 return ERR_PTR (err );
273273}
274274
275- /* Master key referenced by FS_POLICY_FLAG_DIRECT_KEY policy */
275+ /* Master key referenced by DIRECT_KEY policy */
276276struct fscrypt_master_key {
277277 struct hlist_node mk_node ;
278278 refcount_t mk_refcount ;
279279 const struct fscrypt_mode * mk_mode ;
280280 struct crypto_skcipher * mk_ctfm ;
281- u8 mk_descriptor [FS_KEY_DESCRIPTOR_SIZE ];
282- u8 mk_raw [FS_MAX_KEY_SIZE ];
281+ u8 mk_descriptor [FSCRYPT_KEY_DESCRIPTOR_SIZE ];
282+ u8 mk_raw [FSCRYPT_MAX_KEY_SIZE ];
283283};
284284
285285static void free_master_key (struct fscrypt_master_key * mk )
@@ -320,13 +320,13 @@ find_or_insert_master_key(struct fscrypt_master_key *to_insert,
320320 * raw key, and use crypto_memneq() when comparing raw keys.
321321 */
322322
323- BUILD_BUG_ON (sizeof (hash_key ) > FS_KEY_DESCRIPTOR_SIZE );
323+ BUILD_BUG_ON (sizeof (hash_key ) > FSCRYPT_KEY_DESCRIPTOR_SIZE );
324324 memcpy (& hash_key , ci -> ci_master_key_descriptor , sizeof (hash_key ));
325325
326326 spin_lock (& fscrypt_master_keys_lock );
327327 hash_for_each_possible (fscrypt_master_keys , mk , mk_node , hash_key ) {
328328 if (memcmp (ci -> ci_master_key_descriptor , mk -> mk_descriptor ,
329- FS_KEY_DESCRIPTOR_SIZE ) != 0 )
329+ FSCRYPT_KEY_DESCRIPTOR_SIZE ) != 0 )
330330 continue ;
331331 if (mode != mk -> mk_mode )
332332 continue ;
@@ -370,7 +370,7 @@ fscrypt_get_master_key(const struct fscrypt_info *ci, struct fscrypt_mode *mode,
370370 goto err_free_mk ;
371371 }
372372 memcpy (mk -> mk_descriptor , ci -> ci_master_key_descriptor ,
373- FS_KEY_DESCRIPTOR_SIZE );
373+ FSCRYPT_KEY_DESCRIPTOR_SIZE );
374374 memcpy (mk -> mk_raw , raw_key , mode -> keysize );
375375
376376 return find_or_insert_master_key (mk , raw_key , mode , ci );
@@ -448,8 +448,8 @@ static int init_essiv_generator(struct fscrypt_info *ci, const u8 *raw_key,
448448
449449/*
450450 * Given the encryption mode and key (normally the derived key, but for
451- * FS_POLICY_FLAG_DIRECT_KEY mode it's the master key), set up the inode's
452- * symmetric cipher transform object(s).
451+ * DIRECT_KEY mode it's the master key), set up the inode's symmetric cipher
452+ * transform object(s).
453453 */
454454static int setup_crypto_transform (struct fscrypt_info * ci ,
455455 struct fscrypt_mode * mode ,
@@ -459,7 +459,7 @@ static int setup_crypto_transform(struct fscrypt_info *ci,
459459 struct crypto_skcipher * ctfm ;
460460 int err ;
461461
462- if (ci -> ci_flags & FS_POLICY_FLAG_DIRECT_KEY ) {
462+ if (ci -> ci_flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY ) {
463463 mk = fscrypt_get_master_key (ci , mode , raw_key , inode );
464464 if (IS_ERR (mk ))
465465 return PTR_ERR (mk );
@@ -476,7 +476,7 @@ static int setup_crypto_transform(struct fscrypt_info *ci,
476476 if (mode -> needs_essiv ) {
477477 /* ESSIV implies 16-byte IVs which implies !DIRECT_KEY */
478478 WARN_ON (mode -> ivsize != AES_BLOCK_SIZE );
479- WARN_ON (ci -> ci_flags & FS_POLICY_FLAG_DIRECT_KEY );
479+ WARN_ON (ci -> ci_flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY );
480480
481481 err = init_essiv_generator (ci , raw_key , mode -> keysize );
482482 if (err ) {
@@ -530,9 +530,10 @@ int fscrypt_get_encryption_info(struct inode *inode)
530530 /* Fake up a context for an unencrypted directory */
531531 memset (& ctx , 0 , sizeof (ctx ));
532532 ctx .format = FS_ENCRYPTION_CONTEXT_FORMAT_V1 ;
533- ctx .contents_encryption_mode = FS_ENCRYPTION_MODE_AES_256_XTS ;
534- ctx .filenames_encryption_mode = FS_ENCRYPTION_MODE_AES_256_CTS ;
535- memset (ctx .master_key_descriptor , 0x42 , FS_KEY_DESCRIPTOR_SIZE );
533+ ctx .contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS ;
534+ ctx .filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS ;
535+ memset (ctx .master_key_descriptor , 0x42 ,
536+ FSCRYPT_KEY_DESCRIPTOR_SIZE );
536537 } else if (res != sizeof (ctx )) {
537538 fscrypt_warn (inode ,
538539 "Unknown encryption context size (%d bytes)" , res );
@@ -545,7 +546,7 @@ int fscrypt_get_encryption_info(struct inode *inode)
545546 return - EINVAL ;
546547 }
547548
548- if (ctx .flags & ~FS_POLICY_FLAGS_VALID ) {
549+ if (ctx .flags & ~FSCRYPT_POLICY_FLAGS_VALID ) {
549550 fscrypt_warn (inode , "Unknown encryption context flags (0x%02x)" ,
550551 ctx .flags );
551552 return - EINVAL ;
@@ -559,7 +560,7 @@ int fscrypt_get_encryption_info(struct inode *inode)
559560 crypt_info -> ci_data_mode = ctx .contents_encryption_mode ;
560561 crypt_info -> ci_filename_mode = ctx .filenames_encryption_mode ;
561562 memcpy (crypt_info -> ci_master_key_descriptor , ctx .master_key_descriptor ,
562- FS_KEY_DESCRIPTOR_SIZE );
563+ FSCRYPT_KEY_DESCRIPTOR_SIZE );
563564 memcpy (crypt_info -> ci_nonce , ctx .nonce , FS_KEY_DERIVATION_NONCE_SIZE );
564565
565566 mode = select_encryption_mode (crypt_info , inode );
0 commit comments