fs/crypto/fscrypt_private.h
Source file repositories/reference/linux-study-clean/fs/crypto/fscrypt_private.h
File Facts
- System
- Linux kernel
- Corpus path
fs/crypto/fscrypt_private.h- Extension
.h- Size
- 25038 bytes
- Lines
- 785
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/sha2.hlinux/fscrypt.hlinux/minmax.hlinux/siphash.hlinux/blk-crypto.h
Detected Declarations
struct fscrypt_context_v1struct fscrypt_context_v2struct fscrypt_symlink_datastruct fscrypt_prepared_keystruct fscrypt_inode_infostruct fscrypt_master_key_secretstruct fscrypt_master_keystruct fscrypt_modefunction fscrypt_context_sizefunction fscrypt_context_is_validfunction fscrypt_policy_sizefunction fscrypt_policy_contents_modefunction fscrypt_policy_fnames_modefunction fscrypt_policy_flagsfunction fscrypt_policy_v2_du_bitsfunction fscrypt_policy_du_bitsfunction fscrypt_max_file_dun_bitsfunction fscrypt_using_inline_encryptionfunction fscrypt_is_key_preparedfunction fscrypt_select_encryption_implfunction fscrypt_using_inline_encryptionfunction fscrypt_prepare_inline_crypt_keyfunction fscrypt_destroy_inline_crypt_keyfunction fscrypt_is_key_preparedfunction master_key_spec_lenfunction fscrypt_require_key
Annotated Snippet
struct fscrypt_context_v1 {
u8 version; /* FSCRYPT_CONTEXT_V1 */
u8 contents_encryption_mode;
u8 filenames_encryption_mode;
u8 flags;
u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
u8 nonce[FSCRYPT_FILE_NONCE_SIZE];
};
struct fscrypt_context_v2 {
u8 version; /* FSCRYPT_CONTEXT_V2 */
u8 contents_encryption_mode;
u8 filenames_encryption_mode;
u8 flags;
u8 log2_data_unit_size;
u8 __reserved[3];
u8 master_key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE];
u8 nonce[FSCRYPT_FILE_NONCE_SIZE];
};
/*
* fscrypt_context - the encryption context of an inode
*
* This is the on-disk equivalent of an fscrypt_policy, stored alongside each
* encrypted file usually in a hidden extended attribute. It contains the
* fields from the fscrypt_policy, in order to identify the encryption algorithm
* and key with which the file is encrypted. It also contains a nonce that was
* randomly generated by fscrypt itself; this is used as KDF input or as a tweak
* to cause different files to be encrypted differently.
*/
union fscrypt_context {
u8 version;
struct fscrypt_context_v1 v1;
struct fscrypt_context_v2 v2;
};
/*
* Return the size expected for the given fscrypt_context based on its version
* number, or 0 if the context version is unrecognized.
*/
static inline int fscrypt_context_size(const union fscrypt_context *ctx)
{
switch (ctx->version) {
case FSCRYPT_CONTEXT_V1:
BUILD_BUG_ON(sizeof(ctx->v1) != 28);
return sizeof(ctx->v1);
case FSCRYPT_CONTEXT_V2:
BUILD_BUG_ON(sizeof(ctx->v2) != 40);
return sizeof(ctx->v2);
}
return 0;
}
/* Check whether an fscrypt_context has a recognized version number and size */
static inline bool fscrypt_context_is_valid(const union fscrypt_context *ctx,
int ctx_size)
{
return ctx_size >= 1 && ctx_size == fscrypt_context_size(ctx);
}
/* Retrieve the context's nonce, assuming the context was already validated */
static inline const u8 *fscrypt_context_nonce(const union fscrypt_context *ctx)
{
switch (ctx->version) {
case FSCRYPT_CONTEXT_V1:
return ctx->v1.nonce;
case FSCRYPT_CONTEXT_V2:
return ctx->v2.nonce;
}
WARN_ON_ONCE(1);
return NULL;
}
union fscrypt_policy {
u8 version;
struct fscrypt_policy_v1 v1;
struct fscrypt_policy_v2 v2;
};
/*
* Return the size expected for the given fscrypt_policy based on its version
* number, or 0 if the policy version is unrecognized.
*/
static inline int fscrypt_policy_size(const union fscrypt_policy *policy)
{
switch (policy->version) {
case FSCRYPT_POLICY_V1:
return sizeof(policy->v1);
case FSCRYPT_POLICY_V2:
return sizeof(policy->v2);
Annotation
- Immediate include surface: `crypto/sha2.h`, `linux/fscrypt.h`, `linux/minmax.h`, `linux/siphash.h`, `linux/blk-crypto.h`.
- Detected declarations: `struct fscrypt_context_v1`, `struct fscrypt_context_v2`, `struct fscrypt_symlink_data`, `struct fscrypt_prepared_key`, `struct fscrypt_inode_info`, `struct fscrypt_master_key_secret`, `struct fscrypt_master_key`, `struct fscrypt_mode`, `function fscrypt_context_size`, `function fscrypt_context_is_valid`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
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.