lib/asn1_encoder.c
Source file repositories/reference/linux-study-clean/lib/asn1_encoder.c
File Facts
- System
- Linux kernel
- Corpus path
lib/asn1_encoder.c- Extension
.c- Size
- 10576 bytes
- Lines
- 454
- Domain
- Kernel Services
- Bucket
- lib
- 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.
Dependency Surface
linux/asn1_encoder.hlinux/bug.hlinux/string.hlinux/module.h
Detected Declarations
function Copyrightfunction asn1_encode_oid_digitfunction asn1_encode_oidfunction asn1_encode_lengthfunction asn1_encode_tagfunction asn1_encode_octet_stringfunction asn1_encode_sequencefunction asn1_encode_booleanexport asn1_encode_integerexport asn1_encode_oidexport asn1_encode_tagexport asn1_encode_octet_stringexport asn1_encode_sequenceexport asn1_encode_boolean
Annotated Snippet
if (!found && (byte & 0x80)) {
/*
* no check needed here, we already know we
* have len >= 1
*/
*d++ = 0;
data_len--;
}
found = true;
if (data_len == 0)
return ERR_PTR(-EINVAL);
*d++ = byte;
data_len--;
}
out:
data[1] = d - data - 2;
return d;
}
EXPORT_SYMBOL_GPL(asn1_encode_integer);
/* calculate the base 128 digit values setting the top bit of the first octet */
static int asn1_encode_oid_digit(unsigned char **_data, int *data_len, u32 oid)
{
unsigned char *data = *_data;
int start = 7 + 7 + 7 + 7;
int ret = 0;
if (*data_len < 1)
return -EINVAL;
/* quick case */
if (oid == 0) {
*data++ = 0x80;
(*data_len)--;
goto out;
}
while (oid >> start == 0)
start -= 7;
while (start > 0 && *data_len > 0) {
u8 byte;
byte = oid >> start;
oid = oid - (byte << start);
start -= 7;
byte |= 0x80;
*data++ = byte;
(*data_len)--;
}
if (*data_len > 0) {
*data++ = oid;
(*data_len)--;
} else {
ret = -EINVAL;
}
out:
*_data = data;
return ret;
}
/**
* asn1_encode_oid() - encode an oid to ASN.1
* @data: position to begin encoding at
* @end_data: end of data pointer, points one beyond last usable byte in @data
* @oid: array of oids
* @oid_len: length of oid array
*
* this encodes an OID up to ASN.1 when presented as an array of OID values
*/
unsigned char *
asn1_encode_oid(unsigned char *data, const unsigned char *end_data,
u32 oid[], int oid_len)
{
int data_len = end_data - data;
unsigned char *d = data + 2;
int i, ret;
if (WARN(oid_len < 2, "OID must have at least two elements"))
return ERR_PTR(-EINVAL);
if (WARN(oid_len > 32, "OID is too large"))
return ERR_PTR(-EINVAL);
Annotation
- Immediate include surface: `linux/asn1_encoder.h`, `linux/bug.h`, `linux/string.h`, `linux/module.h`.
- Detected declarations: `function Copyright`, `function asn1_encode_oid_digit`, `function asn1_encode_oid`, `function asn1_encode_length`, `function asn1_encode_tag`, `function asn1_encode_octet_string`, `function asn1_encode_sequence`, `function asn1_encode_boolean`, `export asn1_encode_integer`, `export asn1_encode_oid`.
- Atlas domain: Kernel Services / lib.
- 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.