Skip to content

Commit e475cc1

Browse files
Harsha Harshamichalsimek
authored andcommitted
drivers: crypto: xilinx: Add support for do_one_request
Add support for do_one_request which will be called when the ECDSA driver is probed. Signed-off-by: Harsha Harsha <harsha.harsha@amd.com>
1 parent 1c6af10 commit e475cc1

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

drivers/crypto/xilinx/xilinx-ecdsa.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ struct xilinx_ecdsa_drv_ctx {
5252
struct device *dev;
5353
};
5454

55+
enum xilinx_akcipher_op {
56+
XILINX_ECDSA_DECRYPT = 0,
57+
XILINX_ECDSA_ENCRYPT
58+
};
59+
5560
struct xilinx_ecdsa_tfm_ctx {
5661
dma_addr_t priv_key_addr, pub_key_addr;
5762
struct crypto_akcipher *fbk_cipher;
@@ -68,6 +73,10 @@ struct xilinx_ecdsa_sign_ctx {
6873
u64 s[ECC_MAX_DIGITS];
6974
};
7075

76+
struct xilinx_ecdsa_req_ctx {
77+
enum xilinx_akcipher_op op;
78+
};
79+
7180
static int xilinx_ecdsa_sign(struct akcipher_request *req)
7281
{
7382
return 0;
@@ -265,9 +274,46 @@ static int xilinx_ecdsa_init_tfm(struct crypto_akcipher *tfm)
265274
return PTR_ERR(tfm_ctx->fbk_cipher);
266275
}
267276

277+
akcipher_set_reqsize(tfm, max(sizeof(struct xilinx_ecdsa_req_ctx),
278+
sizeof(struct akcipher_request) +
279+
crypto_akcipher_reqsize(tfm_ctx->fbk_cipher)));
280+
268281
return xilinx_ecdsa_ctx_init(tfm_ctx, ECC_CURVE_NIST_P384);
269282
}
270283

284+
static int handle_ecdsa_req(struct crypto_engine *engine, void *req)
285+
{
286+
struct akcipher_request *areq = container_of(req,
287+
struct akcipher_request,
288+
base);
289+
struct crypto_akcipher *akcipher = crypto_akcipher_reqtfm(req);
290+
struct akcipher_alg *cipher_alg = crypto_akcipher_alg(akcipher);
291+
const struct xilinx_ecdsa_tfm_ctx *tfm_ctx = akcipher_tfm_ctx(akcipher);
292+
const struct xilinx_ecdsa_req_ctx *rq_ctx = akcipher_request_ctx(areq);
293+
struct akcipher_request *subreq = akcipher_request_ctx(req);
294+
struct xilinx_ecdsa_drv_ctx *drv_ctx;
295+
int err;
296+
297+
drv_ctx = container_of(cipher_alg, struct xilinx_ecdsa_drv_ctx, alg.base);
298+
299+
akcipher_request_set_tfm(subreq, tfm_ctx->fbk_cipher);
300+
301+
akcipher_request_set_callback(subreq, areq->base.flags, NULL, NULL);
302+
akcipher_request_set_crypt(subreq, areq->src, areq->dst,
303+
areq->src_len, areq->dst_len);
304+
305+
if (rq_ctx->op == XILINX_ECDSA_ENCRYPT)
306+
err = crypto_akcipher_encrypt(subreq);
307+
else if (rq_ctx->op == XILINX_ECDSA_DECRYPT)
308+
err = crypto_akcipher_decrypt(subreq);
309+
else
310+
err = -EOPNOTSUPP;
311+
312+
crypto_finalize_akcipher_request(engine, areq, err);
313+
314+
return 0;
315+
}
316+
271317
static struct xilinx_ecdsa_drv_ctx versal_ecdsa_drv_ctx = {
272318
.alg.base = {
273319
.verify = xilinx_ecdsa_verify,
@@ -288,6 +334,9 @@ static struct xilinx_ecdsa_drv_ctx versal_ecdsa_drv_ctx = {
288334
.cra_ctxsize = sizeof(struct xilinx_ecdsa_tfm_ctx),
289335
},
290336
},
337+
.alg.op = {
338+
.do_one_request = handle_ecdsa_req,
339+
},
291340
};
292341

293342
static struct xlnx_feature ecdsa_feature_map[] = {
@@ -333,7 +382,7 @@ static int xilinx_ecdsa_probe(struct platform_device *pdev)
333382
}
334383

335384
ecdsa_drv_ctx->dev = dev;
336-
platform_set_drvdata(pdev, &ecdsa_drv_ctx);
385+
platform_set_drvdata(pdev, ecdsa_drv_ctx);
337386

338387
return crypto_engine_register_akcipher(&ecdsa_drv_ctx->alg);
339388
}

0 commit comments

Comments
 (0)