[][src]Module solana_libra_nextgen_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 crypto::hash::{CryptoHasher, TestOnlyHasher};
use nextgen_crypto::{
    ed25519::*,
    traits::{Signature, SigningKey, Uniform},
};
use rand::{rngs::StdRng, SeedableRng};

let mut hasher = TestOnlyHasher::default();
hasher.write("Test message".as_bytes());
let hashed_message = hasher.finish();

let mut rng: StdRng = SeedableRng::from_seed([0; 32]);
let private_key = Ed25519PrivateKey::generate_for_testing(&mut rng);
let public_key: Ed25519PublicKey = (&private_key).into();
let signature = private_key.sign_message(&hashed_message);
assert!(signature.verify(&hashed_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.

Modules

compat

Those transitory traits are meant to help with the progressive migration of the code base to the nextgen_crypto module and will disappear after

Structs

Ed25519PrivateKey

An Ed25519 private key

Ed25519PublicKey

An Ed25519 public key

Ed25519Signature

An Ed25519 signature