1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
//! # Verifiable Random Function
//!
//! This crate defines a trait that must be implemented by VRFs.
//!
use openssl::{
rsa::Rsa,
pkey::{Public, Private}
};
pub mod vrf;
/// A trait containing the common capabilities for VRF implementations
///
pub trait VRF {
type Error;
/// Generates proof from a private key and a message
///
/// # Arguments:
///
/// * `pkey`: a private key
/// * `alpha_string`: octet string message represented by a slice
///
/// # Returns:
///
/// * if successful, a vector of octets representing the VRF proof
///
fn prove(&mut self, pkey: &Rsa<Private>, alpha_string: &[u8]) -> Result<Vec<u8>, Self::Error>;
/// Generates VRF hash output from the provided proof
///
/// # Arguments:
///
/// * `pi_string`: generated VRF proof
///
/// # Returns:
///
/// * the VRF hash output
///
fn proof_to_hash(&mut self, pi_string: &[u8]) -> Result<Vec<u8>, Self::Error>;
/// Verifies the provided VRF proof and computes the VRF hash output
///
/// # Arguments:
///
/// * `public_key`: a public key
/// * `alpha_string`: VRF hash input, an octet string
/// * `pi_string`: proof to be verified, an octet string
///
/// # Returns:
///
/// * if successful, a vector of octets with the VRF hash output
///
fn verify(&mut self, public_key: &Rsa<Public>, alpha_string: &[u8], pi_string: &[u8]) -> Result<Vec<u8>, Self::Error>;
}
pub mod ecvrf;
/// A trait containing common capabilities for ECVRF implementations
///
pub trait ECVRF<PrivateKey, PublicKey> {
type Error;
/// Generates proof from a private key and a message
///
/// # Arguments:
///
/// * `pkey`: a private key
/// * `alpha_string`: octet string message represented by a slice
///
/// # Returns:
///
/// * if successful, a vector of octets representing the VRF proof
///
fn prove(&mut self, pkey: PrivateKey, alpha_string: &[u8]) -> Result<Vec<u8>, Self::Error>;
/// Generates VRF hash output from the provided proof
///
/// # Arguments:
///
/// * `pi_string`: generated VRF proof
///
/// # Returns:
///
/// * the VRF hash output
///
fn proof_to_hash(&mut self, pi_string: &[u8]) -> Result<Vec<u8>, Self::Error>;
/// Verifies the provided VRF proof and computes the VRF hash output
///
/// # Arguments:
///
/// * `public_key`: a public key
/// * `alpha_string`: VRF hash input, an octet string
/// * `pi_string`: proof to be verified, an octet string
///
/// # Returns:
///
/// * if successful, a vector of octets with the VRF hash output
///
fn verify(&mut self, public_key: PublicKey, alpha_string: &[u8], pi_string: &[u8]) -> Result<Vec<u8>, Self::Error>;
}