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

Trait for weak keys #1738

Closed
baloo opened this issue Jan 28, 2025 · 2 comments · Fixed by #1742
Closed

Trait for weak keys #1738

baloo opened this issue Jan 28, 2025 · 2 comments · Fixed by #1742

Comments

@baloo
Copy link
Member

baloo commented Jan 28, 2025

It would be great to get a trait to test for weak keys.

For example there are 64 known weak keys for DES (https://en.wikipedia.org/wiki/Weak_key#Weak_keys_in_DES), or an AES key with zeros on the upper half.

The purpose is the rejection of weak keys as specified in the TPM spec section 11.4.10.4:
https://trustedcomputinggroup.org/wp-content/uploads/TPM-2.0-1.83-Part-1-Architecture.pdf#page=82

@newpavlov
Copy link
Member

newpavlov commented Jan 28, 2025

Sounds interesting. Do you imagine something like this?

trait WeakKeyTest: KeySizeUser {
    fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError>;
}

One open question is whether we should have a default impl which returns Ok(()). If yes, then it may make sense to move the test method to KeySizeUser or KeyInit trait.

@baloo
Copy link
Member Author

baloo commented Jan 29, 2025

Something along those lines, and a:

impl<T> for Key<T> where T: WeakKeyTest {
    fn is_weak(&self) -> Result<(), WeakKeyError> {
        T:weak_key_test(self)
    }
}

To make it a bit more convenient to use.

I guess KeySizeUser with a default implementation would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants