Rust crypto library for Cortex M

Hi

I am building a Rust application to run on my dev board which has a Cortex M4. And I want to generate a certificate and validate a signature with it. I looked it up on the web and found Rust based like Ring and rustls, but Ring failed to compile when I set my target to thumbv7em-none-eabi. Then I tried to build my application with openssl crate but it failed cargo check with error[E0463]: can't find crate for std.

Has anyone had any experience with Rust crypto library for Cortex M processor? I am not sure what has been supported on this particular processor.

Thanks
Yu

What algorithms do you need?
Some no std can be found here:
https://crates.io/teams/github:rustcrypto:aeads

In this project the chacha20poly1305 is used:

I definitely wouldn't expect OpenSSL to work on microcontrollers (in general, in a no_std environment). It being C also complicates things.

The pure-rust crypto implementations under Rust Crypto · GitHub tend to work fine though. There's hashes as well as digital signatures. And lots of other things.

Mainly PKI related stuff. I don't expect Cortex-M4 can work well enough for RSA key, but I want to find Rust base crypto library for EC key at least.

Thanks for the information. I looked into GitHub - RustCrypto/RSA: RSA implementation in pure Rust then I added it into my cargo.toml as below:

[dependencies]
panic-halt = "0.2.0"
cortex-m-rt = "0.6.12"
rsa = "0.3.0"

But I ran into another compilation error which looks like rsa crate require std package.

C:\Users\yu\nrf-rs\myapp>cargo check
Updating crates.io index
Checking regex-syntax v0.6.18
Checking base64 v0.12.3
Checking opaque-debug v0.3.0
Checking smallvec v1.4.0
Checking once_cell v1.4.0
error[E0463]: can't find crate for std
--> C:\Users\leeyuc.cargo\registry\src\github.com-1ecc6299db9ec823\smallvec-1.4.0\lib.rs:72:1
|
72 | extern crate std;
| ^^^^^^^^^^^^^^^^^ can't find crate
|
= note: the thumbv7em-none-eabi target may not be installed

Please let me know if you think I did anything wrong here.
Yu

Right now RSA no_std support is work in progress. You can play with code from the PR using the following configuration:

[dependencies.rsa]
git = "https://github.com/sunriseos/RSA"
branch = "nostd"
default-features = false
features = ["alloc"]

But note that you will need to define a global allocator. No-heap support is tracked in this issue.

I think dalek crates support no_std, so check them out as well.

1 Like

at this moment for crypto on embedded devices, I use mbedtls (pure C GitHub - Mbed-TLS/mbedtls: An open source, portable, easy to use, readable and flexible SSL library) library.

I also found few rust libs which some of the pure rust, some of it is wrappers but not tested it yet.

This is a list:

sodiumoxide would theoretically be really nice for interoperability with other libsodium things but, i have yet to solve the compiling-on-arm problems in libsodium-sys sodiumoxide#363. If you just need elliptic curve things you might also be interested in dalek-cryptography/ed25519-dalek

Thanks for all the feedback. Since I do need RSA functionality in no_std environment, I will try to build with C base mbedtls library first.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.