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

feat: DES encryption #101

Merged
merged 8 commits into from
Jun 27, 2024
Merged

feat: DES encryption #101

merged 8 commits into from
Jun 27, 2024

Conversation

lonerapier
Copy link
Collaborator

This PR fixes/closes issue #100

It changes the following:

  • adds DES symmetric encryption algorithm
  • demonstrates various attacks possible:
    • known plaintext attack
    • weak key attack
    • bit complements

@lonerapier lonerapier linked an issue Jun 25, 2024 that may be closed by this pull request
Copy link
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

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

This PR is beautiful, seriously! Amazing work. The README is so helpful, the code is well structured. I had to try hard to come up with suggestions, but I left a few for you if you want. By no means do you have to take them, I'm okay with merging this as-is.

@@ -0,0 +1,256 @@
//! Contains implementation of DES encryption
#[doc = include_str!("./README.md")]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really nice touch. We should add this everywhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added to other modules as well

Comment on lines 236 to 255
pub fn encrypt(&self, message: &Block) -> Block { Self::des(message, self.subkeys.iter()) }

/// Decrypt a ciphertext of size [`Block`]
///
/// ## Example
/// ```rust
/// use rand::{thread_rng, Rng};
/// use ronkathon::primitives::symmetric::encryption::des::DES;
/// let mut rng = thread_rng();
/// let secret_key = rng.gen();
///
/// let des = DES::new(secret_key);
///
/// let message = rng.gen();
/// let encrypted = des.encrypt(&message);
/// let decrypted = des.decrypt(&encrypted);
/// ```
pub fn decrypt(&self, ciphertext: &Block) -> Block {
Self::des(ciphertext, self.subkeys.iter().rev())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps these should be part of a trait?

Would be really cool if we could have a proof that decrypt(encrypt(msg)) = msg, but, alas, we are in Rust land not Lean land.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this module we could add a trait for Encryption or something. Though if we do that, it's a little odd to have symmetric::encryption and perhaps we should reverse into encryption::symmetric and define an encryption trait in encryption module. Perhaps we ultimately have subtraits for symmetric/asymmetric? Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

totally makes sense. i'll restructure according to this, and think on the encryption trait

@lonerapier
Copy link
Collaborator Author

@Autoparallel added a SymmetricEncryption trait that I think is general enough for now (will work with DES, AES), and we can iterate later if we decide to add new encryption functions in future

wdyt? can it be improved further?

Copy link
Contributor

@0xJepsen 0xJepsen left a comment

Choose a reason for hiding this comment

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

This looks really good to me, i like the way this module is shaping up. Nice work!

@lonerapier lonerapier merged commit 4b55b02 into pluto:main Jun 27, 2024
4 checks passed
@lonerapier lonerapier deleted the des branch June 27, 2024 05:35
@eightfilms eightfilms mentioned this pull request Jun 28, 2024
3 tasks
@github-actions github-actions bot mentioned this pull request Jul 1, 2024
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.

DES encryption
3 participants