Skip to content

Commit

Permalink
drivers: crypto: xilinx: Add support for do_one_request
Browse files Browse the repository at this point in the history
Add support for do_one_request which will be called when the ECDSA
driver is probed.

Signed-off-by: Harsha Harsha <[email protected]>
  • Loading branch information
Harsha Harsha authored and michalsimek committed Apr 27, 2024
1 parent 1c6af10 commit e475cc1
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion drivers/crypto/xilinx/xilinx-ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ struct xilinx_ecdsa_drv_ctx {
struct device *dev;
};

enum xilinx_akcipher_op {
XILINX_ECDSA_DECRYPT = 0,
XILINX_ECDSA_ENCRYPT
};

struct xilinx_ecdsa_tfm_ctx {
dma_addr_t priv_key_addr, pub_key_addr;
struct crypto_akcipher *fbk_cipher;
Expand All @@ -68,6 +73,10 @@ struct xilinx_ecdsa_sign_ctx {
u64 s[ECC_MAX_DIGITS];
};

struct xilinx_ecdsa_req_ctx {
enum xilinx_akcipher_op op;
};

static int xilinx_ecdsa_sign(struct akcipher_request *req)
{
return 0;
Expand Down Expand Up @@ -265,9 +274,46 @@ static int xilinx_ecdsa_init_tfm(struct crypto_akcipher *tfm)
return PTR_ERR(tfm_ctx->fbk_cipher);
}

akcipher_set_reqsize(tfm, max(sizeof(struct xilinx_ecdsa_req_ctx),
sizeof(struct akcipher_request) +
crypto_akcipher_reqsize(tfm_ctx->fbk_cipher)));

return xilinx_ecdsa_ctx_init(tfm_ctx, ECC_CURVE_NIST_P384);
}

static int handle_ecdsa_req(struct crypto_engine *engine, void *req)
{
struct akcipher_request *areq = container_of(req,
struct akcipher_request,
base);
struct crypto_akcipher *akcipher = crypto_akcipher_reqtfm(req);
struct akcipher_alg *cipher_alg = crypto_akcipher_alg(akcipher);
const struct xilinx_ecdsa_tfm_ctx *tfm_ctx = akcipher_tfm_ctx(akcipher);
const struct xilinx_ecdsa_req_ctx *rq_ctx = akcipher_request_ctx(areq);
struct akcipher_request *subreq = akcipher_request_ctx(req);
struct xilinx_ecdsa_drv_ctx *drv_ctx;
int err;

drv_ctx = container_of(cipher_alg, struct xilinx_ecdsa_drv_ctx, alg.base);

akcipher_request_set_tfm(subreq, tfm_ctx->fbk_cipher);

akcipher_request_set_callback(subreq, areq->base.flags, NULL, NULL);
akcipher_request_set_crypt(subreq, areq->src, areq->dst,
areq->src_len, areq->dst_len);

if (rq_ctx->op == XILINX_ECDSA_ENCRYPT)
err = crypto_akcipher_encrypt(subreq);
else if (rq_ctx->op == XILINX_ECDSA_DECRYPT)
err = crypto_akcipher_decrypt(subreq);
else
err = -EOPNOTSUPP;

crypto_finalize_akcipher_request(engine, areq, err);

return 0;
}

static struct xilinx_ecdsa_drv_ctx versal_ecdsa_drv_ctx = {
.alg.base = {
.verify = xilinx_ecdsa_verify,
Expand All @@ -288,6 +334,9 @@ static struct xilinx_ecdsa_drv_ctx versal_ecdsa_drv_ctx = {
.cra_ctxsize = sizeof(struct xilinx_ecdsa_tfm_ctx),
},
},
.alg.op = {
.do_one_request = handle_ecdsa_req,
},
};

static struct xlnx_feature ecdsa_feature_map[] = {
Expand Down Expand Up @@ -333,7 +382,7 @@ static int xilinx_ecdsa_probe(struct platform_device *pdev)
}

ecdsa_drv_ctx->dev = dev;
platform_set_drvdata(pdev, &ecdsa_drv_ctx);
platform_set_drvdata(pdev, ecdsa_drv_ctx);

return crypto_engine_register_akcipher(&ecdsa_drv_ctx->alg);
}
Expand Down

0 comments on commit e475cc1

Please sign in to comment.