Exemplo n.º 1
0
    def test_tv(self):
        """ Test using test vectors """

        for vector in vectors:
            r, c = commitments.nm_commit(None, vector['X'], vector['R'])

            self.assertEqual(vector['R'], r)
            self.assertEqual(vector['C'], c)
Exemplo n.º 2
0
def generate_key_material_zkp(rng, key_material, ID, AD=None):
    """ Generate ZK Proofs for key material

    Generate a commitment to the ECDSA PK, a Schnorr's
    Proof for the ECDSA PK and a factoring Proof for the
    Paillier PK
    The key material dictionary must have keys:
     * paillier_sk
     * paillier_pk
     * ecdsa_sk
     * ecdsa_pk

    Args::

        rng: pointer to CSPRNG
        key_material: dictionary with the key material

    Returns::

        r:  secret value for the ECDSA PK commitment
        c:  commitment for the ECDSA PK
        sc: commitment for the Schnorr's Proof
        sp: Schnorr's Proof
        fe: Factoring Proof. First component
        fy: Factoring Proof. Second component

    """
    # Commit to ECDSA PK
    r, c = commitments.nm_commit(rng, key_material['ecdsa_pk'])

    # Generate Schnorr's proof for ECDSA PK
    sr, sc = schnorr.commit(rng)
    e = schnorr.challenge(key_material['ecdsa_pk'], sc, ID, AD=AD)
    sp = schnorr.prove(sr, e, key_material['ecdsa_sk'])

    # Generate ZKP of knowledge of factorization for
    # Paillier key pair
    psk_p, psk_q = mpc.mpc_dump_paillier_sk(key_material['paillier_sk'])

    fe, fy = factoring_zk.prove(rng, psk_p, psk_q, ID, ad=AD)

    return r, c, sc, sp, fe, fy
Exemplo n.º 3
0
    def test_random(self):
        """ Test using rng """
        r, c = commitments.nm_commit(self.rng, self.msg)

        self.assertEqual(r, self.r_golden)
        self.assertEqual(c, self.c_golden)
Exemplo n.º 4
0
under the License.
"""

import os
import sys
from bench import time_func

sys.path.insert(0,
                os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from amcl import commitments

x_hex = "40576370e36018f6bfaffc4c66780303a361f0c5f4a18a86a74fb179ca0fcf22"
r_hex = "296f910bde4530efe3533ed3b74475d6022364db2e57773207734b6daf547ac8"

if __name__ == "__main__":
    x = bytes.fromhex(x_hex)
    r = bytes.fromhex(r_hex)

    # Generate quantities for benchmark
    r, c = commitments.nm_commit(None, x, r)

    assert commitments.nm_decommit(x, r, c) == commitments.OK

    # Run benchmark
    fncall = lambda: commitments.nm_commit(None, x, r)
    time_func("nm_commit  ", fncall, unit="us")

    fncall = lambda: commitments.nm_decommit(x, r, c)
    time_func("nm_decommit", fncall, unit="us")
Exemplo n.º 5
0
    M = b'test message'

    print(f"\nSign message '{M.decode('utf-8')}'")

    # Generate k, gamma and gamma.G
    print("[Alice] Generate k, gamma and gamma.G")
    GAMMA1, gamma1 = mpc.mpc_ecdsa_key_pair_generate(rng)
    k1 = mpc.mpc_k_generate(rng)

    print("[Bob] Generate k, gamma and gamma.G")
    GAMMA2, gamma2 = mpc.mpc_ecdsa_key_pair_generate(rng)
    k2 = mpc.mpc_k_generate(rng)

    ## Commit to GAMMA1, GAMMA2 and exchange nonces for liveliness
    print("[Alice] Commit to GAMMA1")
    GAMMAR1, GAMMAC1 = commitments.nm_commit(rng, GAMMA1)

    bob_ad = core_utils.generate_random(rng, 32)

    print("[Bob] Commit to GAMMA2")
    GAMMAR2, GAMMAC2 = commitments.nm_commit(rng, GAMMA2)

    alice_ad = core_utils.generate_random(rng, 32)

    ## Engage in MTA with k_i, gamma_j

    # k1, gamma2
    print("[Alice] Engage in MTA with shares k1, gamma2")

    ca = mpc.mpc_mta_client1(rng, key_material1['paillier_pk'], k1)
    cb, beta2 = mpc.mpc_mta_server(rng, c_key_material2['paillier_pk'], gamma2, ca)
Exemplo n.º 6
0
                os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from amcl import core_utils, commitments

seed_hex = "78d0fb6705ce77dee47d03eb5b9c5d30"

if __name__ == "__main__":
    seed = bytes.fromhex(seed_hex)
    rng = core_utils.create_csprng(seed)

    print("Example Non Malleable Commitment")
    print("Message: BANANA")

    x = b'BANANA'

    # Commitment Phase
    r, c = commitments.nm_commit(rng, x)

    print("\nCommitment")
    print(f"\tr = {r.hex()}")
    print(f"\tc = {c.hex()}")

    # Decommitment Phase. After both c, r and x have been revealed
    rc = commitments.nm_decommit(x, r, c)

    print("\nDecommitment")
    if rc == commitments.OK:
        print("\tSuccess")
    else:
        print("\tFailure")