Exemplo n.º 1
0
    def __init__(self, sig: bytes = bytes()) -> None:
        self.value: G1Obj = G1Obj()
        if len(sig) == 0:
            MilagroPairing.ECP_BLS381_inf(byref(self.value))
            return

        g: Tuple[bool, bool, bool, Big384] = parse(sig)

        if g[0] != g[1]:
            raise Exception("Infinite flag set improperly.")

        if g[0]:
            MilagroPairing.ECP_BLS381_inf(byref(self.value))
            return

        if MilagroPairing.ECP_BLS381_setx(byref(self.value), g[3], 0) != 1:
            raise Exception("Invalid G1.")

        yNeg: FP1Obj = FP1Obj()
        MilagroPairing.FP_BLS381_neg(byref(yNeg), byref(self.value.y))

        a: Big384 = Big384()
        b: Big384 = Big384()
        MilagroCurve.FP_BLS381_redc(a, byref(self.value.y))
        MilagroCurve.FP_BLS381_redc(b, byref(yNeg))
        if (MilagroCurve.BIG_384_58_comp(a, b) == 1) != g[2]:
            if MilagroPairing.ECP_BLS381_setx(byref(self.value), g[3], 1) != 1:
                raise Exception("Setting a proven valid X failed.")
Exemplo n.º 2
0
    def __init__(self, value: Any = None) -> None:
        if isinstance(value, List):
            if len(value) != 1:
                raise Exception(
                    "Incompatible field element integer list passed to BLS12_381_F1."
                )
            value = value[0]

        self.value = FP1Obj()
        if (value is None) or (isinstance(value, int) and (value == 0)):
            MilagroCurve.FP_BLS381_zero(byref(self.value))
        elif isinstance(value, int):
            if value == 1:
                MilagroCurve.FP_BLS381_one(byref(self.value))
            else:
                temp: Big384 = Big384()
                MilagroCurve.BIG_384_58_fromBytes(
                    temp, c_char_p(value.to_bytes(48, byteorder="big")))
                MilagroCurve.FP_BLS381_rcopy(byref(self.value), temp)

        #Clone the value.
        elif isinstance(value, FP1Obj):
            self.value = clone(value)
        elif isinstance(value, BLS12_381_F1):
            self.value = clone(value.value)
        else:
            raise Exception("Unknown type passed to BLS12-381 F1 constructor.")
Exemplo n.º 3
0
 def negative(self) -> Any:
     result: FP1Obj = FP1Obj()
     MilagroCurve.FP_BLS381_neg(byref(result), byref(self.value))
     return BLS12_381_F1(result)
Exemplo n.º 4
0
 def __mul__(self, other: Any) -> Any:
     result: FP1Obj = FP1Obj()
     MilagroCurve.FP_BLS381_mul(byref(result), byref(self.value),
                                byref(BLS12_381_F1(other).value))
     return BLS12_381_F1(result)
Exemplo n.º 5
0
def clone(value: FP1Obj) -> FP1Obj:
    result: FP1Obj = FP1Obj()
    MilagroCurve.BIG_384_58_copy(result.g, value.g)
    result.XES = value.XES
    return result
Exemplo n.º 6
0
 def sqrt(self) -> Any:
     result: FP1Obj = FP1Obj()
     MilagroCurve.FP_BLS381_sqrt(byref(result), byref(self.value))
     return BLS12_381_F1(result)