crypto/ecdsa-x962.c
Source file repositories/reference/linux-study-clean/crypto/ecdsa-x962.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/ecdsa-x962.c- Extension
.c- Size
- 5989 bytes
- Lines
- 239
- Domain
- Kernel Services
- Bucket
- crypto
- Inferred role
- Kernel Services: implementation source
- Status
- source 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.
- 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_decoder.hlinux/err.hlinux/module.hcrypto/algapi.hcrypto/sig.hcrypto/internal/ecc.hcrypto/internal/sig.hecdsasignature.asn1.h
Detected Declarations
struct ecdsa_x962_ctxstruct ecdsa_x962_signature_ctxfunction ecdsa_get_signature_rsfunction ecdsa_get_signature_rfunction ecdsa_get_signature_sfunction ecdsa_x962_verifyfunction ecdsa_x962_key_sizefunction ecdsa_x962_max_sizefunction ecdsa_x962_digest_sizefunction ecdsa_x962_set_pub_keyfunction ecdsa_x962_init_tfmfunction ecdsa_x962_exit_tfmfunction ecdsa_x962_freefunction ecdsa_x962_create
Annotated Snippet
struct ecdsa_x962_ctx {
struct crypto_sig *child;
};
struct ecdsa_x962_signature_ctx {
struct ecdsa_raw_sig sig;
unsigned int ndigits;
};
/* Get the r and s components of a signature from the X.509 certificate. */
static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag,
const void *value, size_t vlen,
unsigned int ndigits)
{
size_t bufsize = ndigits * sizeof(u64);
const char *d = value;
if (!value || !vlen || vlen > bufsize + 1)
return -EINVAL;
/*
* vlen may be 1 byte larger than bufsize due to a leading zero byte
* (necessary if the most significant bit of the integer is set).
*/
if (vlen > bufsize) {
/* skip over leading zeros that make 'value' a positive int */
if (*d == 0) {
vlen -= 1;
d++;
} else {
return -EINVAL;
}
}
ecc_digits_from_bytes(d, vlen, dest, ndigits);
return 0;
}
int ecdsa_get_signature_r(void *context, size_t hdrlen, unsigned char tag,
const void *value, size_t vlen)
{
struct ecdsa_x962_signature_ctx *sig_ctx = context;
return ecdsa_get_signature_rs(sig_ctx->sig.r, hdrlen, tag, value, vlen,
sig_ctx->ndigits);
}
int ecdsa_get_signature_s(void *context, size_t hdrlen, unsigned char tag,
const void *value, size_t vlen)
{
struct ecdsa_x962_signature_ctx *sig_ctx = context;
return ecdsa_get_signature_rs(sig_ctx->sig.s, hdrlen, tag, value, vlen,
sig_ctx->ndigits);
}
static int ecdsa_x962_verify(struct crypto_sig *tfm,
const void *src, unsigned int slen,
const void *digest, unsigned int dlen)
{
struct ecdsa_x962_ctx *ctx = crypto_sig_ctx(tfm);
struct ecdsa_x962_signature_ctx sig_ctx;
int err;
sig_ctx.ndigits = DIV_ROUND_UP_POW2(crypto_sig_keysize(ctx->child),
sizeof(u64) * BITS_PER_BYTE);
err = asn1_ber_decoder(&ecdsasignature_decoder, &sig_ctx, src, slen);
if (err < 0)
return err;
return crypto_sig_verify(ctx->child, &sig_ctx.sig, sizeof(sig_ctx.sig),
digest, dlen);
}
static unsigned int ecdsa_x962_key_size(struct crypto_sig *tfm)
{
struct ecdsa_x962_ctx *ctx = crypto_sig_ctx(tfm);
return crypto_sig_keysize(ctx->child);
}
static unsigned int ecdsa_x962_max_size(struct crypto_sig *tfm)
{
struct ecdsa_x962_ctx *ctx = crypto_sig_ctx(tfm);
struct sig_alg *alg = crypto_sig_alg(ctx->child);
int slen = DIV_ROUND_UP_POW2(crypto_sig_keysize(ctx->child),
BITS_PER_BYTE);
Annotation
- Immediate include surface: `linux/asn1_decoder.h`, `linux/err.h`, `linux/module.h`, `crypto/algapi.h`, `crypto/sig.h`, `crypto/internal/ecc.h`, `crypto/internal/sig.h`, `ecdsasignature.asn1.h`.
- Detected declarations: `struct ecdsa_x962_ctx`, `struct ecdsa_x962_signature_ctx`, `function ecdsa_get_signature_rs`, `function ecdsa_get_signature_r`, `function ecdsa_get_signature_s`, `function ecdsa_x962_verify`, `function ecdsa_x962_key_size`, `function ecdsa_x962_max_size`, `function ecdsa_x962_digest_size`, `function ecdsa_x962_set_pub_key`.
- Atlas domain: Kernel Services / crypto.
- 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.