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

Clarify GCM FFI code #970

Merged
merged 5 commits into from
Apr 30, 2020
Merged

Clarify GCM FFI code #970

merged 5 commits into from
Apr 30, 2020

Conversation

briansmith
Copy link
Owner

Clarify some pointer aliasing in gcm.rs by removing the questionable key_aliasing pattern. It was much easier to remove it than to figure out if it is guaranteed to work. Clarify how keys and contexts are passed to the non-Rust GCM code. Although these changes are justified on their own, they also make merging upstream BoringSSL changes easier. The individual commit messages each contain more detailed explanation.

Rust's pointer aliasing rules are tricky. Avoid dealing with them in
this code.

I remember feeling like I needed the `key_aliasing` pattern when I wrote
the code as it was, but it seems like I could/should have done it this
cleaner way even back then.
BoringSSL has changed such that it uses a different definition of
`GCM128_KEY`. Avoid any confusion regarding that by avoiding the name
`GCM128_KEY`. Looking at how `GCM128_KEY` is actually used in the code,
this actually makes the code clearer anyway, even if there weren't
potential for confusion with BoringSSL's changes.
It has always been confusing that *ring* uses a different definition of
`GCM128_CONTEXT` than BoringSSL. Clarify the situation by avoiding the
`GCM128_CONTEXT` name. Also remove the already-unused C definition of
`GCM128_CONTEXT`.
Clarify what the key initialization functions actually do: They
calcualte the H table from H.

Now the `Key` type exposed from the module isn't `repr(transparent)`
which helps with encapsulation as we can now guarantee that nothing
outside the module uses the contents of the key by passing it to
non-Rust code.
Stop marking `Context` as `#[repr(transparent)]`. Change the remaining
declarations of non-Rust functinos to use the `ContextInner` type
instead.
@briansmith briansmith merged commit 31d3969 into master Apr 30, 2020
@briansmith briansmith deleted the b/clarify-gcm branch April 30, 2020 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant