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

Improving/simplifying cfg attributes for target features #18

Open
tarcieri opened this issue Apr 1, 2023 · 4 comments
Open

Improving/simplifying cfg attributes for target features #18

tarcieri opened this issue Apr 1, 2023 · 4 comments

Comments

@tarcieri
Copy link
Member

tarcieri commented Apr 1, 2023

After many issues using crate features for controlling usage of target features, we've largely migrated to using cfg attributes instead.

Here are some of the cfg attributes we've defined:

  • aes_force_soft: use the software AES backend
  • aes_armv8: enable ARMv8 AES intrinsics (nightly-only)
  • chacha20_force_avx2: force the use of the AVX2 backend for ChaCha20
  • chacha20_force_sse2: force the use of the SSE2 backend for ChaCha20
  • chacha20_force_soft: force the use of the software-only backend for ChaCha20
  • polyval_force_soft: use the software POLYVAL backend
  • polyval_armv8: enable ARMv8 PMULL intrinsics (nightly-only)

First off, these all are selecting one of many options and are mutually exclusive at a crate level. cfg attributes make that possible in ways crate features don.t Alternatively we could have:

  • aes_backend="armv8", aes_backend="soft"
  • chacha20_backend="avx2", chacha20_backend="sse2", chacha20_backend="soft",
  • polyval_backend="armv8", polyval_backend="soft"

This would both be consistent across crates and simplify the logic in regard to conflicting attributes.

However, it would also be nice to have some way of enabling e.g. ARMv8 support without having to know about every subcomponent crate and whether or not it has ARMv8-specific features.

For example, right now to have fully hardware accelerated AES-GCM on ARMv8, an aes-gcm crate user needs to enable the aes_armv8 and polyval_armv8 cfg attributes.

It would be nice if there were a single cfg attribute that could be used to enable this across the whole project, e.g.

rustcrypto_target_arch="armv8"

To make this a bit easier to implement, we can continue to use the crate-specific attributes as the canonical cfg attributes, and use a build script to propagate the "global" cfg attributes.

@tarcieri
Copy link
Member Author

tarcieri commented Apr 1, 2023

A couple other related issues...

There's a proposed chacha20_*_neon attribute here: RustCrypto/stream-ciphers#316

This PR proposes rustcrypto_cpubits: RustCrypto/utils#826

@newpavlov
Copy link
Member

I don't think Rust currently supports aes_backend="armv8" for configuration flags. Ideally, such flags should be defined in Cargo.toml, with appropriate cargo support for them, but I don't recall any accepted proposals for such feature.

@tarcieri
Copy link
Member Author

tarcieri commented Apr 1, 2023

It definitely works. curve25519-dalek is using it:

https://github.com/dalek-cryptography/curve25519-dalek#backends

It just maps to #[cfg(aes_backend = "armv8")].

@newpavlov
Copy link
Member

newpavlov commented Apr 1, 2023

Oh, TIL. If I knew about it, I probably would've used it for aes and other crates.

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

No branches or pull requests

2 participants