Skip to content

Commit

Permalink
Better gating of alloc (#62)
Browse files Browse the repository at this point in the history
Gate all `alloc` usage with feature `alloc` instead of not std.

Update CI to check `alloc` feature only build & test.

Resolves #36.
  • Loading branch information
Taowyoo authored Apr 14, 2024
1 parent 9802e4a commit db39e4d
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rustls-rustcrypto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}
- run: cargo build
- name: Test no_std with alloc build
run: cargo build --no-default-features --features tls12,alloc

clippy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -74,3 +76,5 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}
- run: cargo test --features tls12
- name: Test no_std with alloc
run: cargo test --no-default-features --features tls12,alloc
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

WIP RustCrypto-based provider implementation for version 0.23 of [rustls](https://github.com/rustls/rustls/pull/1405).

Some code comes directly from one of main rustls contributor, [@ctz](https://github.com/ctz).
Some code comes directly from one of main rustls contributor, [@ctz](https://github.com/ctz).

Some part of this code is directly derived from his work but modified to use generic instead.

## ⚠️USE THIS AT YOUR OWN RISK! DO NOT USE THIS IN PRODUCTION⚠️

Not only that this is incomplete that only few selected TLS suites implemented (it should be well enough to cover 70% of the usage), but the elephant in the room is that neither did rustls nor RustCrypto packages were formally verified and certified with FIPS compliance.
Not only that this is incomplete that only few selected TLS suites implemented (it should be well enough to cover 70% of the usage), but the elephant in the room is that neither did rustls nor RustCrypto packages were formally verified and certified with FIPS compliance.

Note that RustCrypto performance is generally inferior than ring, but in exchange you got a pure Rust implementation that theoretically compiles everywhere Rust was ported to. In our case, we need to have `std` but foundational support for future `no_std` expansion is already here.

This package is still in its very early phase, so until we think the code is okay for general public use, this won't be published to crates.io anytime soon.
This package is still in its very early phase, so until we think the code is okay for general public use, this won't be published to crates.io anytime soon.

Meanwhile you can try it out using git crate installation:
```

```toml
rustls-rustcrypto = { git = "https://github.com/RustCrypto/rustls-rustcrypto", version = "0.1" }
```

Expand All @@ -33,14 +34,14 @@ rustls-rustcrypto = { git = "https://github.com/RustCrypto/rustls-rustcrypto", v

## QUIC Support

There won't be QUIC support anytime soon until https://github.com/rustls/rustls/issues/1491 is solved. HTTP/2 however should work out of the box.
There won't be QUIC support anytime soon until <https://github.com/rustls/rustls/issues/1491> is solved. HTTP/2 however should work out of the box.

## License

Licensed under either of:

* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)
- [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
- [MIT license](http://opensource.org/licenses/MIT)

at your option.

Expand Down
2 changes: 1 addition & 1 deletion src/aead/chacha20.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(feature = "std"))]
#[cfg(feature = "alloc")]
use alloc::boxed::Box;

use super::{DecryptBufferAdapter, EncryptBufferAdapter};
Expand Down
2 changes: 1 addition & 1 deletion src/aead/gcm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(feature = "std"))]
#[cfg(feature = "alloc")]
use alloc::boxed::Box;

use super::{DecryptBufferAdapter, EncryptBufferAdapter};
Expand Down
2 changes: 1 addition & 1 deletion src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(feature = "std"))]
#[cfg(feature = "alloc")]
use alloc::boxed::Box;

use digest::{Digest, OutputSizeUser};
Expand Down
2 changes: 1 addition & 1 deletion src/hmac.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(feature = "std"))]
#[cfg(feature = "alloc")]
use alloc::boxed::Box;

use crypto_common::OutputSizeUser;
Expand Down
2 changes: 1 addition & 1 deletion src/kx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(feature = "std"))]
#[cfg(feature = "alloc")]
use alloc::boxed::Box;

use crypto::{SharedSecret, SupportedKxGroup};
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "alloc"))]
compile_error!("Rustls currently does not support alloc-less environments");

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "alloc")]
use alloc::sync::Arc;

use rustls::crypto::{
Expand Down
2 changes: 1 addition & 1 deletion src/quic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::duplicate_mod)]

#[cfg(not(feature = "std"))]
#[cfg(feature = "alloc")]
use alloc::boxed::Box;

use aead::AeadCore;
Expand Down
5 changes: 2 additions & 3 deletions src/sign.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloc::sync::Arc;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
#[cfg(feature = "alloc")]
use alloc::{sync::Arc, vec::Vec};
use core::marker::PhantomData;

use self::ecdsa::{EcdsaSigningKeyP256, EcdsaSigningKeyP384};
Expand Down
6 changes: 2 additions & 4 deletions src/sign/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
use alloc::format;
use alloc::sync::Arc;
#[cfg(feature = "alloc")]
use alloc::{boxed::Box, format, sync::Arc};
use core::marker::PhantomData;

use paste::paste;
Expand Down
6 changes: 2 additions & 4 deletions src/sign/eddsa.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use alloc::format;
use alloc::sync::Arc;
#[cfg(feature = "alloc")]
use alloc::{boxed::Box, format, string::ToString, sync::Arc};
use core::marker::PhantomData;
#[cfg(not(feature = "std"))]
use {alloc::boxed::Box, alloc::string::ToString};

use pkcs8::DecodePrivateKey;
use pki_types::PrivateKeyDer;
Expand Down
6 changes: 2 additions & 4 deletions src/sign/rsa.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use alloc::format;
use alloc::sync::Arc;
#[cfg(not(feature = "std"))]
use {alloc::boxed::Box, alloc::string::ToString};
#[cfg(feature = "alloc")]
use alloc::{boxed::Box, format, string::ToString, sync::Arc};

use pkcs8::DecodePrivateKey;
use pki_types::PrivateKeyDer;
Expand Down

0 comments on commit db39e4d

Please sign in to comment.