Re: [PATCH 2/6] crypto: ccp - Remove unneeded sign-extension support

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

 



On 10/13/2016 09:53 AM, Gary R Hook wrote:
> The reverse-get/set functions can be simplified by
> eliminating unused code.
> 
> 
> Signed-off-by: Gary R Hook <gary.hook@xxxxxxx>
> ---
>  drivers/crypto/ccp/ccp-ops.c |  145 +++++++++++++++++-------------------------
>  1 file changed, 59 insertions(+), 86 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
> index 8fedb14..82cc637 100644
> --- a/drivers/crypto/ccp/ccp-ops.c
> +++ b/drivers/crypto/ccp/ccp-ops.c
> @@ -198,62 +198,46 @@ static void ccp_get_dm_area(struct ccp_dm_workarea *wa, unsigned int wa_offset,
>  }
>  
>  static int ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa,
> +				   unsigned int wa_offset,
>  				   struct scatterlist *sg,
> -				   unsigned int len, unsigned int se_len,
> -				   bool sign_extend)
> +				   unsigned int sg_offset,
> +				   unsigned int len)
>  {
> -	unsigned int nbytes, sg_offset, dm_offset, sb_len, i;
> -	u8 buffer[CCP_REVERSE_BUF_SIZE];
> -
> -	if (WARN_ON(se_len > sizeof(buffer)))
> -		return -EINVAL;
> -
> -	sg_offset = len;
> -	dm_offset = 0;
> -	nbytes = len;
> -	while (nbytes) {
> -		sb_len = min_t(unsigned int, nbytes, se_len);
> -		sg_offset -= sb_len;
> -
> -		scatterwalk_map_and_copy(buffer, sg, sg_offset, sb_len, 0);
> -		for (i = 0; i < sb_len; i++)
> -			wa->address[dm_offset + i] = buffer[sb_len - i - 1];
> -
> -		dm_offset += sb_len;
> -		nbytes -= sb_len;
> -
> -		if ((sb_len != se_len) && sign_extend) {
> -			/* Must sign-extend to nearest sign-extend length */
> -			if (wa->address[dm_offset - 1] & 0x80)
> -				memset(wa->address + dm_offset, 0xff,
> -				       se_len - sb_len);
> -		}
> +	u8 *p, *q;
> +
> +	ccp_set_dm_area(wa, wa_offset, sg, sg_offset, len);
> +
> +	p = wa->address + wa_offset;
> +	q = p + len - 1;
> +	while (p < q) {
> +		*p = *p ^ *q;
> +		*q = *p ^ *q;
> +		*p = *p ^ *q;
> +		p++;
> +		q--;
>  	}
> -
>  	return 0;
>  }
>  
>  static void ccp_reverse_get_dm_area(struct ccp_dm_workarea *wa,
> +				    unsigned int wa_offset,
>  				    struct scatterlist *sg,
> +				    unsigned int sg_offset,
>  				    unsigned int len)
>  {
> -	unsigned int nbytes, sg_offset, dm_offset, sb_len, i;
> -	u8 buffer[CCP_REVERSE_BUF_SIZE];
> -
> -	sg_offset = 0;
> -	dm_offset = len;
> -	nbytes = len;
> -	while (nbytes) {
> -		sb_len = min_t(unsigned int, nbytes, sizeof(buffer));
> -		dm_offset -= sb_len;
> -
> -		for (i = 0; i < sb_len; i++)
> -			buffer[sb_len - i - 1] = wa->address[dm_offset + i];
> -		scatterwalk_map_and_copy(buffer, sg, sg_offset, sb_len, 1);
> -
> -		sg_offset += sb_len;
> -		nbytes -= sb_len;
> +	u8 *p, *q;
> +
> +	p = wa->address + wa_offset;
> +	q = p + len - 1;
> +	while (p < q) {
> +		*p = *p ^ *q;
> +		*q = *p ^ *q;
> +		*p = *p ^ *q;
> +		p++;
> +		q--;
>  	}
> +
> +	ccp_get_dm_area(wa, wa_offset, sg, sg_offset, len);
>  }
>  
>  static void ccp_free_data(struct ccp_data *data, struct ccp_cmd_queue *cmd_q)
> @@ -1294,7 +1278,9 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
>  	struct ccp_data dst;
>  	struct ccp_op op;
>  	unsigned int sb_count, i_len, o_len;
> -	int ret;
> +	unsigned int dm_offset;
> +	int i = 0;

Is "dm_offset" and "i" used anywhere?  I don't see them used in this
function...

> +	int ret = 0;

No need to change this, is there?

Thanks,
Tom

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



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

  Powered by Linux