Implement oprf_key test
This commit is contained in:
+1
-1
@@ -509,7 +509,7 @@ mod tests {
|
||||
message,
|
||||
state: client,
|
||||
} = ClientRegistration::<Default>::start(&mut OsRng, PASSWORD.as_bytes())?;
|
||||
let ServerRegistrationStartResult { message } =
|
||||
let ServerRegistrationStartResult { message, .. } =
|
||||
ServerRegistration::start(&server_setup, message, &[])?;
|
||||
let ClientRegistrationFinishResult { message, .. } = client.finish(
|
||||
&mut OsRng,
|
||||
|
||||
@@ -357,6 +357,9 @@ impl<CS: CipherSuite> ClientRegistration<CS> {
|
||||
pub struct ServerRegistrationStartResult<CS: CipherSuite> {
|
||||
/// The registration resposne message to send to the client
|
||||
pub message: RegistrationResponse<CS>,
|
||||
/// OPRF key, only used in tests
|
||||
#[cfg(test)]
|
||||
pub oprf_key: GenericArray<u8, <CS::Group as Group>::ScalarLen>,
|
||||
}
|
||||
|
||||
// Cannot be derived because it would require for CS to be Clone.
|
||||
@@ -364,6 +367,8 @@ impl<CS: CipherSuite> Clone for ServerRegistrationStartResult<CS> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
message: self.message.clone(),
|
||||
#[cfg(test)]
|
||||
oprf_key: self.oprf_key.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,6 +422,8 @@ impl<CS: CipherSuite> ServerRegistration<CS> {
|
||||
beta,
|
||||
server_s_pk: server_setup.keypair.public().clone(),
|
||||
},
|
||||
#[cfg(test)]
|
||||
oprf_key: CS::Group::scalar_as_bytes(oprf_key),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -758,6 +765,9 @@ pub struct ServerLoginStartResult<CS: CipherSuite> {
|
||||
/// Server MAC key, only used in tests
|
||||
#[cfg(test)]
|
||||
pub server_mac_key: GenericArray<u8, <CS::Hash as Digest>::OutputSize>,
|
||||
/// OPRF key, only used in tests
|
||||
#[cfg(test)]
|
||||
pub oprf_key: GenericArray<u8, <CS::Group as Group>::ScalarLen>,
|
||||
}
|
||||
|
||||
// Cannot be derived because it would require for CS to be Clone.
|
||||
@@ -770,6 +780,8 @@ impl<CS: CipherSuite> Clone for ServerLoginStartResult<CS> {
|
||||
handshake_secret: self.handshake_secret.clone(),
|
||||
#[cfg(test)]
|
||||
server_mac_key: self.server_mac_key.clone(),
|
||||
#[cfg(test)]
|
||||
oprf_key: self.oprf_key.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -899,6 +911,8 @@ impl<CS: CipherSuite> ServerLogin<CS> {
|
||||
handshake_secret: result.2,
|
||||
#[cfg(test)]
|
||||
server_mac_key: result.3,
|
||||
#[cfg(test)]
|
||||
oprf_key: CS::Group::scalar_as_bytes(oprf_key),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ pub struct TestVectorParameters {
|
||||
pub handshake_secret: Vec<u8>,
|
||||
pub server_mac_key: Vec<u8>,
|
||||
pub client_mac_key: Vec<u8>,
|
||||
pub oprf_key: Vec<u8>,
|
||||
}
|
||||
|
||||
// Pulled from "OPAQUE-3DH Test Vector 1" and "OPAQUE-3DH Test Vector 6"
|
||||
@@ -492,6 +493,7 @@ fn populate_test_vectors(values: &Value) -> TestVectorParameters {
|
||||
handshake_secret: parse!(values, "handshake_secret"),
|
||||
server_mac_key: parse!(values, "server_mac_key"),
|
||||
client_mac_key: parse!(values, "client_mac_key"),
|
||||
oprf_key: parse!(values, "oprf_key"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,6 +551,10 @@ fn test_registration_response() -> Result<(), ProtocolError> {
|
||||
RegistrationRequest::deserialize(¶meters.registration_request[..]).unwrap(),
|
||||
¶meters.credential_identifier,
|
||||
)?;
|
||||
assert_eq!(
|
||||
hex::encode(parameters.oprf_key),
|
||||
hex::encode(server_registration_start_result.oprf_key)
|
||||
);
|
||||
assert_eq!(
|
||||
hex::encode(parameters.registration_response),
|
||||
hex::encode(server_registration_start_result.message.serialize())
|
||||
@@ -667,6 +673,10 @@ fn test_ke2() -> Result<(), ProtocolError> {
|
||||
hex::encode(¶meters.server_mac_key),
|
||||
hex::encode(server_login_start_result.server_mac_key)
|
||||
);
|
||||
assert_eq!(
|
||||
hex::encode(¶meters.oprf_key),
|
||||
hex::encode(server_login_start_result.oprf_key)
|
||||
);
|
||||
assert_eq!(
|
||||
hex::encode(¶meters.KE2),
|
||||
hex::encode(server_login_start_result.message.serialize())
|
||||
|
||||
Reference in New Issue
Block a user