security/keys/trusted-keys/trusted_tpm2.c
Source file repositories/reference/linux-study-clean/security/keys/trusted-keys/trusted_tpm2.c
File Facts
- System
- Linux kernel
- Corpus path
security/keys/trusted-keys/trusted_tpm2.c- Extension
.c- Size
- 14180 bytes
- Lines
- 606
- Domain
- Core OS
- Bucket
- Security And Isolation
- 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.
- 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
linux/asn1_encoder.hlinux/oid_registry.hlinux/string.hlinux/err.hlinux/tpm.hlinux/tpm_command.hkeys/trusted-type.hkeys/trusted_tpm.hlinux/unaligned.htpm2key.asn1.h
Detected Declarations
struct tpm2_key_contextfunction tpm2_key_encodefunction tpm2_key_decodefunction tpm2_key_parentfunction tpm2_key_typefunction tpm2_key_pubfunction tpm2_key_privfunction tpm2_buf_append_authfunction tpm2_seal_trustedfunction tpm2_load_cmdfunction tpm2_unseal_cmdfunction tpm2_unseal_trusted
Annotated Snippet
struct tpm2_key_context {
u32 parent;
const u8 *pub;
u32 pub_len;
const u8 *priv;
u32 priv_len;
};
static int tpm2_key_decode(struct trusted_key_payload *payload,
struct trusted_key_options *options,
u8 **buf)
{
int ret;
struct tpm2_key_context ctx;
u8 *blob;
memset(&ctx, 0, sizeof(ctx));
ret = asn1_ber_decoder(&tpm2key_decoder, &ctx, payload->blob,
payload->blob_len);
if (ret < 0)
return ret;
if (ctx.priv_len + ctx.pub_len > MAX_BLOB_SIZE)
return -EINVAL;
blob = kmalloc(ctx.priv_len + ctx.pub_len + 4, GFP_KERNEL);
if (!blob)
return -ENOMEM;
*buf = blob;
options->keyhandle = ctx.parent;
memcpy(blob, ctx.priv, ctx.priv_len);
blob += ctx.priv_len;
memcpy(blob, ctx.pub, ctx.pub_len);
return 0;
}
int tpm2_key_parent(void *context, size_t hdrlen,
unsigned char tag,
const void *value, size_t vlen)
{
struct tpm2_key_context *ctx = context;
const u8 *v = value;
int i;
ctx->parent = 0;
for (i = 0; i < vlen; i++) {
ctx->parent <<= 8;
ctx->parent |= v[i];
}
return 0;
}
int tpm2_key_type(void *context, size_t hdrlen,
unsigned char tag,
const void *value, size_t vlen)
{
enum OID oid = look_up_OID(value, vlen);
if (oid != OID_TPMSealedData) {
char buffer[50];
sprint_oid(value, vlen, buffer, sizeof(buffer));
pr_debug("OID is \"%s\" which is not TPMSealedData\n",
buffer);
return -EINVAL;
}
return 0;
}
int tpm2_key_pub(void *context, size_t hdrlen,
unsigned char tag,
const void *value, size_t vlen)
{
struct tpm2_key_context *ctx = context;
ctx->pub = value;
ctx->pub_len = vlen;
return 0;
}
int tpm2_key_priv(void *context, size_t hdrlen,
unsigned char tag,
Annotation
- Immediate include surface: `linux/asn1_encoder.h`, `linux/oid_registry.h`, `linux/string.h`, `linux/err.h`, `linux/tpm.h`, `linux/tpm_command.h`, `keys/trusted-type.h`, `keys/trusted_tpm.h`.
- Detected declarations: `struct tpm2_key_context`, `function tpm2_key_encode`, `function tpm2_key_decode`, `function tpm2_key_parent`, `function tpm2_key_type`, `function tpm2_key_pub`, `function tpm2_key_priv`, `function tpm2_buf_append_auth`, `function tpm2_seal_trusted`, `function tpm2_load_cmd`.
- Atlas domain: Core OS / Security And Isolation.
- 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.