|
7#
大 中
小 發表於 2019-10-11 12:44 只看該作者
二元橢圓曲線加密請見連結介紹,本文僅就例4、例5以\(maxima\)示範計算過程。
https://math.pro/db/attachment.p ... 04&t=1565140250
※橢圓曲線在\(F_{2^n}\)下的運算規則
例子4:在有限體\(F_{2^4}\)之下,取橢圓曲線\(y^2+xy=x^3+g^8x^2+g^2\)上的兩點\(P=(g^3,g^9)\)及\(Q=(g,g^5)\),其中\(g=(0010)\)為\(F_{2^4}\)的生成數,且不可約多項式為\(f(x)=x^4+x+1\)。若\(P+Q=R=(x_3,y_3)\),則\(R=\)?
例子5:承例子4,若\(P+P=2P=R=(x_3,y_3)\),則\(R=\)?
F[2]/(x^4+x+1) 的Galois體
(%i1) gf_set_data(2,4);
(%o1) Structure [GF-DATA]
F[2]/(x^4+x+1) 不可約多項式為x^4+x+1,元素個數16個
(%i2) [p,ReductionPoly,g,n,m]:gf_infolist();
(%o2) \(\left[2,x^4+x+1,x,16,15 \right]\)
產生g^1,g^2,...,g^15
(%i3) g:create_list(gf_exp(g,i),i,1,n-1);
(g) \(\left[x,x^2,x^3,x+1,x^2+x,x^3+x^2,x^3+x+1,x^2+1,x^3+x,x^2+x+1,x^3+x^2+x,x^3+x^2+x+1,x^3+x^2+1,x^3+1,1\right]\)
y^2+xy=x^3+ax^2+b (mod 2)(mod x^4+x+1)的橢圓曲線
(%i5)
a:g[8];
b:g[2];
(a) \(x^2+1\)
(b) \(x^2\)
分式的分子和分母係數超過2以(mod 2)化簡
(%i6)
PolyMod2(poly,PrintList):=block
([numpoly:num(poly),denompoly:denom(poly),numpolymod2,denompolymod2],
numpolymod2:polymod(numpoly,2),/*分子多項式對2同餘*/
denompolymod2:polymod(denompoly,2),/*分母多項式對2同餘*/
if denompoly=1 then/*分母為1,是多項式*/
(if numpoly#numpolymod2 then
(PrintList:append(PrintList,["=",poly:numpolymod2]))
)
else
(if numpoly#numpolymod2 or denompoly#denompolymod2 then
(PrintList:append(PrintList,["=",poly:numpolymod2/denompolymod2]))
),
return([poly,PrintList])
)$
分式的分子和分母超過4次方以(mod x^4+x+1)化簡
(%i7)
PolyModGF(poly,PrintList):=block
([numpoly:num(poly),denompoly:denom(poly),numpolymodGF,denompolymodGF],
numpolymodGF:polymod(remainder(numpoly,ReductionPoly),2),/*分子多項式對x^4+x+1同餘*/
denompolymodGF:polymod(remainder(denompoly,ReductionPoly),2),/*分母多項式對x^4+x+1同餘*/
if denompoly=1 then/*分母為1,是多項式*/
(if numpoly#numpolymodGF then
(PrintList:append(PrintList,["=",poly:numpolymodGF]))
)
else/*分母不為1是分式,針對分子和分母分開對x^4+x+1同餘*/
(if numpoly#numpolymodGF or denompoly#denompolymodGF then
(PrintList:append(PrintList,["=",poly:numpolymodGF/denompolymodGF]))
),
return([poly,PrintList])
)$
針對分式的分母求反元素
(%i8)
Inverse(poly,PrintList):=block
([numpoly:num(poly),denompoly:denom(poly)],
if denompoly#1 then/*分母不為1才需要計算反元素*/
(PrintList:append(PrintList,["=(",numpoly,")(",gf_inv(denompoly),")"]),
PrintList:append(PrintList,["=",poly:expand(numpoly*gf_inv(denompoly))]),
[poly,PrintList]:PolyMod2(poly,PrintList),
[poly,PrintList]:PolyModGF(poly,PrintList)
),
return([poly,PrintList])
)$
橢圓曲線點相加
注意:
多項式係數超過2以(mod 2)化簡
超過4次方以(mod x^4+x+1)化簡
(%i9)
PointAdd(P,Q):=block
([R:[0,0],lambda,inv_P1,PrintList],
if P=[inf,inf] then (return(Q))
else if Q=[inf,inf] then (return(P))
else if P=Q then
(if P[1]=0 then
(print(" P,Q兩點x座標為0,相加結果為無窮遠點"),
return([inf,inf])
),
/*計算λ=(P1^2+P2)/P1*/
PrintList:["λ=",(x_1^2+y_1)/x_1,"=",lambda:(P[1]^2+P[2])/P[1]],
if P[1]^2#expand(P[1]^2) then/*若P[1]超過1項,將平方展開過程列出來*/
(PrintList:append(PrintList,["=",lambda:expand(P[1]^2+P[2])/P[1]])),
[lambda,PrintList]:PolyMod2(lambda,PrintList),/*若係數大於2,同餘2*/
[lambda,PrintList]:PolyModGF(lambda,PrintList),/*若超過4次方,同餘x^4+x+1*/
[lambda,PrintList]:Inverse(lambda,PrintList),/*若λ為分式,將分母取反元素後和分子相乘*/
apply(print,PrintList),/*將λ計算過程印出來*/
/*計算R1=λ^2+λ+a*/
print(x_3,"=λ"^2,"+λ+a=(",lambda,")"^2,"+(",lambda,")+(",a,")"),
PrintList:[x_3,"=(",expand(lambda^2),")+",lambda+a,
"=",R[1]:expand(lambda^2)+lambda+a],
[R[1],PrintList]:PolyMod2(R[1],PrintList),/*若係數大於2,同餘2*/
[R[1],PrintList]:PolyModGF(R[1],PrintList),/*若超過4次方,同餘x^4+x+1*/
apply(print,PrintList),/*將R1計算過程印出來*/
/*計算R2=P1^2+λR1+R1*/
print(y_3,"=",x_1^2,"+λ",x_3,"+",x_3,"=(",P[1],")"^2,"+(",lambda,")(",R[1],")+(",R[1],")"),
PrintList:[y_3,"=(",expand(P[1]^2),")+(",expand(lambda*R[1]),")+",R[1],
"=",R[2]:expand(P[1]^2+lambda*R[1])+R[1]],
[R[2],PrintList]:PolyMod2(R[2],PrintList),/*若係數大於2,同餘2*/
[R[2],PrintList]:PolyModGF(R[2],PrintList),/*若超過4次方,同餘x^4+x+1*/
apply(print,PrintList)/*將R2計算過程印出來*/
)
else
(if gf_add(P[1],Q[1])=0 then
(print(" P,Q兩點x座標相同,相加結果為無窮遠點"),
return([inf,inf])
),
/*計算λ=(P2+Q2)/(P1+Q1)*/
PrintList:["λ=",(y_1+y_2)/(x_1+x_2),"=",lambda:(P[2]+Q[2])/(P[1]+Q[1])],
[lambda,PrintList]:PolyMod2(lambda,PrintList),/*若係數大於2,同餘2*/
[lambda,PrintList]:PolyModGF(lambda,PrintList),/*若超過4次方,同餘x^4+x+1*/
[lambda,PrintList]:Inverse(lambda,PrintList),/*若λ為分式,將分母取反元素後和分子相乘*/
apply(print,PrintList),/*將λ計算過程印出來*/
/*計算R1=λ^2+λ+P1+Q1+a*/
print(x_3,"=λ"^2,"+λ+",x_1,"+",x_2,"+a=(",lambda,")"^2,"+(",lambda,")+(",P[1],")+(",Q[1],")+(",a,")"),
PrintList:[x_3,"=(",expand(lambda^2),")+",lambda+P[1]+Q[1]+a,
"=",R[1]:expand(lambda^2)+lambda+P[1]+Q[1]+a],
[R[1],PrintList]:PolyMod2(R[1],PrintList),/*若係數大於2,同餘2*/
[R[1],PrintList]:PolyModGF(R[1],PrintList),/*若超過4次方,同餘x^4+x+1*/
apply(print,PrintList),/*將R1計算過程印出來*/
/*計算R2=λ(P1+R1)+R1+P2*/
print(y_3,"=λ(",x_1,"+",x_3,")+",x_3,"+",y_1,"=(",lambda,")(",P[1]+R[1],")+(",R[1],")+(",P[2],")"),
PrintList:[y_3,"=(",expand(lambda*(P[1]+R[1])),")+",R[1]+P[2],
"=",R[2]:expand(lambda*(P[1]+R[1]))+R[1]+P[2]],
[R[2],PrintList]:PolyMod2(R[2],PrintList),/*若係數大於2,同餘2*/
[R[2],PrintList]:PolyModGF(R[2],PrintList),/*若超過4次方,同餘x^4+x+1*/
apply(print,PrintList)/*將R2計算過程印出來*/
),
print("(",x_3,",",y_3,")=(",R[1],",",R[2],")=(",if R[1]=0 then 0 else "g"^gf_index(R[1]),",",
if R[2]=0 then 0 else "g"^gf_index(R[2]),")"),
return(R)
)$
P=(x1,y1)=(g^3,g^9)
Q=(x2,y2)=(g^1,g^5)
(%i11)
P:[g[3],g[9]];
Q:[g[1],g[5]];
(P) \(\left[x^3,x^3+x \right]\)
(Q) \(\left[x,x^2+x \right]\)
計算P+Q=R=(x3,y3)
(%i12) R:PointAdd(P,Q);
\(\displaystyle \lambda=\frac{y_2+y_1}{x_2+x_1}=\frac{x^3+x^2+2x}{x^3+x}=\frac{x^3+x^2}{x^3+x}=(x^3+x^2)(x^3+x^2)=x^6+2x^5+x^4=x^6+x^4=x^3+x^2+x+1\)
\(x_3=\lambda^2+\lambda+x_1+x_2+a=(x^3+x^2+x+1)^2+(x^3+x^2+x+1)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