Skip to content

Commit

Permalink
Test P-384
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 7, 2022
1 parent 2dc6a8b commit 8c413b6
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ zeroize = { version = "1.5", default-features = false }
generic-array = { version = "0.14", features = ["more_lengths"] }
hex = "0.4"
json = "0.12"
p256 = { version = "0.11", default-features = false, features = [
p256 = { version = "0.12.0-pre.0", default-features = false, features = [
"hash2curve",
"voprf",
] }
p384 = { version = "0.12.0-pre.0", default-features = false, features = [
"hash2curve",
"voprf",
] }
Expand All @@ -60,3 +64,8 @@ sha2 = "0.10"
[package.metadata.docs.rs]
features = ["danger", "std"]
targets = []

[patch.crates-io]
elliptic-curve = { git = "https://github.com/RustCrypto/traits", rev = "d28eb2408070b247ebc0fd243a39dedf52b594d4" }
p256 = { git = "https://github.com/khonsulabs/elliptic-curves", branch = "p384-hash-to-curve" }
p384 = { git = "https://github.com/khonsulabs/elliptic-curves", branch = "p384-hash-to-curve" }
5 changes: 3 additions & 2 deletions src/group/elliptic_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{Error, InternalError, Result};
impl<C> Group for C
where
C: GroupDigest,
ProjectivePoint<Self>: CofactorGroup + ToEncodedPoint<Self>,
ProjectivePoint<Self>: CofactorGroup,
FieldSize<Self>: ModulusSize,
AffinePoint<Self>: FromEncodedPoint<Self> + ToEncodedPoint<Self>,
Scalar<Self>: FromOkm,
Expand Down Expand Up @@ -65,7 +65,8 @@ where
}

fn serialize_elem(elem: Self::Elem) -> GenericArray<u8, Self::ElemLen> {
let bytes = elem.to_encoded_point(true);
let affine: AffinePoint<Self> = elem.into();
let bytes = affine.to_encoded_point(true);
let bytes = bytes.as_bytes();
let mut result = GenericArray::default();
result[..bytes.len()].copy_from_slice(bytes);
Expand Down
4 changes: 4 additions & 0 deletions src/group/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{Error, Group, Result};
#[test]
fn test_group_properties() -> Result<()> {
use p256::NistP256;
use p384::NistP384;

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

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

Ok(())
}

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

#[cfg(feature = "ristretto255")]
{
Expand All @@ -447,6 +448,13 @@ mod tests {
zeroize_oprf_client::<NistP256>();
zeroize_oprf_server::<NistP256>();

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

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

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

#[cfg(feature = "ristretto255")]
{
Expand All @@ -990,6 +991,13 @@ mod tests {
zeroize_verifiable_client::<NistP256>();
zeroize_verifiable_server::<NistP256>();

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

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

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

let _ = $item::<p256::NistP256>::deserialize(&$bytes[..]);
let _ = $item::<p384::NistP384>::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 @@ -85,6 +85,7 @@ macro_rules! json_to_test_vectors {
#[test]
fn test_vectors() -> Result<()> {
use p256::NistP256;
use p384::NistP384;

let rfc = json::parse(rfc_to_json(super::cfrg_vectors::VECTORS).as_str())
.expect("Could not parse json");
Expand Down Expand Up @@ -157,6 +158,33 @@ fn test_vectors() -> Result<()> {
test_poprf_finalize::<NistP256>(&p256_poprf_tvs)?;
test_poprf_evaluate::<NistP256>(&p256_poprf_tvs)?;

let p384_oprf_tvs =
json_to_test_vectors!(rfc, String::from("P-384, SHA-384"), String::from("OPRF"));
assert_ne!(p384_oprf_tvs.len(), 0);
test_oprf_seed_to_key::<NistP384>(&p384_oprf_tvs)?;
test_oprf_blind::<NistP384>(&p384_oprf_tvs)?;
test_oprf_blind_evaluate::<NistP384>(&p384_oprf_tvs)?;
test_oprf_finalize::<NistP384>(&p384_oprf_tvs)?;
test_oprf_evaluate::<NistP384>(&p384_oprf_tvs)?;

let p384_voprf_tvs =
json_to_test_vectors!(rfc, String::from("P-384, SHA-384"), String::from("VOPRF"));
assert_ne!(p384_voprf_tvs.len(), 0);
test_voprf_seed_to_key::<NistP384>(&p384_voprf_tvs)?;
test_voprf_blind::<NistP384>(&p384_voprf_tvs)?;
test_voprf_blind_evaluate::<NistP384>(&p384_voprf_tvs)?;
test_voprf_finalize::<NistP384>(&p384_voprf_tvs)?;
test_voprf_evaluate::<NistP384>(&p384_voprf_tvs)?;

let p384_poprf_tvs =
json_to_test_vectors!(rfc, String::from("P-384, SHA-384"), String::from("POPRF"));
assert_ne!(p384_poprf_tvs.len(), 0);
test_poprf_seed_to_key::<NistP384>(&p384_poprf_tvs)?;
test_poprf_blind::<NistP384>(&p384_poprf_tvs)?;
test_poprf_blind_evaluate::<NistP384>(&p384_poprf_tvs)?;
test_poprf_finalize::<NistP384>(&p384_poprf_tvs)?;
test_poprf_evaluate::<NistP384>(&p384_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 @@ -837,6 +837,7 @@ mod tests {
#[test]
fn test_functionality() -> Result<()> {
use p256::NistP256;
use p384::NistP384;

#[cfg(feature = "ristretto255")]
{
Expand All @@ -861,6 +862,15 @@ mod tests {
zeroize_voprf_client::<NistP256>();
zeroize_voprf_server::<NistP256>();

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

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

Ok(())
}
}

0 comments on commit 8c413b6

Please sign in to comment.