@@ -52,6 +52,11 @@ struct xilinx_ecdsa_drv_ctx {
52
52
struct device * dev ;
53
53
};
54
54
55
+ enum xilinx_akcipher_op {
56
+ XILINX_ECDSA_DECRYPT = 0 ,
57
+ XILINX_ECDSA_ENCRYPT
58
+ };
59
+
55
60
struct xilinx_ecdsa_tfm_ctx {
56
61
dma_addr_t priv_key_addr , pub_key_addr ;
57
62
struct crypto_akcipher * fbk_cipher ;
@@ -68,6 +73,10 @@ struct xilinx_ecdsa_sign_ctx {
68
73
u64 s [ECC_MAX_DIGITS ];
69
74
};
70
75
76
+ struct xilinx_ecdsa_req_ctx {
77
+ enum xilinx_akcipher_op op ;
78
+ };
79
+
71
80
static int xilinx_ecdsa_sign (struct akcipher_request * req )
72
81
{
73
82
return 0 ;
@@ -265,9 +274,46 @@ static int xilinx_ecdsa_init_tfm(struct crypto_akcipher *tfm)
265
274
return PTR_ERR (tfm_ctx -> fbk_cipher );
266
275
}
267
276
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
+
268
281
return xilinx_ecdsa_ctx_init (tfm_ctx , ECC_CURVE_NIST_P384 );
269
282
}
270
283
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
+
271
317
static struct xilinx_ecdsa_drv_ctx versal_ecdsa_drv_ctx = {
272
318
.alg .base = {
273
319
.verify = xilinx_ecdsa_verify ,
@@ -288,6 +334,9 @@ static struct xilinx_ecdsa_drv_ctx versal_ecdsa_drv_ctx = {
288
334
.cra_ctxsize = sizeof (struct xilinx_ecdsa_tfm_ctx ),
289
335
},
290
336
},
337
+ .alg .op = {
338
+ .do_one_request = handle_ecdsa_req ,
339
+ },
291
340
};
292
341
293
342
static struct xlnx_feature ecdsa_feature_map [] = {
@@ -333,7 +382,7 @@ static int xilinx_ecdsa_probe(struct platform_device *pdev)
333
382
}
334
383
335
384
ecdsa_drv_ctx -> dev = dev ;
336
- platform_set_drvdata (pdev , & ecdsa_drv_ctx );
385
+ platform_set_drvdata (pdev , ecdsa_drv_ctx );
337
386
338
387
return crypto_engine_register_akcipher (& ecdsa_drv_ctx -> alg );
339
388
}
0 commit comments