Commit 05d46ad8 authored by Naga Suramouli's avatar Naga Suramouli
Browse files

Merge branch 'aaisha' into 'master'

Aaisha

See merge request !7
parents 3282fe82 55d390bf
def Pointaddition_affine_Mont(x1,y1,x2,y2,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)
x2_poly= str_to_poly(x2)
y2_poly=str_to_poly(y2)
x1_poly_MD = x1_poly * r2poly * rinvpoly
y1_poly_MD = y1_poly * r2poly * rinvpoly
x2_poly_MD = x2_poly * r2poly * rinvpoly
y2_poly_MD = y2_poly * r2poly * rinvpoly
#print 'x1_poly=',x1_poly
#print 'y1_poly=',y1_poly
#print 'x2_poly=',x2_poly
#print 'y2_poly=',y2_poly
x1poly_MD = (1 * r2poly * rinvpoly)
exp = 2^PRECISION-2
for i in reversed(xrange(PRECISION)):
x1poly_MD = x1poly_MD * x1poly_MD * rinvpoly
if(exp.digits(base=2,padto=PRECISION)[i] == 1):
x1poly_MD = x1_poly_MD * x1poly_MD * rinvpoly
inv_x1_poly_MD = x1poly_MD
x2poly_MD = (1 * r2poly * rinvpoly)
exp = 2^PRECISION-2
for i in reversed(xrange(PRECISION)):
x2poly_MD = x2poly_MD * x2poly_MD * rinvpoly
if(exp.digits(base=2,padto=PRECISION)[i] == 1):
x2poly_MD = x2_poly_MD * x2poly_MD * rinvpoly
inv_x2_poly_MD = x2poly_MD
a_MD = (a * r2poly * rinvpoly)
1_MD = (1 * r2poly * rinvpoly)
c1_MD = y1_poly_MD + y1_poly_MD * rinvpoly
c2_MD = inv_x1_poly_MD + inv_x2_poly_MD * rinvpoly
c3_MD = c1_MD * c2_MD * rinvpoly
c4_MD = c3_MD * c3_MD * rinvpoly
c5_MD = c4_MD + c3_MD * rinvpoly
c6_MD = c5_MD +x1_poly_MD * rinvpoly
c7_MD = c6_MD +x2_poly_MD * rinvpoly
x3_poly_MD = c7_MD +a_MD * rinvpoly
c1_MD = y1_poly_MD + y1_poly_MD * rinvpoly
c2_MD = inv_x1_poly_MD + inv_x2_poly_MD * rinvpoly
c3_MD = c1_MD * c2_MD * rinvpoly
c4_MD = c3_MD * c3_MD * rinvpoly
c5_MD = c4_MD * c3_MD * rinvpoly
c6_MD = c5_MD + 1_MD * rinvpoly
c7_MD = c6_MD + x2_poly_MD * rinvpoly
c8_MD = c6_MD + a_MD * rinvpoly
c9_MD = c8_MD + c3_MD * rinvpoly
c10_MD = c9_MD + x1_poly_MD * rinvpoly
c11_MD = c10_MD + x2_poly_MD * rinvpoly
c12_MD = c11_MD + y1_poly_MD * rinvpoly
y3_poly_MD = c12_MD +a_MD * rinvpoly
print 'x3_MD=',poly_to_str(x3_poly_MD)
print 'y3_MD=',poly_to_str(y3_poly_MD)
\ No newline at end of file
def Pointaddition_Jacobi(x1,y1,z1,x2,y2,z2,PRECISION):
x1_poly = str_to_poly(x1)
y1_poly = str_to_poly(y1)
z1_poly = str_to_poly(b1)
x2_poly = str_to_poly(x2)
y2_poly = str_to_poly(y2)
z2_poly = str_to_poly(z2)
print 'x1_poly=',x1_poly
print 'y1_poly=',y1_poly
print 'z1_poly=',z1_poly
print 'x2_poly=',x2_poly
print 'y2_poly=',y2_poly
print 'z2_poly=',z2_poly
o1_poly = z1_poly * z1_poly
b_poly = x2_poly * o1_poly
d_poly = y2_poly * o1_poly * z1_poly
e_poly = x1_poly + b_poly
f_poly = y1_poly + d_poly
z3_poly = e_poly * z1_poly
h_poly = f_poly * x2_poly + z3_poly * y2_poly
i_poly = f_poly + z3_poly
g_poly = e_poly + z1_poly
x3_poly = a_poly * g_poly + f_poly * i_poly + e_poly * e_poly * e_poly
y3_poly = i_poly * x3_poly + g_poly * h_poly
print 'x3=',poly_to_str(x3_poly)
print 'y3=',poly_to_str(y3_poly)
print 'z3=',poly_to_str(z3_poly)
#formulas:
#O1 = Z12
#B = X2*O1
#D = Y2*O1*Z1
#E = X1+B
#F = Y1+D
#Z3 = E*Z1
#H = F*X2+Z3*Y2
#I = F+Z3
#G = Z32
#X3 = a2*G+F*I+E*E2
#Y3 = I*X3+G*H
\ No newline at end of file
def Pointaddition_Jacobi_Mont(x1,y1,z1,x2,y2,z2,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)
z1_poly = str_to_poly(b1)
x2_poly = str_to_poly(x2)
y2_poly = str_to_poly(y2)
z2_poly = str_to_poly(z2)
x1_poly_MD = x1_poly * r2poly * rinvpoly
y1_poly_MD = y1_poly * r2poly * rinvpoly
z1_poly_MD = z1_poly * r2poly * rinvpoly
x2_poly_MD = x2_poly * r2poly * rinvpoly
y2_poly_MD = y2_poly * r2poly * rinvpoly
z2_poly_MD = z2_poly * r2poly * rinvpoly
o1_poly_MD = z1_poly_MD * z1_poly_MD * rinvpoly
b_poly_MD = x2_poly_MD * o1_poly_MD * rinvpoly
c1_poly_MD = y2_poly_MD * o1_poly_MD * rinvpoly
d_poly_MD = c1_poly_MD * z1_poly_MD * rinvpoly
e_poly_MD = x1_poly_MD + b_poly_MD * rinvpoly
f_poly_MD = y1_poly_MD + d_poly_MD * rinvpoly
z3_poly_MD = e_poly_MD * z1_poly_MD * rinvpoly
c2_poly_MD = f_poly_MD * x2_poly_MD * rinvpoly
c3_poly_MD = z3_poly_MD * y2_poly_MD * rinvpoly
h_poly_MD = c2_poly_MD + c3_poly_MD * rinvpoly
i_poly_MD = f_poly_MD + z3_poly_MD * rinvpoly
g_poly_MD = e_poly_MD + z1_poly_MD * rinvpoly
c4_poly_MD = a_poly_MD * g_poly_MD * rinvpoly
c5_poly_MD = f_poly_MD * i_poly_MD * rinvpoly
c6_poly_MD = e_poly_MD * e_poly_MD * rinvpoly
c9_poly_MD = c4_poly_MD + c5_poly_MD * rinvpoly
c10_poly_MD = c6_poly_MD * e_poly * rinvpoly
x3_poly_MD = c9_poly_MD + c10_poly_MD * rinvpoly
c7_poly_MD = i_poly_MD * x3_poly_MD * rinvpoly
c8_poly_MD = g_poly _MD* h_poly_MD * rinvpoly
y3_poly_MD = c7_poly_MD + c8_poly_MD * rinvpoly
print 'x3_MD=',poly_to_str(x3_poly_MD)
print 'y3_MD=',poly_to_str(y3_poly_MD)
print 'z3_MD=',poly_to_str(z3_poly_MD)
#formulas:
#O1 = Z12
#B = X2*O1
#D = Y2*O1*Z1
#E = X1+B
#F = Y1+D
#Z3 = E*Z1
#H = F*X2+Z3*Y2
#I = F+Z3
#G = Z32
#X3 = a2*G+F*I+E*E2
#Y3 = I*X3+G*H
\ No newline at end of file
def Pointaddition_affine(x1,x2,y1,y2,a,PRECISION):
x1_poly= str_to_poly(x1)
y1_poly=str_to_poly(y1)
x2_poly= str_to_poly(x2)
y2_poly=str_to_poly(y2)
print 'x1_poly=',x1_poly
print 'y1_poly=',y1_poly
print 'x2_poly=',x2_poly
print 'y2_poly=',y2_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 = x1_poly* xpoly
inv_x1_poly = xpoly
xpoly = (2)
expp = 2^PRECISION-2
for i in reversed(xrange(PRECISION)):
xpoly = xpoly * xpoly
if(expp.digits(base = 2,padto=PRECISION)[i] == 1):
xpoly = x2_poly* xpoly
inv_x2_poly = xpoly
#Calculation of resultant coordinates
x3_poly = ( (y1_poly + y2_poly) *(inv_x1_poly + inv_x2_poly) ) ** 2 + ( (y1_poly + y2_poly) * (inv_x1_poly + inv_x2_poly) ) + x1_poly + x2_poly + a
y3_poly = ( (y1_poly + y2_poly) *(inv_x1_poly + inv_x2_poly) ) ** 3 + (x2_poly + a + 1 ) * (y1_poly + y2_poly *(inv_x1_poly + inv_x2_poly) ) + x1_poly + x2_poly + a + y1_poly
print 'x3=',poly_to_str(x3_poly)
print 'y3=',poly_to_str(y3_poly)
#Affine addition formulas:
#(x1,y1)+(x2,y2)=(x3,y3)
#where
# x3 = ((y1+y2)/(x1+x2))2+((y1+y2)/(x1+x2))+x1+x2+a2
# y3 = ((y1+y2)/(x1+x2))3+(x2+a2+1)*((y1+y2)/(x1+x2))+x1+x2+a2+y1
\ No newline at end of file
......@@ -28,13 +28,45 @@ Within this project work a Linux device driver should be extended by following E
Functions:
Preparation, Montgomery Transformation, Affine-to-Jacobi Transformation,
Point Doubling, Point Addition, Jacobi-to-Affine Transformation,
Preparation, Montgomery Transformation, Affine-to-Jacobi Transformation, Point Addition,
Point Doubling, Jacobi-to-Affine Transformation,
Montgomery Back-transformation, Point Validation.
By using a Linux User Space Application the correct functionality should be verified by performing Point Validations in GF(2m) for the supported ECC precision widths. Based on a
given Point and elliptic curve equation a statement must be made whether the Point is on the curve or not.For the validation of the calculation inside of the CryptoCore the open-source mathematics
software SageMath should be used.In order to be able to illustrate the time required for ECC Point Validation with different precision widths the Real Time Library support (-lrt) should be included.
Point Addition:
With 2 distinct points, P and Q, addition is defined as the negation of the point resulting from the intersection of the curve, E, and the straight line defined by the points P and Q, giving the point, R.
P+Q=R
(x1,y1)+(x2,y2)=(x3,y3)
An elliptic curve in short Weierstrass form has parameters a2 a6 and coordinates x y satisfying the following equations:
y^2+x*y=x^3+a2*x^2+a6
Affine addition formulas: (x1,y1)+(x2,y2)=(x3,y3) where
x3 = ((y1+y2)/(x1+x2))^2+((y1+y2)/(x1+x2))+x1+x2+a2
y3 = ((y1+y2)/(x1+x2))^3+(x2+a2+1)*((y1+y2)/(x1+x2))+x1+x2+a2+y1
Jacobian coordinates represent x y as X Y Z satisfying the following equations:
x=X/Z^2
y=Y/Z^3
Assumptions: Z2=1.
Explicit formulas:
O1 = Z1^2
B = X2*O1
D = Y2*O1*Z1
E = X1+B
F = Y1+D
Z3 = E*Z1
H = F*X2+Z3*Y2
I = F+Z3
G = Z3^2
X3 = a2*G+F*I+E*E^S2
Y3 = I*X3+G*H
Contributors:
......@@ -42,7 +74,7 @@ Contributors:
2)Harshal Likhar
3)Aisha
3)Aaisha Ghodekar (Developer)
4)Hamza
......
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