mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-23 03:59:22 +00:00
Document the transcript library
This commit is contained in:
parent
c5f75568cd
commit
f8760ae021
2 changed files with 16 additions and 0 deletions
|
@ -6,6 +6,9 @@ Flexible Transcript is a crate offering:
|
||||||
provided hash function.
|
provided hash function.
|
||||||
- `MerlinTranscript`, a wrapper of `merlin` into the trait (available via the
|
- `MerlinTranscript`, a wrapper of `merlin` into the trait (available via the
|
||||||
`merlin` feature).
|
`merlin` feature).
|
||||||
|
- `RecommendedTranscript`, a transcript recommended for usage in applications.
|
||||||
|
Currently, this is `DigestTranscript<Blake2b512>` (available via the
|
||||||
|
`recommended` feature).
|
||||||
|
|
||||||
The trait was created while working on an IETF draft which defined an incredibly
|
The trait was created while working on an IETF draft which defined an incredibly
|
||||||
simple transcript format. Extensions of the protocol would quickly require a
|
simple transcript format. Extensions of the protocol would quickly require a
|
||||||
|
|
|
@ -10,9 +10,19 @@ use digest::{typenum::type_operators::IsGreaterOrEqual, consts::U256, Digest, Ou
|
||||||
pub trait Transcript {
|
pub trait Transcript {
|
||||||
type Challenge: Clone + Send + Sync + AsRef<[u8]>;
|
type Challenge: Clone + Send + Sync + AsRef<[u8]>;
|
||||||
|
|
||||||
|
/// Apply a domain separator to the transcript
|
||||||
fn domain_separate(&mut self, label: &'static [u8]);
|
fn domain_separate(&mut self, label: &'static [u8]);
|
||||||
|
|
||||||
|
/// Append a message to the transcript
|
||||||
fn append_message(&mut self, label: &'static [u8], message: &[u8]);
|
fn append_message(&mut self, label: &'static [u8], message: &[u8]);
|
||||||
|
|
||||||
|
/// Produce a challenge. This MUST update the transcript as it does so, preventing the same
|
||||||
|
/// challenge from being generated multiple times
|
||||||
fn challenge(&mut self, label: &'static [u8]) -> Self::Challenge;
|
fn challenge(&mut self, label: &'static [u8]) -> Self::Challenge;
|
||||||
|
|
||||||
|
/// Produce a RNG seed. Helper function for parties needing to generate random data from an
|
||||||
|
/// agreed upon state. Internally calls the challenge function for the needed bytes, converting
|
||||||
|
/// them to the seed format rand_core expects
|
||||||
fn rng_seed(&mut self, label: &'static [u8]) -> [u8; 32];
|
fn rng_seed(&mut self, label: &'static [u8]) -> [u8; 32];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +46,12 @@ impl DigestTranscriptMember {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A trait defining Digests with at least a 256-byte output size, assuming at least a 128-bit
|
||||||
|
/// level of security accordingly
|
||||||
pub trait SecureDigest: Clone + Digest {}
|
pub trait SecureDigest: Clone + Digest {}
|
||||||
impl<D: Clone + Digest> SecureDigest for D where D::OutputSize: IsGreaterOrEqual<U256> {}
|
impl<D: Clone + Digest> SecureDigest for D where D::OutputSize: IsGreaterOrEqual<U256> {}
|
||||||
|
|
||||||
|
/// A simple transcript format constructed around the specified hash algorithm
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct DigestTranscript<D: SecureDigest>(D);
|
pub struct DigestTranscript<D: SecureDigest>(D);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue