fadeevab/cocoon

Using --no-default-features still compiles getrandom

Closed this issue ยท 10 comments

I am trying to utilize the "no_std" features of the crate for a cortex-m arch build that does not have a std environment. Even with alloc, std, and getrandom disabled in the toml file, the library still tries to compile those and fails.

Some more context: trying the use of StdRng still uses the std library during compilation meaning the crate can't be used on embedded systems where std does not exist. I am looking the possibility to make that optional

@ProjectInitiative getrandom comes with aes-gcm, need to try to disable all features for aes-gcm and try to make it compiling

โ”œโ”€โ”€ aes-gcm v0.10.1
โ”‚   โ”œโ”€โ”€ aead v0.5.0
โ”‚   โ”‚   โ”œโ”€โ”€ crypto-common v0.1.6
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ rand_core v0.6.3
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ getrandom v0.2.7

@ProjectInitiative

aes-gcm = {version = "0.10", default-features = false, features = ["aes"]}

It almost makes it work, alas, there is one error should be fixed yet:

error[E0599]: no method named `concat` found for array `[&[u8]; 2]` in the current scope
  --> src/kdf.rs:20:42
   |
20 |         let ext_salt = [b"cocoon", salt].concat();
   |                                          ^^^^^^ method not found in `[&[u8]; 2]`

concat is not defined in the no_std... seems like it worked because of the side-effect of linking std because of aes-gcm.

@ProjectInitiative https://github.com/fadeevab/cocoon/pull/20/files

It would be great if you're able to build it locally.

Thank you so much for reporting the issue!

I reviewed the PR, and was able to successfully build the PR locally. Going to try and get a simple example running on a Raspberry Pi pico (RP2040 micro controller)

I was able to compile an in place encryption with the .encrypt and .decrypt functions. The provided example in the docs is good for a no_std env. Working with a no_std and no_alloc I used the following, and might be useful to include in the docs:

    const MAX_DATA_LEN: usize = 64; // Adjust this size as needed
    let mut data = [0u8; MAX_DATA_LEN];
    let data_str = "my secret data";

    // Copy the string's bytes into the fixed-size array
    let data_len = data_str.len().min(MAX_DATA_LEN);
    data[0..data_len].copy_from_slice(data_str.as_bytes());

Re-opening until the PR gets merged into mainline

@ProjectInitiative Thank you, good man ๐Ÿ˜„ I need time to merge, I want also commit linter fixes, maybe I will add your example as well...

@ProjectInitiative I just published v0.3.3 (https://crates.io/crates/cocoon) try it out!

P.S.: And please, don't hesitate to open an issue in case of any improvement requests.

Just tried out 3.3.3, works well so far, will definitely reach out if I run into something else!