Merge pull request #81 from huitseeker/cross-compilation

Add cross-compilation on 32-bits + fix the associated bugs
This commit is contained in:
François Garillot
2020-11-12 12:03:21 -05:00
committed by GitHub
4 changed files with 47 additions and 14 deletions
+20
View File
@@ -35,6 +35,26 @@ jobs:
command: test
args: --no-default-features --features ${{ matrix.backend_feature }}
cross-test:
name: Test on ${{ matrix.target }} (using cross)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
# 32-bit x86
- i686-unknown-linux-gnu
backend_feature:
- u64_backend
- u32_backend
steps:
- uses: actions/checkout@v2
- uses: hecrj/setup-rust-action@v1
- run: cargo install cross
# Note: just use `cross` as you would `cargo`, but always
# pass the `--target=${{ matrix.target }}` arg. (Yes, really).
- run: cross test --verbose --target=${{ matrix.target }} --no-default-features --features ${{ matrix.backend_feature }}
benches:
name: cargo bench compilation
runs-on: ubuntu-latest
+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[..]);