示例#1
0
def add_mixed_hmv(
    pt1, pt2: Optimized_Point3D[Optimized_Field]
) -> Optimized_Point3D[Optimized_Field]:
    x1, y1, z1 = pt1
    x2, y2, z2 = pt2
    assert z2 == FQ2.one()
    T1 = z1 * z1
    T2 = T1 * z1
    T1 = T1 * x2
    T2 = T2 * y2
    T1 = T1 - x1
    T2 = T2 - y1
    if T1 == FQ2.zero():
        if T2 == FQ2.zero():
            return double(pt1)
        return inf
    z3 = z1 * T1
    T3 = T1 * T1
    T4 = T3 * T1
    T3 = T3 * x1
    T1 = 2 * T3
    x3 = T2 * T2
    x3 = x3 - T1
    x3 = x3 - T4
    T3 = T3 - x3
    T3 = T3 * T2
    T4 = T4 * y1
    y3 = T3 - T4
    return (x3, y3, z3)
示例#2
0
from py_ecc.optimized_bn128 import FQ2, b2 as B
from py_ecc.typing import Optimized_Field, Optimized_Point3D

inf = (FQ2.zero(), FQ2.one(), FQ2.zero())


def double(
    pt: Optimized_Point3D[Optimized_Field],
) -> Optimized_Point3D[Optimized_Field]:
    x, y, z = pt
    A = x * x
    B = y * y
    C = B * B
    t = x + B
    D = 2 * (t * t - A - C)
    E = 3 * A
    F = E * E
    x3 = F - 2 * D
    y3 = E * (D - x3) - 8 * C
    z3 = 2 * z * y
    return (x3, y3, z3)


def add(
    pt1, pt2: Optimized_Point3D[Optimized_Field]
) -> Optimized_Point3D[Optimized_Field]:
    x1, y1, z1 = pt1
    x2, y2, z2 = pt2
    Z1Z1 = z1 * z1
    Z2Z2 = z2 * z2
    U1 = x1 * Z2Z2