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

Expose block nature of MAC functions? #216

Closed
newpavlov opened this issue Jul 14, 2020 · 5 comments
Closed

Expose block nature of MAC functions? #216

newpavlov opened this issue Jul 14, 2020 · 5 comments
Labels
cipher Block and stream cipher crate crypto-mac Message Authentication Code (MAC) crate univeral-hash Universal Hash Function (UHF) crate

Comments

@newpavlov
Copy link
Member

newpavlov commented Jul 14, 2020

Most (if not all?) MAC constructs process messages in blocks. I think we either could add a BlockMac trait which would process messages in blocks (its state will not contain internal buffer for partially processed messages) and on top of which will be built a Mac implementation using wrapper defined in crypto-mac, or less invasive approach would be to add a trait similar to digest::BlockInput.

Exposing block nature could be helpful for RustCrypto/AEADs#74 and may reduce some amount of boilerplate if we are to follow the first option.

@tarcieri
Copy link
Member

Sounds a bit closer to the API that UniversalHash exposes. I agree it's nice to remove that sort of intermediate buffering logic whenever possible, and so far UniversalHash has not needed it at all. I managed to remove the last of it from poly1305 in this PR:

https://github.com/RustCrypto/universal-hashes/pull/52/files#diff-5161721feffdc096d85fc7e5023453fe

Though to make xsalsa20poly1305 work, I did have to add a multi-block "unpadded" API:

RustCrypto/universal-hashes#55

I guess one thing to potentially keep in mind, both for MACs and for universal-hash, is processing multiple blocks in parallel. BlockCipher captures this well now with ParBlocks. I think both UniversalHash, and a hypothetical block-oriented MAC interface, could benefit from this as well, especially for SIMD implementations.

@newpavlov
Copy link
Member Author

One deficiency of the ParBlocks approach is that its value is fixed, while SIMD accelerated code may change number of blocks processed in parallel depending on hardware capabilities. I've encountered this problem in RustCrypto/block-ciphers#135, the new version of aes-soft should have ParBlocks = U1, while AES-NI uses ParBlocks = U8, so we will not be able to implement runtime switch between them 100% correctly, since associated constant/type can not change at runtime.

@tarcieri
Copy link
Member

Perhaps we could have an API that acts on an arbitrary sized slice of blocks?

@newpavlov
Copy link
Member Author

Yes, it's a viable option, but we would have to keep in mind that ParBlocks may influence memory layout, e.g. as done in pmac. I guess we could keep ParBlocks in addition to the new API and state that it should take value of max possible parallel processing capability, it could lead to some wasted memory, but I guess there is no nice workaround for it.

@tarcieri tarcieri added cipher Block and stream cipher crate crypto-mac Message Authentication Code (MAC) crate univeral-hash Universal Hash Function (UHF) crate labels Jul 29, 2020
@newpavlov
Copy link
Member Author

Resolved in #819.

dns2utf8 pushed a commit to dns2utf8/traits that referenced this issue Jan 24, 2023
…Crypto#216)

Adds support for optional parameters for identifying a specific Argon2
secret key ID to use when computing a password hash, and optional
associated data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cipher Block and stream cipher crate crypto-mac Message Authentication Code (MAC) crate univeral-hash Universal Hash Function (UHF) crate
Projects
None yet
Development

No branches or pull requests

2 participants