diff --git a/src/group.rs b/src/group.rs index 18be92f..44547d2 100644 --- a/src/group.rs +++ b/src/group.rs @@ -46,7 +46,7 @@ pub trait Group: Sized + for<'a> Mul<&'a ::Scalar, Output = Self> element_bits: &GenericArray, ) -> Result; /// Serializes the `self` group element - fn to_bytes(&self) -> GenericArray; + fn to_arr(&self) -> GenericArray; /// Hashes points presumed to be uniformly random to the curve. The /// impl is allowed to perform additional hashes if it needs to, but this @@ -87,7 +87,7 @@ impl Group for RistrettoPoint { .ok_or_else(|| InternalPakeError::PointError) } // serialization of a group element - fn to_bytes(&self) -> GenericArray { + fn to_arr(&self) -> GenericArray { let c = self.compress(); *GenericArray::from_slice(c.as_bytes()) } @@ -135,7 +135,7 @@ impl Group for EdwardsPoint { .ok_or_else(|| InternalPakeError::PointError) } // serialization of a group element - fn to_bytes(&self) -> GenericArray { + fn to_arr(&self) -> GenericArray { let c = self.compress(); *GenericArray::from_slice(c.as_bytes()) } diff --git a/src/opaque.rs b/src/opaque.rs index 2fe0a33..5b306cc 100644 --- a/src/opaque.rs +++ b/src/opaque.rs @@ -46,7 +46,7 @@ impl TryFrom<&[u8]> for RegisterFirstMessage { impl RegisterFirstMessage { pub fn to_bytes(&self) -> GenericArray { - self.alpha.to_bytes() + self.alpha.to_arr() } } @@ -82,7 +82,7 @@ where Grp: Group, { pub fn to_bytes(&self) -> Vec { - self.beta.to_bytes().to_vec() + self.beta.to_arr().to_vec() } } @@ -101,11 +101,7 @@ where KeyFormat: KeyPair, { pub fn to_bytes(&self) -> Vec { - [ - &self.envelope.to_bytes(), - self.client_s_pk.to_arr().as_slice(), - ] - .concat() + [&self.envelope.to_bytes(), &self.client_s_pk.to_arr()[..]].concat() } } @@ -156,11 +152,7 @@ impl TryFrom<&[u8]> for LoginFirstMessage { impl LoginFirstMessage { pub fn to_bytes(&self) -> Vec { - [ - self.alpha.to_bytes().as_slice(), - &self.ke1_message.to_bytes(), - ] - .concat() + [&self.alpha.to_arr()[..], &self.ke1_message.to_bytes()].concat() } } @@ -182,7 +174,7 @@ where { pub fn to_bytes(&self) -> Vec { [ - &self.beta.to_bytes()[..], + &self.beta.to_arr()[..], &self.envelope.to_bytes()[..], &self.ke2_message.to_bytes()[..], ] @@ -275,7 +267,7 @@ impl TryFrom<&[u8]> for ClientRegistration { impl ClientRegistration { pub fn to_bytes(&self) -> Vec { let output: Vec = [ - CS::Group::scalar_as_bytes(&self.blinding_factor).as_slice(), + &CS::Group::scalar_as_bytes(&self.blinding_factor)[..], &self.password, ] .concat(); @@ -439,8 +431,7 @@ where { type Error = ProtocolError; fn try_from(server_registration_bytes: &[u8]) -> Result { - let key_len = - <::Repr as SizedBytes>::Len::to_usize(); + let key_len = <::Repr as SizedBytes>::Len::to_usize(); let scalar_len = ::ScalarLen::to_usize(); let envelope_size = key_len + Envelope::additional_size(); @@ -620,7 +611,7 @@ impl TryFrom<&[u8]> for ClientLogin { impl ClientLogin { pub fn to_bytes(&self) -> Vec { let output: Vec = [ - CS::Group::scalar_as_bytes(&self.blinding_factor).as_slice(), + &CS::Group::scalar_as_bytes(&self.blinding_factor)[..], &self.ke1_state.to_bytes(), &self.password, ] @@ -665,7 +656,7 @@ impl ClientLogin { } = oprf::generate_oprf1::(&password, pepper, rng)?; let (ke1_state, ke1_message) = - generate_ke1::<_, CS::KeyFormat>(alpha.to_bytes().to_vec(), rng)?; + generate_ke1::<_, CS::KeyFormat>(alpha.to_arr().to_vec(), rng)?; let l1 = LoginFirstMessage { alpha, ke1_message }; @@ -719,7 +710,7 @@ impl ClientLogin { server_s_pk: &::Repr, _client_e_sk_rng: &mut R, ) -> Result { - let l2_bytes: Vec = [l2.beta.to_bytes().as_slice(), &l2.envelope.to_bytes()].concat(); + let l2_bytes: Vec = [&l2.beta.to_arr()[..], &l2.envelope.to_bytes()].concat(); let password_derived_key = get_password_derived_key::( self.password.clone(), @@ -822,7 +813,7 @@ impl ServerLogin { .ok_or(InternalPakeError::SealError)?; let envelope = password_file.envelope.ok_or(InternalPakeError::SealError)?; - let l2_component: Vec = [beta.to_bytes().as_slice(), &envelope.to_bytes()].concat(); + let l2_component: Vec = [&beta.to_arr()[..], &envelope.to_bytes()].concat(); let (ke2_state, ke2_message) = generate_ke2::<_, CS::KeyFormat>( rng, diff --git a/src/oprf.rs b/src/oprf.rs index 6e5be4b..98c066d 100644 --- a/src/oprf.rs +++ b/src/oprf.rs @@ -50,7 +50,7 @@ pub(crate) fn generate_oprf3( blinding_factor: &G::Scalar, ) -> Result::OutputSize>, InternalPakeError> { let unblinded = point * &G::scalar_invert(&blinding_factor); - let ikm: Vec = [&unblinded.to_bytes(), input].concat(); + let ikm: Vec = [&unblinded.to_arr()[..], input].concat(); let (prk, _) = Hkdf::::extract(None, &ikm); Ok(prk) } @@ -77,7 +77,7 @@ mod tests { let scalar = RistrettoPoint::from_scalar_slice(GenericArray::from_slice(&oprf_key[..])).unwrap(); let res = point * scalar; - let ikm: Vec = [res.to_bytes().as_slice(), &input].concat(); + let ikm: Vec = [&res.to_arr()[..], &input].concat(); let (prk, _) = Hkdf::::extract(None, &ikm); prk @@ -126,7 +126,7 @@ mod tests { let point = RistrettoPoint::from_uniform_bytes(&bits); let mut ikm: Vec = Vec::new(); - ikm.extend_from_slice(&point.to_bytes()); + ikm.extend_from_slice(&point.to_arr()); ikm.extend_from_slice(&input); let (prk, _) = Hkdf::::extract(None, &ikm); diff --git a/src/tests/serialization.rs b/src/tests/serialization.rs index 7e51d22..0a755fe 100644 --- a/src/tests/serialization.rs +++ b/src/tests/serialization.rs @@ -85,7 +85,7 @@ fn server_registration_roundtrip() { #[test] fn register_first_message_roundtrip() { let pt = random_ristretto_point(); - let pt_bytes = pt.to_bytes(); + let pt_bytes = pt.to_arr(); let r1 = RegisterFirstMessage::::try_from(pt_bytes.as_slice()).unwrap(); let r1_bytes = r1.to_bytes(); assert_eq!(pt_bytes, r1_bytes); @@ -94,7 +94,7 @@ fn register_first_message_roundtrip() { #[test] fn register_second_message_roundtrip() { let pt = random_ristretto_point(); - let pt_bytes = pt.to_bytes(); + let pt_bytes = pt.to_arr(); let message = pt_bytes.to_vec(); let r2 = RegisterSecondMessage::::try_from(&message[..]).unwrap();