* [PATCH 1/2] MPILIB: Fix comparison of negative MPIs
@ 2014-12-06 0:00 Rasmus Villemoes
2014-12-06 0:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp Rasmus Villemoes
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Rasmus Villemoes @ 2014-12-06 0:00 UTC (permalink / raw)
To: David Howells, Rusty Russell; +Cc: Rasmus Villemoes, linux-kernel
If u and v both represent negative integers and their limb counts
happen to differ, mpi_cmp will always return a positive value - this
is obviously bogus. u is smaller than v if and only if it is larger in
absolute value.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/mpi/mpi-cmp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
index 1871e7b61ca0..3801694240d8 100644
--- a/lib/mpi/mpi-cmp.c
+++ b/lib/mpi/mpi-cmp.c
@@ -57,7 +57,7 @@ int mpi_cmp(MPI u, MPI v)
if (usize != vsize && !u->sign && !v->sign)
return usize - vsize;
if (usize != vsize && u->sign && v->sign)
- return vsize + usize;
+ return vsize - usize;
if (!usize)
return 0;
cmp = mpihelp_cmp(u->d, v->d, usize);
--
2.1.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp
2014-12-06 0:00 [PATCH 1/2] MPILIB: Fix comparison of negative MPIs Rasmus Villemoes
@ 2014-12-06 0:00 ` Rasmus Villemoes
2015-01-09 10:58 ` [PATCH 1/2] MPILIB: Fix comparison of negative MPIs David Howells
2015-01-09 11:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp David Howells
2 siblings, 0 replies; 8+ messages in thread
From: Rasmus Villemoes @ 2014-12-06 0:00 UTC (permalink / raw)
To: David Howells, Rusty Russell; +Cc: Rasmus Villemoes, linux-kernel
The condition preceding 'return 1;' makes my head hurt. At this point,
we know that u and v have the same sign; if they are negative, they
compare opposite to how their absolute values compare (which
mpihelp_cmp found for us), otherwise cmp itself is the
answer. Negating cmp is ok since mpihelp_cmp returns {-1,0,1};
-INT_MIN==INT_MIN won't bite us.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/mpi/mpi-cmp.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
index 3801694240d8..d25e9e96c310 100644
--- a/lib/mpi/mpi-cmp.c
+++ b/lib/mpi/mpi-cmp.c
@@ -61,10 +61,8 @@ int mpi_cmp(MPI u, MPI v)
if (!usize)
return 0;
cmp = mpihelp_cmp(u->d, v->d, usize);
- if (!cmp)
- return 0;
- if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0))
- return 1;
- return -1;
+ if (u->sign)
+ return -cmp;
+ return cmp;
}
EXPORT_SYMBOL_GPL(mpi_cmp);
--
2.1.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] MPILIB: Fix comparison of negative MPIs
2014-12-06 0:00 [PATCH 1/2] MPILIB: Fix comparison of negative MPIs Rasmus Villemoes
2014-12-06 0:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp Rasmus Villemoes
@ 2015-01-09 10:58 ` David Howells
2015-01-10 10:27 ` [Keyrings] " Dmitry Kasatkin
2015-01-09 11:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp David Howells
2 siblings, 1 reply; 8+ messages in thread
From: David Howells @ 2015-01-09 10:58 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: dhowells, Rusty Russell, d.kasatkin, linux-kernel, keyrings
I think you're right - *adding* the two sizes makes no sense. cc'ing Dmitry
also for his check.
David
Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> If u and v both represent negative integers and their limb counts
> happen to differ, mpi_cmp will always return a positive value - this
> is obviously bogus. u is smaller than v if and only if it is larger in
> absolute value.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> lib/mpi/mpi-cmp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
> index 1871e7b61ca0..3801694240d8 100644
> --- a/lib/mpi/mpi-cmp.c
> +++ b/lib/mpi/mpi-cmp.c
> @@ -57,7 +57,7 @@ int mpi_cmp(MPI u, MPI v)
> if (usize != vsize && !u->sign && !v->sign)
> return usize - vsize;
> if (usize != vsize && u->sign && v->sign)
> - return vsize + usize;
> + return vsize - usize;
> if (!usize)
> return 0;
> cmp = mpihelp_cmp(u->d, v->d, usize);
> --
> 2.1.3
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp
2014-12-06 0:00 [PATCH 1/2] MPILIB: Fix comparison of negative MPIs Rasmus Villemoes
2014-12-06 0:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp Rasmus Villemoes
2015-01-09 10:58 ` [PATCH 1/2] MPILIB: Fix comparison of negative MPIs David Howells
@ 2015-01-09 11:00 ` David Howells
2015-01-10 10:29 ` [Keyrings] " Dmitry Kasatkin
2015-01-12 11:43 ` David Howells
2 siblings, 2 replies; 8+ messages in thread
From: David Howells @ 2015-01-09 11:00 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: dhowells, Rusty Russell, d.kasatkin, linux-kernel, keyrings
This looks very reasonable. cc'ing Dmitry for his check.
David
---
Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> The condition preceding 'return 1;' makes my head hurt. At this point,
> we know that u and v have the same sign; if they are negative, they
> compare opposite to how their absolute values compare (which
> mpihelp_cmp found for us), otherwise cmp itself is the
> answer. Negating cmp is ok since mpihelp_cmp returns {-1,0,1};
> -INT_MIN==INT_MIN won't bite us.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> lib/mpi/mpi-cmp.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
> index 3801694240d8..d25e9e96c310 100644
> --- a/lib/mpi/mpi-cmp.c
> +++ b/lib/mpi/mpi-cmp.c
> @@ -61,10 +61,8 @@ int mpi_cmp(MPI u, MPI v)
> if (!usize)
> return 0;
> cmp = mpihelp_cmp(u->d, v->d, usize);
> - if (!cmp)
> - return 0;
> - if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0))
> - return 1;
> - return -1;
> + if (u->sign)
> + return -cmp;
> + return cmp;
> }
> EXPORT_SYMBOL_GPL(mpi_cmp);
> --
> 2.1.3
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Keyrings] [PATCH 1/2] MPILIB: Fix comparison of negative MPIs
2015-01-09 10:58 ` [PATCH 1/2] MPILIB: Fix comparison of negative MPIs David Howells
@ 2015-01-10 10:27 ` Dmitry Kasatkin
0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2015-01-10 10:27 UTC (permalink / raw)
To: David Howells; +Cc: Rasmus Villemoes, keyrings, Rusty Russell, linux-kernel
Hi,
Thank you. It looks correct.
Ack.
- Dmitry
On 9 January 2015 at 12:58, David Howells <dhowells@redhat.com> wrote:
> I think you're right - *adding* the two sizes makes no sense. cc'ing Dmitry
> also for his check.
>
> David
>
>
> Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
>
>> If u and v both represent negative integers and their limb counts
>> happen to differ, mpi_cmp will always return a positive value - this
>> is obviously bogus. u is smaller than v if and only if it is larger in
>> absolute value.
>>
>> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
>> ---
>> lib/mpi/mpi-cmp.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
>> index 1871e7b61ca0..3801694240d8 100644
>> --- a/lib/mpi/mpi-cmp.c
>> +++ b/lib/mpi/mpi-cmp.c
>> @@ -57,7 +57,7 @@ int mpi_cmp(MPI u, MPI v)
>> if (usize != vsize && !u->sign && !v->sign)
>> return usize - vsize;
>> if (usize != vsize && u->sign && v->sign)
>> - return vsize + usize;
>> + return vsize - usize;
>> if (!usize)
>> return 0;
>> cmp = mpihelp_cmp(u->d, v->d, usize);
>> --
>> 2.1.3
>>
> _______________________________________________
> Keyrings mailing list
> Keyrings@linux-nfs.org
> To change your subscription to this list, please see http://linux-nfs.org/cgi-bin/mailman/listinfo/keyrings
--
Thanks,
Dmitry
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Keyrings] [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp
2015-01-09 11:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp David Howells
@ 2015-01-10 10:29 ` Dmitry Kasatkin
2015-01-12 11:43 ` David Howells
1 sibling, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2015-01-10 10:29 UTC (permalink / raw)
To: David Howells
Cc: Rasmus Villemoes, keyrings, Dmitry Kasatkin, Rusty Russell, linux-kernel
Hi,
Thank you. Indeed '-cmp' is much more clear.
Ack.
- Dmitry
On 9 January 2015 at 13:00, David Howells <dhowells@redhat.com> wrote:
> This looks very reasonable. cc'ing Dmitry for his check.
>
> David
> ---
> Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
>
>> The condition preceding 'return 1;' makes my head hurt. At this point,
>> we know that u and v have the same sign; if they are negative, they
>> compare opposite to how their absolute values compare (which
>> mpihelp_cmp found for us), otherwise cmp itself is the
>> answer. Negating cmp is ok since mpihelp_cmp returns {-1,0,1};
>> -INT_MIN==INT_MIN won't bite us.
>>
>> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
>> ---
>> lib/mpi/mpi-cmp.c | 8 +++-----
>> 1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
>> index 3801694240d8..d25e9e96c310 100644
>> --- a/lib/mpi/mpi-cmp.c
>> +++ b/lib/mpi/mpi-cmp.c
>> @@ -61,10 +61,8 @@ int mpi_cmp(MPI u, MPI v)
>> if (!usize)
>> return 0;
>> cmp = mpihelp_cmp(u->d, v->d, usize);
>> - if (!cmp)
>> - return 0;
>> - if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0))
>> - return 1;
>> - return -1;
>> + if (u->sign)
>> + return -cmp;
>> + return cmp;
>> }
>> EXPORT_SYMBOL_GPL(mpi_cmp);
>> --
>> 2.1.3
> _______________________________________________
> Keyrings mailing list
> Keyrings@linux-nfs.org
> To change your subscription to this list, please see http://linux-nfs.org/cgi-bin/mailman/listinfo/keyrings
--
Thanks,
Dmitry
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Keyrings] [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp
2015-01-09 11:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp David Howells
2015-01-10 10:29 ` [Keyrings] " Dmitry Kasatkin
@ 2015-01-12 11:43 ` David Howells
2015-01-12 11:47 ` Dmitry Kasatkin
1 sibling, 1 reply; 8+ messages in thread
From: David Howells @ 2015-01-12 11:43 UTC (permalink / raw)
To: Dmitry Kasatkin
Cc: dhowells, Rasmus Villemoes, keyrings, Dmitry Kasatkin,
Rusty Russell, linux-kernel
Dmitry Kasatkin <dmitry.kasatkin@gmail.com> wrote:
> Ack.
To what email address do I translate that now?
Acked-by: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
perchance?
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Keyrings] [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp
2015-01-12 11:43 ` David Howells
@ 2015-01-12 11:47 ` Dmitry Kasatkin
0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2015-01-12 11:47 UTC (permalink / raw)
To: David Howells; +Cc: Rasmus Villemoes, keyrings, Rusty Russell, linux-kernel
correct.
Acked-by: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
Dmitry
On 12 January 2015 at 13:43, David Howells <dhowells@redhat.com> wrote:
> Dmitry Kasatkin <dmitry.kasatkin@gmail.com> wrote:
>
>> Ack.
>
> To what email address do I translate that now?
>
> Acked-by: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
>
> perchance?
>
> David
--
Thanks,
Dmitry
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-01-12 11:47 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-06 0:00 [PATCH 1/2] MPILIB: Fix comparison of negative MPIs Rasmus Villemoes
2014-12-06 0:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp Rasmus Villemoes
2015-01-09 10:58 ` [PATCH 1/2] MPILIB: Fix comparison of negative MPIs David Howells
2015-01-10 10:27 ` [Keyrings] " Dmitry Kasatkin
2015-01-09 11:00 ` [PATCH 2/2] MPILIB: Deobfuscate mpi_cmp David Howells
2015-01-10 10:29 ` [Keyrings] " Dmitry Kasatkin
2015-01-12 11:43 ` David Howells
2015-01-12 11:47 ` Dmitry Kasatkin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.