drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
Source file repositories/reference/linux-study-clean/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c- Extension
.c- Size
- 13847 bytes
- Lines
- 487
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/internal/hash.hcrypto/md5.hcrypto/sha1.hcrypto/sha2.hlinux/bottom_half.hlinux/dma-mapping.hlinux/kernel.hlinux/pm_runtime.hlinux/scatterlist.hlinux/slab.hlinux/string.hsun8i-ce.h
Detected Declarations
function Copyrightfunction sun8i_ce_hash_init_tfmfunction sun8i_ce_hash_exit_tfmfunction sun8i_ce_hash_initfunction sun8i_ce_hash_exportfunction sun8i_ce_hash_importfunction sun8i_ce_hash_finalfunction sun8i_ce_hash_updatefunction sun8i_ce_hash_finupfunction sun8i_ce_hash_digest_fbfunction sun8i_ce_hash_need_fallbackfunction sun8i_ce_hash_digestfunction hash_padfunction sun8i_ce_hash_preparefunction sun8i_ce_hash_unpreparefunction sun8i_ce_hash_run
Annotated Snippet
if (sg->length % 4) {
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
algt->stat_fb_srclen++;
return true;
}
if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
algt->stat_fb_srcali++;
return true;
}
sg = sg_next(sg);
}
return false;
}
int sun8i_ce_hash_digest(struct ahash_request *areq)
{
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm);
struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx_dma(areq);
struct sun8i_ce_dev *ce = ctx->ce;
struct crypto_engine *engine;
int e;
if (sun8i_ce_hash_need_fallback(areq))
return sun8i_ce_hash_digest_fb(areq);
e = sun8i_ce_get_engine_number(ce);
rctx->flow = e;
engine = ce->chanlist[e].engine;
return crypto_transfer_hash_request_to_engine(engine, areq);
}
static u64 hash_pad(__le32 *buf, unsigned int bufsize, u64 padi, u64 byte_count, bool le, int bs)
{
u64 fill, min_fill, j, k;
__be64 *bebits;
__le64 *lebits;
j = padi;
buf[j++] = cpu_to_le32(0x80);
if (bs == 64) {
fill = 64 - (byte_count % 64);
min_fill = 2 * sizeof(u32) + sizeof(u32);
} else {
fill = 128 - (byte_count % 128);
min_fill = 4 * sizeof(u32) + sizeof(u32);
}
if (fill < min_fill)
fill += bs;
k = j;
j += (fill - min_fill) / sizeof(u32);
if (j * 4 > bufsize) {
pr_err("%s OVERFLOW %llu\n", __func__, j);
return 0;
}
for (; k < j; k++)
buf[k] = 0;
if (le) {
/* MD5 */
lebits = (__le64 *)&buf[j];
*lebits = cpu_to_le64(byte_count << 3);
j += 2;
} else {
if (bs == 64) {
/* sha1 sha224 sha256 */
bebits = (__be64 *)&buf[j];
*bebits = cpu_to_be64(byte_count << 3);
j += 2;
} else {
/* sha384 sha512*/
bebits = (__be64 *)&buf[j];
*bebits = cpu_to_be64(byte_count >> 61);
j += 2;
bebits = (__be64 *)&buf[j];
*bebits = cpu_to_be64(byte_count << 3);
j += 2;
}
}
if (j * 4 > bufsize) {
pr_err("%s OVERFLOW %llu\n", __func__, j);
return 0;
}
Annotation
- Immediate include surface: `crypto/internal/hash.h`, `crypto/md5.h`, `crypto/sha1.h`, `crypto/sha2.h`, `linux/bottom_half.h`, `linux/dma-mapping.h`, `linux/kernel.h`, `linux/pm_runtime.h`.
- Detected declarations: `function Copyright`, `function sun8i_ce_hash_init_tfm`, `function sun8i_ce_hash_exit_tfm`, `function sun8i_ce_hash_init`, `function sun8i_ce_hash_export`, `function sun8i_ce_hash_import`, `function sun8i_ce_hash_final`, `function sun8i_ce_hash_update`, `function sun8i_ce_hash_finup`, `function sun8i_ce_hash_digest_fb`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.