Re: [PATCH v2] crypto: starfive - Align rsa input data to 32-bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 13, 2024 at 04:39:42PM +0800, Jia Jie Ho wrote:
>
> @@ -217,12 +218,11 @@ struct starfive_cryp_request_ctx {
>  	struct scatterlist			*out_sg;
>  	struct ahash_request			ahash_fbk_req;
>  	size_t					total;
> -	size_t					nents;
>  	unsigned int				blksize;
>  	unsigned int				digsize;
>  	unsigned long				in_sg_len;
>  	unsigned char				*adata;
> -	u8 rsa_data[] __aligned(sizeof(u32));
> +	u8 rsa_data[STARFIVE_RSA_MAX_KEYSZ];

I think you should retain the aligned attribute.

> @@ -74,14 +73,13 @@ static int starfive_rsa_montgomery_form(struct starfive_cryp_ctx *ctx,
>  {
>  	struct starfive_cryp_dev *cryp = ctx->cryp;
>  	struct starfive_cryp_request_ctx *rctx = ctx->rctx;
> -	int count = rctx->total / sizeof(u32) - 1;
> +	int count = (ALIGN(rctx->total, sizeof(u32)) >> 2) - 1;

This is a bit confusing.  Perhaps use 4 instead of sizeof(u32), i.e.

	int count = (ALIGN(rctx->total, 4) / 4) - 1;

>  	int loop;
>  	u32 temp;
>  	u8 opsize;
>  
>  	opsize = (bit_len - 1) >> 5;
>  	rctx->csr.pka.v = 0;
> -

Please do not make unrelated changes like this.

> -	rctx->total = sg_copy_to_buffer(rctx->in_sg, rctx->nents,
> -					rctx->rsa_data, rctx->total);
> +	if (!IS_ALIGNED(rctx->total, sizeof(u32))) {
> +		shift = sizeof(u32) - (rctx->total & 0x3);
> +		memset(rctx->rsa_data, 0, shift);
> +	}
> +
> +	rctx->total = sg_copy_to_buffer(rctx->in_sg, sg_nents(rctx->in_sg),
> +					rctx->rsa_data + shift, rctx->total);

The rctx->nents change appears to be unrelated to this patch so
if you want to do it please move it to another patch.

Thanks,
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux