Rename Group::to_bytes() into Group::to_arr(),
This brings the `Group` and `SizedBytes` traits into some sort of name coherence (they both return a GenericArray). This also uses `&my_generic_array[..]` (i.e. the `Deref` impl) over `my_generic_array.as_slice()`.
This commit is contained in:
+3
-3
@@ -46,7 +46,7 @@ pub trait Group: Sized + for<'a> Mul<&'a <Self as Group>::Scalar, Output = Self>
|
||||
element_bits: &GenericArray<u8, Self::ElemLen>,
|
||||
) -> Result<Self, InternalPakeError>;
|
||||
/// Serializes the `self` group element
|
||||
fn to_bytes(&self) -> GenericArray<u8, Self::ElemLen>;
|
||||
fn to_arr(&self) -> GenericArray<u8, Self::ElemLen>;
|
||||
|
||||
/// 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<u8, Self::ElemLen> {
|
||||
fn to_arr(&self) -> GenericArray<u8, Self::ElemLen> {
|
||||
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<u8, Self::ElemLen> {
|
||||
fn to_arr(&self) -> GenericArray<u8, Self::ElemLen> {
|
||||
let c = self.compress();
|
||||
*GenericArray::from_slice(c.as_bytes())
|
||||
}
|
||||
|
||||
+11
-20
@@ -46,7 +46,7 @@ impl<Grp: Group> TryFrom<&[u8]> for RegisterFirstMessage<Grp> {
|
||||
|
||||
impl<Grp: Group> RegisterFirstMessage<Grp> {
|
||||
pub fn to_bytes(&self) -> GenericArray<u8, Grp::ElemLen> {
|
||||
self.alpha.to_bytes()
|
||||
self.alpha.to_arr()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ where
|
||||
Grp: Group,
|
||||
{
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
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<u8> {
|
||||
[
|
||||
&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<Grp: Group> TryFrom<&[u8]> for LoginFirstMessage<Grp> {
|
||||
|
||||
impl<Grp: Group> LoginFirstMessage<Grp> {
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
[
|
||||
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<u8> {
|
||||
[
|
||||
&self.beta.to_bytes()[..],
|
||||
&self.beta.to_arr()[..],
|
||||
&self.envelope.to_bytes()[..],
|
||||
&self.ke2_message.to_bytes()[..],
|
||||
]
|
||||
@@ -275,7 +267,7 @@ impl<CS: CipherSuite> TryFrom<&[u8]> for ClientRegistration<CS> {
|
||||
impl<CS: CipherSuite> ClientRegistration<CS> {
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
let output: Vec<u8> = [
|
||||
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<Self, Self::Error> {
|
||||
let key_len =
|
||||
<<CS::KeyFormat as KeyPair>::Repr as SizedBytes>::Len::to_usize();
|
||||
let key_len = <<CS::KeyFormat as KeyPair>::Repr as SizedBytes>::Len::to_usize();
|
||||
let scalar_len = <CS::Group as Group>::ScalarLen::to_usize();
|
||||
let envelope_size = key_len + Envelope::additional_size();
|
||||
|
||||
@@ -620,7 +611,7 @@ impl<CS: CipherSuite> TryFrom<&[u8]> for ClientLogin<CS> {
|
||||
impl<CS: CipherSuite> ClientLogin<CS> {
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
let output: Vec<u8> = [
|
||||
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<CS: CipherSuite> ClientLogin<CS> {
|
||||
} = oprf::generate_oprf1::<R, CS::Group>(&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<CS: CipherSuite> ClientLogin<CS> {
|
||||
server_s_pk: &<CS::KeyFormat as KeyPair>::Repr,
|
||||
_client_e_sk_rng: &mut R,
|
||||
) -> Result<ClientLoginFinishResult, ProtocolError> {
|
||||
let l2_bytes: Vec<u8> = [l2.beta.to_bytes().as_slice(), &l2.envelope.to_bytes()].concat();
|
||||
let l2_bytes: Vec<u8> = [&l2.beta.to_arr()[..], &l2.envelope.to_bytes()].concat();
|
||||
|
||||
let password_derived_key = get_password_derived_key::<CS::Group, CS::SlowHash>(
|
||||
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<u8> = [beta.to_bytes().as_slice(), &envelope.to_bytes()].concat();
|
||||
let l2_component: Vec<u8> = [&beta.to_arr()[..], &envelope.to_bytes()].concat();
|
||||
|
||||
let (ke2_state, ke2_message) = generate_ke2::<_, CS::KeyFormat>(
|
||||
rng,
|
||||
|
||||
+3
-3
@@ -50,7 +50,7 @@ pub(crate) fn generate_oprf3<G: Group>(
|
||||
blinding_factor: &G::Scalar,
|
||||
) -> Result<GenericArray<u8, <Sha256 as Digest>::OutputSize>, InternalPakeError> {
|
||||
let unblinded = point * &G::scalar_invert(&blinding_factor);
|
||||
let ikm: Vec<u8> = [&unblinded.to_bytes(), input].concat();
|
||||
let ikm: Vec<u8> = [&unblinded.to_arr()[..], input].concat();
|
||||
let (prk, _) = Hkdf::<Sha256>::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<u8> = [res.to_bytes().as_slice(), &input].concat();
|
||||
let ikm: Vec<u8> = [&res.to_arr()[..], &input].concat();
|
||||
|
||||
let (prk, _) = Hkdf::<Sha256>::extract(None, &ikm);
|
||||
prk
|
||||
@@ -126,7 +126,7 @@ mod tests {
|
||||
|
||||
let point = RistrettoPoint::from_uniform_bytes(&bits);
|
||||
let mut ikm: Vec<u8> = Vec::new();
|
||||
ikm.extend_from_slice(&point.to_bytes());
|
||||
ikm.extend_from_slice(&point.to_arr());
|
||||
ikm.extend_from_slice(&input);
|
||||
let (prk, _) = Hkdf::<Sha256>::extract(None, &ikm);
|
||||
|
||||
|
||||
@@ -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::<RistrettoPoint>::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::<RistrettoPoint>::try_from(&message[..]).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user