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

aes-gcm: Clarify CPU feature detection. #2106

Merged
merged 1 commit into from
Jun 23, 2024
Merged

Conversation

briansmith
Copy link
Owner

Although every key has been represented with the same types aes::AES_KEY and gcm::HTable regardless of which implementation is used, in reality those types are polymorphic in ways that aren't captured by the type system currently. Thus, the
set_encrypt_key! function must be matched with the corresponding encrypt_block! and/or ctr32_encrypt_blocks! function. Previously, we did CPU feature detection for each function call and assumed that CPU feature detection is idempotent. Now, we do CPU feature detection during key construction and make the lesser assumption that at least those same CPU features are available as long as the key exists.

This is a step towards making further improvements in CPU-feature-based dispatching.

One side-effect of this change is that GCM keys (and thus AES-GCM keys) are now much smaller on targets that don't support any assembly implementation, as they now just store a single U128 instead of a whole HTable.

@briansmith briansmith self-assigned this Jun 19, 2024
Copy link

codecov bot commented Jun 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.12%. Comparing base (515a04a) to head (9ce7475).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2106      +/-   ##
==========================================
+ Coverage   97.07%   97.12%   +0.05%     
==========================================
  Files         144      151       +7     
  Lines       20124    20101      -23     
  Branches      456      447       -9     
==========================================
- Hits        19536    19524      -12     
+ Misses        492      482      -10     
+ Partials       96       95       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@briansmith briansmith force-pushed the b/aes-features-refactor-1 branch 5 times, most recently from 5f52f1d to 63f67a7 Compare June 21, 2024 05:50
Although every key has been represented with the same types
`aes::AES_KEY` and `gcm::HTable` regardless of which implementation is
used, in reality those types are polymorphic in ways that aren't
captured by the type system currently. Thus, the
`set_encrypt_key!` function must be matched with the corresponding
`encrypt_block!` and/or `ctr32_encrypt_blocks!` function. Previously,
we did CPU feature detection for each function call and assumed that
CPU feature detection is idempotent. Now, we do CPU feature detection
during key construction and make the lesser assumption that at least
those same CPU features are available as long as the key exists.

This is a step towards making further improvements in CPU-feature-based
dispatching.

This makes code coverage reporting a little clearer. For example, it
became clearer that the x86 VPAES implementation wasn't being tested in
CI; this will be rectified in another commit.

One side-effect of this change is that GCM keys (and thus AES-GCM keys)
are now much smaller on targets that don't support any assembly
implementation, as they now just store a single `U128` instead of a
whole `HTable`.

Another nice effect is that the dead ctr32_encrypt_blocks
implementation for aarch64 is no longer needed.

```
git difftool HEAD^1:src/aead/aes.rs src/aead/aes/bs.rs
git difftool HEAD^1:src/aead/aes.rs src/aead/aes/vp.rs
```
@briansmith briansmith merged commit 525047a into main Jun 23, 2024
158 checks passed
@briansmith briansmith deleted the b/aes-features-refactor-1 branch June 23, 2024 02:00
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.

1 participant