[PATCH] mpi_swap_conditional

Dmitry Eremin-Solenikov dbaryshkov at gmail.com
Thu Jun 19 11:03:29 CEST 2014


Hello,

On Thu, Jun 19, 2014 at 9:52 AM, NIIBE Yutaka <gniibe at fsij.org> wrote:
[skipped]
> diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
> index fdce578..e0afec0 100644
> --- a/mpi/mpiutil.c
> +++ b/mpi/mpiutil.c
> @@ -541,6 +541,43 @@ _gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b)
>      tmp = *a; *a = *b; *b = tmp;
>  }
>
> +void
> +_gcry_mpi_swap_conditional (gcry_mpi_t a, gcry_mpi_t b, unsigned long swap)
> +{
> +  size_t i;
> +  size_t nlimbs = a->nlimbs;
> +  unsigned long mask = -(long)swap;

I'd suggest to have something like
unsigned long mask = 0Ul - !!swap;
That would be more robust - you can use then all
expressions as 'swap' argument instead of plain 0 or 1.

-- 
With best wishes
Dmitry



More information about the Gcrypt-devel mailing list