-
Notifications
You must be signed in to change notification settings - Fork 130
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
Implemented DES #2
Conversation
Hmm, now that I think about it, it would probably be cleaner to just use big endian integers and work from the LSB instead of using little endian and working from the MSB. I'll experiment with that. |
Thank you! Also you can implement 3DES, not sure if it's better to use the separate crate for it or include in this one. |
Also check this implementation (it uses |
I've updated your code with optimizations I borrowed from antoyo's I haven't modified Currently I am getting 17 MB/s without initialization. Meanwhile OpenSSL implementation gives approximately 50 MB/s, so there is still room for improvement. EDIT: Forgot about functions inlining, using it gives 19 MB/s respectively. |
|
||
[dependencies] | ||
generic-array = "0.5" | ||
block-cipher-trait = "0.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use old version of crates:
generic-array = "0.6"
block-cipher-trait = "0.3"
(Forgot to update blowfish)
} | ||
|
||
impl BlockCipherFixKey for Des { | ||
type KeySize = U8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be U7
?
fn encrypt_block(&self, input: &Block<U8>, output: &mut Block<U8>) { | ||
let block = read_u64_be(input); | ||
let res = self.encrypt(block); | ||
write_u64_be(output, res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added read_u64_be
to byte-tools
. Don't forget to run cargo update
to get new version.
I've been invited to participate to this discussion, so here I am :p . How can I give you a write access to the |
@antoyo
You can do it using cargo with this command:
You don't need to be authenticated on crates.io if your cargo token is intact. Your problems with cargo.io could be because of privacy settings, as it uses github for authentication. As a backup plan you can contact Alex Crichton. |
I added you as an owner. |
@antoyo Meanwhile can you compare your S-box implementation with gsingh93's implementation? As I understand in the later transformed S-boxes are used to improve performance. Simple tests show that this implementation is a bit faster than yours, but maybe you know about additional optimizations which can be applied here? |
Sorry it took so long! I will merge this PR, although before publishing I'll need to make some changes. |
BTW it looks like you had a bug in decryption part. |
Ack. Fairly busy for a while, so if you or anyone can fix that would be great. Otherwise, I'll take a look when I have time. |
This is an implementation of DES. The included benchmark gives 2 MB/s performance, I'm not sure if that's good or bad. Most of the trickiness with the implementation is the fact that the most significant bit is considered bit zero instead of the least significant bit. It's possible I did some unnecessary shifting/arithmetic to account for this.
Note that the crate name
des
is taken on crates.io, so we might have to change that name.I'm planning on adding more test cases. I have a file of
(input, key, output)
tuples that I need to parse and turn into the correct format for tests used in this repo.