Matching to latest test vectors with metadata mode (#3)

This commit is contained in:
Kevin Lewi
2021-09-13 16:02:09 -07:00
committed by GitHub
parent fe3222d148
commit 485d18deec
10 changed files with 1317 additions and 141 deletions
+21 -1
View File
@@ -5,7 +5,14 @@
//! Defines the CipherSuite trait to specify the underlying primitives for VOPRF
use crate::{group::Group, hash::Hash};
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 {
@@ -14,4 +21,17 @@ pub trait CipherSuite {
type 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())
}
}