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
643 stars 241 forks source link

Point Multiplication Error #42

Closed newdible closed 7 years ago

newdible commented 7 years ago

调用miracl库计算点乘时,得出的计算结果不正确,不知错误在哪里?哪位大神能帮忙指点下吗?非常感谢。实现源码如下: p1 = epoint_init(); pa = epoint_init();

mip->IOBASE=16;
cinstr(Para_a, "00");
cinstr(Para_b, "05");
cinstr(Prime_p, "B640000002A3A6F1D603AB4FF58EC74521F2934B1A7AEEDBE56F9B27E351457D");
cinstr(Order_n, "B640000002A3A6F1D603AB4FF58EC74449F2934B18EA8BEEE56EE19CD69ECF25");
cinstr(P1_x, "93DE051D62BF718FF5ED0704487D01D6E1E4086909DC3280E8C4E4817C66DDDD");
cinstr(P1_y, "21FE8DDA4F21E607631065125C395BBC1C1C00CBFA6024350C464CD70A3EA616");
cinstr(k1, "01EDEE3778F441F8DEA3D9FA0ACC4E07EE36C93F9A08618AF4AD85CEDE1C22");

ecurve_init(Para_a, Para_b, Prime_p, MR_AFFINE);
p1->marker = MR_EPOINT_NORMALIZED; 
epoint_set(P1_x, P1_y, 0, p1);

ecurve_mult(k1, p1, pa);
cotnum(k1, stdout); 
cotnum(p1->X, stdout);  
cotnum(p1->Y, stdout);
cotnum(pa->X, stdout);  
cotnum(pa->Y, stdout);
mcarrickscott commented 7 years ago

Its not clear what the question is...

I edited this into an executable program:-

include

include "miracl.h"

int main() { miracl *mip=mirsys(20,0); big Para_a = mirvar(0); big Para_b = mirvar(0); big Prime_p = mirvar(0); big Order_n = mirvar(0); big P1_x = mirvar(0); big P1_y = mirvar(0); big k1 = mirvar(0);

epoint p1 = epoint_init(); epoint pa = epoint_init();

mip->IOBASE=16; cinstr(Para_a, "00"); cinstr(Para_b, "05"); cinstr(Prime_p, "B640000002A3A6F1D603AB4FF58EC74521F2934B1A7AEEDBE56F9B27E351457D"); cinstr(Order_n, "B640000002A3A6F1D603AB4FF58EC74449F2934B18EA8BEEE56EE19CD69ECF25"); cinstr(P1_x, "93DE051D62BF718FF5ED0704487D01D6E1E4086909DC3280E8C4E4817C66DDDD"); cinstr(P1_y, "21FE8DDA4F21E607631065125C395BBC1C1C00CBFA6024350C464CD70A3EA616"); cinstr(k1, "01EDEE3778F441F8DEA3D9FA0ACC4E07EE36C93F9A08618AF4AD85CEDE1C22");

ecurve_init(Para_a, Para_b, Prime_p, MR_AFFINE); p1->marker = MR_EPOINT_NORMALIZED; epoint_set(P1_x, P1_y, 0, p1);

ecurve_mult(k1, p1, pa); cotnum(k1, stdout); cotnum(p1->X, stdout); redc(p1->X,p1->X); cotnum(p1->X, stdout); cotnum(p1->Y, stdout); cotnum(pa->X, stdout); cotnum(pa->Y, stdout); }

When I ran it I got this output

1EDEE3778F441F8DEA3D9FA0ACC4E07EE36C93F9A08618AF4AD85CEDE1C22 5129787C869140B5EFD0CEC817A649BEA946FD5E0073282C22E935E29860501B 93DE051D62BF718FF5ED0704487D01D6E1E4086909DC3280E8C4E4817C66DDDD 7215717763C39828326353912824EFBF15563CBDEC30A576EE779649EB87F7C7 8E9D4801427952C396A4FC340BABF39C05B5819E592CF644262F9394E35ACD2F AB233D9FE7D9CCE040DEECD3B369455963ABAAC06ECE9D43A3032470B7633709

Which looks OK to me.

One point:- its important to know that coordinates (x,y) are converted internally to Montgomery Format. So when p1 is printed out, it is printed out in this format. So it does not look the same as it was input.

To convert back to "normal" format before printing, do

redc(p1->X,p1->X); cotnum(p1->X, stdout);

Note that redc() converts from Montgomery format back to normal format.

Hope this helps..

Mike

On Mon, Jan 9, 2017 at 7:56 AM, newdible notifications@github.com wrote:

调用miracl库计算点乘时,得出的计算结果不正确,不知错误在哪里?哪位大神能帮忙指点下吗?非常感谢。实现源码如下: Para_a = mirvar(0); Para_b = mirvar(0); Prime_p = mirvar(0); Order_n = mirvar(0); P1_x = mirvar(0); P1_y = mirvar(0); k1 = mirvar(0);

p1 = epoint_init(); pa = epoint_init();

mip->IOBASE=16; cinstr(Para_a, "00"); cinstr(Para_b, "05"); cinstr(Prime_p, "B640000002A3A6F1D603AB4FF58EC74521F2934B1A7AEEDBE56F9B27E351457D"); cinstr(Order_n, "B640000002A3A6F1D603AB4FF58EC74449F2934B18EA8BEEE56EE19CD69ECF25"); cinstr(P1_x, "93DE051D62BF718FF5ED0704487D01D6E1E4086909DC3280E8C4E4817C66DDDD"); cinstr(P1_y, "21FE8DDA4F21E607631065125C395BBC1C1C00CBFA6024350C464CD70A3EA616"); cinstr(k1, "01EDEE3778F441F8DEA3D9FA0ACC4E07EE36C93F9A08618AF4AD85CEDE1C22");

ecurve_init(Para_a, Para_b, Prime_p, MR_AFFINE); p1->marker = MR_EPOINT_NORMALIZED; epoint_set(P1_x, P1_y, 0, p1);

ecurve_mult(k1, p1, pa); cotnum(k1, stdout); cotnum(p1->X, stdout); cotnum(p1->Y, stdout); cotnum(pa->X, stdout); cotnum(pa->Y, stdout);

— 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/42, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jmL3n2CwOyKGLjE7QcCf1m-g9J0Oks5rQegQgaJpZM4LeAfv .

newdible commented 7 years ago

@mcarrickscott Thank you very much.My English is very poor. I would describe the question roughly. As you say, the question would be caused by the Format. I will try it, thanks again. Besides, I am studying the paring calculation, and build the libray myself. The lib include the file ake12bnx.cpp, but I donnot have the corresponding header file of this, How can I invoke the function of the cpp? I am looking forward to your reply. Thank you.

mcarrickscott commented 7 years ago

The instructions for building the library are given in the file first.txt

The instructions for building ake12bnx.cpp are given in the comments at the start of the file:-

There is no corresponding header file

g++ -O2 ake12bnx.cpp zzn12a.cpp zzn4.cpp ecn2.cpp zzn2.cpp big.cpp zzn.cpp ecn.cpp miracl.a -o ake12bnx

Mike

On Fri, Jan 13, 2017 at 1:09 AM, newdible notifications@github.com wrote:

@mcarrickscott https://github.com/mcarrickscott Thank you very much.My English is very poor. I would describe the question roughly. As you say, the question would be caused by the Format. I will try it, thanks again. Besides, I am studying the paring calculation, and build the libray myself. The lib include the file ake12bnx.cpp, but I donnot have the corresponding header file of this, How can I invoke the function of the cpp? I am looking forward to your reply. Thank you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/42#issuecomment-272333216, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jvy95IMxl-fsLwnagRCtF1_3lxN6ks5rRs7TgaJpZM4LeAfv .

newdible commented 7 years ago

@mcarrickscott Thank you.

khadijaAssafra commented 5 years ago

I use the miracl library in my project. I have an error in the call to the function set 'P.set (x, y);' x, y are Big and P is of type ECn. The error is understood after the call of the function get 'P.get (x, y);'. Executing the get method gives me two zeros, but I displayed the x and y values ​​before the assignment at point P and gave me two Bigs of size 16. Can you help me? And thank you in advance

mcarrickscott commented 5 years ago

Not enough information for me to help you.

The most likely explanation is that the (x,y) point is not on the curve.

Mike

On Mon, May 6, 2019 at 11:51 AM khadijaAssafra notifications@github.com wrote:

I use the miracl library in my project. I have an error in the call to the function set 'P.set (x, y);' x, y are Big and P is of type ECn. The error is understood after the call of the function get 'P.get (x, y);'. Executing the get method gives me two zeros, but I displayed the x and y values ​​before the assignment at point P and gave me two Bigs of size 16. Can you help me? And thank you in advance

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/42#issuecomment-489579894, or mute the thread https://github.com/notifications/unsubscribe-auth/AAU3ZDVEKJTTTPTTONICOT3PUAERZANCNFSM4C3YA7XQ .

khadijaAssafra commented 5 years ago

Thank you for your response

Le lun. 6 mai 2019 à 19:00, Michael Scott notifications@github.com a écrit :

Not enough information for me to help you.

The most likely explanation is that the (x,y) point is not on the curve.

Mike

On Mon, May 6, 2019 at 11:51 AM khadijaAssafra notifications@github.com wrote:

I use the miracl library in my project. I have an error in the call to the function set 'P.set (x, y);' x, y are Big and P is of type ECn. The error is understood after the call of the function get 'P.get (x, y);'. Executing the get method gives me two zeros, but I displayed the x and y values ​​before the assignment at point P and gave me two Bigs of size 16. Can you help me? And thank you in advance

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/42#issuecomment-489579894, or mute the thread < https://github.com/notifications/unsubscribe-auth/AAU3ZDVEKJTTTPTTONICOT3PUAERZANCNFSM4C3YA7XQ

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/42#issuecomment-489715707, or mute the thread https://github.com/notifications/unsubscribe-auth/AEIAYB7AOOSR7Z2AO7MRFS3PUBW5TANCNFSM4C3YA7XQ .