Constraint Scalar with Copy
This commit is contained in:
+4
-4
@@ -38,8 +38,8 @@ fn build_inner_envelope_internal<CS: CipherSuite>(
|
||||
h.expand(&[nonce, STR_PRIVATE_KEY].concat(), &mut keypair_seed)
|
||||
.map_err(|_| InternalPakeError::HkdfError)?;
|
||||
let client_static_keypair =
|
||||
KeyPair::<CS::Group>::from_private_key_slice(CS::Group::scalar_as_bytes(
|
||||
&CS::Group::hash_to_scalar::<CS::Hash>(&keypair_seed[..], STR_OPAQUE_HASH_TO_SCALAR)?,
|
||||
KeyPair::<CS::Group>::from_private_key_slice(&CS::Group::scalar_as_bytes(
|
||||
CS::Group::hash_to_scalar::<CS::Hash>(&keypair_seed[..], STR_OPAQUE_HASH_TO_SCALAR)?,
|
||||
))?;
|
||||
|
||||
Ok(client_static_keypair.public().clone())
|
||||
@@ -54,8 +54,8 @@ fn recover_keys_internal<CS: CipherSuite>(
|
||||
h.expand(&[nonce, STR_PRIVATE_KEY].concat(), &mut keypair_seed)
|
||||
.map_err(|_| InternalPakeError::HkdfError)?;
|
||||
let client_static_keypair =
|
||||
KeyPair::<CS::Group>::from_private_key_slice(CS::Group::scalar_as_bytes(
|
||||
&CS::Group::hash_to_scalar::<CS::Hash>(&keypair_seed[..], STR_OPAQUE_HASH_TO_SCALAR)?,
|
||||
KeyPair::<CS::Group>::from_private_key_slice(&CS::Group::scalar_as_bytes(
|
||||
CS::Group::hash_to_scalar::<CS::Hash>(&keypair_seed[..], STR_OPAQUE_HASH_TO_SCALAR)?,
|
||||
))?;
|
||||
|
||||
Ok(client_static_keypair)
|
||||
|
||||
+4
-4
@@ -28,7 +28,7 @@ use zeroize::Zeroize;
|
||||
/// subgroup is noted additively — as in the draft RFC — in this trait.
|
||||
pub trait Group: Copy + Sized + for<'a> Mul<&'a <Self as Group>::Scalar, Output = Self> {
|
||||
/// The type of base field scalars
|
||||
type Scalar: Zeroize + Clone;
|
||||
type Scalar: Zeroize + Copy;
|
||||
/// The byte length necessary to represent scalars
|
||||
type ScalarLen: ArrayLength<u8> + 'static;
|
||||
/// Return a scalar from its fixed-length bytes representation
|
||||
@@ -38,7 +38,7 @@ pub trait Group: Copy + Sized + for<'a> Mul<&'a <Self as Group>::Scalar, Output
|
||||
/// picks a scalar at random
|
||||
fn random_nonzero_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar;
|
||||
/// Serializes a scalar to bytes
|
||||
fn scalar_as_bytes(scalar: &Self::Scalar) -> &GenericArray<u8, Self::ScalarLen>;
|
||||
fn scalar_as_bytes(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen>;
|
||||
/// The multiplicative inverse of this scalar
|
||||
fn scalar_invert(scalar: &Self::Scalar) -> Self::Scalar;
|
||||
|
||||
@@ -105,8 +105,8 @@ impl Group for RistrettoPoint {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn scalar_as_bytes(scalar: &Self::Scalar) -> &GenericArray<u8, Self::ScalarLen> {
|
||||
GenericArray::from_slice(scalar.as_bytes())
|
||||
fn scalar_as_bytes(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen> {
|
||||
scalar.to_bytes().into()
|
||||
}
|
||||
fn scalar_invert(scalar: &Self::Scalar) -> Self::Scalar {
|
||||
scalar.invert()
|
||||
|
||||
+2
-2
@@ -78,8 +78,8 @@ impl<G: Group> KeyPair<G> {
|
||||
/// Generating a random key pair given a cryptographic rng
|
||||
pub(crate) fn generate_random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
|
||||
let sk = G::random_nonzero_scalar(rng);
|
||||
let sk_bytes = G::scalar_as_bytes(&sk);
|
||||
let pk = G::base_point().mult_by_slice(sk_bytes);
|
||||
let sk_bytes = G::scalar_as_bytes(sk);
|
||||
let pk = G::base_point().mult_by_slice(&sk_bytes);
|
||||
Self {
|
||||
pk: PublicKey::new(Key(pk.to_arr().to_vec())),
|
||||
sk: PrivateKey::new(Key(sk_bytes.to_vec())),
|
||||
|
||||
+2
-2
@@ -115,7 +115,7 @@ impl<CS: CipherSuite> ClientRegistration<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
[
|
||||
&CS::Group::scalar_as_bytes(&self.token.blind)[..],
|
||||
&CS::Group::scalar_as_bytes(self.token.blind)[..],
|
||||
&self.token.data,
|
||||
]
|
||||
.concat()
|
||||
@@ -415,7 +415,7 @@ impl<CS: CipherSuite> ClientLogin<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
let output: Vec<u8> = [
|
||||
&CS::Group::scalar_as_bytes(&self.token.blind)[..],
|
||||
&CS::Group::scalar_as_bytes(self.token.blind)[..],
|
||||
&serialize(&self.serialized_credential_request, 2),
|
||||
&serialize(&self.ke1_state.to_bytes(), 2),
|
||||
&self.token.data,
|
||||
|
||||
@@ -307,13 +307,13 @@ fn generate_parameters<CS: CipherSuite>() -> TestVectorParameters {
|
||||
.unwrap();
|
||||
|
||||
let blinding_factor = CS::Group::random_nonzero_scalar(&mut rng);
|
||||
let blinding_factor_bytes = CS::Group::scalar_as_bytes(&blinding_factor).clone();
|
||||
let blinding_factor_bytes = CS::Group::scalar_as_bytes(blinding_factor).clone();
|
||||
|
||||
let mut blinding_factor_registration_rng = CycleRng::new(blinding_factor_bytes.to_vec());
|
||||
let client_registration_start_result =
|
||||
ClientRegistration::<CS>::start(&mut blinding_factor_registration_rng, password).unwrap();
|
||||
let blinding_factor_bytes_returned =
|
||||
CS::Group::scalar_as_bytes(&client_registration_start_result.state.token.blind).clone();
|
||||
CS::Group::scalar_as_bytes(client_registration_start_result.state.token.blind).clone();
|
||||
assert_eq!(
|
||||
hex::encode(&blinding_factor_bytes),
|
||||
hex::encode(&blinding_factor_bytes_returned)
|
||||
|
||||
@@ -73,7 +73,7 @@ fn test_blind() -> Result<(), PakeError> {
|
||||
|
||||
assert_eq!(
|
||||
¶meters.blind,
|
||||
&RistrettoPoint::scalar_as_bytes(&token.blind).to_vec()
|
||||
&RistrettoPoint::scalar_as_bytes(token.blind).to_vec()
|
||||
);
|
||||
assert_eq!(
|
||||
¶meters.blinded_element,
|
||||
|
||||
Reference in New Issue
Block a user