Git Product home page Git Product logo

tiny-ecdh-python's Introduction

Tiny ECDH in Python

This is a Python implementation of the Tiny ECDH in C

It's a small and portable implementation of the Elliptic-Curve Diffie-Hellman key agreement algorithm written in Python.

Description from Wikipedia:

Elliptic-curve Diffie–Hellman (ECDH) is an anonymous key agreement protocol that allows two parties, each having an elliptic-curve public–private key pair, to establish a shared secret over an insecure channel. This shared secret may be directly used as a key, or to derive another key. The key, or the derived key, can then be used to encrypt subsequent communications using a symmetric-key cipher. It is a variant of the Diffie–Hellman protocol using elliptic-curve cryptography. ` This repository was developed just by replicating the C version in Python, and can be improved to a more pythonic alternative. It's still very slow when compared to the C version.

Usage:

The ECDH algorithm (Elliptic Curve Diffie–Hellman Key Exchange) is trivial:

  1. Alice generates a random ECC key pair: {alicePrivKey, alicePubKey = alicePrivKey * G}
# Assumes private key is filled with random data before calling, and generates public key
alicePrivKey, alicePubKey = ecdh_generate_keys(alicePrivKey, alicePubKey)
  1. Bob generates a random ECC key pair: {bobPrivKey, bobPubKey = bobPrivKey * G}
# Assumes private key is filled with random data before calling, and generates public key
bobPrivKey, bobPubKey = ecdh_generate_keys(bobPrivKey, bobPubKey)
  1. Alice and Bob exchange their public keys through the insecure channel (e.g. over Bluetooth)

  2. Alice calculates sharedKey = bobPubKey * alicePrivKey

# own private key + Bob's public key will generate a shared secret key
aliceSharedKey = ecdh_shared_secret(alicePrivKey, bobPubKey)
  1. Bob calculates sharedKey = alicePubKey * bobPrivKey
# own private key + Alice's public key will generate a shared secret key
bobSharedKey = ecdh_shared_secret(bobPrivKey, alicePubKey)
  1. Now both Alice and Bob have the same sharedKey == bobPubKey * alicePrivKey == alicePubKey * bobPrivKey
assert aliceSharedKey == bobSharedKey

TODO:

  • Add more NIST curves
  • Create a more pythonic alternative

tiny-ecdh-python's People

Contributors

danielsousaoliveira avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.