algt = container_of(alg, struct sun8i_ss_alg_template, alg.rng);
ss = algt->ss;
if (ctx->slen == 0) {
dev_err(ss->dev, "The PRNG is not seeded\n"); return -EINVAL;
}
/* The SS does not give an updated seed, so we need to get a new one. *SowewillaskforanextraPRNG_SEED_SIZEdata. *Wewantdlen+seedsizeroundeduptoamultipleofPRNG_DATA_SIZE
*/
todo = dlen + PRNG_SEED_SIZE + PRNG_DATA_SIZE;
todo -= todo % PRNG_DATA_SIZE;
todo_with_padding = ALIGN(todo, dma_get_cache_alignment()); if (todo_with_padding < todo || todo < dlen) return -EOVERFLOW;
d = kzalloc(todo_with_padding, GFP_KERNEL); if (!d) return -ENOMEM;
mutex_lock(&ss->mlock);
writel(dma_iv, ss->base + SS_IV_ADR_REG); /* the PRNG act badly (failing rngtest) without SS_KEY_ADR_REG set */
writel(dma_iv, ss->base + SS_KEY_ADR_REG);
writel(dma_dst, ss->base + SS_DST_ADR_REG);
writel(todo / 4, ss->base + SS_LEN_ADR_REG);
reinit_completion(&ss->flows[flow].complete);
ss->flows[flow].status = 0; /* Be sure all data is written before enabling the task */
wmb();
writel(v, ss->base + SS_CTL_REG);
wait_for_completion_interruptible_timeout(&ss->flows[flow].complete,
msecs_to_jiffies(todo)); if (ss->flows[flow].status == 0) {
dev_err(ss->dev, "DMA timeout for PRNG (size=%u)\n", todo);
err = -EFAULT;
} /* Since cipher and hash use the linux/cryptoengine and that we have *acryptoengineperflow,wearesurethattheywillissueonlyone *requestperflow. *Sincethecryptoenginewaitforcompletionbeforesubmittinganew *one,themlockcouldbeleftjustafterthefinalwritel. *Butcryptoenginecannothandlecrypto_rng,soweneedtobesure *nothingwilluseourflow. *Theeasiestwayistograbmlockuntilthehardwareendourrequests. *Wecouldhaveusedaperflowlock,butthiswouldincrease *complexity. *Thedrawbackisthatnorequestcouldbehandledfortheotherflow.
*/
mutex_unlock(&ss->mlock);
pm_runtime_put(ss->dev);
err_pm:
dma_unmap_single(ss->dev, dma_dst, todo, DMA_FROM_DEVICE);
err_iv:
dma_unmap_single(ss->dev, dma_iv, ctx->slen, DMA_TO_DEVICE);
if (!err) {
memcpy(dst, d, dlen); /* Update seed */
memcpy(ctx->seed, d + dlen, ctx->slen);
}
err_free:
kfree_sensitive(d);
return err;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-10-01)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.