Skip to content

Commit

Permalink
Test P-521 (facebook#127)
Browse files Browse the repository at this point in the history
(cherry picked from commit 68cc7d3)
  • Loading branch information
daxpedda authored and cyyynthia committed Sep 22, 2024
1 parent 88d9366 commit 834fe58
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ p384 = { version = "0.13", default-features = false, features = [
"hash2curve",
"voprf",
] }
p521 = { version = "0.13.3", default-features = false, features = [
"hash2curve",
"voprf",
] }
proptest = "1"
rand = "0.8"
regex = "1"
Expand Down
4 changes: 4 additions & 0 deletions src/group/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{Error, Group, Result};
fn test_group_properties() -> Result<()> {
use p256::NistP256;
use p384::NistP384;
use p521::NistP521;

#[cfg(feature = "ristretto255")]
{
Expand All @@ -32,6 +33,9 @@ fn test_group_properties() -> Result<()> {
test_identity_element_error::<NistP384>()?;
test_zero_scalar_error::<NistP384>()?;

test_identity_element_error::<NistP521>()?;
test_zero_scalar_error::<NistP521>()?;

Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions src/oprf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ mod tests {
fn test_functionality() -> Result<()> {
use p256::NistP256;
use p384::NistP384;
use p521::NistP521;

#[cfg(feature = "ristretto255")]
{
Expand Down Expand Up @@ -456,6 +457,13 @@ mod tests {
zeroize_oprf_client::<NistP384>();
zeroize_oprf_server::<NistP384>();

base_retrieval::<NistP521>();
base_inversion_unsalted::<NistP521>();
server_evaluate::<NistP521>();

zeroize_oprf_client::<NistP521>();
zeroize_oprf_server::<NistP521>();

Ok(())
}
}
8 changes: 8 additions & 0 deletions src/poprf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ mod tests {
fn test_functionality() -> Result<()> {
use p256::NistP256;
use p384::NistP384;
use p521::NistP521;

#[cfg(feature = "ristretto255")]
{
Expand Down Expand Up @@ -999,6 +1000,13 @@ mod tests {
zeroize_verifiable_client::<NistP384>();
zeroize_verifiable_server::<NistP384>();

verifiable_retrieval::<NistP521>();
verifiable_bad_public_key::<NistP521>();
verifiable_server_evaluate::<NistP521>();

zeroize_verifiable_client::<NistP521>();
zeroize_verifiable_server::<NistP521>();

Ok(())
}
}
1 change: 1 addition & 0 deletions src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ mod test {

let _ = $item::<p256::NistP256>::deserialize(&$bytes[..]);
let _ = $item::<p384::NistP384>::deserialize(&$bytes[..]);
let _ = $item::<p521::NistP521>::deserialize(&$bytes[..]);
};
}

Expand Down
28 changes: 28 additions & 0 deletions src/tests/test_cfrg_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ macro_rules! json_to_test_vectors {
fn test_vectors() -> Result<()> {
use p256::NistP256;
use p384::NistP384;
use p521::NistP521;

let rfc: Value = serde_json::from_str(rfc_to_json(super::cfrg_vectors::VECTORS).as_str())
.expect("Could not parse json");
Expand Down Expand Up @@ -188,6 +189,33 @@ fn test_vectors() -> Result<()> {
test_poprf_finalize::<NistP384>(&p384_poprf_tvs)?;
test_poprf_evaluate::<NistP384>(&p384_poprf_tvs)?;

let p521_oprf_tvs =
json_to_test_vectors!(rfc, String::from("P521-SHA512"), String::from("OPRF"));
assert_ne!(p521_oprf_tvs.len(), 0);
test_oprf_seed_to_key::<NistP521>(&p521_oprf_tvs)?;
test_oprf_blind::<NistP521>(&p521_oprf_tvs)?;
test_oprf_blind_evaluate::<NistP521>(&p521_oprf_tvs)?;
test_oprf_finalize::<NistP521>(&p521_oprf_tvs)?;
test_oprf_evaluate::<NistP521>(&p521_oprf_tvs)?;

let p521_voprf_tvs =
json_to_test_vectors!(rfc, String::from("P521-SHA512"), String::from("VOPRF"));
assert_ne!(p521_voprf_tvs.len(), 0);
test_voprf_seed_to_key::<NistP521>(&p521_voprf_tvs)?;
test_voprf_blind::<NistP521>(&p521_voprf_tvs)?;
test_voprf_blind_evaluate::<NistP521>(&p521_voprf_tvs)?;
test_voprf_finalize::<NistP521>(&p521_voprf_tvs)?;
test_voprf_evaluate::<NistP521>(&p521_voprf_tvs)?;

let p521_poprf_tvs =
json_to_test_vectors!(rfc, String::from("P521-SHA512"), String::from("POPRF"));
assert_ne!(p521_poprf_tvs.len(), 0);
test_poprf_seed_to_key::<NistP521>(&p521_poprf_tvs)?;
test_poprf_blind::<NistP521>(&p521_poprf_tvs)?;
test_poprf_blind_evaluate::<NistP521>(&p521_poprf_tvs)?;
test_poprf_finalize::<NistP521>(&p521_poprf_tvs)?;
test_poprf_evaluate::<NistP521>(&p521_poprf_tvs)?;

Ok(())
}

Expand Down
10 changes: 10 additions & 0 deletions src/voprf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ mod tests {
fn test_functionality() -> Result<()> {
use p256::NistP256;
use p384::NistP384;
use p521::NistP521;

#[cfg(feature = "ristretto255")]
{
Expand Down Expand Up @@ -872,6 +873,15 @@ mod tests {
zeroize_voprf_client::<NistP384>();
zeroize_voprf_server::<NistP384>();

verifiable_retrieval::<NistP521>();
verifiable_batch_retrieval::<NistP521>();
verifiable_bad_public_key::<NistP521>();
verifiable_batch_bad_public_key::<NistP521>();
verifiable_server_evaluate::<NistP521>();

zeroize_voprf_client::<NistP521>();
zeroize_voprf_server::<NistP521>();

Ok(())
}
}

0 comments on commit 834fe58

Please sign in to comment.