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.")
def msgToG(msg: bytes) -> G1Obj: result: G1Obj = G1Obj() hashed: OctetObj = OctetObj() shake: Any = shake_256() shake.update(msg) hashed.val = c_char_p(shake.digest(48)) hashed.len = 48 hashed.max = 48 MilagroCurve.ECP_BLS381_mapit(byref(result), hashed) return result
def __init__(self, x: Any, y: Optional[BLS12_381_F1] = None) -> None: self.value: G1Obj = G1Obj() if isinstance(x, G1Obj): MilagroCurve.ECP_BLS381_copy(byref(self.value), byref(x)) elif isinstance(x, BLS12_381_G1): MilagroCurve.ECP_BLS381_copy(byref(self.value), byref(x.value)) elif (isinstance(x, BLS12_381_F1) and isinstance(y, BLS12_381_F1)): xBig: Big384 = x.value.toBig384() yBig: Big384 = y.value.toBig384() if MilagroCurve.ECP_BLS381_set(byref(self.value), xBig, yBig) != 1: raise Exception("Passed invalid x/y to G1 constructor.") else: raise Exception("Unknown type passed to BLS12-381 G1 constructor.")
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
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.")
def __add__(self, other: Any) -> GroupElement: result: G1Obj = G1Obj() MilagroCurve.ECP_BLS381_copy(byref(result), byref(self.value)) MilagroCurve.ECP_BLS381_add(byref(result), byref(other.value)) return BLS12_381_G1(result)