Lines Matching refs:crypt_stat

62 				  struct ecryptfs_crypt_stat *crypt_stat,  in ecryptfs_calculate_md5()  argument
65 int rc = crypto_shash_tfm_digest(crypt_stat->hash_tfm, src, len, dst); in ecryptfs_calculate_md5()
110 int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_derive_iv() argument
119 ecryptfs_dump_hex(crypt_stat->root_iv, crypt_stat->iv_bytes); in ecryptfs_derive_iv()
125 memcpy(src, crypt_stat->root_iv, crypt_stat->iv_bytes); in ecryptfs_derive_iv()
126 memset((src + crypt_stat->iv_bytes), 0, 16); in ecryptfs_derive_iv()
127 snprintf((src + crypt_stat->iv_bytes), 16, "%lld", offset); in ecryptfs_derive_iv()
130 ecryptfs_dump_hex(src, (crypt_stat->iv_bytes + 16)); in ecryptfs_derive_iv()
132 rc = ecryptfs_calculate_md5(dst, crypt_stat, src, in ecryptfs_derive_iv()
133 (crypt_stat->iv_bytes + 16)); in ecryptfs_derive_iv()
139 memcpy(iv, dst, crypt_stat->iv_bytes); in ecryptfs_derive_iv()
142 ecryptfs_dump_hex(iv, crypt_stat->iv_bytes); in ecryptfs_derive_iv()
154 int ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat) in ecryptfs_init_crypt_stat() argument
168 memset((void *)crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); in ecryptfs_init_crypt_stat()
169 INIT_LIST_HEAD(&crypt_stat->keysig_list); in ecryptfs_init_crypt_stat()
170 mutex_init(&crypt_stat->keysig_list_mutex); in ecryptfs_init_crypt_stat()
171 mutex_init(&crypt_stat->cs_mutex); in ecryptfs_init_crypt_stat()
172 mutex_init(&crypt_stat->cs_tfm_mutex); in ecryptfs_init_crypt_stat()
173 crypt_stat->hash_tfm = tfm; in ecryptfs_init_crypt_stat()
174 crypt_stat->flags |= ECRYPTFS_STRUCT_INITIALIZED; in ecryptfs_init_crypt_stat()
185 void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat) in ecryptfs_destroy_crypt_stat() argument
189 crypto_free_skcipher(crypt_stat->tfm); in ecryptfs_destroy_crypt_stat()
190 crypto_free_shash(crypt_stat->hash_tfm); in ecryptfs_destroy_crypt_stat()
192 &crypt_stat->keysig_list, crypt_stat_list) { in ecryptfs_destroy_crypt_stat()
196 memset(crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); in ecryptfs_destroy_crypt_stat()
290 static int crypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, in crypt_scatterlist() argument
301 crypt_stat->key_size); in crypt_scatterlist()
302 ecryptfs_dump_hex(crypt_stat->key, in crypt_scatterlist()
303 crypt_stat->key_size); in crypt_scatterlist()
308 mutex_lock(&crypt_stat->cs_tfm_mutex); in crypt_scatterlist()
309 req = skcipher_request_alloc(crypt_stat->tfm, GFP_NOFS); in crypt_scatterlist()
311 mutex_unlock(&crypt_stat->cs_tfm_mutex); in crypt_scatterlist()
320 if (!(crypt_stat->flags & ECRYPTFS_KEY_SET)) { in crypt_scatterlist()
321 rc = crypto_skcipher_setkey(crypt_stat->tfm, crypt_stat->key, in crypt_scatterlist()
322 crypt_stat->key_size); in crypt_scatterlist()
327 mutex_unlock(&crypt_stat->cs_tfm_mutex); in crypt_scatterlist()
331 crypt_stat->flags |= ECRYPTFS_KEY_SET; in crypt_scatterlist()
333 mutex_unlock(&crypt_stat->cs_tfm_mutex); in crypt_scatterlist()
354 static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat, in lower_offset_for_page() argument
357 return ecryptfs_lower_header_size(crypt_stat) + in lower_offset_for_page()
374 static int crypt_extent(struct ecryptfs_crypt_stat *crypt_stat, in crypt_extent() argument
383 size_t extent_size = crypt_stat->extent_size; in crypt_extent()
387 rc = ecryptfs_derive_iv(extent_iv, crypt_stat, in crypt_extent()
404 rc = crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, extent_size, in crypt_extent()
436 struct ecryptfs_crypt_stat *crypt_stat; in ecryptfs_encrypt_page() local
444 crypt_stat = in ecryptfs_encrypt_page()
445 &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); in ecryptfs_encrypt_page()
446 BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); in ecryptfs_encrypt_page()
456 extent_offset < (PAGE_SIZE / crypt_stat->extent_size); in ecryptfs_encrypt_page()
458 rc = crypt_extent(crypt_stat, enc_extent_page, page, in ecryptfs_encrypt_page()
467 lower_offset = lower_offset_for_page(crypt_stat, page); in ecryptfs_encrypt_page()
505 struct ecryptfs_crypt_stat *crypt_stat; in ecryptfs_decrypt_page() local
512 crypt_stat = in ecryptfs_decrypt_page()
513 &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); in ecryptfs_decrypt_page()
514 BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); in ecryptfs_decrypt_page()
516 lower_offset = lower_offset_for_page(crypt_stat, page); in ecryptfs_decrypt_page()
529 extent_offset < (PAGE_SIZE / crypt_stat->extent_size); in ecryptfs_decrypt_page()
531 rc = crypt_extent(crypt_stat, page, page, in ecryptfs_decrypt_page()
554 int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat) in ecryptfs_init_crypt_ctx() argument
562 crypt_stat->cipher, (int)strlen(crypt_stat->cipher), in ecryptfs_init_crypt_ctx()
563 crypt_stat->key_size << 3); in ecryptfs_init_crypt_ctx()
564 mutex_lock(&crypt_stat->cs_tfm_mutex); in ecryptfs_init_crypt_ctx()
565 if (crypt_stat->tfm) { in ecryptfs_init_crypt_ctx()
570 crypt_stat->cipher, "cbc"); in ecryptfs_init_crypt_ctx()
573 crypt_stat->tfm = crypto_alloc_skcipher(full_alg_name, 0, 0); in ecryptfs_init_crypt_ctx()
574 if (IS_ERR(crypt_stat->tfm)) { in ecryptfs_init_crypt_ctx()
575 rc = PTR_ERR(crypt_stat->tfm); in ecryptfs_init_crypt_ctx()
576 crypt_stat->tfm = NULL; in ecryptfs_init_crypt_ctx()
582 crypto_skcipher_set_flags(crypt_stat->tfm, in ecryptfs_init_crypt_ctx()
588 mutex_unlock(&crypt_stat->cs_tfm_mutex); in ecryptfs_init_crypt_ctx()
592 static void set_extent_mask_and_shift(struct ecryptfs_crypt_stat *crypt_stat) in set_extent_mask_and_shift() argument
596 crypt_stat->extent_mask = 0xFFFFFFFF; in set_extent_mask_and_shift()
597 crypt_stat->extent_shift = 0; in set_extent_mask_and_shift()
598 if (crypt_stat->extent_size == 0) in set_extent_mask_and_shift()
600 extent_size_tmp = crypt_stat->extent_size; in set_extent_mask_and_shift()
603 crypt_stat->extent_mask <<= 1; in set_extent_mask_and_shift()
604 crypt_stat->extent_shift++; in set_extent_mask_and_shift()
608 void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat) in ecryptfs_set_default_sizes() argument
612 crypt_stat->extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE; in ecryptfs_set_default_sizes()
613 set_extent_mask_and_shift(crypt_stat); in ecryptfs_set_default_sizes()
614 crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES; in ecryptfs_set_default_sizes()
615 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) in ecryptfs_set_default_sizes()
616 crypt_stat->metadata_size = ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; in ecryptfs_set_default_sizes()
619 crypt_stat->metadata_size = in ecryptfs_set_default_sizes()
622 crypt_stat->metadata_size = PAGE_SIZE; in ecryptfs_set_default_sizes()
631 int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat) in ecryptfs_compute_root_iv() argument
636 BUG_ON(crypt_stat->iv_bytes > MD5_DIGEST_SIZE); in ecryptfs_compute_root_iv()
637 BUG_ON(crypt_stat->iv_bytes <= 0); in ecryptfs_compute_root_iv()
638 if (!(crypt_stat->flags & ECRYPTFS_KEY_VALID)) { in ecryptfs_compute_root_iv()
644 rc = ecryptfs_calculate_md5(dst, crypt_stat, crypt_stat->key, in ecryptfs_compute_root_iv()
645 crypt_stat->key_size); in ecryptfs_compute_root_iv()
651 memcpy(crypt_stat->root_iv, dst, crypt_stat->iv_bytes); in ecryptfs_compute_root_iv()
654 memset(crypt_stat->root_iv, 0, crypt_stat->iv_bytes); in ecryptfs_compute_root_iv()
655 crypt_stat->flags |= ECRYPTFS_SECURITY_WARNING; in ecryptfs_compute_root_iv()
660 static void ecryptfs_generate_new_key(struct ecryptfs_crypt_stat *crypt_stat) in ecryptfs_generate_new_key() argument
662 get_random_bytes(crypt_stat->key, crypt_stat->key_size); in ecryptfs_generate_new_key()
663 crypt_stat->flags |= ECRYPTFS_KEY_VALID; in ecryptfs_generate_new_key()
664 ecryptfs_compute_root_iv(crypt_stat); in ecryptfs_generate_new_key()
667 ecryptfs_dump_hex(crypt_stat->key, in ecryptfs_generate_new_key()
668 crypt_stat->key_size); in ecryptfs_generate_new_key()
681 struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_copy_mount_wide_flags_to_inode_flags() argument
685 crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; in ecryptfs_copy_mount_wide_flags_to_inode_flags()
687 crypt_stat->flags |= ECRYPTFS_VIEW_AS_ENCRYPTED; in ecryptfs_copy_mount_wide_flags_to_inode_flags()
689 crypt_stat->flags |= ECRYPTFS_ENCRYPT_FILENAMES; in ecryptfs_copy_mount_wide_flags_to_inode_flags()
692 crypt_stat->flags |= ECRYPTFS_ENCFN_USE_MOUNT_FNEK; in ecryptfs_copy_mount_wide_flags_to_inode_flags()
695 crypt_stat->flags |= ECRYPTFS_ENCFN_USE_FEK; in ecryptfs_copy_mount_wide_flags_to_inode_flags()
700 struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_copy_mount_wide_sigs_to_inode_sigs() argument
706 mutex_lock(&crypt_stat->keysig_list_mutex); in ecryptfs_copy_mount_wide_sigs_to_inode_sigs()
714 rc = ecryptfs_add_keysig(crypt_stat, global_auth_tok->sig); in ecryptfs_copy_mount_wide_sigs_to_inode_sigs()
723 mutex_unlock(&crypt_stat->keysig_list_mutex); in ecryptfs_copy_mount_wide_sigs_to_inode_sigs()
735 struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_set_default_crypt_stat_vals() argument
738 ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat, in ecryptfs_set_default_crypt_stat_vals()
740 ecryptfs_set_default_sizes(crypt_stat); in ecryptfs_set_default_crypt_stat_vals()
741 strcpy(crypt_stat->cipher, ECRYPTFS_DEFAULT_CIPHER); in ecryptfs_set_default_crypt_stat_vals()
742 crypt_stat->key_size = ECRYPTFS_DEFAULT_KEY_BYTES; in ecryptfs_set_default_crypt_stat_vals()
743 crypt_stat->flags &= ~(ECRYPTFS_KEY_VALID); in ecryptfs_set_default_crypt_stat_vals()
744 crypt_stat->file_version = ECRYPTFS_FILE_VERSION; in ecryptfs_set_default_crypt_stat_vals()
745 crypt_stat->mount_crypt_stat = mount_crypt_stat; in ecryptfs_set_default_crypt_stat_vals()
769 struct ecryptfs_crypt_stat *crypt_stat = in ecryptfs_new_file_context() local
770 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; in ecryptfs_new_file_context()
777 ecryptfs_set_default_crypt_stat_vals(crypt_stat, mount_crypt_stat); in ecryptfs_new_file_context()
778 crypt_stat->flags |= (ECRYPTFS_ENCRYPTED | ECRYPTFS_KEY_VALID); in ecryptfs_new_file_context()
779 ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat, in ecryptfs_new_file_context()
781 rc = ecryptfs_copy_mount_wide_sigs_to_inode_sigs(crypt_stat, in ecryptfs_new_file_context()
790 memcpy(crypt_stat->cipher, in ecryptfs_new_file_context()
793 crypt_stat->cipher[cipher_name_len] = '\0'; in ecryptfs_new_file_context()
794 crypt_stat->key_size = in ecryptfs_new_file_context()
796 ecryptfs_generate_new_key(crypt_stat); in ecryptfs_new_file_context()
797 rc = ecryptfs_init_crypt_ctx(crypt_stat); in ecryptfs_new_file_context()
801 crypt_stat->cipher, rc); in ecryptfs_new_file_context()
847 static void ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_process_flags() argument
856 crypt_stat->flags |= ecryptfs_flag_map[i].local_flag; in ecryptfs_process_flags()
858 crypt_stat->flags &= ~(ecryptfs_flag_map[i].local_flag); in ecryptfs_process_flags()
860 crypt_stat->file_version = ((flags >> 24) & 0xFF); in ecryptfs_process_flags()
884 struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_write_crypt_stat_flags() argument
891 if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag) in ecryptfs_write_crypt_stat_flags()
894 flags |= ((((u8)crypt_stat->file_version) << 24) & 0xFF000000); in ecryptfs_write_crypt_stat_flags()
998 struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_write_header_metadata() argument
1004 header_extent_size = (u32)crypt_stat->extent_size; in ecryptfs_write_header_metadata()
1006 (u16)(crypt_stat->metadata_size / crypt_stat->extent_size); in ecryptfs_write_header_metadata()
1048 struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_write_headers_virt() argument
1058 ecryptfs_write_crypt_stat_flags((page_virt + offset), crypt_stat, in ecryptfs_write_headers_virt()
1061 ecryptfs_write_header_metadata((page_virt + offset), crypt_stat, in ecryptfs_write_headers_virt()
1064 rc = ecryptfs_generate_key_packet_set((page_virt + offset), crypt_stat, in ecryptfs_write_headers_virt()
1144 struct ecryptfs_crypt_stat *crypt_stat = in ecryptfs_write_metadata() local
1145 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; in ecryptfs_write_metadata()
1152 if (likely(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { in ecryptfs_write_metadata()
1153 if (!(crypt_stat->flags & ECRYPTFS_KEY_VALID)) { in ecryptfs_write_metadata()
1164 virt_len = crypt_stat->metadata_size; in ecryptfs_write_metadata()
1174 rc = ecryptfs_write_headers_virt(virt, virt_len, &size, crypt_stat, in ecryptfs_write_metadata()
1181 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) in ecryptfs_write_metadata()
1200 static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat, in parse_header_metadata() argument
1211 crypt_stat->metadata_size = (((size_t)num_header_extents_at_front in parse_header_metadata()
1215 && (crypt_stat->metadata_size in parse_header_metadata()
1219 crypt_stat->metadata_size); in parse_header_metadata()
1232 static void set_default_header_data(struct ecryptfs_crypt_stat *crypt_stat) in set_default_header_data() argument
1234 crypt_stat->metadata_size = ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; in set_default_header_data()
1240 struct ecryptfs_crypt_stat *crypt_stat; in ecryptfs_i_size_init() local
1243 crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat; in ecryptfs_i_size_init()
1248 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) in ecryptfs_i_size_init()
1249 file_size += crypt_stat->metadata_size; in ecryptfs_i_size_init()
1253 crypt_stat->flags |= ECRYPTFS_I_SIZE_INITIALIZED; in ecryptfs_i_size_init()
1269 struct ecryptfs_crypt_stat *crypt_stat, in ecryptfs_read_headers_virt() argument
1277 ecryptfs_set_default_sizes(crypt_stat); in ecryptfs_read_headers_virt()
1278 crypt_stat->mount_crypt_stat = &ecryptfs_superblock_to_private( in ecryptfs_read_headers_virt()
1284 if (!(crypt_stat->flags & ECRYPTFS_I_SIZE_INITIALIZED)) in ecryptfs_read_headers_virt()
1287 ecryptfs_process_flags(crypt_stat, (page_virt + offset), &bytes_read); in ecryptfs_read_headers_virt()
1288 if (crypt_stat->file_version > ECRYPTFS_SUPPORTED_FILE_VERSION) { in ecryptfs_read_headers_virt()
1292 crypt_stat->file_version, in ecryptfs_read_headers_virt()
1298 if (crypt_stat->file_version >= 1) { in ecryptfs_read_headers_virt()
1299 rc = parse_header_metadata(crypt_stat, (page_virt + offset), in ecryptfs_read_headers_virt()
1307 set_default_header_data(crypt_stat); in ecryptfs_read_headers_virt()
1308 rc = ecryptfs_parse_packet_set(crypt_stat, (page_virt + offset), in ecryptfs_read_headers_virt()
1385 struct ecryptfs_crypt_stat *crypt_stat = in ecryptfs_read_metadata() local
1386 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; in ecryptfs_read_metadata()
1391 ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat, in ecryptfs_read_metadata()
1399 rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size, in ecryptfs_read_metadata()
1402 rc = ecryptfs_read_headers_virt(page_virt, crypt_stat, in ecryptfs_read_metadata()
1416 rc = ecryptfs_read_headers_virt(page_virt, crypt_stat, in ecryptfs_read_metadata()
1425 if (crypt_stat->mount_crypt_stat->flags in ecryptfs_read_metadata()
1427 crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; in ecryptfs_read_metadata()