Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make find_record constant time #3097

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fog/view/enclave/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ license = "GPL-3.0"
[dependencies]
aes-gcm = "0.10.1"
aligned-cmov = "2.2"
static_assertions = "1.1.0"

mc-attest-ake = { path = "../../../../attest/ake", default-features = false }
mc-attest-core = { path = "../../../../attest/core", default-features = false }
mc-attest-enclave-api = { path = "../../../../attest/enclave-api", default-features = false }
Expand Down
26 changes: 9 additions & 17 deletions fog/view/enclave/impl/src/e_tx_out_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,15 @@ impl<OSC: ORAMStorageCreator<StorageDataSize, StorageMetaSize>> ETxOutStore<OSC>
);
}

// TOOO: Per https://github.com/mobilecoinfoundation/mobilecoin/issues/2965, use a
// a constant time comparison function to always copy the same number of bytes.
// NOTE: As of right now, this code is not constant time and therefore
// blocks the v5 release.
// Code to implement:
// ```
// const LENGTH_TO_COPY: usize = core::cmp::min(FIXED_CIPHERTEXT_LENGTH,
// ValueSize::USIZE - 1);
// (&result.ciphertext[..LENGTH_TO_COPY]).copy_from_slice(&value[1..LENGTH_TO_COPY]);
// ```
let data_end = ValueSize::USIZE - value[0] as usize;
let payload = &value[1..data_end];
// Use this instead of payload.len() because the slice `len` method isn't
// guaranteed to be constant time.
let payload_length = data_end - 1;
result.ciphertext[0..payload_length].copy_from_slice(payload);
result.payload_length = payload_length as u32;
// To preserve constant time execution, we always copy `ValueSize::USIZE - 1`
// bytes. To ensure the copy doesn't panic, assert that the length to
// copy is less than the maximum length that ciphertext can be, which is
// `FIXED_CIPHERTEXT_LENGTH`.
const LENGTH_TO_COPY: usize = ValueSize::USIZE - 1;
static_assertions::const_assert!(LENGTH_TO_COPY < FIXED_CIPHERTEXT_LENGTH);

result.ciphertext[..LENGTH_TO_COPY].copy_from_slice(&value[1..(LENGTH_TO_COPY + 1)]);
result.payload_length = (ValueSize::USIZE - 1 - (value[0] as usize)) as u32;

result
}
Expand Down
1 change: 1 addition & 0 deletions fog/view/enclave/trusted/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.