mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-05 20:30:57 +00:00
Merge branch 'release/0.5.1'
This commit is contained in:
commit
45bc970eec
4 changed files with 33 additions and 64 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "x25519-dalek"
|
name = "x25519-dalek"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
authors = [
|
authors = [
|
||||||
"Isis Lovecruft <isis@patternsinthevoid.net>",
|
"Isis Lovecruft <isis@patternsinthevoid.net>",
|
||||||
"DebugSteven <debugsteven@gmail.com>",
|
"DebugSteven <debugsteven@gmail.com>",
|
||||||
|
|
|
||||||
73
README.md
73
README.md
|
|
@ -1,7 +1,7 @@
|
||||||
# x25519-dalek [](https://crates.io/crates/x25519-dalek) [](https://docs.rs/x25519-dalek) [](https://travis-ci.org/dalek-cryptography/x25519-dalek)
|
# x25519-dalek [](https://crates.io/crates/x25519-dalek) [](https://docs.rs/x25519-dalek) [](https://travis-ci.org/dalek-cryptography/x25519-dalek)
|
||||||
|
|
||||||
A pure-Rust implementation of x25519 elliptic curve Diffie-Hellman key exchange,
|
A pure-Rust implementation of x25519 elliptic curve Diffie-Hellman key exchange,
|
||||||
with curve operations provided by
|
with curve operations provided by
|
||||||
[curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek).
|
[curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek).
|
||||||
|
|
||||||
This crate provides two levels of API: a bare byte-oriented `x25519`
|
This crate provides two levels of API: a bare byte-oriented `x25519`
|
||||||
|
|
@ -11,7 +11,7 @@ well as a higher-level Rust API for static and ephemeral Diffie-Hellman.
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
<a href="https://shop.bubblesort.io">
|
<a href="https://shop.bubblesort.io">
|
||||||
<img
|
<img
|
||||||
style="float: right; width: auto; height: 300px;"
|
style="float: right; width: auto; height: 300px;"
|
||||||
src="https://raw.githubusercontent.com/dalek-cryptography/x25519-dalek/master/res/bubblesort-zines-secret-messages-cover.jpeg"/>
|
src="https://raw.githubusercontent.com/dalek-cryptography/x25519-dalek/master/res/bubblesort-zines-secret-messages-cover.jpeg"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
@ -31,99 +31,46 @@ the rest of the afternoon nomming some yummy pie!
|
||||||
First, Alice uses `EphemeralSecret::new()` and then
|
First, Alice uses `EphemeralSecret::new()` and then
|
||||||
`PublicKey::from()` to produce her secret and public keys:
|
`PublicKey::from()` to produce her secret and public keys:
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
extern crate rand_os;
|
extern crate rand_os;
|
||||||
|
extern crate x25519_dalek;
|
||||||
|
|
||||||
use rand_os::OsRng;
|
use rand_os::OsRng;
|
||||||
|
|
||||||
extern crate x25519_dalek;
|
|
||||||
use x25519_dalek::EphemeralSecret;
|
use x25519_dalek::EphemeralSecret;
|
||||||
use x25519_dalek::PublicKey;
|
use x25519_dalek::PublicKey;
|
||||||
|
|
||||||
# fn main() {
|
|
||||||
let mut alice_csprng = OsRng::new().unwrap();
|
let mut alice_csprng = OsRng::new().unwrap();
|
||||||
let alice_secret = EphemeralSecret::new(&mut alice_csprng);
|
let alice_secret = EphemeralSecret::new(&mut alice_csprng);
|
||||||
let alice_public = PublicKey::from(&alice_secret);
|
let alice_public = PublicKey::from(&alice_secret);
|
||||||
# }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Bob does the same:
|
Bob does the same:
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
# extern crate rand_os;
|
|
||||||
# use rand_os::OsRng;
|
|
||||||
#
|
|
||||||
# extern crate x25519_dalek;
|
|
||||||
# use x25519_dalek::EphemeralSecret;
|
|
||||||
# use x25519_dalek::PublicKey;
|
|
||||||
# fn main() {
|
|
||||||
let mut bob_csprng = OsRng::new().unwrap();
|
let mut bob_csprng = OsRng::new().unwrap();
|
||||||
let bob_secret = EphemeralSecret::new(&mut bob_csprng);
|
let bob_secret = EphemeralSecret::new(&mut bob_csprng);
|
||||||
let bob_public = PublicKey::from(&bob_secret);
|
let bob_public = PublicKey::from(&bob_secret);
|
||||||
# }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Alice meows across the room, telling `alice_public` to Bob, and Bob
|
Alice meows across the room, telling `alice_public` to Bob, and Bob
|
||||||
loudly meows `bob_public` back to Alice. Alice now computes her
|
loudly meows `bob_public` back to Alice. Alice now computes her
|
||||||
shared secret with Bob by doing:
|
shared secret with Bob by doing:
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
# extern crate rand_os;
|
|
||||||
# use rand_os::OsRng;
|
|
||||||
#
|
|
||||||
# extern crate x25519_dalek;
|
|
||||||
# use x25519_dalek::EphemeralSecret;
|
|
||||||
# use x25519_dalek::PublicKey;
|
|
||||||
#
|
|
||||||
# fn main() {
|
|
||||||
# let mut csprng = OsRng::new().unwrap();
|
|
||||||
# let alice_secret = EphemeralSecret::new(&mut csprng);
|
|
||||||
# let alice_public = PublicKey::from(&alice_secret);
|
|
||||||
# let bob_secret = EphemeralSecret::new(&mut csprng);
|
|
||||||
# let bob_public = PublicKey::from(&bob_secret);
|
|
||||||
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
||||||
# }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Similarly, Bob computes a shared secret by doing:
|
Similarly, Bob computes a shared secret by doing:
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
# extern crate rand_os;
|
|
||||||
# use rand_os::OsRng;
|
|
||||||
#
|
|
||||||
# extern crate x25519_dalek;
|
|
||||||
# use x25519_dalek::EphemeralSecret;
|
|
||||||
# use x25519_dalek::PublicKey;
|
|
||||||
#
|
|
||||||
# fn main() {
|
|
||||||
# let mut csprng = OsRng::new().unwrap();
|
|
||||||
# let alice_secret = EphemeralSecret::new(&mut csprng);
|
|
||||||
# let alice_public = PublicKey::from(&alice_secret);
|
|
||||||
# let bob_secret = EphemeralSecret::new(&mut csprng);
|
|
||||||
# let bob_public = PublicKey::from(&bob_secret);
|
|
||||||
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
||||||
# }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
These secrets are the same:
|
These secrets are the same:
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
# extern crate rand_os;
|
|
||||||
# use rand_os::OsRng;
|
|
||||||
#
|
|
||||||
# extern crate x25519_dalek;
|
|
||||||
# use x25519_dalek::EphemeralSecret;
|
|
||||||
# use x25519_dalek::PublicKey;
|
|
||||||
#
|
|
||||||
# fn main() {
|
|
||||||
# let mut csprng = OsRng::new().unwrap();
|
|
||||||
# let alice_secret = EphemeralSecret::new(&mut csprng);
|
|
||||||
# let alice_public = PublicKey::from(&alice_secret);
|
|
||||||
# let bob_secret = EphemeralSecret::new(&mut csprng);
|
|
||||||
# let bob_public = PublicKey::from(&bob_secret);
|
|
||||||
# let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
|
||||||
# let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
|
||||||
assert_eq!(alice_shared_secret.as_bytes(), bob_shared_secret.as_bytes());
|
assert_eq!(alice_shared_secret.as_bytes(), bob_shared_secret.as_bytes());
|
||||||
# }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Voilá! Alice and Bob can now use their shared secret to encrypt their
|
Voilá! Alice and Bob can now use their shared secret to encrypt their
|
||||||
|
|
@ -140,7 +87,7 @@ To install, add the following to your project's `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies.x25519-dalek]
|
[dependencies.x25519-dalek]
|
||||||
version = "^0.4"
|
version = "^0.5"
|
||||||
```
|
```
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@ extern crate curve25519_dalek;
|
||||||
|
|
||||||
extern crate rand_core;
|
extern crate rand_core;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
extern crate rand_os;
|
||||||
|
|
||||||
mod x25519;
|
mod x25519;
|
||||||
|
|
||||||
pub use x25519::*;
|
pub use x25519::*;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ use rand_core::CryptoRng;
|
||||||
|
|
||||||
/// A `PublicKey` is the corresponding public key converted from
|
/// A `PublicKey` is the corresponding public key converted from
|
||||||
/// an `EphemeralSecret` or a `StaticSecret` key.
|
/// an `EphemeralSecret` or a `StaticSecret` key.
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct PublicKey(pub (crate) MontgomeryPoint);
|
pub struct PublicKey(pub (crate) MontgomeryPoint);
|
||||||
|
|
||||||
impl From<[u8; 32]> for PublicKey {
|
impl From<[u8; 32]> for PublicKey {
|
||||||
|
|
@ -191,6 +192,24 @@ pub const X25519_BASEPOINT_BYTES: [u8; 32] = [
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
use rand_os::OsRng;
|
||||||
|
|
||||||
|
// This was previously a doctest but it got moved to the README to
|
||||||
|
// avoid duplication where it then wasn't being run, so now it
|
||||||
|
// lives here.
|
||||||
|
#[test]
|
||||||
|
fn alice_and_bob() {
|
||||||
|
let mut csprng = OsRng::new().unwrap();
|
||||||
|
let alice_secret = EphemeralSecret::new(&mut csprng);
|
||||||
|
let alice_public = PublicKey::from(&alice_secret);
|
||||||
|
let bob_secret = EphemeralSecret::new(&mut csprng);
|
||||||
|
let bob_public = PublicKey::from(&bob_secret);
|
||||||
|
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
||||||
|
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
||||||
|
|
||||||
|
assert_eq!(alice_shared_secret.as_bytes(), bob_shared_secret.as_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn byte_basepoint_matches_edwards_scalar_mul() {
|
fn byte_basepoint_matches_edwards_scalar_mul() {
|
||||||
let mut scalar_bytes = [0x37; 32];
|
let mut scalar_bytes = [0x37; 32];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue