Commit 9d91d8b8 authored by Naga Suramouli's avatar Naga Suramouli
Browse files

Merge branch 'aaisha' into 'master'

POINT Multiplication

See merge request !27
parents 6f8e77c9 db7e2e8f
# point_doubling_affine_Mont
def Pointdoubling_affine_Mont(x1,y1,a,PRECISION):
r=(2^PRECISION).__xor__(n); rpoly = str_to_poly(r)
r2poly = rpoly * rpoly; r2 = poly_to_str(r2poly)
rinvpoly = rpoly^-1; rinv = poly_to_str(rinvpoly)
x1_poly= str_to_poly(x1)
y1_poly=str_to_poly(y1)
x1_poly_MD = x1_poly * r2poly * rinvpoly
y1_poly_MD = y1_poly * r2poly * rinvpoly
#print 'x1_poly=',x1_poly
#print 'y1_poly=',y1_poly
xpoly_MD = (1 * r2poly * rinvpoly)
exp = 2^PRECISION-2
for i in reversed(xrange(PRECISION)):
xpoly_MD = xpoly_MD * xpoly_MD * rinvpoly
if(exp.digits(base=2,padto=PRECISION)[i] == 1):
xpoly_MD = y1_poly_MD * xpoly_MD * rinvpoly
inv_y1_poly_MD = xpoly_MD
c_MD = (3 * r2poly * rinvpoly)
c1_MD = c_MD * x1_poly_MD * rinvpoly
c2_MD = c1_MD * x1_poly_MD * rinvpoly
a_MD = (a * r2poly * rinvpoly)
c3_MD = (c2_MD + a_MD)
c4_MD = (2 * r2poly * rinvpoly)
c5_MD = c3_MD * c4_MD * rinvpoly
s_poly_MD = c5_MD * inv_y1_poly_MD * rinvpoly
c6_MD = s_poly_MD * s_poly_MD * rinvpoly
c7_MD = c4_MD * x1_poly_MD * rinvpoly
x2_poly_MD = c6_MD - c7_MD
c8_MD = (x1_poly_MD - x2_poly_MD)
c9_MD = s_poly_MD * c8_MD * rinvpoly
y2_poly_MD = c9_MD - y1_poly_MD
print 'x2_MD=',poly_to_str(x2_poly_MD)
print 'y2_MD=',poly_to_str(y2_poly_MD)
# PointDoubling_Affine
def Pointdoubling_affine(x1,y1,a,n,PRECISION):
x1_poly = str_to_poly(x1)
y1_poly = str_to_poly(y1)
#print 'x1_poly =', x1_poly
#print 'y1_poly =', y1_poly
xpoly = (1)
expp = 2^PRECISION-2
for i in reversed(xrange(PRECISION)):
xpoly = xpoly * xpoly
if(expp.digits(base = 2,padto=PRECISION)[i] == 1):
xpoly = y1_poly* xpoly
inv_y1_poly = xpoly
s_poly = (3*x1_poly*x1_poly+a)*2*inv_y1_poly
x2_poly = s_poly*s_poly-2*x1_poly
y2_poly = s_poly*(x1_poly-x2_poly)-y1_poly
print 'x2 =',poly_to_str(x2_poly)
print 'y2 =',poly_to_str(y2_poly)
def Montgomerize(xg,yg,p,PRECISION):
r=(2^PRECISION)#.__xor__(n)
rpoly = str_to_poly(r)
r2poly = rpoly * rpoly
r2 = poly_to_str(r2poly)
rinvpoly = rpoly^-1
rinv = poly_to_str(rinvpoly)
x1_poly = str_to_poly(x1)
y1_poly = str_to_poly(y1)
x1_poly_MD = x1_poly * r2poly * rinvpoly
y1_poly_MD = y1_poly * r2poly * rinvpoly
return (x1_poly_MD,y1_poly_MD)
def MontgomerizePrep(a,b,p,PRECISION):
r=(2^PRECISION).__xor__(n)
rpoly = str_to_poly(r)
r2poly = rpoly * rpoly
r2 = poly_to_str(r2poly)
rinvpoly = rpoly^-1
rinv = poly_to_str(rinvpoly)
a_poly = str_to_poly(a)
b_poly = str_to_poly(b)
a_poly_MD = a_poly * r2poly * rinvpoly
b_poly_MD = b_poly * r2poly * rinvpoly
num2_MD = (2 * r2poly * rinvpoly )
num3_MD = (3 * r2poly * rinvpoly )
num8_MD = (8 * r2poly * rinvpoly )
def AffineToJacobiTransformation(x1_MD,y1_MD,PRECISION):
r=(2^PRECISION).__xor__(n)
rpoly = str_to_poly(r)
r2poly = rpoly * rpoly
r2 = poly_to_str(r2poly)
rinvpoly = rpoly^-1
rinv = poly_to_str(rinvpoly)
x1_MD_Poly = x1_MD
y1_MD_Poly = y1_MD
z1_MD_Poly = r
return(x1_MD_Poly,y1_MD_Poly,z1_MD_Poly)
def JacobiToAffineTransformation(xr1_Mont,yr1_Mont,zr1_Mont,p,PRECISION):
r=(2^PRECISION).__xor__(n)
rpoly = str_to_poly(r)
r2poly = rpoly * rpoly
r2 = poly_to_str(r2poly)
rinvpoly = rpoly^-1
rinv = poly_to_str(rinvpoly)
xpoly_MD = (1 * r2poly * rinvpoly)
exp = 2^PRECISION-2
for i in reversed(xrange(PRECISION)):
xpoly_MD = xpoly_MD * xpoly_MD * rinvpoly
if(exp.digits(base=2,padto=PRECISION)[i] == 1):
xpoly_MD = zr1_Mont * xpoly_MD * rinvpoly
inv_z1_poly_MD = xpoly_MD
inv_z2_poly_MD = inv_z1_poly_MD * inv_z1_poly_MD * rinvpoly
inv_z1_poly_MD = inv_z2_poly_MD * inv_z2_poly_MD * rinvpoly
return(xf_mont,yf_mont)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment