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 RawPadding trait to block-padding for padding blocks of arbitrary size #870

Merged
merged 3 commits into from
Apr 1, 2023

Conversation

czinn
Copy link
Contributor

@czinn czinn commented Mar 25, 2023

Closes #860

The existing Padding trait is automatically implemented using raw_pad and raw_unpad from RawPadding.

Because all implementations are inlined, code generation for users of Padding is the same as before. I checked this by defining some functions (see below) to monomorphize the Padding trait for an instance of Padding and comparing the generated assembly (using e.g. cargo asm block_padding::concrete_pad --build-type release) before and after this change. I observed no differences.

pub fn concrete_pad(block: &mut Block<generic_array::typenum::U128>, pos: usize) {
    Iso7816::pad(block, pos);
}

pub fn concrete_unpad(block: &mut Block<generic_array::typenum::U128>) -> Result<&[u8], UnpadError> {
    Iso7816::unpad(block)
}

I'm not attached to RawPadding as a name, something like ArbitraryPadding could also work. I think Padding and BlockPadding for (what is currently called) RawPadding and Padding would be better, but it wouldn't be worth the breaking interface change.

@newpavlov
Copy link
Member

newpavlov commented Apr 1, 2023

Thank you! I will publish this crate in the current form, but I probably will redesign the traits in v0.4.

@newpavlov newpavlov merged commit 63fb20f into RustCrypto:master Apr 1, 2023
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.

block-padding does not support dynamic block sizes
2 participants