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
653 stars 242 forks source link

MIRACL error from routine epoint_negate called from ecurve_mult called from your program Internal result is negative #93

Open wangli2022 opened 3 years ago

wangli2022 commented 3 years ago

Functions Bullet_Setup and imP_Setup cannot be run together, otherwise the above error will occur,why?

main{ int range = 32; int intLength=64;

imP_Primepair primepair; Bullet_PP pedprm;

Bullet_Setup(range, pedprm); imP_Setup(intLength, primepair); }

struct Bullet_PP { ECn g, h; };

struct im_Primepair { Big Prime_p; Big Prime_q; Big lambda; Big g; };

void Bullet_Setup(const int n, Bullet_PP &pp) { pp.g = random_gg(); pp.h = random_gg(); }

ECn random_gg() { Big r = rand(q); //q is a based prime number ECn G = BasePoint; G *= r; return G; }

void im_Setup(const int keyLength, im_Primepair& pp) { GenPrimePair(pp.Prime_p, pp.Prime_q, keyLength);//Produces unequal prime pairs Big n = pp.Prime_p * pp.Prime_q; pp.lambda = lcm(pp.Prime_p - 1, pp.Prime_q - 1); pp.g = generateRankNumber(pp.lambda, n);//pp.lambda=lcm(p-1,q-1) }

Big generateRankNumber(const Big& m, const Big& n) { Big ret,temp; while (true) { ret = generateCoprimeNumber(n n); temp = pow(ret, m, n n); temp = L_function(ret, n); if (gcd(temp, n) == 1) { return ret; } } }