DaGenix / rust-crypto

A (mostly) pure-Rust implementation of various cryptographic algorithms.
Apache License 2.0
1.38k stars 296 forks source link

No support for #![no_std] #405

Open UnlawfulMonad opened 7 years ago

UnlawfulMonad commented 7 years ago

I've been using rust-crypto as the main crypto library for a multi-platform library I'm developing. One of those platforms however doesn't have an allocator and so I can't use crates that aren't #![no_std]. I'm willing to go through and add the necessary changes to make this crate #![no_std] compatible. Right now I have a local copy of rust-crypto that I've stripped to the point where I can use it with #![no_std] but it'd be awesome if it was usable straight from crates.io (albeit lacking some features).

If I was to submit a PR for #![no_std] support behind a feature flag would that be desirable?

newpavlov commented 7 years ago

You could instead take a look at RustCrypto organization. One of the goals of this project is to develop cryptographic crates with no_std support if its possible.

What algorithms do you need? I am willing to focus on them if you are interested. And of course contributions are extremely welcome too!

UnlawfulMonad commented 7 years ago

The main algorithms I need are sha2 (256 and 512), scrypt and Curve25519. Curve25519 is already no_std ready but scrypt requires some dynamic allocations as part of the calls to pbkdf2 and later to call store the results from scrypt_ro_mix. I'm pretty sure sha2 doesn't require any dynamic allocations (but either way the sha2 implementation in the RustCrypto organization). I see that non-allocating scrypt might be difficult (if not impossible) since one of its main selling points is being able to increase memory usage through parameters.

newpavlov commented 7 years ago

Regarding Curve25519 I would recommend to look at curve25519-dalek crate instead of using code from rust-crypto.

About scrypt, I think it's possible to write a generic implementation using typenum and generic-array crates. Of course you'll have to fix those parameters at compile time. (no alloca...) But I'll need some time to experiment around it.

burdges commented 7 years ago

You might check if stack guards are implemented for your platform too.