Пример #1
0
def calculate_voting_result_rtk_handler():
    data = get_post_data(request)

    indexes = str_to_int(data.get('indexes'))

    polynomialCoefficientsExponents = str_to_int(
        data.get('polynomialCoefficientsExponents'))
    partialDecrypts = str_to_int(data.get('partialDecrypts'))

    sum_A = str_to_int(data.get('sum_A'))
    sum_B = str_to_int(data.get('sum_B'))

    votersNum = str_to_int(data.get('votersNum'))
    optionsNum = str_to_int(data.get('optionsNum'))

    commissionPubKey = str_to_hex(data.get('commissionPubKey'))
    decryptKey = str_to_int(data.get('decryptKey'))
    commissionDecrypt = str_to_int(data.get('commissionDecrypt'))

    result, error = calculate_voting_result_rtk(
        indexes, votersNum, optionsNum, polynomialCoefficientsExponents,
        partialDecrypts, sum_A, sum_B, decryptKey, commissionPubKey,
        commissionDecrypt)

    if not result:
        return jsonify(error), 400
    else:
        return jsonify({"result": result})
Пример #2
0
def calculate_voting_result_v2_handler():
    data = get_post_data(request)

    indexes = str_to_int(data.get('indexes'))

    polynomialCoefficientsExponents = str_to_int(
        data.get('polynomialCoefficientsExponents'))
    partialDecrypts = str_to_int(data.get('partialDecrypts'))

    mainKey = str_to_int(data.get('mainKey'))

    sum_A = str_to_int(data.get('sum_A'))
    sum_B = str_to_int(data.get('sum_B'))

    votersNum = str_to_int(data.get('votersNum'))
    optionsNum = str_to_int(data.get('optionsNum'))

    result, error = calculate_voting_result(indexes, votersNum, optionsNum,
                                            polynomialCoefficientsExponents,
                                            partialDecrypts, sum_A, sum_B,
                                            mainKey)

    if not result:
        return jsonify(error), 400
    else:
        return jsonify({"result": result})
Пример #3
0
def calculate_main_key_hanlder():
    data = get_post_data(request)
    publicKeysCommits = list(
        map(lambda publicKeyCommit: str_to_int(publicKeyCommit),
            data.get('publicKeysCommits')))
    secretKeysOfCommits = str_to_int(data.get('secretKeysOfCommits'))
    mainKey = calculate_main_key(publicKeysCommits, secretKeysOfCommits)
    return jsonify({"mainKey": int_to_str(mainKey)})
Пример #4
0
def verify_private_key_handler():
    data = get_post_data(request)
    publicKey = str_to_hex(data.get('publicKey'))
    privateKey = int(data.get('privateKey'))
    valid, error = validate_private_key(
        [str(publicKey[0]), str(publicKey[1])], privateKey)

    return jsonify({"valid": valid, "error": error})
Пример #5
0
def verify_encrypted_bulletin_handler():
    data = get_post_data(request)
    encryptedBulletin = str_to_int(data.get('encryptedBulletin')[0])
    sumRangeProof = str_to_int(data.get('encryptedBulletin')[1])
    mainKey = str_to_int(data.get('mainKey'))
    verified = verify_encrypted_bulletin(encryptedBulletin, sumRangeProof,
                                         mainKey)
    return jsonify({"verified": verified})
Пример #6
0
def add_commission_key_handler():
    data = get_post_data(request)
    decryptKey = str_to_int(data.get('decryptKey'))
    commissionPubKey = str_to_hex(data.get('commissionPubKey'))
    result, data = add_commission_key(decryptKey, commissionPubKey)
    if not result:
        return jsonify(data), 400
    else:
        return jsonify({"mainKey": int_to_str(data)})
Пример #7
0
def verify_equality_of_dl_handler():
    data = get_post_data(request)
    decrypted = str_to_int(data.get('decrypted'))
    publicKey = str_to_hex(data.get('publicKey'))
    sum_A = str_to_int(data.get('sum_A'))

    verified = verify_equality_of_dl_wrapped(decrypted, sum_A, publicKey)

    return jsonify({"verified": verified})
Пример #8
0
def add_encrypted_bulletins_to_sum_handler():
    data = get_post_data(request)
    encryptedBulletins = list(str_to_int(data.get('encryptedBulletins')))
    mainKey = str_to_int(data.get('mainKey'))
    prevSums = data.get('prevSums')

    sum_A, sum_B = add_encrypted_bulletins_to_sum(encryptedBulletins, mainKey,
                                                  prevSums)

    return jsonify({"sum_A": int_to_str(sum_A), "sum_B": int_to_str(sum_B)})
Пример #9
0
def calculate_polynomial_coefficients_exponents_handler():
    data = get_post_data(request)
    coefficients = str_to_int(data.get('polynomialCoefficients'))
    polynomialCoefficientsExponents = calculate_polynomial_coefficients_exponents(
        coefficients)
    return jsonify({
        "polynomialCoefficientsExponents":
        list(
            map(lambda exponent: int_to_str([exponent.x, exponent.y]),
                polynomialCoefficientsExponents))
    })
Пример #10
0
def generate_key_pair_handler():
    data = get_post_data(request)
    privateKey, publicKey = generate_key_pair()
    if data.get('format') == 'hex':
        publicKey = [format(publicKey.x, 'x'), format(publicKey.y, 'x')]
    else:
        publicKey = int_to_str([publicKey.x, publicKey.y])

    return jsonify({
        "privateKey": int_to_str(privateKey),
        "publicKey": publicKey
    })
Пример #11
0
def subtract_encrypted_bulletins_from_sum_handler():
    data = get_post_data(request)
    encryptedBulletins = list(
        map(lambda v: [str_to_int(v[0]), str_to_int(v[1])],
            data.get('encryptedBulletins')))
    mainKey = str_to_int(data.get('mainKey'))
    prevSums = data.get('prevSums')

    sum_A, sum_B = subtract_encrypted_bulletins_from_sum(
        encryptedBulletins, mainKey, prevSums)

    return jsonify({"sum_A": int_to_str(sum_A), "sum_B": int_to_str(sum_B)})
Пример #12
0
def blind_signature_verify_rsa_handler():
    data = get_post_data(request)

    signature = int(data.get('signature'), 16)
    modulo = int(data.get('modulo'), 16)
    publicExp = int(data.get('publicExp'), 16)
    message = bytes(data.get('message'), encoding='utf-8')

    return jsonify({
        "verified":
        blind_signature_verify_rsa(signature, message, publicExp, modulo)
    })
Пример #13
0
def blind_signature_generate_rsa_handler():
    data = get_post_data(request)

    message = bytes(data.get('message'), encoding='utf-8')
    signature = dummy_blind_signature_generate_rsa(message)

    return jsonify({
        "message": data.get('message'),
        "signature": dec_to_hexstr(signature),
        "publicExp": dec_to_hexstr(public_exp),
        "modulo": dec_to_hexstr(modulo)
    })
Пример #14
0
def point_validate_handler():
    data = get_post_data(request)
    point = str_to_hex(data.get('point'))
    if data.get('curve') == 'gost':
        valid = gost_point_validate(point)
    elif data.get('curve') == 'bitcoin':
        point = [str(point[0]), str(point[1])]
        valid = point_validate(point)
    else:
        return jsonify({"valid": False, "error": "Unknown curve"}), 400

    return jsonify({"valid": valid})
Пример #15
0
def unblind_public_keys_hanlder():
    data = get_post_data(request)
    publicKeysCommits = list(
        map(lambda publicKeyCommit: str_to_int(publicKeyCommit),
            data.get('publicKeysCommits')))
    secretKeysOfCommits = str_to_int(data.get('secretKeysOfCommits'))
    unblindedPublicKeys = unblind_public_keys(publicKeysCommits,
                                              secretKeysOfCommits)
    return jsonify({
        "unblindedPublicKeys":
        list(
            map(lambda publicKey: int_to_str([publicKey.x, publicKey.y]),
                unblindedPublicKeys))
    })
Пример #16
0
def blind_signature_generate_handler():
    data = get_post_data(request)

    message = data.get('message')
    rho, omega, sigma, delta, Z, public_key = dummy_blind_signature_generate(
        message)

    return jsonify({
        "rho": dec_to_hexstr(rho),
        "omega": dec_to_hexstr(omega),
        "sigma": dec_to_hexstr(sigma),
        "delta": dec_to_hexstr(delta),
        "Z": dec_to_hexstr([Z.x, Z.y]),
        "message": message,
        "publicKey": dec_to_hexstr([public_key.x, public_key.y]),
    })
Пример #17
0
def calculate_encrypted_shadows_handler():
    data = get_post_data(request)
    coefficients = str_to_int(data.get('polynomialCoefficients'))
    unblindedPublicKeys = list(
        map(lambda publicKey: str_to_int(publicKey),
            data.get('unblindedPublicKeys')))
    encryptedShadows = calculate_encrypted_shadows(coefficients,
                                                   unblindedPublicKeys)
    return jsonify({
        "encryptedShadows":
        list(
            map(
                lambda encryptedShadow: {
                    "privateKey":
                    int_to_str(encryptedShadow[0]),
                    "publicKey":
                    int_to_str([encryptedShadow[1].x, encryptedShadow[1].y])
                }, encryptedShadows))
    })
Пример #18
0
def blind_signature_verify_handler():
    data = get_post_data(request)

    rho = int(data.get('rho'), 16)
    omega = int(data.get('omega'), 16)
    delta = int(data.get('delta'), 16)
    sigma = int(data.get('sigma'), 16)
    message = data.get('message')
    Z = data.get('Z')
    Z = [int(Z[0], 16), int(Z[1], 16)]

    public_key = data.get('publicKey')
    public_key = [int(public_key[0], 16), int(public_key[1], 16)]

    return jsonify({
        "verified":
        blind_signature_verify(rho, omega, sigma, delta, Z, message,
                               public_key)
    })
Пример #19
0
def decrypt_and_check_shadows_handler():
    data = get_post_data(request)
    privateKey = str_to_int(data.get('privateKey'))
    idx = str_to_int(data.get('idx'))
    polynomialCoefficientsExponents = list(
        str_to_int(data.get('polynomialCoefficientsExponents')))
    encrypted_shadows = list(
        map(
            lambda shadow: [
                str_to_int(shadow['privateKey']),
                str_to_int([shadow['publicKey'][0], shadow['publicKey'][1]])
            ], data.get('encryptedShadows')))

    unblindedPublicKeys = list(
        map(lambda publicKey: str_to_int(publicKey),
            data.get('unblindedPublicKeys')))

    result = decrypt_and_check_shadows(privateKey, idx, encrypted_shadows,
                                       polynomialCoefficientsExponents,
                                       unblindedPublicKeys)
    return result
Пример #20
0
def restore_common_secret_handler():
    data = get_post_data(request)
    indexes = str_to_int(data.get('indexes'))
    decryptedShadowsSums = str_to_int(data.get('decryptedShadowsSums'))
    commonSecret = restore_common_secret(indexes, decryptedShadowsSums)
    return jsonify({"commonSecret": int_to_str(commonSecret)})
Пример #21
0
def make_encrypted_bulletin_handler():
    data = get_post_data(request)
    bulletin = str_to_int(data.get('bulletin'))
    mainKey = str_to_int(data.get('mainKey'))
    encrypted_bulletin, proof = make_encrypted_bulletin(bulletin, mainKey)
    return jsonify([list(int_to_str(encrypted_bulletin)), int_to_str(proof)])
Пример #22
0
def partially_decrypt_sum_a_handler():
    data = get_post_data(request)
    sum_A = str_to_int(data.get('sum_A'))
    decryptedShadowsSum = str_to_int(data.get('decryptedShadowsSum'))
    partiallyDecrypted = partially_decrypt_sum_a(sum_A, decryptedShadowsSum)
    return jsonify({"partiallyDecrypted": int_to_str(partiallyDecrypted)})
Пример #23
0
def generate_polynomial_coefficients_handler():
    data = get_post_data(request)
    privateKey = str_to_int(data.get('privateKey'))
    k = str_to_int(data.get('k'))
    coefficients = generate_polynomial_coefficients(privateKey, k)
    return jsonify({"polynomialCoefficients": int_to_str(coefficients)})
Пример #24
0
def verify_encrypted_bulletins_handler_v2():
    data = get_post_data(request)
    encryptedBulletins = str_to_int(data.get('encryptedBulletins'))
    mainKey = str_to_int(data.get('mainKey'))
    verified = verify_encrypted_bulletins_v2(encryptedBulletins, mainKey)
    return jsonify({"verified": verified})