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 9, 2022
1 parent ba5979a commit fe76f90
Show file tree
Hide file tree
Showing 5 changed files with 810 additions and 78 deletions.
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ chacha20poly1305 = "0.10"
criterion = "0.4"
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 @@ -80,3 +84,9 @@ targets = []
[[example]]
name = "simple_login"
required-features = ["argon2"]

[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" }
voprf = { git = "https://github.com/khonsulabs/voprf", branch = "p384" }
5 changes: 3 additions & 2 deletions src/key_exchange/group/elliptic_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
G: GroupDigest,
FieldSize<Self>: ModulusSize,
AffinePoint<Self>: FromEncodedPoint<Self> + ToEncodedPoint<Self>,
ProjectivePoint<Self>: CofactorGroup + ToEncodedPoint<Self>,
ProjectivePoint<Self>: CofactorGroup,
Scalar<Self>: FromOkm,
{
type Pk = ProjectivePoint<Self>;
Expand All @@ -37,7 +37,8 @@ where
type SkLen = FieldSize<Self>;

fn serialize_pk(pk: Self::Pk) -> GenericArray<u8, Self::PkLen> {
GenericArray::clone_from_slice(pk.to_encoded_point(true).as_bytes())
let affine: AffinePoint<Self> = pk.into();
GenericArray::clone_from_slice(affine.to_encoded_point(true).as_bytes())
}

fn deserialize_pk(bytes: &[u8]) -> Result<Self::Pk, InternalError> {
Expand Down
2 changes: 2 additions & 0 deletions src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ mod tests {
#[cfg(feature = "ristretto255")]
inner::<crate::Ristretto255>();
inner::<::p256::NistP256>();
inner::<::p384::NistP384>();
}

macro_rules! test {
Expand Down Expand Up @@ -277,6 +278,7 @@ mod tests {
#[cfg(feature = "ristretto255")]
test!(ristretto, crate::Ristretto255);
test!(p256, ::p256::NistP256);
test!(p384, ::p384::NistP384);

#[test]
fn remote_key() {
Expand Down
22 changes: 22 additions & 0 deletions src/serialization/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ impl CipherSuite for P256 {
type Ksf = crate::ksf::Identity;
}

struct P384;

impl CipherSuite for P384 {
type OprfCs = ::p384::NistP384;
type KeGroup = ::p384::NistP384;
type KeyExchange = TripleDh;
type Ksf = crate::ksf::Identity;
}

fn random_point<CS: CipherSuite>() -> <CS::KeGroup as KeGroup>::Pk
where
<OprfHash<CS> as OutputSizeUser>::OutputSize:
Expand Down Expand Up @@ -104,6 +113,7 @@ fn client_registration_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -157,6 +167,7 @@ fn server_registration_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -199,6 +210,7 @@ fn registration_request_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -250,6 +262,7 @@ fn registration_response_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -311,6 +324,7 @@ fn registration_upload_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -368,6 +382,7 @@ fn credential_request_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -456,6 +471,7 @@ fn credential_response_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -487,6 +503,7 @@ fn credential_finalization_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -554,6 +571,7 @@ fn client_login_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -593,6 +611,7 @@ fn ke1_message_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -636,6 +655,7 @@ fn ke2_message_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -670,6 +690,7 @@ fn ke3_message_roundtrip() -> Result<(), ProtocolError> {
#[cfg(feature = "ristretto255")]
inner::<Ristretto255>()?;
inner::<P256>()?;
inner::<P384>()?;

Ok(())
}
Expand Down Expand Up @@ -760,3 +781,4 @@ macro_rules! test {
#[cfg(feature = "ristretto255")]
test!(ristretto255, Ristretto255);
test!(p256, P256);
test!(p384, P384);
Loading

0 comments on commit fe76f90

Please sign in to comment.