def test_GFp2():
one = (1,0)
i = (0,1)
x23 = (2, 3)
x57 = (5, 7)
test.test("1+i", GFp2.add(one, i), (1, 1))
test.test("1*i", GFp2.mul(one, i), (0, 1))
test.test("i*i", GFp2.mul(i, i), (p1271 - 1, 0))
test.test("add", GFp2.add(x23, x57), (7, 10))
test.test("sub-pos", GFp2.sub(x57, x23), (3, 4))
test.test("sub-neg", GFp2.sub(x23, x57), (p1271 - 3, p1271 - 4))
test.test("mul", GFp2.mul(x23, x57), (p1271 - 11, 29))
test.test("sqr", GFp2.sqr(x23), (p1271 - 5, 12))
x23c = GFp2.conj(x23)
x23i = GFp2.inv(x23)
x23is = GFp2.invsqrt(x23)
test.test("conj", x23c, (2, GFp.neg(3)))
test.test("inv-1271-2", GFp2.mul(x23, x23i), one)
test.test("invsqrt-1271-2", GFp2.mul(x23, GFp2.sqr(x23is)), one)
select1 = GFp2.select(1, x23, x57)
select0 = GFp2.select(0, x23, x57)
test.test("select(1)", select1, x23)
test.test("select(0)", select0, x57)
评论列表
文章目录