How to use the fastecdsa.curve function in fastecdsa

To help you get started, we’ve selected a few fastecdsa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / normandy / normandy / recipes / signing.py View on Github external
#     assert len(signature) == 2*l, (len(signature), 2*l)
        # If the AssertionError is consistent with that signature, translate it
        # to a nicer error. Otherwise re-raise.
        if (
            len(e.args) == 1
            and isinstance(e.args[0], tuple)
            and len(e.args[0]) == 2
            and isinstance(e.args[0][0], int)
            and isinstance(e.args[0][1], int)
        ):
            raise WrongSignatureSize()
        else:
            raise

    verified = fastecdsa.ecdsa.verify(
        signature, data, verifying_pubkey, curve=fastecdsa.curve.P384, hashfunc=hashlib.sha384
    )

    if not verified:
        raise SignatureDoesNotMatch()

    return True
github blockstack / blockstack-core / blockstack_cli_0.14.1 / blockstack_client / storage.py View on Github external
Returns signature as a base64 string
    """

    # force uncompressed
    priv = str(privatekey_hex)
    if len(priv) > 64:
        assert priv[-2:] == '01'
        priv = priv[:64]

    pk_i = int(priv, 16)
    sig_r, sig_s = fastecdsa.ecdsa.sign(raw_data, pk_i, curve=fastecdsa.curve.secp256k1)

    # enforce low-s 
    if sig_s * 2 >= fastecdsa.curve.secp256k1.q:
        log.debug("High-S to low-S")
        sig_s = fastecdsa.curve.secp256k1.q - sig_s

    sig_bin = '{:064x}{:064x}'.format(sig_r, sig_s).decode('hex')
    assert len(sig_bin) == 64

    sig_b64 = base64.b64encode(sig_bin)
    return sig_b64