pub struct Timelock<'a, S>where
S: Scheme,{ /* private fields */ }Expand description
Encrypts and decrypts messages for one drand chain.
Construct the chain info with an independently pinned chain hash. A verified beacon from that chain is required for decryption.
Implementations§
Source§impl<'a, S> Timelock<'a, S>where
S: Scheme,
impl<'a, S> Timelock<'a, S>where
S: Scheme,
Sourcepub const fn new(chain_info: &'a ChainInfo<S>) -> Timelock<'a, S>
pub const fn new(chain_info: &'a ChainInfo<S>) -> Timelock<'a, S>
Creates a timelock using chain_info.
This does not check a pinned chain hash. Use
ChainInfo::new_pinned when obtaining chain info from a relay.
Sourcepub const fn chain_info(&self) -> &ChainInfo<S>
pub const fn chain_info(&self) -> &ChainInfo<S>
Returns the chain info used by this timelock.
Source§impl Timelock<'_, PedersenBlsUnchained>
impl Timelock<'_, PedersenBlsUnchained>
Sourcepub fn encrypt<const N: usize>(
&self,
rng: &mut impl CryptoRng,
round: Round,
msg: &[u8; N],
) -> Result<Ciphertext<G1Projective, N>, Error>
pub fn encrypt<const N: usize>( &self, rng: &mut impl CryptoRng, round: Round, msg: &[u8; N], ) -> Result<Ciphertext<G1Projective, N>, Error>
Encrypts msg for round using fresh randomness from rng.
N must be between 16 and 32, inclusive; other lengths fail to compile.
§Errors
Returns Error::InvalidPublicKey if the chain’s public key is invalid.
§Panics
Panics if the RNG panics or scalar rejection sampling is exhausted.
Sourcepub fn decrypt<const N: usize>(
&self,
ciphertext: &Ciphertext<G1Projective, N>,
beacon: &VerifiedBeacon<PedersenBlsUnchained>,
) -> Result<Zeroizing<[u8; N]>, Error>
pub fn decrypt<const N: usize>( &self, ciphertext: &Ciphertext<G1Projective, N>, beacon: &VerifiedBeacon<PedersenBlsUnchained>, ) -> Result<Zeroizing<[u8; N]>, Error>
Decrypts ciphertext using the target round’s verified beacon.
N must be between 16 and 32, inclusive; other lengths fail to compile.
The returned plaintext is cleared on drop.
§Errors
Returns an error if the round or chain differs, the beacon signature is malformed, or the ciphertext fails its integrity check.
§Panics
Panics if scalar rejection sampling is exhausted.
Source§impl Timelock<'_, BlsUnchainedOnG1>
impl Timelock<'_, BlsUnchainedOnG1>
Sourcepub fn encrypt<const N: usize>(
&self,
rng: &mut impl CryptoRng,
round: Round,
msg: &[u8; N],
) -> Result<Ciphertext<G2Projective, N>, Error>
pub fn encrypt<const N: usize>( &self, rng: &mut impl CryptoRng, round: Round, msg: &[u8; N], ) -> Result<Ciphertext<G2Projective, N>, Error>
Encrypts msg for round using fresh randomness from rng.
This legacy scheme uses drand’s non-RFC-9380 domain separation tag.
N must be between 16 and 32, inclusive; other lengths fail to compile.
§Errors
Returns Error::InvalidPublicKey if the chain’s public key is invalid.
§Panics
Panics if the RNG panics or scalar rejection sampling is exhausted.
Sourcepub fn decrypt<const N: usize>(
&self,
ciphertext: &Ciphertext<G2Projective, N>,
beacon: &VerifiedBeacon<BlsUnchainedOnG1>,
) -> Result<Zeroizing<[u8; N]>, Error>
pub fn decrypt<const N: usize>( &self, ciphertext: &Ciphertext<G2Projective, N>, beacon: &VerifiedBeacon<BlsUnchainedOnG1>, ) -> Result<Zeroizing<[u8; N]>, Error>
Decrypts ciphertext using the target round’s verified beacon.
N must be between 16 and 32, inclusive; other lengths fail to compile.
The returned plaintext is cleared on drop.
§Errors
Returns an error if the round or chain differs, the beacon signature is malformed, or the ciphertext fails its integrity check.
§Panics
Panics if scalar rejection sampling is exhausted.
Source§impl Timelock<'_, BlsUnchainedG1Rfc9380>
impl Timelock<'_, BlsUnchainedG1Rfc9380>
Sourcepub fn encrypt<const N: usize>(
&self,
rng: &mut impl CryptoRng,
round: Round,
msg: &[u8; N],
) -> Result<Ciphertext<G2Projective, N>, Error>
pub fn encrypt<const N: usize>( &self, rng: &mut impl CryptoRng, round: Round, msg: &[u8; N], ) -> Result<Ciphertext<G2Projective, N>, Error>
Encrypts msg for round using fresh randomness from rng.
N must be between 16 and 32, inclusive; other lengths fail to compile.
§Errors
Returns Error::InvalidPublicKey if the chain’s public key is invalid.
§Panics
Panics if the RNG panics or scalar rejection sampling is exhausted.
Sourcepub fn decrypt<const N: usize>(
&self,
ciphertext: &Ciphertext<G2Projective, N>,
beacon: &VerifiedBeacon<BlsUnchainedG1Rfc9380>,
) -> Result<Zeroizing<[u8; N]>, Error>
pub fn decrypt<const N: usize>( &self, ciphertext: &Ciphertext<G2Projective, N>, beacon: &VerifiedBeacon<BlsUnchainedG1Rfc9380>, ) -> Result<Zeroizing<[u8; N]>, Error>
Decrypts ciphertext using the target round’s verified beacon.
N must be between 16 and 32, inclusive; other lengths fail to compile.
The returned plaintext is cleared on drop.
§Errors
Returns an error if the round or chain differs, the beacon signature is malformed, or the ciphertext fails its integrity check.
§Panics
Panics if scalar rejection sampling is exhausted.