Exemple #1
0
def OpBLS_G2_Add(arg):
    op = json.loads(arg)
    a_v = to_int(op['a_v'])
    a_w = to_int(op['a_w'])
    a_x = to_int(op['a_x'])
    a_y = to_int(op['a_y'])
    b_v = to_int(op['b_v'])
    b_w = to_int(op['b_w'])
    b_x = to_int(op['b_x'])
    b_y = to_int(op['b_y'])

    A = (FQ2((a_v, a_x)), FQ2((a_w, a_y)), FQ2.one())
    B = (FQ2((b_v, b_x)), FQ2((b_w, b_y)), FQ2.one())

    if not (is_on_curve(A, b2) and subgroup_check(A)):
        return
    if not (is_on_curve(B, b2) and subgroup_check(B)):
        return

    result = add(A, B)

    x = result[0] / result[2]
    y = result[1] / result[2]

    result = [[str(x.coeffs[0]), str(y.coeffs[0])],
              [str(x.coeffs[1]), str(y.coeffs[1])]]

    r = json.dumps(result)
    return bytes(r, 'utf-8')
Exemple #2
0
def OpBLS_G1_Add(arg):
    op = json.loads(arg)
    a_x = to_int(op['a_x'])
    a_y = to_int(op['a_y'])
    b_x = to_int(op['b_x'])
    b_y = to_int(op['b_y'])

    if (a_x % MOD, a_y % MOD) == (0, 0):
        return
    if (b_x % MOD, b_y % MOD) == (0, 0):
        return

    A = [FQ(a_x), FQ(a_y), FQ.one()]
    B = [FQ(b_x), FQ(b_y), FQ.one()]

    if not (is_on_curve(A, b) and subgroup_check(A)):
        return
    if not (is_on_curve(B, b) and subgroup_check(B)):
        return

    result = add(A, B)

    result = [str(result[0] / result[2]), str(result[1] / result[2])]
    r = json.dumps(result)
    return bytes(r, 'utf-8')
Exemple #3
0
    def _CoreAggregateVerify(cls, PKs: Sequence[BLSPubkey],
                             messages: Sequence[bytes],
                             signature: BLSSignature, DST: bytes) -> bool:
        try:
            # Inputs validation
            for pk in PKs:
                assert cls._is_valid_pubkey(pk)
            for message in messages:
                assert cls._is_valid_message(message)
            assert len(PKs) == len(messages)
            assert cls._is_valid_signature(signature)

            # Preconditions
            assert len(PKs) >= 1

            # Procedure
            signature_point = signature_to_G2(signature)
            if not subgroup_check(signature_point):
                return False
            aggregate = FQ12.one()
            for pk, message in zip(PKs, messages):
                assert cls.KeyValidate(pk)
                pubkey_point = pubkey_to_G1(pk)
                message_point = hash_to_G2(message, DST, cls.xmd_hash_function)
                aggregate *= pairing(message_point,
                                     pubkey_point,
                                     final_exponentiate=False)
            aggregate *= pairing(signature_point,
                                 neg(G1),
                                 final_exponentiate=False)
            return final_exponentiate(aggregate) == FQ12.one()

        except (ValidationError, ValueError, AssertionError):
            return False
Exemple #4
0
    def _CoreVerify(cls, PK: BLSPubkey, message: bytes,
                    signature: BLSSignature, DST: bytes) -> bool:
        try:
            # Inputs validation
            assert cls._is_valid_pubkey(PK)
            assert cls._is_valid_message(message)
            assert cls._is_valid_signature(signature)

            # Procedure
            assert cls.KeyValidate(PK)
            signature_point = signature_to_G2(signature)
            if not subgroup_check(signature_point):
                return False
            final_exponentiation = final_exponentiate(
                pairing(
                    signature_point,
                    G1,
                    final_exponentiate=False,
                ) * pairing(
                    hash_to_G2(message, DST, cls.xmd_hash_function),
                    neg(pubkey_to_G1(PK)),
                    final_exponentiate=False,
                ))
            return final_exponentiation == FQ12.one()
        except (ValidationError, ValueError, AssertionError):
            return False
Exemple #5
0
    def KeyValidate(PK: BLSPubkey) -> bool:
        try:
            pubkey_point = pubkey_to_G1(PK)
        except (ValidationError, ValueError, AssertionError):
            return False

        if is_inf(pubkey_point):
            return False

        if not subgroup_check(pubkey_point):
            return False

        return True
Exemple #6
0
def OpBLS_IsG1OnCurve(arg):
    op = json.loads(arg)
    x = to_int(op['g1_x'])
    y = to_int(op['g1_y'])

    g1 = [FQ(x), FQ(y), FQ.one()]

    if is_valid([x, y]) == False:
        return

    #r = json.dumps(is_on_curve(g2, b2))
    r = json.dumps(is_on_curve(g1, b) and subgroup_check(g1))
    return bytes(r, 'utf-8')
Exemple #7
0
def OpBLS_IsG2OnCurve(arg):
    op = json.loads(arg)
    v = to_int(op['g2_v'])
    w = to_int(op['g2_w'])
    x = to_int(op['g2_x'])
    y = to_int(op['g2_y'])

    g2 = (FQ2((v, x)), FQ2((w, y)), FQ2.one())

    if is_valid([v, w, x, y]) == False:
        return

    r = json.dumps(is_on_curve(g2, b2) and subgroup_check(g2))
    return bytes(r, 'utf-8')
Exemple #8
0
checker(wow, b"D")
ex = True

q = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab

cv = ((q**12) - 1) // 115

ex = True
cnt = 0

for i in range(len(wow)):
    #  res = singlechecker(pubkey_to_G1(bytes.fromhex(wow[i]["PK"])), signature_to_G2(bytes.fromhex(wow[i]["Sign"])), wow[i]["Vote"].encode())
    # print(res)
    pub = pubkey_to_G1(bytes.fromhex(wow[i]["PK"]))
    sig = signature_to_G2(bytes.fromhex(wow[i]["Sign"]))
    print("pubkey check", i, subgroup_check(pub))
    print("sig check", i, subgroup_check(sig))
    if wow[i]["Vote"] == "D":
        if ex:
            ex = False
            fin = creator(wow[i]["Name"], "D", wow[i]["Sign"])
            r.sendline(fin)
            continue
        res1 = hasher(b"D")
        res2 = hasher(b"R")

        tt = (res2 * inverse(res1, cv)) % cv
        sigs = signature_to_G2(bytes.fromhex(wow[i]["Sign"]))
        sigs = multiply(sigs, tt)
        # do this part only if you want fake flag
        if cnt == 0: