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

Improve MAC validation #333

Merged
merged 4 commits into from
Nov 23, 2023
Merged

Improve MAC validation #333

merged 4 commits into from
Nov 23, 2023

Conversation

dani-garcia
Copy link
Member

Type of change

- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Change the name of the function validate_mac to the more appropiate generate_mac, and change the mac comparison to be constant time with the use of the subtle crate.

Note that hmac.finalize() returns a type CtOutput that supports constant time comparison by using the subtle crate internally, but CtOutput doesn't allow getting a reference to the internal array which would complicate the implementation of EncString, so I chose to use the subtle constant time comparison directly.

@dani-garcia dani-garcia requested a review from Hinton November 17, 2023 12:37
@bitwarden-bot
Copy link

bitwarden-bot commented Nov 17, 2023

Logo
Checkmarx One – Scan Summary & Details37febaa9-976f-4c4a-a74b-3d0eae4ddbdf

No New Or Fixed Issues Found

Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

Do you know how much of a performance improvement this actually is?

Could you also add some unit tests to generate_mac while at it?

@dani-garcia
Copy link
Member Author

I don't think this will change much either way performance wise, if anything it's more of a tiny security improvement.

Ultimately the goal is more to keep in line with how the hmac crate handles the MAC comparisons, where they use a constant time equality check by default on their output types returned from calling hmac.finalize(). Sadly we can't just use those directly because we require access to the raw byte values for serialization of the EncStrings.

@dani-garcia dani-garcia merged commit 47e1a5d into master Nov 23, 2023
46 checks passed
@dani-garcia dani-garcia deleted the ps/improve-mac-validation branch November 23, 2023 15:38
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.

3 participants