miracl / MIRACL

MIRACL Cryptographic SDK: Multiprecision Integer and Rational Arithmetic Cryptographic Library is a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography (ECC).
https://miracl.com
638 stars 241 forks source link

Subsequent additions in ECn2 #25

Closed baz1 closed 8 years ago

baz1 commented 8 years ago

Hello,

After investigating the "Illegal parameter usage [in ecn2_add]" error that I received in my program, I reduced the code to the "simplest" version below that still produces that error:

#define MR_PAIRING_BN
#include "pairing_3.h"
int main() {
    PFC pfc(128);
    G2 t1, t2, t3;
    pfc.random(t1);
    t2 = t1 + t1;
    t3 = t1 + t2;
    return 0;
}

I figured that the bug came from mrecn2.c, function ecn2_add3 lines 578-580:

    if (Q!=P && Q->marker==MR_EPOINT_GENERAL)
    { /* Sorry, this code is optimized for mixed addition only */
        mr_berror(_MIPP_ MR_ERR_BAD_PARAMETERS);

I understand that this comment and error have been put here on purpose, but I believe that the C++ wrappers provided in pairing_3.h should make the life easier for users and allow, say, multiple additions of elements in G2. I noticed that adding the line t2.g.norm(); before the faulty line t3 = t1 + t2; solves the problem, which means it could easily be solved in bn_pair.cpp too (if not simply bundled in mrecn2.c by default ; it is always better not to get an error message when we can avoid it). Thank you

Rémi

mcarrickscott commented 8 years ago

Thanks for spotting that bug.

Will update MIRACL later this week in response to your observations.

Mike

On Sun, Jul 3, 2016 at 4:12 AM, Rémi Bazin notifications@github.com wrote:

Hello,

After investigating the "Illegal parameter usage [in ecn2_add]" error that I received in my program, I reduced the code to the "simplest" version below that still produces that error:

define MR_PAIRING_BN

include "pairing_3.h"

int main() { PFC pfc(128); G2 t1, t2, t3; pfc.random(t1); t2 = t1 + t1; t3 = t1 + t2; return 0; }

I figured that the bug came from mrecn2.c, function ecn2_add3 lines 578-580:

if (Q!=P && Q->marker==MR_EPOINT_GENERAL)
{ /* Sorry, this code is optimized for mixed addition only */
    mr_berror(_MIPP_ MR_ERR_BAD_PARAMETERS);

I understand that this comment and error have been put here on purpose, but I believe that the C++ wrappers provided in pairing_3.h should make the life easier for users and allow, say, multiple additions of elements in G2. I noticed that adding the line t2.g.norm(); before the faulty line t3 = t1 + t2; solves the problem, which means it could easily be solved in bn_pair.cpp too (if not simply bundled in mrecn2.c by default ; it is always better not to get an error message when we can avoid it). Thank you

Rémi

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/25, or mute the thread https://github.com/notifications/unsubscribe/ACm8jtuYkHEGNjrhOEtJw6QDjW3I_Sdmks5qRyiGgaJpZM4JDywT .