[][src]Module solana_libra_nextgen_crypto::bls12381

This module implements the Verifying/Signing API for signatures on the BLS12-381 curve.

Example

use crypto::hash::{CryptoHasher, TestOnlyHasher};
use nextgen_crypto::{
    bls12381::*,
    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 = BLS12381PrivateKey::generate_for_testing(&mut rng);
let public_key: BLS12381PublicKey = (&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.

This module is not currently used, but could be included in the future for improved performance in consensus.

Structs

BLS12381PrivateKey

A BLS12-381 private key

BLS12381PublicKey

A BLS12-381 public key

BLS12381Signature

A BLS12-381 signature