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

Add inout crate and prepare block-padding v0.3 #675

Merged
merged 1 commit into from Feb 10, 2022
Merged

Conversation

newpavlov
Copy link
Member

Split-off from #566

This crate aims to generalize over in-place and buffer-to-buffer modes of operation and it's designed to be used in our cipher crates, i.e. block/stream ciphers, block modes, AE(AD)s.

inout/src/inout_buf.rs Outdated Show resolved Hide resolved
inout/src/inout.rs Outdated Show resolved Hide resolved
@newpavlov
Copy link
Member Author

@steffahn
I have the following question, if you don't mind. Is it safe to define get_in/get_out methods on InOut like this?

pub fn get_in<'b>(&'b self) -> &'b T {
    unsafe { &*self.in_ptr }
}

 pub fn get_out<'b>(&'b mut self) -> &'b mut T {
    unsafe { &mut *self.out_ptr }
}

@steffahn
Copy link

It's been a while since I last looked at this. It should probably be safe.

To determine safety, there's two concerns:

  • Does the code break any invariants for references/pointers, i.e. is is just plain always-UB? (E.g. aliasing mutable references, or invalidating pointers, etc...)
    • On this point, the methods seem very straightforward, so I don't see any danger
  • Does the method offer a sound API? (I.e. are all the lifetimes right, is there some tricky way to abuse it, etc.) On this front, I think that remembering my proposed alternative-implementation helps. If InOut<'a, T> was just an enum { Same(&'a mut T), Separate(&'a T, &'a mut T) }, would the API be possible to implement in safe code? If that's true for all the API surface (perhaps ignoring things like from_raw), then it is for sure sound.

@newpavlov newpavlov changed the title inout: initial crate Add inout crate and prepare block-padding v0.3 Feb 10, 2022
@newpavlov newpavlov merged commit de1a2cb into master Feb 10, 2022
@newpavlov newpavlov deleted the add_inout branch February 10, 2022 06:11
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.

None yet

3 participants