-
Notifications
You must be signed in to change notification settings - Fork 147
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
ocb3: fix nonce and tag size bounds #595
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tarcieri
reviewed
Mar 27, 2024
tarcieri
approved these changes
Mar 27, 2024
newpavlov
commented
Mar 27, 2024
TagSize: ArrayLength<u8> + NonZero + IsLessOrEqual<U16>, | ||
GrEq<NonceSize, U6>: NonZero, | ||
LeEq<NonceSize, U15>: NonZero, | ||
LeEq<TagSize, U16>: NonZero, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that these bounds cause quite ugly compilation errors:
error[E0599]: the function or associated item `new` exists for struct `Ocb3<Aes128, UInt<UInt<..., ...>, ...>, ...>`, but its trait bounds were not satisfied
--> ocb3/src/lib.rs:100:40
|
9 | let cipher = Ocb3::<Aes128, U12, U20>::new(&key);
| ^^^ function or associated item cannot be called on `Ocb3<Aes128, UInt<UInt<..., ...>, ...>, ...>` due to unsatisfied trait bounds
|
= note: the full type name has been written to '/tmp/rustdoctestWBN6Uv/rust_out.long-type-4996721529537771483.txt'
= note: consider using `--verbose` to print the full type name to the console
= note: the following trait bounds were not satisfied:
`&Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: InnerInit`
which is required by `&Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: KeyInit`
`&Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: InnerUser`
which is required by `&Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: KeyInit`
`&mut Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: InnerInit`
which is required by `&mut Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: KeyInit`
`&mut Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: InnerUser`
which is required by `&mut Ocb3<Aes128, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>>: KeyInit`
error[E0277]: the trait bound `B0: aes::cipher::typenum::NonZero` is not satisfied
--> ocb3/src/lib.rs:100:14
|
9 | let cipher = Ocb3::<Aes128, U12, U20>::new(&key);
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `aes::cipher::typenum::NonZero` is not implemented for `B0`
|
= help: the following other types implement trait `aes::cipher::typenum::NonZero`:
B1
PInt<U>
NInt<U>
UInt<U, B>
note: required by a bound in `Ocb3`
--> /home/newpavlov/projects/rust/crypto/AEADs/ocb3/src/lib.rs:108:25
|
102 | pub struct Ocb3<Cipher, NonceSize = U12, TagSize = U16>
| ---- required by a bound in this struct
...
108 | LeEq<TagSize, U16>: NonZero,
| ^^^^^^^ required by this bound in `Ocb3`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that might be a good reason to use sealed traits for now
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Also adds
compile_fail
tests to check that the sizes are correctly enforced at compile time.The first commit intentionally does not include the fix to demonstrate that
NonZero
bounds are necessary.