* mpmod aliasing
@ 2017-02-05 0:09 Julius Schmidt
2017-02-05 0:26 ` [9front] " Nick Owens
2017-02-05 1:40 ` cinap_lenrek
0 siblings, 2 replies; 3+ messages in thread
From: Julius Schmidt @ 2017-02-05 0:09 UTC (permalink / raw)
To: 9front
mpmod has a bug when n==r and x is negative.
my best attempt at a fix:
void
mpmod(mpint *x, mpint *n, mpint *r)
{
int sign;
mpint *ns;
sign = x->sign;
ns = sign < 0 && n == r ? mpcopy(n) : n;
if((n->flags & MPfield) == 0
|| ((Mfield*)n)->reduce((Mfield*)n, x, r) != 0)
mpdiv(x, n, nil, r);
if(sign < 0)
mpmagsub(ns, r, r);
if(ns != n) mpfree(ns);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] mpmod aliasing
2017-02-05 0:09 mpmod aliasing Julius Schmidt
@ 2017-02-05 0:26 ` Nick Owens
2017-02-05 1:40 ` cinap_lenrek
1 sibling, 0 replies; 3+ messages in thread
From: Nick Owens @ 2017-02-05 0:26 UTC (permalink / raw)
To: 9front
for reference, i found this in rsafill()'s call mpmod(c2, x, x), where
d parameter is negative (rsagen created a rsa key with negative dk).
On Sat, Feb 4, 2017 at 4:09 PM, Julius Schmidt <aiju@phicode.de> wrote:
> mpmod has a bug when n==r and x is negative.
> my best attempt at a fix:
>
> void
> mpmod(mpint *x, mpint *n, mpint *r)
> {
> int sign;
> mpint *ns;
>
> sign = x->sign;
> ns = sign < 0 && n == r ? mpcopy(n) : n;
> if((n->flags & MPfield) == 0
> || ((Mfield*)n)->reduce((Mfield*)n, x, r) != 0)
> mpdiv(x, n, nil, r);
> if(sign < 0)
> mpmagsub(ns, r, r);
> if(ns != n) mpfree(ns);
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] mpmod aliasing
2017-02-05 0:09 mpmod aliasing Julius Schmidt
2017-02-05 0:26 ` [9front] " Nick Owens
@ 2017-02-05 1:40 ` cinap_lenrek
1 sibling, 0 replies; 3+ messages in thread
From: cinap_lenrek @ 2017-02-05 1:40 UTC (permalink / raw)
To: 9front
looks good to me. you can also move the if(ns != n) comparsion
inside the if(sign < 0){ ... } branch... so we dont have to
check for it in the common case.
--
cinap
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-05 1:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-05 0:09 mpmod aliasing Julius Schmidt
2017-02-05 0:26 ` [9front] " Nick Owens
2017-02-05 1:40 ` cinap_lenrek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).