def test_ec(): g = generator_Fq(default_ec) assert g.is_on_curve() assert 2 * g == g + g assert (3 * g).is_on_curve() assert 3 * g == g + g + g P = hash_to_point_Fq(bytes([])) assert P.is_on_curve() assert P.serialize() == bytes.fromhex( "12fc5ad5a2fbe9d4b6eb0bc16d530e5f263b6d59cbaf26c3f2831962924aa588ab84d46cc80d3a433ce064adb307f256" ) g2 = generator_Fq2(default_ec_twist) assert g2.x * (2 * g2.y) == 2 * (g2.x * g2.y) assert g2.is_on_curve() s = g2 + g2 assert untwist(twist(s)) == s assert untwist(5 * twist(s)) == 5 * s assert 5 * twist(s) == twist(5 * s) assert s.is_on_curve() assert g2.is_on_curve() assert g2 + g2 == 2 * g2 assert g2 * 5 == (g2 * 2) + (2 * g2) + g2 y = y_for_x(g2.x, default_ec_twist, Fq2) assert y[0] == g2.y or y[1] == g2.y assert hash_to_point_Fq2("chia") == hash_to_point_Fq2("chia") g_j = generator_Fq(default_ec_twist).to_jacobian() g2_j = generator_Fq2(default_ec_twist).to_jacobian() g2_j2 = (generator_Fq2(default_ec_twist) * 2).to_jacobian() assert g.to_jacobian().to_affine() == g assert (g_j * 2).to_affine() == g * 2 assert (g2_j + g2_j2).to_affine() == g2 * 3 assert sw_encode(Fq(default_ec.q, 0)).infinity assert sw_encode(Fq(default_ec.q, 1)) == sw_encode(Fq(default_ec.q, -1)).negate() assert ( sw_encode( Fq( default_ec.q, 0x019CFABA0C258165D092F6BCA9A081871E62A126C499340DC71C0E9527F923F3B299592A7A9503066CC5362484D96DD7, ) ) == generator_Fq() ) assert ( sw_encode( Fq( default_ec.q, 0x186417302D5A65347A88B0F999AB2B504614AA5E2EEBDEB1A014C40BCEB7D2306C12A6D436BEFCF94D39C9DB7B263CD4, ) ) == generator_Fq().negate() )
def test_ec(): g = generator_Fq(default_ec) assert (g.is_on_curve()) assert (2 * g == g + g) assert ((3 * g).is_on_curve()) assert (3 * g == g + g + g) P = hash_to_point_Fq(bytes([])) assert (P.is_on_curve()) assert (P.serialize() == bytes.fromhex( "12fc5ad5a2fbe9d4b6eb0bc16d530e5f263b6d59cbaf26c3f2831962924aa588ab84d46cc80d3a433ce064adb307f256" )) g2 = generator_Fq2(default_ec_twist) assert (g2.x * (2 * g2.y) == 2 * (g2.x * g2.y)) assert (g2.is_on_curve()) s = g2 + g2 assert (untwist(twist(s)) == s) assert (untwist(5 * twist(s)) == 5 * s) assert (5 * twist(s) == twist(5 * s)) assert (s.is_on_curve()) assert (g2.is_on_curve()) assert (g2 + g2 == 2 * g2) assert (g2 * 5 == (g2 * 2) + (2 * g2) + g2) y = y_for_x(g2.x, default_ec_twist, Fq2) assert (y[0] == g2.y or y[1] == g2.y) assert (hash_to_point_Fq2("chia") == hash_to_point_Fq2("chia")) g_j = generator_Fq(default_ec_twist).to_jacobian() g2_j = generator_Fq2(default_ec_twist).to_jacobian() g2_j2 = (generator_Fq2(default_ec_twist) * 2).to_jacobian() assert (g.to_jacobian().to_affine() == g) assert ((g_j * 2).to_affine() == g * 2) assert ((g2_j + g2_j2).to_affine() == g2 * 3) assert (sw_encode(Fq(default_ec.q, 0)).infinity) assert (sw_encode(Fq(default_ec.q, 1)) == sw_encode(Fq(default_ec.q, -1)).negate()) assert (sw_encode( Fq( default_ec.q, 0x019cfaba0c258165d092f6bca9a081871e62a126c499340dc71c0e9527f923f3b299592a7a9503066cc5362484d96dd7 )) == generator_Fq()) assert (sw_encode( Fq( default_ec.q, 0x186417302d5a65347a88b0f999ab2b504614aa5e2eebdeb1a014c40bceb7d2306c12a6d436befcf94d39c9db7b263cd4 )) == generator_Fq().negate())