crypto/asymmetric_keys/pkcs7_parser.c
Source file repositories/reference/linux-study-clean/crypto/asymmetric_keys/pkcs7_parser.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/asymmetric_keys/pkcs7_parser.c- Extension
.c- Size
- 18239 bytes
- Lines
- 739
- Domain
- Kernel Services
- Bucket
- crypto
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/module.hlinux/export.hlinux/slab.hlinux/err.hlinux/oid_registry.hcrypto/public_key.hpkcs7_parser.hpkcs7.asn1.h
Detected Declarations
struct pkcs7_parse_contextfunction pkcs7_free_signed_infofunction pkcs7_free_messagefunction pkcs7_check_authattrsfunction pkcs7_get_content_datafunction pkcs7_note_OIDfunction pkcs7_sig_note_digest_algofunction pkcs7_sig_note_pkey_algofunction pkcs7_check_content_typefunction pkcs7_note_signeddata_versionfunction pkcs7_note_signerinfo_versionfunction pkcs7_extract_certfunction pkcs7_note_certificate_listfunction pkcs7_note_contentfunction pkcs7_note_datafunction pkcs7_sig_note_authenticated_attrfunction pkcs7_sig_note_set_of_authattrsfunction pkcs7_sig_note_serialfunction pkcs7_sig_note_issuerfunction pkcs7_sig_note_skidfunction pkcs7_sig_note_signaturefunction pkcs7_note_signed_infoexport pkcs7_free_messageexport pkcs7_parse_messageexport pkcs7_get_content_data
Annotated Snippet
struct pkcs7_parse_context {
struct pkcs7_message *msg; /* Message being constructed */
struct pkcs7_signed_info *sinfo; /* SignedInfo being constructed */
struct pkcs7_signed_info **ppsinfo;
struct x509_certificate *certs; /* Certificate cache */
struct x509_certificate **ppcerts;
unsigned long data; /* Start of data */
enum OID last_oid; /* Last OID encountered */
unsigned x509_index;
unsigned sinfo_index;
const void *raw_serial;
unsigned raw_serial_size;
unsigned raw_issuer_size;
const void *raw_issuer;
const void *raw_skid;
unsigned raw_skid_size;
bool expect_skid;
};
/*
* Free a signed information block.
*/
static void pkcs7_free_signed_info(struct pkcs7_signed_info *sinfo)
{
if (sinfo) {
public_key_signature_free(sinfo->sig);
kfree(sinfo);
}
}
/**
* pkcs7_free_message - Free a PKCS#7 message
* @pkcs7: The PKCS#7 message to free
*/
void pkcs7_free_message(struct pkcs7_message *pkcs7)
{
struct x509_certificate *cert;
struct pkcs7_signed_info *sinfo;
if (pkcs7) {
while (pkcs7->certs) {
cert = pkcs7->certs;
pkcs7->certs = cert->next;
x509_free_certificate(cert);
}
while (pkcs7->crl) {
cert = pkcs7->crl;
pkcs7->crl = cert->next;
x509_free_certificate(cert);
}
while (pkcs7->signed_infos) {
sinfo = pkcs7->signed_infos;
pkcs7->signed_infos = sinfo->next;
pkcs7_free_signed_info(sinfo);
}
kfree(pkcs7);
}
}
EXPORT_SYMBOL_GPL(pkcs7_free_message);
/*
* Check authenticatedAttributes are provided or not provided consistently.
*/
static int pkcs7_check_authattrs(struct pkcs7_message *msg)
{
struct pkcs7_signed_info *sinfo;
bool want = false;
sinfo = msg->signed_infos;
if (!sinfo)
goto inconsistent;
#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA
msg->authattrs_rej_waivable = true;
#endif
if (sinfo->authattrs) {
want = true;
msg->have_authattrs = true;
#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA
if (strncmp(sinfo->sig->pkey_algo, "mldsa", 5) != 0)
msg->authattrs_rej_waivable = false;
#endif
} else if (sinfo->sig->algo_takes_data) {
sinfo->sig->hash_algo = "none";
}
for (sinfo = sinfo->next; sinfo; sinfo = sinfo->next) {
if (!!sinfo->authattrs != want)
goto inconsistent;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/export.h`, `linux/slab.h`, `linux/err.h`, `linux/oid_registry.h`, `crypto/public_key.h`, `pkcs7_parser.h`.
- Detected declarations: `struct pkcs7_parse_context`, `function pkcs7_free_signed_info`, `function pkcs7_free_message`, `function pkcs7_check_authattrs`, `function pkcs7_get_content_data`, `function pkcs7_note_OID`, `function pkcs7_sig_note_digest_algo`, `function pkcs7_sig_note_pkey_algo`, `function pkcs7_check_content_type`, `function pkcs7_note_signeddata_version`.
- Atlas domain: Kernel Services / crypto.
- Implementation status: integration 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.