Adding serialization and docs (#6)

This commit is contained in:
Kevin Lewi
2021-09-15 17:49:31 -07:00
committed by GitHub
parent 671d1180a2
commit fa2d8ec191
8 changed files with 1120 additions and 907 deletions
+2 -24
View File
@@ -5,33 +5,11 @@
//! Defines the CipherSuite trait to specify the underlying primitives for VOPRF
use crate::{errors::InternalError, group::Group, hash::Hash};
static STR_VOPRF: &[u8] = b"VOPRF07-";
pub enum Mode {
Base = 0,
Verifiable = 1,
}
/// Configures the underlying primitives used in VOPRF
pub trait CipherSuite {
/// A finite cyclic group along with a point representation that allows some
/// customization on how to hash an input to a curve point. See `group::Group`.
type Group: Group;
type Group: crate::group::Group;
/// The main hash function to use (for HKDF computations and hashing transcripts).
type Hash: Hash;
/// Generates the contextString parameter as defined in
/// <https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-07.html>
fn get_context_string(mode: Mode) -> Result<alloc::vec::Vec<u8>, InternalError> {
use crate::serialization::i2osp;
Ok([
STR_VOPRF,
&i2osp(mode as usize, 1)?,
&i2osp(Self::Group::SUITE_ID, 2)?,
]
.concat())
}
type Hash: crate::hash::Hash;
}