mbox series

[V2,0/4] crypto: Add Xilinx ZynqMP RSA driver support

Message ID 20230321053446.4303-1-harsha.harsha@amd.com
Headers show
Series crypto: Add Xilinx ZynqMP RSA driver support | expand

Message

Harsha Harsha March 21, 2023, 5:34 a.m. UTC
This patch set does the following:
  - Get the SoC family specific data for crypto operation
  - Adds communication layer support for zynqmp_pm_rsa in zynqmp.c
  - Adds Xilinx driver for RSA Algorithm
  - Updates the list of MAINTAINERS

V2 changes:
- Added CRYPTO_ALG_ASYNC flag in .cra_flags

Harsha Harsha (4):
  firmware: xilinx: Get the SoC family specific data for crypto
    operation
  firmware: xilinx: Add ZynqMP RSA API for RSA encrypt/decrypt operation
  crypto: xilinx: Add ZynqMP RSA driver
  MAINTAINERS: Add maintainer for Xilinx ZynqMP RSA driver

 MAINTAINERS                          |   5 +
 drivers/crypto/Kconfig               |  10 +
 drivers/crypto/xilinx/Makefile       |   1 +
 drivers/crypto/xilinx/xilinx-rsa.c   | 490 +++++++++++++++++++++++++++
 drivers/firmware/xilinx/zynqmp.c     | 100 ++++++
 include/linux/firmware/xlnx-zynqmp.h |  42 +++
 6 files changed, 648 insertions(+)
 create mode 100644 drivers/crypto/xilinx/xilinx-rsa.c

Comments

Herbert Xu March 31, 2023, 9:03 a.m. UTC | #1
On Tue, Mar 21, 2023 at 11:04:45AM +0530, Harsha Harsha wrote:
>
> +static inline int xilinx_copy_and_save_keypart(u8 **kpbuf, unsigned int *kplen,
> +					       const u8 *buf, size_t sz)
> +{
> +	int nskip;
> +
> +	for (nskip = 0; nskip < sz; nskip++)
> +		if (buf[nskip])
> +			break;
> +
> +	*kplen = sz - nskip;
> +	*kpbuf = kmemdup(buf + nskip, *kplen, GFP_KERNEL);
> +	if (!*kpbuf)
> +		return -ENOMEM;
> +
> +	return 0;
> +}

...

> +static int xilinx_rsa_setkey(struct crypto_akcipher *tfm, const void *key,
> +			     unsigned int keylen, bool private)
> +{
> +	struct xilinx_rsa_tfm_ctx *tctx = akcipher_tfm_ctx(tfm);
> +	struct rsa_key raw_key;
> +	int ret;
> +
> +	if (private)
> +		ret = rsa_parse_priv_key(&raw_key, key, keylen);
> +	else
> +		ret = rsa_parse_pub_key(&raw_key, key, keylen);
> +	if (ret)
> +		goto n_key;
> +
> +	ret = xilinx_copy_and_save_keypart(&tctx->n_buf, &tctx->n_len,
> +					   raw_key.n, raw_key.n_sz);

What happens when you call setkey twice? Wouldn't this leak memory?

Cheers,