Skip to content

Commit 4d2724e

Browse files
Tabaiearmfazh
authored andcommitted
refactor sswu map matching current standard
1 parent 3e4f002 commit 4d2724e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

mapping/sswu.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,52 @@ func (m *sswu) verify() bool {
6464
return precond1 && precond2 && cond1 && cond2 && cond4
6565
}
6666

67+
func (m *sswu) sqrtRatio(u GF.Elt, v GF.Elt) (bool, GF.Elt) {
68+
F := m.E.F
69+
r := F.Inv(v)
70+
r = F.Mul(r, u)
71+
if F.IsSquare(r) {
72+
return true, F.Sqrt(r)
73+
}
74+
r = F.Mul(r, m.Z)
75+
return false, F.Sqrt(r)
76+
}
77+
6778
func (m *sswu) Map(u GF.Elt) C.Point {
79+
F := m.E.F
80+
var tv1, tv2, tv3, tv4, tv5, tv6, x, y GF.Elt
81+
82+
tv1 = F.Sqr(u) // 1. tv1 = u^2
83+
tv1 = F.Mul(m.Z, tv1) // 2. tv1 = Z * tv1
84+
tv2 = F.Sqr(tv1) // 3. tv2 = tv1^2
85+
tv2 = F.Add(tv2, tv1) // 4. tv2 = tv2 + tv1
86+
tv3 = F.Add(tv2, F.One()) // 5. tv3 = tv2 + 1
87+
tv3 = F.Mul(m.E.B, tv3) // 6. tv3 = B * tv3
88+
tv4 = F.CMov(m.Z, F.Neg(tv2), !F.IsZero(tv2)) // 7. tv4 = CMOV(Z, -tv2, tv2 != 0)
89+
tv4 = F.Mul(m.E.A, tv4) // 8. tv4 = A * tv4
90+
tv2 = F.Sqr(tv3) // 9. tv2 = tv3^2
91+
tv6 = F.Sqr(tv4) // 10. tv6 = tv4^2
92+
tv5 = F.Mul(m.E.A, tv6) // 11. tv5 = A * tv6
93+
tv2 = F.Add(tv2, tv5) // 12. tv2 = tv2 + tv5
94+
tv2 = F.Mul(tv2, tv3) // 13. tv2 = tv2 * tv3
95+
tv6 = F.Mul(tv6, tv4) // 14. tv6 = tv6 * tv4
96+
tv5 = F.Mul(m.E.B, tv6) // 15. tv5 = B * tv6
97+
tv2 = F.Add(tv2, tv5) // 16. tv2 = tv2 + tv5
98+
x = F.Mul(tv1, tv3) // 17. x = tv1 * tv3
99+
isGx1Square, y1 := m.sqrtRatio(tv2, tv6) // 18. (is_gx1_square, y1) = sqrt_ratio(tv2, tv6)
100+
y = F.Mul(tv1, u) // 19. y = tv1 * u
101+
y = F.Mul(y, y1) // 20. y = y * y1
102+
x = F.CMov(x, tv3, isGx1Square) // 21. x = CMOV(x, tv3, is_gx1_square)
103+
y = F.CMov(y, y1, isGx1Square) // 22. y = CMOV(y, y1, is_gx1_square)
104+
e1 := F.Sgn0(u) == F.Sgn0(y) // 23. e1 = sgn0(u) == sgn0(y)
105+
y = F.CMov(F.Neg(y), y, e1) // 24. y = CMOV(-y, y, e1)
106+
tv4 = F.Inv(tv4) // 25. x = x / tv4
107+
x = F.Mul(x, tv4)
108+
109+
return m.E.NewPoint(x, y)
110+
}
111+
112+
func (m *sswu) Map2(u GF.Elt) C.Point {
68113
F := m.E.F
69114
var t1, t2 GF.Elt
70115
var x1, x2, gx1, gx2, y2, x, y GF.Elt

0 commit comments

Comments
 (0)