예제 #1
0
def test_single_eddsa_vector(privkey, pubkey, message, signature):
    my_pubkey = cosi.pubkey_from_privkey(privkey)
    assert my_pubkey == pubkey
    try:
        cosi.verify(signature, message, pubkey)
    except ValueError:
        pytest.fail("Signature does not verify.")

    fake_signature = signature[:37] + b"\xf0" + signature[38:]
    with pytest.raises(_ed25519.SignatureMismatch):
        cosi.verify(fake_signature, message, pubkey)
예제 #2
0
def test_single_eddsa_vector(privkey, pubkey, message, signature):
    my_pubkey = cosi.pubkey_from_privkey(privkey)
    assert my_pubkey == pubkey
    try:
        cosi.verify(signature, message, pubkey)
    except ValueError:
        pytest.fail("Signature does not verify.")

    fake_signature = b"\xf1" + signature[1:]
    with pytest.raises(ValueError):
        cosi.verify(fake_signature, message, pubkey)
예제 #3
0
def test_single_eddsa_vector(privkey, pubkey, message, signature):
    my_pubkey = cosi.pubkey_from_privkey(privkey)
    assert my_pubkey == pubkey
    try:
        cosi.verify(signature, message, pubkey)
    except ValueError:
        pytest.fail("Signature does not verify.")

    fake_signature = signature[:37] + b"\xf0" + signature[38:]
    with pytest.raises(_ed25519.SignatureMismatch):
        cosi.verify(fake_signature, message, pubkey)
예제 #4
0
    def test_cosi_compat(self):
        self.setup_mnemonic_pin_passphrase()

        digest = sha256(b'this is not a pipe').digest()
        remote_commit = self.client.cosi_commit(parse_path("10018'/0'"), digest)

        local_privkey = sha256(b'private key').digest()[:32]
        local_pubkey = cosi.pubkey_from_privkey(local_privkey)
        local_nonce, local_commitment = cosi.get_nonce(local_privkey, digest, 42)

        global_pk = cosi.combine_keys([remote_commit.pubkey, local_pubkey])
        global_R = cosi.combine_keys([remote_commit.commitment, local_commitment])

        remote_sig = self.client.cosi_sign(parse_path("10018'/0'"), digest, global_R, global_pk)
        local_sig = cosi.sign_with_privkey(digest, local_privkey, global_pk, local_nonce, global_R)
        sig = cosi.combine_sig(global_R, [remote_sig.signature, local_sig])

        cosi.verify(sig, digest, global_pk)
예제 #5
0
def test_cosi_compat(client):
    digest = sha256(b"this is not a pipe").digest()
    remote_commit = cosi.commit(client, parse_path("10018'/0'"), digest)

    local_privkey = sha256(b"private key").digest()[:32]
    local_pubkey = cosi.pubkey_from_privkey(local_privkey)
    local_nonce, local_commitment = cosi.get_nonce(local_privkey, digest, 42)

    global_pk = cosi.combine_keys([remote_commit.pubkey, local_pubkey])
    global_R = cosi.combine_keys([remote_commit.commitment, local_commitment])

    remote_sig = cosi.sign(client, parse_path("10018'/0'"), digest, global_R,
                           global_pk)
    local_sig = cosi.sign_with_privkey(digest, local_privkey, global_pk,
                                       local_nonce, global_R)
    sig = cosi.combine_sig(global_R, [remote_sig.signature, local_sig])

    cosi.verify_combined(sig, digest, global_pk)
예제 #6
0
def sign_with_privkeys(digest: bytes, privkeys: List[bytes]) -> bytes:
    """Locally produce a CoSi signature."""
    pubkeys = [cosi.pubkey_from_privkey(sk) for sk in privkeys]
    nonces = [cosi.get_nonce(sk, digest, i) for i, sk in enumerate(privkeys)]

    global_pk = cosi.combine_keys(pubkeys)
    global_R = cosi.combine_keys(R for r, R in nonces)

    sigs = [
        cosi.sign_with_privkey(digest, sk, global_pk, r, global_R)
        for sk, (r, R) in zip(privkeys, nonces)
    ]

    signature = cosi.combine_sig(global_R, sigs)
    try:
        cosi.verify_combined(signature, digest, global_pk)
    except Exception as e:
        raise click.ClickException("Failed to produce valid signature.") from e

    return signature
예제 #7
0
    def test_cosi_compat(self):
        self.setup_mnemonic_pin_passphrase()

        digest = sha256(b"this is not a pipe").digest()
        remote_commit = cosi.commit(self.client, parse_path("10018'/0'"), digest)

        local_privkey = sha256(b"private key").digest()[:32]
        local_pubkey = cosi.pubkey_from_privkey(local_privkey)
        local_nonce, local_commitment = cosi.get_nonce(local_privkey, digest, 42)

        global_pk = cosi.combine_keys([remote_commit.pubkey, local_pubkey])
        global_R = cosi.combine_keys([remote_commit.commitment, local_commitment])

        remote_sig = cosi.sign(
            self.client, parse_path("10018'/0'"), digest, global_R, global_pk
        )
        local_sig = cosi.sign_with_privkey(
            digest, local_privkey, global_pk, local_nonce, global_R
        )
        sig = cosi.combine_sig(global_R, [remote_sig.signature, local_sig])

        cosi.verify(sig, digest, global_pk)