[][src]Module libra_crypto::ed25519

This module provides an API for the PureEdDSA signature scheme over the ed25519 twisted Edwards curve as defined in RFC8032.

Signature verification also checks and rejects non-canonical signatures.

Examples

use libra_crypto_derive::{CryptoHasher, LCSCryptoHash};
use libra_crypto::{
    ed25519::*,
    traits::{Signature, SigningKey, Uniform},
};
use rand::{rngs::StdRng, SeedableRng};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, CryptoHasher, LCSCryptoHash)]
pub struct TestCryptoDocTest(String);
let message = TestCryptoDocTest("Test message".to_string());

let mut rng: StdRng = SeedableRng::from_seed([0; 32]);
let private_key = Ed25519PrivateKey::generate(&mut rng);
let public_key: Ed25519PublicKey = (&private_key).into();
let signature = private_key.sign(&message);
assert!(signature.verify(&message, &public_key).is_ok());

Note: The above example generates a private key using a private function intended only for testing purposes. Production code should find an alternate means for secure key generation.

Structs

Ed25519PrivateKey

An Ed25519 private key

Ed25519PublicKey

An Ed25519 public key

Ed25519Signature

An Ed25519 signature

Constants

ED25519_PRIVATE_KEY_LENGTH

The length of the Ed25519PrivateKey

ED25519_PUBLIC_KEY_LENGTH

The length of the Ed25519PublicKey

ED25519_SIGNATURE_LENGTH

The length of the Ed25519Signature

Functions

keypair_strategy

Produces a uniformly random ed25519 keypair from a seed