Implement oprf_key test

This commit is contained in:
dAxpeDDa
2021-07-30 14:45:27 -07:00
committed by Kevin Lewi
parent a5b9330b63
commit db4e07811e
3 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -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,
+14
View File
@@ -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),
})
}
+10
View File
@@ -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(&parameters.registration_request[..]).unwrap(),
&parameters.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(&parameters.server_mac_key),
hex::encode(server_login_start_result.server_mac_key)
);
assert_eq!(
hex::encode(&parameters.oprf_key),
hex::encode(server_login_start_result.oprf_key)
);
assert_eq!(
hex::encode(&parameters.KE2),
hex::encode(server_login_start_result.message.serialize())