# Problems with SAGE operations

I have defined in SAGE one Elliptic curve, two points: P and P_a and theree integers u1,u2 and n.

p=(10^34+1000).next_prime()

E=EllipticCurve(GF(p),[0,57]);

P= E(9128294291047160967288425267449898,3015386503039089432053383415473448)

P_a= E(4259903772238643554901244696272038,3809941931717614434052814194698091)

u1=32670546509638242125495495

u2=10120953885076574089031876

n=74226928212769886074449493

Q = Integer(u1)P+Integer(u2)P_a

v = mod(Q[0],n)

print v

Now i try to calculate the coordinates of a new point Q, and modular n of the first, called v.

Q = Integer(u1)P+Integer(u2)P_a

v = mod(Q[0],n]

The result that i obtained is 49823540439822066091848818, but desired is 2715371088067745779674921

Where is the mistake? I'm going crazy because i don't understand it.

Can you help me? Thank you very much.!!!!!!!

edit retag close merge delete

Sort by ยป oldest newest most voted

The following example (with your curve but changed Pa,u1,u2,r ) shows that "SAGE operations" are OK

p=(10^34+1000).next_prime()
E=EllipticCurve(GF(p),[0,57]);
x,y=(4259903772238643554901244696272038,3809941931717614434052814194698091)
E.is_on_curve(x,y)
#True
P=E(x,y)
n=P.order()
d=ZZ.random_element(n)   # Priv key
Pa=d*P                   # Pub key

kE=ZZ.random_element(n)  # Eph key
R=kE*P
r=Integer(R.xy()[0])     # first part of the signature
hx=ZZ.random_element(n)  # hash of the message
s=Mod((hx+d*r)*inverse_mod(kE,n),n)  # second part
w=s^-1
u1=Integer(Mod(w*hx,n))
u2=Integer(Mod(w*r,n))
Q=u1*P+u2*Pa
Integer(Q.xy()[0])==r    # Verification
#True

more

Thank you very much. You are a great SAGE programmer!!!

( 2012-06-16 03:39:46 -0500 )edit