Skip to content

digest: add dev::initialized_mac_test function#2367

Merged
newpavlov merged 3 commits intoRustCrypto:masterfrom
SalusaSecondus:add-raw_mac_test
Apr 7, 2026
Merged

digest: add dev::initialized_mac_test function#2367
newpavlov merged 3 commits intoRustCrypto:masterfrom
SalusaSecondus:add-raw_mac_test

Conversation

@SalusaSecondus
Copy link
Copy Markdown
Contributor

This is a prerequisite of implementing GMAC in RustCrypto/MACs#1

As GMAC is nonce-based it cannot implement KeyInit and thus the current mac_test function cannot work for it. However, it doesn't make sense to build significant logic for a single special MAC. So, this breaks mac_test into two parts:

  1. A compatibility part (same name of mac_test) that constructs a Mac that implements KeyInit and then passes it to raw_mac_test.
  2. raw_mac_test which is what actually does the testing but simply clones the supplied MAC.

This way all "normal" MACs can keep being tested the same way they always have but "special" MACs can take advantage of the shared test logic.

I did not modify reset_mac_test because nonce-based MACs like GMAC cannot be safely reset, so the refactoring would not have been worth it.

I am not passing in the existing MacTestVector structure, because it isn't applicable to nonce-based MACs and we only need input and tag so they are easy enough to pass independently.

I have manually tested this by redirecting the cmac tests to use my local changes. I also had my new gmac tests use the new logic successfully.

Copy link
Copy Markdown
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I would name the test something like initialized_mac_test for better clarity.

@SalusaSecondus
Copy link
Copy Markdown
Contributor Author

SalusaSecondus commented Apr 6, 2026

Looks good, but I would name the test something like initialized_mac_test for better clarity.

Done.

It just occurred to me. Should I also bump the patch/minor version for this package?

@newpavlov
Copy link
Copy Markdown
Member

Should I also bump the patch/minor version for this package?

No, we usually do it in release PRs.

@newpavlov newpavlov changed the title Add raw_mac_test to allow testing Macs that don't support KeyInit digest: add dev::initialized_mac_test function Apr 7, 2026
@newpavlov newpavlov merged commit f18bb80 into RustCrypto:master Apr 7, 2026
22 checks passed
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.

2 participants