Skip to content

Update rust-crypto dependency to RustCrypto project#14

Closed
cheme wants to merge 3 commits into
paritytech:masterfrom
cheme:RustCrypto
Closed

Update rust-crypto dependency to RustCrypto project#14
cheme wants to merge 3 commits into
paritytech:masterfrom
cheme:RustCrypto

Conversation

@cheme
Copy link
Copy Markdown
Collaborator

@cheme cheme commented Aug 6, 2018

In this PR I got rid of the remaining uses of the rust-crypto crate, to use the corresponding RustCrypto ones.
One major difference is that I do not target aes-safe but the roots aes crates : if compiling with RUSTFLAGS='-C target-feature=+aes,+ssse3,+sse2' the aesni implementation will be used (only for x86).
There is also two aes encoder/decoder struct which are basically here to get rid of rust-crypto in network-devp2p.

cheme added 2 commits August 6, 2018 14:34
Note that we use RustCrypto aes root crates : so if we build with RUSTFLAGS='-C target-feature=+aes,+ssse3,+sse2' on x86, AES native instruction will be used.

Also added two Aes encryptor struct in preparation of switching (only
two use case remaining at the time in 'network-devp2p' crate.
@cheme cheme requested review from debris and dvdplm August 6, 2018 16:25
Copy link
Copy Markdown
Contributor

@debris debris left a comment

Choose a reason for hiding this comment

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

We definitely need to switch from rust-crypto to something else, but I'm not convinced that we should go with RustCrypto. There are several things that I don't like about it:

  • the structure; Currently we use a single crypto library. Replacing it with 6 other is a maintenance overhead. Every time one of those libraries is updated, we should go to the repo and check the code that has been changed since the last release

  • lack of users; There is no guarantee that this libraries will be maintained a few months from now

  • the interface; I quite lack the consistency and low-level interface of rust-crypto. I don't know why it was changed, but seeing additional copy_from_slice calls makes me wonder if the performance of those two libraries is the same. Without benchmarks and a proof that it is, we cannot merge it

@cheme
Copy link
Copy Markdown
Collaborator Author

cheme commented Aug 7, 2018

I agree with your first two points, this PR is mainly an update (RustCrypto is mainly rust-crypto with maintenance and some evo).

On the third point we can still use a similar interface as rust-crypto (I just change to avoid usage of two buffers so we would need to copy_from_slice too at some places), yet the stream interface leads to better results in my case (no need to adjust buffer size to a block length multiple).

About the copy_from_slice it can be avoided by using the additional inplace function in parity-crypto and sometime avoid buffer allocation: eg openethereum/parity-ethereum@master...cheme:RustCrypto#diff-ee20f8e316717999d2a4dee44afa6154
(it is a branch of parity-ethereum with all rust-crypto dependancies moved to parity-crypto but it uses the RustCrypto version of parity-crypto so I will probably not PR (I used it for my still syncing node with aes-ni activated and it may be a bit faster but I did not have metrics)).

As you asked I did a very quick bench : https://gist.github.com/cheme/2dcd97a7a08efc73027126f70fb3e64a

There is some small difference (I think instantiation may be a bit more costy with RustCrypto : for small content it is slower while for big content it is way faster).
But for nework-devp2p for instance it should be not that problematic because the encoder/decoder are stored and not instantiated for every operations.

I am keeping it for now (it was in libp2p that rust-crypto was a real issue : libp2p/rust-libp2p#371 ), as it is not that big of an issue to drop it but other.

Also about the choice of a crypto crate, I do not believe there is a magic solution, yet I think that using standard traits could be a good thing (being able to switch crypto implementation easily, especially when targeting wasm or other less common targets).

@dvdplm
Copy link
Copy Markdown
Contributor

dvdplm commented Aug 20, 2018

using standard traits could be a good thing

@cheme I've seen this idea floating around in a few places and it sounds very enticing (especially being able to have a fully pluggable crypto backend so we can run tests against all backends) but I'm a bit hazy on the details of how this would work exactly. Do you have a clear picture of the set of traits we'd need? Maybe even an example? Would be curious to see it. :)

@dvdplm
Copy link
Copy Markdown
Contributor

dvdplm commented Sep 26, 2018

@debris @cheme while we do not want to invest substantial amount of work on rust-crypto or RustCrypto before having a clear path ahead, it looks to me that this PR is an improvement to what we currently have. If you agree I think we should merge it; if not we should close it.

@cheme
Copy link
Copy Markdown
Collaborator Author

cheme commented Sep 26, 2018

I think we should ask @tomaka about that (I believe there was some issues using it with libp2p use and we may want his feedback).
Edit : It seems its issue was unrelated, so I got nothing against merging this PR (I can update it if needed)

Remove unused scrypt features.
sorpaas pushed a commit that referenced this pull request Jan 24, 2019
@ddorgan
Copy link
Copy Markdown
Member

ddorgan commented Jan 25, 2019

[clabot:check]

@parity-cla-bot
Copy link
Copy Markdown

It looks like @cheme signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

1 similar comment
@parity-cla-bot
Copy link
Copy Markdown

It looks like @cheme signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

tomaka pushed a commit to tomaka/parity-common that referenced this pull request Apr 29, 2019
tomaka pushed a commit to tomaka/parity-common that referenced this pull request Apr 29, 2019
@ordian
Copy link
Copy Markdown
Contributor

ordian commented May 4, 2019

Superseded by #85.

@ordian ordian closed this May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants