Fixing some clippy errors and CI
This commit is contained in:
@@ -72,6 +72,20 @@ jobs:
|
||||
- uses: hecrj/setup-rust-action@v1
|
||||
- run: cargo test --verbose --features slow-hash --no-default-features --features ${{ matrix.backend_feature }}
|
||||
|
||||
serde-test:
|
||||
name: Test on ${{ matrix.target }} with serde support
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
backend_feature:
|
||||
- u64_backend
|
||||
- u32_backend
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: hecrj/setup-rust-action@v1
|
||||
- run: cargo test --verbose --features serialize --no-default-features --features ${{ matrix.backend_feature }}
|
||||
|
||||
|
||||
simple-login-test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
+4
-4
@@ -179,7 +179,7 @@ impl<D: Hash> Envelope<D> {
|
||||
optional_ids: Option<(Vec<u8>, Vec<u8>)>,
|
||||
) -> Result<(Self, GenericArray<u8, <D as Digest>::OutputSize>), InternalPakeError> {
|
||||
let aad = construct_aad(server_s_pk, &optional_ids);
|
||||
Self::seal_raw(rng, key, &client_s_sk, &aad, mode_from_ids(&optional_ids))
|
||||
Self::seal_raw(rng, key, client_s_sk, &aad, mode_from_ids(&optional_ids))
|
||||
}
|
||||
|
||||
/// Uses a key to convert the plaintext into an envelope, authenticated by the aad field.
|
||||
@@ -194,7 +194,7 @@ impl<D: Hash> Envelope<D> {
|
||||
let mut nonce = vec![0u8; NONCE_LEN];
|
||||
rng.fill_bytes(&mut nonce);
|
||||
|
||||
let h = Hkdf::<D>::new(Some(&nonce), &key);
|
||||
let h = Hkdf::<D>::new(Some(&nonce), key);
|
||||
let mut xor_key = vec![0u8; plaintext.len()];
|
||||
let mut hmac_key = vec![0u8; Self::hmac_key_size()];
|
||||
let mut export_key = vec![0u8; Self::export_key_size()];
|
||||
@@ -221,7 +221,7 @@ impl<D: Hash> Envelope<D> {
|
||||
let mut hmac =
|
||||
Hmac::<D>::new_varkey(&hmac_key).map_err(|_| InternalPakeError::HmacError)?;
|
||||
hmac.update(&inner_envelope.serialize());
|
||||
hmac.update(&aad);
|
||||
hmac.update(aad);
|
||||
|
||||
let hmac_bytes = hmac.finalize().into_bytes();
|
||||
|
||||
@@ -266,7 +266,7 @@ impl<D: Hash> Envelope<D> {
|
||||
key: &[u8],
|
||||
aad: &[u8],
|
||||
) -> Result<OpenedInnerEnvelope<D>, InternalPakeError> {
|
||||
let h = Hkdf::<D>::new(Some(&self.inner_envelope.nonce), &key);
|
||||
let h = Hkdf::<D>::new(Some(&self.inner_envelope.nonce), key);
|
||||
let mut xor_key = vec![0u8; self.inner_envelope.ciphertext.len()];
|
||||
let mut hmac_key = vec![0u8; Self::hmac_key_size()];
|
||||
let mut export_key = vec![0u8; Self::export_key_size()];
|
||||
|
||||
@@ -313,7 +313,7 @@ impl TryFrom<&[u8]> for Ke1Message {
|
||||
Ok(Self {
|
||||
client_nonce: GenericArray::clone_from_slice(&checked_nonce[..nonce_len]),
|
||||
info,
|
||||
client_e_pk: Key::from_bytes(&checked_client_e_pk)?,
|
||||
client_e_pk: Key::from_bytes(checked_client_e_pk)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -419,7 +419,7 @@ impl<HashLen: ArrayLength<u8>> TryFrom<&[u8]> for Ke2Message<HashLen> {
|
||||
server_nonce: GenericArray::clone_from_slice(&checked_nonce[..nonce_len]),
|
||||
server_e_pk: Key::from_bytes(&checked_server_e_pk[..KEY_LEN])?,
|
||||
e_info,
|
||||
mac: GenericArray::clone_from_slice(&checked_mac),
|
||||
mac: GenericArray::clone_from_slice(checked_mac),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -459,10 +459,10 @@ impl<HashLen: ArrayLength<u8>> TryFrom<&[u8]> for Ke3Message<HashLen> {
|
||||
type Error = PakeError;
|
||||
|
||||
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
|
||||
let checked_bytes = check_slice_size(&bytes, HashLen::to_usize(), "ke3_message")?;
|
||||
let checked_bytes = check_slice_size(bytes, HashLen::to_usize(), "ke3_message")?;
|
||||
|
||||
Ok(Self {
|
||||
mac: GenericArray::clone_from_slice(&checked_bytes),
|
||||
mac: GenericArray::clone_from_slice(checked_bytes),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -485,30 +485,30 @@ fn derive_3dh_keys<D: Hash, G: Group>(
|
||||
let extracted_ikm = Hkdf::<D>::new(None, &ikm);
|
||||
let handshake_secret = derive_secrets::<D>(
|
||||
&extracted_ikm,
|
||||
&STR_HANDSHAKE_SECRET,
|
||||
&hashed_derivation_transcript,
|
||||
STR_HANDSHAKE_SECRET,
|
||||
hashed_derivation_transcript,
|
||||
)?;
|
||||
let session_key = derive_secrets::<D>(
|
||||
&extracted_ikm,
|
||||
&STR_SESSION_SECRET,
|
||||
&hashed_derivation_transcript,
|
||||
STR_SESSION_SECRET,
|
||||
hashed_derivation_transcript,
|
||||
)?;
|
||||
|
||||
let km2 = hkdf_expand_label::<D>(
|
||||
&handshake_secret,
|
||||
&STR_SERVER_MAC,
|
||||
STR_SERVER_MAC,
|
||||
b"",
|
||||
<D as Digest>::OutputSize::to_usize(),
|
||||
)?;
|
||||
let ke2 = hkdf_expand_label::<D>(
|
||||
&handshake_secret,
|
||||
&STR_HANDSHAKE_ENC,
|
||||
STR_HANDSHAKE_ENC,
|
||||
b"",
|
||||
<D as Digest>::OutputSize::to_usize(),
|
||||
)?;
|
||||
let km3 = hkdf_expand_label::<D>(
|
||||
&handshake_secret,
|
||||
&STR_CLIENT_MAC,
|
||||
STR_CLIENT_MAC,
|
||||
b"",
|
||||
<D as Digest>::OutputSize::to_usize(),
|
||||
)?;
|
||||
@@ -543,11 +543,11 @@ fn hkdf_expand_label_extracted<D: Hash>(
|
||||
hkdf_label.extend_from_slice(&length.to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
|
||||
|
||||
let mut opaque_label: Vec<u8> = Vec::new();
|
||||
opaque_label.extend_from_slice(&STR_OPAQUE);
|
||||
opaque_label.extend_from_slice(&label);
|
||||
opaque_label.extend_from_slice(STR_OPAQUE);
|
||||
opaque_label.extend_from_slice(label);
|
||||
hkdf_label.extend_from_slice(&serialize(&opaque_label, 1));
|
||||
|
||||
hkdf_label.extend_from_slice(&serialize(&context, 1));
|
||||
hkdf_label.extend_from_slice(&serialize(context, 1));
|
||||
|
||||
hkdf.expand(&hkdf_label, &mut okm)
|
||||
.map_err(|_| InternalPakeError::HkdfError)?;
|
||||
@@ -562,7 +562,7 @@ fn derive_secrets<D: Hash>(
|
||||
hkdf_expand_label_extracted::<D>(
|
||||
hkdf,
|
||||
label,
|
||||
&hashed_derivation_transcript,
|
||||
hashed_derivation_transcript,
|
||||
<D as Digest>::OutputSize::to_usize(),
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -81,7 +81,7 @@ impl<G: Group> KeyPair<G> {
|
||||
pub(crate) fn generate_random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
|
||||
let sk = G::random_scalar(rng);
|
||||
let sk_bytes = G::scalar_as_bytes(&sk);
|
||||
let pk = G::base_point().mult_by_slice(&sk_bytes);
|
||||
let pk = G::base_point().mult_by_slice(sk_bytes);
|
||||
Self {
|
||||
pk: Key(pk.to_arr().to_vec()),
|
||||
sk: Key(sk_bytes.to_vec()),
|
||||
@@ -93,7 +93,7 @@ impl<G: Group> KeyPair<G> {
|
||||
/// &public_from_private(self.private()) == self.public()
|
||||
pub(crate) fn public_from_private(bytes: &Key) -> Key {
|
||||
let bytes_data = GenericArray::<u8, G::ScalarLen>::from_slice(&bytes.0[..]);
|
||||
Key(G::base_point().mult_by_slice(&bytes_data).to_arr().to_vec())
|
||||
Key(G::base_point().mult_by_slice(bytes_data).to_arr().to_vec())
|
||||
}
|
||||
|
||||
/// Check whether a public key is valid. This is meant to be applied on
|
||||
@@ -107,14 +107,14 @@ impl<G: Group> KeyPair<G> {
|
||||
/// Computes the diffie hellman function on a public key and private key
|
||||
pub(crate) fn diffie_hellman(pk: Key, sk: Key) -> Result<Vec<u8>, InternalPakeError> {
|
||||
let pk_data = GenericArray::<u8, G::ElemLen>::from_slice(&pk.0[..]);
|
||||
let point = G::from_element_slice(&pk_data)?;
|
||||
let point = G::from_element_slice(pk_data)?;
|
||||
let secret_data = GenericArray::<u8, G::ScalarLen>::from_slice(&sk.0[..]);
|
||||
Ok(G::mult_by_slice(&point, &secret_data).to_arr().to_vec())
|
||||
Ok(G::mult_by_slice(&point, secret_data).to_arr().to_vec())
|
||||
}
|
||||
|
||||
/// Obtains a KeyPair from a slice representing the private key
|
||||
pub fn from_private_key_slice(input: &[u8]) -> Result<Self, InternalPakeError> {
|
||||
let sk = Key::from_arr(GenericArray::from_slice(&input))?;
|
||||
let sk = Key::from_arr(GenericArray::from_slice(input))?;
|
||||
let pk = Self::public_from_private(&sk);
|
||||
Self::new(pk, sk)
|
||||
}
|
||||
|
||||
+5
-6
@@ -39,7 +39,7 @@ impl<CS: CipherSuite> RegistrationRequest<CS> {
|
||||
/// Deserialization from bytes
|
||||
pub fn deserialize(input: &[u8]) -> Result<Self, ProtocolError> {
|
||||
let elem_len = <CS::Group as Group>::ElemLen::to_usize();
|
||||
let checked_slice = check_slice_size(&input, elem_len, "first_message_bytes")?;
|
||||
let checked_slice = check_slice_size(input, elem_len, "first_message_bytes")?;
|
||||
// Check that the message is actually containing an element of the
|
||||
// correct subgroup
|
||||
let arr = GenericArray::from_slice(checked_slice);
|
||||
@@ -70,7 +70,7 @@ impl<CS: CipherSuite> RegistrationResponse<CS> {
|
||||
let elem_len = <CS::Group as Group>::ElemLen::to_usize();
|
||||
let key_len = <Key as SizedBytes>::Len::to_usize();
|
||||
let checked_slice =
|
||||
check_slice_size(&input, elem_len + key_len, "registration_response_bytes")?;
|
||||
check_slice_size(input, elem_len + key_len, "registration_response_bytes")?;
|
||||
|
||||
// Check that the message is actually containing an element of the
|
||||
// correct subgroup
|
||||
@@ -110,7 +110,7 @@ impl<CS: CipherSuite> RegistrationUpload<CS> {
|
||||
pub fn deserialize(input: &[u8]) -> Result<Self, ProtocolError> {
|
||||
let key_len = <Key as SizedBytes>::Len::to_usize();
|
||||
|
||||
let checked_slice = check_slice_size_atleast(&input, key_len, "registration_upload_bytes")?;
|
||||
let checked_slice = check_slice_size_atleast(input, key_len, "registration_upload_bytes")?;
|
||||
|
||||
let (envelope, remainder) = Envelope::<CS::Hash>::deserialize(&checked_slice[key_len..])?;
|
||||
|
||||
@@ -149,8 +149,7 @@ impl<CS: CipherSuite> CredentialRequest<CS> {
|
||||
pub fn deserialize(input: &[u8]) -> Result<Self, ProtocolError> {
|
||||
let elem_len = <CS::Group as Group>::ElemLen::to_usize();
|
||||
|
||||
let checked_slice =
|
||||
check_slice_size_atleast(&input, elem_len, "login_first_message_bytes")?;
|
||||
let checked_slice = check_slice_size_atleast(input, elem_len, "login_first_message_bytes")?;
|
||||
|
||||
// Check that the message is actually containing an element of the
|
||||
// correct subgroup
|
||||
@@ -226,7 +225,7 @@ impl<CS: CipherSuite> CredentialResponse<CS> {
|
||||
check_slice_size_atleast(&remainder, ke2_message_size, "login_second_message_bytes")?;
|
||||
let ke2_message =
|
||||
<CS::KeyExchange as KeyExchange<CS::Hash, CS::Group>>::KE2Message::try_from(
|
||||
&checked_remainder,
|
||||
checked_remainder,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
+4
-4
@@ -136,7 +136,7 @@ impl<CS: CipherSuite> ClientRegistration<CS> {
|
||||
blinding_factor_rng: &mut R,
|
||||
password: &[u8],
|
||||
) -> Result<ClientRegistrationStartResult<CS>, ProtocolError> {
|
||||
let (token, alpha) = oprf::blind::<R, CS::Group, CS::Hash>(&password, blinding_factor_rng)?;
|
||||
let (token, alpha) = oprf::blind::<R, CS::Group, CS::Hash>(password, blinding_factor_rng)?;
|
||||
|
||||
Ok(ClientRegistrationStartResult {
|
||||
message: RegistrationRequest::<CS> { alpha },
|
||||
@@ -266,7 +266,7 @@ impl<CS: CipherSuite> ServerRegistration<CS> {
|
||||
let key_len = <Key as SizedBytes>::Len::to_usize();
|
||||
|
||||
let checked_bytes =
|
||||
check_slice_size_atleast(&input, scalar_len + key_len, "server_registration_bytes")?;
|
||||
check_slice_size_atleast(input, scalar_len + key_len, "server_registration_bytes")?;
|
||||
|
||||
let oprf_key_bytes = GenericArray::from_slice(&checked_bytes[..scalar_len]);
|
||||
let oprf_key = CS::Group::from_scalar_slice(oprf_key_bytes)?;
|
||||
@@ -543,7 +543,7 @@ impl<CS: CipherSuite> ClientLogin<CS> {
|
||||
) -> Result<ClientLoginStartResult<CS>, ProtocolError> {
|
||||
let ClientLoginStartParameters::WithInfo(info) = params;
|
||||
|
||||
let (token, alpha) = oprf::blind::<R, CS::Group, CS::Hash>(&password, rng)?;
|
||||
let (token, alpha) = oprf::blind::<R, CS::Group, CS::Hash>(password, rng)?;
|
||||
|
||||
let (ke1_state, ke1_message) = CS::KeyExchange::generate_ke1(info, rng)?;
|
||||
|
||||
@@ -789,7 +789,7 @@ impl<CS: CipherSuite> ServerLogin<CS> {
|
||||
|
||||
let l1_bytes = &l1.serialize();
|
||||
let beta = oprf::evaluate(l1.alpha, &password_file.oprf_key);
|
||||
let server_s_pk = KeyPair::<CS::Group>::public_from_private(&server_s_sk);
|
||||
let server_s_pk = KeyPair::<CS::Group>::public_from_private(server_s_sk);
|
||||
|
||||
let credential_response_component =
|
||||
CredentialResponse::<CS>::serialize_without_ke(&beta, &server_s_pk, &envelope);
|
||||
|
||||
@@ -54,7 +54,6 @@ pub(crate) fn tokenize(input: &[u8], size_bytes: usize) -> Result<(Vec<u8>, Vec<
|
||||
}
|
||||
|
||||
/// Inner macro used for deriving `serde`'s `Serialize` and `Deserialize` traits.
|
||||
#[cfg(feature = "serialize")]
|
||||
#[macro_export]
|
||||
macro_rules! impl_serialize_and_deserialize_for {
|
||||
($t:ident) => {
|
||||
|
||||
Reference in New Issue
Block a user