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

Get wrong value of epoint* G when after runing powmod() #115

Open beiluoshimeng opened 1 year ago

beiluoshimeng commented 1 year ago

I just started using miracl to implement ECC, as shown in the picture, why do I get the wrong G after executing powmod()? 1680754483001 image

mcarrickscott commented 1 year ago

Clearly what you are doing makes little sense - why do a finite field powmod in the middle of some elliptic curve calculations?

The reason for this causing a problem is that each MIRACL instance uses a global internal modulus. See the main miracl structure in miracl.h

        /* Montgomery constants */

mr_small ndash; big modulus; big pR; BOOL ACTIVE; BOOL MONTY;

The call to powmod internally changes this modulus, causing the wrong modulus to be used subsequently.

So the solution is - just don't do it..

Mike

On Thu, Apr 6, 2023 at 5:15 AM Jiaqi Yang @.***> wrote:

I just started using miracl to implement ECC, as shown in the picture, why do I get the wrong G after executing pow()? [image: 1680754483001] https://user-images.githubusercontent.com/41739439/230270545-3a7a01af-6ff7-4712-bd3b-ebcf5c67e448.jpg [image: image] https://user-images.githubusercontent.com/41739439/230270585-6fdf6faa-e2e7-4445-a1a9-4509674dfe1a.png

— Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/115, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU3ZDXUJ6PZ4H5SIHA4B7LW7Y7OJANCNFSM6AAAAAAWU4IE3M . You are receiving this because you are subscribed to this thread.Message ID: @.***>