How to use the ecdsa.SigningKey.generate function in ecdsa

To help you get started, we’ve selected a few ecdsa 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-services / autopush-loadtester / aplt / vapid.py View on Github external
def generate_keys(self):
        """Generate a valid ECDSA Key Pair."""
        self.private_key = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p)
        # init the public key using the above property function
        self.public_key
github P2PSP / core / src / tools / crypto-test / test-ecdsa.py View on Github external
def main(args):
    message = "Hello, P2PSP!" * 1024
    sk = SigningKey.generate()
    vk = sk.get_verifying_key()
    # measure the sign time
    start_time = time.time()
    for _ in xrange(N):
        sig = sign(message, sk)
    print "key.sign x{0} times: {1}s".format(N, time.time() - start_time)

    #measure the verify time
    sig = sign(message, sk)
    start_time = time.time()
    for _ in xrange(N):
        r = check(message, vk, sig)
    print "key.verify x{0} times: {1}s".format(N, time.time() - start_time)
github mpdavis / python-jose / tests / algorithms / test_cryptography_EC.py View on Github external
def test_key_too_short(self):
        priv_key = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p).to_pem()
        key = CryptographyECKey(priv_key, ALGORITHMS.ES512)
        with pytest.raises(TypeError):
            key.sign('foo')
github justinmoon / digital-cash / banknetcoin_tests.py View on Github external
import uuid, pytest
from ecdsa import SigningKey, VerifyingKey, SECP256k1
from ecdsa.keys import BadSignatureError
from bankutxocoin import TxIn, TxOut, Tx, Bank
# from mybanknetcoin import TxIn, TxOut, Tx, Bank

# The usual suspects
bob_private_key = SigningKey.generate(curve=SECP256k1)
alice_private_key = SigningKey.generate(curve=SECP256k1)
bob_public_key = bob_private_key.get_verifying_key()
alice_public_key = alice_private_key.get_verifying_key()


def test_bank_balances():
    # Create bank and issue Alice some coins
    bank = Bank()
    coinbase = bank.issue(1000, alice_public_key)

    # Alice sends 10 coins to Bob
    tx_ins = [
        TxIn(tx_id=coinbase.id, index=0, signature=None),
    ]
    tx_id = uuid.uuid4()
    tx_outs = [
github adafruit / Adafruit_nRF52_Arduino / tools / nrfutil-0.5.2 / nordicsemi / dfu / signing.py View on Github external
def gen_key(self, filename):
        """
        Generate a new Signing key using NIST P-256 curve
        """
        self.sk = SigningKey.generate(curve=NIST256p)

        with open(filename, "w") as sk_file:
            sk_file.write(self.sk.to_pem())
github warner / python-ecdsa / speed.py View on Github external
S2 = "sk = SigningKey.generate(%s)" % curve
    S3 = "msg = six.b('msg')"
    S4 = "sig = sk.sign(msg)"
    S5 = "vk = sk.get_verifying_key()"
    S6 = "vk.precompute()"
    S7 = "vk.verify(sig, msg)"
    # We happen to know that .generate() also calculates the
    # verifying key, which is the time-consuming part. If the code
    # were changed to lazily calculate vk, we'd need to change this
    # benchmark to loop over S5 instead of S2
    keygen = do([S1], S2)
    sign = do([S1,S2,S3], S4)
    verf = do([S1,S2,S3,S4,S5,S6], S7)
    import ecdsa
    c = getattr(ecdsa, curve)
    sig = ecdsa.SigningKey.generate(c).sign(six.b("msg"))
    print(prnt_form.format(
        name=curve, sep=":", siglen=len(sig), unit="s", keygen=keygen,
        keygen_inv=1.0/keygen, sign=sign, sign_inv=1.0/sign, verify=verf,
        verify_inv=1.0/verf, form=".5f", form_inv=".2f"))

print('')

ecdh_form = (
    "{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} "
    "{ecdh_inv:>9{form_inv}}")

print(ecdh_form.format(ecdh="ecdh", ecdh_inv="ecdh/s", name="", sep="",
                       unit="", form="", form_inv=""))

for curve in [i.name for i in curves]:
    S1 = "from ecdsa import SigningKey, ECDH, {0}".format(curve)
github cloudera / hue / desktop / core / ext-py / cryptography-2.0 / docs / development / custom-vectors / secp256k1 / generate_secp256k1.py View on Github external
vectors[vector['digest_algorithm']].append(vector['message'])

    for digest_algorithm, messages in vectors.items():
        if digest_algorithm not in HASHLIB_HASH_TYPES:
            continue

        yield ""
        yield "[K-256,{0}]".format(digest_algorithm)
        yield ""

        for message in messages:
            # Make a hash context
            hash_func = TruncatedHash(HASHLIB_HASH_TYPES[digest_algorithm]())

            # Sign the message using warner/ecdsa
            secret_key = SigningKey.generate(curve=SECP256k1)
            public_key = secret_key.get_verifying_key()
            signature = secret_key.sign(message, hashfunc=hash_func,
                                        sigencode=sigencode_der)

            r, s = sigdecode_der(signature, None)

            yield "Msg = {0}".format(hexlify(message))
            yield "d = {0:x}".format(secret_key.privkey.secret_multiplier)
            yield "Qx = {0:x}".format(public_key.pubkey.point.x())
            yield "Qy = {0:x}".format(public_key.pubkey.point.y())
            yield "R = {0:x}".format(r)
            yield "S = {0:x}".format(s)
            yield ""
github perone / protocoin / protocoin / keys.py View on Github external
def __init__(self, hexkey=None, entropy=None):
        if hexkey:
            stringkey = hexkey.decode("hex")
            self.private_key = \
                ecdsa.SigningKey.from_string(stringkey, curve=ecdsa.SECP256k1)
        else:
            self.private_key = \
                ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1,
                    entropy=entropy)
github mozilla / chromeless / python-lib / cuddlefish / preflight.py View on Github external
def create_key(keydir, name):
    # return jid
    from ecdsa import SigningKey, NIST256p
    sk = SigningKey.generate(curve=NIST256p)
    sk_text = "private-jid0-%s" % my_b32encode(sk.to_string())
    vk = sk.get_verifying_key()
    vk_text = "public-jid0-%s" % my_b32encode(vk.to_string())
    jid = vk_to_jid(vk)
    program_id = jid_to_programid(jid)
    # save privkey to ~/.jetpack-keys/$jid
    f = open(os.path.join(keydir, jid), "w")
    f.write("private-key: %s\n" % sk_text)
    f.write("public-key: %s\n" % vk_text)
    f.write("jid: %s\n" % jid)
    f.write("program-id: %s\n" % program_id)
    f.write("name: %s\n" % name)
    f.close()
    return jid
github cosme12 / SimpleCoin / simpleCoin / wallet.py View on Github external
def generate_ECDSA_keys():
    """This function takes care of creating your private and public (your address) keys.
    It's very important you don't lose any of them or those wallets will be lost
    forever. If someone else get access to your private key, you risk losing your coins.

    private_key: str
    public_ley: base64 (to make it shorter)
    """
    sk = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1) #this is your sign (private key)
    private_key = sk.to_string().hex() #convert your private key to hex
    vk = sk.get_verifying_key() #this is your verification key (public key)
    public_key = vk.to_string().hex()
    #we are going to encode the public key to make it shorter
    public_key = base64.b64encode(bytes.fromhex(public_key))

    filename = input("Write the name of your new address: ") + ".txt"
    with open(filename, "w") as f:
        f.write("Private key: {0}\nWallet address / Public key: {1}".format(private_key, public_key.decode()))
    print("Your new address and private key are now in the file {0}".format(filename))