crypto/rsassa-pkcs1.c
Source file repositories/reference/linux-study-clean/crypto/rsassa-pkcs1.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/rsassa-pkcs1.c- Extension
.c- Size
- 11391 bytes
- Lines
- 438
- 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/module.hlinux/scatterlist.hcrypto/akcipher.hcrypto/algapi.hcrypto/hash.hcrypto/sig.hcrypto/internal/akcipher.hcrypto/internal/rsa.hcrypto/internal/sig.h
Detected Declarations
struct rsassa_pkcs1_ctxstruct rsassa_pkcs1_inst_ctxfunction rsassa_pkcs1_invalid_hash_lenfunction rsassa_pkcs1_signfunction rsassa_pkcs1_verifyfunction rsassa_pkcs1_key_sizefunction rsassa_pkcs1_set_pub_keyfunction rsassa_pkcs1_set_priv_keyfunction rsassa_pkcs1_init_tfmfunction rsassa_pkcs1_exit_tfmfunction rsassa_pkcs1_freefunction rsassa_pkcs1_create
Annotated Snippet
struct rsassa_pkcs1_ctx {
struct crypto_akcipher *child;
unsigned int key_size;
};
struct rsassa_pkcs1_inst_ctx {
struct crypto_akcipher_spawn spawn;
const struct hash_prefix *hash_prefix;
};
static int rsassa_pkcs1_sign(struct crypto_sig *tfm,
const void *src, unsigned int slen,
void *dst, unsigned int dlen)
{
struct sig_instance *inst = sig_alg_instance(tfm);
struct rsassa_pkcs1_inst_ctx *ictx = sig_instance_ctx(inst);
const struct hash_prefix *hash_prefix = ictx->hash_prefix;
struct rsassa_pkcs1_ctx *ctx = crypto_sig_ctx(tfm);
unsigned int pad_len;
unsigned int ps_end;
unsigned int len;
u8 *in_buf;
int err;
if (!ctx->key_size)
return -EINVAL;
if (dlen < ctx->key_size)
return -EOVERFLOW;
if (rsassa_pkcs1_invalid_hash_len(slen, hash_prefix))
return -EINVAL;
if (slen + hash_prefix->size > ctx->key_size - 11)
return -EOVERFLOW;
pad_len = ctx->key_size - slen - hash_prefix->size - 1;
/* RFC 8017 sec 8.2.1 step 1 - EMSA-PKCS1-v1_5 encoding generation */
in_buf = dst;
memmove(in_buf + pad_len + hash_prefix->size, src, slen);
memcpy(in_buf + pad_len, hash_prefix->data, hash_prefix->size);
ps_end = pad_len - 1;
in_buf[0] = 0x01;
memset(in_buf + 1, 0xff, ps_end - 1);
in_buf[ps_end] = 0x00;
/* RFC 8017 sec 8.2.1 step 2 - RSA signature */
err = crypto_akcipher_sync_decrypt(ctx->child, in_buf,
ctx->key_size - 1, in_buf,
ctx->key_size);
if (err < 0)
return err;
len = err;
pad_len = ctx->key_size - len;
/* Four billion to one */
if (unlikely(pad_len)) {
memmove(dst + pad_len, dst, len);
memset(dst, 0, pad_len);
}
return ctx->key_size;
}
static int rsassa_pkcs1_verify(struct crypto_sig *tfm,
const void *src, unsigned int slen,
const void *digest, unsigned int dlen)
{
struct sig_instance *inst = sig_alg_instance(tfm);
struct rsassa_pkcs1_inst_ctx *ictx = sig_instance_ctx(inst);
const struct hash_prefix *hash_prefix = ictx->hash_prefix;
struct rsassa_pkcs1_ctx *ctx = crypto_sig_ctx(tfm);
unsigned int child_reqsize = crypto_akcipher_reqsize(ctx->child);
struct akcipher_request *child_req __free(kfree_sensitive) = NULL;
struct crypto_wait cwait;
struct scatterlist sg;
unsigned int dst_len;
unsigned int pos;
u8 *out_buf;
int err;
/* RFC 8017 sec 8.2.2 step 1 - length checking */
if (!ctx->key_size ||
slen != ctx->key_size ||
rsassa_pkcs1_invalid_hash_len(dlen, hash_prefix))
return -EINVAL;
Annotation
- Immediate include surface: `linux/module.h`, `linux/scatterlist.h`, `crypto/akcipher.h`, `crypto/algapi.h`, `crypto/hash.h`, `crypto/sig.h`, `crypto/internal/akcipher.h`, `crypto/internal/rsa.h`.
- Detected declarations: `struct rsassa_pkcs1_ctx`, `struct rsassa_pkcs1_inst_ctx`, `function rsassa_pkcs1_invalid_hash_len`, `function rsassa_pkcs1_sign`, `function rsassa_pkcs1_verify`, `function rsassa_pkcs1_key_size`, `function rsassa_pkcs1_set_pub_key`, `function rsassa_pkcs1_set_priv_key`, `function rsassa_pkcs1_init_tfm`, `function rsassa_pkcs1_exit_tfm`.
- 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.