Giter Club home page Giter Club logo

x25519-dalek's Introduction

x25519-dalek

A pure-Rust implementation of x25519 elliptic curve Diffie-Hellman key exchange, as specified by Mike Hamburg and Adam Langley in RFC7748, using curve25519-dalek.

Examples

"Secret Messages" cover image and zine copyright © Amy Wibowo (@sailorhg)

Alice and Bob are two adorable kittens who have lost their mittens, and they wish to be able to send secret messages to each other to coordinate finding them, otherwise—if their caretaker cat finds out—they will surely be called naughty kittens and be given no pie!

But the two kittens are quite clever. Even though their paws are still too big and the rest of them is 90% fuzziness, these clever kittens have been studying up on modern public key cryptography and have learned a nifty trick called elliptic curve Diffie-Hellman key exchange. With the right incantations, the kittens will be able to secretly organise to find their mittens, and then spend the rest of the afternoon nomming some yummy pie!

First, Alice uses x25519_dalek::generate_secret() and then x25519_dalek::generate_public() to produce her secret and public keys:

extern crate x25519_dalek;
extern crate rand;

use x25519_dalek::generate_secret;
use x25519_dalek::generate_public;
use rand::OsRng;

let mut alice_csprng = OsRng::new().unwrap();
let     alice_secret = generate_secret(&mut alice_csprng);
let     alice_public = generate_public(&alice_secret);

Bob does the same:

let mut bob_csprng = OsRng::new().unwrap();
let     bob_secret = generate_secret(&mut bob_csprng);
let     bob_public = generate_public(&bob_secret);

Alice meows across the room, telling alice_public to Bob, and Bob loudly meows bob_public back to Alice. Alice now computes her shared secret with Bob by doing:

use x25519_dalek::diffie_hellman;

let shared_secret = diffie_hellman(&alice_secret, &bob_public.as_bytes());

Similarly, Bob computes the same shared secret by doing:

let shared_secret = diffie_hellman(&bob_secret, &alice_public.as_bytes());

Voilá! Alice and Bob can now use their shared secret to encrypt their meows, for example, by using it to generate a key and nonce for an authenticated-encryption cipher.

Warnings

Our elliptic curve library (which this code uses) has received one formal cryptographic and security review. It has not yet received what we would consider sufficient peer review by other qualified cryptographers to be considered in any way, shape, or form, safe.

This code matches the test vectors, as specified in RFC7748, however:

USE AT YOUR OWN RISK.

Documentation

Documentation is available here.

Installation

To install, add the following to your project's Cargo.toml:

[dependencies.x25519-dalek]
version = "^0.3"

Then, in your library or executable source, add:

extern crate x25519_dalek;

x25519-dalek's People

Contributors

isislovecruft avatar mcginty avatar oleganza avatar

Watchers

Artyom Pavlov avatar James Cloos 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.