Skip to content

Commit

Permalink
docs refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DebugSteven committed Dec 2, 2018
2 parents 734abac + 7d80f96 commit 2619200
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,44 @@ 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::EphemeralSecret::new()` and then
`x25519_dalek::EphemeralPublic::generate_public()` to produce her secret and public keys:
`x25519_dalek::EphemeralPublic::from()` to produce her secret and public keys:

```rust
extern crate x25519_dalek;
extern crate rand;

use x25519_dalek::Ephemeral;
use x25519_dalek::EphemeralPublic;
use x25519_dalek::EphemeralSecret;
use rand::OsRng;

let mut alice_csprng = OsRng::new().unwrap();
let alice_secret = EphemeralSecret::new(&mut alice_csprng);
let alice_public = EphemeralPublic::generate_public(&alice_secret);
let alice_public = EphemeralPublic::from(&alice_secret);
```

Bob does the same:

```rust
let mut bob_csprng = OsRng::new().unwrap();
let bob_secret = EphemeralSecret::new(&mut bob_csprng);
let bob_public = EphemeralPublic::generate_public(&bob_secret);
let bob_public = EphemeralPublic::from(&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:

```rust
use x25519_dalek::Ephemeral;
use x25519_dalek::EphemeralPublic;
use x25519_dalek::EphemeralSecret;

let shared_secret = Ephemeral::diffie_hellman(&alice_secret, &bob_public);
let shared_secret = EphemeralSecret::diffie_hellman(&alice_secret, &bob_public);
```

Similarly, Bob computes the same shared secret by doing:

```rust
let shared_secret = Ephemeral::diffie_hellman(&bob_secret, &alice_public);
let shared_secret = EphemeralSecret::diffie_hellman(&bob_secret, &alice_public);
```

Voilá! Alice and Bob can now use their shared secret to encrypt their
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
//! # let bob_secret = EphemeralSecret::new(&mut bob_csprng);
//! # let bob_public = EphemeralPublic::from(&bob_secret);
//! #
//!
//! #
//! let shared_secret = EphemeralSecret::diffie_hellman(&alice_secret, &bob_public);
//! # }
//! ```
Expand Down

0 comments on commit 2619200

Please sign in to comment.