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

Bring in cpufeatures v0.2.9 #6

Merged
merged 117 commits into from
Sep 13, 2023
Merged

Conversation

eranrund
Copy link

This PR merges the cpufeatures-v0.2.9 tag while maintaining our hack that disables the CPUID call.
This is used in enclave builds. I needed 0.2.9 since the crates that depend on cpufeatures moved to that version.
I verified this works by deploying it: https://github.com/mobilecoinfoundation/mobilecoin/actions/runs/6178026343
Prior to this switch, the enclave crashed (since the stock cpufeatures 0.2.9 was included, which called CPUID inside SGX).

tarcieri and others added 30 commits March 25, 2022 19:30
It was pinned due to issues around `aarch64_target_feature`
stabilization, but those have been resolved upstream.
See rust-lang/unsafe-code-guidelines#133
Calling as_mut_ptr creates a unique reference, and as_ptr a shared
reference. These 2 conflict, and one invalidates the other. Both
ptr need to be reborrows of or be basically the same pointer.
Also removes all uses of `html_root_url` and relevant notes from Cargo.toml.
)

Sometimes libraries want to be generic across types like `Vec<u8>` and
`Box<[u8]>`. Therefore, they use bounds like `T: AsRef<[u8]>`. The
`Zeroizing<Vec<u8>>` type should be transparently equivalent to
`Vec<u8>` in this regard. This allows `Zeroizing` to be used with all
such bounds.

Signed-off-by: Nathaniel McCallum <[email protected]>
This implements Zeroize for std::ffi::CString. As CString is not in
allocate but in std, a new optional std feature is added to depend
on the std library.
This crate provides a `generic-array`-inspired array type which uses some
of the ideas from `crypto-bigint` to provide type-level conversions between
const generics and typenum-based arrays.

I originally looked at trying to add this sort of thing as an
afterthought to `generic-array`, but felt that it would really be
helpful if it were the core abstraction everything else is built on.
Also `generic-array` is full of huge swaths of complicated `unsafe` code
which is completely unnecessary in the setup used in this crate, which
merely uses the type system to map to Rust's underlying array types.

It provides an `Array` type similar to `GenericArray` along with an
`Array<T, const N: usize>` trait which can be used to map const generic
parameters to underlying array types.

Macros are used to write the `Array`/`ArraySize` trait impls for the
following array sizes:

- 0-64
- 96
- 128
- 192
- 256
- 384
- 448
- 512
- 768
- 896
- 1024
- 2048
- 8192

This is a smaller range of sizes than what `generic-array` supports due
to `typenum` type alias definitions. It is necessary to make the
const generic linkage work.

The overall API is *much* closer to `core::array` than `GenericArray`
is. For example, `GenericArray` has a panicking `From` providing
`TryFrom`-like behavior, and confusingly receives the blanket impl of
`TryFrom`, so people can mistakenly use `TryFrom` expecting a fallible
API only to get the blanket impl of `From` and a panic in the event of
an error.

Everywhere possible, it uses const generic implementations of traits
rather than macro-based implementations in order to improve compile
times and keep the macro-based parts to a minimum.

This includes:

- `AsRef<[T; N]>`
- `AsMut<[T; N]>`
- `Borrow<[T; N]>`
- `BorrowMut<T; N]>`
- `From<[T; N]>`
- `Index<I>`
- `IndexMut<I>`
- `TryFrom<&[T]>`
Adds support for extracting secp384r1 test vectors from Wycheproof, in
order to test the `p384` crate.
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.36 to 1.0.39.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](dtolnay/proc-macro2@1.0.36...1.0.39)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This crate is a tool for transforming `fiat-crypto`-generated field
arithmetic into `const fn` form.

It performs mechanical translation to the parsed AST of the code, making
some assumptions about how it's structured and rewriting the usages of
mutable references into a functional form.

Manual tests confirm the output from the p386 base field compiles.
Adds `allow` directives for the following:

- `clippy::identity_op`
- `clippy::unnecessary_cast`
Reorder code in terms of precedence; add whitespace
This test relies on UB and is flaking out in certain cases:

RustCrypto#774

It's unclear if the test failure indicates a genuine bug in the
implementation, or is the result of a test with UB.

However, in the meantime it shouldn't block users who would just like
the test suite to run reliably.
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.39 to 1.0.40.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](dtolnay/proc-macro2@1.0.39...1.0.40)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This (optional) feature implements Serialize/Deserialize for Zeroizing when
the inner type implements these traits. This makes it possible to use
Zeroizing in serde contexts.

Signed-off-by: Nathaniel McCallum <[email protected]>
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.40 to 1.0.42.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](dtolnay/proc-macro2@1.0.40...1.0.42)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Miri is an interpreter, and though it tries to emulate the target CPU
it does not support any target features.
rvolosatovs and others added 28 commits April 19, 2023 08:28
This fixes compilation of dependent crates for these targets.

For example, `sha2`:

Before:
```
$ cargo build --target x86_64-unknown-none --no-default-features
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
LLVM ERROR: Do not know how to split the result of this operator!

error: could not compile `sha2`
$ cargo build --target x86_64-unknown-uefi --no-default-features
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
LLVM ERROR: Do not know how to split the result of this operator!

error: could not compile `sha2`
```

After:
```
$ cargo build --target x86_64-unknown-none --no-default-features
   Compiling cpufeatures v0.2.5 (/home/rvolosatovs/src/github.com/rustcrypto/utils/cpufeatures)
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
    Finished dev [optimized + debuginfo] target(s) in 0.19s
$ cargo build --target x86_64-unknown-uefi --no-default-features
   Compiling cpufeatures v0.2.5 (/home/rvolosatovs/src/github.com/rustcrypto/utils/cpufeatures)
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
    Finished dev [optimized + debuginfo] target(s) in 0.19s
```

Signed-off-by: Roman Volosatovs <[email protected]>
It's quite annoying to have to add a generic parameter to `ArraySize`,
particularly when notating it in bounds.

GATs provide a solution to this problem, moving the type parameter to
the associated type so bounds are simply `N: ArraySize`.
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.57 to 1.0.59.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](dtolnay/proc-macro2@1.0.57...1.0.59)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Adds a set of reference conversions to `Array<T, U>` as well as the
`ArrayOps` trait:

- `&Array<T, U>`: `From<&[T, N]>` + TryFrom<&[T]>
- `&mut Array<T, U>`: `From<&mut [T, N]>` + `TryFrom<&mut [T]>`

The implementation uses an unsafe pointer cast to convert a slice into
the corresponding reference newtype.

Additionally it adds the following panicking inherent methods to
`Array<T, U>` to ease migrating code based on `GenericArray`:

- `Array::ref_from_slice`: alternative to `GenericArray::from_slice`
- `Array::ref_from_mut_slice`: alternative to
  `GenericArray::from_mut_slice`
- `Array::clone_from_slice`: alternative to
  `GenericArray::clone_from_slice`

These methods are marked with TODOs to deprecate them before a final
v0.2.0 release, however for now they're not deprecate to ease a
migration.
Adds an extension trait with a blanket impl for all core arrays, and
adds it to the bounds for `ArraySize::ArrayType`.

It currently provides a `from_fn` constructor which is now leveraged by
a now-generic `Default` impl which bounds on `ArraySize`.

This reduces the bounds needed in generic code to just `ArraySize`, even
to leverage the `Default` impl, and should also permit some additional
array constructors.
Derefs to the inner core array type.

Also adds bounds for `Deref`/`DerefMut` to `ArrayOps`, with a `Target`
of `[T; N]`.
…RustCrypto#910)

Changes `ArrayOps` to contain only operations that need to know the
exact size (as a const generic) of an associated array.
It's leaked through `ArraySize::ArrayType` bounds, and it may
potentially be useful to have in the public API.
This makes porting existing `generic-array` code easier, and also means
deref coercion will allow `&Array<T, _>` to deref to `&[T]`, making it
usable anywhere a slice is.
It's used when checking the lengths of slices match an array size prior
to using a pointer cast to convert types.

If someone were to make their own `typenum::Unsigned` type and impl
`ArraySize` for it with an `ArrayType` whose size does not match
`Unsigned::USIZE`, that would be UB.

Really `ArraySize` is not intended for downstream crates to impl anyway,
but making it an `unsafe trait` at least captures the UB potential.

Additionally this adds more debug checks to `check_slice_length` to
ensure that if there is a length mismatch, it's at least caught in debug
builds.
Renames the following methods of the `ArrayOps` trait:
- `as_array_ref` -> `as_core_array`
- `as_array_mut` -> `as_mut_core_array`
- `from_core_array_ref` -> `ref_from_core_array`
- `from_core_array_mut` -> `ref_from_mut_core_array`
- `map` -> `map_to_core_array`
Copy link

@nick-mobilecoin nick-mobilecoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, there appears to be no conflicts in the merge.

@eranrund eranrund merged commit f04659d into mobilecoin Sep 13, 2023
99 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.