Adding identity element checks and ensuring non-zero scalar selection
This commit is contained in:
@@ -28,6 +28,14 @@ pub struct RegistrationRequest<CS: CipherSuite> {
|
||||
pub(crate) alpha: CS::Group,
|
||||
}
|
||||
|
||||
impl<CS: CipherSuite> RegistrationRequest<CS> {
|
||||
/// Only used for testing purposes
|
||||
#[cfg(test)]
|
||||
pub fn get_alpha_for_testing(&self) -> CS::Group {
|
||||
self.alpha
|
||||
}
|
||||
}
|
||||
|
||||
// Cannot be derived because it would require for CS to be Clone.
|
||||
impl<CS: CipherSuite> Clone for RegistrationRequest<CS> {
|
||||
fn clone(&self) -> Self {
|
||||
@@ -49,6 +57,11 @@ impl<CS: CipherSuite> RegistrationRequest<CS> {
|
||||
// correct subgroup
|
||||
let arr = GenericArray::from_slice(checked_slice);
|
||||
let alpha = CS::Group::from_element_slice(arr)?;
|
||||
|
||||
// Throw an error if the identity group element is encountered
|
||||
if alpha.is_identity() {
|
||||
return Err(PakeError::IdentityGroupElementError.into());
|
||||
}
|
||||
Ok(Self { alpha })
|
||||
}
|
||||
}
|
||||
@@ -91,6 +104,13 @@ impl<CS: CipherSuite> RegistrationResponse<CS> {
|
||||
// correct subgroup
|
||||
let arr = GenericArray::from_slice(&checked_slice[..elem_len]);
|
||||
let beta = CS::Group::from_element_slice(arr)?;
|
||||
|
||||
// Throw an error if the identity group element is encountered
|
||||
if beta.is_identity() {
|
||||
return Err(PakeError::IdentityGroupElementError.into());
|
||||
}
|
||||
|
||||
// Ensure that public key is valid
|
||||
let server_s_pk = KeyPair::<CS::Group>::check_public_key(PublicKey::from_bytes(
|
||||
&checked_slice[elem_len..],
|
||||
)?)?;
|
||||
@@ -188,6 +208,11 @@ impl<CS: CipherSuite> CredentialRequest<CS> {
|
||||
let arr = GenericArray::from_slice(&checked_slice[..elem_len]);
|
||||
let alpha = CS::Group::from_element_slice(arr)?;
|
||||
|
||||
// Throw an error if the identity group element is encountered
|
||||
if alpha.is_identity() {
|
||||
return Err(PakeError::IdentityGroupElementError.into());
|
||||
}
|
||||
|
||||
let ke1_message =
|
||||
<CS::KeyExchange as KeyExchange<CS::Hash, CS::Group>>::KE1Message::from_bytes::<CS>(
|
||||
&checked_slice[elem_len..],
|
||||
@@ -258,6 +283,11 @@ impl<CS: CipherSuite> CredentialResponse<CS> {
|
||||
let arr = GenericArray::from_slice(beta_bytes);
|
||||
let beta = CS::Group::from_element_slice(arr)?;
|
||||
|
||||
// Throw an error if the identity group element is encountered
|
||||
if beta.is_identity() {
|
||||
return Err(PakeError::IdentityGroupElementError.into());
|
||||
}
|
||||
|
||||
let unchecked_server_s_pk =
|
||||
PublicKey::from_bytes(&checked_slice[elem_len..elem_len + key_len])?;
|
||||
let server_s_pk = KeyPair::<CS::Group>::check_public_key(unchecked_server_s_pk)?;
|
||||
|
||||
Reference in New Issue
Block a user