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

remove rustc-serialize (#359) #386

Merged
merged 13 commits into from
Aug 10, 2018
Merged

remove rustc-serialize (#359) #386

merged 13 commits into from
Aug 10, 2018

Conversation

cheme
Copy link
Contributor

@cheme cheme commented Aug 2, 2018

In this commit I replace rust-serialize with RustSerialize project aes-ctr crate.
Fixes #383
Note that to avoid any api changes, I do not transmit a possible encoding error (the error seems a bit unlikely to occurs : end of keystream), it will likely panic on failure.

This should also fix #371 but it needs to be tested.

To use aes native instruction, the following rust-flags must be use RUSTFLAGS="-C target-feature=+aes,+ssse3" RUSTDOCFLAGS="-C target-feature=+aes,+ssse3".

I also add a feature 'aes-all' for including both version of the aes lib (aes-ni or aes-soft) and choose at runtime (with 'is_86_feature_enabled' macro) which one to use.
I do not believe if there is still a lot of x86 without support for aes or ssse3 and this feature may not be usefull (not activated by default and I would understand if we want to get rid of it).

cheme added 2 commits August 2, 2018 10:53
Feature gated behind 'aes-all'.
Building requires RUSTFLAGS="-C target-feature=+aes,+ssse3" and RUSTDOCFLAGS="-C target-feature=+aes,+ssse3".
Only support x86 case.
cheme added 2 commits August 6, 2018 11:57
RUSTC aes and sse are enabled).
To build with aes-all, aes and sse flag should not be set.
secio/Cargo.toml Outdated
@@ -14,7 +14,7 @@ protobuf = "2.0.2"
rand = "0.3.17"
ring = { version = "0.12.1", features = ["rsa_signing"] }
aes-ctr = "0.1.0"
aes-soft = { version = "0.2", optional = true }
aesni = { git="https://github.com/cheme/block-ciphers.git", features = ["nocheck"], optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

@cheme is there anything in the git-repo that isn't in the release on crates.io? Or why can't we use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes there was a little change, but RustCrypto guys merge it: RustCrypto/block-ciphers#22 , so we can now use the crates.io dependancy (I change it).

@gnunicorn
Copy link
Contributor

@cheme thanks heaps. Could you rebase this on master, so the win32 tests will be included?

@ghost ghost assigned tomaka Aug 10, 2018
@ghost ghost added the in progress label Aug 10, 2018
@tomaka
Copy link
Member

tomaka commented Aug 10, 2018

Anyone should be able to merge master thanks to github's button.

@cheme
Copy link
Contributor Author

cheme commented Aug 10, 2018

win32 pass 👍

@gnunicorn gnunicorn merged commit 7399688 into libp2p:master Aug 10, 2018
@ghost ghost removed the in progress label Aug 10, 2018
@@ -0,0 +1,109 @@

Copy link
Member

Choose a reason for hiding this comment

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

Missing copyright header.


/// Returns your stream cipher depending on `KeySize`.
#[cfg(not(all(feature = "aes-all", any(target_arch = "x86_64", target_arch = "x86"))))]
pub(crate) fn ctr(key_size: KeySize, key: &[u8], iv: &[u8]) -> Box<StreamCipherCore + 'static> {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't need to be pub(crate).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed.

feature = "aes-all",
any(target_arch = "x86_64", target_arch = "x86"),
))]
#[test]
Copy link
Member

Choose a reason for hiding this comment

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

Should be in a mod tests module.

// Apparently this is the fastest way of doing.
// See https://gist.github.com/kirushik/e0d93759b0cd102f814408595c20a9d0
let mut out_buffer = BytesMut::from(vec![0; capacity]);
let mut data_buf = item;
Copy link
Member

Choose a reason for hiding this comment

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

Why this line, instead of renaming the function parameter or using item in the code below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Useless (just wanted to keep proto looks but does not need to be here).

/// Returns your stream cipher depending on `KeySize`.
#[cfg(all(feature = "aes-all", any(target_arch = "x86_64", target_arch = "x86")))]
pub(crate) fn ctr(key_size: KeySize, key: &[u8], iv: &[u8]) -> Box<StreamCipherCore + 'static> {
if *aes_alt::AES_NI {
Copy link
Member

Choose a reason for hiding this comment

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

I haven't really digged into the crate, but from what I understand the aes_ctr crate already does that, no?
It would really really really be great if we didn't have platform-specific code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aes_ctr run compile time switch between NI and soft implementation (to activate NI only crate flags from original PR msg should be use). A runtime check is not in aes_ctr crate, that is what eas-all feature does, but honestly I doubt that there is a lot of x86 cpu that could not run NI (I did my tests with qemu).
The best thing to do would be to try to PR runtime NI check to RustCrypto (not directly this code as dynamic type usage does not fit RustCrypto crates design), not sure if it would be easily accepted.
Another option would be to simply remove the 'aes-all' feature as I do not know if it is wanted (usecase would be single x86 build supporting old x86 cpu, it seems reasonable to me to defaults to NI activated build (binary distribution) and ask users to build from source if they are using x86 cpu that does not support aes NI and sse3). For info in #371 Sergei low end config could run aes-ni.

@tomaka
Copy link
Member

tomaka commented Aug 12, 2018

Haven't had time to review.

@cheme cheme mentioned this pull request Aug 14, 2018
tomaka added a commit to tomaka/libp2p-rs that referenced this pull request Sep 7, 2018
tomaka added a commit that referenced this pull request Sep 7, 2018
tomaka added a commit to tomaka/libp2p-rs that referenced this pull request Sep 13, 2018
tomaka added a commit that referenced this pull request Sep 17, 2018
@tomaka tomaka mentioned this pull request Oct 12, 2018
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.

Illegal instruction trap is generated if CPU doesn't support AVX
3 participants