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 aggregate(sigs: List[Any]) -> Any:
        result: Signature = Signature.__new__(Signature)
        result.value = G1Obj()

        if not sigs:
            MilagroPairing.ECP_BLS381_inf(byref(result.value))
            return result

        MilagroPairing.ECP_BLS381_copy(byref(result.value),
                                       byref(sigs[0].value))
        for s in range(1, len(sigs)):
            if sigs[s].isInf():
                MilagroPairing.ECP_BLS381_inf(byref(result.value))
                return result

            MilagroPairing.ECP_BLS381_add(byref(result.value),
                                          byref(sigs[s].value))

        return result
Exemplo n.º 3
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.")

        if self.value.y.isLargerThanNegative() != g[2]:
            if MilagroPairing.ECP_BLS381_setx(byref(self.value), g[3], 1) != 1:
                raise Exception("Setting a proven valid X failed.")