Correct platform size bug

This commit is contained in:
François Garillot
2020-11-12 10:42:45 -05:00
parent eb1a93c379
commit 05514e49aa
3 changed files with 27 additions and 14 deletions
+1 -1
View File
@@ -468,7 +468,7 @@ fn hkdf_expand_label_extracted<D: Hash>(
let mut okm = vec![0u8; length];
let mut hkdf_label: Vec<u8> = Vec::new();
hkdf_label.extend_from_slice(&length.to_be_bytes()[6..]);
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);
+11 -2
View File
@@ -82,7 +82,8 @@ impl<T: CipherSuite> From<&LoginThirdMessage<T>> for ProtocolMessageType {
pub(crate) fn serialize(input: &[u8], max_bytes: usize) -> Vec<u8> {
let mut output: Vec<u8> = Vec::new();
output.extend_from_slice(&input.len().to_be_bytes()[8 - max_bytes..]);
output
.extend_from_slice(&input.len().to_be_bytes()[std::mem::size_of::<usize>() - max_bytes..]);
output.extend_from_slice(&input[..]);
output
}
@@ -96,7 +97,15 @@ pub(crate) fn tokenize(input: Vec<u8>, size_bytes: usize) -> Result<(Vec<u8>, Ve
for i in 0..size_bytes {
size_array[8 - size_bytes + i] = input[i];
}
let size = usize::from_be_bytes(size_array);
let big_size = u64::from_be_bytes(size_array);
// TODO:: check RFC compliance in refusing this
if big_size >= u32::MAX as u64 {
return Err(PakeError::SerializationError);
}
let size = big_size as usize;
if size_bytes + size > input.len() {
return Err(PakeError::SerializationError);
+15 -11
View File
@@ -118,8 +118,8 @@ fn register_first_message_roundtrip() {
let mut input = Vec::new();
input.extend_from_slice(&[ProtocolMessageType::RegistrationRequest as u8 + 1]);
input.extend_from_slice(&total_length.to_be_bytes()[8 - 3..]);
input.extend_from_slice(&alpha_length.to_be_bytes()[8 - 2..]);
input.extend_from_slice(&total_length.to_be_bytes()[std::mem::size_of::<usize>() - 3..]);
input.extend_from_slice(&alpha_length.to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
input.extend_from_slice(pt_bytes.as_slice());
let r1 = RegisterFirstMessage::<RistrettoPoint>::deserialize(input.as_slice()).unwrap();
@@ -142,10 +142,10 @@ fn register_second_message_roundtrip() {
let mut input = Vec::new();
input.extend_from_slice(&[ProtocolMessageType::RegistrationResponse as u8 + 1]);
input.extend_from_slice(&total_length.to_be_bytes()[8 - 3..]);
input.extend_from_slice(&beta_length.to_be_bytes()[8 - 2..]);
input.extend_from_slice(&total_length.to_be_bytes()[std::mem::size_of::<usize>() - 3..]);
input.extend_from_slice(&beta_length.to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
input.extend_from_slice(beta_bytes.as_slice());
input.extend_from_slice(&pubkey_length.to_be_bytes()[8 - 2..]);
input.extend_from_slice(&pubkey_length.to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
input.extend_from_slice(&pubkey_bytes.as_slice());
input.extend_from_slice(&credential_types);
@@ -175,9 +175,9 @@ fn register_third_message_roundtrip() {
let mut input = Vec::new();
input.extend_from_slice(&[ProtocolMessageType::RegistrationUpload as u8 + 1]);
input.extend_from_slice(&total_length.to_be_bytes()[8 - 3..]);
input.extend_from_slice(&total_length.to_be_bytes()[std::mem::size_of::<usize>() - 3..]);
input.extend_from_slice(&envelope_bytes);
input.extend_from_slice(&pubkey_length.to_be_bytes()[8 - 2..]);
input.extend_from_slice(&pubkey_length.to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
input.extend_from_slice(&pubkey_bytes[..]);
let r3 = RegisterThirdMessage::<X25519KeyPair, sha2::Sha256>::deserialize(&input[..]).unwrap();
@@ -202,8 +202,10 @@ fn login_first_message_roundtrip() {
let mut input = Vec::new();
input.extend_from_slice(&[ProtocolMessageType::CredentialRequest as u8 + 1]);
input.extend_from_slice(&total_length_without_ke1m.to_be_bytes()[8 - 3..]);
input.extend_from_slice(&alpha_length.to_be_bytes()[8 - 2..]);
input.extend_from_slice(
&total_length_without_ke1m.to_be_bytes()[std::mem::size_of::<usize>() - 3..],
);
input.extend_from_slice(&alpha_length.to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
input.extend_from_slice(&alpha_bytes);
input.extend_from_slice(&ke1m[..]);
@@ -242,8 +244,10 @@ fn login_second_message_roundtrip() {
let mut input = Vec::new();
input.extend_from_slice(&[ProtocolMessageType::CredentialResponse as u8 + 1]);
input.extend_from_slice(&total_length_without_ke2m.to_be_bytes()[8 - 3..]);
input.extend_from_slice(&pt_bytes.len().to_be_bytes()[8 - 2..]);
input.extend_from_slice(
&total_length_without_ke2m.to_be_bytes()[std::mem::size_of::<usize>() - 3..],
);
input.extend_from_slice(&pt_bytes.len().to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
input.extend_from_slice(pt_bytes.as_slice());
input.extend_from_slice(&envelope.to_bytes());
input.extend_from_slice(&ke2m[..]);