drivers/crypto/nx/nx-sha256.c
Source file repositories/reference/linux-study-clean/drivers/crypto/nx/nx-sha256.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/nx/nx-sha256.c- Extension
.c- Size
- 6795 bytes
- Lines
- 261
- Domain
- Driver Families
- Bucket
- drivers/crypto
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/internal/hash.hcrypto/sha2.hlinux/errno.hlinux/kernel.hlinux/module.hlinux/spinlock.hlinux/string.hlinux/unaligned.hnx_csbcpb.hnx.h
Detected Declarations
struct sha256_state_befunction nx_crypto_ctx_sha256_initfunction nx_sha256_initfunction nx_sha256_updatefunction nx_sha256_finupfunction nx_sha256_exportfunction nx_sha256_import
Annotated Snippet
struct sha256_state_be {
__be32 state[SHA256_DIGEST_SIZE / 4];
u64 count;
};
static int nx_crypto_ctx_sha256_init(struct crypto_shash *tfm)
{
struct nx_crypto_ctx *nx_ctx = crypto_shash_ctx(tfm);
int err;
err = nx_crypto_ctx_sha_init(tfm);
if (err)
return err;
nx_ctx_init(nx_ctx, HCOP_FC_SHA);
nx_ctx->ap = &nx_ctx->props[NX_PROPS_SHA256];
NX_CPB_SET_DIGEST_SIZE(nx_ctx->csbcpb, NX_DS_SHA256);
return 0;
}
static int nx_sha256_init(struct shash_desc *desc)
{
struct sha256_state_be *sctx = shash_desc_ctx(desc);
sctx->state[0] = __cpu_to_be32(SHA256_H0);
sctx->state[1] = __cpu_to_be32(SHA256_H1);
sctx->state[2] = __cpu_to_be32(SHA256_H2);
sctx->state[3] = __cpu_to_be32(SHA256_H3);
sctx->state[4] = __cpu_to_be32(SHA256_H4);
sctx->state[5] = __cpu_to_be32(SHA256_H5);
sctx->state[6] = __cpu_to_be32(SHA256_H6);
sctx->state[7] = __cpu_to_be32(SHA256_H7);
sctx->count = 0;
return 0;
}
static int nx_sha256_update(struct shash_desc *desc, const u8 *data,
unsigned int len)
{
struct nx_crypto_ctx *nx_ctx = crypto_shash_ctx(desc->tfm);
struct sha256_state_be *sctx = shash_desc_ctx(desc);
struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb;
u64 to_process, leftover, total = len;
struct nx_sg *out_sg;
unsigned long irq_flags;
int rc = 0;
int data_len;
u32 max_sg_len;
spin_lock_irqsave(&nx_ctx->lock, irq_flags);
memcpy(csbcpb->cpb.sha256.message_digest, sctx->state, SHA256_DIGEST_SIZE);
NX_CPB_FDM(csbcpb) |= NX_FDM_INTERMEDIATE;
NX_CPB_FDM(csbcpb) |= NX_FDM_CONTINUATION;
max_sg_len = min_t(u64, nx_ctx->ap->sglen,
nx_driver.of.max_sg_len/sizeof(struct nx_sg));
max_sg_len = min_t(u64, max_sg_len,
nx_ctx->ap->databytelen/NX_PAGE_SIZE);
data_len = SHA256_DIGEST_SIZE;
out_sg = nx_build_sg_list(nx_ctx->out_sg, (u8 *)sctx->state,
&data_len, max_sg_len);
nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg);
if (data_len != SHA256_DIGEST_SIZE) {
rc = -EINVAL;
goto out;
}
do {
struct nx_sg *in_sg = nx_ctx->in_sg;
to_process = total & ~(SHA256_BLOCK_SIZE - 1);
data_len = to_process;
in_sg = nx_build_sg_list(in_sg, (u8 *) data,
&data_len, max_sg_len);
nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * sizeof(struct nx_sg);
to_process = data_len;
leftover = total - to_process;
/*
* we've hit the nx chip previously and we're updating
Annotation
- Immediate include surface: `crypto/internal/hash.h`, `crypto/sha2.h`, `linux/errno.h`, `linux/kernel.h`, `linux/module.h`, `linux/spinlock.h`, `linux/string.h`, `linux/unaligned.h`.
- Detected declarations: `struct sha256_state_be`, `function nx_crypto_ctx_sha256_init`, `function nx_sha256_init`, `function nx_sha256_update`, `function nx_sha256_finup`, `function nx_sha256_export`, `function nx_sha256_import`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.