Lines Matching +full:- +full:seed

1 // SPDX-License-Identifier: GPL-2.0
3 * sun8i-ce-prng.c - hardware cryptographic offloader for
6 * Copyright (C) 2015-2020 Corentin Labbe <clabbe@baylibre.com>
12 #include "sun8i-ce.h"
13 #include <linux/dma-mapping.h>
29 kfree_sensitive(ctx->seed); in sun8i_ce_prng_exit()
30 ctx->seed = NULL; in sun8i_ce_prng_exit()
31 ctx->slen = 0; in sun8i_ce_prng_exit()
34 int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed, in sun8i_ce_prng_seed() argument
39 if (ctx->seed && ctx->slen != slen) { in sun8i_ce_prng_seed()
40 kfree_sensitive(ctx->seed); in sun8i_ce_prng_seed()
41 ctx->slen = 0; in sun8i_ce_prng_seed()
42 ctx->seed = NULL; in sun8i_ce_prng_seed()
44 if (!ctx->seed) in sun8i_ce_prng_seed()
45 ctx->seed = kmalloc(slen, GFP_KERNEL | GFP_DMA); in sun8i_ce_prng_seed()
46 if (!ctx->seed) in sun8i_ce_prng_seed()
47 return -ENOMEM; in sun8i_ce_prng_seed()
49 memcpy(ctx->seed, seed, slen); in sun8i_ce_prng_seed()
50 ctx->slen = slen; in sun8i_ce_prng_seed()
72 ce = algt->ce; in sun8i_ce_prng_generate()
74 if (ctx->slen == 0) { in sun8i_ce_prng_generate()
75 dev_err(ce->dev, "not seeded\n"); in sun8i_ce_prng_generate()
76 return -EINVAL; in sun8i_ce_prng_generate()
80 todo = dlen + ctx->slen + PRNG_DATA_SIZE * 2; in sun8i_ce_prng_generate()
81 todo -= todo % PRNG_DATA_SIZE; in sun8i_ce_prng_generate()
85 err = -ENOMEM; in sun8i_ce_prng_generate()
89 dev_dbg(ce->dev, "%s PRNG slen=%u dlen=%u todo=%u multi=%u\n", __func__, in sun8i_ce_prng_generate()
93 algt->stat_req++; in sun8i_ce_prng_generate()
94 algt->stat_bytes += todo; in sun8i_ce_prng_generate()
97 dma_iv = dma_map_single(ce->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE); in sun8i_ce_prng_generate()
98 if (dma_mapping_error(ce->dev, dma_iv)) { in sun8i_ce_prng_generate()
99 dev_err(ce->dev, "Cannot DMA MAP IV\n"); in sun8i_ce_prng_generate()
100 err = -EFAULT; in sun8i_ce_prng_generate()
104 dma_dst = dma_map_single(ce->dev, d, todo, DMA_FROM_DEVICE); in sun8i_ce_prng_generate()
105 if (dma_mapping_error(ce->dev, dma_dst)) { in sun8i_ce_prng_generate()
106 dev_err(ce->dev, "Cannot DMA MAP DST\n"); in sun8i_ce_prng_generate()
107 err = -EFAULT; in sun8i_ce_prng_generate()
111 err = pm_runtime_resume_and_get(ce->dev); in sun8i_ce_prng_generate()
115 mutex_lock(&ce->rnglock); in sun8i_ce_prng_generate()
116 chan = &ce->chanlist[flow]; in sun8i_ce_prng_generate()
118 cet = &chan->tl[0]; in sun8i_ce_prng_generate()
121 cet->t_id = cpu_to_le32(flow); in sun8i_ce_prng_generate()
122 common = ce->variant->prng | CE_COMM_INT; in sun8i_ce_prng_generate()
123 cet->t_common_ctl = cpu_to_le32(common); in sun8i_ce_prng_generate()
126 if (ce->variant->prng_t_dlen_in_bytes) in sun8i_ce_prng_generate()
127 cet->t_dlen = cpu_to_le32(todo); in sun8i_ce_prng_generate()
129 cet->t_dlen = cpu_to_le32(todo / 4); in sun8i_ce_prng_generate()
132 cet->t_sym_ctl = cpu_to_le32(sym); in sun8i_ce_prng_generate()
133 cet->t_asym_ctl = 0; in sun8i_ce_prng_generate()
135 cet->t_key = cpu_to_le32(dma_iv); in sun8i_ce_prng_generate()
136 cet->t_iv = cpu_to_le32(dma_iv); in sun8i_ce_prng_generate()
138 cet->t_dst[0].addr = cpu_to_le32(dma_dst); in sun8i_ce_prng_generate()
139 cet->t_dst[0].len = cpu_to_le32(todo / 4); in sun8i_ce_prng_generate()
140 ce->chanlist[flow].timeout = 2000; in sun8i_ce_prng_generate()
143 mutex_unlock(&ce->rnglock); in sun8i_ce_prng_generate()
145 pm_runtime_put(ce->dev); in sun8i_ce_prng_generate()
148 dma_unmap_single(ce->dev, dma_dst, todo, DMA_FROM_DEVICE); in sun8i_ce_prng_generate()
150 dma_unmap_single(ce->dev, dma_iv, ctx->slen, DMA_TO_DEVICE); in sun8i_ce_prng_generate()
154 memcpy(ctx->seed, d + dlen, ctx->slen); in sun8i_ce_prng_generate()