py_ecc/bls/utils.py
def decompress_G2(p: G2Compressed) -> G2Uncompressed:
    """
    Recovers x and y coordinates from the compressed point (z1, z2).
    """
    z1, z2 = p

    # b_flag == 1 indicates the infinity point
    b_flag1 = (z1 % POW_2_383) // POW_2_382
    if b_flag1 == 1:
        return Z2

    x1 = z1 % POW_2_381
    x2 = z2
    # x1 is the imaginary part, x2 is the real part
    x = FQ2([x2, x1])
    y = modular_squareroot_in_FQ2(x**3 + b2)
    if y is None:
        raise ValueError("Failed to find a modular squareroot")

    # Choose the y whose leftmost bit of the imaginary part is equal to the a_flag1
    # If y_im happens to be zero, then use the bit of y_re
    a_flag1 = (z1 % POW_2_382) // POW_2_381
    y_re, y_im = y.coeffs
    if (y_im > 0 and (y_im * 2) // q != a_flag1) or (y_im == 0 and (y_re * 2) // q != a_flag1):
        y = FQ2((y * -1).coeffs)

    if not is_on_curve((x, y, FQ2([1, 0])), b2):
        raise ValueError(
            "The given point is not on the twisted curve over FQ**2"
        )
    return (x, y, FQ2([1, 0]))
def decompress_G2(p: G2Compressed) -> G2Uncompressed:
    """
    Recovers x and y coordinates from the compressed point (z1, z2).
    """
    z1, z2 = p

    # b_flag == 1 indicates the infinity point
    b_flag1 = (z1 % POW_2_383) // POW_2_382
    if b_flag1 == 1:
        return Z2

    x1 = z1 % POW_2_381
    x2 = z2
    # x1 is the imaginary part, x2 is the real part
    x = FQ2([x2, x1])
    y = modular_squareroot_in_FQ2(x**3 + b2)
    if y is None:
        raise ValueError("Failed to find a modular squareroot")

    # Choose the y whose leftmost bit of the imaginary part is equal to the a_flag1
    # If y_im happens to be zero, then use the bit of y_re
    a_flag1 = (z1 % POW_2_382) // POW_2_381
    y_re, y_im = y.coeffs
    if (y_im > 0 and (y_im * 2) // q != a_flag1) or (y_im == 0 and (y_re * 2) // q != a_flag1):
        y = FQ2((y * -1).coeffs)

    if not is_on_curve((x, y, FQ2([1, 0])), b2):
        raise ValueError(
            "The given point is not on the twisted curve over FQ**2"
        )
    return (x, y, FQ2([1, 0]))
def decompress_G2 ( p : G2Compressed ) -> G2Uncompressed : z1 , z2 = p # b_flag == 1 indicates the infinity point b_flag1 = ( z1 % POW_2_383 ) // POW_2_382 if b_flag1 == 1 : return Z2 x1 = z1 % POW_2_381 x2 = z2 # x1 is the imaginary part, x2 is the real part x = FQ2 ( [ x2 , x1 ] ) y = modular_squareroot_in_FQ2 ( x ** 3 + b2 ) if y is None : raise ValueError ( "Failed to find a modular squareroot" ) # Choose the y whose leftmost bit of the imaginary part is equal to the a_flag1 # If y_im happens to be zero, then use the bit of y_re a_flag1 = ( z1 % POW_2_382 ) // POW_2_381 y_re , y_im = y . coeffs if ( y_im > 0 and ( y_im * 2 ) // q != a_flag1 ) or ( y_im == 0 and ( y_re * 2 ) // q != a_flag1 ) : y = FQ2 ( ( y * - 1 ) . coeffs ) if not is_on_curve ( ( x , y , FQ2 ( [ 1 , 0 ] ) ) , b2 ) : raise ValueError ( "The given point is not on the twisted curve over FQ**2" ) return ( x , y , FQ2 ( [ 1 , 0 ] ) )
Recovers x and y coordinates from the compressed point (z1, z2).
Recovers x and y coordinates from the compressed point ( z1 z2 ) .