fs/ecryptfs/crypto.c
Source file repositories/reference/linux-study-clean/fs/ecryptfs/crypto.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ecryptfs/crypto.c- Extension
.c- Size
- 59387 bytes
- Lines
- 1986
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/skcipher.hlinux/fs.hlinux/mount.hlinux/pagemap.hlinux/random.hlinux/compiler.hlinux/key.hlinux/namei.hlinux/file.hlinux/scatterlist.hlinux/slab.hlinux/string.hlinux/unaligned.hlinux/kernel.hlinux/xattr.hecryptfs_kernel.h
Detected Declarations
struct ecryptfs_flag_map_elemstruct ecryptfs_cipher_code_str_map_elemfunction sizefunction ecryptfs_crypto_api_algify_cipher_namefunction ecryptfs_derive_ivfunction ecryptfs_init_crypt_statfunction ecryptfs_destroy_crypt_statfunction ecryptfs_destroy_mount_crypt_statfunction virt_to_scatterlistfunction crypt_scatterlistfunction lower_offset_for_pagefunction crypt_extentfunction ecryptfs_encrypt_pagefunction ecryptfs_decrypt_pagefunction ecryptfs_init_crypt_ctxfunction set_extent_mask_and_shiftfunction ecryptfs_set_default_sizesfunction ecryptfs_compute_root_ivfunction ecryptfs_generate_new_keyfunction ecryptfs_copy_mount_wide_flags_to_inode_flagsfunction ecryptfs_copy_mount_wide_sigs_to_inode_sigsfunction list_for_each_entryfunction ecryptfs_set_default_crypt_stat_valsfunction ecryptfs_new_file_contextfunction ecryptfs_validate_markerfunction ecryptfs_process_flagsfunction write_ecryptfs_markerfunction ecryptfs_write_crypt_stat_flagsfunction ecryptfs_code_for_cipher_stringfunction ecryptfs_cipher_code_to_stringfunction ecryptfs_read_and_validate_header_regionfunction ecryptfs_write_header_metadatafunction datafunction ecryptfs_write_metadata_to_contentsfunction ecryptfs_write_metadata_to_xattrfunction ecryptfs_get_zeroed_pagesfunction ecryptfs_write_metadatafunction parse_header_metadatafunction set_default_header_datafunction ecryptfs_i_size_initfunction ecryptfs_write_headers_virtfunction ecryptfs_read_xattr_regionfunction ecryptfs_read_and_validate_xattr_regionfunction ecryptfs_read_metadatafunction ecryptfs_encrypt_filenamefunction ecryptfs_copy_filenamefunction ecryptfs_process_key_cipherfunction ecryptfs_init_crypto
Annotated Snippet
struct ecryptfs_flag_map_elem {
u32 file_flag;
u32 local_flag;
};
/* Add support for additional flags by adding elements here. */
static struct ecryptfs_flag_map_elem ecryptfs_flag_map[] = {
{0x00000001, ECRYPTFS_ENABLE_HMAC},
{0x00000002, ECRYPTFS_ENCRYPTED},
{0x00000004, ECRYPTFS_METADATA_IN_XATTR},
{0x00000008, ECRYPTFS_ENCRYPT_FILENAMES}
};
/**
* ecryptfs_process_flags
* @crypt_stat: The cryptographic context
* @page_virt: Source data to be parsed
* @bytes_read: Updated with the number of bytes read
*/
static void ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat,
char *page_virt, int *bytes_read)
{
int i;
u32 flags;
flags = get_unaligned_be32(page_virt);
for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++)
if (flags & ecryptfs_flag_map[i].file_flag) {
crypt_stat->flags |= ecryptfs_flag_map[i].local_flag;
} else
crypt_stat->flags &= ~(ecryptfs_flag_map[i].local_flag);
/* Version is in top 8 bits of the 32-bit flag vector */
crypt_stat->file_version = ((flags >> 24) & 0xFF);
(*bytes_read) = 4;
}
/**
* write_ecryptfs_marker
* @page_virt: The pointer to in a page to begin writing the marker
* @written: Number of bytes written
*
* Marker = 0x3c81b7f5
*/
static void write_ecryptfs_marker(char *page_virt, size_t *written)
{
u32 m_1, m_2;
get_random_bytes(&m_1, (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2));
m_2 = (m_1 ^ MAGIC_ECRYPTFS_MARKER);
put_unaligned_be32(m_1, page_virt);
page_virt += (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2);
put_unaligned_be32(m_2, page_virt);
(*written) = MAGIC_ECRYPTFS_MARKER_SIZE_BYTES;
}
void ecryptfs_write_crypt_stat_flags(char *page_virt,
struct ecryptfs_crypt_stat *crypt_stat,
size_t *written)
{
u32 flags = 0;
int i;
for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++)
if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag)
flags |= ecryptfs_flag_map[i].file_flag;
/* Version is in top 8 bits of the 32-bit flag vector */
flags |= ((((u8)crypt_stat->file_version) << 24) & 0xFF000000);
put_unaligned_be32(flags, page_virt);
(*written) = 4;
}
struct ecryptfs_cipher_code_str_map_elem {
char cipher_str[16];
u8 cipher_code;
};
/* Add support for additional ciphers by adding elements here. The
* cipher_code is whatever OpenPGP applications use to identify the
* ciphers. List in order of probability. */
static struct ecryptfs_cipher_code_str_map_elem
ecryptfs_cipher_code_str_map[] = {
{"aes",RFC2440_CIPHER_AES_128 },
{"blowfish", RFC2440_CIPHER_BLOWFISH},
{"des3_ede", RFC2440_CIPHER_DES3_EDE},
{"cast5", RFC2440_CIPHER_CAST_5},
{"twofish", RFC2440_CIPHER_TWOFISH},
{"cast6", RFC2440_CIPHER_CAST_6},
{"aes", RFC2440_CIPHER_AES_192},
{"aes", RFC2440_CIPHER_AES_256}
};
Annotation
- Immediate include surface: `crypto/skcipher.h`, `linux/fs.h`, `linux/mount.h`, `linux/pagemap.h`, `linux/random.h`, `linux/compiler.h`, `linux/key.h`, `linux/namei.h`.
- Detected declarations: `struct ecryptfs_flag_map_elem`, `struct ecryptfs_cipher_code_str_map_elem`, `function size`, `function ecryptfs_crypto_api_algify_cipher_name`, `function ecryptfs_derive_iv`, `function ecryptfs_init_crypt_stat`, `function ecryptfs_destroy_crypt_stat`, `function ecryptfs_destroy_mount_crypt_stat`, `function virt_to_scatterlist`, `function crypt_scatterlist`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.