Crate ed25519_dalek [] [src]

ed25519 signatures and verification

Example

Creating an ed25519 signature on a message is simple.

First, we need to generate a Keypair, which includes both public and secret halves of an asymmetric key. To do so, we need a cryptographically secure pseudorandom number generator (CSPRING), and a hash function which has 512 bits of output. For this example, we'll use the operating system's builtin PRNG and SHA-512 to generate a keypair:

extern crate rand;
extern crate sha2;
extern crate ed25519_dalek;

use rand::Rng;
use rand::OsRng;
use sha2::Sha512;
use ed25519_dalek::Keypair;
use ed25519_dalek::Signature;

let mut cspring: OsRng = OsRng::new().unwrap();
let keypair: Keypair = Keypair::generate::<Sha512>(&mut cspring);

We can now use this keypair to sign a message:

let message: &[u8] = "This is a test of the tsunami alert system.".as_bytes();
let signature: Signature = keypair.sign::<Sha512>(message);

As well as to verify that this is, indeed, a valid signature on that message:

let verified: bool = keypair.verify::<Sha512>(message, &signature);

assert!(verified);

Anyone else, given the public half of the keypair can also easily verify this signature:

use ed25519_dalek::PublicKey;
let public_key: PublicKey = keypair.public;
let verified: bool = public_key.verify::<Sha512>(message, &signature);

assert!(verified);

Structs

Keypair

An ed25519 keypair.

PublicKey

An ed25519 public key.

SecretKey

An EdDSA secret key.

Signature

An EdDSA signature.

Constants

PUBLIC_KEY_LENGTH

The length of an ed25519 EdDSA PublicKey, in bytes.

SECRET_KEY_LENGTH

The length of an ed25519 EdDSA SecretKey, in bytes.

SIGNATURE_LENGTH

The length of an ed25519 EdDSA Signature, in bytes.